@pasko70/pibo 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps/chat/agent-profiles.js +4 -1
- package/dist/apps/chat/agent-store.js +196 -3
- package/dist/apps/chat/web-app.js +5 -4
- package/dist/apps/chat-ui/assets/{dist-D1Laodgo.js → dist-B6kzRv2_.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-BtF63vik.js → dist-Bns-O5iY.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-85Cc5Hut.js → dist-CVcI9eYD.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-CQXtvBTs.js → dist-CqkKCn6l.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-B8jspmzT.js → dist-D4CEl91a.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-DE8W5WKg.js → dist-D9K0kHT0.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-oLAGkW6G.js → dist-DWA7BIr3.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-DcME5mJj.js → dist-Dj3uUYqF.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-ecTM1pdv.js → dist-DqaKPP5Y.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-BGqK-7Ep.js → dist-DuM9PL5k.js} +1 -1
- package/dist/apps/chat-ui/assets/{dist-eG89IJAV.js → dist-DvPgMX-r.js} +1 -1
- package/dist/apps/chat-ui/assets/{index-D4uifikB.js → index-Baxj7Erc.js} +6 -5
- package/dist/apps/chat-ui/index.html +1 -1
- package/dist/apps/chat-vscode-web/assets/{index-CRUSv6iR.js → index-CjOC7zYy.js} +4 -4
- package/dist/apps/chat-vscode-web/index.html +1 -1
- package/dist/apps/cli-ui/inkMarkdown.js +8 -3
- package/dist/apps/cli-ui/inkSyntaxHighlighter.js +166 -0
- package/dist/apps/vscode-artifacts/latest.vsix +0 -0
- package/dist/apps/vscode-artifacts/{pibo-vscode-ext-1.4.5.vsix → pibo-vscode-ext-1.4.6.vsix} +0 -0
- package/dist/cli.js +20 -0
- package/dist/mcp/agent-context.js +10 -6
- package/dist/mcp/commands/info.js +19 -7
- package/dist/mcp/config.js +98 -65
- package/dist/plugins/builtin.js +15 -1
- package/dist/session-ui/terminalRows.js +56 -2
- package/dist/shared/trace-nodes.js +12 -0
- package/dist/skills/cli.js +25 -1
- package/dist/tools/guides.js +71 -0
- package/dist/tools/index.js +7 -3
- package/dist/tools/python-runtime.js +2 -2
- package/dist/tools/registry.js +25 -1
- package/package.json +93 -93
- package/skills/builtin/graphify/SKILL.md +52 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-B6kzRv2_.js","assets/dist-SVPsM5Oi.js","assets/dist-tGfufz3b.js","assets/dist-C5YJOwhH.js","assets/dist-CKM5j-iy.js","assets/rolldown-runtime-S-ySWqyJ.js","assets/dist-CVcI9eYD.js","assets/dist-DWA7BIr3.js","assets/dist-Dj3uUYqF.js","assets/dist--55mTWk3.js","assets/dist-Bns-O5iY.js","assets/dist-BZ39rB1W.js","assets/dist-C5oXtFSP.js","assets/dist-DvPgMX-r.js","assets/dist-D9K0kHT0.js","assets/dist-D4CEl91a.js","assets/dist-CqkKCn6l.js","assets/dist-CUp9us2q.js","assets/dist-DSKQpPaz.js","assets/dist-CZ9T4Cly.js","assets/dist-Zqt9kNG9.js","assets/dist-BsedZGJo.js","assets/dockerfile-CUaqzcqp.js","assets/simple-mode-CL04yRVp.js","assets/factor-C2tAxNob.js","assets/nsis-SMDwKltR.js","assets/pug-Bo3wfL-f.js","assets/javascript-DSlzRUd8.js","assets/dist-DuM9PL5k.js","assets/dist-DqaKPP5Y.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{n as e,r as t,t as n}from"./rolldown-runtime-S-ySWqyJ.js";import{$ as r,A as i,At as a,Ct as o,Dt as s,E as c,Et as l,G as u,J as d,K as f,L as p,Mt as m,Nt as h,O as g,Ot as _,P as v,Pt as y,Q as b,S as x,St as S,T as C,Tt as w,W as T,X as E,Y as D,Z as O,_t as k,a as A,at as j,bt as M,c as N,ct as P,dt as F,et as ee,f as te,ft as I,g as ne,gt as L,ht as re,it as ie,j as ae,jt as oe,kt as se,l as ce,lt as le,mt as ue,n as de,nt as fe,o as pe,ot as me,pt as he,q as ge,rt as _e,st as ve,t as ye,tt as be,ut as xe,v as Se,vt as Ce,w as we,wt as Te,x as Ee,xt as De,yt as Oe}from"./dist-SVPsM5Oi.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),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ke=n((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 ee=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)},te={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=te,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,ee)}catch(e){ee(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.5`})),Ae=n(((e,t)=>{t.exports=ke()})),je=n((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}}}})),Me=n(((e,t)=>{t.exports=je()})),Ne=n((e=>{var t=Ae();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.5`})),Pe=n(((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=Ne()})),Fe=n((e=>{var t=Me(),n=Ae(),r=Pe();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},ee=[],te=-1;function I(e){return{current:e}}function ne(e){0>te||(e.current=ee[te],ee[te]=null,te--)}function L(e,t){te++,ee[te]=e.current,e.current=t}var re=I(null),ie=I(null),ae=I(null),oe=I(null);function se(e,t){switch(L(ae,t),L(ie,e),L(re,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Qd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Qd(t),e=$d(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ne(re),L(re,e)}function ce(){ne(re),ne(ie),ne(ae)}function le(e){e.memoizedState!==null&&L(oe,e);var t=re.current,n=$d(t,e.type);t!==n&&(L(ie,e),L(re,n))}function ue(e){ie.current===e&&(ne(re),ne(ie)),oe.current===e&&(ne(oe),lp._currentValue=F)}var de,fe;function pe(e){if(de===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);de=t&&t[1]||``,fe=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+de+e+fe}var me=!1;function he(e,t){if(!e||me)return``;me=!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(`
|
|
@@ -124,7 +124,7 @@ Error generating stack: `+e.message+`
|
|
|
124
124
|
`},sO=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},sle=function(){R.useEffect(function(){return document.body.setAttribute(oO,(sO()+1).toString()),function(){var e=sO()-1;e<=0?document.body.removeAttribute(oO):document.body.setAttribute(oO,e.toString())}},[])},cle=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;sle();var a=R.useMemo(function(){return ile(i)},[i]);return R.createElement(ale,{styles:ole(a,!t,i,n?``:`!important`)})},cO=!1;if(typeof window<`u`)try{var lO=Object.defineProperty({},`passive`,{get:function(){return cO=!0,!0}});window.addEventListener(`test`,lO,lO),window.removeEventListener(`test`,lO,lO)}catch{cO=!1}var uO=cO?{passive:!1}:!1,lle=function(e){return e.tagName===`TEXTAREA`},dO=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!lle(e)&&n[t]===`visible`)},ule=function(e){return dO(e,`overflowY`)},dle=function(e){return dO(e,`overflowX`)},fO=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),pO(e,r)){var i=mO(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},fle=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},ple=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},pO=function(e,t){return e===`v`?ule(t):dle(t)},mO=function(e,t){return e===`v`?fle(t):ple(t)},mle=function(e,t){return e===`h`&&t===`rtl`?-1:1},hle=function(e,t,n,r,i){var a=mle(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=mO(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&pO(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},hO=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},gO=function(e){return[e.deltaX,e.deltaY]},_O=function(e){return e&&`current`in e?e.current:e},gle=function(e,t){return e[0]===t[0]&&e[1]===t[1]},_le=function(e){return`
|
|
125
125
|
.block-interactivity-${e} {pointer-events: none;}
|
|
126
126
|
.allow-interactivity-${e} {pointer-events: all;}
|
|
127
|
-
`},vle=0,vO=[];function yle(e){var t=R.useRef([]),n=R.useRef([0,0]),r=R.useRef(),i=R.useState(vle++)[0],a=R.useState(iO)[0],o=R.useRef(e);R.useEffect(function(){o.current=e},[e]),R.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Bce([e.lockRef.current],(e.shards||[]).map(_O),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=R.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=hO(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=fO(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=fO(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return hle(h,t,e,h===`h`?s:c,!0)},[]),c=R.useCallback(function(e){var n=e;if(!(!vO.length||vO[vO.length-1]!==a)){var r=`deltaY`in n?gO(n):hO(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&gle(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(_O).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=R.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:ble(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=R.useCallback(function(e){n.current=hO(e),r.current=void 0},[]),d=R.useCallback(function(t){l(t.type,gO(t),t.target,s(t,e.lockRef.current))},[]),f=R.useCallback(function(t){l(t.type,hO(t),t.target,s(t,e.lockRef.current))},[]);R.useEffect(function(){return vO.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,uO),document.addEventListener(`touchmove`,c,uO),document.addEventListener(`touchstart`,u,uO),function(){vO=vO.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,uO),document.removeEventListener(`touchmove`,c,uO),document.removeEventListener(`touchstart`,u,uO)}},[]);var p=e.removeScrollBar,m=e.inert;return R.createElement(R.Fragment,null,m?R.createElement(a,{styles:_le(i)}):null,p?R.createElement(cle,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ble(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var xle=Yce(eO,yle),yO=R.forwardRef(function(e,t){return R.createElement(nO,qD({},e,{ref:t,sideCar:xle}))});yO.classNames=nO.classNames;var bO=`Popover`,[xO,Sle]=zT(bO,[CD]),SO=CD(),[Cle,CO]=xO(bO),wO=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=SO(t),c=R.useRef(null),[l,u]=R.useState(!1),[d,f]=BD({prop:r,defaultProp:i??!1,onChange:a,caller:bO});return(0,z.jsx)(ND,{...s,children:(0,z.jsx)(Cle,{scope:t,contentId:lE(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:R.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:R.useCallback(()=>u(!0),[]),onCustomAnchorRemove:R.useCallback(()=>u(!1),[]),modal:o,children:n})})};wO.displayName=bO;var TO=`PopoverAnchor`,EO=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=CO(TO,n),a=SO(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return R.useEffect(()=>(o(),()=>s()),[o,s]),(0,z.jsx)(PD,{...a,...r,ref:t})});EO.displayName=TO;var DO=`PopoverTrigger`,OO=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=CO(DO,n),a=SO(n),o=RT(t,i.triggerRef),s=(0,z.jsx)(HT.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":IO(i.open),...r,ref:o,onClick:FT(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,z.jsx)(PD,{asChild:!0,...a,children:s})});OO.displayName=DO;var kO=`PopoverPortal`,[wle,Tle]=xO(kO,{forceMount:void 0}),AO=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=CO(kO,t);return(0,z.jsx)(wle,{scope:t,forceMount:n,children:(0,z.jsx)(RD,{present:n||a.open,children:(0,z.jsx)(LD,{asChild:!0,container:i,children:r})})})};AO.displayName=kO;var jO=`PopoverContent`,MO=R.forwardRef((e,t)=>{let n=Tle(jO,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=CO(jO,e.__scopePopover);return(0,z.jsx)(RD,{present:r||a.open,children:a.modal?(0,z.jsx)(Dle,{...i,ref:t}):(0,z.jsx)(Ole,{...i,ref:t})})});MO.displayName=jO;var Ele=BT(`PopoverContent.RemoveScroll`),Dle=R.forwardRef((e,t)=>{let n=CO(jO,e.__scopePopover),r=R.useRef(null),i=RT(t,r),a=R.useRef(!1);return R.useEffect(()=>{let e=r.current;if(e)return KD(e)},[]),(0,z.jsx)(yO,{as:Ele,allowPinchZoom:!0,children:(0,z.jsx)(NO,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:FT(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:FT(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:FT(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),Ole=R.forwardRef((e,t)=>{let n=CO(jO,e.__scopePopover),r=R.useRef(!1),i=R.useRef(!1);return(0,z.jsx)(NO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),NO=R.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=CO(jO,n),p=SO(n);return ZT(),(0,z.jsx)(nE,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,z.jsx)(qT,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,z.jsx)(FD,{"data-state":IO(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),PO=`PopoverClose`,kle=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=CO(PO,n);return(0,z.jsx)(HT.button,{type:`button`,...r,ref:t,onClick:FT(e.onClick,()=>i.onOpenChange(!1))})});kle.displayName=PO;var Ale=`PopoverArrow`,FO=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=SO(n);return(0,z.jsx)(ID,{...i,...r,ref:t})});FO.displayName=Ale;function IO(e){return e?`open`:`closed`}var LO=wO,jle=EO,RO=AO,Mle=MO,zO=FO;function BO(e){let t=e+`CollectionProvider`,[n,r]=zT(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=R.useRef(null),a=R.useRef(new Map).current;return(0,z.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=BT(s),l=R.forwardRef((e,t)=>{let{scope:n,children:r}=e;return(0,z.jsx)(c,{ref:RT(t,a(s,n).collectionRef),children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=BT(u),p=R.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=R.useRef(null),s=RT(t,o),c=a(u,n);return R.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,z.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return R.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}var Nle=R.createContext(void 0);function VO(e){let t=R.useContext(Nle);return e||t||`ltr`}var HO=`rovingFocusGroup.onEntryFocus`,Ple={bubbles:!1,cancelable:!0},UO=`RovingFocusGroup`,[WO,GO,Fle]=BO(UO),[Ile,KO]=zT(UO,[Fle]),[Lle,Rle]=Ile(UO),qO=R.forwardRef((e,t)=>(0,z.jsx)(WO.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,z.jsx)(WO.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,z.jsx)(zle,{...e,ref:t})})}));qO.displayName=UO;var zle=R.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=R.useRef(null),p=RT(t,f),m=VO(a),[h,g]=BD({prop:o,defaultProp:s??null,onChange:c,caller:UO}),[_,v]=R.useState(!1),y=UT(l),b=GO(n),x=R.useRef(!1),[S,C]=R.useState(0);return R.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(HO,y),()=>e.removeEventListener(HO,y)},[y]),(0,z.jsx)(Lle,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:R.useCallback(e=>g(e),[g]),onItemShiftTab:R.useCallback(()=>v(!0),[]),onFocusableItemAdd:R.useCallback(()=>C(e=>e+1),[]),onFocusableItemRemove:R.useCallback(()=>C(e=>e-1),[]),children:(0,z.jsx)(HT.div,{tabIndex:_||S===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:FT(e.onMouseDown,()=>{x.current=!0}),onFocus:FT(e.onFocus,e=>{let t=!x.current;if(e.target===e.currentTarget&&t&&!_){let t=new CustomEvent(HO,Ple);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=b().filter(e=>e.focusable);QO([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}x.current=!1}),onBlur:FT(e.onBlur,()=>v(!1))})})}),JO=`RovingFocusGroupItem`,YO=R.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=lE(),l=a||c,u=Rle(JO,n),d=u.currentTabStopId===l,f=GO(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u;return R.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),(0,z.jsx)(WO.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,z.jsx)(HT.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:FT(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:FT(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:FT(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=ZO(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?$O(n,r+1):n.slice(r+1)}setTimeout(()=>QO(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})});YO.displayName=JO;var Ble={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function XO(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}function ZO(e,t,n){let r=XO(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return Ble[r]}function QO(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $O(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ek=qO,tk=YO,nk=`Separator`,rk=`horizontal`,ik=[`horizontal`,`vertical`],ak=R.forwardRef((e,t)=>{let{decorative:n,orientation:r=rk,...i}=e,a=ok(r)?r:rk,o=n?{role:`none`}:{"aria-orientation":a===`vertical`?a:void 0,role:`separator`};return(0,z.jsx)(HT.div,{"data-orientation":a,...o,...i,ref:t})});ak.displayName=nk;function ok(e){return ik.includes(e)}var sk=ak,ck=`Toggle`,lk=R.forwardRef((e,t)=>{let{pressed:n,defaultPressed:r,onPressedChange:i,...a}=e,[o,s]=BD({prop:n,onChange:i,defaultProp:r??!1,caller:ck});return(0,z.jsx)(HT.button,{type:`button`,"aria-pressed":o,"data-state":o?`on`:`off`,"data-disabled":e.disabled?``:void 0,...a,ref:t,onClick:FT(e.onClick,()=>{e.disabled||s(!o)})})});lk.displayName=ck;var uk=`ToggleGroup`,[dk,fk]=zT(uk,[KO]),pk=KO(),mk=R.forwardRef((e,t)=>{let{type:n,...r}=e;if(n===`single`)return(0,z.jsx)(_k,{...r,ref:t});if(n===`multiple`)return(0,z.jsx)(vk,{...r,ref:t});throw Error(`Missing prop \`type\` expected on \`${uk}\``)});mk.displayName=uk;var[hk,gk]=dk(uk),_k=R.forwardRef((e,t)=>{let{value:n,defaultValue:r,onValueChange:i=()=>{},...a}=e,[o,s]=BD({prop:n,defaultProp:r??``,onChange:i,caller:uk});return(0,z.jsx)(hk,{scope:e.__scopeToggleGroup,type:`single`,value:R.useMemo(()=>o?[o]:[],[o]),onItemActivate:s,onItemDeactivate:R.useCallback(()=>s(``),[s]),children:(0,z.jsx)(xk,{...a,ref:t})})}),vk=R.forwardRef((e,t)=>{let{value:n,defaultValue:r,onValueChange:i=()=>{},...a}=e,[o,s]=BD({prop:n,defaultProp:r??[],onChange:i,caller:uk}),c=R.useCallback(e=>s((t=[])=>[...t,e]),[s]),l=R.useCallback(e=>s((t=[])=>t.filter(t=>t!==e)),[s]);return(0,z.jsx)(hk,{scope:e.__scopeToggleGroup,type:`multiple`,value:o,onItemActivate:c,onItemDeactivate:l,children:(0,z.jsx)(xk,{...a,ref:t})})});mk.displayName=uk;var[yk,bk]=dk(uk),xk=R.forwardRef((e,t)=>{let{__scopeToggleGroup:n,disabled:r=!1,rovingFocus:i=!0,orientation:a,dir:o,loop:s=!0,...c}=e,l=pk(n),u=VO(o),d={role:`group`,dir:u,...c};return(0,z.jsx)(yk,{scope:n,rovingFocus:i,disabled:r,children:i?(0,z.jsx)(ek,{asChild:!0,...l,orientation:a,dir:u,loop:s,children:(0,z.jsx)(HT.div,{...d,ref:t})}):(0,z.jsx)(HT.div,{...d,ref:t})})}),Sk=`ToggleGroupItem`,Ck=R.forwardRef((e,t)=>{let n=gk(Sk,e.__scopeToggleGroup),r=bk(Sk,e.__scopeToggleGroup),i=pk(e.__scopeToggleGroup),a=n.value.includes(e.value),o=r.disabled||e.disabled,s={...e,pressed:a,disabled:o},c=R.useRef(null);return r.rovingFocus?(0,z.jsx)(tk,{asChild:!0,...i,focusable:!o,active:a,ref:c,children:(0,z.jsx)(wk,{...s,ref:t})}):(0,z.jsx)(wk,{...s,ref:t})});Ck.displayName=Sk;var wk=R.forwardRef((e,t)=>{let{__scopeToggleGroup:n,value:r,...i}=e,a=gk(Sk,n),o={role:`radio`,"aria-checked":e.pressed,"aria-pressed":void 0};return(0,z.jsx)(lk,{...a.type===`single`?o:void 0,...i,ref:t,onPressedChange:e=>{e?a.onItemActivate(r):a.onItemDeactivate(r)}})}),Tk=mk,Ek=Ck,Dk=`Toolbar`,[Ok,Vle]=zT(Dk,[KO,fk]),kk=KO(),Ak=fk(),[jk,Mk]=Ok(Dk),Nk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,orientation:r=`horizontal`,dir:i,loop:a=!0,...o}=e,s=kk(n),c=VO(i);return(0,z.jsx)(jk,{scope:n,orientation:r,dir:c,children:(0,z.jsx)(ek,{asChild:!0,...s,orientation:r,dir:c,loop:a,children:(0,z.jsx)(HT.div,{role:`toolbar`,"aria-orientation":r,dir:c,...o,ref:t})})})});Nk.displayName=Dk;var Pk=`ToolbarSeparator`,Fk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=Mk(Pk,n);return(0,z.jsx)(sk,{orientation:i.orientation===`horizontal`?`vertical`:`horizontal`,...r,ref:t})});Fk.displayName=Pk;var Ik=`ToolbarButton`,Lk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=kk(n);return(0,z.jsx)(tk,{asChild:!0,...i,focusable:!e.disabled,children:(0,z.jsx)(HT.button,{type:`button`,...r,ref:t})})});Lk.displayName=Ik;var Rk=`ToolbarLink`,zk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=kk(n);return(0,z.jsx)(tk,{asChild:!0,...i,focusable:!0,children:(0,z.jsx)(HT.a,{...r,ref:t,onKeyDown:FT(e.onKeyDown,e=>{e.key===` `&&e.currentTarget.click()})})})});zk.displayName=Rk;var Bk=`ToolbarToggleGroup`,Vk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=Mk(Bk,n),a=Ak(n);return(0,z.jsx)(Tk,{"data-orientation":i.orientation,dir:i.dir,...a,...r,ref:t,rovingFocus:!1})});Vk.displayName=Bk;var Hk=`ToolbarToggleItem`,Uk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=Ak(n);return(0,z.jsx)(Lk,{asChild:!0,__scopeToolbar:e.__scopeToolbar,children:(0,z.jsx)(Ek,{...i,...r,ref:t})})});Uk.displayName=Hk;var Wk=Nk,Gk=Fk,Kk=Lk,qk=Vk,Jk=Uk;function Yk(e,t){return e===null||e===t?!1:e.dataset.editorDialog!==void 0||e.dataset.toolbarItem!==void 0||e.dataset.editorDropdown?!0:Yk(e.parentElement,t)}function Xk(){let e=[...Array(256).keys()].map(e=>e.toString(16).padStart(2,`0`)),t=crypto.getRandomValues(new Uint8Array(16));return t[6]=t[6]&15|64,t[8]=t[8]&63|128,[...t.entries()].map(([t,n])=>[4,6,8,10].includes(t)?`-${e[n]}`:e[n]).join(``)}var Zk=e=>e===0?`th`:`td`,Qk={center:mw.centeredCell,left:mw.leftAlignedCell,right:mw.rightAlignedCell},$k=({mdastNode:e,parentEditor:t,lexicalTable:n})=>{let[r,i]=R.useState(null),[a,o]=Hl(NC,WS),s=R.useMemo(()=>e=>(e.__cacheKey??=Xk(),e.__cacheKey),[]),c=R.useCallback(e=>{let r=n.getColCount();if(e===null){i(null);return}let[a,o]=e;if(a>r-1&&(a=0,o++),a<0&&(a=r-1,--o),o>n.getRowCount()-1){i(null),t.update(()=>{if(n.getLatest().getNextSibling())n.getLatest().selectNext();else{let e=nh();n.insertAfter(e),e.select()}});return}if(o<0){i(null),t.update(()=>{n.getLatest().selectPrevious()});return}i([a,o])},[n,t]);R.useEffect(()=>{n.focusEmitter.subscribe(c)},[n,c]);let l=R.useCallback(e=>{e.preventDefault(),t.update(()=>{n.addRowToBottom(),i([0,n.getRowCount()])})},[t,n]),u=R.useCallback(e=>{e.preventDefault(),t.update(()=>{n.addColumnToRight(),i([n.getColCount(),0])})},[t,n]),[d,f]=R.useState([-1,-1]),p=R.useCallback(e=>{let t=e.target;for(;t&&![`TH`,`TD`].includes(t.tagName);){if(t===e.currentTarget)return;t=t.parentElement}if(t===null)return;let n=t.parentElement;f([n.parentElement.tagName===`TFOOT`?-1:Array.from(n.children).indexOf(t),t.tagName===`TH`?-1:Array.from(n.parentElement.children).indexOf(n)])},[]),m=rw();return R.createElement(`table`,{className:mw.tableEditor,onMouseOver:p,onMouseLeave:()=>{f([-1,-1])}},R.createElement(`colgroup`,null,o?null:R.createElement(`col`,null),Array.from({length:e.children[0].children.length},(t,n)=>{let r=Qk[(e.align??[])[n]??`left`];return R.createElement(`col`,{key:n,className:r})}),o?null:R.createElement(`col`,null)),o||R.createElement(`thead`,null,R.createElement(`tr`,null,R.createElement(`th`,{className:mw.tableToolsColumn}),Array.from({length:e.children[0].children.length},(r,i)=>R.createElement(`th`,{key:i,"data-tool-cell":!0},R.createElement(nA,{setActiveCellWithBoundaries:c,parentEditor:t,colIndex:i,highlightedCoordinates:d,lexicalTable:n,align:(e.align??[])[i]}))),R.createElement(`th`,{className:mw.tableToolsColumn,"data-tool-cell":!0},R.createElement(`button`,{className:mw.iconButton,type:`button`,title:m(`table.deleteTable`,`Delete table`),onClick:e=>{e.preventDefault(),t.update(()=>{n.selectNext(),n.remove()})}},a(`delete_small`))))),R.createElement(`tbody`,null,e.children.map((i,l)=>{let f=Zk(l);return R.createElement(`tr`,{key:l},o||R.createElement(f,{className:mw.toolCell,"data-tool-cell":!0},R.createElement(rA,{setActiveCellWithBoundaries:c,parentEditor:t,rowIndex:l,highlightedCoordinates:d,lexicalTable:n})),i.children.map((i,a)=>R.createElement(eA,{align:e.align?.[a],key:s(i),contents:i.children,setActiveCell:c,rowIndex:l,colIndex:a,lexicalTable:n,parentEditor:t,activeCell:o?[-1,-1]:r})),o||l===0&&R.createElement(`th`,{rowSpan:n.getRowCount(),"data-tool-cell":!0},R.createElement(`button`,{type:`button`,className:mw.addColumnButton,onClick:u},a(`add_column`))))})),o||R.createElement(`tfoot`,null,R.createElement(`tr`,null,R.createElement(`th`,null),R.createElement(`th`,{colSpan:n.getColCount(),"data-tool-cell":!0},R.createElement(`button`,{type:`button`,className:mw.addRowButton,onClick:l},a(`add_row`))),R.createElement(`th`,null))))},eA=({align:e,...t})=>{let{activeCell:n,setActiveCell:r}=t,i=!!(n&&n[0]===t.colIndex&&n[1]===t.rowIndex),a=Qk[e??`left`],o=Zk(t.rowIndex);return R.createElement(o,{className:a,"data-active":i,onClick:()=>{r([t.colIndex,t.rowIndex])}},R.createElement(tA,{...t,focus:i}))},tA=({focus:e,setActiveCell:t,parentEditor:n,lexicalTable:r,contents:i,colIndex:a,rowIndex:o})=>{let[s,c,l,u,d,f,p,m,h]=Hl(iC,cC,aC,fC,pC,mC,dC,BS,GC),[g]=R.useState(()=>{let e=ah({nodes:l,theme:RS,namespace:`TableCellEditor`});return e.update(()=>{bS({root:Ih(),mdastRoot:{type:`root`,children:[{type:`paragraph`,children:i}]},visitors:s,jsxComponentDescriptors:u,directiveDescriptors:d,codeBlockEditorDescriptors:f})}),e}),_=R.useCallback(e=>{g.getEditorState().read(()=>{let e=jx({root:Ih(),jsxComponentDescriptors:u,visitors:c,jsxIsAvailable:p});n.update(()=>{r.updateCellContents(a,o,e.children[0].children)},{discrete:!0}),n.dispatchCommand(zS,void 0)}),t(e)},[a,g,c,u,p,r,n,o,t]);return R.useEffect(()=>U_(g.registerCommand(vf,e=>(e.preventDefault(),_(e.shiftKey?[a-1,o]:[a+1,o]),!0),4),g.registerCommand(Pf,()=>(t([a,o]),!1),1),g.registerCommand(pf,e=>(e?.preventDefault(),_(e?.shiftKey?[a,o-1]:[a,o+1]),!0),4),g.registerCommand(Ff,e=>{let t=e.relatedTarget;return Yk(t,m.getRootElement())?!1:(_(null),!0)},0),g.registerCommand(zS,()=>(_(null),!0),0)),[a,g,m,o,_,t]),R.useEffect(()=>{e&&g.focus()},[e,g]),R.createElement(Joe,{initialEditor:g},R.createElement(pw,{contentEditable:R.createElement(sw,null),placeholder:R.createElement(`div`,null),ErrorBoundary:uw}),h.map((e,t)=>R.createElement(e,{key:t})),R.createElement(cv,null))},nA=({parentEditor:e,highlightedCoordinates:t,align:n,lexicalTable:r,colIndex:i,setActiveCellWithBoundaries:a})=>{let[o,s]=Hl(hC,NC),c=R.useCallback(t=>{e.update(()=>{r.insertColumnAt(t)}),a([t,0])},[e,r,a]),l=R.useCallback(t=>{e.update(()=>{r.deleteColumnAt(t)})},[e,r]),u=R.useCallback((t,n)=>{e.update(()=>{r.setColumnAlign(t,n)})},[e,r]),d=rw();return R.createElement(LO,null,R.createElement(OO,{className:mw.tableColumnEditorTrigger,"data-active":t[0]===i+1,title:d(`table.columnMenu`,`Column menu`)},s(`more_horiz`)),R.createElement(RO,{container:o?.current},R.createElement(MO,{className:(0,rT.default)(mw.tableColumnEditorPopoverContent),onOpenAutoFocus:e=>{e.preventDefault()},sideOffset:5,side:`top`},R.createElement(Wk,{className:mw.tableColumnEditorToolbar},R.createElement(qk,{className:mw.toggleGroupRoot,onValueChange:e=>{u(i,e)},value:n??`left`,type:`single`,"aria-label":d(`table.textAlignment`,`Text alignment`)},R.createElement(Jk,{value:`left`,title:d(`table.alignLeft`,`Align left`)},s(`format_align_left`)),R.createElement(Jk,{value:`center`,title:d(`table.alignCenter`,`Align center`)},s(`format_align_center`)),R.createElement(Jk,{value:`right`,title:d(`table.alignRight`,`Align right`)},s(`format_align_right`))),R.createElement(Gk,null),R.createElement(Kk,{onClick:c.bind(null,i),title:d(`table.insertColumnLeft`,`Insert a column to the left of this one`)},s(`insert_col_left`)),R.createElement(Kk,{onClick:c.bind(null,i+1),title:d(`table.insertColumnRight`,`Insert a column to the right of this one`)},s(`insert_col_right`)),R.createElement(Kk,{onClick:l.bind(null,i),title:d(`table.deleteColumn`,`Delete this column`)},s(`delete_small`))),R.createElement(zO,{className:mw.popoverArrow}))))},rA=({parentEditor:e,highlightedCoordinates:t,lexicalTable:n,rowIndex:r,setActiveCellWithBoundaries:i})=>{let[a,o]=Hl(hC,NC),s=R.useCallback(t=>{e.update(()=>{n.insertRowAt(t)}),i([0,t])},[e,n,i]),c=R.useCallback(t=>{e.update(()=>{n.deleteRowAt(t)})},[e,n]),l=rw();return R.createElement(LO,null,R.createElement(OO,{className:mw.tableColumnEditorTrigger,"data-active":t[1]===r,title:l(`table.rowMenu`,`Row menu`)},o(`more_horiz`)),R.createElement(RO,{container:a?.current},R.createElement(MO,{className:(0,rT.default)(mw.tableColumnEditorPopoverContent),onOpenAutoFocus:e=>{e.preventDefault()},sideOffset:5,side:`bottom`},R.createElement(Wk,{className:mw.tableColumnEditorToolbar},R.createElement(Kk,{onClick:s.bind(null,r),title:l(`table.insertRowAbove`,`Insert a row above this one`)},o(`insert_row_above`)),R.createElement(Kk,{onClick:s.bind(null,r+1),title:l(`table.insertRowBelow`,`Insert a row below this one`)},o(`insert_row_below`)),R.createElement(Kk,{onClick:c.bind(null,r),title:l(`table.deleteRow`,`Delete this row`)},o(`delete_small`))),R.createElement(zO,{className:mw.popoverArrow}))))},iA=Object.defineProperty,aA=(e,t,n)=>t in e?iA(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oA=(e,t,n)=>(aA(e,typeof t==`symbol`?t:t+``,n),n),sA={type:`tableCell`,children:[]};function cA(){let e=Yl;return{publish:t=>{e(t)},subscribe:t=>{e=t}}}var lA=class e extends Wm{constructor(e,t){super(t),oA(this,`__mdastNode`),oA(this,`focusEmitter`,cA()),this.__mdastNode=e??{type:`table`,children:[]}}static getType(){return`table`}static clone(t){return new e(structuredClone(t.__mdastNode),t.__key)}static importJSON(e){return dA(e.mdastNode)}static importDOM(){return{table:()=>({conversion:fA,priority:3})}}exportJSON(){return{mdastNode:structuredClone(this.__mdastNode),type:`table`,version:1}}getMdastNode(){return this.__mdastNode}getRowCount(){return this.__mdastNode.children.length}getColCount(){return this.__mdastNode.children[0]?.children.length||0}createDOM(){return document.createElement(`div`)}updateDOM(){return!1}updateCellContents(e,t,n){let r=this.getWritable().__mdastNode,i=r.children[t],a=i.children,o=a[e],s=Array.from(a),c={...o,children:n},l={...i,children:s};s[e]=c,r.children[t]=l}insertColumnAt(e){let t=this.getWritable().__mdastNode;for(let n=0;n<t.children.length;n++){let r=t.children[n],i=r.children,a=Array.from(i),o={...r,children:a};a.splice(e,0,structuredClone(sA)),t.children[n]=o}t.align&&t.align.length>0&&t.align.splice(e,0,`left`)}deleteColumnAt(e){let t=this.getWritable().__mdastNode;for(let n=0;n<t.children.length;n++){let r=t.children[n],i=r.children,a=Array.from(i),o={...r,children:a};a.splice(e,1),t.children[n]=o}}insertRowAt(e){let t=this.getWritable().__mdastNode,n={type:`tableRow`,children:Array.from({length:this.getColCount()},()=>structuredClone(sA))};t.children.splice(e,0,n)}deleteRowAt(e){this.getRowCount()===1?(this.selectNext(),this.remove()):this.getWritable().__mdastNode.children.splice(e,1)}addRowToBottom(){this.insertRowAt(this.getRowCount())}addColumnToRight(){this.insertColumnAt(this.getColCount())}setColumnAlign(e,t){let n=this.getWritable().__mdastNode;n.align??=[],n.align[e]=t}decorate(e){return R.createElement($k,{lexicalTable:this,mdastNode:this.__mdastNode,parentEditor:e})}select(e){this.focusEmitter.publish(e??[0,0])}isInline(){return!1}};function uA(e){return e instanceof lA}function dA(e){return new lA(e)}function fA(e){let t=e.querySelectorAll(`tr`);return{node:new lA({type:`table`,children:Array.from(t).map(e=>({type:`tableRow`,children:Array.from(e.querySelectorAll(`td, th`)).map(e=>({type:`tableCell`,children:[{type:`text`,value:e.textContent}]}))}))})}}var pA={testLexicalNode:uA,visitLexicalNode({actions:e,mdastParent:t,lexicalNode:n}){e.appendToParent(t,n.getMdastNode())}},mA={testNode:`table`,visitNode({mdastNode:e,lexicalParent:t}){t.append(dA(e))}};function hA(e=1,t=1){let n={type:`table`,children:[]};for(let r=0;r<e;r++){let e={type:`tableRow`,children:[]};for(let n=0;n<t;n++)e.children.push({type:`tableCell`,children:[]});n.children.push(e)}return n}var gA=Ll(e=>{e.link(e.pipe(gA,Wl(({rows:e,columns:t})=>()=>dA(hA(e,t)))),XC)}),_A=Xl({init(e,t){e.pubIn({[xC]:wT(),[bC]:OT(),[yC]:mA,[vC]:lA,[SC]:pA,[CC]:DT({tableCellPadding:t?.tableCellPadding??!0,tablePipeAlign:t?.tablePipeAlign??!0})})}}),vA={testNode:`link`,visitNode({mdastNode:e,actions:t}){t.addAndStepInto(gw(e.url,{title:e.title}))}},yA={testLexicalNode:_w,visitLexicalNode:({lexicalNode:e,actions:t})=>{t.addAndStepInto(`link`,{url:e.getURL(),title:e.getTitle()})}};function bA({validateUrl:e,attributes:t}){let[n]=eu();return(0,R.useEffect)((()=>{if(!n.hasNodes([hw]))throw Error(`LinkPlugin: LinkNode not registered on editor`);return U_(n.registerCommand(xw,(n=>{if(n===null)return Cw(n),!0;if(typeof n==`string`)return!(e!==void 0&&!e(n))&&(Cw(n,t),!0);{let{url:e,target:r,rel:i,title:a}=n;return Cw(e,{...t,rel:i,target:r,title:a}),!0}}),1),e===void 0?()=>{}:n.registerCommand(Qd,(r=>{let i=G();if(!W(i)||i.isCollapsed()||!$_(r,ClipboardEvent)||r.clipboardData===null)return!1;let a=r.clipboardData.getData(`text`);return!!e(a)&&!i.getNodes().some((e=>K(e)))&&(n.dispatchCommand(xw,{...t,url:a}),r.preventDefault(),!0)}),1))}),[n,e,t]),null}function xA(e,t=(e=>e)){return n=>{let r=e.exec(n);return r===null?null:{index:r.index,length:r[0].length,text:r[0],url:t(r[0])}}}function SA(e,t){for(let n=0;n<t.length;n++){let r=t[n](e);if(r)return r}return null}var CA=/[.,;\s]/;function wA(e){return CA.test(e)}function TA(e){return wA(e[e.length-1])}function EA(e){return wA(e[0])}function DA(e){let t=e.getPreviousSibling();return K(t)&&(t=t.getLastDescendant()),t===null||vp(t)||U(t)&&TA(t.getTextContent())}function OA(e){let t=e.getNextSibling();return K(t)&&(t=t.getFirstDescendant()),t===null||vp(t)||U(t)&&EA(t.getTextContent())}function kA(e,t,n,r){return(e>0?wA(n[e-1]):DA(r[0]))?t<n.length?wA(n[t]):OA(r[r.length-1]):!1}function AA(e,t,n){let r=[],i=[],a=[],o=0,s=0,c=[...e];for(;c.length>0;){let e=c[0],l=e.getTextContent().length,u=s;s+l<=t?(r.push(e),o+=l):u>=n?a.push(e):i.push(e),s+=l,c.shift()}return[o,r,i,a]}function jA(e,t,n,r){let i=yw(r.url,r.attributes);if(e.length===1){let a,o=e[0];t===0?[a,o]=o.splitText(n):[,a,o]=o.splitText(t,n);let s=Fp(r.text);return s.setFormat(a.getFormat()),s.setDetail(a.getDetail()),s.setStyle(a.getStyle()),i.append(s),a.replace(i),o}if(e.length>1){let r=e[0],a,o=r.getTextContent().length;t===0?a=r:[,a]=r.splitText(t);let s=[],c;for(let t=1;t<e.length;t++){let r=e[t],i=r.getTextContent().length,a=o;if(a<n)if(o+i<=n)s.push(r);else{let[e,t]=r.splitText(n-a);s.push(e),c=t}o+=i}let l=G(),u=l?l.getNodes().find(U):void 0,d=Fp(a.getTextContent());return d.setFormat(a.getFormat()),d.setDetail(a.getDetail()),d.setStyle(a.getStyle()),i.append(d,...s),u&&u===a&&(W(l)?d.select(l.anchor.offset,l.focus.offset):Kp(l)&&d.select(0,d.getTextContent().length)),a.replace(i),c}}function MA(e,t,n){let r=e.getChildren(),i=r.length;for(let t=0;t<i;t++){let i=r[t];if(!U(i)||!i.isSimpleText())return NA(e),void n(null,e.getURL())}let a=e.getTextContent(),o=SA(a,t);if(o===null||o.text!==a||!DA(e)||!OA(e))return NA(e),void n(null,e.getURL());let s=e.getURL();if(s!==o.url&&(e.setURL(o.url),n(o.url,s)),o.attributes){let t=e.getRel();t!==o.attributes.rel&&(e.setRel(o.attributes.rel||null),n(o.attributes.rel||null,t));let r=e.getTarget();r!==o.attributes.target&&(e.setTarget(o.attributes.target||null),n(o.attributes.target||null,r))}}function NA(e){let t=e.getChildren();for(let n=t.length-1;n>=0;n--)e.insertAfter(t[n]);return e.remove(),t.map((e=>e.getLatest()))}function PA(e,t,n){(0,R.useEffect)((()=>{e.hasNodes([vw])||function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(77);let r=(e,t)=>{n&&n(e,t)};return U_(e.registerNodeTransform(Ep,(e=>{let n=e.getParentOrThrow(),i=e.getPreviousSibling();bw(n)&&!n.getIsUnlinked()?MA(n,t,r):_w(n)||(e.isSimpleText()&&(EA(e.getTextContent())||!bw(i))&&(function(e,t,n){let r=[...e],i=r.map((e=>e.getTextContent())).join(``),a,o=i,s=0;for(;(a=SA(o,t))&&a!==null;){let e=a.index,t=e+a.length;if(kA(s+e,s+t,i,r)){let[i,,o,c]=AA(r,s+e,s+t),l=jA(o,s+e-i,s+t-i,a);r=l?[l,...c]:c,n(a.url,null),s=0}else s+=t;o=o.substring(t)}})(function(e){let t=[e],n=e.getNextSibling();for(;n!==null&&U(n)&&n.isSimpleText()&&(t.push(n),!/[\s]/.test(n.getTextContent()));)n=n.getNextSibling();return t}(e),t,r),(function(e,t,n){let r=e.getPreviousSibling(),i=e.getNextSibling(),a=e.getTextContent();var o;!bw(r)||r.getIsUnlinked()||EA(a)&&(o=a,!(r.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(o):/^\.[a-zA-Z0-9]{1,}/.test(o)))||(r.append(e),MA(r,t,n),n(null,r.getURL())),!bw(i)||i.getIsUnlinked()||TA(a)||(NA(i),MA(i,t,n),n(null,i.getURL()))})(e,t,r))})),e.registerCommand(xw,(e=>{let t=G();return e!==null||!W(t)||t.extract().forEach((e=>{let t=e.getParent();bw(t)&&(t.setIsUnlinked(!t.getIsUnlinked()),t.markDirty())})),!1}),1))}),[e,t,n])}function FA({matchers:e,onChange:t}){let[n]=eu();return PA(n,e,t),null}var IA=[xA(/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,e=>e.startsWith(`http`)?e:`https://${e}`),xA(/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/,e=>`mailto:${e}`)],LA=()=>R.createElement(FA,{matchers:IA}),RA=Il(!1),zA=Xl({init(e,t){let n=!!t?.disableAutoLink,r=t?.validateUrl?{validateUrl:t.validateUrl}:{},i=()=>R.createElement(R.Fragment,null,R.createElement(bA,{...r}),n?null:R.createElement(LA,null));e.pubIn({[ew]:`link`,[yC]:vA,[vC]:[hw,vw],[SC]:yA,[RA]:n,[WC]:i,[KC]:i,[BC]:i})}}),BA=e=>e.type===`checkbox`,VA=e=>e instanceof Date,HA=e=>e==null,UA=e=>typeof e==`object`,WA=e=>!HA(e)&&!Array.isArray(e)&&UA(e)&&!VA(e),GA=e=>WA(e)&&e.target?BA(e.target)?e.target.checked:e.target.value:e,KA=(e,t)=>t.split(`.`).some((t,n,r)=>!isNaN(Number(t))&&e.has(r.slice(0,n).join(`.`))),qA=e=>{let t=e.constructor&&e.constructor.prototype;return WA(t)&&t.hasOwnProperty(`isPrototypeOf`)},JA=typeof window<`u`&&window.HTMLElement!==void 0&&typeof document<`u`;function YA(e){if(e instanceof Date)return new Date(e);let t=typeof FileList<`u`&&e instanceof FileList;if(JA&&(e instanceof Blob||t))return e;let n=Array.isArray(e);if(!n&&!(WA(e)&&qA(e)))return e;let r=n?[]:Object.create(Object.getPrototypeOf(e));for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=YA(e[t]));return r}var XA=e=>/^\w*$/.test(e),ZA=e=>e===void 0,QA=e=>Array.isArray(e)?e.filter(Boolean):[],$A=e=>QA(e.replace(/["|']|\]/g,``).split(/\.|\[/)),ej=(e,t,n)=>{if(!t||!WA(e))return n;let r=(XA(t)?[t]:$A(t)).reduce((e,t)=>HA(e)?void 0:e[t],e);return ZA(r)||r===e?ZA(e[t])?n:e[t]:r},tj=e=>typeof e==`boolean`,nj=e=>typeof e==`function`,rj=(e,t,n)=>{let r=-1,i=XA(t)?[t]:$A(t),a=i.length,o=a-1;for(;++r<a;){let t=i[r],a=n;if(r!==o){let n=e[t];a=WA(n)||Array.isArray(n)?n:isNaN(+i[r+1])?{}:[]}if(t===`__proto__`||t===`constructor`||t===`prototype`)return;e[t]=a,e=e[t]}},ij={BLUR:`blur`,FOCUS_OUT:`focusout`,CHANGE:`change`,SUBMIT:`submit`,TRIGGER:`trigger`,VALID:`valid`},aj={onBlur:`onBlur`,onChange:`onChange`,onSubmit:`onSubmit`,onTouched:`onTouched`,all:`all`},oj={max:`max`,min:`min`,maxLength:`maxLength`,minLength:`minLength`,pattern:`pattern`,required:`required`,validate:`validate`},sj=`form`,cj=`root`,lj=R.createContext(null);lj.displayName=`HookFormControlContext`;var uj=()=>R.useContext(lj),dj=(e,t,n,r=!0)=>{let i={defaultValues:t._defaultValues};for(let a in e)Object.defineProperty(i,a,{get:()=>{let i=a;return t._proxyFormState[i]!==aj.all&&(t._proxyFormState[i]=!r||aj.all),n&&(n[i]=!0),e[i]}});return i},fj=typeof window<`u`?R.useLayoutEffect:R.useEffect;function Hle(e){let t=uj(),{control:n=t,disabled:r,name:i,exact:a}=e||{},[o,s]=R.useState(n._formState),c=R.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return fj(()=>n._subscribe({name:i,formState:c.current,exact:a,callback:e=>{!r&&s({...n._formState,...e})}}),[i,r,a]),R.useEffect(()=>{c.current.isValid&&n._setValid(!0)},[n]),R.useMemo(()=>dj(o,n,c.current,!1),[o,n])}var pj=e=>typeof e==`string`,mj=(e,t,n,r,i)=>pj(e)?(r&&t.watch.add(e),ej(n,e,i)):Array.isArray(e)?e.map(e=>(r&&t.watch.add(e),ej(n,e))):(r&&(t.watchAll=!0),n),hj=e=>HA(e)||!UA(e);function gj(e,t,n=new WeakSet){if(e===t)return!0;if(hj(e)||hj(t))return Object.is(e,t);if(VA(e)&&VA(t))return Object.is(e.getTime(),t.getTime());let r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;if(n.has(e)||n.has(t))return!0;n.add(e),n.add(t);for(let i of r){let r=e[i];if(!(i in t))return!1;if(i!==`ref`){let e=t[i];if(VA(r)&&VA(e)||(WA(r)||Array.isArray(r))&&(WA(e)||Array.isArray(e))?!gj(r,e,n):!Object.is(r,e))return!1}}return!0}function Ule(e){let t=uj(),{control:n=t,name:r,defaultValue:i,disabled:a,exact:o,compute:s}=e||{},c=R.useRef(i),l=R.useRef(s),u=R.useRef(void 0),d=R.useRef(n),f=R.useRef(r);l.current=s;let[p,m]=R.useState(()=>{let e=n._getWatch(r,c.current);return l.current?l.current(e):e}),h=R.useCallback(e=>{let t=mj(r,n._names,e||n._formValues,!1,c.current);return l.current?l.current(t):t},[n._formValues,n._names,r]),g=R.useCallback(e=>{if(!a){let t=mj(r,n._names,e||n._formValues,!1,c.current);if(l.current){let e=l.current(t);gj(e,u.current)||(m(e),u.current=e)}else m(t)}},[n._formValues,n._names,a,r]);fj(()=>((d.current!==n||!gj(f.current,r))&&(d.current=n,f.current=r,g()),n._subscribe({name:r,formState:{values:!0},exact:o,callback:e=>{g(e.values)}})),[n,o,r,g]),R.useEffect(()=>n._removeUnmounted());let _=d.current!==n,v=f.current,y=R.useMemo(()=>{if(a)return null;let e=!_&&!gj(v,r);return _||e?h():null},[a,_,r,v,h]);return y===null?p:y}function Wle(e){let t=uj(),{name:n,disabled:r,control:i=t,shouldUnregister:a,defaultValue:o,exact:s=!0}=e,c=KA(i._names.array,n),l=Ule({control:i,name:n,defaultValue:R.useMemo(()=>ej(i._formValues,n,ej(i._defaultValues,n,o)),[i,n,o]),exact:s}),u=Hle({control:i,name:n,exact:s}),d=R.useRef(e),f=R.useRef(i.register(n,{...e.rules,value:l,...tj(e.disabled)?{disabled:e.disabled}:{}}));d.current=e;let p=R.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ej(u.errors,n)},isDirty:{enumerable:!0,get:()=>!!ej(u.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ej(u.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ej(u.validatingFields,n)},error:{enumerable:!0,get:()=>ej(u.errors,n)}}),[u,n]),m=R.useCallback(e=>f.current.onChange({target:{value:GA(e),name:n},type:ij.CHANGE}),[n]),h=R.useCallback(()=>f.current.onBlur({target:{value:ej(i._formValues,n),name:n},type:ij.BLUR}),[n,i._formValues]),g=R.useCallback(e=>{let t=ej(i._fields,n);t&&t._f&&e&&(t._f.ref={focus:()=>nj(e.focus)&&e.focus(),select:()=>nj(e.select)&&e.select(),setCustomValidity:t=>nj(e.setCustomValidity)&&e.setCustomValidity(t),reportValidity:()=>nj(e.reportValidity)&&e.reportValidity()})},[i._fields,n]),_=R.useMemo(()=>({name:n,value:l,...tj(r)||u.disabled?{disabled:u.disabled||r}:{},onChange:m,onBlur:h,ref:g}),[n,r,u.disabled,m,h,g,l]);return R.useEffect(()=>{let e=i._options.shouldUnregister||a;i.register(n,{...d.current.rules,...tj(d.current.disabled)?{disabled:d.current.disabled}:{}});let t=(e,t)=>{let n=ej(i._fields,e);n&&n._f&&(n._f.mount=t)};if(t(n,!0),e){let e=YA(ej(i._options.defaultValues,n,d.current.defaultValue));rj(i._defaultValues,n,e),ZA(ej(i._formValues,n))&&rj(i._formValues,n,e)}return!c&&i.register(n),()=>{(c?e&&!i._state.action:e)?i.unregister(n):t(n,!1)}},[n,i,c,a]),R.useEffect(()=>{i._setDisabledField({disabled:r,name:n})},[r,n,i]),R.useMemo(()=>({field:_,formState:u,fieldState:p}),[_,u,p])}var Gle=e=>e.render(Wle(e)),Kle=R.createContext(null);Kle.displayName=`HookFormContext`;var qle=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},_j=e=>Array.isArray(e)?e:[e],vj=()=>{let e=[];return{get observers(){return e},next:t=>{for(let n of e)n.next&&n.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter(e=>e!==t)}}),unsubscribe:()=>{e=[]}}};function yj(e,t){let n={};for(let r in e)if(e.hasOwnProperty(r)){let i=e[r],a=t[r];if(i&&WA(i)&&a){let e=yj(i,a);WA(e)&&(n[r]=e)}else e[r]&&(n[r]=a)}return n}var bj=e=>WA(e)&&!Object.keys(e).length,xj=e=>e.type===`file`,Sj=e=>{if(!JA)return!1;let t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Cj=e=>e.type===`select-multiple`,wj=e=>e.type===`radio`,Jle=e=>wj(e)||BA(e),Tj=e=>Sj(e)&&e.isConnected;function Yle(e,t){let n=t.slice(0,-1).length,r=0;for(;r<n;){if(HA(e)){e=void 0;break}e=e[t[r]],r++}return e}function Xle(e){for(let t in e)if(e.hasOwnProperty(t)&&!ZA(e[t]))return!1;return!0}function Ej(e,t){if(pj(t)&&Object.prototype.hasOwnProperty.call(e,t))return delete e[t],e;let n=Array.isArray(t)?t:XA(t)?[t]:$A(t),r=n.length===1?e:Yle(e,n),i=n.length-1,a=n[i];return r&&delete r[a],i!==0&&(WA(r)&&bj(r)||Array.isArray(r)&&Xle(r))&&Ej(e,n.slice(0,-1)),e}var Zle=e=>{for(let t in e)if(nj(e[t]))return!0;return!1};function Dj(e){return Array.isArray(e)||WA(e)&&!Zle(e)}function Oj(e,t={}){for(let n in e){let r=e[n];Dj(r)?(t[n]=Array.isArray(r)?[]:{},Oj(r,t[n])):ZA(r)||(t[n]=!0)}return t}function kj(e,t,n){n||=Oj(t);for(let r in e){let i=e[r];if(Dj(i))ZA(t)||hj(n[r])?n[r]=Oj(i,Array.isArray(i)?[]:{}):kj(i,HA(t)?{}:t[r],n[r]);else{let e=t[r];n[r]=!gj(i,e)}}return n}var Aj={value:!1,isValid:!1},jj={value:!0,isValid:!0},Mj=e=>{if(Array.isArray(e)){if(e.length>1){let t=e.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!ZA(e[0].attributes.value)?ZA(e[0].value)||e[0].value===``?jj:{value:e[0].value,isValid:!0}:jj:Aj}return Aj},Nj=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>ZA(e)?e:t?e===``?NaN:e&&+e:n&&pj(e)?new Date(e):r?r(e):e,Pj={isValid:!1,value:null},Fj=e=>Array.isArray(e)?e.reduce((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e,Pj):Pj;function Ij(e){let t=e.ref;return xj(t)?t.files:wj(t)?Fj(e.refs).value:Cj(t)?[...t.selectedOptions].map(({value:e})=>e):BA(t)?Mj(e.refs).value:Nj(ZA(t.value)?e.ref.value:t.value,e)}var Qle=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,$le=(e,t,n,r)=>{let i={};for(let n of e){let e=ej(t,n);e&&rj(i,n,e._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Lj=e=>e instanceof RegExp,Rj=e=>ZA(e)?e:Lj(e)?e.source:WA(e)?Lj(e.value)?e.value.source:e.value:e,zj=e=>({isOnSubmit:!e||e===aj.onSubmit,isOnBlur:e===aj.onBlur,isOnChange:e===aj.onChange,isOnAll:e===aj.all,isOnTouch:e===aj.onTouched}),Bj=`AsyncFunction`,eue=e=>!!e&&!!e.validate&&!!(nj(e.validate)&&e.validate.constructor.name===Bj||WA(e.validate)&&Object.values(e.validate).find(e=>e.constructor.name===Bj)),tue=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),Vj=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))),Hj=(e,t,n,r)=>{for(let i of n||Object.keys(e)){let n=ej(e,i);if(n){let{_f:e,...a}=n;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],i)&&!r||e.ref&&t(e.ref,e.name)&&!r)return!0;if(Hj(a,t))break}else if(WA(a)&&Hj(a,t))break}}};function Uj(e,t,n){let r=ej(e,n);if(r||XA(n))return{error:r,name:n};let i=n.split(`.`);for(;i.length;){let r=i.join(`.`),a=ej(t,r),o=ej(e,r);if(a&&!Array.isArray(a)&&n!==r)return{name:n};if(o&&o.type)return{name:r,error:o};if(o&&o.root&&o.root.type)return{name:`${r}.root`,error:o.root};i.pop()}return{name:n}}var nue=(e,t,n,r)=>{n(e);let{name:i,...a}=e;return bj(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find(e=>t[e]===(!r||aj.all))},rue=(e,t,n)=>!e||!t||e===t||_j(e).some(e=>e&&(n?e===t:e.startsWith(t)||t.startsWith(e))),iue=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,aue=(e,t)=>!QA(ej(e,t)).length&&Ej(e,t),oue=(e,t,n)=>{let r=_j(ej(e,n));return rj(r,cj,t[n]),rj(e,n,r),e};function Wj(e,t,n=`validate`){if(pj(e)||Array.isArray(e)&&e.every(pj)||tj(e)&&!e)return{type:n,message:pj(e)?e:``,ref:t}}var Gj=e=>WA(e)&&!Lj(e)?e:{value:e,message:``},Kj=async(e,t,n,r,i,a)=>{let{ref:o,refs:s,required:c,maxLength:l,minLength:u,min:d,max:f,pattern:p,validate:m,name:h,valueAsNumber:g,mount:_}=e._f,v=ej(n,h);if(!_||t.has(h))return{};let y=s?s[0]:o,b=e=>{i&&y.reportValidity&&(y.setCustomValidity(tj(e)?``:e||``),y.reportValidity())},x={},S=wj(o),C=BA(o),w=S||C,T=(g||xj(o))&&ZA(o.value)&&ZA(v)||Sj(o)&&o.value===``||v===``||Array.isArray(v)&&!v.length||g&&typeof v==`number`&&isNaN(v),E=qle.bind(null,h,r,x),D=(e,t,n,r=oj.maxLength,i=oj.minLength)=>{let a=e?t:n;x[h]={type:e?r:i,message:a,ref:o,...E(e?r:i,a)}};if(a?!Array.isArray(v)||!v.length:c&&(!w&&(T||HA(v))||tj(v)&&!v||C&&!Mj(s).isValid||S&&!Fj(s).isValid)){let{value:e,message:t}=pj(c)?{value:!!c,message:c}:Gj(c);if(e&&(x[h]={type:oj.required,message:t,ref:y,...E(oj.required,t)},!r))return b(t),x}if(!T&&(!HA(d)||!HA(f))){let e,t,n=Gj(f),i=Gj(d);if(!HA(v)&&!isNaN(v)){let r=o.valueAsNumber||v&&+v;HA(n.value)||(e=r>n.value),HA(i.value)||(t=r<i.value)}else{let r=o.valueAsDate||new Date(v),a=e=>new Date(new Date().toDateString()+` `+e),s=o.type==`time`,c=o.type==`week`;pj(n.value)&&v&&(e=s?a(v)>a(n.value):c?v>n.value:r>new Date(n.value)),pj(i.value)&&v&&(t=s?a(v)<a(i.value):c?v<i.value:r<new Date(i.value))}if((e||t)&&(D(!!e,n.message,i.message,oj.max,oj.min),!r))return b(x[h].message),x}if((l||u)&&!T&&(pj(v)||a&&Array.isArray(v))){let e=Gj(l),t=Gj(u),n=!HA(e.value)&&v.length>+e.value,i=!HA(t.value)&&v.length<+t.value;if((n||i)&&(D(n,e.message,t.message),!r))return b(x[h].message),x}if(p&&!T&&pj(v)){let{value:e,message:t}=Gj(p);if(Lj(e)&&!v.match(e)&&(x[h]={type:oj.pattern,message:t,ref:o,...E(oj.pattern,t)},!r))return b(t),x}if(m){if(nj(m)){let e=Wj(await m(v,n),y);if(e&&(x[h]={...e,...E(oj.validate,e.message)},!r))return b(e.message),x}else if(WA(m)){let e={};for(let t in m){if(!bj(e)&&!r)break;let i=Wj(await m[t](v,n),y,t);i&&(e={...i,...E(t,i.message)},b(i.message),r&&(x[h]=e))}if(!bj(e)&&(x[h]={ref:y,...e},!r))return x}}return b(!0),x},sue={mode:aj.onSubmit,reValidateMode:aj.onChange,shouldFocusError:!0};function cue(e={}){let t={...sue,...e},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:nj(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=(WA(t.defaultValues)||WA(t.values))&&YA(t.defaultValues||t.values)||{},a=t.shouldUnregister?{}:YA(i),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},s={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set,registerName:new Set},c,l=0,u={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={...u},f={...d},p={array:vj(),state:vj()},m=t.criteriaMode===aj.all,h=e=>t=>{clearTimeout(l),l=setTimeout(e,t)},g=async e=>{if(!o.keepIsValid&&!t.disabled&&(d.isValid||f.isValid||e)){let e;t.resolver?(e=bj((await T()).errors),_()):e=await O({fields:r,onlyCheckValid:!0,eventType:ij.VALID}),e!==n.isValid&&p.state.next({isValid:e})}},_=(e,r)=>{!t.disabled&&(d.isValidating||d.validatingFields||f.isValidating||f.validatingFields)&&((e||Array.from(s.mount)).forEach(e=>{e&&(r?rj(n.validatingFields,e,r):Ej(n.validatingFields,e))}),p.state.next({validatingFields:n.validatingFields,isValidating:!bj(n.validatingFields)}))},v=e=>{let t=kj(i,a),r=Qle(e);rj(n.dirtyFields,r,ej(t,r))},y=(e,i=[],s,c,l=!0,u=!0)=>{if(c&&s&&!t.disabled){if(o.action=!0,u&&Array.isArray(ej(r,e))){let t=s(ej(r,e),c.argA,c.argB);l&&rj(r,e,t)}if(u&&Array.isArray(ej(n.errors,e))){let t=s(ej(n.errors,e),c.argA,c.argB);l&&rj(n.errors,e,t),aue(n.errors,e)}if((d.touchedFields||f.touchedFields)&&u&&Array.isArray(ej(n.touchedFields,e))){let t=s(ej(n.touchedFields,e),c.argA,c.argB);l&&rj(n.touchedFields,e,t)}(d.dirtyFields||f.dirtyFields)&&v(e),p.state.next({name:e,isDirty:A(e,i),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else rj(a,e,i)},b=(e,t)=>{rj(n.errors,e,t),p.state.next({errors:n.errors})},x=e=>{n.errors=e,p.state.next({errors:n.errors,isValid:!1})},S=(e,t,n,s)=>{let c=ej(r,e);if(c){let r=ej(a,e,ZA(n)?ej(i,e):n);ZA(r)||s&&s.defaultChecked||t?rj(a,e,t?r:Ij(c._f)):N(e,r),o.mount&&!o.action&&g()}},C=(e,r,a,o,s)=>{let c=!1,l=!1,u={name:e};if(!t.disabled){if(!a||o){(d.isDirty||f.isDirty)&&(l=n.isDirty,n.isDirty=u.isDirty=A(),c=l!==u.isDirty);let t=gj(ej(i,e),r);l=!!ej(n.dirtyFields,e),t?Ej(n.dirtyFields,e):rj(n.dirtyFields,e,!0),u.dirtyFields=n.dirtyFields,c||=(d.dirtyFields||f.dirtyFields)&&l!==!t}if(a){let t=ej(n.touchedFields,e);t||(rj(n.touchedFields,e,a),u.touchedFields=n.touchedFields,c||=(d.touchedFields||f.touchedFields)&&t!==a)}c&&s&&p.state.next(u)}return c?u:{}},w=(e,r,i,a)=>{let o=ej(n.errors,e),s=(d.isValid||f.isValid)&&tj(r)&&n.isValid!==r;if(t.delayError&&i?(c=h(()=>b(e,i)),c(t.delayError)):(clearTimeout(l),c=null,i?rj(n.errors,e,i):Ej(n.errors,e)),(i?!gj(o,i):o)||!bj(a)||s){let t={...a,...s&&tj(r)?{isValid:r}:{},errors:n.errors,name:e};n={...n,...t},p.state.next(t)}},T=async e=>(_(e,!0),await t.resolver(a,t.context,$le(e||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation))),E=async e=>{let{errors:t}=await T(e);if(_(e),e)for(let r of e){let e=ej(t,r);e?rj(n.errors,r,e):Ej(n.errors,r)}else n.errors=t;return t},D=async({name:t,eventType:r})=>{if(e.validate){let i=await e.validate({formValues:a,formState:n,name:t,eventType:r});if(WA(i))for(let e in i)i[e]&&ae(`${sj}.${e}`,{message:pj(i.message)?i.message:``,type:oj.validate});else pj(i)||!i?ae(sj,{message:i||``,type:oj.validate}):ie(sj);return i}return!0},O=async({fields:r,onlyCheckValid:i,name:o,eventType:c,context:l={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(l.runRootValidation=!0,!await D({name:o,eventType:c})&&(l.valid=!1,i)))return l.valid;for(let o in r){let u=r[o];if(u){let{_f:r,...f}=u;if(r){let o=s.array.has(r.name),c=u._f&&eue(u._f);c&&d.validatingFields&&_([r.name],!0);let f=await Kj(u,s.disabled,a,m,t.shouldUseNativeValidation&&!i,o);if(c&&d.validatingFields&&_([r.name]),f[r.name]&&(l.valid=!1,i)||(!i&&(ej(f,r.name)?o?oue(n.errors,f,r.name):rj(n.errors,r.name,f[r.name]):Ej(n.errors,r.name)),e.shouldUseNativeValidation&&f[r.name]))break}!bj(f)&&await O({context:l,onlyCheckValid:i,fields:f,name:o,eventType:c})}}return l.valid},k=()=>{for(let e of s.unMount){let t=ej(r,e);t&&(t._f.refs?t._f.refs.every(e=>!Tj(e)):!Tj(t._f.ref))&&le(e)}s.unMount=new Set},A=(e,n)=>!t.disabled&&(e&&n&&rj(a,e,n),!gj(L(),i)),j=(e,t,n)=>mj(e,s,{...o.mount?a:ZA(t)?i:pj(e)?{[e]:t}:t},n,t),M=e=>QA(ej(o.mount?a:i,e,t.shouldUnregister?ej(i,e,[]):[])),N=(e,t,n={})=>{let i=ej(r,e),o=t;if(i){let n=i._f;n&&(!n.disabled&&rj(a,e,Nj(t,n)),o=Sj(n.ref)&&HA(t)?``:t,Cj(n.ref)?[...n.ref.options].forEach(e=>e.selected=o.includes(e.value)):n.refs?BA(n.ref)?n.refs.forEach(e=>{(!e.defaultChecked||!e.disabled)&&(Array.isArray(o)?e.checked=!!o.find(t=>t===e.value):e.checked=o===e.value||!!o)}):n.refs.forEach(e=>e.checked=e.value===o):xj(n.ref)?n.ref.value=``:(n.ref.value=o,n.ref.type||p.state.next({name:e,values:YA(a)})))}(n.shouldDirty||n.shouldTouch)&&C(e,o,n.shouldTouch,n.shouldDirty,!0),n.shouldValidate&&ne(e)},P=(e,t,n)=>{for(let i in t){if(!t.hasOwnProperty(i))return;let a=t[i],o=e+`.`+i,c=ej(r,o);(s.array.has(e)||WA(a)||c&&!c._f)&&!VA(a)?P(o,a,n):N(o,a,n)}},F=(e,t,i={})=>{let c=ej(r,e),l=s.array.has(e),u=YA(t),d=gj(ej(a,e),u);if(rj(a,e,u),l)p.array.next({name:e,values:YA(a)}),i.shouldDirty&&(v(e),p.state.next({name:e,dirtyFields:n.dirtyFields,isDirty:A(e,u)}));else{let t=Array.isArray(u)&&!u.length||bj(u);!c||c._f||HA(u)||t?N(e,u,i):P(e,u,i)}d||(Vj(e,s)?p.state.next({...n,name:e,values:YA(a)}):p.state.next({name:o.mount?e:void 0,values:YA(a)}))},ee=e=>{let t=nj(e)?e(a):e;gj(a,t)||(a={...a,...t},p.state.next({...n,values:a}))},te=async i=>{o.mount=!0;let l=i.target,u=l.name,h=!0,v=ej(r,u),y=e=>{h=Number.isNaN(e)||VA(e)&&isNaN(e.getTime())||gj(e,ej(a,u,e))},b=zj(t.mode),x=zj(t.reValidateMode);if(v){let o,S,E=l.type?Ij(v._f):GA(i),k=i.type===ij.BLUR||i.type===ij.FOCUS_OUT,A=!tue(v._f)&&!e.validate&&!t.resolver&&!ej(n.errors,u)&&!v._f.deps||iue(k,ej(n.touchedFields,u),n.isSubmitted,x,b),j=Vj(u,s,k);rj(a,u,E),k?(!l||!l.readOnly)&&(v._f.onBlur&&v._f.onBlur(i),c&&c(0)):v._f.onChange&&v._f.onChange(i);let M=C(u,E,k),N=!bj(M)||j;if(!k&&p.state.next({name:u,type:i.type,values:YA(a)}),A)return(d.isValid||f.isValid)&&(t.mode===`onBlur`?k&&g():k||g()),N&&p.state.next({name:u,...j?{}:M});if(!t.resolver&&e.validate&&await D({name:u,eventType:i.type}),!k&&j&&p.state.next({...n}),t.resolver){let{errors:e}=await T([u]);if(_([u]),y(E),h){let t=Uj(n.errors,r,u),i=Uj(e,r,t.name||u);o=i.error,u=i.name,S=bj(e)}}else _([u],!0),o=(await Kj(v,s.disabled,a,m,t.shouldUseNativeValidation))[u],_([u]),y(E),h&&(o?S=!1:(d.isValid||f.isValid)&&(S=await O({fields:r,onlyCheckValid:!0,name:u,eventType:i.type})));h&&(v._f.deps&&(!Array.isArray(v._f.deps)||v._f.deps.length>0)&&ne(v._f.deps),w(u,S,o,M))}},I=(e,t)=>{if(ej(n.errors,t)&&e.focus)return e.focus(),1},ne=async(e,i={})=>{let a,o,c=_j(e);if(t.resolver){let t=await E(ZA(e)?e:c);a=bj(t),o=e?!c.some(e=>ej(t,e)):a}else e?(o=(await Promise.all(c.map(async e=>{let t=ej(r,e);return await O({fields:t&&t._f?{[e]:t}:t,eventType:ij.TRIGGER})}))).every(Boolean),!(!o&&!n.isValid)&&g()):o=a=await O({fields:r,name:e,eventType:ij.TRIGGER});return p.state.next({...!pj(e)||(d.isValid||f.isValid)&&a!==n.isValid?{}:{name:e},...t.resolver||!e?{isValid:a}:{},errors:n.errors}),i.shouldFocus&&!o&&Hj(r,I,e?c:s.mount),o},L=(e,t)=>{let r={...o.mount?a:i};return t&&(r=yj(t.dirtyFields?n.dirtyFields:n.touchedFields,r)),ZA(e)?r:pj(e)?ej(r,e):e.map(e=>ej(r,e))},re=(e,t)=>({invalid:!!ej((t||n).errors,e),isDirty:!!ej((t||n).dirtyFields,e),error:ej((t||n).errors,e),isValidating:!!ej(n.validatingFields,e),isTouched:!!ej((t||n).touchedFields,e)}),ie=e=>{let t=e?_j(e):void 0;t?.forEach(e=>Ej(n.errors,e)),t?t.forEach(e=>{p.state.next({name:e,errors:n.errors})}):p.state.next({errors:{}})},ae=(e,t,i)=>{let a=(ej(r,e,{_f:{}})._f||{}).ref,{ref:o,message:s,type:c,...l}=ej(n.errors,e)||{};rj(n.errors,e,{...l,...t,ref:a}),p.state.next({name:e,errors:n.errors,isValid:!1}),i&&i.shouldFocus&&a&&a.focus&&a.focus()},oe=(e,t)=>nj(e)?p.state.subscribe({next:n=>`values`in n&&e(n.values||j(void 0,t),n)}):j(e,t,!0),se=e=>p.state.subscribe({next:t=>{if(rue(e.name,t.name,e.exact)&&nue(t,e.formState||d,ye,e.reRenderRoot)){let r={...a};e.callback({values:r,...n,...t,defaultValues:i})}}}).unsubscribe,ce=e=>(o.mount=!0,f={...f,...e.formState},se({...e,formState:{...u,...e.formState}})),le=(e,o={})=>{for(let c of e?_j(e):s.mount)s.mount.delete(c),s.array.delete(c),o.keepValue||(Ej(r,c),Ej(a,c)),!o.keepError&&Ej(n.errors,c),!o.keepDirty&&Ej(n.dirtyFields,c),!o.keepTouched&&Ej(n.touchedFields,c),!o.keepIsValidating&&Ej(n.validatingFields,c),!t.shouldUnregister&&!o.keepDefaultValue&&Ej(i,c);p.state.next({values:YA(a)}),p.state.next({...n,...o.keepDirty?{isDirty:A()}:{}}),!o.keepIsValid&&g()},ue=({disabled:e,name:t})=>{if(tj(e)&&o.mount||e||s.disabled.has(t)){let n=s.disabled.has(t)!==!!e;e?s.disabled.add(t):s.disabled.delete(t),n&&o.mount&&!o.action&&g()}},de=(e,n={})=>{let a=ej(r,e),c=tj(n.disabled)||tj(t.disabled),l=!s.registerName.has(e)&&a&&a._f&&!a._f.mount;return rj(r,e,{...a||{},_f:{...a&&a._f?a._f:{ref:{name:e}},name:e,mount:!0,...n}}),s.mount.add(e),a&&!l?ue({disabled:tj(n.disabled)?n.disabled:t.disabled,name:e}):S(e,!0,n.value),{...c?{disabled:n.disabled||t.disabled}:{},...t.progressive?{required:!!n.required,min:Rj(n.min),max:Rj(n.max),minLength:Rj(n.minLength),maxLength:Rj(n.maxLength),pattern:Rj(n.pattern)}:{},name:e,onChange:te,onBlur:te,ref:c=>{if(c){s.registerName.add(e),de(e,n),s.registerName.delete(e),a=ej(r,e);let t=ZA(c.value)&&c.querySelectorAll&&c.querySelectorAll(`input,select,textarea`)[0]||c,o=Jle(t),l=a._f.refs||[];if(o?l.find(e=>e===t):t===a._f.ref)return;rj(r,e,{_f:{...a._f,...o?{refs:[...l.filter(Tj),t,...Array.isArray(ej(i,e))?[{}]:[]],ref:{type:t.type,name:e}}:{ref:t}}}),S(e,!1,void 0,t)}else a=ej(r,e,{}),a._f&&(a._f.mount=!1),(t.shouldUnregister||n.shouldUnregister)&&!(KA(s.array,e)&&o.action)&&s.unMount.add(e)}}},fe=()=>t.shouldFocusError&&Hj(r,I,s.mount),pe=e=>{tj(e)&&(p.state.next({disabled:e}),Hj(r,(t,n)=>{let i=ej(r,n);i&&(t.disabled=i._f.disabled||e,Array.isArray(i._f.refs)&&i._f.refs.forEach(t=>{t.disabled=i._f.disabled||e}))},0,!1))},me=(e,i)=>async o=>{let c;o&&(o.preventDefault&&o.preventDefault(),o.persist&&o.persist());let l=YA(a);if(p.state.next({isSubmitting:!0}),t.resolver){let{errors:e,values:t}=await T();_(),n.errors=e,l=YA(t)}else await O({fields:r,eventType:ij.SUBMIT});if(s.disabled.size)for(let e of s.disabled)Ej(l,e);if(Ej(n.errors,cj),bj(n.errors)){p.state.next({errors:{}});try{await e(l,o)}catch(e){c=e}}else i&&await i({...n.errors},o),fe(),setTimeout(fe);if(p.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bj(n.errors)&&!c,submitCount:n.submitCount+1,errors:n.errors}),c)throw c},he=(e,t={})=>{ej(r,e)&&(ZA(t.defaultValue)?F(e,YA(ej(i,e))):(F(e,t.defaultValue),rj(i,e,YA(t.defaultValue))),t.keepTouched||Ej(n.touchedFields,e),t.keepDirty||(Ej(n.dirtyFields,e),n.isDirty=t.defaultValue?A(e,YA(ej(i,e))):A()),t.keepError||(Ej(n.errors,e),d.isValid&&g()),p.state.next({...n}))},ge=(e,c={})=>{let l=e?YA(e):i,u=YA(l),f=bj(e),m=f?i:u;if(c.keepDefaultValues||(i=l),!c.keepValues){if(c.keepDirtyValues){let e=new Set([...s.mount,...Object.keys(kj(i,a))]);for(let t of Array.from(e)){let e=ej(n.dirtyFields,t),r=ej(a,t),i=ej(m,t);e&&!ZA(r)?rj(m,t,r):!e&&!ZA(i)&&F(t,i)}}else{if(JA&&ZA(e))for(let e of s.mount){let t=ej(r,e);if(t&&t._f){let e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Sj(e)){let t=e.closest(`form`);if(t){t.reset();break}}}}if(c.keepFieldsRef)for(let e of s.mount)F(e,ej(m,e));else r={}}a=t.shouldUnregister?c.keepDefaultValues?YA(i):{}:YA(m),p.array.next({values:{...m}}),p.state.next({values:{...m}})}s={mount:c.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,registerName:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:``},o.mount=!d.isValid||!!c.keepIsValid||!!c.keepDirtyValues||!t.shouldUnregister&&!bj(m),o.watch=!!t.shouldUnregister,o.keepIsValid=!!c.keepIsValid,o.action=!1,c.keepErrors||(n.errors={}),p.state.next({submitCount:c.keepSubmitCount?n.submitCount:0,isDirty:f?!1:c.keepDirty?n.isDirty:!!(c.keepDefaultValues&&!gj(e,i)),isSubmitted:c.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:f?{}:c.keepDirtyValues?c.keepDefaultValues&&a?kj(i,a):n.dirtyFields:c.keepDefaultValues&&e?kj(i,e):c.keepDirty?n.dirtyFields:{},touchedFields:c.keepTouched?n.touchedFields:{},errors:c.keepErrors?n.errors:{},isSubmitSuccessful:c.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:i})},_e=(e,n)=>ge(nj(e)?e(a):e,{...t.resetOptions,...n}),ve=(e,t={})=>{let n=ej(r,e),i=n&&n._f;if(i){let e=i.refs?i.refs[0]:i.ref;e.focus&&setTimeout(()=>{e.focus(),t.shouldSelect&&nj(e.select)&&e.select()})}},ye=e=>{n={...n,...e}},be={control:{register:de,unregister:le,getFieldState:re,handleSubmit:me,setError:ae,_subscribe:se,_runSchema:T,_updateIsValidating:_,_focusError:fe,_getWatch:j,_getDirty:A,_setValid:g,_setFieldArray:y,_setDisabledField:ue,_setErrors:x,_getFieldArray:M,_reset:ge,_resetDefaultValues:()=>nj(t.defaultValues)&&t.defaultValues().then(e=>{_e(e,t.resetOptions),p.state.next({isLoading:!1})}),_removeUnmounted:k,_disableForm:pe,_subjects:p,_proxyFormState:d,get _fields(){return r},get _formValues(){return a},get _state(){return o},set _state(e){o=e},get _defaultValues(){return i},get _names(){return s},set _names(e){s=e},get _formState(){return n},get _options(){return t},set _options(e){t={...t,...e}}},subscribe:ce,trigger:ne,register:de,handleSubmit:me,watch:oe,setValue:F,setValues:ee,getValues:L,reset:_e,resetField:he,clearErrors:ie,unregister:le,setError:ae,setFocus:ve,getFieldState:re};return{...be,formControl:be}}function lue(e={}){let t=R.useRef(void 0),n=R.useRef(void 0),[r,i]=R.useState({isDirty:!1,isValidating:!1,isLoading:nj(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:nj(e.defaultValues)?void 0:e.defaultValues});if(!t.current)if(e.formControl)t.current={...e.formControl,formState:r},e.defaultValues&&!nj(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{let{formControl:n,...i}=cue(e);t.current={...i,formState:r}}let a=t.current.control;return a._options=e,fj(()=>{let e=a._subscribe({formState:a._proxyFormState,callback:()=>i({...a._formState}),reRenderRoot:!0});return i(e=>({...e,isReady:!0})),a._formState.isReady=!0,e},[a]),R.useEffect(()=>a._disableForm(e.disabled),[a,e.disabled]),R.useEffect(()=>{e.mode&&(a._options.mode=e.mode),e.reValidateMode&&(a._options.reValidateMode=e.reValidateMode)},[a,e.mode,e.reValidateMode]),R.useEffect(()=>{e.errors&&(a._setErrors(e.errors),a._focusError())},[a,e.errors]),R.useEffect(()=>{e.shouldUnregister&&a._subjects.state.next({values:a._getWatch()})},[a,e.shouldUnregister]),R.useEffect(()=>{if(a._proxyFormState.isDirty){let e=a._getDirty();e!==r.isDirty&&a._subjects.state.next({isDirty:e})}},[a,r.isDirty]),R.useEffect(()=>{e.values&&!gj(e.values,n.current)?(a._reset(e.values,{keepFieldsRef:!0,...a._options.resetOptions}),a._options.resetOptions?.keepIsValid||a._setValid(),n.current=e.values,i(e=>({...e}))):a._resetDefaultValues()},[a,e.values]),R.useEffect(()=>{a._state.mount||(a._setValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),t.current.formState=R.useMemo(()=>dj(r,a),[a,r]),t.current}function qj(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function q(){return q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},q.apply(null,arguments)}var uue=n(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),due=n(((e,t)=>{var n=uue();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),fue=n(((e,t)=>{t.exports=due()()})),pue=n((e=>{if(typeof Symbol==`function`&&Symbol.for){var t=Symbol.for;t(`react.element`),t(`react.portal`),t(`react.fragment`),t(`react.strict_mode`),t(`react.profiler`),t(`react.provider`),t(`react.context`),t(`react.forward_ref`),t(`react.suspense`),t(`react.suspense_list`),t(`react.memo`),t(`react.lazy`),t(`react.block`),t(`react.server.block`),t(`react.fundamental`),t(`react.debug_trace_mode`),t(`react.legacy_hidden`)}})),mue=n(((e,t)=>{t.exports=pue()})),Jj=e=>typeof e==`object`&&!!e&&e.nodeType===1,Yj=(e,t)=>(!t||e!==`hidden`)&&e!==`visible`&&e!==`clip`,Xj=(e,t)=>{if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){let n=getComputedStyle(e,null);return Yj(n.overflowY,t)||Yj(n.overflowX,t)||(e=>{let t=(e=>{if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch{return null}})(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)})(e)}return!1},Zj=(e,t,n,r,i,a,o,s)=>a<e&&o>t||a>e&&o<t?0:a<=e&&s<=n||o>=t&&s>=n?a-e-r:o>t&&s<n||a<e&&s>n?o-t+i:0,hue=e=>e.parentElement??(e.getRootNode().host||null),gue=(e,t)=>{if(typeof document>`u`)return[];let{scrollMode:n,block:r,inline:i,boundary:a,skipOverflowHiddenElements:o}=t,s=typeof a==`function`?a:e=>e!==a;if(!Jj(e))throw TypeError(`Invalid target`);let c=document.scrollingElement||document.documentElement,l=[],u=e;for(;Jj(u)&&s(u);){if(u=hue(u),u===c){l.push(u);break}u!=null&&u===document.body&&Xj(u)&&!Xj(document.documentElement)||u!=null&&Xj(u,o)&&l.push(u)}let d=window.visualViewport?.width??innerWidth,f=window.visualViewport?.height??innerHeight,p=window.scrollX??pageXOffset,m=window.scrollY??pageYOffset,{height:h,width:g,top:_,right:v,bottom:y,left:b}=e.getBoundingClientRect(),x=r===`start`||r===`nearest`?_:r===`end`?y:_+h/2,S=i===`center`?b+g/2:i===`end`?v:b,C=[];for(let e=0;e<l.length;e++){let t=l[e],{height:a,width:o,top:s,right:u,bottom:w,left:T}=t.getBoundingClientRect();if(n===`if-needed`&&_>=0&&b>=0&&y<=f&&v<=d&&_>=s&&y<=w&&b>=T&&v<=u)return C;let E=getComputedStyle(t),D=parseInt(E.borderLeftWidth,10),O=parseInt(E.borderTopWidth,10),k=parseInt(E.borderRightWidth,10),A=parseInt(E.borderBottomWidth,10),j=0,M=0,N=`offsetWidth`in t?t.offsetWidth-t.clientWidth-D-k:0,P=`offsetHeight`in t?t.offsetHeight-t.clientHeight-O-A:0,F=`offsetWidth`in t?t.offsetWidth===0?0:o/t.offsetWidth:0,ee=`offsetHeight`in t?t.offsetHeight===0?0:a/t.offsetHeight:0;if(c===t)j=r===`start`?x:r===`end`?x-f:r===`nearest`?Zj(m,m+f,f,O,A,m+x,m+x+h,h):x-f/2,M=i===`start`?S:i===`center`?S-d/2:i===`end`?S-d:Zj(p,p+d,d,D,k,p+S,p+S+g,g),j=Math.max(0,j+m),M=Math.max(0,M+p);else{j=r===`start`?x-s-O:r===`end`?x-w+A+P:r===`nearest`?Zj(s,w,a,O,A+P,x,x+h,h):x-(s+a/2)+P/2,M=i===`start`?S-T-D:i===`center`?S-(T+o/2)+N/2:i===`end`?S-u+k+N:Zj(T,u,o,D,k+N,S,S+g,g);let{scrollLeft:e,scrollTop:n}=t;j=Math.max(0,Math.min(n+j/ee,t.scrollHeight-a/ee+P)),M=Math.max(0,Math.min(e+M/F,t.scrollWidth-o/F+N)),x+=n-j,S+=e-M}C.push({el:t,top:j,left:M})}return C},J=t(fue());mue();var _ue=0;function Qj(){}function vue(e,t){e&&gue(e,{boundary:t,block:`nearest`,scrollMode:`if-needed`}).forEach(function(e){var t=e.el,n=e.top,r=e.left;t.scrollTop=n,t.scrollLeft=r})}function $j(e,t,n){return e===t||t instanceof n.Node&&e.contains&&e.contains(t)}function eM(e,t){var n;function r(){n&&clearTimeout(n)}function i(){var i=[...arguments];r(),n=setTimeout(function(){n=null,e.apply(void 0,i)},t)}return i.cancel=r,i}function tM(){var e=[...arguments];return function(t){var n=[...arguments].slice(1);return e.some(function(e){return e&&e.apply(void 0,[t].concat(n)),t.preventDownshiftDefault||t.hasOwnProperty(`nativeEvent`)&&t.nativeEvent.preventDownshiftDefault})}}function nM(){var e=[...arguments];return function(t){e.forEach(function(e){typeof e==`function`?e(t):e&&(e.current=t)})}}function yue(){return String(_ue++)}function bue(e){var t=e.isOpen,n=e.resultCount,r=e.previousResultCount;return t?n?n===r?``:n+` result`+(n===1?` is`:`s are`)+` available, use up and down arrow keys to navigate. Press Enter key to select.`:`No results are available.`:``}function rM(e,t){return Object.keys(e).reduce(function(n,r){return n[r]=iM(t,r)?t[r]:e[r],n},{})}function iM(e,t){return e[t]!==void 0}function aM(e){var t=e.key,n=e.keyCode;return n>=37&&n<=40&&t.indexOf(`Arrow`)!==0?`Arrow`+t:t}function oM(e,t,n,r,i){if(i===void 0&&(i=!0),n===0)return-1;var a=n-1;(typeof t!=`number`||t<0||t>=n)&&(t=e>0?-1:a+1);var o=t+e;o<0?o=i?a:0:o>a&&(o=i?0:a);var s=sM(e,o,n,r,i);return s===-1?t>=n?-1:t:s}function sM(e,t,n,r,i){var a=r(t);if(!a||!a.hasAttribute(`disabled`))return t;if(e>0){for(var o=t+1;o<n;o++)if(!r(o).hasAttribute(`disabled`))return o}else for(var s=t-1;s>=0;s--)if(!r(s).hasAttribute(`disabled`))return s;return i?e>0?sM(1,0,n,r,!1):sM(-1,n-1,n,r,!1):-1}function cM(e,t,n,r){return r===void 0&&(r=!0),t.some(function(t){return t&&($j(t,e,n)||r&&$j(t,n.document.activeElement,n))})}var xue=eM(function(e){uM(e).textContent=``},500);function lM(e,t){var n=uM(t);e&&(n.textContent=e,xue(t))}function uM(e){e===void 0&&(e=document);var t=e.getElementById(`a11y-status-message`);return t||(t=e.createElement(`div`),t.setAttribute(`id`,`a11y-status-message`),t.setAttribute(`role`,`status`),t.setAttribute(`aria-live`,`polite`),t.setAttribute(`aria-relevant`,`additions text`),Object.assign(t.style,{border:`0`,clip:`rect(0 0 0 0)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:`0`,position:`absolute`,width:`1px`}),e.body.appendChild(t),t)}var Sue=[`isInitialMount`,`highlightedIndex`,`items`,`environment`],dM={highlightedIndex:-1,isOpen:!1,selectedItem:null,inputValue:``};function Cue(e,t,n){var r=e.props,i=e.type,a={};Object.keys(t).forEach(function(r){wue(r,e,t,n),n[r]!==t[r]&&(a[r]=n[r])}),r.onStateChange&&Object.keys(a).length&&r.onStateChange(q({type:i},a))}function wue(e,t,n,r){var i=t.props,a=t.type,o=`on`+mM(e)+`Change`;i[o]&&r[e]!==void 0&&r[e]!==n[e]&&i[o](q({type:a},r))}function Tue(e,t){return t.changes}function Eue(e){var t=e.selectedItem,n=e.itemToString;return t?n(t)+` has been selected.`:``}var Due=eM(function(e,t){lM(e(),t)},200),Oue=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0?R.useLayoutEffect:R.useEffect;function fM(e){var t=e.id,n=t===void 0?`downshift-`+yue():t,r=e.labelId,i=e.menuId,a=e.getItemId,o=e.toggleButtonId,s=e.inputId;return(0,R.useRef)({labelId:r||n+`-label`,menuId:i||n+`-menu`,getItemId:a||function(e){return n+`-item-`+e},toggleButtonId:o||n+`-toggle-button`,inputId:s||n+`-input`}).current}function pM(e,t,n,r){var i,a;if(e===void 0){if(t===void 0)throw Error(r);i=n[t],a=t}else a=t===void 0?n.indexOf(e):t,i=e;return[i,a]}function kue(e){return e?String(e):``}function Aue(e){return/^\S{1}$/.test(e)}function mM(e){return``+e.slice(0,1).toUpperCase()+e.slice(1)}function hM(e){var t=(0,R.useRef)(e);return t.current=e,t}function gM(e,t,n){var r=(0,R.useRef)(),i=(0,R.useRef)(),a=(0,R.useReducer)((0,R.useCallback)(function(t,n){i.current=n,t=rM(t,n.props);var r=e(t,n);return n.props.stateReducer(t,q({},n,{changes:r}))},[e]),t),o=a[0],s=a[1],c=hM(n),l=(0,R.useCallback)(function(e){return s(q({props:c.current},e))},[c]),u=i.current;return(0,R.useEffect)(function(){u&&r.current&&r.current!==o&&Cue(u,rM(r.current,u.props),o),r.current=o},[o,n,u]),[o,l]}function _M(e,t,n){var r=gM(e,t,n),i=r[0],a=r[1];return[rM(i,n),a]}var vM={itemToString:kue,stateReducer:Tue,getA11ySelectionMessage:Eue,scrollIntoView:vue,environment:typeof window>`u`?{}:window};function yM(e,t,n){n===void 0&&(n=dM);var r=e[`default`+mM(t)];return r===void 0?n[t]:r}function bM(e,t,n){n===void 0&&(n=dM);var r=e[t];if(r!==void 0)return r;var i=e[`initial`+mM(t)];return i===void 0?yM(e,t,n):i}function xM(e){var t=bM(e,`selectedItem`),n=bM(e,`isOpen`),r=bM(e,`highlightedIndex`),i=bM(e,`inputValue`);return{highlightedIndex:r<0&&t&&n?e.items.indexOf(t):r,isOpen:n,selectedItem:t,inputValue:i}}function SM(e,t,n){var r=e.items,i=e.initialHighlightedIndex,a=e.defaultHighlightedIndex,o=t.selectedItem,s=t.highlightedIndex;return r.length===0?-1:i!==void 0&&s===i?i:a===void 0?o?r.indexOf(o):n===0?-1:n<0?r.length-1:0:a}function CM(e,t,n,r){var i=(0,R.useRef)({isMouseDown:!1,isTouchMove:!1});return(0,R.useEffect)(function(){if(n?.addEventListener!=null){var a=function(){i.current.isMouseDown=!0},o=function(a){i.current.isMouseDown=!1,e&&!cM(a.target,t.map(function(e){return e.current}),n)&&r()},s=function(){i.current.isTouchMove=!1},c=function(){i.current.isTouchMove=!0},l=function(a){e&&!i.current.isTouchMove&&!cM(a.target,t.map(function(e){return e.current}),n,!1)&&r()};return n.addEventListener(`mousedown`,a),n.addEventListener(`mouseup`,o),n.addEventListener(`touchstart`,s),n.addEventListener(`touchmove`,c),n.addEventListener(`touchend`,l),function(){n.removeEventListener(`mousedown`,a),n.removeEventListener(`mouseup`,o),n.removeEventListener(`touchstart`,s),n.removeEventListener(`touchmove`,c),n.removeEventListener(`touchend`,l)}}},[e,n]),i}var wM=function(){return Qj};function TM(e,t,n){var r=n.isInitialMount,i=n.highlightedIndex,a=n.items,o=n.environment,s=qj(n,Sue);(0,R.useEffect)(function(){r||Due(function(){return e(q({highlightedIndex:i,highlightedItem:a[i],resultCount:a.length},s))},o.document)},t)}function EM(e){var t=e.highlightedIndex,n=e.isOpen,r=e.itemRefs,i=e.getItemNodeFromIndex,a=e.menuElement,o=e.scrollIntoView,s=(0,R.useRef)(!0);return Oue(function(){t<0||!n||!Object.keys(r.current).length||(s.current===!1?s.current=!0:o(i(t),a))},[t]),s}var DM=Qj;function OM(e,t,n){return n===void 0&&(n=!0),q({isOpen:!1,highlightedIndex:-1},e.items?.length&&t>=0&&q({selectedItem:e.items[t],isOpen:yM(e,`isOpen`),highlightedIndex:yM(e,`highlightedIndex`)},n&&{inputValue:e.itemToString(e.items[t])}))}function kM(e,t,n){var r=t.type,i=t.props,a;switch(r){case n.ItemMouseMove:a={highlightedIndex:t.disabled?-1:t.index};break;case n.MenuMouseLeave:a={highlightedIndex:-1};break;case n.ToggleButtonClick:case n.FunctionToggleMenu:a={isOpen:!e.isOpen,highlightedIndex:e.isOpen?-1:SM(i,e,0)};break;case n.FunctionOpenMenu:a={isOpen:!0,highlightedIndex:SM(i,e,0)};break;case n.FunctionCloseMenu:a={isOpen:!1};break;case n.FunctionSetHighlightedIndex:a={highlightedIndex:t.highlightedIndex};break;case n.FunctionSetInputValue:a={inputValue:t.inputValue};break;case n.FunctionReset:a={highlightedIndex:yM(i,`highlightedIndex`),isOpen:yM(i,`isOpen`),selectedItem:yM(i,`selectedItem`),inputValue:yM(i,`inputValue`)};break;default:throw Error(`Reducer called without proper action type.`)}return q({},e,a)}function jue(e){for(var t=e.keysSoFar,n=e.highlightedIndex,r=e.items,i=e.itemToString,a=e.getItemNodeFromIndex,o=t.toLowerCase(),s=0;s<r.length;s++){var c=(s+n+ +(t.length<2))%r.length,l=r[c];if(l!==void 0&&i(l).toLowerCase().startsWith(o)&&!a(c)?.hasAttribute(`disabled`))return c}return n}J.default.array.isRequired,J.default.func,J.default.func,J.default.func,J.default.number,J.default.number,J.default.number,J.default.bool,J.default.bool,J.default.bool,J.default.any,J.default.any,J.default.any,J.default.string,J.default.string,J.default.string,J.default.func,J.default.string,J.default.func,J.default.func,J.default.func,J.default.func,J.default.func,J.default.shape({addEventListener:J.default.func,removeEventListener:J.default.func,document:J.default.shape({getElementById:J.default.func,activeElement:J.default.any,body:J.default.any})});function Mue(e){var t=e.isOpen,n=e.resultCount,r=e.previousResultCount;return t?n?n===r?``:`${n} result${n===1?` is`:`s are`} available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.`:`No results are available.`:``}var Nue=qD(qD({},vM),{getA11yStatusMessage:Mue}),Pue=Qj,AM=0,jM=1,MM=2,NM=3,PM=4,FM=5,IM=6,LM=7,RM=8,zM=9,BM=10,VM=11,HM=12,UM=13,WM=14,GM=15,KM=16,qM=17,JM=18,YM=19,XM=20,ZM=21,QM=Object.freeze({__proto__:null,ToggleButtonClick:AM,ToggleButtonKeyDownArrowDown:jM,ToggleButtonKeyDownArrowUp:MM,ToggleButtonKeyDownCharacter:NM,ToggleButtonKeyDownEscape:PM,ToggleButtonKeyDownHome:FM,ToggleButtonKeyDownEnd:IM,ToggleButtonKeyDownEnter:LM,ToggleButtonKeyDownSpaceButton:RM,ToggleButtonKeyDownPageUp:zM,ToggleButtonKeyDownPageDown:BM,ToggleButtonBlur:VM,MenuMouseLeave:HM,ItemMouseMove:UM,ItemClick:WM,FunctionToggleMenu:GM,FunctionOpenMenu:KM,FunctionCloseMenu:qM,FunctionSetHighlightedIndex:JM,FunctionSelectItem:YM,FunctionSetInputValue:XM,FunctionReset:ZM});function Fue(e,t){var n=t.type,r=t.props,i=t.altKey,a;switch(n){case WM:a={isOpen:yM(r,`isOpen`),highlightedIndex:yM(r,`highlightedIndex`),selectedItem:r.items[t.index]};break;case NM:var o=t.key,s=``+e.inputValue+o;a={inputValue:s,highlightedIndex:jue({keysSoFar:s,highlightedIndex:!e.isOpen&&e.selectedItem?r.items.indexOf(e.selectedItem):e.highlightedIndex,items:r.items,itemToString:r.itemToString,getItemNodeFromIndex:t.getItemNodeFromIndex}),isOpen:!0};break;case jM:a={highlightedIndex:e.isOpen?oM(1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1):i&&e.selectedItem==null?-1:SM(r,e,1),isOpen:!0};break;case MM:a=e.isOpen&&i?OM(r,e.highlightedIndex,!1):{highlightedIndex:e.isOpen?oM(-1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1):SM(r,e,-1),isOpen:!0};break;case LM:case RM:a=OM(r,e.highlightedIndex,!1);break;case FM:a={highlightedIndex:sM(1,0,r.items.length,t.getItemNodeFromIndex,!1),isOpen:!0};break;case IM:a={highlightedIndex:sM(-1,r.items.length-1,r.items.length,t.getItemNodeFromIndex,!1),isOpen:!0};break;case zM:a={highlightedIndex:oM(-10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case BM:a={highlightedIndex:oM(10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case PM:a={isOpen:!1,highlightedIndex:-1};break;case VM:a=q({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&r.items?.length&&{selectedItem:r.items[e.highlightedIndex]});break;case YM:a={selectedItem:t.selectedItem};break;default:return kM(e,t,QM)}return q({},e,a)}var Iue=[`onMouseLeave`,`refKey`,`onKeyDown`,`onBlur`,`ref`],Lue=[`onBlur`,`onClick`,`onPress`,`onKeyDown`,`refKey`,`ref`],Rue=[`item`,`index`,`onMouseMove`,`onClick`,`onPress`,`refKey`,`ref`,`disabled`];$M.stateChangeTypes=QM;function $M(e){e===void 0&&(e={}),Pue(e,$M);var t=q({},Nue,e),n=t.items,r=t.scrollIntoView,i=t.environment,a=t.itemToString,o=t.getA11ySelectionMessage,s=t.getA11yStatusMessage,c=_M(Fue,xM(t),t),l=c[0],u=c[1],d=l.isOpen,f=l.highlightedIndex,p=l.selectedItem,m=l.inputValue,h=(0,R.useRef)(null),g=(0,R.useRef)(null),_=(0,R.useRef)({}),v=(0,R.useRef)(null),y=fM(t),b=(0,R.useRef)(),x=(0,R.useRef)(!0),S=hM({state:l,props:t}),C=(0,R.useCallback)(function(e){return _.current[y.getItemId(e)]},[y]);TM(s,[d,f,m,n],q({isInitialMount:x.current,previousResultCount:b.current,items:n,environment:i,itemToString:a},l)),TM(o,[p],q({isInitialMount:x.current,previousResultCount:b.current,items:n,environment:i,itemToString:a},l));var w=EM({menuElement:g.current,highlightedIndex:f,isOpen:d,itemRefs:_,scrollIntoView:r,getItemNodeFromIndex:C});(0,R.useEffect)(function(){return v.current=eM(function(e){e({type:XM,inputValue:``})},500),function(){v.current.cancel()}},[]),(0,R.useEffect)(function(){m&&v.current(u)},[u,m]),DM({isInitialMount:x.current,props:t,state:l}),(0,R.useEffect)(function(){x.current||(b.current=n.length)});var T=CM(d,[g,h],i,function(){u({type:VM})}),E=wM(`getMenuProps`,`getToggleButtonProps`);(0,R.useEffect)(function(){return x.current=!1,function(){x.current=!0}},[]),(0,R.useEffect)(function(){d||(_.current={})},[d]);var D=(0,R.useMemo)(function(){return{ArrowDown:function(e){e.preventDefault(),u({type:jM,getItemNodeFromIndex:C,altKey:e.altKey})},ArrowUp:function(e){e.preventDefault(),u({type:MM,getItemNodeFromIndex:C,altKey:e.altKey})},Home:function(e){e.preventDefault(),u({type:FM,getItemNodeFromIndex:C})},End:function(e){e.preventDefault(),u({type:IM,getItemNodeFromIndex:C})},Escape:function(){S.current.state.isOpen&&u({type:PM})},Enter:function(e){e.preventDefault(),u({type:S.current.state.isOpen?LM:AM})},PageUp:function(e){S.current.state.isOpen&&(e.preventDefault(),u({type:zM,getItemNodeFromIndex:C}))},PageDown:function(e){S.current.state.isOpen&&(e.preventDefault(),u({type:BM,getItemNodeFromIndex:C}))}," ":function(e){e.preventDefault();var t=S.current.state;if(!t.isOpen){u({type:AM});return}t.inputValue?u({type:NM,key:` `,getItemNodeFromIndex:C}):u({type:RM})}}},[u,C,S]),O=(0,R.useCallback)(function(){u({type:GM})},[u]),k=(0,R.useCallback)(function(){u({type:qM})},[u]),A=(0,R.useCallback)(function(){u({type:KM})},[u]),j=(0,R.useCallback)(function(e){u({type:JM,highlightedIndex:e})},[u]),M=(0,R.useCallback)(function(e){u({type:YM,selectedItem:e})},[u]),N=(0,R.useCallback)(function(){u({type:ZM})},[u]),P=(0,R.useCallback)(function(e){u({type:XM,inputValue:e})},[u]),F=(0,R.useCallback)(function(e){return q({id:y.labelId,htmlFor:y.toggleButtonId},e)},[y]),ee=(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onMouseLeave,a=r.refKey,o=a===void 0?`ref`:a;r.onKeyDown,r.onBlur;var s=r.ref,c=qj(r,Iue),l=(t===void 0?{}:t).suppressRefError;return E(`getMenuProps`,l===void 0?!1:l,o,g),q((n={},n[o]=nM(s,function(e){g.current=e}),n.id=y.menuId,n.role=`listbox`,n[`aria-labelledby`]=c&&c[`aria-label`]?void 0:``+y.labelId,n.onMouseLeave=tM(i,function(){u({type:HM})}),n),c)},[u,E,y]);return{getToggleButtonProps:(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onBlur,a=r.onClick;r.onPress;var o=r.onKeyDown,s=r.refKey,c=s===void 0?`ref`:s,l=r.ref,d=qj(r,Lue),f=(t===void 0?{}:t).suppressRefError,p=f===void 0?!1:f,m=S.current.state,g=function(){u({type:AM})},_=function(){m.isOpen&&!T.current.isMouseDown&&u({type:VM})},v=function(e){var t=aM(e);t&&D[t]?D[t](e):Aue(t)&&u({type:NM,key:t,getItemNodeFromIndex:C})},b=q((n={},n[c]=nM(l,function(e){h.current=e}),n[`aria-activedescendant`]=m.isOpen&&m.highlightedIndex>-1?y.getItemId(m.highlightedIndex):``,n[`aria-controls`]=y.menuId,n[`aria-expanded`]=S.current.state.isOpen,n[`aria-haspopup`]=`listbox`,n[`aria-labelledby`]=d&&d[`aria-label`]?void 0:``+y.labelId,n.id=y.toggleButtonId,n.role=`combobox`,n.tabIndex=0,n.onBlur=tM(i,_),n),d);return d.disabled||(b.onClick=tM(a,g),b.onKeyDown=tM(o,v)),E(`getToggleButtonProps`,p,c,h),b},[S,y,E,u,T,D,C]),getLabelProps:F,getMenuProps:ee,getItemProps:(0,R.useCallback)(function(e){var t,n=e===void 0?{}:e,r=n.item,i=n.index,a=n.onMouseMove,o=n.onClick;n.onPress;var s=n.refKey,c=s===void 0?`ref`:s,l=n.ref,d=n.disabled,f=qj(n,Rue),m=S.current,h=m.state,g=m.props,v=pM(r,i,g.items,`Pass either item or index to getItemProps!`),b=v[0],x=v[1],C=function(){x!==h.highlightedIndex&&(w.current=!1,u({type:UM,index:x,disabled:d}))},T=function(){u({type:WM,index:x})},E=q((t={disabled:d,role:`option`,"aria-selected":``+(b===p),id:y.getItemId(x)},t[c]=nM(l,function(e){e&&(_.current[y.getItemId(x)]=e)}),t),f);return d||(E.onClick=tM(o,T)),E.onMouseMove=tM(a,C),E},[S,p,y,w,u]),toggleMenu:O,openMenu:A,closeMenu:k,setHighlightedIndex:j,selectItem:M,reset:N,setInputValue:P,highlightedIndex:f,isOpen:d,selectedItem:p,inputValue:m}}var eN=0,tN=1,nN=2,rN=3,iN=4,aN=5,oN=6,sN=7,cN=8,lN=9,uN=10,dN=11,fN=12,pN=13,mN=14,hN=15,gN=16,_N=17,vN=18,yN=19,bN=20,xN=21,SN=22,CN=Object.freeze({__proto__:null,InputKeyDownArrowDown:eN,InputKeyDownArrowUp:tN,InputKeyDownEscape:nN,InputKeyDownHome:rN,InputKeyDownEnd:iN,InputKeyDownPageUp:aN,InputKeyDownPageDown:oN,InputKeyDownEnter:sN,InputChange:cN,InputBlur:lN,InputFocus:uN,MenuMouseLeave:dN,ItemMouseMove:fN,ItemClick:pN,ToggleButtonClick:mN,FunctionToggleMenu:hN,FunctionOpenMenu:gN,FunctionCloseMenu:_N,FunctionSetHighlightedIndex:vN,FunctionSelectItem:yN,FunctionSetInputValue:bN,FunctionReset:xN,ControlledPropUpdatedSelectedItem:SN});function zue(e){var t=xM(e),n=t.selectedItem,r=t.inputValue;return r===``&&n&&e.defaultInputValue===void 0&&e.initialInputValue===void 0&&e.inputValue===void 0&&(r=e.itemToString(n)),q({},t,{inputValue:r})}J.default.array.isRequired,J.default.func,J.default.func,J.default.func,J.default.func,J.default.number,J.default.number,J.default.number,J.default.bool,J.default.bool,J.default.bool,J.default.any,J.default.any,J.default.any,J.default.string,J.default.string,J.default.string,J.default.string,J.default.string,J.default.string,J.default.func,J.default.string,J.default.string,J.default.func,J.default.func,J.default.func,J.default.func,J.default.func,J.default.func,J.default.shape({addEventListener:J.default.func,removeEventListener:J.default.func,document:J.default.shape({getElementById:J.default.func,activeElement:J.default.any,body:J.default.any})});function Bue(e,t,n){var r=(0,R.useRef)(),i=gM(e,t,n),a=i[0],o=i[1];return(0,R.useEffect)(function(){iM(n,`selectedItem`)&&(n.selectedItemChanged(r.current,n.selectedItem)&&o({type:SN,inputValue:n.itemToString(n.selectedItem)}),r.current=a.selectedItem===r.current?n.selectedItem:a.selectedItem)},[a.selectedItem,n.selectedItem]),[rM(a,n),o]}var Vue=Qj,Hue=q({},vM,{selectedItemChanged:function(e,t){return e!==t},getA11yStatusMessage:bue});function Uue(e,t){var n=t.type,r=t.props,i=t.altKey,a;switch(n){case pN:a={isOpen:yM(r,`isOpen`),highlightedIndex:yM(r,`highlightedIndex`),selectedItem:r.items[t.index],inputValue:r.itemToString(r.items[t.index])};break;case eN:a=e.isOpen?{highlightedIndex:oM(1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!0)}:{highlightedIndex:i&&e.selectedItem==null?-1:SM(r,e,1,t.getItemNodeFromIndex),isOpen:r.items.length>=0};break;case tN:a=e.isOpen?i?OM(r,e.highlightedIndex):{highlightedIndex:oM(-1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!0)}:{highlightedIndex:SM(r,e,-1,t.getItemNodeFromIndex),isOpen:r.items.length>=0};break;case sN:a=OM(r,e.highlightedIndex);break;case nN:a=q({isOpen:!1,highlightedIndex:-1},!e.isOpen&&{selectedItem:null,inputValue:``});break;case aN:a={highlightedIndex:oM(-10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case oN:a={highlightedIndex:oM(10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case rN:a={highlightedIndex:sM(1,0,r.items.length,t.getItemNodeFromIndex,!1)};break;case iN:a={highlightedIndex:sM(-1,r.items.length-1,r.items.length,t.getItemNodeFromIndex,!1)};break;case lN:a=q({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&r.items?.length&&t.selectItem&&{selectedItem:r.items[e.highlightedIndex],inputValue:r.itemToString(r.items[e.highlightedIndex])});break;case cN:a={isOpen:!0,highlightedIndex:yM(r,`highlightedIndex`),inputValue:t.inputValue};break;case uN:a={isOpen:!0,highlightedIndex:SM(r,e,0)};break;case yN:a={selectedItem:t.selectedItem,inputValue:r.itemToString(t.selectedItem)};break;case SN:a={inputValue:t.inputValue};break;default:return kM(e,t,CN)}return q({},e,a)}var Wue=[`onMouseLeave`,`refKey`,`ref`],Gue=[`item`,`index`,`refKey`,`ref`,`onMouseMove`,`onMouseDown`,`onClick`,`onPress`,`disabled`],Kue=[`onClick`,`onPress`,`refKey`,`ref`],que=[`onKeyDown`,`onChange`,`onInput`,`onFocus`,`onBlur`,`onChangeText`,`refKey`,`ref`];wN.stateChangeTypes=CN;function wN(e){e===void 0&&(e={}),Vue(e,wN);var t=q({},Hue,e),n=t.initialIsOpen,r=t.defaultIsOpen,i=t.items,a=t.scrollIntoView,o=t.environment,s=t.getA11yStatusMessage,c=t.getA11ySelectionMessage,l=t.itemToString,u=Bue(Uue,zue(t),t),d=u[0],f=u[1],p=d.isOpen,m=d.highlightedIndex,h=d.selectedItem,g=d.inputValue,_=(0,R.useRef)(null),v=(0,R.useRef)({}),y=(0,R.useRef)(null),b=(0,R.useRef)(null),x=(0,R.useRef)(!0),S=fM(t),C=(0,R.useRef)(),w=hM({state:d,props:t}),T=(0,R.useCallback)(function(e){return v.current[S.getItemId(e)]},[S]);TM(s,[p,m,g,i],q({isInitialMount:x.current,previousResultCount:C.current,items:i,environment:o,itemToString:l},d)),TM(c,[h],q({isInitialMount:x.current,previousResultCount:C.current,items:i,environment:o,itemToString:l},d));var E=EM({menuElement:_.current,highlightedIndex:m,isOpen:p,itemRefs:v,scrollIntoView:a,getItemNodeFromIndex:T});DM({isInitialMount:x.current,props:t,state:d}),(0,R.useEffect)(function(){(n||r||p)&&y.current&&y.current.focus()},[]),(0,R.useEffect)(function(){x.current||(C.current=i.length)});var D=CM(p,[y,_,b],o,function(){f({type:lN,selectItem:!1})}),O=wM(`getInputProps`,`getMenuProps`);(0,R.useEffect)(function(){return x.current=!1,function(){x.current=!0}},[]),(0,R.useEffect)(function(){if(!p)v.current={};else if(o.document?.activeElement!==y.current){var e;y==null||(e=y.current)==null||e.focus()}},[p,o]);var k=(0,R.useMemo)(function(){return{ArrowDown:function(e){e.preventDefault(),f({type:eN,altKey:e.altKey,getItemNodeFromIndex:T})},ArrowUp:function(e){e.preventDefault(),f({type:tN,altKey:e.altKey,getItemNodeFromIndex:T})},Home:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:rN,getItemNodeFromIndex:T}))},End:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:iN,getItemNodeFromIndex:T}))},Escape:function(e){var t=w.current.state;(t.isOpen||t.inputValue||t.selectedItem||t.highlightedIndex>-1)&&(e.preventDefault(),f({type:nN}))},Enter:function(e){!w.current.state.isOpen||e.which===229||(e.preventDefault(),f({type:sN,getItemNodeFromIndex:T}))},PageUp:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:aN,getItemNodeFromIndex:T}))},PageDown:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:oN,getItemNodeFromIndex:T}))}}},[f,w,T]),A=(0,R.useCallback)(function(e){return q({id:S.labelId,htmlFor:S.inputId},e)},[S]),j=(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onMouseLeave,a=r.refKey,o=a===void 0?`ref`:a,s=r.ref,c=qj(r,Wue),l=(t===void 0?{}:t).suppressRefError;return O(`getMenuProps`,l===void 0?!1:l,o,_),q((n={},n[o]=nM(s,function(e){_.current=e}),n.id=S.menuId,n.role=`listbox`,n[`aria-labelledby`]=c&&c[`aria-label`]?void 0:``+S.labelId,n.onMouseLeave=tM(i,function(){f({type:dN})}),n),c)},[f,O,S]),M=(0,R.useCallback)(function(e){var t,n,r=e===void 0?{}:e,i=r.item,a=r.index,o=r.refKey,s=o===void 0?`ref`:o,c=r.ref,l=r.onMouseMove,u=r.onMouseDown,d=r.onClick;r.onPress;var p=r.disabled,m=qj(r,Gue),h=w.current,g=h.props,_=h.state,y=pM(i,a,g.items,`Pass either item or index to getItemProps!`)[1],b=`onClick`,x=d;return q((t={},t[s]=nM(c,function(e){e&&(v.current[S.getItemId(y)]=e)}),t.disabled=p,t.role=`option`,t[`aria-selected`]=``+(y===_.highlightedIndex),t.id=S.getItemId(y),t),!p&&(n={},n[b]=tM(x,function(){f({type:pN,index:y})}),n),{onMouseMove:tM(l,function(){y!==_.highlightedIndex&&(E.current=!1,f({type:fN,index:y,disabled:p}))}),onMouseDown:tM(u,function(e){return e.preventDefault()})},m)},[f,w,E,S]),N=(0,R.useCallback)(function(e){var t,n=e===void 0?{}:e,r=n.onClick;n.onPress;var i=n.refKey,a=i===void 0?`ref`:i,o=n.ref,s=qj(n,Kue),c=w.current.state;return q((t={},t[a]=nM(o,function(e){b.current=e}),t[`aria-controls`]=S.menuId,t[`aria-expanded`]=c.isOpen,t.id=S.toggleButtonId,t.tabIndex=-1,t),!s.disabled&&q({},{onClick:tM(r,function(){f({type:mN})})}),s)},[f,w,S]),P=(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onKeyDown,a=r.onChange,s=r.onInput,c=r.onFocus,l=r.onBlur;r.onChangeText;var u=r.refKey,d=u===void 0?`ref`:u,p=r.ref,m=qj(r,que),h=(t===void 0?{}:t).suppressRefError;O(`getInputProps`,h===void 0?!1:h,d,y);var g=w.current.state,_=function(e){var t=aM(e);t&&k[t]&&k[t](e)},v=function(e){f({type:cN,inputValue:e.target.value})},b=function(e){g.isOpen&&!D.current.isMouseDown&&f({type:lN,selectItem:!(e.relatedTarget===null&&o.document.activeElement!==o.document.body)})},x=function(){g.isOpen||f({type:uN})},C=`onChange`,T={};if(!m.disabled){var E;T=(E={},E[C]=tM(a,s,v),E.onKeyDown=tM(i,_),E.onBlur=tM(l,b),E.onFocus=tM(c,x),E)}return q((n={},n[d]=nM(p,function(e){y.current=e}),n[`aria-activedescendant`]=g.isOpen&&g.highlightedIndex>-1?S.getItemId(g.highlightedIndex):``,n[`aria-autocomplete`]=`list`,n[`aria-controls`]=S.menuId,n[`aria-expanded`]=g.isOpen,n[`aria-labelledby`]=m&&m[`aria-label`]?void 0:``+S.labelId,n.autoComplete=`off`,n.id=S.inputId,n.role=`combobox`,n.value=g.inputValue,n),T,m)},[O,w,S,k,f,D,o]),F=(0,R.useCallback)(function(){f({type:hN})},[f]),ee=(0,R.useCallback)(function(){f({type:_N})},[f]),te=(0,R.useCallback)(function(){f({type:gN})},[f]),I=(0,R.useCallback)(function(e){f({type:vN,highlightedIndex:e})},[f]),ne=(0,R.useCallback)(function(e){f({type:yN,selectedItem:e})},[f]);return{getItemProps:M,getLabelProps:A,getMenuProps:j,getInputProps:P,getToggleButtonProps:N,toggleMenu:F,openMenu:te,closeMenu:ee,setHighlightedIndex:I,setInputValue:(0,R.useCallback)(function(e){f({type:bN,inputValue:e})},[f]),selectItem:ne,reset:(0,R.useCallback)(function(){f({type:xN})},[f]),highlightedIndex:m,isOpen:p,selectedItem:h,inputValue:g}}var TN={activeIndex:-1,selectedItems:[]};function EN(e,t){return bM(e,t,TN)}function DN(e,t){return yM(e,t,TN)}function Jue(e){return{activeIndex:EN(e,`activeIndex`),selectedItems:EN(e,`selectedItems`)}}function ON(e){if(e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)return!1;var t=e.target;return!(t instanceof HTMLInputElement&&t.value!==``&&(t.selectionStart!==0||t.selectionEnd!==0))}function Yue(e){var t=e.removedSelectedItem,n=e.itemToString;return n(t)+` has been removed.`}J.default.array,J.default.array,J.default.array,J.default.func,J.default.func,J.default.func,J.default.number,J.default.number,J.default.number,J.default.func,J.default.func,J.default.string,J.default.string,J.default.shape({addEventListener:J.default.func,removeEventListener:J.default.func,document:J.default.shape({getElementById:J.default.func,activeElement:J.default.any,body:J.default.any})});var Xue={itemToString:vM.itemToString,stateReducer:vM.stateReducer,environment:vM.environment,getA11yRemovalMessage:Yue,keyNavigationNext:`ArrowRight`,keyNavigationPrevious:`ArrowLeft`},Zue=Qj,kN=0,AN=1,jN=2,MN=3,NN=4,PN=5,FN=6,IN=7,LN=8,RN=9,zN=10,BN=11,VN=12,Que=Object.freeze({__proto__:null,SelectedItemClick:kN,SelectedItemKeyDownDelete:AN,SelectedItemKeyDownBackspace:jN,SelectedItemKeyDownNavigationNext:MN,SelectedItemKeyDownNavigationPrevious:NN,DropdownKeyDownNavigationPrevious:PN,DropdownKeyDownBackspace:FN,DropdownClick:IN,FunctionAddSelectedItem:LN,FunctionRemoveSelectedItem:RN,FunctionSetSelectedItems:zN,FunctionSetActiveIndex:BN,FunctionReset:VN});function $ue(e,t){var n=t.type,r=t.index,i=t.props,a=t.selectedItem,o=e.activeIndex,s=e.selectedItems,c;switch(n){case kN:c={activeIndex:r};break;case NN:c={activeIndex:o-1<0?0:o-1};break;case MN:c={activeIndex:o+1>=s.length?-1:o+1};break;case jN:case AN:if(o<0)break;var l=o;s.length===1?l=-1:o===s.length-1&&(l=s.length-2),c=q({selectedItems:[].concat(s.slice(0,o),s.slice(o+1))},{activeIndex:l});break;case PN:c={activeIndex:s.length-1};break;case FN:c={selectedItems:s.slice(0,s.length-1)};break;case LN:c={selectedItems:[].concat(s,[a])};break;case IN:c={activeIndex:-1};break;case RN:var u=o,d=s.indexOf(a);if(d<0)break;s.length===1?u=-1:d===s.length-1&&(u=s.length-2),c={selectedItems:[].concat(s.slice(0,d),s.slice(d+1)),activeIndex:u};break;case zN:c={selectedItems:t.selectedItems};break;case BN:c={activeIndex:t.activeIndex};break;case VN:c={activeIndex:DN(i,`activeIndex`),selectedItems:DN(i,`selectedItems`)};break;default:throw Error(`Reducer called without proper action type.`)}return q({},e,c)}var ede=[`refKey`,`ref`,`onClick`,`onKeyDown`,`selectedItem`,`index`],tde=[`refKey`,`ref`,`onKeyDown`,`onClick`,`preventKeyAction`];HN.stateChangeTypes=Que;function HN(e){e===void 0&&(e={}),Zue(e,HN);var t=q({},Xue,e),n=t.getA11yRemovalMessage,r=t.itemToString,i=t.environment,a=t.keyNavigationNext,o=t.keyNavigationPrevious,s=_M($ue,Jue(t),t),c=s[0],l=s[1],u=c.activeIndex,d=c.selectedItems,f=(0,R.useRef)(!0),p=(0,R.useRef)(null),m=(0,R.useRef)(d),h=(0,R.useRef)();h.current=[];var g=hM({state:c,props:t});(0,R.useEffect)(function(){if(!f.current){if(d.length<m.current.length){var e=m.current.find(function(e){return d.indexOf(e)<0});lM(n({itemToString:r,resultCount:d.length,removedSelectedItem:e,activeIndex:u,activeSelectedItem:d[u]}),i.document)}m.current=d}},[d.length]),(0,R.useEffect)(function(){f.current||(u===-1&&p.current?p.current.focus():h.current[u]&&h.current[u].focus())},[u]),DM({isInitialMount:f.current,props:t,state:c});var _=wM(`getDropdownProps`);(0,R.useEffect)(function(){return f.current=!1,function(){f.current=!0}},[]);var v=(0,R.useMemo)(function(){var e;return e={},e[o]=function(){l({type:NN})},e[a]=function(){l({type:MN})},e.Delete=function(){l({type:AN})},e.Backspace=function(){l({type:jN})},e},[l,a,o]),y=(0,R.useMemo)(function(){var e;return e={},e[o]=function(e){ON(e)&&l({type:PN})},e.Backspace=function(e){ON(e)&&l({type:FN})},e},[l,o]);return{getSelectedItemProps:(0,R.useCallback)(function(e){var t,n=e===void 0?{}:e,r=n.refKey,i=r===void 0?`ref`:r,a=n.ref,o=n.onClick,s=n.onKeyDown,c=n.selectedItem,u=n.index,d=qj(n,ede),f=g.current.state,p=pM(c,u,f.selectedItems,`Pass either item or index to getSelectedItemProps!`)[1],m=p>-1&&p===f.activeIndex;return q((t={},t[i]=nM(a,function(e){e&&h.current.push(e)}),t.tabIndex=m?0:-1,t.onClick=tM(o,function(){l({type:kN,index:p})}),t.onKeyDown=tM(s,function(e){var t=aM(e);t&&v[t]&&v[t](e)}),t),d)},[l,g,v]),getDropdownProps:(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.refKey,a=i===void 0?`ref`:i,o=r.ref,s=r.onKeyDown,c=r.onClick,u=r.preventKeyAction,d=u===void 0?!1:u,f=qj(r,tde),m=(t===void 0?{}:t).suppressRefError;return _(`getDropdownProps`,m===void 0?!1:m,a,p),q((n={},n[a]=nM(o,function(e){e&&(p.current=e)}),n),!d&&{onKeyDown:tM(s,function(e){var t=aM(e);t&&y[t]&&y[t](e)}),onClick:tM(c,function(){l({type:IN})})},f)},[l,y,_]),addSelectedItem:(0,R.useCallback)(function(e){l({type:LN,selectedItem:e})},[l]),removeSelectedItem:(0,R.useCallback)(function(e){l({type:RN,selectedItem:e})},[l]),setSelectedItems:(0,R.useCallback)(function(e){l({type:zN,selectedItems:e})},[l]),setActiveIndex:(0,R.useCallback)(function(e){l({type:BN,activeIndex:e})},[l]),reset:(0,R.useCallback)(function(){l({type:VN})},[l]),selectedItems:d,activeIndex:u}}var UN=20,nde=e=>e.suggestions.length>0?R.createElement(rde,{...e}):R.createElement(`input`,{className:mw.textInput,size:40,autoFocus:!0,...e.register(e.inputName)}),rde=({autofocus:e,suggestions:t,control:n,inputName:r,placeholder:i,initialInputValue:a,setValue:o})=>{let[s,c]=R.useState(t.slice(0,UN)),l=Vl(NC),u=t.length>0,{isOpen:d,getToggleButtonProps:f,getMenuProps:p,getInputProps:m,highlightedIndex:h,getItemProps:g,selectedItem:_}=wN({initialInputValue:a,onInputValueChange({inputValue:e=``}){o(r,e),e=e.toLowerCase()||``;let n=[];for(let r of t)if(r.toLowerCase().includes(e)&&(n.push(r),n.length>=UN))break;c(n)},items:s,itemToString(e){return e??``}}),v=d&&s.length>0;return R.createElement(`div`,{className:mw.downshiftAutocompleteContainer},R.createElement(`div`,{"data-visible-dropdown":v,className:mw.downshiftInputWrapper},R.createElement(Gle,{name:r,control:n,render:({field:t})=>{let n=m();return R.createElement(`input`,{...n,name:t.name,placeholder:i,className:mw.downshiftInput,size:30,"data-editor-dialog":!0,autoFocus:e})}}),u&&R.createElement(`button`,{"aria-label":`toggle menu`,type:`button`,...f()},l(`arrow_drop_down`))),R.createElement(`div`,{className:mw.downshiftAutocompleteContainer},R.createElement(`ul`,{...p(),"data-visible":v},s.map((e,t)=>R.createElement(`li`,{"data-selected":_===e,"data-highlighted":h===t,key:`${e}${t}`,...g({item:e,index:t})},e)))))};function ide(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}var ade={testNode:`blockquote`,visitNode({actions:e}){e.addAndStepInto(wv())}},ode={testLexicalNode:Tv,visitLexicalNode:({actions:e})=>{e.addAndStepInto(`blockquote`)}},sde=Xl({init(e){e.pubIn({[ew]:`quote`,[yC]:ade,[vC]:Cv,[SC]:ode})}});function WN(){let e=Yl;return{publish:()=>{e()},subscribe:t=>{e=t}}}var cde=Object.defineProperty,lde=(e,t,n)=>t in e?cde(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,GN=(e,t,n)=>(lde(e,typeof t==`symbol`?t:t+``,n),n),KN=class e extends Wm{constructor(e,t,n,r){super(r),GN(this,`__code`),GN(this,`__meta`),GN(this,`__language`),GN(this,`__focusEmitter`,WN()),GN(this,`setCode`,e=>{e!==this.__code&&(this.getWritable().__code=e)}),GN(this,`setMeta`,e=>{e!==this.__meta&&(this.getWritable().__meta=e)}),GN(this,`setLanguage`,e=>{e!==this.__language&&(this.getWritable().__language=e)}),GN(this,`select`,()=>{this.__focusEmitter.publish()}),this.__code=e,this.__meta=n,this.__language=t}static getType(){return`codeblock`}static clone(t){return new e(t.__code,t.__language,t.__meta,t.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__code=e.__code,this.__meta=e.__meta,this.__language=e.__language,this.__focusEmitter=WN()}static importJSON(e){let{code:t,meta:n,language:r}=e;return YN({code:t,language:r,meta:n})}static importDOM(){return{pre:()=>({conversion:pde,priority:3})}}exportJSON(){return{code:this.getCode(),language:this.getLanguage(),meta:this.getMeta(),type:`codeblock`,version:1}}createDOM(e,t){return document.createElement(`div`)}updateDOM(){return!1}getCode(){return this.__code}getMeta(){return this.__meta}getLanguage(){return this.__language}decorate(e){return R.createElement(dde,{parentEditor:e,code:this.getCode(),meta:this.getMeta(),language:this.getLanguage(),codeBlockNode:this,nodeKey:this.getKey(),focusEmitter:this.__focusEmitter})}isInline(){return!1}},qN=R.createContext(null),ude=({parentEditor:e,lexicalNode:t,children:n})=>{let r=R.useMemo(()=>({lexicalNode:t,parentEditor:e,setCode:n=>{e.update(()=>{t.setCode(n),setTimeout(()=>{e.dispatchCommand(zS,void 0)},0)})},setLanguage:n=>{e.update(()=>{t.setLanguage(n)})},setMeta:n=>{e.update(()=>{t.setMeta(n)})}}),[t,e]);return R.createElement(qN.Provider,{value:r},n)};function JN(){let e=R.useContext(qN);if(!e)throw Error(`useCodeBlockEditor must be used within a CodeBlockEditor`);return e}var dde=e=>{let t=Vl(mC),n=Vl(XN),r=t.sort((e,t)=>t.priority-e.priority).find(t=>t.match(e.language||``,e.meta||``));if(r??=t.find(t=>t.match(n||``,e.meta||``)),!r)throw Error(`No CodeBlockEditor registered for language=${e.language} meta=${e.meta}`);let i=r.Editor,{codeBlockNode:a,parentEditor:o,...s}=e;return R.createElement(ude,{parentEditor:e.parentEditor,lexicalNode:e.codeBlockNode},R.createElement(i,{...s}))};function YN(e){let{code:t=``,language:n=``,meta:r=``}=e;return new KN(t,n,r)}function fde(e){return e instanceof KN}function pde(e){let t=e,n=t.textContent,r=e.getAttribute(`class`)??``,i=e.getAttribute(`data-language`)??``,a=/language-(\w+)/.exec(r);return{node:YN({code:n,language:a?a[1]:i,meta:t.getAttribute(`data-meta`)??``})}}var mde={testLexicalNode:fde,visitLexicalNode:({lexicalNode:e,actions:t})=>{t.addAndStepInto(`code`,{value:e.getCode(),lang:e.getLanguage(),meta:e.getMeta()})}},hde={testNode:(e,{codeBlockEditorDescriptors:t})=>e.type===`code`?t.find(t=>t.match(e.lang,e.meta))!==void 0:!1,visitNode({mdastNode:e,actions:t}){t.addAndStepInto(YN({code:e.value,language:e.lang??``,meta:e.meta??``}))}},XN=Il(``),ZN=Ll(e=>{e.link(e.pipe(ZN,Gl(XN),Wl(([e,t])=>()=>YN({language:t,...e}))),XC)}),gde=PC(mC),_de=Xl({update(e,t){e.pub(XN,t?.defaultCodeBlockLanguage??``)},init(e,t){e.pubIn({[ew]:`codeblock`,[mC]:t?.codeBlockEditorDescriptors??[],[yC]:hde,[vC]:KN,[SC]:mde})}}),vde=`modulepreload`,yde=function(e){return`/apps/chat/`+e},QN={},Y=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=yde(t,n),t in QN)return;QN[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:vde,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},$N=class{constructor(e,t,n,r){this.state=e,this.pos=t,this.explicit=n,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ae(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),r=t.text.slice(n-t.from,this.pos-t.from),i=r.search(iP(e,!1));return i<0?null:{from:n+i,to:this.pos,text:r.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e==`abort`&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}};function eP(e){let t=Object.keys(e).join(``),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,``)),`[${n?`\\w`:``}${t.replace(/[^\w\s]/g,`\\$&`)}]`}function bde(e){let t=Object.create(null),n=Object.create(null);for(let{label:r}of e){t[r[0]]=!0;for(let e=1;e<r.length;e++)n[r[e]]=!0}let r=eP(t)+eP(n)+`*$`;return[RegExp(`^`+r),new RegExp(r)]}function tP(e){let t=e.map(e=>typeof e==`string`?{label:e}:e),[n,r]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:bde(t);return e=>{let i=e.matchBefore(r);return i||e.explicit?{from:i?i.from:e.pos,options:t,validFor:n}:null}}function xde(e,t){return n=>{for(let t=ae(n.state).resolveInner(n.pos,-1);t;t=t.parent){if(e.indexOf(t.name)>-1)return null;if(t.type.isTop)break}return t(n)}}var nP=class{constructor(e,t,n,r){this.completion=e,this.source=t,this.match=n,this.score=r}};function rP(e){return e.selection.main.from}function iP(e,t){let{source:n}=e,r=t&&n[0]!=`^`,i=n[n.length-1]!=`$`;return!r&&!i?e:RegExp(`${r?`^`:``}(?:${n})${i?`$`:``}`,e.flags??(e.ignoreCase?`i`:``))}var aP=he.define();function Sde(e,t,n,r){let{main:i}=e.selection,a=n-i.from,o=r-i.from;return{...e.changeByRange(s=>{if(s!=i&&n!=r&&e.sliceDoc(s.from+a,s.from+o)!=e.sliceDoc(n,r))return{range:s};let c=e.toText(t);return{changes:{from:s.from+a,to:r==i.from?s.to:s.from+o,insert:c},range:k.cursor(s.from+a+c.length)}}),scrollIntoView:!0,userEvent:`input.complete`}}var oP=new WeakMap;function Cde(e){if(!Array.isArray(e))return e;let t=oP.get(e);return t||oP.set(e,t=tP(e)),t}var sP=w.define(),cP=w.define(),wde=class{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let n=se(e,t),r=a(n);this.chars.push(n);let i=e.slice(t,t+r),o=i.toUpperCase();this.folded.push(se(o==i?i.toLowerCase():o,0)),t+=r}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:n,any:r,precise:i,byWord:o}=this;if(t.length==1){let r=se(e,0),i=a(r),o=i==e.length?0:-100;if(r!=t[0])if(r==n[0])o+=-200;else return null;return this.ret(o,[0,i])}let s=e.indexOf(this.pattern);if(s==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=t.length,l=0;if(s<0){for(let i=0,o=Math.min(e.length,200);i<o&&l<c;){let o=se(e,i);(o==t[l]||o==n[l])&&(r[l++]=i),i+=a(o)}if(l<c)return null}let u=0,d=0,f=!1,p=0,m=-1,h=-1,g=/[a-z]/.test(e),_=!0;for(let r=0,l=Math.min(e.length,200),v=0;r<l&&d<c;){let l=se(e,r);s<0&&(u<c&&l==t[u]&&(i[u++]=r),p<c&&(l==t[p]||l==n[p]?(p==0&&(m=r),h=r+1,p++):p=0));let b,x=l<255?l>=48&&l<=57||l>=97&&l<=122?2:+(l>=65&&l<=90):(b=y(l))==b.toLowerCase()?b==b.toUpperCase()?0:2:1;(!r||x==1&&g||v==0&&x!=0)&&(t[d]==l||n[d]==l&&(f=!0)?o[d++]=r:o.length&&(_=!1)),v=x,r+=a(l)}return d==c&&o[0]==0&&_?this.result(-100+(f?-200:0),o,e):p==c&&m==0?this.ret(-200-e.length+(h==e.length?0:-100),[0,h]):s>-1?this.ret(-700-e.length,[s,s+this.pattern.length]):p==c?this.ret(-900-e.length,[m,h]):d==c?this.result(-100+(f?-200:0)+-700+(_?0:-1100),o,e):t.length==2?null:this.result((r[0]?-700:0)+-200+-1100,r,e)}result(e,t,n){let r=[],i=0;for(let e of t){let t=e+(this.astral?a(se(n,e)):1);i&&r[i-1]==e?r[i-1]=t:(r[i++]=e,r[i++]=t)}return this.ret(e-n.length,r)}},Tde=class{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),n=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return n==null?null:(this.matched=[0,t.length],this.score=n+(e.length==this.pattern.length?0:-100),this)}},lP=Oe.define({combine(e){return oe(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>``,optionClass:()=>``,aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Ede,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>n=>uP(e(n),t(n)),optionClass:(e,t)=>n=>uP(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function uP(e,t){return e?t?e+` `+t:e:t}function Ede(e,t,n,r,i,a){let o=e.textDirection==u.RTL,s=o,c=!1,l=`top`,d,f,p=t.left-i.left,m=i.right-t.right,h=r.right-r.left,g=r.bottom-r.top;if(s&&p<Math.min(h,m)?s=!1:!s&&m<Math.min(h,p)&&(s=!0),h<=(s?p:m))d=Math.max(i.top,Math.min(n.top,i.bottom-g))-t.top,f=Math.min(400,s?p:m);else{c=!0,f=Math.min(400,(o?t.right:i.right-t.left)-30);let e=i.bottom-t.bottom;e>=g||e>t.top?d=n.bottom-t.top:(l=`bottom`,d=t.bottom-n.top)}let _=(t.bottom-t.top)/a.offsetHeight,v=(t.right-t.left)/a.offsetWidth;return{style:`${l}: ${d/_}px; max-width: ${f/v}px`,class:`cm-completionInfo-`+(c?o?`left-narrow`:`right-narrow`:s?`left`:`right`)}}var dP=w.define();function Dde(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(e){let t=document.createElement(`div`);return t.classList.add(`cm-completionIcon`),e.type&&t.classList.add(...e.type.split(/\s+/g).map(e=>`cm-completionIcon-`+e)),t.setAttribute(`aria-hidden`,`true`),t},position:20}),t.push({render(e,t,n,r){let i=document.createElement(`span`);i.className=`cm-completionLabel`;let a=e.displayLabel||e.label,o=0;for(let e=0;e<r.length;){let t=r[e++],n=r[e++];t>o&&i.appendChild(document.createTextNode(a.slice(o,t)));let s=i.appendChild(document.createElement(`span`));s.appendChild(document.createTextNode(a.slice(t,n))),s.className=`cm-completionMatchedText`,o=n}return o<a.length&&i.appendChild(document.createTextNode(a.slice(o))),i},position:50},{render(e){if(!e.detail)return null;let t=document.createElement(`span`);return t.className=`cm-completionDetail`,t.textContent=e.detail,t},position:80}),t.sort((e,t)=>e.position-t.position).map(e=>e.render)}function fP(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let e=Math.floor(t/n);return{from:e*n,to:(e+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}var Ode=class{constructor(e,t,n){this.view=e,this.stateField=t,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:e=>this.placeInfo(e),key:this},this.space=null,this.currentClass=``;let r=e.state.field(t),{options:i,selected:a}=r.open,o=e.state.facet(lP);this.optionContent=Dde(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=fP(i.length,a,o.maxRenderedOptions),this.dom=document.createElement(`div`),this.dom.className=`cm-tooltip-autocomplete`,this.updateTooltipClass(e.state),this.dom.addEventListener(`mousedown`,n=>{let{options:r}=e.state.field(t).open;for(let t=n.target,i;t&&t!=this.dom;t=t.parentNode)if(t.nodeName==`LI`&&(i=/-(\d+)$/.exec(t.id))&&+i[1]<r.length){this.applyCompletion(e,r[+i[1]]),n.preventDefault();return}if(n.target==this.list){let t=this.list.classList.contains(`cm-completionListIncompleteTop`)&&n.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains(`cm-completionListIncompleteBottom`)&&n.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;t!=null&&(e.dispatch({effects:dP.of(t)}),n.preventDefault())}}),this.dom.addEventListener(`focusout`,t=>{let n=e.state.field(this.stateField,!1);n&&n.tooltip&&e.state.facet(lP).closeOnBlur&&t.relatedTarget!=e.contentDOM&&e.dispatch({effects:cP.of(null)})}),this.showOptions(i,r.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener(`scroll`,()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){let t=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),t!=n){let{options:r,selected:i,disabled:a}=t.open;(!n.open||n.open.options!=r)&&(this.range=fP(r.length,i,e.state.facet(lP).maxRenderedOptions),this.showOptions(r,t.id)),this.updateSel(),a!=n.open?.disabled&&this.dom.classList.toggle(`cm-tooltip-autocomplete-disabled`,!!a)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let e of this.currentClass.split(` `))e&&this.dom.classList.remove(e);for(let e of t.split(` `))e&&this.dom.classList.add(e);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=fP(t.options.length,t.selected,this.view.state.facet(lP).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:r}=t.options[t.selected],{info:i}=r;if(!i)return;let a=typeof i==`string`?document.createTextNode(i):i(r);if(!a)return;`then`in a?a.then(t=>{t&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(t,r)}).catch(e=>me(this.view.state,e,`completion info`)):(this.addInfoPane(a,r),n.setAttribute(`aria-describedby`,this.info.id))}}addInfoPane(e,t){this.destroyInfo();let n=this.info=document.createElement(`div`);if(n.className=`cm-tooltip cm-completionInfo`,n.id=`cm-completionInfo-`+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)n.appendChild(e),this.infoDestroy=null;else{let{dom:t,destroy:r}=e;n.appendChild(t),this.infoDestroy=r||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,r=this.range.from;n;n=n.nextSibling,r++)n.nodeName!=`LI`||!n.id?r--:r==e?n.hasAttribute(`aria-selected`)||(n.setAttribute(`aria-selected`,`true`),t=n):n.hasAttribute(`aria-selected`)&&(n.removeAttribute(`aria-selected`),n.removeAttribute(`aria-describedby`));return t&&Ade(this.list,t),t}measureInfo(){let e=this.dom.querySelector(`[aria-selected]`);if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),r=e.getBoundingClientRect(),i=this.space;if(!i){let e=this.dom.ownerDocument.documentElement;i={left:0,top:0,right:e.clientWidth,bottom:e.clientHeight}}return r.top>Math.min(i.bottom,t.bottom)-10||r.bottom<Math.max(i.top,t.top)+10?null:this.view.state.facet(lP).positionInfo(this.view,t,r,n,i,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className=`cm-tooltip cm-completionInfo `+(e.class||``)):this.info.style.cssText=`top: -1e6px`)}createListBox(e,t,n){let r=document.createElement(`ul`);r.id=t,r.setAttribute(`role`,`listbox`),r.setAttribute(`aria-expanded`,`true`),r.setAttribute(`aria-label`,this.view.state.phrase(`Completions`)),r.addEventListener(`mousedown`,e=>{e.target==r&&e.preventDefault()});let i=null;for(let a=n.from;a<n.to;a++){let{completion:o,match:s}=e[a],{section:c}=o;if(c){let e=typeof c==`string`?c:c.name;if(e!=i&&(a>n.from||n.from==0))if(i=e,typeof c!=`string`&&c.header)r.appendChild(c.header(c));else{let t=r.appendChild(document.createElement(`completion-section`));t.textContent=e}}let l=r.appendChild(document.createElement(`li`));l.id=t+`-`+a,l.setAttribute(`role`,`option`);let u=this.optionClass(o);u&&(l.className=u);for(let e of this.optionContent){let t=e(o,this.view.state,this.view,s);t&&l.appendChild(t)}}return n.from&&r.classList.add(`cm-completionListIncompleteTop`),n.to<e.length&&r.classList.add(`cm-completionListIncompleteBottom`),r}destroyInfo(){this.info&&=(this.infoDestroy&&this.infoDestroy(),this.info.remove(),null)}destroy(){this.destroyInfo()}};function kde(e,t){return n=>new Ode(n,e,t)}function Ade(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/i)}function pP(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+ +!!e.type}function jde(e,t){let n=[],r=null,i=null,a=e=>{n.push(e);let{section:t}=e.completion;if(t){r||=[];let e=typeof t==`string`?t:t.name;r.some(t=>t.name==e)||r.push(typeof t==`string`?{name:e}:t)}},o=t.facet(lP);for(let r of e)if(r.hasResult()){let e=r.result.getMatch;if(r.result.filter===!1)for(let t of r.result.options)a(new nP(t,r.source,e?e(t):[],1e9-n.length));else{let n=t.sliceDoc(r.from,r.to),s,c=o.filterStrict?new Tde(n):new wde(n);for(let t of r.result.options)if(s=c.match(t.label)){let n=t.displayLabel?e?e(t,s.matched):[]:s.matched,o=s.score+(t.boost||0);if(a(new nP(t,r.source,n,o)),typeof t.section==`object`&&t.section.rank===`dynamic`){let{name:e}=t.section;i||=Object.create(null),i[e]=Math.max(o,i[e]||-1e9)}}}}if(r){let e=Object.create(null),t=0,a=(e,t)=>(e.rank===`dynamic`&&t.rank===`dynamic`?i[t.name]-i[e.name]:0)||(typeof e.rank==`number`?e.rank:1e9)-(typeof t.rank==`number`?t.rank:1e9)||(e.name<t.name?-1:1);for(let n of r.sort(a))t-=1e5,e[n.name]=t;for(let t of n){let{section:n}=t.completion;n&&(t.score+=e[typeof n==`string`?n:n.name])}}let s=[],c=null,l=o.compareCompletions;for(let e of n.sort((e,t)=>t.score-e.score||l(e.completion,t.completion))){let t=e.completion;!c||c.label!=t.label||c.detail!=t.detail||c.type!=null&&t.type!=null&&c.type!=t.type||c.apply!=t.apply||c.boost!=t.boost?s.push(e):pP(e.completion)>pP(c)&&(s[s.length-1]=e),c=e.completion}return s}var Mde=class e{constructor(e,t,n,r,i,a){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=r,this.selected=i,this.disabled=a}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new e(this.options,mP(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,i,a,o){if(i&&!o&&t.some(e=>e.isPending))return i.setDisabled();let s=jde(t,n);if(!s.length)return i&&t.some(e=>e.isPending)?i.setDisabled():null;let c=n.facet(lP).selectOnOpen?0:-1;if(i&&i.selected!=c&&i.selected!=-1){let e=i.options[i.selected].completion;for(let t=0;t<s.length;t++)if(s[t].completion==e){c=t;break}}return new e(s,mP(r,c),{pos:t.reduce((e,t)=>t.hasResult()?Math.min(e,t.from):e,1e8),create:zde,above:a.aboveCursor},i?i.timestamp:Date.now(),c,!1)}map(t){return new e(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new e(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}},Nde=class e{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new e(Lde,`cm-ac-`+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet(lP),i=(r.override||n.languageDataAt(`autocomplete`,rP(n)).map(Cde)).map(e=>(this.active.find(t=>t.source==e)||new gP(e,+!!this.active.some(e=>e.state!=0))).update(t,r));i.length==this.active.length&&i.every((e,t)=>e==this.active[t])&&(i=this.active);let a=this.open,o=t.effects.some(e=>e.is(vP));a&&t.docChanged&&(a=a.map(t.changes)),t.selection||i.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!Pde(i,this.active)||o?a=Mde.build(i,n,this.id,a,r,o):a&&a.disabled&&!i.some(e=>e.isPending)&&(a=null),!a&&i.every(e=>!e.isPending)&&i.some(e=>e.hasResult())&&(i=i.map(e=>e.hasResult()?new gP(e.source,0):e));for(let e of t.effects)e.is(dP)&&(a&&=a.setSelected(e.value,this.id));return i==this.active&&a==this.open?this:new e(i,this.id,a)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Fde:Ide}};function Pde(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let i=n==e.length,a=r==t.length;if(i||a)return i==a;if(e[n++].result!=t[r++].result)return!1}}var Fde={"aria-autocomplete":`list`},Ide={};function mP(e,t){let n={"aria-autocomplete":`list`,"aria-haspopup":`listbox`,"aria-controls":e};return t>-1&&(n[`aria-activedescendant`]=e+`-`+t),n}var Lde=[];function hP(e,t){if(e.isUserEvent(`input.complete`)){let n=e.annotation(aP);if(n&&t.activateOnCompletion(n))return 12}let n=e.isUserEvent(`input.type`);return n&&t.activateOnTyping?5:n?1:e.isUserEvent(`delete.backward`)?2:e.selection?8:e.docChanged?16:0}var gP=class e{constructor(e,t,n=!1){this.source=e,this.state=t,this.explicit=n}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=hP(t,n),i=this;(r&8||r&16&&this.touches(t))&&(i=new e(i.source,0)),r&4&&i.state==0&&(i=new e(this.source,1)),i=i.updateFor(t,r);for(let n of t.effects)if(n.is(sP))i=new e(i.source,1,n.value);else if(n.is(cP))i=new e(i.source,0);else if(n.is(vP))for(let e of n.value)e.source==i.source&&(i=e);return i}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(rP(e.state))}},_P=class e extends gP{constructor(e,t,n,r,i,a){super(e,3,t),this.limit=n,this.result=r,this.from=i,this.to=a}hasResult(){return!0}updateFor(t,n){if(!(n&3))return this.map(t.changes);let r=this.result;r.map&&!t.changes.empty&&(r=r.map(r,t.changes));let i=t.changes.mapPos(this.from),a=t.changes.mapPos(this.to,1),o=rP(t.state);if(o>a||!r||n&2&&(rP(t.startState)==this.from||o<this.limit))return new gP(this.source,n&4?1:0);let s=t.changes.mapPos(this.limit);return Rde(r.validFor,t.state,i,a)?new e(this.source,this.explicit,s,r,i,a):r.update&&(r=r.update(r,i,a,new $N(t.state,o,!1)))?new e(this.source,this.explicit,s,r,r.from,r.to??rP(t.state)):new gP(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new e(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new gP(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}};function Rde(e,t,n,r){if(!e)return!1;let i=t.sliceDoc(n,r);return typeof e==`function`?e(i,n,r,t):iP(e,!0).test(i)}var vP=w.define({map(e,t){return e.map(e=>e.map(t))}}),yP=l.define({create(){return Nde.start()},update(e,t){return e.update(t)},provide:e=>[F.from(e,e=>e.tooltip),f.contentAttributes.from(e,e=>e.attrs)]});function bP(e,t){let n=t.completion.apply||t.completion.label,r=e.state.field(yP).active.find(e=>e.source==t.source);return r instanceof _P?(typeof n==`string`?e.dispatch({...Sde(e.state,n,r.from,r.to),annotations:aP.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}var zde=kde(yP,bP);function xP(e,t=`option`){return n=>{let i=n.state.field(yP,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<n.state.facet(lP).interactionDelay)return!1;let a=1,o;t==`page`&&(o=r(n,i.open.tooltip))&&(a=Math.max(2,Math.floor(o.dom.offsetHeight/o.dom.querySelector(`li`).offsetHeight)-1));let{length:s}=i.open.options,c=i.open.selected>-1?i.open.selected+a*(e?1:-1):e?0:s-1;return c<0?c=t==`page`?0:s-1:c>=s&&(c=t==`page`?s-1:0),n.dispatch({effects:dP.of(c)}),!0}}var Bde=e=>{let t=e.state.field(yP,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(lP).interactionDelay?!1:bP(e,t.open.options[t.open.selected])},SP=e=>e.state.field(yP,!1)?(e.dispatch({effects:sP.of(!0)}),!0):!1,Vde=e=>{let t=e.state.field(yP,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(e.dispatch({effects:cP.of(null)}),!0)},Hde=class{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}},Ude=50,Wde=1e3,Gde=ge.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(yP).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(yP),n=e.state.facet(lP);if(!e.selectionSet&&!e.docChanged&&e.startState.field(yP)==t)return;let r=e.transactions.some(e=>{let t=hP(e,n);return t&8||(e.selection||e.docChanged)&&!(t&3)});for(let t=0;t<this.running.length;t++){let n=this.running[t];if(r||n.context.abortOnDocChange&&e.docChanged||n.updates.length+e.transactions.length>Ude&&Date.now()-n.time>Wde){for(let e of n.context.abortListeners)try{e()}catch(e){me(this.view.state,e)}n.context.abortListeners=null,this.running.splice(t--,1)}else n.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(e=>e.effects.some(e=>e.is(sP)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(e=>e.isPending&&!this.running.some(t=>t.active.source==e.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let t of e.transactions)t.isUserEvent(`input.type`)?this.composing=2:this.composing==2&&t.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(yP);for(let e of t.active)e.isPending&&!this.running.some(t=>t.active.source==e.source)&&this.startQuery(e);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(lP).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=new $N(t,rP(t),e.explicit,this.view),r=new Hde(e,n);this.running.push(r),Promise.resolve(e.source(n)).then(e=>{r.context.aborted||(r.done=e||null,this.scheduleAccept())},e=>{this.view.dispatch({effects:cP.of(null)}),me(this.view.state,e)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(lP).updateSyncTime))}accept(){this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(lP),n=this.view.state.field(yP);for(let r=0;r<this.running.length;r++){let i=this.running[r];if(i.done===void 0)continue;if(this.running.splice(r--,1),i.done){let n=rP(i.updates.length?i.updates[0].startState:this.view.state),r=Math.min(n,i.done.from+ +!i.active.explicit),a=new _P(i.active.source,i.active.explicit,r,i.done,i.done.from,i.done.to??n);for(let e of i.updates)a=a.update(e,t);if(a.hasResult()){e.push(a);continue}}let a=n.active.find(e=>e.source==i.active.source);if(a&&a.isPending)if(i.done==null){let n=new gP(i.active.source,0);for(let e of i.updates)n=n.update(e,t);n.isPending||e.push(n)}else this.startQuery(a)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:vP.of(e)})}},{eventHandlers:{blur(e){let t=this.view.state.field(yP,!1);if(t&&t.tooltip&&this.view.state.facet(lP).closeOnBlur){let n=t.open&&r(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:cP.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:sP.of(!1)}),20),this.composing=0}}}),Kde=typeof navigator==`object`&&/Win/.test(navigator.platform),qde=De.highest(f.domEventHandlers({keydown(e,t){let n=t.state.field(yP,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(Kde&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],i=n.active.find(e=>e.source==r.source),a=r.completion.commitCharacters||i.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&bP(t,r),!1}})),CP=f.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:`monospace`,whiteSpace:`nowrap`,overflow:`hidden auto`,maxWidth_fallback:`700px`,maxWidth:`min(700px, 95vw)`,minWidth:`250px`,maxHeight:`10em`,height:`100%`,listStyle:`none`,margin:0,padding:0,"& > li, & > completion-section":{padding:`1px 3px`,lineHeight:1.2},"& > li":{overflowX:`hidden`,textOverflow:`ellipsis`,cursor:`pointer`},"& > completion-section":{display:`list-item`,borderBottom:`1px solid silver`,paddingLeft:`0.5em`,opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#17c`,color:`white`},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#777`},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#347`,color:`white`},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#444`},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:`"···"`,opacity:.5,display:`block`,textAlign:`center`},".cm-tooltip.cm-completionInfo":{position:`absolute`,padding:`3px 9px`,width:`max-content`,maxWidth:`400px`,boxSizing:`border-box`,whiteSpace:`pre-line`},".cm-completionInfo.cm-completionInfo-left":{right:`100%`},".cm-completionInfo.cm-completionInfo-right":{left:`100%`},".cm-completionInfo.cm-completionInfo-left-narrow":{right:`30px`},".cm-completionInfo.cm-completionInfo-right-narrow":{left:`30px`},"&light .cm-snippetField":{backgroundColor:`#00000022`},"&dark .cm-snippetField":{backgroundColor:`#ffffff22`},".cm-snippetFieldPosition":{verticalAlign:`text-top`,width:0,height:`1.15em`,display:`inline-block`,margin:`0 -0.7px -.7em`,borderLeft:`1.4px dotted #888`},".cm-completionMatchedText":{textDecoration:`underline`},".cm-completionDetail":{marginLeft:`0.5em`,fontStyle:`italic`},".cm-completionIcon":{fontSize:`90%`,width:`.8em`,display:`inline-block`,textAlign:`center`,paddingRight:`.6em`,opacity:`0.6`,boxSizing:`content-box`},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:`'ƒ'`}},".cm-completionIcon-class":{"&:after":{content:`'○'`}},".cm-completionIcon-interface":{"&:after":{content:`'◌'`}},".cm-completionIcon-variable":{"&:after":{content:`'𝑥'`}},".cm-completionIcon-constant":{"&:after":{content:`'𝐶'`}},".cm-completionIcon-type":{"&:after":{content:`'𝑡'`}},".cm-completionIcon-enum":{"&:after":{content:`'∪'`}},".cm-completionIcon-property":{"&:after":{content:`'□'`}},".cm-completionIcon-keyword":{"&:after":{content:`'🔑︎'`}},".cm-completionIcon-namespace":{"&:after":{content:`'▢'`}},".cm-completionIcon-text":{"&:after":{content:`'abc'`,fontSize:`50%`,verticalAlign:`middle`}}}),Jde=class{constructor(e,t,n,r){this.field=e,this.line=t,this.from=n,this.to=r}},Yde=class e{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(t){let n=t.mapPos(this.from,-1,M.TrackDel),r=t.mapPos(this.to,1,M.TrackDel);return n==null||r==null?null:new e(this.field,n,r)}},Xde=class e{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],r=[t],i=e.doc.lineAt(t),a=/^\s*/.exec(i.text)[0];for(let i of this.lines){if(n.length){let n=a,o=/^\t*/.exec(i)[0].length;for(let t=0;t<o;t++)n+=e.facet(c);r.push(t+n.length-o),i=n+i.slice(o)}n.push(i),t+=i.length+1}return{text:n,ranges:this.fieldPositions.map(e=>new Yde(e.field,r[e.line]+e.from,r[e.line]+e.to))}}static parse(t){let n=[],r=[],i=[],a;for(let e of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(e);){let t=a[1]?+a[1]:null,o=a[2]||a[3]||``,s=-1,c=o.replace(/\\[{}]/g,e=>e[1]);for(let e=0;e<n.length;e++)(t==null?c&&n[e].name==c:n[e].seq==t)&&(s=e);if(s<0){let e=0;for(;e<n.length&&(t==null||n[e].seq!=null&&n[e].seq<t);)e++;n.splice(e,0,{seq:t,name:c}),s=e;for(let e of i)e.field>=s&&e.field++}for(let e of i)if(e.line==r.length&&e.from>a.index){let t=a[2]?3+(a[1]||``).length:2;e.from-=t,e.to-=t}i.push(new Jde(s,r.length,a.index,a.index+c.length)),e=e.slice(0,a.index)+o+e.slice(a.index+a[0].length)}e=e.replace(/\\([{}])/g,(e,t,n)=>{for(let e of i)e.line==r.length&&e.from>n&&(e.from--,e.to--);return t}),r.push(e)}return new e(r,i)}},Zde=T.widget({widget:new class extends d{toDOM(){let e=document.createElement(`span`);return e.className=`cm-snippetFieldPosition`,e}ignoreEvent(){return!1}}}),Qde=T.mark({class:`cm-snippetField`}),wP=class e{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(e=>(e.from==e.to?Zde:Qde).range(e.from,e.to)),!0)}map(t){let n=[];for(let e of this.ranges){let r=e.map(t);if(!r)return null;n.push(r)}return new e(n,this.active)}selectionInsideField(e){return e.ranges.every(e=>this.ranges.some(t=>t.field==this.active&&t.from<=e.from&&t.to>=e.to))}},TP=w.define({map(e,t){return e&&e.map(t)}}),$de=w.define(),EP=l.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(TP))return n.value;if(n.is($de)&&e)return new wP(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>f.decorations.from(e,e=>e?e.deco:T.none)});function DP(e,t){return k.create(e.filter(e=>e.field==t).map(e=>k.range(e.from,e.to)))}function efe(e){let t=Xde.parse(e);return(e,n,r,i)=>{let{text:a,ranges:o}=t.instantiate(e.state,r),{main:c}=e.state.selection,l={changes:{from:r,to:i==c.from?c.to:i,insert:s.of(a)},scrollIntoView:!0,annotations:n?[aP.of(n),_.userEvent.of(`input.complete`)]:void 0};if(o.length&&(l.selection=DP(o,0)),o.some(e=>e.field>0)){let t=new wP(o,0),n=l.effects=[TP.of(t)];e.state.field(EP,!1)===void 0&&n.push(w.appendConfig.of([EP,nfe,ife,CP]))}e.dispatch(e.state.update(l))}}function OP(e){return({state:t,dispatch:n})=>{let r=t.field(EP,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(t=>t.field==i+e);return n(t.update({selection:DP(r.ranges,i),effects:TP.of(a?null:new wP(r.ranges,i)),scrollIntoView:!0})),!0}}var tfe=[{key:`Tab`,run:OP(1),shift:OP(-1)},{key:`Escape`,run:({state:e,dispatch:t})=>e.field(EP,!1)?(t(e.update({effects:TP.of(null)})),!0):!1}],kP=Oe.define({combine(e){return e.length?e[0]:tfe}}),nfe=De.highest(ie.compute([kP],e=>e.facet(kP)));function rfe(e,t){return{...t,apply:efe(e)}}var ife=f.domEventHandlers({mousedown(e,t){let n=t.state.field(EP,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(e=>e.from<=r&&e.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:DP(n.ranges,i.field),effects:TP.of(n.ranges.some(e=>e.field>i.field)?new wP(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),AP={brackets:[`(`,`[`,`{`,`'`,`"`],before:`)]}:;>`,stringPrefixes:[]},jP=w.define({map(e,t){return t.mapPos(e,-1,M.TrackAfter)??void 0}}),MP=new class extends Te{};MP.startSide=1,MP.endSide=-1;var NP=l.define({create(){return S.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:e=>e>=n.from&&e<=n.to})}for(let n of t.effects)n.is(jP)&&(e=e.update({add:[MP.range(n.value,n.value+1)]}));return e}});function afe(){return[sfe,NP]}var PP=`()[]{}<>«»»«[]{}`;function FP(e){for(let t=0;t<16;t+=2)if(PP.charCodeAt(t)==e)return PP.charAt(t+1);return y(e<128?e:e+1)}function IP(e,t){return e.languageDataAt(`closeBrackets`,t)[0]||AP}var ofe=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),sfe=f.inputHandler.of((e,t,n,r)=>{if((ofe?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let i=e.state.selection.main;if(r.length>2||r.length==2&&a(se(r,0))==1||t!=i.from||n!=i.to)return!1;let o=lfe(e.state,r);return o?(e.dispatch(o),!0):!1}),cfe=[{key:`Backspace`,run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=IP(e,e.selection.main.head).brackets||AP.brackets,r=null,i=e.changeByRange(t=>{if(t.empty){let r=ufe(e.doc,t.head);for(let i of n)if(i==r&&RP(e.doc,t.head)==FP(se(i,0)))return{changes:{from:t.head-i.length,to:t.head+i.length},range:k.cursor(t.head-i.length)}}return{range:r=t}});return r||t(e.update(i,{scrollIntoView:!0,userEvent:`delete.backward`})),!r}}];function lfe(e,t){let n=IP(e,e.selection.main.head),r=n.brackets||AP.brackets;for(let i of r){let a=FP(se(i,0));if(t==i)return a==i?pfe(e,i,r.indexOf(i+i+i)>-1,n):dfe(e,i,a,n.before||AP.before);if(t==a&&LP(e,e.selection.main.from))return ffe(e,i,a)}return null}function LP(e,t){let n=!1;return e.field(NP).between(0,e.doc.length,e=>{e==t&&(n=!0)}),n}function RP(e,t){let n=e.sliceString(t,t+2);return n.slice(0,a(se(n,0)))}function ufe(e,t){let n=e.sliceString(t-2,t);return a(se(n,0))==n.length?n:n.slice(1)}function dfe(e,t,n,r){let i=null,a=e.changeByRange(a=>{if(!a.empty)return{changes:[{insert:t,from:a.from},{insert:n,from:a.to}],effects:jP.of(a.to+t.length),range:k.range(a.anchor+t.length,a.head+t.length)};let o=RP(e.doc,a.head);return!o||/\s/.test(o)||r.indexOf(o)>-1?{changes:{insert:t+n,from:a.head},effects:jP.of(a.head+t.length),range:k.cursor(a.head+t.length)}:{range:i=a}});return i?null:e.update(a,{scrollIntoView:!0,userEvent:`input.type`})}function ffe(e,t,n){let r=null,i=e.changeByRange(t=>t.empty&&RP(e.doc,t.head)==n?{changes:{from:t.head,to:t.head+n.length,insert:n},range:k.cursor(t.head+n.length)}:r={range:t});return r?null:e.update(i,{scrollIntoView:!0,userEvent:`input.type`})}function pfe(e,t,n,r){let i=r.stringPrefixes||AP.stringPrefixes,a=null,o=e.changeByRange(r=>{if(!r.empty)return{changes:[{insert:t,from:r.from},{insert:t,from:r.to}],effects:jP.of(r.to+t.length),range:k.range(r.anchor+t.length,r.head+t.length)};let o=r.head,s=RP(e.doc,o),c;if(s==t){if(zP(e,o))return{changes:{insert:t+t,from:o},effects:jP.of(o+t.length),range:k.cursor(o+t.length)};if(LP(e,o)){let r=n&&e.sliceDoc(o,o+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:o,to:o+r.length,insert:r},range:k.cursor(o+r.length)}}}else if(n&&e.sliceDoc(o-2*t.length,o)==t+t&&(c=BP(e,o-2*t.length,i))>-1&&zP(e,c))return{changes:{insert:t+t+t+t,from:o},effects:jP.of(o+t.length),range:k.cursor(o+t.length)};else if(e.charCategorizer(o)(s)!=L.Word&&BP(e,o,i)>-1&&!mfe(e,o,t,i))return{changes:{insert:t+t,from:o},effects:jP.of(o+t.length),range:k.cursor(o+t.length)};return{range:a=r}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:`input.type`})}function zP(e,t){let n=ae(e).resolveInner(t+1);return n.parent&&n.from==t}function mfe(e,t,n,r){let i=ae(e).resolveInner(t,-1),a=r.reduce((e,t)=>Math.max(e,t.length),0);for(let o=0;o<5;o++){let o=e.sliceDoc(i.from,Math.min(i.to,i.from+n.length+a)),s=o.indexOf(n);if(!s||s>-1&&r.indexOf(o.slice(0,s))>-1){let t=i.firstChild;for(;t&&t.from==i.from&&t.to-t.from>n.length+s;){if(e.sliceDoc(t.to-n.length,t.to)==n)return!1;t=t.firstChild}return!0}let c=i.to==t&&i.parent;if(!c)break;i=c}return!1}function BP(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=L.Word)return t;for(let i of n){let n=t-i.length;if(e.sliceDoc(n,t)==i&&r(e.sliceDoc(n-1,n))!=L.Word)return n}return-1}function hfe(e={}){return[qde,yP,lP.of(e),Gde,gfe,CP]}var VP=[{key:`Ctrl-Space`,run:SP},{mac:"Alt-`",run:SP},{mac:`Alt-i`,run:SP},{key:`Escape`,run:Vde},{key:`ArrowDown`,run:xP(!0)},{key:`ArrowUp`,run:xP(!1)},{key:`PageDown`,run:xP(!0,`page`)},{key:`PageUp`,run:xP(!1,`page`)},{key:`Enter`,run:Bde}],gfe=De.highest(ie.computeN([lP],e=>e.facet(lP).defaultKeymap?[VP]:[])),_fe=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=UP(e.state,n.from);return r.line?vfe(e):r.block?bfe(e):!1};function HP(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var vfe=HP(Cfe,0),yfe=HP(GP,0),bfe=HP((e,t)=>GP(e,t,Sfe(t)),0);function UP(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var WP=50;function xfe(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-WP,r),o=e.sliceDoc(i,i+WP),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*WP?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+WP),d=e.sliceDoc(i-WP,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function Sfe(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function GP(e,t,n=t.selection.ranges){let r=n.map(e=>UP(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>xfe(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function Cfe(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=UP(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var KP=he.define(),wfe=he.define(),Tfe=Oe.define(),qP=Oe.define({combine(e){return oe(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),JP=l.define({create(){return aF.empty},update(e,t){let n=t.state.facet(qP),r=t.annotation(KP);if(r){let i=$P.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?eF(o,o.length,n.minDepth,i):rF(o,t.startState.selection),new aF(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(wfe);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(_.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=$P.fromTransaction(t),o=t.annotation(_.time),s=t.annotation(_.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new aF(e.done.map($P.fromJSON),e.undone.map($P.fromJSON))}});function YP(e={}){return[JP,qP.of(e),f.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?ZP:e.inputType==`historyRedo`?QP:null;return n?(e.preventDefault(),n(t)):!1}})]}function XP(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(JP,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var ZP=XP(0,!1),QP=XP(1,!1),Efe=XP(0,!0),Dfe=XP(1,!0),$P=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&re.fromJSON(t.changes),[],t.mapped&&ue.fromJSON(t.mapped),t.startSelection&&k.fromJSON(t.startSelection),t.selectionsAfter.map(k.fromJSON))}static fromTransaction(t,n){let r=nF;for(let e of t.startState.facet(Tfe)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,nF)}static selection(t){return new e(void 0,nF,void 0,void 0,t)}};function eF(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function Ofe(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function kfe(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function tF(e,t){return e.length?t.length?e.concat(t):e:t}var nF=[],Afe=200;function rF(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Afe));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),eF(e,e.length-1,1e9,n.setSelAfter(r)))}else return[$P.selection([t])]}function jfe(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function iF(e,t){if(!e.length)return e;let n=e.length,r=nF;for(;n;){let i=Mfe(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[$P.selection(r)]:nF}function Mfe(e,t,n){let r=tF(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):nF,n);if(!e.changes)return $P.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new $P(i,w.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var Nfe=/^(input\.type|delete)($|\.)/,aF=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||Nfe.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,Ofe(s.changes,t.changes))||r==`input.type.compose`)?eF(o,o.length-1,i.minDepth,new $P(t.changes.compose(s.changes),tF(w.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,nF)):eF(o,o.length,i.minDepth,t),new e(o,nF,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:nF;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&kfe(a[a.length-1],t)?this:new e(rF(this.done,t),this.undone,n,r)}addMapping(t){return new e(iF(this.done,t),iF(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:KP.of({side:e,rest:jfe(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?nF:r.slice(0,r.length-1);return i.mapped&&(n=iF(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:KP.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};aF.empty=new aF(nF,nF);var oF=[{key:`Mod-z`,run:ZP,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:QP,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:QP,preventDefault:!0},{key:`Mod-u`,run:Efe,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:Dfe,preventDefault:!0}];function sF(e,t){return k.create(e.ranges.map(t),e.mainIndex)}function cF(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function lF({state:e,dispatch:t},n){let r=sF(e.selection,n);return r.eq(e.selection,!0)?!1:(t(cF(e,r)),!0)}function uF(e,t){return k.cursor(t?e.to:e.from)}function dF(e,t){return lF(e,n=>n.empty?e.moveByChar(n,t):uF(n,t))}function fF(e){return e.textDirectionAt(e.state.selection.main.head)==u.LTR}var pF=e=>dF(e,!fF(e)),mF=e=>dF(e,fF(e));function hF(e,t){return lF(e,n=>n.empty?e.moveByGroup(n,t):uF(n,t))}var Pfe=e=>hF(e,!fF(e)),Ffe=e=>hF(e,fF(e));typeof Intl<`u`&&Intl.Segmenter;function Ife(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function gF(e,t,n){let r=ae(e).resolveInner(t.head),i=n?p.closedBy:p.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;Ife(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?g(e,r.from,1):g(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,k.cursor(s,n?-1:1)}var Lfe=e=>lF(e,t=>gF(e.state,t,!fF(e))),Rfe=e=>lF(e,t=>gF(e.state,t,fF(e)));function _F(e,t){return lF(e,n=>{if(!n.empty)return uF(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var vF=e=>_F(e,!1),yF=e=>_F(e,!0);function bF(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(f.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function xF(e,t){let n=bF(e),{state:r}=e,i=sF(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):uF(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=f.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(cF(r,i),{effects:a}),!0}var SF=e=>xF(e,!1),CF=e=>xF(e,!0);function wF(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=k.cursor(r.from+n))}return i}var zfe=e=>lF(e,t=>wF(e,t,!0)),Bfe=e=>lF(e,t=>wF(e,t,!1)),Vfe=e=>lF(e,t=>wF(e,t,!fF(e))),Hfe=e=>lF(e,t=>wF(e,t,fF(e))),Ufe=e=>lF(e,t=>k.cursor(e.lineBlockAt(t.head).from,1)),Wfe=e=>lF(e,t=>k.cursor(e.lineBlockAt(t.head).to,-1));function Gfe(e,t,n){let r=!1,i=sF(e.selection,t=>{let i=g(e,t.head,-1)||g(e,t.head,1)||t.head>0&&g(e,t.head-1,1)||t.head<e.doc.length&&g(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?k.range(t.anchor,a):k.cursor(a)});return r?(t(cF(e,i)),!0):!1}var Kfe=({state:e,dispatch:t})=>Gfe(e,t,!1);function TF(e,t){let n=sF(e.state.selection,e=>{let n=t(e);return k.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(cF(e.state,n)),!0)}function EF(e,t){return TF(e,n=>e.moveByChar(n,t))}var DF=e=>EF(e,!fF(e)),OF=e=>EF(e,fF(e));function kF(e,t){return TF(e,n=>e.moveByGroup(n,t))}var qfe=e=>kF(e,!fF(e)),Jfe=e=>kF(e,fF(e)),Yfe=e=>TF(e,t=>gF(e.state,t,!fF(e))),Xfe=e=>TF(e,t=>gF(e.state,t,fF(e)));function AF(e,t){return TF(e,n=>e.moveVertically(n,t))}var jF=e=>AF(e,!1),MF=e=>AF(e,!0);function NF(e,t){return TF(e,n=>e.moveVertically(n,t,bF(e).height))}var PF=e=>NF(e,!1),FF=e=>NF(e,!0),Zfe=e=>TF(e,t=>wF(e,t,!0)),Qfe=e=>TF(e,t=>wF(e,t,!1)),$fe=e=>TF(e,t=>wF(e,t,!fF(e))),epe=e=>TF(e,t=>wF(e,t,fF(e))),tpe=e=>TF(e,t=>k.cursor(e.lineBlockAt(t.head).from)),npe=e=>TF(e,t=>k.cursor(e.lineBlockAt(t.head).to)),IF=({state:e,dispatch:t})=>(t(cF(e,{anchor:0})),!0),LF=({state:e,dispatch:t})=>(t(cF(e,{anchor:e.doc.length})),!0),RF=({state:e,dispatch:t})=>(t(cF(e,{anchor:e.selection.main.anchor,head:0})),!0),zF=({state:e,dispatch:t})=>(t(cF(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),rpe=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),ipe=({state:e,dispatch:t})=>{let n=JF(e).map(({from:t,to:n})=>k.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:k.create(n),userEvent:`select`})),!0},ape=({state:e,dispatch:t})=>{let n=sF(e.selection,t=>{let n=ae(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return k.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(cF(e,n)),!0)};function BF(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(cF(n,k.create(i,i.length-1))),!0)}var ope=e=>BF(e,!1),spe=e=>BF(e,!0),cpe=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=k.create([n.main]):n.main.empty||(r=k.create([k.cursor(n.main.head)])),r?(t(cF(e,r)),!0):!1};function VF(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=HF(e,o,!1)):o>i&&(n=`delete.forward`,o=HF(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=HF(e,i,!1),a=HF(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:k.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?f.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function HF(e,t,n){if(e instanceof f)for(let r of e.state.facet(f.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var UF=(e,t,n)=>VF(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=m(s,a.tabSize)%Ee(a)||Ee(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=h(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=h(o.text,c-o.from,!1,!1)+o.from);return c}),WF=e=>UF(e,!1,!0),GF=e=>UF(e,!0,!1),KF=(e,t)=>VF(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=h(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),qF=e=>KF(e,!1),lpe=e=>KF(e,!0),upe=e=>VF(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),dpe=e=>VF(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),fpe=e=>VF(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ppe=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:s.of([``,``])},range:k.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},mpe=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:h(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:h(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:k.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function JF(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function YF(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of JF(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(k.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(k.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:k.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var hpe=({state:e,dispatch:t})=>YF(e,t,!1),gpe=({state:e,dispatch:t})=>YF(e,t,!0);function XF(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of JF(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var _pe=({state:e,dispatch:t})=>XF(e,t,!1),vpe=({state:e,dispatch:t})=>XF(e,t,!0),ype=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(JF(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=sF(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function bpe(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=ae(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(p.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var ZF=QF(!1),xpe=QF(!0);function QF(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&bpe(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let c=new de(t,{simulateBreak:r,simulateDoubleBreak:!!o}),l=x(c,r);for(l??=m(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let u=[``,C(t,l)];return o&&u.push(C(t,c.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:s.of(u)},range:k.cursor(r+1+u[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function $F(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:k.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Spe=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new de(e,{overrideIndentation:e=>n[e]??-1}),i=$F(e,(t,i,a)=>{let o=x(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=C(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},eI=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update($F(e,(t,n)=>{n.push({from:t.from,insert:e.facet(c)})}),{userEvent:`input.indent`})),!0),tI=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update($F(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=m(r,e.tabSize),a=0,o=C(e,Math.max(0,i-Ee(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),Cpe=e=>(e.setTabFocusMode(),!0),wpe=[{key:`Ctrl-b`,run:pF,shift:DF,preventDefault:!0},{key:`Ctrl-f`,run:mF,shift:OF},{key:`Ctrl-p`,run:vF,shift:jF},{key:`Ctrl-n`,run:yF,shift:MF},{key:`Ctrl-a`,run:Ufe,shift:tpe},{key:`Ctrl-e`,run:Wfe,shift:npe},{key:`Ctrl-d`,run:GF},{key:`Ctrl-h`,run:WF},{key:`Ctrl-k`,run:upe},{key:`Ctrl-Alt-h`,run:qF},{key:`Ctrl-o`,run:ppe},{key:`Ctrl-t`,run:mpe},{key:`Ctrl-v`,run:CF}],Tpe=[{key:`ArrowLeft`,run:pF,shift:DF,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:Pfe,shift:qfe,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Vfe,shift:$fe,preventDefault:!0},{key:`ArrowRight`,run:mF,shift:OF,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:Ffe,shift:Jfe,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Hfe,shift:epe,preventDefault:!0},{key:`ArrowUp`,run:vF,shift:jF,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:IF,shift:RF},{mac:`Ctrl-ArrowUp`,run:SF,shift:PF},{key:`ArrowDown`,run:yF,shift:MF,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:LF,shift:zF},{mac:`Ctrl-ArrowDown`,run:CF,shift:FF},{key:`PageUp`,run:SF,shift:PF},{key:`PageDown`,run:CF,shift:FF},{key:`Home`,run:Bfe,shift:Qfe,preventDefault:!0},{key:`Mod-Home`,run:IF,shift:RF},{key:`End`,run:zfe,shift:Zfe,preventDefault:!0},{key:`Mod-End`,run:LF,shift:zF},{key:`Enter`,run:ZF,shift:ZF},{key:`Mod-a`,run:rpe},{key:`Backspace`,run:WF,shift:WF,preventDefault:!0},{key:`Delete`,run:GF,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:qF,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:lpe,preventDefault:!0},{mac:`Mod-Backspace`,run:dpe,preventDefault:!0},{mac:`Mod-Delete`,run:fpe,preventDefault:!0}].concat(wpe.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),nI=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:Lfe,shift:Yfe},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Rfe,shift:Xfe},{key:`Alt-ArrowUp`,run:hpe},{key:`Shift-Alt-ArrowUp`,run:_pe},{key:`Alt-ArrowDown`,run:gpe},{key:`Shift-Alt-ArrowDown`,run:vpe},{key:`Mod-Alt-ArrowUp`,run:ope},{key:`Mod-Alt-ArrowDown`,run:spe},{key:`Escape`,run:cpe},{key:`Mod-Enter`,run:xpe},{key:`Alt-l`,mac:`Ctrl-l`,run:ipe},{key:`Mod-i`,run:ape,preventDefault:!0},{key:`Mod-[`,run:tI},{key:`Mod-]`,run:eI},{key:`Mod-Alt-\\`,run:Spe},{key:`Shift-Mod-k`,run:ype},{key:`Shift-Mod-\\`,run:Kfe},{key:`Mod-/`,run:_fe},{key:`Alt-A`,run:yfe},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:Cpe}].concat(Tpe),Epe={key:`Tab`,run:eI,shift:tI};function Dpe(e,t,n,r){let i=Vl(VS),a=Ul(jC),o=R.useRef(null),{lexicalNode:s}=JN(),c=R.useRef(!1),l=R.useRef(!1),u=R.useCallback(()=>{a({editorType:t,rootNode:s,editorRef:o.current})},[t,s,a]),d=R.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=Ah(e);n.getNextSibling()?((t=o.current?.getCodemirror())==null||t.contentDOM.blur(),n.selectNext()):n.insertAfter(nh())}),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=Ah(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(()=>{Ah(e).remove()})},[i,e]);return R.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]),R.useEffect(()=>{r.subscribe(()=>{var e;(e=o.current?.getCodemirror())==null||e.focus(),u()})},[r,o,e,u]),o}function X(e){return new pe(N.define(e))}function rI(e){return Y(()=>import(`./dist-D1Laodgo.js`).then(t=>t.sql({dialect:t[e]})),__vite__mapDeps([0,1,2]))}var Ope=[A.of({name:`C`,extensions:[`c`,`h`,`ino`],load(){return Y(()=>import(`./dist-C5YJOwhH.js`).then(e=>e.cpp()),__vite__mapDeps([3,1,2]))}}),A.of({name:`C++`,alias:[`cpp`],extensions:[`cpp`,`c++`,`cc`,`cxx`,`hpp`,`h++`,`hh`,`hxx`],load(){return Y(()=>import(`./dist-C5YJOwhH.js`).then(e=>e.cpp()),__vite__mapDeps([3,1,2]))}}),A.of({name:`CQL`,alias:[`cassandra`],extensions:[`cql`],load(){return rI(`Cassandra`)}}),A.of({name:`CSS`,extensions:[`css`],load(){return Y(()=>import(`./dist-CKM5j-iy.js`).then(e=>e.i).then(e=>e.css()),__vite__mapDeps([4,5,1,2]))}}),A.of({name:`Go`,extensions:[`go`],load(){return Y(()=>import(`./dist-85Cc5Hut.js`).then(e=>e.go()),__vite__mapDeps([6,1,2]))}}),A.of({name:`HTML`,alias:[`xhtml`],extensions:[`html`,`htm`,`handlebars`,`hbs`],load(){return Y(()=>import(`./dist-oLAGkW6G.js`).then(e=>e.html()),__vite__mapDeps([7,4,5,1,2,8]))}}),A.of({name:`Java`,extensions:[`java`],load(){return Y(()=>import(`./dist--55mTWk3.js`).then(e=>e.java()),__vite__mapDeps([9,1,2]))}}),A.of({name:`JavaScript`,alias:[`ecmascript`,`js`,`node`],extensions:[`js`,`mjs`,`cjs`],load(){return Y(()=>import(`./dist-DcME5mJj.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`Jinja`,extensions:[`j2`,`jinja`,`jinja2`],load(){return Y(()=>import(`./dist-BtF63vik.js`).then(e=>e.jinja()),__vite__mapDeps([10,7,4,5,1,2,8]))}}),A.of({name:`JSON`,alias:[`json5`],extensions:[`json`,`map`],load(){return Y(()=>import(`./dist-BZ39rB1W.js`).then(e=>e.json()),__vite__mapDeps([11,1,2]))}}),A.of({name:`JSX`,extensions:[`jsx`],load(){return Y(()=>import(`./dist-DcME5mJj.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`LESS`,extensions:[`less`],load(){return Y(()=>import(`./dist-C5oXtFSP.js`).then(e=>e.less()),__vite__mapDeps([12,4,5,1,2]))}}),A.of({name:`Liquid`,extensions:[`liquid`],load(){return Y(()=>import(`./dist-eG89IJAV.js`).then(e=>e.liquid()),__vite__mapDeps([13,7,4,5,1,2,8]))}}),A.of({name:`MariaDB SQL`,load(){return rI(`MariaSQL`)}}),A.of({name:`Markdown`,extensions:[`md`,`markdown`,`mkd`],load(){return Y(()=>import(`./dist-DE8W5WKg.js`).then(e=>e.markdown()),__vite__mapDeps([14,7,4,5,1,2,8]))}}),A.of({name:`MS SQL`,load(){return rI(`MSSQL`)}}),A.of({name:`MySQL`,load(){return rI(`MySQL`)}}),A.of({name:`PHP`,extensions:[`php`,`php3`,`php4`,`php5`,`php7`,`phtml`],load(){return Y(()=>import(`./dist-B8jspmzT.js`).then(e=>e.php()),__vite__mapDeps([15,7,4,5,1,2,8]))}}),A.of({name:`PLSQL`,extensions:[`pls`],load(){return rI(`PLSQL`)}}),A.of({name:`PostgreSQL`,load(){return rI(`PostgreSQL`)}}),A.of({name:`Python`,extensions:[`BUILD`,`bzl`,`py`,`pyw`],filename:/^(BUCK|BUILD)$/,load(){return Y(()=>import(`./dist-CQXtvBTs.js`).then(e=>e.python()),__vite__mapDeps([16,1,2]))}}),A.of({name:`Rust`,extensions:[`rs`],load(){return Y(()=>import(`./dist-CUp9us2q.js`).then(e=>e.rust()),__vite__mapDeps([17,1,2]))}}),A.of({name:`Sass`,extensions:[`sass`],load(){return Y(()=>import(`./dist-DSKQpPaz.js`).then(e=>e.sass({indented:!0})),__vite__mapDeps([18,4,5,1,2]))}}),A.of({name:`SCSS`,extensions:[`scss`],load(){return Y(()=>import(`./dist-DSKQpPaz.js`).then(e=>e.sass()),__vite__mapDeps([18,4,5,1,2]))}}),A.of({name:`SQL`,extensions:[`sql`],load(){return rI(`StandardSQL`)}}),A.of({name:`SQLite`,load(){return rI(`SQLite`)}}),A.of({name:`TSX`,extensions:[`tsx`],load(){return Y(()=>import(`./dist-DcME5mJj.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0,typescript:!0})),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`TypeScript`,alias:[`ts`],extensions:[`ts`,`mts`,`cts`],load(){return Y(()=>import(`./dist-DcME5mJj.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`WebAssembly`,extensions:[`wat`,`wast`],load(){return Y(()=>import(`./dist-CZ9T4Cly.js`).then(e=>e.wast()),__vite__mapDeps([19,1,2]))}}),A.of({name:`XML`,alias:[`rss`,`wsdl`,`xsd`],extensions:[`xml`,`xsl`,`xsd`,`svg`],load(){return Y(()=>import(`./dist-Zqt9kNG9.js`).then(e=>e.xml()),__vite__mapDeps([20,1,2]))}}),A.of({name:`YAML`,alias:[`yml`],extensions:[`yaml`,`yml`],load(){return Y(()=>import(`./dist-BsedZGJo.js`).then(e=>e.yaml()),__vite__mapDeps([21,1,2]))}}),A.of({name:`APL`,extensions:[`dyalog`,`apl`],load(){return Y(()=>import(`./apl-BxEMbctQ.js`).then(e=>X(e.apl)),[])}}),A.of({name:`PGP`,alias:[`asciiarmor`],extensions:[`asc`,`pgp`,`sig`],load(){return Y(()=>import(`./asciiarmor-eFjeGRuZ.js`).then(e=>X(e.asciiArmor)),[])}}),A.of({name:`ASN.1`,extensions:[`asn`,`asn1`],load(){return Y(()=>import(`./asn1-Cfx-0pt9.js`).then(e=>X(e.asn1({}))),[])}}),A.of({name:`Asterisk`,filename:/^extensions\.conf$/i,load(){return Y(()=>import(`./asterisk-B5BHTsBr.js`).then(e=>X(e.asterisk)),[])}}),A.of({name:`Brainfuck`,extensions:[`b`,`bf`],load(){return Y(()=>import(`./brainfuck-CAA2xofr.js`).then(e=>X(e.brainfuck)),[])}}),A.of({name:`Cobol`,extensions:[`cob`,`cpy`],load(){return Y(()=>import(`./cobol-BfgHZgup.js`).then(e=>X(e.cobol)),[])}}),A.of({name:`C#`,alias:[`csharp`,`cs`],extensions:[`cs`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.csharp)),[])}}),A.of({name:`Clojure`,extensions:[`clj`,`cljc`,`cljx`],load(){return Y(()=>import(`./clojure-kVFSWX0o.js`).then(e=>X(e.clojure)),[])}}),A.of({name:`ClojureScript`,extensions:[`cljs`],load(){return Y(()=>import(`./clojure-kVFSWX0o.js`).then(e=>X(e.clojure)),[])}}),A.of({name:`Closure Stylesheets (GSS)`,extensions:[`gss`],load(){return Y(()=>import(`./css-BqOeyZOV.js`).then(e=>X(e.gss)),[])}}),A.of({name:`CMake`,extensions:[`cmake`,`cmake.in`],filename:/^CMakeLists\.txt$/,load(){return Y(()=>import(`./cmake-BUPAhezI.js`).then(e=>X(e.cmake)),[])}}),A.of({name:`CoffeeScript`,alias:[`coffee`,`coffee-script`],extensions:[`coffee`],load(){return Y(()=>import(`./coffeescript-G1Pe_1AZ.js`).then(e=>X(e.coffeeScript)),[])}}),A.of({name:`Common Lisp`,alias:[`lisp`],extensions:[`cl`,`lisp`,`el`],load(){return Y(()=>import(`./commonlisp-B3N0CjHn.js`).then(e=>X(e.commonLisp)),[])}}),A.of({name:`Cypher`,extensions:[`cyp`,`cypher`],load(){return Y(()=>import(`./cypher-KjIKv-wW.js`).then(e=>X(e.cypher)),[])}}),A.of({name:`Cython`,extensions:[`pyx`,`pxd`,`pxi`],load(){return Y(()=>import(`./python-C2_X1GpX.js`).then(e=>X(e.cython)),[])}}),A.of({name:`Crystal`,extensions:[`cr`],load(){return Y(()=>import(`./crystal-C15ndaGM.js`).then(e=>X(e.crystal)),[])}}),A.of({name:`D`,extensions:[`d`],load(){return Y(()=>import(`./d-BlT5AEC-.js`).then(e=>X(e.d)),[])}}),A.of({name:`Dart`,extensions:[`dart`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.dart)),[])}}),A.of({name:`diff`,extensions:[`diff`,`patch`],load(){return Y(()=>import(`./diff-oF98tbqj.js`).then(e=>X(e.diff)),[])}}),A.of({name:`Dockerfile`,filename:/^Dockerfile$/,load(){return Y(()=>import(`./dockerfile-CUaqzcqp.js`).then(e=>X(e.dockerFile)),__vite__mapDeps([22,23]))}}),A.of({name:`DTD`,extensions:[`dtd`],load(){return Y(()=>import(`./dtd-VCA9yr61.js`).then(e=>X(e.dtd)),[])}}),A.of({name:`Dylan`,extensions:[`dylan`,`dyl`,`intr`],load(){return Y(()=>import(`./dylan-O-V5Dw5W.js`).then(e=>X(e.dylan)),[])}}),A.of({name:`EBNF`,load(){return Y(()=>import(`./ebnf-SPmdBkvT.js`).then(e=>X(e.ebnf)),[])}}),A.of({name:`ECL`,extensions:[`ecl`],load(){return Y(()=>import(`./ecl-ChfCttfI.js`).then(e=>X(e.ecl)),[])}}),A.of({name:`edn`,extensions:[`edn`],load(){return Y(()=>import(`./clojure-kVFSWX0o.js`).then(e=>X(e.clojure)),[])}}),A.of({name:`Eiffel`,extensions:[`e`],load(){return Y(()=>import(`./eiffel-cB9EbjeN.js`).then(e=>X(e.eiffel)),[])}}),A.of({name:`Elm`,extensions:[`elm`],load(){return Y(()=>import(`./elm-BTiVflBU.js`).then(e=>X(e.elm)),[])}}),A.of({name:`Erlang`,extensions:[`erl`],load(){return Y(()=>import(`./erlang-egf0TXFm.js`).then(e=>X(e.erlang)),[])}}),A.of({name:`Esper`,load(){return Y(()=>import(`./sql-D_dieYbr.js`).then(e=>X(e.esper)),[])}}),A.of({name:`Factor`,extensions:[`factor`],load(){return Y(()=>import(`./factor-C2tAxNob.js`).then(e=>X(e.factor)),__vite__mapDeps([24,23]))}}),A.of({name:`FCL`,load(){return Y(()=>import(`./fcl-BiCjh1tj.js`).then(e=>X(e.fcl)),[])}}),A.of({name:`Forth`,extensions:[`forth`,`fth`,`4th`],load(){return Y(()=>import(`./forth-C4kDGW6u.js`).then(e=>X(e.forth)),[])}}),A.of({name:`Fortran`,extensions:[`f`,`for`,`f77`,`f90`,`f95`],load(){return Y(()=>import(`./fortran-DzkLaPnd.js`).then(e=>X(e.fortran)),[])}}),A.of({name:`F#`,alias:[`fsharp`],extensions:[`fs`],load(){return Y(()=>import(`./mllike-wTFlPWXS.js`).then(e=>X(e.fSharp)),[])}}),A.of({name:`Gas`,extensions:[`s`],load(){return Y(()=>import(`./gas-DMOxskQF.js`).then(e=>X(e.gas)),[])}}),A.of({name:`Gherkin`,extensions:[`feature`],load(){return Y(()=>import(`./gherkin-BPxBpp-k.js`).then(e=>X(e.gherkin)),[])}}),A.of({name:`Groovy`,extensions:[`groovy`,`gradle`],filename:/^Jenkinsfile$/,load(){return Y(()=>import(`./groovy-CkEnc0ZY.js`).then(e=>X(e.groovy)),[])}}),A.of({name:`Haskell`,extensions:[`hs`],load(){return Y(()=>import(`./haskell-Dadpo9-w.js`).then(e=>X(e.haskell)),[])}}),A.of({name:`Haxe`,extensions:[`hx`],load(){return Y(()=>import(`./haxe-CDNZL9MW.js`).then(e=>X(e.haxe)),[])}}),A.of({name:`HXML`,extensions:[`hxml`],load(){return Y(()=>import(`./haxe-CDNZL9MW.js`).then(e=>X(e.hxml)),[])}}),A.of({name:`HTTP`,load(){return Y(()=>import(`./http-jy9Zxxt3.js`).then(e=>X(e.http)),[])}}),A.of({name:`IDL`,extensions:[`pro`],load(){return Y(()=>import(`./idl-CGSB6iiy.js`).then(e=>X(e.idl)),[])}}),A.of({name:`JSON-LD`,alias:[`jsonld`],extensions:[`jsonld`],load(){return Y(()=>import(`./javascript-DSlzRUd8.js`).then(e=>X(e.jsonld)),[])}}),A.of({name:`Julia`,extensions:[`jl`],load(){return Y(()=>import(`./julia-DTiF9v6R.js`).then(e=>X(e.julia)),[])}}),A.of({name:`Kotlin`,extensions:[`kt`,`kts`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.kotlin)),[])}}),A.of({name:`LiveScript`,alias:[`ls`],extensions:[`ls`],load(){return Y(()=>import(`./livescript-Ci8Xxna6.js`).then(e=>X(e.liveScript)),[])}}),A.of({name:`Lua`,extensions:[`lua`],load(){return Y(()=>import(`./lua-eVxIrt9t.js`).then(e=>X(e.lua)),[])}}),A.of({name:`mIRC`,extensions:[`mrc`],load(){return Y(()=>import(`./mirc-CtHu9S1B.js`).then(e=>X(e.mirc)),[])}}),A.of({name:`Mathematica`,extensions:[`m`,`nb`,`wl`,`wls`],load(){return Y(()=>import(`./mathematica-Da3grj36.js`).then(e=>X(e.mathematica)),[])}}),A.of({name:`Modelica`,extensions:[`mo`],load(){return Y(()=>import(`./modelica-cKbQ0UXu.js`).then(e=>X(e.modelica)),[])}}),A.of({name:`MUMPS`,extensions:[`mps`],load(){return Y(()=>import(`./mumps-CKBHkOQq.js`).then(e=>X(e.mumps)),[])}}),A.of({name:`Mbox`,extensions:[`mbox`],load(){return Y(()=>import(`./mbox-BWBMSafM.js`).then(e=>X(e.mbox)),[])}}),A.of({name:`Nginx`,filename:/nginx.*\.conf$/i,load(){return Y(()=>import(`./nginx-B00AiQel.js`).then(e=>X(e.nginx)),[])}}),A.of({name:`NSIS`,extensions:[`nsh`,`nsi`],load(){return Y(()=>import(`./nsis-SMDwKltR.js`).then(e=>X(e.nsis)),__vite__mapDeps([25,23]))}}),A.of({name:`NTriples`,extensions:[`nt`,`nq`],load(){return Y(()=>import(`./ntriples-B_36EBV0.js`).then(e=>X(e.ntriples)),[])}}),A.of({name:`Objective-C`,alias:[`objective-c`,`objc`],extensions:[`m`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.objectiveC)),[])}}),A.of({name:`Objective-C++`,alias:[`objective-c++`,`objc++`],extensions:[`mm`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.objectiveCpp)),[])}}),A.of({name:`OCaml`,extensions:[`ml`,`mli`,`mll`,`mly`],load(){return Y(()=>import(`./mllike-wTFlPWXS.js`).then(e=>X(e.oCaml)),[])}}),A.of({name:`Octave`,extensions:[`m`],load(){return Y(()=>import(`./octave-BXPjzAif.js`).then(e=>X(e.octave)),[])}}),A.of({name:`Oz`,extensions:[`oz`],load(){return Y(()=>import(`./oz-Dedpat1M.js`).then(e=>X(e.oz)),[])}}),A.of({name:`Pascal`,extensions:[`p`,`pas`],load(){return Y(()=>import(`./pascal-CMcUg72K.js`).then(e=>X(e.pascal)),[])}}),A.of({name:`Perl`,extensions:[`pl`,`pm`],load(){return Y(()=>import(`./perl-DoVTbnzt.js`).then(e=>X(e.perl)),[])}}),A.of({name:`Pig`,extensions:[`pig`],load(){return Y(()=>import(`./pig-CULXT1YV.js`).then(e=>X(e.pig)),[])}}),A.of({name:`PowerShell`,extensions:[`ps1`,`psd1`,`psm1`],load(){return Y(()=>import(`./powershell-Cv5Uhf6b.js`).then(e=>X(e.powerShell)),[])}}),A.of({name:`Properties files`,alias:[`ini`,`properties`],extensions:[`properties`,`ini`,`in`],load(){return Y(()=>import(`./properties-CQ1C2P-M.js`).then(e=>X(e.properties)),[])}}),A.of({name:`ProtoBuf`,extensions:[`proto`],load(){return Y(()=>import(`./protobuf-SRlvzrl6.js`).then(e=>X(e.protobuf)),[])}}),A.of({name:`Pug`,alias:[`jade`],extensions:[`pug`,`jade`],load(){return Y(()=>import(`./pug-Bo3wfL-f.js`).then(e=>X(e.pug)),__vite__mapDeps([26,27]))}}),A.of({name:`Puppet`,extensions:[`pp`],load(){return Y(()=>import(`./puppet-ClSqCGj6.js`).then(e=>X(e.puppet)),[])}}),A.of({name:`Q`,extensions:[`q`],load(){return Y(()=>import(`./q-B_6Gdyzl.js`).then(e=>X(e.q)),[])}}),A.of({name:`R`,alias:[`rscript`],extensions:[`r`,`R`],load(){return Y(()=>import(`./r-BD07NGED.js`).then(e=>X(e.r)),[])}}),A.of({name:`RPM Changes`,load(){return Y(()=>import(`./rpm-CRu5Z2Jl.js`).then(e=>X(e.rpmChanges)),[])}}),A.of({name:`RPM Spec`,extensions:[`spec`],load(){return Y(()=>import(`./rpm-CRu5Z2Jl.js`).then(e=>X(e.rpmSpec)),[])}}),A.of({name:`Ruby`,alias:[`jruby`,`macruby`,`rake`,`rb`,`rbx`],extensions:[`rb`],filename:/^(Gemfile|Rakefile)$/,load(){return Y(()=>import(`./ruby-dZPnOz8h.js`).then(e=>X(e.ruby)),[])}}),A.of({name:`SAS`,extensions:[`sas`],load(){return Y(()=>import(`./sas-S2t8_sDI.js`).then(e=>X(e.sas)),[])}}),A.of({name:`Scala`,extensions:[`scala`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.scala)),[])}}),A.of({name:`Scheme`,extensions:[`scm`,`ss`],load(){return Y(()=>import(`./scheme-WcyFWLW2.js`).then(e=>X(e.scheme)),[])}}),A.of({name:`Shell`,alias:[`bash`,`sh`,`zsh`],extensions:[`sh`,`ksh`,`bash`],filename:/^PKGBUILD$/,load(){return Y(()=>import(`./shell-DUelnYSh.js`).then(e=>X(e.shell)),[])}}),A.of({name:`Sieve`,extensions:[`siv`,`sieve`],load(){return Y(()=>import(`./sieve-jDjlVhNh.js`).then(e=>X(e.sieve)),[])}}),A.of({name:`Smalltalk`,extensions:[`st`],load(){return Y(()=>import(`./smalltalk-ddWDYy10.js`).then(e=>X(e.smalltalk)),[])}}),A.of({name:`Solr`,load(){return Y(()=>import(`./solr-C7rQhLuW.js`).then(e=>X(e.solr)),[])}}),A.of({name:`SML`,extensions:[`sml`,`sig`,`fun`,`smackspec`],load(){return Y(()=>import(`./mllike-wTFlPWXS.js`).then(e=>X(e.sml)),[])}}),A.of({name:`SPARQL`,alias:[`sparul`],extensions:[`rq`,`sparql`],load(){return Y(()=>import(`./sparql--fPCCgVd.js`).then(e=>X(e.sparql)),[])}}),A.of({name:`Spreadsheet`,alias:[`excel`,`formula`],load(){return Y(()=>import(`./spreadsheet-DjthqD5G.js`).then(e=>X(e.spreadsheet)),[])}}),A.of({name:`Squirrel`,extensions:[`nut`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.squirrel)),[])}}),A.of({name:`Stylus`,extensions:[`styl`],load(){return Y(()=>import(`./stylus-DxF70RNr.js`).then(e=>X(e.stylus)),[])}}),A.of({name:`Swift`,extensions:[`swift`],load(){return Y(()=>import(`./swift-T0hDoOb-.js`).then(e=>X(e.swift)),[])}}),A.of({name:`sTeX`,load(){return Y(()=>import(`./stex-rHcFYcA0.js`).then(e=>X(e.stex)),[])}}),A.of({name:`LaTeX`,alias:[`tex`],extensions:[`text`,`ltx`,`tex`],load(){return Y(()=>import(`./stex-rHcFYcA0.js`).then(e=>X(e.stex)),[])}}),A.of({name:`SystemVerilog`,extensions:[`v`,`sv`,`svh`],load(){return Y(()=>import(`./verilog-BJOO83gk.js`).then(e=>X(e.verilog)),[])}}),A.of({name:`Tcl`,extensions:[`tcl`],load(){return Y(()=>import(`./tcl-Dlzy1mPk.js`).then(e=>X(e.tcl)),[])}}),A.of({name:`Textile`,extensions:[`textile`],load(){return Y(()=>import(`./textile-Dy5rFZe5.js`).then(e=>X(e.textile)),[])}}),A.of({name:`TiddlyWiki`,load(){return Y(()=>import(`./tiddlywiki-DQP1OymS.js`).then(e=>X(e.tiddlyWiki)),[])}}),A.of({name:`Tiki wiki`,load(){return Y(()=>import(`./tiki-0vOj3DB2.js`).then(e=>X(e.tiki)),[])}}),A.of({name:`TOML`,extensions:[`toml`],load(){return Y(()=>import(`./toml-DEltN0lI.js`).then(e=>X(e.toml)),[])}}),A.of({name:`Troff`,extensions:[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`],load(){return Y(()=>import(`./troff-CRbBpEqY.js`).then(e=>X(e.troff)),[])}}),A.of({name:`TTCN`,extensions:[`ttcn`,`ttcn3`,`ttcnpp`],load(){return Y(()=>import(`./ttcn-M5q1nLKg.js`).then(e=>X(e.ttcn)),[])}}),A.of({name:`TTCN_CFG`,extensions:[`cfg`],load(){return Y(()=>import(`./ttcn-cfg-Rmw9NWq9.js`).then(e=>X(e.ttcnCfg)),[])}}),A.of({name:`Turtle`,extensions:[`ttl`],load(){return Y(()=>import(`./turtle-BCDWhJK0.js`).then(e=>X(e.turtle)),[])}}),A.of({name:`Web IDL`,extensions:[`webidl`],load(){return Y(()=>import(`./webidl-Ddy6hbV6.js`).then(e=>X(e.webIDL)),[])}}),A.of({name:`VB.NET`,extensions:[`vb`],load(){return Y(()=>import(`./vb-QQ7LGlOz.js`).then(e=>X(e.vb)),[])}}),A.of({name:`VBScript`,extensions:[`vbs`],load(){return Y(()=>import(`./vbscript-BiSEdUzz.js`).then(e=>X(e.vbScript)),[])}}),A.of({name:`Velocity`,extensions:[`vtl`],load(){return Y(()=>import(`./velocity-CzMg5_6w.js`).then(e=>X(e.velocity)),[])}}),A.of({name:`Verilog`,extensions:[`v`],load(){return Y(()=>import(`./verilog-BJOO83gk.js`).then(e=>X(e.verilog)),[])}}),A.of({name:`VHDL`,extensions:[`vhd`,`vhdl`],load(){return Y(()=>import(`./vhdl-ed4zAZAA.js`).then(e=>X(e.vhdl)),[])}}),A.of({name:`XQuery`,extensions:[`xy`,`xquery`,`xq`,`xqm`,`xqy`],load(){return Y(()=>import(`./xquery-Bw1zwhh6.js`).then(e=>X(e.xQuery)),[])}}),A.of({name:`Yacas`,extensions:[`ys`],load(){return Y(()=>import(`./yacas-DZdTXy3s.js`).then(e=>X(e.yacas)),[])}}),A.of({name:`Z80`,extensions:[`z80`],load(){return Y(()=>import(`./z80-DMG02_YV.js`).then(e=>X(e.z80)),[])}}),A.of({name:`MscGen`,extensions:[`mscgen`,`mscin`,`msc`],load(){return Y(()=>import(`./mscgen-C5pXQCMK.js`).then(e=>X(e.mscgen)),[])}}),A.of({name:`Xù`,extensions:[`xu`],load(){return Y(()=>import(`./mscgen-C5pXQCMK.js`).then(e=>X(e.xu)),[])}}),A.of({name:`MsGenny`,extensions:[`msgenny`],load(){return Y(()=>import(`./mscgen-C5pXQCMK.js`).then(e=>X(e.msgenny)),[])}}),A.of({name:`Vue`,extensions:[`vue`],load(){return Y(()=>import(`./dist-BGqK-7Ep.js`).then(e=>e.vue()),__vite__mapDeps([28,7,4,5,1,2,8]))}}),A.of({name:`Angular Template`,load(){return Y(()=>import(`./dist-ecTM1pdv.js`).then(e=>e.angular()),__vite__mapDeps([29,7,4,5,1,2,8]))}})],iI=`#2e3440`,aI=`#3b4252`,oI=`#434c5e`,sI=`#4c566a`,cI=`#e5e9f0`,lI=`#eceff4`,uI=`#8fbcbb`,dI=`#88c0d0`,kpe=`#81a1c1`,fI=`#5e81ac`,Ape=`#bf616a`,pI=`#d08770`,mI=`#ebcb8b`,hI=`#a3be8c`,jpe=`#b48ead`,gI=`#d30102`,_I=lI,vI=_I,Mpe=`#ffffff`,yI=aI,Npe=_I,bI=aI,Ppe=[f.theme({"&":{color:iI,backgroundColor:Mpe},".cm-content":{caretColor:bI},".cm-cursor, .cm-dropCursor":{borderLeftColor:bI},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Npe},".cm-panels":{backgroundColor:_I,color:sI},".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 ${sI}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:cI},".cm-activeLine":{backgroundColor:vI},".cm-selectionMatch":{backgroundColor:cI},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${sI}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:lI},".cm-gutters":{backgroundColor:lI,color:iI,border:`none`},".cm-activeLineGutter":{backgroundColor:vI},".cm-foldPlaceholder":{backgroundColor:`transparent`,border:`none`,color:`#ddd`},".cm-tooltip":{border:`none`,backgroundColor:yI},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:`transparent`,borderBottomColor:`transparent`},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:yI,borderBottomColor:yI},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:vI,color:sI}}},{dark:!1}),i(ye.define([{tag:v.keyword,color:fI},{tag:[v.name,v.deleted,v.character,v.propertyName,v.macroName],color:pI},{tag:[v.variableName],color:pI},{tag:[v.function(v.variableName)],color:fI},{tag:[v.labelName],color:kpe},{tag:[v.color,v.constant(v.name),v.standard(v.name)],color:fI},{tag:[v.definition(v.name),v.separator],color:hI},{tag:[v.brace],color:uI},{tag:[v.annotation],color:gI},{tag:[v.number,v.changed,v.annotation,v.modifier,v.self,v.namespace],color:dI},{tag:[v.typeName,v.className],color:mI},{tag:[v.operator,v.operatorKeyword],color:hI},{tag:[v.tagName],color:jpe},{tag:[v.squareBracket],color:Ape},{tag:[v.angleBracket],color:pI},{tag:[v.attributeName],color:mI},{tag:[v.regexp],color:fI},{tag:[v.quote],color:aI},{tag:[v.string],color:pI},{tag:v.link,color:uI,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[v.url,v.escape,v.special(v.string)],color:pI},{tag:[v.meta],color:dI},{tag:[v.comment],color:oI,fontStyle:`italic`},{tag:v.strong,fontWeight:`bold`,color:fI},{tag:v.emphasis,fontStyle:`italic`,color:fI},{tag:v.strikethrough,textDecoration:`line-through`},{tag:v.heading,fontWeight:`bold`,color:fI},{tag:v.special(v.heading1),fontWeight:`bold`,color:fI},{tag:v.heading1,fontWeight:`bold`,color:fI},{tag:[v.heading2,v.heading3,v.heading4],fontWeight:`bold`,color:fI},{tag:[v.heading5,v.heading6],color:fI},{tag:[v.atom,v.bool,v.special(v.variableName)],color:pI},{tag:[v.processingInstruction,v.inserted],color:uI},{tag:[v.contentSeparator],color:mI},{tag:v.invalid,color:oI,borderBottom:`1px dotted ${gI}`}]))],xI=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,SI=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(xI(e)):xI,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 se(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=y(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=a(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`&&(SI.prototype[Symbol.iterator]=function(){return this});var CI={from:-1,to:-1,match:/.*/.exec(``),precise:!0},wI=`gm`+(/x/.unicode==null?``:`u`),TI=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=CI,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new OI(e,t,n,r,i);this.re=new RegExp(t,wI+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter();let a=e.lineAt(r);this.curLineStart=a.from,this.matchPos=kI(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=kI(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}}},EI=new WeakMap,DI=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=EI.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return EI.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)),EI.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},OI=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=CI,this.matchPos=kI(e,r),this.re=new RegExp(t,wI+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=DI.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=kI(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=DI.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(TI.prototype[Symbol.iterator]=OI.prototype[Symbol.iterator]=function(){return this});function Fpe(e){try{return new RegExp(e,wI),!0}catch{return!1}}function kI(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 Ipe=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=le(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 p=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),m=k.cursor(p.from+Math.max(0,Math.min(u,p.length)));e.dispatch({effects:[r,f.scrollIntoView(m.from,{y:`center`})],selection:m})}),!0},Lpe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},AI=Oe.define({combine(e){return oe(e,Lpe,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Rpe(e){let t=[Upe,Hpe];return e&&t.push(AI.of(e)),t}var zpe=T.mark({class:`cm-selectionMatch`}),Bpe=T.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function jI(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=L.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=L.Word)}function Vpe(e,t,n,r){return e(t.sliceDoc(n,n+1))==L.Word&&e(t.sliceDoc(r-1,r))==L.Word}var Hpe=ge.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(AI),{state:n}=e,r=n.selection;if(r.ranges.length>1)return T.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return T.none;let e=n.wordAt(i.head);if(!e)return T.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 T.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(jI(o,n,i.from,i.to)&&Vpe(o,n,i.from,i.to)))return T.none}else if(a=n.sliceDoc(i.from,i.to),!a)return T.none}let s=[];for(let r of e.visibleRanges){let e=new SI(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||jI(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Bpe.range(r,a)):(r>=i.to||a<=i.from)&&s.push(zpe.range(r,a)),s.length>t.maxMatches))return T.none}}return T.set(s)}},{decorations:e=>e.decorations}),Upe=f.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Wpe=({state:e,dispatch:t})=>{let{selection:n}=e,r=k.create(n.ranges.map(t=>e.wordAt(t.head)||k.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function Gpe(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 SI(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new SI(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 Kpe=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Wpe({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=Gpe(e,r);return i?(t(e.update({selection:e.selection.addRange(k.range(i.from,i.to),!1),effects:f.scrollIntoView(i.to)})),!0):!1},MI=Oe.define({combine(e){return oe(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new ome(e),scrollToMatch:e=>f.scrollIntoView(e)})}}),NI=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||Fpe(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`?`
|
|
127
|
+
`},vle=0,vO=[];function yle(e){var t=R.useRef([]),n=R.useRef([0,0]),r=R.useRef(),i=R.useState(vle++)[0],a=R.useState(iO)[0],o=R.useRef(e);R.useEffect(function(){o.current=e},[e]),R.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Bce([e.lockRef.current],(e.shards||[]).map(_O),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=R.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=hO(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=fO(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=fO(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return hle(h,t,e,h===`h`?s:c,!0)},[]),c=R.useCallback(function(e){var n=e;if(!(!vO.length||vO[vO.length-1]!==a)){var r=`deltaY`in n?gO(n):hO(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&gle(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(_O).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=R.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:ble(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=R.useCallback(function(e){n.current=hO(e),r.current=void 0},[]),d=R.useCallback(function(t){l(t.type,gO(t),t.target,s(t,e.lockRef.current))},[]),f=R.useCallback(function(t){l(t.type,hO(t),t.target,s(t,e.lockRef.current))},[]);R.useEffect(function(){return vO.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,uO),document.addEventListener(`touchmove`,c,uO),document.addEventListener(`touchstart`,u,uO),function(){vO=vO.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,uO),document.removeEventListener(`touchmove`,c,uO),document.removeEventListener(`touchstart`,u,uO)}},[]);var p=e.removeScrollBar,m=e.inert;return R.createElement(R.Fragment,null,m?R.createElement(a,{styles:_le(i)}):null,p?R.createElement(cle,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ble(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var xle=Yce(eO,yle),yO=R.forwardRef(function(e,t){return R.createElement(nO,qD({},e,{ref:t,sideCar:xle}))});yO.classNames=nO.classNames;var bO=`Popover`,[xO,Sle]=zT(bO,[CD]),SO=CD(),[Cle,CO]=xO(bO),wO=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=SO(t),c=R.useRef(null),[l,u]=R.useState(!1),[d,f]=BD({prop:r,defaultProp:i??!1,onChange:a,caller:bO});return(0,z.jsx)(ND,{...s,children:(0,z.jsx)(Cle,{scope:t,contentId:lE(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:R.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:R.useCallback(()=>u(!0),[]),onCustomAnchorRemove:R.useCallback(()=>u(!1),[]),modal:o,children:n})})};wO.displayName=bO;var TO=`PopoverAnchor`,EO=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=CO(TO,n),a=SO(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return R.useEffect(()=>(o(),()=>s()),[o,s]),(0,z.jsx)(PD,{...a,...r,ref:t})});EO.displayName=TO;var DO=`PopoverTrigger`,OO=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=CO(DO,n),a=SO(n),o=RT(t,i.triggerRef),s=(0,z.jsx)(HT.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":IO(i.open),...r,ref:o,onClick:FT(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,z.jsx)(PD,{asChild:!0,...a,children:s})});OO.displayName=DO;var kO=`PopoverPortal`,[wle,Tle]=xO(kO,{forceMount:void 0}),AO=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=CO(kO,t);return(0,z.jsx)(wle,{scope:t,forceMount:n,children:(0,z.jsx)(RD,{present:n||a.open,children:(0,z.jsx)(LD,{asChild:!0,container:i,children:r})})})};AO.displayName=kO;var jO=`PopoverContent`,MO=R.forwardRef((e,t)=>{let n=Tle(jO,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=CO(jO,e.__scopePopover);return(0,z.jsx)(RD,{present:r||a.open,children:a.modal?(0,z.jsx)(Dle,{...i,ref:t}):(0,z.jsx)(Ole,{...i,ref:t})})});MO.displayName=jO;var Ele=BT(`PopoverContent.RemoveScroll`),Dle=R.forwardRef((e,t)=>{let n=CO(jO,e.__scopePopover),r=R.useRef(null),i=RT(t,r),a=R.useRef(!1);return R.useEffect(()=>{let e=r.current;if(e)return KD(e)},[]),(0,z.jsx)(yO,{as:Ele,allowPinchZoom:!0,children:(0,z.jsx)(NO,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:FT(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:FT(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:FT(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),Ole=R.forwardRef((e,t)=>{let n=CO(jO,e.__scopePopover),r=R.useRef(!1),i=R.useRef(!1);return(0,z.jsx)(NO,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),NO=R.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=CO(jO,n),p=SO(n);return ZT(),(0,z.jsx)(nE,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,z.jsx)(qT,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,z.jsx)(FD,{"data-state":IO(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),PO=`PopoverClose`,kle=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=CO(PO,n);return(0,z.jsx)(HT.button,{type:`button`,...r,ref:t,onClick:FT(e.onClick,()=>i.onOpenChange(!1))})});kle.displayName=PO;var Ale=`PopoverArrow`,FO=R.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=SO(n);return(0,z.jsx)(ID,{...i,...r,ref:t})});FO.displayName=Ale;function IO(e){return e?`open`:`closed`}var LO=wO,jle=EO,RO=AO,Mle=MO,zO=FO;function BO(e){let t=e+`CollectionProvider`,[n,r]=zT(t),[i,a]=n(t,{collectionRef:{current:null},itemMap:new Map}),o=e=>{let{scope:t,children:n}=e,r=R.useRef(null),a=R.useRef(new Map).current;return(0,z.jsx)(i,{scope:t,itemMap:a,collectionRef:r,children:n})};o.displayName=t;let s=e+`CollectionSlot`,c=BT(s),l=R.forwardRef((e,t)=>{let{scope:n,children:r}=e;return(0,z.jsx)(c,{ref:RT(t,a(s,n).collectionRef),children:r})});l.displayName=s;let u=e+`CollectionItemSlot`,d=`data-radix-collection-item`,f=BT(u),p=R.forwardRef((e,t)=>{let{scope:n,children:r,...i}=e,o=R.useRef(null),s=RT(t,o),c=a(u,n);return R.useEffect(()=>(c.itemMap.set(o,{ref:o,...i}),()=>void c.itemMap.delete(o))),(0,z.jsx)(f,{[d]:``,ref:s,children:r})});p.displayName=u;function m(t){let n=a(e+`CollectionConsumer`,t);return R.useCallback(()=>{let e=n.collectionRef.current;if(!e)return[];let t=Array.from(e.querySelectorAll(`[${d}]`));return Array.from(n.itemMap.values()).sort((e,n)=>t.indexOf(e.ref.current)-t.indexOf(n.ref.current))},[n.collectionRef,n.itemMap])}return[{Provider:o,Slot:l,ItemSlot:p},m,r]}var Nle=R.createContext(void 0);function VO(e){let t=R.useContext(Nle);return e||t||`ltr`}var HO=`rovingFocusGroup.onEntryFocus`,Ple={bubbles:!1,cancelable:!0},UO=`RovingFocusGroup`,[WO,GO,Fle]=BO(UO),[Ile,KO]=zT(UO,[Fle]),[Lle,Rle]=Ile(UO),qO=R.forwardRef((e,t)=>(0,z.jsx)(WO.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,z.jsx)(WO.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,z.jsx)(zle,{...e,ref:t})})}));qO.displayName=UO;var zle=R.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=R.useRef(null),p=RT(t,f),m=VO(a),[h,g]=BD({prop:o,defaultProp:s??null,onChange:c,caller:UO}),[_,v]=R.useState(!1),y=UT(l),b=GO(n),x=R.useRef(!1),[S,C]=R.useState(0);return R.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(HO,y),()=>e.removeEventListener(HO,y)},[y]),(0,z.jsx)(Lle,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:R.useCallback(e=>g(e),[g]),onItemShiftTab:R.useCallback(()=>v(!0),[]),onFocusableItemAdd:R.useCallback(()=>C(e=>e+1),[]),onFocusableItemRemove:R.useCallback(()=>C(e=>e-1),[]),children:(0,z.jsx)(HT.div,{tabIndex:_||S===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:FT(e.onMouseDown,()=>{x.current=!0}),onFocus:FT(e.onFocus,e=>{let t=!x.current;if(e.target===e.currentTarget&&t&&!_){let t=new CustomEvent(HO,Ple);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=b().filter(e=>e.focusable);QO([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}x.current=!1}),onBlur:FT(e.onBlur,()=>v(!1))})})}),JO=`RovingFocusGroupItem`,YO=R.forwardRef((e,t)=>{let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=lE(),l=a||c,u=Rle(JO,n),d=u.currentTabStopId===l,f=GO(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u;return R.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),(0,z.jsx)(WO.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,z.jsx)(HT.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:FT(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:FT(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:FT(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=ZO(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?$O(n,r+1):n.slice(r+1)}setTimeout(()=>QO(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})});YO.displayName=JO;var Ble={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function XO(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}function ZO(e,t,n){let r=XO(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return Ble[r]}function QO(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function $O(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ek=qO,tk=YO,nk=`Separator`,rk=`horizontal`,ik=[`horizontal`,`vertical`],ak=R.forwardRef((e,t)=>{let{decorative:n,orientation:r=rk,...i}=e,a=ok(r)?r:rk,o=n?{role:`none`}:{"aria-orientation":a===`vertical`?a:void 0,role:`separator`};return(0,z.jsx)(HT.div,{"data-orientation":a,...o,...i,ref:t})});ak.displayName=nk;function ok(e){return ik.includes(e)}var sk=ak,ck=`Toggle`,lk=R.forwardRef((e,t)=>{let{pressed:n,defaultPressed:r,onPressedChange:i,...a}=e,[o,s]=BD({prop:n,onChange:i,defaultProp:r??!1,caller:ck});return(0,z.jsx)(HT.button,{type:`button`,"aria-pressed":o,"data-state":o?`on`:`off`,"data-disabled":e.disabled?``:void 0,...a,ref:t,onClick:FT(e.onClick,()=>{e.disabled||s(!o)})})});lk.displayName=ck;var uk=`ToggleGroup`,[dk,fk]=zT(uk,[KO]),pk=KO(),mk=R.forwardRef((e,t)=>{let{type:n,...r}=e;if(n===`single`)return(0,z.jsx)(_k,{...r,ref:t});if(n===`multiple`)return(0,z.jsx)(vk,{...r,ref:t});throw Error(`Missing prop \`type\` expected on \`${uk}\``)});mk.displayName=uk;var[hk,gk]=dk(uk),_k=R.forwardRef((e,t)=>{let{value:n,defaultValue:r,onValueChange:i=()=>{},...a}=e,[o,s]=BD({prop:n,defaultProp:r??``,onChange:i,caller:uk});return(0,z.jsx)(hk,{scope:e.__scopeToggleGroup,type:`single`,value:R.useMemo(()=>o?[o]:[],[o]),onItemActivate:s,onItemDeactivate:R.useCallback(()=>s(``),[s]),children:(0,z.jsx)(xk,{...a,ref:t})})}),vk=R.forwardRef((e,t)=>{let{value:n,defaultValue:r,onValueChange:i=()=>{},...a}=e,[o,s]=BD({prop:n,defaultProp:r??[],onChange:i,caller:uk}),c=R.useCallback(e=>s((t=[])=>[...t,e]),[s]),l=R.useCallback(e=>s((t=[])=>t.filter(t=>t!==e)),[s]);return(0,z.jsx)(hk,{scope:e.__scopeToggleGroup,type:`multiple`,value:o,onItemActivate:c,onItemDeactivate:l,children:(0,z.jsx)(xk,{...a,ref:t})})});mk.displayName=uk;var[yk,bk]=dk(uk),xk=R.forwardRef((e,t)=>{let{__scopeToggleGroup:n,disabled:r=!1,rovingFocus:i=!0,orientation:a,dir:o,loop:s=!0,...c}=e,l=pk(n),u=VO(o),d={role:`group`,dir:u,...c};return(0,z.jsx)(yk,{scope:n,rovingFocus:i,disabled:r,children:i?(0,z.jsx)(ek,{asChild:!0,...l,orientation:a,dir:u,loop:s,children:(0,z.jsx)(HT.div,{...d,ref:t})}):(0,z.jsx)(HT.div,{...d,ref:t})})}),Sk=`ToggleGroupItem`,Ck=R.forwardRef((e,t)=>{let n=gk(Sk,e.__scopeToggleGroup),r=bk(Sk,e.__scopeToggleGroup),i=pk(e.__scopeToggleGroup),a=n.value.includes(e.value),o=r.disabled||e.disabled,s={...e,pressed:a,disabled:o},c=R.useRef(null);return r.rovingFocus?(0,z.jsx)(tk,{asChild:!0,...i,focusable:!o,active:a,ref:c,children:(0,z.jsx)(wk,{...s,ref:t})}):(0,z.jsx)(wk,{...s,ref:t})});Ck.displayName=Sk;var wk=R.forwardRef((e,t)=>{let{__scopeToggleGroup:n,value:r,...i}=e,a=gk(Sk,n),o={role:`radio`,"aria-checked":e.pressed,"aria-pressed":void 0};return(0,z.jsx)(lk,{...a.type===`single`?o:void 0,...i,ref:t,onPressedChange:e=>{e?a.onItemActivate(r):a.onItemDeactivate(r)}})}),Tk=mk,Ek=Ck,Dk=`Toolbar`,[Ok,Vle]=zT(Dk,[KO,fk]),kk=KO(),Ak=fk(),[jk,Mk]=Ok(Dk),Nk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,orientation:r=`horizontal`,dir:i,loop:a=!0,...o}=e,s=kk(n),c=VO(i);return(0,z.jsx)(jk,{scope:n,orientation:r,dir:c,children:(0,z.jsx)(ek,{asChild:!0,...s,orientation:r,dir:c,loop:a,children:(0,z.jsx)(HT.div,{role:`toolbar`,"aria-orientation":r,dir:c,...o,ref:t})})})});Nk.displayName=Dk;var Pk=`ToolbarSeparator`,Fk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=Mk(Pk,n);return(0,z.jsx)(sk,{orientation:i.orientation===`horizontal`?`vertical`:`horizontal`,...r,ref:t})});Fk.displayName=Pk;var Ik=`ToolbarButton`,Lk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=kk(n);return(0,z.jsx)(tk,{asChild:!0,...i,focusable:!e.disabled,children:(0,z.jsx)(HT.button,{type:`button`,...r,ref:t})})});Lk.displayName=Ik;var Rk=`ToolbarLink`,zk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=kk(n);return(0,z.jsx)(tk,{asChild:!0,...i,focusable:!0,children:(0,z.jsx)(HT.a,{...r,ref:t,onKeyDown:FT(e.onKeyDown,e=>{e.key===` `&&e.currentTarget.click()})})})});zk.displayName=Rk;var Bk=`ToolbarToggleGroup`,Vk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=Mk(Bk,n),a=Ak(n);return(0,z.jsx)(Tk,{"data-orientation":i.orientation,dir:i.dir,...a,...r,ref:t,rovingFocus:!1})});Vk.displayName=Bk;var Hk=`ToolbarToggleItem`,Uk=R.forwardRef((e,t)=>{let{__scopeToolbar:n,...r}=e,i=Ak(n);return(0,z.jsx)(Lk,{asChild:!0,__scopeToolbar:e.__scopeToolbar,children:(0,z.jsx)(Ek,{...i,...r,ref:t})})});Uk.displayName=Hk;var Wk=Nk,Gk=Fk,Kk=Lk,qk=Vk,Jk=Uk;function Yk(e,t){return e===null||e===t?!1:e.dataset.editorDialog!==void 0||e.dataset.toolbarItem!==void 0||e.dataset.editorDropdown?!0:Yk(e.parentElement,t)}function Xk(){let e=[...Array(256).keys()].map(e=>e.toString(16).padStart(2,`0`)),t=crypto.getRandomValues(new Uint8Array(16));return t[6]=t[6]&15|64,t[8]=t[8]&63|128,[...t.entries()].map(([t,n])=>[4,6,8,10].includes(t)?`-${e[n]}`:e[n]).join(``)}var Zk=e=>e===0?`th`:`td`,Qk={center:mw.centeredCell,left:mw.leftAlignedCell,right:mw.rightAlignedCell},$k=({mdastNode:e,parentEditor:t,lexicalTable:n})=>{let[r,i]=R.useState(null),[a,o]=Hl(NC,WS),s=R.useMemo(()=>e=>(e.__cacheKey??=Xk(),e.__cacheKey),[]),c=R.useCallback(e=>{let r=n.getColCount();if(e===null){i(null);return}let[a,o]=e;if(a>r-1&&(a=0,o++),a<0&&(a=r-1,--o),o>n.getRowCount()-1){i(null),t.update(()=>{if(n.getLatest().getNextSibling())n.getLatest().selectNext();else{let e=nh();n.insertAfter(e),e.select()}});return}if(o<0){i(null),t.update(()=>{n.getLatest().selectPrevious()});return}i([a,o])},[n,t]);R.useEffect(()=>{n.focusEmitter.subscribe(c)},[n,c]);let l=R.useCallback(e=>{e.preventDefault(),t.update(()=>{n.addRowToBottom(),i([0,n.getRowCount()])})},[t,n]),u=R.useCallback(e=>{e.preventDefault(),t.update(()=>{n.addColumnToRight(),i([n.getColCount(),0])})},[t,n]),[d,f]=R.useState([-1,-1]),p=R.useCallback(e=>{let t=e.target;for(;t&&![`TH`,`TD`].includes(t.tagName);){if(t===e.currentTarget)return;t=t.parentElement}if(t===null)return;let n=t.parentElement;f([n.parentElement.tagName===`TFOOT`?-1:Array.from(n.children).indexOf(t),t.tagName===`TH`?-1:Array.from(n.parentElement.children).indexOf(n)])},[]),m=rw();return R.createElement(`table`,{className:mw.tableEditor,onMouseOver:p,onMouseLeave:()=>{f([-1,-1])}},R.createElement(`colgroup`,null,o?null:R.createElement(`col`,null),Array.from({length:e.children[0].children.length},(t,n)=>{let r=Qk[(e.align??[])[n]??`left`];return R.createElement(`col`,{key:n,className:r})}),o?null:R.createElement(`col`,null)),o||R.createElement(`thead`,null,R.createElement(`tr`,null,R.createElement(`th`,{className:mw.tableToolsColumn}),Array.from({length:e.children[0].children.length},(r,i)=>R.createElement(`th`,{key:i,"data-tool-cell":!0},R.createElement(nA,{setActiveCellWithBoundaries:c,parentEditor:t,colIndex:i,highlightedCoordinates:d,lexicalTable:n,align:(e.align??[])[i]}))),R.createElement(`th`,{className:mw.tableToolsColumn,"data-tool-cell":!0},R.createElement(`button`,{className:mw.iconButton,type:`button`,title:m(`table.deleteTable`,`Delete table`),onClick:e=>{e.preventDefault(),t.update(()=>{n.selectNext(),n.remove()})}},a(`delete_small`))))),R.createElement(`tbody`,null,e.children.map((i,l)=>{let f=Zk(l);return R.createElement(`tr`,{key:l},o||R.createElement(f,{className:mw.toolCell,"data-tool-cell":!0},R.createElement(rA,{setActiveCellWithBoundaries:c,parentEditor:t,rowIndex:l,highlightedCoordinates:d,lexicalTable:n})),i.children.map((i,a)=>R.createElement(eA,{align:e.align?.[a],key:s(i),contents:i.children,setActiveCell:c,rowIndex:l,colIndex:a,lexicalTable:n,parentEditor:t,activeCell:o?[-1,-1]:r})),o||l===0&&R.createElement(`th`,{rowSpan:n.getRowCount(),"data-tool-cell":!0},R.createElement(`button`,{type:`button`,className:mw.addColumnButton,onClick:u},a(`add_column`))))})),o||R.createElement(`tfoot`,null,R.createElement(`tr`,null,R.createElement(`th`,null),R.createElement(`th`,{colSpan:n.getColCount(),"data-tool-cell":!0},R.createElement(`button`,{type:`button`,className:mw.addRowButton,onClick:l},a(`add_row`))),R.createElement(`th`,null))))},eA=({align:e,...t})=>{let{activeCell:n,setActiveCell:r}=t,i=!!(n&&n[0]===t.colIndex&&n[1]===t.rowIndex),a=Qk[e??`left`],o=Zk(t.rowIndex);return R.createElement(o,{className:a,"data-active":i,onClick:()=>{r([t.colIndex,t.rowIndex])}},R.createElement(tA,{...t,focus:i}))},tA=({focus:e,setActiveCell:t,parentEditor:n,lexicalTable:r,contents:i,colIndex:a,rowIndex:o})=>{let[s,c,l,u,d,f,p,m,h]=Hl(iC,cC,aC,fC,pC,mC,dC,BS,GC),[g]=R.useState(()=>{let e=ah({nodes:l,theme:RS,namespace:`TableCellEditor`});return e.update(()=>{bS({root:Ih(),mdastRoot:{type:`root`,children:[{type:`paragraph`,children:i}]},visitors:s,jsxComponentDescriptors:u,directiveDescriptors:d,codeBlockEditorDescriptors:f})}),e}),_=R.useCallback(e=>{g.getEditorState().read(()=>{let e=jx({root:Ih(),jsxComponentDescriptors:u,visitors:c,jsxIsAvailable:p});n.update(()=>{r.updateCellContents(a,o,e.children[0].children)},{discrete:!0}),n.dispatchCommand(zS,void 0)}),t(e)},[a,g,c,u,p,r,n,o,t]);return R.useEffect(()=>U_(g.registerCommand(vf,e=>(e.preventDefault(),_(e.shiftKey?[a-1,o]:[a+1,o]),!0),4),g.registerCommand(Pf,()=>(t([a,o]),!1),1),g.registerCommand(pf,e=>(e?.preventDefault(),_(e?.shiftKey?[a,o-1]:[a,o+1]),!0),4),g.registerCommand(Ff,e=>{let t=e.relatedTarget;return Yk(t,m.getRootElement())?!1:(_(null),!0)},0),g.registerCommand(zS,()=>(_(null),!0),0)),[a,g,m,o,_,t]),R.useEffect(()=>{e&&g.focus()},[e,g]),R.createElement(Joe,{initialEditor:g},R.createElement(pw,{contentEditable:R.createElement(sw,null),placeholder:R.createElement(`div`,null),ErrorBoundary:uw}),h.map((e,t)=>R.createElement(e,{key:t})),R.createElement(cv,null))},nA=({parentEditor:e,highlightedCoordinates:t,align:n,lexicalTable:r,colIndex:i,setActiveCellWithBoundaries:a})=>{let[o,s]=Hl(hC,NC),c=R.useCallback(t=>{e.update(()=>{r.insertColumnAt(t)}),a([t,0])},[e,r,a]),l=R.useCallback(t=>{e.update(()=>{r.deleteColumnAt(t)})},[e,r]),u=R.useCallback((t,n)=>{e.update(()=>{r.setColumnAlign(t,n)})},[e,r]),d=rw();return R.createElement(LO,null,R.createElement(OO,{className:mw.tableColumnEditorTrigger,"data-active":t[0]===i+1,title:d(`table.columnMenu`,`Column menu`)},s(`more_horiz`)),R.createElement(RO,{container:o?.current},R.createElement(MO,{className:(0,rT.default)(mw.tableColumnEditorPopoverContent),onOpenAutoFocus:e=>{e.preventDefault()},sideOffset:5,side:`top`},R.createElement(Wk,{className:mw.tableColumnEditorToolbar},R.createElement(qk,{className:mw.toggleGroupRoot,onValueChange:e=>{u(i,e)},value:n??`left`,type:`single`,"aria-label":d(`table.textAlignment`,`Text alignment`)},R.createElement(Jk,{value:`left`,title:d(`table.alignLeft`,`Align left`)},s(`format_align_left`)),R.createElement(Jk,{value:`center`,title:d(`table.alignCenter`,`Align center`)},s(`format_align_center`)),R.createElement(Jk,{value:`right`,title:d(`table.alignRight`,`Align right`)},s(`format_align_right`))),R.createElement(Gk,null),R.createElement(Kk,{onClick:c.bind(null,i),title:d(`table.insertColumnLeft`,`Insert a column to the left of this one`)},s(`insert_col_left`)),R.createElement(Kk,{onClick:c.bind(null,i+1),title:d(`table.insertColumnRight`,`Insert a column to the right of this one`)},s(`insert_col_right`)),R.createElement(Kk,{onClick:l.bind(null,i),title:d(`table.deleteColumn`,`Delete this column`)},s(`delete_small`))),R.createElement(zO,{className:mw.popoverArrow}))))},rA=({parentEditor:e,highlightedCoordinates:t,lexicalTable:n,rowIndex:r,setActiveCellWithBoundaries:i})=>{let[a,o]=Hl(hC,NC),s=R.useCallback(t=>{e.update(()=>{n.insertRowAt(t)}),i([0,t])},[e,n,i]),c=R.useCallback(t=>{e.update(()=>{n.deleteRowAt(t)})},[e,n]),l=rw();return R.createElement(LO,null,R.createElement(OO,{className:mw.tableColumnEditorTrigger,"data-active":t[1]===r,title:l(`table.rowMenu`,`Row menu`)},o(`more_horiz`)),R.createElement(RO,{container:a?.current},R.createElement(MO,{className:(0,rT.default)(mw.tableColumnEditorPopoverContent),onOpenAutoFocus:e=>{e.preventDefault()},sideOffset:5,side:`bottom`},R.createElement(Wk,{className:mw.tableColumnEditorToolbar},R.createElement(Kk,{onClick:s.bind(null,r),title:l(`table.insertRowAbove`,`Insert a row above this one`)},o(`insert_row_above`)),R.createElement(Kk,{onClick:s.bind(null,r+1),title:l(`table.insertRowBelow`,`Insert a row below this one`)},o(`insert_row_below`)),R.createElement(Kk,{onClick:c.bind(null,r),title:l(`table.deleteRow`,`Delete this row`)},o(`delete_small`))),R.createElement(zO,{className:mw.popoverArrow}))))},iA=Object.defineProperty,aA=(e,t,n)=>t in e?iA(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oA=(e,t,n)=>(aA(e,typeof t==`symbol`?t:t+``,n),n),sA={type:`tableCell`,children:[]};function cA(){let e=Yl;return{publish:t=>{e(t)},subscribe:t=>{e=t}}}var lA=class e extends Wm{constructor(e,t){super(t),oA(this,`__mdastNode`),oA(this,`focusEmitter`,cA()),this.__mdastNode=e??{type:`table`,children:[]}}static getType(){return`table`}static clone(t){return new e(structuredClone(t.__mdastNode),t.__key)}static importJSON(e){return dA(e.mdastNode)}static importDOM(){return{table:()=>({conversion:fA,priority:3})}}exportJSON(){return{mdastNode:structuredClone(this.__mdastNode),type:`table`,version:1}}getMdastNode(){return this.__mdastNode}getRowCount(){return this.__mdastNode.children.length}getColCount(){return this.__mdastNode.children[0]?.children.length||0}createDOM(){return document.createElement(`div`)}updateDOM(){return!1}updateCellContents(e,t,n){let r=this.getWritable().__mdastNode,i=r.children[t],a=i.children,o=a[e],s=Array.from(a),c={...o,children:n},l={...i,children:s};s[e]=c,r.children[t]=l}insertColumnAt(e){let t=this.getWritable().__mdastNode;for(let n=0;n<t.children.length;n++){let r=t.children[n],i=r.children,a=Array.from(i),o={...r,children:a};a.splice(e,0,structuredClone(sA)),t.children[n]=o}t.align&&t.align.length>0&&t.align.splice(e,0,`left`)}deleteColumnAt(e){let t=this.getWritable().__mdastNode;for(let n=0;n<t.children.length;n++){let r=t.children[n],i=r.children,a=Array.from(i),o={...r,children:a};a.splice(e,1),t.children[n]=o}}insertRowAt(e){let t=this.getWritable().__mdastNode,n={type:`tableRow`,children:Array.from({length:this.getColCount()},()=>structuredClone(sA))};t.children.splice(e,0,n)}deleteRowAt(e){this.getRowCount()===1?(this.selectNext(),this.remove()):this.getWritable().__mdastNode.children.splice(e,1)}addRowToBottom(){this.insertRowAt(this.getRowCount())}addColumnToRight(){this.insertColumnAt(this.getColCount())}setColumnAlign(e,t){let n=this.getWritable().__mdastNode;n.align??=[],n.align[e]=t}decorate(e){return R.createElement($k,{lexicalTable:this,mdastNode:this.__mdastNode,parentEditor:e})}select(e){this.focusEmitter.publish(e??[0,0])}isInline(){return!1}};function uA(e){return e instanceof lA}function dA(e){return new lA(e)}function fA(e){let t=e.querySelectorAll(`tr`);return{node:new lA({type:`table`,children:Array.from(t).map(e=>({type:`tableRow`,children:Array.from(e.querySelectorAll(`td, th`)).map(e=>({type:`tableCell`,children:[{type:`text`,value:e.textContent}]}))}))})}}var pA={testLexicalNode:uA,visitLexicalNode({actions:e,mdastParent:t,lexicalNode:n}){e.appendToParent(t,n.getMdastNode())}},mA={testNode:`table`,visitNode({mdastNode:e,lexicalParent:t}){t.append(dA(e))}};function hA(e=1,t=1){let n={type:`table`,children:[]};for(let r=0;r<e;r++){let e={type:`tableRow`,children:[]};for(let n=0;n<t;n++)e.children.push({type:`tableCell`,children:[]});n.children.push(e)}return n}var gA=Ll(e=>{e.link(e.pipe(gA,Wl(({rows:e,columns:t})=>()=>dA(hA(e,t)))),XC)}),_A=Xl({init(e,t){e.pubIn({[xC]:wT(),[bC]:OT(),[yC]:mA,[vC]:lA,[SC]:pA,[CC]:DT({tableCellPadding:t?.tableCellPadding??!0,tablePipeAlign:t?.tablePipeAlign??!0})})}}),vA={testNode:`link`,visitNode({mdastNode:e,actions:t}){t.addAndStepInto(gw(e.url,{title:e.title}))}},yA={testLexicalNode:_w,visitLexicalNode:({lexicalNode:e,actions:t})=>{t.addAndStepInto(`link`,{url:e.getURL(),title:e.getTitle()})}};function bA({validateUrl:e,attributes:t}){let[n]=eu();return(0,R.useEffect)((()=>{if(!n.hasNodes([hw]))throw Error(`LinkPlugin: LinkNode not registered on editor`);return U_(n.registerCommand(xw,(n=>{if(n===null)return Cw(n),!0;if(typeof n==`string`)return!(e!==void 0&&!e(n))&&(Cw(n,t),!0);{let{url:e,target:r,rel:i,title:a}=n;return Cw(e,{...t,rel:i,target:r,title:a}),!0}}),1),e===void 0?()=>{}:n.registerCommand(Qd,(r=>{let i=G();if(!W(i)||i.isCollapsed()||!$_(r,ClipboardEvent)||r.clipboardData===null)return!1;let a=r.clipboardData.getData(`text`);return!!e(a)&&!i.getNodes().some((e=>K(e)))&&(n.dispatchCommand(xw,{...t,url:a}),r.preventDefault(),!0)}),1))}),[n,e,t]),null}function xA(e,t=(e=>e)){return n=>{let r=e.exec(n);return r===null?null:{index:r.index,length:r[0].length,text:r[0],url:t(r[0])}}}function SA(e,t){for(let n=0;n<t.length;n++){let r=t[n](e);if(r)return r}return null}var CA=/[.,;\s]/;function wA(e){return CA.test(e)}function TA(e){return wA(e[e.length-1])}function EA(e){return wA(e[0])}function DA(e){let t=e.getPreviousSibling();return K(t)&&(t=t.getLastDescendant()),t===null||vp(t)||U(t)&&TA(t.getTextContent())}function OA(e){let t=e.getNextSibling();return K(t)&&(t=t.getFirstDescendant()),t===null||vp(t)||U(t)&&EA(t.getTextContent())}function kA(e,t,n,r){return(e>0?wA(n[e-1]):DA(r[0]))?t<n.length?wA(n[t]):OA(r[r.length-1]):!1}function AA(e,t,n){let r=[],i=[],a=[],o=0,s=0,c=[...e];for(;c.length>0;){let e=c[0],l=e.getTextContent().length,u=s;s+l<=t?(r.push(e),o+=l):u>=n?a.push(e):i.push(e),s+=l,c.shift()}return[o,r,i,a]}function jA(e,t,n,r){let i=yw(r.url,r.attributes);if(e.length===1){let a,o=e[0];t===0?[a,o]=o.splitText(n):[,a,o]=o.splitText(t,n);let s=Fp(r.text);return s.setFormat(a.getFormat()),s.setDetail(a.getDetail()),s.setStyle(a.getStyle()),i.append(s),a.replace(i),o}if(e.length>1){let r=e[0],a,o=r.getTextContent().length;t===0?a=r:[,a]=r.splitText(t);let s=[],c;for(let t=1;t<e.length;t++){let r=e[t],i=r.getTextContent().length,a=o;if(a<n)if(o+i<=n)s.push(r);else{let[e,t]=r.splitText(n-a);s.push(e),c=t}o+=i}let l=G(),u=l?l.getNodes().find(U):void 0,d=Fp(a.getTextContent());return d.setFormat(a.getFormat()),d.setDetail(a.getDetail()),d.setStyle(a.getStyle()),i.append(d,...s),u&&u===a&&(W(l)?d.select(l.anchor.offset,l.focus.offset):Kp(l)&&d.select(0,d.getTextContent().length)),a.replace(i),c}}function MA(e,t,n){let r=e.getChildren(),i=r.length;for(let t=0;t<i;t++){let i=r[t];if(!U(i)||!i.isSimpleText())return NA(e),void n(null,e.getURL())}let a=e.getTextContent(),o=SA(a,t);if(o===null||o.text!==a||!DA(e)||!OA(e))return NA(e),void n(null,e.getURL());let s=e.getURL();if(s!==o.url&&(e.setURL(o.url),n(o.url,s)),o.attributes){let t=e.getRel();t!==o.attributes.rel&&(e.setRel(o.attributes.rel||null),n(o.attributes.rel||null,t));let r=e.getTarget();r!==o.attributes.target&&(e.setTarget(o.attributes.target||null),n(o.attributes.target||null,r))}}function NA(e){let t=e.getChildren();for(let n=t.length-1;n>=0;n--)e.insertAfter(t[n]);return e.remove(),t.map((e=>e.getLatest()))}function PA(e,t,n){(0,R.useEffect)((()=>{e.hasNodes([vw])||function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(77);let r=(e,t)=>{n&&n(e,t)};return U_(e.registerNodeTransform(Ep,(e=>{let n=e.getParentOrThrow(),i=e.getPreviousSibling();bw(n)&&!n.getIsUnlinked()?MA(n,t,r):_w(n)||(e.isSimpleText()&&(EA(e.getTextContent())||!bw(i))&&(function(e,t,n){let r=[...e],i=r.map((e=>e.getTextContent())).join(``),a,o=i,s=0;for(;(a=SA(o,t))&&a!==null;){let e=a.index,t=e+a.length;if(kA(s+e,s+t,i,r)){let[i,,o,c]=AA(r,s+e,s+t),l=jA(o,s+e-i,s+t-i,a);r=l?[l,...c]:c,n(a.url,null),s=0}else s+=t;o=o.substring(t)}})(function(e){let t=[e],n=e.getNextSibling();for(;n!==null&&U(n)&&n.isSimpleText()&&(t.push(n),!/[\s]/.test(n.getTextContent()));)n=n.getNextSibling();return t}(e),t,r),(function(e,t,n){let r=e.getPreviousSibling(),i=e.getNextSibling(),a=e.getTextContent();var o;!bw(r)||r.getIsUnlinked()||EA(a)&&(o=a,!(r.isEmailURI()?/^\.[a-zA-Z]{2,}/.test(o):/^\.[a-zA-Z0-9]{1,}/.test(o)))||(r.append(e),MA(r,t,n),n(null,r.getURL())),!bw(i)||i.getIsUnlinked()||TA(a)||(NA(i),MA(i,t,n),n(null,i.getURL()))})(e,t,r))})),e.registerCommand(xw,(e=>{let t=G();return e!==null||!W(t)||t.extract().forEach((e=>{let t=e.getParent();bw(t)&&(t.setIsUnlinked(!t.getIsUnlinked()),t.markDirty())})),!1}),1))}),[e,t,n])}function FA({matchers:e,onChange:t}){let[n]=eu();return PA(n,e,t),null}var IA=[xA(/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/,e=>e.startsWith(`http`)?e:`https://${e}`),xA(/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/,e=>`mailto:${e}`)],LA=()=>R.createElement(FA,{matchers:IA}),RA=Il(!1),zA=Xl({init(e,t){let n=!!t?.disableAutoLink,r=t?.validateUrl?{validateUrl:t.validateUrl}:{},i=()=>R.createElement(R.Fragment,null,R.createElement(bA,{...r}),n?null:R.createElement(LA,null));e.pubIn({[ew]:`link`,[yC]:vA,[vC]:[hw,vw],[SC]:yA,[RA]:n,[WC]:i,[KC]:i,[BC]:i})}}),BA=e=>e.type===`checkbox`,VA=e=>e instanceof Date,HA=e=>e==null,UA=e=>typeof e==`object`,WA=e=>!HA(e)&&!Array.isArray(e)&&UA(e)&&!VA(e),GA=e=>WA(e)&&e.target?BA(e.target)?e.target.checked:e.target.value:e,KA=(e,t)=>t.split(`.`).some((t,n,r)=>!isNaN(Number(t))&&e.has(r.slice(0,n).join(`.`))),qA=e=>{let t=e.constructor&&e.constructor.prototype;return WA(t)&&t.hasOwnProperty(`isPrototypeOf`)},JA=typeof window<`u`&&window.HTMLElement!==void 0&&typeof document<`u`;function YA(e){if(e instanceof Date)return new Date(e);let t=typeof FileList<`u`&&e instanceof FileList;if(JA&&(e instanceof Blob||t))return e;let n=Array.isArray(e);if(!n&&!(WA(e)&&qA(e)))return e;let r=n?[]:Object.create(Object.getPrototypeOf(e));for(let t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=YA(e[t]));return r}var XA=e=>/^\w*$/.test(e),ZA=e=>e===void 0,QA=e=>Array.isArray(e)?e.filter(Boolean):[],$A=e=>QA(e.replace(/["|']|\]/g,``).split(/\.|\[/)),ej=(e,t,n)=>{if(!t||!WA(e))return n;let r=(XA(t)?[t]:$A(t)).reduce((e,t)=>HA(e)?void 0:e[t],e);return ZA(r)||r===e?ZA(e[t])?n:e[t]:r},tj=e=>typeof e==`boolean`,nj=e=>typeof e==`function`,rj=(e,t,n)=>{let r=-1,i=XA(t)?[t]:$A(t),a=i.length,o=a-1;for(;++r<a;){let t=i[r],a=n;if(r!==o){let n=e[t];a=WA(n)||Array.isArray(n)?n:isNaN(+i[r+1])?{}:[]}if(t===`__proto__`||t===`constructor`||t===`prototype`)return;e[t]=a,e=e[t]}},ij={BLUR:`blur`,FOCUS_OUT:`focusout`,CHANGE:`change`,SUBMIT:`submit`,TRIGGER:`trigger`,VALID:`valid`},aj={onBlur:`onBlur`,onChange:`onChange`,onSubmit:`onSubmit`,onTouched:`onTouched`,all:`all`},oj={max:`max`,min:`min`,maxLength:`maxLength`,minLength:`minLength`,pattern:`pattern`,required:`required`,validate:`validate`},sj=`form`,cj=`root`,lj=R.createContext(null);lj.displayName=`HookFormControlContext`;var uj=()=>R.useContext(lj),dj=(e,t,n,r=!0)=>{let i={defaultValues:t._defaultValues};for(let a in e)Object.defineProperty(i,a,{get:()=>{let i=a;return t._proxyFormState[i]!==aj.all&&(t._proxyFormState[i]=!r||aj.all),n&&(n[i]=!0),e[i]}});return i},fj=typeof window<`u`?R.useLayoutEffect:R.useEffect;function Hle(e){let t=uj(),{control:n=t,disabled:r,name:i,exact:a}=e||{},[o,s]=R.useState(n._formState),c=R.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return fj(()=>n._subscribe({name:i,formState:c.current,exact:a,callback:e=>{!r&&s({...n._formState,...e})}}),[i,r,a]),R.useEffect(()=>{c.current.isValid&&n._setValid(!0)},[n]),R.useMemo(()=>dj(o,n,c.current,!1),[o,n])}var pj=e=>typeof e==`string`,mj=(e,t,n,r,i)=>pj(e)?(r&&t.watch.add(e),ej(n,e,i)):Array.isArray(e)?e.map(e=>(r&&t.watch.add(e),ej(n,e))):(r&&(t.watchAll=!0),n),hj=e=>HA(e)||!UA(e);function gj(e,t,n=new WeakSet){if(e===t)return!0;if(hj(e)||hj(t))return Object.is(e,t);if(VA(e)&&VA(t))return Object.is(e.getTime(),t.getTime());let r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;if(n.has(e)||n.has(t))return!0;n.add(e),n.add(t);for(let i of r){let r=e[i];if(!(i in t))return!1;if(i!==`ref`){let e=t[i];if(VA(r)&&VA(e)||(WA(r)||Array.isArray(r))&&(WA(e)||Array.isArray(e))?!gj(r,e,n):!Object.is(r,e))return!1}}return!0}function Ule(e){let t=uj(),{control:n=t,name:r,defaultValue:i,disabled:a,exact:o,compute:s}=e||{},c=R.useRef(i),l=R.useRef(s),u=R.useRef(void 0),d=R.useRef(n),f=R.useRef(r);l.current=s;let[p,m]=R.useState(()=>{let e=n._getWatch(r,c.current);return l.current?l.current(e):e}),h=R.useCallback(e=>{let t=mj(r,n._names,e||n._formValues,!1,c.current);return l.current?l.current(t):t},[n._formValues,n._names,r]),g=R.useCallback(e=>{if(!a){let t=mj(r,n._names,e||n._formValues,!1,c.current);if(l.current){let e=l.current(t);gj(e,u.current)||(m(e),u.current=e)}else m(t)}},[n._formValues,n._names,a,r]);fj(()=>((d.current!==n||!gj(f.current,r))&&(d.current=n,f.current=r,g()),n._subscribe({name:r,formState:{values:!0},exact:o,callback:e=>{g(e.values)}})),[n,o,r,g]),R.useEffect(()=>n._removeUnmounted());let _=d.current!==n,v=f.current,y=R.useMemo(()=>{if(a)return null;let e=!_&&!gj(v,r);return _||e?h():null},[a,_,r,v,h]);return y===null?p:y}function Wle(e){let t=uj(),{name:n,disabled:r,control:i=t,shouldUnregister:a,defaultValue:o,exact:s=!0}=e,c=KA(i._names.array,n),l=Ule({control:i,name:n,defaultValue:R.useMemo(()=>ej(i._formValues,n,ej(i._defaultValues,n,o)),[i,n,o]),exact:s}),u=Hle({control:i,name:n,exact:s}),d=R.useRef(e),f=R.useRef(i.register(n,{...e.rules,value:l,...tj(e.disabled)?{disabled:e.disabled}:{}}));d.current=e;let p=R.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ej(u.errors,n)},isDirty:{enumerable:!0,get:()=>!!ej(u.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ej(u.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ej(u.validatingFields,n)},error:{enumerable:!0,get:()=>ej(u.errors,n)}}),[u,n]),m=R.useCallback(e=>f.current.onChange({target:{value:GA(e),name:n},type:ij.CHANGE}),[n]),h=R.useCallback(()=>f.current.onBlur({target:{value:ej(i._formValues,n),name:n},type:ij.BLUR}),[n,i._formValues]),g=R.useCallback(e=>{let t=ej(i._fields,n);t&&t._f&&e&&(t._f.ref={focus:()=>nj(e.focus)&&e.focus(),select:()=>nj(e.select)&&e.select(),setCustomValidity:t=>nj(e.setCustomValidity)&&e.setCustomValidity(t),reportValidity:()=>nj(e.reportValidity)&&e.reportValidity()})},[i._fields,n]),_=R.useMemo(()=>({name:n,value:l,...tj(r)||u.disabled?{disabled:u.disabled||r}:{},onChange:m,onBlur:h,ref:g}),[n,r,u.disabled,m,h,g,l]);return R.useEffect(()=>{let e=i._options.shouldUnregister||a;i.register(n,{...d.current.rules,...tj(d.current.disabled)?{disabled:d.current.disabled}:{}});let t=(e,t)=>{let n=ej(i._fields,e);n&&n._f&&(n._f.mount=t)};if(t(n,!0),e){let e=YA(ej(i._options.defaultValues,n,d.current.defaultValue));rj(i._defaultValues,n,e),ZA(ej(i._formValues,n))&&rj(i._formValues,n,e)}return!c&&i.register(n),()=>{(c?e&&!i._state.action:e)?i.unregister(n):t(n,!1)}},[n,i,c,a]),R.useEffect(()=>{i._setDisabledField({disabled:r,name:n})},[r,n,i]),R.useMemo(()=>({field:_,formState:u,fieldState:p}),[_,u,p])}var Gle=e=>e.render(Wle(e)),Kle=R.createContext(null);Kle.displayName=`HookFormContext`;var qle=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},_j=e=>Array.isArray(e)?e:[e],vj=()=>{let e=[];return{get observers(){return e},next:t=>{for(let n of e)n.next&&n.next(t)},subscribe:t=>(e.push(t),{unsubscribe:()=>{e=e.filter(e=>e!==t)}}),unsubscribe:()=>{e=[]}}};function yj(e,t){let n={};for(let r in e)if(e.hasOwnProperty(r)){let i=e[r],a=t[r];if(i&&WA(i)&&a){let e=yj(i,a);WA(e)&&(n[r]=e)}else e[r]&&(n[r]=a)}return n}var bj=e=>WA(e)&&!Object.keys(e).length,xj=e=>e.type===`file`,Sj=e=>{if(!JA)return!1;let t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Cj=e=>e.type===`select-multiple`,wj=e=>e.type===`radio`,Jle=e=>wj(e)||BA(e),Tj=e=>Sj(e)&&e.isConnected;function Yle(e,t){let n=t.slice(0,-1).length,r=0;for(;r<n;){if(HA(e)){e=void 0;break}e=e[t[r]],r++}return e}function Xle(e){for(let t in e)if(e.hasOwnProperty(t)&&!ZA(e[t]))return!1;return!0}function Ej(e,t){if(pj(t)&&Object.prototype.hasOwnProperty.call(e,t))return delete e[t],e;let n=Array.isArray(t)?t:XA(t)?[t]:$A(t),r=n.length===1?e:Yle(e,n),i=n.length-1,a=n[i];return r&&delete r[a],i!==0&&(WA(r)&&bj(r)||Array.isArray(r)&&Xle(r))&&Ej(e,n.slice(0,-1)),e}var Zle=e=>{for(let t in e)if(nj(e[t]))return!0;return!1};function Dj(e){return Array.isArray(e)||WA(e)&&!Zle(e)}function Oj(e,t={}){for(let n in e){let r=e[n];Dj(r)?(t[n]=Array.isArray(r)?[]:{},Oj(r,t[n])):ZA(r)||(t[n]=!0)}return t}function kj(e,t,n){n||=Oj(t);for(let r in e){let i=e[r];if(Dj(i))ZA(t)||hj(n[r])?n[r]=Oj(i,Array.isArray(i)?[]:{}):kj(i,HA(t)?{}:t[r],n[r]);else{let e=t[r];n[r]=!gj(i,e)}}return n}var Aj={value:!1,isValid:!1},jj={value:!0,isValid:!0},Mj=e=>{if(Array.isArray(e)){if(e.length>1){let t=e.filter(e=>e&&e.checked&&!e.disabled).map(e=>e.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!ZA(e[0].attributes.value)?ZA(e[0].value)||e[0].value===``?jj:{value:e[0].value,isValid:!0}:jj:Aj}return Aj},Nj=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>ZA(e)?e:t?e===``?NaN:e&&+e:n&&pj(e)?new Date(e):r?r(e):e,Pj={isValid:!1,value:null},Fj=e=>Array.isArray(e)?e.reduce((e,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:e,Pj):Pj;function Ij(e){let t=e.ref;return xj(t)?t.files:wj(t)?Fj(e.refs).value:Cj(t)?[...t.selectedOptions].map(({value:e})=>e):BA(t)?Mj(e.refs).value:Nj(ZA(t.value)?e.ref.value:t.value,e)}var Qle=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,$le=(e,t,n,r)=>{let i={};for(let n of e){let e=ej(t,n);e&&rj(i,n,e._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Lj=e=>e instanceof RegExp,Rj=e=>ZA(e)?e:Lj(e)?e.source:WA(e)?Lj(e.value)?e.value.source:e.value:e,zj=e=>({isOnSubmit:!e||e===aj.onSubmit,isOnBlur:e===aj.onBlur,isOnChange:e===aj.onChange,isOnAll:e===aj.all,isOnTouch:e===aj.onTouched}),Bj=`AsyncFunction`,eue=e=>!!e&&!!e.validate&&!!(nj(e.validate)&&e.validate.constructor.name===Bj||WA(e.validate)&&Object.values(e.validate).find(e=>e.constructor.name===Bj)),tue=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),Vj=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(t=>e.startsWith(t)&&/^\.\w+/.test(e.slice(t.length)))),Hj=(e,t,n,r)=>{for(let i of n||Object.keys(e)){let n=ej(e,i);if(n){let{_f:e,...a}=n;if(e){if(e.refs&&e.refs[0]&&t(e.refs[0],i)&&!r||e.ref&&t(e.ref,e.name)&&!r)return!0;if(Hj(a,t))break}else if(WA(a)&&Hj(a,t))break}}};function Uj(e,t,n){let r=ej(e,n);if(r||XA(n))return{error:r,name:n};let i=n.split(`.`);for(;i.length;){let r=i.join(`.`),a=ej(t,r),o=ej(e,r);if(a&&!Array.isArray(a)&&n!==r)return{name:n};if(o&&o.type)return{name:r,error:o};if(o&&o.root&&o.root.type)return{name:`${r}.root`,error:o.root};i.pop()}return{name:n}}var nue=(e,t,n,r)=>{n(e);let{name:i,...a}=e;return bj(a)||Object.keys(a).length>=Object.keys(t).length||Object.keys(a).find(e=>t[e]===(!r||aj.all))},rue=(e,t,n)=>!e||!t||e===t||_j(e).some(e=>e&&(n?e===t:e.startsWith(t)||t.startsWith(e))),iue=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,aue=(e,t)=>!QA(ej(e,t)).length&&Ej(e,t),oue=(e,t,n)=>{let r=_j(ej(e,n));return rj(r,cj,t[n]),rj(e,n,r),e};function Wj(e,t,n=`validate`){if(pj(e)||Array.isArray(e)&&e.every(pj)||tj(e)&&!e)return{type:n,message:pj(e)?e:``,ref:t}}var Gj=e=>WA(e)&&!Lj(e)?e:{value:e,message:``},Kj=async(e,t,n,r,i,a)=>{let{ref:o,refs:s,required:c,maxLength:l,minLength:u,min:d,max:f,pattern:p,validate:m,name:h,valueAsNumber:g,mount:_}=e._f,v=ej(n,h);if(!_||t.has(h))return{};let y=s?s[0]:o,b=e=>{i&&y.reportValidity&&(y.setCustomValidity(tj(e)?``:e||``),y.reportValidity())},x={},S=wj(o),C=BA(o),w=S||C,T=(g||xj(o))&&ZA(o.value)&&ZA(v)||Sj(o)&&o.value===``||v===``||Array.isArray(v)&&!v.length||g&&typeof v==`number`&&isNaN(v),E=qle.bind(null,h,r,x),D=(e,t,n,r=oj.maxLength,i=oj.minLength)=>{let a=e?t:n;x[h]={type:e?r:i,message:a,ref:o,...E(e?r:i,a)}};if(a?!Array.isArray(v)||!v.length:c&&(!w&&(T||HA(v))||tj(v)&&!v||C&&!Mj(s).isValid||S&&!Fj(s).isValid)){let{value:e,message:t}=pj(c)?{value:!!c,message:c}:Gj(c);if(e&&(x[h]={type:oj.required,message:t,ref:y,...E(oj.required,t)},!r))return b(t),x}if(!T&&(!HA(d)||!HA(f))){let e,t,n=Gj(f),i=Gj(d);if(!HA(v)&&!isNaN(v)){let r=o.valueAsNumber||v&&+v;HA(n.value)||(e=r>n.value),HA(i.value)||(t=r<i.value)}else{let r=o.valueAsDate||new Date(v),a=e=>new Date(new Date().toDateString()+` `+e),s=o.type==`time`,c=o.type==`week`;pj(n.value)&&v&&(e=s?a(v)>a(n.value):c?v>n.value:r>new Date(n.value)),pj(i.value)&&v&&(t=s?a(v)<a(i.value):c?v<i.value:r<new Date(i.value))}if((e||t)&&(D(!!e,n.message,i.message,oj.max,oj.min),!r))return b(x[h].message),x}if((l||u)&&!T&&(pj(v)||a&&Array.isArray(v))){let e=Gj(l),t=Gj(u),n=!HA(e.value)&&v.length>+e.value,i=!HA(t.value)&&v.length<+t.value;if((n||i)&&(D(n,e.message,t.message),!r))return b(x[h].message),x}if(p&&!T&&pj(v)){let{value:e,message:t}=Gj(p);if(Lj(e)&&!v.match(e)&&(x[h]={type:oj.pattern,message:t,ref:o,...E(oj.pattern,t)},!r))return b(t),x}if(m){if(nj(m)){let e=Wj(await m(v,n),y);if(e&&(x[h]={...e,...E(oj.validate,e.message)},!r))return b(e.message),x}else if(WA(m)){let e={};for(let t in m){if(!bj(e)&&!r)break;let i=Wj(await m[t](v,n),y,t);i&&(e={...i,...E(t,i.message)},b(i.message),r&&(x[h]=e))}if(!bj(e)&&(x[h]={ref:y,...e},!r))return x}}return b(!0),x},sue={mode:aj.onSubmit,reValidateMode:aj.onChange,shouldFocusError:!0};function cue(e={}){let t={...sue,...e},n={submitCount:0,isDirty:!1,isReady:!1,isLoading:nj(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=(WA(t.defaultValues)||WA(t.values))&&YA(t.defaultValues||t.values)||{},a=t.shouldUnregister?{}:YA(i),o={action:!1,mount:!1,watch:!1,keepIsValid:!1},s={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set,registerName:new Set},c,l=0,u={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={...u},f={...d},p={array:vj(),state:vj()},m=t.criteriaMode===aj.all,h=e=>t=>{clearTimeout(l),l=setTimeout(e,t)},g=async e=>{if(!o.keepIsValid&&!t.disabled&&(d.isValid||f.isValid||e)){let e;t.resolver?(e=bj((await T()).errors),_()):e=await O({fields:r,onlyCheckValid:!0,eventType:ij.VALID}),e!==n.isValid&&p.state.next({isValid:e})}},_=(e,r)=>{!t.disabled&&(d.isValidating||d.validatingFields||f.isValidating||f.validatingFields)&&((e||Array.from(s.mount)).forEach(e=>{e&&(r?rj(n.validatingFields,e,r):Ej(n.validatingFields,e))}),p.state.next({validatingFields:n.validatingFields,isValidating:!bj(n.validatingFields)}))},v=e=>{let t=kj(i,a),r=Qle(e);rj(n.dirtyFields,r,ej(t,r))},y=(e,i=[],s,c,l=!0,u=!0)=>{if(c&&s&&!t.disabled){if(o.action=!0,u&&Array.isArray(ej(r,e))){let t=s(ej(r,e),c.argA,c.argB);l&&rj(r,e,t)}if(u&&Array.isArray(ej(n.errors,e))){let t=s(ej(n.errors,e),c.argA,c.argB);l&&rj(n.errors,e,t),aue(n.errors,e)}if((d.touchedFields||f.touchedFields)&&u&&Array.isArray(ej(n.touchedFields,e))){let t=s(ej(n.touchedFields,e),c.argA,c.argB);l&&rj(n.touchedFields,e,t)}(d.dirtyFields||f.dirtyFields)&&v(e),p.state.next({name:e,isDirty:A(e,i),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else rj(a,e,i)},b=(e,t)=>{rj(n.errors,e,t),p.state.next({errors:n.errors})},x=e=>{n.errors=e,p.state.next({errors:n.errors,isValid:!1})},S=(e,t,n,s)=>{let c=ej(r,e);if(c){let r=ej(a,e,ZA(n)?ej(i,e):n);ZA(r)||s&&s.defaultChecked||t?rj(a,e,t?r:Ij(c._f)):N(e,r),o.mount&&!o.action&&g()}},C=(e,r,a,o,s)=>{let c=!1,l=!1,u={name:e};if(!t.disabled){if(!a||o){(d.isDirty||f.isDirty)&&(l=n.isDirty,n.isDirty=u.isDirty=A(),c=l!==u.isDirty);let t=gj(ej(i,e),r);l=!!ej(n.dirtyFields,e),t?Ej(n.dirtyFields,e):rj(n.dirtyFields,e,!0),u.dirtyFields=n.dirtyFields,c||=(d.dirtyFields||f.dirtyFields)&&l!==!t}if(a){let t=ej(n.touchedFields,e);t||(rj(n.touchedFields,e,a),u.touchedFields=n.touchedFields,c||=(d.touchedFields||f.touchedFields)&&t!==a)}c&&s&&p.state.next(u)}return c?u:{}},w=(e,r,i,a)=>{let o=ej(n.errors,e),s=(d.isValid||f.isValid)&&tj(r)&&n.isValid!==r;if(t.delayError&&i?(c=h(()=>b(e,i)),c(t.delayError)):(clearTimeout(l),c=null,i?rj(n.errors,e,i):Ej(n.errors,e)),(i?!gj(o,i):o)||!bj(a)||s){let t={...a,...s&&tj(r)?{isValid:r}:{},errors:n.errors,name:e};n={...n,...t},p.state.next(t)}},T=async e=>(_(e,!0),await t.resolver(a,t.context,$le(e||s.mount,r,t.criteriaMode,t.shouldUseNativeValidation))),E=async e=>{let{errors:t}=await T(e);if(_(e),e)for(let r of e){let e=ej(t,r);e?rj(n.errors,r,e):Ej(n.errors,r)}else n.errors=t;return t},D=async({name:t,eventType:r})=>{if(e.validate){let i=await e.validate({formValues:a,formState:n,name:t,eventType:r});if(WA(i))for(let e in i)i[e]&&ae(`${sj}.${e}`,{message:pj(i.message)?i.message:``,type:oj.validate});else pj(i)||!i?ae(sj,{message:i||``,type:oj.validate}):ie(sj);return i}return!0},O=async({fields:r,onlyCheckValid:i,name:o,eventType:c,context:l={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(l.runRootValidation=!0,!await D({name:o,eventType:c})&&(l.valid=!1,i)))return l.valid;for(let o in r){let u=r[o];if(u){let{_f:r,...f}=u;if(r){let o=s.array.has(r.name),c=u._f&&eue(u._f);c&&d.validatingFields&&_([r.name],!0);let f=await Kj(u,s.disabled,a,m,t.shouldUseNativeValidation&&!i,o);if(c&&d.validatingFields&&_([r.name]),f[r.name]&&(l.valid=!1,i)||(!i&&(ej(f,r.name)?o?oue(n.errors,f,r.name):rj(n.errors,r.name,f[r.name]):Ej(n.errors,r.name)),e.shouldUseNativeValidation&&f[r.name]))break}!bj(f)&&await O({context:l,onlyCheckValid:i,fields:f,name:o,eventType:c})}}return l.valid},k=()=>{for(let e of s.unMount){let t=ej(r,e);t&&(t._f.refs?t._f.refs.every(e=>!Tj(e)):!Tj(t._f.ref))&&le(e)}s.unMount=new Set},A=(e,n)=>!t.disabled&&(e&&n&&rj(a,e,n),!gj(L(),i)),j=(e,t,n)=>mj(e,s,{...o.mount?a:ZA(t)?i:pj(e)?{[e]:t}:t},n,t),M=e=>QA(ej(o.mount?a:i,e,t.shouldUnregister?ej(i,e,[]):[])),N=(e,t,n={})=>{let i=ej(r,e),o=t;if(i){let n=i._f;n&&(!n.disabled&&rj(a,e,Nj(t,n)),o=Sj(n.ref)&&HA(t)?``:t,Cj(n.ref)?[...n.ref.options].forEach(e=>e.selected=o.includes(e.value)):n.refs?BA(n.ref)?n.refs.forEach(e=>{(!e.defaultChecked||!e.disabled)&&(Array.isArray(o)?e.checked=!!o.find(t=>t===e.value):e.checked=o===e.value||!!o)}):n.refs.forEach(e=>e.checked=e.value===o):xj(n.ref)?n.ref.value=``:(n.ref.value=o,n.ref.type||p.state.next({name:e,values:YA(a)})))}(n.shouldDirty||n.shouldTouch)&&C(e,o,n.shouldTouch,n.shouldDirty,!0),n.shouldValidate&&ne(e)},P=(e,t,n)=>{for(let i in t){if(!t.hasOwnProperty(i))return;let a=t[i],o=e+`.`+i,c=ej(r,o);(s.array.has(e)||WA(a)||c&&!c._f)&&!VA(a)?P(o,a,n):N(o,a,n)}},F=(e,t,i={})=>{let c=ej(r,e),l=s.array.has(e),u=YA(t),d=gj(ej(a,e),u);if(rj(a,e,u),l)p.array.next({name:e,values:YA(a)}),i.shouldDirty&&(v(e),p.state.next({name:e,dirtyFields:n.dirtyFields,isDirty:A(e,u)}));else{let t=Array.isArray(u)&&!u.length||bj(u);!c||c._f||HA(u)||t?N(e,u,i):P(e,u,i)}d||(Vj(e,s)?p.state.next({...n,name:e,values:YA(a)}):p.state.next({name:o.mount?e:void 0,values:YA(a)}))},ee=e=>{let t=nj(e)?e(a):e;gj(a,t)||(a={...a,...t},p.state.next({...n,values:a}))},te=async i=>{o.mount=!0;let l=i.target,u=l.name,h=!0,v=ej(r,u),y=e=>{h=Number.isNaN(e)||VA(e)&&isNaN(e.getTime())||gj(e,ej(a,u,e))},b=zj(t.mode),x=zj(t.reValidateMode);if(v){let o,S,E=l.type?Ij(v._f):GA(i),k=i.type===ij.BLUR||i.type===ij.FOCUS_OUT,A=!tue(v._f)&&!e.validate&&!t.resolver&&!ej(n.errors,u)&&!v._f.deps||iue(k,ej(n.touchedFields,u),n.isSubmitted,x,b),j=Vj(u,s,k);rj(a,u,E),k?(!l||!l.readOnly)&&(v._f.onBlur&&v._f.onBlur(i),c&&c(0)):v._f.onChange&&v._f.onChange(i);let M=C(u,E,k),N=!bj(M)||j;if(!k&&p.state.next({name:u,type:i.type,values:YA(a)}),A)return(d.isValid||f.isValid)&&(t.mode===`onBlur`?k&&g():k||g()),N&&p.state.next({name:u,...j?{}:M});if(!t.resolver&&e.validate&&await D({name:u,eventType:i.type}),!k&&j&&p.state.next({...n}),t.resolver){let{errors:e}=await T([u]);if(_([u]),y(E),h){let t=Uj(n.errors,r,u),i=Uj(e,r,t.name||u);o=i.error,u=i.name,S=bj(e)}}else _([u],!0),o=(await Kj(v,s.disabled,a,m,t.shouldUseNativeValidation))[u],_([u]),y(E),h&&(o?S=!1:(d.isValid||f.isValid)&&(S=await O({fields:r,onlyCheckValid:!0,name:u,eventType:i.type})));h&&(v._f.deps&&(!Array.isArray(v._f.deps)||v._f.deps.length>0)&&ne(v._f.deps),w(u,S,o,M))}},I=(e,t)=>{if(ej(n.errors,t)&&e.focus)return e.focus(),1},ne=async(e,i={})=>{let a,o,c=_j(e);if(t.resolver){let t=await E(ZA(e)?e:c);a=bj(t),o=e?!c.some(e=>ej(t,e)):a}else e?(o=(await Promise.all(c.map(async e=>{let t=ej(r,e);return await O({fields:t&&t._f?{[e]:t}:t,eventType:ij.TRIGGER})}))).every(Boolean),!(!o&&!n.isValid)&&g()):o=a=await O({fields:r,name:e,eventType:ij.TRIGGER});return p.state.next({...!pj(e)||(d.isValid||f.isValid)&&a!==n.isValid?{}:{name:e},...t.resolver||!e?{isValid:a}:{},errors:n.errors}),i.shouldFocus&&!o&&Hj(r,I,e?c:s.mount),o},L=(e,t)=>{let r={...o.mount?a:i};return t&&(r=yj(t.dirtyFields?n.dirtyFields:n.touchedFields,r)),ZA(e)?r:pj(e)?ej(r,e):e.map(e=>ej(r,e))},re=(e,t)=>({invalid:!!ej((t||n).errors,e),isDirty:!!ej((t||n).dirtyFields,e),error:ej((t||n).errors,e),isValidating:!!ej(n.validatingFields,e),isTouched:!!ej((t||n).touchedFields,e)}),ie=e=>{let t=e?_j(e):void 0;t?.forEach(e=>Ej(n.errors,e)),t?t.forEach(e=>{p.state.next({name:e,errors:n.errors})}):p.state.next({errors:{}})},ae=(e,t,i)=>{let a=(ej(r,e,{_f:{}})._f||{}).ref,{ref:o,message:s,type:c,...l}=ej(n.errors,e)||{};rj(n.errors,e,{...l,...t,ref:a}),p.state.next({name:e,errors:n.errors,isValid:!1}),i&&i.shouldFocus&&a&&a.focus&&a.focus()},oe=(e,t)=>nj(e)?p.state.subscribe({next:n=>`values`in n&&e(n.values||j(void 0,t),n)}):j(e,t,!0),se=e=>p.state.subscribe({next:t=>{if(rue(e.name,t.name,e.exact)&&nue(t,e.formState||d,ye,e.reRenderRoot)){let r={...a};e.callback({values:r,...n,...t,defaultValues:i})}}}).unsubscribe,ce=e=>(o.mount=!0,f={...f,...e.formState},se({...e,formState:{...u,...e.formState}})),le=(e,o={})=>{for(let c of e?_j(e):s.mount)s.mount.delete(c),s.array.delete(c),o.keepValue||(Ej(r,c),Ej(a,c)),!o.keepError&&Ej(n.errors,c),!o.keepDirty&&Ej(n.dirtyFields,c),!o.keepTouched&&Ej(n.touchedFields,c),!o.keepIsValidating&&Ej(n.validatingFields,c),!t.shouldUnregister&&!o.keepDefaultValue&&Ej(i,c);p.state.next({values:YA(a)}),p.state.next({...n,...o.keepDirty?{isDirty:A()}:{}}),!o.keepIsValid&&g()},ue=({disabled:e,name:t})=>{if(tj(e)&&o.mount||e||s.disabled.has(t)){let n=s.disabled.has(t)!==!!e;e?s.disabled.add(t):s.disabled.delete(t),n&&o.mount&&!o.action&&g()}},de=(e,n={})=>{let a=ej(r,e),c=tj(n.disabled)||tj(t.disabled),l=!s.registerName.has(e)&&a&&a._f&&!a._f.mount;return rj(r,e,{...a||{},_f:{...a&&a._f?a._f:{ref:{name:e}},name:e,mount:!0,...n}}),s.mount.add(e),a&&!l?ue({disabled:tj(n.disabled)?n.disabled:t.disabled,name:e}):S(e,!0,n.value),{...c?{disabled:n.disabled||t.disabled}:{},...t.progressive?{required:!!n.required,min:Rj(n.min),max:Rj(n.max),minLength:Rj(n.minLength),maxLength:Rj(n.maxLength),pattern:Rj(n.pattern)}:{},name:e,onChange:te,onBlur:te,ref:c=>{if(c){s.registerName.add(e),de(e,n),s.registerName.delete(e),a=ej(r,e);let t=ZA(c.value)&&c.querySelectorAll&&c.querySelectorAll(`input,select,textarea`)[0]||c,o=Jle(t),l=a._f.refs||[];if(o?l.find(e=>e===t):t===a._f.ref)return;rj(r,e,{_f:{...a._f,...o?{refs:[...l.filter(Tj),t,...Array.isArray(ej(i,e))?[{}]:[]],ref:{type:t.type,name:e}}:{ref:t}}}),S(e,!1,void 0,t)}else a=ej(r,e,{}),a._f&&(a._f.mount=!1),(t.shouldUnregister||n.shouldUnregister)&&!(KA(s.array,e)&&o.action)&&s.unMount.add(e)}}},fe=()=>t.shouldFocusError&&Hj(r,I,s.mount),pe=e=>{tj(e)&&(p.state.next({disabled:e}),Hj(r,(t,n)=>{let i=ej(r,n);i&&(t.disabled=i._f.disabled||e,Array.isArray(i._f.refs)&&i._f.refs.forEach(t=>{t.disabled=i._f.disabled||e}))},0,!1))},me=(e,i)=>async o=>{let c;o&&(o.preventDefault&&o.preventDefault(),o.persist&&o.persist());let l=YA(a);if(p.state.next({isSubmitting:!0}),t.resolver){let{errors:e,values:t}=await T();_(),n.errors=e,l=YA(t)}else await O({fields:r,eventType:ij.SUBMIT});if(s.disabled.size)for(let e of s.disabled)Ej(l,e);if(Ej(n.errors,cj),bj(n.errors)){p.state.next({errors:{}});try{await e(l,o)}catch(e){c=e}}else i&&await i({...n.errors},o),fe(),setTimeout(fe);if(p.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bj(n.errors)&&!c,submitCount:n.submitCount+1,errors:n.errors}),c)throw c},he=(e,t={})=>{ej(r,e)&&(ZA(t.defaultValue)?F(e,YA(ej(i,e))):(F(e,t.defaultValue),rj(i,e,YA(t.defaultValue))),t.keepTouched||Ej(n.touchedFields,e),t.keepDirty||(Ej(n.dirtyFields,e),n.isDirty=t.defaultValue?A(e,YA(ej(i,e))):A()),t.keepError||(Ej(n.errors,e),d.isValid&&g()),p.state.next({...n}))},ge=(e,c={})=>{let l=e?YA(e):i,u=YA(l),f=bj(e),m=f?i:u;if(c.keepDefaultValues||(i=l),!c.keepValues){if(c.keepDirtyValues){let e=new Set([...s.mount,...Object.keys(kj(i,a))]);for(let t of Array.from(e)){let e=ej(n.dirtyFields,t),r=ej(a,t),i=ej(m,t);e&&!ZA(r)?rj(m,t,r):!e&&!ZA(i)&&F(t,i)}}else{if(JA&&ZA(e))for(let e of s.mount){let t=ej(r,e);if(t&&t._f){let e=Array.isArray(t._f.refs)?t._f.refs[0]:t._f.ref;if(Sj(e)){let t=e.closest(`form`);if(t){t.reset();break}}}}if(c.keepFieldsRef)for(let e of s.mount)F(e,ej(m,e));else r={}}a=t.shouldUnregister?c.keepDefaultValues?YA(i):{}:YA(m),p.array.next({values:{...m}}),p.state.next({values:{...m}})}s={mount:c.keepDirtyValues?s.mount:new Set,unMount:new Set,array:new Set,registerName:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:``},o.mount=!d.isValid||!!c.keepIsValid||!!c.keepDirtyValues||!t.shouldUnregister&&!bj(m),o.watch=!!t.shouldUnregister,o.keepIsValid=!!c.keepIsValid,o.action=!1,c.keepErrors||(n.errors={}),p.state.next({submitCount:c.keepSubmitCount?n.submitCount:0,isDirty:f?!1:c.keepDirty?n.isDirty:!!(c.keepDefaultValues&&!gj(e,i)),isSubmitted:c.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:f?{}:c.keepDirtyValues?c.keepDefaultValues&&a?kj(i,a):n.dirtyFields:c.keepDefaultValues&&e?kj(i,e):c.keepDirty?n.dirtyFields:{},touchedFields:c.keepTouched?n.touchedFields:{},errors:c.keepErrors?n.errors:{},isSubmitSuccessful:c.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:i})},_e=(e,n)=>ge(nj(e)?e(a):e,{...t.resetOptions,...n}),ve=(e,t={})=>{let n=ej(r,e),i=n&&n._f;if(i){let e=i.refs?i.refs[0]:i.ref;e.focus&&setTimeout(()=>{e.focus(),t.shouldSelect&&nj(e.select)&&e.select()})}},ye=e=>{n={...n,...e}},be={control:{register:de,unregister:le,getFieldState:re,handleSubmit:me,setError:ae,_subscribe:se,_runSchema:T,_updateIsValidating:_,_focusError:fe,_getWatch:j,_getDirty:A,_setValid:g,_setFieldArray:y,_setDisabledField:ue,_setErrors:x,_getFieldArray:M,_reset:ge,_resetDefaultValues:()=>nj(t.defaultValues)&&t.defaultValues().then(e=>{_e(e,t.resetOptions),p.state.next({isLoading:!1})}),_removeUnmounted:k,_disableForm:pe,_subjects:p,_proxyFormState:d,get _fields(){return r},get _formValues(){return a},get _state(){return o},set _state(e){o=e},get _defaultValues(){return i},get _names(){return s},set _names(e){s=e},get _formState(){return n},get _options(){return t},set _options(e){t={...t,...e}}},subscribe:ce,trigger:ne,register:de,handleSubmit:me,watch:oe,setValue:F,setValues:ee,getValues:L,reset:_e,resetField:he,clearErrors:ie,unregister:le,setError:ae,setFocus:ve,getFieldState:re};return{...be,formControl:be}}function lue(e={}){let t=R.useRef(void 0),n=R.useRef(void 0),[r,i]=R.useState({isDirty:!1,isValidating:!1,isLoading:nj(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:nj(e.defaultValues)?void 0:e.defaultValues});if(!t.current)if(e.formControl)t.current={...e.formControl,formState:r},e.defaultValues&&!nj(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{let{formControl:n,...i}=cue(e);t.current={...i,formState:r}}let a=t.current.control;return a._options=e,fj(()=>{let e=a._subscribe({formState:a._proxyFormState,callback:()=>i({...a._formState}),reRenderRoot:!0});return i(e=>({...e,isReady:!0})),a._formState.isReady=!0,e},[a]),R.useEffect(()=>a._disableForm(e.disabled),[a,e.disabled]),R.useEffect(()=>{e.mode&&(a._options.mode=e.mode),e.reValidateMode&&(a._options.reValidateMode=e.reValidateMode)},[a,e.mode,e.reValidateMode]),R.useEffect(()=>{e.errors&&(a._setErrors(e.errors),a._focusError())},[a,e.errors]),R.useEffect(()=>{e.shouldUnregister&&a._subjects.state.next({values:a._getWatch()})},[a,e.shouldUnregister]),R.useEffect(()=>{if(a._proxyFormState.isDirty){let e=a._getDirty();e!==r.isDirty&&a._subjects.state.next({isDirty:e})}},[a,r.isDirty]),R.useEffect(()=>{e.values&&!gj(e.values,n.current)?(a._reset(e.values,{keepFieldsRef:!0,...a._options.resetOptions}),a._options.resetOptions?.keepIsValid||a._setValid(),n.current=e.values,i(e=>({...e}))):a._resetDefaultValues()},[a,e.values]),R.useEffect(()=>{a._state.mount||(a._setValid(),a._state.mount=!0),a._state.watch&&(a._state.watch=!1,a._subjects.state.next({...a._formState})),a._removeUnmounted()}),t.current.formState=R.useMemo(()=>dj(r,a),[a,r]),t.current}function qj(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function q(){return q=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},q.apply(null,arguments)}var uue=n(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),due=n(((e,t)=>{var n=uue();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),fue=n(((e,t)=>{t.exports=due()()})),pue=n((e=>{if(typeof Symbol==`function`&&Symbol.for){var t=Symbol.for;t(`react.element`),t(`react.portal`),t(`react.fragment`),t(`react.strict_mode`),t(`react.profiler`),t(`react.provider`),t(`react.context`),t(`react.forward_ref`),t(`react.suspense`),t(`react.suspense_list`),t(`react.memo`),t(`react.lazy`),t(`react.block`),t(`react.server.block`),t(`react.fundamental`),t(`react.debug_trace_mode`),t(`react.legacy_hidden`)}})),mue=n(((e,t)=>{t.exports=pue()})),Jj=e=>typeof e==`object`&&!!e&&e.nodeType===1,Yj=(e,t)=>(!t||e!==`hidden`)&&e!==`visible`&&e!==`clip`,Xj=(e,t)=>{if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){let n=getComputedStyle(e,null);return Yj(n.overflowY,t)||Yj(n.overflowX,t)||(e=>{let t=(e=>{if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch{return null}})(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)})(e)}return!1},Zj=(e,t,n,r,i,a,o,s)=>a<e&&o>t||a>e&&o<t?0:a<=e&&s<=n||o>=t&&s>=n?a-e-r:o>t&&s<n||a<e&&s>n?o-t+i:0,hue=e=>e.parentElement??(e.getRootNode().host||null),gue=(e,t)=>{if(typeof document>`u`)return[];let{scrollMode:n,block:r,inline:i,boundary:a,skipOverflowHiddenElements:o}=t,s=typeof a==`function`?a:e=>e!==a;if(!Jj(e))throw TypeError(`Invalid target`);let c=document.scrollingElement||document.documentElement,l=[],u=e;for(;Jj(u)&&s(u);){if(u=hue(u),u===c){l.push(u);break}u!=null&&u===document.body&&Xj(u)&&!Xj(document.documentElement)||u!=null&&Xj(u,o)&&l.push(u)}let d=window.visualViewport?.width??innerWidth,f=window.visualViewport?.height??innerHeight,p=window.scrollX??pageXOffset,m=window.scrollY??pageYOffset,{height:h,width:g,top:_,right:v,bottom:y,left:b}=e.getBoundingClientRect(),x=r===`start`||r===`nearest`?_:r===`end`?y:_+h/2,S=i===`center`?b+g/2:i===`end`?v:b,C=[];for(let e=0;e<l.length;e++){let t=l[e],{height:a,width:o,top:s,right:u,bottom:w,left:T}=t.getBoundingClientRect();if(n===`if-needed`&&_>=0&&b>=0&&y<=f&&v<=d&&_>=s&&y<=w&&b>=T&&v<=u)return C;let E=getComputedStyle(t),D=parseInt(E.borderLeftWidth,10),O=parseInt(E.borderTopWidth,10),k=parseInt(E.borderRightWidth,10),A=parseInt(E.borderBottomWidth,10),j=0,M=0,N=`offsetWidth`in t?t.offsetWidth-t.clientWidth-D-k:0,P=`offsetHeight`in t?t.offsetHeight-t.clientHeight-O-A:0,F=`offsetWidth`in t?t.offsetWidth===0?0:o/t.offsetWidth:0,ee=`offsetHeight`in t?t.offsetHeight===0?0:a/t.offsetHeight:0;if(c===t)j=r===`start`?x:r===`end`?x-f:r===`nearest`?Zj(m,m+f,f,O,A,m+x,m+x+h,h):x-f/2,M=i===`start`?S:i===`center`?S-d/2:i===`end`?S-d:Zj(p,p+d,d,D,k,p+S,p+S+g,g),j=Math.max(0,j+m),M=Math.max(0,M+p);else{j=r===`start`?x-s-O:r===`end`?x-w+A+P:r===`nearest`?Zj(s,w,a,O,A+P,x,x+h,h):x-(s+a/2)+P/2,M=i===`start`?S-T-D:i===`center`?S-(T+o/2)+N/2:i===`end`?S-u+k+N:Zj(T,u,o,D,k+N,S,S+g,g);let{scrollLeft:e,scrollTop:n}=t;j=Math.max(0,Math.min(n+j/ee,t.scrollHeight-a/ee+P)),M=Math.max(0,Math.min(e+M/F,t.scrollWidth-o/F+N)),x+=n-j,S+=e-M}C.push({el:t,top:j,left:M})}return C},J=t(fue());mue();var _ue=0;function Qj(){}function vue(e,t){e&&gue(e,{boundary:t,block:`nearest`,scrollMode:`if-needed`}).forEach(function(e){var t=e.el,n=e.top,r=e.left;t.scrollTop=n,t.scrollLeft=r})}function $j(e,t,n){return e===t||t instanceof n.Node&&e.contains&&e.contains(t)}function eM(e,t){var n;function r(){n&&clearTimeout(n)}function i(){var i=[...arguments];r(),n=setTimeout(function(){n=null,e.apply(void 0,i)},t)}return i.cancel=r,i}function tM(){var e=[...arguments];return function(t){var n=[...arguments].slice(1);return e.some(function(e){return e&&e.apply(void 0,[t].concat(n)),t.preventDownshiftDefault||t.hasOwnProperty(`nativeEvent`)&&t.nativeEvent.preventDownshiftDefault})}}function nM(){var e=[...arguments];return function(t){e.forEach(function(e){typeof e==`function`?e(t):e&&(e.current=t)})}}function yue(){return String(_ue++)}function bue(e){var t=e.isOpen,n=e.resultCount,r=e.previousResultCount;return t?n?n===r?``:n+` result`+(n===1?` is`:`s are`)+` available, use up and down arrow keys to navigate. Press Enter key to select.`:`No results are available.`:``}function rM(e,t){return Object.keys(e).reduce(function(n,r){return n[r]=iM(t,r)?t[r]:e[r],n},{})}function iM(e,t){return e[t]!==void 0}function aM(e){var t=e.key,n=e.keyCode;return n>=37&&n<=40&&t.indexOf(`Arrow`)!==0?`Arrow`+t:t}function oM(e,t,n,r,i){if(i===void 0&&(i=!0),n===0)return-1;var a=n-1;(typeof t!=`number`||t<0||t>=n)&&(t=e>0?-1:a+1);var o=t+e;o<0?o=i?a:0:o>a&&(o=i?0:a);var s=sM(e,o,n,r,i);return s===-1?t>=n?-1:t:s}function sM(e,t,n,r,i){var a=r(t);if(!a||!a.hasAttribute(`disabled`))return t;if(e>0){for(var o=t+1;o<n;o++)if(!r(o).hasAttribute(`disabled`))return o}else for(var s=t-1;s>=0;s--)if(!r(s).hasAttribute(`disabled`))return s;return i?e>0?sM(1,0,n,r,!1):sM(-1,n-1,n,r,!1):-1}function cM(e,t,n,r){return r===void 0&&(r=!0),t.some(function(t){return t&&($j(t,e,n)||r&&$j(t,n.document.activeElement,n))})}var xue=eM(function(e){uM(e).textContent=``},500);function lM(e,t){var n=uM(t);e&&(n.textContent=e,xue(t))}function uM(e){e===void 0&&(e=document);var t=e.getElementById(`a11y-status-message`);return t||(t=e.createElement(`div`),t.setAttribute(`id`,`a11y-status-message`),t.setAttribute(`role`,`status`),t.setAttribute(`aria-live`,`polite`),t.setAttribute(`aria-relevant`,`additions text`),Object.assign(t.style,{border:`0`,clip:`rect(0 0 0 0)`,height:`1px`,margin:`-1px`,overflow:`hidden`,padding:`0`,position:`absolute`,width:`1px`}),e.body.appendChild(t),t)}var Sue=[`isInitialMount`,`highlightedIndex`,`items`,`environment`],dM={highlightedIndex:-1,isOpen:!1,selectedItem:null,inputValue:``};function Cue(e,t,n){var r=e.props,i=e.type,a={};Object.keys(t).forEach(function(r){wue(r,e,t,n),n[r]!==t[r]&&(a[r]=n[r])}),r.onStateChange&&Object.keys(a).length&&r.onStateChange(q({type:i},a))}function wue(e,t,n,r){var i=t.props,a=t.type,o=`on`+mM(e)+`Change`;i[o]&&r[e]!==void 0&&r[e]!==n[e]&&i[o](q({type:a},r))}function Tue(e,t){return t.changes}function Eue(e){var t=e.selectedItem,n=e.itemToString;return t?n(t)+` has been selected.`:``}var Due=eM(function(e,t){lM(e(),t)},200),Oue=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0?R.useLayoutEffect:R.useEffect;function fM(e){var t=e.id,n=t===void 0?`downshift-`+yue():t,r=e.labelId,i=e.menuId,a=e.getItemId,o=e.toggleButtonId,s=e.inputId;return(0,R.useRef)({labelId:r||n+`-label`,menuId:i||n+`-menu`,getItemId:a||function(e){return n+`-item-`+e},toggleButtonId:o||n+`-toggle-button`,inputId:s||n+`-input`}).current}function pM(e,t,n,r){var i,a;if(e===void 0){if(t===void 0)throw Error(r);i=n[t],a=t}else a=t===void 0?n.indexOf(e):t,i=e;return[i,a]}function kue(e){return e?String(e):``}function Aue(e){return/^\S{1}$/.test(e)}function mM(e){return``+e.slice(0,1).toUpperCase()+e.slice(1)}function hM(e){var t=(0,R.useRef)(e);return t.current=e,t}function gM(e,t,n){var r=(0,R.useRef)(),i=(0,R.useRef)(),a=(0,R.useReducer)((0,R.useCallback)(function(t,n){i.current=n,t=rM(t,n.props);var r=e(t,n);return n.props.stateReducer(t,q({},n,{changes:r}))},[e]),t),o=a[0],s=a[1],c=hM(n),l=(0,R.useCallback)(function(e){return s(q({props:c.current},e))},[c]),u=i.current;return(0,R.useEffect)(function(){u&&r.current&&r.current!==o&&Cue(u,rM(r.current,u.props),o),r.current=o},[o,n,u]),[o,l]}function _M(e,t,n){var r=gM(e,t,n),i=r[0],a=r[1];return[rM(i,n),a]}var vM={itemToString:kue,stateReducer:Tue,getA11ySelectionMessage:Eue,scrollIntoView:vue,environment:typeof window>`u`?{}:window};function yM(e,t,n){n===void 0&&(n=dM);var r=e[`default`+mM(t)];return r===void 0?n[t]:r}function bM(e,t,n){n===void 0&&(n=dM);var r=e[t];if(r!==void 0)return r;var i=e[`initial`+mM(t)];return i===void 0?yM(e,t,n):i}function xM(e){var t=bM(e,`selectedItem`),n=bM(e,`isOpen`),r=bM(e,`highlightedIndex`),i=bM(e,`inputValue`);return{highlightedIndex:r<0&&t&&n?e.items.indexOf(t):r,isOpen:n,selectedItem:t,inputValue:i}}function SM(e,t,n){var r=e.items,i=e.initialHighlightedIndex,a=e.defaultHighlightedIndex,o=t.selectedItem,s=t.highlightedIndex;return r.length===0?-1:i!==void 0&&s===i?i:a===void 0?o?r.indexOf(o):n===0?-1:n<0?r.length-1:0:a}function CM(e,t,n,r){var i=(0,R.useRef)({isMouseDown:!1,isTouchMove:!1});return(0,R.useEffect)(function(){if(n?.addEventListener!=null){var a=function(){i.current.isMouseDown=!0},o=function(a){i.current.isMouseDown=!1,e&&!cM(a.target,t.map(function(e){return e.current}),n)&&r()},s=function(){i.current.isTouchMove=!1},c=function(){i.current.isTouchMove=!0},l=function(a){e&&!i.current.isTouchMove&&!cM(a.target,t.map(function(e){return e.current}),n,!1)&&r()};return n.addEventListener(`mousedown`,a),n.addEventListener(`mouseup`,o),n.addEventListener(`touchstart`,s),n.addEventListener(`touchmove`,c),n.addEventListener(`touchend`,l),function(){n.removeEventListener(`mousedown`,a),n.removeEventListener(`mouseup`,o),n.removeEventListener(`touchstart`,s),n.removeEventListener(`touchmove`,c),n.removeEventListener(`touchend`,l)}}},[e,n]),i}var wM=function(){return Qj};function TM(e,t,n){var r=n.isInitialMount,i=n.highlightedIndex,a=n.items,o=n.environment,s=qj(n,Sue);(0,R.useEffect)(function(){r||Due(function(){return e(q({highlightedIndex:i,highlightedItem:a[i],resultCount:a.length},s))},o.document)},t)}function EM(e){var t=e.highlightedIndex,n=e.isOpen,r=e.itemRefs,i=e.getItemNodeFromIndex,a=e.menuElement,o=e.scrollIntoView,s=(0,R.useRef)(!0);return Oue(function(){t<0||!n||!Object.keys(r.current).length||(s.current===!1?s.current=!0:o(i(t),a))},[t]),s}var DM=Qj;function OM(e,t,n){return n===void 0&&(n=!0),q({isOpen:!1,highlightedIndex:-1},e.items?.length&&t>=0&&q({selectedItem:e.items[t],isOpen:yM(e,`isOpen`),highlightedIndex:yM(e,`highlightedIndex`)},n&&{inputValue:e.itemToString(e.items[t])}))}function kM(e,t,n){var r=t.type,i=t.props,a;switch(r){case n.ItemMouseMove:a={highlightedIndex:t.disabled?-1:t.index};break;case n.MenuMouseLeave:a={highlightedIndex:-1};break;case n.ToggleButtonClick:case n.FunctionToggleMenu:a={isOpen:!e.isOpen,highlightedIndex:e.isOpen?-1:SM(i,e,0)};break;case n.FunctionOpenMenu:a={isOpen:!0,highlightedIndex:SM(i,e,0)};break;case n.FunctionCloseMenu:a={isOpen:!1};break;case n.FunctionSetHighlightedIndex:a={highlightedIndex:t.highlightedIndex};break;case n.FunctionSetInputValue:a={inputValue:t.inputValue};break;case n.FunctionReset:a={highlightedIndex:yM(i,`highlightedIndex`),isOpen:yM(i,`isOpen`),selectedItem:yM(i,`selectedItem`),inputValue:yM(i,`inputValue`)};break;default:throw Error(`Reducer called without proper action type.`)}return q({},e,a)}function jue(e){for(var t=e.keysSoFar,n=e.highlightedIndex,r=e.items,i=e.itemToString,a=e.getItemNodeFromIndex,o=t.toLowerCase(),s=0;s<r.length;s++){var c=(s+n+ +(t.length<2))%r.length,l=r[c];if(l!==void 0&&i(l).toLowerCase().startsWith(o)&&!a(c)?.hasAttribute(`disabled`))return c}return n}J.default.array.isRequired,J.default.func,J.default.func,J.default.func,J.default.number,J.default.number,J.default.number,J.default.bool,J.default.bool,J.default.bool,J.default.any,J.default.any,J.default.any,J.default.string,J.default.string,J.default.string,J.default.func,J.default.string,J.default.func,J.default.func,J.default.func,J.default.func,J.default.func,J.default.shape({addEventListener:J.default.func,removeEventListener:J.default.func,document:J.default.shape({getElementById:J.default.func,activeElement:J.default.any,body:J.default.any})});function Mue(e){var t=e.isOpen,n=e.resultCount,r=e.previousResultCount;return t?n?n===r?``:`${n} result${n===1?` is`:`s are`} available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.`:`No results are available.`:``}var Nue=qD(qD({},vM),{getA11yStatusMessage:Mue}),Pue=Qj,AM=0,jM=1,MM=2,NM=3,PM=4,FM=5,IM=6,LM=7,RM=8,zM=9,BM=10,VM=11,HM=12,UM=13,WM=14,GM=15,KM=16,qM=17,JM=18,YM=19,XM=20,ZM=21,QM=Object.freeze({__proto__:null,ToggleButtonClick:AM,ToggleButtonKeyDownArrowDown:jM,ToggleButtonKeyDownArrowUp:MM,ToggleButtonKeyDownCharacter:NM,ToggleButtonKeyDownEscape:PM,ToggleButtonKeyDownHome:FM,ToggleButtonKeyDownEnd:IM,ToggleButtonKeyDownEnter:LM,ToggleButtonKeyDownSpaceButton:RM,ToggleButtonKeyDownPageUp:zM,ToggleButtonKeyDownPageDown:BM,ToggleButtonBlur:VM,MenuMouseLeave:HM,ItemMouseMove:UM,ItemClick:WM,FunctionToggleMenu:GM,FunctionOpenMenu:KM,FunctionCloseMenu:qM,FunctionSetHighlightedIndex:JM,FunctionSelectItem:YM,FunctionSetInputValue:XM,FunctionReset:ZM});function Fue(e,t){var n=t.type,r=t.props,i=t.altKey,a;switch(n){case WM:a={isOpen:yM(r,`isOpen`),highlightedIndex:yM(r,`highlightedIndex`),selectedItem:r.items[t.index]};break;case NM:var o=t.key,s=``+e.inputValue+o;a={inputValue:s,highlightedIndex:jue({keysSoFar:s,highlightedIndex:!e.isOpen&&e.selectedItem?r.items.indexOf(e.selectedItem):e.highlightedIndex,items:r.items,itemToString:r.itemToString,getItemNodeFromIndex:t.getItemNodeFromIndex}),isOpen:!0};break;case jM:a={highlightedIndex:e.isOpen?oM(1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1):i&&e.selectedItem==null?-1:SM(r,e,1),isOpen:!0};break;case MM:a=e.isOpen&&i?OM(r,e.highlightedIndex,!1):{highlightedIndex:e.isOpen?oM(-1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1):SM(r,e,-1),isOpen:!0};break;case LM:case RM:a=OM(r,e.highlightedIndex,!1);break;case FM:a={highlightedIndex:sM(1,0,r.items.length,t.getItemNodeFromIndex,!1),isOpen:!0};break;case IM:a={highlightedIndex:sM(-1,r.items.length-1,r.items.length,t.getItemNodeFromIndex,!1),isOpen:!0};break;case zM:a={highlightedIndex:oM(-10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case BM:a={highlightedIndex:oM(10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case PM:a={isOpen:!1,highlightedIndex:-1};break;case VM:a=q({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&r.items?.length&&{selectedItem:r.items[e.highlightedIndex]});break;case YM:a={selectedItem:t.selectedItem};break;default:return kM(e,t,QM)}return q({},e,a)}var Iue=[`onMouseLeave`,`refKey`,`onKeyDown`,`onBlur`,`ref`],Lue=[`onBlur`,`onClick`,`onPress`,`onKeyDown`,`refKey`,`ref`],Rue=[`item`,`index`,`onMouseMove`,`onClick`,`onPress`,`refKey`,`ref`,`disabled`];$M.stateChangeTypes=QM;function $M(e){e===void 0&&(e={}),Pue(e,$M);var t=q({},Nue,e),n=t.items,r=t.scrollIntoView,i=t.environment,a=t.itemToString,o=t.getA11ySelectionMessage,s=t.getA11yStatusMessage,c=_M(Fue,xM(t),t),l=c[0],u=c[1],d=l.isOpen,f=l.highlightedIndex,p=l.selectedItem,m=l.inputValue,h=(0,R.useRef)(null),g=(0,R.useRef)(null),_=(0,R.useRef)({}),v=(0,R.useRef)(null),y=fM(t),b=(0,R.useRef)(),x=(0,R.useRef)(!0),S=hM({state:l,props:t}),C=(0,R.useCallback)(function(e){return _.current[y.getItemId(e)]},[y]);TM(s,[d,f,m,n],q({isInitialMount:x.current,previousResultCount:b.current,items:n,environment:i,itemToString:a},l)),TM(o,[p],q({isInitialMount:x.current,previousResultCount:b.current,items:n,environment:i,itemToString:a},l));var w=EM({menuElement:g.current,highlightedIndex:f,isOpen:d,itemRefs:_,scrollIntoView:r,getItemNodeFromIndex:C});(0,R.useEffect)(function(){return v.current=eM(function(e){e({type:XM,inputValue:``})},500),function(){v.current.cancel()}},[]),(0,R.useEffect)(function(){m&&v.current(u)},[u,m]),DM({isInitialMount:x.current,props:t,state:l}),(0,R.useEffect)(function(){x.current||(b.current=n.length)});var T=CM(d,[g,h],i,function(){u({type:VM})}),E=wM(`getMenuProps`,`getToggleButtonProps`);(0,R.useEffect)(function(){return x.current=!1,function(){x.current=!0}},[]),(0,R.useEffect)(function(){d||(_.current={})},[d]);var D=(0,R.useMemo)(function(){return{ArrowDown:function(e){e.preventDefault(),u({type:jM,getItemNodeFromIndex:C,altKey:e.altKey})},ArrowUp:function(e){e.preventDefault(),u({type:MM,getItemNodeFromIndex:C,altKey:e.altKey})},Home:function(e){e.preventDefault(),u({type:FM,getItemNodeFromIndex:C})},End:function(e){e.preventDefault(),u({type:IM,getItemNodeFromIndex:C})},Escape:function(){S.current.state.isOpen&&u({type:PM})},Enter:function(e){e.preventDefault(),u({type:S.current.state.isOpen?LM:AM})},PageUp:function(e){S.current.state.isOpen&&(e.preventDefault(),u({type:zM,getItemNodeFromIndex:C}))},PageDown:function(e){S.current.state.isOpen&&(e.preventDefault(),u({type:BM,getItemNodeFromIndex:C}))}," ":function(e){e.preventDefault();var t=S.current.state;if(!t.isOpen){u({type:AM});return}t.inputValue?u({type:NM,key:` `,getItemNodeFromIndex:C}):u({type:RM})}}},[u,C,S]),O=(0,R.useCallback)(function(){u({type:GM})},[u]),k=(0,R.useCallback)(function(){u({type:qM})},[u]),A=(0,R.useCallback)(function(){u({type:KM})},[u]),j=(0,R.useCallback)(function(e){u({type:JM,highlightedIndex:e})},[u]),M=(0,R.useCallback)(function(e){u({type:YM,selectedItem:e})},[u]),N=(0,R.useCallback)(function(){u({type:ZM})},[u]),P=(0,R.useCallback)(function(e){u({type:XM,inputValue:e})},[u]),F=(0,R.useCallback)(function(e){return q({id:y.labelId,htmlFor:y.toggleButtonId},e)},[y]),ee=(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onMouseLeave,a=r.refKey,o=a===void 0?`ref`:a;r.onKeyDown,r.onBlur;var s=r.ref,c=qj(r,Iue),l=(t===void 0?{}:t).suppressRefError;return E(`getMenuProps`,l===void 0?!1:l,o,g),q((n={},n[o]=nM(s,function(e){g.current=e}),n.id=y.menuId,n.role=`listbox`,n[`aria-labelledby`]=c&&c[`aria-label`]?void 0:``+y.labelId,n.onMouseLeave=tM(i,function(){u({type:HM})}),n),c)},[u,E,y]);return{getToggleButtonProps:(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onBlur,a=r.onClick;r.onPress;var o=r.onKeyDown,s=r.refKey,c=s===void 0?`ref`:s,l=r.ref,d=qj(r,Lue),f=(t===void 0?{}:t).suppressRefError,p=f===void 0?!1:f,m=S.current.state,g=function(){u({type:AM})},_=function(){m.isOpen&&!T.current.isMouseDown&&u({type:VM})},v=function(e){var t=aM(e);t&&D[t]?D[t](e):Aue(t)&&u({type:NM,key:t,getItemNodeFromIndex:C})},b=q((n={},n[c]=nM(l,function(e){h.current=e}),n[`aria-activedescendant`]=m.isOpen&&m.highlightedIndex>-1?y.getItemId(m.highlightedIndex):``,n[`aria-controls`]=y.menuId,n[`aria-expanded`]=S.current.state.isOpen,n[`aria-haspopup`]=`listbox`,n[`aria-labelledby`]=d&&d[`aria-label`]?void 0:``+y.labelId,n.id=y.toggleButtonId,n.role=`combobox`,n.tabIndex=0,n.onBlur=tM(i,_),n),d);return d.disabled||(b.onClick=tM(a,g),b.onKeyDown=tM(o,v)),E(`getToggleButtonProps`,p,c,h),b},[S,y,E,u,T,D,C]),getLabelProps:F,getMenuProps:ee,getItemProps:(0,R.useCallback)(function(e){var t,n=e===void 0?{}:e,r=n.item,i=n.index,a=n.onMouseMove,o=n.onClick;n.onPress;var s=n.refKey,c=s===void 0?`ref`:s,l=n.ref,d=n.disabled,f=qj(n,Rue),m=S.current,h=m.state,g=m.props,v=pM(r,i,g.items,`Pass either item or index to getItemProps!`),b=v[0],x=v[1],C=function(){x!==h.highlightedIndex&&(w.current=!1,u({type:UM,index:x,disabled:d}))},T=function(){u({type:WM,index:x})},E=q((t={disabled:d,role:`option`,"aria-selected":``+(b===p),id:y.getItemId(x)},t[c]=nM(l,function(e){e&&(_.current[y.getItemId(x)]=e)}),t),f);return d||(E.onClick=tM(o,T)),E.onMouseMove=tM(a,C),E},[S,p,y,w,u]),toggleMenu:O,openMenu:A,closeMenu:k,setHighlightedIndex:j,selectItem:M,reset:N,setInputValue:P,highlightedIndex:f,isOpen:d,selectedItem:p,inputValue:m}}var eN=0,tN=1,nN=2,rN=3,iN=4,aN=5,oN=6,sN=7,cN=8,lN=9,uN=10,dN=11,fN=12,pN=13,mN=14,hN=15,gN=16,_N=17,vN=18,yN=19,bN=20,xN=21,SN=22,CN=Object.freeze({__proto__:null,InputKeyDownArrowDown:eN,InputKeyDownArrowUp:tN,InputKeyDownEscape:nN,InputKeyDownHome:rN,InputKeyDownEnd:iN,InputKeyDownPageUp:aN,InputKeyDownPageDown:oN,InputKeyDownEnter:sN,InputChange:cN,InputBlur:lN,InputFocus:uN,MenuMouseLeave:dN,ItemMouseMove:fN,ItemClick:pN,ToggleButtonClick:mN,FunctionToggleMenu:hN,FunctionOpenMenu:gN,FunctionCloseMenu:_N,FunctionSetHighlightedIndex:vN,FunctionSelectItem:yN,FunctionSetInputValue:bN,FunctionReset:xN,ControlledPropUpdatedSelectedItem:SN});function zue(e){var t=xM(e),n=t.selectedItem,r=t.inputValue;return r===``&&n&&e.defaultInputValue===void 0&&e.initialInputValue===void 0&&e.inputValue===void 0&&(r=e.itemToString(n)),q({},t,{inputValue:r})}J.default.array.isRequired,J.default.func,J.default.func,J.default.func,J.default.func,J.default.number,J.default.number,J.default.number,J.default.bool,J.default.bool,J.default.bool,J.default.any,J.default.any,J.default.any,J.default.string,J.default.string,J.default.string,J.default.string,J.default.string,J.default.string,J.default.func,J.default.string,J.default.string,J.default.func,J.default.func,J.default.func,J.default.func,J.default.func,J.default.func,J.default.shape({addEventListener:J.default.func,removeEventListener:J.default.func,document:J.default.shape({getElementById:J.default.func,activeElement:J.default.any,body:J.default.any})});function Bue(e,t,n){var r=(0,R.useRef)(),i=gM(e,t,n),a=i[0],o=i[1];return(0,R.useEffect)(function(){iM(n,`selectedItem`)&&(n.selectedItemChanged(r.current,n.selectedItem)&&o({type:SN,inputValue:n.itemToString(n.selectedItem)}),r.current=a.selectedItem===r.current?n.selectedItem:a.selectedItem)},[a.selectedItem,n.selectedItem]),[rM(a,n),o]}var Vue=Qj,Hue=q({},vM,{selectedItemChanged:function(e,t){return e!==t},getA11yStatusMessage:bue});function Uue(e,t){var n=t.type,r=t.props,i=t.altKey,a;switch(n){case pN:a={isOpen:yM(r,`isOpen`),highlightedIndex:yM(r,`highlightedIndex`),selectedItem:r.items[t.index],inputValue:r.itemToString(r.items[t.index])};break;case eN:a=e.isOpen?{highlightedIndex:oM(1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!0)}:{highlightedIndex:i&&e.selectedItem==null?-1:SM(r,e,1,t.getItemNodeFromIndex),isOpen:r.items.length>=0};break;case tN:a=e.isOpen?i?OM(r,e.highlightedIndex):{highlightedIndex:oM(-1,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!0)}:{highlightedIndex:SM(r,e,-1,t.getItemNodeFromIndex),isOpen:r.items.length>=0};break;case sN:a=OM(r,e.highlightedIndex);break;case nN:a=q({isOpen:!1,highlightedIndex:-1},!e.isOpen&&{selectedItem:null,inputValue:``});break;case aN:a={highlightedIndex:oM(-10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case oN:a={highlightedIndex:oM(10,e.highlightedIndex,r.items.length,t.getItemNodeFromIndex,!1)};break;case rN:a={highlightedIndex:sM(1,0,r.items.length,t.getItemNodeFromIndex,!1)};break;case iN:a={highlightedIndex:sM(-1,r.items.length-1,r.items.length,t.getItemNodeFromIndex,!1)};break;case lN:a=q({isOpen:!1,highlightedIndex:-1},e.highlightedIndex>=0&&r.items?.length&&t.selectItem&&{selectedItem:r.items[e.highlightedIndex],inputValue:r.itemToString(r.items[e.highlightedIndex])});break;case cN:a={isOpen:!0,highlightedIndex:yM(r,`highlightedIndex`),inputValue:t.inputValue};break;case uN:a={isOpen:!0,highlightedIndex:SM(r,e,0)};break;case yN:a={selectedItem:t.selectedItem,inputValue:r.itemToString(t.selectedItem)};break;case SN:a={inputValue:t.inputValue};break;default:return kM(e,t,CN)}return q({},e,a)}var Wue=[`onMouseLeave`,`refKey`,`ref`],Gue=[`item`,`index`,`refKey`,`ref`,`onMouseMove`,`onMouseDown`,`onClick`,`onPress`,`disabled`],Kue=[`onClick`,`onPress`,`refKey`,`ref`],que=[`onKeyDown`,`onChange`,`onInput`,`onFocus`,`onBlur`,`onChangeText`,`refKey`,`ref`];wN.stateChangeTypes=CN;function wN(e){e===void 0&&(e={}),Vue(e,wN);var t=q({},Hue,e),n=t.initialIsOpen,r=t.defaultIsOpen,i=t.items,a=t.scrollIntoView,o=t.environment,s=t.getA11yStatusMessage,c=t.getA11ySelectionMessage,l=t.itemToString,u=Bue(Uue,zue(t),t),d=u[0],f=u[1],p=d.isOpen,m=d.highlightedIndex,h=d.selectedItem,g=d.inputValue,_=(0,R.useRef)(null),v=(0,R.useRef)({}),y=(0,R.useRef)(null),b=(0,R.useRef)(null),x=(0,R.useRef)(!0),S=fM(t),C=(0,R.useRef)(),w=hM({state:d,props:t}),T=(0,R.useCallback)(function(e){return v.current[S.getItemId(e)]},[S]);TM(s,[p,m,g,i],q({isInitialMount:x.current,previousResultCount:C.current,items:i,environment:o,itemToString:l},d)),TM(c,[h],q({isInitialMount:x.current,previousResultCount:C.current,items:i,environment:o,itemToString:l},d));var E=EM({menuElement:_.current,highlightedIndex:m,isOpen:p,itemRefs:v,scrollIntoView:a,getItemNodeFromIndex:T});DM({isInitialMount:x.current,props:t,state:d}),(0,R.useEffect)(function(){(n||r||p)&&y.current&&y.current.focus()},[]),(0,R.useEffect)(function(){x.current||(C.current=i.length)});var D=CM(p,[y,_,b],o,function(){f({type:lN,selectItem:!1})}),O=wM(`getInputProps`,`getMenuProps`);(0,R.useEffect)(function(){return x.current=!1,function(){x.current=!0}},[]),(0,R.useEffect)(function(){if(!p)v.current={};else if(o.document?.activeElement!==y.current){var e;y==null||(e=y.current)==null||e.focus()}},[p,o]);var k=(0,R.useMemo)(function(){return{ArrowDown:function(e){e.preventDefault(),f({type:eN,altKey:e.altKey,getItemNodeFromIndex:T})},ArrowUp:function(e){e.preventDefault(),f({type:tN,altKey:e.altKey,getItemNodeFromIndex:T})},Home:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:rN,getItemNodeFromIndex:T}))},End:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:iN,getItemNodeFromIndex:T}))},Escape:function(e){var t=w.current.state;(t.isOpen||t.inputValue||t.selectedItem||t.highlightedIndex>-1)&&(e.preventDefault(),f({type:nN}))},Enter:function(e){!w.current.state.isOpen||e.which===229||(e.preventDefault(),f({type:sN,getItemNodeFromIndex:T}))},PageUp:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:aN,getItemNodeFromIndex:T}))},PageDown:function(e){w.current.state.isOpen&&(e.preventDefault(),f({type:oN,getItemNodeFromIndex:T}))}}},[f,w,T]),A=(0,R.useCallback)(function(e){return q({id:S.labelId,htmlFor:S.inputId},e)},[S]),j=(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onMouseLeave,a=r.refKey,o=a===void 0?`ref`:a,s=r.ref,c=qj(r,Wue),l=(t===void 0?{}:t).suppressRefError;return O(`getMenuProps`,l===void 0?!1:l,o,_),q((n={},n[o]=nM(s,function(e){_.current=e}),n.id=S.menuId,n.role=`listbox`,n[`aria-labelledby`]=c&&c[`aria-label`]?void 0:``+S.labelId,n.onMouseLeave=tM(i,function(){f({type:dN})}),n),c)},[f,O,S]),M=(0,R.useCallback)(function(e){var t,n,r=e===void 0?{}:e,i=r.item,a=r.index,o=r.refKey,s=o===void 0?`ref`:o,c=r.ref,l=r.onMouseMove,u=r.onMouseDown,d=r.onClick;r.onPress;var p=r.disabled,m=qj(r,Gue),h=w.current,g=h.props,_=h.state,y=pM(i,a,g.items,`Pass either item or index to getItemProps!`)[1],b=`onClick`,x=d;return q((t={},t[s]=nM(c,function(e){e&&(v.current[S.getItemId(y)]=e)}),t.disabled=p,t.role=`option`,t[`aria-selected`]=``+(y===_.highlightedIndex),t.id=S.getItemId(y),t),!p&&(n={},n[b]=tM(x,function(){f({type:pN,index:y})}),n),{onMouseMove:tM(l,function(){y!==_.highlightedIndex&&(E.current=!1,f({type:fN,index:y,disabled:p}))}),onMouseDown:tM(u,function(e){return e.preventDefault()})},m)},[f,w,E,S]),N=(0,R.useCallback)(function(e){var t,n=e===void 0?{}:e,r=n.onClick;n.onPress;var i=n.refKey,a=i===void 0?`ref`:i,o=n.ref,s=qj(n,Kue),c=w.current.state;return q((t={},t[a]=nM(o,function(e){b.current=e}),t[`aria-controls`]=S.menuId,t[`aria-expanded`]=c.isOpen,t.id=S.toggleButtonId,t.tabIndex=-1,t),!s.disabled&&q({},{onClick:tM(r,function(){f({type:mN})})}),s)},[f,w,S]),P=(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.onKeyDown,a=r.onChange,s=r.onInput,c=r.onFocus,l=r.onBlur;r.onChangeText;var u=r.refKey,d=u===void 0?`ref`:u,p=r.ref,m=qj(r,que),h=(t===void 0?{}:t).suppressRefError;O(`getInputProps`,h===void 0?!1:h,d,y);var g=w.current.state,_=function(e){var t=aM(e);t&&k[t]&&k[t](e)},v=function(e){f({type:cN,inputValue:e.target.value})},b=function(e){g.isOpen&&!D.current.isMouseDown&&f({type:lN,selectItem:!(e.relatedTarget===null&&o.document.activeElement!==o.document.body)})},x=function(){g.isOpen||f({type:uN})},C=`onChange`,T={};if(!m.disabled){var E;T=(E={},E[C]=tM(a,s,v),E.onKeyDown=tM(i,_),E.onBlur=tM(l,b),E.onFocus=tM(c,x),E)}return q((n={},n[d]=nM(p,function(e){y.current=e}),n[`aria-activedescendant`]=g.isOpen&&g.highlightedIndex>-1?S.getItemId(g.highlightedIndex):``,n[`aria-autocomplete`]=`list`,n[`aria-controls`]=S.menuId,n[`aria-expanded`]=g.isOpen,n[`aria-labelledby`]=m&&m[`aria-label`]?void 0:``+S.labelId,n.autoComplete=`off`,n.id=S.inputId,n.role=`combobox`,n.value=g.inputValue,n),T,m)},[O,w,S,k,f,D,o]),F=(0,R.useCallback)(function(){f({type:hN})},[f]),ee=(0,R.useCallback)(function(){f({type:_N})},[f]),te=(0,R.useCallback)(function(){f({type:gN})},[f]),I=(0,R.useCallback)(function(e){f({type:vN,highlightedIndex:e})},[f]),ne=(0,R.useCallback)(function(e){f({type:yN,selectedItem:e})},[f]);return{getItemProps:M,getLabelProps:A,getMenuProps:j,getInputProps:P,getToggleButtonProps:N,toggleMenu:F,openMenu:te,closeMenu:ee,setHighlightedIndex:I,setInputValue:(0,R.useCallback)(function(e){f({type:bN,inputValue:e})},[f]),selectItem:ne,reset:(0,R.useCallback)(function(){f({type:xN})},[f]),highlightedIndex:m,isOpen:p,selectedItem:h,inputValue:g}}var TN={activeIndex:-1,selectedItems:[]};function EN(e,t){return bM(e,t,TN)}function DN(e,t){return yM(e,t,TN)}function Jue(e){return{activeIndex:EN(e,`activeIndex`),selectedItems:EN(e,`selectedItems`)}}function ON(e){if(e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)return!1;var t=e.target;return!(t instanceof HTMLInputElement&&t.value!==``&&(t.selectionStart!==0||t.selectionEnd!==0))}function Yue(e){var t=e.removedSelectedItem,n=e.itemToString;return n(t)+` has been removed.`}J.default.array,J.default.array,J.default.array,J.default.func,J.default.func,J.default.func,J.default.number,J.default.number,J.default.number,J.default.func,J.default.func,J.default.string,J.default.string,J.default.shape({addEventListener:J.default.func,removeEventListener:J.default.func,document:J.default.shape({getElementById:J.default.func,activeElement:J.default.any,body:J.default.any})});var Xue={itemToString:vM.itemToString,stateReducer:vM.stateReducer,environment:vM.environment,getA11yRemovalMessage:Yue,keyNavigationNext:`ArrowRight`,keyNavigationPrevious:`ArrowLeft`},Zue=Qj,kN=0,AN=1,jN=2,MN=3,NN=4,PN=5,FN=6,IN=7,LN=8,RN=9,zN=10,BN=11,VN=12,Que=Object.freeze({__proto__:null,SelectedItemClick:kN,SelectedItemKeyDownDelete:AN,SelectedItemKeyDownBackspace:jN,SelectedItemKeyDownNavigationNext:MN,SelectedItemKeyDownNavigationPrevious:NN,DropdownKeyDownNavigationPrevious:PN,DropdownKeyDownBackspace:FN,DropdownClick:IN,FunctionAddSelectedItem:LN,FunctionRemoveSelectedItem:RN,FunctionSetSelectedItems:zN,FunctionSetActiveIndex:BN,FunctionReset:VN});function $ue(e,t){var n=t.type,r=t.index,i=t.props,a=t.selectedItem,o=e.activeIndex,s=e.selectedItems,c;switch(n){case kN:c={activeIndex:r};break;case NN:c={activeIndex:o-1<0?0:o-1};break;case MN:c={activeIndex:o+1>=s.length?-1:o+1};break;case jN:case AN:if(o<0)break;var l=o;s.length===1?l=-1:o===s.length-1&&(l=s.length-2),c=q({selectedItems:[].concat(s.slice(0,o),s.slice(o+1))},{activeIndex:l});break;case PN:c={activeIndex:s.length-1};break;case FN:c={selectedItems:s.slice(0,s.length-1)};break;case LN:c={selectedItems:[].concat(s,[a])};break;case IN:c={activeIndex:-1};break;case RN:var u=o,d=s.indexOf(a);if(d<0)break;s.length===1?u=-1:d===s.length-1&&(u=s.length-2),c={selectedItems:[].concat(s.slice(0,d),s.slice(d+1)),activeIndex:u};break;case zN:c={selectedItems:t.selectedItems};break;case BN:c={activeIndex:t.activeIndex};break;case VN:c={activeIndex:DN(i,`activeIndex`),selectedItems:DN(i,`selectedItems`)};break;default:throw Error(`Reducer called without proper action type.`)}return q({},e,c)}var ede=[`refKey`,`ref`,`onClick`,`onKeyDown`,`selectedItem`,`index`],tde=[`refKey`,`ref`,`onKeyDown`,`onClick`,`preventKeyAction`];HN.stateChangeTypes=Que;function HN(e){e===void 0&&(e={}),Zue(e,HN);var t=q({},Xue,e),n=t.getA11yRemovalMessage,r=t.itemToString,i=t.environment,a=t.keyNavigationNext,o=t.keyNavigationPrevious,s=_M($ue,Jue(t),t),c=s[0],l=s[1],u=c.activeIndex,d=c.selectedItems,f=(0,R.useRef)(!0),p=(0,R.useRef)(null),m=(0,R.useRef)(d),h=(0,R.useRef)();h.current=[];var g=hM({state:c,props:t});(0,R.useEffect)(function(){if(!f.current){if(d.length<m.current.length){var e=m.current.find(function(e){return d.indexOf(e)<0});lM(n({itemToString:r,resultCount:d.length,removedSelectedItem:e,activeIndex:u,activeSelectedItem:d[u]}),i.document)}m.current=d}},[d.length]),(0,R.useEffect)(function(){f.current||(u===-1&&p.current?p.current.focus():h.current[u]&&h.current[u].focus())},[u]),DM({isInitialMount:f.current,props:t,state:c});var _=wM(`getDropdownProps`);(0,R.useEffect)(function(){return f.current=!1,function(){f.current=!0}},[]);var v=(0,R.useMemo)(function(){var e;return e={},e[o]=function(){l({type:NN})},e[a]=function(){l({type:MN})},e.Delete=function(){l({type:AN})},e.Backspace=function(){l({type:jN})},e},[l,a,o]),y=(0,R.useMemo)(function(){var e;return e={},e[o]=function(e){ON(e)&&l({type:PN})},e.Backspace=function(e){ON(e)&&l({type:FN})},e},[l,o]);return{getSelectedItemProps:(0,R.useCallback)(function(e){var t,n=e===void 0?{}:e,r=n.refKey,i=r===void 0?`ref`:r,a=n.ref,o=n.onClick,s=n.onKeyDown,c=n.selectedItem,u=n.index,d=qj(n,ede),f=g.current.state,p=pM(c,u,f.selectedItems,`Pass either item or index to getSelectedItemProps!`)[1],m=p>-1&&p===f.activeIndex;return q((t={},t[i]=nM(a,function(e){e&&h.current.push(e)}),t.tabIndex=m?0:-1,t.onClick=tM(o,function(){l({type:kN,index:p})}),t.onKeyDown=tM(s,function(e){var t=aM(e);t&&v[t]&&v[t](e)}),t),d)},[l,g,v]),getDropdownProps:(0,R.useCallback)(function(e,t){var n,r=e===void 0?{}:e,i=r.refKey,a=i===void 0?`ref`:i,o=r.ref,s=r.onKeyDown,c=r.onClick,u=r.preventKeyAction,d=u===void 0?!1:u,f=qj(r,tde),m=(t===void 0?{}:t).suppressRefError;return _(`getDropdownProps`,m===void 0?!1:m,a,p),q((n={},n[a]=nM(o,function(e){e&&(p.current=e)}),n),!d&&{onKeyDown:tM(s,function(e){var t=aM(e);t&&y[t]&&y[t](e)}),onClick:tM(c,function(){l({type:IN})})},f)},[l,y,_]),addSelectedItem:(0,R.useCallback)(function(e){l({type:LN,selectedItem:e})},[l]),removeSelectedItem:(0,R.useCallback)(function(e){l({type:RN,selectedItem:e})},[l]),setSelectedItems:(0,R.useCallback)(function(e){l({type:zN,selectedItems:e})},[l]),setActiveIndex:(0,R.useCallback)(function(e){l({type:BN,activeIndex:e})},[l]),reset:(0,R.useCallback)(function(){l({type:VN})},[l]),selectedItems:d,activeIndex:u}}var UN=20,nde=e=>e.suggestions.length>0?R.createElement(rde,{...e}):R.createElement(`input`,{className:mw.textInput,size:40,autoFocus:!0,...e.register(e.inputName)}),rde=({autofocus:e,suggestions:t,control:n,inputName:r,placeholder:i,initialInputValue:a,setValue:o})=>{let[s,c]=R.useState(t.slice(0,UN)),l=Vl(NC),u=t.length>0,{isOpen:d,getToggleButtonProps:f,getMenuProps:p,getInputProps:m,highlightedIndex:h,getItemProps:g,selectedItem:_}=wN({initialInputValue:a,onInputValueChange({inputValue:e=``}){o(r,e),e=e.toLowerCase()||``;let n=[];for(let r of t)if(r.toLowerCase().includes(e)&&(n.push(r),n.length>=UN))break;c(n)},items:s,itemToString(e){return e??``}}),v=d&&s.length>0;return R.createElement(`div`,{className:mw.downshiftAutocompleteContainer},R.createElement(`div`,{"data-visible-dropdown":v,className:mw.downshiftInputWrapper},R.createElement(Gle,{name:r,control:n,render:({field:t})=>{let n=m();return R.createElement(`input`,{...n,name:t.name,placeholder:i,className:mw.downshiftInput,size:30,"data-editor-dialog":!0,autoFocus:e})}}),u&&R.createElement(`button`,{"aria-label":`toggle menu`,type:`button`,...f()},l(`arrow_drop_down`))),R.createElement(`div`,{className:mw.downshiftAutocompleteContainer},R.createElement(`ul`,{...p(),"data-visible":v},s.map((e,t)=>R.createElement(`li`,{"data-selected":_===e,"data-highlighted":h===t,key:`${e}${t}`,...g({item:e,index:t})},e)))))};function ide(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);return e.replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`).replace(/-/g,`\\x2d`)}var ade={testNode:`blockquote`,visitNode({actions:e}){e.addAndStepInto(wv())}},ode={testLexicalNode:Tv,visitLexicalNode:({actions:e})=>{e.addAndStepInto(`blockquote`)}},sde=Xl({init(e){e.pubIn({[ew]:`quote`,[yC]:ade,[vC]:Cv,[SC]:ode})}});function WN(){let e=Yl;return{publish:()=>{e()},subscribe:t=>{e=t}}}var cde=Object.defineProperty,lde=(e,t,n)=>t in e?cde(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,GN=(e,t,n)=>(lde(e,typeof t==`symbol`?t:t+``,n),n),KN=class e extends Wm{constructor(e,t,n,r){super(r),GN(this,`__code`),GN(this,`__meta`),GN(this,`__language`),GN(this,`__focusEmitter`,WN()),GN(this,`setCode`,e=>{e!==this.__code&&(this.getWritable().__code=e)}),GN(this,`setMeta`,e=>{e!==this.__meta&&(this.getWritable().__meta=e)}),GN(this,`setLanguage`,e=>{e!==this.__language&&(this.getWritable().__language=e)}),GN(this,`select`,()=>{this.__focusEmitter.publish()}),this.__code=e,this.__meta=n,this.__language=t}static getType(){return`codeblock`}static clone(t){return new e(t.__code,t.__language,t.__meta,t.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__code=e.__code,this.__meta=e.__meta,this.__language=e.__language,this.__focusEmitter=WN()}static importJSON(e){let{code:t,meta:n,language:r}=e;return YN({code:t,language:r,meta:n})}static importDOM(){return{pre:()=>({conversion:pde,priority:3})}}exportJSON(){return{code:this.getCode(),language:this.getLanguage(),meta:this.getMeta(),type:`codeblock`,version:1}}createDOM(e,t){return document.createElement(`div`)}updateDOM(){return!1}getCode(){return this.__code}getMeta(){return this.__meta}getLanguage(){return this.__language}decorate(e){return R.createElement(dde,{parentEditor:e,code:this.getCode(),meta:this.getMeta(),language:this.getLanguage(),codeBlockNode:this,nodeKey:this.getKey(),focusEmitter:this.__focusEmitter})}isInline(){return!1}},qN=R.createContext(null),ude=({parentEditor:e,lexicalNode:t,children:n})=>{let r=R.useMemo(()=>({lexicalNode:t,parentEditor:e,setCode:n=>{e.update(()=>{t.setCode(n),setTimeout(()=>{e.dispatchCommand(zS,void 0)},0)})},setLanguage:n=>{e.update(()=>{t.setLanguage(n)})},setMeta:n=>{e.update(()=>{t.setMeta(n)})}}),[t,e]);return R.createElement(qN.Provider,{value:r},n)};function JN(){let e=R.useContext(qN);if(!e)throw Error(`useCodeBlockEditor must be used within a CodeBlockEditor`);return e}var dde=e=>{let t=Vl(mC),n=Vl(XN),r=t.sort((e,t)=>t.priority-e.priority).find(t=>t.match(e.language||``,e.meta||``));if(r??=t.find(t=>t.match(n||``,e.meta||``)),!r)throw Error(`No CodeBlockEditor registered for language=${e.language} meta=${e.meta}`);let i=r.Editor,{codeBlockNode:a,parentEditor:o,...s}=e;return R.createElement(ude,{parentEditor:e.parentEditor,lexicalNode:e.codeBlockNode},R.createElement(i,{...s}))};function YN(e){let{code:t=``,language:n=``,meta:r=``}=e;return new KN(t,n,r)}function fde(e){return e instanceof KN}function pde(e){let t=e,n=t.textContent,r=e.getAttribute(`class`)??``,i=e.getAttribute(`data-language`)??``,a=/language-(\w+)/.exec(r);return{node:YN({code:n,language:a?a[1]:i,meta:t.getAttribute(`data-meta`)??``})}}var mde={testLexicalNode:fde,visitLexicalNode:({lexicalNode:e,actions:t})=>{t.addAndStepInto(`code`,{value:e.getCode(),lang:e.getLanguage(),meta:e.getMeta()})}},hde={testNode:(e,{codeBlockEditorDescriptors:t})=>e.type===`code`?t.find(t=>t.match(e.lang,e.meta))!==void 0:!1,visitNode({mdastNode:e,actions:t}){t.addAndStepInto(YN({code:e.value,language:e.lang??``,meta:e.meta??``}))}},XN=Il(``),ZN=Ll(e=>{e.link(e.pipe(ZN,Gl(XN),Wl(([e,t])=>()=>YN({language:t,...e}))),XC)}),gde=PC(mC),_de=Xl({update(e,t){e.pub(XN,t?.defaultCodeBlockLanguage??``)},init(e,t){e.pubIn({[ew]:`codeblock`,[mC]:t?.codeBlockEditorDescriptors??[],[yC]:hde,[vC]:KN,[SC]:mde})}}),vde=`modulepreload`,yde=function(e){return`/apps/chat/`+e},QN={},Y=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=yde(t,n),t in QN)return;QN[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:vde,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},$N=class{constructor(e,t,n,r){this.state=e,this.pos=t,this.explicit=n,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ae(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),r=t.text.slice(n-t.from,this.pos-t.from),i=r.search(iP(e,!1));return i<0?null:{from:n+i,to:this.pos,text:r.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e==`abort`&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}};function eP(e){let t=Object.keys(e).join(``),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,``)),`[${n?`\\w`:``}${t.replace(/[^\w\s]/g,`\\$&`)}]`}function bde(e){let t=Object.create(null),n=Object.create(null);for(let{label:r}of e){t[r[0]]=!0;for(let e=1;e<r.length;e++)n[r[e]]=!0}let r=eP(t)+eP(n)+`*$`;return[RegExp(`^`+r),new RegExp(r)]}function tP(e){let t=e.map(e=>typeof e==`string`?{label:e}:e),[n,r]=t.every(e=>/^\w+$/.test(e.label))?[/\w*$/,/\w+$/]:bde(t);return e=>{let i=e.matchBefore(r);return i||e.explicit?{from:i?i.from:e.pos,options:t,validFor:n}:null}}function xde(e,t){return n=>{for(let t=ae(n.state).resolveInner(n.pos,-1);t;t=t.parent){if(e.indexOf(t.name)>-1)return null;if(t.type.isTop)break}return t(n)}}var nP=class{constructor(e,t,n,r){this.completion=e,this.source=t,this.match=n,this.score=r}};function rP(e){return e.selection.main.from}function iP(e,t){let{source:n}=e,r=t&&n[0]!=`^`,i=n[n.length-1]!=`$`;return!r&&!i?e:RegExp(`${r?`^`:``}(?:${n})${i?`$`:``}`,e.flags??(e.ignoreCase?`i`:``))}var aP=he.define();function Sde(e,t,n,r){let{main:i}=e.selection,a=n-i.from,o=r-i.from;return{...e.changeByRange(s=>{if(s!=i&&n!=r&&e.sliceDoc(s.from+a,s.from+o)!=e.sliceDoc(n,r))return{range:s};let c=e.toText(t);return{changes:{from:s.from+a,to:r==i.from?s.to:s.from+o,insert:c},range:k.cursor(s.from+a+c.length)}}),scrollIntoView:!0,userEvent:`input.complete`}}var oP=new WeakMap;function Cde(e){if(!Array.isArray(e))return e;let t=oP.get(e);return t||oP.set(e,t=tP(e)),t}var sP=w.define(),cP=w.define(),wde=class{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let n=se(e,t),r=a(n);this.chars.push(n);let i=e.slice(t,t+r),o=i.toUpperCase();this.folded.push(se(o==i?i.toLowerCase():o,0)),t+=r}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:n,any:r,precise:i,byWord:o}=this;if(t.length==1){let r=se(e,0),i=a(r),o=i==e.length?0:-100;if(r!=t[0])if(r==n[0])o+=-200;else return null;return this.ret(o,[0,i])}let s=e.indexOf(this.pattern);if(s==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=t.length,l=0;if(s<0){for(let i=0,o=Math.min(e.length,200);i<o&&l<c;){let o=se(e,i);(o==t[l]||o==n[l])&&(r[l++]=i),i+=a(o)}if(l<c)return null}let u=0,d=0,f=!1,p=0,m=-1,h=-1,g=/[a-z]/.test(e),_=!0;for(let r=0,l=Math.min(e.length,200),v=0;r<l&&d<c;){let l=se(e,r);s<0&&(u<c&&l==t[u]&&(i[u++]=r),p<c&&(l==t[p]||l==n[p]?(p==0&&(m=r),h=r+1,p++):p=0));let b,x=l<255?l>=48&&l<=57||l>=97&&l<=122?2:+(l>=65&&l<=90):(b=y(l))==b.toLowerCase()?b==b.toUpperCase()?0:2:1;(!r||x==1&&g||v==0&&x!=0)&&(t[d]==l||n[d]==l&&(f=!0)?o[d++]=r:o.length&&(_=!1)),v=x,r+=a(l)}return d==c&&o[0]==0&&_?this.result(-100+(f?-200:0),o,e):p==c&&m==0?this.ret(-200-e.length+(h==e.length?0:-100),[0,h]):s>-1?this.ret(-700-e.length,[s,s+this.pattern.length]):p==c?this.ret(-900-e.length,[m,h]):d==c?this.result(-100+(f?-200:0)+-700+(_?0:-1100),o,e):t.length==2?null:this.result((r[0]?-700:0)+-200+-1100,r,e)}result(e,t,n){let r=[],i=0;for(let e of t){let t=e+(this.astral?a(se(n,e)):1);i&&r[i-1]==e?r[i-1]=t:(r[i++]=e,r[i++]=t)}return this.ret(e-n.length,r)}},Tde=class{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),n=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return n==null?null:(this.matched=[0,t.length],this.score=n+(e.length==this.pattern.length?0:-100),this)}},lP=Oe.define({combine(e){return oe(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>``,optionClass:()=>``,aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Ede,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>n=>uP(e(n),t(n)),optionClass:(e,t)=>n=>uP(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function uP(e,t){return e?t?e+` `+t:e:t}function Ede(e,t,n,r,i,a){let o=e.textDirection==u.RTL,s=o,c=!1,l=`top`,d,f,p=t.left-i.left,m=i.right-t.right,h=r.right-r.left,g=r.bottom-r.top;if(s&&p<Math.min(h,m)?s=!1:!s&&m<Math.min(h,p)&&(s=!0),h<=(s?p:m))d=Math.max(i.top,Math.min(n.top,i.bottom-g))-t.top,f=Math.min(400,s?p:m);else{c=!0,f=Math.min(400,(o?t.right:i.right-t.left)-30);let e=i.bottom-t.bottom;e>=g||e>t.top?d=n.bottom-t.top:(l=`bottom`,d=t.bottom-n.top)}let _=(t.bottom-t.top)/a.offsetHeight,v=(t.right-t.left)/a.offsetWidth;return{style:`${l}: ${d/_}px; max-width: ${f/v}px`,class:`cm-completionInfo-`+(c?o?`left-narrow`:`right-narrow`:s?`left`:`right`)}}var dP=w.define();function Dde(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(e){let t=document.createElement(`div`);return t.classList.add(`cm-completionIcon`),e.type&&t.classList.add(...e.type.split(/\s+/g).map(e=>`cm-completionIcon-`+e)),t.setAttribute(`aria-hidden`,`true`),t},position:20}),t.push({render(e,t,n,r){let i=document.createElement(`span`);i.className=`cm-completionLabel`;let a=e.displayLabel||e.label,o=0;for(let e=0;e<r.length;){let t=r[e++],n=r[e++];t>o&&i.appendChild(document.createTextNode(a.slice(o,t)));let s=i.appendChild(document.createElement(`span`));s.appendChild(document.createTextNode(a.slice(t,n))),s.className=`cm-completionMatchedText`,o=n}return o<a.length&&i.appendChild(document.createTextNode(a.slice(o))),i},position:50},{render(e){if(!e.detail)return null;let t=document.createElement(`span`);return t.className=`cm-completionDetail`,t.textContent=e.detail,t},position:80}),t.sort((e,t)=>e.position-t.position).map(e=>e.render)}function fP(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let e=Math.floor(t/n);return{from:e*n,to:(e+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}var Ode=class{constructor(e,t,n){this.view=e,this.stateField=t,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:e=>this.placeInfo(e),key:this},this.space=null,this.currentClass=``;let r=e.state.field(t),{options:i,selected:a}=r.open,o=e.state.facet(lP);this.optionContent=Dde(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=fP(i.length,a,o.maxRenderedOptions),this.dom=document.createElement(`div`),this.dom.className=`cm-tooltip-autocomplete`,this.updateTooltipClass(e.state),this.dom.addEventListener(`mousedown`,n=>{let{options:r}=e.state.field(t).open;for(let t=n.target,i;t&&t!=this.dom;t=t.parentNode)if(t.nodeName==`LI`&&(i=/-(\d+)$/.exec(t.id))&&+i[1]<r.length){this.applyCompletion(e,r[+i[1]]),n.preventDefault();return}if(n.target==this.list){let t=this.list.classList.contains(`cm-completionListIncompleteTop`)&&n.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains(`cm-completionListIncompleteBottom`)&&n.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;t!=null&&(e.dispatch({effects:dP.of(t)}),n.preventDefault())}}),this.dom.addEventListener(`focusout`,t=>{let n=e.state.field(this.stateField,!1);n&&n.tooltip&&e.state.facet(lP).closeOnBlur&&t.relatedTarget!=e.contentDOM&&e.dispatch({effects:cP.of(null)})}),this.showOptions(i,r.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener(`scroll`,()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){let t=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),t!=n){let{options:r,selected:i,disabled:a}=t.open;(!n.open||n.open.options!=r)&&(this.range=fP(r.length,i,e.state.facet(lP).maxRenderedOptions),this.showOptions(r,t.id)),this.updateSel(),a!=n.open?.disabled&&this.dom.classList.toggle(`cm-tooltip-autocomplete-disabled`,!!a)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let e of this.currentClass.split(` `))e&&this.dom.classList.remove(e);for(let e of t.split(` `))e&&this.dom.classList.add(e);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=fP(t.options.length,t.selected,this.view.state.facet(lP).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:r}=t.options[t.selected],{info:i}=r;if(!i)return;let a=typeof i==`string`?document.createTextNode(i):i(r);if(!a)return;`then`in a?a.then(t=>{t&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(t,r)}).catch(e=>me(this.view.state,e,`completion info`)):(this.addInfoPane(a,r),n.setAttribute(`aria-describedby`,this.info.id))}}addInfoPane(e,t){this.destroyInfo();let n=this.info=document.createElement(`div`);if(n.className=`cm-tooltip cm-completionInfo`,n.id=`cm-completionInfo-`+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)n.appendChild(e),this.infoDestroy=null;else{let{dom:t,destroy:r}=e;n.appendChild(t),this.infoDestroy=r||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,r=this.range.from;n;n=n.nextSibling,r++)n.nodeName!=`LI`||!n.id?r--:r==e?n.hasAttribute(`aria-selected`)||(n.setAttribute(`aria-selected`,`true`),t=n):n.hasAttribute(`aria-selected`)&&(n.removeAttribute(`aria-selected`),n.removeAttribute(`aria-describedby`));return t&&Ade(this.list,t),t}measureInfo(){let e=this.dom.querySelector(`[aria-selected]`);if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),r=e.getBoundingClientRect(),i=this.space;if(!i){let e=this.dom.ownerDocument.documentElement;i={left:0,top:0,right:e.clientWidth,bottom:e.clientHeight}}return r.top>Math.min(i.bottom,t.bottom)-10||r.bottom<Math.max(i.top,t.top)+10?null:this.view.state.facet(lP).positionInfo(this.view,t,r,n,i,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className=`cm-tooltip cm-completionInfo `+(e.class||``)):this.info.style.cssText=`top: -1e6px`)}createListBox(e,t,n){let r=document.createElement(`ul`);r.id=t,r.setAttribute(`role`,`listbox`),r.setAttribute(`aria-expanded`,`true`),r.setAttribute(`aria-label`,this.view.state.phrase(`Completions`)),r.addEventListener(`mousedown`,e=>{e.target==r&&e.preventDefault()});let i=null;for(let a=n.from;a<n.to;a++){let{completion:o,match:s}=e[a],{section:c}=o;if(c){let e=typeof c==`string`?c:c.name;if(e!=i&&(a>n.from||n.from==0))if(i=e,typeof c!=`string`&&c.header)r.appendChild(c.header(c));else{let t=r.appendChild(document.createElement(`completion-section`));t.textContent=e}}let l=r.appendChild(document.createElement(`li`));l.id=t+`-`+a,l.setAttribute(`role`,`option`);let u=this.optionClass(o);u&&(l.className=u);for(let e of this.optionContent){let t=e(o,this.view.state,this.view,s);t&&l.appendChild(t)}}return n.from&&r.classList.add(`cm-completionListIncompleteTop`),n.to<e.length&&r.classList.add(`cm-completionListIncompleteBottom`),r}destroyInfo(){this.info&&=(this.infoDestroy&&this.infoDestroy(),this.info.remove(),null)}destroy(){this.destroyInfo()}};function kde(e,t){return n=>new Ode(n,e,t)}function Ade(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),i=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/i)}function pP(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+ +!!e.type}function jde(e,t){let n=[],r=null,i=null,a=e=>{n.push(e);let{section:t}=e.completion;if(t){r||=[];let e=typeof t==`string`?t:t.name;r.some(t=>t.name==e)||r.push(typeof t==`string`?{name:e}:t)}},o=t.facet(lP);for(let r of e)if(r.hasResult()){let e=r.result.getMatch;if(r.result.filter===!1)for(let t of r.result.options)a(new nP(t,r.source,e?e(t):[],1e9-n.length));else{let n=t.sliceDoc(r.from,r.to),s,c=o.filterStrict?new Tde(n):new wde(n);for(let t of r.result.options)if(s=c.match(t.label)){let n=t.displayLabel?e?e(t,s.matched):[]:s.matched,o=s.score+(t.boost||0);if(a(new nP(t,r.source,n,o)),typeof t.section==`object`&&t.section.rank===`dynamic`){let{name:e}=t.section;i||=Object.create(null),i[e]=Math.max(o,i[e]||-1e9)}}}}if(r){let e=Object.create(null),t=0,a=(e,t)=>(e.rank===`dynamic`&&t.rank===`dynamic`?i[t.name]-i[e.name]:0)||(typeof e.rank==`number`?e.rank:1e9)-(typeof t.rank==`number`?t.rank:1e9)||(e.name<t.name?-1:1);for(let n of r.sort(a))t-=1e5,e[n.name]=t;for(let t of n){let{section:n}=t.completion;n&&(t.score+=e[typeof n==`string`?n:n.name])}}let s=[],c=null,l=o.compareCompletions;for(let e of n.sort((e,t)=>t.score-e.score||l(e.completion,t.completion))){let t=e.completion;!c||c.label!=t.label||c.detail!=t.detail||c.type!=null&&t.type!=null&&c.type!=t.type||c.apply!=t.apply||c.boost!=t.boost?s.push(e):pP(e.completion)>pP(c)&&(s[s.length-1]=e),c=e.completion}return s}var Mde=class e{constructor(e,t,n,r,i,a){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=r,this.selected=i,this.disabled=a}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new e(this.options,mP(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,i,a,o){if(i&&!o&&t.some(e=>e.isPending))return i.setDisabled();let s=jde(t,n);if(!s.length)return i&&t.some(e=>e.isPending)?i.setDisabled():null;let c=n.facet(lP).selectOnOpen?0:-1;if(i&&i.selected!=c&&i.selected!=-1){let e=i.options[i.selected].completion;for(let t=0;t<s.length;t++)if(s[t].completion==e){c=t;break}}return new e(s,mP(r,c),{pos:t.reduce((e,t)=>t.hasResult()?Math.min(e,t.from):e,1e8),create:zde,above:a.aboveCursor},i?i.timestamp:Date.now(),c,!1)}map(t){return new e(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new e(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}},Nde=class e{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new e(Lde,`cm-ac-`+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet(lP),i=(r.override||n.languageDataAt(`autocomplete`,rP(n)).map(Cde)).map(e=>(this.active.find(t=>t.source==e)||new gP(e,+!!this.active.some(e=>e.state!=0))).update(t,r));i.length==this.active.length&&i.every((e,t)=>e==this.active[t])&&(i=this.active);let a=this.open,o=t.effects.some(e=>e.is(vP));a&&t.docChanged&&(a=a.map(t.changes)),t.selection||i.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!Pde(i,this.active)||o?a=Mde.build(i,n,this.id,a,r,o):a&&a.disabled&&!i.some(e=>e.isPending)&&(a=null),!a&&i.every(e=>!e.isPending)&&i.some(e=>e.hasResult())&&(i=i.map(e=>e.hasResult()?new gP(e.source,0):e));for(let e of t.effects)e.is(dP)&&(a&&=a.setSelected(e.value,this.id));return i==this.active&&a==this.open?this:new e(i,this.id,a)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Fde:Ide}};function Pde(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let i=n==e.length,a=r==t.length;if(i||a)return i==a;if(e[n++].result!=t[r++].result)return!1}}var Fde={"aria-autocomplete":`list`},Ide={};function mP(e,t){let n={"aria-autocomplete":`list`,"aria-haspopup":`listbox`,"aria-controls":e};return t>-1&&(n[`aria-activedescendant`]=e+`-`+t),n}var Lde=[];function hP(e,t){if(e.isUserEvent(`input.complete`)){let n=e.annotation(aP);if(n&&t.activateOnCompletion(n))return 12}let n=e.isUserEvent(`input.type`);return n&&t.activateOnTyping?5:n?1:e.isUserEvent(`delete.backward`)?2:e.selection?8:e.docChanged?16:0}var gP=class e{constructor(e,t,n=!1){this.source=e,this.state=t,this.explicit=n}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=hP(t,n),i=this;(r&8||r&16&&this.touches(t))&&(i=new e(i.source,0)),r&4&&i.state==0&&(i=new e(this.source,1)),i=i.updateFor(t,r);for(let n of t.effects)if(n.is(sP))i=new e(i.source,1,n.value);else if(n.is(cP))i=new e(i.source,0);else if(n.is(vP))for(let e of n.value)e.source==i.source&&(i=e);return i}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(rP(e.state))}},_P=class e extends gP{constructor(e,t,n,r,i,a){super(e,3,t),this.limit=n,this.result=r,this.from=i,this.to=a}hasResult(){return!0}updateFor(t,n){if(!(n&3))return this.map(t.changes);let r=this.result;r.map&&!t.changes.empty&&(r=r.map(r,t.changes));let i=t.changes.mapPos(this.from),a=t.changes.mapPos(this.to,1),o=rP(t.state);if(o>a||!r||n&2&&(rP(t.startState)==this.from||o<this.limit))return new gP(this.source,n&4?1:0);let s=t.changes.mapPos(this.limit);return Rde(r.validFor,t.state,i,a)?new e(this.source,this.explicit,s,r,i,a):r.update&&(r=r.update(r,i,a,new $N(t.state,o,!1)))?new e(this.source,this.explicit,s,r,r.from,r.to??rP(t.state)):new gP(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new e(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new gP(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}};function Rde(e,t,n,r){if(!e)return!1;let i=t.sliceDoc(n,r);return typeof e==`function`?e(i,n,r,t):iP(e,!0).test(i)}var vP=w.define({map(e,t){return e.map(e=>e.map(t))}}),yP=l.define({create(){return Nde.start()},update(e,t){return e.update(t)},provide:e=>[F.from(e,e=>e.tooltip),f.contentAttributes.from(e,e=>e.attrs)]});function bP(e,t){let n=t.completion.apply||t.completion.label,r=e.state.field(yP).active.find(e=>e.source==t.source);return r instanceof _P?(typeof n==`string`?e.dispatch({...Sde(e.state,n,r.from,r.to),annotations:aP.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}var zde=kde(yP,bP);function xP(e,t=`option`){return n=>{let i=n.state.field(yP,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<n.state.facet(lP).interactionDelay)return!1;let a=1,o;t==`page`&&(o=r(n,i.open.tooltip))&&(a=Math.max(2,Math.floor(o.dom.offsetHeight/o.dom.querySelector(`li`).offsetHeight)-1));let{length:s}=i.open.options,c=i.open.selected>-1?i.open.selected+a*(e?1:-1):e?0:s-1;return c<0?c=t==`page`?0:s-1:c>=s&&(c=t==`page`?s-1:0),n.dispatch({effects:dP.of(c)}),!0}}var Bde=e=>{let t=e.state.field(yP,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet(lP).interactionDelay?!1:bP(e,t.open.options[t.open.selected])},SP=e=>e.state.field(yP,!1)?(e.dispatch({effects:sP.of(!0)}),!0):!1,Vde=e=>{let t=e.state.field(yP,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(e.dispatch({effects:cP.of(null)}),!0)},Hde=class{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}},Ude=50,Wde=1e3,Gde=ge.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(yP).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(yP),n=e.state.facet(lP);if(!e.selectionSet&&!e.docChanged&&e.startState.field(yP)==t)return;let r=e.transactions.some(e=>{let t=hP(e,n);return t&8||(e.selection||e.docChanged)&&!(t&3)});for(let t=0;t<this.running.length;t++){let n=this.running[t];if(r||n.context.abortOnDocChange&&e.docChanged||n.updates.length+e.transactions.length>Ude&&Date.now()-n.time>Wde){for(let e of n.context.abortListeners)try{e()}catch(e){me(this.view.state,e)}n.context.abortListeners=null,this.running.splice(t--,1)}else n.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(e=>e.effects.some(e=>e.is(sP)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(e=>e.isPending&&!this.running.some(t=>t.active.source==e.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let t of e.transactions)t.isUserEvent(`input.type`)?this.composing=2:this.composing==2&&t.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(yP);for(let e of t.active)e.isPending&&!this.running.some(t=>t.active.source==e.source)&&this.startQuery(e);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(lP).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=new $N(t,rP(t),e.explicit,this.view),r=new Hde(e,n);this.running.push(r),Promise.resolve(e.source(n)).then(e=>{r.context.aborted||(r.done=e||null,this.scheduleAccept())},e=>{this.view.dispatch({effects:cP.of(null)}),me(this.view.state,e)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(lP).updateSyncTime))}accept(){this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(lP),n=this.view.state.field(yP);for(let r=0;r<this.running.length;r++){let i=this.running[r];if(i.done===void 0)continue;if(this.running.splice(r--,1),i.done){let n=rP(i.updates.length?i.updates[0].startState:this.view.state),r=Math.min(n,i.done.from+ +!i.active.explicit),a=new _P(i.active.source,i.active.explicit,r,i.done,i.done.from,i.done.to??n);for(let e of i.updates)a=a.update(e,t);if(a.hasResult()){e.push(a);continue}}let a=n.active.find(e=>e.source==i.active.source);if(a&&a.isPending)if(i.done==null){let n=new gP(i.active.source,0);for(let e of i.updates)n=n.update(e,t);n.isPending||e.push(n)}else this.startQuery(a)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:vP.of(e)})}},{eventHandlers:{blur(e){let t=this.view.state.field(yP,!1);if(t&&t.tooltip&&this.view.state.facet(lP).closeOnBlur){let n=t.open&&r(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:cP.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:sP.of(!1)}),20),this.composing=0}}}),Kde=typeof navigator==`object`&&/Win/.test(navigator.platform),qde=De.highest(f.domEventHandlers({keydown(e,t){let n=t.state.field(yP,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(Kde&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],i=n.active.find(e=>e.source==r.source),a=r.completion.commitCharacters||i.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&bP(t,r),!1}})),CP=f.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:`monospace`,whiteSpace:`nowrap`,overflow:`hidden auto`,maxWidth_fallback:`700px`,maxWidth:`min(700px, 95vw)`,minWidth:`250px`,maxHeight:`10em`,height:`100%`,listStyle:`none`,margin:0,padding:0,"& > li, & > completion-section":{padding:`1px 3px`,lineHeight:1.2},"& > li":{overflowX:`hidden`,textOverflow:`ellipsis`,cursor:`pointer`},"& > completion-section":{display:`list-item`,borderBottom:`1px solid silver`,paddingLeft:`0.5em`,opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#17c`,color:`white`},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#777`},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:`#347`,color:`white`},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:`#444`},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:`"···"`,opacity:.5,display:`block`,textAlign:`center`},".cm-tooltip.cm-completionInfo":{position:`absolute`,padding:`3px 9px`,width:`max-content`,maxWidth:`400px`,boxSizing:`border-box`,whiteSpace:`pre-line`},".cm-completionInfo.cm-completionInfo-left":{right:`100%`},".cm-completionInfo.cm-completionInfo-right":{left:`100%`},".cm-completionInfo.cm-completionInfo-left-narrow":{right:`30px`},".cm-completionInfo.cm-completionInfo-right-narrow":{left:`30px`},"&light .cm-snippetField":{backgroundColor:`#00000022`},"&dark .cm-snippetField":{backgroundColor:`#ffffff22`},".cm-snippetFieldPosition":{verticalAlign:`text-top`,width:0,height:`1.15em`,display:`inline-block`,margin:`0 -0.7px -.7em`,borderLeft:`1.4px dotted #888`},".cm-completionMatchedText":{textDecoration:`underline`},".cm-completionDetail":{marginLeft:`0.5em`,fontStyle:`italic`},".cm-completionIcon":{fontSize:`90%`,width:`.8em`,display:`inline-block`,textAlign:`center`,paddingRight:`.6em`,opacity:`0.6`,boxSizing:`content-box`},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:`'ƒ'`}},".cm-completionIcon-class":{"&:after":{content:`'○'`}},".cm-completionIcon-interface":{"&:after":{content:`'◌'`}},".cm-completionIcon-variable":{"&:after":{content:`'𝑥'`}},".cm-completionIcon-constant":{"&:after":{content:`'𝐶'`}},".cm-completionIcon-type":{"&:after":{content:`'𝑡'`}},".cm-completionIcon-enum":{"&:after":{content:`'∪'`}},".cm-completionIcon-property":{"&:after":{content:`'□'`}},".cm-completionIcon-keyword":{"&:after":{content:`'🔑︎'`}},".cm-completionIcon-namespace":{"&:after":{content:`'▢'`}},".cm-completionIcon-text":{"&:after":{content:`'abc'`,fontSize:`50%`,verticalAlign:`middle`}}}),Jde=class{constructor(e,t,n,r){this.field=e,this.line=t,this.from=n,this.to=r}},Yde=class e{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(t){let n=t.mapPos(this.from,-1,M.TrackDel),r=t.mapPos(this.to,1,M.TrackDel);return n==null||r==null?null:new e(this.field,n,r)}},Xde=class e{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],r=[t],i=e.doc.lineAt(t),a=/^\s*/.exec(i.text)[0];for(let i of this.lines){if(n.length){let n=a,o=/^\t*/.exec(i)[0].length;for(let t=0;t<o;t++)n+=e.facet(c);r.push(t+n.length-o),i=n+i.slice(o)}n.push(i),t+=i.length+1}return{text:n,ranges:this.fieldPositions.map(e=>new Yde(e.field,r[e.line]+e.from,r[e.line]+e.to))}}static parse(t){let n=[],r=[],i=[],a;for(let e of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(e);){let t=a[1]?+a[1]:null,o=a[2]||a[3]||``,s=-1,c=o.replace(/\\[{}]/g,e=>e[1]);for(let e=0;e<n.length;e++)(t==null?c&&n[e].name==c:n[e].seq==t)&&(s=e);if(s<0){let e=0;for(;e<n.length&&(t==null||n[e].seq!=null&&n[e].seq<t);)e++;n.splice(e,0,{seq:t,name:c}),s=e;for(let e of i)e.field>=s&&e.field++}for(let e of i)if(e.line==r.length&&e.from>a.index){let t=a[2]?3+(a[1]||``).length:2;e.from-=t,e.to-=t}i.push(new Jde(s,r.length,a.index,a.index+c.length)),e=e.slice(0,a.index)+o+e.slice(a.index+a[0].length)}e=e.replace(/\\([{}])/g,(e,t,n)=>{for(let e of i)e.line==r.length&&e.from>n&&(e.from--,e.to--);return t}),r.push(e)}return new e(r,i)}},Zde=T.widget({widget:new class extends d{toDOM(){let e=document.createElement(`span`);return e.className=`cm-snippetFieldPosition`,e}ignoreEvent(){return!1}}}),Qde=T.mark({class:`cm-snippetField`}),wP=class e{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(e=>(e.from==e.to?Zde:Qde).range(e.from,e.to)),!0)}map(t){let n=[];for(let e of this.ranges){let r=e.map(t);if(!r)return null;n.push(r)}return new e(n,this.active)}selectionInsideField(e){return e.ranges.every(e=>this.ranges.some(t=>t.field==this.active&&t.from<=e.from&&t.to>=e.to))}},TP=w.define({map(e,t){return e&&e.map(t)}}),$de=w.define(),EP=l.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(TP))return n.value;if(n.is($de)&&e)return new wP(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>f.decorations.from(e,e=>e?e.deco:T.none)});function DP(e,t){return k.create(e.filter(e=>e.field==t).map(e=>k.range(e.from,e.to)))}function efe(e){let t=Xde.parse(e);return(e,n,r,i)=>{let{text:a,ranges:o}=t.instantiate(e.state,r),{main:c}=e.state.selection,l={changes:{from:r,to:i==c.from?c.to:i,insert:s.of(a)},scrollIntoView:!0,annotations:n?[aP.of(n),_.userEvent.of(`input.complete`)]:void 0};if(o.length&&(l.selection=DP(o,0)),o.some(e=>e.field>0)){let t=new wP(o,0),n=l.effects=[TP.of(t)];e.state.field(EP,!1)===void 0&&n.push(w.appendConfig.of([EP,nfe,ife,CP]))}e.dispatch(e.state.update(l))}}function OP(e){return({state:t,dispatch:n})=>{let r=t.field(EP,!1);if(!r||e<0&&r.active==0)return!1;let i=r.active+e,a=e>0&&!r.ranges.some(t=>t.field==i+e);return n(t.update({selection:DP(r.ranges,i),effects:TP.of(a?null:new wP(r.ranges,i)),scrollIntoView:!0})),!0}}var tfe=[{key:`Tab`,run:OP(1),shift:OP(-1)},{key:`Escape`,run:({state:e,dispatch:t})=>e.field(EP,!1)?(t(e.update({effects:TP.of(null)})),!0):!1}],kP=Oe.define({combine(e){return e.length?e[0]:tfe}}),nfe=De.highest(ie.compute([kP],e=>e.facet(kP)));function rfe(e,t){return{...t,apply:efe(e)}}var ife=f.domEventHandlers({mousedown(e,t){let n=t.state.field(EP,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let i=n.ranges.find(e=>e.from<=r&&e.to>=r);return!i||i.field==n.active?!1:(t.dispatch({selection:DP(n.ranges,i.field),effects:TP.of(n.ranges.some(e=>e.field>i.field)?new wP(n.ranges,i.field):null),scrollIntoView:!0}),!0)}}),AP={brackets:[`(`,`[`,`{`,`'`,`"`],before:`)]}:;>`,stringPrefixes:[]},jP=w.define({map(e,t){return t.mapPos(e,-1,M.TrackAfter)??void 0}}),MP=new class extends Te{};MP.startSide=1,MP.endSide=-1;var NP=l.define({create(){return S.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:e=>e>=n.from&&e<=n.to})}for(let n of t.effects)n.is(jP)&&(e=e.update({add:[MP.range(n.value,n.value+1)]}));return e}});function afe(){return[sfe,NP]}var PP=`()[]{}<>«»»«[]{}`;function FP(e){for(let t=0;t<16;t+=2)if(PP.charCodeAt(t)==e)return PP.charAt(t+1);return y(e<128?e:e+1)}function IP(e,t){return e.languageDataAt(`closeBrackets`,t)[0]||AP}var ofe=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),sfe=f.inputHandler.of((e,t,n,r)=>{if((ofe?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let i=e.state.selection.main;if(r.length>2||r.length==2&&a(se(r,0))==1||t!=i.from||n!=i.to)return!1;let o=lfe(e.state,r);return o?(e.dispatch(o),!0):!1}),cfe=[{key:`Backspace`,run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=IP(e,e.selection.main.head).brackets||AP.brackets,r=null,i=e.changeByRange(t=>{if(t.empty){let r=ufe(e.doc,t.head);for(let i of n)if(i==r&&RP(e.doc,t.head)==FP(se(i,0)))return{changes:{from:t.head-i.length,to:t.head+i.length},range:k.cursor(t.head-i.length)}}return{range:r=t}});return r||t(e.update(i,{scrollIntoView:!0,userEvent:`delete.backward`})),!r}}];function lfe(e,t){let n=IP(e,e.selection.main.head),r=n.brackets||AP.brackets;for(let i of r){let a=FP(se(i,0));if(t==i)return a==i?pfe(e,i,r.indexOf(i+i+i)>-1,n):dfe(e,i,a,n.before||AP.before);if(t==a&&LP(e,e.selection.main.from))return ffe(e,i,a)}return null}function LP(e,t){let n=!1;return e.field(NP).between(0,e.doc.length,e=>{e==t&&(n=!0)}),n}function RP(e,t){let n=e.sliceString(t,t+2);return n.slice(0,a(se(n,0)))}function ufe(e,t){let n=e.sliceString(t-2,t);return a(se(n,0))==n.length?n:n.slice(1)}function dfe(e,t,n,r){let i=null,a=e.changeByRange(a=>{if(!a.empty)return{changes:[{insert:t,from:a.from},{insert:n,from:a.to}],effects:jP.of(a.to+t.length),range:k.range(a.anchor+t.length,a.head+t.length)};let o=RP(e.doc,a.head);return!o||/\s/.test(o)||r.indexOf(o)>-1?{changes:{insert:t+n,from:a.head},effects:jP.of(a.head+t.length),range:k.cursor(a.head+t.length)}:{range:i=a}});return i?null:e.update(a,{scrollIntoView:!0,userEvent:`input.type`})}function ffe(e,t,n){let r=null,i=e.changeByRange(t=>t.empty&&RP(e.doc,t.head)==n?{changes:{from:t.head,to:t.head+n.length,insert:n},range:k.cursor(t.head+n.length)}:r={range:t});return r?null:e.update(i,{scrollIntoView:!0,userEvent:`input.type`})}function pfe(e,t,n,r){let i=r.stringPrefixes||AP.stringPrefixes,a=null,o=e.changeByRange(r=>{if(!r.empty)return{changes:[{insert:t,from:r.from},{insert:t,from:r.to}],effects:jP.of(r.to+t.length),range:k.range(r.anchor+t.length,r.head+t.length)};let o=r.head,s=RP(e.doc,o),c;if(s==t){if(zP(e,o))return{changes:{insert:t+t,from:o},effects:jP.of(o+t.length),range:k.cursor(o+t.length)};if(LP(e,o)){let r=n&&e.sliceDoc(o,o+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:o,to:o+r.length,insert:r},range:k.cursor(o+r.length)}}}else if(n&&e.sliceDoc(o-2*t.length,o)==t+t&&(c=BP(e,o-2*t.length,i))>-1&&zP(e,c))return{changes:{insert:t+t+t+t,from:o},effects:jP.of(o+t.length),range:k.cursor(o+t.length)};else if(e.charCategorizer(o)(s)!=L.Word&&BP(e,o,i)>-1&&!mfe(e,o,t,i))return{changes:{insert:t+t,from:o},effects:jP.of(o+t.length),range:k.cursor(o+t.length)};return{range:a=r}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:`input.type`})}function zP(e,t){let n=ae(e).resolveInner(t+1);return n.parent&&n.from==t}function mfe(e,t,n,r){let i=ae(e).resolveInner(t,-1),a=r.reduce((e,t)=>Math.max(e,t.length),0);for(let o=0;o<5;o++){let o=e.sliceDoc(i.from,Math.min(i.to,i.from+n.length+a)),s=o.indexOf(n);if(!s||s>-1&&r.indexOf(o.slice(0,s))>-1){let t=i.firstChild;for(;t&&t.from==i.from&&t.to-t.from>n.length+s;){if(e.sliceDoc(t.to-n.length,t.to)==n)return!1;t=t.firstChild}return!0}let c=i.to==t&&i.parent;if(!c)break;i=c}return!1}function BP(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=L.Word)return t;for(let i of n){let n=t-i.length;if(e.sliceDoc(n,t)==i&&r(e.sliceDoc(n-1,n))!=L.Word)return n}return-1}function hfe(e={}){return[qde,yP,lP.of(e),Gde,gfe,CP]}var VP=[{key:`Ctrl-Space`,run:SP},{mac:"Alt-`",run:SP},{mac:`Alt-i`,run:SP},{key:`Escape`,run:Vde},{key:`ArrowDown`,run:xP(!0)},{key:`ArrowUp`,run:xP(!1)},{key:`PageDown`,run:xP(!0,`page`)},{key:`PageUp`,run:xP(!1,`page`)},{key:`Enter`,run:Bde}],gfe=De.highest(ie.computeN([lP],e=>e.facet(lP).defaultKeymap?[VP]:[])),_fe=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=UP(e.state,n.from);return r.line?vfe(e):r.block?bfe(e):!1};function HP(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var vfe=HP(Cfe,0),yfe=HP(GP,0),bfe=HP((e,t)=>GP(e,t,Sfe(t)),0);function UP(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var WP=50;function xfe(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-WP,r),o=e.sliceDoc(i,i+WP),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*WP?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+WP),d=e.sliceDoc(i-WP,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function Sfe(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function GP(e,t,n=t.selection.ranges){let r=n.map(e=>UP(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>xfe(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function Cfe(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=UP(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var KP=he.define(),wfe=he.define(),Tfe=Oe.define(),qP=Oe.define({combine(e){return oe(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),JP=l.define({create(){return aF.empty},update(e,t){let n=t.state.facet(qP),r=t.annotation(KP);if(r){let i=$P.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?eF(o,o.length,n.minDepth,i):rF(o,t.startState.selection),new aF(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(wfe);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(_.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=$P.fromTransaction(t),o=t.annotation(_.time),s=t.annotation(_.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new aF(e.done.map($P.fromJSON),e.undone.map($P.fromJSON))}});function YP(e={}){return[JP,qP.of(e),f.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?ZP:e.inputType==`historyRedo`?QP:null;return n?(e.preventDefault(),n(t)):!1}})]}function XP(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(JP,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var ZP=XP(0,!1),QP=XP(1,!1),Efe=XP(0,!0),Dfe=XP(1,!0),$P=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&re.fromJSON(t.changes),[],t.mapped&&ue.fromJSON(t.mapped),t.startSelection&&k.fromJSON(t.startSelection),t.selectionsAfter.map(k.fromJSON))}static fromTransaction(t,n){let r=nF;for(let e of t.startState.facet(Tfe)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,nF)}static selection(t){return new e(void 0,nF,void 0,void 0,t)}};function eF(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function Ofe(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function kfe(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function tF(e,t){return e.length?t.length?e.concat(t):e:t}var nF=[],Afe=200;function rF(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Afe));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),eF(e,e.length-1,1e9,n.setSelAfter(r)))}else return[$P.selection([t])]}function jfe(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function iF(e,t){if(!e.length)return e;let n=e.length,r=nF;for(;n;){let i=Mfe(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[$P.selection(r)]:nF}function Mfe(e,t,n){let r=tF(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):nF,n);if(!e.changes)return $P.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new $P(i,w.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var Nfe=/^(input\.type|delete)($|\.)/,aF=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||Nfe.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,Ofe(s.changes,t.changes))||r==`input.type.compose`)?eF(o,o.length-1,i.minDepth,new $P(t.changes.compose(s.changes),tF(w.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,nF)):eF(o,o.length,i.minDepth,t),new e(o,nF,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:nF;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&kfe(a[a.length-1],t)?this:new e(rF(this.done,t),this.undone,n,r)}addMapping(t){return new e(iF(this.done,t),iF(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:KP.of({side:e,rest:jfe(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?nF:r.slice(0,r.length-1);return i.mapped&&(n=iF(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:KP.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};aF.empty=new aF(nF,nF);var oF=[{key:`Mod-z`,run:ZP,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:QP,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:QP,preventDefault:!0},{key:`Mod-u`,run:Efe,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:Dfe,preventDefault:!0}];function sF(e,t){return k.create(e.ranges.map(t),e.mainIndex)}function cF(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function lF({state:e,dispatch:t},n){let r=sF(e.selection,n);return r.eq(e.selection,!0)?!1:(t(cF(e,r)),!0)}function uF(e,t){return k.cursor(t?e.to:e.from)}function dF(e,t){return lF(e,n=>n.empty?e.moveByChar(n,t):uF(n,t))}function fF(e){return e.textDirectionAt(e.state.selection.main.head)==u.LTR}var pF=e=>dF(e,!fF(e)),mF=e=>dF(e,fF(e));function hF(e,t){return lF(e,n=>n.empty?e.moveByGroup(n,t):uF(n,t))}var Pfe=e=>hF(e,!fF(e)),Ffe=e=>hF(e,fF(e));typeof Intl<`u`&&Intl.Segmenter;function Ife(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function gF(e,t,n){let r=ae(e).resolveInner(t.head),i=n?p.closedBy:p.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;Ife(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?g(e,r.from,1):g(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,k.cursor(s,n?-1:1)}var Lfe=e=>lF(e,t=>gF(e.state,t,!fF(e))),Rfe=e=>lF(e,t=>gF(e.state,t,fF(e)));function _F(e,t){return lF(e,n=>{if(!n.empty)return uF(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var vF=e=>_F(e,!1),yF=e=>_F(e,!0);function bF(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(f.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function xF(e,t){let n=bF(e),{state:r}=e,i=sF(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):uF(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=f.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(cF(r,i),{effects:a}),!0}var SF=e=>xF(e,!1),CF=e=>xF(e,!0);function wF(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=k.cursor(r.from+n))}return i}var zfe=e=>lF(e,t=>wF(e,t,!0)),Bfe=e=>lF(e,t=>wF(e,t,!1)),Vfe=e=>lF(e,t=>wF(e,t,!fF(e))),Hfe=e=>lF(e,t=>wF(e,t,fF(e))),Ufe=e=>lF(e,t=>k.cursor(e.lineBlockAt(t.head).from,1)),Wfe=e=>lF(e,t=>k.cursor(e.lineBlockAt(t.head).to,-1));function Gfe(e,t,n){let r=!1,i=sF(e.selection,t=>{let i=g(e,t.head,-1)||g(e,t.head,1)||t.head>0&&g(e,t.head-1,1)||t.head<e.doc.length&&g(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?k.range(t.anchor,a):k.cursor(a)});return r?(t(cF(e,i)),!0):!1}var Kfe=({state:e,dispatch:t})=>Gfe(e,t,!1);function TF(e,t){let n=sF(e.state.selection,e=>{let n=t(e);return k.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(cF(e.state,n)),!0)}function EF(e,t){return TF(e,n=>e.moveByChar(n,t))}var DF=e=>EF(e,!fF(e)),OF=e=>EF(e,fF(e));function kF(e,t){return TF(e,n=>e.moveByGroup(n,t))}var qfe=e=>kF(e,!fF(e)),Jfe=e=>kF(e,fF(e)),Yfe=e=>TF(e,t=>gF(e.state,t,!fF(e))),Xfe=e=>TF(e,t=>gF(e.state,t,fF(e)));function AF(e,t){return TF(e,n=>e.moveVertically(n,t))}var jF=e=>AF(e,!1),MF=e=>AF(e,!0);function NF(e,t){return TF(e,n=>e.moveVertically(n,t,bF(e).height))}var PF=e=>NF(e,!1),FF=e=>NF(e,!0),Zfe=e=>TF(e,t=>wF(e,t,!0)),Qfe=e=>TF(e,t=>wF(e,t,!1)),$fe=e=>TF(e,t=>wF(e,t,!fF(e))),epe=e=>TF(e,t=>wF(e,t,fF(e))),tpe=e=>TF(e,t=>k.cursor(e.lineBlockAt(t.head).from)),npe=e=>TF(e,t=>k.cursor(e.lineBlockAt(t.head).to)),IF=({state:e,dispatch:t})=>(t(cF(e,{anchor:0})),!0),LF=({state:e,dispatch:t})=>(t(cF(e,{anchor:e.doc.length})),!0),RF=({state:e,dispatch:t})=>(t(cF(e,{anchor:e.selection.main.anchor,head:0})),!0),zF=({state:e,dispatch:t})=>(t(cF(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),rpe=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),ipe=({state:e,dispatch:t})=>{let n=JF(e).map(({from:t,to:n})=>k.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:k.create(n),userEvent:`select`})),!0},ape=({state:e,dispatch:t})=>{let n=sF(e.selection,t=>{let n=ae(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return k.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(cF(e,n)),!0)};function BF(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(cF(n,k.create(i,i.length-1))),!0)}var ope=e=>BF(e,!1),spe=e=>BF(e,!0),cpe=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=k.create([n.main]):n.main.empty||(r=k.create([k.cursor(n.main.head)])),r?(t(cF(e,r)),!0):!1};function VF(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=HF(e,o,!1)):o>i&&(n=`delete.forward`,o=HF(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=HF(e,i,!1),a=HF(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:k.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?f.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function HF(e,t,n){if(e instanceof f)for(let r of e.state.facet(f.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var UF=(e,t,n)=>VF(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=m(s,a.tabSize)%Ee(a)||Ee(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=h(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=h(o.text,c-o.from,!1,!1)+o.from);return c}),WF=e=>UF(e,!1,!0),GF=e=>UF(e,!0,!1),KF=(e,t)=>VF(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=h(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),qF=e=>KF(e,!1),lpe=e=>KF(e,!0),upe=e=>VF(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),dpe=e=>VF(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),fpe=e=>VF(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),ppe=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:s.of([``,``])},range:k.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},mpe=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:h(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:h(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:k.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function JF(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function YF(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of JF(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(k.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(k.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:k.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var hpe=({state:e,dispatch:t})=>YF(e,t,!1),gpe=({state:e,dispatch:t})=>YF(e,t,!0);function XF(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of JF(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var _pe=({state:e,dispatch:t})=>XF(e,t,!1),vpe=({state:e,dispatch:t})=>XF(e,t,!0),ype=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(JF(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=sF(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function bpe(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=ae(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(p.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var ZF=QF(!1),xpe=QF(!0);function QF(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&bpe(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let c=new de(t,{simulateBreak:r,simulateDoubleBreak:!!o}),l=x(c,r);for(l??=m(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let u=[``,C(t,l)];return o&&u.push(C(t,c.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:s.of(u)},range:k.cursor(r+1+u[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function $F(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:k.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var Spe=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new de(e,{overrideIndentation:e=>n[e]??-1}),i=$F(e,(t,i,a)=>{let o=x(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=C(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},eI=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update($F(e,(t,n)=>{n.push({from:t.from,insert:e.facet(c)})}),{userEvent:`input.indent`})),!0),tI=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update($F(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=m(r,e.tabSize),a=0,o=C(e,Math.max(0,i-Ee(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),Cpe=e=>(e.setTabFocusMode(),!0),wpe=[{key:`Ctrl-b`,run:pF,shift:DF,preventDefault:!0},{key:`Ctrl-f`,run:mF,shift:OF},{key:`Ctrl-p`,run:vF,shift:jF},{key:`Ctrl-n`,run:yF,shift:MF},{key:`Ctrl-a`,run:Ufe,shift:tpe},{key:`Ctrl-e`,run:Wfe,shift:npe},{key:`Ctrl-d`,run:GF},{key:`Ctrl-h`,run:WF},{key:`Ctrl-k`,run:upe},{key:`Ctrl-Alt-h`,run:qF},{key:`Ctrl-o`,run:ppe},{key:`Ctrl-t`,run:mpe},{key:`Ctrl-v`,run:CF}],Tpe=[{key:`ArrowLeft`,run:pF,shift:DF,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:Pfe,shift:qfe,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Vfe,shift:$fe,preventDefault:!0},{key:`ArrowRight`,run:mF,shift:OF,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:Ffe,shift:Jfe,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Hfe,shift:epe,preventDefault:!0},{key:`ArrowUp`,run:vF,shift:jF,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:IF,shift:RF},{mac:`Ctrl-ArrowUp`,run:SF,shift:PF},{key:`ArrowDown`,run:yF,shift:MF,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:LF,shift:zF},{mac:`Ctrl-ArrowDown`,run:CF,shift:FF},{key:`PageUp`,run:SF,shift:PF},{key:`PageDown`,run:CF,shift:FF},{key:`Home`,run:Bfe,shift:Qfe,preventDefault:!0},{key:`Mod-Home`,run:IF,shift:RF},{key:`End`,run:zfe,shift:Zfe,preventDefault:!0},{key:`Mod-End`,run:LF,shift:zF},{key:`Enter`,run:ZF,shift:ZF},{key:`Mod-a`,run:rpe},{key:`Backspace`,run:WF,shift:WF,preventDefault:!0},{key:`Delete`,run:GF,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:qF,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:lpe,preventDefault:!0},{mac:`Mod-Backspace`,run:dpe,preventDefault:!0},{mac:`Mod-Delete`,run:fpe,preventDefault:!0}].concat(wpe.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),nI=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:Lfe,shift:Yfe},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Rfe,shift:Xfe},{key:`Alt-ArrowUp`,run:hpe},{key:`Shift-Alt-ArrowUp`,run:_pe},{key:`Alt-ArrowDown`,run:gpe},{key:`Shift-Alt-ArrowDown`,run:vpe},{key:`Mod-Alt-ArrowUp`,run:ope},{key:`Mod-Alt-ArrowDown`,run:spe},{key:`Escape`,run:cpe},{key:`Mod-Enter`,run:xpe},{key:`Alt-l`,mac:`Ctrl-l`,run:ipe},{key:`Mod-i`,run:ape,preventDefault:!0},{key:`Mod-[`,run:tI},{key:`Mod-]`,run:eI},{key:`Mod-Alt-\\`,run:Spe},{key:`Shift-Mod-k`,run:ype},{key:`Shift-Mod-\\`,run:Kfe},{key:`Mod-/`,run:_fe},{key:`Alt-A`,run:yfe},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:Cpe}].concat(Tpe),Epe={key:`Tab`,run:eI,shift:tI};function Dpe(e,t,n,r){let i=Vl(VS),a=Ul(jC),o=R.useRef(null),{lexicalNode:s}=JN(),c=R.useRef(!1),l=R.useRef(!1),u=R.useCallback(()=>{a({editorType:t,rootNode:s,editorRef:o.current})},[t,s,a]),d=R.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=Ah(e);n.getNextSibling()?((t=o.current?.getCodemirror())==null||t.contentDOM.blur(),n.selectNext()):n.insertAfter(nh())}),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=Ah(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(()=>{Ah(e).remove()})},[i,e]);return R.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]),R.useEffect(()=>{r.subscribe(()=>{var e;(e=o.current?.getCodemirror())==null||e.focus(),u()})},[r,o,e,u]),o}function X(e){return new pe(N.define(e))}function rI(e){return Y(()=>import(`./dist-B6kzRv2_.js`).then(t=>t.sql({dialect:t[e]})),__vite__mapDeps([0,1,2]))}var Ope=[A.of({name:`C`,extensions:[`c`,`h`,`ino`],load(){return Y(()=>import(`./dist-C5YJOwhH.js`).then(e=>e.cpp()),__vite__mapDeps([3,1,2]))}}),A.of({name:`C++`,alias:[`cpp`],extensions:[`cpp`,`c++`,`cc`,`cxx`,`hpp`,`h++`,`hh`,`hxx`],load(){return Y(()=>import(`./dist-C5YJOwhH.js`).then(e=>e.cpp()),__vite__mapDeps([3,1,2]))}}),A.of({name:`CQL`,alias:[`cassandra`],extensions:[`cql`],load(){return rI(`Cassandra`)}}),A.of({name:`CSS`,extensions:[`css`],load(){return Y(()=>import(`./dist-CKM5j-iy.js`).then(e=>e.i).then(e=>e.css()),__vite__mapDeps([4,5,1,2]))}}),A.of({name:`Go`,extensions:[`go`],load(){return Y(()=>import(`./dist-CVcI9eYD.js`).then(e=>e.go()),__vite__mapDeps([6,1,2]))}}),A.of({name:`HTML`,alias:[`xhtml`],extensions:[`html`,`htm`,`handlebars`,`hbs`],load(){return Y(()=>import(`./dist-DWA7BIr3.js`).then(e=>e.html()),__vite__mapDeps([7,4,5,1,2,8]))}}),A.of({name:`Java`,extensions:[`java`],load(){return Y(()=>import(`./dist--55mTWk3.js`).then(e=>e.java()),__vite__mapDeps([9,1,2]))}}),A.of({name:`JavaScript`,alias:[`ecmascript`,`js`,`node`],extensions:[`js`,`mjs`,`cjs`],load(){return Y(()=>import(`./dist-Dj3uUYqF.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`Jinja`,extensions:[`j2`,`jinja`,`jinja2`],load(){return Y(()=>import(`./dist-Bns-O5iY.js`).then(e=>e.jinja()),__vite__mapDeps([10,7,4,5,1,2,8]))}}),A.of({name:`JSON`,alias:[`json5`],extensions:[`json`,`map`],load(){return Y(()=>import(`./dist-BZ39rB1W.js`).then(e=>e.json()),__vite__mapDeps([11,1,2]))}}),A.of({name:`JSX`,extensions:[`jsx`],load(){return Y(()=>import(`./dist-Dj3uUYqF.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`LESS`,extensions:[`less`],load(){return Y(()=>import(`./dist-C5oXtFSP.js`).then(e=>e.less()),__vite__mapDeps([12,4,5,1,2]))}}),A.of({name:`Liquid`,extensions:[`liquid`],load(){return Y(()=>import(`./dist-DvPgMX-r.js`).then(e=>e.liquid()),__vite__mapDeps([13,7,4,5,1,2,8]))}}),A.of({name:`MariaDB SQL`,load(){return rI(`MariaSQL`)}}),A.of({name:`Markdown`,extensions:[`md`,`markdown`,`mkd`],load(){return Y(()=>import(`./dist-D9K0kHT0.js`).then(e=>e.markdown()),__vite__mapDeps([14,7,4,5,1,2,8]))}}),A.of({name:`MS SQL`,load(){return rI(`MSSQL`)}}),A.of({name:`MySQL`,load(){return rI(`MySQL`)}}),A.of({name:`PHP`,extensions:[`php`,`php3`,`php4`,`php5`,`php7`,`phtml`],load(){return Y(()=>import(`./dist-D4CEl91a.js`).then(e=>e.php()),__vite__mapDeps([15,7,4,5,1,2,8]))}}),A.of({name:`PLSQL`,extensions:[`pls`],load(){return rI(`PLSQL`)}}),A.of({name:`PostgreSQL`,load(){return rI(`PostgreSQL`)}}),A.of({name:`Python`,extensions:[`BUILD`,`bzl`,`py`,`pyw`],filename:/^(BUCK|BUILD)$/,load(){return Y(()=>import(`./dist-CqkKCn6l.js`).then(e=>e.python()),__vite__mapDeps([16,1,2]))}}),A.of({name:`Rust`,extensions:[`rs`],load(){return Y(()=>import(`./dist-CUp9us2q.js`).then(e=>e.rust()),__vite__mapDeps([17,1,2]))}}),A.of({name:`Sass`,extensions:[`sass`],load(){return Y(()=>import(`./dist-DSKQpPaz.js`).then(e=>e.sass({indented:!0})),__vite__mapDeps([18,4,5,1,2]))}}),A.of({name:`SCSS`,extensions:[`scss`],load(){return Y(()=>import(`./dist-DSKQpPaz.js`).then(e=>e.sass()),__vite__mapDeps([18,4,5,1,2]))}}),A.of({name:`SQL`,extensions:[`sql`],load(){return rI(`StandardSQL`)}}),A.of({name:`SQLite`,load(){return rI(`SQLite`)}}),A.of({name:`TSX`,extensions:[`tsx`],load(){return Y(()=>import(`./dist-Dj3uUYqF.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0,typescript:!0})),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`TypeScript`,alias:[`ts`],extensions:[`ts`,`mts`,`cts`],load(){return Y(()=>import(`./dist-Dj3uUYqF.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([8,5,1,2]))}}),A.of({name:`WebAssembly`,extensions:[`wat`,`wast`],load(){return Y(()=>import(`./dist-CZ9T4Cly.js`).then(e=>e.wast()),__vite__mapDeps([19,1,2]))}}),A.of({name:`XML`,alias:[`rss`,`wsdl`,`xsd`],extensions:[`xml`,`xsl`,`xsd`,`svg`],load(){return Y(()=>import(`./dist-Zqt9kNG9.js`).then(e=>e.xml()),__vite__mapDeps([20,1,2]))}}),A.of({name:`YAML`,alias:[`yml`],extensions:[`yaml`,`yml`],load(){return Y(()=>import(`./dist-BsedZGJo.js`).then(e=>e.yaml()),__vite__mapDeps([21,1,2]))}}),A.of({name:`APL`,extensions:[`dyalog`,`apl`],load(){return Y(()=>import(`./apl-BxEMbctQ.js`).then(e=>X(e.apl)),[])}}),A.of({name:`PGP`,alias:[`asciiarmor`],extensions:[`asc`,`pgp`,`sig`],load(){return Y(()=>import(`./asciiarmor-eFjeGRuZ.js`).then(e=>X(e.asciiArmor)),[])}}),A.of({name:`ASN.1`,extensions:[`asn`,`asn1`],load(){return Y(()=>import(`./asn1-Cfx-0pt9.js`).then(e=>X(e.asn1({}))),[])}}),A.of({name:`Asterisk`,filename:/^extensions\.conf$/i,load(){return Y(()=>import(`./asterisk-B5BHTsBr.js`).then(e=>X(e.asterisk)),[])}}),A.of({name:`Brainfuck`,extensions:[`b`,`bf`],load(){return Y(()=>import(`./brainfuck-CAA2xofr.js`).then(e=>X(e.brainfuck)),[])}}),A.of({name:`Cobol`,extensions:[`cob`,`cpy`],load(){return Y(()=>import(`./cobol-BfgHZgup.js`).then(e=>X(e.cobol)),[])}}),A.of({name:`C#`,alias:[`csharp`,`cs`],extensions:[`cs`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.csharp)),[])}}),A.of({name:`Clojure`,extensions:[`clj`,`cljc`,`cljx`],load(){return Y(()=>import(`./clojure-kVFSWX0o.js`).then(e=>X(e.clojure)),[])}}),A.of({name:`ClojureScript`,extensions:[`cljs`],load(){return Y(()=>import(`./clojure-kVFSWX0o.js`).then(e=>X(e.clojure)),[])}}),A.of({name:`Closure Stylesheets (GSS)`,extensions:[`gss`],load(){return Y(()=>import(`./css-BqOeyZOV.js`).then(e=>X(e.gss)),[])}}),A.of({name:`CMake`,extensions:[`cmake`,`cmake.in`],filename:/^CMakeLists\.txt$/,load(){return Y(()=>import(`./cmake-BUPAhezI.js`).then(e=>X(e.cmake)),[])}}),A.of({name:`CoffeeScript`,alias:[`coffee`,`coffee-script`],extensions:[`coffee`],load(){return Y(()=>import(`./coffeescript-G1Pe_1AZ.js`).then(e=>X(e.coffeeScript)),[])}}),A.of({name:`Common Lisp`,alias:[`lisp`],extensions:[`cl`,`lisp`,`el`],load(){return Y(()=>import(`./commonlisp-B3N0CjHn.js`).then(e=>X(e.commonLisp)),[])}}),A.of({name:`Cypher`,extensions:[`cyp`,`cypher`],load(){return Y(()=>import(`./cypher-KjIKv-wW.js`).then(e=>X(e.cypher)),[])}}),A.of({name:`Cython`,extensions:[`pyx`,`pxd`,`pxi`],load(){return Y(()=>import(`./python-C2_X1GpX.js`).then(e=>X(e.cython)),[])}}),A.of({name:`Crystal`,extensions:[`cr`],load(){return Y(()=>import(`./crystal-C15ndaGM.js`).then(e=>X(e.crystal)),[])}}),A.of({name:`D`,extensions:[`d`],load(){return Y(()=>import(`./d-BlT5AEC-.js`).then(e=>X(e.d)),[])}}),A.of({name:`Dart`,extensions:[`dart`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.dart)),[])}}),A.of({name:`diff`,extensions:[`diff`,`patch`],load(){return Y(()=>import(`./diff-oF98tbqj.js`).then(e=>X(e.diff)),[])}}),A.of({name:`Dockerfile`,filename:/^Dockerfile$/,load(){return Y(()=>import(`./dockerfile-CUaqzcqp.js`).then(e=>X(e.dockerFile)),__vite__mapDeps([22,23]))}}),A.of({name:`DTD`,extensions:[`dtd`],load(){return Y(()=>import(`./dtd-VCA9yr61.js`).then(e=>X(e.dtd)),[])}}),A.of({name:`Dylan`,extensions:[`dylan`,`dyl`,`intr`],load(){return Y(()=>import(`./dylan-O-V5Dw5W.js`).then(e=>X(e.dylan)),[])}}),A.of({name:`EBNF`,load(){return Y(()=>import(`./ebnf-SPmdBkvT.js`).then(e=>X(e.ebnf)),[])}}),A.of({name:`ECL`,extensions:[`ecl`],load(){return Y(()=>import(`./ecl-ChfCttfI.js`).then(e=>X(e.ecl)),[])}}),A.of({name:`edn`,extensions:[`edn`],load(){return Y(()=>import(`./clojure-kVFSWX0o.js`).then(e=>X(e.clojure)),[])}}),A.of({name:`Eiffel`,extensions:[`e`],load(){return Y(()=>import(`./eiffel-cB9EbjeN.js`).then(e=>X(e.eiffel)),[])}}),A.of({name:`Elm`,extensions:[`elm`],load(){return Y(()=>import(`./elm-BTiVflBU.js`).then(e=>X(e.elm)),[])}}),A.of({name:`Erlang`,extensions:[`erl`],load(){return Y(()=>import(`./erlang-egf0TXFm.js`).then(e=>X(e.erlang)),[])}}),A.of({name:`Esper`,load(){return Y(()=>import(`./sql-D_dieYbr.js`).then(e=>X(e.esper)),[])}}),A.of({name:`Factor`,extensions:[`factor`],load(){return Y(()=>import(`./factor-C2tAxNob.js`).then(e=>X(e.factor)),__vite__mapDeps([24,23]))}}),A.of({name:`FCL`,load(){return Y(()=>import(`./fcl-BiCjh1tj.js`).then(e=>X(e.fcl)),[])}}),A.of({name:`Forth`,extensions:[`forth`,`fth`,`4th`],load(){return Y(()=>import(`./forth-C4kDGW6u.js`).then(e=>X(e.forth)),[])}}),A.of({name:`Fortran`,extensions:[`f`,`for`,`f77`,`f90`,`f95`],load(){return Y(()=>import(`./fortran-DzkLaPnd.js`).then(e=>X(e.fortran)),[])}}),A.of({name:`F#`,alias:[`fsharp`],extensions:[`fs`],load(){return Y(()=>import(`./mllike-wTFlPWXS.js`).then(e=>X(e.fSharp)),[])}}),A.of({name:`Gas`,extensions:[`s`],load(){return Y(()=>import(`./gas-DMOxskQF.js`).then(e=>X(e.gas)),[])}}),A.of({name:`Gherkin`,extensions:[`feature`],load(){return Y(()=>import(`./gherkin-BPxBpp-k.js`).then(e=>X(e.gherkin)),[])}}),A.of({name:`Groovy`,extensions:[`groovy`,`gradle`],filename:/^Jenkinsfile$/,load(){return Y(()=>import(`./groovy-CkEnc0ZY.js`).then(e=>X(e.groovy)),[])}}),A.of({name:`Haskell`,extensions:[`hs`],load(){return Y(()=>import(`./haskell-Dadpo9-w.js`).then(e=>X(e.haskell)),[])}}),A.of({name:`Haxe`,extensions:[`hx`],load(){return Y(()=>import(`./haxe-CDNZL9MW.js`).then(e=>X(e.haxe)),[])}}),A.of({name:`HXML`,extensions:[`hxml`],load(){return Y(()=>import(`./haxe-CDNZL9MW.js`).then(e=>X(e.hxml)),[])}}),A.of({name:`HTTP`,load(){return Y(()=>import(`./http-jy9Zxxt3.js`).then(e=>X(e.http)),[])}}),A.of({name:`IDL`,extensions:[`pro`],load(){return Y(()=>import(`./idl-CGSB6iiy.js`).then(e=>X(e.idl)),[])}}),A.of({name:`JSON-LD`,alias:[`jsonld`],extensions:[`jsonld`],load(){return Y(()=>import(`./javascript-DSlzRUd8.js`).then(e=>X(e.jsonld)),[])}}),A.of({name:`Julia`,extensions:[`jl`],load(){return Y(()=>import(`./julia-DTiF9v6R.js`).then(e=>X(e.julia)),[])}}),A.of({name:`Kotlin`,extensions:[`kt`,`kts`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.kotlin)),[])}}),A.of({name:`LiveScript`,alias:[`ls`],extensions:[`ls`],load(){return Y(()=>import(`./livescript-Ci8Xxna6.js`).then(e=>X(e.liveScript)),[])}}),A.of({name:`Lua`,extensions:[`lua`],load(){return Y(()=>import(`./lua-eVxIrt9t.js`).then(e=>X(e.lua)),[])}}),A.of({name:`mIRC`,extensions:[`mrc`],load(){return Y(()=>import(`./mirc-CtHu9S1B.js`).then(e=>X(e.mirc)),[])}}),A.of({name:`Mathematica`,extensions:[`m`,`nb`,`wl`,`wls`],load(){return Y(()=>import(`./mathematica-Da3grj36.js`).then(e=>X(e.mathematica)),[])}}),A.of({name:`Modelica`,extensions:[`mo`],load(){return Y(()=>import(`./modelica-cKbQ0UXu.js`).then(e=>X(e.modelica)),[])}}),A.of({name:`MUMPS`,extensions:[`mps`],load(){return Y(()=>import(`./mumps-CKBHkOQq.js`).then(e=>X(e.mumps)),[])}}),A.of({name:`Mbox`,extensions:[`mbox`],load(){return Y(()=>import(`./mbox-BWBMSafM.js`).then(e=>X(e.mbox)),[])}}),A.of({name:`Nginx`,filename:/nginx.*\.conf$/i,load(){return Y(()=>import(`./nginx-B00AiQel.js`).then(e=>X(e.nginx)),[])}}),A.of({name:`NSIS`,extensions:[`nsh`,`nsi`],load(){return Y(()=>import(`./nsis-SMDwKltR.js`).then(e=>X(e.nsis)),__vite__mapDeps([25,23]))}}),A.of({name:`NTriples`,extensions:[`nt`,`nq`],load(){return Y(()=>import(`./ntriples-B_36EBV0.js`).then(e=>X(e.ntriples)),[])}}),A.of({name:`Objective-C`,alias:[`objective-c`,`objc`],extensions:[`m`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.objectiveC)),[])}}),A.of({name:`Objective-C++`,alias:[`objective-c++`,`objc++`],extensions:[`mm`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.objectiveCpp)),[])}}),A.of({name:`OCaml`,extensions:[`ml`,`mli`,`mll`,`mly`],load(){return Y(()=>import(`./mllike-wTFlPWXS.js`).then(e=>X(e.oCaml)),[])}}),A.of({name:`Octave`,extensions:[`m`],load(){return Y(()=>import(`./octave-BXPjzAif.js`).then(e=>X(e.octave)),[])}}),A.of({name:`Oz`,extensions:[`oz`],load(){return Y(()=>import(`./oz-Dedpat1M.js`).then(e=>X(e.oz)),[])}}),A.of({name:`Pascal`,extensions:[`p`,`pas`],load(){return Y(()=>import(`./pascal-CMcUg72K.js`).then(e=>X(e.pascal)),[])}}),A.of({name:`Perl`,extensions:[`pl`,`pm`],load(){return Y(()=>import(`./perl-DoVTbnzt.js`).then(e=>X(e.perl)),[])}}),A.of({name:`Pig`,extensions:[`pig`],load(){return Y(()=>import(`./pig-CULXT1YV.js`).then(e=>X(e.pig)),[])}}),A.of({name:`PowerShell`,extensions:[`ps1`,`psd1`,`psm1`],load(){return Y(()=>import(`./powershell-Cv5Uhf6b.js`).then(e=>X(e.powerShell)),[])}}),A.of({name:`Properties files`,alias:[`ini`,`properties`],extensions:[`properties`,`ini`,`in`],load(){return Y(()=>import(`./properties-CQ1C2P-M.js`).then(e=>X(e.properties)),[])}}),A.of({name:`ProtoBuf`,extensions:[`proto`],load(){return Y(()=>import(`./protobuf-SRlvzrl6.js`).then(e=>X(e.protobuf)),[])}}),A.of({name:`Pug`,alias:[`jade`],extensions:[`pug`,`jade`],load(){return Y(()=>import(`./pug-Bo3wfL-f.js`).then(e=>X(e.pug)),__vite__mapDeps([26,27]))}}),A.of({name:`Puppet`,extensions:[`pp`],load(){return Y(()=>import(`./puppet-ClSqCGj6.js`).then(e=>X(e.puppet)),[])}}),A.of({name:`Q`,extensions:[`q`],load(){return Y(()=>import(`./q-B_6Gdyzl.js`).then(e=>X(e.q)),[])}}),A.of({name:`R`,alias:[`rscript`],extensions:[`r`,`R`],load(){return Y(()=>import(`./r-BD07NGED.js`).then(e=>X(e.r)),[])}}),A.of({name:`RPM Changes`,load(){return Y(()=>import(`./rpm-CRu5Z2Jl.js`).then(e=>X(e.rpmChanges)),[])}}),A.of({name:`RPM Spec`,extensions:[`spec`],load(){return Y(()=>import(`./rpm-CRu5Z2Jl.js`).then(e=>X(e.rpmSpec)),[])}}),A.of({name:`Ruby`,alias:[`jruby`,`macruby`,`rake`,`rb`,`rbx`],extensions:[`rb`],filename:/^(Gemfile|Rakefile)$/,load(){return Y(()=>import(`./ruby-dZPnOz8h.js`).then(e=>X(e.ruby)),[])}}),A.of({name:`SAS`,extensions:[`sas`],load(){return Y(()=>import(`./sas-S2t8_sDI.js`).then(e=>X(e.sas)),[])}}),A.of({name:`Scala`,extensions:[`scala`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.scala)),[])}}),A.of({name:`Scheme`,extensions:[`scm`,`ss`],load(){return Y(()=>import(`./scheme-WcyFWLW2.js`).then(e=>X(e.scheme)),[])}}),A.of({name:`Shell`,alias:[`bash`,`sh`,`zsh`],extensions:[`sh`,`ksh`,`bash`],filename:/^PKGBUILD$/,load(){return Y(()=>import(`./shell-DUelnYSh.js`).then(e=>X(e.shell)),[])}}),A.of({name:`Sieve`,extensions:[`siv`,`sieve`],load(){return Y(()=>import(`./sieve-jDjlVhNh.js`).then(e=>X(e.sieve)),[])}}),A.of({name:`Smalltalk`,extensions:[`st`],load(){return Y(()=>import(`./smalltalk-ddWDYy10.js`).then(e=>X(e.smalltalk)),[])}}),A.of({name:`Solr`,load(){return Y(()=>import(`./solr-C7rQhLuW.js`).then(e=>X(e.solr)),[])}}),A.of({name:`SML`,extensions:[`sml`,`sig`,`fun`,`smackspec`],load(){return Y(()=>import(`./mllike-wTFlPWXS.js`).then(e=>X(e.sml)),[])}}),A.of({name:`SPARQL`,alias:[`sparul`],extensions:[`rq`,`sparql`],load(){return Y(()=>import(`./sparql--fPCCgVd.js`).then(e=>X(e.sparql)),[])}}),A.of({name:`Spreadsheet`,alias:[`excel`,`formula`],load(){return Y(()=>import(`./spreadsheet-DjthqD5G.js`).then(e=>X(e.spreadsheet)),[])}}),A.of({name:`Squirrel`,extensions:[`nut`],load(){return Y(()=>import(`./clike-BoDCOLzN.js`).then(e=>X(e.squirrel)),[])}}),A.of({name:`Stylus`,extensions:[`styl`],load(){return Y(()=>import(`./stylus-DxF70RNr.js`).then(e=>X(e.stylus)),[])}}),A.of({name:`Swift`,extensions:[`swift`],load(){return Y(()=>import(`./swift-T0hDoOb-.js`).then(e=>X(e.swift)),[])}}),A.of({name:`sTeX`,load(){return Y(()=>import(`./stex-rHcFYcA0.js`).then(e=>X(e.stex)),[])}}),A.of({name:`LaTeX`,alias:[`tex`],extensions:[`text`,`ltx`,`tex`],load(){return Y(()=>import(`./stex-rHcFYcA0.js`).then(e=>X(e.stex)),[])}}),A.of({name:`SystemVerilog`,extensions:[`v`,`sv`,`svh`],load(){return Y(()=>import(`./verilog-BJOO83gk.js`).then(e=>X(e.verilog)),[])}}),A.of({name:`Tcl`,extensions:[`tcl`],load(){return Y(()=>import(`./tcl-Dlzy1mPk.js`).then(e=>X(e.tcl)),[])}}),A.of({name:`Textile`,extensions:[`textile`],load(){return Y(()=>import(`./textile-Dy5rFZe5.js`).then(e=>X(e.textile)),[])}}),A.of({name:`TiddlyWiki`,load(){return Y(()=>import(`./tiddlywiki-DQP1OymS.js`).then(e=>X(e.tiddlyWiki)),[])}}),A.of({name:`Tiki wiki`,load(){return Y(()=>import(`./tiki-0vOj3DB2.js`).then(e=>X(e.tiki)),[])}}),A.of({name:`TOML`,extensions:[`toml`],load(){return Y(()=>import(`./toml-DEltN0lI.js`).then(e=>X(e.toml)),[])}}),A.of({name:`Troff`,extensions:[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`],load(){return Y(()=>import(`./troff-CRbBpEqY.js`).then(e=>X(e.troff)),[])}}),A.of({name:`TTCN`,extensions:[`ttcn`,`ttcn3`,`ttcnpp`],load(){return Y(()=>import(`./ttcn-M5q1nLKg.js`).then(e=>X(e.ttcn)),[])}}),A.of({name:`TTCN_CFG`,extensions:[`cfg`],load(){return Y(()=>import(`./ttcn-cfg-Rmw9NWq9.js`).then(e=>X(e.ttcnCfg)),[])}}),A.of({name:`Turtle`,extensions:[`ttl`],load(){return Y(()=>import(`./turtle-BCDWhJK0.js`).then(e=>X(e.turtle)),[])}}),A.of({name:`Web IDL`,extensions:[`webidl`],load(){return Y(()=>import(`./webidl-Ddy6hbV6.js`).then(e=>X(e.webIDL)),[])}}),A.of({name:`VB.NET`,extensions:[`vb`],load(){return Y(()=>import(`./vb-QQ7LGlOz.js`).then(e=>X(e.vb)),[])}}),A.of({name:`VBScript`,extensions:[`vbs`],load(){return Y(()=>import(`./vbscript-BiSEdUzz.js`).then(e=>X(e.vbScript)),[])}}),A.of({name:`Velocity`,extensions:[`vtl`],load(){return Y(()=>import(`./velocity-CzMg5_6w.js`).then(e=>X(e.velocity)),[])}}),A.of({name:`Verilog`,extensions:[`v`],load(){return Y(()=>import(`./verilog-BJOO83gk.js`).then(e=>X(e.verilog)),[])}}),A.of({name:`VHDL`,extensions:[`vhd`,`vhdl`],load(){return Y(()=>import(`./vhdl-ed4zAZAA.js`).then(e=>X(e.vhdl)),[])}}),A.of({name:`XQuery`,extensions:[`xy`,`xquery`,`xq`,`xqm`,`xqy`],load(){return Y(()=>import(`./xquery-Bw1zwhh6.js`).then(e=>X(e.xQuery)),[])}}),A.of({name:`Yacas`,extensions:[`ys`],load(){return Y(()=>import(`./yacas-DZdTXy3s.js`).then(e=>X(e.yacas)),[])}}),A.of({name:`Z80`,extensions:[`z80`],load(){return Y(()=>import(`./z80-DMG02_YV.js`).then(e=>X(e.z80)),[])}}),A.of({name:`MscGen`,extensions:[`mscgen`,`mscin`,`msc`],load(){return Y(()=>import(`./mscgen-C5pXQCMK.js`).then(e=>X(e.mscgen)),[])}}),A.of({name:`Xù`,extensions:[`xu`],load(){return Y(()=>import(`./mscgen-C5pXQCMK.js`).then(e=>X(e.xu)),[])}}),A.of({name:`MsGenny`,extensions:[`msgenny`],load(){return Y(()=>import(`./mscgen-C5pXQCMK.js`).then(e=>X(e.msgenny)),[])}}),A.of({name:`Vue`,extensions:[`vue`],load(){return Y(()=>import(`./dist-DuM9PL5k.js`).then(e=>e.vue()),__vite__mapDeps([28,7,4,5,1,2,8]))}}),A.of({name:`Angular Template`,load(){return Y(()=>import(`./dist-DqaKPP5Y.js`).then(e=>e.angular()),__vite__mapDeps([29,7,4,5,1,2,8]))}})],iI=`#2e3440`,aI=`#3b4252`,oI=`#434c5e`,sI=`#4c566a`,cI=`#e5e9f0`,lI=`#eceff4`,uI=`#8fbcbb`,dI=`#88c0d0`,kpe=`#81a1c1`,fI=`#5e81ac`,Ape=`#bf616a`,pI=`#d08770`,mI=`#ebcb8b`,hI=`#a3be8c`,jpe=`#b48ead`,gI=`#d30102`,_I=lI,vI=_I,Mpe=`#ffffff`,yI=aI,Npe=_I,bI=aI,Ppe=[f.theme({"&":{color:iI,backgroundColor:Mpe},".cm-content":{caretColor:bI},".cm-cursor, .cm-dropCursor":{borderLeftColor:bI},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Npe},".cm-panels":{backgroundColor:_I,color:sI},".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 ${sI}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:cI},".cm-activeLine":{backgroundColor:vI},".cm-selectionMatch":{backgroundColor:cI},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${sI}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:lI},".cm-gutters":{backgroundColor:lI,color:iI,border:`none`},".cm-activeLineGutter":{backgroundColor:vI},".cm-foldPlaceholder":{backgroundColor:`transparent`,border:`none`,color:`#ddd`},".cm-tooltip":{border:`none`,backgroundColor:yI},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:`transparent`,borderBottomColor:`transparent`},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:yI,borderBottomColor:yI},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:vI,color:sI}}},{dark:!1}),i(ye.define([{tag:v.keyword,color:fI},{tag:[v.name,v.deleted,v.character,v.propertyName,v.macroName],color:pI},{tag:[v.variableName],color:pI},{tag:[v.function(v.variableName)],color:fI},{tag:[v.labelName],color:kpe},{tag:[v.color,v.constant(v.name),v.standard(v.name)],color:fI},{tag:[v.definition(v.name),v.separator],color:hI},{tag:[v.brace],color:uI},{tag:[v.annotation],color:gI},{tag:[v.number,v.changed,v.annotation,v.modifier,v.self,v.namespace],color:dI},{tag:[v.typeName,v.className],color:mI},{tag:[v.operator,v.operatorKeyword],color:hI},{tag:[v.tagName],color:jpe},{tag:[v.squareBracket],color:Ape},{tag:[v.angleBracket],color:pI},{tag:[v.attributeName],color:mI},{tag:[v.regexp],color:fI},{tag:[v.quote],color:aI},{tag:[v.string],color:pI},{tag:v.link,color:uI,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[v.url,v.escape,v.special(v.string)],color:pI},{tag:[v.meta],color:dI},{tag:[v.comment],color:oI,fontStyle:`italic`},{tag:v.strong,fontWeight:`bold`,color:fI},{tag:v.emphasis,fontStyle:`italic`,color:fI},{tag:v.strikethrough,textDecoration:`line-through`},{tag:v.heading,fontWeight:`bold`,color:fI},{tag:v.special(v.heading1),fontWeight:`bold`,color:fI},{tag:v.heading1,fontWeight:`bold`,color:fI},{tag:[v.heading2,v.heading3,v.heading4],fontWeight:`bold`,color:fI},{tag:[v.heading5,v.heading6],color:fI},{tag:[v.atom,v.bool,v.special(v.variableName)],color:pI},{tag:[v.processingInstruction,v.inserted],color:uI},{tag:[v.contentSeparator],color:mI},{tag:v.invalid,color:oI,borderBottom:`1px dotted ${gI}`}]))],xI=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,SI=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(xI(e)):xI,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 se(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=y(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=a(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`&&(SI.prototype[Symbol.iterator]=function(){return this});var CI={from:-1,to:-1,match:/.*/.exec(``),precise:!0},wI=`gm`+(/x/.unicode==null?``:`u`),TI=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=CI,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new OI(e,t,n,r,i);this.re=new RegExp(t,wI+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter();let a=e.lineAt(r);this.curLineStart=a.from,this.matchPos=kI(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=kI(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}}},EI=new WeakMap,DI=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=EI.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return EI.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)),EI.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},OI=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=CI,this.matchPos=kI(e,r),this.re=new RegExp(t,wI+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=DI.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=kI(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=DI.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(TI.prototype[Symbol.iterator]=OI.prototype[Symbol.iterator]=function(){return this});function Fpe(e){try{return new RegExp(e,wI),!0}catch{return!1}}function kI(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 Ipe=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=le(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 p=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),m=k.cursor(p.from+Math.max(0,Math.min(u,p.length)));e.dispatch({effects:[r,f.scrollIntoView(m.from,{y:`center`})],selection:m})}),!0},Lpe={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},AI=Oe.define({combine(e){return oe(e,Lpe,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Rpe(e){let t=[Upe,Hpe];return e&&t.push(AI.of(e)),t}var zpe=T.mark({class:`cm-selectionMatch`}),Bpe=T.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function jI(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=L.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=L.Word)}function Vpe(e,t,n,r){return e(t.sliceDoc(n,n+1))==L.Word&&e(t.sliceDoc(r-1,r))==L.Word}var Hpe=ge.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(AI),{state:n}=e,r=n.selection;if(r.ranges.length>1)return T.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return T.none;let e=n.wordAt(i.head);if(!e)return T.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 T.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(jI(o,n,i.from,i.to)&&Vpe(o,n,i.from,i.to)))return T.none}else if(a=n.sliceDoc(i.from,i.to),!a)return T.none}let s=[];for(let r of e.visibleRanges){let e=new SI(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||jI(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Bpe.range(r,a)):(r>=i.to||a<=i.from)&&s.push(zpe.range(r,a)),s.length>t.maxMatches))return T.none}}return T.set(s)}},{decorations:e=>e.decorations}),Upe=f.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Wpe=({state:e,dispatch:t})=>{let{selection:n}=e,r=k.create(n.ranges.map(t=>e.wordAt(t.head)||k.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function Gpe(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 SI(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new SI(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 Kpe=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Wpe({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=Gpe(e,r);return i?(t(e.update({selection:e.selection.addRange(k.range(i.from,i.to),!1),effects:f.scrollIntoView(i.to)})),!0):!1},MI=Oe.define({combine(e){return oe(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new ome(e),scrollToMatch:e=>f.scrollIntoView(e)})}}),NI=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||Fpe(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`?`
|
|
128
128
|
`: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 Qpe(this):new Ype(this)}getCursor(e,t=0,n){let r=e.doc?e:Ce.create({doc:e});return n??=r.doc.length,this.regexp?II(this,r,t,n):FI(this,r,t,n)}},PI=class{constructor(e){this.spec=e}};function qpe(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 FI(e,t,n,r){let i;return e.wholeWord&&(i=Jpe(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=qpe(e.test,t,i)),new SI(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function Jpe(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(LI(i,n-a))!=L.Word||t(RI(i,n-a))!=L.Word)&&(t(RI(i,r-a))!=L.Word||t(LI(i,r-a))!=L.Word))}var Ype=class extends PI{constructor(e){super(e)}nextMatch(e,t,n){let r=FI(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=FI(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=FI(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=FI(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=FI(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 Xpe(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function II(e,t,n,r){let i;return e.wholeWord&&(i=Zpe(t.charCategorizer(t.selection.main.head))),e.test&&(i=Xpe(e.test,t,i)),new TI(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function LI(e,t){return e.slice(h(e,t,!1),t)}function RI(e,t){return e.slice(t,h(e,t))}function Zpe(e){return(t,n,r)=>!r[0].length||(e(LI(r.input,r.index))!=L.Word||e(RI(r.input,r.index))!=L.Word)&&(e(RI(r.input,r.index+r[0].length))!=L.Word||e(LI(r.input,r.index+r[0].length))!=L.Word)}var Qpe=class extends PI{nextMatch(e,t,n){let r=II(this.spec,e,n,e.doc.length).next();return r.done&&(r=II(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=II(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=II(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=II(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)}},zI=w.define(),BI=w.define(),VI=l.define({create(e){return new HI(JI(e).create(),null)},update(e,t){for(let n of t.effects)n.is(zI)?e=new HI(n.value.create(),e.panel):n.is(BI)&&(e=new HI(e.query,n.value?qI:null));return e},provide:e=>xe.from(e,e=>e.panel)}),HI=class{constructor(e,t){this.query=e,this.panel=t}},$pe=T.mark({class:`cm-searchMatch`}),eme=T.mark({class:`cm-searchMatch cm-searchMatch-selected`}),tme=ge.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(VI))}update(e){let t=e.state.field(VI);(t!=e.startState.field(VI)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return T.none;let{view:n}=this,r=new o;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?eme:$pe)})}return r.finish()}},{decorations:e=>e.decorations});function UI(e){return t=>{let n=t.state.field(VI,!1);return n&&n.query.spec.valid?e(t,n):ZI(t)}}var WI=UI((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=k.single(r.from,r.to),a=e.state.facet(MI);return e.dispatch({selection:i,effects:[nL(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),XI(e),!0}),GI=UI((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=k.single(i.from,i.to),o=e.state.facet(MI);return e.dispatch({selection:a,effects:[nL(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),XI(e),!0}),nme=UI((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:k.create(n.map(e=>k.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),rme=({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 SI(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(k.range(t.value.from,t.value.to))}return t(e.update({selection:k.create(a,o),userEvent:`select.search.matches`})),!0},KI=UI((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}),u.push(f.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=k.single(o.from,o.to).map(d),u.push(nL(e,o)),u.push(n.facet(MI).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),ime=UI((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:f.announce.of(r),userEvent:`input.replace.all`}),!0});function qI(e){return e.state.facet(MI).createPanel(e)}function JI(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(MI);return new NI({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 YI(e){let t=b(e,qI);return t&&t.dom.querySelector(`[main-field]`)}function XI(e){let t=YI(e);t&&t==e.root.activeElement&&t.select()}var ZI=e=>{let t=e.state.field(VI,!1);if(t&&t.panel){let n=YI(e);if(n&&n!=e.root.activeElement){let r=JI(e.state,t.query.spec);r.valid&&e.dispatch({effects:zI.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[BI.of(!0),t?zI.of(JI(e.state,t.query.spec)):w.appendConfig.of(cme)]});return!0},QI=e=>{let t=e.state.field(VI,!1);if(!t||!t.panel)return!1;let n=b(e,qI);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:BI.of(!1)}),!0},ame=[{key:`Mod-f`,run:ZI,scope:`editor search-panel`},{key:`F3`,run:WI,shift:GI,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:WI,shift:GI,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:QI,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:rme},{key:`Mod-Alt-g`,run:Ipe},{key:`Mod-d`,run:Kpe,preventDefault:!0}],ome=class{constructor(e){this.view=e;let t=this.query=e.state.field(VI).query.spec;this.commit=this.commit.bind(this),this.searchField=I(`input`,{value:t.search,placeholder:$I(e,`Find`),"aria-label":$I(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=I(`input`,{value:t.replace,placeholder:$I(e,`Replace`),"aria-label":$I(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=I(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=I(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=I(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return I(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=I(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>WI(e),[$I(e,`next`)]),n(`prev`,()=>GI(e),[$I(e,`previous`)]),n(`select`,()=>nme(e),[$I(e,`all`)]),I(`label`,null,[this.caseField,$I(e,`match case`)]),I(`label`,null,[this.reField,$I(e,`regexp`)]),I(`label`,null,[this.wordField,$I(e,`by word`)]),...e.state.readOnly?[]:[I(`br`),this.replaceField,n(`replace`,()=>KI(e),[$I(e,`replace`)]),n(`replaceAll`,()=>ime(e),[$I(e,`replace all`)])],I(`button`,{name:`close`,onclick:()=>QI(e),"aria-label":$I(e,`close`),type:`button`},[`×`])])}commit(){let e=new NI({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:zI.of(e)}))}keydown(e){P(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?GI:WI)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),KI(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(zI)&&!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(MI).top}};function $I(e,t){return e.state.phrase(t)}var eL=30,tL=/[\s\.,:;?!]/;function nL(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-eL),o=Math.min(i,n+eL),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<eL;e++)if(!tL.test(s[e+1])&&tL.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-eL;e--)if(!tL.test(s[e-1])&&tL.test(s[e])){s=s.slice(0,e);break}}return f.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var sme=f.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`}}),cme=[VI,De.low(tme),sme],rL=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},iL=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(dL).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),s=new o,c=[],l=0,u=r.doc.iter(),d=0,f=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!c.length)break;let n,r;if(c.length)n=l,r=c.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>f)break;r=t.to,c.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))c.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,f);let i=!1;if(c.some(e=>e.from==n&&(e.to==r||r==f))&&(i=n==r,!i&&r-n<10)){let e=n-(d+u.value.length);e>0&&(u.next(e),d=n);for(let e=n;;){if(e>=r){i=!0;break}if(!u.lineBreak&&d+u.value.length>e)break;e=d+u.value.length,d+=u.value.length,u.next()}}let o=bme(c);if(i)s.add(n,n,T.widget({widget:new gme(o),diagnostics:c.slice()}));else{let e=c.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);s.add(n,r,T.mark({class:`cm-lintRange cm-lintRange-`+o+e,diagnostics:c.slice(),inclusiveEnd:c.some(e=>e.to>r)}))}if(l=r,l==f)break;for(let e=0;e<c.length;e++)c[e].to<=l&&c.splice(e--,1)}let p=s.finish();return new e(p,n,aL(p))}};function aL(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 rL(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new rL(r.from,n,r.diagnostic)}),r}function lme(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(dL).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(oL))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function ume(e,t){return e.field(lL,!1)?t:t.concat(w.appendConfig.of(xme))}var oL=w.define(),sL=w.define(),cL=w.define(),lL=l.define({create(){return new iL(T.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=aL(n,e.selected.diagnostic,i)||aL(n,null,i)}!n.size&&i&&t.state.facet(dL).autoPanel&&(i=null),e=new iL(n,i,r)}for(let n of t.effects)if(n.is(oL)){let r=t.state.facet(dL).autoPanel?n.value.length?gL.open:null:e.panel;e=iL.init(n.value,r,t.state)}else n.is(sL)?e=new iL(e.diagnostics,n.value?gL.open:null,e.selected):n.is(cL)&&(e=new iL(e.diagnostics,e.panel,n.value));return e},provide:e=>[xe.from(e,e=>e.panel),f.decorations.from(e,e=>e.diagnostics)]}),dme=T.mark({class:`cm-lintRange cm-lintRange-active`});function fme(e,t,n){let{diagnostics:r}=e.state.field(lL),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(dL).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:pme(e,i)}}}:null}function pme(e,t){return I(`ul`,{class:`cm-tooltip-lint`},t.map(t=>mL(e,t,!1)))}var mme=e=>{let t=e.state.field(lL,!1);(!t||!t.panel)&&e.dispatch({effects:ume(e.state,[sL.of(!0)])});let n=b(e,gL.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},uL=e=>{let t=e.state.field(lL,!1);return!t||!t.panel?!1:(e.dispatch({effects:sL.of(!1)}),!0)},hme=[{key:`Mod-Shift-m`,run:mme,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(lL,!1);if(!t)return!1;let n=e.state.selection.main,r=aL(t.diagnostics,null,n.to+1);return!r&&(r=aL(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}),!0)}}],dL=Oe.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...oe(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:fL,tooltipFilter:fL,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 fL(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function pL(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 mL(e,t,n){let r=n?pL(t.actions):[];return I(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},I(`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=aL(e.state.field(lL).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),I(`u`,s.slice(c,c+1)),s.slice(c+1)];return I(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&I(`div`,{class:`cm-diagnosticSource`},t.source))}var gme=class extends d{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return I(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},hL=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=mL(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},gL=class e{constructor(e){this.view=e,this.items=[];let t=t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)uL(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=pL(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=aL(this.view.state.field(lL).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=I(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t,onclick:n}),this.dom=I(`div`,{class:`cm-panel-lint`},this.list,I(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>uL(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(lL).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(lL),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 hL(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 hL(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=aL(this.view.state.field(lL).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:cL.of(t)})}static open(t){return new e(t)}};function _me(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 _L(e){return _me(`<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 vme=f.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:_L(`#d11`)},".cm-lintRange-warning":{backgroundImage:_L(`orange`)},".cm-lintRange-info":{backgroundImage:_L(`#999`)},".cm-lintRange-hint":{backgroundImage:_L(`#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 yme(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function bme(e){let t=`hint`,n=1;for(let r of e){let e=yme(r.severity);e>n&&(n=e,t=r.severity)}return t}var xme=[lL,f.decorations.compute([lL],e=>{let{selected:t,panel:n}=e.field(lL);return!t||!n||t.from==t.to?T.none:T.set([dme.range(t.from,t.to)])}),_e(fme,{hideOn:lme}),vme],Sme=[j(),be(),fe(),YP(),ne(),E(),O(),Ce.allowMultipleSelections.of(!0),we(),i(te,{fallback:!0}),ce(),afe(),hfe(),ve(),D(),ee(),Rpe(),ie.of([...cfe,...nI,...ame,...oF,...Se,...VP,...hme])];fe(),YP(),E(),i(te,{fallback:!0}),ie.of([...nI,...oF]);function vL(e,[t,n]){return Math.min(n,Math.max(t,e))}function Cme(e){let t=R.useRef({value:e,previous:e});return R.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var yL=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`}),wme=`VisuallyHidden`,bL=R.forwardRef((e,t)=>(0,z.jsx)(HT.span,{...e,ref:t,style:{...yL,...e.style}}));bL.displayName=wme;var Tme=bL,Eme=[` `,`Enter`,`ArrowUp`,`ArrowDown`],Dme=[` `,`Enter`],xL=`Select`,[SL,CL,Ome]=BO(xL),[wL,kme]=zT(xL,[Ome,CD]),TL=CD(),[Ame,EL]=wL(xL),[jme,Mme]=wL(xL),DL=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}=e,h=TL(t),[g,_]=R.useState(null),[v,y]=R.useState(null),[b,x]=R.useState(!1),S=VO(l),[C,w]=BD({prop:r,defaultProp:i??!1,onChange:a,caller:xL}),[T,E]=BD({prop:o,defaultProp:s,onChange:c,caller:xL}),D=R.useRef(null),O=g?m||!!g.closest(`form`):!0,[k,A]=R.useState(new Set),j=Array.from(k).map(e=>e.props.value).join(`;`);return(0,z.jsx)(ND,{...h,children:(0,z.jsxs)(Ame,{required:p,scope:t,trigger:g,onTriggerChange:_,valueNode:v,onValueNodeChange:y,valueNodeHasChildren:b,onValueNodeHasChildrenChange:x,contentId:lE(),value:T,onValueChange:E,open:C,onOpenChange:w,dir:S,triggerPointerDownPosRef:D,disabled:f,children:[(0,z.jsx)(SL.Provider,{scope:t,children:(0,z.jsx)(jme,{scope:e.__scopeSelect,onNativeOptionAdd:R.useCallback(e=>{A(t=>new Set(t).add(e))},[]),onNativeOptionRemove:R.useCallback(e=>{A(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),O?(0,z.jsxs)(iR,{"aria-hidden":!0,required:p,tabIndex:-1,name:u,autoComplete:d,value:T,onChange:e=>E(e.target.value),disabled:f,form:m,children:[T===void 0?(0,z.jsx)(`option`,{value:``}):null,Array.from(k)]},j):null]})})};DL.displayName=xL;var OL=`SelectTrigger`,kL=R.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...i}=e,a=TL(n),o=EL(OL,n),s=o.disabled||r,c=RT(t,o.onTriggerChange),l=CL(n),u=R.useRef(`touch`),[d,f,p]=oR(e=>{let t=l().filter(e=>!e.disabled),n=sR(t,e,t.find(e=>e.value===o.value));n!==void 0&&o.onValueChange(n.value)}),m=e=>{s||(o.onOpenChange(!0),p()),e&&(o.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,z.jsx)(PD,{asChild:!0,...a,children:(0,z.jsx)(HT.button,{type:`button`,role:`combobox`,"aria-controls":o.contentId,"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":aR(o.value)?``:void 0,...i,ref:c,onClick:FT(i.onClick,e=>{e.currentTarget.focus(),u.current!==`mouse`&&m(e)}),onPointerDown:FT(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:FT(i.onKeyDown,e=>{let t=d.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&f(e.key),!(t&&e.key===` `)&&Eme.includes(e.key)&&(m(),e.preventDefault())})})})});kL.displayName=OL;var AL=`SelectValue`,jL=R.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,children:a,placeholder:o=``,...s}=e,c=EL(AL,n),{onValueNodeHasChildrenChange:l}=c,u=a!==void 0,d=RT(t,c.onValueNodeChange);return cE(()=>{l(u)},[l,u]),(0,z.jsx)(HT.span,{...s,ref:d,style:{pointerEvents:`none`},children:aR(c.value)?(0,z.jsx)(z.Fragment,{children:o}):a})});jL.displayName=AL;var Nme=`SelectIcon`,ML=R.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...i}=e;return(0,z.jsx)(HT.span,{"aria-hidden":!0,...i,ref:t,children:r||`▼`})});ML.displayName=Nme;var Pme=`SelectPortal`,NL=e=>(0,z.jsx)(LD,{asChild:!0,...e});NL.displayName=Pme;var PL=`SelectContent`,FL=R.forwardRef((e,t)=>{let n=EL(PL,e.__scopeSelect),[r,i]=R.useState();if(cE(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?Na.createPortal((0,z.jsx)(LL,{scope:e.__scopeSelect,children:(0,z.jsx)(SL.Slot,{scope:e.__scopeSelect,children:(0,z.jsx)(`div`,{children:e.children})})}),t):null}return(0,z.jsx)(zL,{...e,ref:t})});FL.displayName=PL;var IL=10,[LL,RL]=wL(PL),Fme=`SelectContentImpl`,Ime=BT(`SelectContent.RemoveScroll`),zL=R.forwardRef((e,t)=>{let{__scopeSelect:n,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=EL(PL,n),[y,b]=R.useState(null),[x,S]=R.useState(null),C=RT(t,e=>b(e)),[w,T]=R.useState(null),[E,D]=R.useState(null),O=CL(n),[k,A]=R.useState(!1),j=R.useRef(!1);R.useEffect(()=>{if(y)return KD(y)},[y]),ZT();let M=R.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=R.useCallback(()=>M([w,y]),[M,w,y]);R.useEffect(()=>{k&&N()},[k,N]);let{onOpenChange:P,triggerPointerDownPosRef:F}=v;R.useEffect(()=>{if(y){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(F.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(F.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():y.contains(n.target)||P(!1),document.removeEventListener(`pointermove`,t),F.current=null};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]),R.useEffect(()=>{let e=()=>P(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[P]);let[ee,te]=oR(e=>{let t=O().filter(e=>!e.disabled),n=sR(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),I=R.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]),ne=R.useCallback(()=>y?.focus(),[y]),L=R.useCallback((e,t,n)=>{let r=!j.current&&!n;(v.value!==void 0&&v.value===t||r)&&D(e)},[v.value]),re=r===`popper`?VL:BL,ie=re===VL?{side:s,sideOffset:c,align:l,alignOffset:u,arrowPadding:d,collisionBoundary:f,collisionPadding:p,sticky:m,hideWhenDetached:h,avoidCollisions:g}:{};return(0,z.jsx)(LL,{scope:n,content:y,viewport:x,onViewportChange:S,itemRefCallback:I,selectedItem:w,onItemLeave:ne,itemTextRefCallback:L,focusSelectedItem:N,selectedItemText:E,position:r,isPositioned:k,searchRef:ee,children:(0,z.jsx)(yO,{as:Ime,allowPinchZoom:!0,children:(0,z.jsx)(nE,{asChild:!0,trapped:v.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:FT(i,e=>{v.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,z.jsx)(qT,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>v.onOpenChange(!1),children:(0,z.jsx)(re,{role:`listbox`,id:v.contentId,"data-state":v.open?`open`:`closed`,dir:v.dir,onContextMenu:e=>e.preventDefault(),..._,...ie,onPlaced:()=>A(!0),ref:C,style:{display:`flex`,flexDirection:`column`,outline:`none`,..._.style},onKeyDown:FT(_.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&te(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()}})})})})})})});zL.displayName=Fme;var Lme=`SelectItemAlignedPosition`,BL=R.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...i}=e,a=EL(PL,n),o=RL(PL,n),[s,c]=R.useState(null),[l,u]=R.useState(null),d=RT(t,e=>u(e)),f=CL(n),p=R.useRef(!1),m=R.useRef(!0),{viewport:h,selectedItem:g,selectedItemText:_,focusSelectedItem:v}=o,y=R.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-IL,d=vL(a,[IL,Math.max(IL,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-IL,d=vL(a,[IL,Math.max(IL,u-l)]);s.style.minWidth=c+`px`,s.style.right=d+`px`}let o=f(),c=window.innerHeight-IL*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-IL,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=`${IL}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]);cE(()=>y(),[y]);let[b,x]=R.useState();return cE(()=>{l&&x(window.getComputedStyle(l).zIndex)},[l]),(0,z.jsx)(zme,{scope:n,contentWrapper:s,shouldExpandOnScrollRef:p,onScrollButtonChange:R.useCallback(e=>{e&&m.current===!0&&(y(),v?.(),m.current=!1)},[y,v]),children:(0,z.jsx)(`div`,{ref:c,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:b},children:(0,z.jsx)(HT.div,{...i,ref:d,style:{boxSizing:`border-box`,maxHeight:`100%`,...i.style}})})})});BL.displayName=Lme;var Rme=`SelectPopperPosition`,VL=R.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=IL,...a}=e,o=TL(n);return(0,z.jsx)(FD,{...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)`}})});VL.displayName=Rme;var[zme,HL]=wL(PL,{}),UL=`SelectViewport`,WL=R.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...i}=e,a=RL(UL,n),o=HL(UL,n),s=RT(t,a.onViewportChange),c=R.useRef(0);return(0,z.jsxs)(z.Fragment,{children:[(0,z.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,z.jsx)(SL.Slot,{scope:n,children:(0,z.jsx)(HT.div,{"data-radix-select-viewport":``,role:`presentation`,...i,ref:s,style:{position:`relative`,flex:1,overflow:`hidden auto`,...i.style},onScroll:FT(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-IL*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})})})]})});WL.displayName=UL;var GL=`SelectGroup`,[Bme,Vme]=wL(GL),Hme=R.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=lE();return(0,z.jsx)(Bme,{scope:n,id:i,children:(0,z.jsx)(HT.div,{role:`group`,"aria-labelledby":i,...r,ref:t})})});Hme.displayName=GL;var KL=`SelectLabel`,Ume=R.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=Vme(KL,n);return(0,z.jsx)(HT.div,{id:i.id,...r,ref:t})});Ume.displayName=KL;var qL=`SelectItem`,[Wme,JL]=wL(qL),YL=R.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:i=!1,textValue:a,...o}=e,s=EL(qL,n),c=RL(qL,n),l=s.value===r,[u,d]=R.useState(a??``),[f,p]=R.useState(!1),m=RT(t,e=>c.itemRefCallback?.(e,r,i)),h=lE(),g=R.useRef(`touch`),_=()=>{i||(s.onValueChange(r),s.onOpenChange(!1))};if(r===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,z.jsx)(Wme,{scope:n,value:r,disabled:i,textId:h,isSelected:l,onItemTextChange:R.useCallback(e=>{d(t=>t||(e?.textContent??``).trim())},[]),children:(0,z.jsx)(SL.ItemSlot,{scope:n,value:r,disabled:i,textValue:u,children:(0,z.jsx)(HT.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:FT(o.onFocus,()=>p(!0)),onBlur:FT(o.onBlur,()=>p(!1)),onClick:FT(o.onClick,()=>{g.current!==`mouse`&&_()}),onPointerUp:FT(o.onPointerUp,()=>{g.current===`mouse`&&_()}),onPointerDown:FT(o.onPointerDown,e=>{g.current=e.pointerType}),onPointerMove:FT(o.onPointerMove,e=>{g.current=e.pointerType,i?c.onItemLeave?.():g.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:FT(o.onPointerLeave,e=>{e.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:FT(o.onKeyDown,e=>{c.searchRef?.current!==``&&e.key===` `||(Dme.includes(e.key)&&_(),e.key===` `&&e.preventDefault())})})})})});YL.displayName=qL;var XL=`SelectItemText`,ZL=R.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:i,...a}=e,o=EL(XL,n),s=RL(XL,n),c=JL(XL,n),l=Mme(XL,n),[u,d]=R.useState(null),f=RT(t,e=>d(e),c.onItemTextChange,e=>s.itemTextRefCallback?.(e,c.value,c.disabled)),p=u?.textContent,m=R.useMemo(()=>(0,z.jsx)(`option`,{value:c.value,disabled:c.disabled,children:p},c.value),[c.disabled,c.value,p]),{onNativeOptionAdd:h,onNativeOptionRemove:g}=l;return cE(()=>(h(m),()=>g(m)),[h,g,m]),(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(HT.span,{id:c.textId,...a,ref:f}),c.isSelected&&o.valueNode&&!o.valueNodeHasChildren?Na.createPortal(a.children,o.valueNode):null]})});ZL.displayName=XL;var QL=`SelectItemIndicator`,Gme=R.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return JL(QL,n).isSelected?(0,z.jsx)(HT.span,{"aria-hidden":!0,...r,ref:t}):null});Gme.displayName=QL;var $L=`SelectScrollUpButton`,Kme=R.forwardRef((e,t)=>{let n=RL($L,e.__scopeSelect),r=HL($L,e.__scopeSelect),[i,a]=R.useState(!1),o=RT(t,r.onScrollButtonChange);return cE(()=>{if(n.viewport&&n.isPositioned){let e=function(){a(t.scrollTop>0)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,z.jsx)(tR,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});Kme.displayName=$L;var eR=`SelectScrollDownButton`,qme=R.forwardRef((e,t)=>{let n=RL(eR,e.__scopeSelect),r=HL(eR,e.__scopeSelect),[i,a]=R.useState(!1),o=RT(t,r.onScrollButtonChange);return cE(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight;a(Math.ceil(t.scrollTop)<e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,z.jsx)(tR,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});qme.displayName=eR;var tR=R.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...i}=e,a=RL(`SelectScrollButton`,n),o=R.useRef(null),s=CL(n),c=R.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},[]);return R.useEffect(()=>()=>c(),[c]),cE(()=>{s().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[s]),(0,z.jsx)(HT.div,{"aria-hidden":!0,...i,ref:t,style:{flexShrink:0,...i.style},onPointerDown:FT(i.onPointerDown,()=>{o.current===null&&(o.current=window.setInterval(r,50))}),onPointerMove:FT(i.onPointerMove,()=>{a.onItemLeave?.(),o.current===null&&(o.current=window.setInterval(r,50))}),onPointerLeave:FT(i.onPointerLeave,()=>{c()})})}),Jme=`SelectSeparator`,nR=R.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,z.jsx)(HT.div,{"aria-hidden":!0,...r,ref:t})});nR.displayName=Jme;var rR=`SelectArrow`,Yme=R.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=TL(n),a=EL(rR,n),o=RL(rR,n);return a.open&&o.position===`popper`?(0,z.jsx)(ID,{...i,...r,ref:t}):null});Yme.displayName=rR;var Xme=`SelectBubbleInput`,iR=R.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let i=R.useRef(null),a=RT(r,i),o=Cme(t);return R.useEffect(()=>{let e=i.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(o!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[o,t]),(0,z.jsx)(HT.select,{...n,style:{...yL,...n.style},ref:a,defaultValue:t})});iR.displayName=Xme;function aR(e){return e===``||e===void 0}function oR(e){let t=UT(e),n=R.useRef(``),r=R.useRef(0),i=R.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=R.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return R.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function sR(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=Zme(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}function Zme(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Qme=DL,$me=kL,ehe=jL,the=ML,nhe=NL,rhe=FL,ihe=WL,ahe=YL,ohe=ZL,she=nR,[cR,che]=zT(`Tooltip`,[CD]),lR=CD(),uR=`TooltipProvider`,lhe=700,dR=`tooltip.open`,[uhe,fR]=cR(uR),pR=e=>{let{__scopeTooltip:t,delayDuration:n=lhe,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=R.useRef(!0),s=R.useRef(!1),c=R.useRef(0);return R.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,z.jsx)(uhe,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:R.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:R.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:R.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};pR.displayName=uR;var mR=`Tooltip`,[dhe,hR]=cR(mR),gR=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=fR(mR,e.__scopeTooltip),l=lR(t),[u,d]=R.useState(null),f=lE(),p=R.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=R.useRef(!1),[_,v]=BD({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(dR))):c.onClose(),a?.(e)},caller:mR}),y=R.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=R.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=R.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=R.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return R.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,z.jsx)(ND,{...l,children:(0,z.jsx)(dhe,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:R.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:R.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};gR.displayName=mR;var _R=`TooltipTrigger`,vR=R.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=hR(_R,n),a=fR(_R,n),o=lR(n),s=RT(t,R.useRef(null),i.onTriggerChange),c=R.useRef(!1),l=R.useRef(!1),u=R.useCallback(()=>c.current=!1,[]);return R.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,z.jsx)(PD,{asChild:!0,...o,children:(0,z.jsx)(HT.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:FT(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:FT(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:FT(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:FT(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:FT(e.onBlur,i.onClose),onClick:FT(e.onClick,i.onClose)})})});vR.displayName=_R;var yR=`TooltipPortal`,[fhe,phe]=cR(yR,{forceMount:void 0}),bR=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=hR(yR,t);return(0,z.jsx)(fhe,{scope:t,forceMount:n,children:(0,z.jsx)(RD,{present:n||a.open,children:(0,z.jsx)(LD,{asChild:!0,container:i,children:r})})})};bR.displayName=yR;var xR=`TooltipContent`,SR=R.forwardRef((e,t)=>{let n=phe(xR,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=hR(xR,e.__scopeTooltip);return(0,z.jsx)(RD,{present:r||o.open,children:o.disableHoverableContent?(0,z.jsx)(CR,{side:i,...a,ref:t}):(0,z.jsx)(mhe,{side:i,...a,ref:t})})}),mhe=R.forwardRef((e,t)=>{let n=hR(xR,e.__scopeTooltip),r=fR(xR,e.__scopeTooltip),i=R.useRef(null),a=RT(t,i),[o,s]=R.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=R.useCallback(()=>{s(null),d(!1)},[d]),p=R.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=yhe(r,vhe(r,n.getBoundingClientRect())),a=bhe(t.getBoundingClientRect());s(She([...i,...a])),d(!0)},[d]);return R.useEffect(()=>()=>f(),[f]),R.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),R.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!xhe(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,z.jsx)(CR,{...e,ref:a})}),[hhe,ghe]=cR(mR,{isInside:!1}),_he=Zoe(`TooltipContent`),CR=R.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=hR(xR,n),l=lR(n),{onClose:u}=c;return R.useEffect(()=>(document.addEventListener(dR,u),()=>document.removeEventListener(dR,u)),[u]),R.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,z.jsx)(qT,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,z.jsxs)(FD,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.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,z.jsx)(_he,{children:r}),(0,z.jsx)(hhe,{scope:n,isInside:!0,children:(0,z.jsx)(Tme,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});SR.displayName=xR;var wR=`TooltipArrow`,TR=R.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=lR(n);return ghe(wR,n).isInside?null:(0,z.jsx)(ID,{...i,...r,ref:t})});TR.displayName=wR;function vhe(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`)}}function yhe(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});break}return r}function bhe(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}]}function xhe(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}function She(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)),Che(t)}function Che(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)}var ER=pR,DR=gR,OR=vR,kR=bR,AR=SR,whe=TR,jR=R.forwardRef(({title:e,children:t},n)=>{let r=Vl(hC);return R.createElement(ER,{delayDuration:100},R.createElement(DR,null,R.createElement(OR,{ref:n,asChild:!0},R.createElement(`span`,{className:mw.tooltipTrigger},t)),R.createElement(kR,{container:r?.current},R.createElement(AR,{className:(0,rT.default)(mw.tooltipContent),sideOffset:10},e))))}),The=R.forwardRef(({children:e,className:t,...n},r)=>R.createElement(ahe,{...n,ref:r,className:(0,rT.default)(t,mw.selectItem)},R.createElement(ohe,null,e))),Ehe=({title:e,placeholder:t,className:n})=>{let[r,i]=Hl(WS,NC);return R.createElement(jR,{title:e},R.createElement($me,{"aria-label":t,className:(0,rT.default)(mw.selectTrigger,n),"data-toolbar-item":!0,disabled:r},R.createElement(ehe,{placeholder:t}),R.createElement(the,{className:mw.selectDropdownArrow},i(`arrow_drop_down`))))},Dhe=({children:e,className:t=mw.selectContainer})=>{let n=Vl(hC);return R.createElement(nhe,{container:n?.current},R.createElement(rhe,{className:(0,rT.default)(t,`mdxeditor-select-content`),onCloseAutoFocus:e=>{e.preventDefault()},position:`popper`},R.createElement(ihe,{"data-editor-dropdown":!0,style:{maxHeight:`var(--radix-select-content-available-height)`}},e)))},MR=e=>R.createElement(Qme,{value:e.value||``,onValueChange:e.onChange,disabled:e.disabled},R.createElement(Ehe,{title:e.triggerTitle,placeholder:e.placeholder}),R.createElement(Dhe,null,e.items.map((e,t)=>e===`separator`?R.createElement(she,{key:t}):R.createElement(The,{key:t,value:e.value},e.label)))),NR=({language:e,nodeKey:t,code:n,focusEmitter:r})=>{let i=rw(),{parentEditor:a,lexicalNode:o}=JN(),[s,c,l,u,d]=Hl(WS,LR,RR,NC,IR),p=Dpe(t,`codeblock`,e,r),{setCode:m}=JN(),h=R.useRef(null),g=R.useRef(null),{value:_,items:v}=R.useMemo(()=>Ohe(d,e),[d,e]),y=R.useRef(m);return y.current=m,p.current={getCodemirror:()=>h.current},R.useEffect(()=>{let t=g.current;return(async()=>{let r=[...c,Sme,Ppe,j(),ie.of([Epe]),f.lineWrapping,f.updateListener.of(({state:e})=>{y.current(e.doc.toString())}),f.domEventHandlers({focus:()=>{a.update(()=>{Rh(null)})}})];if(s&&r.push(Ce.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=Ope.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=``,h.current=new f({parent:t,state:Ce.create({doc:n,extensions:r})}),t.addEventListener(`keydown`,PR)})(),()=>{var e;(e=h.current)==null||e.destroy(),h.current=null,t.removeEventListener(`keydown`,PR)}},[s,e,...c]),R.createElement(`div`,{className:mw.codeMirrorWrapper},R.createElement(`div`,{className:mw.codeMirrorToolbar},R.createElement(MR,{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}),R.createElement(`button`,{className:mw.iconButton,type:`button`,disabled:s,title:i(`codeblock.delete`,`Delete code block`),onClick:e=>{e.preventDefault(),a.update(()=>{o.remove()})}},u(`delete_small`))),R.createElement(`div`,{ref:g}))};function PR(e){e.stopPropagation()}function FR(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 Ohe(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 IR=Il(FR({js:`JavaScript`,ts:`TypeScript`,tsx:`TypeScript (React)`,jsx:`JavaScript (React)`,css:`CSS`})),khe=Ll(e=>{e.link(e.pipe(khe,Wl(({language:e,code:t})=>({code:t,language:e,meta:``}))),ZN)}),LR=Il([]),RR=Il(!0),Ahe=Xl({update(e,t){e.pubIn({[IR]:FR(t?.codeBlockLanguages??{}),[LR]:t?.codeMirrorExtensions??[],[RR]:t?.autoLoadLanguageSupport??!0})},init(e,t){let n=FR(t?.codeBlockLanguages??{});e.pubIn({[IR]:n,[LR]:t?.codeMirrorExtensions??[],[gde]:jhe(),[RR]:t?.autoLoadLanguageSupport??!0})}});function jhe(e){return{match(e,t){return!t},priority:1,Editor:NR}}function Mhe({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}=lue({values:{url:e,title:t,text:n}}),p=rw();return R.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,rT.default)(mw.multiFieldForm,mw.linkDialogEditForm)},R.createElement(`div`,{className:mw.formField},R.createElement(`label`,{htmlFor:`link-url`},p(`createLink.url`,`URL`)),R.createElement(nde,{register:c,initialInputValue:e,inputName:`url`,suggestions:a,setValue:d,control:u,placeholder:p(`createLink.urlPlaceholder`,`Select or paste an URL`),autofocus:!0})),s?R.createElement(`div`,{className:mw.formField},R.createElement(`label`,{htmlFor:`link-text`,title:p(`createLink.textTooltip`,`The text to be displayed for the link`)},p(`createLink.text`,`Anchor text`)),R.createElement(`input`,{id:`link-text`,className:mw.textInput,size:40,...c(`text`)})):null,o?R.createElement(`div`,{className:mw.formField},R.createElement(`label`,{htmlFor:`link-title`,title:p(`createLink.titleTooltip`,`The link's title attribute, shown on hover`)},p(`createLink.title`,`Link title`)),R.createElement(`input`,{id:`link-title`,className:mw.textInput,size:40,...c(`title`)})):null,R.createElement(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:`var(--spacing-2)`}},R.createElement(`button`,{type:`submit`,title:p(`createLink.saveTooltip`,`Set URL`),"aria-label":p(`createLink.saveTooltip`,`Set URL`),className:(0,rT.default)(mw.primaryButton)},p(`dialogControls.save`,`Save`)),R.createElement(`button`,{type:`reset`,title:p(`createLink.cancelTooltip`,`Cancel change`),"aria-label":p(`createLink.cancelTooltip`,`Cancel change`),className:(0,rT.default)(mw.secondaryButton)},p(`dialogControls.cancel`,`Cancel`))))}var Nhe=()=>{let[e,t,n,r,i,a,o]=Hl(hC,VS,NC,HR,JR,YR,QR),s=Ul(VR),c=Ul(UR),l=Ul(WR),u=Ul(GR),d=Ul(KR);R.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]=R.useState(!1),m=rw();if(r.type===`inactive`)return null;let h=r.rectangle,g=r.type===`preview`&&r.url.startsWith(`http`);return R.createElement(LO,{open:!0},R.createElement(jle,{"data-visible":r.type===`edit`,className:mw.linkDialogAnchor,style:{top:`${h.top}px`,left:`${h.left}px`,width:`${h.width}px`,height:`${h.height}px`}}),R.createElement(RO,{container:e?.current},R.createElement(Mle,{className:(0,rT.default)(mw.linkDialogPopoverContent),sideOffset:5,onOpenAutoFocus:e=>{e.preventDefault()},key:r.linkNodeKey},r.type===`edit`&&R.createElement(Mhe,{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`&&R.createElement(R.Fragment,null,R.createElement(`a`,{className:mw.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},R.createElement(`span`,null,r.url),g&&n(`open_in_new`)),R.createElement(zR,{onClick:()=>{u()},title:m(`linkPreview.edit`,`Edit link URL`),"aria-label":m(`linkPreview.edit`,`Edit link URL`)},n(`edit`)),R.createElement(ER,null,R.createElement(DR,{open:f},R.createElement(OR,{asChild:!0},R.createElement(zR,{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`))),R.createElement(kR,{container:e?.current},R.createElement(AR,{className:(0,rT.default)(mw.tooltipContent),sideOffset:5},m(`linkPreview.copied`,`Copied!`),R.createElement(whe,null))))),R.createElement(zR,{title:m(`linkPreview.remove`,`Remove link`),"aria-label":m(`linkPreview.remove`,`Remove link`),onClick:()=>{d()}},n(`link_off`))),R.createElement(zO,{className:mw.popoverArrow}))))},zR=R.forwardRef(({className:e,...t},n)=>R.createElement(`button`,{className:(0,rT.default)(mw.actionButton,e),ref:n,...t}));function BR(e){if(!e)return null;let t=qae(e);if(t===null)return null;let n=t.getParent();return _w(n)?n:_w(t)?t:null}var VR=Ll(),HR=Il({type:`inactive`},e=>{e.pub(LC,t=>t.registerCommand(gf,()=>e.getValue(HR).type===`preview`?(e.pub(HR,{type:`inactive`}),!0):!1,1)),e.sub(e.pipe(ZC),t=>{t!==`rich-text`&&e.pub(HR,{type:`inactive`})}),e.pub(LC,t=>t.registerCommand(of,t=>t.key===`k`&&(aT?t.metaKey:t.ctrlKey)&&!e.getValue(WS)&&W(G())?(e.pub(qR),t.stopPropagation(),t.preventDefault(),!0):!1,3)),e.sub(e.pipe(GR,Gl(HR,VS)),([,t,n])=>{if(t.type===`preview`)setTimeout(()=>{n?.getEditorState().read(()=>{let n=Ah(t.linkNodeKey),r=_w(n)?n.getTextContent().length>0&&n.getChildrenSize()<=1:!1,i=r&&n?n.getTextContent():``;e.pub(HR,{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(UR,Gl(VS,HR,QS)),([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=BR(i);if(!t){let t=gw(o,{title:s});t.append(Fp(e)),pm([t]),t.select()}else if(bw(t)){let e=gw(o,{title:s});e.append(Fp(a)),t.replace(e),e.select()}else t.setURL(o),t.setTitle(s),ZR(t.getFirstChild(),a)},{discrete:!0})}else n?.update(()=>{ZR(i?.anchor.getNode(),a)}),n?.dispatchCommand(xw,{url:o,title:s});e.pub(HR,{type:`preview`,linkNodeKey:r.linkNodeKey,rectangle:r.rectangle,title:s,url:o})}else r.type===`edit`&&r.initialUrl!==``&&n?.dispatchCommand(xw,null),e.pub(HR,{type:`inactive`})}),e.link(e.pipe(WR,Gl(HR,VS),Wl(([,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`)})),HR),e.link(e.pipe(e.combine(QS,VR),Gl(VS,HR,WS),Wl(([[e],t,n,r])=>{if(W(e)&&t&&!r){let n=BR(e);if(!e.isCollapsed())return{type:`inactive`};if(n){let e=nT(t);return e?{type:`preview`,url:n.getURL(),linkNodeKey:n.getKey(),title:n.getTitle(),rectangle:e}:{type:`inactive`}}else return{type:`inactive`}}else return{type:`inactive`}})),HR)}),UR=Ll(),WR=Rl();Rl();var GR=Rl(),KR=Rl(e=>{e.sub(e.pipe(KR,Gl(VS)),([,e])=>{e?.dispatchCommand(xw,null)})}),qR=Rl(e=>{e.sub(e.pipe(qR,Gl(QS,VS),Kl(([,e])=>W(e))),([,t,n])=>{n?.focus(()=>{setTimeout(()=>{n.getEditorState().read(()=>{let r=BR(t),i=nT(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(HR,{type:`edit`,initialUrl:a,url:o,title:s,text:u,withAnchorText:l,linkNodeKey:c,rectangle:i})})})})})}),JR=Il([]),YR=Il(null),XR=Il(null,e=>{e.pub(LC,t=>{function n(n){let[r,i]=e.getValues([WS,XR]);!r||i===null||t.update(()=>{let e=Nh(n.target);if(e!==null){let t=Z_(e,e=>e instanceof hw);t!==null&&i(n,t,t.getURL())}})}return t.registerRootListener((e,t)=>{e&&e.addEventListener(`click`,n),t&&t.removeEventListener(`click`,n)})})});function ZR(e,t){U(e)&&t&&(e.setTextContent(t),e.selectStart())}var QR=Il(!0),Phe=Xl({init(e,t){e.pub(BC,t?.LinkDialog??Nhe),e.pub(YR,t?.onClickLinkCallback??null),e.pub(XR,t?.onReadOnlyClickLinkCallback??null),e.pub(QR,t?.showLinkTitleField??!0)},update(e,t={}){e.pub(JR,t.linkAutocompleteSuggestions??[])}});function $R(e,t){return R.forwardRef((n,r)=>{let i=(0,rT.default)(t.className,n.className);return R.createElement(e,{...t,...n,className:i,ref:r})})}function Fhe(e){return({title:t,children:n,...r})=>R.createElement(e,{"aria-label":t,...r},R.createElement(jR,{title:t},n))}var Ihe=({readOnly:e,children:t,className:n})=>R.createElement(Wk,{className:(0,rT.default)(`mdxeditor-toolbar`,mw.toolbarRoot,{[mw.readOnlyToolbarRoot]:e},n),...e?{tabIndex:-1}:{}},t),ez=Fhe($R(Kk,{className:mw.toolbarButton,"data-toolbar-item":!0})),tz=$R(Jk,{className:mw.toolbarToggleItem,"data-toolbar-item":!0});$R(qk,{type:`single`,className:mw.toolbarToggleSingleGroup});var nz=R.forwardRef(({on:e,title:t,children:n,disabled:r,...i},a)=>R.createElement(qk,{type:`single`,className:mw.toolbarToggleSingleGroup,...i,value:e?`on`:`off`,ref:a},R.createElement(tz,{"aria-label":t,value:`on`,disabled:r},R.createElement(jR,{title:t},n)))),rz=({items:e})=>R.createElement(`div`,{className:mw.toolbarGroupOfGroups},e.map((e,t)=>R.createElement(nz,{key:t,title:e.title,on:e.active,onValueChange:t=>{e.onChange(t===`on`)},disabled:e.disabled},e.contents))),Lhe=({value:e,onChange:t,className:n,ggClassName:r,items:i,disabled:a})=>{let o=rw();return R.createElement(`div`,{className:(0,rT.default)(mw.toolbarGroupOfGroups,r)},R.createElement(qk,{"aria-label":o(`toolbar.toggleGroup`,`toggle group`),type:`single`,className:(0,rT.default)(mw.toolbarToggleSingleGroup,n),onValueChange:t,value:e||``,disabled:a,onFocus:e=>{e.preventDefault()}},i.map((e,t)=>R.createElement(tz,{key:t,"aria-label":e.title,value:e.value},R.createElement(jR,{title:e.title},e.contents)))))},iz=Il(()=>null),az=Il(``),oz=()=>"This is an empty toolbar. Pass `{toolbarContents: () => { return <>toolbar components</> }}` to the toolbarPlugin to customize it.",Rhe=Xl({init(e,t){let n=t?.toolbarPosition===`bottom`?mae:pae;e.pubIn({[iz]:t?.toolbarContents??oz,[az]:t?.toolbarClassName??``,[n]:()=>{let[e,t,n]=Hl(iz,WS,az);return R.createElement(Ihe,{className:n,readOnly:t},e())}})},update(e,t){e.pub(iz,t?.toolbarContents??oz),e.pub(az,t?.toolbarClassName??``)}});Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},Prism.languages.javascript=Prism.languages.extend(`clike`,{"class-name":[Prism.languages.clike[`class-name`],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(`(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])`),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),Prism.languages.javascript[`class-name`][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,Prism.languages.insertBefore(`javascript`,`keyword`,{regex:{pattern:RegExp(`((?:^|[^$\\w\\xA0-\\uFFFF."'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/)*(?:$|[\\r\\n,.;:})\\]]|\\/\\/))`),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:`language-regex`,inside:Prism.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:`function`},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore(`javascript`,`string`,{hashbang:{pattern:/^#!.*/,greedy:!0,alias:`comment`},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:`string`},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:`punctuation`},rest:Prism.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:`property`}}),Prism.languages.insertBefore(`javascript`,`operator`,{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:`property`}}),Prism.languages.markup&&(Prism.languages.markup.tag.addInlined(`script`,`javascript`),Prism.languages.markup.tag.addAttribute(`on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)`,`javascript`)),Prism.languages.js=Prism.languages.javascript,Prism.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:`attr-equals`},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:`named-entity`},/&#x?[\da-f]{1,8};/i]},Prism.languages.markup.tag.inside[`attr-value`].inside.entity=Prism.languages.markup.entity,Prism.languages.markup.doctype.inside[`internal-subset`].inside=Prism.languages.markup,Prism.hooks.add(`wrap`,function(e){e.type===`entity`&&(e.attributes.title=e.content.replace(/&/,`&`))}),Object.defineProperty(Prism.languages.markup.tag,`addInlined`,{value:function(e,t){var n={};n[`language-`+t]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:Prism.languages[t]},n.cdata=/^<!\[CDATA\[|\]\]>$/i;var r={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:n}};r[`language-`+t]={pattern:/[\s\S]+/,inside:Prism.languages[t]};var i={};i[e]={pattern:RegExp(`(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[\\s\\S])*?(?=<\\/__>)`.replace(/__/g,function(){return e}),`i`),lookbehind:!0,greedy:!0,inside:r},Prism.languages.insertBefore(`markup`,`cdata`,i)}}),Object.defineProperty(Prism.languages.markup.tag,`addAttribute`,{value:function(e,t){Prism.languages.markup.tag.inside[`special-attr`].push({pattern:RegExp(`(^|["'\\s])(?:`+e+`)\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s'">=]+(?=[\\s>]))`,`i`),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,`language-`+t],inside:Prism.languages[t]},punctuation:[{pattern:/^=/,alias:`attr-equals`},/"|'/]}}}})}}),Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup,Prism.languages.xml=Prism.languages.extend(`markup`,{}),Prism.languages.ssml=Prism.languages.xml,Prism.languages.atom=Prism.languages.xml,Prism.languages.rss=Prism.languages.xml,(function(e){var t=`(?:\\\\.|[^\\\\\\n\\r]|(?:\\n|\\r\\n?)(?![\\r\\n]))`;function n(e){return e=e.replace(/<inner>/g,function(){return t}),RegExp(`((?:^|[^\\\\])(?:\\\\{2})*)(?:`+e+`)`)}var r="(?:\\\\.|``(?:[^`\\r\\n]|`(?!`))+``|`[^`\\r\\n]+`|[^\\\\|\\r\\n`])+",i=`\\|?__(?:\\|__)+\\|?(?:(?:\\n|\\r\\n?)|(?![\\s\\S]))`.replace(/__/g,function(){return r}),a=`\\|?[ \\t]*:?-{3,}:?[ \\t]*(?:\\|[ \\t]*:?-{3,}:?[ \\t]*)+\\|?(?:\\n|\\r\\n?)`;e.languages.markdown=e.languages.extend(`markup`,{}),e.languages.insertBefore(`markdown`,`prolog`,{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"front-matter":{pattern:/\S+(?:\s+\S+)*/,alias:[`yaml`,`language-yaml`],inside:e.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:`punctuation`},table:{pattern:RegExp(`^`+i+a+`(?:`+i+`)*`,`m`),inside:{"table-data-rows":{pattern:RegExp(`^(`+i+a+`)(?:`+i+`)*$`),lookbehind:!0,inside:{"table-data":{pattern:RegExp(r),inside:e.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp(`^(`+i+`)`+a+`$`),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp(`^`+i+`$`),inside:{"table-header":{pattern:RegExp(r),alias:`important`,inside:e.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:`keyword`},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:`important`,inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:`important`,inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:`punctuation`},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:`punctuation`},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:`url`},bold:{pattern:n(`\\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\\b|\\*\\*(?:(?!\\*)<inner>|\\*(?:(?!\\*)<inner>)+\\*)+\\*\\*`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n(`\\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\\b|\\*(?:(?!\\*)<inner>|\\*\\*(?:(?!\\*)<inner>)+\\*\\*)+\\*`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n(`(~~?)(?:(?!~)<inner>)+\\2`),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},"code-snippet":{pattern:/(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,lookbehind:!0,greedy:!0,alias:[`code`,`keyword`]},url:{pattern:n(`!?\\[(?:(?!\\])<inner>)+\\](?:\\([^\\s)]+(?:[\\t ]+"(?:\\\\.|[^"\\\\])*")?\\)|[ \\t]?\\[(?:(?!\\])<inner>)+\\])`),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),[`url`,`bold`,`italic`,`strike`].forEach(function(t){[`url`,`bold`,`italic`,`strike`,`code-snippet`].forEach(function(n){t!==n&&(e.languages.markdown[t].inside.content.inside[n]=e.languages.markdown[n])})}),e.hooks.add(`after-tokenize`,function(e){if(e.language!==`markdown`&&e.language!==`md`)return;function t(e){if(!(!e||typeof e==`string`))for(var n=0,r=e.length;n<r;n++){var i=e[n];if(i.type!==`code`){t(i.content);continue}var a=i.content[1],o=i.content[3];if(a&&o&&a.type===`code-language`&&o.type===`code-block`&&typeof a.content==`string`){var s=a.content.replace(/\b#/g,`sharp`).replace(/\b\+\+/g,`pp`);s=(/[a-z][\w-]*/i.exec(s)||[``])[0].toLowerCase();var c=`language-`+s;o.alias?typeof o.alias==`string`?o.alias=[o.alias,c]:o.alias.push(c):o.alias=[c]}}}t(e.tokens)}),e.hooks.add(`wrap`,function(t){if(t.type===`code-block`){for(var n=``,r=0,i=t.classes.length;r<i;r++){var a=t.classes[r],o=/language-(.+)/.exec(a);if(o){n=o[1];break}}var s=e.languages[n];if(s)t.content=e.highlight(l(t.content),s,n);else if(n&&n!==`none`&&e.plugins.autoloader){var c=`md-`+new Date().valueOf()+`-`+Math.floor(Math.random()*0x2386f26fc10000);t.attributes.id=c,e.plugins.autoloader.loadLanguages(n,function(){var t=document.getElementById(c);t&&(t.innerHTML=e.highlight(t.textContent,e.languages[n],n))})}}});var o=RegExp(e.languages.markup.tag.pattern.source,`gi`),s={amp:`&`,lt:`<`,gt:`>`,quot:`"`},c=String.fromCodePoint||String.fromCharCode;function l(e){var t=e.replace(o,``);return t=t.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi,function(e,t){return t=t.toLowerCase(),t[0]===`#`?c(t[1]===`x`?parseInt(t.slice(2),16):Number(t.slice(1))):s[t]||e}),t}e.languages.md=e.languages.markdown})(Prism),Prism.languages.c=Prism.languages.extend(`clike`,{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,lookbehind:!0},keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,function:/\b[a-z_]\w*(?=\s*\()/i,number:/(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/}),Prism.languages.insertBefore(`c`,`string`,{char:{pattern:/'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,greedy:!0}}),Prism.languages.insertBefore(`c`,`string`,{macro:{pattern:/(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:`property`,inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},Prism.languages.c.string],char:Prism.languages.c.char,comment:Prism.languages.c.comment,"macro-name":[{pattern:/(^#\s*define\s+)\w+\b(?!\()/i,lookbehind:!0},{pattern:/(^#\s*define\s+)\w+\b(?=\()/i,lookbehind:!0,alias:`function`}],directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:`keyword`},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:Prism.languages.c}}}}),Prism.languages.insertBefore(`c`,`function`,{constant:/\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/}),delete Prism.languages.c.boolean,(function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp(`@[\\w-](?:[^;{\\s"']|\\s+(?!\\s)|`+t.source+`)*?(?:;|(?=\\s*\\{))`),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:`selector`},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp(`\\burl\\((?:`+t.source+`|(?:[^\\\\\\r\\n()"']|\\\\[\\s\\S])*)\\)`,`i`),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp(`^`+t.source+`$`),alias:`url`}}},selector:{pattern:RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|`+t.source+`)*(?=\\s*\\{)`),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined(`style`,`css`),n.tag.addAttribute(`style`,`css`))})(Prism),Prism.languages.objectivec=Prism.languages.extend(`c`,{string:{pattern:/@?"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},keyword:/\b(?:asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|in|inline|int|long|register|return|self|short|signed|sizeof|static|struct|super|switch|typedef|typeof|union|unsigned|void|volatile|while)\b|(?:@interface|@end|@implementation|@protocol|@class|@public|@protected|@private|@property|@try|@catch|@finally|@throw|@synthesize|@dynamic|@selector)\b/,operator:/-[->]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/@]/}),delete Prism.languages.objectivec[`class-name`],Prism.languages.objc=Prism.languages.objectivec,Prism.languages.sql={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,lookbehind:!0},variable:[{pattern:/@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,greedy:!0},/@[\w.$]+/],string:{pattern:/(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,greedy:!0,lookbehind:!0},identifier:{pattern:/(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,greedy:!0,lookbehind:!0,inside:{punctuation:/^`|`$/}},function:/\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i,keyword:/\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,boolean:/\b(?:FALSE|NULL|TRUE)\b/i,number:/\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,operator:/[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,punctuation:/[;[\]()`,.]/},(function(e){var t=e.languages.powershell={comment:[{pattern:/(^|[^`])<#[\s\S]*?#>/,lookbehind:!0},{pattern:/(^|[^`])#.*/,lookbehind:!0}],string:[{pattern:/"(?:`[\s\S]|[^`"])*"/,greedy:!0,inside:null},{pattern:/'(?:[^']|'')*'/,greedy:!0}],namespace:/\[[a-z](?:\[(?:\[[^\]]*\]|[^\[\]])*\]|[^\[\]])*\]/i,boolean:/\$(?:false|true)\b/i,variable:/\$\w+\b/,function:[/\b(?:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|ForEach|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Sort|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Tee|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Where|Write)-[a-z]+\b/i,/\b(?:ac|cat|chdir|clc|cli|clp|clv|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|ebp|echo|epal|epcsv|epsn|erase|fc|fl|ft|fw|gal|gbp|gc|gci|gcs|gdr|gi|gl|gm|gp|gps|group|gsv|gu|gv|gwmi|iex|ii|ipal|ipcsv|ipsn|irm|iwmi|iwr|kill|lp|ls|measure|mi|mount|move|mp|mv|nal|ndr|ni|nv|ogv|popd|ps|pushd|pwd|rbp|rd|rdr|ren|ri|rm|rmdir|rni|rnp|rp|rv|rvpa|rwmi|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spps|spsv|start|sv|swmi|tee|trcm|type|write)\b/i],keyword:/\b(?:Begin|Break|Catch|Class|Continue|Data|Define|Do|DynamicParam|Else|ElseIf|End|Exit|Filter|Finally|For|ForEach|From|Function|If|InlineScript|Parallel|Param|Process|Return|Sequence|Switch|Throw|Trap|Try|Until|Using|Var|While|Workflow)\b/i,operator:{pattern:/(^|\W)(?:!|-(?:b?(?:and|x?or)|as|(?:Not)?(?:Contains|In|Like|Match)|eq|ge|gt|is(?:Not)?|Join|le|lt|ne|not|Replace|sh[lr])\b|-[-=]?|\+[+=]?|[*\/%]=?)/i,lookbehind:!0},punctuation:/[|{}[\];(),.]/};t.string[0].inside={function:{pattern:/(^|[^`])\$\((?:\$\([^\r\n()]*\)|(?!\$\()[^\r\n)])*\)/,lookbehind:!0,inside:t},boolean:t.boolean,variable:t.variable}})(Prism),Prism.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern://,alias:`punctuation`},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:`string`},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:[`annotation`,`punctuation`],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},Prism.languages.python[`string-interpolation`].inside.interpolation.inside.rest=Prism.languages.python,Prism.languages.py=Prism.languages.python,(function(e){for(var t=`\\/\\*(?:[^*/]|\\*(?!\\/)|\\/(?!\\*)|<self>)*\\*\\/`,n=0;n<2;n++)t=t.replace(/<self>/g,function(){return t});t=t.replace(/<self>/g,function(){return`[^\\s\\S]`}),e.languages.rust={comment:[{pattern:RegExp(`(^|[^\\\\])`+t),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,greedy:!0},attribute:{pattern:/#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,greedy:!0,alias:`attr-name`,inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:`punctuation`},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:`symbol`},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:`punctuation`},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s+)\w+/,lookbehind:!0,alias:`function`},"type-definition":{pattern:/(\b(?:enum|struct|trait|type|union)\s+)\w+/,lookbehind:!0,alias:`class-name`},"module-declaration":[{pattern:/(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,lookbehind:!0,alias:`namespace`},{pattern:/(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,lookbehind:!0,alias:`namespace`,inside:{punctuation:/::/}}],keyword:[/\b(?:Self|abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,macro:{pattern:/\b\w+!/,alias:`property`},constant:/\b[A-Z_][A-Z_\d]+\b/,"class-name":/\b[A-Z]\w*\b/,namespace:{pattern:/(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,inside:{punctuation:/::/}},number:/\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/},e.languages.rust[`closure-params`].inside.rest=e.languages.rust,e.languages.rust.attribute.inside.string=e.languages.rust.string})(Prism),Prism.languages.swift={comment:{pattern:/(^|[^\\:])(?:\/\/.*|\/\*(?:[^/*]|\/(?!\*)|\*(?!\/)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\*\/)/,lookbehind:!0,greedy:!0},"string-literal":[{pattern:RegExp(`(^|[^"#])(?:"(?:\\\\(?:\\((?:[^()]|\\([^()]*\\))*\\)|\\r\\n|[^(])|[^\\\\\\r\\n"])*"|"""(?:\\\\(?:\\((?:[^()]|\\([^()]*\\))*\\)|[^(])|[^\\\\"]|"(?!""))*""")(?!["#])`),lookbehind:!0,greedy:!0,inside:{interpolation:{pattern:/(\\\()(?:[^()]|\([^()]*\))*(?=\))/,lookbehind:!0,inside:null},"interpolation-punctuation":{pattern:/^\)|\\\($/,alias:`punctuation`},punctuation:/\\(?=[\r\n])/,string:/[\s\S]+/}},{pattern:RegExp(`(^|[^"#])(#+)(?:"(?:\\\\(?:#+\\((?:[^()]|\\([^()]*\\))*\\)|\\r\\n|[^#])|[^\\\\\\r\\n])*?"|"""(?:\\\\(?:#+\\((?:[^()]|\\([^()]*\\))*\\)|[^#])|[^\\\\])*?""")\\2`),lookbehind:!0,greedy:!0,inside:{interpolation:{pattern:/(\\#+\()(?:[^()]|\([^()]*\))*(?=\))/,lookbehind:!0,inside:null},"interpolation-punctuation":{pattern:/^\)|\\#+\($/,alias:`punctuation`},string:/[\s\S]+/}}],directive:{pattern:RegExp(`#(?:(?:elseif|if)\\b(?:[ ]*(?:![ \\t]*)?(?:\\b\\w+\\b(?:[ \\t]*\\((?:[^()]|\\([^()]*\\))*\\))?|\\((?:[^()]|\\([^()]*\\))*\\))(?:[ \\t]*(?:&&|\\|\\|))?)+|(?:else|endif)\\b)`),alias:`property`,inside:{"directive-name":/^#\w+/,boolean:/\b(?:false|true)\b/,number:/\b\d+(?:\.\d+)*\b/,operator:/!|&&|\|\||[<>]=?/,punctuation:/[(),]/}},literal:{pattern:/#(?:colorLiteral|column|dsohandle|file(?:ID|Literal|Path)?|function|imageLiteral|line)\b/,alias:`constant`},"other-directive":{pattern:/#\w+\b/,alias:`property`},attribute:{pattern:/@\w+/,alias:`atrule`},"function-definition":{pattern:/(\bfunc\s+)\w+/,lookbehind:!0,alias:`function`},label:{pattern:/\b(break|continue)\s+\w+|\b[a-zA-Z_]\w*(?=\s*:\s*(?:for|repeat|while)\b)/,lookbehind:!0,alias:`important`},keyword:/\b(?:Any|Protocol|Self|Type|actor|as|assignment|associatedtype|associativity|async|await|break|case|catch|class|continue|convenience|default|defer|deinit|didSet|do|dynamic|else|enum|extension|fallthrough|fileprivate|final|for|func|get|guard|higherThan|if|import|in|indirect|infix|init|inout|internal|is|isolated|lazy|left|let|lowerThan|mutating|none|nonisolated|nonmutating|open|operator|optional|override|postfix|precedencegroup|prefix|private|protocol|public|repeat|required|rethrows|return|right|safe|self|set|some|static|struct|subscript|super|switch|throw|throws|try|typealias|unowned|unsafe|var|weak|where|while|willSet)\b/,boolean:/\b(?:false|true)\b/,nil:{pattern:/\bnil\b/,alias:`constant`},"short-argument":/\$\d+\b/,omit:{pattern:/\b_\b/,alias:`keyword`},number:/\b(?:[\d_]+(?:\.[\de_]+)?|0x[a-f0-9_]+(?:\.[a-f0-9p_]+)?|0b[01_]+|0o[0-7_]+)\b/i,"class-name":/\b[A-Z](?:[A-Z_\d]*[a-z]\w*)?\b/,function:/\b[a-z_]\w*(?=\s*\()/i,constant:/\b(?:[A-Z_]{2,}|k[A-Z][A-Za-z_]+)\b/,operator:/[-+*/%=!<>&|^~?]+|\.[.\-+*/%=!<>&|^~?]+/,punctuation:/[{}[\]();,.:\\]/},Prism.languages.swift[`string-literal`].forEach(function(e){e.inside.interpolation.inside=Prism.languages.swift}),(function(e){e.languages.typescript=e.languages.extend(`javascript`,{"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|type)\s+)(?!keyof\b)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?:\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)?/,lookbehind:!0,greedy:!0,inside:null},builtin:/\b(?:Array|Function|Promise|any|boolean|console|never|number|string|symbol|unknown)\b/}),e.languages.typescript.keyword.push(/\b(?:abstract|declare|is|keyof|readonly|require)\b/,/\b(?:asserts|infer|interface|module|namespace|type)\b(?=\s*(?:[{_$a-zA-Z\xA0-\uFFFF]|$))/,/\btype\b(?=\s*(?:[\{*]|$))/),delete e.languages.typescript.parameter,delete e.languages.typescript[`literal-property`];var t=e.languages.extend(`typescript`,{});delete t[`class-name`],e.languages.typescript[`class-name`].inside=t,e.languages.insertBefore(`typescript`,`function`,{decorator:{pattern:/@[$\w\xA0-\uFFFF]+/,inside:{at:{pattern:/^@/,alias:`operator`},function:/^[\s\S]+/}},"generic-function":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>(?=\s*\()/,greedy:!0,inside:{function:/^#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*/,generic:{pattern:/<[\s\S]+/,alias:`class-name`,inside:t}}}}),e.languages.ts=e.languages.typescript})(Prism),(function(e){var t=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,n=`(?:[a-z]\\w*\\s*\\.\\s*)*(?:[A-Z]\\w*\\s*\\.\\s*)*`,r={pattern:RegExp(`(^|[^\\w.])`+n+`[A-Z](?:[\\d_A-Z]*[a-z]\\w*)?\\b`),lookbehind:!0,inside:{namespace:{pattern:/^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,inside:{punctuation:/\./}},punctuation:/\./}};e.languages.java=e.languages.extend(`clike`,{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,lookbehind:!0,greedy:!0},"class-name":[r,{pattern:RegExp(`(^|[^\\w.])`+n+`[A-Z]\\w*(?=\\s+\\w+\\s*[;,=()]|\\s*(?:\\[[\\s,]*\\]\\s*)?::\\s*new\\b)`),lookbehind:!0,inside:r.inside},{pattern:RegExp(`(\\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\\s+)`+n+`[A-Z]\\w*\\b`),lookbehind:!0,inside:r.inside}],keyword:t,function:[e.languages.clike.function,{pattern:/(::\s*)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0},constant:/\b[A-Z][A-Z_\d]+\b/}),e.languages.insertBefore(`java`,`string`,{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:`string`},char:{pattern:/'(?:\\.|[^'\\\r\n]){1,6}'/,greedy:!0}}),e.languages.insertBefore(`java`,`class-name`,{annotation:{pattern:/(^|[^.])@\w+(?:\s*\.\s*\w+)*/,lookbehind:!0,alias:`punctuation`},generics:{pattern:/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,inside:{"class-name":r,keyword:t,punctuation:/[<>(),.:]/,operator:/[?&|]/}},import:[{pattern:RegExp(`(\\bimport\\s+)`+n+`(?:[A-Z]\\w*|\\*)(?=\\s*;)`),lookbehind:!0,inside:{namespace:r.inside.namespace,punctuation:/\./,operator:/\*/,"class-name":/\w+/}},{pattern:RegExp(`(\\bimport\\s+static\\s+)`+n+`(?:\\w+|\\*)(?=\\s*;)`),lookbehind:!0,alias:`static`,inside:{namespace:r.inside.namespace,static:/\b\w+$/,punctuation:/\./,operator:/\*/,"class-name":/\w+/}}],namespace:{pattern:RegExp(`(\\b(?:exports|import(?:\\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\\s+)(?!<keyword>)[a-z]\\w*(?:\\.[a-z]\\w*)*\\.?`.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0,inside:{punctuation:/\./}}})})(Prism),(function(e){var t=/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,n=`\\b(?!<keyword>)\\w+(?:\\s*\\.\\s*\\w+)*\\b`.replace(/<keyword>/g,function(){return t.source});e.languages.cpp=e.languages.extend(`c`,{"class-name":[{pattern:RegExp(`(\\b(?:class|concept|enum|struct|typename)\\s+)(?!<keyword>)\\w+`.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0},/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/],keyword:t,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,greedy:!0},operator:/>>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:false|true)\b/}),e.languages.insertBefore(`cpp`,`string`,{module:{pattern:RegExp(`(\\b(?:import|module)\\s+)(?:"(?:\\\\(?:\\r\\n|[\\s\\S])|[^"\\\\\\r\\n])*"|<[^<>\\r\\n]*>|`+`<mod-name>(?:\\s*:\\s*<mod-name>)?|:\\s*<mod-name>`.replace(/<mod-name>/g,function(){return n})+`)`),lookbehind:!0,greedy:!0,inside:{string:/^[<"][\s\S]+/,operator:/:/,punctuation:/\./}},"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:`string`,greedy:!0}}),e.languages.insertBefore(`cpp`,`keyword`,{"generic-function":{pattern:/\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,inside:{function:/^\w+/,generic:{pattern:/<[\s\S]+/,alias:`class-name`,inside:e.languages.cpp}}}}),e.languages.insertBefore(`cpp`,`operator`,{"double-colon":{pattern:/::/,alias:`punctuation`}}),e.languages.insertBefore(`cpp`,`class-name`,{"base-clause":{pattern:/(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,lookbehind:!0,greedy:!0,inside:e.languages.extend(`cpp`,{})}}),e.languages.insertBefore(`inside`,`double-colon`,{"class-name":/\b[a-z_]\w*\b(?!\s*::)/i},e.languages.cpp[`base-clause`])})(Prism);function sz(e,t){for(let n of e.childNodes){if(Cg(n)&&n.tagName===t)return!0;sz(n,t)}return!1}var cz=`data-language`,lz=`data-highlight-language`,uz=`data-theme`,dz=class e extends Hm{static getType(){return`code`}static clone(t){return new e(t.__language,t.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){let t=document.createElement(`code`);K_(t,e.theme.code),t.setAttribute(`spellcheck`,`false`);let n=this.getLanguage();n&&(t.setAttribute(cz,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(lz,n));let r=this.getTheme();r&&t.setAttribute(uz,r);let i=this.getStyle();return i&&t.setAttribute(`style`,i),t}updateDOM(e,t,n){let r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(cz,r):i&&t.removeAttribute(cz);let a=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?a&&r?r!==i&&t.setAttribute(lz,r):t.removeAttribute(lz):a&&r&&t.setAttribute(lz,r);let o=this.__theme,s=e.__theme;o?o!==s&&t.setAttribute(uz,o):s&&t.removeAttribute(uz);let c=this.__style,l=e.__style;return c?c!==l&&t.setAttribute(`style`,c):l&&t.removeAttribute(`style`),!1}exportDOM(e){let t=document.createElement(`pre`);K_(t,e._config.theme.code),t.setAttribute(`spellcheck`,`false`);let n=this.getLanguage();n&&(t.setAttribute(cz,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(lz,n));let r=this.getTheme();r&&t.setAttribute(uz,r);let i=this.getStyle();return i&&t.setAttribute(`style`,i),{element:t}}static importDOM(){return{code:e=>e.textContent!=null&&(/\r?\n/.test(e.textContent)||sz(e,`BR`))?{conversion:mz,priority:1}:null,div:()=>({conversion:zhe,priority:1}),pre:()=>({conversion:mz,priority:0}),table:e=>_z(e)?{conversion:Bhe,priority:3}:null,td:e=>{let t=e,n=t.closest(`table`);return t.classList.contains(`js-file-line`)||n&&_z(n)?{conversion:hz,priority:3}:null},tr:e=>{let t=e.closest(`table`);return t&&_z(t)?{conversion:hz,priority:3}:null}}}static importJSON(e){return fz().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){let n=this.getChildren(),r=n.length;if(r>=2&&n[r-1].getTextContent()===`
|
|
129
129
|
`&&n[r-2].getTextContent()===`
|
|
130
130
|
`&&e.isCollapsed()&&e.anchor.key===this.__key&&e.anchor.offset===r){n[r-1].remove(),n[r-2].remove();let e=nh();return this.insertAfter(e,t),e}let{anchor:i,focus:a}=e,o=(i.isBefore(a)?i:a).getNode();if(U(o)){let e=Hhe(o),t=[];for(;;)if(zp(e))t.push(Rp()),e=e.getNextSibling();else{if(!xz(e))break;{let n=0,r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&r[n]===` `;)n++;if(n!==0&&t.push(bz(` `.repeat(n))),n!==i)break;e=e.getNextSibling()}}let n=o.splitText(i.offset)[0],r=i.offset===0?0:1,a=n.getIndexWithinParent()+r,s=o.getParentOrThrow(),c=[_p(),...t];s.splice(a,0,c);let l=t[t.length-1];l?l.select():i.offset===0?n.selectPrevious():n.getNextSibling().selectNext(0,0)}if(pz(o)){let{offset:t}=e.anchor;o.splice(t,0,[_p()]),o.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){let e=nh();return this.getChildren().forEach((t=>e.append(t))),this.replace(e),!0}setLanguage(e){let t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){let t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){let t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}};function fz(e,t){return Rg(dz).setLanguage(e).setTheme(t)}function pz(e){return e instanceof dz}function mz(e){return{node:fz(e.getAttribute(cz))}}function zhe(e){let t=e,n=gz(t);return n||function(e){let t=e.parentElement;for(;t!==null;){if(gz(t))return!0;t=t.parentElement}return!1}(t)?{node:n?fz():null}:{node:null}}function Bhe(){return{node:fz()}}function hz(){return{node:null}}function gz(e){return e.style.fontFamily.match(`monospace`)!==null}function _z(e){return e.classList.contains(`js-file-line-container`)}var vz=class e extends Ep{constructor(e=``,t,n){super(e,n),this.__highlightType=t}static getType(){return`code-highlight`}static clone(t){return new e(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){let t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){let t=super.createDOM(e);return K_(t,yz(e.theme,this.__highlightType)),t}updateDOM(e,t,n){let r=super.updateDOM(e,t,n),i=yz(n.theme,e.__highlightType),a=yz(n.theme,this.__highlightType);return i!==a&&(i&&q_(t,i),a&&K_(t,a)),r}static importJSON(e){return bz().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return fz()}};function yz(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function bz(e=``,t){return hg(new vz(e,t))}function xz(e){return e instanceof vz}function Vhe(e,t){let n=e;for(let r=Xg(e,t);r&&(xz(r.origin)||zp(r.origin));r=J_(r))n=r.origin;return n}function Hhe(e){return Vhe(e,`previous`)}(function(e){e.languages.diff={coord:[/^(?:\*{3}|-{3}|\+{3}).*$/m,/^@@.*@@$/m,/^\d.*$/m]};var t={"deleted-sign":`-`,"deleted-arrow":`<`,"inserted-sign":`+`,"inserted-arrow":`>`,unchanged:` `,diff:`!`};Object.keys(t).forEach((function(n){var r=t[n],i=[];/^\w+$/.test(n)||i.push(/\w+/.exec(n)[0]),n===`diff`&&i.push(`bold`),e.languages.diff[n]={pattern:RegExp(`^(?:[`+r+`].*(?:\r
|
|
@@ -159,7 +159,8 @@ Error generating stack: `+e.message+`
|
|
|
159
159
|
M${w.x},${w.y}h${w.width}v${w.height}h${-w.width}z`,fillRule:`evenodd`,pointerEvents:`none`})]})})}A$.displayName=`MiniMap`;var MEe=(0,R.memo)(A$),NEe=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,PEe={[ZZ.Line]:`right`,[ZZ.Handle]:`bottom-right`};function FEe({nodeId:e,position:t,variant:n=ZZ.Handle,className:r,style:i=void 0,children:a,color:o,minWidth:s=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:d=!1,resizeDirection:f,autoScale:p=!0,shouldResize:m,onResizeStart:h,onResize:g,onResizeEnd:_}){let v=GQ(),y=typeof e==`string`?e:v,b=dQ(),x=(0,R.useRef)(null),S=n===ZZ.Handle,C=uQ((0,R.useCallback)(NEe(S&&p),[S,p]),sQ),w=(0,R.useRef)(null),T=t??PEe[n];return(0,R.useEffect)(()=>{if(!(!x.current||!y))return w.current||=vwe({domNode:x.current,nodeId:y,getStoreItems:()=>{let{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,domNode:a}=b.getState();return{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,paneDomNode:a}},onChange:(e,t)=>{let{triggerNodeChanges:n,nodeLookup:r,parentLookup:i,nodeOrigin:a}=b.getState(),o=[],s={x:e.x,y:e.y},c=r.get(y);if(c&&c.expandParent&&c.parentId){let t=c.origin??a,n=e.width??c.measured.width??0,l=e.height??c.measured.height??0,u=PZ([{id:c.id,parentId:c.parentId,rect:{width:n,height:l,...rZ({x:e.x??c.position.x,y:e.y??c.position.y},{width:n,height:l},c.parentId,r,t)}}],r,i,a);o.push(...u),s.x=e.x?Math.max(t[0]*n,e.x):void 0,s.y=e.y?Math.max(t[1]*l,e.y):void 0}if(s.x!==void 0&&s.y!==void 0){let e={id:y,type:`position`,position:{...s}};o.push(e)}if(e.width!==void 0&&e.height!==void 0){let t={id:y,type:`dimensions`,resizing:!0,setAttributes:f?f===`horizontal`?`width`:`height`:!0,dimensions:{width:e.width,height:e.height}};o.push(t)}for(let e of t){let t={...e,type:`position`};o.push(t)}n(o)},onEnd:({width:e,height:t})=>{let n={id:y,type:`dimensions`,resizing:!1,dimensions:{width:e,height:t}};b.getState().triggerNodeChanges([n])}}),w.current.update({controlPosition:T,boundaries:{minWidth:s,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:d,resizeDirection:f,onResizeStart:h,onResize:g,onResizeEnd:_,shouldResize:m}),()=>{w.current?.destroy()}},[T,s,c,l,u,d,h,g,_,m]),(0,z.jsx)(`div`,{className:dJ([`react-flow__resize-control`,`nodrag`,...T.split(`-`),n,r]),ref:x,style:{...i,scale:C,...o&&{[S?`backgroundColor`:`borderColor`]:o}},children:a})}(0,R.memo)(FEe);var j$={x:80,y:80},M$=260,N$=150;function P$(e,t){let n=I$(e),r=Object.entries(n),i=V$(e),a=new Set(r.map(([e])=>e)),o=0;return{nodes:r.map(([n,a],s)=>{let c=i[n]??REe(a),l=c??zEe(s,r.length);return c||(o+=1),{id:n,type:`workflowNode`,position:l,data:{nodeId:n,label:B$(n,a),kind:z$(a),validationCount:GEe(t,n),isInitial:q$(e).includes(n)}}}),edges:Object.entries(L$(e)).flatMap(([e,t])=>{let n=J$(t.from),r=J$(t.to);if(!n||!r||!a.has(n)||!a.has(r))return[];let i=typeof t.kind==`string`?t.kind:`data`;return[{id:e,source:n,target:r,type:`smoothstep`,label:i,data:{edgeId:e,kind:i},markerEnd:{type:wX.ArrowClosed,color:`#38bdf8`},style:{stroke:`#38bdf8`,strokeWidth:1.5}}]}),usedAutoLayout:o>0,missingPositionCount:o}}function IEe(e,t){return t.type===`node`?e.nodes.some(e=>e.id===t.id):e.edges.some(e=>e.id===t.id)}function F$(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function I$(e){return R$(e.nodes)}function L$(e){return R$(e.edges)}function R$(e){if(!F$(e))return{};let t={};for(let[n,r]of Object.entries(e))F$(r)&&(t[n]=r);return t}function z$(e){return typeof e.kind==`string`?e.kind:`node`}function B$(e,t){return typeof t.label==`string`&&t.label.trim()?t.label.trim():`${LEe(z$(t))} ${e}`}function LEe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function V$(e){let t=F$(e.ui)?e.ui:void 0,n=t&&F$(t.positions)?t.positions:void 0;if(!n)return{};let r={};for(let[e,t]of Object.entries(n)){let n=H$(t);n&&(r[e]=n)}return r}function REe(e){let t=F$(e.ui)?e.ui:void 0;return t?H$(t.position):void 0}function H$(e){if(!F$(e))return;let{x:t,y:n}=e;return typeof t==`number`&&Number.isFinite(t)&&typeof n==`number`&&Number.isFinite(n)?{x:t,y:n}:void 0}function zEe(e,t){if(t<=0)return j$;let n=Math.max(1,Math.ceil(Math.sqrt(t)));return{x:j$.x+e%n*M$,y:j$.y+Math.floor(e/n)*N$}}function U$(e){return e.length?{x:j$.x+e.length%3*M$,y:j$.y+Math.floor(e.length/3)*N$}:j$}function W$(e,t){let n=I$(e);if(!Object.hasOwn(n,t))return t;let r=2;for(;Object.hasOwn(n,`${t}_${r}`);)r+=1;return`${t}_${r}`}function BEe(e,t,n){let r=L$(e),i=`edge_${t}_to_${n}`.replace(/[^a-zA-Z0-9_-]/g,`-`);if(!Object.hasOwn(r,i))return i;let a=2;for(;Object.hasOwn(r,`${i}_${a}`);)a+=1;return`${i}_${a}`}function G$(e,t,n,r){let i=I$(e),a={...e,nodes:{...i,[t]:r},edges:F$(e.edges)?e.edges:{}};return q$(a).length||(a.initial=t),K$(a,{...V$(e),[t]:n})}function VEe(e,t,n,r){return{...e,edges:{...L$(e),[t]:{id:t,from:{nodeId:n},to:{nodeId:r},kind:`data`}}}}function HEe(e,t){let n=I$(e);delete n[t];let r=Object.fromEntries(Object.entries(L$(e)).filter(([,e])=>J$(e.from)!==t&&J$(e.to)!==t)),i=V$(e);return delete i[t],WEe(K$({...e,nodes:n,edges:r},i),t,Object.keys(n))}function UEe(e,t){let n=L$(e);return delete n[t],{...e,edges:n}}function WEe(e,t,n){let r={...e};if(typeof r.initial==`string`)return r.initial===t&&(n[0]?r.initial=n[0]:delete r.initial),r;if(Array.isArray(r.initial)){let e=r.initial.filter(e=>e!==t);e.length?r.initial=e:n[0]?r.initial=n[0]:delete r.initial}return r}function K$(e,t){let n=F$(e.ui)?e.ui:{};return{...e,ui:{...n,layout:`manual`,positions:t}}}function q$(e){return typeof e.initial==`string`?[e.initial]:Array.isArray(e.initial)?e.initial.filter(e=>typeof e==`string`):[]}function GEe(e,t){return e.filter(e=>e.nodeId===t||e.path?.startsWith(`$.nodes.${t}`)).length}function J$(e){return F$(e)&&typeof e.nodeId==`string`&&e.nodeId.trim()?e.nodeId.trim():void 0}var Y$={type:`object`,properties:{},required:[],additionalProperties:!1},X$=[`global`,`local`,`edge`],KEe=[`draft`,`notes`,`result`],qEe=[`payload`,`previous`,`resume`],JEe=[`global`,`local`];function YEe(e,t){return Z$(e.state,t.stateAccess)}function Z$(e,t){let n=Q$(e);return JSON.stringify({reads:n.reads,writes:n.writes})!==JSON.stringify({reads:t.reads,writes:t.writes})}function Q$(e){let t=F$(e)?e:{},n=$$(t.reads),r=$$(t.writes),i=r1(n[0]),a=r1(r[0]);return{reads:n,writes:r,readScope:i?.scope??`global`,readPath:i?.path??``,writeScope:a?.scope===`edge`?`global`:a?.scope??`global`,writePath:a?.scope===`edge`?``:a?.path??``}}function $$(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!r1(e)):[]}function e1(e,t){let n=F$(e.state)?{...e.state}:{};t.reads.length?n.reads=[...t.reads]:delete n.reads,t.writes.length?n.writes=[...t.writes]:delete n.writes,Object.keys(n).length?e.state=n:delete e.state}function t1(e,t,n){let r=n.flatMap(e=>{let n=r1(e);return n?.scope===t?[n.path]:[]}),i=t===`global`?n1(e):t===`local`?KEe:qEe;return[...new Set([...i,...r])].sort()}function n1(e){let t=F$(e.state)?e.state:void 0,n=t&&F$(t.global)?t.global:void 0;return n?Object.keys(n).sort():[]}function XEe(e){return e.trim().replace(/\s+/g,``).replace(/^\.+/,``).replace(/\.+$/,``).replace(/\.{2,}/g,`.`)}function r1(e){if(!e)return;let t=e.indexOf(`.`);if(t<=0||t===e.length-1)return;let n=e.slice(0,t),r=e.slice(t+1);if(X$.includes(n)&&!r.split(`.`).some(e=>!e))return{scope:n,path:r}}function i1(e){let t=typeof e.workflowId==`string`?e.workflowId:``,n=typeof e.workflowVersion==`string`?e.workflowVersion:``;return{label:typeof e.label==`string`?e.label:``,description:typeof e.description==`string`?e.description:``,inputKind:c1(e.input),inputDescription:l1(e.input),inputSchemaText:u1(e.input),outputKind:c1(e.output),outputDescription:l1(e.output),outputSchemaText:u1(e.output),stateAccess:Q$(e.state),profileId:$Ee(e.profile),promptTemplate:typeof e.promptTemplate==`string`?e.promptTemplate:``,handlerId:typeof e.handler==`string`?e.handler:``,adapterRef:eDe(e.handler),adapterParamsText:y1(tDe(e.handler)),workflowVersionKey:t&&n?cDe(t,n):``,humanPrompt:typeof e.prompt==`string`?e.prompt:``,humanSchemaText:e.schema===void 0?``:d1(e.schema),humanActionRefs:nDe(e.actions),humanTimeoutKind:aDe(e.timeout),humanTimeoutValue:oDe(e.timeout)}}function ZEe(e,t,n){let r=I$(e),i=r[t];if(!i)return e;let a=z$(i),o={...i};if(x1(o,`label`,n.label),x1(o,`description`,n.description),m1(o,`input`,n.inputKind,n.inputDescription,i.input,n.inputSchemaText),m1(o,`output`,n.outputKind,n.outputDescription,i.output,n.outputSchemaText),e1(o,n.stateAccess),a===`agent`&&(o.runtime=`pibo`,n.profileId.trim()&&(o.profile={kind:`fixed`,id:n.profileId.trim()}),x1(o,`promptTemplate`,n.promptTemplate),n.promptTemplate.trim()&&delete o.promptBuilder),a===`code`&&(o.language=`typescript`,n.handlerId.trim()&&(o.handler=n.handlerId.trim())),a===`adapter`&&(o.mode=`deterministic`,n.adapterRef.trim())){let e=g1(n.adapterRef.trim());b1(e,n.adapterParamsText),o.handler=e}if(a===`workflow`){let e=lDe(n.workflowVersionKey);e&&(o.workflowId=e.workflowId,o.workflowVersion=e.workflowVersion)}return a===`human`&&(x1(o,`prompt`,n.humanPrompt),n.humanSchemaText.trim()?o.schema=f1(n.humanSchemaText):delete o.schema,iDe(o,n.humanActionRefs),sDe(o,n.humanTimeoutKind,n.humanTimeoutValue)),{...e,nodes:{...r,[t]:o}}}function a1(e,t){let n=F$(e.from)?e.from:{},r=F$(e.to)?e.to:{},i=F$(e.guard)?e.guard:void 0,a=F$(e.adapter)?e.adapter:void 0,o=a&&F$(a.transform)?a.transform:void 0,s=typeof e.kind==`string`&&[`data`,`control`,`error`,`resume`].includes(e.kind)?e.kind:`data`;return{sourceNodeId:typeof n.nodeId==`string`?n.nodeId:t[0]??``,sourcePortId:typeof n.portId==`string`?n.portId:``,targetNodeId:typeof r.nodeId==`string`?r.nodeId:t.find(e=>e!==(n.nodeId??t[0]))??``,targetPortId:typeof r.portId==`string`?r.portId:``,kind:s,guardHandler:i&&typeof i.handler==`string`?i.handler:``,guardPriority:i&&typeof i.priority==`number`?String(i.priority):``,guardParamsText:y1(i?.params),adapterRef:o&&typeof o.id==`string`?o.id:``,adapterParamsText:y1(o?.params),stateAccess:Q$(e.state)}}function QEe(e,t,n){let r=L$(e),i=r[t];if(!i)return e;let a={...i,id:t,from:h1(n.sourceNodeId,n.sourcePortId),to:h1(n.targetNodeId,n.targetPortId),kind:n.kind},o=n.guardHandler.trim();if(o){let e=Number.parseInt(n.guardPriority,10),t={handler:o,...Number.isInteger(e)&&e>=0?{priority:e}:{}};b1(t,n.guardParamsText),a.guard=t}else delete a.guard;e1(a,n.stateAccess);let s=n.adapterRef.trim();if(s){let e=F$(i.adapter)?i.adapter:{},t=g1(s);b1(t,n.adapterParamsText),a.adapter={...e,kind:`edgeAdapter`,output:F$(e.output)?e.output:p1(`text`,``,void 0),transform:t}}else delete a.adapter;return{...e,edges:{...r,[t]:a}}}function o1(e){return JSON.parse(JSON.stringify(e))}function s1(e,t){return F$(e)?e.kind===`json`?`json`:`text`:t}function c1(e){return F$(e)?s1(e,`text`):`none`}function l1(e){return F$(e)&&typeof e.description==`string`?e.description:``}function u1(e){return d1(F$(e)&&e.schema!==void 0?e.schema:Y$)}function d1(e){try{return JSON.stringify(e??Y$,null,2)??JSON.stringify(Y$,null,2)}catch{return JSON.stringify(Y$,null,2)}}function f1(e){let t=e.trim();if(!t)return o1(Y$);try{return JSON.parse(t)}catch{return e}}function p1(e,t,n,r){let i={kind:e};return x1(i,`description`,t),e===`json`&&(i.schema=f1(r??u1(n))),i}function m1(e,t,n,r,i,a){if(n===`none`){delete e[t];return}e[t]=p1(n,r,i,a)}function h1(e,t){let n={nodeId:e};return x1(n,`portId`,t),n}function $Ee(e){return F$(e)&&e.kind===`fixed`&&typeof e.id==`string`?e.id:``}function eDe(e){return F$(e)&&e.kind===`adapter`&&e.language===`typescript`&&typeof e.id==`string`?e.id:``}function tDe(e){return F$(e)&&e.kind===`adapter`&&e.language===`typescript`?e.params:void 0}function g1(e){return{kind:`adapter`,language:`typescript`,id:e}}function nDe(e){return Array.isArray(e)?e.flatMap(e=>!F$(e)||typeof e.id!=`string`||!e.id.trim()?[]:[_1(e.id,typeof e.kind==`string`?e.kind:void 0)]):[]}function _1(e,t){return t?{id:e,kind:t}:{id:e}}function v1(e){return e.kind?{id:e.id,kind:e.kind}:{id:e.id}}function rDe(e,t,n){return n?e.some(e=>e.id===t.id)?e:[...e,_1(t.id,t.kind)]:e.filter(e=>e.id!==t.id)}function iDe(e,t){if(!t.length){delete e.actions;return}e.actions=t.map(v1)}function aDe(e){return!F$(e)||typeof e.kind!=`string`?`none`:[`milliseconds`,`seconds`,`minutes`,`iso8601`].includes(e.kind)?e.kind:`none`}function oDe(e){return F$(e)&&(typeof e.value==`number`||typeof e.value==`string`)?String(e.value):``}function sDe(e,t,n){let r=n.trim();if(t===`none`||!r){delete e.timeout;return}if(t===`iso8601`){e.timeout={kind:t,value:r};return}let i=Number(r);Number.isFinite(i)&&i>0?e.timeout={kind:t,value:i}:delete e.timeout}function y1(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)??``}catch{return``}}function b1(e,t){let n=t.trim();if(!n){delete e.params;return}try{e.params=JSON.parse(n)}catch{e.params=n}}function x1(e,t,n){let r=n.trim();r?e[t]=r:delete e[t]}function cDe(e,t){return`${e}@${t}`}function lDe(e){let t=e.indexOf(`@`);if(!(t<=0||t===e.length-1))return{workflowId:e.slice(0,t),workflowVersion:e.slice(t+1)}}var S1=`Use the workflow input to produce a concise answer.
|
|
160
160
|
|
|
161
161
|
{{input}}`;function uDe(e,t,n,r){return G$(e,t,n,mDe(t,r))}function dDe(e,t,n,r){return G$(e,t,n,hDe(t,r))}function fDe(e,t,n,r){return G$(e,t,n,C1(t,r))}function pDe(e,t,n,r){return G$(e,t,n,gDe(t,r))}function mDe(e,t){return{kind:`agent`,runtime:`pibo`,label:`Agent ${e}`,profile:{kind:`fixed`,id:t||`base`},promptTemplate:S1,metadata:{sessionOverrides:{prompt:!0}}}}function hDe(e,t){return{kind:`workflow`,label:`Workflow ${e}`,workflowId:t.id,workflowVersion:t.version}}function C1(e,t,n,r){return{kind:`adapter`,label:`Adapter ${e}`,mode:`deterministic`,handler:g1(t),input:o1(n??p1(`text`,``,void 0)),output:o1(r??p1(`text`,``,void 0))}}function gDe(e,t){return{kind:`human`,label:`Human ${e}`,prompt:`Review the workflow context and choose an available action.`,input:p1(`text`,`Context for human review.`,void 0),output:p1(`json`,`Human action result.`,void 0,d1(Y$)),schema:o1(Y$),actions:[v1(t)],timeout:{kind:`minutes`,value:60}}}var _De=`v2-starter-draft`;function w1(e,t){return`${e}@${t}`}function T1(e){let t=e.lastIndexOf(`@`);if(!(t<=0||t===e.length-1))return{workflowId:e.slice(0,t),workflowVersion:e.slice(t+1)}}function E1(e,t){return`/apps/chat/workflows/view/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function vDe(e){return`/apps/chat/workflows/drafts/${encodeURIComponent(e)}`}function D1(e){typeof window>`u`||window.location.assign(e)}function O1(e){return e.source===`custom`?`${e.displayName} (custom)`:`${e.displayName} (global)`}function k1(e){return`${e.displayName} (${e.id})`}function A1(e){return`${e.displayName} (${e.id})`}function yDe(e){return`${e.displayName}${e.kind?` · ${e.kind}`:``} (${e.id})`}function j1(e){return w1(e.id,e.version)}function M1(e){return`${e.title} (${j1(e)})`}function N1({diagnostics:e,emptyLabel:t}){return e.length?(0,z.jsx)(`div`,{className:`grid gap-2`,"aria-label":`Inspector diagnostics`,children:e.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-2 text-[11px] leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:12}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),e.path?(0,z.jsx)(`div`,{className:`mt-1 font-mono text-amber-200/80`,children:e.path}):null,e.hint?(0,z.jsx)(`div`,{className:`mt-1 text-amber-200/80`,children:e.hint}):null]},`${e.code}:${e.path??e.nodeId??e.edgeId??e.registryRef??e.message}`))}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-2 text-[11px] text-slate-500`,children:t})}function P1({label:e}){return(0,z.jsx)(`span`,{className:`rounded-full border border-slate-700 bg-[#101d22] px-2 py-0.5 text-slate-400`,children:e})}function F1({diagnostics:e}){return e.length?(0,z.jsx)(`div`,{className:`grid gap-2`,"aria-label":`Inspector picker diagnostics`,children:e.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-2 text-[11px] leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:12}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-amber-200/80`,children:e.path}),(0,z.jsx)(`div`,{className:`mt-1 text-amber-200/80`,children:e.hint})]},`${e.code}:${e.registryRef}`))}):null}function I1({option:e,badge:t}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`font-semibold text-slate-200`,children:e.displayName}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:e.id})]}),(0,z.jsx)(P1,{label:t})]}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,e.paramsSchema?(0,z.jsx)(`div`,{className:`mt-3`,children:(0,z.jsx)(L1,{label:`paramsSchema`,schema:e.paramsSchema})}):null]})}function L1({label:e,schema:t}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-slate-500`,children:e}),(0,z.jsx)(`pre`,{className:`mt-1 max-h-24 overflow-auto whitespace-pre-wrap font-mono text-[11px] leading-5 text-slate-300`,children:bDe(t)})]})}function bDe(e){return e?JSON.stringify(e,null,2):`null`}function xDe({workflowId:e,workflowVersion:t}){let[n,r]=(0,R.useState)(),[i,a]=(0,R.useState)(`loading`),[o,s]=(0,R.useState)();(0,R.useEffect)(()=>{let n=!1;return a(`loading`),s(void 0),lJ({selectedWorkflowId:e,selectedWorkflowVersion:t}).then(e=>{n||(r(e),a(`loaded`))}).catch(e=>{n||(s(e instanceof Error?e.message:`Failed to load workflow viewer`),a(`error`))}),()=>{n=!0}},[e,t]);let c=(0,R.useMemo)(()=>n?.options.find(e=>e.id===n.selectedWorkflowId&&e.version===n.selectedWorkflowVersion),[n]);return i===`loading`?(0,z.jsxs)(`div`,{className:`flex w-full items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4 text-sm text-slate-300`,"aria-live":`polite`,children:[(0,z.jsx)(Cs,{size:16,className:`animate-spin text-[#11a4d4]`}),`Loading workflow viewer `,e,`@`,t,`…`]}):i===`error`?(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-4 text-sm leading-6 text-red-200`,role:`alert`,children:[(0,z.jsx)(`div`,{className:`font-bold`,children:`Could not load workflow viewer`}),(0,z.jsx)(`div`,{className:`mt-1 text-xs`,children:o??`Failed to load workflow metadata.`})]}):(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(rs,{size:13}),`Workflow version viewer`]}),(0,z.jsx)(`h3`,{className:`mt-1 text-lg font-bold text-slate-100`,children:c?.title??`${e}@${t}`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-500`,children:`This separate viewer is the nested workflow navigation target. Parent graphs do not inline-expand nested workflow internals in V2.`})]}),(0,z.jsx)(`a`,{className:`shrink-0 rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,href:`/apps/chat/workflows`,children:`Back to Workflows`})]}),c?(0,z.jsx)(R1,{option:c}):null,(0,z.jsx)(z1,{diagnostics:n?.diagnostics??[],ariaLabel:`Workflow viewer diagnostics`}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Viewer mode shows registry metadata and navigation context only. To change a child workflow, open its own UI draft or duplicate/edit a published workflow from the Workflow Library.`})]})}function R1({option:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:[(0,z.jsxs)(`div`,{className:`font-semibold text-slate-200`,children:[`Selected workflow: `,e.title]}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:[e.id,`@`,e.version]}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,(0,z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${e.source} source`}),(0,z.jsx)(P1,{label:e.status}),e.tags.map(e=>(0,z.jsx)(P1,{label:e},e))]})]})}function SDe({option:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`font-semibold text-slate-200`,children:e.title}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:[e.id,`@`,e.version]})]}),(0,z.jsx)(P1,{label:`published workflow`})]}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,(0,z.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${e.source} source`}),e.tags.map(e=>(0,z.jsx)(P1,{label:e},e))]})]})}function z1({diagnostics:e,ariaLabel:t}){return e.length?(0,z.jsx)(`div`,{className:`grid gap-2`,"aria-label":t,children:e.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:13}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-amber-200/80`,children:e.path}),(0,z.jsx)(`div`,{className:`mt-1 text-amber-200/80`,children:e.hint})]},`${e.code}:${e.registryRef}`))}):null}function CDe(){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(wDe,{}),(0,z.jsx)(TDe,{}),(0,z.jsx)(EDe,{}),(0,z.jsx)(DDe,{})]})}function wDe(){let[e,t]=(0,R.useState)(ODe),[n,r]=(0,R.useState)(S1),[i,a]=(0,R.useState)(),[o,s]=(0,R.useState)(`loading`),[c,l]=(0,R.useState)();(0,R.useEffect)(()=>{let t=!1;return s(`loading`),l(void 0),iJ(e||void 0).then(e=>{t||(a(e),s(`loaded`))}).catch(e=>{t||(l(e instanceof Error?e.message:`Failed to load workflow profile picker`),s(`error`))}),()=>{t=!0}},[e]);let u=(0,R.useMemo)(()=>i?.options.find(e=>e.id===i.selectedProfileId),[i]),d=i?.diagnostics??[];return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(Po,{size:13}),`Agent node editor`]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:`Select a non-archived Agent Designer profile and edit the direct prompt template stored on the Pibo Workflow IR node.`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 px-2 py-1 text-[11px] font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void MDe(e,a,s,l),disabled:o===`loading`,children:[o===`loading`?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ls,{size:12}),`Refresh`]})]}),(0,z.jsxs)(`label`,{className:`grid gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Agent Designer profile`}),(0,z.jsxs)(`select`,{"aria-label":`Agent Designer profile`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-3 py-2 text-sm text-slate-100 outline-none transition focus:border-[#11a4d4] disabled:opacity-60`,value:i?.selectedProfileId??``,onChange:e=>t(e.target.value),disabled:o===`loading`||o===`error`,children:[(0,z.jsx)(`option`,{value:``,children:`Select a non-archived profile`}),i?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:O1(e)},e.id))]})]}),o===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:c??`Failed to load workflow profile picker.`}):null,u?(0,z.jsx)(IDe,{option:u}):null,d.length?(0,z.jsx)(`div`,{className:`grid gap-2`,"aria-label":`Agent profile diagnostics`,children:d.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:13}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),(0,z.jsx)(`div`,{className:`mt-1 text-amber-200/80`,children:e.hint})]},`${e.code}:${e.registryRef}`))}):null,(0,z.jsxs)(`label`,{className:`grid gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Prompt template`}),(0,z.jsx)(`textarea`,{"aria-label":`Agent prompt template`,className:`min-h-28 resize-y rounded-sm border border-slate-700 bg-[#151f24] px-3 py-2 font-mono text-xs leading-5 text-slate-100 outline-none transition focus:border-[#11a4d4]`,value:n,onChange:e=>r(e.target.value)}),(0,z.jsxs)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:[`This editor is enabled for Agent nodes with a direct `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`promptTemplate`}),`. Nodes backed by registered prompt builders remain registry-controlled.`]})]}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Archived profiles are intentionally omitted from the picker. If a loaded draft already references one, the API returns a structured diagnostic and keeps the selection empty.`})]})}function TDe(){let[e,t]=(0,R.useState)(kDe),[n,r]=(0,R.useState)(),[i,a]=(0,R.useState)(`loading`),[o,s]=(0,R.useState)();(0,R.useEffect)(()=>{let t=!1;return a(`loading`),s(void 0),aJ(e||void 0).then(e=>{t||(r(e),a(`loaded`))}).catch(e=>{t||(s(e instanceof Error?e.message:`Failed to load workflow handler picker`),a(`error`))}),()=>{t=!0}},[e]);let c=(0,R.useMemo)(()=>n?.options.find(e=>e.id===n.selectedHandlerId),[n]),l=n?.diagnostics??[];return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(Zo,{size:13}),`Code node editor`]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:`Select a registered Workflow Registry handler ref. The UI stores only the handler id on the Pibo Workflow IR node and never opens inline TypeScript, JavaScript, shell, or eval code.`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 px-2 py-1 text-[11px] font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void NDe(e,r,a,s),disabled:i===`loading`,children:[i===`loading`?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ls,{size:12}),`Refresh`]})]}),(0,z.jsxs)(`label`,{className:`grid gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Registered code handler`}),(0,z.jsxs)(`select`,{"aria-label":`Registered code handler`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-3 py-2 text-sm text-slate-100 outline-none transition focus:border-[#11a4d4] disabled:opacity-60`,value:n?.selectedHandlerId??``,onChange:e=>t(e.target.value),disabled:i===`loading`||i===`error`,children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered handler ref`}),n?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:k1(e)},e.id))]})]}),i===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:o??`Failed to load workflow handler picker.`}):null,c?(0,z.jsx)(LDe,{option:c}):null,l.length?(0,z.jsx)(`div`,{className:`grid gap-2`,"aria-label":`Code handler diagnostics`,children:l.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:13}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),(0,z.jsx)(`div`,{className:`mt-1 text-amber-200/80`,children:e.hint})]},`${e.code}:${e.registryRef}`))}):null,(0,z.jsxs)(`div`,{className:`grid gap-3`,"aria-label":`Registered handler picker options`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Registered handler refs`}),n?.options.map(e=>(0,z.jsx)(RDe,{option:e},e.id))]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:[`Missing handler refs return structured `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`WorkflowGraphError.unknownHandlerRef`}),` diagnostics and block publish/run paths once executable validation is invoked.`]})]})}function EDe(){let[e,t]=(0,R.useState)(ADe),[n,r]=(0,R.useState)(),[i,a]=(0,R.useState)(`loading`),[o,s]=(0,R.useState)();(0,R.useEffect)(()=>{let t=!1;return a(`loading`),s(void 0),oJ(e||void 0).then(e=>{t||(r(e),a(`loaded`))}).catch(e=>{t||(s(e instanceof Error?e.message:`Failed to load workflow adapter picker`),a(`error`))}),()=>{t=!0}},[e]);let c=(0,R.useMemo)(()=>n?.options.find(e=>e.id===n.selectedRefId),[n]),l=n?.diagnostics??[];return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(bs,{size:13}),`Adapter node editor`]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:`Select a registered deterministic adapter ref for visible adapter nodes. The UI stores only the registry ref and never opens inline transformation code.`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 px-2 py-1 text-[11px] font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void PDe(e,r,a,s),disabled:i===`loading`,children:[i===`loading`?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ls,{size:12}),`Refresh`]})]}),(0,z.jsxs)(`label`,{className:`grid gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Registered adapter`}),(0,z.jsxs)(`select`,{"aria-label":`Registered adapter`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-3 py-2 text-sm text-slate-100 outline-none transition focus:border-[#11a4d4] disabled:opacity-60`,value:n?.selectedRefId??``,onChange:e=>t(e.target.value),disabled:i===`loading`||i===`error`,children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered adapter ref`}),n?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),i===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:o??`Failed to load workflow adapter picker.`}):null,c?(0,z.jsx)(I1,{option:c,badge:`registered adapter`}):null,(0,z.jsx)(F1,{diagnostics:l}),(0,z.jsxs)(`div`,{className:`grid gap-3`,"aria-label":`Registered adapter picker options`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Registered adapter refs`}),n?.options.map(e=>(0,z.jsx)(I1,{option:e,badge:`registered adapter`},e.id))]}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Adapter nodes are visible graph nodes for schema transformation. Incompatible edges can alternatively use the compatible edge adapter dialog to keep the adapter on the edge.`})]})}function DDe(){let[e,t]=(0,R.useState)(jDe),[n,r]=(0,R.useState)(),[i,a]=(0,R.useState)(`loading`),[o,s]=(0,R.useState)();(0,R.useEffect)(()=>{let t=!1;return a(`loading`),s(void 0),cJ({selectedWorkflowId:e.workflowId||void 0,selectedWorkflowVersion:e.workflowVersion||void 0}).then(e=>{t||(r(e),a(`loaded`))}).catch(e=>{t||(s(e instanceof Error?e.message:`Failed to load workflow version picker`),a(`error`))}),()=>{t=!0}},[e.workflowId,e.workflowVersion]);let c=(0,R.useMemo)(()=>n?.options.find(e=>e.id===n.selectedWorkflowId&&e.version===n.selectedWorkflowVersion),[n]),l=c?j1(c):``,u=n?.diagnostics??[];return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(vs,{size:13}),`Workflow node editor`]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:`Select a published workflow id/version from registry metadata. The parent graph stores only this reference and opens the child workflow separately.`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 px-2 py-1 text-[11px] font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void FDe(e,r,a,s),disabled:i===`loading`,children:[i===`loading`?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ls,{size:12}),`Refresh`]})]}),(0,z.jsxs)(`label`,{className:`grid gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Nested workflow version`}),(0,z.jsxs)(`select`,{"aria-label":`Nested workflow picker`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-3 py-2 text-sm text-slate-100 outline-none transition focus:border-[#11a4d4] disabled:opacity-60`,value:l,onChange:e=>t(T1(e.target.value)??{workflowId:``,workflowVersion:``}),disabled:i===`loading`||i===`error`,children:[(0,z.jsx)(`option`,{value:``,children:`Select a published workflow version`}),n?.options.map(e=>(0,z.jsx)(`option`,{value:j1(e),children:M1(e)},j1(e)))]})]}),i===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:o??`Failed to load workflow version picker.`}):null,c?(0,z.jsx)(R1,{option:c}):null,(0,z.jsx)(z1,{diagnostics:u,ariaLabel:`Nested workflow diagnostics`}),(0,z.jsxs)(`a`,{className:`inline-flex items-center justify-center gap-2 rounded-sm border px-3 py-2 text-xs font-semibold transition ${c?`border-[#11a4d4]/50 text-[#8bdcf4] hover:border-[#11a4d4] hover:text-slate-100`:`pointer-events-none border-slate-800 text-slate-600`}`,href:c?E1(c.id,c.version):`#`,"aria-disabled":!c,children:[(0,z.jsx)(rs,{size:13}),`Open workflow`]}),(0,z.jsxs)(`div`,{className:`grid gap-3`,"aria-label":`Nested workflow picker options`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Published workflow refs`}),n?.options.map(e=>(0,z.jsx)(SDe,{option:e},j1(e)))]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:[`Nested workflow internals stay collapsed in the parent graph for V2. Use `,(0,z.jsx)(`span`,{className:`font-semibold text-slate-300`,children:`Open workflow`}),` to navigate to the child workflow viewer instead of inline-expanding its graph.`]})]})}function ODe(){return typeof window>`u`?``:new URL(window.location.href).searchParams.get(`profileRef`)??``}function kDe(){return typeof window>`u`?``:new URL(window.location.href).searchParams.get(`handlerRef`)??``}function ADe(){return typeof window>`u`?``:new URL(window.location.href).searchParams.get(`adapterRef`)??``}function jDe(){if(typeof window>`u`)return{workflowId:``,workflowVersion:``};let e=new URL(window.location.href).searchParams,t=e.get(`workflowRef`);return t?T1(t)??{workflowId:t,workflowVersion:``}:{workflowId:e.get(`workflowId`)??``,workflowVersion:e.get(`workflowVersion`)??``}}async function MDe(e,t,n,r){n(`loading`),r(void 0);try{t(await iJ(e||void 0)),n(`loaded`)}catch(e){r(e instanceof Error?e.message:`Failed to load workflow profile picker`),n(`error`)}}async function NDe(e,t,n,r){n(`loading`),r(void 0);try{t(await aJ(e||void 0)),n(`loaded`)}catch(e){r(e instanceof Error?e.message:`Failed to load workflow handler picker`),n(`error`)}}async function PDe(e,t,n,r){n(`loading`),r(void 0);try{t(await oJ(e||void 0)),n(`loaded`)}catch(e){r(e instanceof Error?e.message:`Failed to load workflow adapter picker`),n(`error`)}}async function FDe(e,t,n,r){n(`loading`),r(void 0);try{t(await cJ({selectedWorkflowId:e.workflowId||void 0,selectedWorkflowVersion:e.workflowVersion||void 0})),n(`loaded`)}catch(e){r(e instanceof Error?e.message:`Failed to load workflow version picker`),n(`error`)}}function IDe({option:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:[(0,z.jsxs)(`div`,{className:`font-semibold text-slate-200`,children:[`Selected profile: `,e.displayName]}),e.description?(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:e.description}):null,(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:e.source===`custom`?`Custom Agent`:`Global profile`}),(0,z.jsx)(P1,{label:`${e.nativeTools.length} native tools`}),(0,z.jsx)(P1,{label:`${e.skills.length} skills`}),(0,z.jsx)(P1,{label:`${e.contextFiles.length} context files`})]})]})}function LDe({option:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:[(0,z.jsxs)(`div`,{className:`font-semibold text-slate-200`,children:[`Selected handler: `,e.displayName]}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:e.id}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,(0,z.jsxs)(`div`,{className:`mt-3 grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(L1,{label:`inputSchema`,schema:e.inputSchema}),(0,z.jsx)(L1,{label:`outputSchema`,schema:e.outputSchema})]})]})}function RDe({option:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`font-semibold text-slate-200`,children:e.displayName}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:e.id})]}),(0,z.jsx)(P1,{label:`registered handler`})]}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,(0,z.jsxs)(`div`,{className:`mt-3 grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(L1,{label:`inputSchema`,schema:e.inputSchema}),(0,z.jsx)(L1,{label:`outputSchema`,schema:e.outputSchema})]})]})}function zDe({draft:e,onDraftChange:t,renderInspectors:n}){let r=(0,R.useMemo)(()=>P$(e.definition,e.diagnostics),[e.definition,e.diagnostics]),[i,a]=(0,R.useState)(r.nodes),[o,s]=(0,R.useState)(r.edges),[c,l]=(0,R.useState)(),[u,d]=(0,R.useState)(``),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(!1),[g,_]=(0,R.useState)(`idle`),[v,y]=(0,R.useState)(),[b,x]=(0,R.useState)(`base`),[S,C]=(0,R.useState)([]),[w,T]=(0,R.useState)(``),[E,D]=(0,R.useState)([]),[O,k]=(0,R.useState)(``),[A,j]=(0,R.useState)([]),[M,N]=(0,R.useState)(``);(0,R.useEffect)(()=>{let e=!1;return iJ().then(t=>{!e&&t.options[0]?.id&&x(t.options[0].id)}).catch(()=>void 0),()=>{e=!0}},[]),(0,R.useEffect)(()=>{let e=!1;return cJ().then(t=>{e||(C(t.options),T(e=>e||(t.options[0]?j1(t.options[0]):``)))}).catch(()=>void 0),()=>{e=!0}},[]),(0,R.useEffect)(()=>{let e=!1;return oJ().then(t=>{e||(D(t.options),k(e=>e||(t.options[0]?.id??``)))}).catch(()=>void 0),()=>{e=!0}},[]),(0,R.useEffect)(()=>{let e=!1;return sJ().then(t=>{e||(j(t.options),N(e=>e||(t.options[0]?.id??``)))}).catch(()=>void 0),()=>{e=!0}},[]),(0,R.useEffect)(()=>{a(r.nodes),s(r.edges),h(!1),l(e=>e&&IEe(r,e)?e:void 0)},[r]);let P=(0,R.useMemo)(()=>i.map(e=>e.id),[i]);(0,R.useEffect)(()=>{d(e=>e&&P.includes(e)?e:P[0]??``),p(e=>e&&P.includes(e)&&e!==u?e:P.find(e=>e!==(u||P[0]))??``)},[P,u]);let F=(0,R.useCallback)(async(n,r,i={})=>{_(`saving`),y(void 0);try{t((await uJ(e.draftId,{definition:n,editTrigger:i.editTrigger??`graph_edit`})).draft),_(`saved`),y(r),i.clearLayoutDirty&&h(!1)}catch(e){_(`error`),y(e instanceof Error?e.message:`Failed to save graph edit`)}},[e.draftId,t]),ee=(0,R.useCallback)(e=>{a(t=>DQ(e,t)),e.some(e=>e.type===`position`)&&h(!0)},[]),te=(0,R.useCallback)(e=>{s(t=>OQ(e,t))},[]),I=()=>{let t=W$(e.definition,`agent`),n=U$(i),r=uDe(e.definition,t,n,b);l({type:`node`,id:t}),F(r,`Added node ${t}.`)},ne=(0,R.useMemo)(()=>S.find(e=>j1(e)===w),[S,w]),L=()=>{if(!ne)return;let t=W$(e.definition,`workflow`),n=U$(i),r=dDe(e.definition,t,n,ne);l({type:`node`,id:t}),F(r,`Added nested workflow node ${t} for ${ne.id}@${ne.version}.`)},re=()=>{if(!O)return;let t=W$(e.definition,`adapter`),n=U$(i),r=fDe(e.definition,t,n,O);l({type:`node`,id:t}),F(r,`Added adapter node ${t} for ${O}.`)},ie=()=>{if(!M)return;let t=W$(e.definition,`human`),n=U$(i),r=A.find(e=>e.id===M),a=pDe(e.definition,t,n,_1(M,r?.kind));l({type:`node`,id:t}),F(a,`Added human node ${t} with action ${M}.`)},ae=(0,R.useCallback)((t=u,n=f)=>{if(!t||!n||t===n)return;let r=BEe(e.definition,t,n),i=VEe(e.definition,r,t,n);s(e=>_Z({id:r,source:t,target:n,type:`smoothstep`},e)),l({type:`edge`,id:r}),F(i,`Connected ${t} to ${n}.`)},[e.definition,F,u,f]),oe=()=>{if(!c)return;let t=c.type===`node`?HEe(e.definition,c.id):UEe(e.definition,c.id);l(void 0),F(t,`Deleted ${c.type} ${c.id}.`)},se=(e,t)=>{c?.type===`node`&&(a(n=>n.map(n=>n.id===c.id?{...n,position:{x:n.position.x+e,y:n.position.y+t},selected:!0}:n)),h(!0),y(`Moved node ${c.id}; save layout to persist UI positions.`))},ce=()=>{F(K$(e.definition,Object.fromEntries(i.map(e=>[e.id,e.position]))),`Layout saved to workflow.ui.positions without changing runtime semantics.`,{clearLayoutDirty:!0})},le=(0,R.useCallback)(e=>{!e.source||!e.target||ae(e.source,e.target)},[ae]),ue=HDe(e.definition,c),de=g===`saving`,fe=P.length>1;return(0,z.jsxs)(`section`,{className:`grid gap-4 rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-labelledby":`workflow-graph-canvas-title`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(ks,{size:13}),`Workflow graph canvas`]}),(0,z.jsx)(`h4`,{id:`workflow-graph-canvas-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:`Visual graph editor`}),(0,z.jsxs)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-500`,children:[`React Flow projects Pibo Workflow IR nodes and edges. Graph edits save IR changes; layout saves only `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`workflow.ui.positions`}),` metadata.`]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${i.length} nodes`}),(0,z.jsx)(P1,{label:`${o.length} edges`}),(0,z.jsx)(P1,{label:r.usedAutoLayout?`auto layout (${r.missingPositionCount} missing)`:`manual positions`})]})]}),(0,z.jsxs)(`div`,{className:`grid gap-3 text-xs xl:grid-cols-[minmax(0,1fr)_18rem]`,children:[(0,z.jsx)(`div`,{className:`h-[420px] min-w-0 overflow-hidden rounded-sm border border-slate-800 bg-[#0c171c]`,"aria-label":`Workflow graph canvas`,children:(0,z.jsxs)(sEe,{nodes:i,edges:o,nodeTypes:VDe,onNodesChange:ee,onEdgesChange:te,onConnect:le,onNodeClick:(e,t)=>l({type:`node`,id:t.id}),onEdgeClick:(e,t)=>l({type:`edge`,id:t.id}),onPaneClick:()=>l(void 0),fitView:!0,minZoom:.35,maxZoom:1.6,colorMode:`dark`,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:wX.ArrowClosed,color:`#38bdf8`}},children:[(0,z.jsx)(fEe,{color:`#1f3a44`,gap:18}),(0,z.jsx)(MEe,{pannable:!0,zoomable:!0,nodeColor:e=>e.selected?`#38bdf8`:`#1e293b`}),(0,z.jsx)(yEe,{showInteractive:!1})]})}),(0,z.jsxs)(`div`,{className:`grid content-start gap-3`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Graph edit controls`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:I,disabled:de,children:[(0,z.jsx)(Ps,{size:13}),`Add Agent node`]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Nested workflow version`}),(0,z.jsx)(`select`,{"aria-label":`Nested workflow version`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:w,onChange:e=>T(e.target.value),disabled:de||!S.length,children:S.length?S.map(e=>(0,z.jsx)(`option`,{value:j1(e),children:M1(e)},j1(e))):(0,z.jsx)(`option`,{value:``,children:`No published workflow versions`})})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:L,disabled:de||!ne,children:[(0,z.jsx)(vs,{size:13}),`Add Workflow node`]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Adapter ref`}),(0,z.jsx)(`select`,{"aria-label":`Adapter node ref`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:O,onChange:e=>k(e.target.value),disabled:de||!E.length,children:E.length?E.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id)):(0,z.jsx)(`option`,{value:``,children:`No registered adapters`})})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:re,disabled:de||!O,children:[(0,z.jsx)(bs,{size:13}),`Add Adapter node`]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Human action ref`}),(0,z.jsx)(`select`,{"aria-label":`Human node action ref`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:M,onChange:e=>N(e.target.value),disabled:de||!A.length,children:A.length?A.map(e=>(0,z.jsx)(`option`,{value:e.id,children:yDe(e)},e.id)):(0,z.jsx)(`option`,{value:``,children:`No registered human actions`})})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:ie,disabled:de||!M,children:[(0,z.jsx)(ks,{size:13}),`Add Human node`]}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-2 text-[11px] leading-5 text-slate-500`,children:`Workflow nodes store only a workflow id/version reference. Adapter and human nodes store only registered deterministic adapter or human action refs. V2 does not inline-expand nested workflow internals or create inline transform code.`}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`From`}),(0,z.jsx)(`select`,{"aria-label":`Connect from node`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:u,onChange:e=>d(e.target.value),disabled:de||!fe,children:P.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`To`}),(0,z.jsx)(`select`,{"aria-label":`Connect to node`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:f,onChange:e=>p(e.target.value),disabled:de||!fe,children:P.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>ae(),disabled:de||!u||!f||u===f,children:[(0,z.jsx)(bs,{size:13}),`Connect nodes`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>se(40,0),disabled:de||c?.type!==`node`,children:[(0,z.jsx)(As,{size:13}),`Nudge selected node`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-red-500/70 hover:text-red-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:oe,disabled:de||!c,children:[(0,z.jsx)(qs,{size:13}),`Delete selected`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-emerald-700/70 px-3 py-2 text-xs font-semibold text-emerald-200 transition hover:border-emerald-400 hover:text-emerald-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:ce,disabled:de||!i.length||!m,children:[de?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save layout`]})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Selected graph element`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Selected graph element`}),(0,z.jsx)(`div`,{className:`mt-2 text-xs leading-5 text-slate-300`,children:ue})]}),n({draft:e,selectedElement:c,nodeIds:P,isSaving:de,onSaveDefinition:F}),v?(0,z.jsx)(`div`,{className:`rounded-sm border p-3 text-xs leading-5 ${g===`error`?`border-red-900/70 bg-red-950/40 text-red-200`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,role:`status`,children:v}):null]})]}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Automatic layout is a canvas projection for workflows without saved positions. Saving layout writes only display metadata and does not change nodes, edges, ports, guards, adapters, runtime routing, or validation semantics.`})]})}function BDe({data:e,selected:t}){return(0,z.jsxs)(`div`,{className:`min-w-44 rounded-sm border bg-[#15242b] px-3 py-2 shadow-lg shadow-black/20 ${t?`border-[#38bdf8]`:`border-slate-700`}`,children:[(0,z.jsx)(KQ,{type:`target`,position:TX.Left,className:`!h-2.5 !w-2.5 !border-[#0f172a] !bg-[#38bdf8]`}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs font-bold text-slate-100`,children:e.label}),(0,z.jsx)(`span`,{className:`rounded-full border border-slate-700 px-2 py-0.5 text-[10px] uppercase tracking-[0.12em] text-slate-400`,children:e.kind})]}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:e.nodeId}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1 text-[10px]`,children:[e.isInitial?(0,z.jsx)(`span`,{className:`rounded-full border border-[#11a4d4]/40 bg-[#11a4d4]/10 px-2 py-0.5 text-[#8bdcf4]`,children:`initial`}):null,e.validationCount?(0,z.jsxs)(`span`,{className:`rounded-full border border-amber-600/60 bg-amber-950/30 px-2 py-0.5 text-amber-200`,children:[e.validationCount,` diagnostics`]}):null]}),(0,z.jsx)(KQ,{type:`source`,position:TX.Right,className:`!h-2.5 !w-2.5 !border-[#0f172a] !bg-[#38bdf8]`})]})}var VDe={workflowNode:BDe};function HDe(e,t){if(!t)return`Select a node or edge in the canvas to inspect or delete it.`;if(t.type===`node`){let n=I$(e)[t.id];return n?`Node ${t.id}: ${z$(n)} — ${B$(t.id,n)}`:`Node ${t.id}`}let n=L$(e)[t.id],r=n?J$(n.from):void 0,i=n?J$(n.to):void 0;return n&&r&&i?`Edge ${t.id}: ${r} → ${i}`:`Edge ${t.id}`}function UDe(e,t){let n=J$(t.from),r=J$(t.to),i=B1(e,t),a=V1(e,t);return{...n?{sourceNodeId:n}:{},...r?{targetNodeId:r}:{},...i?{sourcePort:i}:{},...a?{targetPort:a}:{},directlyCompatible:!!(i&&a&&qDe(i,a))}}function WDe(e){let t=F$(e.adapter)?e.adapter:void 0;return YDe(t&&F$(t.transform)?t.transform:void 0)}function GDe(e,t,n){let r=L$(e),i=r[t];if(!i)return e;let a=V1(e,i)??U1();return{...e,edges:{...r,[t]:{...i,id:t,adapter:{kind:`edgeAdapter`,transform:JDe(n),output:G1(a)}}}}}function KDe(e,t,n){let r=L$(e),i=r[t];if(!i)return e;let a=J$(i.from),o=J$(i.to);if(!a||!o)return e;let s=I$(e),c=W$(e,`adapter`),l=B1(e,i)??U1(),u=V1(e,i)??U1(),d=V$(e),f=XDe(d[a],d[o])??U$(P$(e,[]).nodes),p={...r};delete p[t];let m=W1(p,`${t}_to_${c}`),h=W1({...p,[m]:{}},`${c}_to_${o}`),g={id:m,from:G1(F$(i.from)?i.from:{nodeId:a}),to:{nodeId:c},kind:typeof i.kind==`string`?i.kind:`data`};F$(i.guard)&&(g.guard=G1(i.guard));let _={id:h,from:{nodeId:c},to:G1(F$(i.to)?i.to:{nodeId:o}),kind:typeof i.kind==`string`?i.kind:`data`};return K$({...e,nodes:{...s,[c]:C1(c,n,l,u)},edges:{...p,[m]:g,[h]:_}},{...d,[c]:f})}function qDe(e,t){return e.kind===`text`&&t.kind===`text`?!0:e.kind!==`json`||t.kind!==`json`?!1:JSON.stringify(e.schema??null)===JSON.stringify(t.schema??null)}function B1(e,t){let n=H1(e,t.from);return n&&F$(n.output)?n.output:void 0}function V1(e,t){let n=H1(e,t.to);return n&&F$(n.input)?n.input:void 0}function H1(e,t){let n=J$(t);return n?I$(e)[n]:void 0}function U1(){return{kind:`text`}}function JDe(e){return{kind:`adapter`,language:`typescript`,id:e}}function YDe(e){return F$(e)&&e.kind===`adapter`&&e.language===`typescript`&&typeof e.id==`string`?e.id:``}function XDe(e,t){return e&&t?{x:(e.x+t.x)/2,y:(e.y+t.y)/2}:void 0}function W1(e,t){let n=t.replace(/[^a-zA-Z0-9_-]/g,`-`);if(!Object.hasOwn(e,n))return n;let r=2;for(;Object.hasOwn(e,`${n}_${r}`);)r+=1;return`${n}_${r}`}function G1(e){return JSON.parse(JSON.stringify(e))}function K1(e){let t=F$(e.metadata)?e.metadata:{};return{title:typeof e.title==`string`?e.title:``,description:typeof e.description==`string`?e.description:``,inputKind:s1(e.input,`text`),inputDescription:l1(e.input),inputSchemaText:u1(e.input),outputKind:s1(e.output,`text`),outputDescription:l1(e.output),outputSchemaText:u1(e.output),globalStateFields:q1(e),metadataTags:Z1(t.tags),metadataUseWhen:Z1(t.useWhen),metadataNotFor:Z1(t.notFor),metadataExamples:Z1(t.examples)}}function ZDe(e,t){let n=F$(e.metadata)?{...e.metadata}:{};Q1(n,`tags`,t.metadataTags),Q1(n,`useWhen`,t.metadataUseWhen),Q1(n,`notFor`,t.metadataNotFor),Q1(n,`examples`,t.metadataExamples);let r={...e,input:p1(t.inputKind,t.inputDescription,e.input,t.inputSchemaText),output:p1(t.outputKind,t.outputDescription,e.output,t.outputSchemaText)};return eOe(r,t.globalStateFields),x1(r,`title`,t.title),x1(r,`description`,t.description),Object.keys(n).length?r.metadata=n:delete r.metadata,r}function QDe(e){let t=new Set(e.map(e=>e.path.trim()).filter(Boolean)),n=`projectGoal`,r=2;for(;t.has(n);)n=`projectGoal${r}`,r+=1;return{path:n,description:``,schemaText:d1(Y$),mergeKind:`none`}}function q1(e){let t=F$(e.state)?e.state:void 0,n=t&&F$(t.global)?t.global:void 0;return n?Object.entries(n).flatMap(([e,t])=>F$(t)?[{path:e,description:typeof t.description==`string`?t.description:``,schemaText:d1(t.schema),mergeKind:$De(t.merge)}]:[]):[]}function $De(e){return!F$(e)||typeof e.kind!=`string`?`none`:[`replace`,`append`,`shallowMerge`].includes(e.kind)?e.kind:`none`}function eOe(e,t){let n=F$(e.state)?{...e.state}:{},r={};for(let e of t){let t=XEe(e.path);if(!t)continue;let n={schema:f1(e.schemaText)};x1(n,`description`,e.description);let i=tOe(e.mergeKind);i&&(n.merge=i),r[t]=n}Object.keys(r).length?n.global=r:delete n.global,Object.keys(n).length?e.state=n:delete e.state}function tOe(e){return e===`none`?void 0:{kind:e}}function nOe(e,t){return JSON.stringify(q1(e))!==JSON.stringify(t.globalStateFields)}function J1(e){return typeof e==`string`?e.trim():F$(e)&&typeof e.id==`string`?e.id.trim():``}function Y1(e,t,n){let r=I$(e),i=r[t];if(!i)return e;let a={...i,promptBuilder:{kind:`promptBuilder`,language:`typescript`,id:n.id,revisionId:n.revisionId,contentHash:n.contentHash,source:n.source},metadata:X1(i.metadata,n)};return delete a.promptTemplate,{...e,metadata:X1(e.metadata,n),nodes:{...r,[t]:a}}}function X1(e,t){let n=F$(e)?{...e}:{},r=Array.isArray(n.promptAssetRefs)?n.promptAssetRefs.filter(e=>typeof e==`string`&&e.trim().length>0):[];return n.promptAssetRefs=[...new Set([...r,t.id])],n.promptAssetPins=[...Array.isArray(n.promptAssetPins)?n.promptAssetPins.filter(e=>F$(e)&&e.assetId!==t.id):[],{assetId:t.id,revisionId:t.revisionId,contentHash:t.contentHash,source:t.source}],n}function Z1(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).join(`
|
|
162
|
-
`):``}function rOe(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Q1(e,t,n){let r=rOe(n);r.length?e[t]=r:delete e[t]}function iOe({draft:e,nodeId:t,node:n,isSaving:r,onSaveDefinition:i}){let[a,o]=(0,R.useState)(J1(n.promptBuilder)),[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(),[d,f]=(0,R.useState)(`idle`),[p,m]=(0,R.useState)(`saved`),[h,g]=(0,R.useState)();(0,R.useEffect)(()=>{o(J1(n.promptBuilder))},[n,t]),(0,R.useEffect)(()=>{let e=!1;return kye(a||void 0).then(t=>{e||c(t)}).catch(()=>void 0),()=>{e=!0}},[a]),(0,R.useEffect)(()=>{let e=!1;return g(void 0),a?(f(`loading`),Aye(a).then(t=>{e||(u(t.asset),f(`loaded`))}).catch(t=>{e||(u(void 0),f(`error`),g(t instanceof Error?t.message:`Failed to load prompt asset`))}),()=>{e=!0}):(u(void 0),f(`idle`),()=>{e=!0})},[a]);let _=s?.options.find(e=>e.id===a),v=typeof n.promptTemplate==`string`?n.promptTemplate:S1,y=l?.markdown??v,b=`${e.draftId}:${t}:${(l?.id??a)||`direct-prompt`}:${l?.revisionId??`draft`}`,x=!!J1(n.promptBuilder),S=a.startsWith(`ui.promptAssets.`),C=`${typeof n.label==`string`&&n.label.trim()?n.label.trim():t} prompt asset`,w=(0,R.useCallback)(async n=>{try{let r=await jye({assetId:S?a:void 0,sourceRefId:a||void 0,displayName:C,description:`Managed prompt asset for ${t} in draft ${e.draftId}.`,markdown:n});await i(Y1(e.definition,t,r.asset),`Saved prompt asset revision ${r.asset.revisionId} and updated ${t}.`,{editTrigger:`prompt_edit`}),o(r.asset.id),u(r.asset),g(`Saved ${r.asset.displayName} as revision ${r.asset.revisionId}; draft now pins ${r.asset.contentHash}.`)}catch(e){throw g(e instanceof Error?e.message:`Failed to save prompt asset revision`),e}},[e.definition,e.draftId,t,i,C,a,S]),T=async()=>{l&&(await i(Y1(e.definition,t,l),`Updated ${t} to use prompt asset ${l.id}.`,{editTrigger:`prompt_edit`}),g(`Draft node ${t} now uses ${l.displayName} at ${l.contentHash}.`))};return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,"aria-label":`Prompt asset Markdown editor`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Prompt asset Markdown editor`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Edit prompt assets with the same Markdown editor pattern as Context Files. Saving creates a managed UI asset revision, updates this draft node to a prompt asset ref, and pins the revision id plus content hash in the Pibo Workflow IR.`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Prompt asset ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a,onChange:e=>o(e.target.value),disabled:r,children:[(0,z.jsx)(`option`,{value:``,children:`Create managed asset from direct prompt template`}),s?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:s?.diagnostics??[]}),_?(0,z.jsx)(I1,{option:_,badge:_.kind===`ui`?`managed prompt asset`:`registered prompt asset`}):null,d===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-2 text-[11px] leading-5 text-red-200`,role:`alert`,children:h??`Failed to load prompt asset.`}):null,(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:(0,z.jsx)(Gz,{documentKey:b,initialMarkdown:y,onPersist:w,onSaveStateChange:m})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:x?`promptBuilder ref`:`direct promptTemplate source`}),(0,z.jsx)(P1,{label:`Markdown save: ${p}`}),l?(0,z.jsx)(P1,{label:`${l.source} · ${l.revisionId}`}):null]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void T(),disabled:r||!l,children:[(0,z.jsx)(Bs,{size:13}),`Use selected asset on draft`]})}),h&&d!==`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-emerald-900/60 bg-emerald-950/20 p-2 text-[11px] leading-5 text-emerald-200`,role:`status`,children:h}):null,(0,z.jsx)(`div`,{className:`text-[11px] leading-5 text-slate-500`,children:`Code/plugin prompt assets are not mutated. Editing a registered asset copies the Markdown into a managed UI prompt asset; later saves append revisions and only affect this draft or future workflow versions that reference the new revision.`})]})}function aOe({draft:e,selectedElement:t,nodeIds:n,isSaving:r,onSaveDefinition:i}){let a=t?.type===`node`?I$(e.definition)[t.id]:void 0,o=t?.type===`edge`?L$(e.definition)[t.id]:void 0;return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Workflow inspectors`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:`Workflow inspectors`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Inspector saves update the same Pibo Workflow IR draft as the graph canvas; XState remains projection-only.`})]}),(0,z.jsx)(cOe,{draft:e,isSaving:r,onSaveDefinition:i}),t?.type===`node`&&a?(0,z.jsx)(lOe,{draft:e,nodeId:t.id,node:a,isSaving:r,onSaveDefinition:i}):t?.type===`edge`&&o?(0,z.jsx)(uOe,{draft:e,edgeId:t.id,edge:o,nodeIds:n,isSaving:r,onSaveDefinition:i}):(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Select a canvas node or edge to open the node or edge inspector. Workflow settings remain editable at all times.`})]})}function oOe(e,t){return e.filter(e=>e.nodeId===t||e.path?.startsWith(`$.nodes.${t}`))}function sOe(e,t){return e.filter(e=>e.edgeId===t||e.path?.startsWith(`$.edges.${t}`))}function cOe({draft:e,isSaving:t,onSaveDefinition:n}){let[r,i]=(0,R.useState)(()=>K1(e.definition));(0,R.useEffect)(()=>{i(K1(e.definition))},[e.definition]);let a=(e,t)=>{i(n=>({...n,[e]:t}))};return(0,z.jsxs)(`details`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,open:!0,children:[(0,z.jsx)(`summary`,{className:`cursor-pointer text-xs font-bold text-slate-200`,children:`Workflow settings inspector`}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Workflow title`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:r.title,onChange:e=>a(`title`,e.target.value)})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Workflow description`}),(0,z.jsx)(`textarea`,{className:`min-h-20 rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:r.description,onChange:e=>a(`description`,e.target.value)})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(n0,{label:`Workflow input port`,kind:r.inputKind,description:r.inputDescription,schemaText:r.inputSchemaText,onKindChange:e=>a(`inputKind`,e),onDescriptionChange:e=>a(`inputDescription`,e),onSchemaChange:e=>a(`inputSchemaText`,e)}),(0,z.jsx)(n0,{label:`Workflow output port`,kind:r.outputKind,description:r.outputDescription,schemaText:r.outputSchemaText,onKindChange:e=>a(`outputKind`,e),onDescriptionChange:e=>a(`outputDescription`,e),onSchemaChange:e=>a(`outputSchemaText`,e)})]}),(0,z.jsx)(fOe,{fields:r.globalStateFields,onAddField:()=>{i(e=>({...e,globalStateFields:[...e.globalStateFields,QDe(e.globalStateFields)]}))},onRemoveField:e=>{i(t=>({...t,globalStateFields:t.globalStateFields.filter((t,n)=>n!==e)}))},onUpdateField:(e,t,n)=>{i(r=>({...r,globalStateFields:r.globalStateFields.map((r,i)=>i===e?{...r,[t]:n}:r)}))}}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(a0,{label:`metadata.tags`,value:r.metadataTags,onChange:e=>a(`metadataTags`,e)}),(0,z.jsx)(a0,{label:`metadata.useWhen`,value:r.metadataUseWhen,onChange:e=>a(`metadataUseWhen`,e)}),(0,z.jsx)(a0,{label:`metadata.notFor`,value:r.metadataNotFor,onChange:e=>a(`metadataNotFor`,e)}),(0,z.jsx)(a0,{label:`metadata.examples`,value:r.metadataExamples,onChange:e=>a(`metadataExamples`,e)})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>{n(ZDe(e.definition,r),`Saved workflow settings inspector edits to the draft IR.`,{editTrigger:nOe(e.definition,r)?`state_edit`:`schema_edit`})},disabled:t,children:[t?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save workflow settings`]})]})]})}function lOe({draft:e,nodeId:t,node:n,isSaving:r,onSaveDefinition:i}){let[a,o]=(0,R.useState)(()=>i1(n)),[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(),[d,f]=(0,R.useState)(),[p,m]=(0,R.useState)(),[h,g]=(0,R.useState)(),_=z$(n),v=oOe(e.diagnostics,t),y=d?.options.find(e=>e.id===(d?.selectedRefId??a.adapterRef)),b=(0,R.useMemo)(()=>new Set(a.humanActionRefs.map(e=>e.id)),[a.humanActionRefs]);(0,R.useEffect)(()=>{o(i1(n))},[n,t]),(0,R.useEffect)(()=>{if(_!==`agent`)return;let e=!1;return iJ(a.profileId||void 0).then(t=>{e||c(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.profileId]),(0,R.useEffect)(()=>{if(_!==`code`)return;let e=!1;return aJ(a.handlerId||void 0).then(t=>{e||u(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.handlerId]),(0,R.useEffect)(()=>{if(_!==`adapter`)return;let e=!1;return oJ(a.adapterRef||void 0).then(t=>{e||f(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.adapterRef]),(0,R.useEffect)(()=>{if(_!==`workflow`)return;let e=!1,t=T1(a.workflowVersionKey);return cJ({selectedWorkflowId:t?.workflowId,selectedWorkflowVersion:t?.workflowVersion}).then(t=>{e||m(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.workflowVersionKey]),(0,R.useEffect)(()=>{if(_!==`human`)return;let e=!1;return sJ().then(t=>{e||g(t)}).catch(()=>void 0),()=>{e=!0}},[_]);let x=(e,t)=>{o(n=>({...n,[e]:t}))},S=(e,t)=>{o(n=>({...n,humanActionRefs:rDe(n.humanActionRefs,e,t)}))};return(0,z.jsxs)(`details`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,open:!0,children:[(0,z.jsxs)(`summary`,{className:`cursor-pointer text-xs font-bold text-slate-200`,children:[`Node inspector: `,t]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${_} node`}),(0,z.jsx)(P1,{label:`${v.length} diagnostics`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Node label`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a.label,onChange:e=>x(`label`,e.target.value)})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Node description`}),(0,z.jsx)(`textarea`,{className:`min-h-16 rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a.description,onChange:e=>x(`description`,e.target.value)})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(r0,{label:`Node input port`,kind:a.inputKind,description:a.inputDescription,schemaText:a.inputSchemaText,onKindChange:e=>x(`inputKind`,e),onDescriptionChange:e=>x(`inputDescription`,e),onSchemaChange:e=>x(`inputSchemaText`,e)}),(0,z.jsx)(r0,{label:`Node output port`,kind:a.outputKind,description:a.outputDescription,schemaText:a.outputSchemaText,onKindChange:e=>x(`outputKind`,e),onDescriptionChange:e=>x(`outputDescription`,e),onSchemaChange:e=>x(`outputSchemaText`,e)})]}),(0,z.jsx)($1,{label:`Node`,definition:e.definition,value:a.stateAccess,onChange:e=>x(`stateAccess`,e)}),_===`agent`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Agent node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Agent profile ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:s?.selectedProfileId??a.profileId,onChange:e=>x(`profileId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a non-archived profile`}),s?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:O1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:s?.diagnostics??[]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Prompt template`}),(0,z.jsx)(`textarea`,{className:`min-h-24 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 font-mono text-slate-100`,value:a.promptTemplate,onChange:e=>x(`promptTemplate`,e.target.value)}),(0,z.jsxs)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:[`Saving direct prompt text writes `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`promptTemplate`}),` on this Pibo Workflow IR node.`]})]}),(0,z.jsx)(iOe,{draft:e,nodeId:t,node:n,isSaving:r,onSaveDefinition:i})]}):null,_===`code`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Code node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Registered code handler`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:l?.selectedHandlerId??a.handlerId,onChange:e=>x(`handlerId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered handler ref`}),l?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:k1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:l?.diagnostics??[]})]}):null,_===`adapter`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Adapter node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Registered adapter ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:d?.selectedRefId??a.adapterRef,onChange:e=>x(`adapterRef`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered adapter ref`}),d?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:d?.diagnostics??[]}),y?.paramsSchema?(0,z.jsx)(o0,{label:`Adapter params JSON`,schema:y.paramsSchema,value:a.adapterParamsText,onChange:e=>x(`adapterParamsText`,e)}):null,(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-2 text-[11px] leading-5 text-slate-500`,children:`Adapter nodes store only a registered deterministic adapter ref. Inline transformation code and hidden LLM coercion are not exposed by the UI.`})]}):null,_===`workflow`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Workflow node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Nested workflow ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:p?.selectedWorkflowId&&p.selectedWorkflowVersion?w1(p.selectedWorkflowId,p.selectedWorkflowVersion):a.workflowVersionKey,onChange:e=>x(`workflowVersionKey`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a published workflow version`}),p?.options.map(e=>(0,z.jsx)(`option`,{value:j1(e),children:M1(e)},j1(e)))]})]}),(0,z.jsx)(z1,{diagnostics:p?.diagnostics??[],ariaLabel:`Workflow node diagnostics`})]}):null,_===`human`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Human node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Human prompt`}),(0,z.jsx)(`textarea`,{className:`min-h-24 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:a.humanPrompt,onChange:e=>x(`humanPrompt`,e.target.value)})]}),(0,z.jsx)(i0,{label:`Human node resume payload schema JSON`,value:a.humanSchemaText,onChange:e=>x(`humanSchemaText`,e)}),(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,"aria-label":`Human action choices`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Registered action choices`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Actions are selected from the Workflow Registry. The label, action kind, and payload requirements come from picker metadata.`})]}),h?.options.length?h.options.map(e=>(0,z.jsxs)(`label`,{className:`grid gap-1 rounded-sm border border-slate-800 bg-[#101d22] p-2 text-slate-300`,children:[(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-2 font-semibold`,children:[(0,z.jsx)(`input`,{type:`checkbox`,className:`h-3.5 w-3.5 accent-[#11a4d4]`,checked:b.has(e.id),onChange:t=>S(e,t.target.checked)}),(0,z.jsx)(`span`,{children:e.displayName}),(0,z.jsx)(P1,{label:`kind: ${e.kind??`registered`}`})]}),(0,z.jsx)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:e.description??e.id}),(0,z.jsxs)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:[`Payload requirements: `,e.paramsSchema?JSON.stringify(e.paramsSchema):`none`]})]},e.id)):(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 p-2 text-[11px] leading-5 text-slate-500`,children:`No registered human actions are available from the picker.`}),(0,z.jsx)(F1,{diagnostics:h?.diagnostics??[]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,"aria-label":`Selected human action refs`,children:a.humanActionRefs.length?a.humanActionRefs.map(e=>(0,z.jsx)(P1,{label:`${e.id}${e.kind?` (${e.kind})`:``}`},`${e.id}:${e.kind??``}`)):(0,z.jsx)(`span`,{className:`text-slate-500`,children:`No human action refs selected.`})})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 md:grid-cols-[1fr_1fr]`,"aria-label":`Human node timeout`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Timeout kind`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a.humanTimeoutKind,onChange:e=>x(`humanTimeoutKind`,e.target.value),children:[(0,z.jsx)(`option`,{value:`none`,children:`No timeout`}),(0,z.jsx)(`option`,{value:`milliseconds`,children:`Milliseconds`}),(0,z.jsx)(`option`,{value:`seconds`,children:`Seconds`}),(0,z.jsx)(`option`,{value:`minutes`,children:`Minutes`}),(0,z.jsx)(`option`,{value:`iso8601`,children:`ISO-8601 duration`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Timeout value`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,type:a.humanTimeoutKind===`iso8601`?`text`:`number`,min:a.humanTimeoutKind===`iso8601`?void 0:1,placeholder:a.humanTimeoutKind===`iso8601`?`PT1H`:`60`,value:a.humanTimeoutValue,onChange:e=>x(`humanTimeoutValue`,e.target.value),disabled:a.humanTimeoutKind===`none`})]})]})]}):null,(0,z.jsx)(N1,{diagnostics:v,emptyLabel:`No diagnostics for selected node.`}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>{let r=ZEe(e.definition,t,a),o=YEe(n,a)?`state_edit`:_===`agent`||_===`human`?`prompt_edit`:`schema_edit`;i(r,`Saved node inspector edits for ${t}.`,{editTrigger:o})},disabled:r,children:[r?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save node inspector`]})]})]})}function $1({label:e,definition:t,value:n,onChange:r,allowEdgeWrites:i=!1}){let a=t1(t,n.readScope,[...n.reads,...n.writes]),o=i?X$:JEe,s=t1(t,n.writeScope,[...n.reads,...n.writes]),c=!!n.readPath.trim(),l=!!n.writePath.trim()&&(i||n.writeScope!==`edge`),u=(e,t)=>r({...n,[e]:t}),d=e=>{let t=e===`reads`?n.readScope:n.writeScope,i=(e===`reads`?n.readPath:n.writePath).trim();if(!i)return;let a=`${t}.${i}`,o=n[e];o.includes(a)||r({...n,[e]:[...o,a]})},f=(e,t)=>r({...n,[e]:n[e].filter(e=>e!==t)});return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,"aria-label":`${e} simple state mapping controls`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:[e,` simple state mappings`]}),(0,z.jsxs)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:[`Add simple scoped state reads and writes as Pibo Workflow IR `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`state.reads`}),` and `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`state.writes`}),` arrays. Complex state mapping DSLs remain raw Workflow IR only.`]})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[0.7fr_1fr_auto]`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Read scope`}),(0,z.jsx)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n.readScope,onChange:e=>u(`readScope`,e.target.value),children:X$.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),(0,z.jsx)(e0,{label:`Read path`,value:n.readPath,options:a,onChange:e=>u(`readPath`,e)}),(0,z.jsx)(`button`,{type:`button`,className:`self-end rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>d(`reads`),disabled:!c,children:`Add read`})]}),(0,z.jsx)(t0,{label:`Reads`,entries:n.reads,onRemove:e=>f(`reads`,e)}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[0.7fr_1fr_auto]`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Write scope`}),(0,z.jsx)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n.writeScope,onChange:e=>u(`writeScope`,e.target.value),children:o.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),(0,z.jsx)(e0,{label:`Write path`,value:n.writePath,options:s,onChange:e=>u(`writePath`,e)}),(0,z.jsx)(`button`,{type:`button`,className:`self-end rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>d(`writes`),disabled:!l,children:`Add write`})]}),(0,z.jsx)(t0,{label:`Writes`,entries:n.writes,onRemove:e=>f(`writes`,e)}),n.writeScope===`global`&&!n1(t).length?(0,z.jsx)(`div`,{className:`rounded-sm border border-amber-900/60 bg-amber-950/20 p-2 text-[11px] leading-5 text-amber-100`,children:`Declare global state fields in the workflow settings inspector before selecting global read/write paths.`}):null]})}function e0({label:e,value:t,options:n,onChange:r}){let i=t&&!n.includes(t)?[t,...n]:n;return(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>r(e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select path`}),i.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]})}function t0({label:e,entries:t,onRemove:n}){return(0,z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-semibold text-slate-400`,children:e}),t.length?(0,z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,z.jsxs)(`button`,{type:`button`,className:`rounded-full border border-slate-700 px-2 py-1 text-[11px] text-slate-300 transition hover:border-red-500/60 hover:text-red-100`,onClick:()=>n(e),title:`Remove ${e}`,children:[e,` ×`]},e))}):(0,z.jsxs)(`div`,{className:`text-[11px] text-slate-500`,children:[`No `,e.toLowerCase(),` declared.`]})]})}function uOe({draft:e,edgeId:t,edge:n,nodeIds:r,isSaving:i,onSaveDefinition:a}){let[o,s]=(0,R.useState)(()=>a1(n,r)),[c,l]=(0,R.useState)(),[u,d]=(0,R.useState)(),[f,p]=(0,R.useState)(!1),m=sOe(e.diagnostics,t),h=UDe(e.definition,n),g=m.some(e=>e.code===`WorkflowGraphError.incompatibleEdgePorts`),_=c?.options.find(e=>e.id===(c?.selectedRefId??o.guardHandler)),v=u?.options.find(e=>e.id===(u?.selectedRefId??o.adapterRef));(0,R.useEffect)(()=>{s(a1(n,r))},[n,t,r]),(0,R.useEffect)(()=>{p(!1)},[t]),(0,R.useEffect)(()=>{let e=!1;return Oye(o.guardHandler||void 0).then(t=>{e||l(t)}).catch(()=>void 0),()=>{e=!0}},[o.guardHandler]),(0,R.useEffect)(()=>{let e=!1;return oJ(o.adapterRef||void 0).then(t=>{e||d(t)}).catch(()=>void 0),()=>{e=!0}},[o.adapterRef]);let y=(e,t)=>{s(n=>({...n,[e]:t}))},b=()=>{let r=QEe(e.definition,t,o),i=Z$(n.state,o.stateAccess)?`state_edit`:`edge_edit`;a(r,`Saved edge inspector edits for ${t}.`,{editTrigger:i})};return(0,z.jsxs)(`details`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,open:!0,children:[(0,z.jsxs)(`summary`,{className:`cursor-pointer text-xs font-bold text-slate-200`,children:[`Edge inspector: `,t]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${o.kind} edge`}),(0,z.jsx)(P1,{label:`${m.length} diagnostics`})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Source node`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.sourceNodeId,onChange:e=>y(`sourceNodeId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select source`}),r.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Target node`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.targetNodeId,onChange:e=>y(`targetNodeId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select target`}),r.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Source port id`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.sourcePortId,onChange:e=>y(`sourcePortId`,e.target.value),placeholder:`default`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Target port id`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.targetPortId,onChange:e=>y(`targetPortId`,e.target.value),placeholder:`default`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Edge kind`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.kind,onChange:e=>y(`kind`,e.target.value),children:[(0,z.jsx)(`option`,{value:`data`,children:`data`}),(0,z.jsx)(`option`,{value:`control`,children:`control`}),(0,z.jsx)(`option`,{value:`error`,children:`error`}),(0,z.jsx)(`option`,{value:`resume`,children:`resume`})]})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Guard ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:c?.selectedRefId??o.guardHandler,onChange:e=>y(`guardHandler`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`No guard`}),c?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Guard priority`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.guardPriority,onChange:e=>y(`guardPriority`,e.target.value),placeholder:`optional integer`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300 md:col-span-2`,children:[(0,z.jsx)(`span`,{children:`Edge adapter ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:u?.selectedRefId??o.adapterRef,onChange:e=>y(`adapterRef`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`No edge adapter`}),u?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]})]}),_?.paramsSchema?(0,z.jsx)(o0,{label:`Guard params JSON`,schema:_.paramsSchema,value:o.guardParamsText,onChange:e=>y(`guardParamsText`,e)}):null,v?.paramsSchema?(0,z.jsx)(o0,{label:`Edge adapter params JSON`,schema:v.paramsSchema,value:o.adapterParamsText,onChange:e=>y(`adapterParamsText`,e)}):null,(0,z.jsx)($1,{label:`Edge`,definition:e.definition,value:o.stateAccess,onChange:e=>y(`stateAccess`,e),allowEdgeWrites:!0}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border px-3 py-2 text-xs font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 ${g?`border-amber-600/70 text-amber-100 hover:border-amber-400`:`border-slate-700 text-slate-300 hover:border-[#11a4d4]/60 hover:text-slate-100`}`,onClick:()=>p(!0),disabled:i||!h.sourcePort||!h.targetPort,children:[(0,z.jsx)(bs,{size:13}),g?`Fix incompatible edge with adapter`:`Open compatible edge adapter dialog`]}),f?(0,z.jsx)(dOe,{draft:e,edgeId:t,edge:n,edgePortDetails:h,isSaving:i,onClose:()=>p(!1),onSaveDefinition:a}):null,(0,z.jsx)(F1,{diagnostics:[...c?.diagnostics??[],...u?.diagnostics??[]]}),(0,z.jsx)(N1,{diagnostics:m,emptyLabel:`No diagnostics for selected edge.`}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:b,disabled:i||!o.sourceNodeId||!o.targetNodeId,children:[i?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save edge inspector`]})]})]})}function dOe({draft:e,edgeId:t,edge:n,edgePortDetails:r,isSaving:i,onClose:a,onSaveDefinition:o}){let[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(WDe(n)),[d,f]=(0,R.useState)(`loading`),[p,m]=(0,R.useState)();(0,R.useEffect)(()=>{let e=!1;return f(`loading`),m(void 0),oJ(l||void 0).then(t=>{e||(c(t),u(e=>e||(t.options[0]?.id??``)),f(`loaded`))}).catch(t=>{e||(m(t instanceof Error?t.message:`Failed to load compatible adapters`),f(`error`))}),()=>{e=!0}},[l]);let h=s?.options.find(e=>e.id===l),g=!!(h&&r.sourcePort&&r.targetPort&&d===`loaded`&&!i),_=async()=>{l&&(await o(GDe(e.definition,t,l),`Applied ${l} as edge adapter for ${t}.`,{editTrigger:`edge_edit`}),a())},v=async()=>{l&&(await o(KDe(e.definition,t,l),`Inserted adapter node for ${t} using ${l}.`,{editTrigger:`graph_edit`}),a())};return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`workflow-edge-adapter-dialog-title`,children:(0,z.jsxs)(`div`,{className:`max-h-[88vh] w-full max-w-3xl overflow-auto rounded-sm border border-slate-700 bg-[#101d22] p-4 shadow-2xl shadow-black/40`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(bs,{size:13}),`Compatible edge adapter dialog`]}),(0,z.jsxs)(`h4`,{id:`workflow-edge-adapter-dialog-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:[`Choose a registered adapter for `,t]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-500`,children:`The dialog shows the source output and target input schemas from the Pibo Workflow IR. Use a registered adapter as an explicit edge adapter, or insert a visible adapter node between the endpoints.`})]}),(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,onClick:a,children:`Close`})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 md:grid-cols-2`,children:[(0,z.jsx)(L1,{label:`From schema${r.sourceNodeId?` (${r.sourceNodeId})`:``}`,schema:r.sourcePort??null}),(0,z.jsx)(L1,{label:`To schema${r.targetNodeId?` (${r.targetNodeId})`:``}`,schema:r.targetPort??null})]}),(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border p-3 text-xs leading-5 ${r.directlyCompatible?`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`:`border-amber-700/70 bg-amber-950/30 text-amber-100`}`,children:r.directlyCompatible?`These ports are directly compatible. An adapter is optional and remains explicit if selected.`:`These ports are not directly compatible. Select a registered adapter instead of hidden LLM coercion or inline transformation code.`}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 text-xs`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Compatible registered adapter`}),(0,z.jsxs)(`select`,{"aria-label":`Compatible registered adapter`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:l,onChange:e=>u(e.target.value),disabled:d===`loading`||d===`error`||i,children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered adapter ref`}),s?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),d===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:p??`Failed to load compatible adapters.`}):null,(0,z.jsx)(F1,{diagnostics:s?.diagnostics??[]}),h?(0,z.jsx)(I1,{option:h,badge:`selected adapter`}):null,(0,z.jsxs)(`div`,{className:`grid gap-2`,"aria-label":`Compatible adapter candidates`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Compatible adapter candidates`}),s?.options.map(e=>(0,z.jsx)(I1,{option:e,badge:`compatible adapter`},e.id))]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void _(),disabled:!g,children:[(0,z.jsx)(bs,{size:13}),`Use as edge adapter`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void v(),disabled:!g,children:[(0,z.jsx)(Ps,{size:13}),`Insert adapter node`]})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:[`Both actions persist Pibo Workflow IR only. Edge adapters store `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`adapter.transform.id`}),`; inserted adapter nodes store a visible deterministic adapter handler ref.`]})]})]})})}function n0({label:e,kind:t,description:n,schemaText:r,onKindChange:i,onDescriptionChange:a,onSchemaChange:o}){return(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>i(e.target.value),children:[(0,z.jsx)(`option`,{value:`text`,children:`text`}),(0,z.jsx)(`option`,{value:`json`,children:`json`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Description`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n,onChange:e=>a(e.target.value),placeholder:`Optional port description`})]}),t===`json`?(0,z.jsx)(i0,{label:`${e} raw JSON schema`,value:r,onChange:o}):null]})}function r0({label:e,kind:t,description:n,schemaText:r,onKindChange:i,onDescriptionChange:a,onSchemaChange:o}){return(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>i(e.target.value),children:[(0,z.jsx)(`option`,{value:`none`,children:`inherit/default`}),(0,z.jsx)(`option`,{value:`text`,children:`text`}),(0,z.jsx)(`option`,{value:`json`,children:`json`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Description`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n,onChange:e=>a(e.target.value),disabled:t===`none`,placeholder:`Optional port description`})]}),t===`json`?(0,z.jsx)(i0,{label:`${e} raw JSON schema`,value:r,onChange:o}):null]})}function fOe({fields:e,onAddField:t,onRemoveField:n,onUpdateField:r}){return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Workflow global state fields`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Workflow global state fields`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Declare simple global state paths for node and edge state mapping dropdowns. State schema changes run draft validation and may invalidate connected graph diagnostics without blocking draft save.`})]}),e.length?e.map((e,t)=>(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#151f24]/70 p-2 md:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Global state path`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:e.path,onChange:e=>r(t,`path`,e.target.value),placeholder:`projectGoal`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Merge policy`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:e.mergeKind,onChange:e=>r(t,`mergeKind`,e.target.value),children:[(0,z.jsx)(`option`,{value:`none`,children:`No merge policy`}),(0,z.jsx)(`option`,{value:`replace`,children:`replace`}),(0,z.jsx)(`option`,{value:`append`,children:`append`}),(0,z.jsx)(`option`,{value:`shallowMerge`,children:`shallowMerge`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300 md:col-span-2`,children:[(0,z.jsx)(`span`,{children:`Description`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:e.description,onChange:e=>r(t,`description`,e.target.value),placeholder:`Optional state description`})]}),(0,z.jsx)(`div`,{className:`md:col-span-2`,children:(0,z.jsx)(i0,{label:`Global state ${e.path||t+1} schema JSON`,value:e.schemaText,onChange:e=>r(t,`schemaText`,e)})}),(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-red-500/70 hover:text-red-100`,onClick:()=>n(t),children:`Remove state field`})]},`${t}:${e.path}`)):(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 p-2 text-[11px] leading-5 text-slate-500`,children:`No global state fields declared. Local and edge path dropdowns remain available for simple node-local state and edge payload access.`}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,onClick:t,children:[(0,z.jsx)(Ps,{size:13}),`Add global state field`]})]})}function i0({label:e,value:t,onChange:n}){return(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsx)(`textarea`,{className:`min-h-36 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 font-mono text-[11px] leading-5 text-slate-100`,value:t,onChange:e=>n(e.target.value),placeholder:JSON.stringify(Y$,null,2),spellCheck:!1,"aria-label":e}),(0,z.jsx)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:`Raw JSON Schema subset only. Unsupported keywords return workflow diagnostics; no Zod, AJV, or form-builder schema layer is introduced.`})]})}function a0({label:e,value:t,onChange:n}){return(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsx)(`textarea`,{className:`min-h-16 rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>n(e.target.value),placeholder:`One value per line`})]})}function o0({label:e,schema:t,value:n,onChange:r}){return(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-2`,"aria-label":e,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-slate-500`,children:e}),(0,z.jsx)(L1,{label:`paramsSchema`,schema:t}),(0,z.jsx)(`textarea`,{className:`min-h-24 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 font-mono text-[11px] leading-5 text-slate-100`,value:n,onChange:e=>r(e.target.value),placeholder:`{}`,"aria-label":`${e} value`}),(0,z.jsx)(`div`,{className:`text-[11px] leading-5 text-slate-500`,children:`Params save as data on the selected registry ref. No inline code path is created.`})]})}function pOe(e){let t=new Map;for(let n of e){let e=t.get(n.id);if(e){e.records.push(n),n.status===`published`&&e.records[0]?.status!==`published`&&(e.title=n.title,e.source=n.source);continue}t.set(n.id,{workflowId:n.id,title:n.title,source:n.source,records:[n]})}return[...t.values()]}function mOe(e){return e.status===`published`?`Published workflow version — selectable for Project sessions and safe to duplicate into UI drafts.`:e.status===`archived`?`Archived workflow version — shown for lifecycle history but hidden from default Project session creation choices.`:e.status===`deleted`?`Deleted workflow definition — historical runs must render from immutable snapshots instead of live catalog links.`:`Draft workflow version — not published and unavailable for Project session creation.`}function s0(e,t){return e.actions.includes(t)}function hOe(e){switch(e){case`view`:return`View`;case`duplicate`:return`Duplicate`;case`create_project_session`:return`Create Project session`;case`edit_draft`:return`Edit draft`;case`validate`:return`Validate`;case`publish`:return`Publish`;case`create_next_draft`:return`Create next draft`;case`version_history`:return`Version history`;case`archive`:return`Archive`;case`delete`:return`Delete`}}function gOe({activeDraftId:e}){let[t,n]=(0,R.useState)([]),[r,i]=(0,R.useState)(`loading`),[a,o]=(0,R.useState)(),[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(),[d,f]=(0,R.useState)(),[p,m]=(0,R.useState)(),[h,g]=(0,R.useState)(),[_,v]=(0,R.useState)(``),[y,b]=(0,R.useState)(),x=!!(s||l||d||p),S=(0,R.useCallback)(async()=>{i(`loading`),o(void 0);try{n((await lJ()).options),i(`loaded`)}catch(e){o(e instanceof Error?e.message:`Failed to load workflow version history`),i(`error`)}},[]);(0,R.useEffect)(()=>{S()},[S]);let C=(0,R.useMemo)(()=>pOe(t),[t]),w=async(e,t)=>{c(w1(e,t)),b(void 0);try{D1((await Lye(e,{version:t})).builderPath)}catch(e){b(e instanceof Error?e.message:`Failed to duplicate workflow into a draft`),c(void 0)}},T=async(e,t)=>{u(w1(e,t)),b(void 0);try{D1((await Rye(e,{version:t})).builderPath)}catch(e){b(e instanceof Error?e.message:`Failed to create next-version draft`),u(void 0)}},E=(e,t)=>{v(``),b(void 0),g({kind:`archive`,workflowId:e,title:t})},D=(e,t)=>{v(``),b(void 0),g({kind:`delete`,workflowId:e,title:t})},O=async()=>{if(!h||h.kind!==`archive`)return;let{workflowId:e}=h;f(e),b(void 0);try{await zye(e),g(void 0),await S()}catch(e){b(e instanceof Error?e.message:`Failed to archive workflow`)}finally{f(void 0)}},k=async()=>{if(!h||h.kind!==`delete`)return;let{workflowId:e}=h;m(e),b(void 0);try{await Bye(e,{confirmWorkflowId:_}),g(void 0),v(``),await S()}catch(e){b(e instanceof Error?e.message:`Failed to delete workflow`)}finally{m(void 0)}};return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:`UI draft`}),(0,z.jsx)(`h3`,{className:`mt-1 text-sm font-bold text-slate-100`,children:`Starter UI draft`}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:`A draft row opens the builder route and loads a partial Pibo Workflow IR wrapper with diagnostics.`})]}),(0,z.jsx)(`a`,{className:`shrink-0 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100`,href:vDe(_De),children:`Open draft`})]}),e===`v2-starter-draft`?(0,z.jsx)(`div`,{className:`mt-3 text-[11px] font-semibold text-emerald-300`,children:`Currently open in the builder.`}):null]}),(0,z.jsx)(bOe,{target:h,busy:x,deleteConfirmWorkflowId:_,onDeleteConfirmChange:v,onCancel:()=>{g(void 0),v(``)},onConfirmArchive:()=>void O(),onConfirmDelete:()=>void k()}),(0,z.jsxs)(`div`,{className:`grid gap-3`,"aria-label":`Workflow version history`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:[(0,z.jsx)(hs,{size:13}),`Version history`]}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Published versions are listed in deterministic workflow/version order. Only published rows are selectable for Project sessions; archived rows stay visible as history while deleted workflows render from Project snapshots.`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 px-2 py-1 text-[11px] font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void S(),disabled:r===`loading`,children:[r===`loading`?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ls,{size:12}),`Refresh`]})]}),r===`loading`?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4 text-xs text-slate-400`,"aria-live":`polite`,children:[(0,z.jsx)(Cs,{size:14,className:`animate-spin text-[#11a4d4]`}),`Loading workflow version history…`]}):null,r===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:a??`Failed to load workflow version history.`}):null,r===`loaded`&&C.length===0?(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 bg-[#101d22]/70 p-4 text-xs text-slate-500`,children:`No workflow versions are registered yet.`}):null,r===`loaded`?C.map(e=>(0,z.jsx)(_Oe,{group:e,busy:x,duplicatingKey:s,editingKey:l,archivingWorkflowId:d,deletingWorkflowId:p,onDuplicate:w,onEditPublished:T,onArchive:E,onDelete:D},e.workflowId)):null]}),y?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:y}):null]})}function _Oe({group:e,busy:t,duplicatingKey:n,editingKey:r,archivingWorkflowId:i,deletingWorkflowId:a,onDuplicate:o,onEditPublished:s,onArchive:c,onDelete:l}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,"aria-label":`Version history for ${e.workflowId}`,children:[(0,z.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`div`,{className:`font-semibold text-slate-100`,children:e.title}),(0,z.jsx)(P1,{label:`${e.records.length} version${e.records.length===1?``:`s`}`}),(0,z.jsx)(P1,{label:`${e.source} source`})]}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-500`,children:e.workflowId})]})}),(0,z.jsx)(`div`,{className:`mt-3 grid gap-2`,children:e.records.map(e=>(0,z.jsx)(vOe,{record:e,busy:t,duplicatingKey:n,editingKey:r,archivingWorkflowId:i,deletingWorkflowId:a,onDuplicate:o,onEditPublished:s,onArchive:c,onDelete:l},w1(e.id,e.version)))})]})}function vOe({record:e,busy:t,duplicatingKey:n,editingKey:r,archivingWorkflowId:i,deletingWorkflowId:a,onDuplicate:o,onEditPublished:s,onArchive:c,onDelete:l}){let u=w1(e.id,e.version),d=e.status===`published`,f=s0(e,`create_next_draft`),p=s0(e,`duplicate`),m=s0(e,`create_project_session`),h=s0(e,`view`),g=d&&s0(e,`archive`),_=d&&s0(e,`delete`);return(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsxs)(`div`,{className:`font-mono text-[11px] font-semibold text-slate-200`,children:[e.id,`@`,e.version]}),(0,z.jsx)(P1,{label:e.status}),(0,z.jsx)(P1,{label:`${e.source} source`}),e.tags.map(e=>(0,z.jsx)(P1,{label:e},e))]}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,(0,z.jsx)(`div`,{className:`mt-2 text-[11px] ${d?`text-emerald-300`:`text-amber-200`}`,children:mOe(e)}),(0,z.jsx)(yOe,{actions:e.actions})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2`,children:[f?(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void s(e.id,e.version),disabled:t,children:[r===u?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(vs,{size:13}),`Edit published`]}):null,p?(0,z.jsxs)(`button`,{type:`button`,className:`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-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void o(e.id,e.version),disabled:t,children:[n===u?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Qo,{size:13}),`Duplicate to draft`]}):null,m?(0,z.jsxs)(`a`,{className:`inline-flex items-center justify-center gap-1 rounded-sm border border-emerald-700/70 px-3 py-1.5 text-xs font-semibold text-emerald-100 transition hover:border-emerald-500 hover:text-emerald-50`,href:`/apps/chat/projects`,children:[(0,z.jsx)(As,{size:13}),`Create Project session`]}):(0,z.jsx)(`div`,{className:`max-w-44 rounded-sm border border-amber-800/70 bg-amber-950/20 p-2 text-[11px] text-amber-100`,children:`Unavailable for Project session selection.`}),h?(0,z.jsxs)(`a`,{className:`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-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,href:E1(e.id,e.version),children:[(0,z.jsx)(rs,{size:13}),`View details`]}):null,g?(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-amber-700/70 px-3 py-1.5 text-xs font-semibold text-amber-100 transition hover:border-amber-500 hover:text-amber-50 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>c(e.id,e.title),disabled:t,children:[i===e.id?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(To,{size:13}),`Archive workflow`]}):null,_?(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-red-800/80 px-3 py-1.5 text-xs font-semibold text-red-100 transition hover:border-red-500 hover:text-red-50 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>l(e.id,e.title),disabled:t,children:[a===e.id?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(qs,{size:13}),`Delete workflow`]}):null]})]})})}function yOe({actions:e}){return(0,z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,"aria-label":`Workflow Library source/status actions`,children:e.map(e=>(0,z.jsx)(P1,{label:hOe(e)},e))})}function bOe({target:e,busy:t,deleteConfirmWorkflowId:n,onDeleteConfirmChange:r,onCancel:i,onConfirmArchive:a,onConfirmDelete:o}){if(!e)return null;let s=e.kind===`delete`,c=n.trim()===e.workflowId;return(0,z.jsx)(`div`,{className:`rounded-sm border p-4 text-xs leading-5 ${s?`border-red-900/70 bg-red-950/25 text-red-100`:`border-amber-800/70 bg-amber-950/20 text-amber-100`}`,role:`region`,"aria-label":`${s?`Delete`:`Archive`} workflow confirmation`,children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em]`,children:[(0,z.jsx)(Js,{size:13}),`Confirm `,s?`delete`:`archive`]}),(0,z.jsx)(`h3`,{className:`mt-1 text-sm font-bold text-slate-100`,children:e.title}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:e.workflowId}),s?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`mt-3`,children:`Deleting tombstones the live workflow identity. It removes this workflow from the default catalog, workflow pickers, duplicate/edit/publish/archive actions, and new Project session creation.`}),(0,z.jsx)(`p`,{className:`mt-2`,children:`Historical Project runs remain inspectable from immutable snapshots and show a definition-deleted state instead of a broken live catalog link.`}),(0,z.jsxs)(`label`,{className:`mt-3 block text-[11px] font-semibold text-red-100`,children:[`Type the workflow id to confirm delete`,(0,z.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),className:`mt-1 w-full rounded-sm border border-red-900/70 bg-[#101d22] px-2 py-1.5 font-mono text-xs text-slate-100 outline-none focus:border-red-400`,placeholder:e.workflowId,disabled:t})]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`mt-3`,children:`Archiving applies to the whole workflow identity. It hides this workflow from the default catalog and Project workflow selection lists.`}),(0,z.jsx)(`p`,{className:`mt-2`,children:`Published versions stay available only through archive filters and historical run links, and historical Project runs continue to render from their snapshots.`})]})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-300 transition hover:border-slate-500 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:i,disabled:t,children:`Cancel`}),(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border px-3 py-1.5 text-xs font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-red-700 text-red-100 hover:border-red-400`:`border-amber-600 text-amber-100 hover:border-amber-400`}`,onClick:s?o:a,disabled:t||s&&!c,children:s?`Delete workflow`:`Archive workflow`})]})]})})}var c0=`WorkflowBuilderWarning.invalidRawIrText`;function xOe({draft:e,onDraftChange:t}){let n=(0,R.useMemo)(()=>JSON.stringify(e.definition,null,2),[e.definition]),[r,i]=(0,R.useState)(n),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(`idle`),[l,u]=(0,R.useState)(),d=e.diagnostics.filter(e=>e.code===c0);(0,R.useEffect)(()=>{a||i(n)},[n,a]);let f=async()=>{c(`saving`),u(void 0);try{let n=await uJ(e.draftId,{rawDefinitionText:r,editTrigger:`raw_ir_edit`});if(t(n.draft),n.diagnostics.some(e=>e.code===c0)){o(!0),c(`warning`),u(`Raw Workflow IR text was not saved; the last valid draft object remains unchanged.`);return}i(JSON.stringify(n.draft.definition,null,2)),o(!1),c(`saved`),u(`Saved raw Workflow IR to the draft. Validation state: ${n.validation.validationState}.`)}catch(e){c(`error`),u(e instanceof Error?e.message:`Failed to save raw Workflow IR text`)}};return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-label":`Raw Pibo Workflow IR editor panel`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Raw Pibo Workflow IR editor`}),(0,z.jsx)(`h4`,{className:`mt-1 text-sm font-bold text-slate-100`,children:`Safe raw Workflow IR sync`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-400`,children:`Edit only Pibo Workflow IR JSON. Saving valid JSON parses into the same draft object used by the graph and inspectors. Invalid JSON or non-object text returns a warning diagnostic and keeps the last valid draft object unchanged; raw XState JSON is not exposed here.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`last valid rev ${e.revision}`}),a?(0,z.jsx)(P1,{label:`unsaved raw text`}):null]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.72fr)]`,children:[(0,z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,z.jsx)(`label`,{className:`text-[11px] font-semibold uppercase tracking-[0.12em] text-slate-500`,htmlFor:`workflow-raw-ir-editor`,children:`Editable Pibo Workflow IR JSON`}),(0,z.jsx)(`textarea`,{id:`workflow-raw-ir-editor`,"aria-label":`Raw Pibo Workflow IR editor`,className:`min-h-[26rem] rounded-sm border border-slate-800 bg-[#101d22] p-3 font-mono text-[11px] leading-5 text-slate-100 outline-none transition focus:border-[#11a4d4]`,spellCheck:!1,value:r,onChange:e=>{i(e.target.value),o(!0),c(`idle`),u(void 0)}}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-emerald-600/70 px-3 py-1.5 text-xs font-semibold text-emerald-200 transition hover:border-emerald-400 hover:text-white disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void f(),disabled:s===`saving`,children:[s===`saving`?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save raw IR`]}),(0,z.jsxs)(`button`,{type:`button`,className:`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-300 transition hover:border-slate-500 hover:text-white`,onClick:()=>{i(n),o(!1),c(`idle`),u(`Reset the editor from the last valid Pibo Workflow IR object.`)},disabled:s===`saving`,children:[(0,z.jsx)(Ls,{size:13}),`Reset from current draft`]})]}),l?(0,z.jsx)(`div`,{className:`rounded-sm border p-3 text-xs leading-5 ${s===`error`?`border-red-900/70 bg-red-950/40 text-red-200`:s===`warning`?`border-amber-700/70 bg-amber-950/30 text-amber-100`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,role:s===`error`||s===`warning`?`alert`:`status`,children:l}):null,d.length?(0,z.jsx)(N1,{diagnostics:d,emptyLabel:`No raw IR parse diagnostics.`}):null]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`mb-2 text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Last valid Pibo Workflow IR object`}),(0,z.jsx)(`pre`,{"aria-label":`Pibo Workflow IR draft`,className:`max-h-[32rem] overflow-auto rounded-sm border border-slate-800 bg-[#101d22] p-3 text-[11px] leading-5 text-slate-200`,children:n})]})]})]})}function SOe({draftId:e,viewWorkflowId:t,viewWorkflowVersion:n}){return(0,z.jsx)(`main`,{className:`h-full min-h-0 overflow-auto bg-[#101d22]`,children:(0,z.jsxs)(`section`,{className:`mx-auto flex w-full max-w-6xl flex-col gap-6 p-6 max-[720px]:p-4`,"aria-labelledby":`workflows-title`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24] p-5 shadow-lg shadow-black/20`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.18em] text-[#11a4d4]`,children:`Workflow UI Authoring V2`}),(0,z.jsx)(`h1`,{id:`workflows-title`,className:`mt-2 text-2xl font-extrabold tracking-tight text-slate-100`,children:`Workflows`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-sm leading-6 text-slate-400`,children:`Browse workflow definitions, duplicate published workflows into UI drafts, and open draft wrappers that edit Pibo Workflow IR from the authenticated Chat Web surface.`})]}),(0,z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[0.9fr_1.1fr]`,children:[(0,z.jsx)(f0,{icon:jo,eyebrow:`Global catalog`,title:`Workflow Library`,description:`Open UI drafts or duplicate published workflow versions into a draft before editing.`,children:(0,z.jsx)(gOe,{activeDraftId:e})}),(0,z.jsx)(f0,{icon:vs,eyebrow:`Visual authoring`,title:`Workflow Builder`,description:`Load a UI draft wrapper and keep Pibo Workflow IR as the editable source of truth.`,children:e?(0,z.jsx)(wOe,{draftId:e}):t&&n?(0,z.jsx)(xDe,{workflowId:t,workflowVersion:n}):(0,z.jsx)(COe,{})})]}),(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#151f24] p-4 text-xs text-slate-400 md:grid-cols-4`,children:[(0,z.jsx)(p0,{icon:Lo,label:`Pibo Workflow IR remains the source of truth`}),(0,z.jsx)(p0,{icon:Qo,label:`Code workflows can be duplicated into UI drafts`}),(0,z.jsx)(p0,{icon:Gs,label:`Workflow capabilities are registered refs only`}),(0,z.jsx)(p0,{icon:vs,label:`XState stays a read-only visualization projection`})]}),(0,z.jsx)(TOe,{})]})})}function COe(){return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,children:[(0,z.jsx)(kOe,{title:`Open a draft to start authoring`,description:`Use the Workflow Library draft row or Duplicate to draft action. The builder route will load a draft wrapper around Pibo Workflow IR, not raw XState source.`}),(0,z.jsx)(l0,{}),(0,z.jsx)(CDe,{})]})}function wOe({draftId:e}){let[t,n]=(0,R.useState)(),[r,i]=(0,R.useState)(`loading`),[a,o]=(0,R.useState)();return(0,R.useEffect)(()=>{let t=!1;return i(`loading`),o(void 0),Pye(e).then(e=>{t||(n(e.draft),i(`loaded`))}).catch(e=>{t||(o(e instanceof Error?e.message:`Failed to load workflow draft`),i(`error`))}),()=>{t=!0}},[e]),r===`loading`?(0,z.jsxs)(`div`,{className:`flex w-full items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4 text-sm text-slate-300`,"aria-live":`polite`,children:[(0,z.jsx)(Cs,{size:16,className:`animate-spin text-[#11a4d4]`}),`Loading workflow draft `,e,`…`]}):r===`error`||!t?(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-4 text-sm leading-6 text-red-200`,role:`alert`,children:[(0,z.jsx)(`div`,{className:`font-bold`,children:`Could not load workflow draft`}),(0,z.jsx)(`div`,{className:`mt-1 text-xs`,children:a??`Draft '${e}' was not found.`})]}):(0,z.jsx)(EOe,{draft:t})}function TOe(){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/60 bg-amber-950/15 p-4 text-xs leading-5 text-amber-100`,"aria-label":`Workflow V2 explicit non-goals`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-amber-200`,children:[(0,z.jsx)(Gs,{size:13}),`V2 scope boundary`]}),(0,z.jsx)(`p`,{className:`mt-2 text-amber-100/90`,children:`Workflows V2 is an authoring surface for Pibo Workflow IR and registered capability references, not a code or product import/export surface.`}),(0,z.jsxs)(`ul`,{className:`mt-3 grid gap-1 text-[11px] text-amber-100/75 md:grid-cols-2`,children:[(0,z.jsx)(`li`,{children:`No inline TypeScript, JavaScript, shell, eval, arbitrary executable code, or raw handler body authoring.`}),(0,z.jsx)(`li`,{children:`No raw XState editing, workflow templates, workflow slash commands, or workflow tools for agents.`}),(0,z.jsx)(`li`,{children:`No YAML/JSON product import/export or TypeScript export path from UI-authored workflows.`}),(0,z.jsx)(`li`,{children:`No Zod schema authoring; schema edits remain constrained to Pibo Workflow IR and registered metadata.`})]})]})}function l0(){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-emerald-900/60 bg-emerald-950/15 p-4 text-xs leading-5 text-emerald-100`,"aria-label":`Registered capability security boundary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-emerald-300`,children:[(0,z.jsx)(Gs,{size:13}),`Registered capability security boundary`]}),(0,z.jsx)(`p`,{className:`mt-2 text-emerald-100/90`,children:`V2 authoring composes registered refs only: non-archived Agent profiles, code handlers, adapters, guards, nested workflows, human actions, and prompt assets.`}),(0,z.jsxs)(`ul`,{className:`mt-3 grid gap-1 text-[11px] text-emerald-100/75`,children:[(0,z.jsx)(`li`,{children:`Existing Chat Web auth plus Project and Pibo Session visibility rules still gate workflow catalog, Project workflow sessions, snapshots, lifecycle events, prompt assets, and human actions.`}),(0,z.jsx)(`li`,{children:`Agent nodes select profile refs only; the UI does not grant extra tools, skills, context files, native tools, MCP servers, or compute-worker access beyond the selected runtime profile.`}),(0,z.jsx)(`li`,{children:`No inline JavaScript, TypeScript, shell, eval, arbitrary executable nodes, or raw handler bodies are created by the UI.`}),(0,z.jsx)(`li`,{children:`Incompatible schemas must use a visible registered adapter node or edge adapter; hidden LLM coercion is not used.`}),(0,z.jsx)(`li`,{children:`XState remains projection-only; Pibo Workflow IR is the persisted source of truth.`}),(0,z.jsx)(`li`,{children:`Workflow inputs, outputs, prompts, prompt assets, state, edge payloads, snapshots, and human action payloads remain sensitive workflow data; normal diagnostics expose only sanitized metadata.`})]})]})}function EOe({draft:e}){let[t,n]=(0,R.useState)(e),[r,i]=(0,R.useState)(e.versionIntent),[a,o]=(0,R.useState)(`idle`),[s,c]=(0,R.useState)(),l=a===`validating`||a===`publishing`,u=t.validation?.errorCount??t.diagnostics.filter(e=>e.severity===`error`).length,d=t.validation?.warningCount??t.diagnostics.filter(e=>e.severity===`warning`).length,f=t.validation?.blocksPublish===!0||u>0;(0,R.useEffect)(()=>{n(e),i(e.versionIntent),o(`idle`),c(void 0)},[e]);let p=async()=>{o(`validating`),c(void 0);try{let e=await Fye(t.draftId);n(e.draft),i(e.draft.versionIntent),o(`validated`),c(`Draft validation ${e.validation.ok?`passed`:`returned diagnostics`}. Publish remains a separate action.`)}catch(e){o(`error`),c(e instanceof Error?e.message:`Failed to validate workflow draft`)}},m=async()=>{o(`publishing`),c(void 0);try{let e=await Iye(t.draftId,{versionIntent:r});n(e.draft),i(e.draft.versionIntent),o(`published`),c(e.publishedVersion?`${e.message??`Published workflow draft.`} Definition hash ${e.publishedVersion.definitionHash}.`:e.message??`Publish validation passed.`)}catch(e){o(`error`),c(e instanceof Error?e.message:`Failed to publish workflow draft`)}};return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:`Loaded UI draft`}),(0,z.jsx)(`h3`,{className:`mt-1 text-lg font-bold text-slate-100`,children:String(t.definition.title??t.workflowId)}),(0,z.jsxs)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-500`,children:[`Builder route `,(0,z.jsxs)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:[`/workflows/drafts/`,t.draftId]}),` loaded a draft wrapper around partial Pibo Workflow IR.`]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${t.source} source`}),(0,z.jsx)(P1,{label:t.status}),(0,z.jsx)(P1,{label:t.validationState}),(0,z.jsx)(P1,{label:`rev ${t.revision}`})]})]}),(0,z.jsxs)(`div`,{className:`grid gap-3 text-xs md:grid-cols-2`,"aria-label":`Workflow draft metadata`,children:[(0,z.jsx)(d0,{label:`Draft id`,value:t.draftId}),(0,z.jsx)(d0,{label:`Workflow id`,value:t.workflowId}),(0,z.jsx)(d0,{label:`Base workflow`,value:t.baseWorkflowId&&t.baseWorkflowVersion?`${t.baseWorkflowId}@${t.baseWorkflowVersion}`:`new UI draft`}),(0,z.jsx)(d0,{label:`Next version path`,value:t.targetWorkflowVersion??`not assigned yet`}),(0,z.jsx)(d0,{label:`Version intent`,value:t.versionIntent})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-label":`Workflow publish version panel`,children:[(0,z.jsxs)(`div`,{id:`workflow-publish-gate`,className:`mb-3 rounded-sm border p-3 text-xs leading-5 ${f?`border-amber-700/70 bg-amber-950/30 text-amber-100`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,"aria-label":`Workflow publish gate`,role:`status`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:f?`Publish blocked by draft diagnostics`:`Publish gate ready`}),(0,z.jsx)(`p`,{className:`mt-1`,children:f?`Publish is disabled because ${u} error diagnostic${u===1?``:`s`} ${u===1?`remains`:`remain`}. Draft save remains allowed while you fix errors; before-publish validation also requires workflow input/output ports and at least one node.`:d>0?`Warnings do not block publishing. Before-publish validation still runs and will block if workflow input/output ports, graph nodes, or registered refs are invalid.`:`No blocking diagnostics are present. Before-publish validation will run again before creating an immutable workflow version.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Publish version intent`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-400`,children:`Default publish increments the patch version. Choose minor or major when the release scope needs a larger semantic version bump.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Version bump intent`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-xs text-slate-100 outline-none transition focus:border-[#11a4d4]`,value:r,onChange:e=>i(e.target.value),disabled:l,"aria-label":`Version bump intent`,children:[(0,z.jsx)(`option`,{value:`patch`,children:`Patch version bump (default)`}),(0,z.jsx)(`option`,{value:`minor`,children:`Minor version bump`}),(0,z.jsx)(`option`,{value:`major`,children:`Major version bump`})]})]}),(0,z.jsxs)(`button`,{type:`button`,className:`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 transition hover:border-[#11a4d4] hover:text-white disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void p(),disabled:l,children:[a===`validating`?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Ls,{size:13}),`Validate draft`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-emerald-600/70 px-3 py-1.5 text-xs font-semibold text-emerald-200 transition hover:border-emerald-400 hover:text-white disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void m(),disabled:l||f,"aria-describedby":`workflow-publish-gate`,children:[a===`publishing`?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Lo,{size:13}),`Publish draft`]})]})]}),s?(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border p-3 text-xs leading-5 ${a===`error`?`border-red-900/70 bg-red-950/40 text-red-200`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,role:a===`error`?`alert`:`status`,children:s}):null]}),(0,z.jsx)(l0,{}),(0,z.jsx)(zDe,{draft:t,onDraftChange:n,renderInspectors:e=>(0,z.jsx)(aOe,{...e})}),(0,z.jsx)(DOe,{draft:t}),(0,z.jsx)(xOe,{draft:t,onDraftChange:n}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Raw XState source is not opened as an editable document. XState remains projection-only; the editable source is the Pibo Workflow IR shown above and in the raw Pibo Workflow IR editor.`})]})}function DOe({draft:e}){let t=e.validation,n=t?.errorCount??e.diagnostics.filter(e=>e.severity===`error`).length,r=t?.warningCount??e.diagnostics.filter(e=>e.severity===`warning`).length,i=t?.infoCount??e.diagnostics.filter(e=>e.severity===`info`).length;return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-label":`Workflow validation panel`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Validation panel`}),(0,z.jsx)(`h4`,{className:`mt-1 text-sm font-bold text-slate-100`,children:`Structured draft diagnostics`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-400`,children:`Draft validation reports sanitized diagnostic fields from the Workflow IR pipeline. Publish remains gated by blocking error diagnostics and the backend before-publish route.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${n} errors`}),(0,z.jsx)(P1,{label:`${r} warnings`}),(0,z.jsx)(P1,{label:`${i} info`})]})]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs md:grid-cols-3`,"aria-label":`Workflow validation summary`,children:[(0,z.jsx)(d0,{label:`Validation state`,value:e.validationState}),(0,z.jsx)(d0,{label:`Last trigger`,value:t?.trigger??`not checked`}),(0,z.jsx)(d0,{label:`Checked at`,value:t?.checkedAt??`not checked`}),(0,z.jsx)(d0,{label:`Publish gate`,value:t?.blocksPublish?`blocked`:`not blocked`}),(0,z.jsx)(d0,{label:`Run gate`,value:t?.blocksRun?`blocked`:`not blocked`}),(0,z.jsx)(d0,{label:`Diagnostic count`,value:String(e.diagnostics.length)})]}),e.diagnostics.length?(0,z.jsx)(OOe,{draft:e}):(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border border-emerald-900/60 bg-emerald-950/20 p-3 text-xs text-emerald-200`,children:`No validation diagnostics returned by the draft pipeline.`})]})}function OOe({draft:e}){return(0,z.jsx)(`div`,{className:`mt-3 grid gap-2`,"aria-label":`Workflow structured diagnostics`,children:e.diagnostics.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:13}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(u0,{label:`Severity`,value:e.severity}),(0,z.jsx)(u0,{label:`Path`,value:e.path}),(0,z.jsx)(u0,{label:`Node`,value:e.nodeId}),(0,z.jsx)(u0,{label:`Edge`,value:e.edgeId}),(0,z.jsx)(u0,{label:`Registry ref`,value:e.registryRef})]}),e.hint?(0,z.jsx)(`div`,{className:`mt-2 text-amber-200/80`,children:e.hint}):null]},`${e.code}:${e.path??e.nodeId??e.edgeId??e.registryRef??`workflow`}`))})}function u0({label:e,value:t}){return t?(0,z.jsxs)(`span`,{className:`rounded-sm border border-amber-700/50 bg-amber-950/40 px-2 py-0.5`,children:[(0,z.jsxs)(`span`,{className:`font-semibold text-amber-200/80`,children:[e,`:`]}),` `,(0,z.jsx)(`code`,{children:t})]}):null}function d0({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-slate-500`,children:e}),(0,z.jsx)(`div`,{className:`mt-1 break-all font-mono text-[11px] text-slate-200`,children:t})]})}function f0({icon:e,eyebrow:t,title:n,description:r,children:i}){return(0,z.jsxs)(`section`,{className:`flex min-h-72 flex-col rounded-sm border border-slate-800 bg-[#151f24] p-5 shadow-lg shadow-black/20`,children:[(0,z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,z.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-sm border border-[#11a4d4]/35 bg-[#11a4d4]/10 text-[#11a4d4]`,children:(0,z.jsx)(e,{size:18})}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:t}),(0,z.jsx)(`h2`,{className:`mt-1 text-lg font-bold text-slate-100`,children:n}),(0,z.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-slate-400`,children:r})]})]}),(0,z.jsx)(`div`,{className:`mt-5 flex flex-1`,children:i})]})}function kOe({title:e,description:t}){return(0,z.jsxs)(`div`,{className:`flex w-full flex-col justify-center rounded-sm border border-dashed border-slate-700 bg-[#101d22]/70 p-4 text-center`,children:[(0,z.jsx)(`div`,{className:`text-sm font-semibold text-slate-200`,children:e}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:t})]})}function p0({icon:e,label:t}){return(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/60 px-3 py-2`,children:[(0,z.jsx)(e,{size:14,className:`shrink-0 text-[#11a4d4]`}),(0,z.jsx)(`span`,{children:t})]})}function m0(e,t=`new-agent`){return{displayName:t,description:``,nativeTools:[],skills:w0(e,`pi-agent-harness`)?[`pi-agent-harness`]:[],contextFiles:[],subagents:[],mcpServers:[],piPackages:[],mainModel:void 0,subagentModel:void 0,thinkingLevel:void 0,mainThinkingLevel:void 0,subagentThinkingLevel:void 0,fast:!1,mainFast:!1,subagentFast:!1,builtinTools:`default`,builtinToolNames:[...b0],autoContextFiles:!0,runControl:!1,brokenContextFiles:[],hardPinnedModel:void 0,source:`custom`}}function AOe(e){let t=new Set([...e].map(e=>e.trim()).filter(Boolean)),n=`new-agent`;if(!t.has(n))return n;for(let e=1;;e+=1){let r=`${n}-${e}`;if(!t.has(r))return r}}function h0(e){return{id:e.id,profileName:e.profileName,displayName:e.displayName,description:e.description??``,nativeTools:e.nativeTools,skills:e.skills,contextFiles:e.contextFiles,subagents:e.subagents,mcpServers:e.mcpServers,piPackages:e.piPackages??[],mainModel:e.mainModel,subagentModel:e.subagentModel,thinkingLevel:e.thinkingLevel,mainThinkingLevel:e.mainThinkingLevel,subagentThinkingLevel:e.subagentThinkingLevel,fast:e.fast??!1,mainFast:e.mainFast??!1,subagentFast:e.subagentFast??!1,builtinTools:e.builtinTools,builtinToolNames:y0(e.builtinToolNames,e.builtinTools),autoContextFiles:e.autoContextFiles??!0,runControl:e.runControl,brokenContextFiles:e.brokenContextFiles??[],archivedAt:e.archivedAt,hardPinnedModel:void 0,source:`custom`}}function g0(e,t){return{displayName:e.name,description:e.description??``,nativeTools:e.nativeTools??[],skills:e.skills??(w0(t,`pi-agent-harness`)?[`pi-agent-harness`]:[]),contextFiles:e.contextFiles??[],subagents:e.subagents??[],mcpServers:e.mcpServers??[],piPackages:e.piPackages??[],mainModel:e.mainModel??e.model,subagentModel:e.subagentModel??e.model,thinkingLevel:e.thinkingLevel,mainThinkingLevel:e.mainThinkingLevel??e.thinkingLevel,subagentThinkingLevel:e.subagentThinkingLevel??e.thinkingLevel,fast:e.fast??!1,mainFast:e.mainFast??e.fast??!1,subagentFast:e.subagentFast??e.fast??!1,builtinTools:e.builtinTools??`default`,builtinToolNames:y0(e.builtinToolNames,e.builtinTools),autoContextFiles:e.autoContextFiles??!0,runControl:e.runControl??!1,brokenContextFiles:[],hardPinnedModel:e.model,profileName:e.name,source:`profile`}}function jOe(e,t){return{...g0(e,t),displayName:`${e.name}-copy`,id:void 0,hardPinnedModel:void 0,profileName:void 0,source:`custom`}}function _0(e){return{...h0(e),displayName:`${e.profileName}-copy`,id:void 0,profileName:void 0,archivedAt:void 0,source:`custom`}}function MOe(e,t){let n=new Map;for(let t of e)n.set(t.name,t.name);for(let e of t)n.set(e.profileName,e.displayName);return[...n.entries()].map(([e,t])=>({value:e,label:t}))}function NOe(e){return e.trim()?e.length>120?`Agent name is too long.`:/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(e)?null:`Use lowercase kebab-case only, for example test-agent.`:`Agent name is required.`}function v0(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function y0(e,t=`default`){if(t===`disabled`)return[];let n=new Set(e??b0);return b0.filter(e=>n.has(e))}var POe=new Set([`apply_patch`,`codex_image_generation`,`web_search`,`view_image`]),b0=[`read`,`bash`,`edit`,`write`],FOe={read:`Read workspace files.`,bash:`Run shell commands.`,edit:`Edit existing files.`,write:`Create or overwrite files.`};function IOe(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=t.pluginId??(POe.has(t.name)?`pibo.codex-compat`:void 0),i=t.pluginName??(e===`pibo.codex-compat`?`Codex Compat`:void 0),a=!e||e===`pibo.core`,o=x0(r,a?`builtin`:`plugin:${e}`,{title:a?`Built-in Tools`:C0(e,i),description:a?`Built-in Pibo tool catalog`:e??`plugin`,kind:a?`builtin`:`plugin`});o.items.push(t),n.has(t.name)&&(o.selectedCount+=1),o.totalCount+=1}return S0(r,[`builtin`,`plugin`])}function LOe(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=t.kind,i=x0(r,e===`plugin`?`plugin:${t.pluginId??t.name}`:e,{title:zOe(t),description:BOe(t),kind:t.kind});i.items.push(t),n.has(t.name)&&(i.selectedCount+=1),i.totalCount+=1}return S0(r,[`builtin`,`plugin`,`user`])}function ROe(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=t.pluginId===`pibo.core`,i=!t.pluginId,a=x0(r,e?`builtin`:i?`custom`:`plugin:${t.pluginId}`,{title:e?`Built-in Context Files`:i?`Custom`:C0(t.pluginId,t.pluginName),description:e?`Pibo built-in context file catalog`:i?`Loose context files without a plugin namespace`:t.pluginId??`plugin`,kind:e?`builtin`:i?`custom`:`plugin`});a.items.push(t),n.has(t.key)&&(a.selectedCount+=1),a.totalCount+=1}return S0(r,[`builtin`,`custom`,`plugin`])}function x0(e,t,n){let r=e.get(t);if(r)return r;let i={key:t,title:n.title,description:n.description,kind:n.kind,items:[],selectedCount:0,totalCount:0,defaultOpen:!1};return e.set(t,i),i}function S0(e,t){let n=new Map(t.map((e,t)=>[e,t]));return[...e.values()].sort((e,r)=>{let i=n.get(e.kind)??t.length,a=n.get(r.kind)??t.length;return i===a?e.title.localeCompare(r.title):i-a}).map(e=>({...e,defaultOpen:!1}))}function C0(e,t){return e===`pibo.codex-compat`?`Codex Compat`:t||(e?(e.split(`.`).filter(Boolean).at(-1)??e).split(`-`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):`Plugin`)}function zOe(e){return e.kind===`builtin`?`Built-in Skills`:e.kind===`user`?`User Skills`:C0(e.pluginId,e.pluginName)}function BOe(e){return e.kind===`builtin`?`Pibo-owned built-in skill catalog`:e.kind===`user`?`User-managed skills`:e.pluginId??`plugin`}function VOe(e){return e.kind===`builtin`?`built-in skill`:e.kind===`user`?`user skill`:e.pluginName??e.pluginId??`plugin skill`}function w0(e,t){return e?.skills.some(e=>e.kind===`builtin`&&e.name===t)??!1}function HOe(e){let t=e.source??`plugin`,n=e.scope??`global`;return e.pluginId===`pibo.core`?`built-in global`:t===`plugin`?`plugin global`:n===`agent`?e.agentProfileName?`agent ${e.agentProfileName}`:`agent local`:`managed global`}function T0(e,t){return e.includes(t.id)||e.includes(t.name)}function UOe(e,t){return T0(e,t)?e.filter(e=>e!==t.id&&e!==t.name):[...e,t.id]}function WOe(e){return e.enabled&&e.installStatus===`installed`}function E0(e){let t=e.resourceTypes.length?e.resourceTypes.join(` + `):`resources pending`,n=e.version?`v${e.version}`:e.installStatus,r=e.diagnostics.some(e=>e.type===`error`)?` / needs attention`:``;return`${t} / ${n} / ${e.enabled?`enabled`:`disabled`}${r}`}function D0(){return`Agent Designer API unavailable. Restart the Pibo web gateway after pulling/building the latest backend.`}function GOe(e){return e.toLowerCase().includes(`not found`)||e.includes(`404`)}function O0({title:e,children:t}){return(0,z.jsxs)(`div`,{className:`border border-slate-700 bg-[#1a262b] rounded-sm p-4`,children:[(0,z.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-400 mb-3`,children:e}),(0,z.jsx)(`div`,{className:`grid gap-3`,children:t})]})}function KOe({title:e,children:t}){return(0,z.jsx)(O0,{title:e,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:t})})}function k0({groups:e,empty:t,renderItem:n}){return e.length===0?(0,z.jsx)(z.Fragment,{children:t}):(0,z.jsx)(`div`,{className:`grid gap-2`,children:e.map(e=>(0,z.jsx)(qOe,{group:e,renderItem:n},e.key))})}function qOe({group:e,renderItem:t}){let[n,r]=(0,R.useState)(e.defaultOpen),i=e.items.slice(0,100),a=e.items.length-i.length,o=e.kind===`custom`||e.kind===`user`?`border-[#f59e0b]/70 text-amber-100 bg-[#f59e0b]/10`:`border-[#11a4d4]/70 text-sky-100 bg-[#11a4d4]/10`;return(0,z.jsxs)(`div`,{className:`border rounded-sm ${n?`border-slate-700 bg-[#101d22]`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 p-2 text-left`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 shrink-0 inline-flex items-center justify-center border rounded-sm ${o}`,children:n?(0,z.jsx)(zo,{size:14}):(0,z.jsx)(Bo,{size:14})}),(0,z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm font-medium text-slate-100`,children:e.title}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:e.description})]}),(0,z.jsxs)(`span`,{className:`shrink-0 text-right font-mono text-sm font-semibold tabular-nums`,"aria-label":`${e.selectedCount} of ${e.totalCount} selected`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:e.selectedCount}),(0,z.jsxs)(`span`,{className:`text-slate-500`,children:[`/`,e.totalCount]})]})]}),n?(0,z.jsxs)(`div`,{className:`border-t border-slate-800 p-2`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:i.map(t)}),a>0?(0,z.jsxs)(`div`,{className:`mt-2 text-xs text-slate-500`,children:[`Showing first `,100,` of `,e.items.length,` items. Use Context to manage the full catalog.`]}):null]}):null]})}function A0({checked:e,disabled:t,title:n,description:r,meta:i,metaClass:a,actionLabel:o,actionIcon:s,actionDisabled:c,onAction:l,onToggle:u}){return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{t||u()},"aria-disabled":t,className:`min-w-0 border rounded-sm p-2 text-left grid grid-cols-[18px_1fr] gap-2 ${t&&!l?`opacity-60`:``} ${e?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,z.jsx)(P0,{checked:e,className:`mt-0.5`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex items-start justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,z.jsx)(`span`,{className:`block text-sm truncate text-slate-200`,children:n})}),o&&l?(0,z.jsx)(`span`,{className:`shrink-0`,children:(0,z.jsxs)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.preventDefault(),e.stopPropagation(),c||l()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&!c&&(e.preventDefault(),e.stopPropagation(),l())},className:`inline-flex h-6 items-center justify-center gap-1 border px-1.5 text-[10px] uppercase tracking-wider ${c?`border-slate-800 text-slate-600`:`border-[#11a4d4]/70 text-[#7dd3fc] hover:border-[#11a4d4] hover:text-sky-100`}`,children:[s,o]})}):null]}),r?(0,z.jsx)(`span`,{className:`block text-xs text-slate-500 truncate`,children:r}):null,i?(0,z.jsx)(`span`,{className:`block font-mono text-[10px] mt-1 ${a??`text-slate-600`}`,children:i}):null]})]})}function JOe({pkg:e,selected:t,readOnly:n,expanded:r,busy:i,onToggleSelected:a,onToggleExpanded:o,onToggleEnabled:s,onUnregister:c}){let l=e.diagnostics.some(e=>e.type===`error`),u=!n&&(e.enabled||t);return(0,z.jsxs)(`div`,{className:`border rounded-sm ${t?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24]`} ${e.enabled?``:`opacity-75`}`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2 p-2`,children:[(0,z.jsxs)(`button`,{type:`button`,disabled:!u,onClick:a,className:`min-w-0 grid grid-cols-[18px_1fr] gap-2 text-left disabled:cursor-not-allowed`,children:[(0,z.jsx)(P0,{checked:t,disabled:!u,className:`mt-0.5`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,z.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,z.jsx)(`span`,{className:`block text-xs text-slate-500 truncate`,children:e.description??e.source}),(0,z.jsx)(`span`,{className:`block font-mono text-[10px] mt-1 ${l?`text-[#f59e0b]`:`text-[#11a4d4]`}`,children:E0(e)})]})]}),(0,z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:o,title:r?`Hide Details`:`Show Details`,"aria-label":r?`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:r?(0,z.jsx)(zo,{size:13}):(0,z.jsx)(Bo,{size:13})}),s?(0,z.jsx)(`button`,{type:`button`,disabled:i,onClick:s,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,z.jsx)(Fs,{size:13}):(0,z.jsx)(Is,{size:13})}):null,c?(0,z.jsx)(`button`,{type:`button`,disabled:i,onClick:c,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,z.jsx)(qs,{size:13})}):null]})]}),r?(0,z.jsx)(j0,{pkg:e}):null]})}function j0({pkg:e}){return(0,z.jsxs)(`div`,{className:`border-t border-slate-800 p-3 grid gap-3 text-xs text-slate-300`,children:[(0,z.jsx)(YOe,{rows:[[`Source`,e.source],[`Install`,e.installSpec],[`Version`,e.version],[`Added`,e.addedAt],[`Updated`,e.updatedAt]]}),e.repositoryUrl?(0,z.jsxs)(`a`,{href:e.repositoryUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex w-fit items-center gap-1 text-[#7dd3fc] hover:text-sky-100`,children:[(0,z.jsx)(rs,{size:12}),`Source repository`]}):null,(0,z.jsx)(M0,{title:`Extensions`,values:e.extensionPaths}),(0,z.jsx)(M0,{title:`Skills`,values:e.skillNames}),(0,z.jsx)(M0,{title:`Prompts`,values:e.promptNames}),(0,z.jsx)(M0,{title:`Themes`,values:e.themeNames}),(0,z.jsx)(M0,{title:`Tools`,values:e.discoveredToolNames}),e.diagnostics.length?(0,z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Diagnostics`}),e.diagnostics.map((e,t)=>(0,z.jsxs)(`div`,{className:`border px-2 py-1 rounded-sm ${e.type===`error`?`border-red-500/50 text-red-200 bg-red-500/10`:e.type===`warning`?`border-[#f59e0b]/50 text-amber-100 bg-[#f59e0b]/10`:`border-slate-700 text-slate-400 bg-[#0e1116]`}`,children:[(0,z.jsx)(`span`,{className:`font-mono uppercase text-[10px] mr-2`,children:e.type}),e.message]},`${e.type}:${t}`))]}):null]})}function YOe({rows:e}){let t=e.filter(([,e])=>e);return t.length===0?null:(0,z.jsx)(`div`,{className:`grid gap-1`,children:t.map(([e,t])=>(0,z.jsxs)(`div`,{className:`grid grid-cols-[84px_minmax(0,1fr)] gap-2`,children:[(0,z.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsx)(`span`,{className:`min-w-0 break-all font-mono text-[11px] text-slate-300`,children:t})]},e))})}function M0({title:e,values:t}){return t?.length?(0,z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,z.jsx)(`span`,{className:`max-w-full break-all border border-slate-700 bg-[#0e1116] px-2 py-1 font-mono text-[11px] text-slate-300 rounded-sm`,children:e},e))})]}):null}function N0({checked:e,disabled:t,title:n,onToggle:r}){return(0,z.jsxs)(`button`,{type:`button`,disabled:t,"aria-pressed":e,onClick:r,className:`inline-flex w-fit items-center gap-2 text-left text-sm text-slate-300 hover:text-slate-100 disabled:opacity-60`,children:[(0,z.jsx)(P0,{checked:e,disabled:t}),(0,z.jsx)(`span`,{children:n})]})}function P0({checked:e,disabled:t,className:n=``}){return(0,z.jsx)(`span`,{className:`h-4 w-4 shrink-0 border rounded-sm inline-flex items-center justify-center ${e?`border-[#11a4d4] text-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-600 text-transparent`} ${t?`opacity-70`:``} ${n}`,children:e?(0,z.jsx)(Ro,{size:12}):null})}function F0({message:e=`Agent Designer API unavailable`}){return(0,z.jsx)(`div`,{className:`text-xs text-amber-100 border border-dashed border-[#f59e0b]/50 bg-[#f59e0b]/10 rounded-sm p-3`,children:e})}function I0({title:e,modelTitle:t,model:n,thinking:r,fast:i,modelCatalog:a,readOnly:o,modelHint:s,configuredProvidersOnly:c=!1,onModelChange:l,onThinkingChange:u,onFastChange:d}){return(0,z.jsxs)(`div`,{className:`grid gap-2 border border-slate-800 rounded-sm p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(150px,190px)_auto] lg:items-start`,children:[(0,z.jsx)(ZOe,{title:t,catalog:a,value:n,allowUnset:!0,readOnly:o,hint:s,emptyProviderLabel:`Default`,configuredProvidersOnly:c,onChange:l}),(0,z.jsx)(XOe,{title:`Thinking`,value:r,readOnly:o,reserveHintSpace:!0,onChange:u}),(0,z.jsxs)(`div`,{className:`grid gap-2 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:`Fast`}),(0,z.jsx)(`div`,{className:`h-4`,"aria-hidden":`true`}),(0,z.jsxs)(`button`,{type:`button`,disabled:o,onClick:()=>d(!i),className:`inline-flex h-9 w-fit items-center gap-2 text-left text-sm text-slate-300 hover:text-slate-100 disabled:opacity-60`,children:[(0,z.jsx)(P0,{checked:i===!0,disabled:o}),(0,z.jsx)(`span`,{children:i?`Fast on`:`Fast off`})]})]})]})]})}function XOe({title:e,value:t,readOnly:n,hint:r,reserveHintSpace:i=!1,onChange:a}){return(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsx)(`button`,{type:`button`,disabled:n||!t,onClick:()=>a(void 0),className:`text-[10px] uppercase tracking-wider text-slate-500 hover:text-slate-300 disabled:opacity-50`,children:`Unset`})]}),r?(0,z.jsx)(`div`,{className:`text-xs text-slate-500`,children:r}):i?(0,z.jsx)(`div`,{className:`h-4`,"aria-hidden":`true`}):null,(0,z.jsxs)(`select`,{value:t??``,disabled:n,onChange:e=>a(e.target.value?e.target.value:void 0),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`,children:[(0,z.jsx)(`option`,{value:``,children:`Default`}),Xq.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]})}function ZOe({title:e,catalog:t,value:n,allowUnset:r,readOnly:i,hint:a,emptyProviderLabel:o=`Select provider`,configuredProvidersOnly:s=!1,onChange:c}){let[l,u]=(0,R.useState)(n?.provider??``),[d,f]=(0,R.useState)(n?.id??``),p=t?.providers??[],m=p.filter(e=>!s||e.authConfigured),h=m.find(e=>e.id===l),g=s?p.find(e=>e.id===l&&!e.authConfigured):void 0,_=!!l&&!h,v=_?g?`${g.label} (not configured)`:`${l} (unknown provider)`:``,y=h?.models.find(e=>e.id===d),b=!!(l&&d&&h&&!y),x=h?.models??[],S=h?.authConfigured;return(0,R.useEffect)(()=>{u(n?.provider??``),f(n?.id??``)},[n?.id,n?.provider]),(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:e}),r?(0,z.jsx)(`button`,{type:`button`,disabled:i||!l&&!d,onClick:()=>{u(``),f(``),c(void 0)},className:`text-[10px] uppercase tracking-wider text-slate-500 hover:text-slate-300 disabled:opacity-50`,children:`Unset`}):null]}),a?(0,z.jsx)(`div`,{className:`text-xs text-slate-500`,children:a}):null,m.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm p-3`,children:p.length===0?`Model catalog unavailable.`:`No configured providers. Configure a provider under Settings > Providers.`}):null,(0,z.jsxs)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:[(0,z.jsxs)(`select`,{value:l,disabled:i,onChange:e=>{let t=e.target.value;u(t),f(``),t||c(void 0)},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`,children:[(0,z.jsx)(`option`,{value:``,children:o}),m.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.label},e.id)),_?(0,z.jsx)(`option`,{value:l,children:v}):null]}),(0,z.jsxs)(`select`,{value:d,disabled:i,onChange:e=>{let t=e.target.value;f(t),t?c({provider:l,id:t}):l&&c(void 0)},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`,children:[(0,z.jsx)(`option`,{value:``,children:l?`Select model`:`Select provider first`}),x.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.label},e.id)),b?(0,z.jsx)(`option`,{value:d,children:`${d} (unknown model)`}):null]})]}),l?(0,z.jsx)(`div`,{className:`text-xs text-slate-500`,children:_?g?`Stored provider is no longer configured.`:`Stored provider is no longer present in the catalog.`:S?`Provider auth configured.`:`Provider auth missing.`}):null,b?(0,z.jsx)(`div`,{className:`text-xs text-amber-100`,children:`Stored model is no longer present in the catalog.`}):null]})}function QOe({agents:e,initialCustomAgents:t,initialCatalog:n,modelCatalog:r,onSelect:i,onCreateSession:a,onEditContextFile:o,onEditMcpServer:s,onAgentsChanged:c,creatingSession:l}){let[u,d]=(0,R.useState)(n??null),[f,p]=(0,R.useState)(t),[m,h]=(0,R.useState)(()=>m0(n)),[g,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(!1),[b,x]=(0,R.useState)(()=>localStorage.getItem(`pibo.chat.showArchivedAgents`)===`true`),[S,C]=(0,R.useState)(``),[w,T]=(0,R.useState)(null),[E,D]=(0,R.useState)(``),[O,k]=(0,R.useState)(`agent`),A=!!u;(0,R.useEffect)(()=>p(t),[t]),(0,R.useEffect)(()=>{n&&d(n)},[n]);let j=(0,R.useMemo)(()=>new Set(f.map(e=>e.profileName)),[f]),M=(0,R.useMemo)(()=>e.filter(e=>!j.has(e.name)),[e,j]),N=(0,R.useMemo)(()=>f.filter(e=>!e.archivedAt),[f]),P=(0,R.useMemo)(()=>f.filter(e=>e.archivedAt),[f]),F=(0,R.useMemo)(()=>MOe(e,N),[e,N]),ee=!!m.archivedAt,te=g&&m.source===`custom`&&!m.id,I=m.source===`profile`||ee,ne=I?null:NOe(m.displayName),L=m.profileName??(ne?`new custom profile`:m.displayName),re=(0,R.useMemo)(()=>u?.contextFiles.filter(e=>(e.scope??`global`)===`agent`?e.agentProfileName===L||m.contextFiles.includes(e.key):!0)??[],[u,m.contextFiles,L]),ie=(0,R.useMemo)(()=>IOe(u?.nativeTools??[],m.nativeTools),[u?.nativeTools,m.nativeTools]),ae=(0,R.useMemo)(()=>LOe(u?.skills??[],m.skills),[u?.skills,m.skills]),oe=(0,R.useMemo)(()=>ROe(re,m.contextFiles),[re,m.contextFiles]),se=()=>{let t=[...e.map(e=>e.name),...f.flatMap(e=>[e.profileName,e.displayName]),...te?[m.displayName]:[]];h(m0(u??void 0,AOe(t))),_(!0),T(null)},ce=async()=>{if(!I){if(ne){T(ne);return}if(!A){T(D0());return}y(!0);try{let e={displayName:m.displayName.trim(),description:(m.description??``).trim()||void 0,nativeTools:m.nativeTools,skills:m.skills,contextFiles:m.contextFiles,subagents:m.subagents.filter(e=>e.name.trim()&&e.targetProfile.trim()),mcpServers:m.mcpServers,piPackages:m.piPackages,mainModel:m.mainModel,subagentModel:m.subagentModel,thinkingLevel:m.thinkingLevel??null,mainThinkingLevel:m.mainThinkingLevel??null,subagentThinkingLevel:m.subagentThinkingLevel??null,fast:m.fast,mainFast:m.mainFast,subagentFast:m.subagentFast,builtinTools:m.builtinTools,builtinToolNames:m.builtinToolNames,autoContextFiles:m.autoContextFiles,runControl:m.runControl},t=m.id?await UW(m.id,e):await HW(e);p(e=>{let n=e.filter(e=>e.id!==t.agent.id);return[t.agent,...n]}),h(h0(t.agent)),_(!1),i(t.agent.profileName),c(),T(null)}catch(e){let t=e instanceof Error?e.message:String(e);T(GOe(t)?D0():t)}finally{y(!1)}}},le=async e=>{if(!(!m.id||m.source!==`custom`)){y(!0);try{let t=await UW(m.id,{archived:e});e&&(x(!0),localStorage.setItem(`pibo.chat.showArchivedAgents`,`true`)),p(e=>e.map(e=>e.id===t.agent.id?t.agent:e)),h(h0(t.agent)),C(``),c(),T(null)}catch(e){T(e instanceof Error?e.message:String(e))}finally{y(!1)}}},ue=async()=>{if(!(I||!A||!E.trim())){if(ne){T(ne);return}y(!0);try{let e=(await sl({label:E.trim(),scope:O,agentProfileName:O===`agent`?L:void 0,markdown:``})).file;d(t=>t&&{...t,contextFiles:[...t.contextFiles,e]}),h(t=>({...t,contextFiles:t.contextFiles.includes(e.key)?t.contextFiles:[...t.contextFiles,e.key]})),D(``),T(null)}catch(e){T(e instanceof Error?e.message:String(e))}finally{y(!1)}}},de=async()=>{if(!(!m.id||!m.profileName||!ee)){y(!0);try{await WW(m.id,S),p(e=>e.filter(e=>e.id!==m.id)),h(m0(u??void 0)),_(!1),C(``),c(),T(null)}catch(e){T(e instanceof Error?e.message:String(e))}finally{y(!1)}}};return(0,z.jsxs)(`div`,{className:`h-full min-h-0 overflow-hidden grid grid-cols-[300px_minmax(0,1fr)] max-[920px]:grid-cols-1`,children:[(0,z.jsxs)(`aside`,{className:`border-r border-slate-800 bg-[#1a262b] min-h-0 overflow-auto`,children:[(0,z.jsxs)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center justify-between text-xs font-bold uppercase tracking-wider`,children:[(0,z.jsx)(`span`,{children:`Agents`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:se,title:`New Agent`,"aria-label":`New Agent`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ps,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>{let e=!b;x(e),localStorage.setItem(`pibo.chat.showArchivedAgents`,String(e))},title:b?`Hide Archived Agents`:`Show Archived Agents`,"aria-label":b?`Hide Archived Agents`:`Show Archived Agents`,className:`p-1 border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${b?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:b?(0,z.jsx)(wo,{size:13}):(0,z.jsx)(To,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:c,title:`Refresh`,"aria-label":`Refresh`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ls,{size:13})})]})]}),(0,z.jsxs)(`div`,{className:`p-2`,children:[(0,z.jsxs)(L0,{title:`Custom Agents`,children:[te?(0,z.jsx)(R0,{title:m.displayName||`new-agent`,subtitle:`unsaved custom agent`,selected:!0,onSelect:()=>{},onCreateSession:()=>{},createSessionDisabled:!0},`unsaved-agent-draft`):null,N.map(e=>(0,z.jsx)(R0,{title:e.displayName,subtitle:e.profileName,selected:m.source===`custom`&&m.id===e.id,onSelect:()=>{_(!1),h(h0(e)),i(e.profileName)},onCopy:()=>{h(_0(e)),_(!0)},onCreateSession:()=>{i(e.profileName),a(e.profileName)},createSessionDisabled:l},e.id)),N.length===0&&!te?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No custom agents`}):null]}),b?(0,z.jsxs)(L0,{title:`Archived Custom Agents`,children:[P.map(e=>(0,z.jsx)(R0,{title:e.displayName,subtitle:e.profileName,selected:m.source===`custom`&&m.id===e.id,onSelect:()=>{_(!1),h(h0(e))},onCopy:()=>{h(_0(e)),_(!0)},onCreateSession:()=>{},createSessionDisabled:!0},e.id)),P.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No archived agents`}):null]}):null,(0,z.jsx)(L0,{title:`Read-only Profiles`,children:M.map(e=>(0,z.jsx)(R0,{title:e.name,subtitle:e.aliases.join(`, `)||`plugin`,selected:m.source===`profile`&&m.profileName===e.name,onSelect:()=>{_(!1),h(g0(e,u??void 0)),i(e.name)},onCopy:()=>{h(jOe(e,u??void 0)),_(!0)},onCreateSession:()=>{i(e.name),a(e.name)},createSessionDisabled:l},e.name))})]})]}),(0,z.jsxs)(`section`,{className:`min-h-0 overflow-auto p-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`h1`,{className:`text-sm font-bold uppercase tracking-wider`,children:`Agent Designer`}),(0,z.jsx)(`div`,{className:`font-mono text-[11px] text-slate-500 truncate`,children:L}),(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:m.source===`profile`?`read-only plugin profile`:ee?`archived custom agent`:`custom agent`})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>{m.profileName&&(i(m.profileName),a(m.profileName))},disabled:!m.profileName||l||ee,title:`New Session With Agent`,"aria-label":`New Session With Agent`,className:`h-8 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,z.jsx)(Ds,{size:14})}),m.source===`custom`&&m.id?(0,z.jsx)(`button`,{type:`button`,onClick:()=>void le(!ee),disabled:v,title:ee?`Restore Agent`:`Archive Agent`,"aria-label":ee?`Restore Agent`:`Archive Agent`,className:`h-8 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:ee?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>void ce(),disabled:I||!A||v||!!ne,title:`Save Agent`,"aria-label":`Save Agent`,className:`h-8 w-8 inline-flex items-center justify-center border border-[#11a4d4] rounded-sm text-[#11a4d4] bg-[#11a4d4]/10 disabled:opacity-50`,children:(0,z.jsx)(Bs,{size:14})})]})]}),A?null:(0,z.jsx)(`div`,{className:`mb-3 border border-[#f59e0b]/60 bg-[#f59e0b]/10 text-amber-100 px-3 py-2 text-sm rounded-sm`,children:D0()}),m.source===`profile`?(0,z.jsx)(`div`,{className:`mb-3 border border-slate-700 bg-[#151f24] text-slate-300 px-3 py-2 text-sm rounded-sm`,children:`This profile is registered by a plugin. Copy it to create an editable custom agent.`}):null,ee?(0,z.jsx)(`div`,{className:`mb-3 border border-[#f59e0b]/60 bg-[#f59e0b]/10 text-amber-100 px-3 py-2 text-sm rounded-sm`,children:`This agent is archived. Restore it before editing or starting new sessions.`}):null,w?(0,z.jsx)(`div`,{className:`mb-3 border border-red-500/60 bg-red-500/10 text-red-200 px-3 py-2 text-sm rounded-sm`,children:w}):null,(0,z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,z.jsxs)(O0,{title:`Basics`,children:[(0,z.jsx)(`input`,{value:m.displayName,disabled:I,onChange:e=>h(t=>({...t,displayName:e.target.value})),className:`min-w-0 bg-[#0e1116] border rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60 ${ne?`border-[#f59e0b]`:`border-slate-700`}`,placeholder:`agent-name`}),ne?(0,z.jsx)(`div`,{className:`text-xs text-amber-100`,children:ne}):null,(0,z.jsx)(`textarea`,{value:m.description,disabled:I,onChange:e=>h(t=>({...t,description:e.target.value})),className:`min-h-[72px] bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,placeholder:`Description`}),m.source===`profile`&&m.hardPinnedModel?(0,z.jsxs)(`div`,{className:`border border-slate-700 bg-[#151f24] text-slate-300 px-3 py-2 text-xs rounded-sm`,children:[`This plugin profile hard-pins `,(0,z.jsx)(`span`,{className:`font-mono`,children:rke(m.hardPinnedModel)}),`. Main-agent and subagent defaults do not apply.`]}):null,(0,z.jsx)(I0,{title:`Main Agent`,modelTitle:`Main Agent Model`,model:m.mainModel,thinking:m.mainThinkingLevel,fast:m.mainFast??!1,modelCatalog:r,readOnly:I,modelHint:`Unset to use the settings default.`,onModelChange:e=>h(t=>({...t,mainModel:e})),onThinkingChange:e=>h(t=>({...t,mainThinkingLevel:e})),onFastChange:e=>h(t=>({...t,mainFast:e}))}),(0,z.jsx)(I0,{title:`Subagent`,modelTitle:`Subagent Model`,model:m.subagentModel,thinking:m.subagentThinkingLevel,fast:m.subagentFast??!1,modelCatalog:r,readOnly:I,modelHint:`Unset to use the settings default.`,onModelChange:e=>h(t=>({...t,subagentModel:e})),onThinkingChange:e=>h(t=>({...t,subagentThinkingLevel:e})),onFastChange:e=>h(t=>({...t,subagentFast:e}))}),(0,z.jsx)(N0,{disabled:I,checked:m.autoContextFiles,title:`Load AGENTS.md / CLAUDE.md`,onToggle:()=>h(e=>({...e,autoContextFiles:!e.autoContextFiles}))}),(0,z.jsx)(eke,{draft:m,setDraft:h,readOnly:I})]}),(0,z.jsx)(O0,{title:`Tools`,children:(0,z.jsx)(k0,{groups:ie,empty:u?(0,z.jsx)(F0,{message:`No native tools registered`}):(0,z.jsx)(F0,{}),renderItem:e=>(0,z.jsx)(A0,{disabled:I,checked:m.nativeTools.includes(e.name),title:e.name,description:e.description,meta:e.yieldable?`yieldable`:`direct only`,onToggle:()=>h(t=>({...t,nativeTools:v0(t.nativeTools,e.name)}))},e.name)})}),(0,z.jsx)(O0,{title:`Skills`,children:(0,z.jsx)(k0,{groups:ae,empty:u?(0,z.jsx)(F0,{message:`No skills registered`}):(0,z.jsx)(F0,{}),renderItem:e=>(0,z.jsx)(A0,{disabled:I,checked:m.skills.includes(e.name),title:e.name,description:e.path,meta:VOe(e),metaClass:e.kind===`user`?`text-amber-200`:`text-[#11a4d4]`,onToggle:()=>h(t=>({...t,skills:v0(t.skills,e.name)}))},e.name)})}),(0,z.jsx)(KOe,{title:`Packages`,children:(0,z.jsx)(A0,{disabled:I,checked:m.runControl,title:`pibo-run-control`,description:`Expose pibo_run_* as one package for yielded native tools and subagents.`,meta:`package`,onToggle:()=>h(e=>({...e,runControl:!e.runControl}))})}),(0,z.jsx)($Oe,{packages:u?.piPackages,draft:m,setDraft:h,readOnly:I}),(0,z.jsxs)(O0,{title:`Context Files`,children:[m.brokenContextFiles?.length?(0,z.jsxs)(`div`,{className:`border border-red-500/60 bg-red-500/10 rounded-sm p-3 space-y-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start gap-2 text-red-100`,children:[(0,z.jsx)(Js,{size:14,className:`mt-0.5 shrink-0`}),(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsx)(`div`,{className:`text-sm font-medium`,children:`This agent references missing context files.`}),(0,z.jsx)(`div`,{className:`text-xs text-red-200/90`,children:`Remove these broken links and save the agent to persist the cleanup.`})]})]}),(0,z.jsx)(`div`,{className:`grid gap-2`,children:m.brokenContextFiles.map(e=>(0,z.jsxs)(`div`,{className:`flex items-center gap-2 border border-red-500/40 bg-[#2a1417] rounded-sm px-3 py-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`truncate text-sm text-red-100`,children:e}),(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-red-300/80`,children:`Broken link`})]}),(0,z.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>h(t=>({...t,contextFiles:t.contextFiles.filter(t=>t!==e),brokenContextFiles:(t.brokenContextFiles??[]).filter(t=>t!==e)})),className:`h-8 w-8 inline-flex items-center justify-center border border-red-500/60 rounded-sm text-red-200 hover:border-red-400 hover:text-red-100 disabled:opacity-50`,title:`Remove Broken Context File`,"aria-label":`Remove Broken Context File`,children:(0,z.jsx)(Qs,{size:14})})]},e))})]}):null,(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2`,children:[(0,z.jsx)(`input`,{value:E,disabled:I,onChange:e=>D(e.target.value),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:`New context file`}),(0,z.jsx)(`button`,{type:`button`,disabled:I||v||!E.trim()||!!ne,onClick:()=>void ue(),title:`Create Context File`,"aria-label":`Create Context File`,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,z.jsx)(Ps,{size:14})})]}),(0,z.jsxs)(`div`,{className:`inline-flex w-fit gap-1 border border-slate-800 bg-[#0e1116] rounded-sm p-1`,children:[(0,z.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>k(`agent`),className:`px-2 py-1 text-xs rounded-sm ${O===`agent`?`bg-[#11a4d4]/20 text-sky-100`:`text-slate-500 hover:text-slate-300`}`,children:`Agent`}),(0,z.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>k(`global`),className:`px-2 py-1 text-xs rounded-sm ${O===`global`?`bg-[#11a4d4]/20 text-sky-100`:`text-slate-500 hover:text-slate-300`}`,children:`Global`})]}),(0,z.jsx)(k0,{groups:oe,empty:u?(0,z.jsx)(F0,{message:`No context files registered`}):(0,z.jsx)(F0,{}),renderItem:e=>(0,z.jsx)(A0,{disabled:I,checked:m.contextFiles.includes(e.key),title:e.label??e.key,description:e.path,meta:HOe(e),metaClass:`text-[#11a4d4]`,actionLabel:`Edit`,actionIcon:(0,z.jsx)(Ms,{size:12}),onAction:()=>o(e.key),onToggle:()=>h(t=>({...t,contextFiles:v0(t.contextFiles,e.key)}))},e.key)})]}),(0,z.jsx)(tke,{draft:m,setDraft:h,profileOptions:F,readOnly:I}),(0,z.jsx)(nke,{servers:u?.mcpServers,draft:m,setDraft:h,readOnly:I,onEditServer:s}),ee&&m.profileName?(0,z.jsxs)(O0,{title:`Delete Agent`,children:[(0,z.jsxs)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-100 rounded-sm p-3 text-sm`,children:[`Permanently deleting this agent also deletes all Chat sessions that use profile `,(0,z.jsx)(`span`,{className:`font-mono`,children:m.profileName}),`.`]}),(0,z.jsx)(`input`,{value:S,onChange:e=>C(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-red-500`,placeholder:m.profileName}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void de(),disabled:v||S!==m.profileName,className:`h-8 w-fit inline-flex items-center gap-2 border border-red-500 rounded-sm px-3 text-red-200 bg-red-500/10 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:14}),`Delete permanently`]})]}):null]})]})]})}function L0({title:e,children:t}){return(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:e}),t]})}function R0({title:e,subtitle:t,selected:n,onSelect:r,onCopy:i,onCreateSession:a,createSessionDisabled:o}){return(0,z.jsx)(`div`,{className:`mb-1 border rounded-sm ${n?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-transparent hover:border-slate-700`}`,children:(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto_auto] items-center gap-1 p-1`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 text-left px-1 py-1`,children:[(0,z.jsx)(`span`,{className:`block text-sm truncate text-slate-200`,children:e}),(0,z.jsx)(`span`,{className:`block text-[10px] font-mono truncate text-slate-500`,children:t})]}),i?(0,z.jsx)(`button`,{type:`button`,onClick:i,title:`Copy To Custom Agent`,"aria-label":`Copy To Custom Agent`,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,z.jsx)(Qo,{size:13})}):(0,z.jsx)(`span`,{className:`h-7 w-7`}),(0,z.jsx)(`button`,{type:`button`,onClick:a,disabled:o,title:`New Session With Profile`,"aria-label":`New Session With Profile`,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,z.jsx)(Ds,{size:13})})]})})}function $Oe({packages:e,draft:t,setDraft:n,readOnly:r}){let[i,a]=(0,R.useState)(()=>new Set),o=e??[],s=o.filter(WOe),c=s.filter(e=>T0(t.piPackages,e)).length,l=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,z.jsxs)(O0,{title:`Pi Packages`,children:[(0,z.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[s.length,` available / `,c,` selected / `,o.length,` registered`]}),e?s.length?(0,z.jsx)(`div`,{className:`grid gap-2`,children:s.map(e=>(0,z.jsx)(JOe,{pkg:e,selected:T0(t.piPackages,e),readOnly:r,expanded:i.has(e.id),busy:!1,onToggleSelected:()=>{r||n(t=>({...t,piPackages:UOe(t.piPackages,e)}))},onToggleExpanded:()=>l(e.id)},e.id))}):(0,z.jsx)(F0,{message:`No installed and enabled Pi packages available. Manage Pi Packages in Settings.`}):(0,z.jsx)(F0,{})]})}function eke({draft:e,setDraft:t,readOnly:n}){let r=y0(e.builtinToolNames,e.builtinTools),[i,a]=(0,R.useState)(r.length!==b0.length),o=e=>{t(t=>{let n=v0(y0(t.builtinToolNames,t.builtinTools),e);return{...t,builtinTools:n.length===0?`disabled`:`default`,builtinToolNames:n}})};return(0,z.jsxs)(`div`,{className:`border rounded-sm ${i?`border-slate-700 bg-[#101d22]`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex w-full items-center gap-2 p-2 text-left`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 shrink-0 inline-flex items-center justify-center border rounded-sm border-[#11a4d4]/70 text-sky-100 bg-[#11a4d4]/10`,children:i?(0,z.jsx)(zo,{size:14}):(0,z.jsx)(Bo,{size:14})}),(0,z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm font-medium text-slate-100`,children:`Pi Built-in Tools`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`basic model tools`})]}),(0,z.jsxs)(`span`,{className:`shrink-0 text-right font-mono text-sm font-semibold tabular-nums`,"aria-label":`${r.length} of ${b0.length} enabled`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:r.length}),(0,z.jsxs)(`span`,{className:`text-slate-500`,children:[`/`,b0.length]})]})]}),i?(0,z.jsx)(`div`,{className:`border-t border-slate-800 p-2`,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:b0.map(e=>(0,z.jsx)(A0,{disabled:n,checked:r.includes(e),title:e,description:FOe[e],meta:`built-in`,onToggle:()=>o(e)},e))})}):null]})}function tke({draft:e,setDraft:t,profileOptions:n,readOnly:r}){let i=(e,n)=>{t(t=>({...t,subagents:t.subagents.map((t,r)=>r===e?{...t,...n}:t)}))};return(0,z.jsxs)(O0,{title:`Subagents`,children:[(0,z.jsx)(`div`,{className:`flex justify-end`,children:(0,z.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>t(e=>({...e,subagents:[...e.subagents,{name:`helper`,targetProfile:n[0]?.value??`base`,maxDepth:3}]})),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`,title:`Add Subagent`,"aria-label":`Add Subagent`,children:(0,z.jsx)(Ps,{size:13})})}),(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[e.subagents.map((e,a)=>(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_1fr_80px_auto] max-[1100px]:grid-cols-1 gap-2 border border-slate-800 bg-[#151f24] p-2 rounded-sm`,children:[(0,z.jsx)(`input`,{value:e.name,disabled:r,onChange:e=>i(a,{name: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] disabled:opacity-60`,placeholder:`name`}),(0,z.jsx)(`select`,{value:e.targetProfile,disabled:r,onChange:e=>i(a,{targetProfile: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] disabled:opacity-60`,children:n.map(e=>(0,z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,z.jsx)(`input`,{type:`number`,min:1,disabled:r,value:e.maxDepth??3,onChange:e=>i(a,{maxDepth:Number(e.target.value)||1}),className:`bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,z.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>t(e=>({...e,subagents:e.subagents.filter((e,t)=>t!==a)})),className:`h-8 w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-red-500 hover:text-red-300 disabled:opacity-50`,title:`Remove Subagent`,"aria-label":`Remove Subagent`,children:(0,z.jsx)(Qs,{size:14})})]},a)),e.subagents.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm p-3`,children:`No subagents configured`}):null]})]})}function nke({servers:e,draft:t,setDraft:n,readOnly:r,onEditServer:i}){return(0,z.jsx)(O0,{title:`MCP Servers`,children:(0,z.jsxs)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:[e?e.map(e=>{let a=r||!e.hasDescription;return(0,z.jsxs)(`div`,{className:`border rounded-sm bg-[#151f24] p-2 ${t.mcpServers.includes(e.name)?`border-[#11a4d4]`:e.hasDescription?`border-slate-800`:`border-[#f59e0b]/60`}`,children:[(0,z.jsxs)(`button`,{type:`button`,disabled:a,onClick:()=>n(t=>({...t,mcpServers:v0(t.mcpServers,e.name)})),className:`grid w-full min-w-0 grid-cols-[18px_1fr] gap-2 text-left disabled:opacity-60`,children:[(0,z.jsx)(P0,{checked:t.mcpServers.includes(e.name),disabled:a,className:`mt-0.5`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(Us,{size:13,className:`text-[#11a4d4]`}),(0,z.jsx)(`span`,{className:`block text-sm truncate text-slate-200`,children:e.name})]}),(0,z.jsxs)(`span`,{className:`block font-mono text-[10px] mt-1 text-slate-600`,children:[e.transport,e.descriptionSource?` / ${e.descriptionSource}`:``]})]})]}),e.hasDescription?(0,z.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:e.description}):(0,z.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-xs text-amber-100`,children:[(0,z.jsx)(Js,{size:13}),`Missing agent description`]}),(0,z.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,z.jsxs)(`button`,{type:`button`,onClick:()=>i(e.name),title:`Edit MCP Tool Context`,"aria-label":`Edit MCP Tool Context`,className:`inline-flex h-6 items-center justify-center gap-1 border border-[#11a4d4]/70 px-1.5 text-[10px] uppercase tracking-wider text-[#7dd3fc] hover:border-[#11a4d4] hover:text-sky-100`,children:[(0,z.jsx)(Ms,{size:12}),`Edit`]})})]},e.name)}):(0,z.jsx)(F0,{}),e&&e.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm p-3`,children:`No MCP servers configured`}):null]})})}function rke(e){return`${e.provider}/${e.id}`}var z0=`pibo.chat.lastSelection`,B0=`pibo.chat.sessionView`,V0=`pibo.chat.composerDraft.`,H0=`pibo.chat.composerHistory`,U0=`pibo.chat.showThinking`,W0=`pibo.chat.expandThinking`,G0=`pibo.chat.showRawEvents`,K0=`pibo.chat.showArchived`,q0=`pibo.chat.showArchivedRooms`,J0=`pibo.chat.newSessionProfile`,Y0=100;function X0(){try{let e=localStorage.getItem(z0);if(!e)return{};let t=JSON.parse(e);if(!l2(t))return{};let n=l2(t.sessionsByRoom)?Object.fromEntries(Object.entries(t.sessionsByRoom).filter(e=>typeof e[0]==`string`&&typeof e[1]==`string`&&!!e[1])):void 0;return{roomId:typeof t.roomId==`string`&&t.roomId?t.roomId:void 0,piboSessionId:typeof t.piboSessionId==`string`&&t.piboSessionId?t.piboSessionId:void 0,...n&&Object.keys(n).length?{sessionsByRoom:n}:{}}}catch{return{}}}function ike(e){try{let t={...X0().sessionsByRoom??{},...e.sessionsByRoom??{}};e.roomId&&e.piboSessionId&&(t[e.roomId]=e.piboSessionId),localStorage.setItem(z0,JSON.stringify({roomId:e.roomId,piboSessionId:e.piboSessionId,...Object.keys(t).length?{sessionsByRoom:t}:{}}))}catch{}}function Z0(e){try{let t=X0();if(!t.sessionsByRoom?.[e])return;let{[e]:n,...r}=t.sessionsByRoom;localStorage.setItem(z0,JSON.stringify({roomId:t.roomId,piboSessionId:t.piboSessionId,...Object.keys(r).length?{sessionsByRoom:r}:{}}))}catch{}}function Q0(e){try{return localStorage.getItem(V0+e)??``}catch{return``}}function $0(e,t){try{let n=V0+e;t?localStorage.setItem(n,t):localStorage.removeItem(n)}catch{}}function e2(){try{let e=localStorage.getItem(H0);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.trim().length>0).slice(-Y0):[]}catch{return[]}}function ake(e){let t=e.trim();if(!t)return;let n=e2();if(n.at(-1)!==t)try{localStorage.setItem(H0,JSON.stringify([...n,t].slice(-Y0)))}catch{}}function t2(){try{return localStorage.getItem(B0)===`terminal`?`terminal`:wc}catch{return wc}}function oke(e){try{localStorage.setItem(B0,e)}catch{}}function ske(){return s2(U0,!0)}function n2(e){c2(U0,e)}function cke(){return s2(W0,!0)}function r2(e){c2(W0,e)}function lke(){return s2(G0,!1)}function i2(e){c2(G0,e)}function uke(){return s2(K0,!1)}function dke(e){c2(K0,e)}function fke(){return s2(q0,!1)}function a2(e){c2(q0,e)}function pke(){try{return localStorage.getItem(J0)??``}catch{return``}}function o2(e){try{localStorage.setItem(J0,e)}catch{}}function mke(){try{localStorage.removeItem(z0)}catch{}}function s2(e,t){try{let n=localStorage.getItem(e);return n===`true`?!0:n===`false`?!1:t}catch{return t}}function c2(e,t){try{localStorage.setItem(e,String(t))}catch{}}function l2(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function u2(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`),Promise.resolve()}finally{document.body.removeChild(t)}}function d2(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function hke({sessionId:e,disabled:t=!1,commands:n,skills:r,value:i,focusSignal:a,selectedWebAnnotations:o,selectedUploadAttachments:s,onValueChange:c,onCommand:l,onDetachWebAnnotation:u,onClearWebAnnotations:d,onAttachUploadedFiles:f,onDetachUploadAttachment:p,onClearUploadAttachments:m,onSend:h}){let g=(0,R.useRef)(null),_=(0,R.useRef)(null),v=(0,R.useRef)(null),y=(0,R.useRef)(null),b=(0,R.useRef)(null),x=(0,R.useRef)(null),S=(0,R.useRef)(null),[C,w]=(0,R.useState)(0),[T,E]=(0,R.useState)(0),[D,O]=(0,R.useState)(0),[k,A]=(0,R.useState)([]),[j,M]=(0,R.useState)(!1),[N,P]=(0,R.useState)(null),[F,ee]=(0,R.useState)(null),te=(0,R.useMemo)(()=>{for(let e=D-1;e>=0;e--){let t=i[e];if(t===` `||t===`
|
|
162
|
+
`):``}function rOe(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean)}function Q1(e,t,n){let r=rOe(n);r.length?e[t]=r:delete e[t]}function iOe({draft:e,nodeId:t,node:n,isSaving:r,onSaveDefinition:i}){let[a,o]=(0,R.useState)(J1(n.promptBuilder)),[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(),[d,f]=(0,R.useState)(`idle`),[p,m]=(0,R.useState)(`saved`),[h,g]=(0,R.useState)();(0,R.useEffect)(()=>{o(J1(n.promptBuilder))},[n,t]),(0,R.useEffect)(()=>{let e=!1;return kye(a||void 0).then(t=>{e||c(t)}).catch(()=>void 0),()=>{e=!0}},[a]),(0,R.useEffect)(()=>{let e=!1;return g(void 0),a?(f(`loading`),Aye(a).then(t=>{e||(u(t.asset),f(`loaded`))}).catch(t=>{e||(u(void 0),f(`error`),g(t instanceof Error?t.message:`Failed to load prompt asset`))}),()=>{e=!0}):(u(void 0),f(`idle`),()=>{e=!0})},[a]);let _=s?.options.find(e=>e.id===a),v=typeof n.promptTemplate==`string`?n.promptTemplate:S1,y=l?.markdown??v,b=`${e.draftId}:${t}:${(l?.id??a)||`direct-prompt`}:${l?.revisionId??`draft`}`,x=!!J1(n.promptBuilder),S=a.startsWith(`ui.promptAssets.`),C=`${typeof n.label==`string`&&n.label.trim()?n.label.trim():t} prompt asset`,w=(0,R.useCallback)(async n=>{try{let r=await jye({assetId:S?a:void 0,sourceRefId:a||void 0,displayName:C,description:`Managed prompt asset for ${t} in draft ${e.draftId}.`,markdown:n});await i(Y1(e.definition,t,r.asset),`Saved prompt asset revision ${r.asset.revisionId} and updated ${t}.`,{editTrigger:`prompt_edit`}),o(r.asset.id),u(r.asset),g(`Saved ${r.asset.displayName} as revision ${r.asset.revisionId}; draft now pins ${r.asset.contentHash}.`)}catch(e){throw g(e instanceof Error?e.message:`Failed to save prompt asset revision`),e}},[e.definition,e.draftId,t,i,C,a,S]),T=async()=>{l&&(await i(Y1(e.definition,t,l),`Updated ${t} to use prompt asset ${l.id}.`,{editTrigger:`prompt_edit`}),g(`Draft node ${t} now uses ${l.displayName} at ${l.contentHash}.`))};return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,"aria-label":`Prompt asset Markdown editor`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Prompt asset Markdown editor`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Edit prompt assets with the same Markdown editor pattern as Context Files. Saving creates a managed UI asset revision, updates this draft node to a prompt asset ref, and pins the revision id plus content hash in the Pibo Workflow IR.`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Prompt asset ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a,onChange:e=>o(e.target.value),disabled:r,children:[(0,z.jsx)(`option`,{value:``,children:`Create managed asset from direct prompt template`}),s?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:s?.diagnostics??[]}),_?(0,z.jsx)(I1,{option:_,badge:_.kind===`ui`?`managed prompt asset`:`registered prompt asset`}):null,d===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-2 text-[11px] leading-5 text-red-200`,role:`alert`,children:h??`Failed to load prompt asset.`}):null,(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:(0,z.jsx)(Gz,{documentKey:b,initialMarkdown:y,onPersist:w,onSaveStateChange:m})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:x?`promptBuilder ref`:`direct promptTemplate source`}),(0,z.jsx)(P1,{label:`Markdown save: ${p}`}),l?(0,z.jsx)(P1,{label:`${l.source} · ${l.revisionId}`}):null]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void T(),disabled:r||!l,children:[(0,z.jsx)(Bs,{size:13}),`Use selected asset on draft`]})}),h&&d!==`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-emerald-900/60 bg-emerald-950/20 p-2 text-[11px] leading-5 text-emerald-200`,role:`status`,children:h}):null,(0,z.jsx)(`div`,{className:`text-[11px] leading-5 text-slate-500`,children:`Code/plugin prompt assets are not mutated. Editing a registered asset copies the Markdown into a managed UI prompt asset; later saves append revisions and only affect this draft or future workflow versions that reference the new revision.`})]})}function aOe({draft:e,selectedElement:t,nodeIds:n,isSaving:r,onSaveDefinition:i}){let a=t?.type===`node`?I$(e.definition)[t.id]:void 0,o=t?.type===`edge`?L$(e.definition)[t.id]:void 0;return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Workflow inspectors`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:`Workflow inspectors`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Inspector saves update the same Pibo Workflow IR draft as the graph canvas; XState remains projection-only.`})]}),(0,z.jsx)(cOe,{draft:e,isSaving:r,onSaveDefinition:i}),t?.type===`node`&&a?(0,z.jsx)(lOe,{draft:e,nodeId:t.id,node:a,isSaving:r,onSaveDefinition:i}):t?.type===`edge`&&o?(0,z.jsx)(uOe,{draft:e,edgeId:t.id,edge:o,nodeIds:n,isSaving:r,onSaveDefinition:i}):(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Select a canvas node or edge to open the node or edge inspector. Workflow settings remain editable at all times.`})]})}function oOe(e,t){return e.filter(e=>e.nodeId===t||e.path?.startsWith(`$.nodes.${t}`))}function sOe(e,t){return e.filter(e=>e.edgeId===t||e.path?.startsWith(`$.edges.${t}`))}function cOe({draft:e,isSaving:t,onSaveDefinition:n}){let[r,i]=(0,R.useState)(()=>K1(e.definition));(0,R.useEffect)(()=>{i(K1(e.definition))},[e.definition]);let a=(e,t)=>{i(n=>({...n,[e]:t}))};return(0,z.jsxs)(`details`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,open:!0,children:[(0,z.jsx)(`summary`,{className:`cursor-pointer text-xs font-bold text-slate-200`,children:`Workflow settings inspector`}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Workflow title`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:r.title,onChange:e=>a(`title`,e.target.value)})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Workflow description`}),(0,z.jsx)(`textarea`,{className:`min-h-20 rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:r.description,onChange:e=>a(`description`,e.target.value)})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(n0,{label:`Workflow input port`,kind:r.inputKind,description:r.inputDescription,schemaText:r.inputSchemaText,onKindChange:e=>a(`inputKind`,e),onDescriptionChange:e=>a(`inputDescription`,e),onSchemaChange:e=>a(`inputSchemaText`,e)}),(0,z.jsx)(n0,{label:`Workflow output port`,kind:r.outputKind,description:r.outputDescription,schemaText:r.outputSchemaText,onKindChange:e=>a(`outputKind`,e),onDescriptionChange:e=>a(`outputDescription`,e),onSchemaChange:e=>a(`outputSchemaText`,e)})]}),(0,z.jsx)(fOe,{fields:r.globalStateFields,onAddField:()=>{i(e=>({...e,globalStateFields:[...e.globalStateFields,QDe(e.globalStateFields)]}))},onRemoveField:e=>{i(t=>({...t,globalStateFields:t.globalStateFields.filter((t,n)=>n!==e)}))},onUpdateField:(e,t,n)=>{i(r=>({...r,globalStateFields:r.globalStateFields.map((r,i)=>i===e?{...r,[t]:n}:r)}))}}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(a0,{label:`metadata.tags`,value:r.metadataTags,onChange:e=>a(`metadataTags`,e)}),(0,z.jsx)(a0,{label:`metadata.useWhen`,value:r.metadataUseWhen,onChange:e=>a(`metadataUseWhen`,e)}),(0,z.jsx)(a0,{label:`metadata.notFor`,value:r.metadataNotFor,onChange:e=>a(`metadataNotFor`,e)}),(0,z.jsx)(a0,{label:`metadata.examples`,value:r.metadataExamples,onChange:e=>a(`metadataExamples`,e)})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>{n(ZDe(e.definition,r),`Saved workflow settings inspector edits to the draft IR.`,{editTrigger:nOe(e.definition,r)?`state_edit`:`schema_edit`})},disabled:t,children:[t?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save workflow settings`]})]})]})}function lOe({draft:e,nodeId:t,node:n,isSaving:r,onSaveDefinition:i}){let[a,o]=(0,R.useState)(()=>i1(n)),[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(),[d,f]=(0,R.useState)(),[p,m]=(0,R.useState)(),[h,g]=(0,R.useState)(),_=z$(n),v=oOe(e.diagnostics,t),y=d?.options.find(e=>e.id===(d?.selectedRefId??a.adapterRef)),b=(0,R.useMemo)(()=>new Set(a.humanActionRefs.map(e=>e.id)),[a.humanActionRefs]);(0,R.useEffect)(()=>{o(i1(n))},[n,t]),(0,R.useEffect)(()=>{if(_!==`agent`)return;let e=!1;return iJ(a.profileId||void 0).then(t=>{e||c(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.profileId]),(0,R.useEffect)(()=>{if(_!==`code`)return;let e=!1;return aJ(a.handlerId||void 0).then(t=>{e||u(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.handlerId]),(0,R.useEffect)(()=>{if(_!==`adapter`)return;let e=!1;return oJ(a.adapterRef||void 0).then(t=>{e||f(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.adapterRef]),(0,R.useEffect)(()=>{if(_!==`workflow`)return;let e=!1,t=T1(a.workflowVersionKey);return cJ({selectedWorkflowId:t?.workflowId,selectedWorkflowVersion:t?.workflowVersion}).then(t=>{e||m(t)}).catch(()=>void 0),()=>{e=!0}},[_,a.workflowVersionKey]),(0,R.useEffect)(()=>{if(_!==`human`)return;let e=!1;return sJ().then(t=>{e||g(t)}).catch(()=>void 0),()=>{e=!0}},[_]);let x=(e,t)=>{o(n=>({...n,[e]:t}))},S=(e,t)=>{o(n=>({...n,humanActionRefs:rDe(n.humanActionRefs,e,t)}))};return(0,z.jsxs)(`details`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,open:!0,children:[(0,z.jsxs)(`summary`,{className:`cursor-pointer text-xs font-bold text-slate-200`,children:[`Node inspector: `,t]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${_} node`}),(0,z.jsx)(P1,{label:`${v.length} diagnostics`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Node label`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a.label,onChange:e=>x(`label`,e.target.value)})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Node description`}),(0,z.jsx)(`textarea`,{className:`min-h-16 rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a.description,onChange:e=>x(`description`,e.target.value)})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsx)(r0,{label:`Node input port`,kind:a.inputKind,description:a.inputDescription,schemaText:a.inputSchemaText,onKindChange:e=>x(`inputKind`,e),onDescriptionChange:e=>x(`inputDescription`,e),onSchemaChange:e=>x(`inputSchemaText`,e)}),(0,z.jsx)(r0,{label:`Node output port`,kind:a.outputKind,description:a.outputDescription,schemaText:a.outputSchemaText,onKindChange:e=>x(`outputKind`,e),onDescriptionChange:e=>x(`outputDescription`,e),onSchemaChange:e=>x(`outputSchemaText`,e)})]}),(0,z.jsx)($1,{label:`Node`,definition:e.definition,value:a.stateAccess,onChange:e=>x(`stateAccess`,e)}),_===`agent`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Agent node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Agent profile ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:s?.selectedProfileId??a.profileId,onChange:e=>x(`profileId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a non-archived profile`}),s?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:O1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:s?.diagnostics??[]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Prompt template`}),(0,z.jsx)(`textarea`,{className:`min-h-24 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 font-mono text-slate-100`,value:a.promptTemplate,onChange:e=>x(`promptTemplate`,e.target.value)}),(0,z.jsxs)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:[`Saving direct prompt text writes `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`promptTemplate`}),` on this Pibo Workflow IR node.`]})]}),(0,z.jsx)(iOe,{draft:e,nodeId:t,node:n,isSaving:r,onSaveDefinition:i})]}):null,_===`code`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Code node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Registered code handler`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:l?.selectedHandlerId??a.handlerId,onChange:e=>x(`handlerId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered handler ref`}),l?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:k1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:l?.diagnostics??[]})]}):null,_===`adapter`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Adapter node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Registered adapter ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:d?.selectedRefId??a.adapterRef,onChange:e=>x(`adapterRef`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered adapter ref`}),d?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),(0,z.jsx)(F1,{diagnostics:d?.diagnostics??[]}),y?.paramsSchema?(0,z.jsx)(o0,{label:`Adapter params JSON`,schema:y.paramsSchema,value:a.adapterParamsText,onChange:e=>x(`adapterParamsText`,e)}):null,(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-2 text-[11px] leading-5 text-slate-500`,children:`Adapter nodes store only a registered deterministic adapter ref. Inline transformation code and hidden LLM coercion are not exposed by the UI.`})]}):null,_===`workflow`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Workflow node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Nested workflow ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:p?.selectedWorkflowId&&p.selectedWorkflowVersion?w1(p.selectedWorkflowId,p.selectedWorkflowVersion):a.workflowVersionKey,onChange:e=>x(`workflowVersionKey`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select a published workflow version`}),p?.options.map(e=>(0,z.jsx)(`option`,{value:j1(e),children:M1(e)},j1(e)))]})]}),(0,z.jsx)(z1,{diagnostics:p?.diagnostics??[],ariaLabel:`Workflow node diagnostics`})]}):null,_===`human`?(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Human node fields`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Human prompt`}),(0,z.jsx)(`textarea`,{className:`min-h-24 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:a.humanPrompt,onChange:e=>x(`humanPrompt`,e.target.value)})]}),(0,z.jsx)(i0,{label:`Human node resume payload schema JSON`,value:a.humanSchemaText,onChange:e=>x(`humanSchemaText`,e)}),(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,"aria-label":`Human action choices`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Registered action choices`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Actions are selected from the Workflow Registry. The label, action kind, and payload requirements come from picker metadata.`})]}),h?.options.length?h.options.map(e=>(0,z.jsxs)(`label`,{className:`grid gap-1 rounded-sm border border-slate-800 bg-[#101d22] p-2 text-slate-300`,children:[(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-2 font-semibold`,children:[(0,z.jsx)(`input`,{type:`checkbox`,className:`h-3.5 w-3.5 accent-[#11a4d4]`,checked:b.has(e.id),onChange:t=>S(e,t.target.checked)}),(0,z.jsx)(`span`,{children:e.displayName}),(0,z.jsx)(P1,{label:`kind: ${e.kind??`registered`}`})]}),(0,z.jsx)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:e.description??e.id}),(0,z.jsxs)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:[`Payload requirements: `,e.paramsSchema?JSON.stringify(e.paramsSchema):`none`]})]},e.id)):(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 p-2 text-[11px] leading-5 text-slate-500`,children:`No registered human actions are available from the picker.`}),(0,z.jsx)(F1,{diagnostics:h?.diagnostics??[]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,"aria-label":`Selected human action refs`,children:a.humanActionRefs.length?a.humanActionRefs.map(e=>(0,z.jsx)(P1,{label:`${e.id}${e.kind?` (${e.kind})`:``}`},`${e.id}:${e.kind??``}`)):(0,z.jsx)(`span`,{className:`text-slate-500`,children:`No human action refs selected.`})})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 md:grid-cols-[1fr_1fr]`,"aria-label":`Human node timeout`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Timeout kind`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:a.humanTimeoutKind,onChange:e=>x(`humanTimeoutKind`,e.target.value),children:[(0,z.jsx)(`option`,{value:`none`,children:`No timeout`}),(0,z.jsx)(`option`,{value:`milliseconds`,children:`Milliseconds`}),(0,z.jsx)(`option`,{value:`seconds`,children:`Seconds`}),(0,z.jsx)(`option`,{value:`minutes`,children:`Minutes`}),(0,z.jsx)(`option`,{value:`iso8601`,children:`ISO-8601 duration`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Timeout value`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,type:a.humanTimeoutKind===`iso8601`?`text`:`number`,min:a.humanTimeoutKind===`iso8601`?void 0:1,placeholder:a.humanTimeoutKind===`iso8601`?`PT1H`:`60`,value:a.humanTimeoutValue,onChange:e=>x(`humanTimeoutValue`,e.target.value),disabled:a.humanTimeoutKind===`none`})]})]})]}):null,(0,z.jsx)(N1,{diagnostics:v,emptyLabel:`No diagnostics for selected node.`}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>{let r=ZEe(e.definition,t,a),o=YEe(n,a)?`state_edit`:_===`agent`||_===`human`?`prompt_edit`:`schema_edit`;i(r,`Saved node inspector edits for ${t}.`,{editTrigger:o})},disabled:r,children:[r?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save node inspector`]})]})]})}function $1({label:e,definition:t,value:n,onChange:r,allowEdgeWrites:i=!1}){let a=t1(t,n.readScope,[...n.reads,...n.writes]),o=i?X$:JEe,s=t1(t,n.writeScope,[...n.reads,...n.writes]),c=!!n.readPath.trim(),l=!!n.writePath.trim()&&(i||n.writeScope!==`edge`),u=(e,t)=>r({...n,[e]:t}),d=e=>{let t=e===`reads`?n.readScope:n.writeScope,i=(e===`reads`?n.readPath:n.writePath).trim();if(!i)return;let a=`${t}.${i}`,o=n[e];o.includes(a)||r({...n,[e]:[...o,a]})},f=(e,t)=>r({...n,[e]:n[e].filter(e=>e!==t)});return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,"aria-label":`${e} simple state mapping controls`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:[e,` simple state mappings`]}),(0,z.jsxs)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:[`Add simple scoped state reads and writes as Pibo Workflow IR `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`state.reads`}),` and `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`state.writes`}),` arrays. Complex state mapping DSLs remain raw Workflow IR only.`]})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[0.7fr_1fr_auto]`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Read scope`}),(0,z.jsx)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n.readScope,onChange:e=>u(`readScope`,e.target.value),children:X$.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),(0,z.jsx)(e0,{label:`Read path`,value:n.readPath,options:a,onChange:e=>u(`readPath`,e)}),(0,z.jsx)(`button`,{type:`button`,className:`self-end rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>d(`reads`),disabled:!c,children:`Add read`})]}),(0,z.jsx)(t0,{label:`Reads`,entries:n.reads,onRemove:e=>f(`reads`,e)}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[0.7fr_1fr_auto]`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Write scope`}),(0,z.jsx)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n.writeScope,onChange:e=>u(`writeScope`,e.target.value),children:o.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),(0,z.jsx)(e0,{label:`Write path`,value:n.writePath,options:s,onChange:e=>u(`writePath`,e)}),(0,z.jsx)(`button`,{type:`button`,className:`self-end rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>d(`writes`),disabled:!l,children:`Add write`})]}),(0,z.jsx)(t0,{label:`Writes`,entries:n.writes,onRemove:e=>f(`writes`,e)}),n.writeScope===`global`&&!n1(t).length?(0,z.jsx)(`div`,{className:`rounded-sm border border-amber-900/60 bg-amber-950/20 p-2 text-[11px] leading-5 text-amber-100`,children:`Declare global state fields in the workflow settings inspector before selecting global read/write paths.`}):null]})}function e0({label:e,value:t,options:n,onChange:r}){let i=t&&!n.includes(t)?[t,...n]:n;return(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>r(e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select path`}),i.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]})}function t0({label:e,entries:t,onRemove:n}){return(0,z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-semibold text-slate-400`,children:e}),t.length?(0,z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,z.jsxs)(`button`,{type:`button`,className:`rounded-full border border-slate-700 px-2 py-1 text-[11px] text-slate-300 transition hover:border-red-500/60 hover:text-red-100`,onClick:()=>n(e),title:`Remove ${e}`,children:[e,` ×`]},e))}):(0,z.jsxs)(`div`,{className:`text-[11px] text-slate-500`,children:[`No `,e.toLowerCase(),` declared.`]})]})}function uOe({draft:e,edgeId:t,edge:n,nodeIds:r,isSaving:i,onSaveDefinition:a}){let[o,s]=(0,R.useState)(()=>a1(n,r)),[c,l]=(0,R.useState)(),[u,d]=(0,R.useState)(),[f,p]=(0,R.useState)(!1),m=sOe(e.diagnostics,t),h=UDe(e.definition,n),g=m.some(e=>e.code===`WorkflowGraphError.incompatibleEdgePorts`),_=c?.options.find(e=>e.id===(c?.selectedRefId??o.guardHandler)),v=u?.options.find(e=>e.id===(u?.selectedRefId??o.adapterRef));(0,R.useEffect)(()=>{s(a1(n,r))},[n,t,r]),(0,R.useEffect)(()=>{p(!1)},[t]),(0,R.useEffect)(()=>{let e=!1;return Oye(o.guardHandler||void 0).then(t=>{e||l(t)}).catch(()=>void 0),()=>{e=!0}},[o.guardHandler]),(0,R.useEffect)(()=>{let e=!1;return oJ(o.adapterRef||void 0).then(t=>{e||d(t)}).catch(()=>void 0),()=>{e=!0}},[o.adapterRef]);let y=(e,t)=>{s(n=>({...n,[e]:t}))},b=()=>{let r=QEe(e.definition,t,o),i=Z$(n.state,o.stateAccess)?`state_edit`:`edge_edit`;a(r,`Saved edge inspector edits for ${t}.`,{editTrigger:i})};return(0,z.jsxs)(`details`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,open:!0,children:[(0,z.jsxs)(`summary`,{className:`cursor-pointer text-xs font-bold text-slate-200`,children:[`Edge inspector: `,t]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${o.kind} edge`}),(0,z.jsx)(P1,{label:`${m.length} diagnostics`})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Source node`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.sourceNodeId,onChange:e=>y(`sourceNodeId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select source`}),r.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Target node`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.targetNodeId,onChange:e=>y(`targetNodeId`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`Select target`}),r.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Source port id`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.sourcePortId,onChange:e=>y(`sourcePortId`,e.target.value),placeholder:`default`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Target port id`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.targetPortId,onChange:e=>y(`targetPortId`,e.target.value),placeholder:`default`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Edge kind`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.kind,onChange:e=>y(`kind`,e.target.value),children:[(0,z.jsx)(`option`,{value:`data`,children:`data`}),(0,z.jsx)(`option`,{value:`control`,children:`control`}),(0,z.jsx)(`option`,{value:`error`,children:`error`}),(0,z.jsx)(`option`,{value:`resume`,children:`resume`})]})]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Guard ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:c?.selectedRefId??o.guardHandler,onChange:e=>y(`guardHandler`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`No guard`}),c?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Guard priority`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:o.guardPriority,onChange:e=>y(`guardPriority`,e.target.value),placeholder:`optional integer`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300 md:col-span-2`,children:[(0,z.jsx)(`span`,{children:`Edge adapter ref`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:u?.selectedRefId??o.adapterRef,onChange:e=>y(`adapterRef`,e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:`No edge adapter`}),u?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]})]}),_?.paramsSchema?(0,z.jsx)(o0,{label:`Guard params JSON`,schema:_.paramsSchema,value:o.guardParamsText,onChange:e=>y(`guardParamsText`,e)}):null,v?.paramsSchema?(0,z.jsx)(o0,{label:`Edge adapter params JSON`,schema:v.paramsSchema,value:o.adapterParamsText,onChange:e=>y(`adapterParamsText`,e)}):null,(0,z.jsx)($1,{label:`Edge`,definition:e.definition,value:o.stateAccess,onChange:e=>y(`stateAccess`,e),allowEdgeWrites:!0}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border px-3 py-2 text-xs font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 ${g?`border-amber-600/70 text-amber-100 hover:border-amber-400`:`border-slate-700 text-slate-300 hover:border-[#11a4d4]/60 hover:text-slate-100`}`,onClick:()=>p(!0),disabled:i||!h.sourcePort||!h.targetPort,children:[(0,z.jsx)(bs,{size:13}),g?`Fix incompatible edge with adapter`:`Open compatible edge adapter dialog`]}),f?(0,z.jsx)(dOe,{draft:e,edgeId:t,edge:n,edgePortDetails:h,isSaving:i,onClose:()=>p(!1),onSaveDefinition:a}):null,(0,z.jsx)(F1,{diagnostics:[...c?.diagnostics??[],...u?.diagnostics??[]]}),(0,z.jsx)(N1,{diagnostics:m,emptyLabel:`No diagnostics for selected edge.`}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:b,disabled:i||!o.sourceNodeId||!o.targetNodeId,children:[i?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save edge inspector`]})]})]})}function dOe({draft:e,edgeId:t,edge:n,edgePortDetails:r,isSaving:i,onClose:a,onSaveDefinition:o}){let[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(WDe(n)),[d,f]=(0,R.useState)(`loading`),[p,m]=(0,R.useState)();(0,R.useEffect)(()=>{let e=!1;return f(`loading`),m(void 0),oJ(l||void 0).then(t=>{e||(c(t),u(e=>e||(t.options[0]?.id??``)),f(`loaded`))}).catch(t=>{e||(m(t instanceof Error?t.message:`Failed to load compatible adapters`),f(`error`))}),()=>{e=!0}},[l]);let h=s?.options.find(e=>e.id===l),g=!!(h&&r.sourcePort&&r.targetPort&&d===`loaded`&&!i),_=async()=>{l&&(await o(GDe(e.definition,t,l),`Applied ${l} as edge adapter for ${t}.`,{editTrigger:`edge_edit`}),a())},v=async()=>{l&&(await o(KDe(e.definition,t,l),`Inserted adapter node for ${t} using ${l}.`,{editTrigger:`graph_edit`}),a())};return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`workflow-edge-adapter-dialog-title`,children:(0,z.jsxs)(`div`,{className:`max-h-[88vh] w-full max-w-3xl overflow-auto rounded-sm border border-slate-700 bg-[#101d22] p-4 shadow-2xl shadow-black/40`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(bs,{size:13}),`Compatible edge adapter dialog`]}),(0,z.jsxs)(`h4`,{id:`workflow-edge-adapter-dialog-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:[`Choose a registered adapter for `,t]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-500`,children:`The dialog shows the source output and target input schemas from the Pibo Workflow IR. Use a registered adapter as an explicit edge adapter, or insert a visible adapter node between the endpoints.`})]}),(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,onClick:a,children:`Close`})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 md:grid-cols-2`,children:[(0,z.jsx)(L1,{label:`From schema${r.sourceNodeId?` (${r.sourceNodeId})`:``}`,schema:r.sourcePort??null}),(0,z.jsx)(L1,{label:`To schema${r.targetNodeId?` (${r.targetNodeId})`:``}`,schema:r.targetPort??null})]}),(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border p-3 text-xs leading-5 ${r.directlyCompatible?`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`:`border-amber-700/70 bg-amber-950/30 text-amber-100`}`,children:r.directlyCompatible?`These ports are directly compatible. An adapter is optional and remains explicit if selected.`:`These ports are not directly compatible. Select a registered adapter instead of hidden LLM coercion or inline transformation code.`}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 text-xs`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Compatible registered adapter`}),(0,z.jsxs)(`select`,{"aria-label":`Compatible registered adapter`,className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:l,onChange:e=>u(e.target.value),disabled:d===`loading`||d===`error`||i,children:[(0,z.jsx)(`option`,{value:``,children:`Select a registered adapter ref`}),s?.options.map(e=>(0,z.jsx)(`option`,{value:e.id,children:A1(e)},e.id))]})]}),d===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:p??`Failed to load compatible adapters.`}):null,(0,z.jsx)(F1,{diagnostics:s?.diagnostics??[]}),h?(0,z.jsx)(I1,{option:h,badge:`selected adapter`}):null,(0,z.jsxs)(`div`,{className:`grid gap-2`,"aria-label":`Compatible adapter candidates`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Compatible adapter candidates`}),s?.options.map(e=>(0,z.jsx)(I1,{option:e,badge:`compatible adapter`},e.id))]}),(0,z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-2`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void _(),disabled:!g,children:[(0,z.jsx)(bs,{size:13}),`Use as edge adapter`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/50 px-3 py-2 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void v(),disabled:!g,children:[(0,z.jsx)(Ps,{size:13}),`Insert adapter node`]})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:[`Both actions persist Pibo Workflow IR only. Edge adapters store `,(0,z.jsx)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:`adapter.transform.id`}),`; inserted adapter nodes store a visible deterministic adapter handler ref.`]})]})]})})}function n0({label:e,kind:t,description:n,schemaText:r,onKindChange:i,onDescriptionChange:a,onSchemaChange:o}){return(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>i(e.target.value),children:[(0,z.jsx)(`option`,{value:`text`,children:`text`}),(0,z.jsx)(`option`,{value:`json`,children:`json`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Description`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n,onChange:e=>a(e.target.value),placeholder:`Optional port description`})]}),t===`json`?(0,z.jsx)(i0,{label:`${e} raw JSON schema`,value:r,onChange:o}):null]})}function r0({label:e,kind:t,description:n,schemaText:r,onKindChange:i,onDescriptionChange:a,onSchemaChange:o}){return(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>i(e.target.value),children:[(0,z.jsx)(`option`,{value:`none`,children:`inherit/default`}),(0,z.jsx)(`option`,{value:`text`,children:`text`}),(0,z.jsx)(`option`,{value:`json`,children:`json`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Description`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 text-slate-100`,value:n,onChange:e=>a(e.target.value),disabled:t===`none`,placeholder:`Optional port description`})]}),t===`json`?(0,z.jsx)(i0,{label:`${e} raw JSON schema`,value:r,onChange:o}):null]})}function fOe({fields:e,onAddField:t,onRemoveField:n,onUpdateField:r}){return(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#101d22] p-3`,"aria-label":`Workflow global state fields`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Workflow global state fields`}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Declare simple global state paths for node and edge state mapping dropdowns. State schema changes run draft validation and may invalidate connected graph diagnostics without blocking draft save.`})]}),e.length?e.map((e,t)=>(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#151f24]/70 p-2 md:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Global state path`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:e.path,onChange:e=>r(t,`path`,e.target.value),placeholder:`projectGoal`})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Merge policy`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:e.mergeKind,onChange:e=>r(t,`mergeKind`,e.target.value),children:[(0,z.jsx)(`option`,{value:`none`,children:`No merge policy`}),(0,z.jsx)(`option`,{value:`replace`,children:`replace`}),(0,z.jsx)(`option`,{value:`append`,children:`append`}),(0,z.jsx)(`option`,{value:`shallowMerge`,children:`shallowMerge`})]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300 md:col-span-2`,children:[(0,z.jsx)(`span`,{children:`Description`}),(0,z.jsx)(`input`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:e.description,onChange:e=>r(t,`description`,e.target.value),placeholder:`Optional state description`})]}),(0,z.jsx)(`div`,{className:`md:col-span-2`,children:(0,z.jsx)(i0,{label:`Global state ${e.path||t+1} schema JSON`,value:e.schemaText,onChange:e=>r(t,`schemaText`,e)})}),(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-red-500/70 hover:text-red-100`,onClick:()=>n(t),children:`Remove state field`})]},`${t}:${e.path}`)):(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 p-2 text-[11px] leading-5 text-slate-500`,children:`No global state fields declared. Local and edge path dropdowns remain available for simple node-local state and edge payload access.`}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-2 rounded-sm border border-slate-700 px-3 py-2 text-xs font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,onClick:t,children:[(0,z.jsx)(Ps,{size:13}),`Add global state field`]})]})}function i0({label:e,value:t,onChange:n}){return(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsx)(`textarea`,{className:`min-h-36 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 font-mono text-[11px] leading-5 text-slate-100`,value:t,onChange:e=>n(e.target.value),placeholder:JSON.stringify(Y$,null,2),spellCheck:!1,"aria-label":e}),(0,z.jsx)(`span`,{className:`text-[11px] font-normal leading-5 text-slate-500`,children:`Raw JSON Schema subset only. Unsupported keywords return workflow diagnostics; no Zod, AJV, or form-builder schema layer is introduced.`})]})}function a0({label:e,value:t,onChange:n}){return(0,z.jsxs)(`label`,{className:`grid gap-1 font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:e}),(0,z.jsx)(`textarea`,{className:`min-h-16 rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-slate-100`,value:t,onChange:e=>n(e.target.value),placeholder:`One value per line`})]})}function o0({label:e,schema:t,value:n,onChange:r}){return(0,z.jsxs)(`div`,{className:`grid gap-2 rounded-sm border border-slate-800 bg-[#101d22] p-2`,"aria-label":e,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-slate-500`,children:e}),(0,z.jsx)(L1,{label:`paramsSchema`,schema:t}),(0,z.jsx)(`textarea`,{className:`min-h-24 rounded-sm border border-slate-700 bg-[#151f24] px-2 py-1.5 font-mono text-[11px] leading-5 text-slate-100`,value:n,onChange:e=>r(e.target.value),placeholder:`{}`,"aria-label":`${e} value`}),(0,z.jsx)(`div`,{className:`text-[11px] leading-5 text-slate-500`,children:`Params save as data on the selected registry ref. No inline code path is created.`})]})}function pOe(e){let t=new Map;for(let n of e){let e=t.get(n.id);if(e){e.records.push(n),n.status===`published`&&e.records[0]?.status!==`published`&&(e.title=n.title,e.source=n.source);continue}t.set(n.id,{workflowId:n.id,title:n.title,source:n.source,records:[n]})}return[...t.values()]}function mOe(e){return e.status===`published`?`Published workflow version — selectable for Project sessions and safe to duplicate into UI drafts.`:e.status===`archived`?`Archived workflow version — shown for lifecycle history but hidden from default Project session creation choices.`:e.status===`deleted`?`Deleted workflow definition — historical runs must render from immutable snapshots instead of live catalog links.`:`Draft workflow version — not published and unavailable for Project session creation.`}function s0(e,t){return e.actions.includes(t)}function hOe(e){switch(e){case`view`:return`View`;case`duplicate`:return`Duplicate`;case`create_project_session`:return`Create Project session`;case`edit_draft`:return`Edit draft`;case`validate`:return`Validate`;case`publish`:return`Publish`;case`create_next_draft`:return`Create next draft`;case`version_history`:return`Version history`;case`archive`:return`Archive`;case`delete`:return`Delete`}}function gOe({activeDraftId:e}){let[t,n]=(0,R.useState)([]),[r,i]=(0,R.useState)(`loading`),[a,o]=(0,R.useState)(),[s,c]=(0,R.useState)(),[l,u]=(0,R.useState)(),[d,f]=(0,R.useState)(),[p,m]=(0,R.useState)(),[h,g]=(0,R.useState)(),[_,v]=(0,R.useState)(``),[y,b]=(0,R.useState)(),x=!!(s||l||d||p),S=(0,R.useCallback)(async()=>{i(`loading`),o(void 0);try{n((await lJ()).options),i(`loaded`)}catch(e){o(e instanceof Error?e.message:`Failed to load workflow version history`),i(`error`)}},[]);(0,R.useEffect)(()=>{S()},[S]);let C=(0,R.useMemo)(()=>pOe(t),[t]),w=async(e,t)=>{c(w1(e,t)),b(void 0);try{D1((await Lye(e,{version:t})).builderPath)}catch(e){b(e instanceof Error?e.message:`Failed to duplicate workflow into a draft`),c(void 0)}},T=async(e,t)=>{u(w1(e,t)),b(void 0);try{D1((await Rye(e,{version:t})).builderPath)}catch(e){b(e instanceof Error?e.message:`Failed to create next-version draft`),u(void 0)}},E=(e,t)=>{v(``),b(void 0),g({kind:`archive`,workflowId:e,title:t})},D=(e,t)=>{v(``),b(void 0),g({kind:`delete`,workflowId:e,title:t})},O=async()=>{if(!h||h.kind!==`archive`)return;let{workflowId:e}=h;f(e),b(void 0);try{await zye(e),g(void 0),await S()}catch(e){b(e instanceof Error?e.message:`Failed to archive workflow`)}finally{f(void 0)}},k=async()=>{if(!h||h.kind!==`delete`)return;let{workflowId:e}=h;m(e),b(void 0);try{await Bye(e,{confirmWorkflowId:_}),g(void 0),v(``),await S()}catch(e){b(e instanceof Error?e.message:`Failed to delete workflow`)}finally{m(void 0)}};return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:`UI draft`}),(0,z.jsx)(`h3`,{className:`mt-1 text-sm font-bold text-slate-100`,children:`Starter UI draft`}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:`A draft row opens the builder route and loads a partial Pibo Workflow IR wrapper with diagnostics.`})]}),(0,z.jsx)(`a`,{className:`shrink-0 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100`,href:vDe(_De),children:`Open draft`})]}),e===`v2-starter-draft`?(0,z.jsx)(`div`,{className:`mt-3 text-[11px] font-semibold text-emerald-300`,children:`Currently open in the builder.`}):null]}),(0,z.jsx)(bOe,{target:h,busy:x,deleteConfirmWorkflowId:_,onDeleteConfirmChange:v,onCancel:()=>{g(void 0),v(``)},onConfirmArchive:()=>void O(),onConfirmDelete:()=>void k()}),(0,z.jsxs)(`div`,{className:`grid gap-3`,"aria-label":`Workflow version history`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:[(0,z.jsx)(hs,{size:13}),`Version history`]}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-5 text-slate-500`,children:`Published versions are listed in deterministic workflow/version order. Only published rows are selectable for Project sessions; archived rows stay visible as history while deleted workflows render from Project snapshots.`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 px-2 py-1 text-[11px] font-semibold text-slate-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void S(),disabled:r===`loading`,children:[r===`loading`?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ls,{size:12}),`Refresh`]})]}),r===`loading`?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4 text-xs text-slate-400`,"aria-live":`polite`,children:[(0,z.jsx)(Cs,{size:14,className:`animate-spin text-[#11a4d4]`}),`Loading workflow version history…`]}):null,r===`error`?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:a??`Failed to load workflow version history.`}):null,r===`loaded`&&C.length===0?(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-700 bg-[#101d22]/70 p-4 text-xs text-slate-500`,children:`No workflow versions are registered yet.`}):null,r===`loaded`?C.map(e=>(0,z.jsx)(_Oe,{group:e,busy:x,duplicatingKey:s,editingKey:l,archivingWorkflowId:d,deletingWorkflowId:p,onDuplicate:w,onEditPublished:T,onArchive:E,onDelete:D},e.workflowId)):null]}),y?(0,z.jsx)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs leading-5 text-red-200`,role:`alert`,children:y}):null]})}function _Oe({group:e,busy:t,duplicatingKey:n,editingKey:r,archivingWorkflowId:i,deletingWorkflowId:a,onDuplicate:o,onEditPublished:s,onArchive:c,onDelete:l}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,"aria-label":`Version history for ${e.workflowId}`,children:[(0,z.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`div`,{className:`font-semibold text-slate-100`,children:e.title}),(0,z.jsx)(P1,{label:`${e.records.length} version${e.records.length===1?``:`s`}`}),(0,z.jsx)(P1,{label:`${e.source} source`})]}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-500`,children:e.workflowId})]})}),(0,z.jsx)(`div`,{className:`mt-3 grid gap-2`,children:e.records.map(e=>(0,z.jsx)(vOe,{record:e,busy:t,duplicatingKey:n,editingKey:r,archivingWorkflowId:i,deletingWorkflowId:a,onDuplicate:o,onEditPublished:s,onArchive:c,onDelete:l},w1(e.id,e.version)))})]})}function vOe({record:e,busy:t,duplicatingKey:n,editingKey:r,archivingWorkflowId:i,deletingWorkflowId:a,onDuplicate:o,onEditPublished:s,onArchive:c,onDelete:l}){let u=w1(e.id,e.version),d=e.status===`published`,f=s0(e,`create_next_draft`),p=s0(e,`duplicate`),m=s0(e,`create_project_session`),h=s0(e,`view`),g=d&&s0(e,`archive`),_=d&&s0(e,`delete`);return(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-xs leading-5 text-slate-400`,children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsxs)(`div`,{className:`font-mono text-[11px] font-semibold text-slate-200`,children:[e.id,`@`,e.version]}),(0,z.jsx)(P1,{label:e.status}),(0,z.jsx)(P1,{label:`${e.source} source`}),e.tags.map(e=>(0,z.jsx)(P1,{label:e},e))]}),e.description?(0,z.jsx)(`div`,{className:`mt-2 text-slate-500`,children:e.description}):null,(0,z.jsx)(`div`,{className:`mt-2 text-[11px] ${d?`text-emerald-300`:`text-amber-200`}`,children:mOe(e)}),(0,z.jsx)(yOe,{actions:e.actions})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2`,children:[f?(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void s(e.id,e.version),disabled:t,children:[r===u?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(vs,{size:13}),`Edit published`]}):null,p?(0,z.jsxs)(`button`,{type:`button`,className:`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-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void o(e.id,e.version),disabled:t,children:[n===u?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Qo,{size:13}),`Duplicate to draft`]}):null,m?(0,z.jsxs)(`a`,{className:`inline-flex items-center justify-center gap-1 rounded-sm border border-emerald-700/70 px-3 py-1.5 text-xs font-semibold text-emerald-100 transition hover:border-emerald-500 hover:text-emerald-50`,href:`/apps/chat/projects`,children:[(0,z.jsx)(As,{size:13}),`Create Project session`]}):(0,z.jsx)(`div`,{className:`max-w-44 rounded-sm border border-amber-800/70 bg-amber-950/20 p-2 text-[11px] text-amber-100`,children:`Unavailable for Project session selection.`}),h?(0,z.jsxs)(`a`,{className:`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-300 transition hover:border-[#11a4d4]/60 hover:text-slate-100`,href:E1(e.id,e.version),children:[(0,z.jsx)(rs,{size:13}),`View details`]}):null,g?(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-amber-700/70 px-3 py-1.5 text-xs font-semibold text-amber-100 transition hover:border-amber-500 hover:text-amber-50 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>c(e.id,e.title),disabled:t,children:[i===e.id?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(To,{size:13}),`Archive workflow`]}):null,_?(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-red-800/80 px-3 py-1.5 text-xs font-semibold text-red-100 transition hover:border-red-500 hover:text-red-50 disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>l(e.id,e.title),disabled:t,children:[a===e.id?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(qs,{size:13}),`Delete workflow`]}):null]})]})})}function yOe({actions:e}){return(0,z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,"aria-label":`Workflow Library source/status actions`,children:e.map(e=>(0,z.jsx)(P1,{label:hOe(e)},e))})}function bOe({target:e,busy:t,deleteConfirmWorkflowId:n,onDeleteConfirmChange:r,onCancel:i,onConfirmArchive:a,onConfirmDelete:o}){if(!e)return null;let s=e.kind===`delete`,c=n.trim()===e.workflowId;return(0,z.jsx)(`div`,{className:`rounded-sm border p-4 text-xs leading-5 ${s?`border-red-900/70 bg-red-950/25 text-red-100`:`border-amber-800/70 bg-amber-950/20 text-amber-100`}`,role:`region`,"aria-label":`${s?`Delete`:`Archive`} workflow confirmation`,children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em]`,children:[(0,z.jsx)(Js,{size:13}),`Confirm `,s?`delete`:`archive`]}),(0,z.jsx)(`h3`,{className:`mt-1 text-sm font-bold text-slate-100`,children:e.title}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-slate-300`,children:e.workflowId}),s?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`mt-3`,children:`Deleting tombstones the live workflow identity. It removes this workflow from the default catalog, workflow pickers, duplicate/edit/publish/archive actions, and new Project session creation.`}),(0,z.jsx)(`p`,{className:`mt-2`,children:`Historical Project runs remain inspectable from immutable snapshots and show a definition-deleted state instead of a broken live catalog link.`}),(0,z.jsxs)(`label`,{className:`mt-3 block text-[11px] font-semibold text-red-100`,children:[`Type the workflow id to confirm delete`,(0,z.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),className:`mt-1 w-full rounded-sm border border-red-900/70 bg-[#101d22] px-2 py-1.5 font-mono text-xs text-slate-100 outline-none focus:border-red-400`,placeholder:e.workflowId,disabled:t})]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`mt-3`,children:`Archiving applies to the whole workflow identity. It hides this workflow from the default catalog and Project workflow selection lists.`}),(0,z.jsx)(`p`,{className:`mt-2`,children:`Published versions stay available only through archive filters and historical run links, and historical Project runs continue to render from their snapshots.`})]})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border border-slate-700 px-3 py-1.5 text-xs font-semibold text-slate-300 transition hover:border-slate-500 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50`,onClick:i,disabled:t,children:`Cancel`}),(0,z.jsx)(`button`,{type:`button`,className:`rounded-sm border px-3 py-1.5 text-xs font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-red-700 text-red-100 hover:border-red-400`:`border-amber-600 text-amber-100 hover:border-amber-400`}`,onClick:s?o:a,disabled:t||s&&!c,children:s?`Delete workflow`:`Archive workflow`})]})]})})}var c0=`WorkflowBuilderWarning.invalidRawIrText`;function xOe({draft:e,onDraftChange:t}){let n=(0,R.useMemo)(()=>JSON.stringify(e.definition,null,2),[e.definition]),[r,i]=(0,R.useState)(n),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(`idle`),[l,u]=(0,R.useState)(),d=e.diagnostics.filter(e=>e.code===c0);(0,R.useEffect)(()=>{a||i(n)},[n,a]);let f=async()=>{c(`saving`),u(void 0);try{let n=await uJ(e.draftId,{rawDefinitionText:r,editTrigger:`raw_ir_edit`});if(t(n.draft),n.diagnostics.some(e=>e.code===c0)){o(!0),c(`warning`),u(`Raw Workflow IR text was not saved; the last valid draft object remains unchanged.`);return}i(JSON.stringify(n.draft.definition,null,2)),o(!1),c(`saved`),u(`Saved raw Workflow IR to the draft. Validation state: ${n.validation.validationState}.`)}catch(e){c(`error`),u(e instanceof Error?e.message:`Failed to save raw Workflow IR text`)}};return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-label":`Raw Pibo Workflow IR editor panel`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Raw Pibo Workflow IR editor`}),(0,z.jsx)(`h4`,{className:`mt-1 text-sm font-bold text-slate-100`,children:`Safe raw Workflow IR sync`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-400`,children:`Edit only Pibo Workflow IR JSON. Saving valid JSON parses into the same draft object used by the graph and inspectors. Invalid JSON or non-object text returns a warning diagnostic and keeps the last valid draft object unchanged; raw XState JSON is not exposed here.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`last valid rev ${e.revision}`}),a?(0,z.jsx)(P1,{label:`unsaved raw text`}):null]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.72fr)]`,children:[(0,z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,z.jsx)(`label`,{className:`text-[11px] font-semibold uppercase tracking-[0.12em] text-slate-500`,htmlFor:`workflow-raw-ir-editor`,children:`Editable Pibo Workflow IR JSON`}),(0,z.jsx)(`textarea`,{id:`workflow-raw-ir-editor`,"aria-label":`Raw Pibo Workflow IR editor`,className:`min-h-[26rem] rounded-sm border border-slate-800 bg-[#101d22] p-3 font-mono text-[11px] leading-5 text-slate-100 outline-none transition focus:border-[#11a4d4]`,spellCheck:!1,value:r,onChange:e=>{i(e.target.value),o(!0),c(`idle`),u(void 0)}}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-emerald-600/70 px-3 py-1.5 text-xs font-semibold text-emerald-200 transition hover:border-emerald-400 hover:text-white disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void f(),disabled:s===`saving`,children:[s===`saving`?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Bs,{size:13}),`Save raw IR`]}),(0,z.jsxs)(`button`,{type:`button`,className:`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-300 transition hover:border-slate-500 hover:text-white`,onClick:()=>{i(n),o(!1),c(`idle`),u(`Reset the editor from the last valid Pibo Workflow IR object.`)},disabled:s===`saving`,children:[(0,z.jsx)(Ls,{size:13}),`Reset from current draft`]})]}),l?(0,z.jsx)(`div`,{className:`rounded-sm border p-3 text-xs leading-5 ${s===`error`?`border-red-900/70 bg-red-950/40 text-red-200`:s===`warning`?`border-amber-700/70 bg-amber-950/30 text-amber-100`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,role:s===`error`||s===`warning`?`alert`:`status`,children:l}):null,d.length?(0,z.jsx)(N1,{diagnostics:d,emptyLabel:`No raw IR parse diagnostics.`}):null]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`mb-2 text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Last valid Pibo Workflow IR object`}),(0,z.jsx)(`pre`,{"aria-label":`Pibo Workflow IR draft`,className:`max-h-[32rem] overflow-auto rounded-sm border border-slate-800 bg-[#101d22] p-3 text-[11px] leading-5 text-slate-200`,children:n})]})]})]})}function SOe({draftId:e,viewWorkflowId:t,viewWorkflowVersion:n}){return(0,z.jsx)(`main`,{className:`h-full min-h-0 overflow-auto bg-[#101d22]`,children:(0,z.jsxs)(`section`,{className:`mx-auto flex w-full max-w-6xl flex-col gap-6 p-6 max-[720px]:p-4`,"aria-labelledby":`workflows-title`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24] p-5 shadow-lg shadow-black/20`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.18em] text-[#11a4d4]`,children:`Workflow UI Authoring V2`}),(0,z.jsx)(`h1`,{id:`workflows-title`,className:`mt-2 text-2xl font-extrabold tracking-tight text-slate-100`,children:`Workflows`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-sm leading-6 text-slate-400`,children:`Browse workflow definitions, duplicate published workflows into UI drafts, and open draft wrappers that edit Pibo Workflow IR from the authenticated Chat Web surface.`})]}),(0,z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[0.9fr_1.1fr]`,children:[(0,z.jsx)(f0,{icon:jo,eyebrow:`Global catalog`,title:`Workflow Library`,description:`Open UI drafts or duplicate published workflow versions into a draft before editing.`,children:(0,z.jsx)(gOe,{activeDraftId:e})}),(0,z.jsx)(f0,{icon:vs,eyebrow:`Visual authoring`,title:`Workflow Builder`,description:`Load a UI draft wrapper and keep Pibo Workflow IR as the editable source of truth.`,children:e?(0,z.jsx)(wOe,{draftId:e}):t&&n?(0,z.jsx)(xDe,{workflowId:t,workflowVersion:n}):(0,z.jsx)(COe,{})})]}),(0,z.jsxs)(`div`,{className:`grid gap-3 rounded-sm border border-slate-800 bg-[#151f24] p-4 text-xs text-slate-400 md:grid-cols-4`,children:[(0,z.jsx)(p0,{icon:Lo,label:`Pibo Workflow IR remains the source of truth`}),(0,z.jsx)(p0,{icon:Qo,label:`Code workflows can be duplicated into UI drafts`}),(0,z.jsx)(p0,{icon:Gs,label:`Workflow capabilities are registered refs only`}),(0,z.jsx)(p0,{icon:vs,label:`XState stays a read-only visualization projection`})]}),(0,z.jsx)(TOe,{})]})})}function COe(){return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,children:[(0,z.jsx)(kOe,{title:`Open a draft to start authoring`,description:`Use the Workflow Library draft row or Duplicate to draft action. The builder route will load a draft wrapper around Pibo Workflow IR, not raw XState source.`}),(0,z.jsx)(l0,{}),(0,z.jsx)(CDe,{})]})}function wOe({draftId:e}){let[t,n]=(0,R.useState)(),[r,i]=(0,R.useState)(`loading`),[a,o]=(0,R.useState)();return(0,R.useEffect)(()=>{let t=!1;return i(`loading`),o(void 0),Pye(e).then(e=>{t||(n(e.draft),i(`loaded`))}).catch(e=>{t||(o(e instanceof Error?e.message:`Failed to load workflow draft`),i(`error`))}),()=>{t=!0}},[e]),r===`loading`?(0,z.jsxs)(`div`,{className:`flex w-full items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4 text-sm text-slate-300`,"aria-live":`polite`,children:[(0,z.jsx)(Cs,{size:16,className:`animate-spin text-[#11a4d4]`}),`Loading workflow draft `,e,`…`]}):r===`error`||!t?(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-900/70 bg-red-950/40 p-4 text-sm leading-6 text-red-200`,role:`alert`,children:[(0,z.jsx)(`div`,{className:`font-bold`,children:`Could not load workflow draft`}),(0,z.jsx)(`div`,{className:`mt-1 text-xs`,children:a??`Draft '${e}' was not found.`})]}):(0,z.jsx)(EOe,{draft:t})}function TOe(){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/60 bg-amber-950/15 p-4 text-xs leading-5 text-amber-100`,"aria-label":`Workflow V2 explicit non-goals`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-amber-200`,children:[(0,z.jsx)(Gs,{size:13}),`V2 scope boundary`]}),(0,z.jsx)(`p`,{className:`mt-2 text-amber-100/90`,children:`Workflows V2 is an authoring surface for Pibo Workflow IR and registered capability references, not a code or product import/export surface.`}),(0,z.jsxs)(`ul`,{className:`mt-3 grid gap-1 text-[11px] text-amber-100/75 md:grid-cols-2`,children:[(0,z.jsx)(`li`,{children:`No inline TypeScript, JavaScript, shell, eval, arbitrary executable code, or raw handler body authoring.`}),(0,z.jsx)(`li`,{children:`No raw XState editing, workflow templates, workflow slash commands, or workflow tools for agents.`}),(0,z.jsx)(`li`,{children:`No YAML/JSON product import/export or TypeScript export path from UI-authored workflows.`}),(0,z.jsx)(`li`,{children:`No Zod schema authoring; schema edits remain constrained to Pibo Workflow IR and registered metadata.`})]})]})}function l0(){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-emerald-900/60 bg-emerald-950/15 p-4 text-xs leading-5 text-emerald-100`,"aria-label":`Registered capability security boundary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-emerald-300`,children:[(0,z.jsx)(Gs,{size:13}),`Registered capability security boundary`]}),(0,z.jsx)(`p`,{className:`mt-2 text-emerald-100/90`,children:`V2 authoring composes registered refs only: non-archived Agent profiles, code handlers, adapters, guards, nested workflows, human actions, and prompt assets.`}),(0,z.jsxs)(`ul`,{className:`mt-3 grid gap-1 text-[11px] text-emerald-100/75`,children:[(0,z.jsx)(`li`,{children:`Existing Chat Web auth plus Project and Pibo Session visibility rules still gate workflow catalog, Project workflow sessions, snapshots, lifecycle events, prompt assets, and human actions.`}),(0,z.jsx)(`li`,{children:`Agent nodes select profile refs only; the UI does not grant extra tools, skills, context files, native tools, MCP servers, or compute-worker access beyond the selected runtime profile.`}),(0,z.jsx)(`li`,{children:`No inline JavaScript, TypeScript, shell, eval, arbitrary executable nodes, or raw handler bodies are created by the UI.`}),(0,z.jsx)(`li`,{children:`Incompatible schemas must use a visible registered adapter node or edge adapter; hidden LLM coercion is not used.`}),(0,z.jsx)(`li`,{children:`XState remains projection-only; Pibo Workflow IR is the persisted source of truth.`}),(0,z.jsx)(`li`,{children:`Workflow inputs, outputs, prompts, prompt assets, state, edge payloads, snapshots, and human action payloads remain sensitive workflow data; normal diagnostics expose only sanitized metadata.`})]})]})}function EOe({draft:e}){let[t,n]=(0,R.useState)(e),[r,i]=(0,R.useState)(e.versionIntent),[a,o]=(0,R.useState)(`idle`),[s,c]=(0,R.useState)(),l=a===`validating`||a===`publishing`,u=t.validation?.errorCount??t.diagnostics.filter(e=>e.severity===`error`).length,d=t.validation?.warningCount??t.diagnostics.filter(e=>e.severity===`warning`).length,f=t.validation?.blocksPublish===!0||u>0;(0,R.useEffect)(()=>{n(e),i(e.versionIntent),o(`idle`),c(void 0)},[e]);let p=async()=>{o(`validating`),c(void 0);try{let e=await Fye(t.draftId);n(e.draft),i(e.draft.versionIntent),o(`validated`),c(`Draft validation ${e.validation.ok?`passed`:`returned diagnostics`}. Publish remains a separate action.`)}catch(e){o(`error`),c(e instanceof Error?e.message:`Failed to validate workflow draft`)}},m=async()=>{o(`publishing`),c(void 0);try{let e=await Iye(t.draftId,{versionIntent:r});n(e.draft),i(e.draft.versionIntent),o(`published`),c(e.publishedVersion?`${e.message??`Published workflow draft.`} Definition hash ${e.publishedVersion.definitionHash}.`:e.message??`Publish validation passed.`)}catch(e){o(`error`),c(e instanceof Error?e.message:`Failed to publish workflow draft`)}};return(0,z.jsxs)(`div`,{className:`flex w-full flex-col gap-4 rounded-sm border border-slate-800 bg-[#101d22]/70 p-4`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:`Loaded UI draft`}),(0,z.jsx)(`h3`,{className:`mt-1 text-lg font-bold text-slate-100`,children:String(t.definition.title??t.workflowId)}),(0,z.jsxs)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-500`,children:[`Builder route `,(0,z.jsxs)(`code`,{className:`rounded bg-slate-900 px-1 text-slate-300`,children:[`/workflows/drafts/`,t.draftId]}),` loaded a draft wrapper around partial Pibo Workflow IR.`]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${t.source} source`}),(0,z.jsx)(P1,{label:t.status}),(0,z.jsx)(P1,{label:t.validationState}),(0,z.jsx)(P1,{label:`rev ${t.revision}`})]})]}),(0,z.jsxs)(`div`,{className:`grid gap-3 text-xs md:grid-cols-2`,"aria-label":`Workflow draft metadata`,children:[(0,z.jsx)(d0,{label:`Draft id`,value:t.draftId}),(0,z.jsx)(d0,{label:`Workflow id`,value:t.workflowId}),(0,z.jsx)(d0,{label:`Base workflow`,value:t.baseWorkflowId&&t.baseWorkflowVersion?`${t.baseWorkflowId}@${t.baseWorkflowVersion}`:`new UI draft`}),(0,z.jsx)(d0,{label:`Next version path`,value:t.targetWorkflowVersion??`not assigned yet`}),(0,z.jsx)(d0,{label:`Version intent`,value:t.versionIntent})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-label":`Workflow publish version panel`,children:[(0,z.jsxs)(`div`,{id:`workflow-publish-gate`,className:`mb-3 rounded-sm border p-3 text-xs leading-5 ${f?`border-amber-700/70 bg-amber-950/30 text-amber-100`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,"aria-label":`Workflow publish gate`,role:`status`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:f?`Publish blocked by draft diagnostics`:`Publish gate ready`}),(0,z.jsx)(`p`,{className:`mt-1`,children:f?`Publish is disabled because ${u} error diagnostic${u===1?``:`s`} ${u===1?`remains`:`remain`}. Draft save remains allowed while you fix errors; before-publish validation also requires workflow input/output ports and at least one node.`:d>0?`Warnings do not block publishing. Before-publish validation still runs and will block if workflow input/output ports, graph nodes, or registered refs are invalid.`:`No blocking diagnostics are present. Before-publish validation will run again before creating an immutable workflow version.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Publish version intent`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-400`,children:`Default publish increments the patch version. Choose minor or major when the release scope needs a larger semantic version bump.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Version bump intent`}),(0,z.jsxs)(`select`,{className:`rounded-sm border border-slate-700 bg-[#101d22] px-2 py-1.5 text-xs text-slate-100 outline-none transition focus:border-[#11a4d4]`,value:r,onChange:e=>i(e.target.value),disabled:l,"aria-label":`Version bump intent`,children:[(0,z.jsx)(`option`,{value:`patch`,children:`Patch version bump (default)`}),(0,z.jsx)(`option`,{value:`minor`,children:`Minor version bump`}),(0,z.jsx)(`option`,{value:`major`,children:`Major version bump`})]})]}),(0,z.jsxs)(`button`,{type:`button`,className:`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 transition hover:border-[#11a4d4] hover:text-white disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void p(),disabled:l,children:[a===`validating`?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Ls,{size:13}),`Validate draft`]}),(0,z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center justify-center gap-1 rounded-sm border border-emerald-600/70 px-3 py-1.5 text-xs font-semibold text-emerald-200 transition hover:border-emerald-400 hover:text-white disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>void m(),disabled:l||f,"aria-describedby":`workflow-publish-gate`,children:[a===`publishing`?(0,z.jsx)(Cs,{size:13,className:`animate-spin`}):(0,z.jsx)(Lo,{size:13}),`Publish draft`]})]})]}),s?(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border p-3 text-xs leading-5 ${a===`error`?`border-red-900/70 bg-red-950/40 text-red-200`:`border-emerald-900/60 bg-emerald-950/20 text-emerald-200`}`,role:a===`error`?`alert`:`status`,children:s}):null]}),(0,z.jsx)(l0,{}),(0,z.jsx)(zDe,{draft:t,onDraftChange:n,renderInspectors:e=>(0,z.jsx)(aOe,{...e})}),(0,z.jsx)(DOe,{draft:t}),(0,z.jsx)(xOe,{draft:t,onDraftChange:n}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3 text-[11px] leading-5 text-slate-500`,children:`Raw XState source is not opened as an editable document. XState remains projection-only; the editable source is the Pibo Workflow IR shown above and in the raw Pibo Workflow IR editor.`})]})}function DOe({draft:e}){let t=e.validation,n=t?.errorCount??e.diagnostics.filter(e=>e.severity===`error`).length,r=t?.warningCount??e.diagnostics.filter(e=>e.severity===`warning`).length,i=t?.infoCount??e.diagnostics.filter(e=>e.severity===`info`).length;return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-4`,"aria-label":`Workflow validation panel`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:`Validation panel`}),(0,z.jsx)(`h4`,{className:`mt-1 text-sm font-bold text-slate-100`,children:`Structured draft diagnostics`}),(0,z.jsx)(`p`,{className:`mt-2 max-w-2xl text-xs leading-5 text-slate-400`,children:`Draft validation reports sanitized diagnostic fields from the Workflow IR pipeline. Publish remains gated by blocking error diagnostics and the backend before-publish route.`})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(P1,{label:`${n} errors`}),(0,z.jsx)(P1,{label:`${r} warnings`}),(0,z.jsx)(P1,{label:`${i} info`})]})]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 text-xs md:grid-cols-3`,"aria-label":`Workflow validation summary`,children:[(0,z.jsx)(d0,{label:`Validation state`,value:e.validationState}),(0,z.jsx)(d0,{label:`Last trigger`,value:t?.trigger??`not checked`}),(0,z.jsx)(d0,{label:`Checked at`,value:t?.checkedAt??`not checked`}),(0,z.jsx)(d0,{label:`Publish gate`,value:t?.blocksPublish?`blocked`:`not blocked`}),(0,z.jsx)(d0,{label:`Run gate`,value:t?.blocksRun?`blocked`:`not blocked`}),(0,z.jsx)(d0,{label:`Diagnostic count`,value:String(e.diagnostics.length)})]}),e.diagnostics.length?(0,z.jsx)(OOe,{draft:e}):(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border border-emerald-900/60 bg-emerald-950/20 p-3 text-xs text-emerald-200`,children:`No validation diagnostics returned by the draft pipeline.`})]})}function OOe({draft:e}){return(0,z.jsx)(`div`,{className:`mt-3 grid gap-2`,"aria-label":`Workflow structured diagnostics`,children:e.diagnostics.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-700/70 bg-amber-950/30 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 font-bold text-amber-200`,children:[(0,z.jsx)(Js,{size:13}),e.code]}),(0,z.jsx)(`div`,{className:`mt-1`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-[11px]`,children:[(0,z.jsx)(u0,{label:`Severity`,value:e.severity}),(0,z.jsx)(u0,{label:`Path`,value:e.path}),(0,z.jsx)(u0,{label:`Node`,value:e.nodeId}),(0,z.jsx)(u0,{label:`Edge`,value:e.edgeId}),(0,z.jsx)(u0,{label:`Registry ref`,value:e.registryRef})]}),e.hint?(0,z.jsx)(`div`,{className:`mt-2 text-amber-200/80`,children:e.hint}):null]},`${e.code}:${e.path??e.nodeId??e.edgeId??e.registryRef??`workflow`}`))})}function u0({label:e,value:t}){return t?(0,z.jsxs)(`span`,{className:`rounded-sm border border-amber-700/50 bg-amber-950/40 px-2 py-0.5`,children:[(0,z.jsxs)(`span`,{className:`font-semibold text-amber-200/80`,children:[e,`:`]}),` `,(0,z.jsx)(`code`,{children:t})]}):null}function d0({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#151f24]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-slate-500`,children:e}),(0,z.jsx)(`div`,{className:`mt-1 break-all font-mono text-[11px] text-slate-200`,children:t})]})}function f0({icon:e,eyebrow:t,title:n,description:r,children:i}){return(0,z.jsxs)(`section`,{className:`flex min-h-72 flex-col rounded-sm border border-slate-800 bg-[#151f24] p-5 shadow-lg shadow-black/20`,children:[(0,z.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,z.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-sm border border-[#11a4d4]/35 bg-[#11a4d4]/10 text-[#11a4d4]`,children:(0,z.jsx)(e,{size:18})}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-slate-500`,children:t}),(0,z.jsx)(`h2`,{className:`mt-1 text-lg font-bold text-slate-100`,children:n}),(0,z.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-slate-400`,children:r})]})]}),(0,z.jsx)(`div`,{className:`mt-5 flex flex-1`,children:i})]})}function kOe({title:e,description:t}){return(0,z.jsxs)(`div`,{className:`flex w-full flex-col justify-center rounded-sm border border-dashed border-slate-700 bg-[#101d22]/70 p-4 text-center`,children:[(0,z.jsx)(`div`,{className:`text-sm font-semibold text-slate-200`,children:e}),(0,z.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-slate-500`,children:t})]})}function p0({icon:e,label:t}){return(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-slate-800 bg-[#101d22]/60 px-3 py-2`,children:[(0,z.jsx)(e,{size:14,className:`shrink-0 text-[#11a4d4]`}),(0,z.jsx)(`span`,{children:t})]})}function m0(e,t=`new-agent`){return{displayName:t,description:``,nativeTools:[],skills:w0(e,`pi-agent-harness`)?[`pi-agent-harness`]:[],contextFiles:[],subagents:[],mcpServers:[],piPackages:[],mainModel:void 0,subagentModel:void 0,thinkingLevel:void 0,mainThinkingLevel:void 0,subagentThinkingLevel:void 0,fast:!1,mainFast:!1,subagentFast:!1,builtinTools:`default`,builtinToolNames:[...b0],autoContextFiles:!0,runControl:!1,brokenContextFiles:[],hardPinnedModel:void 0,source:`custom`}}function AOe(e){let t=new Set([...e].map(e=>e.trim()).filter(Boolean)),n=`new-agent`;if(!t.has(n))return n;for(let e=1;;e+=1){let r=`${n}-${e}`;if(!t.has(r))return r}}function h0(e){return{id:e.id,profileName:e.profileName,displayName:e.displayName,description:e.description??``,nativeTools:e.nativeTools,skills:e.skills,contextFiles:e.contextFiles,subagents:e.subagents,mcpServers:e.mcpServers,piPackages:e.piPackages??[],mainModel:e.mainModel,subagentModel:e.subagentModel,thinkingLevel:e.thinkingLevel,mainThinkingLevel:e.mainThinkingLevel,subagentThinkingLevel:e.subagentThinkingLevel,fast:e.fast??!1,mainFast:e.mainFast??!1,subagentFast:e.subagentFast??!1,builtinTools:e.builtinTools,builtinToolNames:y0(e.builtinToolNames,e.builtinTools),autoContextFiles:e.autoContextFiles??!0,runControl:e.runControl,brokenContextFiles:e.brokenContextFiles??[],archivedAt:e.archivedAt,hardPinnedModel:void 0,source:`custom`}}function g0(e,t){return{displayName:e.name,description:e.description??``,nativeTools:e.nativeTools??[],skills:e.skills??(w0(t,`pi-agent-harness`)?[`pi-agent-harness`]:[]),contextFiles:e.contextFiles??[],subagents:e.subagents??[],mcpServers:e.mcpServers??[],piPackages:e.piPackages??[],mainModel:e.mainModel??e.model,subagentModel:e.subagentModel??e.model,thinkingLevel:e.thinkingLevel,mainThinkingLevel:e.mainThinkingLevel??e.thinkingLevel,subagentThinkingLevel:e.subagentThinkingLevel??e.thinkingLevel,fast:e.fast??!1,mainFast:e.mainFast??e.fast??!1,subagentFast:e.subagentFast??e.fast??!1,builtinTools:e.builtinTools??`default`,builtinToolNames:y0(e.builtinToolNames,e.builtinTools),autoContextFiles:e.autoContextFiles??!0,runControl:e.runControl??!1,brokenContextFiles:[],hardPinnedModel:e.model,profileName:e.name,source:`profile`}}function jOe(e,t){return{...g0(e,t),displayName:`${e.name}-copy`,id:void 0,hardPinnedModel:void 0,profileName:void 0,source:`custom`}}function _0(e){return{...h0(e),displayName:`${e.profileName}-copy`,id:void 0,profileName:void 0,archivedAt:void 0,source:`custom`}}function MOe(e,t){let n=new Map;for(let t of e)n.set(t.name,t.name);for(let e of t)n.set(e.profileName,e.displayName);return[...n.entries()].map(([e,t])=>({value:e,label:t}))}function NOe(e){return e.trim()?e.length>120?`Agent name is too long.`:/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(e)?null:`Use lowercase kebab-case only, for example test-agent.`:`Agent name is required.`}function v0(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function y0(e,t=`default`){if(t===`disabled`)return[];let n=new Set(e??b0);return b0.filter(e=>n.has(e))}var POe=new Set([`apply_patch`,`codex_image_generation`,`web_search`,`view_image`]),b0=[`read`,`bash`,`edit`,`write`],FOe={read:`Read workspace files.`,bash:`Run shell commands.`,edit:`Edit existing files.`,write:`Create or overwrite files.`};function IOe(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=t.pluginId??(POe.has(t.name)?`pibo.codex-compat`:void 0),i=t.pluginName??(e===`pibo.codex-compat`?`Codex Compat`:void 0),a=!e||e===`pibo.core`,o=x0(r,a?`builtin`:`plugin:${e}`,{title:a?`Built-in Tools`:C0(e,i),description:a?`Built-in Pibo tool catalog`:e??`plugin`,kind:a?`builtin`:`plugin`});o.items.push(t),n.has(t.name)&&(o.selectedCount+=1),o.totalCount+=1}return S0(r,[`builtin`,`plugin`])}function LOe(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=t.kind,i=x0(r,e===`plugin`?`plugin:${t.pluginId??t.name}`:e,{title:zOe(t),description:BOe(t),kind:t.kind});i.items.push(t),n.has(t.name)&&(i.selectedCount+=1),i.totalCount+=1}return S0(r,[`builtin`,`plugin`,`user`])}function ROe(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=t.pluginId===`pibo.core`,i=!t.pluginId,a=x0(r,e?`builtin`:i?`custom`:`plugin:${t.pluginId}`,{title:e?`Built-in Context Files`:i?`Custom`:C0(t.pluginId,t.pluginName),description:e?`Pibo built-in context file catalog`:i?`Loose context files without a plugin namespace`:t.pluginId??`plugin`,kind:e?`builtin`:i?`custom`:`plugin`});a.items.push(t),n.has(t.key)&&(a.selectedCount+=1),a.totalCount+=1}return S0(r,[`builtin`,`custom`,`plugin`])}function x0(e,t,n){let r=e.get(t);if(r)return r;let i={key:t,title:n.title,description:n.description,kind:n.kind,items:[],selectedCount:0,totalCount:0,defaultOpen:!1};return e.set(t,i),i}function S0(e,t){let n=new Map(t.map((e,t)=>[e,t]));return[...e.values()].sort((e,r)=>{let i=n.get(e.kind)??t.length,a=n.get(r.kind)??t.length;return i===a?e.title.localeCompare(r.title):i-a}).map(e=>({...e,defaultOpen:!1}))}function C0(e,t){return e===`pibo.codex-compat`?`Codex Compat`:t||(e?(e.split(`.`).filter(Boolean).at(-1)??e).split(`-`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):`Plugin`)}function zOe(e){return e.kind===`builtin`?`Built-in Skills`:e.kind===`user`?`User Skills`:C0(e.pluginId,e.pluginName)}function BOe(e){return e.kind===`builtin`?`Pibo-owned built-in skill catalog`:e.kind===`user`?`User-managed skills`:e.pluginId??`plugin`}function VOe(e){return e.kind===`builtin`?`built-in skill`:e.kind===`user`?`user skill`:e.pluginName??e.pluginId??`plugin skill`}function w0(e,t){return e?.skills.some(e=>e.kind===`builtin`&&e.name===t)??!1}function HOe(e){let t=e.source??`plugin`,n=e.scope??`global`;return e.pluginId===`pibo.core`?`built-in global`:t===`plugin`?`plugin global`:n===`agent`?e.agentProfileName?`agent ${e.agentProfileName}`:`agent local`:`managed global`}function T0(e,t){return e.includes(t.id)||e.includes(t.name)}function UOe(e,t){return T0(e,t)?e.filter(e=>e!==t.id&&e!==t.name):[...e,t.id]}function WOe(e){return e.enabled&&e.installStatus===`installed`}function E0(e){let t=e.resourceTypes.length?e.resourceTypes.join(` + `):`resources pending`,n=e.version?`v${e.version}`:e.installStatus,r=e.diagnostics.some(e=>e.type===`error`)?` / needs attention`:``;return`${t} / ${n} / ${e.enabled?`enabled`:`disabled`}${r}`}function D0(){return`Agent Designer API unavailable. Restart the Pibo web gateway after pulling/building the latest backend.`}function GOe(e){return e.toLowerCase().includes(`not found`)||e.includes(`404`)}function O0({title:e,children:t}){return(0,z.jsxs)(`div`,{className:`border border-slate-700 bg-[#1a262b] rounded-sm p-4`,children:[(0,z.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-400 mb-3`,children:e}),(0,z.jsx)(`div`,{className:`grid gap-3`,children:t})]})}function KOe({title:e,children:t}){return(0,z.jsx)(O0,{title:e,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:t})})}function k0({groups:e,empty:t,renderItem:n}){return e.length===0?(0,z.jsx)(z.Fragment,{children:t}):(0,z.jsx)(`div`,{className:`grid gap-2`,children:e.map(e=>(0,z.jsx)(qOe,{group:e,renderItem:n},e.key))})}function qOe({group:e,renderItem:t}){let[n,r]=(0,R.useState)(e.defaultOpen),i=e.items.slice(0,100),a=e.items.length-i.length,o=e.kind===`custom`||e.kind===`user`?`border-[#f59e0b]/70 text-amber-100 bg-[#f59e0b]/10`:`border-[#11a4d4]/70 text-sky-100 bg-[#11a4d4]/10`;return(0,z.jsxs)(`div`,{className:`border rounded-sm ${n?`border-slate-700 bg-[#101d22]`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 p-2 text-left`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 shrink-0 inline-flex items-center justify-center border rounded-sm ${o}`,children:n?(0,z.jsx)(zo,{size:14}):(0,z.jsx)(Bo,{size:14})}),(0,z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm font-medium text-slate-100`,children:e.title}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:e.description})]}),(0,z.jsxs)(`span`,{className:`shrink-0 text-right font-mono text-sm font-semibold tabular-nums`,"aria-label":`${e.selectedCount} of ${e.totalCount} selected`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:e.selectedCount}),(0,z.jsxs)(`span`,{className:`text-slate-500`,children:[`/`,e.totalCount]})]})]}),n?(0,z.jsxs)(`div`,{className:`border-t border-slate-800 p-2`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:i.map(t)}),a>0?(0,z.jsxs)(`div`,{className:`mt-2 text-xs text-slate-500`,children:[`Showing first `,100,` of `,e.items.length,` items. Use Context to manage the full catalog.`]}):null]}):null]})}function A0({checked:e,disabled:t,title:n,description:r,meta:i,metaClass:a,actionLabel:o,actionIcon:s,actionDisabled:c,onAction:l,onToggle:u}){return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{t||u()},"aria-disabled":t,className:`min-w-0 border rounded-sm p-2 text-left grid grid-cols-[18px_1fr] gap-2 ${t&&!l?`opacity-60`:``} ${e?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,z.jsx)(P0,{checked:e,className:`mt-0.5`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex items-start justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,z.jsx)(`span`,{className:`block text-sm truncate text-slate-200`,children:n})}),o&&l?(0,z.jsx)(`span`,{className:`shrink-0`,children:(0,z.jsxs)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.preventDefault(),e.stopPropagation(),c||l()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&!c&&(e.preventDefault(),e.stopPropagation(),l())},className:`inline-flex h-6 items-center justify-center gap-1 border px-1.5 text-[10px] uppercase tracking-wider ${c?`border-slate-800 text-slate-600`:`border-[#11a4d4]/70 text-[#7dd3fc] hover:border-[#11a4d4] hover:text-sky-100`}`,children:[s,o]})}):null]}),r?(0,z.jsx)(`span`,{className:`block text-xs text-slate-500 truncate`,children:r}):null,i?(0,z.jsx)(`span`,{className:`block font-mono text-[10px] mt-1 ${a??`text-slate-600`}`,children:i}):null]})]})}function JOe({pkg:e,selected:t,readOnly:n,expanded:r,busy:i,onToggleSelected:a,onToggleExpanded:o,onToggleEnabled:s,onUnregister:c}){let l=e.diagnostics.some(e=>e.type===`error`),u=!n&&(e.enabled||t);return(0,z.jsxs)(`div`,{className:`border rounded-sm ${t?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#151f24]`} ${e.enabled?``:`opacity-75`}`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2 p-2`,children:[(0,z.jsxs)(`button`,{type:`button`,disabled:!u,onClick:a,className:`min-w-0 grid grid-cols-[18px_1fr] gap-2 text-left disabled:cursor-not-allowed`,children:[(0,z.jsx)(P0,{checked:t,disabled:!u,className:`mt-0.5`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,z.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,z.jsx)(`span`,{className:`block text-xs text-slate-500 truncate`,children:e.description??e.source}),(0,z.jsx)(`span`,{className:`block font-mono text-[10px] mt-1 ${l?`text-[#f59e0b]`:`text-[#11a4d4]`}`,children:E0(e)})]})]}),(0,z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:o,title:r?`Hide Details`:`Show Details`,"aria-label":r?`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:r?(0,z.jsx)(zo,{size:13}):(0,z.jsx)(Bo,{size:13})}),s?(0,z.jsx)(`button`,{type:`button`,disabled:i,onClick:s,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,z.jsx)(Fs,{size:13}):(0,z.jsx)(Is,{size:13})}):null,c?(0,z.jsx)(`button`,{type:`button`,disabled:i,onClick:c,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,z.jsx)(qs,{size:13})}):null]})]}),r?(0,z.jsx)(j0,{pkg:e}):null]})}function j0({pkg:e}){return(0,z.jsxs)(`div`,{className:`border-t border-slate-800 p-3 grid gap-3 text-xs text-slate-300`,children:[(0,z.jsx)(YOe,{rows:[[`Source`,e.source],[`Install`,e.installSpec],[`Version`,e.version],[`Added`,e.addedAt],[`Updated`,e.updatedAt]]}),e.repositoryUrl?(0,z.jsxs)(`a`,{href:e.repositoryUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex w-fit items-center gap-1 text-[#7dd3fc] hover:text-sky-100`,children:[(0,z.jsx)(rs,{size:12}),`Source repository`]}):null,(0,z.jsx)(M0,{title:`Extensions`,values:e.extensionPaths}),(0,z.jsx)(M0,{title:`Skills`,values:e.skillNames}),(0,z.jsx)(M0,{title:`Prompts`,values:e.promptNames}),(0,z.jsx)(M0,{title:`Themes`,values:e.themeNames}),(0,z.jsx)(M0,{title:`Tools`,values:e.discoveredToolNames}),e.diagnostics.length?(0,z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Diagnostics`}),e.diagnostics.map((e,t)=>(0,z.jsxs)(`div`,{className:`border px-2 py-1 rounded-sm ${e.type===`error`?`border-red-500/50 text-red-200 bg-red-500/10`:e.type===`warning`?`border-[#f59e0b]/50 text-amber-100 bg-[#f59e0b]/10`:`border-slate-700 text-slate-400 bg-[#0e1116]`}`,children:[(0,z.jsx)(`span`,{className:`font-mono uppercase text-[10px] mr-2`,children:e.type}),e.message]},`${e.type}:${t}`))]}):null]})}function YOe({rows:e}){let t=e.filter(([,e])=>e);return t.length===0?null:(0,z.jsx)(`div`,{className:`grid gap-1`,children:t.map(([e,t])=>(0,z.jsxs)(`div`,{className:`grid grid-cols-[84px_minmax(0,1fr)] gap-2`,children:[(0,z.jsx)(`span`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsx)(`span`,{className:`min-w-0 break-all font-mono text-[11px] text-slate-300`,children:t})]},e))})}function M0({title:e,values:t}){return t?.length?(0,z.jsxs)(`div`,{className:`grid gap-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,z.jsx)(`span`,{className:`max-w-full break-all border border-slate-700 bg-[#0e1116] px-2 py-1 font-mono text-[11px] text-slate-300 rounded-sm`,children:e},e))})]}):null}function N0({checked:e,disabled:t,title:n,onToggle:r}){return(0,z.jsxs)(`button`,{type:`button`,disabled:t,"aria-pressed":e,onClick:r,className:`inline-flex w-fit items-center gap-2 text-left text-sm text-slate-300 hover:text-slate-100 disabled:opacity-60`,children:[(0,z.jsx)(P0,{checked:e,disabled:t}),(0,z.jsx)(`span`,{children:n})]})}function P0({checked:e,disabled:t,className:n=``}){return(0,z.jsx)(`span`,{className:`h-4 w-4 shrink-0 border rounded-sm inline-flex items-center justify-center ${e?`border-[#11a4d4] text-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-600 text-transparent`} ${t?`opacity-70`:``} ${n}`,children:e?(0,z.jsx)(Ro,{size:12}):null})}function F0({message:e=`Agent Designer API unavailable`}){return(0,z.jsx)(`div`,{className:`text-xs text-amber-100 border border-dashed border-[#f59e0b]/50 bg-[#f59e0b]/10 rounded-sm p-3`,children:e})}function I0({title:e,modelTitle:t,model:n,thinking:r,fast:i,modelCatalog:a,readOnly:o,modelHint:s,configuredProvidersOnly:c=!1,onModelChange:l,onThinkingChange:u,onFastChange:d}){return(0,z.jsxs)(`div`,{className:`grid gap-2 border border-slate-800 rounded-sm p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(150px,190px)_auto] lg:items-start`,children:[(0,z.jsx)(ZOe,{title:t,catalog:a,value:n,allowUnset:!0,readOnly:o,hint:s,emptyProviderLabel:`Default`,configuredProvidersOnly:c,onChange:l}),(0,z.jsx)(XOe,{title:`Thinking`,value:r,readOnly:o,reserveHintSpace:!0,onChange:u}),(0,z.jsxs)(`div`,{className:`grid gap-2 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:`Fast`}),(0,z.jsx)(`div`,{className:`h-4`,"aria-hidden":`true`}),(0,z.jsxs)(`button`,{type:`button`,disabled:o,onClick:()=>d(!i),className:`inline-flex h-9 w-fit items-center gap-2 text-left text-sm text-slate-300 hover:text-slate-100 disabled:opacity-60`,children:[(0,z.jsx)(P0,{checked:i===!0,disabled:o}),(0,z.jsx)(`span`,{children:i?`Fast on`:`Fast off`})]})]})]})]})}function XOe({title:e,value:t,readOnly:n,hint:r,reserveHintSpace:i=!1,onChange:a}){return(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:e}),(0,z.jsx)(`button`,{type:`button`,disabled:n||!t,onClick:()=>a(void 0),className:`text-[10px] uppercase tracking-wider text-slate-500 hover:text-slate-300 disabled:opacity-50`,children:`Unset`})]}),r?(0,z.jsx)(`div`,{className:`text-xs text-slate-500`,children:r}):i?(0,z.jsx)(`div`,{className:`h-4`,"aria-hidden":`true`}):null,(0,z.jsxs)(`select`,{value:t??``,disabled:n,onChange:e=>a(e.target.value?e.target.value:void 0),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`,children:[(0,z.jsx)(`option`,{value:``,children:`Default`}),Xq.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]})}function ZOe({title:e,catalog:t,value:n,allowUnset:r,readOnly:i,hint:a,emptyProviderLabel:o=`Select provider`,configuredProvidersOnly:s=!1,onChange:c}){let[l,u]=(0,R.useState)(n?.provider??``),[d,f]=(0,R.useState)(n?.id??``),p=t?.providers??[],m=p.filter(e=>!s||e.authConfigured),h=m.find(e=>e.id===l),g=s?p.find(e=>e.id===l&&!e.authConfigured):void 0,_=!!l&&!h,v=_?g?`${g.label} (not configured)`:`${l} (unknown provider)`:``,y=h?.models.find(e=>e.id===d),b=!!(l&&d&&h&&!y),x=h?.models??[],S=h?.authConfigured;return(0,R.useEffect)(()=>{u(n?.provider??``),f(n?.id??``)},[n?.id,n?.provider]),(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:e}),r?(0,z.jsx)(`button`,{type:`button`,disabled:i||!l&&!d,onClick:()=>{u(``),f(``),c(void 0)},className:`text-[10px] uppercase tracking-wider text-slate-500 hover:text-slate-300 disabled:opacity-50`,children:`Unset`}):null]}),a?(0,z.jsx)(`div`,{className:`text-xs text-slate-500`,children:a}):null,m.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm p-3`,children:p.length===0?`Model catalog unavailable.`:`No configured providers. Configure a provider under Settings > Providers.`}):null,(0,z.jsxs)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:[(0,z.jsxs)(`select`,{value:l,disabled:i,onChange:e=>{let t=e.target.value;u(t),f(``),t||c(void 0)},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`,children:[(0,z.jsx)(`option`,{value:``,children:o}),m.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.label},e.id)),_?(0,z.jsx)(`option`,{value:l,children:v}):null]}),(0,z.jsxs)(`select`,{value:d,disabled:i,onChange:e=>{let t=e.target.value;f(t),t?c({provider:l,id:t}):l&&c(void 0)},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`,children:[(0,z.jsx)(`option`,{value:``,children:l?`Select model`:`Select provider first`}),x.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.label},e.id)),b?(0,z.jsx)(`option`,{value:d,children:`${d} (unknown model)`}):null]})]}),l?(0,z.jsx)(`div`,{className:`text-xs text-slate-500`,children:_?g?`Stored provider is no longer configured.`:`Stored provider is no longer present in the catalog.`:S?`Provider auth configured.`:`Provider auth missing.`}):null,b?(0,z.jsx)(`div`,{className:`text-xs text-amber-100`,children:`Stored model is no longer present in the catalog.`}):null]})}function QOe({agents:e,initialCustomAgents:t,initialCatalog:n,modelCatalog:r,onSelect:i,onCreateSession:a,onEditContextFile:o,onEditMcpServer:s,onAgentsChanged:c,creatingSession:l}){let[u,d]=(0,R.useState)(n??null),[f,p]=(0,R.useState)(t),[m,h]=(0,R.useState)(()=>m0(n)),[g,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(!1),[b,x]=(0,R.useState)(!1),S=(0,R.useRef)(new Set),[C,w]=(0,R.useState)(()=>localStorage.getItem(`pibo.chat.showArchivedAgents`)===`true`),[T,E]=(0,R.useState)(``),[D,O]=(0,R.useState)(null),[k,A]=(0,R.useState)(``),[j,M]=(0,R.useState)(`agent`),N=!!u,P=(0,R.useCallback)(async()=>{x(!0);try{let e=await cl(),t=new Set(e.map(e=>e.key));d(t=>t&&{...t,contextFiles:e}),p(e=>e.map(e=>({...e,brokenContextFiles:(e.brokenContextFiles??[]).filter(e=>!t.has(e))}))),h(e=>({...e,brokenContextFiles:(e.brokenContextFiles??[]).filter(e=>!t.has(e))})),c(),O(null)}catch(e){O(e instanceof Error?e.message:String(e))}finally{x(!1)}},[c]);(0,R.useEffect)(()=>p(t),[t]),(0,R.useEffect)(()=>{n&&d(n)},[n]),(0,R.useEffect)(()=>{let e=m.brokenContextFiles??[];if(!e.length||b)return;let t=e.slice().sort().join(`
|
|
163
|
+
`);S.current.has(t)||(S.current.add(t),P())},[m.brokenContextFiles,P,b]);let F=(0,R.useMemo)(()=>new Set(f.map(e=>e.profileName)),[f]),ee=(0,R.useMemo)(()=>e.filter(e=>!F.has(e.name)),[e,F]),te=(0,R.useMemo)(()=>f.filter(e=>!e.archivedAt),[f]),I=(0,R.useMemo)(()=>f.filter(e=>e.archivedAt),[f]),ne=(0,R.useMemo)(()=>MOe(e,te),[e,te]),L=!!m.archivedAt,re=g&&m.source===`custom`&&!m.id,ie=m.source===`profile`||L,ae=ie?null:NOe(m.displayName),oe=m.profileName??(ae?`new custom profile`:m.displayName),se=(0,R.useMemo)(()=>u?.contextFiles.filter(e=>(e.scope??`global`)===`agent`?e.agentProfileName===oe||m.contextFiles.includes(e.key):!0)??[],[u,m.contextFiles,oe]),ce=(0,R.useMemo)(()=>IOe(u?.nativeTools??[],m.nativeTools),[u?.nativeTools,m.nativeTools]),le=(0,R.useMemo)(()=>LOe(u?.skills??[],m.skills),[u?.skills,m.skills]),ue=(0,R.useMemo)(()=>ROe(se,m.contextFiles),[se,m.contextFiles]),de=()=>{let t=[...e.map(e=>e.name),...f.flatMap(e=>[e.profileName,e.displayName]),...re?[m.displayName]:[]];h(m0(u??void 0,AOe(t))),_(!0),O(null)},fe=async()=>{if(!ie){if(ae){O(ae);return}if(!N){O(D0());return}y(!0);try{let e={displayName:m.displayName.trim(),description:(m.description??``).trim()||void 0,nativeTools:m.nativeTools,skills:m.skills,contextFiles:m.contextFiles,subagents:m.subagents.filter(e=>e.name.trim()&&e.targetProfile.trim()),mcpServers:m.mcpServers,piPackages:m.piPackages,mainModel:m.mainModel,subagentModel:m.subagentModel,thinkingLevel:m.thinkingLevel??null,mainThinkingLevel:m.mainThinkingLevel??null,subagentThinkingLevel:m.subagentThinkingLevel??null,fast:m.fast,mainFast:m.mainFast,subagentFast:m.subagentFast,builtinTools:m.builtinTools,builtinToolNames:m.builtinToolNames,autoContextFiles:m.autoContextFiles,runControl:m.runControl},t=m.id?await UW(m.id,e):await HW(e);p(e=>{let n=e.filter(e=>e.id!==t.agent.id);return[t.agent,...n]}),h(h0(t.agent)),_(!1),i(t.agent.profileName),c(),O(null)}catch(e){let t=e instanceof Error?e.message:String(e);O(GOe(t)?D0():t)}finally{y(!1)}}},pe=async e=>{if(!(!m.id||m.source!==`custom`)){y(!0);try{let t=await UW(m.id,{archived:e});e&&(w(!0),localStorage.setItem(`pibo.chat.showArchivedAgents`,`true`)),p(e=>e.map(e=>e.id===t.agent.id?t.agent:e)),h(h0(t.agent)),E(``),c(),O(null)}catch(e){O(e instanceof Error?e.message:String(e))}finally{y(!1)}}},me=async()=>{if(!(ie||!N||!k.trim())){if(ae){O(ae);return}y(!0);try{let e=(await sl({label:k.trim(),scope:j,agentProfileName:j===`agent`?oe:void 0,markdown:``})).file;d(t=>t&&{...t,contextFiles:[...t.contextFiles,e]}),h(t=>({...t,contextFiles:t.contextFiles.includes(e.key)?t.contextFiles:[...t.contextFiles,e.key]})),A(``),O(null)}catch(e){O(e instanceof Error?e.message:String(e))}finally{y(!1)}}},he=async()=>{if(!(!m.id||!m.profileName||!L)){y(!0);try{await WW(m.id,T),p(e=>e.filter(e=>e.id!==m.id)),h(m0(u??void 0)),_(!1),E(``),c(),O(null)}catch(e){O(e instanceof Error?e.message:String(e))}finally{y(!1)}}};return(0,z.jsxs)(`div`,{className:`h-full min-h-0 overflow-hidden grid grid-cols-[300px_minmax(0,1fr)] max-[920px]:grid-cols-1`,children:[(0,z.jsxs)(`aside`,{className:`border-r border-slate-800 bg-[#1a262b] min-h-0 overflow-auto`,children:[(0,z.jsxs)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center justify-between text-xs font-bold uppercase tracking-wider`,children:[(0,z.jsx)(`span`,{children:`Agents`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:de,title:`New Agent`,"aria-label":`New Agent`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ps,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>{let e=!C;w(e),localStorage.setItem(`pibo.chat.showArchivedAgents`,String(e))},title:C?`Hide Archived Agents`:`Show Archived Agents`,"aria-label":C?`Hide Archived Agents`:`Show Archived Agents`,className:`p-1 border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${C?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:C?(0,z.jsx)(wo,{size:13}):(0,z.jsx)(To,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:c,title:`Refresh`,"aria-label":`Refresh`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ls,{size:13})})]})]}),(0,z.jsxs)(`div`,{className:`p-2`,children:[(0,z.jsxs)(L0,{title:`Custom Agents`,children:[re?(0,z.jsx)(R0,{title:m.displayName||`new-agent`,subtitle:`unsaved custom agent`,selected:!0,onSelect:()=>{},onCreateSession:()=>{},createSessionDisabled:!0},`unsaved-agent-draft`):null,te.map(e=>(0,z.jsx)(R0,{title:e.displayName,subtitle:e.profileName,selected:m.source===`custom`&&m.id===e.id,onSelect:()=>{_(!1),h(h0(e)),i(e.profileName)},onCopy:()=>{h(_0(e)),_(!0)},onCreateSession:()=>{i(e.profileName),a(e.profileName)},createSessionDisabled:l},e.id)),te.length===0&&!re?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No custom agents`}):null]}),C?(0,z.jsxs)(L0,{title:`Archived Custom Agents`,children:[I.map(e=>(0,z.jsx)(R0,{title:e.displayName,subtitle:e.profileName,selected:m.source===`custom`&&m.id===e.id,onSelect:()=>{_(!1),h(h0(e))},onCopy:()=>{h(_0(e)),_(!0)},onCreateSession:()=>{},createSessionDisabled:!0},e.id)),I.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No archived agents`}):null]}):null,(0,z.jsx)(L0,{title:`Read-only Profiles`,children:ee.map(e=>(0,z.jsx)(R0,{title:e.name,subtitle:e.aliases.join(`, `)||`plugin`,selected:m.source===`profile`&&m.profileName===e.name,onSelect:()=>{_(!1),h(g0(e,u??void 0)),i(e.name)},onCopy:()=>{h(jOe(e,u??void 0)),_(!0)},onCreateSession:()=>{i(e.name),a(e.name)},createSessionDisabled:l},e.name))})]})]}),(0,z.jsxs)(`section`,{className:`min-h-0 overflow-auto p-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`h1`,{className:`text-sm font-bold uppercase tracking-wider`,children:`Agent Designer`}),(0,z.jsx)(`div`,{className:`font-mono text-[11px] text-slate-500 truncate`,children:oe}),(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-slate-500`,children:m.source===`profile`?`read-only plugin profile`:L?`archived custom agent`:`custom agent`})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>{m.profileName&&(i(m.profileName),a(m.profileName))},disabled:!m.profileName||l||L,title:`New Session With Agent`,"aria-label":`New Session With Agent`,className:`h-8 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,z.jsx)(Ds,{size:14})}),m.source===`custom`&&m.id?(0,z.jsx)(`button`,{type:`button`,onClick:()=>void pe(!L),disabled:v,title:L?`Restore Agent`:`Archive Agent`,"aria-label":L?`Restore Agent`:`Archive Agent`,className:`h-8 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:L?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>void fe(),disabled:ie||!N||v||!!ae,title:`Save Agent`,"aria-label":`Save Agent`,className:`h-8 w-8 inline-flex items-center justify-center border border-[#11a4d4] rounded-sm text-[#11a4d4] bg-[#11a4d4]/10 disabled:opacity-50`,children:(0,z.jsx)(Bs,{size:14})})]})]}),N?null:(0,z.jsx)(`div`,{className:`mb-3 border border-[#f59e0b]/60 bg-[#f59e0b]/10 text-amber-100 px-3 py-2 text-sm rounded-sm`,children:D0()}),m.source===`profile`?(0,z.jsx)(`div`,{className:`mb-3 border border-slate-700 bg-[#151f24] text-slate-300 px-3 py-2 text-sm rounded-sm`,children:`This profile is registered by a plugin. Copy it to create an editable custom agent.`}):null,L?(0,z.jsx)(`div`,{className:`mb-3 border border-[#f59e0b]/60 bg-[#f59e0b]/10 text-amber-100 px-3 py-2 text-sm rounded-sm`,children:`This agent is archived. Restore it before editing or starting new sessions.`}):null,D?(0,z.jsx)(`div`,{className:`mb-3 border border-red-500/60 bg-red-500/10 text-red-200 px-3 py-2 text-sm rounded-sm`,children:D}):null,(0,z.jsxs)(`div`,{className:`grid gap-4`,children:[(0,z.jsxs)(O0,{title:`Basics`,children:[(0,z.jsx)(`input`,{value:m.displayName,disabled:ie,onChange:e=>h(t=>({...t,displayName:e.target.value})),className:`min-w-0 bg-[#0e1116] border rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60 ${ae?`border-[#f59e0b]`:`border-slate-700`}`,placeholder:`agent-name`}),ae?(0,z.jsx)(`div`,{className:`text-xs text-amber-100`,children:ae}):null,(0,z.jsx)(`textarea`,{value:m.description,disabled:ie,onChange:e=>h(t=>({...t,description:e.target.value})),className:`min-h-[72px] bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`,placeholder:`Description`}),m.source===`profile`&&m.hardPinnedModel?(0,z.jsxs)(`div`,{className:`border border-slate-700 bg-[#151f24] text-slate-300 px-3 py-2 text-xs rounded-sm`,children:[`This plugin profile hard-pins `,(0,z.jsx)(`span`,{className:`font-mono`,children:rke(m.hardPinnedModel)}),`. Main-agent and subagent defaults do not apply.`]}):null,(0,z.jsx)(I0,{title:`Main Agent`,modelTitle:`Main Agent Model`,model:m.mainModel,thinking:m.mainThinkingLevel,fast:m.mainFast??!1,modelCatalog:r,readOnly:ie,modelHint:`Unset to use the settings default.`,onModelChange:e=>h(t=>({...t,mainModel:e})),onThinkingChange:e=>h(t=>({...t,mainThinkingLevel:e})),onFastChange:e=>h(t=>({...t,mainFast:e}))}),(0,z.jsx)(I0,{title:`Subagent`,modelTitle:`Subagent Model`,model:m.subagentModel,thinking:m.subagentThinkingLevel,fast:m.subagentFast??!1,modelCatalog:r,readOnly:ie,modelHint:`Unset to use the settings default.`,onModelChange:e=>h(t=>({...t,subagentModel:e})),onThinkingChange:e=>h(t=>({...t,subagentThinkingLevel:e})),onFastChange:e=>h(t=>({...t,subagentFast:e}))}),(0,z.jsx)(N0,{disabled:ie,checked:m.autoContextFiles,title:`Load AGENTS.md / CLAUDE.md`,onToggle:()=>h(e=>({...e,autoContextFiles:!e.autoContextFiles}))}),(0,z.jsx)(eke,{draft:m,setDraft:h,readOnly:ie})]}),(0,z.jsx)(O0,{title:`Tools`,children:(0,z.jsx)(k0,{groups:ce,empty:u?(0,z.jsx)(F0,{message:`No native tools registered`}):(0,z.jsx)(F0,{}),renderItem:e=>(0,z.jsx)(A0,{disabled:ie,checked:m.nativeTools.includes(e.name),title:e.name,description:e.description,meta:e.yieldable?`yieldable`:`direct only`,onToggle:()=>h(t=>({...t,nativeTools:v0(t.nativeTools,e.name)}))},e.name)})}),(0,z.jsx)(O0,{title:`Skills`,children:(0,z.jsx)(k0,{groups:le,empty:u?(0,z.jsx)(F0,{message:`No skills registered`}):(0,z.jsx)(F0,{}),renderItem:e=>(0,z.jsx)(A0,{disabled:ie,checked:m.skills.includes(e.name),title:e.name,description:e.path,meta:VOe(e),metaClass:e.kind===`user`?`text-amber-200`:`text-[#11a4d4]`,onToggle:()=>h(t=>({...t,skills:v0(t.skills,e.name)}))},e.name)})}),(0,z.jsx)(KOe,{title:`Packages`,children:(0,z.jsx)(A0,{disabled:ie,checked:m.runControl,title:`pibo-run-control`,description:`Expose pibo_run_* as one package for yielded native tools and subagents.`,meta:`package`,onToggle:()=>h(e=>({...e,runControl:!e.runControl}))})}),(0,z.jsx)($Oe,{packages:u?.piPackages,draft:m,setDraft:h,readOnly:ie}),(0,z.jsxs)(O0,{title:`Context Files`,children:[m.brokenContextFiles?.length?(0,z.jsxs)(`div`,{className:`border border-red-500/60 bg-red-500/10 rounded-sm p-3 space-y-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start gap-2 text-red-100`,children:[(0,z.jsx)(Js,{size:14,className:`mt-0.5 shrink-0`}),(0,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsx)(`div`,{className:`text-sm font-medium`,children:`This agent references missing or unregistered context files.`}),(0,z.jsx)(`div`,{className:`text-xs text-red-200/90`,children:`Re-check context files before removing links that may still exist on disk.`})]})]}),(0,z.jsxs)(`button`,{type:`button`,disabled:b,onClick:()=>void P(),className:`inline-flex w-fit items-center gap-2 border border-red-500/50 rounded-sm px-2 py-1 text-xs font-medium text-red-100 hover:border-red-300 hover:text-white disabled:opacity-50`,title:`Re-check Context Files`,children:[(0,z.jsx)(Ls,{size:12,className:b?`animate-spin`:void 0}),b?`Re-checking...`:`Re-check context files`]}),(0,z.jsx)(`div`,{className:`grid gap-2`,children:m.brokenContextFiles.map(e=>(0,z.jsxs)(`div`,{className:`flex items-center gap-2 border border-red-500/40 bg-[#2a1417] rounded-sm px-3 py-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`truncate text-sm text-red-100`,children:e}),(0,z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-red-300/80`,children:`Broken link`})]}),(0,z.jsx)(`button`,{type:`button`,disabled:ie,onClick:()=>h(t=>({...t,contextFiles:t.contextFiles.filter(t=>t!==e),brokenContextFiles:(t.brokenContextFiles??[]).filter(t=>t!==e)})),className:`h-8 w-8 inline-flex items-center justify-center border border-red-500/60 rounded-sm text-red-200 hover:border-red-400 hover:text-red-100 disabled:opacity-50`,title:`Remove Broken Context File`,"aria-label":`Remove Broken Context File`,children:(0,z.jsx)(Qs,{size:14})})]},e))})]}):null,(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2`,children:[(0,z.jsx)(`input`,{value:k,disabled:ie,onChange:e=>A(e.target.value),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:`New context file`}),(0,z.jsx)(`button`,{type:`button`,disabled:ie||v||!k.trim()||!!ae,onClick:()=>void me(),title:`Create Context File`,"aria-label":`Create Context File`,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,z.jsx)(Ps,{size:14})})]}),(0,z.jsxs)(`div`,{className:`inline-flex w-fit gap-1 border border-slate-800 bg-[#0e1116] rounded-sm p-1`,children:[(0,z.jsx)(`button`,{type:`button`,disabled:ie,onClick:()=>M(`agent`),className:`px-2 py-1 text-xs rounded-sm ${j===`agent`?`bg-[#11a4d4]/20 text-sky-100`:`text-slate-500 hover:text-slate-300`}`,children:`Agent`}),(0,z.jsx)(`button`,{type:`button`,disabled:ie,onClick:()=>M(`global`),className:`px-2 py-1 text-xs rounded-sm ${j===`global`?`bg-[#11a4d4]/20 text-sky-100`:`text-slate-500 hover:text-slate-300`}`,children:`Global`})]}),(0,z.jsx)(k0,{groups:ue,empty:u?(0,z.jsx)(F0,{message:`No context files registered`}):(0,z.jsx)(F0,{}),renderItem:e=>(0,z.jsx)(A0,{disabled:ie,checked:m.contextFiles.includes(e.key),title:e.label??e.key,description:e.path,meta:HOe(e),metaClass:`text-[#11a4d4]`,actionLabel:`Edit`,actionIcon:(0,z.jsx)(Ms,{size:12}),onAction:()=>o(e.key),onToggle:()=>h(t=>({...t,contextFiles:v0(t.contextFiles,e.key)}))},e.key)})]}),(0,z.jsx)(tke,{draft:m,setDraft:h,profileOptions:ne,readOnly:ie}),(0,z.jsx)(nke,{servers:u?.mcpServers,draft:m,setDraft:h,readOnly:ie,onEditServer:s}),L&&m.profileName?(0,z.jsxs)(O0,{title:`Delete Agent`,children:[(0,z.jsxs)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-100 rounded-sm p-3 text-sm`,children:[`Permanently deleting this agent also deletes all Chat sessions that use profile `,(0,z.jsx)(`span`,{className:`font-mono`,children:m.profileName}),`.`]}),(0,z.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-red-500`,placeholder:m.profileName}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void he(),disabled:v||T!==m.profileName,className:`h-8 w-fit inline-flex items-center gap-2 border border-red-500 rounded-sm px-3 text-red-200 bg-red-500/10 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:14}),`Delete permanently`]})]}):null]})]})]})}function L0({title:e,children:t}){return(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:e}),t]})}function R0({title:e,subtitle:t,selected:n,onSelect:r,onCopy:i,onCreateSession:a,createSessionDisabled:o}){return(0,z.jsx)(`div`,{className:`mb-1 border rounded-sm ${n?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-transparent hover:border-slate-700`}`,children:(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto_auto] items-center gap-1 p-1`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 text-left px-1 py-1`,children:[(0,z.jsx)(`span`,{className:`block text-sm truncate text-slate-200`,children:e}),(0,z.jsx)(`span`,{className:`block text-[10px] font-mono truncate text-slate-500`,children:t})]}),i?(0,z.jsx)(`button`,{type:`button`,onClick:i,title:`Copy To Custom Agent`,"aria-label":`Copy To Custom Agent`,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,z.jsx)(Qo,{size:13})}):(0,z.jsx)(`span`,{className:`h-7 w-7`}),(0,z.jsx)(`button`,{type:`button`,onClick:a,disabled:o,title:`New Session With Profile`,"aria-label":`New Session With Profile`,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,z.jsx)(Ds,{size:13})})]})})}function $Oe({packages:e,draft:t,setDraft:n,readOnly:r}){let[i,a]=(0,R.useState)(()=>new Set),o=e??[],s=o.filter(WOe),c=s.filter(e=>T0(t.piPackages,e)).length,l=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,z.jsxs)(O0,{title:`Pi Packages`,children:[(0,z.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[s.length,` available / `,c,` selected / `,o.length,` registered`]}),e?s.length?(0,z.jsx)(`div`,{className:`grid gap-2`,children:s.map(e=>(0,z.jsx)(JOe,{pkg:e,selected:T0(t.piPackages,e),readOnly:r,expanded:i.has(e.id),busy:!1,onToggleSelected:()=>{r||n(t=>({...t,piPackages:UOe(t.piPackages,e)}))},onToggleExpanded:()=>l(e.id)},e.id))}):(0,z.jsx)(F0,{message:`No installed and enabled Pi packages available. Manage Pi Packages in Settings.`}):(0,z.jsx)(F0,{})]})}function eke({draft:e,setDraft:t,readOnly:n}){let r=y0(e.builtinToolNames,e.builtinTools),[i,a]=(0,R.useState)(r.length!==b0.length),o=e=>{t(t=>{let n=v0(y0(t.builtinToolNames,t.builtinTools),e);return{...t,builtinTools:n.length===0?`disabled`:`default`,builtinToolNames:n}})};return(0,z.jsxs)(`div`,{className:`border rounded-sm ${i?`border-slate-700 bg-[#101d22]`:`border-slate-800 bg-[#151f24] hover:border-slate-700`}`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex w-full items-center gap-2 p-2 text-left`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 shrink-0 inline-flex items-center justify-center border rounded-sm border-[#11a4d4]/70 text-sky-100 bg-[#11a4d4]/10`,children:i?(0,z.jsx)(zo,{size:14}):(0,z.jsx)(Bo,{size:14})}),(0,z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm font-medium text-slate-100`,children:`Pi Built-in Tools`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`basic model tools`})]}),(0,z.jsxs)(`span`,{className:`shrink-0 text-right font-mono text-sm font-semibold tabular-nums`,"aria-label":`${r.length} of ${b0.length} enabled`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:r.length}),(0,z.jsxs)(`span`,{className:`text-slate-500`,children:[`/`,b0.length]})]})]}),i?(0,z.jsx)(`div`,{className:`border-t border-slate-800 p-2`,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:b0.map(e=>(0,z.jsx)(A0,{disabled:n,checked:r.includes(e),title:e,description:FOe[e],meta:`built-in`,onToggle:()=>o(e)},e))})}):null]})}function tke({draft:e,setDraft:t,profileOptions:n,readOnly:r}){let i=(e,n)=>{t(t=>({...t,subagents:t.subagents.map((t,r)=>r===e?{...t,...n}:t)}))};return(0,z.jsxs)(O0,{title:`Subagents`,children:[(0,z.jsx)(`div`,{className:`flex justify-end`,children:(0,z.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>t(e=>({...e,subagents:[...e.subagents,{name:`helper`,targetProfile:n[0]?.value??`base`,maxDepth:3}]})),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`,title:`Add Subagent`,"aria-label":`Add Subagent`,children:(0,z.jsx)(Ps,{size:13})})}),(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[e.subagents.map((e,a)=>(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_1fr_80px_auto] max-[1100px]:grid-cols-1 gap-2 border border-slate-800 bg-[#151f24] p-2 rounded-sm`,children:[(0,z.jsx)(`input`,{value:e.name,disabled:r,onChange:e=>i(a,{name: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] disabled:opacity-60`,placeholder:`name`}),(0,z.jsx)(`select`,{value:e.targetProfile,disabled:r,onChange:e=>i(a,{targetProfile: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] disabled:opacity-60`,children:n.map(e=>(0,z.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,z.jsx)(`input`,{type:`number`,min:1,disabled:r,value:e.maxDepth??3,onChange:e=>i(a,{maxDepth:Number(e.target.value)||1}),className:`bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-sm outline-none focus:border-[#11a4d4] disabled:opacity-60`}),(0,z.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>t(e=>({...e,subagents:e.subagents.filter((e,t)=>t!==a)})),className:`h-8 w-8 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-red-500 hover:text-red-300 disabled:opacity-50`,title:`Remove Subagent`,"aria-label":`Remove Subagent`,children:(0,z.jsx)(Qs,{size:14})})]},a)),e.subagents.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm p-3`,children:`No subagents configured`}):null]})]})}function nke({servers:e,draft:t,setDraft:n,readOnly:r,onEditServer:i}){return(0,z.jsx)(O0,{title:`MCP Servers`,children:(0,z.jsxs)(`div`,{className:`grid grid-cols-2 max-[1100px]:grid-cols-1 gap-2`,children:[e?e.map(e=>{let a=r||!e.hasDescription;return(0,z.jsxs)(`div`,{className:`border rounded-sm bg-[#151f24] p-2 ${t.mcpServers.includes(e.name)?`border-[#11a4d4]`:e.hasDescription?`border-slate-800`:`border-[#f59e0b]/60`}`,children:[(0,z.jsxs)(`button`,{type:`button`,disabled:a,onClick:()=>n(t=>({...t,mcpServers:v0(t.mcpServers,e.name)})),className:`grid w-full min-w-0 grid-cols-[18px_1fr] gap-2 text-left disabled:opacity-60`,children:[(0,z.jsx)(P0,{checked:t.mcpServers.includes(e.name),disabled:a,className:`mt-0.5`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(Us,{size:13,className:`text-[#11a4d4]`}),(0,z.jsx)(`span`,{className:`block text-sm truncate text-slate-200`,children:e.name})]}),(0,z.jsxs)(`span`,{className:`block font-mono text-[10px] mt-1 text-slate-600`,children:[e.transport,e.descriptionSource?` / ${e.descriptionSource}`:``]})]})]}),e.hasDescription?(0,z.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:e.description}):(0,z.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-xs text-amber-100`,children:[(0,z.jsx)(Js,{size:13}),`Missing agent description`]}),(0,z.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,z.jsxs)(`button`,{type:`button`,onClick:()=>i(e.name),title:`Edit MCP Tool Context`,"aria-label":`Edit MCP Tool Context`,className:`inline-flex h-6 items-center justify-center gap-1 border border-[#11a4d4]/70 px-1.5 text-[10px] uppercase tracking-wider text-[#7dd3fc] hover:border-[#11a4d4] hover:text-sky-100`,children:[(0,z.jsx)(Ms,{size:12}),`Edit`]})})]},e.name)}):(0,z.jsx)(F0,{}),e&&e.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm p-3`,children:`No MCP servers configured`}):null]})})}function rke(e){return`${e.provider}/${e.id}`}var z0=`pibo.chat.lastSelection`,B0=`pibo.chat.sessionView`,V0=`pibo.chat.composerDraft.`,H0=`pibo.chat.composerHistory`,U0=`pibo.chat.showThinking`,W0=`pibo.chat.expandThinking`,G0=`pibo.chat.showRawEvents`,K0=`pibo.chat.showArchived`,q0=`pibo.chat.showArchivedRooms`,J0=`pibo.chat.newSessionProfile`,Y0=100;function X0(){try{let e=localStorage.getItem(z0);if(!e)return{};let t=JSON.parse(e);if(!l2(t))return{};let n=l2(t.sessionsByRoom)?Object.fromEntries(Object.entries(t.sessionsByRoom).filter(e=>typeof e[0]==`string`&&typeof e[1]==`string`&&!!e[1])):void 0;return{roomId:typeof t.roomId==`string`&&t.roomId?t.roomId:void 0,piboSessionId:typeof t.piboSessionId==`string`&&t.piboSessionId?t.piboSessionId:void 0,...n&&Object.keys(n).length?{sessionsByRoom:n}:{}}}catch{return{}}}function ike(e){try{let t={...X0().sessionsByRoom??{},...e.sessionsByRoom??{}};e.roomId&&e.piboSessionId&&(t[e.roomId]=e.piboSessionId),localStorage.setItem(z0,JSON.stringify({roomId:e.roomId,piboSessionId:e.piboSessionId,...Object.keys(t).length?{sessionsByRoom:t}:{}}))}catch{}}function Z0(e){try{let t=X0();if(!t.sessionsByRoom?.[e])return;let{[e]:n,...r}=t.sessionsByRoom;localStorage.setItem(z0,JSON.stringify({roomId:t.roomId,piboSessionId:t.piboSessionId,...Object.keys(r).length?{sessionsByRoom:r}:{}}))}catch{}}function Q0(e){try{return localStorage.getItem(V0+e)??``}catch{return``}}function $0(e,t){try{let n=V0+e;t?localStorage.setItem(n,t):localStorage.removeItem(n)}catch{}}function e2(){try{let e=localStorage.getItem(H0);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.trim().length>0).slice(-Y0):[]}catch{return[]}}function ake(e){let t=e.trim();if(!t)return;let n=e2();if(n.at(-1)!==t)try{localStorage.setItem(H0,JSON.stringify([...n,t].slice(-Y0)))}catch{}}function t2(){try{return localStorage.getItem(B0)===`terminal`?`terminal`:wc}catch{return wc}}function oke(e){try{localStorage.setItem(B0,e)}catch{}}function ske(){return s2(U0,!0)}function n2(e){c2(U0,e)}function cke(){return s2(W0,!0)}function r2(e){c2(W0,e)}function lke(){return s2(G0,!1)}function i2(e){c2(G0,e)}function uke(){return s2(K0,!1)}function dke(e){c2(K0,e)}function fke(){return s2(q0,!1)}function a2(e){c2(q0,e)}function pke(){try{return localStorage.getItem(J0)??``}catch{return``}}function o2(e){try{localStorage.setItem(J0,e)}catch{}}function mke(){try{localStorage.removeItem(z0)}catch{}}function s2(e,t){try{let n=localStorage.getItem(e);return n===`true`?!0:n===`false`?!1:t}catch{return t}}function c2(e,t){try{localStorage.setItem(e,String(t))}catch{}}function l2(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function u2(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`),Promise.resolve()}finally{document.body.removeChild(t)}}function d2(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function hke({sessionId:e,disabled:t=!1,commands:n,skills:r,value:i,focusSignal:a,selectedWebAnnotations:o,selectedUploadAttachments:s,onValueChange:c,onCommand:l,onDetachWebAnnotation:u,onClearWebAnnotations:d,onAttachUploadedFiles:f,onDetachUploadAttachment:p,onClearUploadAttachments:m,onSend:h}){let g=(0,R.useRef)(null),_=(0,R.useRef)(null),v=(0,R.useRef)(null),y=(0,R.useRef)(null),b=(0,R.useRef)(null),x=(0,R.useRef)(null),S=(0,R.useRef)(null),[C,w]=(0,R.useState)(0),[T,E]=(0,R.useState)(0),[D,O]=(0,R.useState)(0),[k,A]=(0,R.useState)([]),[j,M]=(0,R.useState)(!1),[N,P]=(0,R.useState)(null),[F,ee]=(0,R.useState)(null),te=(0,R.useMemo)(()=>{for(let e=D-1;e>=0;e--){let t=i[e];if(t===` `||t===`
|
|
163
164
|
`||t===` `)break;if(t===`$`){if(e>0&&i[e-1]===`\\`)continue;return{query:i.slice(e+1,D).toLowerCase(),startPos:e,endPos:D}}}return null},[i,D]),I=i.trim().startsWith(`/`)?i.trim().split(/\s+/)[0]:null,ne=te?f2(te.startPos,i.slice(te.startPos,D)):null,L=I?p2(I):null,re=(0,R.useMemo)(()=>te?r.filter(e=>e.name.toLowerCase().startsWith(te.query)):[],[te,r]),ie=(0,R.useMemo)(()=>I?n.filter(e=>e.slash.startsWith(I)):[],[I,n]),ae=ne&&k.includes(ne)?[]:re,oe=L&&k.includes(L)?[]:ie,se=(0,R.useCallback)(e=>{e&&A(t=>t.includes(e)?t:[...t,e])},[]),ce=(0,R.useCallback)(()=>{let e=[re.length?ne:null,ie.length?L:null].filter(e=>!!e);e.length&&A(t=>{let n=new Set(t);for(let t of e)n.add(t);return n.size===t.length?t:[...n]})},[L,ie.length,re.length,ne]);(0,R.useEffect)(()=>{let e=[ne,L].filter(e=>!!e);A(t=>t.filter(t=>e.includes(t)))},[L,ne]),(0,R.useEffect)(()=>{!oe.length||C<oe.length||w(0)},[C,oe.length]),(0,R.useEffect)(()=>{!ae.length||T<ae.length||E(0)},[T,ae.length]),(0,R.useEffect)(()=>{let e=requestAnimationFrame(()=>b.current?.scrollIntoView({block:`nearest`}));return()=>cancelAnimationFrame(e)},[C,oe.length]),(0,R.useEffect)(()=>{let e=requestAnimationFrame(()=>x.current?.scrollIntoView({block:`nearest`}));return()=>cancelAnimationFrame(e)},[T,ae.length]),(0,R.useEffect)(()=>{S.current=null},[e]),(0,R.useEffect)(()=>{if(!F)return;let e=requestAnimationFrame(()=>y.current?.focus());return()=>{cancelAnimationFrame(e),URL.revokeObjectURL(F.previewUrl)}},[F]),(0,R.useEffect)(()=>{if(a<=0)return;let e=_.current;if(!e)return;let t=e.value.length;e.focus(),e.setSelectionRange(t,t),O(t)},[a]),(0,R.useEffect)(()=>{if(!oe.length&&!ae.length)return;let e=e=>{let t=e.target;t instanceof Node&&(g.current?.contains(t)||ce())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[ce,oe.length,ae.length]),(0,R.useLayoutEffect)(()=>{xke(_.current)},[i]);let le=e=>{if(!te||!_.current)return;let t=i.slice(0,te.startPos),n=i.slice(te.endPos);c(t+`$`+e+n),se(f2(te.startPos,`$${e}`));let r=te.startPos+1+e.length;O(r),requestAnimationFrame(()=>{_.current?.setSelectionRange(r,r),O(r)})},ue=e=>{c(e),requestAnimationFrame(()=>{let e=_.current;if(!e)return;let t=e.value.length;e.setSelectionRange(t,t),O(t)})},de=e=>{let t=S.current;if(!t){if(e===`next`||i!==``)return!1;let t=e2();if(!t.length)return!1;let n=e===`previous`?t.length-1:0;return S.current={entries:t,index:n,draft:i},ue(t[n]),!0}if(e===`previous`){let e=Math.max(0,t.index-1);return S.current={...t,index:e},ue(t.entries[e]),!0}let n=t.index+1;return n>=t.entries.length?(S.current=null,ue(t.draft),!0):(S.current={...t,index:n},ue(t.entries[n]),!0)},fe=()=>{t||j||v.current?.click()},pe=()=>{ee(null)},me=e=>{if(t||j)return;let n=gke(e.clipboardData);if(!n.length)return;e.preventDefault(),ce(),P(null);let r=n[0];ee(e=>(e&&URL.revokeObjectURL(e.previewUrl),{file:r,previewUrl:URL.createObjectURL(r)}))},he=async()=>{if(!F||j)return;let e=F.file;ee(null),await ge([e])},ge=async e=>{if(e.length){M(!0),P({message:`Uploading ${e.length} file${e.length===1?``:`s`}...`,error:!1});try{f((await Nc(e)).files),P(null)}catch(e){P({message:e instanceof Error?e.message:String(e),error:!0})}finally{M(!1)}}},_e=async()=>{if(t)return;let e=i.trim();if(e){if(ae.length){le(ae[Math.min(T,ae.length-1)].name);return}if(oe.length&&!n.some(t=>t.slash===e.split(/\s+/)[0])){let e=oe[Math.min(C,oe.length-1)].slash;c(e),se(p2(e));return}if(S.current=null,ake(e),c(``),e.split(/\s+/)[0]===`/upload`){fe();return}e.startsWith(`/`)&&await l(e)||await h(e)}};return(0,z.jsxs)(`div`,{ref:g,"data-pibo-debug":`composer`,"data-pibo-session-id":e??void 0,"data-pibo-state":t?`disabled`:i?`non-empty`:`empty`,className:`relative p-3 bg-[#151f24] border-t border-slate-800 max-[980px]:p-2`,children:[(0,z.jsx)(`input`,{ref:v,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{let t=Array.from(e.target.files??[]);e.target.value=``,ge(t)}}),N?(0,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-sm border px-3 py-2 text-xs ${N.error?`border-red-900 bg-red-950/40 text-red-200`:N.copyText?`border-green-900/60 bg-green-950/30 text-green-300`:`border-slate-700 bg-[#0e1116] text-slate-300`}`,children:[(0,z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:N.message}),N.copyText?(0,z.jsx)(`button`,{type:`button`,onClick:()=>void u2(N.copyText),title:`Copy uploaded file path`,"aria-label":`Copy uploaded file path`,className:`shrink-0 rounded-sm p-0.5 text-slate-400 hover:bg-slate-800 hover:text-[#11a4d4]`,children:(0,z.jsx)($o,{size:13})}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>P(null),title:`Hide upload status`,"aria-label":`Hide upload status`,className:`shrink-0 rounded-sm p-0.5 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,children:(0,z.jsx)(Qs,{size:13})})]}):null,F?(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 grid place-items-center bg-black/60 px-4`,role:`dialog`,"aria-modal":`true`,"aria-label":`Upload pasted image`,onKeyDown:e=>{e.key===`Escape`&&pe()},children:(0,z.jsxs)(`div`,{className:`w-full max-w-md rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800 px-4 py-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-sm font-semibold text-slate-100`,children:`Pasted image detected`}),(0,z.jsx)(`div`,{className:`mt-1 text-xs text-slate-400`,children:`Upload this clipboard image to ~/.pibo/uploads?`})]}),(0,z.jsx)(`button`,{type:`button`,onClick:pe,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Cancel pasted image upload`,children:(0,z.jsx)(Qs,{size:14})})]}),(0,z.jsxs)(`div`,{className:`space-y-3 px-4 py-4`,children:[(0,z.jsx)(`img`,{src:F.previewUrl,alt:`Pasted clipboard image preview`,className:`max-h-64 w-full rounded-sm border border-slate-800 bg-[#0e1116] object-contain`}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-slate-400`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate font-mono`,children:F.file.name}),(0,z.jsx)(`span`,{className:`shrink-0 font-mono`,children:bke(F.file.size)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-slate-800 px-4 py-3`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:pe,className:`h-8 rounded-sm border border-slate-700 px-3 text-xs text-slate-300 hover:border-slate-500 hover:text-slate-100`,children:`Cancel`}),(0,z.jsx)(`button`,{ref:y,type:`button`,onClick:()=>void he(),disabled:j,className:`h-8 rounded-sm bg-[#11a4d4] px-3 text-xs font-medium text-white disabled:opacity-50`,children:`Upload image`})]})]})}):null,ae.length?(0,z.jsx)(`div`,{className:`absolute left-3 bottom-full mb-2 w-[min(520px,calc(100%-24px))] max-h-72 overflow-auto bg-[#0e1116] border border-emerald-500 rounded-sm shadow-xl`,children:ae.map((e,t)=>(0,z.jsxs)(`button`,{ref:t===T?x:null,type:`button`,onClick:()=>le(e.name),className:`w-full grid grid-cols-[120px_1fr] gap-2 px-3 py-2 text-left border-b border-slate-800 ${t===T?`bg-emerald-500/15`:``}`,children:[(0,z.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,e.name]}),(0,z.jsx)(`span`,{className:`text-xs text-slate-400`,children:e.description??e.path??``})]},e.name))}):null,s.length?(0,z.jsxs)(`div`,{className:`mb-2 rounded-sm border border-slate-800 bg-[#0e1116] px-2.5 py-1.5`,"data-pibo-debug":`composer-upload-attachments`,"data-upload-attachment-count":s.length,children:[(0,z.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Attached uploads`}),(0,z.jsx)(`button`,{type:`button`,onClick:m,className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Clear`})]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map(e=>(0,z.jsxs)(`div`,{title:e.path,className:`inline-flex max-w-80 items-center gap-1 rounded-sm border border-emerald-500/45 bg-emerald-500/10 px-2 py-1 text-left text-[11px] text-slate-200`,"data-pibo-debug":`composer-upload-attachment-chip`,"data-upload-path":e.path,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate`,children:d2(e.name||e.path,100)}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void u2(e.path),title:`Copy uploaded file path`,"aria-label":`Copy uploaded file path`,className:`shrink-0 rounded-sm p-0.5 text-emerald-300 hover:bg-slate-800 hover:text-[#11a4d4]`,children:(0,z.jsx)($o,{size:11})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>p(e.id),title:`Detach ${e.name||e.path}`,"aria-label":`Detach ${e.name||e.path}`,className:`shrink-0 rounded-sm p-0.5 text-emerald-300 hover:bg-slate-800 hover:text-slate-100`,children:(0,z.jsx)(Qs,{size:11})})]},e.id))})]}):null,o.length?(0,z.jsxs)(`div`,{className:`mb-2 rounded-sm border border-slate-800 bg-[#0e1116] px-3 py-2`,"data-pibo-debug":`composer-web-annotations`,"data-web-annotation-count":o.length,children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Attached web annotations`}),(0,z.jsx)(`button`,{type:`button`,onClick:d,className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`Clear`})]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:o.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),title:`Detach ${e.id}`,className:`inline-flex max-w-72 items-center gap-1 rounded-sm border border-[#11a4d4]/50 bg-[#11a4d4]/10 px-2 py-1 text-left text-[11px] text-slate-200`,"data-pibo-debug":`composer-web-annotation-chip`,"data-web-annotation-id":e.id,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate`,children:d2(e.primaryTarget||e.label||e.note||e.id,100)}),(0,z.jsx)(Qs,{size:11,className:`shrink-0 text-[#11a4d4]`})]},e.id))})]}):null,oe.length?(0,z.jsx)(`div`,{className:`absolute left-3 bottom-full mb-2 w-[min(520px,calc(100%-24px))] max-h-72 overflow-auto bg-[#0e1116] border border-[#11a4d4] rounded-sm shadow-xl`,children:oe.map((e,t)=>(0,z.jsxs)(`button`,{ref:t===C?b:null,type:`button`,onClick:()=>{c(e.slash),se(p2(e.slash)),w(t)},className:`w-full grid grid-cols-[120px_1fr] gap-2 px-3 py-2 text-left border-b border-slate-800 ${t===C?`bg-[#11a4d4]/15`:``}`,children:[(0,z.jsx)(`span`,{className:`font-mono text-[#11a4d4]`,children:e.slash}),(0,z.jsx)(`span`,{className:`text-xs text-slate-400`,children:e.description})]},e.slash))}):null,(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-end gap-2`,children:[(0,z.jsx)(`textarea`,{ref:_,"data-pibo-debug":`composer-input`,"data-pibo-session-id":e??void 0,"data-pibo-state":t?`disabled`:i?`non-empty`:`empty`,rows:1,value:i,disabled:t,onChange:e=>{S.current=null,c(e.target.value),O(e.target.selectionStart)},onKeyDown:e=>{if(e.key===`Escape`&&(ae.length||oe.length)){e.preventDefault(),e.stopPropagation(),ce();return}if(ae.length&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),E(t=>e.key===`ArrowDown`?(t+1)%ae.length:(t-1+ae.length)%ae.length);return}if(oe.length&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){e.preventDefault(),w(t=>e.key===`ArrowDown`?(t+1)%oe.length:(t-1+oe.length)%oe.length);return}if((e.key===`ArrowUp`||e.key===`ArrowDown`)&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&de(e.key===`ArrowUp`?`previous`:`next`)){e.preventDefault();return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),_e())},onPaste:me,placeholder:t?`Select a session to message`:`Send Message (/ for commands or $ for skills)`,className:`h-10 min-h-10 resize-none overflow-hidden bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm leading-5 outline-none focus:border-[#11a4d4] disabled:opacity-50 [scrollbar-gutter:stable]`}),(0,z.jsx)(`button`,{type:`button`,disabled:t||j,onClick:()=>void _e(),title:`Send message`,"aria-label":`Send message`,className:`h-10 w-10 self-end inline-flex items-center justify-center bg-[#11a4d4] rounded-sm text-white disabled:opacity-50`,children:(0,z.jsx)(Hs,{size:16})})]})]})}function f2(e,t){return`skill:${e}:${t}`}function p2(e){return`command:${e}`}function gke(e){let t=Array.from(e.items).filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);return(t.length?t:Array.from(e.files).filter(e=>e.type.startsWith(`image/`))).map(_ke)}function _ke(e){return e.name&&e.name!==`image.png`?e:new File([e],vke(e.type),{type:e.type||`image/png`,lastModified:Date.now()})}function vke(e){let t=yke(e),n=new Date;return`screenshot-${[n.getFullYear(),m2(n.getMonth()+1),m2(n.getDate()),`-`,m2(n.getHours()),m2(n.getMinutes()),m2(n.getSeconds())].join(``)}${t}`}function yke(e){switch(e){case`image/jpeg`:return`.jpg`;case`image/gif`:return`.gif`;case`image/webp`:return`.webp`;case`image/svg+xml`:return`.svg`;default:return`.png`}}function m2(e){return String(e).padStart(2,`0`)}function bke(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(1)} MiB`}function xke(e){if(!e)return;if(!e.value.includes(`
|
|
164
|
-
`)&&e.value.length<80){e.style.height=``,e.style.overflowY=`hidden`;return}let t=window.getComputedStyle(e),n=h2(t.lineHeight,20),r=h2(t.borderTopWidth)+h2(t.borderBottomWidth),i=n*5+h2(t.paddingTop)+h2(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 h2(e,t=0){let n=Number.parseFloat(e);return Number.isFinite(n)?n:t}async function Ske(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),V(`/api/web-annotations?${n.toString()}`)}async function Cke(e,t){return V(`/api/web-annotations/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(_2(t))})}async function wke(e){let t=new URLSearchParams;return e?.trim()&&t.set(`cdpUrl`,e.trim()),V(`/api/web-annotations/targets${t.size?`?${t.toString()}`:``}`)}async function g2(e){return V(`/api/web-annotations/bindings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(_2(e))})}async function Tke(e,t){return V(`/api/web-annotations/bindings/${encodeURIComponent(e)}/inject`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(_2(t))})}function _2(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))}var v2=`pibo.chat.webAnnotations.cdpUrl`,y2=`pibo.chat.webAnnotations.selected.`,Eke=`pibo.chat.webAnnotations.overlay.`,b2=`pibo.chat.webAnnotations.panelCollapsed`,x2=`pibo.chat.shortcuts.webAnnotationsToggle`,S2=`Alt+Shift+A`;function Dke(){try{return localStorage.getItem(v2)??``}catch{return``}}function Oke(e){try{e.trim()?localStorage.setItem(v2,e.trim()):localStorage.removeItem(v2)}catch{}}function C2(){try{return localStorage.getItem(x2)||`Alt+Shift+A`}catch{return S2}}function w2(e){let t=E2(e)||`Alt+Shift+A`;try{localStorage.setItem(x2,t)}catch{}}function T2(e){window.__piboWebAnnotations?.setShortcut?.(e);try{window.dispatchEvent(new CustomEvent(`pibo:web-annotation-shortcut-changed`,{detail:{shortcut:e}}))}catch{}}function E2(e){return e.replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,80)}function D2(e){try{return k2(localStorage.getItem(O2(e)))}catch{return null}}function O2(e){return Eke+e}function k2(e){if(!e)return null;try{return A2(JSON.parse(e))}catch{return null}}function A2(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 kke(e){try{let t=localStorage.getItem(y2+e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&!!e.trim()).slice(0,5):[]}catch{return[]}}function j2(e,t){try{let n=y2+e,r=[...new Set(t.filter(e=>e.trim()))].slice(0,5);r.length?localStorage.setItem(n,JSON.stringify(r)):localStorage.removeItem(n)}catch{}}function Ake(){try{return localStorage.getItem(b2)===`true`}catch{return!1}}function jke(e){try{localStorage.setItem(b2,String(e))}catch{}}function Mke({piboSessionId:e,annotations:t,selectedIds:n,loading:r,error:i,collapsed:a,onRefresh:o,onToggle:s,onClear:c,onCollapse:l,onClose:u}){return e?(0,z.jsxs)(`section`,{className:`border-t border-slate-800 bg-[#101d22] px-3 py-2 sm:px-4`,"data-pibo-debug":`web-annotations-session-panel`,"data-pibo-session-id":e,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web annotations`}),(0,z.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,z.jsxs)(`span`,{className:`rounded-sm border border-[#11a4d4]/50 px-1.5 py-0.5 text-[10px] text-[#11a4d4]`,children:[n.length,` attached`]}):null]}),a?null:(0,z.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Global annotation list. Selected attachments are remembered per session.`})]}),(0,z.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:o,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,z.jsx)(Ls,{size:12,className:r?`animate-spin`:void 0})}),(0,z.jsx)(`button`,{type:`button`,onClick:c,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,z.jsx)(qs,{size:12})}),(0,z.jsx)(`button`,{type:`button`,onClick:l,title:a?`Expand annotations panel`:`Collapse annotations panel`,"aria-label":a?`Expand annotations panel`:`Collapse annotations panel`,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] sm:h-7 sm:w-7`,children:a?(0,z.jsx)(Wo,{size:12}):(0,z.jsx)(Ho,{size:12})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,title:`Hide annotations panel`,"aria-label":`Hide annotations panel`,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] sm:h-7 sm:w-7`,children:(0,z.jsx)(Qs,{size:12})})]})]}),a?null:i?(0,z.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:I2(i,220)}):r&&!t.length?(0,z.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,z.jsx)(`div`,{className:`mt-2 grid max-h-[min(40svh,18rem)] grid-cols-1 gap-2 overflow-y-auto pr-1 sm:max-h-56 sm:grid-cols-[repeat(auto-fill,minmax(16rem,1fr))]`,"data-pibo-debug":`web-annotations-list`,children:t.map(e=>{let t=n.includes(e.id);return(0,z.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":t?`true`:`false`,className:`min-w-0 rounded-sm border px-3 py-2 text-xs ${t?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#0e1116]`}`,children:[(0,z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,z.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-slate-500`,children:[e.status,` · `,e.targetKind]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id),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 ${t?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:[t?(0,z.jsx)(Qs,{size:11}):(0,z.jsx)(Ps,{size:11}),` `,t?`Detach`:`Attach`]})]}),(0,z.jsx)(`div`,{className:`truncate text-slate-200`,title:e.primaryTarget||e.label||e.selector||e.id,children:I2(e.primaryTarget||e.label||e.selector||e.id,120)}),e.piboContext?(0,z.jsx)(`div`,{className:`truncate font-mono text-[11px] text-[#11a4d4]`,title:e.piboContext,children:I2(e.piboContext,140)}):null,(0,z.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:F2(e.url)}),(0,z.jsx)(`div`,{className:`mt-1 line-clamp-2 text-slate-400`,title:e.note,children:I2(e.note,180)}),(0,z.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-600`,children:Lke(e.createdAt)})]},e.id)})}):(0,z.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 Nke({piboSessionId:e,piboRoomId:t,disabled:n,panelVisible:r,onShowPanel:i,onHidePanel:a,onError:o}){let[s,c]=(0,R.useState)(!1),[l,u]=(0,R.useState)(``),[d,f]=(0,R.useState)(()=>Dke()),[p,m]=(0,R.useState)([]),[h,g]=(0,R.useState)(`idle`),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null);(0,R.useEffect)(()=>{n&&c(!1)},[n]),(0,R.useEffect)(()=>{Oke(d)},[d]);let x=async()=>{if(e){g(`loading`),b(null);try{m((await wke(d)).targets.filter(e=>e.type===`page`||e.attachable)),g(`loaded`)}catch(e){let t=N2(e,`CDP unavailable`);m([]),g(`error`),b({kind:`error`,message:t}),o(t)}}},S=async n=>{if(!e)throw Error(`No active session context`);return Tke(n.binding.id,M2({piboSessionId:e,piboRoomId:t,cdpUrl:d,annotationShortcut:C2()}))},C=async()=>{if(!(!e||_)){i(),v(!0),b({kind:`info`,message:`Injecting annotation overlay into this Pibo page…`});try{let n=await g2({piboSessionId:e,piboRoomId:t,url:window.location.href,title:document.title,sameOrigin:!0,annotationShortcut:C2()});if(!n.overlay)throw Error(`Overlay config missing from same-origin binding response`);await Ike(n.overlay),b({kind:`success`,message:`Annotation overlay is ready on this Pibo page. Open the overlay controls or use the shortcut to start annotating.`}),o(null)}catch(e){let t=N2(e,`Current-page annotation failed`);b({kind:`error`,message:t}),o(t)}finally{v(!1)}}},w=async()=>{if(!e||_)return;i();let n=l.trim();if(!n){b({kind:`error`,message:`URL is required`});return}if(Fke(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.`;b({kind:`error`,message:e}),o(e);return}v(!0),b({kind:`info`,message:`Opening target and injecting overlay…`});try{let r=await g2(M2({piboSessionId:e,piboRoomId:t,url:n,cdpUrl:d})),i=await S(r);b({kind:`success`,message:`Annotation overlay injected for ${P2(i.target??r.target,i.binding.url)}`}),u(``),o(null)}catch(e){let t=N2(e,`Annotation failed`);b({kind:`error`,message:t}),o(t)}finally{v(!1)}},T=async n=>{if(!(!e||_)){i(),v(!0),b({kind:`info`,message:`Binding selected target and injecting overlay…`});try{let r=await S(await g2(M2({piboSessionId:e,piboRoomId:t,targetId:n.id,cdpUrl:d})));b({kind:`success`,message:`Annotation overlay injected for ${P2(r.target??n,r.binding.url)}`}),o(null)}catch(e){let t=N2(e,n.attachable?`Target annotation failed`:`Target not attachable`);b({kind:`error`,message:t}),o(t)}finally{v(!1)}}};return(0,z.jsxs)(`div`,{className:`relative`,"data-pibo-debug":`web-annotations-entry`,"data-pibo-session-id":e??void 0,children:[(0,z.jsx)(Pke,{onClick:()=>{n||(c(e=>!e),r||i())},title:n?`Select an active session to annotate a web page`:r?`Web Annotations`:`Show Web Annotations`,ariaLabel:`Web Annotations`,active:s||r,children:(0,z.jsx)(Ao,{size:14})}),s&&!n?(0,z.jsxs)(`div`,{className:`fixed inset-x-2 bottom-3 z-40 max-h-[calc(100svh-1.5rem)] overflow-y-auto rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-sm shadow-xl sm:absolute sm:inset-auto sm:right-0 sm:top-full sm:bottom-auto sm:mt-2 sm:w-[min(420px,calc(100vw-24px))] sm:max-h-[calc(100svh-5rem)]`,role:`dialog`,"aria-label":`Web Annotations`,children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web Annotations`}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:r?a:i,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":r?`Hide annotation list`:`Show annotation list`,title:r?`Hide annotation list`:`Show annotation list`,children:(0,z.jsx)(zs,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Close Web Annotations panel`,children:(0,z.jsx)(Qs,{size:14})})]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void C(),disabled:_,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,z.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,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto]`,children:[(0,z.jsx)(`input`,{id:`web-annotation-url`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&w()},placeholder:`http://localhost:5173`,disabled:_,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,z.jsx)(`button`,{type:`button`,onClick:()=>void w(),disabled:_||!l.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,z.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,z.jsx)(`input`,{id:`web-annotation-cdp-url`,value:d,onChange:e=>f(e.target.value),placeholder:`Use gateway default`,disabled:_,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,z.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-slate-500`,children:`Existing targets`}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void x(),disabled:_||h===`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,z.jsx)(Ls,{size:12,className:h===`loading`?`animate-spin`:void 0}),` Refresh`]})]}),(0,z.jsxs)(`div`,{className:`mt-2 max-h-[min(34svh,14rem)] overflow-auto rounded-sm border border-slate-800 sm:max-h-56`,children:[h===`idle`?(0,z.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`Refresh to list reachable browser targets.`}):null,h===`loading`?(0,z.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-400`,children:`Loading targets…`}):null,h===`loaded`&&!p.length?(0,z.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`No attachable browser targets found.`}):null,p.map(e=>(0,z.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,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs text-slate-200`,title:e.title||e.url,children:I2(e.title||`Untitled target`,120)}),(0,z.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:I2(e.url||e.id,160)})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void T(e),disabled:_||!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))]}),y?(0,z.jsx)(`div`,{className:`mt-2 rounded-sm border px-2 py-2 text-xs ${y.kind===`error`?`border-red-900 bg-red-950/40 text-red-200`:y.kind===`success`?`border-emerald-900/60 bg-emerald-950/30 text-emerald-300`:`border-slate-700 bg-[#151f24] text-slate-300`}`,children:y.message}):null]}):null]})}function Pke({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,z.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function M2(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e&&e.trim()))}function Fke(e){try{let t=new URL(e);return t.port===`56663`||t.pathname.startsWith(`/json/`)}catch{return!1}}function Ike(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 N2(e,t){let n=Rke(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 P2(e,t){let n=e?.url||t||e?.title||`target`;return F2(e?.title||n)}function F2(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return I2(e,80)}}function I2(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function Lke(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function Rke(e){return e instanceof Error?e.message:String(e)}var zke={terminal:[`terminal`],workflow:[`workflow`]},L2=`1970-01-01T00:00:00.000Z`;function R2(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function Bke(e){return R2(e)&&e.state===`configured`&&!e.workflowRunId}function Vke(e){let t=e.selectedSessionNode?.workflowSessionKind??Hke(e.selectedSession?.metadata);if(t===`main_workflow`||t===`nested_workflow`){if(e.selectedProjectSession&&!R2(e.selectedProjectSession)||!e.selectedProjectSession&&t===`main_workflow`&&z2(e.selectedSession?.metadata)===`simple-chat`)return{viewId:`terminal`};let n=e.selectedProjectSession&&R2(e.selectedProjectSession)?e.selectedProjectSession:Uke({selectedSessionNode:e.selectedSessionNode,selectedSession:e.selectedSession,selectedProject:e.selectedProject,workflowSessionKind:t});return{viewId:`workflow`,...n?{workflowProjectSession:n}:{}}}return t===`agent_node`||t===`subagent`?{viewId:`terminal`}:e.selectedProjectSession&&R2(e.selectedProjectSession)?{viewId:`workflow`,workflowProjectSession:e.selectedProjectSession}:{viewId:`terminal`}}function Hke(e){let t=B2(e,`workflowSessionKind`);if(t===`main_workflow`||t===`nested_workflow`||t===`agent_node`||t===`subagent`)return t;if(B2(e,`projectSessionKind`)===`main`)return`main_workflow`}function z2(e){return B2(e,`projectWorkflowId`)??B2(e,`workflowId`)}function Uke(e){let t=e.selectedSessionNode?.piboSessionId??e.selectedSession?.id;if(!t)return;let n=e.selectedSession?.metadata,r=z2(n)??(e.workflowSessionKind===`nested_workflow`?`nested-workflow-session`:`workflow-session`),i=B2(n,`projectWorkflowVersion`)??B2(n,`workflowVersion`),a=B2(n,`workflowRunId`);return{projectId:e.selectedProject?.id??B2(n,`projectId`)??`project`,piboSessionId:t,kind:e.workflowSessionKind===`nested_workflow`?`sub`:`main`,workflowId:r,...i?{workflowVersion:i}:{},...a?{workflowRunId:a}:{},...e.selectedSessionNode?.parentId?{parentMainSessionId:e.selectedSessionNode.parentId}:{},...e.selectedSessionNode?.title||e.selectedSession?.title?{title:e.selectedSessionNode?.title??e.selectedSession?.title}:{},state:Wke(e.selectedSessionNode,a),...e.selectedSessionNode?.archived===void 0?{}:{archived:e.selectedSessionNode.archived},createdAt:e.selectedSession?.createdAt??L2,updatedAt:e.selectedSession?.updatedAt??e.selectedSessionNode?.lastActivityAt??L2}}function Wke(e,t){return e?.status===`error`?`failed`:e?.status===`running`?`running`:t?`workflow`:`configured`}function B2(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():void 0}function Gke(e){if(!R2(e))return`Workflow: ${e.workflowId}`;let t=e.workflowRunId?` · run ${U2(e.workflowRunId)}`:``;return`Workflow: ${e.workflowId}${t} · ${V2(e)}`}function Kke(e,t){return{workflowId:e.workflowId,state:V2(e,t),...e.workflowRunId?{workflowRunId:e.workflowRunId}:{}}}function qke({summary:e}){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,z.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,z.jsxs)(`span`,{className:H2(e.state),children:[`state `,e.state]}),e.workflowRunId?(0,z.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 `,U2(e.workflowRunId)]}):null]})}function V2(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.state?e.state.replace(/_/g,` `):e.workflowRunId?`workflow`:e.kind}function Jke(e,t){return H2(V2(e,t),e.archived)}function H2(e,t=!1){let n=e.toLowerCase(),r=`shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide`;return t?`${r} border-slate-700 text-slate-500`:n.includes(`failed`)||n.includes(`error`)?`${r} border-red-500/40 text-red-300 bg-red-500/10`:n.includes(`waiting`)?`${r} border-amber-500/40 text-amber-300 bg-amber-500/10`:n.includes(`complete`)||n.includes(`done`)?`${r} border-emerald-500/40 text-emerald-300 bg-emerald-500/10`:`${r} border-[#11a4d4]/40 text-[#11a4d4] bg-[#11a4d4]/10`}function U2(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function Yke({title:e,roomLabel:t,headerPiboSessionId:n,piboSessionId:r,piboRoomId:i,webAnnotationsDisabled:a,webAnnotationsPanelRendered:o,workflowHeader:s,sessionViewId:c,sessionViews:l,currentSessionView:u,allowedSessionViewIds:d,showRawEvents:f,showThinking:p,expandThinking:m,onShowWebAnnotationsPanel:h,onHideWebAnnotationsPanel:g,onSelectSessionView:_,onToggleRawEvents:v,onToggleThinking:y,onToggleExpandThinking:b,onError:x}){let[S,C]=(0,R.useState)(null),w=(0,R.useRef)(void 0),T=S===n,E=(0,R.useMemo)(()=>d?new Set(d):null,[d]);(0,R.useEffect)(()=>()=>{w.current&&window.clearTimeout(w.current)},[]);let D=()=>{n&&(u2(n).catch(()=>void 0),C(n),w.current&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>C(null),900))};return(0,z.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`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:e}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 font-mono text-[11px] text-slate-500`,children:[(0,z.jsx)(`span`,{className:`truncate`,children:t}),n?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,z.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>void D(),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:n})]}):null,s?(0,z.jsx)(qke,{summary:s}):null]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(Nke,{piboSessionId:r,piboRoomId:i,disabled:a,panelVisible:o,onShowPanel:h,onHidePanel:g,onError:x}),(0,z.jsx)(`div`,{className:`flex items-center rounded-sm border border-slate-700 bg-[#0e1116] p-0.5`,children:l.map(e=>{let t=!!(E&&!E.has(e.id));return(0,z.jsx)(`button`,{type:`button`,onClick:()=>{t||_(e.id)},disabled:t,title:t?`Project session routing uses the ${u.label} view for this session kind.`:e.description??e.label,"aria-label":t?`${e.label} view unavailable for this Project session kind`:`Switch to ${e.label} view`,className:`min-w-20 px-2.5 py-1 text-[11px] font-bold tracking-wide max-[980px]:min-w-0 max-[980px]:px-1.5 disabled:cursor-not-allowed disabled:text-slate-600 ${c===e.id?`bg-[#11a4d4]/10 text-[#11a4d4]`:`text-slate-400 hover:text-[#11a4d4] disabled:hover:text-slate-600`}`,children:e.label},e.id)})}),(0,z.jsx)(W2,{onClick:v,title:f?`Hide Raw Events`:`Show Raw Events`,ariaLabel:f?`Hide Raw Events`:`Show Raw Events`,active:f,children:(0,z.jsx)(Fo,{size:14})}),(0,z.jsx)(W2,{onClick:y,title:p?`Hide Thinking`:`Show Thinking`,ariaLabel:p?`Hide Thinking`:`Show Thinking`,active:p,children:p?(0,z.jsx)(Po,{size:14}):(0,z.jsx)(is,{size:14})}),p?(0,z.jsx)(W2,{onClick:b,title:m?`Collapse Thinking`:`Expand Thinking`,ariaLabel:m?`Collapse Thinking`:`Expand Thinking`,active:m,children:m?(0,z.jsx)(Ho,{size:14}):(0,z.jsx)(Wo,{size:14})}):null]})]})}function W2({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,z.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function Xke(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&Zke(e,n)){e.count+=1,e.createdAt=n.createdAt,e.payload={...q2(e.payload)?e.payload:{},text:`${G2(e.payload)}${G2(n.payload)}`};continue}t.push({...n,count:1})}return t}function Zke(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=q2(e.payload)?e.payload:{},r=q2(t.payload)?t.payload:{};return K2(n)===K2(r)}function G2(e){return q2(e)?typeof e.text==`string`?e.text:typeof e.delta==`string`?e.delta:``:``}function K2(e){return e.eventId??e.messageId}function q2(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Qke({traceView:e,eventLimit:t,isFetching:n,visible:r,onLoadOlder:i}){let a=(0,R.useMemo)(()=>r?Xke(e?.rawEvents??[]):[],[e?.rawEvents,r]);return r?(0,z.jsxs)(`aside`,{className:`min-h-0 overflow-auto bg-[#0e1116] border-l border-slate-800 max-[980px]:hidden`,children:[(0,z.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,z.jsxs)(`div`,{className:`p-3 flex flex-col gap-2`,children:[e&&a.length>=t?(0,z.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,z.jsxs)(`div`,{className:`border-l-2 border-[#11a4d4] bg-[#151f24] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[#11a4d4] font-mono text-[11px] mb-1`,children:[(0,z.jsx)(`span`,{children:e.type}),e.count>1?(0,z.jsxs)(`span`,{className:`text-slate-500`,children:[`x`,e.count]}):null]}),(0,z.jsx)(vq,{value:e.payload,showControls:!1})]},e.id))]})]}):null}function $ke({traceView:e,eventLimit:t,isFetching:n,onLoadOlder:r}){if(!e?.hasOlderEvents)return null;let i=Math.min(e.eventLimit??t,e.eventCount??t),a=e.eventCount??`many`;return(0,z.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-2 text-center`,children:(0,z.jsx)(`button`,{type:`button`,onClick:r,disabled:n,className:`rounded-sm border border-slate-700 px-3 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading history…`:`Load older trace history (${i} of ${a} events)`})})}function eAe({selectedPiboSessionId:e,selectedRoomId:t,fallbackRoomId:n,sessionViewId:r,loadingTrace:i,traceError:a,showRawEvents:o,currentTraceView:s,traceEventLimit:c,rawEventLimit:l,tracePageFetching:u,onLoadOlderTracePage:d,onLoadMoreRawEvents:f,headerProps:p,projectSessionCreatePanel:m,workflowStartPanel:h,currentSessionView:g,sessionViewProps:_,webAnnotationsPanelRendered:v,webAnnotationsPanelProps:y,composerProps:b}){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`main`,{"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":i?`loading`:a?`error`:e?`ready`:`empty`,className:`min-h-0 flex flex-col`,children:[(0,z.jsx)(Yke,{...p}),m?(0,z.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:m}):null,h?(0,z.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:h}):null,(0,z.jsx)($ke,{traceView:s,eventLimit:c,isFetching:u,onLoadOlder:()=>d(s?.nextBeforeSequence)}),a&&!s?(0,z.jsx)(`div`,{className:`min-h-0 flex-1 p-4 text-sm text-red-200`,children:a}):g.render(_),v?(0,z.jsx)(Mke,{...y}):null,(0,z.jsx)(hke,{...b})]}),(0,z.jsx)(Qke,{traceView:s,eventLimit:l,isFetching:u,visible:o,onLoadOlder:f})]})}var tAe=5e3,nAe=50,J2=new Map;function rAe(e){let t=J2.get(e);return t||(t={snapshots:[],pending:null,pendingTimer:null},J2.set(e,t)),t}function Y2(){try{return localStorage.getItem(`pibo.chat.traceDebug`)===`true`}catch{return!1}}function iAe(e){let t=0;for(let n of e)for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);t=(t<<5)-t+r,t|=0}return t.toString(36)}function X2(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&&n.trigger===t.trigger&&n.traceVersion===t.traceVersion&&JSON.stringify(n.layers.map(e=>e.ids))===JSON.stringify(t.layers.map(e=>e.ids))||(e.snapshots.push(t),e.snapshots.length>tAe&&e.snapshots.shift()),e.pending=null}function aAe(e){if(!Y2())return;let t=rAe(e.piboSessionId);if(t.pendingTimer&&=(clearTimeout(t.pendingTimer),null),(!t.pending||t.pending.trigger!==e.trigger||t.pending.piboSessionId!==e.piboSessionId)&&(X2(t),t.pending={timestamp:Date.now(),piboSessionId:e.piboSessionId,trigger:e.trigger,layers:[],expansionOverrides:e.expansionOverrides,traceVersion:e.traceVersion,latestStreamId:e.latestStreamId,lastRawEventId:e.lastRawEventId}),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),t.pendingTimer=setTimeout(()=>{X2(t),t.pendingTimer=null},nAe)}function oAe(e,t,n,r){let i=$2(n);aAe({piboSessionId:e,trigger:t,layer:{kind:`backendNodes`,ids:i.map(e=>e.id),digest:iAe(i.map(e=>e.id)),meta:i.map(e=>({id:e.id,type:e.type,orderKey:JSON.stringify(e.orderKey),parentId:e.parentId}))},...r})}function Z2(e){let t=J2.get(e);return t?(X2(t),t.snapshots):[]}function Q2(e){if(e){let t=Z2(e);return JSON.stringify({piboSessionId:e,snapshots:t},null,2)}let t={};for(let[e,n]of J2)X2(n),t[e]=n.snapshots;return JSON.stringify(t,null,2)}function sAe(e){e?J2.delete(e):J2.clear()}function $2(e){return e.flatMap(e=>[e,...$2(e.children??[])])}typeof window<`u`&&(window.__piboTraceSnapshots={exportAsJson:e=>{let t=Q2(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:Z2,clearSnapshots:sAe,exportSnapshots:Q2});function e4(e){let t=!1,n=e.map(e=>e.children.length?(t=!0,{...e,children:e4(e.children)}):e);return cAe(n)?t?n:[...e]:[...n].sort(t4)}function cAe(e){for(let t=1;t<e.length;t+=1)if(t4(e[t-1],e[t])>0)return!1;return!0}function t4(e,t){let n=lAe(e.startedAt,t.startedAt);if(n!==0)return n;let r=Jc(e.orderKey,t.orderKey);return r===0?e.id.localeCompare(t.id):r}function lAe(e,t){return!e&&!t?0:e?t?e.localeCompare(t):-1:1}function n4(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 uAe(e,t,n,r){if(!r4(t))return;let i=r.get(e)?.filter(e=>e.metadata?.subagentToolName===t)??[],a=fAe(n);return a?i.find(e=>e.metadata?.threadKey===a)?.id:i.length===1?i[0].id:void 0}function r4(e){return e.startsWith(`pibo_subagent_`)}function dAe(e){return e.slice(14)}function fAe(e){let t=`args`in e&&e.args&&typeof e.args==`object`&&!Array.isArray(e.args)?e.args:void 0,n=t&&`threadKey`in t?t.threadKey:void 0;return typeof n==`string`&&n.trim()?n.trim():void 0}function i4(e,t,n,r){let i=mAe(e,t,n,r);if(!i)return;let a=e.children.find(e=>e.id===i.id);if(a){hAe(a,i),a.runId=i.runId??a.runId;return}e.children.push(i)}function pAe(e){let t=new Map;for(let n of n4(e)){let e=o4(n.output);if(!e)continue;let r=c4(e.runId);r&&t.set(r,{snapshot:e,completedAt:c4(e.completedAt)??c4(e.updatedAt)??n.completedAt})}for(let n of n4(e)){if(n.type!==`agent.async`||!n.runId)continue;let e=t.get(n.runId);if(!e)continue;let r=c4(e.snapshot.status);r!==`completed`&&r!==`cancelled`&&r!==`failed`||(n.status=r===`failed`?`error`:`done`,n.completedAt=e.completedAt??n.completedAt,n.output=e.snapshot,r===`failed`&&(n.error=c4(e.snapshot.summary)??n.error))}}function mAe(e,t,n,r){if(!a4(e))return;let i=o4(e.output),a=l4(e.input)?e.input:{},o=c4(i?.toolName)??c4(a.toolName)??r?.title;if(!o||!r4(o))return;let s=c4(r?.summary)??dAe(o),c=c4(i?.runId),l=c4(i?.status),u=a.arguments,d=c4(i?.completionPolicy)??c4(a.completionPolicy);return{id:`${e.id}:async-agent`,parentId:e.id,piboSessionId:t,eventId:e.eventId,toolCallId:e.toolCallId,runId:c,type:`agent.async`,title:s,status:gAe(e,l),startedAt:r?.startedAt??n??e.startedAt,completedAt:l===`completed`||l===`cancelled`?e.completedAt:void 0,summary:`Started by ${e.title}`,input:{startedBy:e.title,startToolCallId:e.toolCallId,toolName:o,subagentName:s,runId:c,completionPolicy:d,arguments:u,threadKey:l4(r?.input)?r.input.threadKey:void 0},output:i,error:e.error,linkedPiboSessionId:r?.linkedPiboSessionId??e.linkedPiboSessionId,source:e.source,stableKey:c?`async-agent:${c}`:`${e.stableKey??e.id}:async-agent`,orderKey:qc(e.orderKey,`agent.async`),children:[]}}function a4(e){return e.type===`tool.call`&&e.title===`pibo_run_start`}function hAe(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 o4(e){if(l4(e)){if(s4(e))return e;if(l4(e.details)&&s4(e.details))return e.details}}function s4(e){return typeof e.runId==`string`&&typeof e.toolName==`string`}function c4(e){return typeof e==`string`?e:void 0}function gAe(e,t){return e.status===`error`||t===`failed`?`error`:t===`completed`||t===`cancelled`?`done`:`running`}function l4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function _Ae(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 vAe(e){let t=yAe(e.notification),n=t.length===1?t[0]:void 0,r=d4(e.notification.failed),i=d4(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:bAe(e.notification),output:e.notification,source:e.source,stableKey:e.stableKey??e.id,orderKey:e.orderKey,children:[]}}function yAe(e){return[...u4(e.completed),...u4(e.failed),...u4(e.cancelled),...u4(e.running)]}function u4(e){return Array.isArray(e)?e.filter(xAe):[]}function d4(e){return Array.isArray(e)?e.length:0}function bAe(e){let t=[[d4(e.completed),`completed`],[d4(e.failed),`failed`],[d4(e.cancelled),`cancelled`],[d4(e.running),`running`]].filter(([e])=>Number(e)>0).map(([e,t])=>`${e} ${t}`);return t.length?t.join(`, `):`No yielded run updates`}function xAe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function SAe(e,t,n,r,i,a,o,s,c){let l=r.payload;if(o&&IAe(l)&&!LAe(l,s)||o&&RAe(l,c))return;if(l.type===`assistant_delta`){MAe(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`thinking_delta`){NAe(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`assistant_message`){let i=CAe(n,l,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex),a=t.get(i.id);if(a){p4(a,i),m4(t,a);return}m4(t,i),e.push(i),t.set(i.id,i);return}let u=jAe(n,l,i,a,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);if(u){if(u.type===`agent.turn`&&u.eventId){let e=[...t.values()].find(e=>e.type===`agent.turn`&&e.eventId===u.eventId);if(e){e.status=u.status,e.completedAt=u.completedAt??e.completedAt;return}}if(u.type===`assistant.message`){let e=t.get(u.id);if(e){p4(e,u),m4(t,e);return}m4(t,u)}if(u.type===`execution.compaction`){let t=BAe(e);if(t){VAe(t,u);return}}if(u.type===`model.reasoning`){let e=t.get(u.id);if(e){PAe(e,u);return}}if(u.toolCallId){let e=[...t.values()].find(e=>e.toolCallId===u.toolCallId&&(e.type===`tool.call`||e.type===`agent.delegation`));if(e){if(a4(e)&&u.type===`agent.delegation`){i4(e,n,r.createdAt,u);return}zAe(e,u),i4(e,n,r.createdAt);return}}if(!(u.eventId&&t.has(u.id))){wAe(u,t),i4(u,n,r.createdAt),e.push(u);for(let e of n4([u]))t.set(e.id,e)}}}function CAe(e,t,n,r,i,a){let o=typeof t.eventId==`string`?t.eventId:void 0,s=b4(t);return{id:s?y4(s):`event:${t.type}:${C4(t)}`,piboSessionId:e,eventId:o,parentId:o?v4(o):void 0,type:`assistant.message`,title:`Agent Message`,status:`done`,startedAt:n,summary:t.text,output:t.text,source:`event-log`,stableKey:s?`assistant:${s}`:_4(t),orderKey:h4(r,t.type,i,a),children:[]}}function wAe(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=TAe(n,t);return r===void 0||e.startedAt<=r}).sort(t4).at(-1);n&&(e.parentId=n.id)}function TAe(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(t4).at(0)?.startedAt}function EAe(e){return e.some(e=>{let t=e.payload.type;return t!==`assistant_delta`&&t!==`thinking_delta`})}function DAe(e){if(e.type===`assistant_delta`){if(e.text.length===0)return;let t=b4(e);return t?y4(t):void 0}if(e.type===`thinking_delta`){if(e.text.length===0)return;let t=S4(e);return t?x4(t):void 0}}function OAe(e,t){let n=t.payload;if(n.type!==`message_queued`||n.source!==`user`)return!1;let r=typeof n.eventId==`string`?n.eventId:t.eventId,i=typeof n.text==`string`?n.text:void 0;return e.some(e=>e.type!==`user.message`||e.source!==`transcript`?!1:r&&(e.entryId===r||e.stableKey===`entry:${r}`)?!0:!!(i&&kAe(e)===i))}function kAe(e){if(typeof e.output==`string`)return e.output;if(typeof e.summary==`string`)return e.summary}function f4(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 AAe(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 jAe(e,t,n,r,i,a,o,s,c){let l=`eventId`in t&&typeof t.eventId==`string`?t.eventId:void 0,u=`event:${t.type}:${l??C4(t)}`,d=l?v4(l):void 0,f={id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:_4(t),orderKey:h4(o,t.type,s,c),children:[]};switch(t.type){case`message_queued`:{let n=_Ae(t.text);return t.source===`service`&&n?vAe({id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:l?`run-notification:${l}`:u,orderKey:h4(o,t.type,s,c),notification:n}):{...f,type:`user.message`,title:`User Message`,status:`done`,summary:t.text,output:t.text}}case`message_started`:case`message_finished`:return t.source===`service`?void 0:{...f,id:l?v4(l):u,type:`agent.turn`,title:`Agent Turn`,status:t.type===`message_finished`||i!==`running`?`done`:`running`,completedAt:t.type===`message_finished`?a:void 0,stableKey:l?`turn:${l}`:f.stableKey};case`thinking_finished`:{if(!HAe(t.text))return;let e=S4(t);return{...f,id:e?x4(e):u,parentId:d,type:`model.reasoning`,title:`Thinking`,status:`done`,summary:t.text,output:t.text,stableKey:e?`reasoning:${e}`:f.stableKey}}case`assistant_message`:{let e=b4(t);return{...f,id:e?y4(e):u,parentId:d,type:`assistant.message`,title:`Agent Message`,status:`done`,summary:t.text,output:t.text,stableKey:e?`assistant:${e}`:f.stableKey}}case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:{let o=r4(t.toolName),s=r.get(t.toolCallId)??(o?uAe(e,t.toolName,t,n):void 0);return{...f,id:`tool:${t.toolCallId}`,parentId:d,toolCallId:t.toolCallId,type:o?`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?UAe(t.result):void 0,linkedPiboSessionId:s,stableKey:`tool:${t.toolCallId}`,children:[]}}case`subagent_session`:return{...f,id:t.toolCallId?`tool:${t.toolCallId}`:u,eventId:l,toolCallId:t.toolCallId,type:`agent.delegation`,title:t.toolName,status:i===`running`?`running`:`done`,summary:t.subagentName,input:{subagentName:t.subagentName,threadKey:t.threadKey},linkedPiboSessionId:t.childPiboSessionId,stableKey:t.toolCallId?`tool:${t.toolCallId}`:`subagent:${t.childPiboSessionId}`,children:[]};case`execution_result`:return FAe(t.action)?void 0:{...f,type:`execution.command`,title:t.action,status:`done`,input:{action:t.action},output:t.result};case`compaction_start`:return{...f,id:`event:compaction:${o??s??C4(t)}`,type:`execution.compaction`,title:`compact`,status:`running`,summary:`Compacting`,input:{reason:t.reason},stableKey:`compaction:active`};case`compaction_end`:return{...f,id:`event:compaction:end:${o??s??C4(t)}`,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:active`};case`session_error`:return{...f,type:`error`,title:`Session Error`,status:`error`,summary:t.errorDetails?.userMessage,input:t.errorDetails,error:t.error,output:t.error};default:return}}function MAe(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=b4(n),l=c?y4(c):`event:assistant_delta:${C4(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?v4(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:c?`assistant:${c}`:l,orderKey:h4(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function p4(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 NAe(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=S4(n),l=c?x4(c):`event:thinking_delta:${C4(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?v4(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:c?`reasoning:${c}`:l,orderKey:h4(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function PAe(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 m4(e,t){if(!t.parentId||t.status!==`done`)return;let n=e.get(t.parentId);!n||n.type!==`agent.turn`||(n.status=`done`,n.completedAt=t.completedAt??t.startedAt??n.completedAt)}function FAe(e){return e===`session.fork`||e===`session.clone`||e===`session.switch`}function IAe(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 LAe(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;return!!(n&&t.has(n))}function RAe(e,t){return t!==`running`&&e.type===`tool_call`}function h4(e,t,n,r){return e===void 0&&(n!==void 0||r!==void 0)?Gc(n,r,g4(t)):Wc(e,g4(t))}function g4(e){switch(e){case`message_queued`: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 _4(e){let t=`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`tool:${e.toolCallId}`;if(t&&(e.type===`message_started`||e.type===`message_finished`))return`turn:${t}`;if(e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`){let t=S4(e);if(t)return`reasoning:${t}`}if(e.type===`assistant_delta`||e.type===`assistant_message`){let t=b4(e);if(t)return`assistant:${t}`}return`event:${e.type}:${t??C4(e)}`}function v4(e){return`event:message:${e}`}function y4(e){return`event:assistant:${e}`}function b4(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 x4(e){return`event:thinking:${e}`}function S4(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 zAe(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 BAe(e){return n4([...e]).reverse().find(e=>e.type===`execution.compaction`&&e.status===`running`)}function VAe(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 HAe(e){return typeof e==`string`&&e.trim().length>0}function UAe(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function C4(e){return WAe(new TextEncoder().encode(JSON.stringify(e))).slice(0,48)}function WAe(e){let t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,n=``,r=0;for(;r+2<e.length;r+=3){let i=e[r]<<16|e[r+1]<<8|e[r+2];n+=t[i>>18&63]+t[i>>12&63]+t[i>>6&63]+t[i&63]}if(r<e.length){let i=e[r],a=r+1<e.length?e[r+1]:0,o=i<<16|a<<8;n+=t[o>>18&63]+t[o>>12&63],r+1<e.length&&(n+=t[o>>6&63])}return n}function GAe(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 e4(n)}function KAe(e,t,n){return t.map(t=>w4(e,t,n))}function w4(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)||T4(r,t))?r:e?{...t,children:r.children}:{...t,children:[]}}let i=t.children.map(t=>w4(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)||T4(r,t))?r:a?{...t,children:r?.children??i}:{...t,children:i}}function T4(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.runId===t.runId&&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.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&&qAe(e.orderKey,t.orderKey)}function qAe(e,t){return e===t?!0:!e||!t?!1:e.sourceRank===t.sourceRank&&e.turnSeq===t.turnSeq&&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 JAe(e,t,n){if(!t.length)return e;let r=new Set(e.rawEvents.map(e=>f4(e))),i=[];for(let e of t){let t=f4(e);r.has(t)||(r.add(t),i.push(e))}if(!i.length)return e;let a=n4(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=[],p=new Set;for(let t of i){if(OAe(o,t))continue;f.push(t);let r=DAe(t.payload);p&&r?p.add(r):p=void 0,SAe(o,s,e.piboSessionId,t,l,u,!1,d,n)}if(!f.length)return e;let m=GAe(o);EAe(f)&&pAe(m);let h=KAe(c,m,p);return{...e,rawEvents:e.rawEvents.length?[...e.rawEvents,...f]:f,nodes:h,latestStreamId:AAe(f,e.latestStreamId)}}function E4(e){let t=new Map;if(O4(e.nodes,t),!t.size)return e;let{nodes:n,changed:r}=k4(e.nodes,t);return r?{...e,nodes:n}:e}function YAe(e){return e.some(D4)}function XAe(e){let t=new Map;return j4(e,e=>{if(e.type!==`user.message`||!e.entryId)return;let n=M4(e),r=t.get(n);r?r.push(e.entryId):t.set(n,[e.entryId])}),t}function ZAe(e,t){if(!t.size)return;let n=new Map;j4(e,e=>{if(e.type!==`user.message`||e.entryId)return;let r=M4(e),i=t.get(r);if(!i?.length)return;let a=n.get(r)??0,o=i[a];o&&(e.entryId=o,n.set(r,a+1))})}function D4(e){let t=e.payload;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&`type`in t&&t.type===`message_queued`&&`source`in t&&t.source===`user`&&`text`in t&&typeof t.text==`string`)}function O4(e,t){for(let n of e){if(n.type===`user.message`&&!A4(n)){let e=M4(n);e&&t.set(e,(t.get(e)??0)+1)}O4(n.children,t)}}function k4(e,t){let n=!1,r=[];for(let i of e){if(A4(i)){let e=M4(i),r=e?t.get(e)??0:0;if(r>0){t.set(e,r-1),n=!0;continue}}let e=k4(i.children,t);n||=e.changed,r.push(e.changed?{...i,children:e.nodes}:i)}return{nodes:n?r:e,changed:n}}function A4(e){return e.type===`user.message`?e.source===`event-log`&&e.id.startsWith(`event:message_queued:`)?!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 j4(e,t){for(let n of e)t(n),j4(n.children,t)}function M4(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function QAe({selectedPiboSessionId:e,reconciledBaseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:i,now:a}){if(!e||t?.piboSessionId!==e)return{traceView:null};let o=n?.piboSessionId===e?n.events:[];if(!o.length)return{traceView:t};let s=a?.(),c=JAe(t,o,r??`idle`),l=YAe(o);return l&&ZAe(c.nodes,i),{traceView:l?E4(c):c,liveTraceComputeDurationMs:s!==void 0&&a?a()-s:void 0}}function N4(e,t){for(let n of e)t(n),N4(n.children,t)}function $Ae(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function P4(e){if(!e)return;let t=0;return N4(e.nodes,e=>{e.type===`assistant.message`&&(t+=$Ae(e).length)}),t}function eje({selectedPiboSessionId:e,baseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r}){let i=(0,R.useMemo)(()=>t?E4(t):null,[t]),a=(0,R.useMemo)(()=>i?XAe(i.nodes):new Map,[i]),o=(0,R.useMemo)(()=>QAe({selectedPiboSessionId:e,reconciledBaseTraceView:i,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:a,now:zU()?()=>performance.now():void 0}),[n,e,r,i,a]),s=o.traceView;return(0,R.useEffect)(()=>{!e||!s?.piboSessionId||!zU()||(XU(s.piboSessionId,{overlayEventCount:n?.piboSessionId===s.piboSessionId?n.events.length:0,traceBaseOutputLength:P4(t),currentOutputLength:P4(s)}),o.liveTraceComputeDurationMs!==void 0&&GU(s.piboSessionId,o.liveTraceComputeDurationMs))},[t,o.liveTraceComputeDurationMs,s,n,e]),(0,R.useEffect)(()=>{let e=()=>{!s?.piboSessionId||!Y2()||oAe(s.piboSessionId,`tab:${document.visibilityState}`,s.nodes,{traceVersion:s.version,latestStreamId:s.latestStreamId,lastRawEventId:s.rawEvents.at(-1)?.id})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[s]),s}var F4=1e4,I4=30*6e4,L4=2e3;function tje(e,t=!1,n){return[`chat`,`bootstrap`,e??``,t?`archived`:`active`,n??``]}function nje(e=!1,t,n){return[`chat`,`sessions`,e?`archived`:`active`,t??``,n??``]}function rje(e){return[`chat`,`trace-summary`,e]}function ije(e,t=!1,n,r=t?60:120){return[`chat`,`session-page`,e,t?`archived`:`active`,n??``,r]}function R4(e,t={}){let n=t.pageSize??t.eventLimit??2e3;return[`chat`,`trace-page`,e,t.includeRawEvents?`raw`:`compact`,t.rawEventsLimit??80,n,t.beforeSequence===void 0?`tail`:String(t.beforeSequence)]}function z4(e){return[`chat`,`trace-summary`,e]}function B4(e){return[`chat`,`trace-page`,e]}function aje(e,t){if(!e||e.piboSessionId!==t.piboSessionId)return e;let n=t.latestStreamId,r=oje(t),i=V4(t.nodes),a=e.events.filter(e=>{if(n!==void 0&&e.streamId!==void 0&&e.streamId<=n||D4(e)&&i.has(e.payload.text))return!1;let t=U4(e);return!t||!r.has(t)});return a.length?{...e,events:a}:null}function V4(e){let t=new Set;for(let n of e){if(n.type===`user.message`&&n.source===`transcript`){let e=sje(n);e&&t.add(e)}for(let e of V4(n.children))t.add(e)}return t}function oje(e){let t=new Set;for(let n of e.rawEvents){let e=U4(n);e&&t.add(e)}return H4(e.nodes,t),t}function H4(e,t){for(let n of e){if(n.type===`user.message`){let e=n.id.startsWith(`event:message_queued:`)?n.id.slice(21):void 0;e&&t.add(`${n.piboSessionId}:message_queued:${e}`),n.source===`transcript`&&n.entryId&&t.add(`${n.piboSessionId}:message_queued:${n.entryId}`)}n.eventId&&n.type===`assistant.message`&&(t.add(`${n.piboSessionId}:assistant_delta:${n.eventId}`),t.add(`${n.piboSessionId}:assistant_message:${n.eventId}`)),n.eventId&&n.type===`model.reasoning`&&(t.add(`${n.piboSessionId}:thinking_delta:${n.eventId}`),t.add(`${n.piboSessionId}:thinking_finished:${n.eventId}`)),H4(n.children,t)}}function U4(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(!(!n||!r))return`${r}:${e.type}:${n}`}function sje(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 cje(e,t){if(e.piboSessionId!==t.piboSessionId)return e;let n=new Set,r=[...t.nodes,...e.nodes].filter(e=>n.has(e.id)?!1:(n.add(e.id),!0)),i=new Set,a=[...t.rawEvents,...e.rawEvents].filter(e=>{let t=e.id||`${e.eventSequence??``}:${e.type}:${e.createdAt}`;return i.has(t)?!1:(i.add(t),!0)});return{...e,version:e.version,nodes:r,rawEvents:a,firstEventSequence:t.firstEventSequence??e.firstEventSequence,nextBeforeSequence:t.nextBeforeSequence,hasOlderEvents:t.hasOlderEvents,eventLimit:(e.eventLimit??0)+(t.eventLimit??t.pageSize??0)}}function lje({selectedPiboSessionId:e,showRawEvents:t,setLiveTraceOverlay:n}){let r=Yt(),[i,a]=(0,R.useState)(L4),[o,s]=(0,R.useState)(80),[c,l]=(0,R.useState)(null),u=(0,R.useMemo)(()=>e?rje(e):null,[e]),d=(0,R.useMemo)(()=>e?R4(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4}):null,[o,e,t]),f=dn({queryKey:u??[`chat`,`trace-summary`,`idle`],queryFn:async()=>{if(!e||!u)throw Error(`Session is required`);let t=r.getQueryData(u),n=await Ic(e,t?.version);if(n.notModified&&t)return t;if(!n.summary)throw Error(`Trace summary response missing payload.`);return n.summary},enabled:!!e,staleTime:F4,gcTime:I4,refetchOnWindowFocus:!1,retry:1}),p=dn({queryKey:d??[`chat`,`trace-page`,`idle`,`compact`,o,2e3,`tail`],queryFn:async()=>{if(!e||!d)throw Error(`Session is required`);let n=r.getQueryData(d),i=await Lc(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4,knownVersion:n?.version});if(i.notModified&&n)return n;if(!i.trace)throw Error(`Trace page response missing payload.`);return i.trace},enabled:!!e,staleTime:F4,gcTime:I4,refetchOnWindowFocus:!1,retry:1});(0,R.useEffect)(()=>{a(L4),s(80),l(null),n(null)},[e,n]),(0,R.useEffect)(()=>{let t=p.data;!t||t.piboSessionId!==e||(zU()&&XU(t.piboSessionId,{overlayEventCount:0,traceBaseOutputLength:P4(t),traceBaseUpdated:!0}),(0,R.startTransition)(()=>{l(t),n(e=>aje(e,t))}))},[e,n,p.data]);let m=(0,R.useCallback)(async n=>{if(!e||!n)return;let i=R4(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4,beforeSequence:n}),s=await r.fetchQuery({queryKey:i,queryFn:async()=>{let a=r.getQueryData(i),s=await Lc(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4,beforeSequence:n,knownVersion:a?.version});if(s.notModified&&a)return a;if(!s.trace)throw Error(`Trace page response missing payload.`);return s.trace},staleTime:F4,gcTime:I4});(0,R.startTransition)(()=>{l(e=>e?cje(e,s):s),a(e=>e+(s.pageSize??2e3))})},[r,o,e,t]),h=(0,R.useCallback)(()=>{s(e=>e+80)},[]);return{baseTraceView:c,traceEventLimit:i,rawEventLimit:o,traceSummaryQuery:f,tracePageQuery:p,tracePageReady:!!d,loadOlderTracePage:m,loadMoreRawEvents:h}}function uje(e){let t=e.currentEvents,n,r,i=()=>(r??=new Set(t.map(K4)),r),a=e=>{n??=t.slice(),n.push(e),t=n};for(let o of e.streamEvents){let s=pje(o,e.piboSessionId,e.nextSequence,e.now??(()=>new Date().toISOString()));if(!s)continue;if(dje(s)){t=fje(t,s),n=t,r=void 0;continue}let c=K4(s),l=i();l.has(c)||(l.add(c),a(s))}return t}function dje(e){return e.type===`assistant_message`||e.type===`thinking_finished`||e.type===`tool_execution_finished`}function fje(e,t){return t.type===`assistant_message`?[...G4(e,t,`assistant_delta`),t]:t.type===`thinking_finished`?[...G4(e,t,`thinking_delta`),t]:t.type===`tool_execution_finished`?[...G4(e,t,`tool_execution_updated`),t]:e}function pje(e,t,n,r){if(e.type===`RAW_EVENT`&&Y4(e.event)&&typeof e.event.type==`string`){let i=e.event;return W4(e,t,e.event.type,i,n,r)}if(e.type===`TEXT_MESSAGE_CONTENT`&&typeof e.delta==`string`)return W4(e,t,`assistant_delta`,{type:`assistant_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...J4(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 W4(e,t,`thinking_delta`,{type:`thinking_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...J4(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 W4(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,args:e.args},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 W4(e,t,a,a===`tool_execution_updated`?{type:`tool_execution_updated`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,partialResult:e.partialResult}:{type:`tool_call`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,argsComplete:!!e.argsComplete},n,r)}if(e.type===`TOOL_CALL_RESULT`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return W4(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,result:e.result,isError:!!e.isError},n,r);if(e.type===`RUN_ERROR`&&typeof e.message==`string`)return W4(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 W4(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();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,streamId:typeof e.streamId==`number`?e.streamId:void 0,streamFrameIndex:s,eventId:typeof r.eventId==`string`?r.eventId:void 0,type:n,createdAt:a(),payload:r}}function G4(e,t,n){let r=q4(t);return e.filter(e=>e.type!==n||q4(e)!==r)}function K4(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 q4(e){let t=Y4(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`)return`${n}:${r}:tool:${t.toolCallId}`;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 J4(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 Y4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var mje=500,hje=1e4,gje=45e3,_je=100;function vje({selectedPiboSessionId:e,tracePageData:t,currentTraceView:n,liveEventSeqRef:r,selectedSessionStatus:i,tracePageReady:a,setLiveTraceOverlay:o,onRefreshTrace:s,onRefreshBootstrap:c,onError:l}){let u=(0,R.useRef)(new Map),d=(0,R.useRef)(void 0),f=(0,R.useRef)(void 0),p=(0,R.useRef)(new Map),m=(0,R.useRef)(new Map),h=(0,R.useRef)(null),g=(0,R.useRef)(void 0),_=(0,R.useRef)(0),[v,y]=(0,R.useState)(0);(0,R.useEffect)(()=>{let n=t;if(!n||n.piboSessionId!==e)return;let i=n.rawEvents.map(e=>e.eventSequence??0).reduce((e,t)=>Math.max(e,t),0);r.current=Math.max(r.current,i+1),n.latestStreamId!==void 0&&Xc(m.current,n.piboSessionId,n.latestStreamId)},[r,e,t]);let b=(0,R.useCallback)(e=>{let t=u.current.get(e);t?.length&&(o(n=>{let i=uje({currentEvents:n?.piboSessionId===e?n.events:[],streamEvents:t,piboSessionId:e,nextSequence:()=>r.current++});return WU(e,t.length,i.length),{piboSessionId:e,events:i}}),u.current.delete(e))},[]),x=(0,R.useCallback)(()=>{if(!(d.current!==void 0||f.current!==void 0||!e)){if(document.hidden){f.current=setTimeout(()=>{f.current=void 0,b(e)},_je);return}d.current=requestAnimationFrame(()=>{d.current=void 0,b(e)})}},[b,e]),S=(0,R.useCallback)((t,n,r=!1)=>{nl(p.current,t,n);let i=r||rl(p.current,t,n),a=u.current.get(t)??[];a.push(n),u.current.set(t,a),UU(t,n,a.length,i),i||t!==e?b(t):x()},[b,x,e]);(0,R.useEffect)(()=>()=>{d.current!==void 0&&cancelAnimationFrame(d.current),f.current!==void 0&&clearTimeout(f.current),g.current!==void 0&&clearTimeout(g.current)},[]);let C=(0,R.useCallback)((e,t)=>{Zc(m.current,e,t)},[]),w=(0,R.useCallback)((e=0)=>{if(g.current!==void 0){if(e>0)return;clearTimeout(g.current)}g.current=setTimeout(()=>{g.current=void 0,y(e=>e+1)},e)},[]),T=(0,R.useCallback)(()=>{if(!e)return;b(e),s().catch(e=>l(X4(e))),c().catch(e=>l(X4(e)));let t=h.current;(!t||t.piboSessionId!==e||t.events.readyState===2||Date.now()-t.lastActivityAt>gje)&&w()},[b,l,c,s,w,e]);(0,R.useEffect)(()=>{if(!e||!a||!n||n.piboSessionId!==e)return;let t=new URLSearchParams({piboSessionId:e});t.set(`mode`,`live`);let r=m.current.get(e),i=r?.cursor??(n.latestStreamId===void 0?void 0:Qc(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()}`),u=Date.now();h.current={piboSessionId:e,events:o,openedAt:u,lastActivityAt:u};let d=!1,f,p,v=!1,y=!1,x=(t,n=!1)=>{if(f){if(!n)return;clearTimeout(f)}qU(e,t),f=setTimeout(()=>{f=void 0,s().catch(e=>l(X4(e)))},t)},T=()=>{if(v){y=!0;return}v=!0,c().catch(e=>l(X4(e))).finally(()=>{v=!1,y&&(y=!1,E(250,!0))})},E=(e,t=!1)=>{if(p){if(!t)return;clearTimeout(p)}p=setTimeout(()=>{p=void 0,T()},e)},D=()=>{E(900,!0)};return o.onopen=()=>{_.current=0,g.current!==void 0&&(clearTimeout(g.current),g.current=void 0),BU(e,o.readyState);let t=h.current;t?.events===o&&(t.lastActivityAt=Date.now())},o.onerror=()=>{if(d)return;VU(e,o.readyState);let t=h.current;t?.events===o&&(t.lastErrorAt=Date.now());let n=_.current++;w(Math.min(hje,mje*2**n))},o.addEventListener(`pibo`,t=>{if(d)return;let n=Yc(t);if(!n)return;let r=n.piboSessionId||e,i=h.current;if(i?.events===o&&(i.lastActivityAt=Date.now()),C(r,n),HU(r,n,t.lastEventId,o.readyState),r===e&&n.type===`ready`&&n.liveReplay?.missed&&x(0,!0),ZU(n))return;let a=n.type!==`TEXT_MESSAGE_CONTENT`&&n.type!==`REASONING_MESSAGE_CONTENT`;r===e&&tl(n)&&S(r,n,a);let s=$c(n);r===e&&s!==void 0?x(s,!0):r===e&&n.type!==`ready`&&n.type!==`RAW_EVENT`&&x(1500,!0),el(n)&&(n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`||n.type===`TEXT_MESSAGE_END`?D():E(r===e?0:150))}),()=>{d=!0,f&&clearTimeout(f),p&&clearTimeout(p),b(e),h.current?.events===o&&(h.current=null),o.close()}},[n?.piboSessionId,S,b,l,c,s,C,w,v,e,a]),(0,R.useEffect)(()=>{n?.piboSessionId&&b(n.piboSessionId)},[n?.piboSessionId,b]),(0,R.useEffect)(()=>{let e=()=>T(),t=()=>{document.hidden||T()};return window.addEventListener(`focus`,e),window.addEventListener(`online`,e),window.addEventListener(`pageshow`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`online`,e),window.removeEventListener(`pageshow`,e),document.removeEventListener(`visibilitychange`,t)}},[T]),(0,R.useEffect)(()=>{if(!e||i!==`running`)return;let t=window.setInterval(()=>{b(e),s().catch(e=>l(X4(e)))},1e3);return()=>window.clearInterval(t)},[b,l,s,e,i])}function X4(e){return e instanceof Error?e.message:String(e)}var yje=10;function bje(e,t,n,r){if(!t||!n.length)return e;let i=e[t]??[],a=new Set(i.map(e=>e.path)),o=n.filter(e=>e.path&&!a.has(e.path)).map(e=>({...e,id:r()}));return o.length?{...e,[t]:[...i,...o].slice(0,yje)}:e}function xje(e,t,n){if(!t)return e;let r=e[t]??[],i=r.filter(e=>e.id!==n);return i.length===r.length?e:{...e,[t]:i}}function Sje(e,t){return!t||!e[t]?.length?e:{...e,[t]:[]}}function Cje(e,t){let[n,r]=(0,R.useState)({});return{selectedUploadAttachments:(0,R.useMemo)(()=>e?n[e]??[]:[],[e,n]),attachUploadedFiles:(0,R.useCallback)(n=>{r(r=>bje(r,e,n,t))},[t,e]),detachUploadAttachment:(0,R.useCallback)(t=>{r(n=>xje(n,e,t))},[e]),clearSelectedUploadAttachments:(0,R.useCallback)(()=>{r(t=>Sje(t,e))},[e])}}function wje({selectedPiboSessionId:e,onError:t,formatError:n}){let[r,i]=(0,R.useState)([]),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(()=>e?D2(e):null),[l,u]=(0,R.useState)(()=>Ake()),[d,f]=(0,R.useState)(!1),p=!!(e&&s?.piboSessionId===e&&s.installed),m=!!e&&(a||p),h=dn({queryKey:[`web-annotations`,`app`,e],queryFn:async()=>{if(!e)throw Error(`Session is required`);return Ske(e,{limit:100,scope:`app`})},enabled:!!e&&(m||r.length>0),staleTime:1e3,refetchOnWindowFocus:m,refetchInterval:m?5e3:!1,retry:1}),g=h.refetch,_=(0,R.useMemo)(()=>(h.data?.annotations??[]).filter(e=>e.status!==`resolved`&&e.status!==`dismissed`),[h.data?.annotations]),v=(0,R.useMemo)(()=>r.map(e=>_.find(t=>t.id===e)).filter(e=>!!e),[r,_]);(0,R.useEffect)(()=>{i(e?kke(e):[]),c(e?D2(e):null)},[e]),(0,R.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.piboSessionId!==e||(c(e=>t.installed?t:e?.installed&&e.bindingId&&t.bindingId&&e.bindingId!==t.bindingId?e:t),t.installed?g():o(!1))},n=e=>t(A2(e.detail)),r=n=>{n.key===O2(e)&&t(k2(n.newValue))},i=()=>t(D2(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)}},[g,e]),(0,R.useEffect)(()=>{if(!h.data)return;if(!_.length){i(t=>(t.length&&e&&j2(e,[]),t.length?[]:t));return}let t=new Set(_.map(e=>e.id));i(n=>{let r=n.filter(e=>t.has(e));return r.length!==n.length&&e&&j2(e,r),r.length===n.length?n:r})},[e,_,h.data]),(0,R.useEffect)(()=>{let e=()=>{o(!0),g()};return window.addEventListener(`pibo:web-annotation-saved`,e),()=>window.removeEventListener(`pibo:web-annotation-saved`,e)},[g]);let y=(0,R.useCallback)(t=>{i(n=>{let r=t(n);return e&&j2(e,r),r})},[e]),b=(0,R.useCallback)(e=>{y(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].slice(0,5))},[y]),x=(0,R.useCallback)(()=>y(()=>[]),[y]);return{selectedWebAnnotationIds:r,selectedWebAnnotations:v,visibleWebAnnotations:_,webAnnotationsPanelCollapsed:l,webAnnotationsPanelRendered:m,webAnnotationsPanelVisible:a,webAnnotationsQuery:h,clearingWebAnnotations:d,setWebAnnotationsPanelVisible:o,toggleWebAnnotationAttachment:b,detachWebAnnotationAttachment:(0,R.useCallback)(e=>{y(t=>t.filter(t=>t!==e))},[y]),clearSelectedWebAnnotationAttachments:x,toggleWebAnnotationsPanelCollapsed:(0,R.useCallback)(()=>{u(e=>{let t=!e;return jke(t),t})},[]),clearVisibleWebAnnotations:(0,R.useCallback)(async()=>{if(!(!_.length||d)&&window.confirm(`Dismiss ${_.length} visible web annotations? This keeps sent messages but clears the annotation list.`)){f(!0);try{await Promise.all(_.map(e=>Cke(e.id,{piboSessionId:e.piboSessionId,status:`dismissed`,summary:`Cleared from Chat Web UI`}))),x(),await g()}catch(e){t(n(e,`Could not clear web annotations`))}finally{f(!1)}}},[d,x,n,t,g,_])}}function Z4(e){return e.session?.profile??e.agents[0]?.name??e.customAgents[0]?.profileName??``}function Tje(e){return e?.identity??{userId:`user`}}function Q4(e,t){let n=Dje(e,t);return n?Eje(n):void 0}function $4(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=$4(n.children,t);if(e)return e}}function e3(e,t,n=[]){for(let r of e){let e=[...n,r];if(r.piboSessionId===t)return e;let i=e3(r.children,t,e);if(i.length)return i}return[]}function t3(){let e=globalThis.crypto?.randomUUID?.()??Math.random().toString(36).slice(2);return`web-${Date.now().toString(36)}-${e}`}function Eje(e){return`${e.provider}/${e.id}`}function Dje(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}function Oje(e,t){return t?{sessionBreadcrumbs:Nje(e,t),originSession:jje(e,t),derivedSessions:Mje(e,t)}:{sessionBreadcrumbs:[],originSession:void 0,derivedSessions:[]}}function kje(e){let t=e.selectedPiboSessionId?$4(e.bootstrap.sessions,e.selectedPiboSessionId):void 0,n=Lje(e.currentTraceView);return Ije(e.selectedSessionActiveModel,e.bootstrap.runtimeStatus?.thinkingLevel??n.level??Pje(e.bootstrap,e.selectedSessionProfile,!!t?.parentId),e.bootstrap.runtimeStatus?.fastMode??n.fast??Fje(e.bootstrap,e.selectedSessionProfile,!!t?.parentId)??!1)}function Aje(e){return{traceView:e.currentTraceView,selectedTrace:null,isLoading:e.isLoading,showThinking:e.showThinking,expandThinking:e.expandThinking,sessionAgentProfile:e.selectedSessionProfile,sessionActiveModel:e.sessionActiveModelBadge,selectedSessionStatus:e.selectedSessionStatus,selectedSessionSignal:e.selectedSessionSignal,workflowProjectSession:e.workflowProjectSession,workflowLifecycleEvents:e.workflowLifecycleEvents,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,onThinkingLevelChange:e.onThinkingLevelChange,onModelChanged:async()=>{await e.onRefreshBootstrap(),await e.onRefreshTrace()},onRefreshBootstrap:e.onRefreshBootstrap,onError:e.onError}}function jje(e,t){let n=$4(e,t);if(!n?.originId)return;let r=$4(e,n.originId);return{piboSessionId:n.originId,label:r?r3(r,0):n.originId}}function Mje(e,t){return $4(e,t)?.derivedSessions.map(e=>({piboSessionId:e.piboSessionId,label:zje(e),profile:e.profile,status:e.status}))??[]}function Nje(e,t){return e3(e,t).map((e,t)=>({piboSessionId:e.piboSessionId,label:r3(e,t)}))}function Pje(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 Fje(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 Ije(e,t,n){if(e)return[e,t,n?`fast`:void 0].filter(Boolean).join(` `)}function Lje(e){let t={};if(!e)return t;for(let n of n3(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`&&Rje(e.level)?e.level:void 0)??t.level,fast:n.title===`fast_mode`?e?.mode===`fast`:t.fast}}return t}function n3(e){return e.flatMap(e=>[e,...n3(e.children)])}function Rje(e){return Xq.includes(e)}function r3(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 zje(e){return e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.title||e.profile||e.subagentName||`Untitled Session`}function Bje({piboSessionId:e,text:t,selectedWebAnnotations:n,selectedUploadAttachments:r,eventSequence:i,now:a,clientTxnId:o}){let s=n.map(e=>e.id),c=r.map(e=>e.path);return{text:t,webAnnotationIds:s,fileAttachmentPaths:c,clientTxnId:o,optimisticEvent:{id:o,piboSessionId:e,eventSequence:i,eventId:o,type:`message_queued`,createdAt:a,payload:{type:`message_queued`,piboSessionId:e,eventId:o,clientTxnId:o,queuedMessages:1,text:t,...c.length?{fileAttachmentPaths:c}:{},source:`user`}}}}function Vje(e,t,n){return{piboSessionId:t,events:[...e?.piboSessionId===t?e.events:[],n]}}function i3(e){return e instanceof Error?e.message:String(e)}function a3({bootstrap:e,selectedPiboSessionId:t,selectedRoomId:n,selectedRoomArchived:r,selectedSessionProfile:i,selectedSessionActiveModel:a,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,projectSessionCreatePanel:u,workflowStartPanel:d,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,creatingSession:g,showRawEvents:_,showThinking:v,expandThinking:y,commands:b,skills:x,composerText:S,composerFocusSignal:C,onComposerTextChange:w,onToggleRawEvents:T,onToggleThinking:E,onToggleExpandThinking:D,onSessionAgentProfileChange:O,onFork:k,onOpenSession:A,onSelectSessionView:j,onCommand:M,onThinkingLevelChange:N,onRefreshTrace:P,onRefreshBootstrap:F,onSend:ee,onError:te}){let I=(0,R.useRef)(0),[ne,L]=(0,R.useState)(null),{baseTraceView:re,traceEventLimit:ie,rawEventLimit:ae,traceSummaryQuery:oe,tracePageQuery:se,tracePageReady:ce,loadOlderTracePage:le,loadMoreRawEvents:ue}=lje({selectedPiboSessionId:t,showRawEvents:_,setLiveTraceOverlay:L}),{selectedWebAnnotationIds:de,selectedWebAnnotations:fe,visibleWebAnnotations:pe,webAnnotationsPanelCollapsed:me,webAnnotationsPanelRendered:he,webAnnotationsPanelVisible:ge,webAnnotationsQuery:_e,clearingWebAnnotations:ve,setWebAnnotationsPanelVisible:ye,toggleWebAnnotationAttachment:be,detachWebAnnotationAttachment:xe,clearSelectedWebAnnotationAttachments:Se,toggleWebAnnotationsPanelCollapsed:Ce,clearVisibleWebAnnotations:we}=wje({selectedPiboSessionId:t,onError:te,formatError:N2}),{selectedUploadAttachments:Te,attachUploadedFiles:Ee,detachUploadAttachment:De,clearSelectedUploadAttachments:Oe}=Cje(t,(0,R.useCallback)(()=>`upload-${t3()}`,[])),ke=eje({selectedPiboSessionId:t,baseTraceView:re,liveTraceOverlay:ne,selectedSessionStatus:o});vje({selectedPiboSessionId:t,tracePageData:se.data,currentTraceView:ke,liveEventSeqRef:I,selectedSessionStatus:o,tracePageReady:ce,setLiveTraceOverlay:L,onRefreshTrace:P,onRefreshBootstrap:F,onError:te});let Ae=kje({bootstrap:e,selectedPiboSessionId:t,selectedSessionProfile:i,selectedSessionActiveModel:a,currentTraceView:ke}),je=(0,R.useMemo)(()=>Oje(e.sessions,t),[e.sessions,t]),Me=!!t&&se.isFetching&&!ke,Ne=se.error?i3(se.error):oe.error?i3(oe.error):null,Pe=ke?.piboSessionId??t??``,Fe=c&&R2(c)?Kke(c,o):null,Ie=async e=>{if(!t)return;let n=Bje({piboSessionId:t,text:e,selectedWebAnnotations:fe,selectedUploadAttachments:Te,eventSequence:I.current++,now:new Date().toISOString(),clientTxnId:t3()});L(e=>Vje(e,t,n.optimisticEvent)),await ee(n.text,n.webAnnotationIds,n.fileAttachmentPaths,n.clientTxnId),Se(),Oe(),await Promise.all([se.refetch(),_e.refetch()])},Le=Aje({currentTraceView:ke,isLoading:Me,showThinking:v,expandThinking:y,selectedSessionProfile:i,sessionActiveModelBadge:Ae,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,sessionNodes:e.sessions,sessionLinks:je,agentProfiles:e.agents,sessionProfileChangeDisabled:g||r,onSessionAgentProfileChange:O,onFork:k,onOpenSession:A,onThinkingLevelChange:N,onRefreshTrace:P,onRefreshBootstrap:F,onError:te});return(0,z.jsx)(eAe,{selectedPiboSessionId:t,selectedRoomId:n,fallbackRoomId:e.selectedRoomId??void 0,sessionViewId:f,loadingTrace:Me,traceError:Ne,showRawEvents:_,currentTraceView:ke,traceEventLimit:ie,rawEventLimit:ae,tracePageFetching:se.isFetching,onLoadOlderTracePage:e=>void le(e),onLoadMoreRawEvents:ue,headerProps:{title:ke?.title??t??e.room?.name??n,roomLabel:e.room?.name??n??`Room`,headerPiboSessionId:Pe,piboSessionId:t,piboRoomId:n??e.selectedRoomId??void 0,webAnnotationsDisabled:!t||r,webAnnotationsPanelRendered:he,workflowHeader:Fe,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,showRawEvents:_,showThinking:v,expandThinking:y,onShowWebAnnotationsPanel:()=>ye(!0),onHideWebAnnotationsPanel:()=>ye(!1),onSelectSessionView:j,onToggleRawEvents:T,onToggleThinking:E,onToggleExpandThinking:D,onError:te},projectSessionCreatePanel:u,workflowStartPanel:d,currentSessionView:m,sessionViewProps:Le,webAnnotationsPanelRendered:he,webAnnotationsPanelProps:{piboSessionId:t,annotations:pe,selectedIds:de,loading:_e.isLoading||_e.isFetching||ve,error:_e.error?i3(_e.error):null,collapsed:me,onRefresh:()=>void _e.refetch(),onToggle:be,onClear:()=>void we(),onCollapse:Ce,onClose:()=>ye(!1)},composerProps:{sessionId:t,disabled:!t||r,commands:b,skills:x,value:S,focusSignal:C,selectedWebAnnotations:fe,selectedUploadAttachments:Te,onValueChange:w,onCommand:M,onDetachWebAnnotation:xe,onClearWebAnnotations:Se,onAttachUploadedFiles:Ee,onDetachUploadAttachment:De,onClearUploadAttachments:Oe,onSend:Ie}})}var o3=3e3;function Hje(e){return`${e.name||`Untitled Room`}\n${e.id}`}function Uje(e){return`${s3(e)}\n${e.piboSessionId}`}function s3(e){return typeof e.title==`string`&&e.title?e.title:`Untitled Session`}function Wje(e,t){let n=`session-signal h-2 w-2 rounded-full`;return e.status===`error`?{className:`${n} session-signal-error`,title:(e.unreadCount??0)>0?`Run failed`:`Run failed (read)`}:e.status===`running`?{className:`${n} session-signal-running`,title:`Runtime is working`}:(e.unreadCount??0)>0||Gje(e,t)?{className:`${n} session-signal-unread`,title:`New completed assistant message`}:{className:`${n} session-signal-idle`,title:`Idle`}}function Gje(e,t){if(!e.lastActivityAt)return!1;let n=Date.parse(e.lastActivityAt);return Number.isFinite(n)&&t-n<o3}function Kje(e,t){let n,r=e=>{if(e.status!==`running`&&e.status!==`error`&&(e.unreadCount??0)===0&&e.lastActivityAt){let r=Date.parse(e.lastActivityAt);if(Number.isFinite(r)){let e=o3-(t-r);e>0&&(n=n===void 0?e:Math.min(n,e))}}for(let t of e.children)r(t)};for(let t of e)r(t);return n===void 0?void 0:n+50}function c3(e,t){return e.some(e=>e.piboSessionId===t||c3(e.children,t))}function l3(e,t=!0){let n=[],r=[];for(let i of e){if(i.archived){t&&r.push(i);continue}let e=l3(i.children,t);n.push({...i,children:e.active}),t&&r.push(...e.archived)}return{active:n,archived:r}}function qje(e,t,n){if(e.length<=t)return e;let r=e.slice(0,t);if(!n)return r;let i=e.find(e=>e.piboSessionId===n||c3(e.children,n));return!i||r.some(e=>e.piboSessionId===i.piboSessionId)?r:[...r,i]}function u3(e){for(let t of e){if(p3(t))return t;let e=u3(t.children??[]);if(e)return e}}function d3(e,t){for(let n of e){if(n.id===t)return n;let e=d3(n.children??[],t);if(e)return e}}function Jje(e){return e.reduce((e,t)=>e+(t.unreadCount??0),0)}function f3(e){let t=[],n=[];for(let r of e){if(p3(r)){let e=f3(r.children??[]);t.push(...e.active),n.push(...e.archived);continue}if(m3(r)){n.push(r);continue}let e=f3(r.children??[]);t.push({...r,children:e.active}),n.push(...e.archived)}return{active:t,archived:n}}function p3(e){return e.metadata.default===!0}function m3(e){return typeof e.metadata.chatRoomArchivedAt==`string`}function Yje(e){return e.topic&&e.workspace?`${e.topic} | ${e.workspace}`:e.topic?e.topic:e.workspace?e.workspace:e.type}function h3({node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:s,onViewContext:c,depth:l=0,loadingPiboSessionId:u,autoRename:d=!1,onAutoRenameConsumed:f,showWorkflowSessionKindMarkers:p=!1}){let m=s3(e),h=Uje(e),[g,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(m),b=(0,R.useRef)(null),x=e.children.length>0,S=n!==null&&e.piboSessionId!==n&&r.has(e.piboSessionId),[C,w]=(0,R.useState)(S),[T,E]=(0,R.useState)(!1),D=(0,R.useRef)(null);(0,R.useEffect)(()=>{if(!T)return;let e=e=>{D.current&&!D.current.contains(e.target)&&E(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[T]),(0,R.useEffect)(()=>{g||y(m)},[g,m]),(0,R.useEffect)(()=>{d&&(y(m===`Untitled Session`?``:m),_(!0),f?.())},[d,m,f]),(0,R.useLayoutEffect)(()=>{g&&(b.current?.focus(),b.current?.select())},[g]),(0,R.useEffect)(()=>{S&&w(!0)},[S]);let O=()=>{let t=v.trim();a(e.piboSessionId,t||null),_(!1)},k=Wje(e,t),A=u===e.piboSessionId,j=p?Xje(e.workflowSessionKind):null,M=j?.Icon;return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{"data-pibo-component":`SessionNode`,"data-pibo-debug":`session-row`,"data-pibo-session-id":e.piboSessionId,"data-pibo-title":m,"data-pibo-selected":e.piboSessionId===n?`true`:`false`,"data-pibo-state":A?`loading`:e.status??`idle`,"data-pibo-archived":e.archived?`true`:`false`,"data-pibo-unread-count":e.unreadCount??0,className:`group w-full grid grid-cols-[1fr_auto] gap-1 items-center mb-1 border rounded-sm ${e.piboSessionId===n?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-transparent`}`,style:{paddingLeft:8+l*14},title:h,children:[g?(0,z.jsxs)(`form`,{className:`min-w-0 grid grid-cols-[1fr_auto_auto] gap-1 py-1 pr-1`,onSubmit:e=>{e.preventDefault(),O()},children:[(0,z.jsx)(`input`,{ref:b,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),_(!1),y(m))},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,z.jsx)(`button`,{type:`submit`,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,z.jsx)(Ro,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>{_(!1),y(m)},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,z.jsx)(Qs,{size:13})})]}):(0,z.jsxs)(`div`,{className:`min-w-0 grid grid-cols-[1fr_auto] gap-2 items-center py-1 pr-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>{if(x&&e.piboSessionId===n){w(e=>!e);return}i(e.piboSessionId)},"aria-label":j?`${j.ariaLabel}: ${m}`:`Open session ${m}`,className:`min-w-0 text-left px-1 py-1 grid grid-cols-[minmax(0,1fr)_auto] gap-2 items-center`,children:(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[j&&M?(0,z.jsx)(`span`,{className:`h-4 w-4 shrink-0 inline-flex items-center justify-center rounded-sm border ${j.className}`,title:j.ariaLabel,"aria-label":j.ariaLabel,children:(0,z.jsx)(M,{size:11,"aria-hidden":`true`})}):null,(0,z.jsx)(`span`,{className:`block min-w-0 truncate text-sm ${e.archived?`text-slate-500`:`text-slate-200`}`,children:m})]}),(0,z.jsxs)(`span`,{className:`mt-0.5 flex min-w-0 items-center gap-1.5`,children:[j?(0,z.jsx)(`span`,{className:`shrink-0 rounded-sm border px-1 py-0.5 text-[9px] font-bold uppercase tracking-wide ${j.className}`,title:j.ariaLabel,children:j.label}):null,(0,z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-slate-500`,children:e.piboSessionId})]})]})}),(0,z.jsxs)(`span`,{className:`grid grid-rows-[16px_16px] place-items-center gap-0.5`,children:[A?(0,z.jsx)(Cs,{size:13,className:`text-[#11a4d4] animate-spin`,"aria-label":`Loading session`}):(0,z.jsx)(`span`,{className:k.className,title:k.title,"aria-label":k.title}),x?(0,z.jsx)(`button`,{type:`button`,onClick:()=>w(e=>!e),"aria-expanded":C,title:C?`Collapse Subsessions`:`Expand Subsessions`,"aria-label":C?`Collapse Subsessions`:`Expand Subsessions`,className:`h-4 w-4 inline-flex items-center justify-center rounded-sm transition-colors ${C?`text-[#0bda57]`:`text-slate-600 hover:text-[#11a4d4]`}`,children:(0,z.jsx)(vs,{size:13})}):(0,z.jsx)(`span`,{className:`h-4 w-4`})]})]}),g?null:(0,z.jsx)(`div`,{className:`flex items-center gap-1 pr-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,children:(0,z.jsxs)(`div`,{className:`relative`,ref:D,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>E(e=>!e),title:`Session actions`,"aria-label":`Session actions`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(ns,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}),T&&(0,z.jsx)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-48 bg-[#1a262b] border border-slate-700 rounded-sm shadow-lg py-1`,children:e.archived?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),o(e.piboSessionId,!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(wo,{size:16}),` Restore Session`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),c(e.piboSessionId)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Fo,{size:16}),` View Context`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),s(e)},className:`w-full text-left px-3 py-2.5 text-sm text-red-300 hover:bg-red-500/10 flex items-center gap-2`,children:[(0,z.jsx)(qs,{size:16}),` Delete Session`]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),_(!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Ms,{size:16}),` Rename Session`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),o(e.piboSessionId,!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(To,{size:16}),` Archive Session`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),c(e.piboSessionId)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Fo,{size:16}),` View Context`]})]})})]})})]}),C?e.children.map(e=>(0,z.jsx)(h3,{node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:s,onViewContext:c,depth:l+1,loadingPiboSessionId:u,showWorkflowSessionKindMarkers:p},e.piboSessionId)):null]})}function Xje(e){switch(e){case`main_workflow`:return{label:`main workflow`,ariaLabel:`Main workflow session`,className:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,Icon:vs};case`nested_workflow`:return{label:`nested workflow`,ariaLabel:`Nested workflow session`,className:`border-violet-400/40 bg-violet-500/10 text-violet-300`,Icon:$o};case`agent_node`:return{label:`agent node`,ariaLabel:`Workflow agent node session`,className:`border-emerald-400/40 bg-emerald-500/10 text-emerald-300`,Icon:Ys};case`subagent`:return{label:`subagent`,ariaLabel:`Subagent session`,className:`border-amber-400/40 bg-amber-500/10 text-amber-300`,Icon:Xs};default:return null}}var Zje=`240px 0px`,g3=192,_3=4,v3=8;function Qje(e){return e>99?`99+`:String(e)}function $je({count:e}){return!e||e<=0?null:(0,z.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:Qje(e)})}function eMe({bootstrap:e,selectedRoomId:t,selectedPiboSessionId:n,showArchivedRooms:r,onToggleArchivedRooms:i,creatingRoom:a,onCreateRoom:o,onSelectRoom:s,onUpdateRoom:c,onArchiveRoom:l,onReadAllRoom:u,onDeleteRoom:d,newSessionProfile:f,onNewSessionProfileChange:p,selectedRoomArchived:m,creatingSession:h,onCreateSession:g,showArchived:_,onToggleArchivedSessions:v,loadingArchivedSessions:y,visibleActiveSessions:b,visibleArchivedSessions:x,totalActiveSessionCount:S,totalArchivedSessionCount:C,hasMoreActiveSessions:w,hasMoreArchivedSessions:T,loadingActiveSessions:E,sessionListScrollRef:D,onLoadMoreSessions:O,signalNow:k,selectedSessionPathIds:A,onSelectSession:j,onRenameSession:M,onArchiveSession:N,onDeleteSession:P,onViewContext:F,loadingPiboSessionId:ee,autoRenameSessionId:te,onAutoRenameConsumed:I}){let ne=!!(e.selectedRoomId||e.room||e.rooms.length),L=e.agents,re=u3(e.rooms),ie=f3(e.rooms);return(0,z.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":_?`archived-visible`:`active-only`,className:`min-h-0 flex-1 overflow-hidden p-2 flex flex-col gap-3`,children:[ne?(0,z.jsxs)(z.Fragment,{children:[re?(0,z.jsxs)(`div`,{className:`shrink-0`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Shared Chat`}),(0,z.jsx)(b3,{room:re,selectedRoomId:t,onSelect:e=>void s(e),onUpdate:(e,t)=>void c(e,t),onArchive:(e,t)=>void l(e,t),onReadAll:e=>void u(e),onDelete:d})]}):null,(0,z.jsxs)(`div`,{className:`min-h-0 flex-1 basis-0 overflow-hidden flex flex-col`,children:[(0,z.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Rooms`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.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,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:i,title:r?`Hide Archived Rooms`:`Show Archived Rooms`,"aria-label":r?`Hide Archived Rooms`:`Show Archived Rooms`,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,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),(0,z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pr-1`,children:[ie.active.map(e=>(0,z.jsx)(b3,{room:e,selectedRoomId:t,onSelect:e=>void s(e),onUpdate:(e,t)=>void c(e,t),onArchive:(e,t)=>void l(e,t),onReadAll:e=>void u(e),onDelete:d},e.id)),ie.active.length===0?(0,z.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,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Rooms`}),ie.archived.length?(0,z.jsx)(tMe,{rooms:ie.archived,selectedRoomId:t,onSelect:e=>void s(e),onUpdate:(e,t)=>void c(e,t),onArchive:(e,t)=>void l(e,t),onReadAll:e=>void u(e),onDelete:d}):(0,z.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,z.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,z.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Sessions`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),disabled:!L.length||m,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:L.map(e=>(0,z.jsx)(`option`,{value:e.name,title:e.description??e.name,children:e.name},e.name))}),(0,z.jsx)(`button`,{"data-pibo-debug":`new-session-button`,"data-pibo-room-id":t??e.selectedRoomId??void 0,"data-pibo-state":h?`creating`:m?`archived-disabled`:`ready`,type:`button`,onClick:()=>void g(),disabled:h||m,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,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void v(),disabled:y,title:_?`Hide Archived Sessions`:`Show Archived Sessions`,"aria-label":_?`Hide Archived Sessions`:`Show Archived Sessions`,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 ${_?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:y?(0,z.jsx)(Cs,{size:14,className:`animate-spin`}):_?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),(0,z.jsxs)(`div`,{ref:D,className:`min-h-0 flex-1 overflow-y-auto pr-1`,children:[b.map(e=>(0,z.jsx)(h3,{node:e,signalNow:k,selectedPiboSessionId:n,selectedSessionPathIds:A,onSelect:e=>void j(e),onRename:(e,t)=>void M(e,t),onArchive:(e,t)=>void N(e,t),onDelete:P,onViewContext:F,loadingPiboSessionId:ee,autoRename:te===e.piboSessionId,onAutoRenameConsumed:()=>I()},e.piboSessionId)),S===0?(0,z.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,w?(0,z.jsx)(y3,{debugName:`active-session-load-more`,loading:E,rootRef:D,onLoadMore:()=>O(!1),children:E?`Loading active sessions…`:`Load more active sessions (${b.length} of ${S})`}):null,_?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.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,z.jsx)(`span`,{children:`Archived Sessions`}),y?(0,z.jsx)(Cs,{size:12,className:`text-[#11a4d4] animate-spin`,"aria-label":`Loading archived sessions`}):null]}),y?(0,z.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,z.jsx)(Cs,{size:13,className:`text-[#11a4d4] animate-spin`}),` Loading archived sessions`]}):C?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(nMe,{sessions:x,signalNow:k,selectedPiboSessionId:n,selectedSessionPathIds:A,onSelect:e=>void j(e),onRename:(e,t)=>void M(e,t),onArchive:(e,t)=>void N(e,t),onDelete:P,onViewContext:F,loadingPiboSessionId:ee,autoRenameSessionId:te,onAutoRenameConsumed:()=>I()}),T?(0,z.jsx)(y3,{debugName:`archived-session-load-more`,loading:y,rootRef:D,onLoadMore:()=>O(!0),children:y?`Loading archived sessions…`:`Load more archived sessions (${x.length} of ${C})`}):null]}):(0,z.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 tMe({rooms:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o}){return(0,z.jsx)(`div`,{children:e.map(e=>(0,z.jsx)(b3,{room:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o},e.id))})}function y3({children:e,debugName:t,loading:n,rootRef:r,onLoadMore:i}){let a=(0,R.useRef)(null),o=(0,R.useRef)(i),s=(0,R.useRef)(!1);(0,R.useEffect)(()=>{o.current=i},[i]),(0,R.useEffect)(()=>{n||(s.current=!1)},[n]);let c=(0,R.useCallback)(()=>{s.current||n||(s.current=!0,Promise.resolve(o.current()).finally(()=>{s.current=!1}))},[n]);return(0,R.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:Zje,threshold:0});return t.observe(e),()=>t.disconnect()},[n,r,c]),(0,z.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 nMe({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,z.jsx)(`div`,{children:e.map(e=>(0,z.jsx)(h3,{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 b3({room:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o,depth:s=0}){let[c,l]=(0,R.useState)(!1),[u,d]=(0,R.useState)(e.name),[f,p]=(0,R.useState)(e.topic??``),[m,h]=(0,R.useState)(e.workspace??``),g=p3(e),_=m3(e),[v,y]=(0,R.useState)(!1),[b,x]=(0,R.useState)(null),S=(0,R.useRef)(null),C=(0,R.useRef)(null),w=Hje(e),T=()=>{u2(e.id).catch(()=>void 0)},E=(0,R.useCallback)(()=>{let e=S.current;if(!e)return;let t=e.getBoundingClientRect(),n=C.current?.offsetWidth??g3,r=_?144:192,i=C.current?.offsetHeight??r,a=Math.max(v3,window.innerWidth-n-v3),o=Math.min(Math.max(v3,t.right-n),a),s=t.bottom+_3,c=s+i<=window.innerHeight-v3?s:Math.max(v3,t.top-_3-i);x(e=>e?.top===c&&e.left===o?e:{top:c,left:o})},[_]);(0,R.useEffect)(()=>{if(!v){x(null);return}E();let e=()=>E();return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[v,E]),(0,R.useLayoutEffect)(()=>{v&&b&&E()},[v,b,E]),(0,R.useEffect)(()=>{if(!v)return;let e=e=>{let t=e.target;S.current?.contains(t)||C.current?.contains(t)||y(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]),(0,R.useEffect)(()=>{c||(d(e.name),p(e.topic??``),h(e.workspace??``))},[c,e.name,e.topic,e.workspace]);let D=()=>{let t=u.trim();t&&(r(e.id,{name:t,topic:f.trim()||null,workspace:m.trim()||null}),l(!1))};return(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`group mb-1 border rounded-sm ${g?e.id===t?`border-[#0bda57] bg-[#0bda57]/10`:`border-[#0bda57]/50 bg-[#0bda57]/5`:e.id===t?`border-[#11a4d4] bg-[#11a4d4]/10`:_?`border-[#f59e0b]/40 bg-[#f59e0b]/5`:`border-transparent`}`,style:{marginLeft:s*12},title:w,children:c&&!g?(0,z.jsxs)(`form`,{className:`grid gap-1 p-1`,onSubmit:e=>{e.preventDefault(),D()},children:[(0,z.jsx)(`input`,{value:u,onChange:e=>d(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,z.jsx)(`input`,{value:f,onChange:e=>p(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,z.jsx)(`input`,{value:m,onChange:e=>h(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,z.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,z.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,z.jsx)(Ro,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>l(!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,z.jsx)(Qs,{size:13})})]})]}):(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-center gap-1 py-1 pr-1`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`min-w-0 text-left px-2 py-1 grid grid-cols-[auto_minmax(0,1fr)_auto] gap-2 items-center`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 inline-flex items-center justify-center rounded-sm ${g?`bg-[#0bda57]/15 text-[#0bda57]`:_?`bg-[#f59e0b]/15 text-[#f59e0b]`:`bg-[#151f24] text-slate-500`}`,children:g?(0,z.jsx)(Ts,{size:13}):_?(0,z.jsx)(To,{size:13}):(0,z.jsx)(ls,{size:13})}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block text-sm truncate ${_?`text-slate-500`:`text-slate-200`}`,children:e.name}),(0,z.jsx)(`span`,{className:`block text-[10px] font-mono truncate text-slate-500`,children:g?`shared default room`:_?`archived`:Yje(e)})]}),(0,z.jsx)($je,{count:e.unreadCount})]}),(0,z.jsx)(`div`,{className:`flex items-center gap-1 pr-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,children:g?(0,z.jsx)(`span`,{title:`Shared Chat is locked`,"aria-label":`Shared Chat is locked`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-[#0bda57]/50 rounded-sm text-[#0bda57]`,children:(0,z.jsx)(Ts,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}):(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`button`,{ref:S,type:`button`,onClick:()=>y(e=>!e),title:`Room actions`,"aria-label":`Room actions`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(ns,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}),v&&b?(0,Na.createPortal)((0,z.jsx)(`div`,{ref:C,className:`fixed z-[1000] bg-[#1a262b] border border-slate-700 rounded-sm shadow-lg py-1`,style:{top:b.top,left:b.left,width:g3},children:_?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{T(),y(!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)($o,{size:16}),` Copy Room ID`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),i(e.id,!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(wo,{size:16}),` Restore Room`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),o(e)},className:`w-full text-left px-3 py-2.5 text-sm text-red-300 hover:bg-red-500/10 flex items-center gap-2`,children:[(0,z.jsx)(qs,{size:16}),` Delete Room`]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{T(),y(!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)($o,{size:16}),` Copy Room ID`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),l(!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Ms,{size:16}),` Edit Room`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),a(e.id)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Lo,{size:16}),` Read All`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),i(e.id,!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(To,{size:16}),` Archive Room`]})]})}),document.body):null]})})]})}),(e.children??[]).map(e=>(0,z.jsx)(b3,{room:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o,depth:s+1},e.id))]})}var x3=0,S3=1,C3=2,w3=4;function rMe(e){return()=>e}function iMe(e){e()}function T3(e,t){return n=>e(t(n))}function aMe(e,t){return()=>e(t)}function oMe(e,t){return n=>e(t,n)}function E3(e){return e!==void 0}function sMe(...e){return()=>{e.map(iMe)}}function D3(){}function O3(e,t){return t(e),e}function cMe(e,t){return t(e)}function k3(...e){return e}function A3(e,t){return e(S3,t)}function j3(e,t){e(x3,t)}function M3(e){e(C3)}function N3(e){return e(w3)}function P3(e,t){return A3(e,oMe(t,x3))}function F3(e,t){let n=e(S3,e=>{n(),t(e)});return n}function I3(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function L3(e,t){return e===t}function R3(e=L3){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function z3(e){return t=>n=>{e(n)&&t(n)}}function B3(e){return t=>T3(t,e)}function V3(e){return t=>()=>{t(e)}}function Q(e,...t){let n=lMe(...t);return((t,r)=>{switch(t){case C3:M3(e);return;case S3:return A3(e,n(r))}})}function H3(e,t){return n=>r=>{n(t=e(t,r))}}function U3(e){return t=>n=>{e>0?e--:t(n)}}function W3(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function G3(...e){let t=Array(e.length),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;A3(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 lMe(...e){return t=>e.reduceRight(cMe,t)}function uMe(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case S3:return a?n===a?void 0:(r(),n=a,t=A3(e,a),t):(r(),D3);case C3:r(),n=null;return}}}function $(e){let t=e,n=q3();return((e,r)=>{switch(e){case x3:t=r;break;case S3:r(t);break;case w3:return t}return n(e,r)})}function K3(e,t){return O3($(t),t=>P3(e,t))}function q3(){let e=[];return((t,n)=>{switch(t){case x3:e.slice().forEach(e=>{e(n)});return;case C3:e.splice(0,e.length);return;case S3:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function J3(e){return O3(q3(),t=>P3(e,t))}function Y3(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:dMe(),singleton:n}}var dMe=()=>Symbol();function fMe(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 X3(...e){let t=q3(),n=Array(e.length),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;A3(e,e=>{n[a]=e,r|=o,r===i&&j3(t,n)})}),function(e,a){switch(e){case C3:M3(t);return;case S3:return r===i&&a(n),A3(t,a)}}}function Z3(e,t=L3){return Q(e,R3(t))}function Q3(...e){return function(t,n){switch(t){case C3:return;case S3:return sMe(...e.map(e=>A3(e,n)))}}}var $3={DEBUG:0,INFO:1,WARN:2,ERROR:3},pMe={[$3.DEBUG]:`debug`,[$3.ERROR]:`error`,[$3.INFO]:`log`,[$3.WARN]:`warn`},mMe=()=>typeof globalThis>`u`?window:globalThis,e6=Y3(()=>{let e=$($3.ERROR);return{log:$((t,n,r=$3.INFO)=>{r>=(mMe().VIRTUOSO_LOG_LEVEL??N3(e))&&console[pMe[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0});function t6(e,t,n){return n6(e,t,n).callbackRef}function n6(e,t,n){let r=R.useRef(null),i=e=>{},a=R.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 r6(e,t,n,r,i,a,o,s,c){return n6(R.useCallback(n=>{let c=hMe(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.scrollLeft:o.scrollTop:u?s?d.scrollX||d.document.documentElement.scrollLeft:d.scrollY||d.document.documentElement.scrollTop:s?l.scrollLeft:l.scrollTop,p=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,m=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight;r({scrollHeight:p,scrollTop:Math.max(f,0),viewportHeight:m}),a?.(s?i6(`column-gap`,getComputedStyle(n).columnGap,i):i6(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function hMe(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),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},$3.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 i6(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,$3.WARN),t===`normal`?0:parseInt(t??`0`,10)}function a6(e,t,n){let r=R.useRef(null),i=R.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}=n6(i,!0,n),s=R.useCallback(()=>{i(o.current)},[i,o]);return R.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 o6=Y3(()=>{let e=q3(),t=q3(),n=$(0),r=q3(),i=$(0),a=q3(),o=q3(),s=$(0),c=$(0),l=$(0),u=$(0),d=q3(),f=q3(),p=$(!1),m=$(!1),h=$(!1);return P3(Q(e,B3(({scrollTop:e})=>e)),t),P3(Q(e,B3(({scrollHeight:e})=>e)),o),P3(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}),s6={lvl:0};function c6(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 l6(e){return e===s6}function u6(e,t){if(!l6(e))return t===e.k?e.v:t<e.k?u6(e.l,t):u6(e.r,t)}function d6(e,t,n=`k`){if(l6(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=d6(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return d6(e.l,t,n)}function f6(e,t,n){return l6(e)?C6(t,n,1):t===e.k?y6(e,{k:t,v:n}):t<e.k?w6(y6(e,{l:f6(e.l,t,n)})):w6(y6(e,{r:f6(e.r,t,n)}))}function p6(){return s6}function m6(e,t,n){if(l6(e))return[];let r=d6(e,t)[0];return gMe(_6(e,r,n))}function h6(e,t){if(l6(e))return s6;let{k:n,l:r,r:i}=e;if(t===n){if(l6(r))return i;if(l6(i))return r;let[t,n]=S6(r);return v6(y6(e,{k:t,l:b6(r),v:n}))}return v6(t<n?y6(e,{l:h6(r,t)}):y6(e,{r:h6(i,t)}))}function g6(e){return l6(e)?[]:[...g6(e.l),{k:e.k,v:e.v},...g6(e.r)]}function _6(e,t,n){if(l6(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(_6(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(_6(a,t,n))),s}function v6(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(x6(t))return T6(y6(e,{lvl:n-1}));if(!l6(t)&&!l6(t.r))return y6(t.r,{l:y6(t,{r:t.r.l}),lvl:n,r:y6(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(x6(e))return E6(y6(e,{lvl:n-1}));if(!l6(r)&&!l6(r.l)){let t=r.l,i=x6(t)?r.lvl-1:r.lvl;return y6(t,{l:y6(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:E6(y6(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function y6(e,t){return C6(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 b6(e){return l6(e.r)?e.l:v6(y6(e,{r:b6(e.r)}))}function x6(e){return l6(e)||e.lvl>e.r.lvl}function S6(e){return l6(e.r)?[e.k,e.v]:S6(e.r)}function C6(e,t,n,r=s6,i=s6){return{k:e,l:r,lvl:n,r:i,v:t}}function w6(e){return E6(T6(e))}function T6(e){let{l:t}=e;return!l6(t)&&t.lvl===e.lvl?y6(t,{r:y6(e,{l:t.r})}):e}function E6(e){let{lvl:t,r:n}=e;return!l6(n)&&!l6(n.r)&&n.lvl===t&&n.r.lvl===t?y6(n,{l:y6(e,{r:n.l}),lvl:t+1}):e}function gMe(e){return c6(e,({k:e,v:t})=>({index:e,value:t}))}function D6(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function O6(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var k6=Y3(()=>({recalcInProgress:$(!1)}),[],{singleton:!0});function A6(e,t,n){return e[j6(e,t,n)]}function j6(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 _Me(e,t,n,r){let i=j6(e,t,r),a=j6(e,n,r,i);return e.slice(i,a+1)}function M6(e,t){return Math.round(e.getBoundingClientRect()[t])}function N6(e){return!l6(e.groupOffsetTree)}function P6({index:e},t){return t===e?0:t<e?-1:1}function vMe(){return{groupIndices:[],groupOffsetTree:p6(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:p6()}}function yMe(e,t){let n=l6(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),l6(e)){e=f6(e,0,i);continue}let o=m6(e,a-1,t+1);if(o.some(EMe(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=h6(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=f6(e,t+1,a));c&&(e=f6(e,a,i))}return[e,n]}function bMe(e){return typeof e.groupIndex<`u`}function xMe({offset:e},t){return t===e?0:t<e?-1:1}function F6(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=A6(t,e,P6),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function I6(e,t){if(!N6(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function L6(e,t,n){if(bMe(e))return t.groupIndices[e.groupIndex]+1;let r=I6(e.index===`LAST`?n:e.index,t);return r=Math.max(0,r,Math.min(n,r)),r}function SMe(e,t,n,r=0){return r>0&&(t=Math.max(t,A6(e,r,P6).offset)),c6(_Me(e,t,n,xMe),TMe)}function CMe(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,$3.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&l6(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>f6(f6(t,n,e),n+1,r),o)}else [o,s]=yMe(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=z6(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>f6(e,t,F6(t,d,i)),p6()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function wMe(e){return g6(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 R6(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 z6(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t!==0){c=j6(i,t-1,P6),s=i[c].offset;let e=d6(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===d6(n,t)[1]&&--c,i=i.slice(0,c+1)}else i=[];for(let{start:e,value:c}of m6(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 TMe(e){return{index:e.index,value:e}}function EMe(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 DMe={offsetHeight:`height`,offsetWidth:`width`},B6=Y3(([{log:e},{recalcInProgress:t}])=>{let n=q3(),r=q3(),i=K3(r,0),a=q3(),o=q3(),s=$(0),c=$([]),l=$(void 0),u=$(void 0),d=$(void 0),f=$(void 0),p=$((e,t)=>M6(e,DMe[t])),m=$(void 0),h=$(0),g=vMe(),_=K3(Q(n,G3(c,e,h),H3(CMe,g),R3()),g),v=K3(Q(c,R3(),H3((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),B3(({prev:e})=>e)),[]);P3(Q(c,z3(e=>e.length>0),G3(_,h),B3(([e,t,n])=>{let r=e.reduce((e,r,i)=>f6(e,r,F6(r,t.offsetTree,n)||i),p6());return{...t,groupIndices:e,groupOffsetTree:r}})),_),P3(Q(r,G3(_),z3(([e,{lastIndex:t}])=>e<t),B3(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),P3(l,u);let y=K3(Q(l,B3(e=>e===void 0)),!0);P3(Q(u,z3(e=>e!==void 0&&l6(N3(_).sizeTree)),B3(e=>{let t=N3(d),n=N3(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),P3(Q(f,z3(e=>e!==void 0&&e.length>0&&l6(N3(_).sizeTree)),B3(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),P3(Q(c,G3(d,u),z3(([,e,t])=>e!==void 0&&t!==void 0),B3(([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=J3(Q(n,G3(_),H3(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),B3(e=>e.changed)));A3(Q(s,H3((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),B3(e=>e.diff)),e=>{let{groupIndices:n}=N3(_);if(e>0)j3(t,!0),j3(a,e+R6(e,n));else if(e<0){let t=N3(v);t.length>0&&(e-=R6(-e,t)),j3(o,e)}}),A3(Q(s,G3(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},$3.ERROR)});let x=J3(a);P3(Q(a,G3(_),B3(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=u6(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=g6(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 g6(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=J3(Q(o,G3(_,h),B3(([e,{offsetTree:t},n])=>F6(-e,t,n))));return P3(Q(o,G3(_,h),B3(([e,t,n])=>{if(t.groupIndices.length>0){if(l6(t.sizeTree))return t;let r=p6(),i=N3(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=g6(t.sizeTree).reduce((t,{k:n,v:r})=>f6(t,Math.max(0,n+e),r),r),a!==-e){let n=u6(t.sizeTree,s);r=f6(r,0,n);let i=d6(t.sizeTree,-e+1)[1];r=f6(r,1,i)}return{...t,sizeTree:r,...z6(t.offsetTree,0,r,n)}}let r=g6(t.sizeTree).reduce((t,{k:n,v:r})=>f6(t,Math.max(0,n+e),r),p6());return{...t,sizeTree:r,...z6(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}},k3(e6,k6),{singleton:!0});function OMe(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var V6=Y3(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=q3(),o=q3(),s=J3(Q(a,B3(OMe)));return P3(Q(s,B3(e=>e.totalCount)),n),P3(Q(s,B3(e=>e.groupIndices)),e),P3(Q(X3(i,t,r),z3(([e,t])=>N6(t)),B3(([e,t,n])=>d6(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),R3(),B3(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},k3(B6,o6)),H6=Y3(([{log:e}])=>{let t=$(!1),n=J3(Q(t,z3(e=>e),R3()));return A3(t,t=>{t&&N3(e)(`props updated`,{},$3.DEBUG)}),{didMount:n,propsReady:t}},k3(e6),{singleton:!0}),kMe=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function U6(e){let t=typeof e==`number`?{index:e}:e;return t.align||=`start`,(!t.behavior||!kMe)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var W6=Y3(([{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=q3(),m=q3(),h=$(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),j3(c,!1)}return P3(Q(p,G3(n,d,r,h,s,o,f),G3(e,a,i),B3(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=U6(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=L6(b,n,w),E=F6(T,n.offsetTree,d)+o;x===`end`?(E+=f+d6(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+d6(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},$3.DEBUG),j3(p,e)):(j3(m,!0),l(`list did not change, scroll successful`,{},$3.DEBUG))};if(y(),S===`smooth`){let e=!1;v=A3(t,t=>{e||=t}),g=F3(u,()=>{D(e)})}else g=F3(Q(t,AMe(150)),D);return _=setTimeout(()=>{y()},1200),j3(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},$3.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},k3(B6,o6,e6),{singleton:!0});function AMe(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function G6(e,t){e===0?t():requestAnimationFrame(()=>{G6(e-1,t)})}function K6(e,t){let n=t-1;return typeof e==`number`?e:e.index===`LAST`?n:e.index}var q6=Y3(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=$(!0),c=$(0),l=$(!0);return P3(Q(o,G3(c),z3(([e,t])=>t!==0),V3(!1)),s),P3(Q(o,G3(c),z3(([e,t])=>t!==0),V3(!1)),l),A3(Q(X3(t,o),G3(s,n,e,l),z3(([[,e],t,{sizeTree:n},r,i])=>e&&(!l6(n)||E3(r))&&!t&&!i),G3(c)),([,e])=>{F3(i,()=>{j3(l,!0)}),G6(4,()=>{F3(r,()=>{j3(s,!0)}),j3(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},k3(B6,o6,W6,H6),{singleton:!0});function J6(e,t){return Math.abs(e-t)<1.01}var Y6=`up`,X6=`down`,jMe=`none`,MMe={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},NMe=0,Z6=Y3(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=$(!1),s=$(!0),c=q3(),l=q3(),u=$(4),d=$(NMe),f=K3(Q(Q3(Q(Z3(i),U3(1),V3(!0)),Q(Z3(i),U3(1),V3(!1),I3(100))),R3()),!1),p=K3(Q(Q3(Q(n,V3(!0)),Q(n,V3(!1),I3(200))),R3()),!1);P3(Q(X3(Z3(i),Z3(d)),B3(([e,t])=>e<=t),R3()),s),P3(Q(s,W3(50)),l);let m=J3(Q(X3(r,Z3(a),Z3(t),Z3(e),Z3(u)),H3((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}},MMe),R3((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=K3(Q(r,H3((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!J6(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}),z3(e=>e.changed),B3(e=>e.jump)),0);P3(Q(m,B3(e=>e.atBottom)),o),P3(Q(o,W3(50)),c);let g=$(X6);P3(Q(r,B3(({scrollTop:e})=>e),R3(),H3((e,t)=>N3(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?Y6:X6,prevScrollTop:t},{direction:X6,prevScrollTop:0}),B3(e=>e.direction)),g),P3(Q(r,W3(50),V3(jMe)),g);let _=$(0);return P3(Q(f,z3(e=>!e),V3(0)),_),P3(Q(i,W3(100),G3(f),z3(([e,t])=>t),H3(([e,t],[n])=>[t,n],[0,0]),B3(([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:_}},k3(o6)),Q6=`top`,$6=`bottom`,e8=`none`;function t8(e,t,n){return typeof e==`number`?n===Y6&&t===Q6||n===X6&&t===$6?e:0:n===Y6?t===Q6?e.main:e.reverse:t===$6?e.main:e.reverse}function n8(e,t){return typeof e==`number`?e:e[t]??0}var r8=Y3(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=q3(),o=$(0),s=$(0),c=$(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:K3(Q(X3(Z3(r),Z3(i),Z3(n),Z3(a,O6),Z3(c),Z3(o),Z3(t),Z3(e),Z3(s)),B3(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=e8,m=n8(l,Q6),h=n8(l,$6);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=Y6),i<e-f+t+h&&(p=X6),p===e8?null:[Math.max(u-n-t8(a,Q6,p)-m,0),u-f-s+t+t8(a,$6,p)+h]}),z3(e=>e!==null),R3(O6)),[0,0])}},k3(o6),{singleton:!0});function PMe(e,t,n){if(N6(t)){let r=I6(e,t);return[{index:d6(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 i8={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function a8(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:s8(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:s8(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function o8(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=K6(t,s);return a8(Array.from({length:s}).map((e,t)=>({data:a[t+c],index:t+c,offset:0,size:0})),[],s,i,n,r)}function s8(e,t,n){if(e.length===0)return[];if(!N6(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=m6(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 c8(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var l8=Y3(([{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=$([]),g=$(0),_=q3(),v=$(0);P3(a.topItemsIndexes,h);let y=K3(Q(X3(p,m,Z3(c,O6),Z3(i),Z3(r),Z3(l),u,Z3(h),Z3(t),Z3(n),Z3(v),e),z3(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),B3(([,,[e,t],n,r,i,a,o,s,c,l,u])=>{let d=r,{offsetTree:f,sizeTree:p}=d,m=N3(g);if(n===0)return{...i8,totalCount:n};if(e===0&&t===0)return m===0?{...i8,totalCount:n}:o8(m,i,r,s,c,u||[]);if(l6(p))return m>0?null:a8(PMe(K6(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 m6(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 a8([],h,n,c,d,s);let _=o.length>0?o[o.length-1]+1:0,v=SMe(f,e,t,_);if(v.length===0)return null;let y=n-1,b=O3([],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=c8(l,Q6),S=c8(l,$6);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=m6(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=m6(p,r,r)[0]?.value??t.size;b.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return a8(b,h,n,c,d,s)}),z3(e=>e!==null),R3()),i8);P3(Q(e,z3(E3),B3(e=>e?.length)),i),P3(Q(y,B3(e=>e.topListHeight)),d),P3(d,s),P3(Q(y,B3(e=>[e.top,e.bottom])),o),P3(Q(y,B3(e=>e.items)),_);let b=J3(Q(y,z3(({items:e})=>e.length>0),G3(i,e),z3(([{items:e},t])=>e[e.length-1].originalIndex===t-1),B3(([,e,t])=>[e-1,t]),R3(O6),B3(([e])=>e))),x=J3(Q(y,W3(200),z3(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),B3(({items:e})=>e[0].index),R3()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:J3(Q(y,z3(({items:e})=>e.length>0),B3(({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}}),R3(D6))),startReached:x,topItemsIndexes:h,...f}},k3(B6,V6,r8,q6,W6,Z6,H6,k6),{singleton:!0}),u8=Y3(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=q3(),o=K3(Q(X3(n,e,r,t,i),B3(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return P3(Z3(o),a),{totalListHeight:o,totalListHeightChanged:a}},k3(o6,l8),{singleton:!0}),FMe=Y3(([{viewportHeight:e},{totalListHeight:t}])=>{let n=$(!1);return{alignToBottom:n,paddingTopAddition:K3(Q(X3(n,e,t),z3(([e])=>e),B3(([,e,t])=>Math.max(0,e-t)),W3(0),R3()),0)}},k3(o6,u8),{singleton:!0}),d8=Y3(()=>({context:$(null)})),IMe=({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,f8=Y3(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=q3();return P3(Q(u,G3(t,c,n,a,i,r,s),G3(e),B3(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=IMe,done:d,...f}=e,p=L6(e,t,r-1),m=F6(p,t.offsetTree,l)+i+a,h=m+d6(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&F3(Q(o,z3(e=>!e),U3(N3(o)?1:2)),d),_}),z3(e=>e!==null)),l),{scrollIntoView:u}},k3(B6,o6,W6,l8,e6),{singleton:!0});function p8(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var LMe=(e,t)=>typeof e==`function`?p8(e(t)):t&&p8(e),RMe=Y3(([{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=$(!1),h=q3(),g=null;function _(e){j3(o,{align:`end`,behavior:e,index:`LAST`})}A3(Q(X3(Q(Z3(t),U3(1)),c),G3(Z3(m),a,s,d),B3(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=LMe(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),z3(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),N3(n)===void 0?g=F3(e,()=>{N3(u)(`following output to `,{totalCount:r},$3.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{N3(u)(`following output to `,{totalCount:r},$3.DEBUG),_(t)})});function v(e){let t=F3(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(N3(u)(`scrolling to bottom due to increased size`,{},$3.DEBUG),_(`auto`))});setTimeout(t,100)}A3(Q(X3(Z3(m),t,l),z3(([e,,t])=>e!==!1&&t),H3(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),z3(({refreshed:e})=>e),G3(m,t)),([,e])=>{N3(s)&&v(e!==!1)}),A3(h,()=>{v(N3(m)!==!1)}),A3(X3(Z3(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=$(null),b=q3();return P3(Q3(Q(Z3(r),B3(e=>e?.length??0)),Q(Z3(t))),b),A3(Q(X3(Q(b,U3(1)),c),G3(Z3(y),s,d,f),B3(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),z3(e=>!!e),W3(0)),t=>{g!==null&&(g(),g=null),N3(n)===void 0?g=F3(e,()=>{N3(u)(`scrolling into view`,{}),j3(p,t),g=null}):requestAnimationFrame(()=>{N3(u)(`scrolling into view`,{}),j3(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},k3(B6,Z6,W6,q6,H6,e6,o6,d8,f8)),zMe=Y3(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(P3(Q(s,G3(a),z3(([,e])=>e!==0),G3(i,r,t,n,e),B3(([[,e],t,n,r,i,a=[]])=>o8(e,t,n,r,i,a))),o),{}),k3(B6,q6,l8,H6),{singleton:!0}),BMe=Y3(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=$(0);return A3(Q(e,G3(r),z3(([,e])=>e!==0),B3(([,e])=>({top:e}))),e=>{F3(Q(n,U3(1),z3(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{j3(t,e)})})}),{initialScrollTop:r}},k3(H6,o6,l8),{singleton:!0}),m8=Y3(([{scrollVelocity:e}])=>{let t=$(!1),n=q3(),r=$(!1);return P3(Q(e,G3(r,t,n),z3(([e,t])=>t!==!1&&t!==void 0),B3(([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}),R3()),t),A3(Q(X3(t,e,n),G3(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}},k3(Z6),{singleton:!0}),h8=Y3(([{scrollContainerState:e,scrollTo:t}])=>{let n=q3(),r=q3(),i=q3(),a=$(!1),o=$(void 0);return P3(Q(X3(n,r),B3(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),P3(Q(t,G3(r),B3(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},k3(o6)),VMe=Y3(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=q3(),u=$(void 0),d=$(null),f=$(null);return P3(s,d),P3(c,f),A3(Q(l,G3(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=wMe(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),P3(Q(u,z3(E3),B3(HMe)),i),P3(Q(a,G3(u),z3(([,e])=>e!==void 0),R3(),B3(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},k3(B6,o6,q6,H6,h8));function HMe(e){return{align:`start`,index:0,offset:e.scrollTop}}var UMe=Y3(([{topItemsIndexes:e}])=>{let t=$(0);return P3(Q(t,z3(e=>e>=0),B3(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},k3(l8));function g8(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var WMe=g8(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),_8=Y3(([{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 P3(k,T.scrollSeekRangeChanged),P3(Q(T.windowViewportRect,B3(e=>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}},k3(B6,q6,o6,VMe,RMe,l8,W6,Y3(([{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=J3(Q(c,G3(o),H3(([,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]),z3(([e])=>e!==0),G3(r,s,n,i,p,m),z3(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===Y6),B3(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},$3.DEBUG),e))));function g(n){n>0?(j3(t,{behavior:`auto`,top:-n}),j3(e,0)):(j3(e,0),j3(t,{behavior:`auto`,top:-n}))}return A3(Q(h,G3(e,a)),([t,n,r])=>{r&&WMe()?j3(e,n-t):g(-t)}),A3(Q(X3(K3(a,!1),e,m),z3(([e,t,n])=>!e&&!n&&t!==0),B3(([e,t])=>t),W3(1)),g),P3(Q(d,B3(e=>({top:-e}))),t),A3(Q(l,G3(f,u),B3(([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=u6(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=>{j3(e,n),requestAnimationFrame(()=>{j3(t,{top:n}),requestAnimationFrame(()=>{j3(e,0),j3(m,!1)})})}),{deviation:e}},k3(o6,Z6,l8,B6,e6,k6)),UMe,V6,Y3(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),k3(r8,zMe,H6,m8,u8,BMe,FMe,h8,f8,e6,d8))));function GMe(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 v8=typeof document<`u`?R.useLayoutEffect:R.useEffect;function y8(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=R.createContext({});function c(e,n){e.propsReady!==void 0&&j3(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];j3(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];j3(i,n[r])}e.propsReady!==void 0&&j3(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];j3(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=uMe(e[t.events[r]]),n),{})}return{Component:R.forwardRef(function(t,a){let{children:d,...f}=t,[p]=R.useState(()=>O3(fMe(e),e=>{c(e,f)})),[m]=R.useState(aMe(u,p));v8(()=>{for(let e of o)e in f&&A3(m[e],f[e]);return()=>{Object.values(m).map(M3)}},[f,m,p]),v8(()=>{c(p,f)}),R.useImperativeHandle(a,rMe(l(p)));let h=n;return(0,z.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,z.jsx)(h,{...GMe([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=R.useContext(s)[e];v8(()=>A3(n,t),[t,n])},useEmitterValue:e=>{let t=R.useContext(s)[e],n=R.useCallback(e=>A3(t,e),[t]);return R.useSyncExternalStore(n,()=>N3(t),()=>N3(t))},usePublisher:e=>{let t=R.useContext(s);return R.useCallback(n=>{j3(t[e],n)},[t,e])}}}var b8=R.createContext(void 0),x8=R.createContext(void 0),S8=`-webkit-sticky`,C8=`sticky`,w8=g8(()=>{if(typeof document>`u`)return C8;let e=document.createElement(`div`);return e.style.position=S8,e.style.position===S8?S8:C8}),T8=typeof document<`u`?R.useLayoutEffect:R.useEffect;function E8(e){return`self`in e}function KMe(e){return`body`in e}function D8(e,t,n,r=D3,i,a){let o=R.useRef(null),s=R.useRef(null),c=R.useRef(null),l=R.useCallback(n=>{let r,i,o,l=n.target;if(KMe(l)||E8(l)){let e=E8(l)?l:l.defaultView;o=a===!0?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?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():Na.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]);R.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;E8(r)?(u=Math.max(M6(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?window.scrollX:window.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=M6(r,a===!0?`width`:`height`),d=r[a===!0?`scrollLeft`:`scrollTop`]);let f=u-l;if(n.top=Math.ceil(Math.max(Math.min(f,n.top),0)),J6(l,u)||n.top===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=n.top,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:n.top}),r.scrollTo(n)}function d(e){a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:e.top}}),o.current.scrollBy(e)}return{scrollByCallback:d,scrollerRef:o,scrollToCallback:u}}function O8(e){return e}var qMe=Y3(([e,t])=>({...e,...t}),k3(_8,Y3(()=>{let e=$(e=>`Item ${e}`),t=$(e=>`Group ${e}`),n=$({}),r=$(O8),i=$(`div`),a=$(D3),o=(e,t=null)=>K3(Q(n,B3(t=>t[e]),R3()),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`)}}))),JMe=({height:e})=>(0,z.jsx)(`div`,{style:{height:e}}),YMe={overflowAnchor:`none`,position:w8(),zIndex:1},k8={overflowAnchor:`none`},XMe={...k8,display:`inline-block`,height:`100%`},A8=R.memo(function({showTopList:e=!1}){let t=R8(`listState`),n=z8(`sizeRanges`),r=R8(`useWindowScroll`),i=R8(`customScrollParent`),a=z8(`windowScrollContainerState`),o=z8(`scrollContainerState`),s=i||r?a:o,c=R8(`itemContent`),l=R8(`context`),u=R8(`groupContent`),d=R8(`trackItemSizes`),f=R8(`itemSize`),p=R8(`log`),m=z8(`gap`),h=R8(`horizontalDirection`),{callbackRef:g}=r6(n,f,d,e?D3:s,p,m,i,h,R8(`skipAnimationFrameInResizeObserver`)),[_,v]=R.useState(0);L8(`deviation`,e=>{_!==e&&v(e)});let y=R8(`EmptyPlaceholder`),b=R8(`ScrollSeekPlaceholder`)??JMe,x=R8(`ListComponent`),S=R8(`ItemComponent`),C=R8(`GroupComponent`),w=R8(`computeItemKey`),T=R8(`isSeeking`),E=R8(`groupIndices`).length>0,D=R8(`alignToBottom`),O=R8(`initialItemFinalLocationReached`),k=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginLeft:_===0?D?`auto`:0:_,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:`nowrap`}:{marginTop:_===0?D?`auto`:0:_,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...O?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&y!=null?(0,z.jsx)(y,{...N8(y,l)}):(0,z.jsx)(x,{...N8(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,R.createElement)(b,{...N8(b,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,R.createElement)(C,{...N8(C,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:YMe},u(e.index,l)):(0,R.createElement)(S,{...N8(S,l),...P8(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?XMe:k8},E?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),ZMe={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},QMe={outline:`none`,overflowX:`auto`,position:`relative`},j8=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),M8=(e,t,n=0)=>({...j8(e),position:t?`relative`:`absolute`,top:t?-n:0}),$Me={position:w8(),top:0,width:`100%`,zIndex:1};function N8(e,t){if(typeof e!=`string`)return{context:t}}function P8(e,t){return{item:typeof e==`string`?void 0:t}}var eNe=R.memo(function(){let e=R8(`HeaderComponent`),t=z8(`headerHeight`),n=R8(`HeaderFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,R8(`skipAnimationFrameInResizeObserver`)),i=R8(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})}),tNe=R.memo(function(){let e=R8(`FooterComponent`),t=z8(`footerHeight`),n=R8(`HeaderFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,R8(`skipAnimationFrameInResizeObserver`)),i=R8(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})});function F8({useEmitter:e,useEmitterValue:t,usePublisher:n}){return R.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}=D8(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,z.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?QMe:ZMe,...i},tabIndex:0,...o,...N8(c,a),children:r})})}function I8({useEmitter:e,useEmitterValue:t,usePublisher:n}){return R.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=R.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=D8(s,l,c,t(`scrollerRef`),f);return T8(()=>(h.current=f||p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,z.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...N8(c,a),children:r})})}var nNe=({children:e})=>{let t=R.useContext(b8),n=z8(`viewportHeight`),r=z8(`fixedItemHeight`),i=R8(`alignToBottom`),a=R8(`horizontalDirection`),o=t6(R.useMemo(()=>T3(n,e=>M6(e,a?`width`:`height`)),[n,a]),!0,R8(`skipAnimationFrameInResizeObserver`));return R.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:j8(i),children:e})},rNe=({children:e})=>{let t=R.useContext(b8),n=z8(`windowViewportRect`),r=z8(`fixedItemHeight`),i=R8(`customScrollParent`),a=R8(`useWindowScroll`),o=R8(`topListHeight`),s=a6(n,i,R8(`skipAnimationFrameInResizeObserver`)),c=R8(`alignToBottom`);return R.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`window`,ref:s,style:M8(c,a,o),children:e})},iNe=({children:e})=>{let t=R8(`TopItemListComponent`)??`div`,n=R8(`headerHeight`);return(0,z.jsx)(t,{style:{...$Me,marginTop:`${n}px`},...N8(t,R8(`context`)),children:e})},{Component:aNe,useEmitter:L8,useEmitterValue:R8,usePublisher:z8}=y8(qMe,{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`}},R.memo(function(e){let t=R8(`useWindowScroll`),n=R8(`topItemsIndexes`).length>0,r=R8(`customScrollParent`),i=R8(`context`);return(0,z.jsxs)(r||t?sNe:oNe,{...e,context:i,children:[n&&(0,z.jsx)(iNe,{children:(0,z.jsx)(A8,{showTopList:!0})}),(0,z.jsxs)(r||t?rNe:nNe,{children:[(0,z.jsx)(eNe,{}),(0,z.jsx)(A8,{}),(0,z.jsx)(tNe,{})]})]})})),oNe=F8({useEmitter:L8,useEmitterValue:R8,usePublisher:z8}),sNe=I8({useEmitter:L8,useEmitterValue:R8,usePublisher:z8}),cNe=aNe,lNe=Y3(([e,t])=>({...e,...t}),k3(_8,Y3(()=>{let e=$(e=>(0,z.jsxs)(`td`,{children:[`Item $`,e]})),t=$(null),n=$(e=>(0,z.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=$(null),i=$(null),a=$({}),o=$(O8),s=$(D3),c=(e,t=null)=>K3(Q(a,B3(t=>t[e]),R3()),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`)}}))),uNe=({height:e})=>(0,z.jsx)(`tr`,{children:(0,z.jsx)(`td`,{style:{height:e}})}),dNe=({height:e})=>(0,z.jsx)(`tr`,{children:(0,z.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),fNe={overflowAnchor:`none`},B8={position:w8(),zIndex:2,overflowAnchor:`none`},V8=R.memo(function({showTopList:e=!1}){let t=U8(`listState`),n=U8(`computeItemKey`),r=U8(`firstItemIndex`),i=U8(`context`),a=U8(`isSeeking`),o=U8(`fixedHeaderHeight`),s=U8(`groupIndices`).length>0,c=U8(`itemContent`),l=U8(`groupContent`),u=U8(`ScrollSeekPlaceholder`)??uNe,d=U8(`GroupComponent`),f=U8(`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,R.createElement)(u,{...N8(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,R.createElement)(d,{...N8(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...B8,top:o}},l(t.index,i)):(0,R.createElement)(f,{...N8(f,i),...P8(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?{...B8,top:o+g}:fNe},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),pNe=R.memo(function(){let e=U8(`listState`),t=U8(`topItemsIndexes`).length>0,n=W8(`sizeRanges`),r=U8(`useWindowScroll`),i=U8(`customScrollParent`),a=W8(`windowScrollContainerState`),o=W8(`scrollContainerState`),s=i||r?a:o,c=U8(`trackItemSizes`),{callbackRef:l,ref:u}=r6(n,U8(`itemSize`),c,s,U8(`log`),void 0,i,!1,U8(`skipAnimationFrameInResizeObserver`)),[d,f]=R.useState(0);H8(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=U8(`EmptyPlaceholder`),m=U8(`FillerRow`)??dNe,h=U8(`TableBodyComponent`),g=U8(`paddingTopAddition`),_=U8(`statefulTotalCount`),v=U8(`context`);if(_===0&&p!=null)return(0,z.jsx)(p,{...N8(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,z.jsx)(m,{context:v,height:b},`padding-top`):null,C=x>0?(0,z.jsx)(m,{context:v,height:x},`padding-bottom`):null;return(0,z.jsxs)(h,{"data-testid":`virtuoso-item-list`,ref:l,...N8(h,v),children:[S,t&&(0,z.jsx)(V8,{showTopList:!0}),(0,z.jsx)(V8,{}),C]})}),mNe=({children:e})=>{let t=R.useContext(b8),n=W8(`viewportHeight`),r=W8(`fixedItemHeight`),i=t6(R.useMemo(()=>T3(n,e=>M6(e,`height`)),[n]),!0,U8(`skipAnimationFrameInResizeObserver`));return R.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:j8(!1),children:e})},hNe=({children:e})=>{let t=R.useContext(b8),n=W8(`windowViewportRect`),r=W8(`fixedItemHeight`),i=U8(`customScrollParent`),a=U8(`useWindowScroll`),o=a6(n,i,U8(`skipAnimationFrameInResizeObserver`));return R.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`window`,ref:o,style:M8(!1,a),children:e})},{Component:gNe,useEmitter:H8,useEmitterValue:U8,usePublisher:W8}=y8(lNe,{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`}},R.memo(function(e){let t=U8(`useWindowScroll`),n=U8(`customScrollParent`),r=W8(`fixedHeaderHeight`),i=W8(`fixedFooterHeight`),a=U8(`fixedHeaderContent`),o=U8(`fixedFooterContent`),s=U8(`context`),c=t6(R.useMemo(()=>T3(r,e=>M6(e,`height`)),[r]),!0,U8(`skipAnimationFrameInResizeObserver`)),l=t6(R.useMemo(()=>T3(i,e=>M6(e,`height`)),[i]),!0,U8(`skipAnimationFrameInResizeObserver`)),u=n||t?vNe:_Ne,d=n||t?hNe:mNe,f=U8(`TableComponent`),p=U8(`TableHeadComponent`),m=U8(`TableFooterComponent`),h=a?(0,z.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...N8(p,s),children:a()},`TableHead`):null,g=o?(0,z.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...N8(m,s),children:o()},`TableFoot`):null;return(0,z.jsx)(u,{...e,...N8(u,s),children:(0,z.jsx)(d,{children:(0,z.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...N8(f,s),children:[h,(0,z.jsx)(pNe,{},`TableBody`),g]})})})})),_Ne=F8({useEmitter:H8,useEmitterValue:U8,usePublisher:W8}),vNe=I8({useEmitter:H8,useEmitterValue:U8,usePublisher:W8}),G8={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},yNe={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:K8,floor:q8,max:J8,min:Y8,round:X8}=Math;function Z8(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function bNe(e){return{...yNe,items:e}}function Q8(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function xNe(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var SNe=Y3(([{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=$(0),C=$(0),w=$(G8),T=$({height:0,width:0}),E=$({height:0,width:0}),D=q3(),O=q3(),k=$(0),A=$(null),j=$({column:0,row:0}),M=q3(),N=q3(),P=$(!1),F=$(0),ee=$(!0),te=$(!1),I=$(!1);A3(Q(m,G3(F),z3(([e,t])=>t!==0)),()=>{j3(ee,!1)}),A3(Q(X3(m,ee,E,T,F,te),z3(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{j3(te,!0),G6(1,()=>{j3(D,e)}),F3(Q(l),()=>{j3(t,[0,0]),j3(ee,!0)})}),P3(Q(N,z3(e=>e!=null&&e.scrollTop>0),V3(0)),C),A3(Q(m,G3(N),z3(([,e])=>e!=null)),([,e])=>{e&&(j3(T,e.viewport),j3(E,e.item),j3(j,e.gap),e.scrollTop>0&&(j3(P,!0),F3(Q(l,U3(1)),e=>{j3(P,!1)}),j3(c,{top:e.scrollTop})))}),P3(Q(T,B3(({height:e})=>e)),d),P3(Q(X3(Z3(T,Q8),Z3(E,Q8),Z3(j,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),Z3(l)),B3(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),M),P3(Q(X3(Z3(S),r,Z3(j,xNe),Z3(E,Q8),Z3(T,Q8),Z3(A),Z3(C),Z3(P),Z3(ee),Z3(F)),z3(([,,,,,,,e])=>!e),B3(([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 G8;if(p===0){let t=K6(l,e);return bNe(Z8(t,t+Math.max(s-1,0),o))}let h=$8(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*q8((t+d)/(f+d)),_=h*K8((n+d)/(f+d))-1,_=Y8(e-1,J8(_,h-1)),g=Y8(_,J8(0,g))):(g=0,_=-1);let v=Z8(g,_,o),{bottom:y,top:b}=e5(a,r,i,v),x=K8(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),P3(Q(A,z3(e=>e!==null),B3(e=>e.length)),S),P3(Q(X3(T,E,w,j),z3(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),B3(([e,t,{items:n},r])=>{let{bottom:i,top:a}=e5(e,r,t,n);return[a,i]}),R3(O6)),t);let ne=$(!1);P3(Q(l,G3(ne),B3(([e,t])=>t||e!==0)),ne);let L=J3(Q(X3(w,S),z3(([{items:e}])=>e.length>0),G3(ne),z3(([[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}),B3(([[,e]])=>e-1),R3())),re=J3(Q(Z3(w),z3(({items:e})=>e.length>0&&e[0].index===0),V3(0),R3())),ie=J3(Q(Z3(w),G3(P),z3(([{items:e},t])=>e.length>0&&!t),B3(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),R3(D6),W3(0)));P3(ie,p.scrollSeekRangeChanged),P3(Q(D,G3(T,E,S,j),B3(([e,t,n,r,i])=>{let a=U6(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=J8(0,l,Y8(r-1,l));let u=t5(t,i,n,l);return o===`end`?u=X8(u-t.height+n.height):o===`center`&&(u=X8(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let ae=K3(Q(w,B3(e=>e.offsetBottom+e.bottom)),0);return P3(Q(b,B3(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:I,initialTopMostItemIndex:F,totalListHeight:ae,...f,endReached:L,propsReady:h,rangeChanged:ie,startReached:re,stateChanged:M,stateRestoreInProgress:P,...x}},k3(r8,o6,Z6,m8,H6,h8,e6));function $8(e,t,n){return J8(1,q8((e+n)/(q8(t)+n)))}function e5(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=t5(e,t,n,r[0].index);return{bottom:t5(e,t,n,r[r.length-1].index)+i,top:a}}function t5(e,t,n,r){let i=q8(r/$8(e.width,n.width,t.column)),a=i*n.height+J8(0,i-1)*t.row;return a>0?a+t.row:a}var CNe=Y3(([e,t])=>({...e,...t}),k3(SNe,Y3(()=>{let e=$(e=>`Item ${e}`),t=$({}),n=$(null),r=$(`virtuoso-grid-item`),i=$(`virtuoso-grid-list`),a=$(O8),o=$(`div`),s=$(D3),c=(e,n=null)=>K3(Q(t,B3(t=>t[e]),R3()),n),l=$(!1),u=$(!1);return P3(Z3(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`)}}))),wNe=R.memo(function(){let e=r5(`gridState`),t=r5(`listClassName`),n=r5(`itemClassName`),r=r5(`itemContent`),i=r5(`computeItemKey`),a=r5(`isSeeking`),o=i5(`scrollHeight`),s=r5(`ItemComponent`),c=r5(`ListComponent`),l=r5(`ScrollSeekPlaceholder`),u=r5(`context`),d=i5(`itemDimensions`),f=i5(`gap`),p=r5(`log`),m=r5(`stateRestoreInProgress`),h=i5(`reportReadyState`),g=t6(R.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:a5(`column-gap`,getComputedStyle(e).columnGap,p),row:a5(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return T8(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,z.jsx)(c,{className:t,ref:g,...N8(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,z.jsx)(l,{...N8(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,R.createElement)(s,{...N8(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),TNe=R.memo(function(){let e=r5(`HeaderComponent`),t=i5(`headerHeight`),n=r5(`headerFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,!1),i=r5(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})}),ENe=R.memo(function(){let e=r5(`FooterComponent`),t=i5(`footerHeight`),n=r5(`headerFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,!1),i=r5(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})}),DNe=({children:e})=>{let t=R.useContext(x8),n=i5(`itemDimensions`),r=i5(`viewportDimensions`),i=t6(R.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return R.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,z.jsx)(`div`,{ref:i,style:j8(!1),children:e})},ONe=({children:e})=>{let t=R.useContext(x8),n=i5(`windowViewportRect`),r=i5(`itemDimensions`),i=r5(`customScrollParent`),a=r5(`useWindowScroll`),o=a6(n,i,!1);return R.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,z.jsx)(`div`,{ref:o,style:M8(!1,a),children:e})},{Component:kNe,useEmitter:n5,useEmitterValue:r5,usePublisher:i5}=y8(CNe,{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`}},R.memo(function({...e}){let t=r5(`useWindowScroll`),n=r5(`customScrollParent`),r=n||t?jNe:ANe,i=n||t?ONe:DNe,a=r5(`context`);return(0,z.jsx)(r,{...e,...N8(r,a),children:(0,z.jsxs)(i,{children:[(0,z.jsx)(TNe,{}),(0,z.jsx)(wNe,{}),(0,z.jsx)(ENe,{})]})})})),ANe=F8({useEmitter:n5,useEmitterValue:r5,usePublisher:i5}),jNe=I8({useEmitter:n5,useEmitterValue:r5,usePublisher:i5});function a5(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,$3.WARN),t===`normal`?0:parseInt(t??`0`,10)}var MNe=24,NNe=700,PNe=3;function FNe({itemCount:e,resetKey:t,contentKey:n,atBottomThreshold:r=MNe}){let i=(0,R.useRef)(null),a=(0,R.useRef)(e),o=(0,R.useRef)(!0),s=(0,R.useRef)(void 0),c=(0,R.useRef)(!1),l=(0,R.useRef)(void 0),u=(0,R.useRef)(void 0),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null);(0,R.useLayoutEffect)(()=>{a.current=e},[e]);let h=(0,R.useCallback)(e=>{o.current=e,f(e)},[]),g=(0,R.useCallback)(()=>{s.current!==void 0&&(cancelAnimationFrame(s.current),s.current=void 0)},[]),_=(0,R.useCallback)((e=`auto`)=>{g(),s.current=requestAnimationFrame(()=>{s.current=void 0;let t=a.current-1;t<0||(i.current?.autoscrollToBottom(),i.current?.scrollToIndex({index:t,align:`end`,behavior:e}),requestAnimationFrame(()=>{o.current&&i.current?.autoscrollToBottom()}))})},[g]),v=(0,R.useCallback)((e=`auto`)=>{h(!0),_(e)},[_,h]),y=(0,R.useCallback)((e,t=`center`,n=`auto`,r={})=>{h(!1),g(),requestAnimationFrame(()=>{if(n!==`fast-smooth`){i.current?.scrollToIndex({index:e,align:t,behavior:n});return}if(r.stagingAlign){i.current?.scrollToIndex({index:e,align:r.stagingAlign,behavior:`auto`}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{i.current?.scrollToIndex({index:e,align:t,behavior:`smooth`})})});return}let o=r.fromIndex,s=Math.abs(typeof o==`number`?o-e:0),c=r.stagingDistance??PNe;if(typeof o!=`number`||s<=c){i.current?.scrollToIndex({index:e,align:t,behavior:`smooth`});return}let l=a.current-1,u=e<o?Math.min(l,e+c):Math.max(0,e-c);i.current?.scrollToIndex({index:u,align:t,behavior:`auto`}),requestAnimationFrame(()=>{i.current?.scrollToIndex({index:e,align:t,behavior:`smooth`})})})},[g,h]),b=(0,R.useCallback)(e=>{c.current=!0,(e instanceof WheelEvent&&e.deltaY<0||p&&!o5(p,r))&&h(!1),l.current!==void 0&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{c.current=!1,l.current=void 0},NNe)},[r,p,h]),x=(0,R.useCallback)(()=>{if(!p)return;let e=INe(p),t=u.current;if(u.current=e,o5(p,r)){h(!0);return}let n=t!==void 0&&e<t-1;(c.current||n)&&h(!1)},[r,p,h]);return(0,R.useEffect)(()=>{if(!p)return;let e=p,t=e=>{let t=e instanceof KeyboardEvent?e.key:``;[`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `].includes(t)&&b()},n=t=>{t.target===e&&b()};return e.addEventListener(`wheel`,b,{passive:!0}),e.addEventListener(`touchmove`,b,{passive:!0}),e.addEventListener(`pointerdown`,n,{passive:!0}),e.addEventListener(`keydown`,t),e.addEventListener(`scroll`,x,{passive:!0}),()=>{e.removeEventListener(`wheel`,b),e.removeEventListener(`touchmove`,b),e.removeEventListener(`pointerdown`,n),e.removeEventListener(`keydown`,t),e.removeEventListener(`scroll`,x)}},[b,p,x]),(0,R.useLayoutEffect)(()=>{u.current=void 0,h(!0),_(`auto`)},[t,_,h]),(0,R.useLayoutEffect)(()=>{o.current&&_(`auto`)},[n,e,_]),(0,R.useEffect)(()=>()=>{g(),l.current!==void 0&&window.clearTimeout(l.current)},[g]),{virtuosoRef:i,isSticky:d,stickToBottom:v,scrollToIndex:y,scrollerRef:m,atBottomStateChange:(0,R.useCallback)(e=>{if(e){h(!0);return}c.current&&h(!1)},[h]),atBottomThreshold:r,followOutput:(0,R.useCallback)(()=>o.current?`auto`:!1,[]),totalListHeightChanged:(0,R.useCallback)(()=>{o.current&&_(`auto`)},[_])}}function o5(e,t){let n=e instanceof Window?document.scrollingElement:e;return n?n.scrollHeight-n.scrollTop-n.clientHeight<=t:!0}function INe(e){return(e instanceof Window?document.scrollingElement:e)?.scrollTop??0}var s5={"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`}},c5=12;function l5(e,t){return t===`all`||e<t}(0,R.memo)(function e({span:t,startTime:n,depth:r=0,expansionDepth:i,expansionSignal:a,expandThinking:o,onFork:s,onOpenSession:c}){let[l,u]=(0,R.useState)(()=>l5(r,i)),[d,f]=(0,R.useState)(()=>t.spanType===`model.reasoning`?o:l5(r,i));(0,R.useEffect)(()=>{let e=l5(r,i);u(e),f(t.spanType===`model.reasoning`?o:e)},[r,i,a,o,t.spanType]),s5[t.spanType]||s5[`agent.run`],t.status,t.status,t.spanType===`user.prompt`||t.spanType;let p=!!t.children?.length;return f5(t.startTime,n),t.durationUs?`${(t.durationUs/1e3).toFixed(1)}`:t.endTime&&`${((t.endTime-t.startTime)/1e3).toFixed(1)}`,(0,z.jsx)(LNe,{span:t,startTime:n,depth:r,contentExpanded:d,childrenExpanded:l,onToggle:(0,R.useCallback)(()=>{f(e=>!e),p&&u(e=>!e)},[p]),onFork:s,onOpenSession:c,childrenContent:p?t.children?.map(t=>(0,z.jsx)(e,{span:t,startTime:n,depth:r+1,expansionDepth:i,expansionSignal:a,expandThinking:o,onFork:s,onOpenSession:c},t.id)):void 0})});var LNe=(0,R.memo)(function({span:e,startTime:t,depth:n=0,contentExpanded:r,childrenExpanded:i,onToggle:a,onFork:o,onOpenSession:s,childrenContent:c}){let l=s5[e.spanType]||s5[`agent.run`],u=e.status===`UNSET`,d=GNe(e.status,u),f=e.spanType===`user.prompt`||e.spanType===`user_input`,p=!!e.children?.length,m=f5(e.startTime,t),h=e.durationUs?`${(e.durationUs/1e3).toFixed(1)}ms`:e.endTime?`${((e.endTime-e.startTime)/1e3).toFixed(1)}ms`:null;return(0,z.jsx)(`div`,{className:`relative mb-4 group`,style:{marginLeft:n>0?c5:0,width:n>0?`calc(100% - ${c5}px)`:`var(--trace-readable-width)`,maxWidth:`100%`},children:(0,z.jsxs)(`div`,{className:`min-w-0 ${f?`bg-[#11a4d4]/10`:`bg-white dark:bg-[#1a262b]`} border ${d.cardClass} rounded-sm shadow-sm transition-all hover:border-opacity-70 focus:outline-none focus:ring-1 focus:ring-[#11a4d4]/50 ${u?d.glowClass:``}`,onDoubleClick:e=>{u5(e)||a()},onKeyDown:e=>{u5(e)||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},role:`button`,tabIndex:0,"aria-expanded":r,children:[(0,z.jsx)(RNe,{span:e,config:l,statusStyles:d,isActive:u,contentExpanded:r,duration:h,relativeTime:m,onToggle:a,onFork:o,onOpenSession:s}),r?(0,z.jsx)(VNe,{span:e}):null,p&&i&&r?(0,z.jsx)(`div`,{className:`min-w-0 border-t border-slate-700 bg-slate-900/50 py-4`,children:c}):null]})})});function u5(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 RNe({span:e,config:t,statusStyles:n,isActive:r,contentExpanded:i,duration:a,relativeTime:o,onToggle:s,onFork:c,onOpenSession:l}){let u=e.spanType===`user.prompt`||e.spanType===`user_input`?`bg-[#11a4d4]/10`:n.headerClass;return(0,z.jsx)(`div`,{className:`${i?`border-b ${t.borderColor}/20`:``} ${u}`,children:(0,z.jsxs)(`div`,{className:`box-border flex w-full min-w-0 items-center`,style:{maxWidth:`100%`},children:[(0,z.jsx)(`div`,{className:`min-w-0 flex-1 px-4 py-2 text-left`,children:(0,z.jsxs)(`span`,{className:`min-w-0 text-xs font-bold ${t.color} uppercase tracking-wider flex items-center gap-2`,children:[i?(0,z.jsx)(zo,{size:12}):(0,z.jsx)(Bo,{size:12}),(0,z.jsx)(zNe,{spanType:e.spanType,config:t,isActive:r}),(0,z.jsx)(`span`,{className:`shrink-0`,children:t.label}),e.name?(0,z.jsxs)(`span`,{className:`min-w-0 truncate font-normal text-slate-500 dark:text-slate-400 normal-case`,children:[`: `,e.name]}):null,r?(0,z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}),(0,z.jsx)(HNe,{forkEntryId:e.pibo?.traceNodeType===`user.message`?e.pibo.entryId:void 0,linkedPiboSessionId:e.pibo?.linkedPiboSessionId,onFork:c,onOpenSession:l}),(0,z.jsx)(BNe,{duration:a,relativeTime:o})]})})}function zNe({spanType:e,config:t,isActive:n}){return(0,z.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,z.jsx)(WNe,{type:e,className:t.color}),n?(0,z.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-1.5 w-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}function BNe({duration:e,relativeTime:t}){return(0,z.jsxs)(`div`,{className:`ml-2 mr-4 flex w-36 shrink-0 items-center justify-end gap-2 font-mono tabular-nums`,children:[e?(0,z.jsx)(`span`,{className:`text-[10px] text-slate-500 dark:text-slate-400`,children:e}):null,(0,z.jsx)(`span`,{className:`text-xs text-slate-400 dark:text-slate-500`,children:t})]})}var VNe=(0,R.memo)(function({span:e}){let[t,n]=(0,R.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=e.status===`ERROR`?(0,z.jsxs)(`div`,{className:`mx-4 mt-4 p-3 bg-red-500/10 border border-red-500/20 rounded-sm text-xs`,children:[(0,z.jsx)(`div`,{className:`flex items-center gap-2 font-semibold text-red-500 mb-1`,children:`Error`}),e.statusMessage?(0,z.jsx)(`div`,{className:`font-mono text-red-400 mb-2`,children:e.statusMessage}):null]}):null;if(r===`user.prompt`||r===`user_input`)return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.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)})]});if(r===`model.response`)return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsx)(`div`,{className:`model-response-markdown min-w-0 p-4 text-sm text-slate-200 leading-relaxed`,children:typeof o==`string`?(0,z.jsx)(zW,{children:o}):(0,z.jsx)(vq,{value:o})})]});if(r===`tool.result`)return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsxs)(`div`,{className:`p-4 bg-green-500/5 border-t border-green-500/20`,children:[(0,z.jsxs)(`div`,{className:`text-xs font-medium text-green-400 mb-2`,children:[`Returned from `,c||a,`:`]}),(0,z.jsx)(vq,{value:l??o})]})]});if(r===`tool.call`){let e=p5(u)?u:{},r=Object.keys(e).length>0;return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`p-4 bg-[#0e1116] border-b border-slate-800`,children:(0,z.jsx)(UNe,{name:c??a,args:e})}),l==null?null:(0,z.jsxs)(`div`,{className:`px-4 py-2 bg-[#1a262b] flex items-center gap-2`,children:[(0,z.jsx)(Eo,{size:14,className:`text-slate-400`}),(0,z.jsx)(`span`,{className:`text-xs font-mono text-slate-500`,children:`Output:`}),(0,z.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,z.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,z.jsx)(is,{size:12}):(0,z.jsx)(as,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,z.jsxs)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116]`,children:[r?(0,z.jsxs)(`div`,{className:`px-4 pt-3 pb-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-semibold text-blue-400 uppercase tracking-wider mb-1.5`,children:`Input`}),(0,z.jsx)(vq,{value:e})]}):null,l==null?null:(0,z.jsxs)(`div`,{className:`px-4 pt-2 pb-3 border-t border-slate-700/30`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-semibold text-green-400 uppercase tracking-wider mb-1.5`,children:`Output`}),(0,z.jsx)(vq,{value:l})]})]}):null,d]})}if(r===`yielded.run`){let e=p5(l)?l:p5(o)?o:{};return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsxs)(`div`,{className:`p-4 border-b border-[#11a4d4]/20 bg-[#11a4d4]/5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,z.jsx)(Oo,{size:14,className:`text-[#11a4d4]`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-[#11a4d4]`,children:`Run notification`}),(0,z.jsx)(`span`,{className:`text-xs font-mono text-slate-400`,children:typeof i.content==`string`?i.content:a})]}),(0,z.jsx)(KNe,{notification:e})]}),(0,z.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,z.jsx)(is,{size:12}):(0,z.jsx)(as,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,z.jsx)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116] px-4 py-3`,children:(0,z.jsx)(vq,{value:e})}):null]})}if(r===`model.reasoning`){let e=i.reasoning||i[`model.reasoning`]||o;return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.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,z.jsx)(`span`,{className:`text-amber-500 opacity-60`,children:`// Model reasoning`}),(0,z.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,z.jsxs)(z.Fragment,{children:[d,(0,z.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,z.jsx)(fs,{size:14,className:`text-orange-500`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Delegated to:`}),(0,z.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),n?(0,z.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,z.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,m5(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,z.jsxs)(z.Fragment,{children:[d,(0,z.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:[(0,z.jsx)(fs,{size:14,className:`text-orange-500`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Async agent started:`}),(0,z.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),a?(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-x-3 gap-y-1 font-mono text-[11px] text-slate-500`,children:[(0,z.jsxs)(`span`,{children:[`Started by `,n||`pibo_run_start`]}),r?(0,z.jsx)(`span`,{children:r}):null]}),t?(0,z.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,m5(t),`"`]}):null]})]})}return r===`agent.run`?(0,z.jsx)(`div`,{className:`flex flex-col`,children:d}):(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsx)(`div`,{className:`p-4 font-mono text-sm text-slate-300`,children:(0,z.jsx)(vq,{value:i})})]})});function HNe({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,z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[i?(0,z.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,z.jsx)(fs,{size:14})}):null,a?(0,z.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,z.jsx)(rs,{size:14})}):null]})}function UNe({name:e,args:t}){return(0,z.jsxs)(`code`,{className:`font-mono text-xs text-green-400`,children:[(0,z.jsx)(`span`,{className:`text-purple-400`,children:`def`}),` `,(0,z.jsx)(`span`,{className:`text-yellow-300`,children:e}),(0,z.jsxs)(`span`,{children:[`(`,Object.entries(t).map(([e,t],n)=>(0,z.jsxs)(`span`,{children:[n>0?`, `:null,(0,z.jsx)(`span`,{className:`text-blue-400`,children:e}),`=`,(0,z.jsx)(`span`,{className:`text-green-300`,children:typeof t==`string`?`'${t.slice(0,50)}${t.length>50?`...`:``}'`:m5(t).slice(0,50)})]},e)),`)`]})]})}function WNe({type:e,className:t}){let n={size:14,className:t};switch(e){case`agent.run`:return(0,z.jsx)(Po,{...n});case`tool.call`:return(0,z.jsx)(ko,{...n});case`tool.result`:return(0,z.jsx)(Eo,{...n});case`model.request`:return(0,z.jsx)(Mo,{...n});case`model.response`:return(0,z.jsx)(Eo,{...n});case`model.reasoning`:return(0,z.jsx)(ys,{...n});case`agent.delegation`:return(0,z.jsx)(fs,{...n});case`agent.async`:return(0,z.jsx)(fs,{...n});case`yielded.run`:return(0,z.jsx)(Oo,{...n});case`user.prompt`:return(0,z.jsx)(Os,{...n});case`user_input`:return(0,z.jsx)(Xs,{...n});case`execution.command`:return(0,z.jsx)(ko,{...n});default:return(0,z.jsx)(Ro,{...n})}}function GNe(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 KNe({notification:e}){let t=[[`completed`,`text-green-500`,e.completed],[`failed`,`text-red-400`,e.failed],[`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(p5):[]})).filter(e=>e.runs.length>0);return t.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-400`,children:`No yielded run updates.`}):(0,z.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider ${e.color}`,children:e.name}),(0,z.jsx)(`div`,{className:`grid gap-1`,children:e.runs.map((t,n)=>(0,z.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,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate font-mono text-xs text-slate-200`,children:d5(t.toolName)||`yielded tool`}),(0,z.jsx)(`div`,{className:`truncate font-mono text-[10px] text-slate-500`,children:d5(t.runId)})]}),(0,z.jsx)(`div`,{className:`font-mono text-[10px] uppercase text-slate-400`,children:d5(t.status)||e.name})]},`${e.name}-${n}`))})]},e.name))})}function d5(e){return typeof e==`string`?e:``}function f5(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 p5(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function m5(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function h5(e){if(e==null)return{kind:`empty`};let t=g5(e);return t===void 0?{kind:`json`,value:e}:{kind:`text`,text:t}}function g5(e){if(typeof e==`string`)return e;if(Array.isArray(e)){let t=e.map(g5).filter(e=>e!==void 0);return t.length===e.length&&t.length>0?t.join(``):void 0}if(!_5(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=g5(e.content);if(n!==void 0&&qNe(e))return n;let r=_5(e.message)?g5(e.message.content):void 0;if(r!==void 0)return r}function qNe(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 _5(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function JNe({row:e,onOpenSession:t}){return(0,z.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,z.jsx)(`div`,{className:`space-y-3`,children:e.detailItems.map(e=>(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e.label}),e.linkedPiboSessionId?(0,z.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,z.jsx)(v5,{label:`Input`,value:e.input}),(0,z.jsx)(v5,{label:`Output`,value:e.output}),(0,z.jsx)(y5,{value:e.output}),e.error?(0,z.jsx)(x5,{label:`Error`,value:e.error,tone:`red`}):null]},e.id))}):(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(v5,{label:`Input`,value:e.input}),(0,z.jsx)(v5,{label:`Output`,value:e.output}),(0,z.jsx)(y5,{value:e.output}),e.error?(0,z.jsx)(x5,{label:`Error`,value:e.error,tone:`red`}):null,e.linkedPiboSessionId?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Child session`}),(0,z.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 v5({label:e,value:t}){let n=h5(t);if(n.kind===`empty`)return null;if(n.kind===`text`){let t=S5(n.text);return t?.kind===`json`?(0,z.jsx)(b5,{label:e,value:t.value,meta:t.meta}):t?.kind===`text`?(0,z.jsx)(x5,{label:e,value:t.text}):(0,z.jsx)(x5,{label:e,value:n.text})}return(0,z.jsx)(b5,{label:e,value:n.value})}function y5({value:e}){let t=YNe(e);return t?(0,z.jsxs)(`details`,{className:`space-y-1 border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:[(0,z.jsxs)(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-[#38bdf8]`,children:[`Show full output (`,t.originalLines,` lines)`]}),t.fullOutput?(0,z.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,z.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 YNe(e){if(!T5(e))return;let t=T5(e.details)?e.details.piboBashOutputCompaction:void 0;if(!T5(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 b5({label:e,value:t,meta:n}){return(0,z.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-json":e,children:[(0,z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),n?(0,z.jsxs)(`div`,{className:`min-w-0 break-words text-[11px] text-[#737373]`,children:[`Status: `,n]}):null]}),(0,z.jsx)(`div`,{className:`compact-terminal-json border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:(0,z.jsx)(vq,{value:t,showControls:!1})})]})}function x5({label:e,value:t,tone:n=`default`}){return(0,z.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-text":e,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),(0,z.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 S5(e){let t=e.trim();if(!t)return;let n=w5(t);if(n!==void 0)return C5(n);let r=t.split(/\r?\n/);for(let e=1;e<r.length;e+=1){let t=r.slice(e).join(`
|
|
165
|
-
`).trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))continue;let n=w5(t);if(n!==void 0)return C5(n,r.slice(0,e).join(` `).trim()||void 0)}}function C5(e,t){let n=h5(e);if(n.kind===`text`){let e=S5(n.text);return e?.kind===`json`?{...e,meta:e.meta??t}:{kind:`text`,text:n.text}}return{kind:`json`,value:e,meta:t}}function w5(e){if(!(!e.startsWith(`{`)&&!e.startsWith(`[`)))try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}function T5(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function XNe({name:e,input:t}){return(0,z.jsxs)(`span`,{className:`compact-terminal-function-call`,children:[(0,z.jsx)(`span`,{className:`text-[#facc15] font-semibold`,children:e}),(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`(`}),t===void 0?null:(0,z.jsx)(ZNe,{value:t}),(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`)`})]})}function ZNe({value:e}){let[t,n]=(0,R.useState)(()=>new Set([`$`])),[r,i]=(0,R.useState)(()=>new Set);return(0,z.jsx)(E5,{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 E5({value:e,path:t,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a}){if(Array.isArray(e))return(0,z.jsx)(D5,{value:e,path:t,open:`[`,close:`]`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if($Ne(e))return(0,z.jsx)(D5,{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,z.jsx)(`span`,{className:`text-[#fb923c]`,children:JSON.stringify(o)});return!i&&e.length<=140?s:(0,z.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`,children:s})}return typeof e==`number`||typeof e==`boolean`||e===null?(0,z.jsx)(`span`,{className:`text-[#60a5fa]`,children:String(e)}):(0,z.jsx)(`span`,{className:`text-[#737373]`,children:JSON.stringify(String(e))})}function D5({value:e,path:t,open:n,close:r,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s}){let c=Array.isArray(e)?e.map((e,t)=>[String(t),e]):Object.entries(e);return i.has(t)?(0,z.jsxs)(`span`,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Collapse JSON`,"aria-label":`Collapse JSON at ${t}`,"data-inline-json-path":t,children:[(0,z.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▾`}),n]}),c.map(([n,r],c)=>{let l=`${t}.${QNe(n)}`;return(0,z.jsxs)(`span`,{children:[c>0?(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`, `}):null,Array.isArray(e)?null:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:JSON.stringify(n)}),(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`:`})]}),(0,z.jsx)(E5,{value:r,path:l,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s})]},l)}),(0,z.jsx)(`span`,{className:`text-[#737373]`,children:r})]}):(0,z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Expand JSON`,"aria-label":`Expand JSON at ${t}`,"data-inline-json-path":t,children:[(0,z.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▸`}),n,`...`,r]})}function QNe(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`.`,`\\.`)}function $Ne(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ePe({line:e,status:t,clampLines:n}){let r=`min-w-0 whitespace-pre-wrap break-words ${n?`block overflow-hidden`:``}`;return(0,z.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre ${nPe(e.prefix,t)}`,children:tPe(e.prefix)}),(0,z.jsxs)(`span`,{className:r,style:n?{maxHeight:`${n*1.45}em`}:void 0,children:[e.tokens.map((e,t)=>(0,z.jsx)(`span`,{className:rPe(e),children:e.text},`${t}:${e.text}`)),e.functionCall?(0,z.jsx)(XNe,{name:e.functionCall.name,input:e.functionCall.input}):null]})]})}function tPe(e=`none`){switch(e){case`bullet`:return`•`;case`detail`:return`└`;case`continuation`:return` `;case`prompt`:return`›`;default:return` `}}function nPe(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 rPe(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()}async function iPe(){await fetch(`/api/auth/sign-out`,{method:`POST`,credentials:`same-origin`,headers:{"content-type":`application/json`},body:`{}`})}async function aPe(){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}function oPe(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 sPe(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 O5(e){return cPe(e)?e.result:e}function cPe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}var lPe={device_code:`Device code`,api_key:`API key`,oauth:`Browser OAuth`};function uPe({row:e,piboSessionId:t}){let n=oPe(e.output)?e.output:void 0,r=(0,R.useMemo)(()=>n?.providers??[],[n?.providers]),[i,a]=(0,R.useState)({type:`select_provider`}),[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(``),[u,d]=(0,R.useState)(``),[f,p]=(0,R.useState)(null),m=(0,R.useCallback)(()=>{a({type:`select_provider`}),l(``),d(``)},[]),h=(0,R.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),p(e),window.setTimeout(()=>p(t=>t===e?null:t),1600)}catch{}},[]),g=(0,R.useCallback)(async e=>{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 n=O5(await yc(t,`login.start`,{provider:e.id}));if(!n?.url){a({type:`error`,provider:e,message:`No login URL returned.`});return}a({type:`device_flow`,provider:e,url:n.url,state:n.state,userCode:n.userCode,instructions:n.instructions})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t]),_=(0,R.useCallback)(async(e,n,r)=>{if(t){s(!0);try{await yc(t,`login.complete`,{provider:e.id,state:n??``,...r?{code:r}:{}}),a({type:`success`,provider:e,message:`${e.name} login completed.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[t]),v=(0,R.useCallback)(async e=>{if(!t)return;let n=c.trim();if(n){s(!0);try{await yc(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,z.jsx)(k5,{title:i.type===`select_provider`?`Login`:fPe(i),tone:i.type===`error`?`red`:i.type===`success`?`green`:`cyan`,action:i.type===`select_provider`?void 0:(0,z.jsx)(dPe,{onClick:m,disabled:o}),children:i.type===`select_provider`?(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a provider. Use `,(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` anytime.`]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,z.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,z.jsx)(`span`,{children:e.name}),e.configured?(0,z.jsx)(`span`,{className:`text-[#22c55e]`,children:`●`}):null]},e.id))})]}):i.type===`select_method`?(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Provider:`}),(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.provider.name}),i.provider.configured?(0,z.jsx)(A5,{tone:`green`,children:`Configured`}):(0,z.jsx)(A5,{tone:`neutral`,children:`Not configured`})]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.provider.authMethods.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>e===`api_key`?a({type:`api_key`,provider:i.provider}):void g(i.provider),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,z.jsx)(gs,{size:11}):(0,z.jsx)(Ts,{size:11}),lPe[e]]},e))})]}):i.type===`device_starting`?(0,z.jsxs)(`div`,{className:`inline-flex items-center gap-2 text-[11px] text-[#38bdf8]`,children:[(0,z.jsx)(Cs,{size:13,className:`animate-spin`}),` Starting device login...`]}):i.type===`device_flow`?(0,z.jsxs)(`div`,{className:`grid gap-2 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Open:`}),(0,z.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[#38bdf8] hover:underline`,children:[pPe(i.url),` `,(0,z.jsx)(rs,{size:11})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void h(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,z.jsx)(qo,{size:10}):(0,z.jsx)($o,{size:10}),` `,f===i.url?`Copied`:`Copy`]})]}),i.userCode?(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Code:`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void h(i.userCode),className:`border border-[#1f4960] px-2 py-0.5 font-semibold tracking-widest text-[#38bdf8] hover:border-[#38bdf8]`,children:i.userCode}),(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`then`}),(0,z.jsxs)(`button`,{type:`button`,disabled:o,onClick:()=>void _(i.provider,i.state),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,z.jsx)(Cs,{size:11,className:`animate-spin`}):(0,z.jsx)(qo,{size:11}),` Complete`]})]}):(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,z.jsx)(`input`,{value:u,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,z.jsxs)(`button`,{type:`button`,disabled:o||!u.trim(),onClick:()=>void _(i.provider,i.state,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,z.jsx)(Cs,{size:11,className:`animate-spin`}):(0,z.jsx)(qo,{size:11}),` Complete`]})]}),i.instructions?(0,z.jsx)(`div`,{className:`text-[#737373]`,children:i.instructions}):null]}):i.type===`api_key`?(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`API key:`}),(0,z.jsx)(`input`,{type:`password`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(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,z.jsxs)(`button`,{type:`button`,disabled:o||!c.trim(),onClick:()=>void v(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,z.jsx)(Cs,{size:11,className:`animate-spin`}):(0,z.jsx)(qo,{size:11}),` Save`]})]}):i.type===`success`?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#22c55e]`,children:[(0,z.jsx)(qo,{size:13}),` `,i.message]}):(0,z.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#ef4444]`,children:[(0,z.jsx)(Go,{size:13,className:`mt-0.5 shrink-0`}),` `,(0,z.jsx)(`span`,{children:i.message})]})}):(0,z.jsx)(k5,{title:`Login`,tone:`red`,children:`Unparseable login payload.`})}function k5({title:e,tone:t,action:n,children:r}){return(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(Ts,{size:14,className:t===`red`?`text-[#ef4444]`:t===`green`?`text-[#22c55e]`:`text-[#38bdf8]`}),(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),n?(0,z.jsx)(`div`,{className:`ml-auto`,children:n}):null]}),r]})}function dPe({onClick:e,disabled:t}){return(0,z.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,z.jsx)(Do,{size:10}),` Back`]})}function A5({tone:e,children:t}){return(0,z.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 fPe(e){return`provider`in e&&e.provider?e.provider.name:`Login`}function pPe(e){try{let t=new URL(e);return`${t.host}${t.pathname}`}catch{return e.length>42?`${e.slice(0,39)}...`:e}}function mPe({row:e,piboSessionId:t,onModelChanged:n}){let r=O5(e.output),i=(sPe(r)?r:void 0)?.providers??[],a=(0,R.useMemo)(()=>i.flatMap(e=>e.models.map(t=>({...t,providerLabel:e.label}))),[i]),[o,s]=(0,R.useState)(``),[c,l]=(0,R.useState)(null),[u,d]=(0,R.useState)(!1),[f,p]=(0,R.useState)(null),m=(0,R.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)){d(!0),l(e),p(null);try{await gc(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,z.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,z.jsx)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[#2a2a2a] px-3 py-2`,children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[#d4d4d4]`,children:`Model`}),(0,z.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a model from authenticated providers. Use `,(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` to add providers.`]})]})}),(0,z.jsxs)(`div`,{className:`space-y-2 p-3`,children:[i.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[#737373]`,children:[(0,z.jsx)(Vs,{size:13}),(0,z.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,z.jsx)(`div`,{className:`max-h-72 overflow-auto border border-[#2a2a2a]`,children:m.length?m.map(e=>(0,z.jsxs)(`button`,{type:`button`,disabled:u,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:opacity-50`,children:[(0,z.jsx)(`span`,{className:`truncate text-[#737373]`,children:e.providerLabel}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-[#d4d4d4]`,children:e.label}),(0,z.jsxs)(`span`,{className:`block truncate text-[11px] text-[#737373]`,children:[e.provider,`/`,e.id]})]}),c?.provider===e.provider&&c?.id===e.id?(0,z.jsx)(Ro,{size:14,className:`text-[#22c55e]`}):null]},`${e.provider}:${e.id}`)):(0,z.jsx)(`div`,{className:`px-3 py-2 text-[#737373]`,children:`No matching models.`})})]}):(0,z.jsxs)(`div`,{className:`text-[#737373]`,children:[`No authenticated model providers found. Run `,(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` first.`]}),f?(0,z.jsx)(`div`,{className:`text-[11px] text-[#a3a3a3]`,children:f}):null]})]})}function hPe(e={}){let t=[],n=[],r=N5(e.warnings),i=N5(e.errors);(e.session?.id||e.session?.title)&&t.push({id:`session`,label:`Session`,value:j5([e.session?.title,e.session?.id].filter(Boolean).join(` | `))}),e.session?.profile&&t.push({id:`profile`,label:`Profile`,value:j5(e.session.profile)}),e.session?.status&&t.push({id:`session-status`,label:`Session status`,value:j5(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:j5(e.model.label??[e.model.provider,e.model.id].filter(Boolean).join(`/`))}),e.runtime?.state&&t.push({id:`runtime`,label:`Runtime`,value:j5(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:j5(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:j5(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`?j5(e.fastMode):e.fastMode?`on`:`off`,tone:e.fastMode?`green`:`neutral`});let o=N5(e.tools?.enabled),s=N5(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:j5(e.providerUsage.planType)}),e.providerUsage?.credits&&t.push({id:`provider-credits`,label:`Credits`,value:e.providerUsage.credits.unlimited?`unlimited`:j5(e.providerUsage.credits.balance??`available`)}),e.message&&t.push({id:`message`,label:`Message`,value:j5(e.message)}),n.push(gPe(e.contextUsage));for(let t of _Pe(e.providerUsage))n.push(t);return{kind:`status`,title:`Status`,fields:t,progress:n,warnings:r,errors:i}}function j5(e){return e.replace(/\b([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD)[A-Z0-9_]*)\s*=\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(api[_-]?key|token|secret|password)\s*[:=]\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(?:sk|pk|pibo|ghp|github_pat)_[A-Za-z0-9_\-]{8,}\b/g,`[redacted]`)}function gPe(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=M5(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:vPe(t)}}function _Pe(e){return e?.limits?.length?e.limits.map((t,n)=>{let r=M5(t.usedPercent),i=M5(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 ${j5(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:yPe(i)}}):[{id:`provider`,label:`Provider quota`,state:`unavailable`,text:`Provider usage unavailable`,tone:`neutral`}]}function M5(e){if(!(typeof e!=`number`||!Number.isFinite(e)))return Math.max(0,Math.min(100,e))}function vPe(e){return e===void 0?`neutral`:e>=80?`red`:e>=50?`yellow`:`green`}function yPe(e){return e===void 0?`neutral`:e<=20?`red`:e<=50?`yellow`:`green`}function N5(e){return(e??[]).map(e=>j5(e)).filter(e=>e.length>0)}function bPe(e){switch(e.kind){case`tool.status`:return xPe(e);case`tool.thinking`:return SPe(e);case`tool.model`:return CPe(e);case`tool.login`:return wPe(e);case`tool.call`:case`tool.image`:case`tool.group.exploring`:case`tool.group.images`:return TPe(e);case`yielded.run`:return P5(e,`yielded-run`,`Yielded run`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`);case`execution.compaction`:return P5(e,`compaction`,e.status===`error`?`Compaction failed`:e.status===`running`?`Compacting`:`Compaction`,e.status===`error`?`red`:`magenta`);case`execution.command`:return P5(e,`command`,`Command`,e.status===`error`?`red`:`yellow`);case`error`:return P5(e,`error`,`Error`,`red`);default:return}}function xPe(e){let t=F5(e.output),n=I5(t,`activeModel`)??I5(t,`model`),r=hPe({session:{id:z5(t,`piboSessionId`)??z5(t,`sessionId`),title:z5(t,`sessionTitle`)??z5(t,`title`),profile:z5(t,`profile`)??z5(t,`activeAgentId`)??z5(t,`agentId`),status:B5(t,`disposed`)?`disposed`:z5(t,`sessionStatus`)},model:n?{provider:z5(n,`provider`),id:z5(n,`id`),label:z5(n,`label`)}:void 0,runtime:{state:B5(t,`disposed`)?`disposed`:B5(t,`processing`)?`processing`:B5(t,`streaming`)?`streaming`:z5(t,`mode`)??`idle`,connected:B5(t,`connected`),queuedMessages:DPe(t,`queuedMessages`),processing:B5(t,`processing`),streaming:B5(t,`streaming`),disposed:B5(t,`disposed`)},cwd:z5(t,`cwd`),contextUsage:I5(t,`contextUsage`),providerUsage:I5(t,`providerUsage`),tools:{enabled:R5(t,`enabledTools`),active:R5(t,`activeTools`)},thinking:z5(t,`thinkingLevel`)?{level:z5(t,`thinkingLevel`)}:void 0,fastMode:B5(t,`fastMode`),warnings:R5(t,`warnings`),errors:R5(t,`errors`),message:z5(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 SPe(e){let t=F5(e.output),n=z5(t,`level`)??`unknown`,r=t?.supported!==!1,i=R5(t,`availableLevels`);return{id:e.id,kind:`thinking`,title:`Thinking`,status:e.status,tone:r?`yellow`:`red`,rows:[{label:`Current`,value:j5(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 CPe(e){let t=L5(F5(e.output),`providers`),n=t.flatMap(e=>{let t=z5(e,`id`)??z5(e,`provider`)??`provider`,n=z5(e,`label`)??z5(e,`name`)??t;return L5(e,`models`).map(e=>{let r=z5(e,`id`)??`model`,i=z5(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 wPe(e){let t=L5(F5(e.output),`providers`),n=t.map(e=>{let t=z5(e,`id`)??`provider`;return{id:`login:${t}`,label:z5(e,`name`)??z5(e,`label`)??t,action:`login.selectProvider`,value:t,description:R5(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 TPe(e){return P5(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 P5(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?``:` ${EPe(e.functionCall.input)}`}`:``}`.trim();return t?[{value:j5(t)}]:[]}),a=e.lines.length===0&&typeof e.output==`string`&&e.output.trim()?[{value:j5(e.output.trim())}]:[],o=[e.error?{label:`Error`,value:j5(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 EPe(e){try{return JSON.stringify(e)}catch{return String(e)}}function F5(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 I5(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function L5(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)):[]}function R5(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function z5(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function DPe(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function B5(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function OPe(e,t){return e?ZPe(V5(e.nodes).sort((e,t)=>t4(e.node,t.node)).filter(e=>e.node.type!==`agent.turn`&&(t.showThinking||e.node.type!==`model.reasoning`)).map(e=>kPe(e.node,e.turnId))).map(e=>e.row):[]}function V5(e,t){let n=[];for(let r of e)r.type!==`agent.turn`&&n.push({node:r,turnId:t}),n.push(...V5(r.children,r.type===`agent.turn`?r.id:t));return n}function kPe(e,t){let n;switch(e.type){case`user.message`:n={row:jPe(e),turnId:t};break;case`assistant.message`:n={row:MPe(e),turnId:t};break;case`model.reasoning`:n={row:NPe(e),turnId:t};break;case`tool.call`:n=PPe(e,t);break;case`tool.result`:n=FPe(e,t);break;case`agent.delegation`:n={row:LPe(e),turnId:t};break;case`agent.async`:n={row:RPe(e),turnId:t};break;case`yielded.run`:n={row:zPe(e),turnId:t};break;case`execution.command`:n={row:BPe(e),turnId:t};break;case`execution.compaction`:n={row:U5(e),turnId:t};break;case`error`:n={row:YPe(e),turnId:t};break;case`agent.turn`:n={row:{id:e.id,kind:`error`,status:`neutral`,lines:[],sourceNodeIds:[e.id]},turnId:t};break}return{...n,row:{...n.row,...APe(e)}}}function APe(e){return{eventId:e.eventId,runId:e.runId,orderSource:e.source,orderStreamId:e.orderKey?.streamId,orderStreamFrameIndex:e.orderKey?.streamFrameIndex}}function jPe(e){let t=s7(e.output)||s7(e.summary)||e.title;return{id:e.id,kind:`message.user`,status:i7(e.status),lines:[{prefix:`prompt`,tokens:[o7(t)]}],sourceNodeIds:[e.id],forkEntryId:e.entryId,output:t}}function MPe(e){return{id:e.id,kind:`message.assistant`,status:i7(e.status),lines:[],sourceNodeIds:[e.id],output:s7(e.output)||s7(e.summary)||``,error:e.error}}function NPe(e){let t=t7(e.output??e.summary);return{id:e.id,kind:`reasoning`,status:i7(e.status),lines:[{prefix:`bullet`,tokens:[o7(e.status===`running`?`Thinking`:`Thought`,`amber`,`semibold`)]}],sourceNodeIds:[e.id],markdown:t}}function PPe(e,t){let n=r7(e.input);if(n&&oFe(e.title))return{row:JPe(e,n),turnId:t,exploring:void 0};let r=K5(e);if(r)return{row:H5(e,r),turnId:t,image:r.groupable?r.detail:void 0};let i=$5(e.error??e.output,5,e.error?`red`:`dim`);return{row:{id:e.id,kind:`tool.call`,status:i7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[o7(cFe(e.status),a7(e.status),`semibold`),o7(` `)],functionCall:{name: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:e7(i,e.error?`error`:`output`)},turnId:t,exploring:aFe(e)}}function H5(e,t){let n=i7(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:[o7(t.verb,a7(e.status),`semibold`)]},{prefix:`detail`,tokens:[o7(r,e.status===`error`?`red`:`cyan`)]}],sourceNodeIds:[e.id],input:J5(e.input),output:t.summary,error:e.error,expandable:e.input!==void 0||t.summary!==void 0||!!e.error}}function FPe(e,t){let n=K5(e);return n?{row:H5(e,n),turnId:t,image:n.groupable?n.detail:void 0}:{row:IPe(e),turnId:t}}function IPe(e){let t=$5(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`tool.call`,status:i7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[o7(e.status===`error`?`Tool failed`:`Returned`,a7(e.status),`semibold`),o7(` ${e.title}`)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:e7(t,e.error?`error`:`output`)}}function LPe(e){let t=s7(c7(e.input)?e.input.subagentName:void 0)||e.summary||e.title,n=n7((c7(e.input)?e.input.arguments:void 0)??e.input),r=n?[{prefix:`detail`,tokens:[o7(n,`dim`)]}]:[];return{id:e.id,kind:`agent.delegation`,status:i7(e.status),lines:[{prefix:`bullet`,tokens:[o7(lFe(e.status),a7(e.status),`semibold`),o7(` ${t}`,`cyan`)]},...r],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}}function RPe(e){let t=$5(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`agent.async`,status:i7(e.status),lines:[{prefix:`bullet`,tokens:[o7(uFe(e.status),a7(e.status),`semibold`),o7(` ${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:e7(t,e.error?`error`:`output`)}}function zPe(e){let t=$5(e.output,5);return{id:e.id,kind:`yielded.run`,status:i7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[o7(e.status===`running`?`Waiting on runs`:`Run update`,a7(e.status),`semibold`),o7(e.summary?` ${e.summary}`:``)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:e7(t,`output`)}}function U5(e){let t=e.status===`running`?`Compacting`:e.status===`error`?`Compaction failed`:s7(e.summary)||`Compacted`;return{id:e.id,kind:`execution.compaction`,status:i7(e.status),lines:[{prefix:`bullet`,tokens:[o7(t,a7(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 BPe(e){if(e.title===`status`)return VPe(e);if(e.title===`thinking`)return HPe(e);if(e.title===`fast_mode`)return UPe(e);if(e.title===`login`&&KPe(e.output))return WPe(e);if(e.title===`model`&&qPe(e.output))return GPe(e);r7(e.output)??r7(e.input)??e.title;let t=$5(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:i7(e.status),lines:[{prefix:`bullet`,tokens:[o7(`Command`,`yellow`,`semibold`),o7(` /${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:e7(t,e.error?`error`:`output`)}}function VPe(e){return{id:e.id,kind:`tool.status`,status:i7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function HPe(e){return{id:e.id,kind:`tool.thinking`,status:i7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function UPe(e){let t=c7(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:i7(e.status),lines:[{prefix:`bullet`,tokens:[o7(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function WPe(e){return{id:e.id,kind:`tool.login`,status:i7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function GPe(e){return{id:e.id,kind:`tool.model`,status:i7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function KPe(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 qPe(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 JPe(e,t){let n=$5(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:i7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[o7(e.status===`running`?`Running`:`Ran`,a7(e.status),`semibold`),o7(` `),...sFe(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:e7(n,e.error?`error`:`output`)}}function YPe(e){return{id:e.id,kind:`error`,status:`error`,errorKind:`system`,lines:[{prefix:`bullet`,tokens:[o7(e.title||`Error`,`red`,`bold`),o7(e.error?` ${e.error}`:``,`red`)]},...XPe(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 XPe(e){return c7(e)?[[`Class`,s7(e.errorClass)??s7(e.category)],[`Code`,s7(e.code)??s7(e.providerCode)],[`Origin`,s7(e.origin)],[`Provider`,[s7(e.api),s7(e.provider),s7(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:[o7(`${e}: `,`dim`),o7(t,`red`)]})):[]}function ZPe(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],i=W5(r);if(!i){t.push(r);continue}let a=[r],o=n+1;for(;o<e.length&&W5(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`?$Pe(a):QPe(a),turnId:r.turnId}),n=o-1}return t}function W5(e){if(e.image)return`images`;if(e.exploring)return`exploring`}function QPe(e){let t=G5(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:[o7(s===`running`?`Exploring`:s===`error`?`Exploring failed`:`Explored`,a7(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[o7(e.label,e.status===`error`?`red`:`dim`)]})),...r>0?[{prefix:`continuation`,tokens:[o7(`+${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 $Pe(e){let t=G5(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:[o7(s===`running`?`Viewing images`:s===`error`?`Image reads failed`:`Viewed images`,a7(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[o7(e.label,e.status===`error`?`red`:`cyan`)]})),...r>0?[{prefix:`continuation`,tokens:[o7(`+${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),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function G5(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,linkedPiboSessionId:e.row.linkedPiboSessionId,previewOmission:e.row.previewOmission}})}function K5(e){let t=(e.title??``).trim().toLowerCase(),n=c7(e.input)?e.input:void 0,r=c7(e.output)?e.output:void 0,i=iFe(r,`details`),a=t===`codex_image_generation`?tFe(i)??nFe(n):void 0,o=a?s7(i?.savedPath)??X5(i):X5(n)??X5(i)??X5(r),s=a?s7(i?.artifactId):void 0,c=Z5(n),l=q5(e.output),u=Y5(t,[`view_image`,`image`,`screenshot`]);if(!l.length&&!u&&!a)return;let d=l.map(e=>e.mimeType).find(e=>!!e),f=Math.max(1,l.length),p={type:l.length>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?s7(i?.model):void 0,referencedImageCount:a?Q5(i?.referencedImageCount):void 0,query:c,mimeType:d,count:f>1?f:void 0,detail:l.length?`Image data hidden in terminal view.`:`Image path only; binary data is hidden in terminal view.`},m=o??s??c??d??`image`,h=a?rFe(e.status,a):eFe(e.status,f);return{count:f,path:o,artifactId:s,query:c,mimeType:d,verb:h,groupable:!a,summary:p,detail:{id:e.id,label:`${h} ${m}`,status:i7(e.status),input:J5(e.input),output:p,error:e.error}}}function q5(e,t=0,n=new Set){if(t>5||typeof e!=`object`||!e||n.has(e))return[];if(n.add(e),Array.isArray(e))return e.flatMap(e=>q5(e,t+1,n));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`||c7(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=[];return`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),s.flatMap(e=>q5(e,t+1,n))}function J5(e){if(Array.isArray(e))return e.map(J5);if(!c7(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]=J5(r)}return t}function eFe(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 tFe(e){let t=s7(e?.operation);return t===`generate`||t===`edit`?t:void 0}function nFe(e){if(!e)return;let t=e.referenced_image_paths;return Array.isArray(t)&&t.length>0||Q5(e.num_last_images_to_include)!==void 0?`edit`:`generate`}function rFe(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 iFe(e,t){let n=e?.[t];return c7(n)?n:void 0}function aFe(e){let t=(e.title??``).trim().toLowerCase(),n=c7(e.input)?e.input:void 0;if(Y5(t,[`read`,`open`]))return{id:e.id,label:`Read ${X5(n)??n7(e.input)}`,status:i7(e.status),input:e.input,output:e.output,error:e.error};if(Y5(t,[`list`,`ls`,`glob`]))return{id:e.id,label:`List ${X5(n)??n7(e.input)}`,status:i7(e.status),input:e.input,output:e.output,error:e.error};if(Y5(t,[`search`,`find`,`grep`,`rg`])){let t=Z5(n),r=X5(n);return{id:e.id,label:`Search ${t??n7(e.input)}${r?` in ${r}`:``}`,status:i7(e.status),input:e.input,output:e.output,error:e.error}}}function Y5(e,t){return t.some(t=>e===t||e.startsWith(`${t}_`)||e.endsWith(`_${t}`)||e.includes(t))}function X5(e){if(e)for(let t of[`path`,`file`,`filePath`,`filepath`,`url`,`uri`,`cwd`,`pattern`,`glob`]){let n=s7(e[t]);if(n)return n}}function Z5(e){if(e)for(let t of[`query`,`pattern`,`text`,`name`,`q`,`regex`]){let n=s7(e[t]);if(n)return n}}function Q5(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function $5(e,t,n=`dim`,r=160){let i={lines:[],visibleLineCount:0,omittedLineCount:0,totalLineCount:0,maxVisibleLineCount:t},a=t7(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:[o7(e,n)]}));return c>0&&l.push({prefix:`continuation`,tokens:[o7(`+${c} more lines`,`dim`,`normal`,!0)]}),{lines:l,visibleLineCount:s.length,omittedLineCount:c,totalLineCount:o.length,maxVisibleLineCount:t}}function e7(e,t){if(!(e.omittedLineCount<=0))return{source:t,visibleLineCount:e.visibleLineCount,omittedLineCount:e.omittedLineCount,totalLineCount:e.totalLineCount,maxVisibleLineCount:e.maxVisibleLineCount}}function t7(e){let t=g5(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 n7(e){return(typeof e==`string`?e:t7(e)).replace(/\s+/g,` `).trim()}function oFe(e){let t=(e??``).trim().toLowerCase();return t===`shell`||t===`bash`||t===`terminal`}function r7(e){if(c7(e))for(let t of[`cmd`,`command`,`script`]){let n=s7(e[t]);if(n)return n}}function sFe(e){let t=e.match(/\s+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s]+/g)??[e],n=!1;return t.map(e=>/^\s+$/.test(e)?o7(e):/^(?:&&|\|\||[|;<>]|2>&1)$/.test(e)?o7(e,`red`,`semibold`):e.startsWith(`-`)?o7(e,`magenta`):e.startsWith(`$`)||e.includes(`=`)?o7(e,`yellow`):/^['"]/.test(e)?o7(e,`green`):n?e.includes(`/`)||e.startsWith(`.`)?o7(e,`cyan`):o7(e,`default`):(n=!0,o7(e,`green`,`semibold`)))}function cFe(e){return e===`running`?`Calling`:e===`error`?`Call failed`:`Called`}function lFe(e){return e===`running`?`Spawning`:e===`error`?`Spawn failed`:`Spawned`}function uFe(e){return e===`running`?`Waiting for`:`Finished waiting for`}function i7(e){return e===`running`?`running`:e===`error`?`error`:`done`}function a7(e){return e===`running`?`cyan`:e===`error`?`red`:e===`done`?`green`:`default`}function o7(e,t=`default`,n=`normal`,r=!1){return{text:e,tone:t,weight:n,italic:r}}function s7(e){return typeof e==`string`&&e.trim().length?e:void 0}function c7(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function dFe(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,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 l7(e,t,n){return n?{id:e,label:t,value:n}:void 0}function u7({field:e,icon:t}){let n=t===`session`?ms:us;return(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,z.jsx)(n,{size:11,className:`shrink-0 text-[#737373]`}),(0,z.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,z.jsx)(`span`,{className:`truncate font-mono ${e.id===`session`?`text-[#38bdf8]`:`text-[#d4d4d4]`}`,children:e.value})]})}function d7({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,z.jsxs)(`div`,{className:`mt-3 space-y-1`,"data-shared-progress":e.id,"data-shared-progress-state":e.state,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:t??e.label}),(0,z.jsx)(`span`,{className:`font-mono text-[#d4d4d4]`,children:e.state===`available`?e.text:`unavailable`})]}),e.state===`available`?(0,z.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,z.jsx)(`div`,{className:`h-full rounded-full ${r} transition-all`,style:{width:`${Math.min(Math.max(n,0),100)}%`}})}):null]})}function fFe(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 pFe({row:e}){let t=dFe(e.output),n=bPe(e),r=n?.kind===`status`?n.statusView:void 0,[i,a]=(0,R.useState)(!1);if(!t||!r)return(0,z.jsx)(`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,z.jsx)(`div`,{className:`text-[#737373]`,children:`Status (unparseable)`})});let o=new Map(r.fields.map(e=>[e.id,e])),s=o.get(`session`)??l7(`session`,`Session`,t.piboSessionId),c=o.get(`cwd`)??l7(`cwd`,`CWD`,t.cwd),l=r.progress.find(e=>e.id===`context`),u=r.progress.filter(e=>e.id.startsWith(`provider`)),d=t.providerUsage?.limits.length?t.providerUsage.limits:void 0,f=t.enabledTools??t.activeTools??[],p=r.fields.filter(e=>!new Set([`session`,`cwd`]).has(e.id)),m=t.providerUsage?.provider?`${t.providerUsage.provider} quota`:`Provider quota`;return(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(Co,{size:14,className:`text-[#22c55e]`}),(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:r.title})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-1.5 sm:grid-cols-2`,children:[s?(0,z.jsx)(u7,{field:s,icon:`session`}):null,c?(0,z.jsx)(u7,{field:c,icon:`cwd`}):null,p.slice(0,8).map(e=>(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,z.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,z.jsx)(`span`,{className:`truncate font-mono text-[#d4d4d4]`,children:e.value})]},e.id))]}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[t.processing?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,z.jsx)(es,{size:10}),` Processing`]}):null,t.streaming?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,z.jsx)(Co,{size:10}),` Streaming`]}):null,typeof t.queuedMessages==`number`&&t.queuedMessages>0?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[11px] text-[#d4d4d4]`,children:[(0,z.jsx)(vs,{size:10}),` Queued: `,t.queuedMessages]}):null,t.disposed?(0,z.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]}),l?(0,z.jsx)(d7,{progress:l,label:`Context Usage`}):null,u.length?(0,z.jsxs)(`div`,{className:`mt-3 space-y-1.5 border-t border-[#2a2a2a] pt-2`,"data-shared-provider-progress":u.length,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-[#737373]`,"data-shared-status-field":`provider-quota`,children:[(0,z.jsx)(ds,{size:11}),(0,z.jsxs)(`span`,{children:[m,t.providerUsage?.planType?` (${t.providerUsage.planType})`:``]})]}),d?d.map(e=>{let t=fFe(e.resetsAt);return(0,z.jsxs)(`div`,{className:`space-y-1`,"data-shared-progress":`provider-limit:${e.label}`,"data-shared-progress-state":`available`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#a3a3a3]`,children:e.label}),(0,z.jsxs)(`span`,{className:`shrink-0 font-mono text-[#d4d4d4]`,children:[e.remainingPercent.toFixed(0),`% left`,t?` · resets ${t}`:``]})]}),(0,z.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,z.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??``}`)}):u.map(e=>(0,z.jsx)(d7,{progress:e},e.id)),t.providerUsage?.credits?(0,z.jsxs)(`div`,{className:`text-[11px] text-[#a3a3a3]`,"data-shared-status-field":`provider-credits`,children:[`Credits: `,t.providerUsage.credits.unlimited?`unlimited`:t.providerUsage.credits.balance??`available`]}):null]}):null,r.warnings.length||r.errors.length?(0,z.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-[#2a2a2a] pt-2`,children:[r.warnings.map((e,t)=>(0,z.jsxs)(`div`,{"data-shared-status-warning":!0,className:`text-[11px] text-[#facc15]`,children:[`⚠ `,e]},`warning-${t}`)),r.errors.map((e,t)=>(0,z.jsxs)(`div`,{"data-shared-status-error":!0,className:`text-[11px] text-[#ef4444]`,children:[`✕ `,e]},`error-${t}`))]}):null,f.length>0?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1.5 text-[11px] text-[#737373] hover:text-[#d4d4d4]`,children:[(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i?`▾`:`▸`}),(0,z.jsxs)(`span`,{children:[`Enabled tools (`,f.length,`)`]})]}),i?(0,z.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:f.map(e=>(0,z.jsx)(`span`,{className:`inline-block rounded-sm border border-[#2a2a2a] bg-[#0b0b0b] px-1.5 py-0.5 font-mono text-[11px] text-[#a3a3a3]`,children:e},e))}):null]}):null]})}function mFe(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 hFe(e){return Xq.includes(e)?e:void 0}function gFe({row:e,onLevelSelect:t}){let n=mFe(e.output);return n?(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(Po,{size:14,className:`text-[#f59e0b]`}),(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:`Thinking`}),n.supported===!1?(0,z.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,z.jsx)(Qs,{size:10}),` Unsupported`]}):(0,z.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,z.jsx)(Ro,{size:10}),` Supported`]})]}),(0,z.jsxs)(`div`,{className:`grid gap-1.5 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Current:`}),(0,z.jsx)(`span`,{className:`font-mono font-semibold text-[#f59e0b]`,children:n.level??`unknown`})]}),n.availableLevels.length?(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,z.jsx)(`span`,{className:`mr-1 text-[#737373]`,children:`Available:`}),n.availableLevels.map(e=>{let r=hFe(e),i=n.supported===!1||!r||!t;return(0,z.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,z.jsxs)(`div`,{className:`text-[#737373]`,children:[`Click a level or use `,(0,z.jsx)(`span`,{className:`text-[#f59e0b]`,children:`/thinking <level>`}),`.`]})]})]}):(0,z.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,z.jsx)(`div`,{className:`text-[#737373]`,children:`Thinking (unparseable)`})})}var _Fe=180,vFe={index:`LAST`,align:`end`},yFe={top:2400,bottom:2400},bFe=84,xFe=6;function SFe({traceView:e,selectedTrace:t,isLoading:n,showThinking:r,expandThinking:i,sessionAgentProfile:a,sessionActiveModel:o,selectedSessionStatus:s,selectedSessionSignal:c,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,agentProfiles:f,sessionProfileChangeDisabled:p,onSessionAgentProfileChange:m,onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:v}){let y=(0,R.useMemo)(()=>OPe(e,{showThinking:r}),[r,e]),[b,x]=(0,R.useState)(new Set),[S,C]=(0,R.useState)(null),w=(0,R.useRef)({}),T=y.filter(e=>e.status===`running`).length,E=y.filter(e=>m7(e,`user`)).length,D=y.filter(e=>m7(e,`tool`)).length,O=y.filter(e=>m7(e,`system`)).length,k=c?c.isTreeActive:s===`running`||T>0||t?.status===`UNSET`,A=FNe({itemCount:y.length,resetKey:e?.piboSessionId,contentKey:y,atBottomThreshold:_Fe});(0,R.useEffect)(()=>{x(e=>OFe(e,y,i))},[i,y]),(0,R.useEffect)(()=>{let e=new Set(y.map(e=>e.id));C(t=>t&&e.has(t)?t:null);for(let t of[`system`,`tool`,`user`]){let n=w.current[t];n&&!e.has(n)&&delete w.current[t]}},[y]);let j=(0,R.useCallback)(e=>{let t=kFe(y,e,w.current[e]);t&&(w.current[e]=t.row.id,C(t.row.id),A.scrollToIndex(t.index,`start`,`fast-smooth`,{fromIndex:t.fromIndex,stagingAlign:e===`tool`?`end`:void 0}),AFe(t.row.id))},[y,A]),M=e=>{e.expandable&&x(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},N=(0,R.useCallback)((t,n)=>(0,z.jsx)(`div`,{className:`px-4`,children:(0,z.jsx)(wFe,{row:n,expanded:b.has(n.id),focused:S===n.id,piboSessionId:e?.piboSessionId??``,onToggle:()=>M(n),onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:v})}),[b,S,h,v,g,_,e?.piboSessionId]),P=(0,R.useMemo)(()=>({Footer:k?FFe:void 0}),[k]);return(0,z.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,children:[(0,z.jsx)(CFe,{errorCount:O,toolErrorCount:D,userMessageCount:E,onNavigate:j,sessionAgentProfile:a,sessionActiveModel:o,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,onOpenSession:g}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e?y.length?(0,z.jsx)(cNe,{ref:A.virtuosoRef,data:y,initialTopMostItemIndex:vFe,increaseViewportBy:yFe,defaultItemHeight:bFe,className:`min-h-0 h-full overflow-x-hidden font-mono text-[12px] leading-[1.45]`,computeItemKey:(e,t)=>t.id,scrollerRef:A.scrollerRef,atBottomStateChange:A.atBottomStateChange,atBottomThreshold:A.atBottomThreshold,followOutput:A.followOutput,totalListHeightChanged:A.totalListHeightChanged,alignToBottom:!0,components:P,itemContent:N},e.piboSessionId):(0,z.jsx)(C7,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m,message:`No visible trace rows yet.`}):(0,z.jsx)(C7,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m})}),A.isSticky?null:(0,z.jsx)(`button`,{type:`button`,onClick:()=>A.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,z.jsx)(zo,{size:18})})]})}function CFe({errorCount:e,toolErrorCount:t,userMessageCount:n,onNavigate:r,sessionAgentProfile:i,sessionActiveModel:a,sessionBreadcrumbs:o,originSession:s,derivedSessions:c,onOpenSession:l}){return(0,z.jsxs)(`div`,{className:`border-b border-[#2a2a2a] bg-[#111111] px-4 py-2 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i?(0,z.jsx)(x7,{tone:`neutral`,children:i}):null,a?(0,z.jsx)(x7,{tone:`purple`,children:a}):null,n>0?(0,z.jsxs)(x7,{tone:`cyan`,label:`${n} user messages · jump to previous user message`,onClick:()=>r(`user`),children:[n,(0,z.jsx)(Os,{size:12})]}):null,e>0?(0,z.jsxs)(x7,{tone:`red`,label:`${e} errors · jump to previous error`,onClick:()=>r(`system`),children:[e,(0,z.jsx)(Jo,{size:12})]}):null,t>0?(0,z.jsxs)(x7,{tone:`amber`,label:`${t} tool call errors · jump to previous tool error`,onClick:()=>r(`tool`),children:[t,(0,z.jsx)(ps,{size:12})]}):null,s?(0,z.jsxs)(f7,{onClick:()=>l(s.piboSessionId),children:[`Origin `,s.label]}):null,c.map(e=>(0,z.jsxs)(f7,{onClick:()=>l(e.piboSessionId),children:[`Derived `,e.label]},e.piboSessionId))]}),o.length?(0,z.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1 text-[#737373]`,children:o.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,z.jsx)(Bo,{size:12,className:`text-[#525252]`}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>l(e.piboSessionId),className:`hover:text-[#38bdf8]`,children:e.label})]},e.piboSessionId))}):null]})}function f7({children:e,onClick:t}){return(0,z.jsx)(`button`,{type:`button`,onClick:t,className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e})}function wFe({row:e,expanded:t,focused:n,piboSessionId:r,onToggle:i,onFork:a,onOpenSession:o,onThinkingLevelChange:s,onModelChanged:c}){let l=!t&&MFe(e),u=l?jFe(e):e.lines;return(0,z.jsxs)(`div`,{className:DFe(e,n),"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||h7(t)||i()}:void 0,onKeyDown:e.expandable?t=>{!e.expandable||h7(t)||(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),i())}:void 0,role:e.expandable?`button`:void 0,tabIndex:e.expandable||n?0:void 0,"aria-expanded":e.expandable?t:void 0,"aria-current":n?`true`:void 0,children:[(0,z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,z.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,z.jsx)(TFe,{row:e,visibleLines:u,collapseToolCallPreview:l,piboSessionId:r,onThinkingLevelChange:s,onModelChanged:c})}),(0,z.jsx)(EFe,{row:e,onFork:a,onOpenSession:o})]}),t?(0,z.jsx)(JNe,{row:e,onOpenSession:o}):null]})}function TFe({row:e,visibleLines:t,collapseToolCallPreview:n,piboSessionId:r,onThinkingLevelChange:i,onModelChanged:a}){return e.kind===`message.assistant`?(0,z.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalAssistantMessage`,children:(0,z.jsx)(`div`,{className:`compact-terminal-markdown`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`assistant-message`,children:(0,z.jsx)(zW,{streaming:e.status===`running`,children:typeof e.output==`string`?e.output:``})})}):e.kind===`tool.status`?(0,z.jsx)(pFe,{row:e}):e.kind===`tool.thinking`?(0,z.jsx)(gFe,{row:e,onLevelSelect:i}):e.kind===`tool.login`?(0,z.jsx)(uPe,{row:e,piboSessionId:r}):e.kind===`tool.model`?(0,z.jsx)(mPe,{row:e,piboSessionId:r,onModelChanged:a}):e.kind===`execution.compaction`&&e.status===`running`?(0,z.jsx)(LFe,{}):e.kind===`reasoning`&&e.markdown?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(p7,{lines:t,status:e.status,clampPreview:n}),(0,z.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalReasoningMarkdown`,children:(0,z.jsx)(`div`,{className:`compact-terminal-markdown compact-terminal-reasoning`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`reasoning`,children:(0,z.jsx)(zW,{streaming:e.status===`running`,children:e.markdown})})})]}):(0,z.jsx)(p7,{lines:t,status:e.status,clampPreview:n})}function p7({lines:e,status:t,clampPreview:n}){return e.map((e,r)=>(0,z.jsx)(ePe,{line:e,status:t,clampLines:n&&r===0?5:void 0},r))}function EFe({row:e,onFork:t,onOpenSession:n}){return(0,z.jsxs)(`div`,{className:`flex shrink-0 items-start gap-1 transition-opacity ${e.forkEntryId?`opacity-100`:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:[e.linkedPiboSessionId?(0,z.jsx)(S7,{label:`Open linked session`,onClick:()=>n(e.linkedPiboSessionId),children:`Open`}):null,e.forkEntryId?(0,z.jsxs)(S7,{label:`Fork from this user message`,onClick:()=>t(e.forkEntryId),children:[(0,z.jsx)(fs,{size:13}),`Fork`]}):null]})}function DFe(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===`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 OFe(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 zFe(e,r)?e:r}function m7(e,t){return t===`user`?e.kind===`message.user`:e.status===`error`?t===`tool`?e.errorKind===`tool`:e.errorKind!==`tool`:!1}function kFe(e,t,n){let r=e.map((e,t)=>({row:e,index:t})).filter(({row:e})=>m7(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 AFe(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 jFe(e){return e.kind===`tool.group.exploring`||e.kind===`tool.group.images`?e.lines.slice(0,xFe):e.lines}function MFe(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 h7(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 NFe=`Working...`,g7=33,PFe=126;function FFe(){let{chars:e,activeIndex:t}=IFe(NFe);return(0,z.jsx)(`div`,{className:`border-t border-[#141414] px-4 py-2`,role:`status`,"aria-live":`polite`,"aria-label":`Working`,children:(0,z.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre text-[#737373]`,children:`•`}),(0,z.jsx)(`span`,{className:`compact-terminal-working-scramble`,"aria-hidden":`true`,children:e.map((e,n)=>(0,z.jsx)(`span`,{className:n===t?`compact-terminal-working-scramble-active`:void 0,children:e},n))})]})})}function IFe(e){let t=(0,R.useMemo)(()=>Array.from(e),[e]),[n,r]=(0,R.useState)(()=>v7(t)),[i,a]=(0,R.useState)(0);return(0,R.useEffect)(()=>{let e=0,n=0,i=b7(),o=0;r(v7(t));let s=window.setInterval(()=>{if(o>0){o--;return}if(e>=t.length){e=0,n=0,i=b7(),r(v7(t)),a(0);return}let s=e,c=t[s]??` `;if(a(s),n++,n<i){r(e=>_7(e,s,y7(c)));return}r(e=>_7(e,s,c)),e++,n=0,i=b7(),e>=t.length&&(r(t),a(-1),o=18)},55);return()=>window.clearInterval(s)},[t]),{chars:n,activeIndex:i}}function _7(e,t,n){let r=[...e];return r[t]=n,r}function v7(e){return e.map(e=>y7(e))}function y7(e){let t=``;do{let e=g7+Math.floor(Math.random()*(PFe-g7+1));t=String.fromCharCode(e)}while(t===e);return t}function b7(){return 2+Math.floor(Math.random()*11)}function LFe(){let e=RFe();return(0,z.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre text-[#38bdf8]`,children:`•`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`font-semibold text-[#38bdf8]`,children:`Compacting`}),(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:e})]})]})}function RFe(){let[e,t]=(0,R.useState)(0);return(0,R.useEffect)(()=>{let e=window.setInterval(()=>t(e=>(e+1)%4),400);return()=>window.clearInterval(e)},[]),`.`.repeat(e)}function x7({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,z.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,z.jsx)(`span`,{className:i,title:t,"aria-label":t,children:r})}function S7({label:e,onClick:t,children:n}){return(0,z.jsx)(`button`,{type:`button`,onClick:t,"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-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:n})}function C7({isLoading:e,agentProfiles:t,disabled:n,onSelectAgentProfile:r,message:i}){return(0,z.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]`,children:[(0,z.jsx)(`div`,{children:e?`Loading trace…`:i??`No trace selected.`}),t.length?(0,z.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:t.map(e=>(0,z.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 zFe(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function BFe({traceView:e,isLoading:t,selectedSessionStatus:n,selectedSessionSignal:r,workflowProjectSession:i,workflowLifecycleEvents:a,sessionNodes:o,onOpenSession:s,onRefreshBootstrap:c,onError:l}){let u=i?QFe(i,e,n,r,a??[],o):null;return u?(0,z.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,z.jsxs)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-4`,children:[(0,z.jsx)(VFe,{model:u}),(0,z.jsx)(w7,{}),(0,z.jsx)(HFe,{model:u,onRefreshBootstrap:c,onError:l}),(0,z.jsx)(WFe,{model:u}),(0,z.jsx)(GFe,{model:u,onOpenSession:s}),(0,z.jsx)(KFe,{nodes:u.nodes,edges:u.edges}),(0,z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,z.jsx)(JFe,{model:u}),(0,z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,z.jsx)(YFe,{model:u}),(0,z.jsx)(XFe,{model:u}),(0,z.jsx)(ZFe,{model:u})]})]})]})}):(0,z.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,z.jsxs)(`div`,{className:`mx-auto flex max-w-4xl flex-col gap-4`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,z.jsx)(vs,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState`]}),(0,z.jsx)(`p`,{className:`mt-2 text-sm text-slate-400`,children:t?`Loading session trace…`:`This session is not linked to a workflow run, so no Workflow/XState projection is available.`})]}),(0,z.jsx)(w7,{})]})})}function VFe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,z.jsx)(vs,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState Projection`]}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2 text-xs`,children:[(0,z.jsx)(q7,{tone:`blue`,children:e.workflowId}),e.workflowRunId?(0,z.jsxs)(q7,{tone:`slate`,children:[`run `,X7(e.workflowRunId)]}):null,(0,z.jsx)(q7,{tone:yIe(e.status),children:e.state})]})]}),(0,z.jsxs)(`div`,{className:`min-w-0 text-right font-mono text-[11px] text-slate-500`,children:[(0,z.jsxs)(`div`,{className:`truncate`,children:[`session `,X7(e.piboSessionId)]}),e.latestStreamId===void 0?null:(0,z.jsxs)(`div`,{children:[`stream `,e.latestStreamId]})]})]}),(0,z.jsx)(`p`,{className:`mt-3 text-sm text-slate-400`,children:`Dedicated Project workflow execution surface. This view derives the current XState-style UI snapshot from project-session workflow linkage and live session state while keeping kernel records as durable truth.`})]})}function w7(){return(0,z.jsx)(`div`,{className:`rounded-sm border border-amber-500/30 bg-amber-500/10 p-4 text-sm`,children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-amber-200`,children:[(0,z.jsx)(Js,{size:14}),`Workflow IR source-of-truth boundary`]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-amber-100/80`,children:`Projects inspect configured sessions, workflow runs, and the XState-style projection derived from Pibo Workflow IR. Authoring stays in the Workflows tab; raw XState editing and inline executable code are not exposed here.`})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,z.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`IR: source of truth`}),(0,z.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`XState: projection only`})]})]})})}function HFe({model:e,onRefreshBootstrap:t,onError:n}){let r=e.workflowRunId?A7(e):void 0,i=`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`;return(0,z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,"aria-label":`Projects workflow execution shell`,children:[(0,z.jsx)(O7,{title:`Workflow configured-session view`,icon:(0,z.jsx)(xs,{size:14}),children:(0,z.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,z.jsx)(k7,{label:`selected workflow`,value:i}),(0,z.jsx)(k7,{label:`session state`,value:e.workflowRunId?`started`:`configured/not-started`}),(0,z.jsx)(k7,{label:`input keys`,value:String(e.configuration.inputKeys.length)}),(0,z.jsx)(k7,{label:`prompt overrides`,value:String(e.configuration.promptOverrideNodeIds.length)}),(0,z.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`Saved configuration is reviewed here before Start. Workflow selection and session overrides remain immutable for this configured Project session.`})]})}),(0,z.jsx)(O7,{title:`Workflow run view`,icon:(0,z.jsx)(Co,{size:14}),children:(0,z.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,z.jsx)(k7,{label:`run id`,value:e.workflowRunId?X7(e.workflowRunId):`not started`}),(0,z.jsx)(k7,{label:`status`,value:e.state}),(0,z.jsx)(k7,{label:`current node`,value:r?.label??`none`}),(0,z.jsx)(k7,{label:`output`,value:e.finalOutput?`available`:`empty`}),(0,z.jsx)(k7,{label:`error`,value:e.runtimeErrors.length?`${e.runtimeErrors.length} runtime errors`:e.validationErrors.length?`${e.validationErrors.length} validation diagnostics`:`none`}),(0,z.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This workflow run view container is the stable Project home for status, current node, output, and error sections.`})]})}),(0,z.jsx)(O7,{title:`Human action area`,icon:(0,z.jsx)(Xo,{size:14}),children:(0,z.jsx)(UFe,{model:e,onRefreshBootstrap:t,onError:n})})]})}function UFe({model:e,onRefreshBootstrap:t,onError:n}){let[r,i]=(0,R.useState)({}),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)({}),[l,u]=(0,R.useState)({}),d=(e,t)=>{i(n=>({...n,[e]:t}))},f=async(i,a)=>{if(!i.waitTokenId||!a.registered)return;let s=`${i.waitTokenId}:${a.id}`,l=a.kind??`resume`,d;if(l===`resume`){let e=r[i.waitTokenId]??(i.payloadRequirements?.required?`{}`:``);if(e.trim())try{d=JSON.parse(e)}catch{let e=[{code:`WorkflowRuntimeError.invalidHumanActionPayload`,message:`Resume payload must be valid JSON before it can be submitted.`,severity:`error`,path:`$.payload`,hint:`Enter JSON such as {"comment":"Approved"}.`}];c(t=>({...t,[i.waitTokenId]:e})),n?.(`Resume payload must be valid JSON.`);return}}o(s),c(e=>({...e,[i.waitTokenId]:[]}));try{await Nye(e.projectId,e.piboSessionId,{waitTokenId:i.waitTokenId,actionId:a.id,...a.kind?{kind:a.kind}:{},...d===void 0?{}:{payload:d}}),u(e=>({...e,[i.waitTokenId]:`${a.displayName} submitted.`})),n?.(null),await t?.()}catch(e){let t=pIe(e);c(e=>({...e,[i.waitTokenId]:t})),n?.(t[0]?.message??V7(e))}finally{o(null)}};return(0,z.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[e.pendingHumanActions.length?(0,z.jsx)(`div`,{className:`space-y-3`,children:e.pendingHumanActions.map(e=>{let t=[...e.diagnostics,...e.waitTokenId?s[e.waitTokenId]??[]:[]];return(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-amber-100`,"aria-label":`Pending workflow human action wait token`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:e.label}),(0,z.jsx)(`div`,{className:`mt-1 break-words text-[11px] leading-5 text-amber-100/80`,children:e.prompt})]}),(0,z.jsx)(`span`,{className:`shrink-0 rounded border border-amber-400/40 bg-[#0b0f14]/40 px-1.5 py-0.5 font-mono text-[10px] text-amber-100/70`,children:e.waitTokenId?X7(e.waitTokenId):e.source})]}),(0,z.jsxs)(`div`,{className:`mt-2 grid gap-2 text-[11px] text-amber-100/75`,children:[(0,z.jsx)(k7,{label:`human node`,value:e.humanNodeId??`unspecified`}),(0,z.jsx)(k7,{label:`payload`,value:e.payloadRequirements?.description??`No persisted payload schema.`}),e.expiresAt?(0,z.jsx)(k7,{label:`expires`,value:e.expiresAt}):null]}),e.payloadRequirements?.schema?(0,z.jsxs)(`div`,{className:`mt-2 rounded-sm border border-amber-400/25 bg-[#0b0f14]/50 p-2`,children:[(0,z.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider text-amber-100/70`,children:`Resume payload schema`}),(0,z.jsx)(vq,{value:e.payloadRequirements.schema,defaultExpandLevel:1,maxHeight:`10rem`,showControls:!1})]}):null,e.availableActions.some(e=>e.kind===`resume`)?(0,z.jsxs)(`label`,{className:`mt-3 block text-[11px] text-amber-100/80`,children:[(0,z.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Resume payload JSON`}),(0,z.jsx)(`textarea`,{className:`min-h-20 w-full rounded-sm border border-amber-500/30 bg-[#0b0f14] px-2 py-1.5 font-mono text-[11px] text-amber-50 outline-none focus:border-[#11a4d4]`,value:r[e.waitTokenId??e.id]??(e.payloadRequirements?.required?`{}`:``),onChange:t=>d(e.waitTokenId??e.id,t.target.value),placeholder:`{"comment":"Approved"}`})]}):null,(0,z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,"aria-label":`Workflow wait token actions`,children:e.availableActions.length?e.availableActions.map(t=>{let n=`${e.waitTokenId}:${t.id}`;return(0,z.jsx)(`button`,{type:`button`,disabled:!e.waitTokenId||!t.registered||a!==null,onClick:()=>void f(e,t),className:`rounded-sm border border-amber-400/40 bg-[#0b0f14]/70 px-2.5 py-1 text-[11px] font-semibold text-amber-100 transition hover:border-[#11a4d4] hover:text-[#8bdcf4] disabled:cursor-not-allowed disabled:opacity-50`,title:t.description??t.id,children:a===n?`Submitting…`:t.displayName},t.id)}):(0,z.jsx)(`span`,{className:`text-amber-100/60`,children:`No registered human actions are available for this wait token.`})}),e.waitTokenId&&l[e.waitTokenId]?(0,z.jsx)(`div`,{className:`mt-2 text-[11px] text-emerald-200`,children:l[e.waitTokenId]}):null,t.length?(0,z.jsx)(`div`,{className:`mt-2 space-y-1`,"aria-label":`Human action diagnostics`,children:t.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded border border-red-400/35 bg-red-500/15 p-2 text-[11px] leading-5 text-red-100`,children:[(0,z.jsx)(`div`,{children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-red-100/70`,children:[e.code,e.path?` · ${e.path}`:``]})]},`${e.code}:${t}`))}):null]},e.id)})}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-slate-500`,children:`No pending human action. Approval, rejection, resume, and cancel controls render here when a persisted workflow wait token exists.`}),(0,z.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This human action area lives inside the workflow run context, validates wait-token state and resume payloads, and stays separate from normal Terminal chat controls.`})]})}function WFe({model:e}){let t=e.workflowRunId?A7(e):void 0,n=[...e.runtimeErrors.map(e=>({...e,source:e.source??`runtime`})),...e.validationErrors.map(e=>({...e,source:e.source??`validation`}))].slice(0,8);return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow run inspection panel`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(ts,{size:14}),`Workflow run inspection`]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Status, current node, history, attempts, transfers, output, and errors are rendered from Project session and workflow run facts when a run is linked. The XState graph remains a visualization projection only.`})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2 text-[10px] uppercase tracking-wide`,children:[(0,z.jsx)(`span`,{className:`rounded border border-emerald-500/40 bg-emerald-500/10 px-2 py-1 text-emerald-200`,children:`kernel/run records: truth`}),(0,z.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1 text-amber-100`,children:`XState projection only`})]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-3`,children:[(0,z.jsxs)(T7,{title:`Status`,badge:e.state,icon:(0,z.jsx)(Co,{size:14}),children:[(0,z.jsx)(E7,{label:`run id`,value:e.workflowRunId?X7(e.workflowRunId):`not started`}),(0,z.jsx)(E7,{label:`status`,value:e.state}),(0,z.jsx)(E7,{label:`record source`,value:e.workflowRunId?`Project workflow run id`:`no run record yet`})]}),(0,z.jsxs)(T7,{title:`Current node`,badge:t?.status??`none`,icon:(0,z.jsx)(Rs,{size:14}),children:[(0,z.jsx)(E7,{label:`node`,value:t?.label??`none`}),(0,z.jsx)(E7,{label:`node id`,value:t?.id??`none`}),(0,z.jsx)(E7,{label:`source`,value:`project/session run cursor`})]}),(0,z.jsx)(T7,{title:`Run history`,badge:`${e.runHistory.length}`,icon:(0,z.jsx)(hs,{size:14}),children:e.runHistory.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.runHistory.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:X7(e.id)}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${Y7(e.status)}`,children:e.status})]}),(0,z.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.currentNodeId?`current ${e.currentNodeId}`:`no current node`,` · `,e.source]}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-600`,children:[`updated `,e.updatedAt]})]},e.id))}):(0,z.jsx)(D7,{children:e.workflowRunId?`No workflow run history for this selected Project session yet.`:`No current run attempts; this configured Project session has not been started.`})})]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 lg:grid-cols-2`,children:[(0,z.jsx)(T7,{title:`Node attempts`,badge:`${e.nodeAttempts.length}`,icon:(0,z.jsx)(xs,{size:14}),children:e.nodeAttempts.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.nodeAttempts.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.label}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:[e.nodeId,` · attempt `,e.attempt]})]}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${Y7(e.status)}`,children:e.status})]}),(0,z.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.kind,` · `,e.source]})]},e.id))}):(0,z.jsx)(D7,{children:e.workflowRunId?`No node attempts recorded for this workflow run yet.`:`No current node attempts; Start has not created a workflow run.`})}),(0,z.jsx)(T7,{title:`Edge transfers`,badge:`${e.edgeTransfers.length}`,icon:(0,z.jsx)(fs,{size:14}),children:e.edgeTransfers.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.edgeTransfers.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:e.edgeId}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${Y7(e.status)}`,children:e.status})]}),(0,z.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.source,e.createdAt?` · ${e.createdAt}`:``]})]},e.id))}):(0,z.jsx)(D7,{children:`No edge transfers recorded for this workflow run yet.`})}),(0,z.jsx)(T7,{title:`Output`,badge:e.finalOutput?`available`:`empty`,icon:(0,z.jsx)(Ko,{size:14}),children:e.finalOutput?(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsx)(`div`,{className:`mb-2 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}),(0,z.jsx)(vq,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`12rem`,showControls:!1})]}):(0,z.jsx)(D7,{children:`No workflow output has been recorded for this run yet.`})}),(0,z.jsx)(T7,{title:`Error`,badge:n.length?`${n.length}`:`none`,icon:(0,z.jsx)(Js,{size:14}),children:n.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2 text-xs text-red-100`,children:[(0,z.jsx)(`div`,{className:`break-words`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,z.jsx)(`span`,{children:e.code}):null,e.source?(0,z.jsx)(`span`,{children:e.source}):null]})]},e.id))}):(0,z.jsx)(D7,{children:`No workflow run errors are recorded.`})})]})]})}function GFe({model:e,onOpenSession:t}){let n=N7(e.definitionLink);return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow navigation links`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(rs,{size:14}),`Workflow navigation links`]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Use these run-view links to move between real nested workflow sessions and the Workflows tab definition. Snapshot-only history is shown when the live definition is deleted or unavailable.`})]}),e.definitionLink.status===`live`&&n?(0,z.jsxs)(`a`,{className:`inline-flex shrink-0 items-center justify-center gap-1 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100`,href:n,children:[(0,z.jsx)(rs,{size:13}),`Open live workflow definition`]}):null]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-2`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Nested workflow child session links`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Nested workflow child sessions`}),(0,z.jsx)(`span`,{className:`rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:e.nestedSessionLinks.length})]}),e.nestedSessionLinks.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.nestedSessionLinks.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>t(e.piboSessionId),className:`w-full rounded-sm border border-slate-800 bg-[#0b0f14] p-2 text-left transition hover:border-[#11a4d4]/60 hover:bg-[#102331]`,children:(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.title}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:X7(e.piboSessionId)})]}),(0,z.jsx)(`span`,{className:`rounded border border-[#11a4d4]/40 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#8bdcf4]`,children:`open session`})]})},e.piboSessionId))}):(0,z.jsx)(D7,{children:`No nested workflow child sessions are linked under this selected Project session yet.`})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Workflow definition link state`,children:[(0,z.jsx)(`div`,{className:`mb-3 text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Workflow definition link`}),e.definitionLink.status===`live`&&n?(0,z.jsxs)(`div`,{className:`rounded-sm border border-emerald-500/35 bg-emerald-500/10 p-3 text-xs leading-5 text-emerald-100`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:`Live workflow definition exists`}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-emerald-100/80`,children:F7(e.definitionLink)}),e.definitionLink.definitionHash?(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-emerald-100/60`,children:[`snapshot `,X7(e.definitionLink.definitionHash)]}):null]}):(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:`Definition deleted — snapshot-only definition-deleted state`}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-amber-100/80`,children:F7(e.definitionLink)}),(0,z.jsx)(`div`,{className:`mt-1 text-amber-100/80`,children:e.definitionLink.tombstoneLabel??`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}),e.definitionLink.definitionHash?(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-amber-100/60`,children:[`snapshot `,X7(e.definitionLink.definitionHash)]}):null]})]})]})]})}function T7({title:e,badge:t,icon:n,children:r}){return(0,z.jsxs)(`section`,{className:`min-w-0 rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":e,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:n}),e]}),(0,z.jsx)(`span`,{className:`shrink-0 rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:t})]}),r]})}function E7({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 py-2 first:pt-0 last:border-b-0 last:pb-0`,children:[(0,z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-slate-500`,children:e}),(0,z.jsx)(`span`,{className:`min-w-0 max-w-[14rem] truncate text-right font-mono text-xs text-slate-300`,title:t,children:t})]})}function D7({children:e}){return(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-800 bg-[#0b0f14] p-3 text-xs leading-5 text-slate-500`,children:e})}function O7({title:e,icon:t,children:n}){return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,"aria-label":e,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:t}),e]}),n]})}function k7({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,z.jsx)(`span`,{className:`uppercase tracking-wide text-slate-500`,children:e}),(0,z.jsx)(`span`,{className:`min-w-0 max-w-[12rem] truncate text-right font-mono text-slate-300`,title:t,children:t})]})}function A7(e){return e.nodes.find(e=>e.status===`active`||e.status===`waiting`)??e.nodes[0]}function KFe({nodes:e,edges:t}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-4`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Rs,{size:14}),`Visual State Flow`]}),(0,z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_auto_1fr_auto_1fr]`,children:e.map((e,n)=>(0,z.jsx)(qFe,{node:e,edge:t[n]},e.id))})]})}function qFe({node:e,edge:t}){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`rounded-sm border p-3 ${J7(e.status)}`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,z.jsx)(K7,{status:e.status}),(0,z.jsx)(`div`,{className:`min-w-0 truncate text-sm font-semibold text-slate-100`,children:e.label})]}),(0,z.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]}),t?(0,z.jsx)(`div`,{className:`hidden items-center justify-center text-center text-[10px] uppercase tracking-wide text-slate-500 md:flex`,children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(fs,{size:14,className:`mx-auto mb-1 text-[#11a4d4]`}),t.label]})}):null]})}function JFe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Co,{size:14}),`Current UI Snapshot`]}),(0,z.jsx)(vq,{value:e.snapshot,showControls:!1})]})}function YFe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(xs,{size:14}),`Node Statuses`]}),(0,z.jsxs)(`span`,{className:`font-mono text-[11px] text-slate-500`,children:[e.nodes.length,` nodes`]})]}),(0,z.jsx)(`div`,{className:`space-y-2`,children:e.nodes.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border px-3 py-2 ${J7(e.status)}`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,z.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:(0,z.jsx)(K7,{status:e.status})}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-sm font-semibold text-slate-100`,children:e.label}),(0,z.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-slate-500`,children:e.id})]})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${bIe(e.status)}`,children:e.status}),(0,z.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]})]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]},e.id))}),(0,z.jsx)(`p`,{className:`mt-3 text-xs text-slate-500`,children:`Node status is reconstructed from the workflow run linkage and live session state; persisted kernel records remain the durable source of truth.`})]})}function XFe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Ko,{size:14}),`Final Output & Validation`]}),(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Final output`}),e.finalOutput?(0,z.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}):null]}),e.finalOutput?(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:(0,z.jsx)(vq,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`14rem`,showControls:!1})}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No final workflow output is available yet. Completed workflow-backed sessions show the final assistant output here.`})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Validation errors`}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 font-mono text-[10px] ${e.validationErrors.length?`border-red-500/40 bg-red-500/10 text-red-300`:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`}`,children:e.validationErrors.length?`${e.validationErrors.length} found`:`none`})]}),e.validationErrors.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.validationErrors.map(e=>(0,z.jsx)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2`,children:(0,z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 text-xs text-red-200`,children:[(0,z.jsx)(Js,{size:14,className:`mt-0.5 shrink-0 text-red-300`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`break-words`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,z.jsx)(`span`,{children:e.code}):null,e.path?(0,z.jsx)(`span`,{children:e.path}):null,e.source?(0,z.jsx)(`span`,{children:e.source}):null]})]})]})},e.id))}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No workflow validation diagnostics were found in the current session trace.`})]})]})]})}function ZFe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Yo,{size:14}),`Projection Facts`]}),(0,z.jsxs)(`dl`,{className:`space-y-3`,children:[(0,z.jsx)(j7,{label:`projection kind`,value:`pibo.workflow.xstateUiModel`}),(0,z.jsx)(j7,{label:`schema`,value:`v1`}),(0,z.jsx)(j7,{label:`durable truth`,value:`kernel`}),(0,z.jsx)(j7,{label:`private payloads`,value:`not exposed`}),(0,z.jsx)(j7,{label:`states`,value:String(e.nodes.length)}),(0,z.jsx)(j7,{label:`transitions`,value:String(e.edges.length)}),(0,z.jsx)(j7,{label:`trace`,value:e.traceVersion??`pending`})]})]})}function j7({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,z.jsx)(`dt`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:e}),(0,z.jsx)(`dd`,{className:`min-w-0 truncate text-right font-mono text-xs text-slate-300`,children:t})]})}function QFe(e,t,n,r,i,a){if(!mIe(e))return null;let o=W7(e,n),s=hIe(e,n),c=gIe(s),l=uIe(t,s),u=[...fIe(t),...dIe(e,i)],d=rIe(e,o,c),f=iIe(t,e.workflowRunId),p=sIe(t,e.workflowRunId),m=cIe(t,r),h=$Fe(e),g=eIe(a,e.piboSessionId),_=[{id:`workflow.entry`,label:`workflow entry`,kind:`initial`,status:s===`idle`?`active`:`completed`,description:`Project session is linked to a workflow-capable route.`},{id:`node.session`,label:t?.title??`pibo session actor`,kind:`agent`,status:c===`node.session`?s:s===`completed`?`completed`:`idle`,description:`Normal Pibo routed session used as the visible workflow actor.`},{id:G7(s),label:_Ie(s),kind:`terminal`,status:c.startsWith(`workflow.`)?s:`idle`,description:`Terminal state projected from the current workflow/session state.`}];return{projectId:e.projectId,workflowId:e.workflowId,...e.workflowVersion?{workflowVersion:e.workflowVersion}:{},...e.workflowRunId?{workflowRunId:e.workflowRunId}:{},piboSessionId:e.piboSessionId,state:o,status:s,traceTitle:t?.title,traceVersion:t?.version,latestStreamId:t?.latestStreamId,nodes:_,edges:[{id:`workflow.transition.entry.session`,source:`workflow.entry`,target:`node.session`,label:`WORKFLOW.START`},{id:`workflow.transition.session.terminal`,source:`node.session`,target:G7(s),label:vIe(s)}],configuration:tIe(e),definitionLink:h,nestedSessionLinks:g,pendingHumanActions:nIe(e,r),runHistory:d,nodeAttempts:f,edgeTransfers:p,runtimeErrors:m,...l?{finalOutput:l}:{},validationErrors:u,snapshot:{kind:`pibo.workflow.xstateUiModel`,schemaVersion:1,projection:{workflowId:e.workflowId,initialStateId:`workflow.entry`,durableTruth:`kernel`,exposesPrivatePayloads:!1},authoring:{location:`workflows_tab`,rawXStateEditingUi:`not_exposed`,inlineExecutableCodeUi:`not_exposed`},current:{snapshotKind:`ui`,...e.workflowRunId?{runId:e.workflowRunId}:{},status:o,stateIds:[c],nodeId:c===`node.session`?`session`:void 0},nodeStatuses:_.map(e=>({id:e.id,kind:e.kind,status:e.status})),runInspection:{durableTruth:`kernel_run_records`,xstateProjectionOnly:!0,runHistoryCount:d.length,nodeAttemptCount:f.length,edgeTransferCount:p.length,runtimeErrorCount:m.length},result:{hasFinalOutput:!!l,validationErrorCount:u.length},actors:[{id:`workflow.actor.session`,kind:`agent`,piboSessionId:e.piboSessionId}],definitionLink:{status:h.status,workflowId:h.workflowId,workflowVersion:h.workflowVersion,hasLiveLink:h.status===`live`&&!!N7(h)},nestedWorkflowSessionCount:g.length}}}function $Fe(e){return e.workflowDefinitionLink?e.workflowDefinitionLink:e.workflowVersion?{status:`live`,workflowId:e.workflowId,workflowVersion:e.workflowVersion,title:e.title??e.workflowId,href:P7(e.workflowId,e.workflowVersion)}:{status:`snapshot_only_definition_deleted`,workflowId:e.workflowId,title:e.title??e.workflowId,tombstoneLabel:`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}}function eIe(e,t){let n=M7(e,t);if(!n)return[];let r=[],i=e=>{for(let t of e)t.workflowSessionKind===`nested_workflow`&&r.push({piboSessionId:t.piboSessionId,title:t.title,kind:t.workflowSessionKind??t.profile??`workflow`,...t.workflowSessionKind?{workflowSessionKind:t.workflowSessionKind}:{}}),i(t.children)};return i(n.children),r}function M7(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=M7(n.children,t);if(e)return e}}function N7(e){if(e.status===`live`){if(e.href)return e.href;if(e.workflowVersion)return P7(e.workflowId,e.workflowVersion)}}function P7(e,t){return`/apps/chat/workflows/view/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function F7(e){return`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`}function tIe(e){let t=e.configuration;return{inputKeys:Object.keys(t?.inputValues??{}).sort(),promptOverrideNodeIds:Object.keys(t?.promptOverrides??{}).sort()}}function nIe(e,t){if(e.pendingHumanActions?.length)return e.pendingHumanActions.map(e=>({id:`wait-token:${e.waitTokenId}`,waitTokenId:e.waitTokenId,workflowRunId:e.workflowRunId,...e.nodeAttemptId?{nodeAttemptId:e.nodeAttemptId}:{},...e.humanNodeId?{humanNodeId:e.humanNodeId}:{},prompt:e.prompt,label:`Pending registered human action`,source:`persisted wait token`,...e.schema?{schema:e.schema}:{},payloadRequirements:e.payloadRequirements,availableActions:e.availableActions,diagnostics:e.diagnostics,createdAt:e.createdAt,...e.expiresAt?{expiresAt:e.expiresAt}:{}}));let n=W7(e,void 0).toLowerCase(),r=[t?.aggregateStatus,t?.localStatus].filter(e=>typeof e==`string`).join(` `).toLowerCase();return n.includes(`waiting`)||n.includes(`blocked`)||r.includes(`waiting`)||r.includes(`blocked`)||t?.hasBlockedDescendant?[{id:`human-action:${e.piboSessionId}`,prompt:`Session signal indicates a wait, but no persisted workflow wait token is available in the Project run store.`,label:`Awaiting human action`,source:t?`session signal`:`project session state`,availableActions:[],diagnostics:[]}]:[]}function rIe(e,t,n){return e.workflowRunId?[{id:e.workflowRunId,status:t,currentNodeId:n,updatedAt:e.updatedAt,source:`project session run record`}]:[]}function iIe(e,t){return!t||!e?[]:I7(e.nodes).filter(aIe).slice(0,8).map((e,t)=>({id:e.id,nodeId:e.stableKey??e.entryId??e.type,label:e.title||e.type,kind:e.type,status:oIe(e.status),attempt:t+1,source:`session trace fact`,...e.startedAt?{startedAt:e.startedAt}:{},...e.completedAt?{completedAt:e.completedAt}:{}}))}function aIe(e){return e.type===`agent.turn`||e.type===`tool.call`||e.type===`execution.command`||e.type===`agent.delegation`||e.type===`agent.async`||e.type===`yielded.run`||e.type===`error`}function oIe(e){return e===`done`?`completed`:e===`error`?`failed`:`running`}function sIe(e,t){if(!t||!e)return[];let n=[];for(let r of e.rawEvents){if(!U7(r.payload))continue;let e=H7(r.payload.type),i=H7(r.payload.runId);if(e!==`edge.transferred`||i&&i!==t)continue;let a=H7(r.payload.edgeId);a&&n.push({id:H7(r.payload.edgeTransferId)??r.id,edgeId:a,status:`transferred`,source:r.type,createdAt:r.createdAt})}return n.slice(0,8)}function cIe(e,t){let n=[];for(let e of t?.errors??[])n.push({id:`signal:${n.length}`,message:e.message,...e.code?{code:e.code}:{},source:e.source??`session signal`});if(e){for(let t of I7(e.nodes)){let e=t.error??(t.status===`error`?R7(t.output)??R7(t.summary):void 0);e&&n.push({id:`node:${t.id}`,message:e,source:t.type})}for(let t of e.rawEvents){if(!U7(t.payload))continue;let e=t.payload.error,r=U7(e)?H7(e.message):H7(e),i=U7(e)?H7(e.code):void 0;r&&n.push({id:`event:${t.id}`,message:r,...i?{code:i}:{},source:t.type})}}return lIe(n).slice(0,8)}function lIe(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.message}:${e.source??``}`;return t.has(n)?!1:(t.add(n),!0)})}function uIe(e,t){if(t!==`completed`||!e)return;let n=I7(e.nodes),r=[...n].reverse().find(e=>e.type===`assistant.message`&&e.status===`done`&&(e.output!==void 0||e.summary));if(r)return{value:r.output??r.summary??``,source:`assistant.message`};let i=[...n].reverse().find(e=>e.status===`done`&&e.type!==`user.message`&&e.type!==`model.reasoning`&&e.output!==void 0);return i?{value:i.output,source:i.type}:void 0}function dIe(e,t){let n=[];for(let r of t)if(r.piboSessionId===e.piboSessionId&&!(r.type!==`project.workflow_start.blocked`&&r.validation?.trigger!==`before_workflow_start`))for(let e of r.diagnostics)e.severity===`error`&&n.push({id:`lifecycle:${r.id}:${n.length}`,message:e.message,code:e.code,path:e.path,source:`start lifecycle event`});return B7(n).slice(0,8)}function fIe(e){if(!e)return[];let t=[];for(let n of I7(e.nodes)){let e=n.error??R7(n.output)??R7(n.summary);e&&(!z7([n.title,n.summary,n.error,n.type].filter(e=>typeof e==`string`).join(` `))&&!z7(e)||t.push({id:`node:${n.id}`,message:e,...n.type?{source:n.type}:{}}))}for(let n of e.rawEvents)L7(n.payload,`event:${n.id}`,t);return B7(t).slice(0,8)}function I7(e){let t=[],n=e=>{for(let r of e)t.push(r),n(r.children)};return n(e),t}function L7(e,t,n,r=0){if(r>4||!U7(e))return;let i=Array.isArray(e.diagnostics)?e.diagnostics:void 0;if(i)for(let e of i){if(!U7(e))continue;let r=H7(e.message)??R7(e);r&&n.push({id:`${t}:diagnostic:${n.length}`,message:r,...H7(e.code)?{code:H7(e.code)}:{},...H7(e.path)?{path:H7(e.path)}:{},source:`workflow.diagnostic`})}let a=e.error;if(U7(a)){let e=H7(a.code),r=H7(a.message)??R7(a);r&&z7([e,r].filter(Boolean).join(` `))&&n.push({id:`${t}:error:${n.length}`,message:r,...e?{code:e}:{},source:`workflow.error`})}else typeof a==`string`&&z7(a)&&n.push({id:`${t}:error:${n.length}`,message:a,source:`workflow.error`});for(let[i,a]of Object.entries(e))i===`diagnostics`||i===`error`||i!==`payload`&&i!==`output`&&i!==`result`&&i!==`data`||L7(a,`${t}:${i}`,n,r+1)}function R7(e){if(typeof e==`string`)return e;if(U7(e))return H7(e.message)??H7(e.error)??H7(e.summary)}function z7(e){let t=e.toLowerCase();return t.includes(`validation`)||t.includes(`validate`)||t.includes(`diagnostic`)||t.includes(`workflowinterfaceerror`)||t.includes(`workflowruntimeerror.validation`)}function B7(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.path??``}:${e.message}`;return t.has(n)?!1:(t.add(n),!0)})}function pIe(e){return U7(e)&&U7(e.data)&&Array.isArray(e.data.diagnostics)?e.data.diagnostics.filter(U7).map(t=>({code:H7(t.code)??`WorkflowRuntimeError.humanActionRejected`,message:H7(t.message)??V7(e),severity:t.severity===`info`||t.severity===`warning`||t.severity===`error`?t.severity:`error`,...H7(t.path)?{path:H7(t.path)}:{},...H7(t.registryRef)?{registryRef:H7(t.registryRef)}:{},...H7(t.hint)?{hint:H7(t.hint)}:{}})):[{code:`WorkflowRuntimeError.humanActionRejected`,message:V7(e),severity:`error`}]}function V7(e){return e instanceof Error?e.message:String(e)}function H7(e){return typeof e==`string`&&e.trim()?e:void 0}function U7(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function mIe(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function W7(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.workflowRunId?`workflow`:e.kind}function hIe(e,t){let n=W7(e,t).toLowerCase();return e.archived?`cancelled`:n.includes(`complete`)||n.includes(`done`)?`completed`:n.includes(`fail`)||n.includes(`error`)?`failed`:n.includes(`cancel`)?`cancelled`:n.includes(`wait`)||n.includes(`blocked`)?`waiting`:!e.workflowRunId&&n.includes(`configured`)?`idle`:`active`}function gIe(e){return e===`completed`?`workflow.completed`:e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`node.session`}function G7(e){return e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`workflow.completed`}function _Ie(e){return e===`failed`?`failed`:e===`cancelled`?`cancelled`:`completed`}function vIe(e){return e===`failed`?`WORKFLOW.FAIL`:e===`cancelled`?`WORKFLOW.CANCEL`:`WORKFLOW.NODE.DONE`}function K7({status:e}){return e===`completed`?(0,z.jsx)(Ko,{size:16,className:`text-emerald-300`}):e===`failed`?(0,z.jsx)(Jo,{size:16,className:`text-red-300`}):e===`cancelled`?(0,z.jsx)(Js,{size:16,className:`text-slate-400`}):e===`waiting`?(0,z.jsx)(Xo,{size:16,className:`text-amber-300`}):e===`active`?(0,z.jsx)(Co,{size:16,className:`text-[#11a4d4]`}):(0,z.jsx)(Yo,{size:16,className:`text-slate-500`})}function q7({tone:e,children:t}){return(0,z.jsx)(`span`,{className:`rounded border px-2 py-1 font-mono ${{blue:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,slate:`border-slate-700 bg-slate-900/50 text-slate-300`,green:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`,amber:`border-amber-500/40 bg-amber-500/10 text-amber-300`,red:`border-red-500/40 bg-red-500/10 text-red-300`}[e]}`,children:t})}function yIe(e){return e===`completed`?`green`:e===`failed`||e===`cancelled`?`red`:e===`waiting`?`amber`:`blue`}function J7(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10`:e===`failed`?`border-red-500/40 bg-red-500/10`:e===`cancelled`?`border-slate-600 bg-slate-800/40`:e===`waiting`?`border-amber-500/40 bg-amber-500/10`:e===`active`?`border-[#11a4d4]/50 bg-[#11a4d4]/10 shadow-[0_0_0_1px_rgba(17,164,212,0.18)]`:`border-slate-800 bg-[#111820]`}function bIe(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:e===`failed`||e===`cancelled`?`border-red-500/40 bg-red-500/10 text-red-300`:e===`waiting`?`border-amber-500/40 bg-amber-500/10 text-amber-300`:e===`active`?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function Y7(e){let t=e.toLowerCase();return t.includes(`complete`)||t.includes(`done`)||t.includes(`transferred`)?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:t.includes(`fail`)||t.includes(`error`)||t.includes(`cancel`)?`border-red-500/40 bg-red-500/10 text-red-300`:t.includes(`wait`)||t.includes(`blocked`)?`border-amber-500/40 bg-amber-500/10 text-amber-300`:t.includes(`run`)||t.includes(`active`)||t.includes(`workflow`)?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function X7(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}var Z7=[{id:`terminal`,label:`Terminal`,description:`Compact Codex-style terminal transcript.`,render:e=>(0,z.jsx)(SFe,{...e})},{id:`workflow`,label:`Workflow`,description:`Workflow/XState visualization for workflow-backed project sessions.`,render:e=>(0,z.jsx)(BFe,{...e})}],Q7=new Map(Z7.map(e=>[e.id,e]));function xIe(){return Z7}function $7(e){return Q7.get(e)??Q7.get(`terminal`)}function e9(e,t){return{localBootstrap:t,queryData:e.getQueriesData({queryKey:[`chat`,`bootstrap`]})}}function t9(e,t){return p9(e.sessions,t.piboSessionId)?e:{...e,sessions:[t,...e.sessions]}}function SIe(e,t){let n=n9(e.sessions,t),r=t.has(e.selectedPiboSessionId);return{...e,selectedPiboSessionId:r?``:e.selectedPiboSessionId,sessions:n}}function n9(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.piboSessionId)){n=!0;continue}let e=n9(i.children,t);e===i.children?r.push(i):(n=!0,r.push({...i,children:e}))}return n?r:e}function r9(e){let t=new Set([e.piboSessionId]);for(let n of e.children)for(let e of r9(n))t.add(e);return t}function CIe(e,t,n){if(!t)return t9(e,n);let r=!1,i=u9(e.sessions,t,()=>(r=!0,n));return{...e,selectedPiboSessionId:e.selectedPiboSessionId===t?n.piboSessionId:e.selectedPiboSessionId,session:e.session.id===t?f9(n,e.session):e.session,sessions:r?i:[n,...i]}}function i9(e,t){let n=typeof t.metadata?.chatWebArchivedAt==`string`;return{...e,session:e.session.id===t.id?t:e.session,sessions:u9(e.sessions,t.id,e=>({...e,profile:t.profile,activeModel:t.activeModel,title:t.title||e.title||`Untitled Session`,archived:n}))}}function a9(e,t,n){let r=e.session.id===t?f9(n(d9(e.session)),e.session):e.session;return{...e,session:r,sessions:u9(e.sessions,t,n)}}function wIe(e,t){return d3(e.rooms,t.id)?e:{...e,room:t,selectedRoomId:t.id,selectedPiboSessionId:``,rooms:[t,...e.rooms]}}function TIe(e,t,n){return{...e,room:e.room?.id===t?n:e.room,selectedRoomId:e.selectedRoomId===t?n.id:e.selectedRoomId,rooms:s9(e.rooms,t,()=>n)}}function o9(e,t,n){return{...e,room:e.room?.id===t?n(e.room):e.room,rooms:s9(e.rooms,t,n)}}function EIe(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:c9(e.rooms,t)}}function s9(e,t,n){let r=!1,i=e.map(e=>{if(e.id===t)return r=!0,n(e);let i=e.children??[],a=s9(i,t,n);return a===i?e:(r=!0,{...e,children:a})});return r?i:e}function c9(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.id)){n=!0;continue}let e=i.children??[],a=c9(e,t);a===e?r.push(i):(n=!0,r.push({...i,children:a}))}return n?r:e}function DIe(e,t){let n=new Date().toISOString();return{id:e,name:t,type:`chat`,createdAt:n,updatedAt:n,metadata:{},children:[]}}function OIe(e,t){let n={...e.metadata};return t?n.chatRoomArchivedAt=new Date().toISOString():delete n.chatRoomArchivedAt,{...e,metadata:n,updatedAt:new Date().toISOString()}}function l9(e){let t=new Set([e.id]);for(let n of e.children??[])for(let e of l9(n))t.add(e);return t}function u9(e,t,n){let r=!1,i=e.map(e=>{if(e.piboSessionId===t)return r=!0,n(e);let i=u9(e.children,t,n);return i===e.children?e:(r=!0,{...e,children:i})});return r?i:e}function kIe(e,t){return{piboSessionId:e,piSessionId:`pending`,profile:t,title:`New Session`,status:`idle`,lastActivityAt:new Date().toISOString(),derivedSessions:[],children:[]}}function d9(e){return{piboSessionId:e.id,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:e.title||`Untitled Session`,archived:typeof e.metadata?.chatWebArchivedAt==`string`,status:`idle`,lastActivityAt:e.updatedAt,derivedSessions:[],children:[]}}function f9(e,t){return{...t,id:e.piboSessionId,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:s3(e),updatedAt:e.lastActivityAt??t.updatedAt}}function p9(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=p9(n.children,t);if(e)return e}}function AIe(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 jIe(e,t){if(e===`thinking`&&t)return{level:t.split(/\s+/,1)[0]};if(e===`compact`&&t)return{customInstructions:t}}function MIe(e){return!m9(e)||!m9(e.result)?null:e}function NIe(e){if(!(!m9(e)||!m9(e.result)))return typeof e.result.piboSessionId==`string`?e.result.piboSessionId:void 0}function m9(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function PIe(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 ~/.pibo/uploads.`},{slash:`/thinking-show`,action:`thinking-show`,description:`Toggle historical thinking display in this browser.`}),t}function FIe(e,t){if(!e)return[];let n=e.agentCatalog?.skills??[],r=e.agentCatalog?.userSkills??[],i=[...n,...r],a=Z4(e),o=t?$4(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 IIe(e,t){let n=e.area===`sessions`?e.roomId:void 0,r=e.area===`sessions`||e.area===`projects`||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 LIe(e){let{bootstrap:t,creatingSession:n,route:r}=e,i=r.area===`sessions`||r.area===`projects`||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 RIe(e,t){if(e.area===`sessions`&&t.selectedPiboSessionId&&!(e.roomId===t.selectedRoomId&&e.piboSessionId===t.selectedPiboSessionId))return t}function zIe(e){return e.area===`sessions`&&!!(e.roomId||e.piboSessionId)}function BIe({activePanel:e,onSelect:t,piPackageCount:n,userSkillCount:r}){return(0,z.jsx)(`div`,{className:`p-2`,children:(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Settings`}),(0,z.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,z.jsx)(Ws,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`General`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`browser + runtime`})]})]}),(0,z.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,z.jsx)(_s,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Shortcuts`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`keyboard`})]})]}),(0,z.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,z.jsx)(vs,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Pi Packages`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`runtime-packages`})]}),(0,z.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,z.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,z.jsx)(Zs,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Skills`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`user-managed`})]}),(0,z.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,z.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,z.jsx)(gs,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Providers`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`auth + api keys`})]})]})]})})}var h9=[{id:`openai-codex`,name:`OpenAI (ChatGPT Plus/Pro)`,authMethod:`oauth`},{id:`openai`,name:`OpenAI (API Key)`,authMethod:`api_key`},{id:`anthropic`,name:`Anthropic (Claude)`,authMethod:`oauth`},{id:`github-copilot`,name:`GitHub Copilot`,authMethod:`oauth`},{id:`kimi-coding`,name:`Kimi for Coding`,authMethod:`api_key`},{id:`google`,name:`Google (Gemini)`,authMethod:`api_key`},{id:`groq`,name:`Groq`,authMethod:`api_key`},{id:`ollama`,name:`Ollama`,authMethod:`api_key`},{id:`minimax`,name:`MiniMax`,authMethod:`api_key`},{id:`minimax-cn`,name:`MiniMax (China)`,authMethod:`api_key`},{id:`glm`,name:`GLM (Z.ai)`,authMethod:`api_key`}];function VIe({piboSessionId:e,onProviderAuthChanged:t}){let[n,r]=(0,R.useState)({}),[i,a]=(0,R.useState)(!1),[o,s]=(0,R.useState)(null),[c,l]=(0,R.useState)(null),[u,d]=(0,R.useState)({}),[f,p]=(0,R.useState)({}),[m,h]=(0,R.useState)({}),[g,_]=(0,R.useState)({}),[v,y]=(0,R.useState)(null),[b,x]=(0,R.useState)({}),S=(0,R.useCallback)(async()=>{if(e){a(!0),s(null);try{let t=g9(await yc(e,`login.status`,{})),n={};if(Array.isArray(t?.providers))for(let e of t.providers){let t=e.id??e.provider;t&&(n[t]=e.configured)}r(n)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}}},[e]);(0,R.useEffect)(()=>{S()},[S]);let C=(0,R.useCallback)(async t=>{if(e){x(e=>({...e,[t]:!0})),s(null),l(null),d(e=>({...e,[t]:{type:`oauth_starting`}}));try{let n=g9(await yc(e,`login.start`,{provider:t})),r=n.url,i=n.state;r?d(e=>({...e,[t]:{type:`oauth_flow`,url:r,state:i,userCode:n.userCode,instructions:n.instructions,flow:n.type}})):(s(`No URL returned from login start.`),d(e=>({...e,[t]:{type:`collapsed`}})))}catch(e){s(e instanceof Error?e.message:String(e)),d(e=>({...e,[t]:{type:`collapsed`}}))}finally{x(e=>({...e,[t]:!1}))}}},[e]),w=(0,R.useCallback)(async(n,i,a)=>{if(e){x(e=>({...e,[n]:!0})),s(null),l(null);try{await yc(e,`login.complete`,{provider:n,...i?{code:i}:{},state:a??``});let o=_9(n);l(`${o} login completed.`),r(e=>({...e,[n]:!0})),d(e=>({...e,[n]:{type:`collapsed`}})),p(e=>({...e,[n]:``})),await t?.(),window.setTimeout(()=>l(e=>e===`${o} login completed.`?null:e),5e3)}catch(e){s(e instanceof Error?e.message:String(e))}finally{x(e=>({...e,[n]:!1}))}}},[t,e]),T=(0,R.useCallback)(async(n,i)=>{if(e){x(e=>({...e,[n]:!0})),s(null),l(null);try{await yc(e,`login.apikey`,{provider:n,apiKey:i});let a=_9(n);l(`${a} API key saved.`),r(e=>({...e,[n]:!0})),d(e=>({...e,[n]:{type:`collapsed`}})),h(e=>({...e,[n]:``})),await t?.(),window.setTimeout(()=>l(e=>e===`${a} API key saved.`?null:e),5e3)}catch(e){s(e instanceof Error?e.message:String(e))}finally{x(e=>({...e,[n]:!1}))}}},[t,e]),E=(0,R.useCallback)(async n=>{if(e){x(e=>({...e,[n]:!0})),s(null),l(null);try{await yc(e,`logout`,{provider:n}),r(e=>({...e,[n]:!1})),await t?.()}catch(e){s(e instanceof Error?e.message:String(e))}finally{x(e=>({...e,[n]:!1}))}}},[t,e]),D=async e=>{try{await navigator.clipboard.writeText(e),y(e),setTimeout(()=>y(null),2e3)}catch{}};return e?(0,z.jsxs)(`div`,{className:`grid gap-4`,children:[o?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-red-500/30 bg-red-500/10 px-3 py-2 text-xs text-red-300`,children:[(0,z.jsx)(Go,{size:14}),o]}):null,c?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-[#0bda57]/30 bg-[#0bda57]/10 px-3 py-2 text-xs text-[#7cf2a2]`,children:[(0,z.jsx)(qo,{size:14}),c]}):null,i?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-[#11a4d4]`,children:[(0,z.jsx)(Cs,{size:14,className:`animate-spin`}),`Loading provider status...`]}):null,h9.map(e=>{let t=n[e.id]??!1,r=u[e.id]??{type:`collapsed`},i=b[e.id]??!1;return(0,z.jsxs)(`div`,{className:`border rounded-sm ${r.type===`collapsed`?t?`border-[#0bda57]/20 bg-[#151f24]`:`border-[#334155] bg-[#151f24] hover:border-slate-600`:`border-[#11a4d4]/50 bg-[#151f24]`}`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 p-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-sm font-medium text-slate-200`,children:e.name}),(0,z.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wider ${e.authMethod===`oauth`?`border-purple-500/40 text-purple-300`:`border-amber-500/40 text-amber-300`}`,children:e.authMethod===`oauth`?`OAuth`:`API Key`})]}),(0,z.jsx)(`div`,{className:`mt-1 flex items-center gap-1.5 text-xs`,children:t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(qo,{size:12,className:`text-[#0bda57]`}),(0,z.jsx)(`span`,{className:`text-[#0bda57]`,children:`Configured`})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(Ts,{size:12,className:`text-slate-500`}),(0,z.jsx)(`span`,{className:`text-slate-500`,children:`Not configured`})]})})]}),(0,z.jsx)(`div`,{className:`flex items-center gap-2`,children:t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>d(t=>({...t,[e.id]:t[e.id]?.type===`collapsed`?e.authMethod===`oauth`?{type:`oauth_starting`}:{type:`api_key`}:{type:`collapsed`}})),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(gs,{size:12}),`Reconfigure`]}),(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void E(e.id),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-1.5 text-[11px] text-slate-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:12}),`Remove`]})]}):(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>e.authMethod===`oauth`?void C(e.id):d(t=>({...t,[e.id]:{type:`api_key`}})),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(gs,{size:12}),`Configure`]})})]}),r.type===`collapsed`?null:(0,z.jsx)(`div`,{className:`border-t border-slate-800 p-3`,children:r.type===`oauth_starting`?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-[#11a4d4]`,children:[(0,z.jsx)(Cs,{size:14,className:`animate-spin`}),`Starting OAuth flow...`]}):r.type===`oauth_flow`?(0,z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Step 1: Open URL`}),(0,z.jsx)(`div`,{className:`break-all rounded-sm border border-slate-700 bg-[#0e1116] p-2 font-mono text-[11px] text-slate-300`,children:r.url}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void D(r.url),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:[v===r.url?(0,z.jsx)(qo,{size:12}):(0,z.jsx)($o,{size:12}),v===r.url?`Copied`:`Copy URL`]}),(0,z.jsxs)(`a`,{href:r.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:[(0,z.jsx)(rs,{size:12}),`Open in Browser`]})]})]}),r.userCode?(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Step 2: Enter Code`}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-center font-mono text-[20px] font-bold tracking-widest text-[#11a4d4]`,children:r.userCode}),r.instructions?(0,z.jsx)(`div`,{className:`text-[11px] leading-relaxed text-slate-500`,children:r.instructions}):null,(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void w(e.id,void 0,r.state),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ts,{size:12}),`Complete Login`]})]}):(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Step 2: Paste Code`}),(0,z.jsx)(`input`,{type:`text`,value:f[e.id]??``,onChange:t=>p(n=>({...n,[e.id]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&(f[e.id]??``).trim()&&w(e.id,f[e.id].trim(),r.state)},placeholder:`Paste authorization code...`,className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1.5 font-mono text-[12px] text-slate-300 placeholder-slate-600 outline-none focus:border-[#11a4d4]`}),(0,z.jsxs)(`button`,{type:`button`,disabled:i||!(f[e.id]??``).trim(),onClick:()=>void w(e.id,f[e.id].trim(),r.state),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ts,{size:12}),`Complete Login`]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>d(t=>({...t,[e.id]:{type:`collapsed`}})),className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`← Cancel`})]}):r.type===`api_key`?(0,z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Enter API Key`}),(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`input`,{type:g[e.id]?`text`:`password`,value:m[e.id]??``,onChange:t=>h(n=>({...n,[e.id]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&(m[e.id]??``).trim()&&T(e.id,m[e.id].trim())},placeholder:`sk-...`,className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1.5 pr-8 font-mono text-[12px] text-slate-300 placeholder-slate-600 outline-none focus:border-[#11a4d4]`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>_(t=>({...t,[e.id]:!t[e.id]})),className:`absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-[#11a4d4]`,title:g[e.id]?`Hide`:`Show`,children:g[e.id]?(0,z.jsx)(is,{size:14}):(0,z.jsx)(as,{size:14})})]}),(0,z.jsxs)(`button`,{type:`button`,disabled:i||!(m[e.id]??``).trim(),onClick:()=>void T(e.id,m[e.id].trim()),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ts,{size:12}),`Save API Key`]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>d(t=>({...t,[e.id]:{type:`collapsed`}})),className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`← Cancel`})]}):null})]},e.id)})]}):(0,z.jsx)(`div`,{className:`border border-slate-700 bg-[#1a262b] rounded-sm p-4 text-sm text-slate-400`,children:`Select a chat session to manage provider authentication.`})}function g9(e){return HIe(e)?e.result:e}function HIe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}function _9(e){return h9.find(t=>t.id===e)?.name??e}function UIe({activePanel:e,showThinking:t,setShowThinking:n,expandThinking:r,setExpandThinking:i,modelDefaults:a,modelCatalog:o,onModelDefaultsChanged:s,piPackages:c,onPiPackageChanged:l,onPiPackageRemoved:u,userSkills:d,onUserSkillChanged:f,onUserSkillRemoved:p,piboSessionId:m,onProviderAuthChanged:h}){return e===`pi-packages`?(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(vs,{size:16}),`Pi Packages`]}),(0,z.jsx)(QIe,{packages:c,onPackageChanged:l,onPackageRemoved:u})]}):e===`skills`?(0,z.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,z.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,z.jsx)(Zs,{size:16}),`Skills`]}),(0,z.jsx)($Ie,{skills:d,onSkillChanged:f,onSkillRemoved:p})]}):e===`providers`?(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(gs,{size:16}),`Providers`]}),(0,z.jsx)(VIe,{piboSessionId:m,onProviderAuthChanged:h})]}):e===`shortcuts`?(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(_s,{size:16}),`Shortcuts`]}),(0,z.jsx)(KIe,{})]}):(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(Ws,{size:16}),`General`]}),(0,z.jsxs)(O0,{title:`General`,children:[(0,z.jsx)(GIe,{}),(0,z.jsx)(N0,{checked:t,title:`Show thinking blocks`,onToggle:()=>{let e=!t;n(e),n2(e)}}),(0,z.jsx)(N0,{checked:r,disabled:!t,title:`Expand thinking blocks`,onToggle:()=>{let e=!r;i(e),r2(e)}}),(0,z.jsx)(ZIe,{modelDefaults:a,modelCatalog:o,onChanged:s})]})]})}var WIe=`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 GIe(){let e=Yt(),{data:t,isLoading:n}=dn({queryKey:[`user-settings`],queryFn:Zz}),r=(0,R.useMemo)(()=>JIe(t?.timezone),[t?.timezone]),[i,a]=(0,R.useState)(`UTC`),[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(null);(0,R.useEffect)(()=>{t?.timezone&&a(t.timezone)},[t?.timezone]);let u=async(t=i)=>{s(!0),l(null);try{let n=await Qz({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,z.jsxs)(`div`,{className:`border-b border-slate-800 pb-4 mb-4`,children:[(0,z.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`App timezone`}),(0,z.jsx)(`div`,{className:`max-w-xl`,children:(0,z.jsx)(`select`,{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,z.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,z.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,z.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,c?(0,z.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:c}):null]})}function KIe(){let e=Yt(),{data:t,isLoading:n}=dn({queryKey:[`user-settings`],queryFn:Zz}),[r,i]=(0,R.useState)(S2),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(!1),[l,u]=(0,R.useState)(null);(0,R.useEffect)(()=>{let e=t?.shortcuts?.webAnnotationsToggle||C2();i(e),w2(e),T2(e)},[t?.shortcuts?.webAnnotationsToggle]);let d=async t=>{let n=E2(t)||`Alt+Shift+A`;i(n),c(!0),u(null);try{let t=await Qz({shortcuts:{webAnnotationsToggle:n}});e.setQueryData([`user-settings`],t),w2(t.shortcuts.webAnnotationsToggle),T2(t.shortcuts.webAnnotationsToggle)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,z.jsx)(O0,{title:`Shortcuts`,children:(0,z.jsxs)(`div`,{className:`grid max-w-2xl gap-3 rounded-sm border border-slate-800 bg-[#151f24] p-3`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-200`,children:[(0,z.jsx)(Ao,{size:15}),` Toggle annotation mode`]}),(0,z.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Toggles the Web Annotation element mode with the pencil button.`})]}),(0,z.jsx)(`kbd`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 font-mono text-xs text-[#7dd3fc]`,children:r})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,disabled:n||s,"aria-pressed":a,onClick:()=>o(e=>!e),onKeyDown:e=>{if(!a)return;let t=qIe(e);t&&(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,z.jsx)(`button`,{type:`button`,disabled:s||r===`Alt+Shift+A`,onClick:()=>void d(S2),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,z.jsx)(`span`,{className:`text-xs text-slate-400`,children:`Saving…`}):null]}),(0,z.jsxs)(`div`,{className:`text-[11px] text-slate-500`,children:[`Default: `,S2,`. Use a modifier combination to avoid conflicts with normal typing.`]}),l?(0,z.jsx)(`div`,{className:`text-xs text-red-300`,children:l}):null]})})}function qIe(e){if([`Alt`,`Control`,`Meta`,`Shift`].includes(e.key))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 JIe(e){let t=new Set([`UTC`,...Intl.supportedValuesOf?.(`timeZone`)??WIe]);return e&&t.add(e),[...t].map(e=>({value:e,label:YIe(e),offset:XIe(e)})).sort((e,t)=>e.offset-t.offset||e.label.localeCompare(t.label)).map(({value:e,label:t})=>({value:e,label:t}))}function YIe(e){let t=e===`UTC`?`UTC`:e.split(`/`).pop()?.replaceAll(`_`,` `)??e,n=e.includes(`/`)?e.split(`/`)[0].replaceAll(`_`,` `):void 0,r=v9(e);return`${t}${n?` (${n})`:``} — ${r}`}function v9(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 XIe(e){let t=v9(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 ZIe({modelDefaults:e,modelCatalog:t,onChanged:n}){let[r,i]=(0,R.useState)(e??{}),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(null);(0,R.useEffect)(()=>{i(e??{})},[e]);let l=async e=>{i(e),o(!0);try{n(await Vge(e)),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}};return(0,z.jsxs)(`div`,{className:`grid gap-3 border-t border-slate-800 pt-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Runtime Model Defaults`}),(0,z.jsx)(I0,{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,z.jsx)(I0,{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,z.jsx)(`div`,{className:`text-xs text-amber-100`,children:s}):null]})}function QIe({packages:e,onPackageChanged:t,onPackageRemoved:n}){let[r,i]=(0,R.useState)(``),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),[l,u]=(0,R.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 KW(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 qW(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 JW(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,z.jsxs)(O0,{title:`Pi Package Management`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,z.jsx)(`input`,{value:r,disabled:!e||a===`add`,onChange:e=>i(e.target.value),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,z.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,z.jsx)(Ps,{size:14})})]}),(0,z.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Extensions execute code in the Pi runtime. Review package source before adding it.`}),s?(0,z.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,z.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,z.jsx)(`div`,{className:`grid gap-2`,children:d.map(e=>(0,z.jsx)(tLe,{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,z.jsx)(F0,{message:`No Pi packages registered`}):(0,z.jsx)(F0,{})]})}function $Ie({skills:e,onSkillChanged:t,onSkillRemoved:n}){let[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(null),[l,u]=(0,R.useState)(``),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),h=e??[],g=h.filter(e=>e.enabled).length,_=async e=>{if(!d){f(`${e.id}:enabled`);try{t(await ZW(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 QW(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 XW(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 $W(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 ZW(e,n)),c(null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(O0,{title:`Skill Management`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.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,z.jsx)(Ps,{size:14}),`Create Skill`]}),(0,z.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,z.jsx)(rs,{size:14}),`Install from URL`]})]}),p?(0,z.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,z.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[h.length,` skills / `,g,` enabled`]})]}),e?h.length?(0,z.jsx)(`div`,{className:`grid gap-2`,children:h.map(e=>(0,z.jsx)(`div`,{className:`border rounded-sm p-2 ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 max-[640px]:items-start`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,z.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,z.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,z.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description||e.path})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void _(e),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,z.jsx)(Fs,{size:13}):(0,z.jsx)(Is,{size:13})}),(0,z.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:async()=>{try{let t=await YW(e.id);c(e),u(t.markdown)}catch{c(e),u(``)}},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,z.jsx)(Ms,{size:13})}),(0,z.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void v(e),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,z.jsx)(qs,{size:13})})]})]})},e.id))}):(0,z.jsx)(F0,{message:`No user skills`}):(0,z.jsx)(F0,{})]}),r?(0,z.jsx)(b9,{title:`Create Skill`,onSave:y,onClose:()=>i(!1),busy:d===`create`}):null,a?(0,z.jsx)(eLe,{onInstall:b,onClose:()=>o(!1),busy:d===`install`}):null,s?(0,z.jsx)(b9,{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 y9({children:e,onClose:t}){return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:[(0,z.jsx)(`div`,{className:`w-full max-w-2xl rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:e}),(0,z.jsx)(`button`,{type:`button`,className:`absolute inset-0 -z-10`,onClick:t,"aria-label":`Close modal`})]})}function b9({title:e,initialName:t=``,initialDescription:n=``,initialMarkdown:r=``,onSave:i,onClose:a,busy:o}){let[s,c]=(0,R.useState)(t),[l,u]=(0,R.useState)(n),[d,f]=(0,R.useState)(r);return(0,z.jsxs)(y9,{onClose:a,children:[(0,z.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,z.jsx)(Ms,{size:16}),e]}),(0,z.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,z.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,z.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,z.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,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.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,z.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 eLe({onInstall:e,onClose:t,busy:n}){let[r,i]=(0,R.useState)(``);return(0,z.jsxs)(y9,{onClose:t,children:[(0,z.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,z.jsx)(rs,{size:16}),`Install Skill`]}),(0,z.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,z.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,z.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Supports skills.sh URLs, GitHub tree URLs, or account/repo shorthand.`}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.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,z.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 tLe({pkg:e,expanded:t,busy:n,onToggleExpanded:r,onToggleEnabled:i,onUnregister:a}){let o=e.diagnostics.some(e=>e.type===`error`);return(0,z.jsxs)(`div`,{className:`border rounded-sm ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2 p-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,z.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,z.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,z.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description??e.source}),(0,z.jsx)(`div`,{className:`font-mono text-[10px] mt-1 ${o?`text-[#f59e0b]`:`text-[#11a4d4]`}`,children:E0(e)})]}),(0,z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,z.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,z.jsx)(zo,{size:13}):(0,z.jsx)(Bo,{size:13})}),(0,z.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,z.jsx)(Fs,{size:13}):(0,z.jsx)(Is,{size:13})}),(0,z.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,z.jsx)(qs,{size:13})})]})]}),t?(0,z.jsx)(j0,{pkg:e}):null]})}function nLe({data:e,selectedProject:t,selectedPiboSessionId:n,selectedProjectSession:r,workflowProjectSessions:i,activeProjects:a,archivedProjects:o,sessionGroups:s,selectedSessionPathIds:c,autoRenameSessionId:l,creatingSession:u,showArchivedProjects:d,showArchivedSessions:f,mobileSidebarOpen:p,onRefresh:m,onCloseMobileSidebar:h,onCreateProject:g,onToggleArchivedProjects:_,onSelectProject:v,onRenameProject:y,onSetProjectArchived:b,onDeleteArchivedProject:x,onCreateProjectSession:S,onToggleArchivedSessions:C,onSelectSession:w,onRenameSession:T,onArchiveSession:E,onDeleteSession:D,onViewContext:O,onAutoRenameConsumed:k}){let A=Date.now();return(0,z.jsxs)(`aside`,{className:`min-h-0 overflow-auto bg-[#1a262b] border-r border-slate-800 max-[980px]:fixed max-[980px]:left-0 max-[980px]:top-0 max-[980px]:bottom-0 max-[980px]:z-40 max-[980px]:w-[280px] max-[980px]:transition-transform max-[980px]:duration-200 ${p?`max-[980px]:translate-x-0`:`max-[980px]:-translate-x-full`}`,children:[(0,z.jsxs)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center justify-between text-xs font-bold uppercase tracking-wider max-[980px]:h-auto max-[980px]:py-2`,children:[(0,z.jsx)(`span`,{children:`projects`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:m,title:`Refresh`,"aria-label":`Refresh`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ls,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:h,title:`Close sidebar`,"aria-label":`Close sidebar`,className:`min-[981px]:hidden p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Qs,{size:13})})]})]}),(0,z.jsxs)(`div`,{className:`p-2 space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Shared Chat`}),(0,z.jsx)(S9,{project:e.sharedDefaultProject,selected:t?.id===e.sharedDefaultProject.id,onSelect:()=>v(e.sharedDefaultProject.id)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Projects`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:g,title:`New Project`,"aria-label":`New Project`,className:`h-6 w-6 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:_,title:`Archived Projects`,"aria-label":`Archived Projects`,className:`h-6 w-6 inline-flex items-center justify-center border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${d?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:d?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),a.map(e=>(0,z.jsx)(S9,{project:e,selected:t?.id===e.id,onSelect:()=>v(e.id),onRename:t=>y(e,t),onArchive:()=>b(e,!0)},e.id)),a.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No projects`}):null,d?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Projects`}),o.map(e=>(0,z.jsx)(S9,{project:e,selected:t?.id===e.id,onSelect:()=>v(e.id),onRename:t=>y(e,t),onArchive:()=>b(e,!1),onDelete:()=>x(e),archived:!0},e.id))]}):null]}),i.length>0?(0,z.jsx)(rLe,{projectSessions:i,sessionNodes:e.sessions,selectedPiboSessionId:n,onSelect:w}):null,(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Project Sessions`}),(0,z.jsx)(`div`,{className:`text-[10px] text-slate-500`,children:r?Gke(r):`Workflow: simple-chat`})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:S,disabled:u||!t,title:`New Project Session`,"aria-label":`New Project Session`,className:`h-6 w-6 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,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:C,title:f?`Hide Archived Project Sessions`:`Show Archived Project Sessions`,"aria-label":f?`Hide Archived Project Sessions`:`Show Archived Project Sessions`,className:`h-6 w-6 inline-flex items-center justify-center border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${f?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:f?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),s.active.map(e=>(0,z.jsx)(h3,{node:e,signalNow:A,selectedPiboSessionId:n,selectedSessionPathIds:c,onSelect:w,onRename:T,onArchive:E,onDelete:D,onViewContext:O,loadingPiboSessionId:null,autoRename:l===e.piboSessionId,onAutoRenameConsumed:k,showWorkflowSessionKindMarkers:!0},e.piboSessionId)),s.active.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No active project sessions`}):null,f?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Project Sessions`}),s.archived.map(e=>(0,z.jsx)(h3,{node:e,signalNow:A,selectedPiboSessionId:n,selectedSessionPathIds:c,onSelect:w,onRename:T,onArchive:E,onDelete:D,onViewContext:O,loadingPiboSessionId:null,showWorkflowSessionKindMarkers:!0},e.piboSessionId)),s.archived.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No archived project sessions`}):null]}):null]})]})]})}function x9(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=x9(n.children,t);if(e)return e}}function rLe({projectSessions:e,sessionNodes:t,selectedPiboSessionId:n,onSelect:r}){return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Workflow Runs`}),(0,z.jsx)(`div`,{className:`text-[10px] text-slate-500`,children:e.length})]}),(0,z.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>{let i=x9(t,e.piboSessionId),a=i?s3(i):e.title??e.piboSessionId,o=e.piboSessionId===n,s=V2(e,i?.status);return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(e.piboSessionId),className:`w-full text-left rounded-sm border px-2 py-2 transition-colors ${o?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 hover:border-slate-700 hover:bg-slate-800/40`}`,title:e.workflowRunId??e.workflowId,children:[(0,z.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 text-xs font-medium text-slate-200 truncate`,children:a}),(0,z.jsx)(`span`,{className:Jke(e,i?.status),children:s})]}),(0,z.jsx)(`span`,{className:`mt-1 block text-[10px] text-slate-500 truncate`,children:e.workflowId}),e.workflowRunId?(0,z.jsxs)(`span`,{className:`block text-[10px] font-mono text-slate-500 truncate`,children:[`run `,U2(e.workflowRunId)]}):null]},`${e.workflowRunId??e.piboSessionId}:${e.piboSessionId}`)})})]})}function S9({project:e,selected:t,archived:n,onSelect:r,onRename:i,onArchive:a,onDelete:o}){let s=e.metadata?.default===!0||e.metadata?.personal===!0,[c,l]=(0,R.useState)(!1),[u,d]=(0,R.useState)(e.name),[f,p]=(0,R.useState)(!1),m=(0,R.useRef)(null),h=(0,R.useRef)(null);(0,R.useEffect)(()=>{c||d(e.name)},[c,e.name]),(0,R.useEffect)(()=>{if(!f)return;let e=e=>{h.current&&!h.current.contains(e.target)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]),(0,R.useLayoutEffect)(()=>{c&&(m.current?.focus(),m.current?.select())},[c]);let g=()=>{let t=u.trim();t&&t!==e.name&&i?.(t),l(!1)};return(0,z.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-sm border px-2 py-2 text-sm ${s?t?`border-[#0bda57] bg-[#0bda57]/10 text-green-100`:`border-[#0bda57]/50 bg-[#0bda57]/5 text-slate-300 hover:border-[#0bda57]`:t?`border-[#11a4d4] bg-[#11a4d4]/10 text-sky-100`:`border-transparent text-slate-300 hover:border-slate-700 hover:bg-slate-900/40`}`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 shrink-0 inline-flex items-center justify-center rounded-sm ${s?`bg-[#0bda57]/15 text-[#0bda57]`:n?`bg-[#f59e0b]/15 text-[#f59e0b]`:`bg-[#151f24] text-slate-500`}`,children:s?(0,z.jsx)(Ts,{size:13}):n?(0,z.jsx)(To,{size:13}):(0,z.jsx)(ls,{size:13})}),c?(0,z.jsxs)(`form`,{className:`min-w-0 flex-1 grid grid-cols-[1fr_auto_auto] gap-1`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,z.jsx)(`input`,{ref:m,value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Escape`&&(t.preventDefault(),l(!1),d(e.name))},className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-sm outline-none focus:border-[#11a4d4]`}),(0,z.jsx)(`button`,{type:`submit`,title:`Save Project Name`,"aria-label":`Save Project 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]`,children:(0,z.jsx)(Ro,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>{l(!1),d(e.name)},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,z.jsx)(Qs,{size:13})})]}):(0,z.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 flex-1 text-left`,children:[(0,z.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,z.jsx)(`span`,{className:`block truncate text-[11px] text-slate-500`,children:s?`shared default project chat`:e.projectFolder})]}),s?(0,z.jsx)(`span`,{title:`Shared Chat is locked`,"aria-label":`Shared Chat is locked`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-[#0bda57]/50 rounded-sm text-[#0bda57]`,children:(0,z.jsx)(Ts,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}):c?null:(0,z.jsxs)(`div`,{className:`relative opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,ref:h,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),title:`Project actions`,"aria-label":`Project actions`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(ns,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}),f?(0,z.jsxs)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-48 bg-[#1a262b] border border-slate-700 rounded-sm shadow-lg py-1`,children:[i?(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{p(!1),l(!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Ms,{size:16}),` Rename Project`]}):null,a?(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{p(!1),a()},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[n?(0,z.jsx)(wo,{size:16}):(0,z.jsx)(To,{size:16}),` `,n?`Restore Project`:`Archive Project`]}):null,o?(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{p(!1),o()},className:`w-full text-left px-3 py-2.5 text-sm text-red-300 hover:bg-red-500/10 flex items-center gap-2`,children:[(0,z.jsx)(qs,{size:16}),` Delete Project`]}):null]}):null]})]})}function iLe({project:e,options:t,selectedOptionKey:n,titleValue:r,loadState:i,errorMessage:a,creating:o,diagnostics:s,onSelectedOptionChange:c,onTitleChange:l,onCreate:u}){let d=t.find(e=>T9(e)===n),f=o||i!==`loaded`||!d||!!e.archivedAt;return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#151f24] p-4 shadow-lg shadow-black/10`,"aria-labelledby":`project-workflow-create-title`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 max-w-2xl`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(vs,{size:13}),`Workflow-backed session`]}),(0,z.jsx)(`h2`,{id:`project-workflow-create-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:`Create workflow Project session`}),(0,z.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-slate-500`,children:`Choose a published workflow version from the global catalog and save a configured Project session. Creation does not start a workflow run.`})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/80 px-2 py-1 text-[11px] uppercase tracking-wide text-slate-500`,children:[`Project: `,(0,z.jsx)(`span`,{className:`text-slate-300`,children:e.name})]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)_auto] md:items-end`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1.5 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Workflow version`}),(0,z.jsxs)(`select`,{"aria-label":`Workflow version`,className:`rounded-sm border border-slate-700 bg-[#101d22] px-3 py-2 text-sm text-slate-100 outline-none transition focus:border-[#11a4d4] disabled:opacity-60`,value:n,onChange:e=>c(e.target.value),disabled:o||i!==`loaded`,children:[(0,z.jsx)(`option`,{value:``,children:`Select a workflow version`}),t.map(e=>(0,z.jsx)(`option`,{value:T9(e),children:pLe(e)},T9(e)))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1.5 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Session name`}),(0,z.jsx)(`input`,{"aria-label":`Workflow session name`,className:`rounded-sm border border-slate-700 bg-[#101d22] px-3 py-2 text-sm text-slate-100 outline-none transition placeholder:text-slate-600 focus:border-[#11a4d4] disabled:opacity-60`,value:r,onChange:e=>l(e.target.value),placeholder:`Optional`,disabled:o})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:u,disabled:f,className:`inline-flex min-h-10 items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/60 bg-[#11a4d4]/10 px-3 py-2 text-xs font-bold uppercase tracking-wide text-[#11a4d4] transition hover:bg-[#11a4d4]/15 disabled:cursor-not-allowed disabled:border-slate-700 disabled:bg-slate-900/40 disabled:text-slate-500`,children:[o?(0,z.jsx)(Cs,{size:14,className:`animate-spin`}):(0,z.jsx)(Bs,{size:14}),`Save configured session`]})]}),d?(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-slate-800 bg-[#101d22]/70 p-3 text-xs leading-5 text-slate-500`,children:[(0,z.jsx)(`span`,{className:`font-semibold text-slate-300`,children:d.title}),` `,(0,z.jsxs)(`span`,{className:`font-mono text-slate-400`,children:[d.id,`@`,d.version]}),d.description?(0,z.jsxs)(`span`,{children:[` — `,d.description]}):null]}):null,(0,z.jsx)(oLe,{}),i===`loading`?(0,z.jsx)(`div`,{className:`mt-3 text-xs text-slate-500`,children:`Loading workflow catalog…`}):null,i===`error`?(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs text-red-200`,role:`alert`,children:a??`Failed to load workflow catalog.`}):null,s.length?(0,z.jsx)(aLe,{label:`Create-blocking diagnostics`,diagnostics:s}):null]})}function aLe({label:e,diagnostics:t}){return(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-red-500/40 bg-red-500/10 p-3 text-xs text-red-100`,role:`alert`,"aria-label":e,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-red-200`,children:[(0,z.jsx)(Js,{size:12}),e]}),(0,z.jsx)(`div`,{className:`mt-2 space-y-2`,children:t.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-[#0b0f14]/60 p-2`,children:[(0,z.jsx)(`div`,{className:`break-words text-red-100`,children:e.message??e.code??`Workflow validation blocked this action.`}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,z.jsx)(`span`,{children:e.code}):null,e.path?(0,z.jsx)(`span`,{children:e.path}):null,e.nodeId?(0,z.jsxs)(`span`,{children:[`node:`,e.nodeId]}):null,e.edgeId?(0,z.jsxs)(`span`,{children:[`edge:`,e.edgeId]}):null,e.registryRef?(0,z.jsx)(`span`,{children:e.registryRef}):null]}),e.hint?(0,z.jsx)(`div`,{className:`mt-1 text-[11px] text-red-100/75`,children:e.hint}):null]},`${e.code??`diagnostic`}:${e.path??e.registryRef??e.nodeId??e.edgeId??t}`))})]})}function oLe(){return(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-amber-700/60 bg-amber-950/15 p-3 text-[11px] leading-5 text-amber-100/80`,"aria-label":`Project workflow V2 explicit non-goals`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-amber-200`,children:[(0,z.jsx)(Ts,{size:12}),`V2 scope boundary`]}),(0,z.jsx)(`p`,{className:`mt-2`,children:`Project workflow sessions select published catalog versions and save configured sessions only. They do not expose workflow templates, workflow slash commands, workflow tools for agents, inline TypeScript/JavaScript/shell/eval code, raw XState editing, TypeScript export, YAML/JSON product import/export, or Zod schema authoring.`})]})}function sLe({projectSession:e,lifecycleEvents:t,starting:n,message:r,onStart:i}){let a=cLe(e),o=dLe(lLe(e.piboSessionId,t)),s=uLe(e.piboSessionId,t),c=fLe(r);return(0,z.jsxs)(`section`,{className:`rounded-sm border border-[#11a4d4]/35 bg-[#111820] p-4 shadow-lg shadow-black/10`,"aria-labelledby":`project-workflow-start-title`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 max-w-2xl`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(Is,{size:13}),`Configured/not-started`]}),(0,z.jsx)(`h2`,{id:`project-workflow-start-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:`Ready to start workflow`}),(0,z.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-slate-500`,children:`This Project session is saved for review. Start explicitly when the configuration is ready.`})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:i,disabled:n,className:`inline-flex min-h-10 items-center justify-center gap-2 rounded-sm border border-emerald-500/60 bg-emerald-500/10 px-3 py-2 text-xs font-bold uppercase tracking-wide text-emerald-300 transition hover:bg-emerald-500/15 disabled:cursor-not-allowed disabled:border-slate-700 disabled:bg-slate-900/40 disabled:text-slate-500`,children:[n?(0,z.jsx)(Cs,{size:14,className:`animate-spin`}):(0,z.jsx)(Is,{size:14}),`Start workflow`]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-2 text-xs md:grid-cols-2 xl:grid-cols-4`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Workflow`}),(0,z.jsx)(`div`,{className:`mt-1 truncate font-mono text-slate-300`,title:e.workflowId,children:e.workflowId}),e.workflowVersion?(0,z.jsxs)(`div`,{className:`mt-1 text-slate-500`,children:[`version `,e.workflowVersion]}):null]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Configuration summary`}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-300`,children:a.primary}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:a.secondary})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Validation state`}),(0,z.jsx)(`div`,{className:o.className,children:o.label}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:o.description})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Run history`}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-300`,children:`No current run attempts`}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:`No workflow run record exists until Start succeeds.`})]})]}),s.length?(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-red-500/40 bg-red-500/10 p-3 text-xs text-red-100`,role:`alert`,"aria-label":`Start-blocking diagnostics`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-red-200`,children:[(0,z.jsx)(Js,{size:12}),`Start-blocking diagnostics`]}),(0,z.jsx)(`div`,{className:`mt-2 space-y-2`,children:s.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-[#0b0f14]/60 p-2`,children:[(0,z.jsx)(`div`,{className:`break-words text-red-100`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[(0,z.jsx)(`span`,{children:e.code}),e.path?(0,z.jsx)(`span`,{children:e.path}):null,e.registryRef?(0,z.jsx)(`span`,{children:e.registryRef}):null]}),e.hint?(0,z.jsx)(`div`,{className:`mt-1 text-[11px] text-red-100/75`,children:e.hint}):null]},`${e.code}:${e.path??e.registryRef??t}`))})]}):null,r?(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border p-3 text-xs ${c}`,role:`status`,children:r}):null]})}function cLe(e){let t=e.configuration,n=Object.keys(t?.inputValues??{}).length,r=Object.keys(t?.promptOverrides??{}).length,i=t?.model?`${t.model.provider}/${t.model.id}`:`default model`,a=t?.thinkingLevel?`${t.thinkingLevel} thinking`:`default thinking`,o=t?.fastMode===!0?`fast mode on`:t?.fastMode===!1?`fast mode off`:`default speed`;return{primary:`${n} input ${n===1?`value`:`values`} · ${r} prompt ${r===1?`override`:`overrides`}`,secondary:`${i} · ${a} · ${o}`}}function lLe(e,t){return C9(t.filter(t=>t.piboSessionId===e&&!!t.validation))}function uLe(e,t){return(C9(t.filter(t=>t.piboSessionId===e&&t.type===`project.workflow_start.blocked`))?.diagnostics??[]).filter(e=>e.severity===`error`)}function C9(e){return e.reduce((e,t)=>e?t.createdAt>e.createdAt?t:e:t,void 0)}function dLe(e){if(!e?.validation)return{label:`not checked yet`,description:`Validation runs before Start creates a workflow run.`,className:`mt-1 text-slate-300`};let t=e.validation,n=`${t.errorCount} errors · ${t.warningCount} warnings`;return t.blocksRun||t.validationState===`error`?{label:`blocked · ${n}`,description:`Last checked ${w9(t.checkedAt)} at ${t.trigger}.`,className:`mt-1 text-red-200`}:t.validationState===`warning`?{label:`warnings · ${n}`,description:`Last checked ${w9(t.checkedAt)} at ${t.trigger}.`,className:`mt-1 text-amber-200`}:{label:`valid · ${n}`,description:`Last checked ${w9(t.checkedAt)} at ${t.trigger}.`,className:`mt-1 text-emerald-200`}}function fLe(e){return e?.toLowerCase().includes(`blocked`)?`border-red-500/40 bg-red-500/10 text-red-200`:`border-emerald-500/40 bg-emerald-500/10 text-emerald-200`}function w9(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function T9(e){return`${e.id}@${e.version}`}function pLe(e){return`${e.title} (${e.id}@${e.version})`}function E9(e){if(!e||typeof e!=`object`||!(`data`in e))return[];let t=e.data;if(!t||typeof t!=`object`||!(`diagnostics`in t))return[];let n=t.diagnostics;return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`):[]}function mLe(e){let t=[],n=[];for(let r of e??[])r.archivedAt?n.push(r):t.push(r);return{active:t,archived:n}}function hLe(e,t){return t?e.find(e=>e.piboSessionId===t):void 0}function gLe(e){return e.filter(R2)}function _Le(e,t){return{...e,...t?.session?{session:t.session}:{},agents:t?.agents??e.agents,customAgents:t?.customAgents??e.customAgents,modelDefaults:t?.modelDefaults??e.modelDefaults,modelCatalog:t?.modelCatalog??e.modelCatalog,agentCatalog:t?.agentCatalog??e.agentCatalog,capabilities:t?.capabilities??e.capabilities,sessions:t?.sessions??[]}}function vLe(e,t,n){return e.find(e=>e.id===t&&e.version===n)??e[0]}function yLe(){return[{code:`ProjectWorkflowSessionCreate.missingWorkflowVersion`,message:`Select a workflow version before creating the Project session.`,severity:`error`}]}function bLe(e){return e?`Workflow run started.`:`Start accepted after validation. No workflow run record exists yet.`}function xLe(e){return`Start blocked: ${e.map(e=>e.code).filter(Boolean).slice(0,3).join(`, `)||`validation diagnostics`}`}var SLe=new Set;function CLe({baseBootstrap:e,routeProjectId:t,routePiboSessionId:n,sessionViews:r,showRawEvents:i,showThinking:a,expandThinking:o,commands:s,skills:c,onNavigate:l,onViewContext:u,onSelectSessionView:d,onToggleRawEvents:f,onToggleThinking:p,onToggleExpandThinking:m,onThinkingLevelChange:h,mobileSidebarOpen:g,onCloseMobileSidebar:_,onError:v}){let[y,b]=(0,R.useState)(null),[x,S]=(0,R.useState)(!0),[C,w]=(0,R.useState)(()=>localStorage.getItem(`pibo.chat.projects.showArchivedProjects`)===`true`),[T,E]=(0,R.useState)(()=>localStorage.getItem(`pibo.chat.projects.showArchivedSessions`)===`true`),[D,O]=(0,R.useState)(!1),[k,A]=(0,R.useState)(!1),[j,M]=(0,R.useState)(`loading`),[N,P]=(0,R.useState)(null),[F,ee]=(0,R.useState)([]),[te,I]=(0,R.useState)(``),[ne,L]=(0,R.useState)(``),[re,ie]=(0,R.useState)(null),[ae,oe]=(0,R.useState)({}),[se,ce]=(0,R.useState)([]),[le,ue]=(0,R.useState)(null),[de,fe]=(0,R.useState)(()=>n?Q0(n):``),[pe,me]=(0,R.useState)(0),he=(0,R.useCallback)(async(e={})=>{S(!0);try{let r=await nc({projectId:e.projectId??t,piboSessionId:e.piboSessionId??n,includeArchived:C||T});return b(r),(!t||r.selectedProjectId!==t||r.selectedPiboSessionId&&r.selectedPiboSessionId!==n)&&l(r.selectedProjectId,r.selectedPiboSessionId,!0,{closeMobileSidebar:!1}),v(null),r}catch(e){throw v(i3(e)),e}finally{S(!1)}},[v,l,n,t,C,T]);(0,R.useEffect)(()=>{he()},[he]),(0,R.useEffect)(()=>{let e=!1;return M(`loading`),P(null),cJ().then(t=>{if(e)return;ee(t.options);let n=vLe(t.options,t.selectedWorkflowId,t.selectedWorkflowVersion);I(e=>e||(n?T9(n):``)),M(`loaded`)}).catch(t=>{e||(P(i3(t)),M(`error`))}),()=>{e=!0}},[]),(0,R.useEffect)(()=>{fe(n?Q0(n):``)},[n]);let ge=y?.project,_e=y?.selectedPiboSessionId??null,ve=_e&&y?$4(y.sessions,_e):void 0,ye=ve?.profile??Z4(e),be=y?.projectSessions??[],xe=hLe(be,_e),Se=gLe(be),Ce=mLe(y?.projects),we=Ce.active,Te=Ce.archived,Ee=(0,R.useMemo)(()=>y?l3(y.sessions,T):{active:[],archived:[]},[y,T]),De=(0,R.useMemo)(()=>_e&&y?new Set(e3(y.sessions,_e).map(e=>e.piboSessionId)):SLe,[y,_e]),Oe=(0,R.useMemo)(()=>_Le(e,y),[e,y]),ke=(0,R.useMemo)(()=>Vke({selectedSessionNode:ve,selectedProjectSession:xe,selectedSession:y?.session,selectedProject:ge}),[y?.session,ge,xe,ve]),Ae=(0,R.useMemo)(()=>$7(ke.viewId),[ke.viewId]),je=async()=>{let e=window.prompt(`Project name`);if(!e)return;let t=window.prompt(`Project folder path (absolute path, e.g. ~/code/my-project or /home/me/code/my-project)`);if(!t)return;let n=window.prompt(`Description (optional)`)??void 0;try{let{project:r}=await rc({name:e,projectFolder:t,createFolder:!0,...n?{description:n}:{}});await he({projectId:r.id}),l(r.id,void 0)}catch(e){v(i3(e))}},Me=async()=>{if(ge){O(!0);try{let e=await oc(ge.id,{profile:ye,workflowId:`simple-chat`});ue(e.session.id),l(ge.id,e.session.id,!1,{closeMobileSidebar:!1}),await he({projectId:ge.id,piboSessionId:e.session.id})}catch(e){v(i3(e))}finally{O(!1)}}},Ne=async()=>{if(!ge)return;let e=F.find(e=>T9(e)===te);if(!e){let e=yLe();ce(e),v(e[0]?.message??`Select a workflow version before creating the Project session.`);return}A(!0),ce([]);try{let t=ne.trim(),n=await Dye(ge.id,{profile:ye,workflowId:e.id,workflowVersion:e.version,...t?{title:t}:{}});L(``),ce([]),l(ge.id,n.session.id,!1,{closeMobileSidebar:!1}),await he({projectId:ge.id,piboSessionId:n.session.id})}catch(e){ce(E9(e)),v(i3(e))}finally{A(!1)}},Pe=async e=>{if(ge){ie(e.piboSessionId);try{let t=bLe((await Mye(ge.id,e.piboSessionId)).projectSession.workflowRunId);oe(n=>({...n,[e.piboSessionId]:t})),v(null),await he({projectId:ge.id,piboSessionId:e.piboSessionId})}catch(t){let n=E9(t);n.length&&oe(t=>({...t,[e.piboSessionId]:xLe(n)})),v(i3(t)),await he({projectId:ge.id,piboSessionId:e.piboSessionId})}finally{ie(null)}}},Fe=async(e,t)=>{try{await sc(e,{title:t}),await he({projectId:ge?.id,piboSessionId:e})}catch(e){v(i3(e))}},Ie=async(e,t)=>{try{await ic(e.id,{name:t}),await he({projectId:ge?.id,piboSessionId:_e??void 0})}catch(e){v(i3(e))}},Le=async(e,t)=>{try{await ic(e.id,{archived:t});let n=await he({projectId:t?void 0:e.id});t&&ge?.id===e.id&&l(n.selectedProjectId,n.selectedPiboSessionId)}catch(e){v(i3(e))}},Re=async e=>{let t=window.prompt(`Type the project name to permanently delete "${e.name}".`);if(t===null)return;let n=window.confirm(`Also delete the real project folder?\n\n${e.projectFolder}`);try{await ac(e.id,{confirmName:t,deleteFiles:n});let r=await he({projectId:ge?.id===e.id?void 0:ge?.id});ge?.id===e.id&&l(r.selectedProjectId,r.selectedPiboSessionId)}catch(e){v(i3(e))}},ze=async e=>{if(!_e)return!1;let t=e.trim().split(/\s+/)[0],n=s.find(e=>e.slash===t);return n?(await yc(_e,n.action),await he({projectId:ge?.id,piboSessionId:_e}),!0):!1},Be=ge&&xe&&Bke(xe)?(0,z.jsx)(sLe,{projectSession:xe,lifecycleEvents:y?.workflowLifecycleEvents??[],starting:re===xe.piboSessionId,message:ae[xe.piboSessionId]??null,onStart:()=>void Pe(xe)}):null;return x&&!y?(0,z.jsx)(`main`,{className:`min-h-0 grid place-items-center text-slate-400`,children:`Loading Projects...`}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/60 min-[981px]:hidden transition-opacity duration-200 ${g?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`,onClick:_}),(0,z.jsx)(nLe,{data:y,selectedProject:ge,selectedPiboSessionId:_e,selectedProjectSession:xe,workflowProjectSessions:Se,activeProjects:we,archivedProjects:Te,sessionGroups:Ee,selectedSessionPathIds:De,autoRenameSessionId:le,creatingSession:D,showArchivedProjects:C,showArchivedSessions:T,mobileSidebarOpen:g,onRefresh:()=>void he(),onCloseMobileSidebar:_,onCreateProject:()=>void je(),onToggleArchivedProjects:()=>{let e=!C;w(e),localStorage.setItem(`pibo.chat.projects.showArchivedProjects`,String(e))},onSelectProject:e=>l(e,void 0),onRenameProject:(e,t)=>void Ie(e,t),onSetProjectArchived:(e,t)=>void Le(e,t),onDeleteArchivedProject:e=>void Re(e),onCreateProjectSession:()=>void Me(),onToggleArchivedSessions:()=>{let e=!T;E(e),localStorage.setItem(`pibo.chat.projects.showArchivedSessions`,String(e))},onSelectSession:e=>l(ge?.id,e),onRenameSession:(e,t)=>void Fe(e,t),onArchiveSession:(e,t)=>void sc(e,{archived:t}).then(()=>he({projectId:ge?.id})),onDeleteSession:e=>void sc(e.piboSessionId,{archived:!0}).then(()=>he({projectId:ge?.id})),onViewContext:u,onAutoRenameConsumed:()=>ue(null)}),(0,z.jsx)(a3,{bootstrap:Oe,selectedPiboSessionId:_e,selectedRoomId:null,selectedRoomArchived:!!ge?.archivedAt,workflowProjectSession:ke.workflowProjectSession,workflowLifecycleEvents:y?.workflowLifecycleEvents??[],projectSessionCreatePanel:ge?(0,z.jsx)(iLe,{project:ge,options:F,selectedOptionKey:te,titleValue:ne,loadState:j,errorMessage:N,creating:k,diagnostics:se,onSelectedOptionChange:e=>{I(e),ce([])},onTitleChange:L,onCreate:()=>void Ne()}):null,workflowStartPanel:Be,selectedSessionProfile:ye,selectedSessionActiveModel:Q4(Oe,ve??{profile:ye}),selectedSessionStatus:ve?.status,sessionViewId:ke.viewId,sessionViews:r,currentSessionView:Ae,allowedSessionViewIds:zke[ke.viewId],creatingSession:D||k,showRawEvents:i,showThinking:a,expandThinking:o,commands:s,skills:c,composerText:de,composerFocusSignal:pe,onComposerTextChange:e=>fe(t=>typeof e==`function`?e(t):e),onToggleRawEvents:f,onToggleThinking:p,onToggleExpandThinking:m,onSessionAgentProfileChange:async e=>{_e&&await gc(_e,{profile:e})},onFork:()=>void 0,onOpenSession:e=>l(ge?.id,e),onSelectSessionView:d,onCommand:ze,onThinkingLevelChange:h,onRefreshTrace:async()=>void 0,onRefreshBootstrap:async()=>{await he({projectId:ge?.id,piboSessionId:_e??void 0})},onSend:async e=>{_e&&(await cc(_e,e,t3()),await he({projectId:ge?.id,piboSessionId:_e}))},onError:v})]})}var D9=`Delete this session`;function wLe({session:e,confirmText:t,deleting:n,onConfirmTextChange:r,onCancel:i,onDelete:a}){return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 grid place-items-center p-4`,children:(0,z.jsxs)(`div`,{className:`w-full max-w-lg border border-red-500/70 bg-[#1a262b] rounded-sm shadow-xl`,children:[(0,z.jsxs)(`div`,{className:`px-4 py-3 border-b border-red-500/50 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{className:`text-sm font-bold uppercase tracking-wider text-red-200`,children:`Delete Session`}),(0,z.jsx)(`div`,{className:`font-mono text-[11px] text-slate-500 truncate`,children:e.piboSessionId})]}),(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,title:`Cancel`,"aria-label":`Cancel`,className:`h-8 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,z.jsx)(Qs,{size:14})})]}),(0,z.jsxs)(`div`,{className:`p-4 grid gap-3`,children:[(0,z.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-100 rounded-sm p-3 text-sm`,children:`This permanently deletes the archived session, its child sessions, and their Chat events. This cannot be undone.`}),(0,z.jsxs)(`div`,{className:`text-sm text-slate-300`,children:[`Type `,(0,z.jsx)(`span`,{className:`font-mono text-red-200`,children:D9}),` to confirm.`]}),(0,z.jsx)(`input`,{value:t,onChange:e=>r(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-red-500`,placeholder:D9,autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`h-8 inline-flex items-center border border-slate-700 rounded-sm px-3 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:`Cancel`}),(0,z.jsxs)(`button`,{type:`button`,onClick:a,disabled:n||t!==D9,className:`h-8 inline-flex items-center gap-2 border border-red-500 rounded-sm px-3 text-red-200 bg-red-500/10 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:14}),`Delete permanently`]})]})]})]})})}function TLe({room:e,confirmName:t,deleting:n,onConfirmNameChange:r,onCancel:i,onDelete:a}){return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 grid place-items-center p-4`,children:(0,z.jsxs)(`div`,{className:`w-full max-w-lg border border-red-500/70 bg-[#1a262b] rounded-sm shadow-xl`,children:[(0,z.jsxs)(`div`,{className:`px-4 py-3 border-b border-red-500/50 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{className:`text-sm font-bold uppercase tracking-wider text-red-200`,children:`Delete Room`}),(0,z.jsx)(`div`,{className:`font-mono text-[11px] text-slate-500 truncate`,children:e.id})]}),(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,title:`Cancel`,"aria-label":`Cancel`,className:`h-8 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,z.jsx)(Qs,{size:14})})]}),(0,z.jsxs)(`div`,{className:`p-4 grid gap-3`,children:[(0,z.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-100 rounded-sm p-3 text-sm`,children:`This permanently deletes the archived room, child rooms, all contained sessions, subagent sessions, and their Chat events. This cannot be undone.`}),(0,z.jsxs)(`div`,{className:`text-sm text-slate-300`,children:[`Type `,(0,z.jsx)(`span`,{className:`font-mono text-red-200`,children:e.name}),` to confirm.`]}),(0,z.jsx)(`input`,{value:t,onChange:e=>r(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-red-500`,placeholder:e.name,autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`h-8 inline-flex items-center border border-slate-700 rounded-sm px-3 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:`Cancel`}),(0,z.jsxs)(`button`,{type:`button`,onClick:a,disabled:n||t!==e.name,className:`h-8 inline-flex items-center gap-2 border border-red-500 rounded-sm px-3 text-red-200 bg-red-500/10 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:14}),`Delete permanently`]})]})]})]})})}var O9=[`sessions`,`projects`,`workflows`,`cron`,`ralph`,`agents`,`context`,`settings`];function ELe(){return(0,z.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,z.jsx)(Js,{size:16}),`Recovery Mode: Main gateway is down. You are connected to a fallback instance.`]})}function DLe({area:e,identity:t,mobileAreaMenuOpen:n,mobileAreaMenuRef:r,totalRoomUnreadCount:i,onOpenMobileSidebar:a,onSelectMainNavArea:o,onToggleMobileAreaMenu:s}){let c=t.email||t.name||t.userId;return(0,z.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,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:a,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,z.jsx)(Es,{size:16})}),(0,z.jsx)(`img`,{src:`/apps/chat/assets/pwa-images/android/launchericon-512x512.png`,alt:`Logo`,className:`h-5 w-auto shrink-0`}),(0,z.jsx)(`div`,{className:`truncate font-extrabold tracking-[0.08em] uppercase text-lg max-[420px]:text-base`,children:`Pibo Chat`})]}),(0,z.jsx)(`nav`,{className:`flex gap-1 max-[1200px]:hidden min-[1201px]:absolute min-[1201px]:left-1/2 min-[1201px]:-translate-x-1/2`,children:O9.map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>o(t),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,z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,z.jsx)(`span`,{children:t}),t===`sessions`?(0,z.jsx)(k9,{count:i}):null]})},t))}),(0,z.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,z.jsx)(Ys,{size:14}),(0,z.jsx)(`span`,{className:`truncate max-[600px]:hidden`,children:c}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void iPe().then(()=>location.reload()),className:`p-1 border border-slate-700 rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Sign out`,"aria-label":`Sign out`,children:(0,z.jsx)(ws,{size:14})}),(0,z.jsxs)(`div`,{className:`relative min-[1201px]:hidden`,ref:r,children:[(0,z.jsx)(`button`,{type:`button`,onClick:s,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-expanded":n,children:(0,z.jsx)(Ss,{size:14})}),n?(0,z.jsx)(`div`,{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`,children:O9.map(t=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>o(t),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`,children:[(0,z.jsx)(`span`,{children:t}),t===`sessions`?(0,z.jsx)(k9,{count:i}):null]},t))}):null]})]})]})}function OLe({message:e,onDismiss:t}){return(0,z.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,z.jsxs)(`div`,{className:`min-w-0 flex items-start gap-2`,children:[(0,z.jsx)(Js,{size:16,className:`mt-0.5 shrink-0 text-red-300`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-red-300`,children:`Session Error`}),(0,z.jsx)(`div`,{className:`break-words`,children:e})]})]}),(0,z.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 kLe({message:e}){return(0,z.jsx)(`div`,{className:`min-h-screen bg-[#101d22] text-slate-300 grid place-items-center`,children:(0,z.jsxs)(`div`,{className:`border border-slate-700 bg-[#1a262b] p-5 rounded-sm`,children:[(0,z.jsx)(`div`,{className:`mb-4 text-sm text-slate-400`,children:e}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void aPe(),className:`px-3 py-2 bg-[#11a4d4] rounded-sm`,children:`Sign in with Google`})]})})}function ALe(e){return e>99?`99+`:String(e)}function k9({count:e}){return!e||e<=0?null:(0,z.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:ALe(e)})}function A9(e,t){return j9(e,e=>F9(t.sessions[e]))}function jLe(e,t){let n=new Map(t.sessionSnapshots.map(e=>[e.piboSessionId,F9(e)]));return j9(e,e=>n.get(e))}function j9(e,t){return{...e,sessions:e.sessions.map(e=>M9(e,t))}}function M9(e,t){let n=t(e.piboSessionId),r=P9(n,N9(e)),i=r&&r!==e.status?L9(e.lastActivityAt,n?.updatedAt,new Date().toISOString()):L9(e.lastActivityAt,n?.updatedAt);return{...e,status:r??e.status,lastActivityAt:i,children:e.children.map(e=>M9(e,t)),derivedSessions:e.derivedSessions.map(e=>{let n=t(e.piboSessionId),r=P9(n,0),i=!!(r&&r!==e.status);return{...e,status:r??e.status,lastActivityAt:i?L9(e.lastActivityAt,n?.updatedAt,new Date().toISOString()):L9(e.lastActivityAt,n?.updatedAt)}})}}function N9(e){return(e.unreadCount??0)+e.children.reduce((e,t)=>e+N9(t),0)}function P9(e,t){return e?.status===`error`?t>0?`error`:e.isTreeActive?`running`:`idle`:e?.status}function F9(e){let t=I9(e);if(!(!e&&!t))return{status:t,updatedAt:e?.updatedAt,isTreeActive:e?.isTreeActive}}function I9(e){if(e)return e.hasError||e.hasErrorDescendant||e.aggregateStatus===`error`?`error`:e.isTreeActive?`running`:`idle`}function L9(...e){let t,n=-1/0;for(let r of e){if(!r)continue;let e=Date.parse(r);!Number.isFinite(e)||e<n||(t=r,n=e)}return t}function MLe(e,t){if(!e||e.rootPiboSessionId!==t.rootPiboSessionId||e.version!==t.fromVersion)return e;let n={...e.nodes};for(let e of t.removes)delete n[e];for(let e of t.upserts)n[e.id]=e;let r={...e.sessions};for(let e of t.sessionSnapshots)r[e.piboSessionId]=e;return{...e,version:t.toVersion,generatedAt:t.generatedAt,nodes:n,sessions:r}}function R9(e,t,n={}){let r=n.readSessionId?NLe(e.sessions,n.readSessionId):new Set,i=new Map;z9(e.sessions,i);let a=[...r].reduce((e,t)=>e+(i.get(t)??0),0);return{...e,identity:t.identity,session:t.session,room:t.room,selectedRoomId:t.selectedRoomId,selectedPiboSessionId:t.selectedPiboSessionId,latestRoomStreamId:t.latestRoomStreamId,rooms:PLe(e.rooms,t.rooms,t.selectedRoomId,a),sessions:V9(t.sessions,r,i)}}function z9(e,t){for(let n of e)t.set(n.piboSessionId,n.unreadCount??0),z9(n.children,t)}function NLe(e,t){let n=new Set,r=e=>e.piboSessionId===t?(B9(e,n),!0):e.children.some(e=>r(e));for(let t of e)r(t);return n}function B9(e,t){t.add(e.piboSessionId);for(let n of e.children)B9(n,t)}function V9(e,t,n){return e.map(e=>{let r=n.get(e.piboSessionId),i=t.has(e.piboSessionId)?0:e.unreadCount??r??0;return{...e,...i>0?{unreadCount:i}:{unreadCount:void 0},children:V9(e.children,t,n)}})}function PLe(e,t,n,r){let i=new Map;return H9(e,i),U9(t,i,n,r).rooms}function H9(e,t){for(let n of e)t.set(n.id,n.unreadCount??0),H9(n.children??[],t)}function U9(e,t,n,r){let i=!1;return{rooms:e.map(e=>{let a=U9(e.children??[],t,n,r),o=e.id===n||a.selectedRoomFound;i||=o;let s=e.unreadCount??t.get(e.id)??0,c=o&&r>0?Math.max(0,s-r):s;return{...e,...c>0?{unreadCount:c}:{unreadCount:void 0},...e.children?{children:a.rooms}:{}}}),selectedRoomFound:i}}function FLe(e,t){if(!t.length)return e;let n=new Set(e.map(e=>e.piboSessionId)),r=t.filter(e=>!n.has(e.piboSessionId));return r.length?[...e,...r]:e}function ILe(e,t){return e.agentCatalog?{...e,agentCatalog:{...e.agentCatalog,mcpServers:e.agentCatalog.mcpServers.map(e=>e.name===t.name?t:e)}}:e}function W9(e,t){if(!e.agentCatalog)return e;let n=e.agentCatalog.piPackages.filter(e=>e.id!==t.id);return{...e,agentCatalog:{...e.agentCatalog,piPackages:J9([...n,t])}}}function G9(e,t){return e.agentCatalog?{...e,agentCatalog:{...e.agentCatalog,piPackages:e.agentCatalog.piPackages.filter(e=>e.id!==t)}}:e}function K9(e,t){if(!e.agentCatalog)return e;let n=e.agentCatalog.userSkills.filter(e=>e.id!==t.id);return{...e,agentCatalog:{...e.agentCatalog,userSkills:J9([...n,t])}}}function q9(e,t){return e.agentCatalog?{...e,agentCatalog:{...e.agentCatalog,userSkills:e.agentCatalog.userSkills.filter(e=>e.id!==t)}}:e}function J9(e){return e.sort((e,t)=>e.name.localeCompare(t.name))}function LLe(e,t){let n=r9(e);return{deletedSessionIds:n,selectedSessionDeleted:t?n.has(t):!1,restoreSelectedPiboSessionId:t}}function RLe(e,t,n){return t?e.includes(t):n}function zLe(e,t){return t?void 0:e??void 0}function BLe(e,t,n){let r=l9(e);return{deletedRoomIds:r,selectedRoomDeleted:t?r.has(t):!1,restoreSelectedRoomId:t,restoreSelectedPiboSessionId:n}}function VLe(e,t){return t===e}function HLe({queryClient:e,bootstrap:t,selectedPiboSessionId:n,selectedRoomId:r,showArchivedRef:i,isSessionsArea:a,loadBootstrap:o,navigateToSelectedSession:s,updateBootstrapCache:c,restoreBootstrapSnapshot:l,setSelectedPiboSessionId:u,setSelectedRoomId:d,setError:f}){let[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(``),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),[x,S]=(0,R.useState)(``),[C,w]=(0,R.useState)(!1),T=e=>{b(e),S(``)},E=()=>{b(null),S(``)},D=async()=>{if(!y)return;w(!0),await e.cancelQueries({queryKey:[`chat`,`bootstrap`]});let d=e9(e,t),p=LLe(y,n);p.selectedSessionDeleted&&u(null),c(e=>SIe(e,p.deletedSessionIds));try{let e=RLe((await _c(y.piboSessionId,x)).deletedSessionIds,n,p.selectedSessionDeleted);e&&u(null);let t=await o(zLe(n,e),i.current,r??void 0,{force:!0});a&&s(t.selectedRoomId,t.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),E(),f(null)}catch(e){l(d),p.selectedSessionDeleted&&u(p.restoreSelectedPiboSessionId),f(e instanceof Error?e.message:String(e))}finally{w(!1)}},O=e=>{m(e),g(``)},k=()=>{m(null),g(``)};return{deleteRoomTarget:p,deleteRoomConfirmName:h,deletingRoom:_,setDeleteRoomConfirmName:g,requestRoomDelete:O,cancelRoomDelete:k,permanentlyDeleteRoom:async()=>{if(!p)return;v(!0),await e.cancelQueries({queryKey:[`chat`,`bootstrap`]});let m=e9(e,t),g=BLe(p,r,n);g.selectedRoomDeleted&&(d(null),u(null)),c(e=>EIe(e,g.deletedRoomIds));try{await hc(p.id,h),VLe(p.id,r)&&(d(null),u(null));let e=await o(void 0,i.current,void 0,{force:!0});a&&s(e.selectedRoomId,e.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),k(),f(null)}catch(e){l(m),g.selectedRoomDeleted&&(d(g.restoreSelectedRoomId),u(g.restoreSelectedPiboSessionId)),f(e instanceof Error?e.message:String(e))}finally{v(!1)}},deleteSessionTarget:y,deleteSessionConfirmText:x,deletingSession:C,setDeleteSessionConfirmText:S,requestSessionDelete:T,cancelSessionDelete:E,permanentlyDeleteSession:D}}var ULe=750,Y9=120,X9=60,WLe=new Set;async function GLe(e,t){let n=tje(t.piboSessionId,t.includeArchived,t.roomId);return await e.removeQueries({queryKey:n,exact:!0}),ec(t.piboSessionId,t.includeArchived,t.roomId,!!t.markRead)}async function Z9(e,t){let n=nje(t.includeArchived,t.roomId,t.piboSessionId);return await e.removeQueries({queryKey:n,exact:!0}),tc(t.piboSessionId,t.includeArchived,t.roomId)}function KLe({route:e}){let t=ja(),n=Yt(),r=e.area,i=e.area===`sessions`?e.roomId:void 0,a=e.area===`projects`?e.projectId:void 0,o=e.area===`sessions`||e.area===`projects`||e.area===`context`?e.piboSessionId:void 0,s=e.area===`sessions`||e.area===`projects`?e.sessionViewId:void 0,c=e.area===`settings`?e.panel??`general`:`general`,[l,u]=(0,R.useState)(null),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(null),[_,v]=(0,R.useState)(ske),[y,b]=(0,R.useState)(cke),[x,S]=(0,R.useState)(lke),[C,w]=(0,R.useState)(uke),[T,E]=(0,R.useState)(fke),[D,O]=(0,R.useState)(pke),[k,A]=(0,R.useState)(()=>s??t2()),[j,M]=(0,R.useState)(``),[N,P]=(0,R.useState)(0),[F,ee]=(0,R.useState)(!1),te=(0,R.useRef)(!1),[I,ne]=(0,R.useState)(!1),[L,re]=(0,R.useState)(!1),[ie,ae]=(0,R.useState)(Y9),[oe,se]=(0,R.useState)(X9),[ce,le]=(0,R.useState)(null),[ue,de]=(0,R.useState)(null),[fe,pe]=(0,R.useState)(`build-context`),[me,he]=(0,R.useState)(null),[ge,_e]=(0,R.useState)(null),[ve,ye]=(0,R.useState)(!1),[be,xe]=(0,R.useState)(!1),[Se,Ce]=(0,R.useState)(!1),we=(0,R.useRef)(null),[Te,Ee]=(0,R.useState)(null),[De,Oe]=(0,R.useState)(null),[ke,Ae]=(0,R.useState)(()=>Date.now()),je=(0,R.useRef)(C),Me=(0,R.useRef)(null),Ne=(0,R.useRef)(null),Pe=(0,R.useRef)(0),Fe=p??l?.selectedRoomId??null,Ie=Fe&&l?d3(l.rooms,Fe)??l.room:void 0,Le=Ie?m3(Ie):!1;(0,R.useEffect)(()=>{je.current=C},[C]),(0,R.useEffect)(()=>{if(!Se)return;let e=e=>{we.current&&!we.current.contains(e.target)&&Ce(!1)},t=e=>{e.key===`Escape`&&Ce(!1)};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)}},[Se]),(0,R.useEffect)(()=>{Ne.current=l},[l]),(0,R.useEffect)(()=>{ae(Y9),se(X9)},[p,C]),(0,R.useEffect)(()=>{Ae(Date.now())},[l]),(0,R.useEffect)(()=>{if(r!==`sessions`||!d){Oe(null);return}let e,t=t=>{e&&clearTimeout(e),e=setTimeout(()=>{e=void 0,Rc(d).then(e=>{Oe(e),u(t=>t&&A9(t,e))}).catch(()=>void 0)},t)},n=zc(d,{onSnapshot:t=>{e&&=(clearTimeout(e),void 0),Oe(t),u(e=>e&&A9(e,t))},onPatch:e=>{Oe(n=>{let r=MLe(n,e);return n&&r===n&&t(0),r}),u(t=>t&&jLe(t,e))},onError:()=>t(ULe)});return()=>{e&&clearTimeout(e),n()}},[r,d]),(0,R.useEffect)(()=>{let e=l?Kje(l.sessions,ke):void 0;if(e===void 0)return;let t=setTimeout(()=>Ae(Date.now()),Math.max(50,e));return()=>clearTimeout(t)},[l,ke]),(0,R.useEffect)(()=>{let e=async()=>{try{let e=await fetch(`/health`,{signal:AbortSignal.timeout(3e3)});e.ok?Ee((await e.json()).mode===`fallback`?`fallback`:`main`):Ee(null)}catch{Ee(null)}};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,R.useEffect)(()=>{if(r!==`sessions`&&r!==`projects`)return;let e=s??t2();A(t=>t===e?t:e)},[r,s]),(0,R.useEffect)(()=>{oke(k)},[k]);let Re=(0,R.useCallback)((e,n=!1,r=k,i={})=>{i.closeMobileSidebar!==!1&&xe(!1),kc(t,e,n,r)},[t,k]),ze=(0,R.useCallback)((e,t,n=!1,r={})=>{if(!t){Re({area:`sessions`,...e?{roomId:e}:{}},n,k,r);return}Re({area:`sessions`,...e?{roomId:e}:{},piboSessionId:t},n,k,r)},[Re,k]),Be=(0,R.useCallback)((e,t,n=!1,r={})=>{if(!t){Re({area:`projects`,...e?{projectId:e}:{}},n,k,r);return}Re({area:`projects`,...e?{projectId:e}:{},piboSessionId:t},n,k,r)},[Re,k]),Ve=(0,R.useCallback)(e=>{pe(`build-context`),Re({area:`context`,piboSessionId:e})},[Re]),He=(0,R.useCallback)(e=>{he(e),pe(`context-files`),Re({area:`context`})},[Re]),Ue=(0,R.useCallback)(e=>{_e(e),pe(`mcp-tools`),Re({area:`context`})},[Re]),We=(0,R.useCallback)(e=>{u(t=>t&&ILe(t,e))},[]),Ge=(0,R.useCallback)(e=>{u(t=>t&&W9(t,e)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&W9(t,e))},[n]),Ke=(0,R.useCallback)(e=>{u(t=>t&&G9(t,e.id)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&G9(t,e.id))},[n]),qe=(0,R.useCallback)(e=>{u(t=>t&&K9(t,e)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&K9(t,e))},[n]),Je=(0,R.useCallback)(e=>{u(t=>t&&q9(t,e)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&q9(t,e))},[n]),Ye=(0,R.useCallback)(async(e,t=je.current,r,i={})=>{let a=Ne.current;if(a&&i.selectSession!==!1&&!i.force){e&&await dc(e);let i=Pe.current+1;Pe.current=i;let o=R9(a,await Z9(n,{piboSessionId:e,includeArchived:t,roomId:r}),{readSessionId:e});return i===Pe.current?(u(o),f(o.selectedPiboSessionId),m(o.selectedRoomId),o):o}let o=Pe.current+1;Pe.current=o;let s=await GLe(n,{piboSessionId:e,includeArchived:t,roomId:r,markRead:i.selectSession!==!1,force:i.force});return o===Pe.current?(u(s),i.selectSession!==!1&&f(s.selectedPiboSessionId),m(s.selectedRoomId),s):s},[n]),Xe=(0,R.useCallback)(async(e,t=je.current,r,i={})=>{let a=Ne.current;if(!a)return Ye(e,t,r,{force:i.force});let o=Pe.current+1;Pe.current=o;let s=R9(a,await Z9(n,{piboSessionId:e,includeArchived:t,roomId:r,force:i.force}),{readSessionId:i.readSessionId});return o===Pe.current?(u(s),f(s.selectedPiboSessionId),m(s.selectedRoomId),s):s},[Ye,n]);(0,R.useEffect)(()=>{if(r!==`sessions`)return;let e=!1,t=window.setInterval(()=>{e||document.hidden||!Ne.current||Xe(d??void 0,je.current,Fe??void 0,{force:!0}).catch(()=>void 0)},2500);return()=>{e=!0,window.clearInterval(t)}},[Fe,r,Xe,d]),(0,R.useEffect)(()=>{let{requestedRoomId:t,requestedPiboSessionId:n}=IIe(e,X0()),r=(t,n=!0)=>{let r=RIe(e,t);r&&ze(r.selectedRoomId,r.selectedPiboSessionId,n)};if(LIe({bootstrap:l,creatingSession:te.current,route:e}))return;let a=l?Xe:Ye;a(n,je.current,t).then(e=>{r(e),g(null)}).catch(s=>{if(e.area===`sessions`&&i&&!o&&n){Z0(i),a(void 0,je.current,i).then(e=>{r(e),g(null)}).catch(e=>g(e instanceof Error?e.message:String(e)));return}if(zIe(e)||!n&&!t){g(s instanceof Error?s.message:String(s));return}mke(),a().then(e=>{r(e),g(null)}).catch(e=>g(e instanceof Error?e.message:String(e)))})},[l,Ye,Xe,ze,e.area,o,i]),(0,R.useEffect)(()=>{!p&&!d||ike({roomId:p??void 0,piboSessionId:d??void 0})},[d,p]),(0,R.useEffect)(()=>{M(d?Q0(d):``)},[d]);let Ze=(0,R.useCallback)(e=>{M(t=>{let n=typeof e==`function`?e(t):e;return d&&$0(d,n),n})},[d]),Qe=(0,R.useMemo)(()=>xIe(),[]),$e=(0,R.useMemo)(()=>$7(k),[k]);(0,R.useEffect)(()=>{if(!l?.agents.length)return;let e=Z4(l),t=D||e,n=Q9(l.agents,t);if(n){D!==n.name&&(O(n.name),o2(n.name));return}let r=Q9(l.agents,e)?.name??l.agents[0].name;O(r),o2(r)},[l,D]);let et=(0,R.useCallback)(e=>{O(e),o2(e)},[]),tt=(0,R.useCallback)(async e=>{let t=JU(e),r=!1;try{await Promise.all([n.invalidateQueries({queryKey:z4(e),refetchType:`none`}),n.invalidateQueries({queryKey:B4(e),refetchType:`none`})]),await Promise.all([n.refetchQueries({queryKey:z4(e),type:`active`}),n.refetchQueries({queryKey:B4(e),type:`active`})])}catch(e){throw r=!0,e}finally{YU(e,t,r)}},[n]),nt=(0,R.useCallback)(()=>d?tt(d):Promise.resolve(),[tt,d]),rt=(0,R.useCallback)(()=>Xe(d??void 0,je.current,p??void 0,{force:!0}),[Xe,d,p]),it=(0,R.useCallback)(async()=>{g(null);let e=d??void 0;await Ye(e,je.current,p??void 0,{force:!0,selectSession:!1}),e&&await tt(e)},[Ye,tt,d,p]),at=(0,R.useCallback)(e=>{u(t=>t&&e(t)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&e(t))},[n]),ot=l?.latestRoomStreamId;(0,R.useEffect)(()=>{if(r!==`sessions`||!Fe)return;let e=new URLSearchParams({roomId:Fe});e.set(`mode`,`summary`),e.set(`since`,`${ot??0}:999999`);let t=new EventSource(`/api/chat/events?${e.toString()}`),n,i=()=>{n&&clearTimeout(n),n=setTimeout(()=>{n=void 0,Ye(d??void 0,je.current,Fe,{force:!0,selectSession:!1}).catch(e=>g(i3(e)))},900)};return t.addEventListener(`pibo`,e=>{let t=Yc(e);if(!t||t.type===`ready`)return;let n=t.piboSessionId,r=ol(t);if(n&&r){let e=new Date().toISOString();at(t=>a9(t,n,t=>({...t,status:r,lastActivityAt:e})))}el(t)&&i()}),()=>{n&&clearTimeout(n),t.close()}},[Fe,r,ot,Ye,d,at]);let st=(0,R.useCallback)(e=>{if(e){u(e.localBootstrap);for(let[t,r]of e.queryData)n.setQueryData(t,r)}},[n]),{deleteRoomTarget:ct,deleteRoomConfirmName:lt,deletingRoom:ut,setDeleteRoomConfirmName:dt,requestRoomDelete:ft,cancelRoomDelete:pt,permanentlyDeleteRoom:mt,deleteSessionTarget:ht,deleteSessionConfirmText:gt,deletingSession:_t,setDeleteSessionConfirmText:vt,requestSessionDelete:yt,cancelSessionDelete:bt,permanentlyDeleteSession:xt}=HLe({queryClient:n,bootstrap:l,selectedPiboSessionId:d,selectedRoomId:p,showArchivedRef:je,isSessionsArea:r===`sessions`,loadBootstrap:Ye,navigateToSelectedSession:ze,updateBootstrapCache:at,restoreBootstrapSnapshot:st,setSelectedPiboSessionId:f,setSelectedRoomId:m,setError:g}),St=fn({mutationFn:({profile:e,roomId:t})=>uc(e||void 0,t),onMutate:async({profile:e})=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let t=e9(n,l),r=d,i=`optimistic-session-${t3()}`;return f(i),at(t=>({...t9(t,kIe(i,e||Z4(t))),selectedPiboSessionId:i})),{snapshot:t,tempId:i,previousSelectedPiboSessionId:r}},onError:(e,t,n)=>{st(n?.snapshot),f(n?.previousSelectedPiboSessionId??null)},onSuccess:(e,t,n)=>{f(e.session.id),at(t=>CIe(t,n?.tempId,d9(e.session)))}}),Ct=fn({mutationFn:({piboSessionId:e,title:t})=>gc(e,{title:t}),onMutate:async({piboSessionId:e,title:t})=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let r=e9(n,l);return at(n=>a9(n,e,e=>({...e,title:t||`Untitled Session`}))),{snapshot:r}},onError:(e,t,n)=>st(n?.snapshot),onSuccess:({session:e})=>at(t=>i9(t,e))}),wt=fn({mutationFn:({piboSessionId:e,archived:t})=>gc(e,{archived:t}),onMutate:async({piboSessionId:e,archived:t})=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let r=e9(n,l);return at(n=>a9(n,e,e=>({...e,archived:t,unreadCount:t?0:e.unreadCount}))),{snapshot:r}},onError:(e,t,n)=>st(n?.snapshot),onSuccess:({session:e})=>at(t=>i9(t,e))}),Tt=fn({mutationFn:({piboSessionId:e,text:t,clientTxnId:n,roomId:r,webAnnotationIds:i,fileAttachmentPaths:a})=>vc(e,t,n,r,i,a),onMutate:async({piboSessionId:e})=>{await n.cancelQueries({queryKey:B4(e)}),at(t=>a9(t,e,e=>({...e,status:`running`,lastActivityAt:new Date().toISOString()})))},onError:(e,t)=>{at(e=>a9(e,t.piboSessionId,e=>({...e,status:`error`})))}}),Et=(0,R.useCallback)(async e=>{if(!(!d||!l||e===Z4(l)))try{await gc(d,{profile:e}),et(e);let t=await Ye(d,je.current,p??void 0);r===`sessions`&&ze(t.selectedRoomId,t.selectedPiboSessionId),await tt(d),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},[r,l,Ye,ze,tt,d,p,et]),Dt=(0,R.useMemo)(()=>PIe(l?.capabilities.actions??[]),[l]),Ot=(0,R.useMemo)(()=>FIe(l,d),[l,d]),kt=(0,R.useCallback)(async e=>{(0,Na.flushSync)(()=>{f(e),le(e),xe(!1)}),ze(p??l?.selectedRoomId,e,!1,{closeMobileSidebar:!1});try{await dc(e);let t=await Xe(e,je.current,p??l?.selectedRoomId,{readSessionId:e});ze(t.selectedRoomId,t.selectedPiboSessionId,!0,{closeMobileSidebar:!1})}finally{le(t=>t===e?null:t)}},[l?.selectedRoomId,Xe,ze,p]),At=(0,R.useCallback)(async(e,t={})=>{let n={...t,closeMobileSidebar:!1},r=X0().sessionsByRoom?.[e];m(e),f(r??null);try{let t=await Xe(r,je.current,e);ze(t.selectedRoomId,t.selectedPiboSessionId,!1,n)}catch(t){if(!r)throw t;Z0(e),f(null);let i=await Xe(void 0,je.current,e);ze(i.selectedRoomId,i.selectedPiboSessionId,!1,n)}},[Xe,ze]),jt=async(e=D)=>{if(!(F||Le)){te.current=!0,ee(!0);try{let t=await St.mutateAsync({profile:e,roomId:p??void 0});f(t.session.id),de(t.session.id),ze(p??l?.selectedRoomId??void 0,t.session.id,!1,{closeMobileSidebar:!1});let n=await Ye(t.session.id,je.current,p??void 0,{force:!0});ze(n.selectedRoomId,n.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{te.current=!1,ee(!1)}}},Mt=async()=>{let e=!C;if(w(e),dke(e),!e){re(!1),g(null);return}re(!0);try{let e=await Xe(d??void 0,!0,p??void 0);r===`sessions`&&ze(e.selectedRoomId,e.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{re(!1)}},Nt=async(e,t)=>{try{await Ct.mutateAsync({piboSessionId:e,title:t});let n=await Ye(d??void 0,je.current,p??void 0,{force:!0});r===`sessions`&&await tt(n.selectedPiboSessionId),r===`sessions`&&ze(n.selectedRoomId,n.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},Pt=async(e,t)=>{try{await wt.mutateAsync({piboSessionId:e,archived:t});let n=await Ye(t&&!C&&d===e?void 0:d??void 0,je.current,p??void 0,{force:!0});r===`sessions`&&ze(n.selectedRoomId,n.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},Ft=async()=>{if(ve)return;ye(!0),await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let e=e9(n,l),t=`optimistic-room-${t3()}`,r=DIe(t,`New Chat`);m(t),f(null),at(e=>wIe(e,r));try{let e=await pc({name:`New Chat`});at(n=>TIe(n,t,e.room)),await At(e.room.id,{closeMobileSidebar:!1}),g(null)}catch(t){st(e),m(p),f(d),g(t instanceof Error?t.message:String(t))}finally{ye(!1)}},It=async(e,t)=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let i=e9(n,l);at(n=>o9(n,e,e=>({...e,...t.name===void 0?{}:{name:t.name},...t.topic===void 0?{}:{topic:t.topic??void 0},...t.workspace===void 0?{}:{workspace:t.workspace??void 0},updatedAt:new Date().toISOString()})));try{let{room:n}=await mc(e,t);at(t=>o9(t,e,()=>n));let i=await Ye(d??void 0,je.current,e,{force:!0});r===`sessions`&&ze(i.selectedRoomId,i.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){st(i),g(e instanceof Error?e.message:String(e))}},Lt=async e=>{try{await fc(e);let t=await Ye(d??void 0,je.current,p??void 0,{force:!0,selectSession:!1});r===`sessions`&&ze(t.selectedRoomId,t.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},Rt=async(e,t)=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let i=e9(n,l);t&&(E(!0),a2(!0)),at(n=>o9(n,e,e=>OIe(e,t)));try{let{room:n}=await mc(e,{archived:t});at(t=>o9(t,e,()=>n));let i=await Ye(d??void 0,je.current,p??void 0,{force:!0});r===`sessions`&&ze(i.selectedRoomId,i.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){st(i),g(e instanceof Error?e.message:String(e))}},zt=(0,R.useCallback)(async e=>{if(!d||Le)return!1;let t=e.trim().split(/\s+/)[0],n=Dt.find(e=>e.slash===t);if(!n)return!1;if(n.action===`thinking-show`){let e=!_;return v(e),n2(e),!0}if(n.action===`download`){let n=AIe(e.slice(t.length));if(!n)return g(`Usage: /download <path>`),!0;try{await Pc(n,{piboSessionId:d,roomId:p??void 0}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}return!0}let i=jIe(n.action,e.slice(t.length).trim()),a=NIe(await yc(d,n.action,i));if((n.action===`session.clone`||n.action===`session.fork`)&&a)await kt(a);else{let e=await Ye(d,je.current,p??void 0);r===`sessions`&&ze(e.selectedRoomId,e.selectedPiboSessionId),await tt(d)}return!0},[r,Ye,ze,tt,kt,d,Le,p,_,Dt]),Bt=(0,R.useCallback)(async e=>{if(!d||Le)return;let t=MIe(await yc(d,`session.fork`,{entryId:e}));if(t?.result.cancelled)return;if(!t)throw Error(`Unexpected fork action response`);let n=typeof t.result.selectedText==`string`?t.result.selectedText:void 0;n!==void 0&&t.result.piboSessionId&&$0(t.result.piboSessionId,n),t.result.piboSessionId&&await kt(t.result.piboSessionId),n!==void 0&&(M(n),P(e=>e+1))},[kt,d,Le]),Vt=(0,R.useCallback)(e=>void kt(e),[kt]),Ht=(0,R.useCallback)(e=>{if(A(e),r===`projects`){Re({area:`projects`,...a?{projectId:a}:{},...o?{piboSessionId:o}:{}},!1,e);return}r===`sessions`&&Re({area:`sessions`,...p?{roomId:p}:{},...d?{piboSessionId:d}:{}},!1,e)},[r,Re,o,a,d,p]),Ut=(0,R.useMemo)(()=>l?l3(l.sessions,C):{active:[],archived:[]},[l?.sessions,C]),Wt=(0,R.useMemo)(()=>qje(Ut.active,ie,d),[Ut.active,d,ie]),Gt=(0,R.useMemo)(()=>C?Ut.archived.slice(0,oe):[],[Ut.archived,C,oe]),Kt=Ut.active.length>Wt.length,qt=C&&Ut.archived.length>Gt.length,Jt=(0,R.useMemo)(()=>d?new Set(e3(l?.sessions??[],d).map(e=>e.piboSessionId)):WLe,[l?.sessions,d]),Xt=(0,R.useCallback)(async e=>{if(!Fe)return;let t=(e?Gt:Wt).at(-1)?.piboSessionId;e?re(!0):ne(!0);try{let r=e?X9:Y9,i=await n.fetchQuery({queryKey:ije(Fe,e,t,r),queryFn:()=>lc({roomId:Fe,piboSessionId:d??void 0,archived:e,cursor:t,limit:r}),staleTime:3e4,gcTime:30*6e4});u(e=>e&&{...e,sessions:FLe(e.sessions,i.sessions)}),e?se(e=>e+r):ae(e=>e+r)}finally{e?re(!1):ne(!1)}},[Fe,n,d,Wt,Gt]);if(h&&!l)return(0,z.jsx)(kLe,{message:h});if(!l)return(0,z.jsx)(`div`,{className:`min-h-screen bg-[#101d22] text-slate-300 grid place-items-center`,children:`Loading Pibo Chat...`});let Zt=d?$4(l.sessions,d):void 0,Qt=d?De?.sessions[d]:void 0,$t=De?.rootPiboSessionId?De.sessions[De.rootPiboSessionId]:void 0,en=Q4(l,Zt??{profile:Z4(l),parentId:l.session?.parentId}),tn=Jje(l.rooms),nn=[...new Set([...l.agents.map(e=>e.name),...l.customAgents.map(e=>e.profileName)])],rn=Tje(l);return(0,z.jsxs)(z.Fragment,{children:[Te===`fallback`?(0,z.jsx)(ELe,{}):null,(0,z.jsxs)(`div`,{"data-pibo-debug":`chat-app`,"data-pibo-area":r,"data-pibo-room-id":p??l.selectedRoomId??void 0,"data-pibo-selected-session-id":d??l.selectedPiboSessionId??void 0,className:`h-dvh overflow-hidden bg-[#101d22] text-slate-200 grid grid-rows-[auto_auto_1fr]`,children:[(0,z.jsx)(DLe,{area:r,identity:rn,mobileAreaMenuOpen:Se,mobileAreaMenuRef:we,totalRoomUnreadCount:tn,onOpenMobileSidebar:()=>xe(!0),onSelectMainNavArea:e=>{if(Ce(!1),e===`sessions`){ze(p??l.selectedRoomId,d??l.selectedPiboSessionId);return}if(e===`projects`){Re({area:`projects`});return}Re({area:e})},onToggleMobileAreaMenu:()=>Ce(e=>!e)}),(0,z.jsx)(`div`,{children:h?(0,z.jsx)(OLe,{message:h,onDismiss:()=>g(null)}):null}),(0,z.jsx)(`div`,{"data-pibo-debug":`route-shell`,"data-pibo-area":r,"data-pibo-room-id":p??l.selectedRoomId??void 0,"data-pibo-selected-session-id":d??void 0,className:`min-h-0 ${r===`agents`||r===`workflows`||r===`cron`||r===`ralph`?`h-full overflow-hidden`:`grid ${(r===`sessions`||r===`projects`)&&x?`grid-cols-[300px_minmax(0,1fr)_320px] max-[980px]:grid-cols-1`:`grid-cols-[300px_minmax(0,1fr)] max-[980px]:grid-cols-1`}`}`,children:r===`cron`?(0,z.jsx)(zve,{bootstrap:l,mobileSidebarOpen:be,onCloseMobileSidebar:()=>xe(!1)}):r===`ralph`?(0,z.jsx)(fye,{bootstrap:l,mobileSidebarOpen:be,onCloseMobileSidebar:()=>xe(!1)}):r===`agents`?(0,z.jsx)(QOe,{agents:l.agents,initialCustomAgents:l.customAgents,initialCatalog:l.agentCatalog,modelCatalog:l.modelCatalog,onSelect:et,onCreateSession:e=>void jt(e),onEditContextFile:He,onEditMcpServer:Ue,onAgentsChanged:()=>void Ye(d??void 0,je.current,p??void 0,{selectSession:!1}),creatingSession:F||Le}):r===`workflows`?(0,z.jsx)(SOe,{draftId:e.area===`workflows`?e.draftId:void 0,viewWorkflowId:e.area===`workflows`?e.viewWorkflowId:void 0,viewWorkflowVersion:e.area===`workflows`?e.viewWorkflowVersion:void 0}):r===`projects`?(0,z.jsx)(CLe,{baseBootstrap:l,routeProjectId:a,routePiboSessionId:o,sessionViews:Qe,showRawEvents:x,showThinking:_,expandThinking:y,commands:Dt,skills:Ot,mobileSidebarOpen:be,onCloseMobileSidebar:()=>xe(!1),onNavigate:Be,onViewContext:Ve,onSelectSessionView:Ht,onToggleRawEvents:()=>{let e=!x;S(e),i2(e)},onToggleThinking:()=>{let e=!_;v(e),n2(e)},onToggleExpandThinking:()=>{let e=!y;b(e),r2(e)},onThinkingLevelChange:e=>void yc(o??``,`thinking`,{level:e}),onError:g}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/60 min-[981px]:hidden transition-opacity duration-200 ${be?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`,onClick:()=>xe(!1)}),(0,z.jsxs)(`aside`,{"data-pibo-debug":`sidebar-shell`,"data-pibo-area":r,"data-pibo-room-id":p??l.selectedRoomId??void 0,"data-pibo-selected-session-id":d??void 0,"data-pibo-state":be?`open`:`closed`,className:`min-h-0 overflow-hidden flex flex-col bg-[#1a262b] border-r border-slate-800 max-[980px]:fixed max-[980px]:left-0 max-[980px]:top-0 max-[980px]:bottom-0 max-[980px]:z-40 max-[980px]:w-[280px] max-[980px]:transition-transform max-[980px]:duration-200 ${be?`max-[980px]:translate-x-0`:`max-[980px]:-translate-x-full`}`,children:[(0,z.jsxs)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center justify-between text-xs font-bold uppercase tracking-wider max-[980px]:h-auto max-[980px]:py-2 max-[980px]:flex-wrap`,children:[(0,z.jsx)(`span`,{children:r}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r===`sessions`?(0,z.jsx)(`button`,{type:`button`,onClick:()=>void Ye(d??void 0,je.current,p??void 0,{force:!0}).then(e=>{d&&tt(d),r===`sessions`&&ze(e.selectedRoomId,e.selectedPiboSessionId)}),title:`Refresh`,"aria-label":`Refresh`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ls,{size:13})}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>xe(!1),className:`min-[981px]:hidden p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Close sidebar`,"aria-label":`Close sidebar`,children:(0,z.jsx)(Qs,{size:13})})]})]}),r===`sessions`?(0,z.jsx)(eMe,{bootstrap:l,selectedRoomId:p,selectedPiboSessionId:d,showArchivedRooms:T,onToggleArchivedRooms:()=>{let e=!T;E(e),a2(e)},creatingRoom:ve,onCreateRoom:()=>Ft(),onSelectRoom:At,onUpdateRoom:It,onArchiveRoom:Rt,onReadAllRoom:Lt,onDeleteRoom:ft,newSessionProfile:D,onNewSessionProfileChange:et,selectedRoomArchived:Le,creatingSession:F,onCreateSession:()=>jt(),showArchived:C,onToggleArchivedSessions:Mt,loadingArchivedSessions:L,visibleActiveSessions:Wt,visibleArchivedSessions:Gt,totalActiveSessionCount:Ut.active.length,totalArchivedSessionCount:Ut.archived.length,hasMoreActiveSessions:Kt,hasMoreArchivedSessions:qt,loadingActiveSessions:I,sessionListScrollRef:Me,onLoadMoreSessions:Xt,signalNow:ke,selectedSessionPathIds:Jt,onSelectSession:kt,onRenameSession:Nt,onArchiveSession:Pt,onDeleteSession:yt,onViewContext:Ve,loadingPiboSessionId:ce,autoRenameSessionId:ue,onAutoRenameConsumed:()=>de(null)}):r===`context`?(0,z.jsx)(jve,{activePanel:fe,onSelect:pe,toolCount:l.agentCatalog?.piboTools.length??0,mcpServerCount:l.agentCatalog?.mcpServers.length??0}):(0,z.jsx)(BIe,{activePanel:c,onSelect:e=>Re({area:`settings`,panel:e}),piPackageCount:l.agentCatalog?.piPackages.length??0,userSkillCount:l.agentCatalog?.userSkills.length??0})]}),r===`sessions`?(0,z.jsx)(a3,{bootstrap:l,selectedPiboSessionId:d,selectedRoomId:p,selectedRoomArchived:Le,selectedSessionProfile:Zt?.profile??Z4(l),selectedSessionActiveModel:en,selectedSessionStatus:I9(Qt??$t)??Zt?.status,selectedSessionSignal:Qt,sessionViewId:k,sessionViews:Qe,currentSessionView:$e,creatingSession:F,showRawEvents:x,showThinking:_,expandThinking:y,commands:Dt,skills:Ot,composerText:j,composerFocusSignal:N,onComposerTextChange:Ze,onToggleRawEvents:()=>{let e=!x;S(e),i2(e)},onToggleThinking:()=>{let e=!_;v(e),n2(e)},onToggleExpandThinking:()=>{let e=!y;b(e),r2(e)},onSessionAgentProfileChange:e=>void Et(e),onFork:Bt,onOpenSession:Vt,onSelectSessionView:Ht,onCommand:zt,onThinkingLevelChange:e=>void zt(`/thinking ${e}`),onRefreshTrace:nt,onRefreshBootstrap:rt,onSend:async(e,t,n,r)=>{if(!(!d||Le))try{await Tt.mutateAsync({piboSessionId:d,text:e,clientTxnId:r??t3(),roomId:p??void 0,webAnnotationIds:t,fileAttachmentPaths:n}),await Ye(d,je.current,p??void 0,{force:!0}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},onError:g}):(0,z.jsx)(`main`,{className:`min-h-0 flex flex-col`,children:r===`context`?fe===`pibo-tools`?(0,z.jsx)(BW,{tools:l.agentCatalog?.piboTools??[]}):fe===`mcp-tools`?(0,z.jsx)(eG,{servers:l.agentCatalog?.mcpServers??[],selectedServerName:ge,onServerSaved:We}):fe===`build-context`?(0,z.jsx)(bve,{piboSessionId:o??null}):fe===`base-prompt`?(0,z.jsx)(Hge,{}):fe===`compaction-prompt`?(0,z.jsx)(Gge,{}):(0,z.jsx)(Tge,{agentProfiles:nn,selectedFileKey:me}):(0,z.jsx)(UIe,{activePanel:c,showThinking:_,setShowThinking:v,expandThinking:y,setExpandThinking:b,modelDefaults:l.modelDefaults,modelCatalog:l.modelCatalog,onModelDefaultsChanged:e=>{u(t=>t&&{...t,modelDefaults:e})},piPackages:l.agentCatalog?.piPackages,onPiPackageChanged:Ge,onPiPackageRemoved:Ke,userSkills:l.agentCatalog?.userSkills,onUserSkillChanged:qe,onUserSkillRemoved:Je,piboSessionId:d,onProviderAuthChanged:it})}),ct?(0,z.jsx)(TLe,{room:ct,confirmName:lt,deleting:ut,onConfirmNameChange:dt,onCancel:pt,onDelete:()=>void mt()}):null,ht?(0,z.jsx)(wLe,{session:ht,confirmText:gt,deleting:_t,onConfirmTextChange:vt,onCancel:bt,onDelete:()=>void xt()}):null]})})]})]})}function Q9(e,t){return e.find(e=>e.name===t||e.aliases.includes(t))}var qLe=new Gt({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1}}});function JLe(){let e=ho({select:e=>({pathname:e.location.pathname,search:e.location.search})});return(0,z.jsx)(KLe,{route:Dc(e.pathname,e.search)})}var $9=Xa({component:JLe}),YLe=Ja({getParentRoute:()=>$9,path:`/`}),XLe=Ja({getParentRoute:()=>$9,path:`sessions/$piboSessionId`}),ZLe=Ja({getParentRoute:()=>$9,path:`rooms/$roomId`}),QLe=Ja({getParentRoute:()=>$9,path:`rooms/$roomId/sessions/$piboSessionId`}),$Le=Ja({getParentRoute:()=>$9,path:`projects`}),eRe=Ja({getParentRoute:()=>$9,path:`projects/$projectId`}),tRe=Ja({getParentRoute:()=>$9,path:`projects/$projectId/sessions/$piboSessionId`}),nRe=Ja({getParentRoute:()=>$9,path:`workflows`}),rRe=Ja({getParentRoute:()=>$9,path:`workflows/drafts/$draftId`}),iRe=Ja({getParentRoute:()=>$9,path:`workflows/view/$workflowId/$workflowVersion`}),aRe=Ja({getParentRoute:()=>$9,path:`agents`}),oRe=Ja({getParentRoute:()=>$9,path:`cron`}),sRe=Ja({getParentRoute:()=>$9,path:`ralph`}),cRe=Ja({getParentRoute:()=>$9,path:`context`}),lRe=Ja({getParentRoute:()=>$9,path:`settings`}),uRe=Ja({getParentRoute:()=>$9,path:`settings/shortcuts`}),dRe=Ja({getParentRoute:()=>$9,path:`settings/pi-packages`}),fRe=Ja({getParentRoute:()=>$9,path:`settings/skills`}),pRe=Ja({getParentRoute:()=>$9,path:`settings/providers`}),mRe=uo({routeTree:$9.addChildren([YLe,XLe,ZLe,QLe,$Le,eRe,tRe,nRe,rRe,iRe,aRe,oRe,sRe,cRe,lRe,uRe,dRe,fRe,pRe]),basepath:`/apps/chat`});`serviceWorker`in navigator&&window.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/apps/chat/sw.js`).catch(()=>{})}),(0,$s.createRoot)(document.getElementById(`root`)).render((0,z.jsx)(R.StrictMode,{children:(0,z.jsx)(Xt,{client:qLe,children:(0,z.jsx)(mo,{router:mRe})})}));export{rfe as i,tP as n,xde as r,$N as t};
|
|
165
|
+
`)&&e.value.length<80){e.style.height=``,e.style.overflowY=`hidden`;return}let t=window.getComputedStyle(e),n=h2(t.lineHeight,20),r=h2(t.borderTopWidth)+h2(t.borderBottomWidth),i=n*5+h2(t.paddingTop)+h2(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 h2(e,t=0){let n=Number.parseFloat(e);return Number.isFinite(n)?n:t}async function Ske(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),V(`/api/web-annotations?${n.toString()}`)}async function Cke(e,t){return V(`/api/web-annotations/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(_2(t))})}async function wke(e){let t=new URLSearchParams;return e?.trim()&&t.set(`cdpUrl`,e.trim()),V(`/api/web-annotations/targets${t.size?`?${t.toString()}`:``}`)}async function g2(e){return V(`/api/web-annotations/bindings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(_2(e))})}async function Tke(e,t){return V(`/api/web-annotations/bindings/${encodeURIComponent(e)}/inject`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(_2(t))})}function _2(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0&&e!==``))}var v2=`pibo.chat.webAnnotations.cdpUrl`,y2=`pibo.chat.webAnnotations.selected.`,Eke=`pibo.chat.webAnnotations.overlay.`,b2=`pibo.chat.webAnnotations.panelCollapsed`,x2=`pibo.chat.shortcuts.webAnnotationsToggle`,S2=`Alt+Shift+A`;function Dke(){try{return localStorage.getItem(v2)??``}catch{return``}}function Oke(e){try{e.trim()?localStorage.setItem(v2,e.trim()):localStorage.removeItem(v2)}catch{}}function C2(){try{return localStorage.getItem(x2)||`Alt+Shift+A`}catch{return S2}}function w2(e){let t=E2(e)||`Alt+Shift+A`;try{localStorage.setItem(x2,t)}catch{}}function T2(e){window.__piboWebAnnotations?.setShortcut?.(e);try{window.dispatchEvent(new CustomEvent(`pibo:web-annotation-shortcut-changed`,{detail:{shortcut:e}}))}catch{}}function E2(e){return e.replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,80)}function D2(e){try{return k2(localStorage.getItem(O2(e)))}catch{return null}}function O2(e){return Eke+e}function k2(e){if(!e)return null;try{return A2(JSON.parse(e))}catch{return null}}function A2(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 kke(e){try{let t=localStorage.getItem(y2+e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`string`&&!!e.trim()).slice(0,5):[]}catch{return[]}}function j2(e,t){try{let n=y2+e,r=[...new Set(t.filter(e=>e.trim()))].slice(0,5);r.length?localStorage.setItem(n,JSON.stringify(r)):localStorage.removeItem(n)}catch{}}function Ake(){try{return localStorage.getItem(b2)===`true`}catch{return!1}}function jke(e){try{localStorage.setItem(b2,String(e))}catch{}}function Mke({piboSessionId:e,annotations:t,selectedIds:n,loading:r,error:i,collapsed:a,onRefresh:o,onToggle:s,onClear:c,onCollapse:l,onClose:u}){return e?(0,z.jsxs)(`section`,{className:`border-t border-slate-800 bg-[#101d22] px-3 py-2 sm:px-4`,"data-pibo-debug":`web-annotations-session-panel`,"data-pibo-session-id":e,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web annotations`}),(0,z.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,z.jsxs)(`span`,{className:`rounded-sm border border-[#11a4d4]/50 px-1.5 py-0.5 text-[10px] text-[#11a4d4]`,children:[n.length,` attached`]}):null]}),a?null:(0,z.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Global annotation list. Selected attachments are remembered per session.`})]}),(0,z.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:o,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,z.jsx)(Ls,{size:12,className:r?`animate-spin`:void 0})}),(0,z.jsx)(`button`,{type:`button`,onClick:c,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,z.jsx)(qs,{size:12})}),(0,z.jsx)(`button`,{type:`button`,onClick:l,title:a?`Expand annotations panel`:`Collapse annotations panel`,"aria-label":a?`Expand annotations panel`:`Collapse annotations panel`,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] sm:h-7 sm:w-7`,children:a?(0,z.jsx)(Wo,{size:12}):(0,z.jsx)(Ho,{size:12})}),(0,z.jsx)(`button`,{type:`button`,onClick:u,title:`Hide annotations panel`,"aria-label":`Hide annotations panel`,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] sm:h-7 sm:w-7`,children:(0,z.jsx)(Qs,{size:12})})]})]}),a?null:i?(0,z.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:I2(i,220)}):r&&!t.length?(0,z.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,z.jsx)(`div`,{className:`mt-2 grid max-h-[min(40svh,18rem)] grid-cols-1 gap-2 overflow-y-auto pr-1 sm:max-h-56 sm:grid-cols-[repeat(auto-fill,minmax(16rem,1fr))]`,"data-pibo-debug":`web-annotations-list`,children:t.map(e=>{let t=n.includes(e.id);return(0,z.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":t?`true`:`false`,className:`min-w-0 rounded-sm border px-3 py-2 text-xs ${t?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 bg-[#0e1116]`}`,children:[(0,z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,z.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-[11px] text-slate-500`,children:[e.status,` · `,e.targetKind]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id),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 ${t?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:[t?(0,z.jsx)(Qs,{size:11}):(0,z.jsx)(Ps,{size:11}),` `,t?`Detach`:`Attach`]})]}),(0,z.jsx)(`div`,{className:`truncate text-slate-200`,title:e.primaryTarget||e.label||e.selector||e.id,children:I2(e.primaryTarget||e.label||e.selector||e.id,120)}),e.piboContext?(0,z.jsx)(`div`,{className:`truncate font-mono text-[11px] text-[#11a4d4]`,title:e.piboContext,children:I2(e.piboContext,140)}):null,(0,z.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:F2(e.url)}),(0,z.jsx)(`div`,{className:`mt-1 line-clamp-2 text-slate-400`,title:e.note,children:I2(e.note,180)}),(0,z.jsx)(`div`,{className:`mt-1 text-[11px] text-slate-600`,children:Lke(e.createdAt)})]},e.id)})}):(0,z.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 Nke({piboSessionId:e,piboRoomId:t,disabled:n,panelVisible:r,onShowPanel:i,onHidePanel:a,onError:o}){let[s,c]=(0,R.useState)(!1),[l,u]=(0,R.useState)(``),[d,f]=(0,R.useState)(()=>Dke()),[p,m]=(0,R.useState)([]),[h,g]=(0,R.useState)(`idle`),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null);(0,R.useEffect)(()=>{n&&c(!1)},[n]),(0,R.useEffect)(()=>{Oke(d)},[d]);let x=async()=>{if(e){g(`loading`),b(null);try{m((await wke(d)).targets.filter(e=>e.type===`page`||e.attachable)),g(`loaded`)}catch(e){let t=N2(e,`CDP unavailable`);m([]),g(`error`),b({kind:`error`,message:t}),o(t)}}},S=async n=>{if(!e)throw Error(`No active session context`);return Tke(n.binding.id,M2({piboSessionId:e,piboRoomId:t,cdpUrl:d,annotationShortcut:C2()}))},C=async()=>{if(!(!e||_)){i(),v(!0),b({kind:`info`,message:`Injecting annotation overlay into this Pibo page…`});try{let n=await g2({piboSessionId:e,piboRoomId:t,url:window.location.href,title:document.title,sameOrigin:!0,annotationShortcut:C2()});if(!n.overlay)throw Error(`Overlay config missing from same-origin binding response`);await Ike(n.overlay),b({kind:`success`,message:`Annotation overlay is ready on this Pibo page. Open the overlay controls or use the shortcut to start annotating.`}),o(null)}catch(e){let t=N2(e,`Current-page annotation failed`);b({kind:`error`,message:t}),o(t)}finally{v(!1)}}},w=async()=>{if(!e||_)return;i();let n=l.trim();if(!n){b({kind:`error`,message:`URL is required`});return}if(Fke(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.`;b({kind:`error`,message:e}),o(e);return}v(!0),b({kind:`info`,message:`Opening target and injecting overlay…`});try{let r=await g2(M2({piboSessionId:e,piboRoomId:t,url:n,cdpUrl:d})),i=await S(r);b({kind:`success`,message:`Annotation overlay injected for ${P2(i.target??r.target,i.binding.url)}`}),u(``),o(null)}catch(e){let t=N2(e,`Annotation failed`);b({kind:`error`,message:t}),o(t)}finally{v(!1)}},T=async n=>{if(!(!e||_)){i(),v(!0),b({kind:`info`,message:`Binding selected target and injecting overlay…`});try{let r=await S(await g2(M2({piboSessionId:e,piboRoomId:t,targetId:n.id,cdpUrl:d})));b({kind:`success`,message:`Annotation overlay injected for ${P2(r.target??n,r.binding.url)}`}),o(null)}catch(e){let t=N2(e,n.attachable?`Target annotation failed`:`Target not attachable`);b({kind:`error`,message:t}),o(t)}finally{v(!1)}}};return(0,z.jsxs)(`div`,{className:`relative`,"data-pibo-debug":`web-annotations-entry`,"data-pibo-session-id":e??void 0,children:[(0,z.jsx)(Pke,{onClick:()=>{n||(c(e=>!e),r||i())},title:n?`Select an active session to annotate a web page`:r?`Web Annotations`:`Show Web Annotations`,ariaLabel:`Web Annotations`,active:s||r,children:(0,z.jsx)(Ao,{size:14})}),s&&!n?(0,z.jsxs)(`div`,{className:`fixed inset-x-2 bottom-3 z-40 max-h-[calc(100svh-1.5rem)] overflow-y-auto rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-sm shadow-xl sm:absolute sm:inset-auto sm:right-0 sm:top-full sm:bottom-auto sm:mt-2 sm:w-[min(420px,calc(100vw-24px))] sm:max-h-[calc(100svh-5rem)]`,role:`dialog`,"aria-label":`Web Annotations`,children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-[#11a4d4]`,children:`Web Annotations`}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:r?a:i,className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":r?`Hide annotation list`:`Show annotation list`,title:r?`Hide annotation list`:`Show annotation list`,children:(0,z.jsx)(zs,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded-sm p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200`,"aria-label":`Close Web Annotations panel`,children:(0,z.jsx)(Qs,{size:14})})]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void C(),disabled:_,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,z.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,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto]`,children:[(0,z.jsx)(`input`,{id:`web-annotation-url`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&w()},placeholder:`http://localhost:5173`,disabled:_,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,z.jsx)(`button`,{type:`button`,onClick:()=>void w(),disabled:_||!l.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,z.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,z.jsx)(`input`,{id:`web-annotation-cdp-url`,value:d,onChange:e=>f(e.target.value),placeholder:`Use gateway default`,disabled:_,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,z.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-slate-500`,children:`Existing targets`}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void x(),disabled:_||h===`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,z.jsx)(Ls,{size:12,className:h===`loading`?`animate-spin`:void 0}),` Refresh`]})]}),(0,z.jsxs)(`div`,{className:`mt-2 max-h-[min(34svh,14rem)] overflow-auto rounded-sm border border-slate-800 sm:max-h-56`,children:[h===`idle`?(0,z.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`Refresh to list reachable browser targets.`}):null,h===`loading`?(0,z.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-400`,children:`Loading targets…`}):null,h===`loaded`&&!p.length?(0,z.jsx)(`div`,{className:`px-3 py-3 text-xs text-slate-500`,children:`No attachable browser targets found.`}):null,p.map(e=>(0,z.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,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs text-slate-200`,title:e.title||e.url,children:I2(e.title||`Untitled target`,120)}),(0,z.jsx)(`div`,{className:`truncate font-mono text-[11px] text-slate-500`,title:e.url,children:I2(e.url||e.id,160)})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void T(e),disabled:_||!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))]}),y?(0,z.jsx)(`div`,{className:`mt-2 rounded-sm border px-2 py-2 text-xs ${y.kind===`error`?`border-red-900 bg-red-950/40 text-red-200`:y.kind===`success`?`border-emerald-900/60 bg-emerald-950/30 text-emerald-300`:`border-slate-700 bg-[#151f24] text-slate-300`}`,children:y.message}):null]}):null]})}function Pke({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,z.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function M2(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e&&e.trim()))}function Fke(e){try{let t=new URL(e);return t.port===`56663`||t.pathname.startsWith(`/json/`)}catch{return!1}}function Ike(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 N2(e,t){let n=Rke(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 P2(e,t){let n=e?.url||t||e?.title||`target`;return F2(e?.title||n)}function F2(e){try{let t=new URL(e);return`${t.host}${t.pathname===`/`?``:t.pathname}`}catch{return I2(e,80)}}function I2(e,t){return e.length>t?`${e.slice(0,Math.max(0,t-1))}…`:e}function Lke(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function Rke(e){return e instanceof Error?e.message:String(e)}var zke={terminal:[`terminal`],workflow:[`workflow`]},L2=`1970-01-01T00:00:00.000Z`;function R2(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function Bke(e){return R2(e)&&e.state===`configured`&&!e.workflowRunId}function Vke(e){let t=e.selectedSessionNode?.workflowSessionKind??Hke(e.selectedSession?.metadata);if(t===`main_workflow`||t===`nested_workflow`){if(e.selectedProjectSession&&!R2(e.selectedProjectSession)||!e.selectedProjectSession&&t===`main_workflow`&&z2(e.selectedSession?.metadata)===`simple-chat`)return{viewId:`terminal`};let n=e.selectedProjectSession&&R2(e.selectedProjectSession)?e.selectedProjectSession:Uke({selectedSessionNode:e.selectedSessionNode,selectedSession:e.selectedSession,selectedProject:e.selectedProject,workflowSessionKind:t});return{viewId:`workflow`,...n?{workflowProjectSession:n}:{}}}return t===`agent_node`||t===`subagent`?{viewId:`terminal`}:e.selectedProjectSession&&R2(e.selectedProjectSession)?{viewId:`workflow`,workflowProjectSession:e.selectedProjectSession}:{viewId:`terminal`}}function Hke(e){let t=B2(e,`workflowSessionKind`);if(t===`main_workflow`||t===`nested_workflow`||t===`agent_node`||t===`subagent`)return t;if(B2(e,`projectSessionKind`)===`main`)return`main_workflow`}function z2(e){return B2(e,`projectWorkflowId`)??B2(e,`workflowId`)}function Uke(e){let t=e.selectedSessionNode?.piboSessionId??e.selectedSession?.id;if(!t)return;let n=e.selectedSession?.metadata,r=z2(n)??(e.workflowSessionKind===`nested_workflow`?`nested-workflow-session`:`workflow-session`),i=B2(n,`projectWorkflowVersion`)??B2(n,`workflowVersion`),a=B2(n,`workflowRunId`);return{projectId:e.selectedProject?.id??B2(n,`projectId`)??`project`,piboSessionId:t,kind:e.workflowSessionKind===`nested_workflow`?`sub`:`main`,workflowId:r,...i?{workflowVersion:i}:{},...a?{workflowRunId:a}:{},...e.selectedSessionNode?.parentId?{parentMainSessionId:e.selectedSessionNode.parentId}:{},...e.selectedSessionNode?.title||e.selectedSession?.title?{title:e.selectedSessionNode?.title??e.selectedSession?.title}:{},state:Wke(e.selectedSessionNode,a),...e.selectedSessionNode?.archived===void 0?{}:{archived:e.selectedSessionNode.archived},createdAt:e.selectedSession?.createdAt??L2,updatedAt:e.selectedSession?.updatedAt??e.selectedSessionNode?.lastActivityAt??L2}}function Wke(e,t){return e?.status===`error`?`failed`:e?.status===`running`?`running`:t?`workflow`:`configured`}function B2(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():void 0}function Gke(e){if(!R2(e))return`Workflow: ${e.workflowId}`;let t=e.workflowRunId?` · run ${U2(e.workflowRunId)}`:``;return`Workflow: ${e.workflowId}${t} · ${V2(e)}`}function Kke(e,t){return{workflowId:e.workflowId,state:V2(e,t),...e.workflowRunId?{workflowRunId:e.workflowRunId}:{}}}function qke({summary:e}){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,z.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,z.jsxs)(`span`,{className:H2(e.state),children:[`state `,e.state]}),e.workflowRunId?(0,z.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 `,U2(e.workflowRunId)]}):null]})}function V2(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.state?e.state.replace(/_/g,` `):e.workflowRunId?`workflow`:e.kind}function Jke(e,t){return H2(V2(e,t),e.archived)}function H2(e,t=!1){let n=e.toLowerCase(),r=`shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide`;return t?`${r} border-slate-700 text-slate-500`:n.includes(`failed`)||n.includes(`error`)?`${r} border-red-500/40 text-red-300 bg-red-500/10`:n.includes(`waiting`)?`${r} border-amber-500/40 text-amber-300 bg-amber-500/10`:n.includes(`complete`)||n.includes(`done`)?`${r} border-emerald-500/40 text-emerald-300 bg-emerald-500/10`:`${r} border-[#11a4d4]/40 text-[#11a4d4] bg-[#11a4d4]/10`}function U2(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function Yke({title:e,roomLabel:t,headerPiboSessionId:n,piboSessionId:r,piboRoomId:i,webAnnotationsDisabled:a,webAnnotationsPanelRendered:o,workflowHeader:s,sessionViewId:c,sessionViews:l,currentSessionView:u,allowedSessionViewIds:d,showRawEvents:f,showThinking:p,expandThinking:m,onShowWebAnnotationsPanel:h,onHideWebAnnotationsPanel:g,onSelectSessionView:_,onToggleRawEvents:v,onToggleThinking:y,onToggleExpandThinking:b,onError:x}){let[S,C]=(0,R.useState)(null),w=(0,R.useRef)(void 0),T=S===n,E=(0,R.useMemo)(()=>d?new Set(d):null,[d]);(0,R.useEffect)(()=>()=>{w.current&&window.clearTimeout(w.current)},[]);let D=()=>{n&&(u2(n).catch(()=>void 0),C(n),w.current&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>C(null),900))};return(0,z.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`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:e}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 font-mono text-[11px] text-slate-500`,children:[(0,z.jsx)(`span`,{className:`truncate`,children:t}),n?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-slate-600`,children:`·`}),(0,z.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>void D(),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:n})]}):null,s?(0,z.jsx)(qke,{summary:s}):null]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(Nke,{piboSessionId:r,piboRoomId:i,disabled:a,panelVisible:o,onShowPanel:h,onHidePanel:g,onError:x}),(0,z.jsx)(`div`,{className:`flex items-center rounded-sm border border-slate-700 bg-[#0e1116] p-0.5`,children:l.map(e=>{let t=!!(E&&!E.has(e.id));return(0,z.jsx)(`button`,{type:`button`,onClick:()=>{t||_(e.id)},disabled:t,title:t?`Project session routing uses the ${u.label} view for this session kind.`:e.description??e.label,"aria-label":t?`${e.label} view unavailable for this Project session kind`:`Switch to ${e.label} view`,className:`min-w-20 px-2.5 py-1 text-[11px] font-bold tracking-wide max-[980px]:min-w-0 max-[980px]:px-1.5 disabled:cursor-not-allowed disabled:text-slate-600 ${c===e.id?`bg-[#11a4d4]/10 text-[#11a4d4]`:`text-slate-400 hover:text-[#11a4d4] disabled:hover:text-slate-600`}`,children:e.label},e.id)})}),(0,z.jsx)(W2,{onClick:v,title:f?`Hide Raw Events`:`Show Raw Events`,ariaLabel:f?`Hide Raw Events`:`Show Raw Events`,active:f,children:(0,z.jsx)(Fo,{size:14})}),(0,z.jsx)(W2,{onClick:y,title:p?`Hide Thinking`:`Show Thinking`,ariaLabel:p?`Hide Thinking`:`Show Thinking`,active:p,children:p?(0,z.jsx)(Po,{size:14}):(0,z.jsx)(is,{size:14})}),p?(0,z.jsx)(W2,{onClick:b,title:m?`Collapse Thinking`:`Expand Thinking`,ariaLabel:m?`Collapse Thinking`:`Expand Thinking`,active:m,children:m?(0,z.jsx)(Ho,{size:14}):(0,z.jsx)(Wo,{size:14})}):null]})]})}function W2({title:e,ariaLabel:t,active:n,onClick:r,children:i}){return(0,z.jsx)(`button`,{type:`button`,onClick:r,title:e,"aria-label":t,className:`h-8 w-8 inline-flex items-center justify-center border rounded-sm transition-colors ${n?`border-[#11a4d4] bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`}`,children:i})}function Xke(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&Zke(e,n)){e.count+=1,e.createdAt=n.createdAt,e.payload={...q2(e.payload)?e.payload:{},text:`${G2(e.payload)}${G2(n.payload)}`};continue}t.push({...n,count:1})}return t}function Zke(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=q2(e.payload)?e.payload:{},r=q2(t.payload)?t.payload:{};return K2(n)===K2(r)}function G2(e){return q2(e)?typeof e.text==`string`?e.text:typeof e.delta==`string`?e.delta:``:``}function K2(e){return e.eventId??e.messageId}function q2(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Qke({traceView:e,eventLimit:t,isFetching:n,visible:r,onLoadOlder:i}){let a=(0,R.useMemo)(()=>r?Xke(e?.rawEvents??[]):[],[e?.rawEvents,r]);return r?(0,z.jsxs)(`aside`,{className:`min-h-0 overflow-auto bg-[#0e1116] border-l border-slate-800 max-[980px]:hidden`,children:[(0,z.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,z.jsxs)(`div`,{className:`p-3 flex flex-col gap-2`,children:[e&&a.length>=t?(0,z.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,z.jsxs)(`div`,{className:`border-l-2 border-[#11a4d4] bg-[#151f24] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[#11a4d4] font-mono text-[11px] mb-1`,children:[(0,z.jsx)(`span`,{children:e.type}),e.count>1?(0,z.jsxs)(`span`,{className:`text-slate-500`,children:[`x`,e.count]}):null]}),(0,z.jsx)(vq,{value:e.payload,showControls:!1})]},e.id))]})]}):null}function $ke({traceView:e,eventLimit:t,isFetching:n,onLoadOlder:r}){if(!e?.hasOlderEvents)return null;let i=Math.min(e.eventLimit??t,e.eventCount??t),a=e.eventCount??`many`;return(0,z.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-2 text-center`,children:(0,z.jsx)(`button`,{type:`button`,onClick:r,disabled:n,className:`rounded-sm border border-slate-700 px-3 py-1 text-xs text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-60`,children:n?`Loading history…`:`Load older trace history (${i} of ${a} events)`})})}function eAe({selectedPiboSessionId:e,selectedRoomId:t,fallbackRoomId:n,sessionViewId:r,loadingTrace:i,traceError:a,showRawEvents:o,currentTraceView:s,traceEventLimit:c,rawEventLimit:l,tracePageFetching:u,onLoadOlderTracePage:d,onLoadMoreRawEvents:f,headerProps:p,projectSessionCreatePanel:m,workflowStartPanel:h,currentSessionView:g,sessionViewProps:_,webAnnotationsPanelRendered:v,webAnnotationsPanelProps:y,composerProps:b}){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`main`,{"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":i?`loading`:a?`error`:e?`ready`:`empty`,className:`min-h-0 flex flex-col`,children:[(0,z.jsx)(Yke,{...p}),m?(0,z.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:m}):null,h?(0,z.jsx)(`div`,{className:`border-b border-slate-800 bg-[#101d22] px-4 py-3`,children:h}):null,(0,z.jsx)($ke,{traceView:s,eventLimit:c,isFetching:u,onLoadOlder:()=>d(s?.nextBeforeSequence)}),a&&!s?(0,z.jsx)(`div`,{className:`min-h-0 flex-1 p-4 text-sm text-red-200`,children:a}):g.render(_),v?(0,z.jsx)(Mke,{...y}):null,(0,z.jsx)(hke,{...b})]}),(0,z.jsx)(Qke,{traceView:s,eventLimit:l,isFetching:u,visible:o,onLoadOlder:f})]})}var tAe=5e3,nAe=50,J2=new Map;function rAe(e){let t=J2.get(e);return t||(t={snapshots:[],pending:null,pendingTimer:null},J2.set(e,t)),t}function Y2(){try{return localStorage.getItem(`pibo.chat.traceDebug`)===`true`}catch{return!1}}function iAe(e){let t=0;for(let n of e)for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);t=(t<<5)-t+r,t|=0}return t.toString(36)}function X2(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&&n.trigger===t.trigger&&n.traceVersion===t.traceVersion&&JSON.stringify(n.layers.map(e=>e.ids))===JSON.stringify(t.layers.map(e=>e.ids))||(e.snapshots.push(t),e.snapshots.length>tAe&&e.snapshots.shift()),e.pending=null}function aAe(e){if(!Y2())return;let t=rAe(e.piboSessionId);if(t.pendingTimer&&=(clearTimeout(t.pendingTimer),null),(!t.pending||t.pending.trigger!==e.trigger||t.pending.piboSessionId!==e.piboSessionId)&&(X2(t),t.pending={timestamp:Date.now(),piboSessionId:e.piboSessionId,trigger:e.trigger,layers:[],expansionOverrides:e.expansionOverrides,traceVersion:e.traceVersion,latestStreamId:e.latestStreamId,lastRawEventId:e.lastRawEventId}),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),t.pendingTimer=setTimeout(()=>{X2(t),t.pendingTimer=null},nAe)}function oAe(e,t,n,r){let i=$2(n);aAe({piboSessionId:e,trigger:t,layer:{kind:`backendNodes`,ids:i.map(e=>e.id),digest:iAe(i.map(e=>e.id)),meta:i.map(e=>({id:e.id,type:e.type,orderKey:JSON.stringify(e.orderKey),parentId:e.parentId}))},...r})}function Z2(e){let t=J2.get(e);return t?(X2(t),t.snapshots):[]}function Q2(e){if(e){let t=Z2(e);return JSON.stringify({piboSessionId:e,snapshots:t},null,2)}let t={};for(let[e,n]of J2)X2(n),t[e]=n.snapshots;return JSON.stringify(t,null,2)}function sAe(e){e?J2.delete(e):J2.clear()}function $2(e){return e.flatMap(e=>[e,...$2(e.children??[])])}typeof window<`u`&&(window.__piboTraceSnapshots={exportAsJson:e=>{let t=Q2(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:Z2,clearSnapshots:sAe,exportSnapshots:Q2});function e4(e){let t=!1,n=e.map(e=>e.children.length?(t=!0,{...e,children:e4(e.children)}):e);return cAe(n)?t?n:[...e]:[...n].sort(t4)}function cAe(e){for(let t=1;t<e.length;t+=1)if(t4(e[t-1],e[t])>0)return!1;return!0}function t4(e,t){let n=lAe(e,t);if(n!==0)return n;let r=uAe(e.startedAt,t.startedAt);if(r!==0)return r;let i=Jc(e.orderKey,t.orderKey);return i===0?e.id.localeCompare(t.id):i}function lAe(e,t){if(!e.eventId||e.eventId!==t.eventId)return 0;let n=e.orderKey?.phaseRank,r=t.orderKey?.phaseRank;return n===void 0||r===void 0?0:n-r}function uAe(e,t){return!e&&!t?0:e?t?e.localeCompare(t):-1:1}function n4(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 dAe(e,t,n,r){if(!r4(t))return;let i=r.get(e)?.filter(e=>e.metadata?.subagentToolName===t)??[],a=pAe(n);return a?i.find(e=>e.metadata?.threadKey===a)?.id:i.length===1?i[0].id:void 0}function r4(e){return e.startsWith(`pibo_subagent_`)}function fAe(e){return e.slice(14)}function pAe(e){let t=`args`in e&&e.args&&typeof e.args==`object`&&!Array.isArray(e.args)?e.args:void 0,n=t&&`threadKey`in t?t.threadKey:void 0;return typeof n==`string`&&n.trim()?n.trim():void 0}function i4(e,t,n,r){let i=hAe(e,t,n,r);if(!i)return;let a=e.children.find(e=>e.id===i.id);if(a){gAe(a,i),a.runId=i.runId??a.runId;return}e.children.push(i)}function mAe(e){let t=new Map;for(let n of n4(e)){let e=o4(n.output);if(!e)continue;let r=c4(e.runId);r&&t.set(r,{snapshot:e,completedAt:c4(e.completedAt)??c4(e.updatedAt)??n.completedAt})}for(let n of n4(e)){if(n.type!==`agent.async`||!n.runId)continue;let e=t.get(n.runId);if(!e)continue;let r=c4(e.snapshot.status);r!==`completed`&&r!==`cancelled`&&r!==`failed`||(n.status=r===`failed`?`error`:`done`,n.completedAt=e.completedAt??n.completedAt,n.output=e.snapshot,r===`failed`&&(n.error=c4(e.snapshot.summary)??n.error))}}function hAe(e,t,n,r){if(!a4(e))return;let i=o4(e.output),a=l4(e.input)?e.input:{},o=c4(i?.toolName)??c4(a.toolName)??r?.title;if(!o||!r4(o))return;let s=c4(r?.summary)??fAe(o),c=c4(i?.runId),l=c4(i?.status),u=a.arguments,d=c4(i?.completionPolicy)??c4(a.completionPolicy);return{id:`${e.id}:async-agent`,parentId:e.id,piboSessionId:t,eventId:e.eventId,toolCallId:e.toolCallId,runId:c,type:`agent.async`,title:s,status:_Ae(e,l),startedAt:r?.startedAt??n??e.startedAt,completedAt:l===`completed`||l===`cancelled`?e.completedAt:void 0,summary:`Started by ${e.title}`,input:{startedBy:e.title,startToolCallId:e.toolCallId,toolName:o,subagentName:s,runId:c,completionPolicy:d,arguments:u,threadKey:l4(r?.input)?r.input.threadKey:void 0},output:i,error:e.error,linkedPiboSessionId:r?.linkedPiboSessionId??e.linkedPiboSessionId,source:e.source,stableKey:c?`async-agent:${c}`:`${e.stableKey??e.id}:async-agent`,orderKey:qc(e.orderKey,`agent.async`),children:[]}}function a4(e){return e.type===`tool.call`&&e.title===`pibo_run_start`}function gAe(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 o4(e){if(l4(e)){if(s4(e))return e;if(l4(e.details)&&s4(e.details))return e.details}}function s4(e){return typeof e.runId==`string`&&typeof e.toolName==`string`}function c4(e){return typeof e==`string`?e:void 0}function _Ae(e,t){return e.status===`error`||t===`failed`?`error`:t===`completed`||t===`cancelled`?`done`:`running`}function l4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function vAe(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 yAe(e){let t=bAe(e.notification),n=t.length===1?t[0]:void 0,r=d4(e.notification.failed),i=d4(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:xAe(e.notification),output:e.notification,source:e.source,stableKey:e.stableKey??e.id,orderKey:e.orderKey,children:[]}}function bAe(e){return[...u4(e.completed),...u4(e.failed),...u4(e.cancelled),...u4(e.running)]}function u4(e){return Array.isArray(e)?e.filter(SAe):[]}function d4(e){return Array.isArray(e)?e.length:0}function xAe(e){let t=[[d4(e.completed),`completed`],[d4(e.failed),`failed`],[d4(e.cancelled),`cancelled`],[d4(e.running),`running`]].filter(([e])=>Number(e)>0).map(([e,t])=>`${e} ${t}`);return t.length?t.join(`, `):`No yielded run updates`}function SAe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function CAe(e,t,n,r,i,a,o,s,c){let l=r.payload;if(o&&LAe(l)&&!RAe(l,s)||o&&zAe(l,c))return;if(l.type===`assistant_delta`){NAe(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`thinking_delta`){PAe(e,t,l,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);return}if(l.type===`assistant_message`){let i=wAe(n,l,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex),a=t.get(i.id);if(a){p4(a,i),m4(t,a);return}m4(t,i),e.push(i),t.set(i.id,i);return}let u=MAe(n,l,i,a,c,r.createdAt,r.eventSequence,r.streamId,r.streamFrameIndex);if(u){if(u.type===`agent.turn`&&u.eventId){let e=[...t.values()].find(e=>e.type===`agent.turn`&&e.eventId===u.eventId);if(e){e.status=u.status,e.completedAt=u.completedAt??e.completedAt;return}}if(u.type===`assistant.message`){let e=t.get(u.id);if(e){p4(e,u),m4(t,e);return}m4(t,u)}if(u.type===`execution.compaction`){let t=VAe(e);if(t){HAe(t,u);return}}if(u.type===`model.reasoning`){let e=t.get(u.id);if(e){FAe(e,u);return}}if(u.toolCallId){let e=[...t.values()].find(e=>e.toolCallId===u.toolCallId&&(e.type===`tool.call`||e.type===`agent.delegation`));if(e){if(a4(e)&&u.type===`agent.delegation`){i4(e,n,r.createdAt,u);return}BAe(e,u),i4(e,n,r.createdAt);return}}if(!(u.eventId&&t.has(u.id))){TAe(u,t),i4(u,n,r.createdAt),e.push(u);for(let e of n4([u]))t.set(e.id,e)}}}function wAe(e,t,n,r,i,a){let o=typeof t.eventId==`string`?t.eventId:void 0,s=b4(t);return{id:s?y4(s):`event:${t.type}:${C4(t)}`,piboSessionId:e,eventId:o,parentId:o?v4(o):void 0,type:`assistant.message`,title:`Agent Message`,status:`done`,startedAt:n,summary:t.text,output:t.text,source:`event-log`,stableKey:s?`assistant:${s}`:_4(t),orderKey:h4(r,t.type,i,a),children:[]}}function TAe(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=EAe(n,t);return r===void 0||e.startedAt<=r}).sort(t4).at(-1);n&&(e.parentId=n.id)}function EAe(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(t4).at(0)?.startedAt}function DAe(e){return e.some(e=>{let t=e.payload.type;return t!==`assistant_delta`&&t!==`thinking_delta`})}function OAe(e){if(e.type===`assistant_delta`){if(e.text.length===0)return;let t=b4(e);return t?y4(t):void 0}if(e.type===`thinking_delta`){if(e.text.length===0)return;let t=S4(e);return t?x4(t):void 0}}function kAe(e,t){let n=t.payload;if(n.type!==`message_queued`||n.source!==`user`)return!1;let r=typeof n.eventId==`string`?n.eventId:t.eventId,i=typeof n.text==`string`?n.text:void 0;return e.some(e=>e.type!==`user.message`||e.source!==`transcript`?!1:r&&(e.entryId===r||e.stableKey===`entry:${r}`)?!0:!!(i&&AAe(e)===i))}function AAe(e){if(typeof e.output==`string`)return e.output;if(typeof e.summary==`string`)return e.summary}function f4(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 jAe(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 MAe(e,t,n,r,i,a,o,s,c){let l=`eventId`in t&&typeof t.eventId==`string`?t.eventId:void 0,u=`event:${t.type}:${l??C4(t)}`,d=l?v4(l):void 0,f={id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:_4(t),orderKey:h4(o,t.type,s,c),children:[]};switch(t.type){case`message_queued`:{let n=vAe(t.text);return t.source===`service`&&n?yAe({id:u,piboSessionId:e,eventId:l,startedAt:a,source:`event-log`,stableKey:l?`run-notification:${l}`:u,orderKey:h4(o,t.type,s,c),notification:n}):{...f,type:`user.message`,title:`User Message`,status:`done`,summary:t.text,output:t.text}}case`message_started`:case`message_finished`:return t.source===`service`?void 0:{...f,id:l?v4(l):u,type:`agent.turn`,title:`Agent Turn`,status:t.type===`message_finished`||i!==`running`?`done`:`running`,completedAt:t.type===`message_finished`?a:void 0,stableKey:l?`turn:${l}`:f.stableKey};case`thinking_finished`:{if(!UAe(t.text))return;let e=S4(t);return{...f,id:e?x4(e):u,parentId:d,type:`model.reasoning`,title:`Thinking`,status:`done`,summary:t.text,output:t.text,stableKey:e?`reasoning:${e}`:f.stableKey}}case`assistant_message`:{let e=b4(t);return{...f,id:e?y4(e):u,parentId:d,type:`assistant.message`,title:`Agent Message`,status:`done`,summary:t.text,output:t.text,stableKey:e?`assistant:${e}`:f.stableKey}}case`tool_call`:case`tool_execution_started`:case`tool_execution_updated`:case`tool_execution_finished`:{let o=r4(t.toolName),s=r.get(t.toolCallId)??(o?dAe(e,t.toolName,t,n):void 0);return{...f,id:`tool:${t.toolCallId}`,parentId:d,toolCallId:t.toolCallId,type:o?`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?WAe(t.result):void 0,linkedPiboSessionId:s,stableKey:`tool:${t.toolCallId}`,children:[]}}case`subagent_session`:return{...f,id:t.toolCallId?`tool:${t.toolCallId}`:u,eventId:l,toolCallId:t.toolCallId,type:`agent.delegation`,title:t.toolName,status:i===`running`?`running`:`done`,summary:t.subagentName,input:{subagentName:t.subagentName,threadKey:t.threadKey},linkedPiboSessionId:t.childPiboSessionId,stableKey:t.toolCallId?`tool:${t.toolCallId}`:`subagent:${t.childPiboSessionId}`,children:[]};case`execution_result`:return IAe(t.action)?void 0:{...f,type:`execution.command`,title:t.action,status:`done`,input:{action:t.action},output:t.result};case`compaction_start`:return{...f,id:`event:compaction:${o??s??C4(t)}`,type:`execution.compaction`,title:`compact`,status:`running`,summary:`Compacting`,input:{reason:t.reason},stableKey:`compaction:active`};case`compaction_end`:return{...f,id:`event:compaction:end:${o??s??C4(t)}`,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:active`};case`session_error`:return{...f,type:`error`,title:`Session Error`,status:`error`,summary:t.errorDetails?.userMessage,input:t.errorDetails,error:t.error,output:t.error};default:return}}function NAe(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=b4(n),l=c?y4(c):`event:assistant_delta:${C4(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?v4(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:c?`assistant:${c}`:l,orderKey:h4(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function p4(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 PAe(e,t,n,r,i,a,o,s){if(n.text.length===0)return;let c=S4(n),l=c?x4(c):`event:thinking_delta:${C4(n)}`,u=t.get(l);if(u){let e=`${typeof u.output==`string`?u.output:``}${n.text}`;u.status=r===`running`?`running`:`done`,u.summary=e,u.output=e;return}let d={id:l,parentId:n.eventId?v4(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:c?`reasoning:${c}`:l,orderKey:h4(a,n.type,o,s),children:[]};e.push(d),t.set(d.id,d)}function FAe(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 m4(e,t){if(!t.parentId||t.status!==`done`)return;let n=e.get(t.parentId);!n||n.type!==`agent.turn`||(n.status=`done`,n.completedAt=t.completedAt??t.startedAt??n.completedAt)}function IAe(e){return e===`session.fork`||e===`session.clone`||e===`session.switch`}function LAe(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 RAe(e,t){let n=`eventId`in e&&typeof e.eventId==`string`?e.eventId:void 0;return!!(n&&t.has(n))}function zAe(e,t){return t!==`running`&&e.type===`tool_call`}function h4(e,t,n,r){return e===void 0&&(n!==void 0||r!==void 0)?Gc(n,r,g4(t)):Wc(e,g4(t))}function g4(e){switch(e){case`message_queued`: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 _4(e){let t=`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`tool:${e.toolCallId}`;if(t&&(e.type===`message_started`||e.type===`message_finished`))return`turn:${t}`;if(e.type===`thinking_started`||e.type===`thinking_delta`||e.type===`thinking_finished`){let t=S4(e);if(t)return`reasoning:${t}`}if(e.type===`assistant_delta`||e.type===`assistant_message`){let t=b4(e);if(t)return`assistant:${t}`}return`event:${e.type}:${t??C4(e)}`}function v4(e){return`event:message:${e}`}function y4(e){return`event:assistant:${e}`}function b4(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 x4(e){return`event:thinking:${e}`}function S4(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 BAe(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 VAe(e){return n4([...e]).reverse().find(e=>e.type===`execution.compaction`&&e.status===`running`)}function HAe(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 UAe(e){return typeof e==`string`&&e.trim().length>0}function WAe(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function C4(e){return GAe(new TextEncoder().encode(JSON.stringify(e))).slice(0,48)}function GAe(e){let t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,n=``,r=0;for(;r+2<e.length;r+=3){let i=e[r]<<16|e[r+1]<<8|e[r+2];n+=t[i>>18&63]+t[i>>12&63]+t[i>>6&63]+t[i&63]}if(r<e.length){let i=e[r],a=r+1<e.length?e[r+1]:0,o=i<<16|a<<8;n+=t[o>>18&63]+t[o>>12&63],r+1<e.length&&(n+=t[o>>6&63])}return n}function KAe(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 e4(n)}function qAe(e,t,n){return t.map(t=>w4(e,t,n))}function w4(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)||T4(r,t))?r:e?{...t,children:r.children}:{...t,children:[]}}let i=t.children.map(t=>w4(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)||T4(r,t))?r:a?{...t,children:r?.children??i}:{...t,children:i}}function T4(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.runId===t.runId&&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.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&&JAe(e.orderKey,t.orderKey)}function JAe(e,t){return e===t?!0:!e||!t?!1:e.sourceRank===t.sourceRank&&e.turnSeq===t.turnSeq&&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 YAe(e,t,n){if(!t.length)return e;let r=new Set(e.rawEvents.map(e=>f4(e))),i=[];for(let e of t){let t=f4(e);r.has(t)||(r.add(t),i.push(e))}if(!i.length)return e;let a=n4(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=[],p=new Set;for(let t of i){if(kAe(o,t))continue;f.push(t);let r=OAe(t.payload);p&&r?p.add(r):p=void 0,CAe(o,s,e.piboSessionId,t,l,u,!1,d,n)}if(!f.length)return e;let m=KAe(o);DAe(f)&&mAe(m);let h=qAe(c,m,p);return{...e,rawEvents:e.rawEvents.length?[...e.rawEvents,...f]:f,nodes:h,latestStreamId:jAe(f,e.latestStreamId)}}function E4(e){let t=new Map;if(O4(e.nodes,t),!t.size)return e;let{nodes:n,changed:r}=k4(e.nodes,t);return r?{...e,nodes:n}:e}function XAe(e){return e.some(D4)}function ZAe(e){let t=new Map;return j4(e,e=>{if(e.type!==`user.message`||!e.entryId)return;let n=M4(e),r=t.get(n);r?r.push(e.entryId):t.set(n,[e.entryId])}),t}function QAe(e,t){if(!t.size)return;let n=new Map;j4(e,e=>{if(e.type!==`user.message`||e.entryId)return;let r=M4(e),i=t.get(r);if(!i?.length)return;let a=n.get(r)??0,o=i[a];o&&(e.entryId=o,n.set(r,a+1))})}function D4(e){let t=e.payload;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&`type`in t&&t.type===`message_queued`&&`source`in t&&t.source===`user`&&`text`in t&&typeof t.text==`string`)}function O4(e,t){for(let n of e){if(n.type===`user.message`&&!A4(n)){let e=M4(n);e&&t.set(e,(t.get(e)??0)+1)}O4(n.children,t)}}function k4(e,t){let n=!1,r=[];for(let i of e){if(A4(i)){let e=M4(i),r=e?t.get(e)??0:0;if(r>0){t.set(e,r-1),n=!0;continue}}let e=k4(i.children,t);n||=e.changed,r.push(e.changed?{...i,children:e.nodes}:i)}return{nodes:n?r:e,changed:n}}function A4(e){return e.type===`user.message`?e.source===`event-log`&&e.id.startsWith(`event:message_queued:`)?!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 j4(e,t){for(let n of e)t(n),j4(n.children,t)}function M4(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function $Ae({selectedPiboSessionId:e,reconciledBaseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:i,now:a}){if(!e||t?.piboSessionId!==e)return{traceView:null};let o=n?.piboSessionId===e?n.events:[];if(!o.length)return{traceView:t};let s=a?.(),c=YAe(t,o,r??`idle`),l=XAe(o);return l&&QAe(c.nodes,i),{traceView:l?E4(c):c,liveTraceComputeDurationMs:s!==void 0&&a?a()-s:void 0}}function N4(e,t){for(let n of e)t(n),N4(n.children,t)}function eje(e){return typeof e.output==`string`?e.output:typeof e.summary==`string`?e.summary:``}function P4(e){if(!e)return;let t=0;return N4(e.nodes,e=>{e.type===`assistant.message`&&(t+=eje(e).length)}),t}function tje({selectedPiboSessionId:e,baseTraceView:t,liveTraceOverlay:n,selectedSessionStatus:r}){let i=(0,R.useMemo)(()=>t?E4(t):null,[t]),a=(0,R.useMemo)(()=>i?ZAe(i.nodes):new Map,[i]),o=(0,R.useMemo)(()=>$Ae({selectedPiboSessionId:e,reconciledBaseTraceView:i,liveTraceOverlay:n,selectedSessionStatus:r,persistedUserMessageIndexForBaseTrace:a,now:zU()?()=>performance.now():void 0}),[n,e,r,i,a]),s=o.traceView;return(0,R.useEffect)(()=>{!e||!s?.piboSessionId||!zU()||(XU(s.piboSessionId,{overlayEventCount:n?.piboSessionId===s.piboSessionId?n.events.length:0,traceBaseOutputLength:P4(t),currentOutputLength:P4(s)}),o.liveTraceComputeDurationMs!==void 0&&GU(s.piboSessionId,o.liveTraceComputeDurationMs))},[t,o.liveTraceComputeDurationMs,s,n,e]),(0,R.useEffect)(()=>{let e=()=>{!s?.piboSessionId||!Y2()||oAe(s.piboSessionId,`tab:${document.visibilityState}`,s.nodes,{traceVersion:s.version,latestStreamId:s.latestStreamId,lastRawEventId:s.rawEvents.at(-1)?.id})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[s]),s}var F4=1e4,I4=30*6e4,L4=2e3;function nje(e,t=!1,n){return[`chat`,`bootstrap`,e??``,t?`archived`:`active`,n??``]}function rje(e=!1,t,n){return[`chat`,`sessions`,e?`archived`:`active`,t??``,n??``]}function ije(e){return[`chat`,`trace-summary`,e]}function aje(e,t=!1,n,r=t?60:120){return[`chat`,`session-page`,e,t?`archived`:`active`,n??``,r]}function R4(e,t={}){let n=t.pageSize??t.eventLimit??2e3;return[`chat`,`trace-page`,e,t.includeRawEvents?`raw`:`compact`,t.rawEventsLimit??80,n,t.beforeSequence===void 0?`tail`:String(t.beforeSequence)]}function z4(e){return[`chat`,`trace-summary`,e]}function B4(e){return[`chat`,`trace-page`,e]}function oje(e,t){if(!e||e.piboSessionId!==t.piboSessionId)return e;let n=t.latestStreamId,r=sje(t),i=V4(t.nodes),a=e.events.filter(e=>{if(n!==void 0&&e.streamId!==void 0&&e.streamId<=n||D4(e)&&i.has(e.payload.text))return!1;let t=U4(e);return!t||!r.has(t)});return a.length?{...e,events:a}:null}function V4(e){let t=new Set;for(let n of e){if(n.type===`user.message`&&n.source===`transcript`){let e=cje(n);e&&t.add(e)}for(let e of V4(n.children))t.add(e)}return t}function sje(e){let t=new Set;for(let n of e.rawEvents){let e=U4(n);e&&t.add(e)}return H4(e.nodes,t),t}function H4(e,t){for(let n of e){if(n.type===`user.message`){let e=n.id.startsWith(`event:message_queued:`)?n.id.slice(21):void 0;e&&t.add(`${n.piboSessionId}:message_queued:${e}`),n.source===`transcript`&&n.entryId&&t.add(`${n.piboSessionId}:message_queued:${n.entryId}`)}n.eventId&&n.type===`assistant.message`&&(t.add(`${n.piboSessionId}:assistant_delta:${n.eventId}`),t.add(`${n.piboSessionId}:assistant_message:${n.eventId}`)),n.eventId&&n.type===`model.reasoning`&&(t.add(`${n.piboSessionId}:thinking_delta:${n.eventId}`),t.add(`${n.piboSessionId}:thinking_finished:${n.eventId}`)),H4(n.children,t)}}function U4(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(!(!n||!r))return`${r}:${e.type}:${n}`}function cje(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 lje(e,t){if(e.piboSessionId!==t.piboSessionId)return e;let n=new Set,r=[...t.nodes,...e.nodes].filter(e=>n.has(e.id)?!1:(n.add(e.id),!0)),i=new Set,a=[...t.rawEvents,...e.rawEvents].filter(e=>{let t=e.id||`${e.eventSequence??``}:${e.type}:${e.createdAt}`;return i.has(t)?!1:(i.add(t),!0)});return{...e,version:e.version,nodes:r,rawEvents:a,firstEventSequence:t.firstEventSequence??e.firstEventSequence,nextBeforeSequence:t.nextBeforeSequence,hasOlderEvents:t.hasOlderEvents,eventLimit:(e.eventLimit??0)+(t.eventLimit??t.pageSize??0)}}function uje({selectedPiboSessionId:e,showRawEvents:t,setLiveTraceOverlay:n}){let r=Yt(),[i,a]=(0,R.useState)(L4),[o,s]=(0,R.useState)(80),[c,l]=(0,R.useState)(null),u=(0,R.useMemo)(()=>e?ije(e):null,[e]),d=(0,R.useMemo)(()=>e?R4(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4}):null,[o,e,t]),f=dn({queryKey:u??[`chat`,`trace-summary`,`idle`],queryFn:async()=>{if(!e||!u)throw Error(`Session is required`);let t=r.getQueryData(u),n=await Ic(e,t?.version);if(n.notModified&&t)return t;if(!n.summary)throw Error(`Trace summary response missing payload.`);return n.summary},enabled:!!e,staleTime:F4,gcTime:I4,refetchOnWindowFocus:!1,retry:1}),p=dn({queryKey:d??[`chat`,`trace-page`,`idle`,`compact`,o,2e3,`tail`],queryFn:async()=>{if(!e||!d)throw Error(`Session is required`);let n=r.getQueryData(d),i=await Lc(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4,knownVersion:n?.version});if(i.notModified&&n)return n;if(!i.trace)throw Error(`Trace page response missing payload.`);return i.trace},enabled:!!e,staleTime:F4,gcTime:I4,refetchOnWindowFocus:!1,retry:1});(0,R.useEffect)(()=>{a(L4),s(80),l(null),n(null)},[e,n]),(0,R.useEffect)(()=>{let t=p.data;!t||t.piboSessionId!==e||(zU()&&XU(t.piboSessionId,{overlayEventCount:0,traceBaseOutputLength:P4(t),traceBaseUpdated:!0}),(0,R.startTransition)(()=>{l(t),n(e=>oje(e,t))}))},[e,n,p.data]);let m=(0,R.useCallback)(async n=>{if(!e||!n)return;let i=R4(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4,beforeSequence:n}),s=await r.fetchQuery({queryKey:i,queryFn:async()=>{let a=r.getQueryData(i),s=await Lc(e,{includeRawEvents:t,rawEventsLimit:o,pageSize:L4,beforeSequence:n,knownVersion:a?.version});if(s.notModified&&a)return a;if(!s.trace)throw Error(`Trace page response missing payload.`);return s.trace},staleTime:F4,gcTime:I4});(0,R.startTransition)(()=>{l(e=>e?lje(e,s):s),a(e=>e+(s.pageSize??2e3))})},[r,o,e,t]),h=(0,R.useCallback)(()=>{s(e=>e+80)},[]);return{baseTraceView:c,traceEventLimit:i,rawEventLimit:o,traceSummaryQuery:f,tracePageQuery:p,tracePageReady:!!d,loadOlderTracePage:m,loadMoreRawEvents:h}}function dje(e){let t=e.currentEvents,n,r,i=()=>(r??=new Set(t.map(K4)),r),a=e=>{n??=t.slice(),n.push(e),t=n};for(let o of e.streamEvents){let s=mje(o,e.piboSessionId,e.nextSequence,e.now??(()=>new Date().toISOString()));if(!s)continue;if(fje(s)){t=pje(t,s),n=t,r=void 0;continue}let c=K4(s),l=i();l.has(c)||(l.add(c),a(s))}return t}function fje(e){return e.type===`assistant_message`||e.type===`thinking_finished`||e.type===`tool_execution_finished`}function pje(e,t){return t.type===`assistant_message`?[...G4(e,t,`assistant_delta`),t]:t.type===`thinking_finished`?[...G4(e,t,`thinking_delta`),t]:t.type===`tool_execution_finished`?[...G4(e,t,`tool_execution_updated`),t]:e}function mje(e,t,n,r){if(e.type===`RAW_EVENT`&&Y4(e.event)&&typeof e.event.type==`string`){let i=e.event;return W4(e,t,e.event.type,i,n,r)}if(e.type===`TEXT_MESSAGE_CONTENT`&&typeof e.delta==`string`)return W4(e,t,`assistant_delta`,{type:`assistant_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...J4(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 W4(e,t,`thinking_delta`,{type:`thinking_delta`,piboSessionId:t,eventId:typeof e.runId==`string`?e.runId:void 0,...J4(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 W4(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,args:e.args},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 W4(e,t,a,a===`tool_execution_updated`?{type:`tool_execution_updated`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,partialResult:e.partialResult}:{type:`tool_call`,piboSessionId:t,eventId:i,toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,argsComplete:!!e.argsComplete},n,r)}if(e.type===`TOOL_CALL_RESULT`&&typeof e.toolCallId==`string`&&typeof e.toolName==`string`)return W4(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,result:e.result,isError:!!e.isError},n,r);if(e.type===`RUN_ERROR`&&typeof e.message==`string`)return W4(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 W4(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();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,streamId:typeof e.streamId==`number`?e.streamId:void 0,streamFrameIndex:s,eventId:typeof r.eventId==`string`?r.eventId:void 0,type:n,createdAt:a(),payload:r}}function G4(e,t,n){let r=q4(t);return e.filter(e=>e.type!==n||q4(e)!==r)}function K4(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 q4(e){let t=Y4(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`)return`${n}:${r}:tool:${t.toolCallId}`;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 J4(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 Y4(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}var hje=500,gje=1e4,_je=45e3,vje=100;function yje({selectedPiboSessionId:e,tracePageData:t,currentTraceView:n,liveEventSeqRef:r,selectedSessionStatus:i,tracePageReady:a,setLiveTraceOverlay:o,onRefreshTrace:s,onRefreshBootstrap:c,onError:l}){let u=(0,R.useRef)(new Map),d=(0,R.useRef)(void 0),f=(0,R.useRef)(void 0),p=(0,R.useRef)(new Map),m=(0,R.useRef)(new Map),h=(0,R.useRef)(null),g=(0,R.useRef)(void 0),_=(0,R.useRef)(0),[v,y]=(0,R.useState)(0);(0,R.useEffect)(()=>{let n=t;if(!n||n.piboSessionId!==e)return;let i=n.rawEvents.map(e=>e.eventSequence??0).reduce((e,t)=>Math.max(e,t),0);r.current=Math.max(r.current,i+1),n.latestStreamId!==void 0&&Xc(m.current,n.piboSessionId,n.latestStreamId)},[r,e,t]);let b=(0,R.useCallback)(e=>{let t=u.current.get(e);t?.length&&(o(n=>{let i=dje({currentEvents:n?.piboSessionId===e?n.events:[],streamEvents:t,piboSessionId:e,nextSequence:()=>r.current++});return WU(e,t.length,i.length),{piboSessionId:e,events:i}}),u.current.delete(e))},[]),x=(0,R.useCallback)(()=>{if(!(d.current!==void 0||f.current!==void 0||!e)){if(document.hidden){f.current=setTimeout(()=>{f.current=void 0,b(e)},vje);return}d.current=requestAnimationFrame(()=>{d.current=void 0,b(e)})}},[b,e]),S=(0,R.useCallback)((t,n,r=!1)=>{nl(p.current,t,n);let i=r||rl(p.current,t,n),a=u.current.get(t)??[];a.push(n),u.current.set(t,a),UU(t,n,a.length,i),i||t!==e?b(t):x()},[b,x,e]);(0,R.useEffect)(()=>()=>{d.current!==void 0&&cancelAnimationFrame(d.current),f.current!==void 0&&clearTimeout(f.current),g.current!==void 0&&clearTimeout(g.current)},[]);let C=(0,R.useCallback)((e,t)=>{Zc(m.current,e,t)},[]),w=(0,R.useCallback)((e=0)=>{if(g.current!==void 0){if(e>0)return;clearTimeout(g.current)}g.current=setTimeout(()=>{g.current=void 0,y(e=>e+1)},e)},[]),T=(0,R.useCallback)(()=>{if(!e)return;b(e),s().catch(e=>l(X4(e))),c().catch(e=>l(X4(e)));let t=h.current;(!t||t.piboSessionId!==e||t.events.readyState===2||Date.now()-t.lastActivityAt>_je)&&w()},[b,l,c,s,w,e]);(0,R.useEffect)(()=>{if(!e||!a||!n||n.piboSessionId!==e)return;let t=new URLSearchParams({piboSessionId:e});t.set(`mode`,`live`);let r=m.current.get(e),i=r?.cursor??(n.latestStreamId===void 0?void 0:Qc(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()}`),u=Date.now();h.current={piboSessionId:e,events:o,openedAt:u,lastActivityAt:u};let d=!1,f,p,v=!1,y=!1,x=(t,n=!1)=>{if(f){if(!n)return;clearTimeout(f)}qU(e,t),f=setTimeout(()=>{f=void 0,s().catch(e=>l(X4(e)))},t)},T=()=>{if(v){y=!0;return}v=!0,c().catch(e=>l(X4(e))).finally(()=>{v=!1,y&&(y=!1,E(250,!0))})},E=(e,t=!1)=>{if(p){if(!t)return;clearTimeout(p)}p=setTimeout(()=>{p=void 0,T()},e)},D=()=>{E(900,!0)};return o.onopen=()=>{_.current=0,g.current!==void 0&&(clearTimeout(g.current),g.current=void 0),BU(e,o.readyState);let t=h.current;t?.events===o&&(t.lastActivityAt=Date.now())},o.onerror=()=>{if(d)return;VU(e,o.readyState);let t=h.current;t?.events===o&&(t.lastErrorAt=Date.now());let n=_.current++;w(Math.min(gje,hje*2**n))},o.addEventListener(`pibo`,t=>{if(d)return;let n=Yc(t);if(!n)return;let r=n.piboSessionId||e,i=h.current;if(i?.events===o&&(i.lastActivityAt=Date.now()),C(r,n),HU(r,n,t.lastEventId,o.readyState),r===e&&n.type===`ready`&&n.liveReplay?.missed&&x(0,!0),ZU(n))return;let a=n.type!==`TEXT_MESSAGE_CONTENT`&&n.type!==`REASONING_MESSAGE_CONTENT`;r===e&&tl(n)&&S(r,n,a);let s=$c(n);r===e&&s!==void 0?x(s,!0):r===e&&n.type!==`ready`&&n.type!==`RAW_EVENT`&&x(1500,!0),el(n)&&(n.type===`RUN_FINISHED`||n.type===`RUN_ERROR`||n.type===`TEXT_MESSAGE_END`?D():E(r===e?0:150))}),()=>{d=!0,f&&clearTimeout(f),p&&clearTimeout(p),b(e),h.current?.events===o&&(h.current=null),o.close()}},[n?.piboSessionId,S,b,l,c,s,C,w,v,e,a]),(0,R.useEffect)(()=>{n?.piboSessionId&&b(n.piboSessionId)},[n?.piboSessionId,b]),(0,R.useEffect)(()=>{let e=()=>T(),t=()=>{document.hidden||T()};return window.addEventListener(`focus`,e),window.addEventListener(`online`,e),window.addEventListener(`pageshow`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`focus`,e),window.removeEventListener(`online`,e),window.removeEventListener(`pageshow`,e),document.removeEventListener(`visibilitychange`,t)}},[T]),(0,R.useEffect)(()=>{if(!e||i!==`running`)return;let t=window.setInterval(()=>{b(e),s().catch(e=>l(X4(e)))},1e3);return()=>window.clearInterval(t)},[b,l,s,e,i])}function X4(e){return e instanceof Error?e.message:String(e)}var bje=10;function xje(e,t,n,r){if(!t||!n.length)return e;let i=e[t]??[],a=new Set(i.map(e=>e.path)),o=n.filter(e=>e.path&&!a.has(e.path)).map(e=>({...e,id:r()}));return o.length?{...e,[t]:[...i,...o].slice(0,bje)}:e}function Sje(e,t,n){if(!t)return e;let r=e[t]??[],i=r.filter(e=>e.id!==n);return i.length===r.length?e:{...e,[t]:i}}function Cje(e,t){return!t||!e[t]?.length?e:{...e,[t]:[]}}function wje(e,t){let[n,r]=(0,R.useState)({});return{selectedUploadAttachments:(0,R.useMemo)(()=>e?n[e]??[]:[],[e,n]),attachUploadedFiles:(0,R.useCallback)(n=>{r(r=>xje(r,e,n,t))},[t,e]),detachUploadAttachment:(0,R.useCallback)(t=>{r(n=>Sje(n,e,t))},[e]),clearSelectedUploadAttachments:(0,R.useCallback)(()=>{r(t=>Cje(t,e))},[e])}}function Tje({selectedPiboSessionId:e,onError:t,formatError:n}){let[r,i]=(0,R.useState)([]),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(()=>e?D2(e):null),[l,u]=(0,R.useState)(()=>Ake()),[d,f]=(0,R.useState)(!1),p=!!(e&&s?.piboSessionId===e&&s.installed),m=!!e&&(a||p),h=dn({queryKey:[`web-annotations`,`app`,e],queryFn:async()=>{if(!e)throw Error(`Session is required`);return Ske(e,{limit:100,scope:`app`})},enabled:!!e&&(m||r.length>0),staleTime:1e3,refetchOnWindowFocus:m,refetchInterval:m?5e3:!1,retry:1}),g=h.refetch,_=(0,R.useMemo)(()=>(h.data?.annotations??[]).filter(e=>e.status!==`resolved`&&e.status!==`dismissed`),[h.data?.annotations]),v=(0,R.useMemo)(()=>r.map(e=>_.find(t=>t.id===e)).filter(e=>!!e),[r,_]);(0,R.useEffect)(()=>{i(e?kke(e):[]),c(e?D2(e):null)},[e]),(0,R.useEffect)(()=>{if(!e)return;let t=t=>{!t||t.piboSessionId!==e||(c(e=>t.installed?t:e?.installed&&e.bindingId&&t.bindingId&&e.bindingId!==t.bindingId?e:t),t.installed?g():o(!1))},n=e=>t(A2(e.detail)),r=n=>{n.key===O2(e)&&t(k2(n.newValue))},i=()=>t(D2(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)}},[g,e]),(0,R.useEffect)(()=>{if(!h.data)return;if(!_.length){i(t=>(t.length&&e&&j2(e,[]),t.length?[]:t));return}let t=new Set(_.map(e=>e.id));i(n=>{let r=n.filter(e=>t.has(e));return r.length!==n.length&&e&&j2(e,r),r.length===n.length?n:r})},[e,_,h.data]),(0,R.useEffect)(()=>{let e=()=>{o(!0),g()};return window.addEventListener(`pibo:web-annotation-saved`,e),()=>window.removeEventListener(`pibo:web-annotation-saved`,e)},[g]);let y=(0,R.useCallback)(t=>{i(n=>{let r=t(n);return e&&j2(e,r),r})},[e]),b=(0,R.useCallback)(e=>{y(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].slice(0,5))},[y]),x=(0,R.useCallback)(()=>y(()=>[]),[y]);return{selectedWebAnnotationIds:r,selectedWebAnnotations:v,visibleWebAnnotations:_,webAnnotationsPanelCollapsed:l,webAnnotationsPanelRendered:m,webAnnotationsPanelVisible:a,webAnnotationsQuery:h,clearingWebAnnotations:d,setWebAnnotationsPanelVisible:o,toggleWebAnnotationAttachment:b,detachWebAnnotationAttachment:(0,R.useCallback)(e=>{y(t=>t.filter(t=>t!==e))},[y]),clearSelectedWebAnnotationAttachments:x,toggleWebAnnotationsPanelCollapsed:(0,R.useCallback)(()=>{u(e=>{let t=!e;return jke(t),t})},[]),clearVisibleWebAnnotations:(0,R.useCallback)(async()=>{if(!(!_.length||d)&&window.confirm(`Dismiss ${_.length} visible web annotations? This keeps sent messages but clears the annotation list.`)){f(!0);try{await Promise.all(_.map(e=>Cke(e.id,{piboSessionId:e.piboSessionId,status:`dismissed`,summary:`Cleared from Chat Web UI`}))),x(),await g()}catch(e){t(n(e,`Could not clear web annotations`))}finally{f(!1)}}},[d,x,n,t,g,_])}}function Z4(e){return e.session?.profile??e.agents[0]?.name??e.customAgents[0]?.profileName??``}function Eje(e){return e?.identity??{userId:`user`}}function Q4(e,t){let n=Oje(e,t);return n?Dje(n):void 0}function $4(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=$4(n.children,t);if(e)return e}}function e3(e,t,n=[]){for(let r of e){let e=[...n,r];if(r.piboSessionId===t)return e;let i=e3(r.children,t,e);if(i.length)return i}return[]}function t3(){let e=globalThis.crypto?.randomUUID?.()??Math.random().toString(36).slice(2);return`web-${Date.now().toString(36)}-${e}`}function Dje(e){return`${e.provider}/${e.id}`}function Oje(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}function kje(e,t){return t?{sessionBreadcrumbs:Pje(e,t),originSession:Mje(e,t),derivedSessions:Nje(e,t)}:{sessionBreadcrumbs:[],originSession:void 0,derivedSessions:[]}}function Aje(e){let t=e.selectedPiboSessionId?$4(e.bootstrap.sessions,e.selectedPiboSessionId):void 0,n=Rje(e.currentTraceView);return Lje(e.selectedSessionActiveModel,e.bootstrap.runtimeStatus?.thinkingLevel??n.level??Fje(e.bootstrap,e.selectedSessionProfile,!!t?.parentId),e.bootstrap.runtimeStatus?.fastMode??n.fast??Ije(e.bootstrap,e.selectedSessionProfile,!!t?.parentId)??!1)}function jje(e){return{traceView:e.currentTraceView,selectedTrace:null,isLoading:e.isLoading,showThinking:e.showThinking,expandThinking:e.expandThinking,sessionAgentProfile:e.selectedSessionProfile,sessionActiveModel:e.sessionActiveModelBadge,selectedSessionStatus:e.selectedSessionStatus,selectedSessionSignal:e.selectedSessionSignal,workflowProjectSession:e.workflowProjectSession,workflowLifecycleEvents:e.workflowLifecycleEvents,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,onThinkingLevelChange:e.onThinkingLevelChange,onModelChanged:async()=>{await e.onRefreshBootstrap(),await e.onRefreshTrace()},onRefreshBootstrap:e.onRefreshBootstrap,onError:e.onError}}function Mje(e,t){let n=$4(e,t);if(!n?.originId)return;let r=$4(e,n.originId);return{piboSessionId:n.originId,label:r?r3(r,0):n.originId}}function Nje(e,t){return $4(e,t)?.derivedSessions.map(e=>({piboSessionId:e.piboSessionId,label:Bje(e),profile:e.profile,status:e.status}))??[]}function Pje(e,t){return e3(e,t).map((e,t)=>({piboSessionId:e.piboSessionId,label:r3(e,t)}))}function Fje(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 Ije(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 Lje(e,t,n){if(e)return[e,t,n?`fast`:void 0].filter(Boolean).join(` `)}function Rje(e){let t={};if(!e)return t;for(let n of n3(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`&&zje(e.level)?e.level:void 0)??t.level,fast:n.title===`fast_mode`?e?.mode===`fast`:t.fast}}return t}function n3(e){return e.flatMap(e=>[e,...n3(e.children)])}function zje(e){return Xq.includes(e)}function r3(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 Bje(e){return e.subagentName&&e.subagentName!==e.profile?`${e.subagentName} (${e.profile})`:e.title||e.profile||e.subagentName||`Untitled Session`}function Vje({piboSessionId:e,text:t,selectedWebAnnotations:n,selectedUploadAttachments:r,eventSequence:i,now:a,clientTxnId:o}){let s=n.map(e=>e.id),c=r.map(e=>e.path);return{text:t,webAnnotationIds:s,fileAttachmentPaths:c,clientTxnId:o,optimisticEvent:{id:o,piboSessionId:e,eventSequence:i,eventId:o,type:`message_queued`,createdAt:a,payload:{type:`message_queued`,piboSessionId:e,eventId:o,clientTxnId:o,queuedMessages:1,text:t,...c.length?{fileAttachmentPaths:c}:{},source:`user`}}}}function Hje(e,t,n){return{piboSessionId:t,events:[...e?.piboSessionId===t?e.events:[],n]}}function i3(e){return e instanceof Error?e.message:String(e)}function a3({bootstrap:e,selectedPiboSessionId:t,selectedRoomId:n,selectedRoomArchived:r,selectedSessionProfile:i,selectedSessionActiveModel:a,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,projectSessionCreatePanel:u,workflowStartPanel:d,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,creatingSession:g,showRawEvents:_,showThinking:v,expandThinking:y,commands:b,skills:x,composerText:S,composerFocusSignal:C,onComposerTextChange:w,onToggleRawEvents:T,onToggleThinking:E,onToggleExpandThinking:D,onSessionAgentProfileChange:O,onFork:k,onOpenSession:A,onSelectSessionView:j,onCommand:M,onThinkingLevelChange:N,onRefreshTrace:P,onRefreshBootstrap:F,onSend:ee,onError:te}){let I=(0,R.useRef)(0),[ne,L]=(0,R.useState)(null),{baseTraceView:re,traceEventLimit:ie,rawEventLimit:ae,traceSummaryQuery:oe,tracePageQuery:se,tracePageReady:ce,loadOlderTracePage:le,loadMoreRawEvents:ue}=uje({selectedPiboSessionId:t,showRawEvents:_,setLiveTraceOverlay:L}),{selectedWebAnnotationIds:de,selectedWebAnnotations:fe,visibleWebAnnotations:pe,webAnnotationsPanelCollapsed:me,webAnnotationsPanelRendered:he,webAnnotationsPanelVisible:ge,webAnnotationsQuery:_e,clearingWebAnnotations:ve,setWebAnnotationsPanelVisible:ye,toggleWebAnnotationAttachment:be,detachWebAnnotationAttachment:xe,clearSelectedWebAnnotationAttachments:Se,toggleWebAnnotationsPanelCollapsed:Ce,clearVisibleWebAnnotations:we}=Tje({selectedPiboSessionId:t,onError:te,formatError:N2}),{selectedUploadAttachments:Te,attachUploadedFiles:Ee,detachUploadAttachment:De,clearSelectedUploadAttachments:Oe}=wje(t,(0,R.useCallback)(()=>`upload-${t3()}`,[])),ke=tje({selectedPiboSessionId:t,baseTraceView:re,liveTraceOverlay:ne,selectedSessionStatus:o});yje({selectedPiboSessionId:t,tracePageData:se.data,currentTraceView:ke,liveEventSeqRef:I,selectedSessionStatus:o,tracePageReady:ce,setLiveTraceOverlay:L,onRefreshTrace:P,onRefreshBootstrap:F,onError:te});let Ae=Aje({bootstrap:e,selectedPiboSessionId:t,selectedSessionProfile:i,selectedSessionActiveModel:a,currentTraceView:ke}),je=(0,R.useMemo)(()=>kje(e.sessions,t),[e.sessions,t]),Me=!!t&&se.isFetching&&!ke,Ne=se.error?i3(se.error):oe.error?i3(oe.error):null,Pe=ke?.piboSessionId??t??``,Fe=c&&R2(c)?Kke(c,o):null,Ie=async e=>{if(!t)return;let n=Vje({piboSessionId:t,text:e,selectedWebAnnotations:fe,selectedUploadAttachments:Te,eventSequence:I.current++,now:new Date().toISOString(),clientTxnId:t3()});L(e=>Hje(e,t,n.optimisticEvent)),await ee(n.text,n.webAnnotationIds,n.fileAttachmentPaths,n.clientTxnId),Se(),Oe(),await Promise.all([se.refetch(),_e.refetch()])},Le=jje({currentTraceView:ke,isLoading:Me,showThinking:v,expandThinking:y,selectedSessionProfile:i,sessionActiveModelBadge:Ae,selectedSessionStatus:o,selectedSessionSignal:s,workflowProjectSession:c,workflowLifecycleEvents:l,sessionNodes:e.sessions,sessionLinks:je,agentProfiles:e.agents,sessionProfileChangeDisabled:g||r,onSessionAgentProfileChange:O,onFork:k,onOpenSession:A,onThinkingLevelChange:N,onRefreshTrace:P,onRefreshBootstrap:F,onError:te});return(0,z.jsx)(eAe,{selectedPiboSessionId:t,selectedRoomId:n,fallbackRoomId:e.selectedRoomId??void 0,sessionViewId:f,loadingTrace:Me,traceError:Ne,showRawEvents:_,currentTraceView:ke,traceEventLimit:ie,rawEventLimit:ae,tracePageFetching:se.isFetching,onLoadOlderTracePage:e=>void le(e),onLoadMoreRawEvents:ue,headerProps:{title:ke?.title??t??e.room?.name??n,roomLabel:e.room?.name??n??`Room`,headerPiboSessionId:Pe,piboSessionId:t,piboRoomId:n??e.selectedRoomId??void 0,webAnnotationsDisabled:!t||r,webAnnotationsPanelRendered:he,workflowHeader:Fe,sessionViewId:f,sessionViews:p,currentSessionView:m,allowedSessionViewIds:h,showRawEvents:_,showThinking:v,expandThinking:y,onShowWebAnnotationsPanel:()=>ye(!0),onHideWebAnnotationsPanel:()=>ye(!1),onSelectSessionView:j,onToggleRawEvents:T,onToggleThinking:E,onToggleExpandThinking:D,onError:te},projectSessionCreatePanel:u,workflowStartPanel:d,currentSessionView:m,sessionViewProps:Le,webAnnotationsPanelRendered:he,webAnnotationsPanelProps:{piboSessionId:t,annotations:pe,selectedIds:de,loading:_e.isLoading||_e.isFetching||ve,error:_e.error?i3(_e.error):null,collapsed:me,onRefresh:()=>void _e.refetch(),onToggle:be,onClear:()=>void we(),onCollapse:Ce,onClose:()=>ye(!1)},composerProps:{sessionId:t,disabled:!t||r,commands:b,skills:x,value:S,focusSignal:C,selectedWebAnnotations:fe,selectedUploadAttachments:Te,onValueChange:w,onCommand:M,onDetachWebAnnotation:xe,onClearWebAnnotations:Se,onAttachUploadedFiles:Ee,onDetachUploadAttachment:De,onClearUploadAttachments:Oe,onSend:Ie}})}var o3=3e3;function Uje(e){return`${e.name||`Untitled Room`}\n${e.id}`}function Wje(e){return`${s3(e)}\n${e.piboSessionId}`}function s3(e){return typeof e.title==`string`&&e.title?e.title:`Untitled Session`}function Gje(e,t){let n=`session-signal h-2 w-2 rounded-full`;return e.status===`error`?{className:`${n} session-signal-error`,title:(e.unreadCount??0)>0?`Run failed`:`Run failed (read)`}:e.status===`running`?{className:`${n} session-signal-running`,title:`Runtime is working`}:(e.unreadCount??0)>0||Kje(e,t)?{className:`${n} session-signal-unread`,title:`New completed assistant message`}:{className:`${n} session-signal-idle`,title:`Idle`}}function Kje(e,t){if(!e.lastActivityAt)return!1;let n=Date.parse(e.lastActivityAt);return Number.isFinite(n)&&t-n<o3}function qje(e,t){let n,r=e=>{if(e.status!==`running`&&e.status!==`error`&&(e.unreadCount??0)===0&&e.lastActivityAt){let r=Date.parse(e.lastActivityAt);if(Number.isFinite(r)){let e=o3-(t-r);e>0&&(n=n===void 0?e:Math.min(n,e))}}for(let t of e.children)r(t)};for(let t of e)r(t);return n===void 0?void 0:n+50}function c3(e,t){return e.some(e=>e.piboSessionId===t||c3(e.children,t))}function l3(e,t=!0){let n=[],r=[];for(let i of e){if(i.archived){t&&r.push(i);continue}let e=l3(i.children,t);n.push({...i,children:e.active}),t&&r.push(...e.archived)}return{active:n,archived:r}}function Jje(e,t,n){if(e.length<=t)return e;let r=e.slice(0,t);if(!n)return r;let i=e.find(e=>e.piboSessionId===n||c3(e.children,n));return!i||r.some(e=>e.piboSessionId===i.piboSessionId)?r:[...r,i]}function u3(e){for(let t of e){if(p3(t))return t;let e=u3(t.children??[]);if(e)return e}}function d3(e,t){for(let n of e){if(n.id===t)return n;let e=d3(n.children??[],t);if(e)return e}}function Yje(e){return e.reduce((e,t)=>e+(t.unreadCount??0),0)}function f3(e){let t=[],n=[];for(let r of e){if(p3(r)){let e=f3(r.children??[]);t.push(...e.active),n.push(...e.archived);continue}if(m3(r)){n.push(r);continue}let e=f3(r.children??[]);t.push({...r,children:e.active}),n.push(...e.archived)}return{active:t,archived:n}}function p3(e){return e.metadata.default===!0}function m3(e){return typeof e.metadata.chatRoomArchivedAt==`string`}function Xje(e){return e.topic&&e.workspace?`${e.topic} | ${e.workspace}`:e.topic?e.topic:e.workspace?e.workspace:e.type}function h3({node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:s,onViewContext:c,depth:l=0,loadingPiboSessionId:u,autoRename:d=!1,onAutoRenameConsumed:f,showWorkflowSessionKindMarkers:p=!1}){let m=s3(e),h=Wje(e),[g,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(m),b=(0,R.useRef)(null),x=e.children.length>0,S=n!==null&&e.piboSessionId!==n&&r.has(e.piboSessionId),[C,w]=(0,R.useState)(S),[T,E]=(0,R.useState)(!1),D=(0,R.useRef)(null);(0,R.useEffect)(()=>{if(!T)return;let e=e=>{D.current&&!D.current.contains(e.target)&&E(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[T]),(0,R.useEffect)(()=>{g||y(m)},[g,m]),(0,R.useEffect)(()=>{d&&(y(m===`Untitled Session`?``:m),_(!0),f?.())},[d,m,f]),(0,R.useLayoutEffect)(()=>{g&&(b.current?.focus(),b.current?.select())},[g]),(0,R.useEffect)(()=>{S&&w(!0)},[S]);let O=()=>{let t=v.trim();a(e.piboSessionId,t||null),_(!1)},k=Gje(e,t),A=u===e.piboSessionId,j=p?Zje(e.workflowSessionKind):null,M=j?.Icon;return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{"data-pibo-component":`SessionNode`,"data-pibo-debug":`session-row`,"data-pibo-session-id":e.piboSessionId,"data-pibo-title":m,"data-pibo-selected":e.piboSessionId===n?`true`:`false`,"data-pibo-state":A?`loading`:e.status??`idle`,"data-pibo-archived":e.archived?`true`:`false`,"data-pibo-unread-count":e.unreadCount??0,className:`group w-full grid grid-cols-[1fr_auto] gap-1 items-center mb-1 border rounded-sm ${e.piboSessionId===n?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-transparent`}`,style:{paddingLeft:8+l*14},title:h,children:[g?(0,z.jsxs)(`form`,{className:`min-w-0 grid grid-cols-[1fr_auto_auto] gap-1 py-1 pr-1`,onSubmit:e=>{e.preventDefault(),O()},children:[(0,z.jsx)(`input`,{ref:b,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),_(!1),y(m))},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,z.jsx)(`button`,{type:`submit`,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,z.jsx)(Ro,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>{_(!1),y(m)},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,z.jsx)(Qs,{size:13})})]}):(0,z.jsxs)(`div`,{className:`min-w-0 grid grid-cols-[1fr_auto] gap-2 items-center py-1 pr-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>{if(x&&e.piboSessionId===n){w(e=>!e);return}i(e.piboSessionId)},"aria-label":j?`${j.ariaLabel}: ${m}`:`Open session ${m}`,className:`min-w-0 text-left px-1 py-1 grid grid-cols-[minmax(0,1fr)_auto] gap-2 items-center`,children:(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[j&&M?(0,z.jsx)(`span`,{className:`h-4 w-4 shrink-0 inline-flex items-center justify-center rounded-sm border ${j.className}`,title:j.ariaLabel,"aria-label":j.ariaLabel,children:(0,z.jsx)(M,{size:11,"aria-hidden":`true`})}):null,(0,z.jsx)(`span`,{className:`block min-w-0 truncate text-sm ${e.archived?`text-slate-500`:`text-slate-200`}`,children:m})]}),(0,z.jsxs)(`span`,{className:`mt-0.5 flex min-w-0 items-center gap-1.5`,children:[j?(0,z.jsx)(`span`,{className:`shrink-0 rounded-sm border px-1 py-0.5 text-[9px] font-bold uppercase tracking-wide ${j.className}`,title:j.ariaLabel,children:j.label}):null,(0,z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-slate-500`,children:e.piboSessionId})]})]})}),(0,z.jsxs)(`span`,{className:`grid grid-rows-[16px_16px] place-items-center gap-0.5`,children:[A?(0,z.jsx)(Cs,{size:13,className:`text-[#11a4d4] animate-spin`,"aria-label":`Loading session`}):(0,z.jsx)(`span`,{className:k.className,title:k.title,"aria-label":k.title}),x?(0,z.jsx)(`button`,{type:`button`,onClick:()=>w(e=>!e),"aria-expanded":C,title:C?`Collapse Subsessions`:`Expand Subsessions`,"aria-label":C?`Collapse Subsessions`:`Expand Subsessions`,className:`h-4 w-4 inline-flex items-center justify-center rounded-sm transition-colors ${C?`text-[#0bda57]`:`text-slate-600 hover:text-[#11a4d4]`}`,children:(0,z.jsx)(vs,{size:13})}):(0,z.jsx)(`span`,{className:`h-4 w-4`})]})]}),g?null:(0,z.jsx)(`div`,{className:`flex items-center gap-1 pr-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,children:(0,z.jsxs)(`div`,{className:`relative`,ref:D,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>E(e=>!e),title:`Session actions`,"aria-label":`Session actions`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(ns,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}),T&&(0,z.jsx)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-48 bg-[#1a262b] border border-slate-700 rounded-sm shadow-lg py-1`,children:e.archived?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),o(e.piboSessionId,!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(wo,{size:16}),` Restore Session`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),c(e.piboSessionId)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Fo,{size:16}),` View Context`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),s(e)},className:`w-full text-left px-3 py-2.5 text-sm text-red-300 hover:bg-red-500/10 flex items-center gap-2`,children:[(0,z.jsx)(qs,{size:16}),` Delete Session`]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),_(!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Ms,{size:16}),` Rename Session`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),o(e.piboSessionId,!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(To,{size:16}),` Archive Session`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{E(!1),c(e.piboSessionId)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Fo,{size:16}),` View Context`]})]})})]})})]}),C?e.children.map(e=>(0,z.jsx)(h3,{node:e,signalNow:t,selectedPiboSessionId:n,selectedSessionPathIds:r,onSelect:i,onRename:a,onArchive:o,onDelete:s,onViewContext:c,depth:l+1,loadingPiboSessionId:u,showWorkflowSessionKindMarkers:p},e.piboSessionId)):null]})}function Zje(e){switch(e){case`main_workflow`:return{label:`main workflow`,ariaLabel:`Main workflow session`,className:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,Icon:vs};case`nested_workflow`:return{label:`nested workflow`,ariaLabel:`Nested workflow session`,className:`border-violet-400/40 bg-violet-500/10 text-violet-300`,Icon:$o};case`agent_node`:return{label:`agent node`,ariaLabel:`Workflow agent node session`,className:`border-emerald-400/40 bg-emerald-500/10 text-emerald-300`,Icon:Ys};case`subagent`:return{label:`subagent`,ariaLabel:`Subagent session`,className:`border-amber-400/40 bg-amber-500/10 text-amber-300`,Icon:Xs};default:return null}}var Qje=`240px 0px`,g3=192,_3=4,v3=8;function $je(e){return e>99?`99+`:String(e)}function eMe({count:e}){return!e||e<=0?null:(0,z.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:$je(e)})}function tMe({bootstrap:e,selectedRoomId:t,selectedPiboSessionId:n,showArchivedRooms:r,onToggleArchivedRooms:i,creatingRoom:a,onCreateRoom:o,onSelectRoom:s,onUpdateRoom:c,onArchiveRoom:l,onReadAllRoom:u,onDeleteRoom:d,newSessionProfile:f,onNewSessionProfileChange:p,selectedRoomArchived:m,creatingSession:h,onCreateSession:g,showArchived:_,onToggleArchivedSessions:v,loadingArchivedSessions:y,visibleActiveSessions:b,visibleArchivedSessions:x,totalActiveSessionCount:S,totalArchivedSessionCount:C,hasMoreActiveSessions:w,hasMoreArchivedSessions:T,loadingActiveSessions:E,sessionListScrollRef:D,onLoadMoreSessions:O,signalNow:k,selectedSessionPathIds:A,onSelectSession:j,onRenameSession:M,onArchiveSession:N,onDeleteSession:P,onViewContext:F,loadingPiboSessionId:ee,autoRenameSessionId:te,onAutoRenameConsumed:I}){let ne=!!(e.selectedRoomId||e.room||e.rooms.length),L=e.agents,re=u3(e.rooms),ie=f3(e.rooms);return(0,z.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":_?`archived-visible`:`active-only`,className:`min-h-0 flex-1 overflow-hidden p-2 flex flex-col gap-3`,children:[ne?(0,z.jsxs)(z.Fragment,{children:[re?(0,z.jsxs)(`div`,{className:`shrink-0`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Shared Chat`}),(0,z.jsx)(b3,{room:re,selectedRoomId:t,onSelect:e=>void s(e),onUpdate:(e,t)=>void c(e,t),onArchive:(e,t)=>void l(e,t),onReadAll:e=>void u(e),onDelete:d})]}):null,(0,z.jsxs)(`div`,{className:`min-h-0 flex-1 basis-0 overflow-hidden flex flex-col`,children:[(0,z.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Rooms`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.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,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:i,title:r?`Hide Archived Rooms`:`Show Archived Rooms`,"aria-label":r?`Hide Archived Rooms`:`Show Archived Rooms`,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,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),(0,z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pr-1`,children:[ie.active.map(e=>(0,z.jsx)(b3,{room:e,selectedRoomId:t,onSelect:e=>void s(e),onUpdate:(e,t)=>void c(e,t),onArchive:(e,t)=>void l(e,t),onReadAll:e=>void u(e),onDelete:d},e.id)),ie.active.length===0?(0,z.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,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Rooms`}),ie.archived.length?(0,z.jsx)(nMe,{rooms:ie.archived,selectedRoomId:t,onSelect:e=>void s(e),onUpdate:(e,t)=>void c(e,t),onArchive:(e,t)=>void l(e,t),onReadAll:e=>void u(e),onDelete:d}):(0,z.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,z.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,z.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Sessions`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),disabled:!L.length||m,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:L.map(e=>(0,z.jsx)(`option`,{value:e.name,title:e.description??e.name,children:e.name},e.name))}),(0,z.jsx)(`button`,{"data-pibo-debug":`new-session-button`,"data-pibo-room-id":t??e.selectedRoomId??void 0,"data-pibo-state":h?`creating`:m?`archived-disabled`:`ready`,type:`button`,onClick:()=>void g(),disabled:h||m,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,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void v(),disabled:y,title:_?`Hide Archived Sessions`:`Show Archived Sessions`,"aria-label":_?`Hide Archived Sessions`:`Show Archived Sessions`,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 ${_?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:y?(0,z.jsx)(Cs,{size:14,className:`animate-spin`}):_?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),(0,z.jsxs)(`div`,{ref:D,className:`min-h-0 flex-1 overflow-y-auto pr-1`,children:[b.map(e=>(0,z.jsx)(h3,{node:e,signalNow:k,selectedPiboSessionId:n,selectedSessionPathIds:A,onSelect:e=>void j(e),onRename:(e,t)=>void M(e,t),onArchive:(e,t)=>void N(e,t),onDelete:P,onViewContext:F,loadingPiboSessionId:ee,autoRename:te===e.piboSessionId,onAutoRenameConsumed:()=>I()},e.piboSessionId)),S===0?(0,z.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,w?(0,z.jsx)(y3,{debugName:`active-session-load-more`,loading:E,rootRef:D,onLoadMore:()=>O(!1),children:E?`Loading active sessions…`:`Load more active sessions (${b.length} of ${S})`}):null,_?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.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,z.jsx)(`span`,{children:`Archived Sessions`}),y?(0,z.jsx)(Cs,{size:12,className:`text-[#11a4d4] animate-spin`,"aria-label":`Loading archived sessions`}):null]}),y?(0,z.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,z.jsx)(Cs,{size:13,className:`text-[#11a4d4] animate-spin`}),` Loading archived sessions`]}):C?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(rMe,{sessions:x,signalNow:k,selectedPiboSessionId:n,selectedSessionPathIds:A,onSelect:e=>void j(e),onRename:(e,t)=>void M(e,t),onArchive:(e,t)=>void N(e,t),onDelete:P,onViewContext:F,loadingPiboSessionId:ee,autoRenameSessionId:te,onAutoRenameConsumed:()=>I()}),T?(0,z.jsx)(y3,{debugName:`archived-session-load-more`,loading:y,rootRef:D,onLoadMore:()=>O(!0),children:y?`Loading archived sessions…`:`Load more archived sessions (${x.length} of ${C})`}):null]}):(0,z.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 nMe({rooms:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o}){return(0,z.jsx)(`div`,{children:e.map(e=>(0,z.jsx)(b3,{room:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o},e.id))})}function y3({children:e,debugName:t,loading:n,rootRef:r,onLoadMore:i}){let a=(0,R.useRef)(null),o=(0,R.useRef)(i),s=(0,R.useRef)(!1);(0,R.useEffect)(()=>{o.current=i},[i]),(0,R.useEffect)(()=>{n||(s.current=!1)},[n]);let c=(0,R.useCallback)(()=>{s.current||n||(s.current=!0,Promise.resolve(o.current()).finally(()=>{s.current=!1}))},[n]);return(0,R.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:Qje,threshold:0});return t.observe(e),()=>t.disconnect()},[n,r,c]),(0,z.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 rMe({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,z.jsx)(`div`,{children:e.map(e=>(0,z.jsx)(h3,{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 b3({room:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o,depth:s=0}){let[c,l]=(0,R.useState)(!1),[u,d]=(0,R.useState)(e.name),[f,p]=(0,R.useState)(e.topic??``),[m,h]=(0,R.useState)(e.workspace??``),g=p3(e),_=m3(e),[v,y]=(0,R.useState)(!1),[b,x]=(0,R.useState)(null),S=(0,R.useRef)(null),C=(0,R.useRef)(null),w=Uje(e),T=()=>{u2(e.id).catch(()=>void 0)},E=(0,R.useCallback)(()=>{let e=S.current;if(!e)return;let t=e.getBoundingClientRect(),n=C.current?.offsetWidth??g3,r=_?144:192,i=C.current?.offsetHeight??r,a=Math.max(v3,window.innerWidth-n-v3),o=Math.min(Math.max(v3,t.right-n),a),s=t.bottom+_3,c=s+i<=window.innerHeight-v3?s:Math.max(v3,t.top-_3-i);x(e=>e?.top===c&&e.left===o?e:{top:c,left:o})},[_]);(0,R.useEffect)(()=>{if(!v){x(null);return}E();let e=()=>E();return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[v,E]),(0,R.useLayoutEffect)(()=>{v&&b&&E()},[v,b,E]),(0,R.useEffect)(()=>{if(!v)return;let e=e=>{let t=e.target;S.current?.contains(t)||C.current?.contains(t)||y(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]),(0,R.useEffect)(()=>{c||(d(e.name),p(e.topic??``),h(e.workspace??``))},[c,e.name,e.topic,e.workspace]);let D=()=>{let t=u.trim();t&&(r(e.id,{name:t,topic:f.trim()||null,workspace:m.trim()||null}),l(!1))};return(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`group mb-1 border rounded-sm ${g?e.id===t?`border-[#0bda57] bg-[#0bda57]/10`:`border-[#0bda57]/50 bg-[#0bda57]/5`:e.id===t?`border-[#11a4d4] bg-[#11a4d4]/10`:_?`border-[#f59e0b]/40 bg-[#f59e0b]/5`:`border-transparent`}`,style:{marginLeft:s*12},title:w,children:c&&!g?(0,z.jsxs)(`form`,{className:`grid gap-1 p-1`,onSubmit:e=>{e.preventDefault(),D()},children:[(0,z.jsx)(`input`,{value:u,onChange:e=>d(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,z.jsx)(`input`,{value:f,onChange:e=>p(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,z.jsx)(`input`,{value:m,onChange:e=>h(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,z.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,z.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,z.jsx)(Ro,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>l(!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,z.jsx)(Qs,{size:13})})]})]}):(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-center gap-1 py-1 pr-1`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`min-w-0 text-left px-2 py-1 grid grid-cols-[auto_minmax(0,1fr)_auto] gap-2 items-center`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 inline-flex items-center justify-center rounded-sm ${g?`bg-[#0bda57]/15 text-[#0bda57]`:_?`bg-[#f59e0b]/15 text-[#f59e0b]`:`bg-[#151f24] text-slate-500`}`,children:g?(0,z.jsx)(Ts,{size:13}):_?(0,z.jsx)(To,{size:13}):(0,z.jsx)(ls,{size:13})}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block text-sm truncate ${_?`text-slate-500`:`text-slate-200`}`,children:e.name}),(0,z.jsx)(`span`,{className:`block text-[10px] font-mono truncate text-slate-500`,children:g?`shared default room`:_?`archived`:Xje(e)})]}),(0,z.jsx)(eMe,{count:e.unreadCount})]}),(0,z.jsx)(`div`,{className:`flex items-center gap-1 pr-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,children:g?(0,z.jsx)(`span`,{title:`Shared Chat is locked`,"aria-label":`Shared Chat is locked`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-[#0bda57]/50 rounded-sm text-[#0bda57]`,children:(0,z.jsx)(Ts,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}):(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`button`,{ref:S,type:`button`,onClick:()=>y(e=>!e),title:`Room actions`,"aria-label":`Room actions`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(ns,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}),v&&b?(0,Na.createPortal)((0,z.jsx)(`div`,{ref:C,className:`fixed z-[1000] bg-[#1a262b] border border-slate-700 rounded-sm shadow-lg py-1`,style:{top:b.top,left:b.left,width:g3},children:_?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{T(),y(!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)($o,{size:16}),` Copy Room ID`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),i(e.id,!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(wo,{size:16}),` Restore Room`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),o(e)},className:`w-full text-left px-3 py-2.5 text-sm text-red-300 hover:bg-red-500/10 flex items-center gap-2`,children:[(0,z.jsx)(qs,{size:16}),` Delete Room`]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{T(),y(!1)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)($o,{size:16}),` Copy Room ID`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),l(!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Ms,{size:16}),` Edit Room`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),a(e.id)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Lo,{size:16}),` Read All`]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{y(!1),i(e.id,!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(To,{size:16}),` Archive Room`]})]})}),document.body):null]})})]})}),(e.children??[]).map(e=>(0,z.jsx)(b3,{room:e,selectedRoomId:t,onSelect:n,onUpdate:r,onArchive:i,onReadAll:a,onDelete:o,depth:s+1},e.id))]})}var x3=0,S3=1,C3=2,w3=4;function iMe(e){return()=>e}function aMe(e){e()}function T3(e,t){return n=>e(t(n))}function oMe(e,t){return()=>e(t)}function sMe(e,t){return n=>e(t,n)}function E3(e){return e!==void 0}function cMe(...e){return()=>{e.map(aMe)}}function D3(){}function O3(e,t){return t(e),e}function lMe(e,t){return t(e)}function k3(...e){return e}function A3(e,t){return e(S3,t)}function j3(e,t){e(x3,t)}function M3(e){e(C3)}function N3(e){return e(w3)}function P3(e,t){return A3(e,sMe(t,x3))}function F3(e,t){let n=e(S3,e=>{n(),t(e)});return n}function I3(e){let t,n;return r=>i=>{t=i,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function L3(e,t){return e===t}function R3(e=L3){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function z3(e){return t=>n=>{e(n)&&t(n)}}function B3(e){return t=>T3(t,e)}function V3(e){return t=>()=>{t(e)}}function Q(e,...t){let n=uMe(...t);return((t,r)=>{switch(t){case C3:M3(e);return;case S3:return A3(e,n(r))}})}function H3(e,t){return n=>r=>{n(t=e(t,r))}}function U3(e){return t=>n=>{e>0?e--:t(n)}}function W3(e){let t=null,n;return r=>i=>{t=i,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function G3(...e){let t=Array(e.length),n=0,r=null,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;A3(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 uMe(...e){return t=>e.reduceRight(lMe,t)}function dMe(e){let t,n,r=()=>t?.();return function(i,a){switch(i){case S3:return a?n===a?void 0:(r(),n=a,t=A3(e,a),t):(r(),D3);case C3:r(),n=null;return}}}function $(e){let t=e,n=q3();return((e,r)=>{switch(e){case x3:t=r;break;case S3:r(t);break;case w3:return t}return n(e,r)})}function K3(e,t){return O3($(t),t=>P3(e,t))}function q3(){let e=[];return((t,n)=>{switch(t){case x3:e.slice().forEach(e=>{e(n)});return;case C3:e.splice(0,e.length);return;case S3:return e.push(n),()=>{let t=e.indexOf(n);t>-1&&e.splice(t,1)}}})}function J3(e){return O3(q3(),t=>P3(e,t))}function Y3(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:fMe(),singleton:n}}var fMe=()=>Symbol();function pMe(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 X3(...e){let t=q3(),n=Array(e.length),r=0,i=2**e.length-1;return e.forEach((e,a)=>{let o=2**a;A3(e,e=>{n[a]=e,r|=o,r===i&&j3(t,n)})}),function(e,a){switch(e){case C3:M3(t);return;case S3:return r===i&&a(n),A3(t,a)}}}function Z3(e,t=L3){return Q(e,R3(t))}function Q3(...e){return function(t,n){switch(t){case C3:return;case S3:return cMe(...e.map(e=>A3(e,n)))}}}var $3={DEBUG:0,INFO:1,WARN:2,ERROR:3},mMe={[$3.DEBUG]:`debug`,[$3.ERROR]:`error`,[$3.INFO]:`log`,[$3.WARN]:`warn`},hMe=()=>typeof globalThis>`u`?window:globalThis,e6=Y3(()=>{let e=$($3.ERROR);return{log:$((t,n,r=$3.INFO)=>{r>=(hMe().VIRTUOSO_LOG_LEVEL??N3(e))&&console[mMe[r]](`%creact-virtuoso: %c%s %o`,`color: #0253b3; font-weight: bold`,`color: initial`,t,n)}),logLevel:e}},[],{singleton:!0});function t6(e,t,n){return n6(e,t,n).callbackRef}function n6(e,t,n){let r=R.useRef(null),i=e=>{},a=R.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 r6(e,t,n,r,i,a,o,s,c){return n6(R.useCallback(n=>{let c=gMe(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.scrollLeft:o.scrollTop:u?s?d.scrollX||d.document.documentElement.scrollLeft:d.scrollY||d.document.documentElement.scrollTop:s?l.scrollLeft:l.scrollTop,p=o?s?o.scrollWidth:o.scrollHeight:u?s?d.document.documentElement.scrollWidth:d.document.documentElement.scrollHeight:s?l.scrollWidth:l.scrollHeight,m=o?s?o.offsetWidth:o.offsetHeight:u?s?d.innerWidth:d.innerHeight:s?l.offsetWidth:l.offsetHeight;r({scrollHeight:p,scrollTop:Math.max(f,0),viewportHeight:m}),a?.(s?i6(`column-gap`,getComputedStyle(n).columnGap,i):i6(`row-gap`,getComputedStyle(n).rowGap,i)),c!==null&&e(c)},[e,t,i,a,o,r,s]),n,c)}function gMe(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),c=parseFloat(i.dataset.knownSize),l=t(i,n);if(l===0&&r(`Zero-sized element, this should not happen`,{child:i},$3.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 i6(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,$3.WARN),t===`normal`?0:parseInt(t??`0`,10)}function a6(e,t,n){let r=R.useRef(null),i=R.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}=n6(i,!0,n),s=R.useCallback(()=>{i(o.current)},[i,o]);return R.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 o6=Y3(()=>{let e=q3(),t=q3(),n=$(0),r=q3(),i=$(0),a=q3(),o=q3(),s=$(0),c=$(0),l=$(0),u=$(0),d=q3(),f=q3(),p=$(!1),m=$(!1),h=$(!1);return P3(Q(e,B3(({scrollTop:e})=>e)),t),P3(Q(e,B3(({scrollHeight:e})=>e)),o),P3(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}),s6={lvl:0};function c6(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 l6(e){return e===s6}function u6(e,t){if(!l6(e))return t===e.k?e.v:t<e.k?u6(e.l,t):u6(e.r,t)}function d6(e,t,n=`k`){if(l6(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){let r=d6(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return d6(e.l,t,n)}function f6(e,t,n){return l6(e)?C6(t,n,1):t===e.k?y6(e,{k:t,v:n}):t<e.k?w6(y6(e,{l:f6(e.l,t,n)})):w6(y6(e,{r:f6(e.r,t,n)}))}function p6(){return s6}function m6(e,t,n){if(l6(e))return[];let r=d6(e,t)[0];return _Me(_6(e,r,n))}function h6(e,t){if(l6(e))return s6;let{k:n,l:r,r:i}=e;if(t===n){if(l6(r))return i;if(l6(i))return r;let[t,n]=S6(r);return v6(y6(e,{k:t,l:b6(r),v:n}))}return v6(t<n?y6(e,{l:h6(r,t)}):y6(e,{r:h6(i,t)}))}function g6(e){return l6(e)?[]:[...g6(e.l),{k:e.k,v:e.v},...g6(e.r)]}function _6(e,t,n){if(l6(e))return[];let{k:r,l:i,r:a,v:o}=e,s=[];return r>t&&(s=s.concat(_6(i,t,n))),r>=t&&r<=n&&s.push({k:r,v:o}),r<=n&&(s=s.concat(_6(a,t,n))),s}function v6(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(x6(t))return T6(y6(e,{lvl:n-1}));if(!l6(t)&&!l6(t.r))return y6(t.r,{l:y6(t,{r:t.r.l}),lvl:n,r:y6(e,{l:t.r.r,lvl:n-1})});throw Error(`Unexpected empty nodes`)}if(x6(e))return E6(y6(e,{lvl:n-1}));if(!l6(r)&&!l6(r.l)){let t=r.l,i=x6(t)?r.lvl-1:r.lvl;return y6(t,{l:y6(e,{lvl:n-1,r:t.l}),lvl:t.lvl+1,r:E6(y6(r,{l:t.r,lvl:i}))})}throw Error(`Unexpected empty nodes`)}function y6(e,t){return C6(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 b6(e){return l6(e.r)?e.l:v6(y6(e,{r:b6(e.r)}))}function x6(e){return l6(e)||e.lvl>e.r.lvl}function S6(e){return l6(e.r)?[e.k,e.v]:S6(e.r)}function C6(e,t,n,r=s6,i=s6){return{k:e,l:r,lvl:n,r:i,v:t}}function w6(e){return E6(T6(e))}function T6(e){let{l:t}=e;return!l6(t)&&t.lvl===e.lvl?y6(t,{r:y6(e,{l:t.r})}):e}function E6(e){let{lvl:t,r:n}=e;return!l6(n)&&!l6(n.r)&&n.lvl===t&&n.r.lvl===t?y6(n,{l:y6(e,{r:n.l}),lvl:t+1}):e}function _Me(e){return c6(e,({k:e,v:t})=>({index:e,value:t}))}function D6(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function O6(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}var k6=Y3(()=>({recalcInProgress:$(!1)}),[],{singleton:!0});function A6(e,t,n){return e[j6(e,t,n)]}function j6(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 vMe(e,t,n,r){let i=j6(e,t,r),a=j6(e,n,r,i);return e.slice(i,a+1)}function M6(e,t){return Math.round(e.getBoundingClientRect()[t])}function N6(e){return!l6(e.groupOffsetTree)}function P6({index:e},t){return t===e?0:t<e?-1:1}function yMe(){return{groupIndices:[],groupOffsetTree:p6(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:p6()}}function bMe(e,t){let n=l6(e)?0:1/0;for(let r of t){let{endIndex:t,size:i,startIndex:a}=r;if(n=Math.min(n,a),l6(e)){e=f6(e,0,i);continue}let o=m6(e,a-1,t+1);if(o.some(DMe(r)))continue;let s=!1,c=!1;for(let{end:n,start:r,value:a}of o)s?(t>=r||i===a)&&(e=h6(e,r)):(c=a!==i,s=!0),n>t&&t>=r&&a!==i&&(e=f6(e,t+1,a));c&&(e=f6(e,a,i))}return[e,n]}function xMe(e){return typeof e.groupIndex<`u`}function SMe({offset:e},t){return t===e?0:t<e?-1:1}function F6(e,t,n){if(t.length===0)return 0;let{index:r,offset:i,size:a}=A6(t,e,P6),o=e-r,s=a*o+(o-1)*n+i;return s>0?s+n:s}function I6(e,t){if(!N6(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function L6(e,t,n){if(xMe(e))return t.groupIndices[e.groupIndex]+1;let r=I6(e.index===`LAST`?n:e.index,t);return r=Math.max(0,r,Math.min(n,r)),r}function CMe(e,t,n,r=0){return r>0&&(t=Math.max(t,A6(e,r,P6).offset)),c6(vMe(e,t,n,SMe),EMe)}function wMe(e,[t,n,r,i]){t.length>0&&r(`received item sizes`,t,$3.DEBUG);let a=e.sizeTree,o=a,s=0;if(n.length>0&&l6(a)&&t.length===2){let e=t[0].size,r=t[1].size;o=n.reduce((t,n)=>f6(f6(t,n,e),n+1,r),o)}else [o,s]=bMe(o,t);if(o===a)return e;let{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d}=z6(e.offsetTree,s,o,i);return{groupIndices:n,groupOffsetTree:n.reduce((e,t)=>f6(e,t,F6(t,d,i)),p6()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:d,sizeTree:o}}function TMe(e){return g6(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 R6(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 z6(e,t,n,r){let i=e,a=0,o=0,s=0,c=0;if(t!==0){c=j6(i,t-1,P6),s=i[c].offset;let e=d6(n,t-1);a=e[0],o=e[1],i.length&&i[c].size===d6(n,t)[1]&&--c,i=i.slice(0,c+1)}else i=[];for(let{start:e,value:c}of m6(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 EMe(e){return{index:e.index,value:e}}function DMe(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 OMe={offsetHeight:`height`,offsetWidth:`width`},B6=Y3(([{log:e},{recalcInProgress:t}])=>{let n=q3(),r=q3(),i=K3(r,0),a=q3(),o=q3(),s=$(0),c=$([]),l=$(void 0),u=$(void 0),d=$(void 0),f=$(void 0),p=$((e,t)=>M6(e,OMe[t])),m=$(void 0),h=$(0),g=yMe(),_=K3(Q(n,G3(c,e,h),H3(wMe,g),R3()),g),v=K3(Q(c,R3(),H3((e,t)=>({current:t,prev:e.current}),{current:[],prev:[]}),B3(({prev:e})=>e)),[]);P3(Q(c,z3(e=>e.length>0),G3(_,h),B3(([e,t,n])=>{let r=e.reduce((e,r,i)=>f6(e,r,F6(r,t.offsetTree,n)||i),p6());return{...t,groupIndices:e,groupOffsetTree:r}})),_),P3(Q(r,G3(_),z3(([e,{lastIndex:t}])=>e<t),B3(([e,{lastIndex:t,lastSize:n}])=>[{endIndex:t,size:n,startIndex:e}])),n),P3(l,u);let y=K3(Q(l,B3(e=>e===void 0)),!0);P3(Q(u,z3(e=>e!==void 0&&l6(N3(_).sizeTree)),B3(e=>{let t=N3(d),n=N3(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),P3(Q(f,z3(e=>e!==void 0&&e.length>0&&l6(N3(_).sizeTree)),B3(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),P3(Q(c,G3(d,u),z3(([,e,t])=>e!==void 0&&t!==void 0),B3(([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=J3(Q(n,G3(_),H3(({sizes:e},[t,n])=>({changed:n!==e,sizes:n}),{changed:!1,sizes:g}),B3(e=>e.changed)));A3(Q(s,H3((e,t)=>({diff:e.prev-t,prev:t}),{diff:0,prev:0}),B3(e=>e.diff)),e=>{let{groupIndices:n}=N3(_);if(e>0)j3(t,!0),j3(a,e+R6(e,n));else if(e<0){let t=N3(v);t.length>0&&(e-=R6(-e,t)),j3(o,e)}}),A3(Q(s,G3(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},$3.ERROR)});let x=J3(a);P3(Q(a,G3(_),B3(([e,t])=>{let n=t.groupIndices.length>0,r=[],i=t.lastSize;if(n){let n=u6(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=g6(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 g6(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=J3(Q(o,G3(_,h),B3(([e,{offsetTree:t},n])=>F6(-e,t,n))));return P3(Q(o,G3(_,h),B3(([e,t,n])=>{if(t.groupIndices.length>0){if(l6(t.sizeTree))return t;let r=p6(),i=N3(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=g6(t.sizeTree).reduce((t,{k:n,v:r})=>f6(t,Math.max(0,n+e),r),r),a!==-e){let n=u6(t.sizeTree,s);r=f6(r,0,n);let i=d6(t.sizeTree,-e+1)[1];r=f6(r,1,i)}return{...t,sizeTree:r,...z6(t.offsetTree,0,r,n)}}let r=g6(t.sizeTree).reduce((t,{k:n,v:r})=>f6(t,Math.max(0,n+e),r),p6());return{...t,sizeTree:r,...z6(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}},k3(e6,k6),{singleton:!0});function kMe(e){return e.reduce((e,t)=>(e.groupIndices.push(e.totalCount),e.totalCount+=t+1,e),{groupIndices:[],totalCount:0})}var V6=Y3(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:i}])=>{let a=q3(),o=q3(),s=J3(Q(a,B3(kMe)));return P3(Q(s,B3(e=>e.totalCount)),n),P3(Q(s,B3(e=>e.groupIndices)),e),P3(Q(X3(i,t,r),z3(([e,t])=>N6(t)),B3(([e,t,n])=>d6(t.groupOffsetTree,Math.max(e-n,0),`v`)[0]),R3(),B3(e=>[e])),o),{groupCounts:a,topItemsIndexes:o}},k3(B6,o6)),H6=Y3(([{log:e}])=>{let t=$(!1),n=J3(Q(t,z3(e=>e),R3()));return A3(t,t=>{t&&N3(e)(`props updated`,{},$3.DEBUG)}),{didMount:n,propsReady:t}},k3(e6),{singleton:!0}),AMe=typeof document<`u`&&`scrollBehavior`in document.documentElement.style;function U6(e){let t=typeof e==`number`?{index:e}:e;return t.align||=`start`,(!t.behavior||!AMe)&&(t.behavior=`auto`),t.offset===void 0&&(t.offset=0),t}var W6=Y3(([{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=q3(),m=q3(),h=$(0),g=null,_=null,v=null;function y(){g!==null&&(g(),g=null),v!==null&&(v(),v=null),_&&=(clearTimeout(_),null),j3(c,!1)}return P3(Q(p,G3(n,d,r,h,s,o,f),G3(e,a,i),B3(([[e,n,r,i,a,o,s,l],d,f,h])=>{let b=U6(e),{align:x,behavior:S,offset:C}=b,w=i-1,T=L6(b,n,w),E=F6(T,n.offsetTree,d)+o;x===`end`?(E+=f+d6(n.sizeTree,T)[1]-r+h,T===w&&(E+=s)):x===`center`?E+=(f+d6(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},$3.DEBUG),j3(p,e)):(j3(m,!0),l(`list did not change, scroll successful`,{},$3.DEBUG))};if(y(),S===`smooth`){let e=!1;v=A3(t,t=>{e||=t}),g=F3(u,()=>{D(e)})}else g=F3(Q(t,jMe(150)),D);return _=setTimeout(()=>{y()},1200),j3(c,!0),l(`scrolling from index to`,{behavior:S,index:T,top:E},$3.DEBUG),{behavior:S,top:E}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:h}},k3(B6,o6,e6),{singleton:!0});function jMe(e){return t=>{let n=setTimeout(()=>{t(!1)},e);return e=>{e&&(t(!0),clearTimeout(n))}}}function G6(e,t){e===0?t():requestAnimationFrame(()=>{G6(e-1,t)})}function K6(e,t){let n=t-1;return typeof e==`number`?e:e.index===`LAST`?n:e.index}var q6=Y3(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:i,scrollToIndex:a},{didMount:o}])=>{let s=$(!0),c=$(0),l=$(!0);return P3(Q(o,G3(c),z3(([e,t])=>t!==0),V3(!1)),s),P3(Q(o,G3(c),z3(([e,t])=>t!==0),V3(!1)),l),A3(Q(X3(t,o),G3(s,n,e,l),z3(([[,e],t,{sizeTree:n},r,i])=>e&&(!l6(n)||E3(r))&&!t&&!i),G3(c)),([,e])=>{F3(i,()=>{j3(l,!0)}),G6(4,()=>{F3(r,()=>{j3(s,!0)}),j3(a,e)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:s}},k3(B6,o6,W6,H6),{singleton:!0});function J6(e,t){return Math.abs(e-t)<1.01}var Y6=`up`,X6=`down`,MMe=`none`,NMe={atBottom:!1,notAtBottomBecause:`NOT_SHOWING_LAST_ITEM`,state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},PMe=0,Z6=Y3(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:i,viewportHeight:a}])=>{let o=$(!1),s=$(!0),c=q3(),l=q3(),u=$(4),d=$(PMe),f=K3(Q(Q3(Q(Z3(i),U3(1),V3(!0)),Q(Z3(i),U3(1),V3(!1),I3(100))),R3()),!1),p=K3(Q(Q3(Q(n,V3(!0)),Q(n,V3(!1),I3(200))),R3()),!1);P3(Q(X3(Z3(i),Z3(d)),B3(([e,t])=>e<=t),R3()),s),P3(Q(s,W3(50)),l);let m=J3(Q(X3(r,Z3(a),Z3(t),Z3(e),Z3(u)),H3((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}},NMe),R3((e,t)=>e!==void 0&&e.atBottom===t.atBottom))),h=K3(Q(r,H3((e,{scrollHeight:t,scrollTop:n,viewportHeight:r})=>{if(!J6(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}),z3(e=>e.changed),B3(e=>e.jump)),0);P3(Q(m,B3(e=>e.atBottom)),o),P3(Q(o,W3(50)),c);let g=$(X6);P3(Q(r,B3(({scrollTop:e})=>e),R3(),H3((e,t)=>N3(p)?{direction:e.direction,prevScrollTop:t}:{direction:t<e.prevScrollTop?Y6:X6,prevScrollTop:t},{direction:X6,prevScrollTop:0}),B3(e=>e.direction)),g),P3(Q(r,W3(50),V3(MMe)),g);let _=$(0);return P3(Q(f,z3(e=>!e),V3(0)),_),P3(Q(i,W3(100),G3(f),z3(([e,t])=>t),H3(([e,t],[n])=>[t,n],[0,0]),B3(([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:_}},k3(o6)),Q6=`top`,$6=`bottom`,e8=`none`;function t8(e,t,n){return typeof e==`number`?n===Y6&&t===Q6||n===X6&&t===$6?e:0:n===Y6?t===Q6?e.main:e.reverse:t===$6?e.main:e.reverse}function n8(e,t){return typeof e==`number`?e:e[t]??0}var r8=Y3(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:i}])=>{let a=q3(),o=$(0),s=$(0),c=$(0);return{increaseViewportBy:s,listBoundary:a,overscan:c,topListHeight:o,visibleRange:K3(Q(X3(Z3(r),Z3(i),Z3(n),Z3(a,O6),Z3(c),Z3(o),Z3(t),Z3(e),Z3(s)),B3(([e,t,n,[r,i],a,o,s,c,l])=>{let u=e-c,d=o+s,f=Math.max(n-u,0),p=e8,m=n8(l,Q6),h=n8(l,$6);return r-=c,r+=n+s,i+=n+s,i-=c,r>e+d-m&&(p=Y6),i<e-f+t+h&&(p=X6),p===e8?null:[Math.max(u-n-t8(a,Q6,p)-m,0),u-f-s+t+t8(a,$6,p)+h]}),z3(e=>e!==null),R3(O6)),[0,0])}},k3(o6),{singleton:!0});function FMe(e,t,n){if(N6(t)){let r=I6(e,t);return[{index:d6(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 i8={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function a8(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:s8(e,i,a),offsetBottom:m,offsetTop:l,top:p,topItems:s8(t,i,a),topListHeight:t.reduce((e,t)=>t.size+e,0),totalCount:n}}function o8(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=K6(t,s);return a8(Array.from({length:s}).map((e,t)=>({data:a[t+c],index:t+c,offset:0,size:0})),[],s,i,n,r)}function s8(e,t,n){if(e.length===0)return[];if(!N6(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=m6(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 c8(e,t){return e===void 0?0:typeof e==`number`?e:e[t]??0}var l8=Y3(([{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=$([]),g=$(0),_=q3(),v=$(0);P3(a.topItemsIndexes,h);let y=K3(Q(X3(p,m,Z3(c,O6),Z3(i),Z3(r),Z3(l),u,Z3(h),Z3(t),Z3(n),Z3(v),e),z3(([e,t,,n,,,,,,,,r])=>{let i=r!==void 0&&r.length!==n;return e&&!t&&!i}),B3(([,,[e,t],n,r,i,a,o,s,c,l,u])=>{let d=r,{offsetTree:f,sizeTree:p}=d,m=N3(g);if(n===0)return{...i8,totalCount:n};if(e===0&&t===0)return m===0?{...i8,totalCount:n}:o8(m,i,r,s,c,u||[]);if(l6(p))return m>0?null:a8(FMe(K6(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 m6(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 a8([],h,n,c,d,s);let _=o.length>0?o[o.length-1]+1:0,v=CMe(f,e,t,_);if(v.length===0)return null;let y=n-1,b=O3([],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=c8(l,Q6),S=c8(l,$6);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=m6(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=m6(p,r,r)[0]?.value??t.size;b.push({data:u?.[r],index:r,offset:n,size:e}),n+=e+c}}}return a8(b,h,n,c,d,s)}),z3(e=>e!==null),R3()),i8);P3(Q(e,z3(E3),B3(e=>e?.length)),i),P3(Q(y,B3(e=>e.topListHeight)),d),P3(d,s),P3(Q(y,B3(e=>[e.top,e.bottom])),o),P3(Q(y,B3(e=>e.items)),_);let b=J3(Q(y,z3(({items:e})=>e.length>0),G3(i,e),z3(([{items:e},t])=>e[e.length-1].originalIndex===t-1),B3(([,e,t])=>[e-1,t]),R3(O6),B3(([e])=>e))),x=J3(Q(y,W3(200),z3(({items:e,topItems:t})=>e.length>0&&e[0].originalIndex===t.length),B3(({items:e})=>e[0].index),R3()));return{endReached:b,initialItemCount:g,itemsRendered:_,listState:y,minOverscanItemCount:v,rangeChanged:J3(Q(y,z3(({items:e})=>e.length>0),B3(({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}}),R3(D6))),startReached:x,topItemsIndexes:h,...f}},k3(B6,V6,r8,q6,W6,Z6,H6,k6),{singleton:!0}),u8=Y3(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:i}])=>{let a=q3(),o=K3(Q(X3(n,e,r,t,i),B3(([e,t,n,r,i])=>e+t+n+r+i.offsetBottom+i.bottom)),0);return P3(Z3(o),a),{totalListHeight:o,totalListHeightChanged:a}},k3(o6,l8),{singleton:!0}),IMe=Y3(([{viewportHeight:e},{totalListHeight:t}])=>{let n=$(!1);return{alignToBottom:n,paddingTopAddition:K3(Q(X3(n,e,t),z3(([e])=>e),B3(([,e,t])=>Math.max(0,e-t)),W3(0),R3()),0)}},k3(o6,u8),{singleton:!0}),d8=Y3(()=>({context:$(null)})),LMe=({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,f8=Y3(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:i,headerHeight:a,scrollingInProgress:o,scrollTop:s,viewportHeight:c},{scrollToIndex:l}])=>{let u=q3();return P3(Q(u,G3(t,c,n,a,i,r,s),G3(e),B3(([[e,t,n,r,i,a,s,c],l])=>{let{calculateViewLocation:u=LMe,done:d,...f}=e,p=L6(e,t,r-1),m=F6(p,t.offsetTree,l)+i+a,h=m+d6(t.sizeTree,p)[1],g=c+a,_=u({itemBottom:h,itemTop:m,locationParams:f,viewportBottom:c+n-s,viewportTop:g});return _===null?d?.():d&&F3(Q(o,z3(e=>!e),U3(N3(o)?1:2)),d),_}),z3(e=>e!==null)),l),{scrollIntoView:u}},k3(B6,o6,W6,l8,e6),{singleton:!0});function p8(e){return e===!1?!1:e===`smooth`?`smooth`:`auto`}var RMe=(e,t)=>typeof e==`function`?p8(e(t)):t&&p8(e),zMe=Y3(([{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=$(!1),h=q3(),g=null;function _(e){j3(o,{align:`end`,behavior:e,index:`LAST`})}A3(Q(X3(Q(Z3(t),U3(1)),c),G3(Z3(m),a,s,d),B3(([[e,t],n,r,i,a])=>{let o=t&&i,s=`auto`;return o&&(s=RMe(n,r||a),o&&=s!==!1),{followOutputBehavior:s,shouldFollow:o,totalCount:e}}),z3(({shouldFollow:e})=>e)),({followOutputBehavior:t,totalCount:r})=>{g!==null&&(g(),g=null),N3(n)===void 0?g=F3(e,()=>{N3(u)(`following output to `,{totalCount:r},$3.DEBUG),_(t),g=null}):requestAnimationFrame(()=>{N3(u)(`following output to `,{totalCount:r},$3.DEBUG),_(t)})});function v(e){let t=F3(i,t=>{e&&!t.atBottom&&t.notAtBottomBecause===`SIZE_INCREASED`&&g===null&&(N3(u)(`scrolling to bottom due to increased size`,{},$3.DEBUG),_(`auto`))});setTimeout(t,100)}A3(Q(X3(Z3(m),t,l),z3(([e,,t])=>e!==!1&&t),H3(({value:e},[,t])=>({refreshed:e===t,value:t}),{refreshed:!1,value:0}),z3(({refreshed:e})=>e),G3(m,t)),([,e])=>{N3(s)&&v(e!==!1)}),A3(h,()=>{v(N3(m)!==!1)}),A3(X3(Z3(m),i),([e,t])=>{e!==!1&&!t.atBottom&&t.notAtBottomBecause===`VIEWPORT_HEIGHT_DECREASING`&&_(`auto`)});let y=$(null),b=q3();return P3(Q3(Q(Z3(r),B3(e=>e?.length??0)),Q(Z3(t))),b),A3(Q(X3(Q(b,U3(1)),c),G3(Z3(y),s,d,f),B3(([[e,t],n,r,i,a])=>t&&r&&n?.({context:a,totalCount:e,scrollingInProgress:i})),z3(e=>!!e),W3(0)),t=>{g!==null&&(g(),g=null),N3(n)===void 0?g=F3(e,()=>{N3(u)(`scrolling into view`,{}),j3(p,t),g=null}):requestAnimationFrame(()=>{N3(u)(`scrolling into view`,{}),j3(p,t)})}),{autoscrollToBottom:h,followOutput:m,scrollIntoViewOnChange:y}},k3(B6,Z6,W6,q6,H6,e6,o6,d8,f8)),BMe=Y3(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:i},{initialItemCount:a,listState:o},{didMount:s}])=>(P3(Q(s,G3(a),z3(([,e])=>e!==0),G3(i,r,t,n,e),B3(([[,e],t,n,r,i,a=[]])=>o8(e,t,n,r,i,a))),o),{}),k3(B6,q6,l8,H6),{singleton:!0}),VMe=Y3(([{didMount:e},{scrollTo:t},{listState:n}])=>{let r=$(0);return A3(Q(e,G3(r),z3(([,e])=>e!==0),B3(([,e])=>({top:e}))),e=>{F3(Q(n,U3(1),z3(e=>e.items.length>1)),()=>{requestAnimationFrame(()=>{j3(t,e)})})}),{initialScrollTop:r}},k3(H6,o6,l8),{singleton:!0}),m8=Y3(([{scrollVelocity:e}])=>{let t=$(!1),n=q3(),r=$(!1);return P3(Q(e,G3(r,t,n),z3(([e,t])=>t!==!1&&t!==void 0),B3(([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}),R3()),t),A3(Q(X3(t,e,n),G3(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}},k3(Z6),{singleton:!0}),h8=Y3(([{scrollContainerState:e,scrollTo:t}])=>{let n=q3(),r=q3(),i=q3(),a=$(!1),o=$(void 0);return P3(Q(X3(n,r),B3(([{scrollTop:e,viewportHeight:t},{offsetTop:n,listHeight:r}])=>({scrollHeight:r,scrollTop:Math.max(0,e-n),viewportHeight:t}))),e),P3(Q(t,G3(r),B3(([e,{offsetTop:t}])=>({...e,top:e.top+t}))),i),{customScrollParent:o,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:i,windowViewportRect:r}},k3(o6)),HMe=Y3(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:i},{didMount:a},{useWindowScroll:o,windowScrollContainerState:s,windowViewportRect:c}])=>{let l=q3(),u=$(void 0),d=$(null),f=$(null);return P3(s,d),P3(c,f),A3(Q(l,G3(t,r,o,d,f,n)),([e,t,n,r,i,a,o])=>{let s=TMe(t.sizeTree);r&&i!==null&&a!==null&&(n=i.scrollTop-a.offsetTop),n-=o,e({ranges:s,scrollTop:n})}),P3(Q(u,z3(E3),B3(UMe)),i),P3(Q(a,G3(u),z3(([,e])=>e!==void 0),R3(),B3(([,e])=>e.ranges)),e),{getState:l,restoreStateFrom:u}},k3(B6,o6,q6,H6,h8));function UMe(e){return{align:`start`,index:0,offset:e.scrollTop}}var WMe=Y3(([{topItemsIndexes:e}])=>{let t=$(0);return P3(Q(t,z3(e=>e>=0),B3(e=>Array.from({length:e}).map((e,t)=>t))),e),{topItemCount:t}},k3(l8));function g8(e){let t=!1,n;return(()=>(t||(t=!0,n=e()),n))}var GMe=g8(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),_8=Y3(([{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 P3(k,T.scrollSeekRangeChanged),P3(Q(T.windowViewportRect,B3(e=>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}},k3(B6,q6,o6,HMe,zMe,l8,W6,Y3(([{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=J3(Q(c,G3(o),H3(([,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]),z3(([e])=>e!==0),G3(r,s,n,i,p,m),z3(([,e,t,n,,,r])=>!r&&!n&&e!==0&&t===Y6),B3(([[e],,,,,t])=>(t(`Upward scrolling compensation`,{amount:e},$3.DEBUG),e))));function g(n){n>0?(j3(t,{behavior:`auto`,top:-n}),j3(e,0)):(j3(e,0),j3(t,{behavior:`auto`,top:-n}))}return A3(Q(h,G3(e,a)),([t,n,r])=>{r&&GMe()?j3(e,n-t):g(-t)}),A3(Q(X3(K3(a,!1),e,m),z3(([e,t,n])=>!e&&!n&&t!==0),B3(([e,t])=>t),W3(1)),g),P3(Q(d,B3(e=>({top:-e}))),t),A3(Q(l,G3(f,u),B3(([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=u6(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=>{j3(e,n),requestAnimationFrame(()=>{j3(t,{top:n}),requestAnimationFrame(()=>{j3(e,0),j3(m,!1)})})}),{deviation:e}},k3(o6,Z6,l8,B6,e6,k6)),WMe,V6,Y3(([e,t,n,r,i,a,o,s,c,l,u])=>({...e,...t,...n,...r,...i,...a,...o,...s,...c,...l,...u}),k3(r8,BMe,H6,m8,u8,VMe,IMe,h8,f8,e6,d8))));function KMe(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 v8=typeof document<`u`?R.useLayoutEffect:R.useEffect;function y8(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=R.createContext({});function c(e,n){e.propsReady!==void 0&&j3(e.propsReady,!1);for(let i of r){let r=e[t.required[i]];j3(r,n[i])}for(let r of i)if(r in n){let i=e[t.optional[r]];j3(i,n[r])}e.propsReady!==void 0&&j3(e.propsReady,!0)}function l(e){return a.reduce((n,r)=>(n[r]=n=>{let i=e[t.methods[r]];j3(i,n)},n),{})}function u(e){return o.reduce((n,r)=>(n[r]=dMe(e[t.events[r]]),n),{})}return{Component:R.forwardRef(function(t,a){let{children:d,...f}=t,[p]=R.useState(()=>O3(pMe(e),e=>{c(e,f)})),[m]=R.useState(oMe(u,p));v8(()=>{for(let e of o)e in f&&A3(m[e],f[e]);return()=>{Object.values(m).map(M3)}},[f,m,p]),v8(()=>{c(p,f)}),R.useImperativeHandle(a,iMe(l(p)));let h=n;return(0,z.jsx)(s.Provider,{value:p,children:n===void 0?d:(0,z.jsx)(h,{...KMe([...r,...i,...o],f),children:d})})}),useEmitter:(e,t)=>{let n=R.useContext(s)[e];v8(()=>A3(n,t),[t,n])},useEmitterValue:e=>{let t=R.useContext(s)[e],n=R.useCallback(e=>A3(t,e),[t]);return R.useSyncExternalStore(n,()=>N3(t),()=>N3(t))},usePublisher:e=>{let t=R.useContext(s);return R.useCallback(n=>{j3(t[e],n)},[t,e])}}}var b8=R.createContext(void 0),x8=R.createContext(void 0),S8=`-webkit-sticky`,C8=`sticky`,w8=g8(()=>{if(typeof document>`u`)return C8;let e=document.createElement(`div`);return e.style.position=S8,e.style.position===S8?S8:C8}),T8=typeof document<`u`?R.useLayoutEffect:R.useEffect;function E8(e){return`self`in e}function qMe(e){return`body`in e}function D8(e,t,n,r=D3,i,a){let o=R.useRef(null),s=R.useRef(null),c=R.useRef(null),l=R.useCallback(n=>{let r,i,o,l=n.target;if(qMe(l)||E8(l)){let e=E8(l)?l:l.defaultView;o=a===!0?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?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():Na.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]);R.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;E8(r)?(u=Math.max(M6(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?window.scrollX:window.scrollY):(u=r[a===!0?`scrollWidth`:`scrollHeight`],l=M6(r,a===!0?`width`:`height`),d=r[a===!0?`scrollLeft`:`scrollTop`]);let f=u-l;if(n.top=Math.ceil(Math.max(Math.min(f,n.top),0)),J6(l,u)||n.top===d){e({scrollHeight:u,scrollTop:d,viewportHeight:l}),i&&t(!0);return}i?(s.current=n.top,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:n.top}),r.scrollTo(n)}function d(e){a===!0&&(e={...e.behavior===void 0?{}:{behavior:e.behavior},...e.top===void 0?{}:{left:e.top}}),o.current.scrollBy(e)}return{scrollByCallback:d,scrollerRef:o,scrollToCallback:u}}function O8(e){return e}var JMe=Y3(([e,t])=>({...e,...t}),k3(_8,Y3(()=>{let e=$(e=>`Item ${e}`),t=$(e=>`Group ${e}`),n=$({}),r=$(O8),i=$(`div`),a=$(D3),o=(e,t=null)=>K3(Q(n,B3(t=>t[e]),R3()),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`)}}))),YMe=({height:e})=>(0,z.jsx)(`div`,{style:{height:e}}),XMe={overflowAnchor:`none`,position:w8(),zIndex:1},k8={overflowAnchor:`none`},ZMe={...k8,display:`inline-block`,height:`100%`},A8=R.memo(function({showTopList:e=!1}){let t=R8(`listState`),n=z8(`sizeRanges`),r=R8(`useWindowScroll`),i=R8(`customScrollParent`),a=z8(`windowScrollContainerState`),o=z8(`scrollContainerState`),s=i||r?a:o,c=R8(`itemContent`),l=R8(`context`),u=R8(`groupContent`),d=R8(`trackItemSizes`),f=R8(`itemSize`),p=R8(`log`),m=z8(`gap`),h=R8(`horizontalDirection`),{callbackRef:g}=r6(n,f,d,e?D3:s,p,m,i,h,R8(`skipAnimationFrameInResizeObserver`)),[_,v]=R.useState(0);L8(`deviation`,e=>{_!==e&&v(e)});let y=R8(`EmptyPlaceholder`),b=R8(`ScrollSeekPlaceholder`)??YMe,x=R8(`ListComponent`),S=R8(`ItemComponent`),C=R8(`GroupComponent`),w=R8(`computeItemKey`),T=R8(`isSeeking`),E=R8(`groupIndices`).length>0,D=R8(`alignToBottom`),O=R8(`initialItemFinalLocationReached`),k=e?{}:{boxSizing:`border-box`,...h?{display:`inline-block`,height:`100%`,marginLeft:_===0?D?`auto`:0:_,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:`nowrap`}:{marginTop:_===0?D?`auto`:0:_,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...O?{}:{visibility:`hidden`}};return!e&&t.totalCount===0&&y!=null?(0,z.jsx)(y,{...N8(y,l)}):(0,z.jsx)(x,{...N8(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,R.createElement)(b,{...N8(b,l),height:e.size,index:e.index,key:r,type:e.type||`item`,...e.type===`group`?{}:{groupIndex:e.groupIndex}}):e.type===`group`?(0,R.createElement)(C,{...N8(C,l),"data-index":n,"data-item-index":e.index,"data-known-size":e.size,key:r,style:XMe},u(e.index,l)):(0,R.createElement)(S,{...N8(S,l),...P8(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?ZMe:k8},E?c(e.index,e.groupIndex,e.data,l):c(e.index,e.data,l))})})}),QMe={height:`100%`,outline:`none`,overflowY:`auto`,position:`relative`,WebkitOverflowScrolling:`touch`},$Me={outline:`none`,overflowX:`auto`,position:`relative`},j8=e=>({height:`100%`,position:`absolute`,top:0,width:`100%`,...e?{display:`flex`,flexDirection:`column`}:void 0}),M8=(e,t,n=0)=>({...j8(e),position:t?`relative`:`absolute`,top:t?-n:0}),eNe={position:w8(),top:0,width:`100%`,zIndex:1};function N8(e,t){if(typeof e!=`string`)return{context:t}}function P8(e,t){return{item:typeof e==`string`?void 0:t}}var tNe=R.memo(function(){let e=R8(`HeaderComponent`),t=z8(`headerHeight`),n=R8(`HeaderFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,R8(`skipAnimationFrameInResizeObserver`)),i=R8(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})}),nNe=R.memo(function(){let e=R8(`FooterComponent`),t=z8(`footerHeight`),n=R8(`HeaderFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,R8(`skipAnimationFrameInResizeObserver`)),i=R8(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})});function F8({useEmitter:e,useEmitterValue:t,usePublisher:n}){return R.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}=D8(s,l,c,u,void 0,d);return e(`scrollTo`,m),e(`scrollBy`,f),(0,z.jsx)(c,{"data-testid":`virtuoso-scroller`,"data-virtuoso-scroller":!0,ref:p,style:{...d?$Me:QMe,...i},tabIndex:0,...o,...N8(c,a),children:r})})}function I8({useEmitter:e,useEmitterValue:t,usePublisher:n}){return R.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=R.useRef(null),{scrollByCallback:m,scrollerRef:h,scrollToCallback:g}=D8(s,l,c,t(`scrollerRef`),f);return T8(()=>(h.current=f||p.current?.ownerDocument.defaultView,()=>{h.current=null}),[h,f]),e(`windowScrollTo`,g),e(`scrollBy`,m),(0,z.jsx)(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:`relative`,...i,...u===0?void 0:{height:u+d}},...o,...N8(c,a),children:r})})}var rNe=({children:e})=>{let t=R.useContext(b8),n=z8(`viewportHeight`),r=z8(`fixedItemHeight`),i=R8(`alignToBottom`),a=R8(`horizontalDirection`),o=t6(R.useMemo(()=>T3(n,e=>M6(e,a?`width`:`height`)),[n,a]),!0,R8(`skipAnimationFrameInResizeObserver`));return R.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`element`,ref:o,style:j8(i),children:e})},iNe=({children:e})=>{let t=R.useContext(b8),n=z8(`windowViewportRect`),r=z8(`fixedItemHeight`),i=R8(`customScrollParent`),a=R8(`useWindowScroll`),o=R8(`topListHeight`),s=a6(n,i,R8(`skipAnimationFrameInResizeObserver`)),c=R8(`alignToBottom`);return R.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`window`,ref:s,style:M8(c,a,o),children:e})},aNe=({children:e})=>{let t=R8(`TopItemListComponent`)??`div`,n=R8(`headerHeight`);return(0,z.jsx)(t,{style:{...eNe,marginTop:`${n}px`},...N8(t,R8(`context`)),children:e})},{Component:oNe,useEmitter:L8,useEmitterValue:R8,usePublisher:z8}=y8(JMe,{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`}},R.memo(function(e){let t=R8(`useWindowScroll`),n=R8(`topItemsIndexes`).length>0,r=R8(`customScrollParent`),i=R8(`context`);return(0,z.jsxs)(r||t?cNe:sNe,{...e,context:i,children:[n&&(0,z.jsx)(aNe,{children:(0,z.jsx)(A8,{showTopList:!0})}),(0,z.jsxs)(r||t?iNe:rNe,{children:[(0,z.jsx)(tNe,{}),(0,z.jsx)(A8,{}),(0,z.jsx)(nNe,{})]})]})})),sNe=F8({useEmitter:L8,useEmitterValue:R8,usePublisher:z8}),cNe=I8({useEmitter:L8,useEmitterValue:R8,usePublisher:z8}),lNe=oNe,uNe=Y3(([e,t])=>({...e,...t}),k3(_8,Y3(()=>{let e=$(e=>(0,z.jsxs)(`td`,{children:[`Item $`,e]})),t=$(null),n=$(e=>(0,z.jsxs)(`td`,{colSpan:1e3,children:[`Group `,e]})),r=$(null),i=$(null),a=$({}),o=$(O8),s=$(D3),c=(e,t=null)=>K3(Q(a,B3(t=>t[e]),R3()),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`)}}))),dNe=({height:e})=>(0,z.jsx)(`tr`,{children:(0,z.jsx)(`td`,{style:{height:e}})}),fNe=({height:e})=>(0,z.jsx)(`tr`,{children:(0,z.jsx)(`td`,{style:{border:0,height:e,padding:0}})}),pNe={overflowAnchor:`none`},B8={position:w8(),zIndex:2,overflowAnchor:`none`},V8=R.memo(function({showTopList:e=!1}){let t=U8(`listState`),n=U8(`computeItemKey`),r=U8(`firstItemIndex`),i=U8(`context`),a=U8(`isSeeking`),o=U8(`fixedHeaderHeight`),s=U8(`groupIndices`).length>0,c=U8(`itemContent`),l=U8(`groupContent`),u=U8(`ScrollSeekPlaceholder`)??dNe,d=U8(`GroupComponent`),f=U8(`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,R.createElement)(u,{...N8(u,i),height:t.size,index:t.index,key:h,type:t.type||`item`}):t.type===`group`?(0,R.createElement)(d,{...N8(d,i),"data-index":m,"data-item-index":t.index,"data-known-size":t.size,key:h,style:{...B8,top:o}},l(t.index,i)):(0,R.createElement)(f,{...N8(f,i),...P8(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?{...B8,top:o+g}:pNe},s?c(t.index,t.groupIndex,t.data,i):c(t.index,t.data,i))})}),mNe=R.memo(function(){let e=U8(`listState`),t=U8(`topItemsIndexes`).length>0,n=W8(`sizeRanges`),r=U8(`useWindowScroll`),i=U8(`customScrollParent`),a=W8(`windowScrollContainerState`),o=W8(`scrollContainerState`),s=i||r?a:o,c=U8(`trackItemSizes`),{callbackRef:l,ref:u}=r6(n,U8(`itemSize`),c,s,U8(`log`),void 0,i,!1,U8(`skipAnimationFrameInResizeObserver`)),[d,f]=R.useState(0);H8(`deviation`,e=>{d!==e&&(u.current.style.marginTop=`${e}px`,f(e))});let p=U8(`EmptyPlaceholder`),m=U8(`FillerRow`)??fNe,h=U8(`TableBodyComponent`),g=U8(`paddingTopAddition`),_=U8(`statefulTotalCount`),v=U8(`context`);if(_===0&&p!=null)return(0,z.jsx)(p,{...N8(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,z.jsx)(m,{context:v,height:b},`padding-top`):null,C=x>0?(0,z.jsx)(m,{context:v,height:x},`padding-bottom`):null;return(0,z.jsxs)(h,{"data-testid":`virtuoso-item-list`,ref:l,...N8(h,v),children:[S,t&&(0,z.jsx)(V8,{showTopList:!0}),(0,z.jsx)(V8,{}),C]})}),hNe=({children:e})=>{let t=R.useContext(b8),n=W8(`viewportHeight`),r=W8(`fixedItemHeight`),i=t6(R.useMemo(()=>T3(n,e=>M6(e,`height`)),[n]),!0,U8(`skipAnimationFrameInResizeObserver`));return R.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`element`,ref:i,style:j8(!1),children:e})},gNe=({children:e})=>{let t=R.useContext(b8),n=W8(`windowViewportRect`),r=W8(`fixedItemHeight`),i=U8(`customScrollParent`),a=U8(`useWindowScroll`),o=a6(n,i,U8(`skipAnimationFrameInResizeObserver`));return R.useEffect(()=>{t&&(r(t.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),(0,z.jsx)(`div`,{"data-viewport-type":`window`,ref:o,style:M8(!1,a),children:e})},{Component:_Ne,useEmitter:H8,useEmitterValue:U8,usePublisher:W8}=y8(uNe,{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`}},R.memo(function(e){let t=U8(`useWindowScroll`),n=U8(`customScrollParent`),r=W8(`fixedHeaderHeight`),i=W8(`fixedFooterHeight`),a=U8(`fixedHeaderContent`),o=U8(`fixedFooterContent`),s=U8(`context`),c=t6(R.useMemo(()=>T3(r,e=>M6(e,`height`)),[r]),!0,U8(`skipAnimationFrameInResizeObserver`)),l=t6(R.useMemo(()=>T3(i,e=>M6(e,`height`)),[i]),!0,U8(`skipAnimationFrameInResizeObserver`)),u=n||t?yNe:vNe,d=n||t?gNe:hNe,f=U8(`TableComponent`),p=U8(`TableHeadComponent`),m=U8(`TableFooterComponent`),h=a?(0,z.jsx)(p,{ref:c,style:{position:`sticky`,top:0,zIndex:2},...N8(p,s),children:a()},`TableHead`):null,g=o?(0,z.jsx)(m,{ref:l,style:{bottom:0,position:`sticky`,zIndex:1},...N8(m,s),children:o()},`TableFoot`):null;return(0,z.jsx)(u,{...e,...N8(u,s),children:(0,z.jsx)(d,{children:(0,z.jsxs)(f,{style:{borderSpacing:0,overflowAnchor:`none`},...N8(f,s),children:[h,(0,z.jsx)(mNe,{},`TableBody`),g]})})})})),vNe=F8({useEmitter:H8,useEmitterValue:U8,usePublisher:W8}),yNe=I8({useEmitter:H8,useEmitterValue:U8,usePublisher:W8}),G8={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},bNe={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:K8,floor:q8,max:J8,min:Y8,round:X8}=Math;function Z8(e,t,n){return Array.from({length:t-e+1}).map((t,r)=>({data:n===null?null:n[r+e],index:r+e}))}function xNe(e){return{...bNe,items:e}}function Q8(e,t){return e!==void 0&&e.width===t.width&&e.height===t.height}function SNe(e,t){return e!==void 0&&e.column===t.column&&e.row===t.row}var CNe=Y3(([{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=$(0),C=$(0),w=$(G8),T=$({height:0,width:0}),E=$({height:0,width:0}),D=q3(),O=q3(),k=$(0),A=$(null),j=$({column:0,row:0}),M=q3(),N=q3(),P=$(!1),F=$(0),ee=$(!0),te=$(!1),I=$(!1);A3(Q(m,G3(F),z3(([e,t])=>t!==0)),()=>{j3(ee,!1)}),A3(Q(X3(m,ee,E,T,F,te),z3(([e,t,n,r,,i])=>e&&!t&&n.height!==0&&r.height!==0&&!i)),([,,,,e])=>{j3(te,!0),G6(1,()=>{j3(D,e)}),F3(Q(l),()=>{j3(t,[0,0]),j3(ee,!0)})}),P3(Q(N,z3(e=>e!=null&&e.scrollTop>0),V3(0)),C),A3(Q(m,G3(N),z3(([,e])=>e!=null)),([,e])=>{e&&(j3(T,e.viewport),j3(E,e.item),j3(j,e.gap),e.scrollTop>0&&(j3(P,!0),F3(Q(l,U3(1)),e=>{j3(P,!1)}),j3(c,{top:e.scrollTop})))}),P3(Q(T,B3(({height:e})=>e)),d),P3(Q(X3(Z3(T,Q8),Z3(E,Q8),Z3(j,(e,t)=>e!==void 0&&e.column===t.column&&e.row===t.row),Z3(l)),B3(([e,t,n,r])=>({gap:n,item:t,scrollTop:r,viewport:e}))),M),P3(Q(X3(Z3(S),r,Z3(j,SNe),Z3(E,Q8),Z3(T,Q8),Z3(A),Z3(C),Z3(P),Z3(ee),Z3(F)),z3(([,,,,,,,e])=>!e),B3(([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 G8;if(p===0){let t=K6(l,e);return xNe(Z8(t,t+Math.max(s-1,0),o))}let h=$8(m,p,u),g,_;c?t===0&&n===0&&s>0?(g=0,_=s-1):(g=h*q8((t+d)/(f+d)),_=h*K8((n+d)/(f+d))-1,_=Y8(e-1,J8(_,h-1)),g=Y8(_,J8(0,g))):(g=0,_=-1);let v=Z8(g,_,o),{bottom:y,top:b}=e5(a,r,i,v),x=K8(e/h);return{bottom:y,itemHeight:f,items:v,itemWidth:p,offsetBottom:x*f+(x-1)*d-y,offsetTop:b,top:b}})),w),P3(Q(A,z3(e=>e!==null),B3(e=>e.length)),S),P3(Q(X3(T,E,w,j),z3(([e,t,{items:n}])=>n.length>0&&t.height!==0&&e.height!==0),B3(([e,t,{items:n},r])=>{let{bottom:i,top:a}=e5(e,r,t,n);return[a,i]}),R3(O6)),t);let ne=$(!1);P3(Q(l,G3(ne),B3(([e,t])=>t||e!==0)),ne);let L=J3(Q(X3(w,S),z3(([{items:e}])=>e.length>0),G3(ne),z3(([[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}),B3(([[,e]])=>e-1),R3())),re=J3(Q(Z3(w),z3(({items:e})=>e.length>0&&e[0].index===0),V3(0),R3())),ie=J3(Q(Z3(w),G3(P),z3(([{items:e},t])=>e.length>0&&!t),B3(([{items:e}])=>({endIndex:e[e.length-1].index,startIndex:e[0].index})),R3(D6),W3(0)));P3(ie,p.scrollSeekRangeChanged),P3(Q(D,G3(T,E,S,j),B3(([e,t,n,r,i])=>{let a=U6(e),{align:o,behavior:s,offset:c}=a,l=a.index;l===`LAST`&&(l=r-1),l=J8(0,l,Y8(r-1,l));let u=t5(t,i,n,l);return o===`end`?u=X8(u-t.height+n.height):o===`center`&&(u=X8(u-t.height/2+n.height/2)),c!==void 0&&c!==0&&(u+=c),{behavior:s,top:u}})),c);let ae=K3(Q(w,B3(e=>e.offsetBottom+e.bottom)),0);return P3(Q(b,B3(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:I,initialTopMostItemIndex:F,totalListHeight:ae,...f,endReached:L,propsReady:h,rangeChanged:ie,startReached:re,stateChanged:M,stateRestoreInProgress:P,...x}},k3(r8,o6,Z6,m8,H6,h8,e6));function $8(e,t,n){return J8(1,q8((e+n)/(q8(t)+n)))}function e5(e,t,n,r){let{height:i}=n;if(i===void 0||r.length===0)return{bottom:0,top:0};let a=t5(e,t,n,r[0].index);return{bottom:t5(e,t,n,r[r.length-1].index)+i,top:a}}function t5(e,t,n,r){let i=q8(r/$8(e.width,n.width,t.column)),a=i*n.height+J8(0,i-1)*t.row;return a>0?a+t.row:a}var wNe=Y3(([e,t])=>({...e,...t}),k3(CNe,Y3(()=>{let e=$(e=>`Item ${e}`),t=$({}),n=$(null),r=$(`virtuoso-grid-item`),i=$(`virtuoso-grid-list`),a=$(O8),o=$(`div`),s=$(D3),c=(e,n=null)=>K3(Q(t,B3(t=>t[e]),R3()),n),l=$(!1),u=$(!1);return P3(Z3(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`)}}))),TNe=R.memo(function(){let e=r5(`gridState`),t=r5(`listClassName`),n=r5(`itemClassName`),r=r5(`itemContent`),i=r5(`computeItemKey`),a=r5(`isSeeking`),o=i5(`scrollHeight`),s=r5(`ItemComponent`),c=r5(`ListComponent`),l=r5(`ScrollSeekPlaceholder`),u=r5(`context`),d=i5(`itemDimensions`),f=i5(`gap`),p=r5(`log`),m=r5(`stateRestoreInProgress`),h=i5(`reportReadyState`),g=t6(R.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:a5(`column-gap`,getComputedStyle(e).columnGap,p),row:a5(`row-gap`,getComputedStyle(e).rowGap,p)})},[o,d,f,p]),!0,!1);return T8(()=>{e.itemHeight>0&&e.itemWidth>0&&h(!0)},[e]),m?null:(0,z.jsx)(c,{className:t,ref:g,...N8(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,z.jsx)(l,{...N8(l,u),height:e.itemHeight,index:t.index,width:e.itemWidth},o):(0,R.createElement)(s,{...N8(s,u),className:n,"data-index":t.index,key:o},r(t.index,t.data,u))})})}),ENe=R.memo(function(){let e=r5(`HeaderComponent`),t=i5(`headerHeight`),n=r5(`headerFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,!1),i=r5(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})}),DNe=R.memo(function(){let e=r5(`FooterComponent`),t=i5(`footerHeight`),n=r5(`headerFooterTag`),r=t6(R.useMemo(()=>e=>{t(M6(e,`height`))},[t]),!0,!1),i=r5(`context`);return e==null?null:(0,z.jsx)(n,{ref:r,children:(0,z.jsx)(e,{...N8(e,i)})})}),ONe=({children:e})=>{let t=R.useContext(x8),n=i5(`itemDimensions`),r=i5(`viewportDimensions`),i=t6(R.useMemo(()=>e=>{r(e.getBoundingClientRect())},[r]),!0,!1);return R.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),(0,z.jsx)(`div`,{ref:i,style:j8(!1),children:e})},kNe=({children:e})=>{let t=R.useContext(x8),n=i5(`windowViewportRect`),r=i5(`itemDimensions`),i=r5(`customScrollParent`),a=r5(`useWindowScroll`),o=a6(n,i,!1);return R.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),(0,z.jsx)(`div`,{ref:o,style:M8(!1,a),children:e})},{Component:ANe,useEmitter:n5,useEmitterValue:r5,usePublisher:i5}=y8(wNe,{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`}},R.memo(function({...e}){let t=r5(`useWindowScroll`),n=r5(`customScrollParent`),r=n||t?MNe:jNe,i=n||t?kNe:ONe,a=r5(`context`);return(0,z.jsx)(r,{...e,...N8(r,a),children:(0,z.jsxs)(i,{children:[(0,z.jsx)(ENe,{}),(0,z.jsx)(TNe,{}),(0,z.jsx)(DNe,{})]})})})),jNe=F8({useEmitter:n5,useEmitterValue:r5,usePublisher:i5}),MNe=I8({useEmitter:n5,useEmitterValue:r5,usePublisher:i5});function a5(e,t,n){return t!==`normal`&&t?.endsWith(`px`)!==!0&&n(`${e} was not resolved to pixel value correctly`,t,$3.WARN),t===`normal`?0:parseInt(t??`0`,10)}var NNe=24,PNe=700,FNe=3;function INe({itemCount:e,resetKey:t,contentKey:n,atBottomThreshold:r=NNe}){let i=(0,R.useRef)(null),a=(0,R.useRef)(e),o=(0,R.useRef)(!0),s=(0,R.useRef)(void 0),c=(0,R.useRef)(!1),l=(0,R.useRef)(void 0),u=(0,R.useRef)(void 0),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(null);(0,R.useLayoutEffect)(()=>{a.current=e},[e]);let h=(0,R.useCallback)(e=>{o.current=e,f(e)},[]),g=(0,R.useCallback)(()=>{s.current!==void 0&&(cancelAnimationFrame(s.current),s.current=void 0)},[]),_=(0,R.useCallback)((e=`auto`)=>{g(),s.current=requestAnimationFrame(()=>{if(s.current=void 0,!o.current)return;let t=a.current-1;t<0||(i.current?.autoscrollToBottom(),i.current?.scrollToIndex({index:t,align:`end`,behavior:e}),requestAnimationFrame(()=>{o.current&&i.current?.autoscrollToBottom()}))})},[g]),v=(0,R.useCallback)((e=`auto`)=>{h(!0),_(e)},[_,h]),y=(0,R.useCallback)((e,t=`center`,n=`auto`,r={})=>{h(!1),g(),requestAnimationFrame(()=>{if(n!==`fast-smooth`){i.current?.scrollToIndex({index:e,align:t,behavior:n});return}if(r.stagingAlign){i.current?.scrollToIndex({index:e,align:r.stagingAlign,behavior:`auto`}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{i.current?.scrollToIndex({index:e,align:t,behavior:`smooth`})})});return}let o=r.fromIndex,s=Math.abs(typeof o==`number`?o-e:0),c=r.stagingDistance??FNe;if(typeof o!=`number`||s<=c){i.current?.scrollToIndex({index:e,align:t,behavior:`smooth`});return}let l=a.current-1,u=e<o?Math.min(l,e+c):Math.max(0,e-c);i.current?.scrollToIndex({index:u,align:t,behavior:`auto`}),requestAnimationFrame(()=>{i.current?.scrollToIndex({index:e,align:t,behavior:`smooth`})})})},[g,h]),b=(0,R.useCallback)(e=>{c.current=!0;let t=e instanceof WheelEvent&&e.deltaY<0;t&&g(),(t||p&&!o5(p,r))&&h(!1),l.current!==void 0&&window.clearTimeout(l.current),l.current=window.setTimeout(()=>{c.current=!1,l.current=void 0},PNe)},[r,g,p,h]),x=(0,R.useCallback)(()=>{if(!p)return;let e=LNe(p),t=u.current;if(u.current=e,o5(p,r)){c.current||h(!0);return}let n=t!==void 0&&e<t-1;(c.current||n)&&h(!1)},[r,p,h]);return(0,R.useEffect)(()=>{if(!p)return;let e=p,t=e=>{let t=e instanceof KeyboardEvent?e.key:``;[`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `].includes(t)&&b()},n=t=>{t.target===e&&b()};return e.addEventListener(`wheel`,b,{passive:!0}),e.addEventListener(`touchmove`,b,{passive:!0}),e.addEventListener(`pointerdown`,n,{passive:!0}),e.addEventListener(`keydown`,t),e.addEventListener(`scroll`,x,{passive:!0}),()=>{e.removeEventListener(`wheel`,b),e.removeEventListener(`touchmove`,b),e.removeEventListener(`pointerdown`,n),e.removeEventListener(`keydown`,t),e.removeEventListener(`scroll`,x)}},[b,p,x]),(0,R.useLayoutEffect)(()=>{u.current=void 0,h(!0),_(`auto`)},[t,_,h]),(0,R.useLayoutEffect)(()=>{o.current&&_(`auto`)},[n,e,_]),(0,R.useEffect)(()=>()=>{g(),l.current!==void 0&&window.clearTimeout(l.current)},[g]),{virtuosoRef:i,isSticky:d,stickToBottom:v,scrollToIndex:y,scrollerRef:m,atBottomStateChange:(0,R.useCallback)(e=>{if(e){c.current||h(!0);return}c.current&&h(!1)},[h]),atBottomThreshold:r,followOutput:(0,R.useCallback)(()=>o.current?`auto`:!1,[]),totalListHeightChanged:(0,R.useCallback)(()=>{o.current&&_(`auto`)},[_])}}function o5(e,t){let n=e instanceof Window?document.scrollingElement:e;return n?n.scrollHeight-n.scrollTop-n.clientHeight<=t:!0}function LNe(e){return(e instanceof Window?document.scrollingElement:e)?.scrollTop??0}var s5={"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`}},c5=12;function l5(e,t){return t===`all`||e<t}(0,R.memo)(function e({span:t,startTime:n,depth:r=0,expansionDepth:i,expansionSignal:a,expandThinking:o,onFork:s,onOpenSession:c}){let[l,u]=(0,R.useState)(()=>l5(r,i)),[d,f]=(0,R.useState)(()=>t.spanType===`model.reasoning`?o:l5(r,i));(0,R.useEffect)(()=>{let e=l5(r,i);u(e),f(t.spanType===`model.reasoning`?o:e)},[r,i,a,o,t.spanType]),s5[t.spanType]||s5[`agent.run`],t.status,t.status,t.spanType===`user.prompt`||t.spanType;let p=!!t.children?.length;return f5(t.startTime,n),t.durationUs?`${(t.durationUs/1e3).toFixed(1)}`:t.endTime&&`${((t.endTime-t.startTime)/1e3).toFixed(1)}`,(0,z.jsx)(RNe,{span:t,startTime:n,depth:r,contentExpanded:d,childrenExpanded:l,onToggle:(0,R.useCallback)(()=>{f(e=>!e),p&&u(e=>!e)},[p]),onFork:s,onOpenSession:c,childrenContent:p?t.children?.map(t=>(0,z.jsx)(e,{span:t,startTime:n,depth:r+1,expansionDepth:i,expansionSignal:a,expandThinking:o,onFork:s,onOpenSession:c},t.id)):void 0})});var RNe=(0,R.memo)(function({span:e,startTime:t,depth:n=0,contentExpanded:r,childrenExpanded:i,onToggle:a,onFork:o,onOpenSession:s,childrenContent:c}){let l=s5[e.spanType]||s5[`agent.run`],u=e.status===`UNSET`,d=KNe(e.status,u),f=e.spanType===`user.prompt`||e.spanType===`user_input`,p=!!e.children?.length,m=f5(e.startTime,t),h=e.durationUs?`${(e.durationUs/1e3).toFixed(1)}ms`:e.endTime?`${((e.endTime-e.startTime)/1e3).toFixed(1)}ms`:null;return(0,z.jsx)(`div`,{className:`relative mb-4 group`,style:{marginLeft:n>0?c5:0,width:n>0?`calc(100% - ${c5}px)`:`var(--trace-readable-width)`,maxWidth:`100%`},children:(0,z.jsxs)(`div`,{className:`min-w-0 ${f?`bg-[#11a4d4]/10`:`bg-white dark:bg-[#1a262b]`} border ${d.cardClass} rounded-sm shadow-sm transition-all hover:border-opacity-70 focus:outline-none focus:ring-1 focus:ring-[#11a4d4]/50 ${u?d.glowClass:``}`,onDoubleClick:e=>{u5(e)||a()},onKeyDown:e=>{u5(e)||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},role:`button`,tabIndex:0,"aria-expanded":r,children:[(0,z.jsx)(zNe,{span:e,config:l,statusStyles:d,isActive:u,contentExpanded:r,duration:h,relativeTime:m,onToggle:a,onFork:o,onOpenSession:s}),r?(0,z.jsx)(HNe,{span:e}):null,p&&i&&r?(0,z.jsx)(`div`,{className:`min-w-0 border-t border-slate-700 bg-slate-900/50 py-4`,children:c}):null]})})});function u5(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 zNe({span:e,config:t,statusStyles:n,isActive:r,contentExpanded:i,duration:a,relativeTime:o,onToggle:s,onFork:c,onOpenSession:l}){let u=e.spanType===`user.prompt`||e.spanType===`user_input`?`bg-[#11a4d4]/10`:n.headerClass;return(0,z.jsx)(`div`,{className:`${i?`border-b ${t.borderColor}/20`:``} ${u}`,children:(0,z.jsxs)(`div`,{className:`box-border flex w-full min-w-0 items-center`,style:{maxWidth:`100%`},children:[(0,z.jsx)(`div`,{className:`min-w-0 flex-1 px-4 py-2 text-left`,children:(0,z.jsxs)(`span`,{className:`min-w-0 text-xs font-bold ${t.color} uppercase tracking-wider flex items-center gap-2`,children:[i?(0,z.jsx)(zo,{size:12}):(0,z.jsx)(Bo,{size:12}),(0,z.jsx)(BNe,{spanType:e.spanType,config:t,isActive:r}),(0,z.jsx)(`span`,{className:`shrink-0`,children:t.label}),e.name?(0,z.jsxs)(`span`,{className:`min-w-0 truncate font-normal text-slate-500 dark:text-slate-400 normal-case`,children:[`: `,e.name]}):null,r?(0,z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}),(0,z.jsx)(UNe,{forkEntryId:e.pibo?.traceNodeType===`user.message`?e.pibo.entryId:void 0,linkedPiboSessionId:e.pibo?.linkedPiboSessionId,onFork:c,onOpenSession:l}),(0,z.jsx)(VNe,{duration:a,relativeTime:o})]})})}function BNe({spanType:e,config:t,isActive:n}){return(0,z.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,z.jsx)(GNe,{type:e,className:t.color}),n?(0,z.jsx)(`span`,{className:`absolute -right-0.5 -top-0.5 h-1.5 w-1.5 rounded-full bg-[#11a4d4] animate-pulse`}):null]})}function VNe({duration:e,relativeTime:t}){return(0,z.jsxs)(`div`,{className:`ml-2 mr-4 flex w-36 shrink-0 items-center justify-end gap-2 font-mono tabular-nums`,children:[e?(0,z.jsx)(`span`,{className:`text-[10px] text-slate-500 dark:text-slate-400`,children:e}):null,(0,z.jsx)(`span`,{className:`text-xs text-slate-400 dark:text-slate-500`,children:t})]})}var HNe=(0,R.memo)(function({span:e}){let[t,n]=(0,R.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=e.status===`ERROR`?(0,z.jsxs)(`div`,{className:`mx-4 mt-4 p-3 bg-red-500/10 border border-red-500/20 rounded-sm text-xs`,children:[(0,z.jsx)(`div`,{className:`flex items-center gap-2 font-semibold text-red-500 mb-1`,children:`Error`}),e.statusMessage?(0,z.jsx)(`div`,{className:`font-mono text-red-400 mb-2`,children:e.statusMessage}):null]}):null;if(r===`user.prompt`||r===`user_input`)return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.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)})]});if(r===`model.response`)return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsx)(`div`,{className:`model-response-markdown min-w-0 p-4 text-sm text-slate-200 leading-relaxed`,children:typeof o==`string`?(0,z.jsx)(zW,{children:o}):(0,z.jsx)(vq,{value:o})})]});if(r===`tool.result`)return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsxs)(`div`,{className:`p-4 bg-green-500/5 border-t border-green-500/20`,children:[(0,z.jsxs)(`div`,{className:`text-xs font-medium text-green-400 mb-2`,children:[`Returned from `,c||a,`:`]}),(0,z.jsx)(vq,{value:l??o})]})]});if(r===`tool.call`){let e=p5(u)?u:{},r=Object.keys(e).length>0;return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`p-4 bg-[#0e1116] border-b border-slate-800`,children:(0,z.jsx)(WNe,{name:c??a,args:e})}),l==null?null:(0,z.jsxs)(`div`,{className:`px-4 py-2 bg-[#1a262b] flex items-center gap-2`,children:[(0,z.jsx)(Eo,{size:14,className:`text-slate-400`}),(0,z.jsx)(`span`,{className:`text-xs font-mono text-slate-500`,children:`Output:`}),(0,z.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,z.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,z.jsx)(is,{size:12}):(0,z.jsx)(as,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,z.jsxs)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116]`,children:[r?(0,z.jsxs)(`div`,{className:`px-4 pt-3 pb-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-semibold text-blue-400 uppercase tracking-wider mb-1.5`,children:`Input`}),(0,z.jsx)(vq,{value:e})]}):null,l==null?null:(0,z.jsxs)(`div`,{className:`px-4 pt-2 pb-3 border-t border-slate-700/30`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-semibold text-green-400 uppercase tracking-wider mb-1.5`,children:`Output`}),(0,z.jsx)(vq,{value:l})]})]}):null,d]})}if(r===`yielded.run`){let e=p5(l)?l:p5(o)?o:{};return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsxs)(`div`,{className:`p-4 border-b border-[#11a4d4]/20 bg-[#11a4d4]/5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,z.jsx)(Oo,{size:14,className:`text-[#11a4d4]`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-[#11a4d4]`,children:`Run notification`}),(0,z.jsx)(`span`,{className:`text-xs font-mono text-slate-400`,children:typeof i.content==`string`?i.content:a})]}),(0,z.jsx)(qNe,{notification:e})]}),(0,z.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,z.jsx)(is,{size:12}):(0,z.jsx)(as,{size:12}),t?`Hide Details`:`Show Details`]}),t?(0,z.jsx)(`div`,{className:`border-t border-slate-700/40 bg-[#0e1116] px-4 py-3`,children:(0,z.jsx)(vq,{value:e})}):null]})}if(r===`model.reasoning`){let e=i.reasoning||i[`model.reasoning`]||o;return(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.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,z.jsx)(`span`,{className:`text-amber-500 opacity-60`,children:`// Model reasoning`}),(0,z.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,z.jsxs)(z.Fragment,{children:[d,(0,z.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,z.jsx)(fs,{size:14,className:`text-orange-500`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Delegated to:`}),(0,z.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),n?(0,z.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,z.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,m5(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,z.jsxs)(z.Fragment,{children:[d,(0,z.jsxs)(`div`,{className:`p-4 border-b border-orange-500/20 bg-orange-500/5`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:[(0,z.jsx)(fs,{size:14,className:`text-orange-500`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-orange-500`,children:`Async agent started:`}),(0,z.jsxs)(`span`,{className:`text-sm font-semibold text-slate-200`,children:[e||`unknown`,` agent`]}),a?(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-x-3 gap-y-1 font-mono text-[11px] text-slate-500`,children:[(0,z.jsxs)(`span`,{children:[`Started by `,n||`pibo_run_start`]}),r?(0,z.jsx)(`span`,{children:r}):null]}),t?(0,z.jsxs)(`div`,{className:`text-xs text-slate-400 font-mono italic line-clamp-2`,children:[`"`,m5(t),`"`]}):null]})]})}return r===`agent.run`?(0,z.jsx)(`div`,{className:`flex flex-col`,children:d}):(0,z.jsxs)(`div`,{className:`flex flex-col`,children:[d,(0,z.jsx)(`div`,{className:`p-4 font-mono text-sm text-slate-300`,children:(0,z.jsx)(vq,{value:i})})]})});function UNe({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,z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[i?(0,z.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,z.jsx)(fs,{size:14})}):null,a?(0,z.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,z.jsx)(rs,{size:14})}):null]})}function WNe({name:e,args:t}){return(0,z.jsxs)(`code`,{className:`font-mono text-xs text-green-400`,children:[(0,z.jsx)(`span`,{className:`text-purple-400`,children:`def`}),` `,(0,z.jsx)(`span`,{className:`text-yellow-300`,children:e}),(0,z.jsxs)(`span`,{children:[`(`,Object.entries(t).map(([e,t],n)=>(0,z.jsxs)(`span`,{children:[n>0?`, `:null,(0,z.jsx)(`span`,{className:`text-blue-400`,children:e}),`=`,(0,z.jsx)(`span`,{className:`text-green-300`,children:typeof t==`string`?`'${t.slice(0,50)}${t.length>50?`...`:``}'`:m5(t).slice(0,50)})]},e)),`)`]})]})}function GNe({type:e,className:t}){let n={size:14,className:t};switch(e){case`agent.run`:return(0,z.jsx)(Po,{...n});case`tool.call`:return(0,z.jsx)(ko,{...n});case`tool.result`:return(0,z.jsx)(Eo,{...n});case`model.request`:return(0,z.jsx)(Mo,{...n});case`model.response`:return(0,z.jsx)(Eo,{...n});case`model.reasoning`:return(0,z.jsx)(ys,{...n});case`agent.delegation`:return(0,z.jsx)(fs,{...n});case`agent.async`:return(0,z.jsx)(fs,{...n});case`yielded.run`:return(0,z.jsx)(Oo,{...n});case`user.prompt`:return(0,z.jsx)(Os,{...n});case`user_input`:return(0,z.jsx)(Xs,{...n});case`execution.command`:return(0,z.jsx)(ko,{...n});default:return(0,z.jsx)(Ro,{...n})}}function KNe(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 qNe({notification:e}){let t=[[`completed`,`text-green-500`,e.completed],[`failed`,`text-red-400`,e.failed],[`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(p5):[]})).filter(e=>e.runs.length>0);return t.length===0?(0,z.jsx)(`div`,{className:`text-xs text-slate-400`,children:`No yielded run updates.`}):(0,z.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider ${e.color}`,children:e.name}),(0,z.jsx)(`div`,{className:`grid gap-1`,children:e.runs.map((t,n)=>(0,z.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,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate font-mono text-xs text-slate-200`,children:d5(t.toolName)||`yielded tool`}),(0,z.jsx)(`div`,{className:`truncate font-mono text-[10px] text-slate-500`,children:d5(t.runId)})]}),(0,z.jsx)(`div`,{className:`font-mono text-[10px] uppercase text-slate-400`,children:d5(t.status)||e.name})]},`${e.name}-${n}`))})]},e.name))})}function d5(e){return typeof e==`string`?e:``}function f5(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 p5(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function m5(e){if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}function h5(e){if(e==null)return{kind:`empty`};let t=g5(e);return t===void 0?{kind:`json`,value:e}:{kind:`text`,text:t}}function g5(e){if(typeof e==`string`)return e;if(Array.isArray(e)){let t=e.map(g5).filter(e=>e!==void 0);return t.length===e.length&&t.length>0?t.join(``):void 0}if(!_5(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=g5(e.content);if(n!==void 0&&JNe(e))return n;let r=_5(e.message)?g5(e.message.content):void 0;if(r!==void 0)return r}function JNe(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 _5(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function YNe({row:e,onOpenSession:t}){return(0,z.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,z.jsx)(`div`,{className:`space-y-3`,children:e.detailItems.map(e=>(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e.label}),e.linkedPiboSessionId?(0,z.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,z.jsx)(v5,{label:`Input`,value:e.input}),(0,z.jsx)(v5,{label:`Output`,value:e.output}),(0,z.jsx)(y5,{value:e.output}),e.error?(0,z.jsx)(x5,{label:`Error`,value:e.error,tone:`red`}):null]},e.id))}):(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(v5,{label:`Input`,value:e.input}),(0,z.jsx)(v5,{label:`Output`,value:e.output}),(0,z.jsx)(y5,{value:e.output}),e.error?(0,z.jsx)(x5,{label:`Error`,value:e.error,tone:`red`}):null,e.linkedPiboSessionId?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Child session`}),(0,z.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 v5({label:e,value:t}){let n=h5(t);if(n.kind===`empty`)return null;if(n.kind===`text`){let t=S5(n.text);return t?.kind===`json`?(0,z.jsx)(b5,{label:e,value:t.value,meta:t.meta}):t?.kind===`text`?(0,z.jsx)(x5,{label:e,value:t.text}):(0,z.jsx)(x5,{label:e,value:n.text})}return(0,z.jsx)(b5,{label:e,value:n.value})}function y5({value:e}){let t=XNe(e);return t?(0,z.jsxs)(`details`,{className:`space-y-1 border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:[(0,z.jsxs)(`summary`,{className:`cursor-pointer text-[11px] font-semibold text-[#38bdf8]`,children:[`Show full output (`,t.originalLines,` lines)`]}),t.fullOutput?(0,z.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,z.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 XNe(e){if(!T5(e))return;let t=T5(e.details)?e.details.piboBashOutputCompaction:void 0;if(!T5(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 b5({label:e,value:t,meta:n}){return(0,z.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-json":e,children:[(0,z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),n?(0,z.jsxs)(`div`,{className:`min-w-0 break-words text-[11px] text-[#737373]`,children:[`Status: `,n]}):null]}),(0,z.jsx)(`div`,{className:`compact-terminal-json border border-[#2a2a2a] bg-[#0b0b0b] p-2`,children:(0,z.jsx)(vq,{value:t,showControls:!1})})]})}function x5({label:e,value:t,tone:n=`default`}){return(0,z.jsxs)(`div`,{className:`space-y-1`,"data-shared-terminal-detail-text":e,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-semibold text-[#737373]`,"data-shared-terminal-detail-label":e,children:e}),(0,z.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 S5(e){let t=e.trim();if(!t)return;let n=w5(t);if(n!==void 0)return C5(n);let r=t.split(/\r?\n/);for(let e=1;e<r.length;e+=1){let t=r.slice(e).join(`
|
|
166
|
+
`).trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))continue;let n=w5(t);if(n!==void 0)return C5(n,r.slice(0,e).join(` `).trim()||void 0)}}function C5(e,t){let n=h5(e);if(n.kind===`text`){let e=S5(n.text);return e?.kind===`json`?{...e,meta:e.meta??t}:{kind:`text`,text:n.text}}return{kind:`json`,value:e,meta:t}}function w5(e){if(!(!e.startsWith(`{`)&&!e.startsWith(`[`)))try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}function T5(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ZNe({name:e,input:t}){return(0,z.jsxs)(`span`,{className:`compact-terminal-function-call`,children:[(0,z.jsx)(`span`,{className:`text-[#facc15] font-semibold`,children:e}),(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`(`}),t===void 0?null:(0,z.jsx)(QNe,{value:t}),(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:`)`})]})}function QNe({value:e}){let[t,n]=(0,R.useState)(()=>new Set([`$`])),[r,i]=(0,R.useState)(()=>new Set);return(0,z.jsx)(E5,{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 E5({value:e,path:t,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a}){if(Array.isArray(e))return(0,z.jsx)(D5,{value:e,path:t,open:`[`,close:`]`,expandedPaths:n,expandedStrings:r,onTogglePath:i,onToggleString:a});if(ePe(e))return(0,z.jsx)(D5,{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,z.jsx)(`span`,{className:`text-[#fb923c]`,children:JSON.stringify(o)});return!i&&e.length<=140?s:(0,z.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`,children:s})}return typeof e==`number`||typeof e==`boolean`||e===null?(0,z.jsx)(`span`,{className:`text-[#60a5fa]`,children:String(e)}):(0,z.jsx)(`span`,{className:`text-[#737373]`,children:JSON.stringify(String(e))})}function D5({value:e,path:t,open:n,close:r,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s}){let c=Array.isArray(e)?e.map((e,t)=>[String(t),e]):Object.entries(e);return i.has(t)?(0,z.jsxs)(`span`,{children:[(0,z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Collapse JSON`,"aria-label":`Collapse JSON at ${t}`,"data-inline-json-path":t,children:[(0,z.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▾`}),n]}),c.map(([n,r],c)=>{let l=`${t}.${$Ne(n)}`;return(0,z.jsxs)(`span`,{children:[c>0?(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`, `}):null,Array.isArray(e)?null:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:JSON.stringify(n)}),(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`:`})]}),(0,z.jsx)(E5,{value:r,path:l,expandedPaths:i,expandedStrings:a,onTogglePath:o,onToggleString:s})]},l)}),(0,z.jsx)(`span`,{className:`text-[#737373]`,children:r})]}):(0,z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t)},className:`compact-terminal-json-toggle align-baseline text-[#737373]`,title:`Expand JSON`,"aria-label":`Expand JSON at ${t}`,"data-inline-json-path":t,children:[(0,z.jsx)(`span`,{className:`compact-terminal-json-caret`,children:`▸`}),n,`...`,r]})}function $Ne(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`.`,`\\.`)}function ePe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function tPe({line:e,status:t,clampLines:n}){let r=`min-w-0 whitespace-pre-wrap break-words ${n?`block overflow-hidden`:``}`;return(0,z.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 leading-[1.45]`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre ${rPe(e.prefix,t)}`,children:nPe(e.prefix)}),(0,z.jsxs)(`span`,{className:r,style:n?{maxHeight:`${n*1.45}em`}:void 0,children:[e.tokens.map((e,t)=>(0,z.jsx)(`span`,{className:iPe(e),children:e.text},`${t}:${e.text}`)),e.functionCall?(0,z.jsx)(ZNe,{name:e.functionCall.name,input:e.functionCall.input}):null]})]})}function nPe(e=`none`){switch(e){case`bullet`:return`•`;case`detail`:return`└`;case`continuation`:return` `;case`prompt`:return`›`;default:return` `}}function rPe(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 iPe(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()}async function aPe(){await fetch(`/api/auth/sign-out`,{method:`POST`,credentials:`same-origin`,headers:{"content-type":`application/json`},body:`{}`})}async function oPe(){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}function sPe(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 cPe(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 O5(e){return lPe(e)?e.result:e}function lPe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}var uPe={device_code:`Device code`,api_key:`API key`,oauth:`Browser OAuth`};function dPe({row:e,piboSessionId:t}){let n=sPe(e.output)?e.output:void 0,r=(0,R.useMemo)(()=>n?.providers??[],[n?.providers]),[i,a]=(0,R.useState)({type:`select_provider`}),[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(``),[u,d]=(0,R.useState)(``),[f,p]=(0,R.useState)(null),m=(0,R.useCallback)(()=>{a({type:`select_provider`}),l(``),d(``)},[]),h=(0,R.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),p(e),window.setTimeout(()=>p(t=>t===e?null:t),1600)}catch{}},[]),g=(0,R.useCallback)(async e=>{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 n=O5(await yc(t,`login.start`,{provider:e.id}));if(!n?.url){a({type:`error`,provider:e,message:`No login URL returned.`});return}a({type:`device_flow`,provider:e,url:n.url,state:n.state,userCode:n.userCode,instructions:n.instructions})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}},[t]),_=(0,R.useCallback)(async(e,n,r)=>{if(t){s(!0);try{await yc(t,`login.complete`,{provider:e.id,state:n??``,...r?{code:r}:{}}),a({type:`success`,provider:e,message:`${e.name} login completed.`})}catch(t){a({type:`error`,provider:e,message:t instanceof Error?t.message:String(t)})}finally{s(!1)}}},[t]),v=(0,R.useCallback)(async e=>{if(!t)return;let n=c.trim();if(n){s(!0);try{await yc(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,z.jsx)(k5,{title:i.type===`select_provider`?`Login`:pPe(i),tone:i.type===`error`?`red`:i.type===`success`?`green`:`cyan`,action:i.type===`select_provider`?void 0:(0,z.jsx)(fPe,{onClick:m,disabled:o}),children:i.type===`select_provider`?(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a provider. Use `,(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` anytime.`]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,z.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,z.jsx)(`span`,{children:e.name}),e.configured?(0,z.jsx)(`span`,{className:`text-[#22c55e]`,children:`●`}):null]},e.id))})]}):i.type===`select_method`?(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Provider:`}),(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i.provider.name}),i.provider.configured?(0,z.jsx)(A5,{tone:`green`,children:`Configured`}):(0,z.jsx)(A5,{tone:`neutral`,children:`Not configured`})]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:i.provider.authMethods.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>e===`api_key`?a({type:`api_key`,provider:i.provider}):void g(i.provider),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,z.jsx)(gs,{size:11}):(0,z.jsx)(Ts,{size:11}),uPe[e]]},e))})]}):i.type===`device_starting`?(0,z.jsxs)(`div`,{className:`inline-flex items-center gap-2 text-[11px] text-[#38bdf8]`,children:[(0,z.jsx)(Cs,{size:13,className:`animate-spin`}),` Starting device login...`]}):i.type===`device_flow`?(0,z.jsxs)(`div`,{className:`grid gap-2 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Open:`}),(0,z.jsxs)(`a`,{href:i.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-[#38bdf8] hover:underline`,children:[mPe(i.url),` `,(0,z.jsx)(rs,{size:11})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void h(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,z.jsx)(qo,{size:10}):(0,z.jsx)($o,{size:10}),` `,f===i.url?`Copied`:`Copy`]})]}),i.userCode?(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Code:`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void h(i.userCode),className:`border border-[#1f4960] px-2 py-0.5 font-semibold tracking-widest text-[#38bdf8] hover:border-[#38bdf8]`,children:i.userCode}),(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`then`}),(0,z.jsxs)(`button`,{type:`button`,disabled:o,onClick:()=>void _(i.provider,i.state),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,z.jsx)(Cs,{size:11,className:`animate-spin`}):(0,z.jsx)(qo,{size:11}),` Complete`]})]}):(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,z.jsx)(`input`,{value:u,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,z.jsxs)(`button`,{type:`button`,disabled:o||!u.trim(),onClick:()=>void _(i.provider,i.state,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,z.jsx)(Cs,{size:11,className:`animate-spin`}):(0,z.jsx)(qo,{size:11}),` Complete`]})]}),i.instructions?(0,z.jsx)(`div`,{className:`text-[#737373]`,children:i.instructions}):null]}):i.type===`api_key`?(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`API key:`}),(0,z.jsx)(`input`,{type:`password`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(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,z.jsxs)(`button`,{type:`button`,disabled:o||!c.trim(),onClick:()=>void v(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,z.jsx)(Cs,{size:11,className:`animate-spin`}):(0,z.jsx)(qo,{size:11}),` Save`]})]}):i.type===`success`?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-[#22c55e]`,children:[(0,z.jsx)(qo,{size:13}),` `,i.message]}):(0,z.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-[#ef4444]`,children:[(0,z.jsx)(Go,{size:13,className:`mt-0.5 shrink-0`}),` `,(0,z.jsx)(`span`,{children:i.message})]})}):(0,z.jsx)(k5,{title:`Login`,tone:`red`,children:`Unparseable login payload.`})}function k5({title:e,tone:t,action:n,children:r}){return(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(Ts,{size:14,className:t===`red`?`text-[#ef4444]`:t===`green`?`text-[#22c55e]`:`text-[#38bdf8]`}),(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:e}),n?(0,z.jsx)(`div`,{className:`ml-auto`,children:n}):null]}),r]})}function fPe({onClick:e,disabled:t}){return(0,z.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,z.jsx)(Do,{size:10}),` Back`]})}function A5({tone:e,children:t}){return(0,z.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 pPe(e){return`provider`in e&&e.provider?e.provider.name:`Login`}function mPe(e){try{let t=new URL(e);return`${t.host}${t.pathname}`}catch{return e.length>42?`${e.slice(0,39)}...`:e}}function hPe({row:e,piboSessionId:t,onModelChanged:n}){let r=O5(e.output),i=(cPe(r)?r:void 0)?.providers??[],a=(0,R.useMemo)(()=>i.flatMap(e=>e.models.map(t=>({...t,providerLabel:e.label}))),[i]),[o,s]=(0,R.useState)(``),[c,l]=(0,R.useState)(null),[u,d]=(0,R.useState)(!1),[f,p]=(0,R.useState)(null),m=(0,R.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)){d(!0),l(e),p(null);try{await gc(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,z.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,z.jsx)(`div`,{className:`flex items-center justify-between gap-3 border-b border-[#2a2a2a] px-3 py-2`,children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[#d4d4d4]`,children:`Model`}),(0,z.jsxs)(`div`,{className:`text-[11px] text-[#737373]`,children:[`Choose a model from authenticated providers. Use `,(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` to add providers.`]})]})}),(0,z.jsxs)(`div`,{className:`space-y-2 p-3`,children:[i.length?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 border border-[#2a2a2a] bg-[#0b0b0b] px-2 py-1 text-[#737373]`,children:[(0,z.jsx)(Vs,{size:13}),(0,z.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,z.jsx)(`div`,{className:`max-h-72 overflow-auto border border-[#2a2a2a]`,children:m.length?m.map(e=>(0,z.jsxs)(`button`,{type:`button`,disabled:u,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:opacity-50`,children:[(0,z.jsx)(`span`,{className:`truncate text-[#737373]`,children:e.providerLabel}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-[#d4d4d4]`,children:e.label}),(0,z.jsxs)(`span`,{className:`block truncate text-[11px] text-[#737373]`,children:[e.provider,`/`,e.id]})]}),c?.provider===e.provider&&c?.id===e.id?(0,z.jsx)(Ro,{size:14,className:`text-[#22c55e]`}):null]},`${e.provider}:${e.id}`)):(0,z.jsx)(`div`,{className:`px-3 py-2 text-[#737373]`,children:`No matching models.`})})]}):(0,z.jsxs)(`div`,{className:`text-[#737373]`,children:[`No authenticated model providers found. Run `,(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:`/login`}),` first.`]}),f?(0,z.jsx)(`div`,{className:`text-[11px] text-[#a3a3a3]`,children:f}):null]})]})}function gPe(e={}){let t=[],n=[],r=N5(e.warnings),i=N5(e.errors);(e.session?.id||e.session?.title)&&t.push({id:`session`,label:`Session`,value:j5([e.session?.title,e.session?.id].filter(Boolean).join(` | `))}),e.session?.profile&&t.push({id:`profile`,label:`Profile`,value:j5(e.session.profile)}),e.session?.status&&t.push({id:`session-status`,label:`Session status`,value:j5(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:j5(e.model.label??[e.model.provider,e.model.id].filter(Boolean).join(`/`))}),e.runtime?.state&&t.push({id:`runtime`,label:`Runtime`,value:j5(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:j5(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:j5(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`?j5(e.fastMode):e.fastMode?`on`:`off`,tone:e.fastMode?`green`:`neutral`});let o=N5(e.tools?.enabled),s=N5(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:j5(e.providerUsage.planType)}),e.providerUsage?.credits&&t.push({id:`provider-credits`,label:`Credits`,value:e.providerUsage.credits.unlimited?`unlimited`:j5(e.providerUsage.credits.balance??`available`)}),e.message&&t.push({id:`message`,label:`Message`,value:j5(e.message)}),n.push(_Pe(e.contextUsage));for(let t of vPe(e.providerUsage))n.push(t);return{kind:`status`,title:`Status`,fields:t,progress:n,warnings:r,errors:i}}function j5(e){return e.replace(/\b([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD)[A-Z0-9_]*)\s*=\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(api[_-]?key|token|secret|password)\s*[:=]\s*([^\s]+)/gi,`$1=[redacted]`).replace(/\b(?:sk|pk|pibo|ghp|github_pat)_[A-Za-z0-9_\-]{8,}\b/g,`[redacted]`)}function _Pe(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=M5(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:yPe(t)}}function vPe(e){return e?.limits?.length?e.limits.map((t,n)=>{let r=M5(t.usedPercent),i=M5(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 ${j5(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:bPe(i)}}):[{id:`provider`,label:`Provider quota`,state:`unavailable`,text:`Provider usage unavailable`,tone:`neutral`}]}function M5(e){if(!(typeof e!=`number`||!Number.isFinite(e)))return Math.max(0,Math.min(100,e))}function yPe(e){return e===void 0?`neutral`:e>=80?`red`:e>=50?`yellow`:`green`}function bPe(e){return e===void 0?`neutral`:e<=20?`red`:e<=50?`yellow`:`green`}function N5(e){return(e??[]).map(e=>j5(e)).filter(e=>e.length>0)}function xPe(e){switch(e.kind){case`tool.status`:return SPe(e);case`tool.thinking`:return CPe(e);case`tool.model`:return wPe(e);case`tool.login`:return TPe(e);case`tool.call`:case`tool.image`:case`tool.group.exploring`:case`tool.group.images`:return EPe(e);case`yielded.run`:return P5(e,`yielded-run`,`Yielded run`,e.status===`error`?`red`:e.status===`running`?`cyan`:`green`);case`execution.compaction`:return P5(e,`compaction`,e.status===`error`?`Compaction failed`:e.status===`running`?`Compacting`:`Compaction`,e.status===`error`?`red`:`magenta`);case`execution.command`:return P5(e,`command`,`Command`,e.status===`error`?`red`:`yellow`);case`error`:return P5(e,`error`,`Error`,`red`);default:return}}function SPe(e){let t=F5(e.output),n=I5(t,`activeModel`)??I5(t,`model`),r=gPe({session:{id:z5(t,`piboSessionId`)??z5(t,`sessionId`),title:z5(t,`sessionTitle`)??z5(t,`title`),profile:z5(t,`profile`)??z5(t,`activeAgentId`)??z5(t,`agentId`),status:B5(t,`disposed`)?`disposed`:z5(t,`sessionStatus`)},model:n?{provider:z5(n,`provider`),id:z5(n,`id`),label:z5(n,`label`)}:void 0,runtime:{state:B5(t,`disposed`)?`disposed`:B5(t,`processing`)?`processing`:B5(t,`streaming`)?`streaming`:z5(t,`mode`)??`idle`,connected:B5(t,`connected`),queuedMessages:OPe(t,`queuedMessages`),processing:B5(t,`processing`),streaming:B5(t,`streaming`),disposed:B5(t,`disposed`)},cwd:z5(t,`cwd`),contextUsage:I5(t,`contextUsage`),providerUsage:I5(t,`providerUsage`),tools:{enabled:R5(t,`enabledTools`),active:R5(t,`activeTools`)},thinking:z5(t,`thinkingLevel`)?{level:z5(t,`thinkingLevel`)}:void 0,fastMode:B5(t,`fastMode`),warnings:R5(t,`warnings`),errors:R5(t,`errors`),message:z5(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 CPe(e){let t=F5(e.output),n=z5(t,`level`)??`unknown`,r=t?.supported!==!1,i=R5(t,`availableLevels`);return{id:e.id,kind:`thinking`,title:`Thinking`,status:e.status,tone:r?`yellow`:`red`,rows:[{label:`Current`,value:j5(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 wPe(e){let t=L5(F5(e.output),`providers`),n=t.flatMap(e=>{let t=z5(e,`id`)??z5(e,`provider`)??`provider`,n=z5(e,`label`)??z5(e,`name`)??t;return L5(e,`models`).map(e=>{let r=z5(e,`id`)??`model`,i=z5(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 TPe(e){let t=L5(F5(e.output),`providers`),n=t.map(e=>{let t=z5(e,`id`)??`provider`;return{id:`login:${t}`,label:z5(e,`name`)??z5(e,`label`)??t,action:`login.selectProvider`,value:t,description:R5(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 EPe(e){return P5(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 P5(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?``:` ${DPe(e.functionCall.input)}`}`:``}`.trim();return t?[{value:j5(t)}]:[]}),a=e.lines.length===0&&typeof e.output==`string`&&e.output.trim()?[{value:j5(e.output.trim())}]:[],o=[e.error?{label:`Error`,value:j5(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 DPe(e){try{return JSON.stringify(e)}catch{return String(e)}}function F5(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 I5(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function L5(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&!Array.isArray(e)):[]}function R5(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function z5(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function OPe(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function B5(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function kPe(e,t){return e?rFe(eFe(V5(e.nodes).sort((e,t)=>t4(e.node,t.node)).filter(e=>e.node.type!==`agent.turn`&&(t.showThinking||e.node.type!==`model.reasoning`)).map(e=>APe(e.node,e.turnId)))).map(e=>e.row):[]}function V5(e,t){let n=[];for(let r of e)r.type!==`agent.turn`&&n.push({node:r,turnId:t}),n.push(...V5(r.children,r.type===`agent.turn`?r.id:t));return n}function APe(e,t){let n;switch(e.type){case`user.message`:n={row:MPe(e),turnId:t};break;case`assistant.message`:n={row:NPe(e),turnId:t};break;case`model.reasoning`:n={row:PPe(e),turnId:t};break;case`tool.call`:n=FPe(e,t);break;case`tool.result`:n=IPe(e,t);break;case`agent.delegation`:n={row:RPe(e),turnId:t};break;case`agent.async`:n={row:zPe(e),turnId:t};break;case`yielded.run`:n={row:BPe(e),turnId:t};break;case`execution.command`:n={row:HPe(e),turnId:t};break;case`execution.compaction`:n={row:VPe(e),turnId:t};break;case`error`:n={row:QPe(e),turnId:t};break;case`agent.turn`:n={row:{id:e.id,kind:`error`,status:`neutral`,lines:[],sourceNodeIds:[e.id]},turnId:t};break}return{...n,row:{...n.row,...jPe(e)}}}function jPe(e){return{eventId:e.eventId,runId:e.runId,orderSource:e.source,orderStreamId:e.orderKey?.streamId,orderStreamFrameIndex:e.orderKey?.streamFrameIndex}}function MPe(e){let t=o7(e.output)||o7(e.summary)||e.title;return{id:e.id,kind:`message.user`,status:r7(e.status),lines:[{prefix:`prompt`,tokens:[a7(t)]}],sourceNodeIds:[e.id],forkEntryId:e.entryId,output:t}}function NPe(e){return{id:e.id,kind:`message.assistant`,status:r7(e.status),lines:[],sourceNodeIds:[e.id],output:o7(e.output)||o7(e.summary)||``,error:e.error}}function PPe(e){let t=e7(e.output??e.summary);return{id:e.id,kind:`reasoning`,status:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(e.status===`running`?`Thinking`:`Thought`,`amber`,`semibold`)]}],sourceNodeIds:[e.id],markdown:t}}function FPe(e,t){let n=n7(e.input);if(n&&fFe(e.title))return{row:ZPe(e,n),turnId:t,exploring:void 0};let r=G5(e);if(r)return{row:H5(e,r),turnId:t,image:r.groupable?r.detail:void 0};let i=Q5(e.error??e.output,5,e.error?`red`:`dim`);return{row:{id:e.id,kind:`tool.call`,status:r7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[a7(mFe(e.status),i7(e.status),`semibold`),a7(` `)],functionCall:{name: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:$5(i,e.error?`error`:`output`)},turnId:t,exploring:dFe(e)}}function H5(e,t){let n=r7(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:[a7(t.verb,i7(e.status),`semibold`)]},{prefix:`detail`,tokens:[a7(r,e.status===`error`?`red`:`cyan`)]}],sourceNodeIds:[e.id],input:q5(e.input),output:t.summary,error:e.error,expandable:e.input!==void 0||t.summary!==void 0||!!e.error}}function IPe(e,t){let n=G5(e);return n?{row:H5(e,n),turnId:t,image:n.groupable?n.detail:void 0}:{row:LPe(e),turnId:t}}function LPe(e){let t=Q5(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`tool.call`,status:r7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[a7(e.status===`error`?`Tool failed`:`Returned`,i7(e.status),`semibold`),a7(` ${e.title}`)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:$5(t,e.error?`error`:`output`)}}function RPe(e){let t=o7(s7(e.input)?e.input.subagentName:void 0)||e.summary||e.title,n=t7((s7(e.input)?e.input.arguments:void 0)??e.input),r=n?[{prefix:`detail`,tokens:[a7(n,`dim`)]}]:[];return{id:e.id,kind:`agent.delegation`,status:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(hFe(e.status),i7(e.status),`semibold`),a7(` ${t}`,`cyan`)]},...r],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}}function zPe(e){let t=Q5(e.error??e.output,5,e.error?`red`:`dim`);return{id:e.id,kind:`agent.async`,status:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(gFe(e.status),i7(e.status),`semibold`),a7(` ${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:$5(t,e.error?`error`:`output`)}}function BPe(e){let t=Q5(e.output,5);return{id:e.id,kind:`yielded.run`,status:r7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[a7(e.status===`running`?`Waiting on runs`:`Run update`,i7(e.status),`semibold`),a7(e.summary?` ${e.summary}`:``)]},...t.lines],sourceNodeIds:[e.id],output:e.output,error:e.error,expandable:e.output!==void 0||!!e.error,previewOmission:$5(t,`output`)}}function VPe(e){let t=e.status===`running`?`Compacting`:e.status===`error`?`Compaction failed`:o7(e.summary)||`Compacted`;return{id:e.id,kind:`execution.compaction`,status:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(t,i7(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 HPe(e){if(e.title===`status`)return UPe(e);if(e.title===`thinking`)return nFe(e.output)?GPe(e):WPe(e);if(e.title===`fast_mode`)return KPe(e);if(e.title===`login`&&YPe(e.output))return qPe(e);if(e.title===`model`&&XPe(e.output))return JPe(e);n7(e.output)??n7(e.input)??e.title;let t=Q5(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(`Command`,`yellow`,`semibold`),a7(` /${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:$5(t,e.error?`error`:`output`)}}function UPe(e){return{id:e.id,kind:`tool.status`,status:r7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function WPe(e){return{id:e.id,kind:`tool.thinking`,status:r7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function GPe(e){let t=s7(e.output)?e.output:void 0,n=o7(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:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function KPe(e){let t=s7(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:r7(e.status),lines:[{prefix:`bullet`,tokens:[a7(a,i?`green`:`dim`,`semibold`)]}],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function qPe(e){return{id:e.id,kind:`tool.login`,status:r7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function JPe(e){return{id:e.id,kind:`tool.model`,status:r7(e.status),lines:[],sourceNodeIds:[e.id],input:e.input,output:e.output,error:e.error,expandable:!1}}function YPe(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 XPe(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 ZPe(e,t){let n=Q5(e.error??e.output,5,e.error?`red`:`dim`,180);return{id:e.id,kind:`execution.command`,status:r7(e.status),errorKind:e.status===`error`?`tool`:void 0,lines:[{prefix:`bullet`,tokens:[a7(e.status===`running`?`Running`:`Ran`,i7(e.status),`semibold`),a7(` `),...pFe(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:$5(n,e.error?`error`:`output`)}}function QPe(e){return{id:e.id,kind:`error`,status:`error`,errorKind:`system`,lines:[{prefix:`bullet`,tokens:[a7(e.title||`Error`,`red`,`bold`),a7(e.error?` ${e.error}`:``,`red`)]},...$Pe(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 $Pe(e){return s7(e)?[[`Class`,o7(e.errorClass)??o7(e.category)],[`Code`,o7(e.code)??o7(e.providerCode)],[`Origin`,o7(e.origin)],[`Provider`,[o7(e.api),o7(e.provider),o7(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:[a7(`${e}: `,`dim`),a7(t,`red`)]})):[]}function eFe(e){let t=e.map(e=>e.row.output).filter(tFe).at(-1);return t?e.map(e=>e.row.kind!==`tool.thinking`||!s7(e.row.output)?e:{...e,row:{...e.row,output:{...e.row.output,level:t.level,availableLevels:t.availableLevels,supported:t.supported}}}):[...e]}function tFe(e){return s7(e)&&typeof e.level==`string`&&Array.isArray(e.availableLevels)}function nFe(e){return s7(e)&&e.action===`set_thinking_level`}function rFe(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n],i=U5(r);if(!i){t.push(r);continue}let a=[r],o=n+1;for(;o<e.length&&U5(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`?aFe(a):iFe(a),turnId:r.turnId}),n=o-1}return t}function U5(e){if(e.image)return`images`;if(e.exploring)return`exploring`}function iFe(e){let t=W5(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:[a7(s===`running`?`Exploring`:s===`error`?`Exploring failed`:`Explored`,i7(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[a7(e.label,e.status===`error`?`red`:`dim`)]})),...r>0?[{prefix:`continuation`,tokens:[a7(`+${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 aFe(e){let t=W5(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:[a7(s===`running`?`Viewing images`:s===`error`?`Image reads failed`:`Viewed images`,i7(s),`semibold`)]},...n.map((e,t)=>({prefix:t===0?`detail`:`continuation`,tokens:[a7(e.label,e.status===`error`?`red`:`cyan`)]})),...r>0?[{prefix:`continuation`,tokens:[a7(`+${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),previewOmission:r>0?{source:`details`,visibleLineCount:n.length,omittedLineCount:r,totalLineCount:t.length,maxVisibleLineCount:6}:void 0}}function W5(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,linkedPiboSessionId:e.row.linkedPiboSessionId,previewOmission:e.row.previewOmission}})}function G5(e){let t=(e.title??``).trim().toLowerCase(),n=s7(e.input)?e.input:void 0,r=s7(e.output)?e.output:void 0,i=uFe(r,`details`),a=t===`codex_image_generation`?sFe(i)??cFe(n):void 0,o=a?o7(i?.savedPath)??Y5(i):Y5(n)??Y5(i)??Y5(r),s=a?o7(i?.artifactId):void 0,c=X5(n),l=K5(e.output),u=J5(t,[`view_image`,`image`,`screenshot`]);if(!l.length&&!u&&!a)return;let d=l.map(e=>e.mimeType).find(e=>!!e),f=Math.max(1,l.length),p={type:l.length>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?o7(i?.model):void 0,referencedImageCount:a?Z5(i?.referencedImageCount):void 0,query:c,mimeType:d,count:f>1?f:void 0,detail:l.length?`Image data hidden in terminal view.`:`Image path only; binary data is hidden in terminal view.`},m=o??s??c??d??`image`,h=a?lFe(e.status,a):oFe(e.status,f);return{count:f,path:o,artifactId:s,query:c,mimeType:d,verb:h,groupable:!a,summary:p,detail:{id:e.id,label:`${h} ${m}`,status:r7(e.status),input:q5(e.input),output:p,error:e.error}}}function K5(e,t=0,n=new Set){if(t>5||typeof e!=`object`||!e||n.has(e))return[];if(n.add(e),Array.isArray(e))return e.flatMap(e=>K5(e,t+1,n));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`||s7(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=[];return`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),s.flatMap(e=>K5(e,t+1,n))}function q5(e){if(Array.isArray(e))return e.map(q5);if(!s7(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]=q5(r)}return t}function oFe(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 sFe(e){let t=o7(e?.operation);return t===`generate`||t===`edit`?t:void 0}function cFe(e){if(!e)return;let t=e.referenced_image_paths;return Array.isArray(t)&&t.length>0||Z5(e.num_last_images_to_include)!==void 0?`edit`:`generate`}function lFe(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 uFe(e,t){let n=e?.[t];return s7(n)?n:void 0}function dFe(e){let t=(e.title??``).trim().toLowerCase(),n=s7(e.input)?e.input:void 0;if(J5(t,[`read`,`open`]))return{id:e.id,label:`Read ${Y5(n)??t7(e.input)}`,status:r7(e.status),input:e.input,output:e.output,error:e.error};if(J5(t,[`list`,`ls`,`glob`]))return{id:e.id,label:`List ${Y5(n)??t7(e.input)}`,status:r7(e.status),input:e.input,output:e.output,error:e.error};if(J5(t,[`search`,`find`,`grep`,`rg`])){let t=X5(n),r=Y5(n);return{id:e.id,label:`Search ${t??t7(e.input)}${r?` in ${r}`:``}`,status:r7(e.status),input:e.input,output:e.output,error:e.error}}}function J5(e,t){return t.some(t=>e===t||e.startsWith(`${t}_`)||e.endsWith(`_${t}`)||e.includes(t))}function Y5(e){if(e)for(let t of[`path`,`file`,`filePath`,`filepath`,`url`,`uri`,`cwd`,`pattern`,`glob`]){let n=o7(e[t]);if(n)return n}}function X5(e){if(e)for(let t of[`query`,`pattern`,`text`,`name`,`q`,`regex`]){let n=o7(e[t]);if(n)return n}}function Z5(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Q5(e,t,n=`dim`,r=160){let i={lines:[],visibleLineCount:0,omittedLineCount:0,totalLineCount:0,maxVisibleLineCount:t},a=e7(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:[a7(e,n)]}));return c>0&&l.push({prefix:`continuation`,tokens:[a7(`+${c} more lines`,`dim`,`normal`,!0)]}),{lines:l,visibleLineCount:s.length,omittedLineCount:c,totalLineCount:o.length,maxVisibleLineCount:t}}function $5(e,t){if(!(e.omittedLineCount<=0))return{source:t,visibleLineCount:e.visibleLineCount,omittedLineCount:e.omittedLineCount,totalLineCount:e.totalLineCount,maxVisibleLineCount:e.maxVisibleLineCount}}function e7(e){let t=g5(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 t7(e){return(typeof e==`string`?e:e7(e)).replace(/\s+/g,` `).trim()}function fFe(e){let t=(e??``).trim().toLowerCase();return t===`shell`||t===`bash`||t===`terminal`}function n7(e){if(s7(e))for(let t of[`cmd`,`command`,`script`]){let n=o7(e[t]);if(n)return n}}function pFe(e){let t=e.match(/\s+|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s]+/g)??[e],n=!1;return t.map(e=>/^\s+$/.test(e)?a7(e):/^(?:&&|\|\||[|;<>]|2>&1)$/.test(e)?a7(e,`red`,`semibold`):e.startsWith(`-`)?a7(e,`magenta`):e.startsWith(`$`)||e.includes(`=`)?a7(e,`yellow`):/^['"]/.test(e)?a7(e,`green`):n?e.includes(`/`)||e.startsWith(`.`)?a7(e,`cyan`):a7(e,`default`):(n=!0,a7(e,`green`,`semibold`)))}function mFe(e){return e===`running`?`Calling`:e===`error`?`Call failed`:`Called`}function hFe(e){return e===`running`?`Spawning`:e===`error`?`Spawn failed`:`Spawned`}function gFe(e){return e===`running`?`Waiting for`:`Finished waiting for`}function r7(e){return e===`running`?`running`:e===`error`?`error`:`done`}function i7(e){return e===`running`?`cyan`:e===`error`?`red`:e===`done`?`green`:`default`}function a7(e,t=`default`,n=`normal`,r=!1){return{text:e,tone:t,weight:n,italic:r}}function o7(e){return typeof e==`string`&&e.trim().length?e:void 0}function s7(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function _Fe(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,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 c7(e,t,n){return n?{id:e,label:t,value:n}:void 0}function l7({field:e,icon:t}){let n=t===`session`?ms:us;return(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,z.jsx)(n,{size:11,className:`shrink-0 text-[#737373]`}),(0,z.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,z.jsx)(`span`,{className:`truncate font-mono ${e.id===`session`?`text-[#38bdf8]`:`text-[#d4d4d4]`}`,children:e.value})]})}function u7({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,z.jsxs)(`div`,{className:`mt-3 space-y-1`,"data-shared-progress":e.id,"data-shared-progress-state":e.state,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:t??e.label}),(0,z.jsx)(`span`,{className:`font-mono text-[#d4d4d4]`,children:e.state===`available`?e.text:`unavailable`})]}),e.state===`available`?(0,z.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,z.jsx)(`div`,{className:`h-full rounded-full ${r} transition-all`,style:{width:`${Math.min(Math.max(n,0),100)}%`}})}):null]})}function vFe(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 yFe({row:e}){let t=_Fe(e.output),n=xPe(e),r=n?.kind===`status`?n.statusView:void 0,[i,a]=(0,R.useState)(!1);if(!t||!r)return(0,z.jsx)(`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,z.jsx)(`div`,{className:`text-[#737373]`,children:`Status (unparseable)`})});let o=new Map(r.fields.map(e=>[e.id,e])),s=o.get(`session`)??c7(`session`,`Session`,t.piboSessionId),c=o.get(`cwd`)??c7(`cwd`,`CWD`,t.cwd),l=r.progress.find(e=>e.id===`context`),u=r.progress.filter(e=>e.id.startsWith(`provider`)),d=t.providerUsage?.limits.length?t.providerUsage.limits:void 0,f=t.enabledTools??t.activeTools??[],p=r.fields.filter(e=>!new Set([`session`,`cwd`]).has(e.id)),m=t.providerUsage?.provider?`${t.providerUsage.provider} quota`:`Provider quota`;return(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(Co,{size:14,className:`text-[#22c55e]`}),(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:r.title})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-1.5 sm:grid-cols-2`,children:[s?(0,z.jsx)(l7,{field:s,icon:`session`}):null,c?(0,z.jsx)(l7,{field:c,icon:`cwd`}):null,p.slice(0,8).map(e=>(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,"data-shared-status-field":e.id,children:[(0,z.jsxs)(`span`,{className:`shrink-0 text-[#737373]`,children:[e.label,`:`]}),(0,z.jsx)(`span`,{className:`truncate font-mono text-[#d4d4d4]`,children:e.value})]},e.id))]}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[t.processing?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,z.jsx)(es,{size:10}),` Processing`]}):null,t.streaming?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#1f4960] px-1.5 py-0.5 text-[11px] text-[#38bdf8]`,children:[(0,z.jsx)(Co,{size:10}),` Streaming`]}):null,typeof t.queuedMessages==`number`&&t.queuedMessages>0?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 border border-[#3a3a3a] px-1.5 py-0.5 text-[11px] text-[#d4d4d4]`,children:[(0,z.jsx)(vs,{size:10}),` Queued: `,t.queuedMessages]}):null,t.disposed?(0,z.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]}),l?(0,z.jsx)(u7,{progress:l,label:`Context Usage`}):null,u.length?(0,z.jsxs)(`div`,{className:`mt-3 space-y-1.5 border-t border-[#2a2a2a] pt-2`,"data-shared-provider-progress":u.length,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-[#737373]`,"data-shared-status-field":`provider-quota`,children:[(0,z.jsx)(ds,{size:11}),(0,z.jsxs)(`span`,{children:[m,t.providerUsage?.planType?` (${t.providerUsage.planType})`:``]})]}),d?d.map(e=>{let t=vFe(e.resetsAt);return(0,z.jsxs)(`div`,{className:`space-y-1`,"data-shared-progress":`provider-limit:${e.label}`,"data-shared-progress-state":`available`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,z.jsx)(`span`,{className:`text-[#a3a3a3]`,children:e.label}),(0,z.jsxs)(`span`,{className:`shrink-0 font-mono text-[#d4d4d4]`,children:[e.remainingPercent.toFixed(0),`% left`,t?` · resets ${t}`:``]})]}),(0,z.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-[#2a2a2a]`,children:(0,z.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??``}`)}):u.map(e=>(0,z.jsx)(u7,{progress:e},e.id)),t.providerUsage?.credits?(0,z.jsxs)(`div`,{className:`text-[11px] text-[#a3a3a3]`,"data-shared-status-field":`provider-credits`,children:[`Credits: `,t.providerUsage.credits.unlimited?`unlimited`:t.providerUsage.credits.balance??`available`]}):null]}):null,r.warnings.length||r.errors.length?(0,z.jsxs)(`div`,{className:`mt-3 space-y-1 border-t border-[#2a2a2a] pt-2`,children:[r.warnings.map((e,t)=>(0,z.jsxs)(`div`,{"data-shared-status-warning":!0,className:`text-[11px] text-[#facc15]`,children:[`⚠ `,e]},`warning-${t}`)),r.errors.map((e,t)=>(0,z.jsxs)(`div`,{"data-shared-status-error":!0,className:`text-[11px] text-[#ef4444]`,children:[`✕ `,e]},`error-${t}`))]}):null,f.length>0?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1.5 text-[11px] text-[#737373] hover:text-[#d4d4d4]`,children:[(0,z.jsx)(`span`,{className:`text-[#d4d4d4]`,children:i?`▾`:`▸`}),(0,z.jsxs)(`span`,{children:[`Enabled tools (`,f.length,`)`]})]}),i?(0,z.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:f.map(e=>(0,z.jsx)(`span`,{className:`inline-block rounded-sm border border-[#2a2a2a] bg-[#0b0b0b] px-1.5 py-0.5 font-mono text-[11px] text-[#a3a3a3]`,children:e},e))}):null]}):null]})}function bFe(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 xFe(e){return Xq.includes(e)?e:void 0}function SFe({row:e,onLevelSelect:t}){let n=bFe(e.output);return n?(0,z.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,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(Po,{size:14,className:`text-[#f59e0b]`}),(0,z.jsx)(`span`,{className:`font-semibold text-[#d4d4d4]`,children:`Thinking`}),n.supported===!1?(0,z.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,z.jsx)(Qs,{size:10}),` Unsupported`]}):(0,z.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,z.jsx)(Ro,{size:10}),` Supported`]})]}),(0,z.jsxs)(`div`,{className:`grid gap-1.5 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-[#737373]`,children:`Current:`}),(0,z.jsx)(`span`,{className:`font-mono font-semibold text-[#f59e0b]`,children:n.level??`unknown`})]}),n.availableLevels.length?(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,z.jsx)(`span`,{className:`mr-1 text-[#737373]`,children:`Available:`}),n.availableLevels.map(e=>{let r=xFe(e),i=n.supported===!1||!r||!t;return(0,z.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,z.jsxs)(`div`,{className:`text-[#737373]`,children:[`Click a level or use `,(0,z.jsx)(`span`,{className:`text-[#f59e0b]`,children:`/thinking <level>`}),`.`]})]})]}):(0,z.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,z.jsx)(`div`,{className:`text-[#737373]`,children:`Thinking (unparseable)`})})}var CFe=180,wFe={index:`LAST`,align:`end`},TFe={top:2400,bottom:2400},EFe=84,DFe=6;function OFe({traceView:e,selectedTrace:t,isLoading:n,showThinking:r,expandThinking:i,sessionAgentProfile:a,sessionActiveModel:o,selectedSessionStatus:s,selectedSessionSignal:c,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,agentProfiles:f,sessionProfileChangeDisabled:p,onSessionAgentProfileChange:m,onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:v}){let y=(0,R.useMemo)(()=>kPe(e,{showThinking:r}),[r,e]),[b,x]=(0,R.useState)(new Set),[S,C]=(0,R.useState)(null),w=(0,R.useRef)({}),T=y.filter(e=>e.status===`running`).length,E=y.filter(e=>p7(e,`user`)).length,D=y.filter(e=>p7(e,`tool`)).length,O=y.filter(e=>p7(e,`system`)).length,k=c?c.isTreeActive:s===`running`||T>0||t?.status===`UNSET`,A=INe({itemCount:y.length,resetKey:e?.piboSessionId,contentKey:y,atBottomThreshold:CFe});(0,R.useEffect)(()=>{x(e=>PFe(e,y,i))},[i,y]),(0,R.useEffect)(()=>{let e=new Set(y.map(e=>e.id));C(t=>t&&e.has(t)?t:null);for(let t of[`system`,`tool`,`user`]){let n=w.current[t];n&&!e.has(n)&&delete w.current[t]}},[y]);let j=(0,R.useCallback)(e=>{let t=FFe(y,e,w.current[e]);t&&(w.current[e]=t.row.id,C(t.row.id),A.scrollToIndex(t.index,`start`,`fast-smooth`,{fromIndex:t.fromIndex,stagingAlign:e===`tool`?`end`:void 0}),IFe(t.row.id))},[y,A]),M=e=>{e.expandable&&x(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},N=(0,R.useCallback)((t,n)=>(0,z.jsx)(`div`,{className:`px-4`,children:(0,z.jsx)(AFe,{row:n,expanded:b.has(n.id),focused:S===n.id,piboSessionId:e?.piboSessionId??``,onToggle:()=>M(n),onFork:h,onOpenSession:g,onThinkingLevelChange:_,onModelChanged:v})}),[b,S,h,v,g,_,e?.piboSessionId]),P=(0,R.useMemo)(()=>({Footer:k?VFe:void 0}),[k]);return(0,z.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,children:[(0,z.jsx)(kFe,{errorCount:O,toolErrorCount:D,userMessageCount:E,onNavigate:j,sessionAgentProfile:a,sessionActiveModel:o,sessionBreadcrumbs:l,originSession:u,derivedSessions:d,onOpenSession:g}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:e?y.length?(0,z.jsx)(lNe,{ref:A.virtuosoRef,data:y,initialTopMostItemIndex:wFe,increaseViewportBy:TFe,defaultItemHeight:EFe,className:`min-h-0 h-full overflow-x-hidden font-mono text-[12px] leading-[1.45]`,computeItemKey:(e,t)=>t.id,scrollerRef:A.scrollerRef,atBottomStateChange:A.atBottomStateChange,atBottomThreshold:A.atBottomThreshold,followOutput:A.followOutput,totalListHeightChanged:A.totalListHeightChanged,alignToBottom:!0,components:P,itemContent:N},e.piboSessionId):(0,z.jsx)(S7,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m,message:`No visible trace rows yet.`}):(0,z.jsx)(S7,{isLoading:n,agentProfiles:f,disabled:p,onSelectAgentProfile:m})}),A.isSticky?null:(0,z.jsx)(`button`,{type:`button`,onClick:()=>A.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,z.jsx)(zo,{size:18})})]})}function kFe({errorCount:e,toolErrorCount:t,userMessageCount:n,onNavigate:r,sessionAgentProfile:i,sessionActiveModel:a,sessionBreadcrumbs:o,originSession:s,derivedSessions:c,onOpenSession:l}){return(0,z.jsxs)(`div`,{className:`border-b border-[#2a2a2a] bg-[#111111] px-4 py-2 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i?(0,z.jsx)(b7,{tone:`neutral`,children:i}):null,a?(0,z.jsx)(b7,{tone:`purple`,children:a}):null,n>0?(0,z.jsxs)(b7,{tone:`cyan`,label:`${n} user messages · jump to previous user message`,onClick:()=>r(`user`),children:[n,(0,z.jsx)(Os,{size:12})]}):null,e>0?(0,z.jsxs)(b7,{tone:`red`,label:`${e} errors · jump to previous error`,onClick:()=>r(`system`),children:[e,(0,z.jsx)(Jo,{size:12})]}):null,t>0?(0,z.jsxs)(b7,{tone:`amber`,label:`${t} tool call errors · jump to previous tool error`,onClick:()=>r(`tool`),children:[t,(0,z.jsx)(ps,{size:12})]}):null,s?(0,z.jsxs)(d7,{onClick:()=>l(s.piboSessionId),children:[`Origin `,s.label]}):null,c.map(e=>(0,z.jsxs)(d7,{onClick:()=>l(e.piboSessionId),children:[`Derived `,e.label]},e.piboSessionId))]}),o.length?(0,z.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1 text-[#737373]`,children:o.map((e,t)=>(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t>0?(0,z.jsx)(Bo,{size:12,className:`text-[#525252]`}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>l(e.piboSessionId),className:`hover:text-[#38bdf8]`,children:e.label})]},e.piboSessionId))}):null]})}function d7({children:e,onClick:t}){return(0,z.jsx)(`button`,{type:`button`,onClick:t,className:`border border-[#3a3a3a] px-2 py-0.5 text-[#38bdf8] hover:border-[#38bdf8]`,children:e})}function AFe({row:e,expanded:t,focused:n,piboSessionId:r,onToggle:i,onFork:a,onOpenSession:o,onThinkingLevelChange:s,onModelChanged:c}){let l=!t&&RFe(e),u=l?LFe(e):e.lines;return(0,z.jsxs)(`div`,{className:NFe(e,n),"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||m7(t)||i()}:void 0,onKeyDown:e.expandable?t=>{!e.expandable||m7(t)||(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),i())}:void 0,role:e.expandable?`button`:void 0,tabIndex:e.expandable||n?0:void 0,"aria-expanded":e.expandable?t:void 0,"aria-current":n?`true`:void 0,children:[(0,z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,z.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,z.jsx)(jFe,{row:e,visibleLines:u,collapseToolCallPreview:l,piboSessionId:r,onThinkingLevelChange:s,onModelChanged:c})}),(0,z.jsx)(MFe,{row:e,onFork:a,onOpenSession:o})]}),t?(0,z.jsx)(YNe,{row:e,onOpenSession:o}):null]})}function jFe({row:e,visibleLines:t,collapseToolCallPreview:n,piboSessionId:r,onThinkingLevelChange:i,onModelChanged:a}){return e.kind===`message.assistant`?(0,z.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalAssistantMessage`,children:(0,z.jsx)(`div`,{className:`compact-terminal-markdown`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`assistant-message`,children:(0,z.jsx)(zW,{streaming:e.status===`running`,children:typeof e.output==`string`?e.output:``})})}):e.kind===`tool.status`?(0,z.jsx)(yFe,{row:e}):e.kind===`tool.thinking`?(0,z.jsx)(SFe,{row:e,onLevelSelect:i}):e.kind===`tool.login`?(0,z.jsx)(dPe,{row:e,piboSessionId:r}):e.kind===`tool.model`?(0,z.jsx)(hPe,{row:e,piboSessionId:r,onModelChanged:a}):e.kind===`execution.compaction`&&e.status===`running`?(0,z.jsx)(UFe,{}):e.kind===`reasoning`&&e.markdown?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(f7,{lines:t,status:e.status,clampPreview:n}),(0,z.jsx)(`div`,{className:`ml-[1.9rem] min-w-0`,"data-pibo-component":`TerminalReasoningMarkdown`,children:(0,z.jsx)(`div`,{className:`compact-terminal-markdown compact-terminal-reasoning`,"data-pibo-component":`MarkdownRendererHost`,"data-pibo-markdown-kind":`reasoning`,children:(0,z.jsx)(zW,{streaming:e.status===`running`,children:e.markdown})})})]}):(0,z.jsx)(f7,{lines:t,status:e.status,clampPreview:n})}function f7({lines:e,status:t,clampPreview:n}){return e.map((e,r)=>(0,z.jsx)(tPe,{line:e,status:t,clampLines:n&&r===0?5:void 0},r))}function MFe({row:e,onFork:t,onOpenSession:n}){return(0,z.jsxs)(`div`,{className:`flex shrink-0 items-start gap-1 transition-opacity ${e.forkEntryId?`opacity-100`:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:[e.linkedPiboSessionId?(0,z.jsx)(x7,{label:`Open linked session`,onClick:()=>n(e.linkedPiboSessionId),children:`Open`}):null,e.forkEntryId?(0,z.jsxs)(x7,{label:`Fork from this user message`,onClick:()=>t(e.forkEntryId),children:[(0,z.jsx)(fs,{size:13}),`Fork`]}):null]})}function NFe(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===`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 PFe(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 GFe(e,r)?e:r}function p7(e,t){return t===`user`?e.kind===`message.user`:e.status===`error`?t===`tool`?e.errorKind===`tool`:e.errorKind!==`tool`:!1}function FFe(e,t,n){let r=e.map((e,t)=>({row:e,index:t})).filter(({row:e})=>p7(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 IFe(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 LFe(e){return e.kind===`tool.group.exploring`||e.kind===`tool.group.images`?e.lines.slice(0,DFe):e.lines}function RFe(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 m7(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 zFe=`Working...`,h7=33,BFe=126;function VFe(){let{chars:e,activeIndex:t}=HFe(zFe);return(0,z.jsx)(`div`,{className:`border-t border-[#141414] px-4 py-2`,role:`status`,"aria-live":`polite`,"aria-label":`Working`,children:(0,z.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre text-[#737373]`,children:`•`}),(0,z.jsx)(`span`,{className:`compact-terminal-working-scramble`,"aria-hidden":`true`,children:e.map((e,n)=>(0,z.jsx)(`span`,{className:n===t?`compact-terminal-working-scramble-active`:void 0,children:e},n))})]})})}function HFe(e){let t=(0,R.useMemo)(()=>Array.from(e),[e]),[n,r]=(0,R.useState)(()=>_7(t)),[i,a]=(0,R.useState)(0);return(0,R.useEffect)(()=>{let e=0,n=0,i=y7(),o=0;r(_7(t));let s=window.setInterval(()=>{if(o>0){o--;return}if(e>=t.length){e=0,n=0,i=y7(),r(_7(t)),a(0);return}let s=e,c=t[s]??` `;if(a(s),n++,n<i){r(e=>g7(e,s,v7(c)));return}r(e=>g7(e,s,c)),e++,n=0,i=y7(),e>=t.length&&(r(t),a(-1),o=18)},55);return()=>window.clearInterval(s)},[t]),{chars:n,activeIndex:i}}function g7(e,t,n){let r=[...e];return r[t]=n,r}function _7(e){return e.map(e=>v7(e))}function v7(e){let t=``;do{let e=h7+Math.floor(Math.random()*(BFe-h7+1));t=String.fromCharCode(e)}while(t===e);return t}function y7(){return 2+Math.floor(Math.random()*11)}function UFe(){let e=WFe();return(0,z.jsxs)(`div`,{className:`grid grid-cols-[1.9rem_minmax(0,1fr)] gap-2 whitespace-pre-wrap break-words`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre text-[#38bdf8]`,children:`•`}),(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`font-semibold text-[#38bdf8]`,children:`Compacting`}),(0,z.jsx)(`span`,{className:`text-[#38bdf8]`,children:e})]})]})}function WFe(){let[e,t]=(0,R.useState)(0);return(0,R.useEffect)(()=>{let e=window.setInterval(()=>t(e=>(e+1)%4),400);return()=>window.clearInterval(e)},[]),`.`.repeat(e)}function b7({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,z.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,z.jsx)(`span`,{className:i,title:t,"aria-label":t,children:r})}function x7({label:e,onClick:t,children:n}){return(0,z.jsx)(`button`,{type:`button`,onClick:t,"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-[#737373] hover:border-[#38bdf8] hover:text-[#38bdf8]`,children:n})}function S7({isLoading:e,agentProfiles:t,disabled:n,onSelectAgentProfile:r,message:i}){return(0,z.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]`,children:[(0,z.jsx)(`div`,{children:e?`Loading trace…`:i??`No trace selected.`}),t.length?(0,z.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:t.map(e=>(0,z.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 GFe(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function KFe({traceView:e,isLoading:t,selectedSessionStatus:n,selectedSessionSignal:r,workflowProjectSession:i,workflowLifecycleEvents:a,sessionNodes:o,onOpenSession:s,onRefreshBootstrap:c,onError:l}){let u=i?iIe(i,e,n,r,a??[],o):null;return u?(0,z.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,z.jsxs)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-4`,children:[(0,z.jsx)(qFe,{model:u}),(0,z.jsx)(C7,{}),(0,z.jsx)(JFe,{model:u,onRefreshBootstrap:c,onError:l}),(0,z.jsx)(XFe,{model:u}),(0,z.jsx)(ZFe,{model:u,onOpenSession:s}),(0,z.jsx)(QFe,{nodes:u.nodes,edges:u.edges}),(0,z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,z.jsx)(eIe,{model:u}),(0,z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,z.jsx)(tIe,{model:u}),(0,z.jsx)(nIe,{model:u}),(0,z.jsx)(rIe,{model:u})]})]})]})}):(0,z.jsx)(`section`,{className:`min-w-0 flex-1 overflow-auto bg-[#0b0f14] p-4 text-slate-300`,children:(0,z.jsxs)(`div`,{className:`mx-auto flex max-w-4xl flex-col gap-4`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,z.jsx)(vs,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState`]}),(0,z.jsx)(`p`,{className:`mt-2 text-sm text-slate-400`,children:t?`Loading session trace…`:`This session is not linked to a workflow run, so no Workflow/XState projection is available.`})]}),(0,z.jsx)(C7,{})]})})}function qFe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-100`,children:[(0,z.jsx)(vs,{size:16,className:`text-[#11a4d4]`}),`Workflow / XState Projection`]}),(0,z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2 text-xs`,children:[(0,z.jsx)(K7,{tone:`blue`,children:e.workflowId}),e.workflowRunId?(0,z.jsxs)(K7,{tone:`slate`,children:[`run `,Y7(e.workflowRunId)]}):null,(0,z.jsx)(K7,{tone:TIe(e.status),children:e.state})]})]}),(0,z.jsxs)(`div`,{className:`min-w-0 text-right font-mono text-[11px] text-slate-500`,children:[(0,z.jsxs)(`div`,{className:`truncate`,children:[`session `,Y7(e.piboSessionId)]}),e.latestStreamId===void 0?null:(0,z.jsxs)(`div`,{children:[`stream `,e.latestStreamId]})]})]}),(0,z.jsx)(`p`,{className:`mt-3 text-sm text-slate-400`,children:`Dedicated Project workflow execution surface. This view derives the current XState-style UI snapshot from project-session workflow linkage and live session state while keeping kernel records as durable truth.`})]})}function C7(){return(0,z.jsx)(`div`,{className:`rounded-sm border border-amber-500/30 bg-amber-500/10 p-4 text-sm`,children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-amber-200`,children:[(0,z.jsx)(Js,{size:14}),`Workflow IR source-of-truth boundary`]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-amber-100/80`,children:`Projects inspect configured sessions, workflow runs, and the XState-style projection derived from Pibo Workflow IR. Authoring stays in the Workflows tab; raw XState editing and inline executable code are not exposed here.`})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,z.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`IR: source of truth`}),(0,z.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-[#0b0f14]/50 px-2 py-1 text-[10px] uppercase tracking-wide text-amber-100/80`,children:`XState: projection only`})]})]})})}function JFe({model:e,onRefreshBootstrap:t,onError:n}){let r=e.workflowRunId?k7(e):void 0,i=`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`;return(0,z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,"aria-label":`Projects workflow execution shell`,children:[(0,z.jsx)(D7,{title:`Workflow configured-session view`,icon:(0,z.jsx)(xs,{size:14}),children:(0,z.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,z.jsx)(O7,{label:`selected workflow`,value:i}),(0,z.jsx)(O7,{label:`session state`,value:e.workflowRunId?`started`:`configured/not-started`}),(0,z.jsx)(O7,{label:`input keys`,value:String(e.configuration.inputKeys.length)}),(0,z.jsx)(O7,{label:`prompt overrides`,value:String(e.configuration.promptOverrideNodeIds.length)}),(0,z.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`Saved configuration is reviewed here before Start. Workflow selection and session overrides remain immutable for this configured Project session.`})]})}),(0,z.jsx)(D7,{title:`Workflow run view`,icon:(0,z.jsx)(Co,{size:14}),children:(0,z.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[(0,z.jsx)(O7,{label:`run id`,value:e.workflowRunId?Y7(e.workflowRunId):`not started`}),(0,z.jsx)(O7,{label:`status`,value:e.state}),(0,z.jsx)(O7,{label:`current node`,value:r?.label??`none`}),(0,z.jsx)(O7,{label:`output`,value:e.finalOutput?`available`:`empty`}),(0,z.jsx)(O7,{label:`error`,value:e.runtimeErrors.length?`${e.runtimeErrors.length} runtime errors`:e.validationErrors.length?`${e.validationErrors.length} validation diagnostics`:`none`}),(0,z.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This workflow run view container is the stable Project home for status, current node, output, and error sections.`})]})}),(0,z.jsx)(D7,{title:`Human action area`,icon:(0,z.jsx)(Xo,{size:14}),children:(0,z.jsx)(YFe,{model:e,onRefreshBootstrap:t,onError:n})})]})}function YFe({model:e,onRefreshBootstrap:t,onError:n}){let[r,i]=(0,R.useState)({}),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)({}),[l,u]=(0,R.useState)({}),d=(e,t)=>{i(n=>({...n,[e]:t}))},f=async(i,a)=>{if(!i.waitTokenId||!a.registered)return;let s=`${i.waitTokenId}:${a.id}`,l=a.kind??`resume`,d;if(l===`resume`){let e=r[i.waitTokenId]??(i.payloadRequirements?.required?`{}`:``);if(e.trim())try{d=JSON.parse(e)}catch{let e=[{code:`WorkflowRuntimeError.invalidHumanActionPayload`,message:`Resume payload must be valid JSON before it can be submitted.`,severity:`error`,path:`$.payload`,hint:`Enter JSON such as {"comment":"Approved"}.`}];c(t=>({...t,[i.waitTokenId]:e})),n?.(`Resume payload must be valid JSON.`);return}}o(s),c(e=>({...e,[i.waitTokenId]:[]}));try{await Nye(e.projectId,e.piboSessionId,{waitTokenId:i.waitTokenId,actionId:a.id,...a.kind?{kind:a.kind}:{},...d===void 0?{}:{payload:d}}),u(e=>({...e,[i.waitTokenId]:`${a.displayName} submitted.`})),n?.(null),await t?.()}catch(e){let t=yIe(e);c(e=>({...e,[i.waitTokenId]:t})),n?.(t[0]?.message??B7(e))}finally{o(null)}};return(0,z.jsxs)(`div`,{className:`space-y-3 text-xs text-slate-400`,children:[e.pendingHumanActions.length?(0,z.jsx)(`div`,{className:`space-y-3`,children:e.pendingHumanActions.map(e=>{let t=[...e.diagnostics,...e.waitTokenId?s[e.waitTokenId]??[]:[]];return(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-amber-100`,"aria-label":`Pending workflow human action wait token`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:e.label}),(0,z.jsx)(`div`,{className:`mt-1 break-words text-[11px] leading-5 text-amber-100/80`,children:e.prompt})]}),(0,z.jsx)(`span`,{className:`shrink-0 rounded border border-amber-400/40 bg-[#0b0f14]/40 px-1.5 py-0.5 font-mono text-[10px] text-amber-100/70`,children:e.waitTokenId?Y7(e.waitTokenId):e.source})]}),(0,z.jsxs)(`div`,{className:`mt-2 grid gap-2 text-[11px] text-amber-100/75`,children:[(0,z.jsx)(O7,{label:`human node`,value:e.humanNodeId??`unspecified`}),(0,z.jsx)(O7,{label:`payload`,value:e.payloadRequirements?.description??`No persisted payload schema.`}),e.expiresAt?(0,z.jsx)(O7,{label:`expires`,value:e.expiresAt}):null]}),e.payloadRequirements?.schema?(0,z.jsxs)(`div`,{className:`mt-2 rounded-sm border border-amber-400/25 bg-[#0b0f14]/50 p-2`,children:[(0,z.jsx)(`div`,{className:`mb-1 text-[10px] font-bold uppercase tracking-wider text-amber-100/70`,children:`Resume payload schema`}),(0,z.jsx)(vq,{value:e.payloadRequirements.schema,defaultExpandLevel:1,maxHeight:`10rem`,showControls:!1})]}):null,e.availableActions.some(e=>e.kind===`resume`)?(0,z.jsxs)(`label`,{className:`mt-3 block text-[11px] text-amber-100/80`,children:[(0,z.jsx)(`span`,{className:`mb-1 block font-semibold`,children:`Resume payload JSON`}),(0,z.jsx)(`textarea`,{className:`min-h-20 w-full rounded-sm border border-amber-500/30 bg-[#0b0f14] px-2 py-1.5 font-mono text-[11px] text-amber-50 outline-none focus:border-[#11a4d4]`,value:r[e.waitTokenId??e.id]??(e.payloadRequirements?.required?`{}`:``),onChange:t=>d(e.waitTokenId??e.id,t.target.value),placeholder:`{"comment":"Approved"}`})]}):null,(0,z.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,"aria-label":`Workflow wait token actions`,children:e.availableActions.length?e.availableActions.map(t=>{let n=`${e.waitTokenId}:${t.id}`;return(0,z.jsx)(`button`,{type:`button`,disabled:!e.waitTokenId||!t.registered||a!==null,onClick:()=>void f(e,t),className:`rounded-sm border border-amber-400/40 bg-[#0b0f14]/70 px-2.5 py-1 text-[11px] font-semibold text-amber-100 transition hover:border-[#11a4d4] hover:text-[#8bdcf4] disabled:cursor-not-allowed disabled:opacity-50`,title:t.description??t.id,children:a===n?`Submitting…`:t.displayName},t.id)}):(0,z.jsx)(`span`,{className:`text-amber-100/60`,children:`No registered human actions are available for this wait token.`})}),e.waitTokenId&&l[e.waitTokenId]?(0,z.jsx)(`div`,{className:`mt-2 text-[11px] text-emerald-200`,children:l[e.waitTokenId]}):null,t.length?(0,z.jsx)(`div`,{className:`mt-2 space-y-1`,"aria-label":`Human action diagnostics`,children:t.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded border border-red-400/35 bg-red-500/15 p-2 text-[11px] leading-5 text-red-100`,children:[(0,z.jsx)(`div`,{children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-red-100/70`,children:[e.code,e.path?` · ${e.path}`:``]})]},`${e.code}:${t}`))}):null]},e.id)})}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-slate-500`,children:`No pending human action. Approval, rejection, resume, and cancel controls render here when a persisted workflow wait token exists.`}),(0,z.jsx)(`p`,{className:`leading-5 text-slate-500`,children:`This human action area lives inside the workflow run context, validates wait-token state and resume payloads, and stays separate from normal Terminal chat controls.`})]})}function XFe({model:e}){let t=e.workflowRunId?k7(e):void 0,n=[...e.runtimeErrors.map(e=>({...e,source:e.source??`runtime`})),...e.validationErrors.map(e=>({...e,source:e.source??`validation`}))].slice(0,8);return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow run inspection panel`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(ts,{size:14}),`Workflow run inspection`]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Status, current node, history, attempts, transfers, output, and errors are rendered from Project session and workflow run facts when a run is linked. The XState graph remains a visualization projection only.`})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2 text-[10px] uppercase tracking-wide`,children:[(0,z.jsx)(`span`,{className:`rounded border border-emerald-500/40 bg-emerald-500/10 px-2 py-1 text-emerald-200`,children:`kernel/run records: truth`}),(0,z.jsx)(`span`,{className:`rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1 text-amber-100`,children:`XState projection only`})]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-3`,children:[(0,z.jsxs)(w7,{title:`Status`,badge:e.state,icon:(0,z.jsx)(Co,{size:14}),children:[(0,z.jsx)(T7,{label:`run id`,value:e.workflowRunId?Y7(e.workflowRunId):`not started`}),(0,z.jsx)(T7,{label:`status`,value:e.state}),(0,z.jsx)(T7,{label:`record source`,value:e.workflowRunId?`Project workflow run id`:`no run record yet`})]}),(0,z.jsxs)(w7,{title:`Current node`,badge:t?.status??`none`,icon:(0,z.jsx)(Rs,{size:14}),children:[(0,z.jsx)(T7,{label:`node`,value:t?.label??`none`}),(0,z.jsx)(T7,{label:`node id`,value:t?.id??`none`}),(0,z.jsx)(T7,{label:`source`,value:`project/session run cursor`})]}),(0,z.jsx)(w7,{title:`Run history`,badge:`${e.runHistory.length}`,icon:(0,z.jsx)(hs,{size:14}),children:e.runHistory.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.runHistory.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:Y7(e.id)}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${J7(e.status)}`,children:e.status})]}),(0,z.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.currentNodeId?`current ${e.currentNodeId}`:`no current node`,` · `,e.source]}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-600`,children:[`updated `,e.updatedAt]})]},e.id))}):(0,z.jsx)(E7,{children:e.workflowRunId?`No workflow run history for this selected Project session yet.`:`No current run attempts; this configured Project session has not been started.`})})]}),(0,z.jsxs)(`div`,{className:`mt-3 grid gap-3 lg:grid-cols-2`,children:[(0,z.jsx)(w7,{title:`Node attempts`,badge:`${e.nodeAttempts.length}`,icon:(0,z.jsx)(xs,{size:14}),children:e.nodeAttempts.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.nodeAttempts.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.label}),(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:[e.nodeId,` · attempt `,e.attempt]})]}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${J7(e.status)}`,children:e.status})]}),(0,z.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.kind,` · `,e.source]})]},e.id))}):(0,z.jsx)(E7,{children:e.workflowRunId?`No node attempts recorded for this workflow run yet.`:`No current node attempts; Start has not created a workflow run.`})}),(0,z.jsx)(w7,{title:`Edge transfers`,badge:`${e.edgeTransfers.length}`,icon:(0,z.jsx)(fs,{size:14}),children:e.edgeTransfers.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.edgeTransfers.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsx)(`div`,{className:`min-w-0 truncate font-mono text-xs text-slate-200`,children:e.edgeId}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${J7(e.status)}`,children:e.status})]}),(0,z.jsxs)(`div`,{className:`mt-1 text-[11px] text-slate-500`,children:[e.source,e.createdAt?` · ${e.createdAt}`:``]})]},e.id))}):(0,z.jsx)(E7,{children:`No edge transfers recorded for this workflow run yet.`})}),(0,z.jsx)(w7,{title:`Output`,badge:e.finalOutput?`available`:`empty`,icon:(0,z.jsx)(Ko,{size:14}),children:e.finalOutput?(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:[(0,z.jsx)(`div`,{className:`mb-2 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}),(0,z.jsx)(vq,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`12rem`,showControls:!1})]}):(0,z.jsx)(E7,{children:`No workflow output has been recorded for this run yet.`})}),(0,z.jsx)(w7,{title:`Error`,badge:n.length?`${n.length}`:`none`,icon:(0,z.jsx)(Js,{size:14}),children:n.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2 text-xs text-red-100`,children:[(0,z.jsx)(`div`,{className:`break-words`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,z.jsx)(`span`,{children:e.code}):null,e.source?(0,z.jsx)(`span`,{children:e.source}):null]})]},e.id))}):(0,z.jsx)(E7,{children:`No workflow run errors are recorded.`})})]})]})}function ZFe({model:e,onOpenSession:t}){let n=M7(e.definitionLink);return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,"aria-label":`Workflow navigation links`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(rs,{size:14}),`Workflow navigation links`]}),(0,z.jsx)(`p`,{className:`mt-2 max-w-3xl text-xs leading-5 text-slate-500`,children:`Use these run-view links to move between real nested workflow sessions and the Workflows tab definition. Snapshot-only history is shown when the live definition is deleted or unavailable.`})]}),e.definitionLink.status===`live`&&n?(0,z.jsxs)(`a`,{className:`inline-flex shrink-0 items-center justify-center gap-1 rounded-sm border border-[#11a4d4]/50 px-3 py-1.5 text-xs font-semibold text-[#8bdcf4] transition hover:border-[#11a4d4] hover:text-slate-100`,href:n,children:[(0,z.jsx)(rs,{size:13}),`Open live workflow definition`]}):null]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 lg:grid-cols-2`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Nested workflow child session links`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Nested workflow child sessions`}),(0,z.jsx)(`span`,{className:`rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:e.nestedSessionLinks.length})]}),e.nestedSessionLinks.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.nestedSessionLinks.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>t(e.piboSessionId),className:`w-full rounded-sm border border-slate-800 bg-[#0b0f14] p-2 text-left transition hover:border-[#11a4d4]/60 hover:bg-[#102331]`,children:(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-xs font-semibold text-slate-200`,children:e.title}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[10px] text-slate-500`,children:Y7(e.piboSessionId)})]}),(0,z.jsx)(`span`,{className:`rounded border border-[#11a4d4]/40 bg-[#11a4d4]/10 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-[#8bdcf4]`,children:`open session`})]})},e.piboSessionId))}):(0,z.jsx)(E7,{children:`No nested workflow child sessions are linked under this selected Project session yet.`})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":`Workflow definition link state`,children:[(0,z.jsx)(`div`,{className:`mb-3 text-xs font-bold uppercase tracking-wider text-slate-500`,children:`Workflow definition link`}),e.definitionLink.status===`live`&&n?(0,z.jsxs)(`div`,{className:`rounded-sm border border-emerald-500/35 bg-emerald-500/10 p-3 text-xs leading-5 text-emerald-100`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:`Live workflow definition exists`}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-emerald-100/80`,children:P7(e.definitionLink)}),e.definitionLink.definitionHash?(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-emerald-100/60`,children:[`snapshot `,Y7(e.definitionLink.definitionHash)]}):null]}):(0,z.jsxs)(`div`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-5 text-amber-100`,children:[(0,z.jsx)(`div`,{className:`font-semibold`,children:`Definition deleted — snapshot-only definition-deleted state`}),(0,z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-amber-100/80`,children:P7(e.definitionLink)}),(0,z.jsx)(`div`,{className:`mt-1 text-amber-100/80`,children:e.definitionLink.tombstoneLabel??`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}),e.definitionLink.definitionHash?(0,z.jsxs)(`div`,{className:`mt-1 font-mono text-[10px] text-amber-100/60`,children:[`snapshot `,Y7(e.definitionLink.definitionHash)]}):null]})]})]})]})}function w7({title:e,badge:t,icon:n,children:r}){return(0,z.jsxs)(`section`,{className:`min-w-0 rounded-sm border border-slate-800 bg-[#0f171e] p-3`,"aria-label":e,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:n}),e]}),(0,z.jsx)(`span`,{className:`shrink-0 rounded border border-slate-700 bg-[#0b0f14] px-1.5 py-0.5 font-mono text-[10px] text-slate-400`,children:t})]}),r]})}function T7({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 py-2 first:pt-0 last:border-b-0 last:pb-0`,children:[(0,z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-slate-500`,children:e}),(0,z.jsx)(`span`,{className:`min-w-0 max-w-[14rem] truncate text-right font-mono text-xs text-slate-300`,title:t,children:t})]})}function E7({children:e}){return(0,z.jsx)(`div`,{className:`rounded-sm border border-dashed border-slate-800 bg-[#0b0f14] p-3 text-xs leading-5 text-slate-500`,children:e})}function D7({title:e,icon:t,children:n}){return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,"aria-label":e,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(`span`,{className:`text-[#11a4d4]`,children:t}),e]}),n]})}function O7({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,z.jsx)(`span`,{className:`uppercase tracking-wide text-slate-500`,children:e}),(0,z.jsx)(`span`,{className:`min-w-0 max-w-[12rem] truncate text-right font-mono text-slate-300`,title:t,children:t})]})}function k7(e){return e.nodes.find(e=>e.status===`active`||e.status===`waiting`)??e.nodes[0]}function QFe({nodes:e,edges:t}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0f171e] p-4`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Rs,{size:14}),`Visual State Flow`]}),(0,z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_auto_1fr_auto_1fr]`,children:e.map((e,n)=>(0,z.jsx)($Fe,{node:e,edge:t[n]},e.id))})]})}function $Fe({node:e,edge:t}){return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`rounded-sm border p-3 ${q7(e.status)}`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,z.jsx)(G7,{status:e.status}),(0,z.jsx)(`div`,{className:`min-w-0 truncate text-sm font-semibold text-slate-100`,children:e.label})]}),(0,z.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]}),t?(0,z.jsx)(`div`,{className:`hidden items-center justify-center text-center text-[10px] uppercase tracking-wide text-slate-500 md:flex`,children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(fs,{size:14,className:`mx-auto mb-1 text-[#11a4d4]`}),t.label]})}):null]})}function eIe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Co,{size:14}),`Current UI Snapshot`]}),(0,z.jsx)(vq,{value:e.snapshot,showControls:!1})]})}function tIe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(xs,{size:14}),`Node Statuses`]}),(0,z.jsxs)(`span`,{className:`font-mono text-[11px] text-slate-500`,children:[e.nodes.length,` nodes`]})]}),(0,z.jsx)(`div`,{className:`space-y-2`,children:e.nodes.map(e=>(0,z.jsxs)(`div`,{className:`rounded-sm border px-3 py-2 ${q7(e.status)}`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,z.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:(0,z.jsx)(G7,{status:e.status})}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`truncate text-sm font-semibold text-slate-100`,children:e.label}),(0,z.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-slate-500`,children:e.id})]})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide ${EIe(e.status)}`,children:e.status}),(0,z.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-slate-400`,children:e.kind})]})]}),(0,z.jsx)(`p`,{className:`mt-2 text-xs text-slate-400`,children:e.description})]},e.id))}),(0,z.jsx)(`p`,{className:`mt-3 text-xs text-slate-500`,children:`Node status is reconstructed from the workflow run linkage and live session state; persisted kernel records remain the durable source of truth.`})]})}function nIe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Ko,{size:14}),`Final Output & Validation`]}),(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Final output`}),e.finalOutput?(0,z.jsx)(`span`,{className:`rounded border border-slate-700 px-1.5 py-0.5 font-mono text-[10px] text-slate-500`,children:e.finalOutput.source}):null]}),e.finalOutput?(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-2`,children:(0,z.jsx)(vq,{value:e.finalOutput.value,defaultExpandLevel:1,maxHeight:`14rem`,showControls:!1})}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No final workflow output is available yet. Completed workflow-backed sessions show the final assistant output here.`})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-slate-400`,children:`Validation errors`}),(0,z.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 font-mono text-[10px] ${e.validationErrors.length?`border-red-500/40 bg-red-500/10 text-red-300`:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`}`,children:e.validationErrors.length?`${e.validationErrors.length} found`:`none`})]}),e.validationErrors.length?(0,z.jsx)(`div`,{className:`space-y-2`,children:e.validationErrors.map(e=>(0,z.jsx)(`div`,{className:`rounded-sm border border-red-500/35 bg-red-500/10 p-2`,children:(0,z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 text-xs text-red-200`,children:[(0,z.jsx)(Js,{size:14,className:`mt-0.5 shrink-0 text-red-300`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`break-words`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,z.jsx)(`span`,{children:e.code}):null,e.path?(0,z.jsx)(`span`,{children:e.path}):null,e.source?(0,z.jsx)(`span`,{children:e.source}):null]})]})]})},e.id))}):(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-800 bg-[#0b0f14] p-3 text-xs text-slate-500`,children:`No workflow validation diagnostics were found in the current session trace.`})]})]})]})}function rIe({model:e}){return(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#111820] p-4 text-sm`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-wider text-slate-500`,children:[(0,z.jsx)(Yo,{size:14}),`Projection Facts`]}),(0,z.jsxs)(`dl`,{className:`space-y-3`,children:[(0,z.jsx)(A7,{label:`projection kind`,value:`pibo.workflow.xstateUiModel`}),(0,z.jsx)(A7,{label:`schema`,value:`v1`}),(0,z.jsx)(A7,{label:`durable truth`,value:`kernel`}),(0,z.jsx)(A7,{label:`private payloads`,value:`not exposed`}),(0,z.jsx)(A7,{label:`states`,value:String(e.nodes.length)}),(0,z.jsx)(A7,{label:`transitions`,value:String(e.edges.length)}),(0,z.jsx)(A7,{label:`trace`,value:e.traceVersion??`pending`})]})]})}function A7({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-slate-800/70 pb-2 last:border-b-0 last:pb-0`,children:[(0,z.jsx)(`dt`,{className:`text-xs uppercase tracking-wide text-slate-500`,children:e}),(0,z.jsx)(`dd`,{className:`min-w-0 truncate text-right font-mono text-xs text-slate-300`,children:t})]})}function iIe(e,t,n,r,i,a){if(!bIe(e))return null;let o=U7(e,n),s=xIe(e,n),c=SIe(s),l=gIe(t,s),u=[...vIe(t),..._Ie(e,i)],d=lIe(e,o,c),f=uIe(t,e.workflowRunId),p=pIe(t,e.workflowRunId),m=mIe(t,r),h=aIe(e),g=oIe(a,e.piboSessionId),_=[{id:`workflow.entry`,label:`workflow entry`,kind:`initial`,status:s===`idle`?`active`:`completed`,description:`Project session is linked to a workflow-capable route.`},{id:`node.session`,label:t?.title??`pibo session actor`,kind:`agent`,status:c===`node.session`?s:s===`completed`?`completed`:`idle`,description:`Normal Pibo routed session used as the visible workflow actor.`},{id:W7(s),label:CIe(s),kind:`terminal`,status:c.startsWith(`workflow.`)?s:`idle`,description:`Terminal state projected from the current workflow/session state.`}];return{projectId:e.projectId,workflowId:e.workflowId,...e.workflowVersion?{workflowVersion:e.workflowVersion}:{},...e.workflowRunId?{workflowRunId:e.workflowRunId}:{},piboSessionId:e.piboSessionId,state:o,status:s,traceTitle:t?.title,traceVersion:t?.version,latestStreamId:t?.latestStreamId,nodes:_,edges:[{id:`workflow.transition.entry.session`,source:`workflow.entry`,target:`node.session`,label:`WORKFLOW.START`},{id:`workflow.transition.session.terminal`,source:`node.session`,target:W7(s),label:wIe(s)}],configuration:sIe(e),definitionLink:h,nestedSessionLinks:g,pendingHumanActions:cIe(e,r),runHistory:d,nodeAttempts:f,edgeTransfers:p,runtimeErrors:m,...l?{finalOutput:l}:{},validationErrors:u,snapshot:{kind:`pibo.workflow.xstateUiModel`,schemaVersion:1,projection:{workflowId:e.workflowId,initialStateId:`workflow.entry`,durableTruth:`kernel`,exposesPrivatePayloads:!1},authoring:{location:`workflows_tab`,rawXStateEditingUi:`not_exposed`,inlineExecutableCodeUi:`not_exposed`},current:{snapshotKind:`ui`,...e.workflowRunId?{runId:e.workflowRunId}:{},status:o,stateIds:[c],nodeId:c===`node.session`?`session`:void 0},nodeStatuses:_.map(e=>({id:e.id,kind:e.kind,status:e.status})),runInspection:{durableTruth:`kernel_run_records`,xstateProjectionOnly:!0,runHistoryCount:d.length,nodeAttemptCount:f.length,edgeTransferCount:p.length,runtimeErrorCount:m.length},result:{hasFinalOutput:!!l,validationErrorCount:u.length},actors:[{id:`workflow.actor.session`,kind:`agent`,piboSessionId:e.piboSessionId}],definitionLink:{status:h.status,workflowId:h.workflowId,workflowVersion:h.workflowVersion,hasLiveLink:h.status===`live`&&!!M7(h)},nestedWorkflowSessionCount:g.length}}}function aIe(e){return e.workflowDefinitionLink?e.workflowDefinitionLink:e.workflowVersion?{status:`live`,workflowId:e.workflowId,workflowVersion:e.workflowVersion,title:e.title??e.workflowId,href:N7(e.workflowId,e.workflowVersion)}:{status:`snapshot_only_definition_deleted`,workflowId:e.workflowId,title:e.title??e.workflowId,tombstoneLabel:`Historical run inspection uses the immutable Project session snapshot instead of a broken live definition link.`}}function oIe(e,t){let n=j7(e,t);if(!n)return[];let r=[],i=e=>{for(let t of e)t.workflowSessionKind===`nested_workflow`&&r.push({piboSessionId:t.piboSessionId,title:t.title,kind:t.workflowSessionKind??t.profile??`workflow`,...t.workflowSessionKind?{workflowSessionKind:t.workflowSessionKind}:{}}),i(t.children)};return i(n.children),r}function j7(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=j7(n.children,t);if(e)return e}}function M7(e){if(e.status===`live`){if(e.href)return e.href;if(e.workflowVersion)return N7(e.workflowId,e.workflowVersion)}}function N7(e,t){return`/apps/chat/workflows/view/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function P7(e){return`${e.workflowId}${e.workflowVersion?`@${e.workflowVersion}`:``}`}function sIe(e){let t=e.configuration;return{inputKeys:Object.keys(t?.inputValues??{}).sort(),promptOverrideNodeIds:Object.keys(t?.promptOverrides??{}).sort()}}function cIe(e,t){if(e.pendingHumanActions?.length)return e.pendingHumanActions.map(e=>({id:`wait-token:${e.waitTokenId}`,waitTokenId:e.waitTokenId,workflowRunId:e.workflowRunId,...e.nodeAttemptId?{nodeAttemptId:e.nodeAttemptId}:{},...e.humanNodeId?{humanNodeId:e.humanNodeId}:{},prompt:e.prompt,label:`Pending registered human action`,source:`persisted wait token`,...e.schema?{schema:e.schema}:{},payloadRequirements:e.payloadRequirements,availableActions:e.availableActions,diagnostics:e.diagnostics,createdAt:e.createdAt,...e.expiresAt?{expiresAt:e.expiresAt}:{}}));let n=U7(e,void 0).toLowerCase(),r=[t?.aggregateStatus,t?.localStatus].filter(e=>typeof e==`string`).join(` `).toLowerCase();return n.includes(`waiting`)||n.includes(`blocked`)||r.includes(`waiting`)||r.includes(`blocked`)||t?.hasBlockedDescendant?[{id:`human-action:${e.piboSessionId}`,prompt:`Session signal indicates a wait, but no persisted workflow wait token is available in the Project run store.`,label:`Awaiting human action`,source:t?`session signal`:`project session state`,availableActions:[],diagnostics:[]}]:[]}function lIe(e,t,n){return e.workflowRunId?[{id:e.workflowRunId,status:t,currentNodeId:n,updatedAt:e.updatedAt,source:`project session run record`}]:[]}function uIe(e,t){return!t||!e?[]:F7(e.nodes).filter(dIe).slice(0,8).map((e,t)=>({id:e.id,nodeId:e.stableKey??e.entryId??e.type,label:e.title||e.type,kind:e.type,status:fIe(e.status),attempt:t+1,source:`session trace fact`,...e.startedAt?{startedAt:e.startedAt}:{},...e.completedAt?{completedAt:e.completedAt}:{}}))}function dIe(e){return e.type===`agent.turn`||e.type===`tool.call`||e.type===`execution.command`||e.type===`agent.delegation`||e.type===`agent.async`||e.type===`yielded.run`||e.type===`error`}function fIe(e){return e===`done`?`completed`:e===`error`?`failed`:`running`}function pIe(e,t){if(!t||!e)return[];let n=[];for(let r of e.rawEvents){if(!H7(r.payload))continue;let e=V7(r.payload.type),i=V7(r.payload.runId);if(e!==`edge.transferred`||i&&i!==t)continue;let a=V7(r.payload.edgeId);a&&n.push({id:V7(r.payload.edgeTransferId)??r.id,edgeId:a,status:`transferred`,source:r.type,createdAt:r.createdAt})}return n.slice(0,8)}function mIe(e,t){let n=[];for(let e of t?.errors??[])n.push({id:`signal:${n.length}`,message:e.message,...e.code?{code:e.code}:{},source:e.source??`session signal`});if(e){for(let t of F7(e.nodes)){let e=t.error??(t.status===`error`?L7(t.output)??L7(t.summary):void 0);e&&n.push({id:`node:${t.id}`,message:e,source:t.type})}for(let t of e.rawEvents){if(!H7(t.payload))continue;let e=t.payload.error,r=H7(e)?V7(e.message):V7(e),i=H7(e)?V7(e.code):void 0;r&&n.push({id:`event:${t.id}`,message:r,...i?{code:i}:{},source:t.type})}}return hIe(n).slice(0,8)}function hIe(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.message}:${e.source??``}`;return t.has(n)?!1:(t.add(n),!0)})}function gIe(e,t){if(t!==`completed`||!e)return;let n=F7(e.nodes),r=[...n].reverse().find(e=>e.type===`assistant.message`&&e.status===`done`&&(e.output!==void 0||e.summary));if(r)return{value:r.output??r.summary??``,source:`assistant.message`};let i=[...n].reverse().find(e=>e.status===`done`&&e.type!==`user.message`&&e.type!==`model.reasoning`&&e.output!==void 0);return i?{value:i.output,source:i.type}:void 0}function _Ie(e,t){let n=[];for(let r of t)if(r.piboSessionId===e.piboSessionId&&!(r.type!==`project.workflow_start.blocked`&&r.validation?.trigger!==`before_workflow_start`))for(let e of r.diagnostics)e.severity===`error`&&n.push({id:`lifecycle:${r.id}:${n.length}`,message:e.message,code:e.code,path:e.path,source:`start lifecycle event`});return z7(n).slice(0,8)}function vIe(e){if(!e)return[];let t=[];for(let n of F7(e.nodes)){let e=n.error??L7(n.output)??L7(n.summary);e&&(!R7([n.title,n.summary,n.error,n.type].filter(e=>typeof e==`string`).join(` `))&&!R7(e)||t.push({id:`node:${n.id}`,message:e,...n.type?{source:n.type}:{}}))}for(let n of e.rawEvents)I7(n.payload,`event:${n.id}`,t);return z7(t).slice(0,8)}function F7(e){let t=[],n=e=>{for(let r of e)t.push(r),n(r.children)};return n(e),t}function I7(e,t,n,r=0){if(r>4||!H7(e))return;let i=Array.isArray(e.diagnostics)?e.diagnostics:void 0;if(i)for(let e of i){if(!H7(e))continue;let r=V7(e.message)??L7(e);r&&n.push({id:`${t}:diagnostic:${n.length}`,message:r,...V7(e.code)?{code:V7(e.code)}:{},...V7(e.path)?{path:V7(e.path)}:{},source:`workflow.diagnostic`})}let a=e.error;if(H7(a)){let e=V7(a.code),r=V7(a.message)??L7(a);r&&R7([e,r].filter(Boolean).join(` `))&&n.push({id:`${t}:error:${n.length}`,message:r,...e?{code:e}:{},source:`workflow.error`})}else typeof a==`string`&&R7(a)&&n.push({id:`${t}:error:${n.length}`,message:a,source:`workflow.error`});for(let[i,a]of Object.entries(e))i===`diagnostics`||i===`error`||i!==`payload`&&i!==`output`&&i!==`result`&&i!==`data`||I7(a,`${t}:${i}`,n,r+1)}function L7(e){if(typeof e==`string`)return e;if(H7(e))return V7(e.message)??V7(e.error)??V7(e.summary)}function R7(e){let t=e.toLowerCase();return t.includes(`validation`)||t.includes(`validate`)||t.includes(`diagnostic`)||t.includes(`workflowinterfaceerror`)||t.includes(`workflowruntimeerror.validation`)}function z7(e){let t=new Set;return e.filter(e=>{let n=`${e.code??``}:${e.path??``}:${e.message}`;return t.has(n)?!1:(t.add(n),!0)})}function yIe(e){return H7(e)&&H7(e.data)&&Array.isArray(e.data.diagnostics)?e.data.diagnostics.filter(H7).map(t=>({code:V7(t.code)??`WorkflowRuntimeError.humanActionRejected`,message:V7(t.message)??B7(e),severity:t.severity===`info`||t.severity===`warning`||t.severity===`error`?t.severity:`error`,...V7(t.path)?{path:V7(t.path)}:{},...V7(t.registryRef)?{registryRef:V7(t.registryRef)}:{},...V7(t.hint)?{hint:V7(t.hint)}:{}})):[{code:`WorkflowRuntimeError.humanActionRejected`,message:B7(e),severity:`error`}]}function B7(e){return e instanceof Error?e.message:String(e)}function V7(e){return typeof e==`string`&&e.trim()?e:void 0}function H7(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function bIe(e){return!!e.workflowRunId||e.state===`workflow`||e.workflowId!==`simple-chat`}function U7(e,t){return e.archived?`archived`:e.state&&e.state!==`workflow`?e.state.replace(/_/g,` `):t===`running`?`running`:t===`error`?`failed`:e.workflowRunId?`workflow`:e.kind}function xIe(e,t){let n=U7(e,t).toLowerCase();return e.archived?`cancelled`:n.includes(`complete`)||n.includes(`done`)?`completed`:n.includes(`fail`)||n.includes(`error`)?`failed`:n.includes(`cancel`)?`cancelled`:n.includes(`wait`)||n.includes(`blocked`)?`waiting`:!e.workflowRunId&&n.includes(`configured`)?`idle`:`active`}function SIe(e){return e===`completed`?`workflow.completed`:e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`node.session`}function W7(e){return e===`failed`?`workflow.failed`:e===`cancelled`?`workflow.cancelled`:`workflow.completed`}function CIe(e){return e===`failed`?`failed`:e===`cancelled`?`cancelled`:`completed`}function wIe(e){return e===`failed`?`WORKFLOW.FAIL`:e===`cancelled`?`WORKFLOW.CANCEL`:`WORKFLOW.NODE.DONE`}function G7({status:e}){return e===`completed`?(0,z.jsx)(Ko,{size:16,className:`text-emerald-300`}):e===`failed`?(0,z.jsx)(Jo,{size:16,className:`text-red-300`}):e===`cancelled`?(0,z.jsx)(Js,{size:16,className:`text-slate-400`}):e===`waiting`?(0,z.jsx)(Xo,{size:16,className:`text-amber-300`}):e===`active`?(0,z.jsx)(Co,{size:16,className:`text-[#11a4d4]`}):(0,z.jsx)(Yo,{size:16,className:`text-slate-500`})}function K7({tone:e,children:t}){return(0,z.jsx)(`span`,{className:`rounded border px-2 py-1 font-mono ${{blue:`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`,slate:`border-slate-700 bg-slate-900/50 text-slate-300`,green:`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`,amber:`border-amber-500/40 bg-amber-500/10 text-amber-300`,red:`border-red-500/40 bg-red-500/10 text-red-300`}[e]}`,children:t})}function TIe(e){return e===`completed`?`green`:e===`failed`||e===`cancelled`?`red`:e===`waiting`?`amber`:`blue`}function q7(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10`:e===`failed`?`border-red-500/40 bg-red-500/10`:e===`cancelled`?`border-slate-600 bg-slate-800/40`:e===`waiting`?`border-amber-500/40 bg-amber-500/10`:e===`active`?`border-[#11a4d4]/50 bg-[#11a4d4]/10 shadow-[0_0_0_1px_rgba(17,164,212,0.18)]`:`border-slate-800 bg-[#111820]`}function EIe(e){return e===`completed`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:e===`failed`||e===`cancelled`?`border-red-500/40 bg-red-500/10 text-red-300`:e===`waiting`?`border-amber-500/40 bg-amber-500/10 text-amber-300`:e===`active`?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function J7(e){let t=e.toLowerCase();return t.includes(`complete`)||t.includes(`done`)||t.includes(`transferred`)?`border-emerald-500/40 bg-emerald-500/10 text-emerald-300`:t.includes(`fail`)||t.includes(`error`)||t.includes(`cancel`)?`border-red-500/40 bg-red-500/10 text-red-300`:t.includes(`wait`)||t.includes(`blocked`)?`border-amber-500/40 bg-amber-500/10 text-amber-300`:t.includes(`run`)||t.includes(`active`)||t.includes(`workflow`)?`border-[#11a4d4]/40 bg-[#11a4d4]/10 text-[#11a4d4]`:`border-slate-700 bg-slate-900/50 text-slate-400`}function Y7(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}var X7=[{id:`terminal`,label:`Terminal`,description:`Compact Codex-style terminal transcript.`,render:e=>(0,z.jsx)(OFe,{...e})},{id:`workflow`,label:`Workflow`,description:`Workflow/XState visualization for workflow-backed project sessions.`,render:e=>(0,z.jsx)(KFe,{...e})}],Z7=new Map(X7.map(e=>[e.id,e]));function DIe(){return X7}function Q7(e){return Z7.get(e)??Z7.get(`terminal`)}function $7(e,t){return{localBootstrap:t,queryData:e.getQueriesData({queryKey:[`chat`,`bootstrap`]})}}function e9(e,t){return f9(e.sessions,t.piboSessionId)?e:{...e,sessions:[t,...e.sessions]}}function OIe(e,t){let n=t9(e.sessions,t),r=t.has(e.selectedPiboSessionId);return{...e,selectedPiboSessionId:r?``:e.selectedPiboSessionId,sessions:n}}function t9(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.piboSessionId)){n=!0;continue}let e=t9(i.children,t);e===i.children?r.push(i):(n=!0,r.push({...i,children:e}))}return n?r:e}function n9(e){let t=new Set([e.piboSessionId]);for(let n of e.children)for(let e of n9(n))t.add(e);return t}function kIe(e,t,n){if(!t)return e9(e,n);let r=!1,i=l9(e.sessions,t,()=>(r=!0,n));return{...e,selectedPiboSessionId:e.selectedPiboSessionId===t?n.piboSessionId:e.selectedPiboSessionId,session:e.session.id===t?d9(n,e.session):e.session,sessions:r?i:[n,...i]}}function r9(e,t){let n=typeof t.metadata?.chatWebArchivedAt==`string`;return{...e,session:e.session.id===t.id?t:e.session,sessions:l9(e.sessions,t.id,e=>({...e,profile:t.profile,activeModel:t.activeModel,title:t.title||e.title||`Untitled Session`,archived:n}))}}function i9(e,t,n){let r=e.session.id===t?d9(n(u9(e.session)),e.session):e.session;return{...e,session:r,sessions:l9(e.sessions,t,n)}}function AIe(e,t){return d3(e.rooms,t.id)?e:{...e,room:t,selectedRoomId:t.id,selectedPiboSessionId:``,rooms:[t,...e.rooms]}}function jIe(e,t,n){return{...e,room:e.room?.id===t?n:e.room,selectedRoomId:e.selectedRoomId===t?n.id:e.selectedRoomId,rooms:o9(e.rooms,t,()=>n)}}function a9(e,t,n){return{...e,room:e.room?.id===t?n(e.room):e.room,rooms:o9(e.rooms,t,n)}}function MIe(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:s9(e.rooms,t)}}function o9(e,t,n){let r=!1,i=e.map(e=>{if(e.id===t)return r=!0,n(e);let i=e.children??[],a=o9(i,t,n);return a===i?e:(r=!0,{...e,children:a})});return r?i:e}function s9(e,t){let n=!1,r=[];for(let i of e){if(t.has(i.id)){n=!0;continue}let e=i.children??[],a=s9(e,t);a===e?r.push(i):(n=!0,r.push({...i,children:a}))}return n?r:e}function NIe(e,t){let n=new Date().toISOString();return{id:e,name:t,type:`chat`,createdAt:n,updatedAt:n,metadata:{},children:[]}}function PIe(e,t){let n={...e.metadata};return t?n.chatRoomArchivedAt=new Date().toISOString():delete n.chatRoomArchivedAt,{...e,metadata:n,updatedAt:new Date().toISOString()}}function c9(e){let t=new Set([e.id]);for(let n of e.children??[])for(let e of c9(n))t.add(e);return t}function l9(e,t,n){let r=!1,i=e.map(e=>{if(e.piboSessionId===t)return r=!0,n(e);let i=l9(e.children,t,n);return i===e.children?e:(r=!0,{...e,children:i})});return r?i:e}function FIe(e,t){return{piboSessionId:e,piSessionId:`pending`,profile:t,title:`New Session`,status:`idle`,lastActivityAt:new Date().toISOString(),derivedSessions:[],children:[]}}function u9(e){return{piboSessionId:e.id,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:e.title||`Untitled Session`,archived:typeof e.metadata?.chatWebArchivedAt==`string`,status:`idle`,lastActivityAt:e.updatedAt,derivedSessions:[],children:[]}}function d9(e,t){return{...t,id:e.piboSessionId,piSessionId:e.piSessionId,profile:e.profile,activeModel:e.activeModel,title:s3(e),updatedAt:e.lastActivityAt??t.updatedAt}}function f9(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=f9(n.children,t);if(e)return e}}function IIe(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 LIe(e,t){if(e===`thinking`&&t)return{level:t.split(/\s+/,1)[0]};if(e===`compact`&&t)return{customInstructions:t}}function RIe(e){return!p9(e)||!p9(e.result)?null:e}function zIe(e){if(!(!p9(e)||!p9(e.result)))return typeof e.result.piboSessionId==`string`?e.result.piboSessionId:void 0}function p9(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function BIe(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 ~/.pibo/uploads.`},{slash:`/thinking-show`,action:`thinking-show`,description:`Toggle historical thinking display in this browser.`}),t}function VIe(e,t){if(!e)return[];let n=e.agentCatalog?.skills??[],r=e.agentCatalog?.userSkills??[],i=[...n,...r],a=Z4(e),o=t?$4(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 HIe(e,t){let n=e.area===`sessions`?e.roomId:void 0,r=e.area===`sessions`||e.area===`projects`||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 UIe(e){let{bootstrap:t,creatingSession:n,route:r}=e,i=r.area===`sessions`||r.area===`projects`||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 WIe(e,t){if(e.area===`sessions`&&t.selectedPiboSessionId&&!(e.roomId===t.selectedRoomId&&e.piboSessionId===t.selectedPiboSessionId))return t}function GIe(e){return e.area===`sessions`&&!!(e.roomId||e.piboSessionId)}function KIe({activePanel:e,onSelect:t,piPackageCount:n,userSkillCount:r}){return(0,z.jsx)(`div`,{className:`p-2`,children:(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Settings`}),(0,z.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,z.jsx)(Ws,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`General`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`browser + runtime`})]})]}),(0,z.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,z.jsx)(_s,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Shortcuts`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`keyboard`})]})]}),(0,z.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,z.jsx)(vs,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Pi Packages`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`runtime-packages`})]}),(0,z.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,z.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,z.jsx)(Zs,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Skills`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`user-managed`})]}),(0,z.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,z.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,z.jsx)(gs,{size:13,className:`text-[#11a4d4]`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate text-sm text-slate-200`,children:`Providers`}),(0,z.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-slate-500`,children:`auth + api keys`})]})]})]})})}var m9=[{id:`openai-codex`,name:`OpenAI (ChatGPT Plus/Pro)`,authMethod:`oauth`},{id:`openai`,name:`OpenAI (API Key)`,authMethod:`api_key`},{id:`anthropic`,name:`Anthropic (Claude)`,authMethod:`oauth`},{id:`github-copilot`,name:`GitHub Copilot`,authMethod:`oauth`},{id:`kimi-coding`,name:`Kimi for Coding`,authMethod:`api_key`},{id:`google`,name:`Google (Gemini)`,authMethod:`api_key`},{id:`groq`,name:`Groq`,authMethod:`api_key`},{id:`ollama`,name:`Ollama`,authMethod:`api_key`},{id:`minimax`,name:`MiniMax`,authMethod:`api_key`},{id:`minimax-cn`,name:`MiniMax (China)`,authMethod:`api_key`},{id:`glm`,name:`GLM (Z.ai)`,authMethod:`api_key`}];function qIe({piboSessionId:e,onProviderAuthChanged:t}){let[n,r]=(0,R.useState)({}),[i,a]=(0,R.useState)(!1),[o,s]=(0,R.useState)(null),[c,l]=(0,R.useState)(null),[u,d]=(0,R.useState)({}),[f,p]=(0,R.useState)({}),[m,h]=(0,R.useState)({}),[g,_]=(0,R.useState)({}),[v,y]=(0,R.useState)(null),[b,x]=(0,R.useState)({}),S=(0,R.useCallback)(async()=>{if(e){a(!0),s(null);try{let t=h9(await yc(e,`login.status`,{})),n={};if(Array.isArray(t?.providers))for(let e of t.providers){let t=e.id??e.provider;t&&(n[t]=e.configured)}r(n)}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}}},[e]);(0,R.useEffect)(()=>{S()},[S]);let C=(0,R.useCallback)(async t=>{if(e){x(e=>({...e,[t]:!0})),s(null),l(null),d(e=>({...e,[t]:{type:`oauth_starting`}}));try{let n=h9(await yc(e,`login.start`,{provider:t})),r=n.url,i=n.state;r?d(e=>({...e,[t]:{type:`oauth_flow`,url:r,state:i,userCode:n.userCode,instructions:n.instructions,flow:n.type}})):(s(`No URL returned from login start.`),d(e=>({...e,[t]:{type:`collapsed`}})))}catch(e){s(e instanceof Error?e.message:String(e)),d(e=>({...e,[t]:{type:`collapsed`}}))}finally{x(e=>({...e,[t]:!1}))}}},[e]),w=(0,R.useCallback)(async(n,i,a)=>{if(e){x(e=>({...e,[n]:!0})),s(null),l(null);try{await yc(e,`login.complete`,{provider:n,...i?{code:i}:{},state:a??``});let o=g9(n);l(`${o} login completed.`),r(e=>({...e,[n]:!0})),d(e=>({...e,[n]:{type:`collapsed`}})),p(e=>({...e,[n]:``})),await t?.(),window.setTimeout(()=>l(e=>e===`${o} login completed.`?null:e),5e3)}catch(e){s(e instanceof Error?e.message:String(e))}finally{x(e=>({...e,[n]:!1}))}}},[t,e]),T=(0,R.useCallback)(async(n,i)=>{if(e){x(e=>({...e,[n]:!0})),s(null),l(null);try{await yc(e,`login.apikey`,{provider:n,apiKey:i});let a=g9(n);l(`${a} API key saved.`),r(e=>({...e,[n]:!0})),d(e=>({...e,[n]:{type:`collapsed`}})),h(e=>({...e,[n]:``})),await t?.(),window.setTimeout(()=>l(e=>e===`${a} API key saved.`?null:e),5e3)}catch(e){s(e instanceof Error?e.message:String(e))}finally{x(e=>({...e,[n]:!1}))}}},[t,e]),E=(0,R.useCallback)(async n=>{if(e){x(e=>({...e,[n]:!0})),s(null),l(null);try{await yc(e,`logout`,{provider:n}),r(e=>({...e,[n]:!1})),await t?.()}catch(e){s(e instanceof Error?e.message:String(e))}finally{x(e=>({...e,[n]:!1}))}}},[t,e]),D=async e=>{try{await navigator.clipboard.writeText(e),y(e),setTimeout(()=>y(null),2e3)}catch{}};return e?(0,z.jsxs)(`div`,{className:`grid gap-4`,children:[o?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-red-500/30 bg-red-500/10 px-3 py-2 text-xs text-red-300`,children:[(0,z.jsx)(Go,{size:14}),o]}):null,c?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-sm border border-[#0bda57]/30 bg-[#0bda57]/10 px-3 py-2 text-xs text-[#7cf2a2]`,children:[(0,z.jsx)(qo,{size:14}),c]}):null,i?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-[#11a4d4]`,children:[(0,z.jsx)(Cs,{size:14,className:`animate-spin`}),`Loading provider status...`]}):null,m9.map(e=>{let t=n[e.id]??!1,r=u[e.id]??{type:`collapsed`},i=b[e.id]??!1;return(0,z.jsxs)(`div`,{className:`border rounded-sm ${r.type===`collapsed`?t?`border-[#0bda57]/20 bg-[#151f24]`:`border-[#334155] bg-[#151f24] hover:border-slate-600`:`border-[#11a4d4]/50 bg-[#151f24]`}`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 p-3`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-sm font-medium text-slate-200`,children:e.name}),(0,z.jsx)(`span`,{className:`shrink-0 border px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wider ${e.authMethod===`oauth`?`border-purple-500/40 text-purple-300`:`border-amber-500/40 text-amber-300`}`,children:e.authMethod===`oauth`?`OAuth`:`API Key`})]}),(0,z.jsx)(`div`,{className:`mt-1 flex items-center gap-1.5 text-xs`,children:t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(qo,{size:12,className:`text-[#0bda57]`}),(0,z.jsx)(`span`,{className:`text-[#0bda57]`,children:`Configured`})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(Ts,{size:12,className:`text-slate-500`}),(0,z.jsx)(`span`,{className:`text-slate-500`,children:`Not configured`})]})})]}),(0,z.jsx)(`div`,{className:`flex items-center gap-2`,children:t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>d(t=>({...t,[e.id]:t[e.id]?.type===`collapsed`?e.authMethod===`oauth`?{type:`oauth_starting`}:{type:`api_key`}:{type:`collapsed`}})),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(gs,{size:12}),`Reconfigure`]}),(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void E(e.id),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-1.5 text-[11px] text-slate-300 hover:border-red-500 hover:text-red-300 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:12}),`Remove`]})]}):(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>e.authMethod===`oauth`?void C(e.id):d(t=>({...t,[e.id]:{type:`api_key`}})),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2.5 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(gs,{size:12}),`Configure`]})})]}),r.type===`collapsed`?null:(0,z.jsx)(`div`,{className:`border-t border-slate-800 p-3`,children:r.type===`oauth_starting`?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-[#11a4d4]`,children:[(0,z.jsx)(Cs,{size:14,className:`animate-spin`}),`Starting OAuth flow...`]}):r.type===`oauth_flow`?(0,z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Step 1: Open URL`}),(0,z.jsx)(`div`,{className:`break-all rounded-sm border border-slate-700 bg-[#0e1116] p-2 font-mono text-[11px] text-slate-300`,children:r.url}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void D(r.url),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:[v===r.url?(0,z.jsx)(qo,{size:12}):(0,z.jsx)($o,{size:12}),v===r.url?`Copied`:`Copy URL`]}),(0,z.jsxs)(`a`,{href:r.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:[(0,z.jsx)(rs,{size:12}),`Open in Browser`]})]})]}),r.userCode?(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Step 2: Enter Code`}),(0,z.jsx)(`div`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] p-3 text-center font-mono text-[20px] font-bold tracking-widest text-[#11a4d4]`,children:r.userCode}),r.instructions?(0,z.jsx)(`div`,{className:`text-[11px] leading-relaxed text-slate-500`,children:r.instructions}):null,(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>void w(e.id,void 0,r.state),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ts,{size:12}),`Complete Login`]})]}):(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Step 2: Paste Code`}),(0,z.jsx)(`input`,{type:`text`,value:f[e.id]??``,onChange:t=>p(n=>({...n,[e.id]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&(f[e.id]??``).trim()&&w(e.id,f[e.id].trim(),r.state)},placeholder:`Paste authorization code...`,className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1.5 font-mono text-[12px] text-slate-300 placeholder-slate-600 outline-none focus:border-[#11a4d4]`}),(0,z.jsxs)(`button`,{type:`button`,disabled:i||!(f[e.id]??``).trim(),onClick:()=>void w(e.id,f[e.id].trim(),r.state),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ts,{size:12}),`Complete Login`]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>d(t=>({...t,[e.id]:{type:`collapsed`}})),className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`← Cancel`})]}):r.type===`api_key`?(0,z.jsxs)(`div`,{className:`grid gap-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Enter API Key`}),(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`input`,{type:g[e.id]?`text`:`password`,value:m[e.id]??``,onChange:t=>h(n=>({...n,[e.id]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&(m[e.id]??``).trim()&&T(e.id,m[e.id].trim())},placeholder:`sk-...`,className:`w-full rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1.5 pr-8 font-mono text-[12px] text-slate-300 placeholder-slate-600 outline-none focus:border-[#11a4d4]`}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>_(t=>({...t,[e.id]:!t[e.id]})),className:`absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-[#11a4d4]`,title:g[e.id]?`Hide`:`Show`,children:g[e.id]?(0,z.jsx)(is,{size:14}):(0,z.jsx)(as,{size:14})})]}),(0,z.jsxs)(`button`,{type:`button`,disabled:i||!(m[e.id]??``).trim(),onClick:()=>void T(e.id,m[e.id].trim()),className:`inline-flex items-center gap-1 rounded-sm border border-slate-700 bg-[#0e1116] px-3 py-1.5 text-[11px] text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:[i?(0,z.jsx)(Cs,{size:12,className:`animate-spin`}):(0,z.jsx)(Ts,{size:12}),`Save API Key`]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>d(t=>({...t,[e.id]:{type:`collapsed`}})),className:`text-[11px] text-slate-500 hover:text-[#11a4d4]`,children:`← Cancel`})]}):null})]},e.id)})]}):(0,z.jsx)(`div`,{className:`border border-slate-700 bg-[#1a262b] rounded-sm p-4 text-sm text-slate-400`,children:`Select a chat session to manage provider authentication.`})}function h9(e){return JIe(e)?e.result:e}function JIe(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.type===`execution_result`}function g9(e){return m9.find(t=>t.id===e)?.name??e}function YIe({activePanel:e,showThinking:t,setShowThinking:n,expandThinking:r,setExpandThinking:i,modelDefaults:a,modelCatalog:o,onModelDefaultsChanged:s,piPackages:c,onPiPackageChanged:l,onPiPackageRemoved:u,userSkills:d,onUserSkillChanged:f,onUserSkillRemoved:p,piboSessionId:m,onProviderAuthChanged:h}){return e===`pi-packages`?(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(vs,{size:16}),`Pi Packages`]}),(0,z.jsx)(iLe,{packages:c,onPackageChanged:l,onPackageRemoved:u})]}):e===`skills`?(0,z.jsxs)(`div`,{className:`overflow-auto p-6 max-[640px]:p-3`,children:[(0,z.jsxs)(`h1`,{className:`mb-4 flex items-center gap-2 text-sm font-bold uppercase tracking-wider`,children:[(0,z.jsx)(Zs,{size:16}),`Skills`]}),(0,z.jsx)(aLe,{skills:d,onSkillChanged:f,onSkillRemoved:p})]}):e===`providers`?(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(gs,{size:16}),`Providers`]}),(0,z.jsx)(qIe,{piboSessionId:m,onProviderAuthChanged:h})]}):e===`shortcuts`?(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(_s,{size:16}),`Shortcuts`]}),(0,z.jsx)(QIe,{})]}):(0,z.jsxs)(`div`,{className:`p-6 overflow-auto`,children:[(0,z.jsxs)(`h1`,{className:`text-sm font-bold uppercase tracking-wider mb-4 flex items-center gap-2`,children:[(0,z.jsx)(Ws,{size:16}),`General`]}),(0,z.jsxs)(O0,{title:`General`,children:[(0,z.jsx)(ZIe,{}),(0,z.jsx)(N0,{checked:t,title:`Show thinking blocks`,onToggle:()=>{let e=!t;n(e),n2(e)}}),(0,z.jsx)(N0,{checked:r,disabled:!t,title:`Expand thinking blocks`,onToggle:()=>{let e=!r;i(e),r2(e)}}),(0,z.jsx)(rLe,{modelDefaults:a,modelCatalog:o,onChanged:s})]})]})}var XIe=`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 ZIe(){let e=Yt(),{data:t,isLoading:n}=dn({queryKey:[`user-settings`],queryFn:Zz}),r=(0,R.useMemo)(()=>eLe(t?.timezone),[t?.timezone]),[i,a]=(0,R.useState)(`UTC`),[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(null);(0,R.useEffect)(()=>{t?.timezone&&a(t.timezone)},[t?.timezone]);let u=async(t=i)=>{s(!0),l(null);try{let n=await Qz({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,z.jsxs)(`div`,{className:`border-b border-slate-800 pb-4 mb-4`,children:[(0,z.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-slate-400`,children:`App timezone`}),(0,z.jsx)(`div`,{className:`max-w-xl`,children:(0,z.jsx)(`select`,{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,z.jsx)(`option`,{value:e.value,children:e.label},e.value))})}),(0,z.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,z.jsx)(`div`,{className:`mt-2 text-xs text-slate-400`,children:`Saving…`}):null,c?(0,z.jsx)(`div`,{className:`mt-2 text-xs text-red-300`,children:c}):null]})}function QIe(){let e=Yt(),{data:t,isLoading:n}=dn({queryKey:[`user-settings`],queryFn:Zz}),[r,i]=(0,R.useState)(S2),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(!1),[l,u]=(0,R.useState)(null);(0,R.useEffect)(()=>{let e=t?.shortcuts?.webAnnotationsToggle||C2();i(e),w2(e),T2(e)},[t?.shortcuts?.webAnnotationsToggle]);let d=async t=>{let n=E2(t)||`Alt+Shift+A`;i(n),c(!0),u(null);try{let t=await Qz({shortcuts:{webAnnotationsToggle:n}});e.setQueryData([`user-settings`],t),w2(t.shortcuts.webAnnotationsToggle),T2(t.shortcuts.webAnnotationsToggle)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}};return(0,z.jsx)(O0,{title:`Shortcuts`,children:(0,z.jsxs)(`div`,{className:`grid max-w-2xl gap-3 rounded-sm border border-slate-800 bg-[#151f24] p-3`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-slate-200`,children:[(0,z.jsx)(Ao,{size:15}),` Toggle annotation mode`]}),(0,z.jsx)(`div`,{className:`mt-1 text-xs text-slate-500`,children:`Toggles the Web Annotation element mode with the pencil button.`})]}),(0,z.jsx)(`kbd`,{className:`rounded-sm border border-slate-700 bg-[#0e1116] px-2 py-1 font-mono text-xs text-[#7dd3fc]`,children:r})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,disabled:n||s,"aria-pressed":a,onClick:()=>o(e=>!e),onKeyDown:e=>{if(!a)return;let t=$Ie(e);t&&(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,z.jsx)(`button`,{type:`button`,disabled:s||r===`Alt+Shift+A`,onClick:()=>void d(S2),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,z.jsx)(`span`,{className:`text-xs text-slate-400`,children:`Saving…`}):null]}),(0,z.jsxs)(`div`,{className:`text-[11px] text-slate-500`,children:[`Default: `,S2,`. Use a modifier combination to avoid conflicts with normal typing.`]}),l?(0,z.jsx)(`div`,{className:`text-xs text-red-300`,children:l}):null]})})}function $Ie(e){if([`Alt`,`Control`,`Meta`,`Shift`].includes(e.key))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 eLe(e){let t=new Set([`UTC`,...Intl.supportedValuesOf?.(`timeZone`)??XIe]);return e&&t.add(e),[...t].map(e=>({value:e,label:tLe(e),offset:nLe(e)})).sort((e,t)=>e.offset-t.offset||e.label.localeCompare(t.label)).map(({value:e,label:t})=>({value:e,label:t}))}function tLe(e){let t=e===`UTC`?`UTC`:e.split(`/`).pop()?.replaceAll(`_`,` `)??e,n=e.includes(`/`)?e.split(`/`)[0].replaceAll(`_`,` `):void 0,r=_9(e);return`${t}${n?` (${n})`:``} — ${r}`}function _9(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 nLe(e){let t=_9(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 rLe({modelDefaults:e,modelCatalog:t,onChanged:n}){let[r,i]=(0,R.useState)(e??{}),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(null);(0,R.useEffect)(()=>{i(e??{})},[e]);let l=async e=>{i(e),o(!0);try{n(await Vge(e)),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{o(!1)}};return(0,z.jsxs)(`div`,{className:`grid gap-3 border-t border-slate-800 pt-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Runtime Model Defaults`}),(0,z.jsx)(I0,{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,z.jsx)(I0,{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,z.jsx)(`div`,{className:`text-xs text-amber-100`,children:s}):null]})}function iLe({packages:e,onPackageChanged:t,onPackageRemoved:n}){let[r,i]=(0,R.useState)(``),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),[l,u]=(0,R.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 KW(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 qW(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 JW(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,z.jsxs)(O0,{title:`Pi Package Management`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,z.jsx)(`input`,{value:r,disabled:!e||a===`add`,onChange:e=>i(e.target.value),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,z.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,z.jsx)(Ps,{size:14})})]}),(0,z.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Extensions execute code in the Pi runtime. Review package source before adding it.`}),s?(0,z.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,z.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,z.jsx)(`div`,{className:`grid gap-2`,children:d.map(e=>(0,z.jsx)(sLe,{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,z.jsx)(F0,{message:`No Pi packages registered`}):(0,z.jsx)(F0,{})]})}function aLe({skills:e,onSkillChanged:t,onSkillRemoved:n}){let[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(null),[l,u]=(0,R.useState)(``),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),h=e??[],g=h.filter(e=>e.enabled).length,_=async e=>{if(!d){f(`${e.id}:enabled`);try{t(await ZW(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 QW(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 XW(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 $W(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 ZW(e,n)),c(null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(null)}};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(O0,{title:`Skill Management`,children:[(0,z.jsxs)(`div`,{className:`grid gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.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,z.jsx)(Ps,{size:14}),`Create Skill`]}),(0,z.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,z.jsx)(rs,{size:14}),`Install from URL`]})]}),p?(0,z.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,z.jsxs)(`div`,{className:`font-mono text-[10px] uppercase tracking-wider text-slate-500`,children:[h.length,` skills / `,g,` enabled`]})]}),e?h.length?(0,z.jsx)(`div`,{className:`grid gap-2`,children:h.map(e=>(0,z.jsx)(`div`,{className:`border rounded-sm p-2 ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 max-[640px]:items-start`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,z.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,z.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,z.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description||e.path})]}),(0,z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void _(e),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,z.jsx)(Fs,{size:13}):(0,z.jsx)(Is,{size:13})}),(0,z.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:async()=>{try{let t=await YW(e.id);c(e),u(t.markdown)}catch{c(e),u(``)}},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,z.jsx)(Ms,{size:13})}),(0,z.jsx)(`button`,{type:`button`,disabled:d?.startsWith(`${e.id}:`)??!1,onClick:()=>void v(e),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,z.jsx)(qs,{size:13})})]})]})},e.id))}):(0,z.jsx)(F0,{message:`No user skills`}):(0,z.jsx)(F0,{})]}),r?(0,z.jsx)(y9,{title:`Create Skill`,onSave:y,onClose:()=>i(!1),busy:d===`create`}):null,a?(0,z.jsx)(oLe,{onInstall:b,onClose:()=>o(!1),busy:d===`install`}):null,s?(0,z.jsx)(y9,{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 v9({children:e,onClose:t}){return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:[(0,z.jsx)(`div`,{className:`w-full max-w-2xl rounded-sm border border-slate-700 bg-[#151f24] shadow-2xl`,children:e}),(0,z.jsx)(`button`,{type:`button`,className:`absolute inset-0 -z-10`,onClick:t,"aria-label":`Close modal`})]})}function y9({title:e,initialName:t=``,initialDescription:n=``,initialMarkdown:r=``,onSave:i,onClose:a,busy:o}){let[s,c]=(0,R.useState)(t),[l,u]=(0,R.useState)(n),[d,f]=(0,R.useState)(r);return(0,z.jsxs)(v9,{onClose:a,children:[(0,z.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,z.jsx)(Ms,{size:16}),e]}),(0,z.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,z.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,z.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,z.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,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.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,z.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 oLe({onInstall:e,onClose:t,busy:n}){let[r,i]=(0,R.useState)(``);return(0,z.jsxs)(v9,{onClose:t,children:[(0,z.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,z.jsx)(rs,{size:16}),`Install Skill`]}),(0,z.jsxs)(`div`,{className:`grid gap-3 p-4`,children:[(0,z.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,z.jsx)(`div`,{className:`text-[11px] text-slate-500`,children:`Supports skills.sh URLs, GitHub tree URLs, or account/repo shorthand.`}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.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,z.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 sLe({pkg:e,expanded:t,busy:n,onToggleExpanded:r,onToggleEnabled:i,onUnregister:a}){let o=e.diagnostics.some(e=>e.type===`error`);return(0,z.jsxs)(`div`,{className:`border rounded-sm ${e.enabled?`border-slate-800 bg-[#151f24]`:`border-slate-800 bg-[#151f24] opacity-75`}`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2 p-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-sm text-slate-200`,children:e.name}),(0,z.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,z.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,z.jsx)(`div`,{className:`truncate text-xs text-slate-500`,children:e.description??e.source}),(0,z.jsx)(`div`,{className:`font-mono text-[10px] mt-1 ${o?`text-[#f59e0b]`:`text-[#11a4d4]`}`,children:E0(e)})]}),(0,z.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,z.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,z.jsx)(zo,{size:13}):(0,z.jsx)(Bo,{size:13})}),(0,z.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,z.jsx)(Fs,{size:13}):(0,z.jsx)(Is,{size:13})}),(0,z.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,z.jsx)(qs,{size:13})})]})]}),t?(0,z.jsx)(j0,{pkg:e}):null]})}function cLe({data:e,selectedProject:t,selectedPiboSessionId:n,selectedProjectSession:r,workflowProjectSessions:i,activeProjects:a,archivedProjects:o,sessionGroups:s,selectedSessionPathIds:c,autoRenameSessionId:l,creatingSession:u,showArchivedProjects:d,showArchivedSessions:f,mobileSidebarOpen:p,onRefresh:m,onCloseMobileSidebar:h,onCreateProject:g,onToggleArchivedProjects:_,onSelectProject:v,onRenameProject:y,onSetProjectArchived:b,onDeleteArchivedProject:x,onCreateProjectSession:S,onToggleArchivedSessions:C,onSelectSession:w,onRenameSession:T,onArchiveSession:E,onDeleteSession:D,onViewContext:O,onAutoRenameConsumed:k}){let A=Date.now();return(0,z.jsxs)(`aside`,{className:`min-h-0 overflow-auto bg-[#1a262b] border-r border-slate-800 max-[980px]:fixed max-[980px]:left-0 max-[980px]:top-0 max-[980px]:bottom-0 max-[980px]:z-40 max-[980px]:w-[280px] max-[980px]:transition-transform max-[980px]:duration-200 ${p?`max-[980px]:translate-x-0`:`max-[980px]:-translate-x-full`}`,children:[(0,z.jsxs)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center justify-between text-xs font-bold uppercase tracking-wider max-[980px]:h-auto max-[980px]:py-2`,children:[(0,z.jsx)(`span`,{children:`projects`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:m,title:`Refresh`,"aria-label":`Refresh`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ls,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:h,title:`Close sidebar`,"aria-label":`Close sidebar`,className:`min-[981px]:hidden p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Qs,{size:13})})]})]}),(0,z.jsxs)(`div`,{className:`p-2 space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Shared Chat`}),(0,z.jsx)(x9,{project:e.sharedDefaultProject,selected:t?.id===e.sharedDefaultProject.id,onSelect:()=>v(e.sharedDefaultProject.id)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Projects`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:g,title:`New Project`,"aria-label":`New Project`,className:`h-6 w-6 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:_,title:`Archived Projects`,"aria-label":`Archived Projects`,className:`h-6 w-6 inline-flex items-center justify-center border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${d?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:d?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),a.map(e=>(0,z.jsx)(x9,{project:e,selected:t?.id===e.id,onSelect:()=>v(e.id),onRename:t=>y(e,t),onArchive:()=>b(e,!0)},e.id)),a.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No projects`}):null,d?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Projects`}),o.map(e=>(0,z.jsx)(x9,{project:e,selected:t?.id===e.id,onSelect:()=>v(e.id),onRename:t=>y(e,t),onArchive:()=>b(e,!1),onDelete:()=>x(e),archived:!0},e.id))]}):null]}),i.length>0?(0,z.jsx)(lLe,{projectSessions:i,sessionNodes:e.sessions,selectedPiboSessionId:n,onSelect:w}):null,(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Project Sessions`}),(0,z.jsx)(`div`,{className:`text-[10px] text-slate-500`,children:r?Gke(r):`Workflow: simple-chat`})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:S,disabled:u||!t,title:`New Project Session`,"aria-label":`New Project Session`,className:`h-6 w-6 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,z.jsx)(Ps,{size:14})}),(0,z.jsx)(`button`,{type:`button`,onClick:C,title:f?`Hide Archived Project Sessions`:`Show Archived Project Sessions`,"aria-label":f?`Hide Archived Project Sessions`:`Show Archived Project Sessions`,className:`h-6 w-6 inline-flex items-center justify-center border rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4] ${f?`border-[#11a4d4] text-[#11a4d4]`:`border-slate-700 text-slate-400`}`,children:f?(0,z.jsx)(wo,{size:14}):(0,z.jsx)(To,{size:14})})]})]}),s.active.map(e=>(0,z.jsx)(h3,{node:e,signalNow:A,selectedPiboSessionId:n,selectedSessionPathIds:c,onSelect:w,onRename:T,onArchive:E,onDelete:D,onViewContext:O,loadingPiboSessionId:null,autoRename:l===e.piboSessionId,onAutoRenameConsumed:k,showWorkflowSessionKindMarkers:!0},e.piboSessionId)),s.active.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No active project sessions`}):null,f?(0,z.jsxs)(`div`,{className:`mt-3`,children:[(0,z.jsx)(`div`,{className:`px-1 pb-1 text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Archived Project Sessions`}),s.archived.map(e=>(0,z.jsx)(h3,{node:e,signalNow:A,selectedPiboSessionId:n,selectedSessionPathIds:c,onSelect:w,onRename:T,onArchive:E,onDelete:D,onViewContext:O,loadingPiboSessionId:null,showWorkflowSessionKindMarkers:!0},e.piboSessionId)),s.archived.length===0?(0,z.jsx)(`div`,{className:`px-2 py-3 text-xs text-slate-500 border border-dashed border-slate-700 rounded-sm`,children:`No archived project sessions`}):null]}):null]})]})]})}function b9(e,t){for(let n of e){if(n.piboSessionId===t)return n;let e=b9(n.children,t);if(e)return e}}function lLe({projectSessions:e,sessionNodes:t,selectedPiboSessionId:n,onSelect:r}){return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1 pb-1`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wider text-slate-500`,children:`Workflow Runs`}),(0,z.jsx)(`div`,{className:`text-[10px] text-slate-500`,children:e.length})]}),(0,z.jsx)(`div`,{className:`space-y-1`,children:e.map(e=>{let i=b9(t,e.piboSessionId),a=i?s3(i):e.title??e.piboSessionId,o=e.piboSessionId===n,s=V2(e,i?.status);return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(e.piboSessionId),className:`w-full text-left rounded-sm border px-2 py-2 transition-colors ${o?`border-[#11a4d4] bg-[#11a4d4]/10`:`border-slate-800 hover:border-slate-700 hover:bg-slate-800/40`}`,title:e.workflowRunId??e.workflowId,children:[(0,z.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 text-xs font-medium text-slate-200 truncate`,children:a}),(0,z.jsx)(`span`,{className:Jke(e,i?.status),children:s})]}),(0,z.jsx)(`span`,{className:`mt-1 block text-[10px] text-slate-500 truncate`,children:e.workflowId}),e.workflowRunId?(0,z.jsxs)(`span`,{className:`block text-[10px] font-mono text-slate-500 truncate`,children:[`run `,U2(e.workflowRunId)]}):null]},`${e.workflowRunId??e.piboSessionId}:${e.piboSessionId}`)})})]})}function x9({project:e,selected:t,archived:n,onSelect:r,onRename:i,onArchive:a,onDelete:o}){let s=e.metadata?.default===!0||e.metadata?.personal===!0,[c,l]=(0,R.useState)(!1),[u,d]=(0,R.useState)(e.name),[f,p]=(0,R.useState)(!1),m=(0,R.useRef)(null),h=(0,R.useRef)(null);(0,R.useEffect)(()=>{c||d(e.name)},[c,e.name]),(0,R.useEffect)(()=>{if(!f)return;let e=e=>{h.current&&!h.current.contains(e.target)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]),(0,R.useLayoutEffect)(()=>{c&&(m.current?.focus(),m.current?.select())},[c]);let g=()=>{let t=u.trim();t&&t!==e.name&&i?.(t),l(!1)};return(0,z.jsxs)(`div`,{className:`group flex items-center gap-2 rounded-sm border px-2 py-2 text-sm ${s?t?`border-[#0bda57] bg-[#0bda57]/10 text-green-100`:`border-[#0bda57]/50 bg-[#0bda57]/5 text-slate-300 hover:border-[#0bda57]`:t?`border-[#11a4d4] bg-[#11a4d4]/10 text-sky-100`:`border-transparent text-slate-300 hover:border-slate-700 hover:bg-slate-900/40`}`,children:[(0,z.jsx)(`span`,{className:`h-6 w-6 shrink-0 inline-flex items-center justify-center rounded-sm ${s?`bg-[#0bda57]/15 text-[#0bda57]`:n?`bg-[#f59e0b]/15 text-[#f59e0b]`:`bg-[#151f24] text-slate-500`}`,children:s?(0,z.jsx)(Ts,{size:13}):n?(0,z.jsx)(To,{size:13}):(0,z.jsx)(ls,{size:13})}),c?(0,z.jsxs)(`form`,{className:`min-w-0 flex-1 grid grid-cols-[1fr_auto_auto] gap-1`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,z.jsx)(`input`,{ref:m,value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Escape`&&(t.preventDefault(),l(!1),d(e.name))},className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-2 py-1 text-sm outline-none focus:border-[#11a4d4]`}),(0,z.jsx)(`button`,{type:`submit`,title:`Save Project Name`,"aria-label":`Save Project 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]`,children:(0,z.jsx)(Ro,{size:13})}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>{l(!1),d(e.name)},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,z.jsx)(Qs,{size:13})})]}):(0,z.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 flex-1 text-left`,children:[(0,z.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,z.jsx)(`span`,{className:`block truncate text-[11px] text-slate-500`,children:s?`shared default project chat`:e.projectFolder})]}),s?(0,z.jsx)(`span`,{title:`Shared Chat is locked`,"aria-label":`Shared Chat is locked`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-[#0bda57]/50 rounded-sm text-[#0bda57]`,children:(0,z.jsx)(Ts,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}):c?null:(0,z.jsxs)(`div`,{className:`relative opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity max-[980px]:opacity-100`,ref:h,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),title:`Project actions`,"aria-label":`Project actions`,className:`h-7 w-7 max-[980px]:h-9 max-[980px]:w-9 inline-flex items-center justify-center border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(ns,{size:24,className:`w-3.5 h-3.5 max-[980px]:w-5 max-[980px]:h-5`})}),f?(0,z.jsxs)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-48 bg-[#1a262b] border border-slate-700 rounded-sm shadow-lg py-1`,children:[i?(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{p(!1),l(!0)},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[(0,z.jsx)(Ms,{size:16}),` Rename Project`]}):null,a?(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{p(!1),a()},className:`w-full text-left px-3 py-2.5 text-sm text-slate-300 hover:bg-[#11a4d4]/10 hover:text-[#11a4d4] flex items-center gap-2`,children:[n?(0,z.jsx)(wo,{size:16}):(0,z.jsx)(To,{size:16}),` `,n?`Restore Project`:`Archive Project`]}):null,o?(0,z.jsxs)(`button`,{type:`button`,onClick:()=>{p(!1),o()},className:`w-full text-left px-3 py-2.5 text-sm text-red-300 hover:bg-red-500/10 flex items-center gap-2`,children:[(0,z.jsx)(qs,{size:16}),` Delete Project`]}):null]}):null]})]})}function uLe({project:e,options:t,selectedOptionKey:n,titleValue:r,loadState:i,errorMessage:a,creating:o,diagnostics:s,onSelectedOptionChange:c,onTitleChange:l,onCreate:u}){let d=t.find(e=>w9(e)===n),f=o||i!==`loaded`||!d||!!e.archivedAt;return(0,z.jsxs)(`section`,{className:`rounded-sm border border-slate-800 bg-[#151f24] p-4 shadow-lg shadow-black/10`,"aria-labelledby":`project-workflow-create-title`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 max-w-2xl`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(vs,{size:13}),`Workflow-backed session`]}),(0,z.jsx)(`h2`,{id:`project-workflow-create-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:`Create workflow Project session`}),(0,z.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-slate-500`,children:`Choose a published workflow version from the global catalog and save a configured Project session. Creation does not start a workflow run.`})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/80 px-2 py-1 text-[11px] uppercase tracking-wide text-slate-500`,children:[`Project: `,(0,z.jsx)(`span`,{className:`text-slate-300`,children:e.name})]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)_auto] md:items-end`,children:[(0,z.jsxs)(`label`,{className:`grid gap-1.5 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Workflow version`}),(0,z.jsxs)(`select`,{"aria-label":`Workflow version`,className:`rounded-sm border border-slate-700 bg-[#101d22] px-3 py-2 text-sm text-slate-100 outline-none transition focus:border-[#11a4d4] disabled:opacity-60`,value:n,onChange:e=>c(e.target.value),disabled:o||i!==`loaded`,children:[(0,z.jsx)(`option`,{value:``,children:`Select a workflow version`}),t.map(e=>(0,z.jsx)(`option`,{value:w9(e),children:yLe(e)},w9(e)))]})]}),(0,z.jsxs)(`label`,{className:`grid gap-1.5 text-xs font-semibold text-slate-300`,children:[(0,z.jsx)(`span`,{children:`Session name`}),(0,z.jsx)(`input`,{"aria-label":`Workflow session name`,className:`rounded-sm border border-slate-700 bg-[#101d22] px-3 py-2 text-sm text-slate-100 outline-none transition placeholder:text-slate-600 focus:border-[#11a4d4] disabled:opacity-60`,value:r,onChange:e=>l(e.target.value),placeholder:`Optional`,disabled:o})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:u,disabled:f,className:`inline-flex min-h-10 items-center justify-center gap-2 rounded-sm border border-[#11a4d4]/60 bg-[#11a4d4]/10 px-3 py-2 text-xs font-bold uppercase tracking-wide text-[#11a4d4] transition hover:bg-[#11a4d4]/15 disabled:cursor-not-allowed disabled:border-slate-700 disabled:bg-slate-900/40 disabled:text-slate-500`,children:[o?(0,z.jsx)(Cs,{size:14,className:`animate-spin`}):(0,z.jsx)(Bs,{size:14}),`Save configured session`]})]}),d?(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-slate-800 bg-[#101d22]/70 p-3 text-xs leading-5 text-slate-500`,children:[(0,z.jsx)(`span`,{className:`font-semibold text-slate-300`,children:d.title}),` `,(0,z.jsxs)(`span`,{className:`font-mono text-slate-400`,children:[d.id,`@`,d.version]}),d.description?(0,z.jsxs)(`span`,{children:[` — `,d.description]}):null]}):null,(0,z.jsx)(fLe,{}),i===`loading`?(0,z.jsx)(`div`,{className:`mt-3 text-xs text-slate-500`,children:`Loading workflow catalog…`}):null,i===`error`?(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border border-red-900/70 bg-red-950/40 p-3 text-xs text-red-200`,role:`alert`,children:a??`Failed to load workflow catalog.`}):null,s.length?(0,z.jsx)(dLe,{label:`Create-blocking diagnostics`,diagnostics:s}):null]})}function dLe({label:e,diagnostics:t}){return(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-red-500/40 bg-red-500/10 p-3 text-xs text-red-100`,role:`alert`,"aria-label":e,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-red-200`,children:[(0,z.jsx)(Js,{size:12}),e]}),(0,z.jsx)(`div`,{className:`mt-2 space-y-2`,children:t.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-[#0b0f14]/60 p-2`,children:[(0,z.jsx)(`div`,{className:`break-words text-red-100`,children:e.message??e.code??`Workflow validation blocked this action.`}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[e.code?(0,z.jsx)(`span`,{children:e.code}):null,e.path?(0,z.jsx)(`span`,{children:e.path}):null,e.nodeId?(0,z.jsxs)(`span`,{children:[`node:`,e.nodeId]}):null,e.edgeId?(0,z.jsxs)(`span`,{children:[`edge:`,e.edgeId]}):null,e.registryRef?(0,z.jsx)(`span`,{children:e.registryRef}):null]}),e.hint?(0,z.jsx)(`div`,{className:`mt-1 text-[11px] text-red-100/75`,children:e.hint}):null]},`${e.code??`diagnostic`}:${e.path??e.registryRef??e.nodeId??e.edgeId??t}`))})]})}function fLe(){return(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-amber-700/60 bg-amber-950/15 p-3 text-[11px] leading-5 text-amber-100/80`,"aria-label":`Project workflow V2 explicit non-goals`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-amber-200`,children:[(0,z.jsx)(Ts,{size:12}),`V2 scope boundary`]}),(0,z.jsx)(`p`,{className:`mt-2`,children:`Project workflow sessions select published catalog versions and save configured sessions only. They do not expose workflow templates, workflow slash commands, workflow tools for agents, inline TypeScript/JavaScript/shell/eval code, raw XState editing, TypeScript export, YAML/JSON product import/export, or Zod schema authoring.`})]})}function pLe({projectSession:e,lifecycleEvents:t,starting:n,message:r,onStart:i}){let a=mLe(e),o=_Le(hLe(e.piboSessionId,t)),s=gLe(e.piboSessionId,t),c=vLe(r);return(0,z.jsxs)(`section`,{className:`rounded-sm border border-[#11a4d4]/35 bg-[#111820] p-4 shadow-lg shadow-black/10`,"aria-labelledby":`project-workflow-start-title`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 max-w-2xl`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-[#11a4d4]`,children:[(0,z.jsx)(Is,{size:13}),`Configured/not-started`]}),(0,z.jsx)(`h2`,{id:`project-workflow-start-title`,className:`mt-1 text-sm font-bold text-slate-100`,children:`Ready to start workflow`}),(0,z.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-slate-500`,children:`This Project session is saved for review. Start explicitly when the configuration is ready.`})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:i,disabled:n,className:`inline-flex min-h-10 items-center justify-center gap-2 rounded-sm border border-emerald-500/60 bg-emerald-500/10 px-3 py-2 text-xs font-bold uppercase tracking-wide text-emerald-300 transition hover:bg-emerald-500/15 disabled:cursor-not-allowed disabled:border-slate-700 disabled:bg-slate-900/40 disabled:text-slate-500`,children:[n?(0,z.jsx)(Cs,{size:14,className:`animate-spin`}):(0,z.jsx)(Is,{size:14}),`Start workflow`]})]}),(0,z.jsxs)(`div`,{className:`mt-4 grid gap-2 text-xs md:grid-cols-2 xl:grid-cols-4`,children:[(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Workflow`}),(0,z.jsx)(`div`,{className:`mt-1 truncate font-mono text-slate-300`,title:e.workflowId,children:e.workflowId}),e.workflowVersion?(0,z.jsxs)(`div`,{className:`mt-1 text-slate-500`,children:[`version `,e.workflowVersion]}):null]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Configuration summary`}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-300`,children:a.primary}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:a.secondary})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Validation state`}),(0,z.jsx)(`div`,{className:o.className,children:o.label}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:o.description})]}),(0,z.jsxs)(`div`,{className:`rounded-sm border border-slate-800 bg-[#101d22]/70 p-3`,children:[(0,z.jsx)(`div`,{className:`text-[10px] font-bold uppercase tracking-wide text-slate-500`,children:`Run history`}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-300`,children:`No current run attempts`}),(0,z.jsx)(`div`,{className:`mt-1 text-slate-500`,children:`No workflow run record exists until Start succeeds.`})]})]}),s.length?(0,z.jsxs)(`div`,{className:`mt-3 rounded-sm border border-red-500/40 bg-red-500/10 p-3 text-xs text-red-100`,role:`alert`,"aria-label":`Start-blocking diagnostics`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.16em] text-red-200`,children:[(0,z.jsx)(Js,{size:12}),`Start-blocking diagnostics`]}),(0,z.jsx)(`div`,{className:`mt-2 space-y-2`,children:s.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-[#0b0f14]/60 p-2`,children:[(0,z.jsx)(`div`,{className:`break-words text-red-100`,children:e.message}),(0,z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1 font-mono text-[10px] text-red-200/70`,children:[(0,z.jsx)(`span`,{children:e.code}),e.path?(0,z.jsx)(`span`,{children:e.path}):null,e.registryRef?(0,z.jsx)(`span`,{children:e.registryRef}):null]}),e.hint?(0,z.jsx)(`div`,{className:`mt-1 text-[11px] text-red-100/75`,children:e.hint}):null]},`${e.code}:${e.path??e.registryRef??t}`))})]}):null,r?(0,z.jsx)(`div`,{className:`mt-3 rounded-sm border p-3 text-xs ${c}`,role:`status`,children:r}):null]})}function mLe(e){let t=e.configuration,n=Object.keys(t?.inputValues??{}).length,r=Object.keys(t?.promptOverrides??{}).length,i=t?.model?`${t.model.provider}/${t.model.id}`:`default model`,a=t?.thinkingLevel?`${t.thinkingLevel} thinking`:`default thinking`,o=t?.fastMode===!0?`fast mode on`:t?.fastMode===!1?`fast mode off`:`default speed`;return{primary:`${n} input ${n===1?`value`:`values`} · ${r} prompt ${r===1?`override`:`overrides`}`,secondary:`${i} · ${a} · ${o}`}}function hLe(e,t){return S9(t.filter(t=>t.piboSessionId===e&&!!t.validation))}function gLe(e,t){return(S9(t.filter(t=>t.piboSessionId===e&&t.type===`project.workflow_start.blocked`))?.diagnostics??[]).filter(e=>e.severity===`error`)}function S9(e){return e.reduce((e,t)=>e?t.createdAt>e.createdAt?t:e:t,void 0)}function _Le(e){if(!e?.validation)return{label:`not checked yet`,description:`Validation runs before Start creates a workflow run.`,className:`mt-1 text-slate-300`};let t=e.validation,n=`${t.errorCount} errors · ${t.warningCount} warnings`;return t.blocksRun||t.validationState===`error`?{label:`blocked · ${n}`,description:`Last checked ${C9(t.checkedAt)} at ${t.trigger}.`,className:`mt-1 text-red-200`}:t.validationState===`warning`?{label:`warnings · ${n}`,description:`Last checked ${C9(t.checkedAt)} at ${t.trigger}.`,className:`mt-1 text-amber-200`}:{label:`valid · ${n}`,description:`Last checked ${C9(t.checkedAt)} at ${t.trigger}.`,className:`mt-1 text-emerald-200`}}function vLe(e){return e?.toLowerCase().includes(`blocked`)?`border-red-500/40 bg-red-500/10 text-red-200`:`border-emerald-500/40 bg-emerald-500/10 text-emerald-200`}function C9(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{dateStyle:`short`,timeStyle:`short`})}function w9(e){return`${e.id}@${e.version}`}function yLe(e){return`${e.title} (${e.id}@${e.version})`}function T9(e){if(!e||typeof e!=`object`||!(`data`in e))return[];let t=e.data;if(!t||typeof t!=`object`||!(`diagnostics`in t))return[];let n=t.diagnostics;return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`):[]}function bLe(e){let t=[],n=[];for(let r of e??[])r.archivedAt?n.push(r):t.push(r);return{active:t,archived:n}}function xLe(e,t){return t?e.find(e=>e.piboSessionId===t):void 0}function SLe(e){return e.filter(R2)}function CLe(e,t){return{...e,...t?.session?{session:t.session}:{},agents:t?.agents??e.agents,customAgents:t?.customAgents??e.customAgents,modelDefaults:t?.modelDefaults??e.modelDefaults,modelCatalog:t?.modelCatalog??e.modelCatalog,agentCatalog:t?.agentCatalog??e.agentCatalog,capabilities:t?.capabilities??e.capabilities,sessions:t?.sessions??[]}}function wLe(e,t,n){return e.find(e=>e.id===t&&e.version===n)??e[0]}function TLe(){return[{code:`ProjectWorkflowSessionCreate.missingWorkflowVersion`,message:`Select a workflow version before creating the Project session.`,severity:`error`}]}function ELe(e){return e?`Workflow run started.`:`Start accepted after validation. No workflow run record exists yet.`}function DLe(e){return`Start blocked: ${e.map(e=>e.code).filter(Boolean).slice(0,3).join(`, `)||`validation diagnostics`}`}var OLe=new Set;function kLe({baseBootstrap:e,routeProjectId:t,routePiboSessionId:n,sessionViews:r,showRawEvents:i,showThinking:a,expandThinking:o,commands:s,skills:c,onNavigate:l,onViewContext:u,onSelectSessionView:d,onToggleRawEvents:f,onToggleThinking:p,onToggleExpandThinking:m,onThinkingLevelChange:h,mobileSidebarOpen:g,onCloseMobileSidebar:_,onError:v}){let[y,b]=(0,R.useState)(null),[x,S]=(0,R.useState)(!0),[C,w]=(0,R.useState)(()=>localStorage.getItem(`pibo.chat.projects.showArchivedProjects`)===`true`),[T,E]=(0,R.useState)(()=>localStorage.getItem(`pibo.chat.projects.showArchivedSessions`)===`true`),[D,O]=(0,R.useState)(!1),[k,A]=(0,R.useState)(!1),[j,M]=(0,R.useState)(`loading`),[N,P]=(0,R.useState)(null),[F,ee]=(0,R.useState)([]),[te,I]=(0,R.useState)(``),[ne,L]=(0,R.useState)(``),[re,ie]=(0,R.useState)(null),[ae,oe]=(0,R.useState)({}),[se,ce]=(0,R.useState)([]),[le,ue]=(0,R.useState)(null),[de,fe]=(0,R.useState)(()=>n?Q0(n):``),[pe,me]=(0,R.useState)(0),he=(0,R.useCallback)(async(e={})=>{S(!0);try{let r=await nc({projectId:e.projectId??t,piboSessionId:e.piboSessionId??n,includeArchived:C||T});return b(r),(!t||r.selectedProjectId!==t||r.selectedPiboSessionId&&r.selectedPiboSessionId!==n)&&l(r.selectedProjectId,r.selectedPiboSessionId,!0,{closeMobileSidebar:!1}),v(null),r}catch(e){throw v(i3(e)),e}finally{S(!1)}},[v,l,n,t,C,T]);(0,R.useEffect)(()=>{he()},[he]),(0,R.useEffect)(()=>{let e=!1;return M(`loading`),P(null),cJ().then(t=>{if(e)return;ee(t.options);let n=wLe(t.options,t.selectedWorkflowId,t.selectedWorkflowVersion);I(e=>e||(n?w9(n):``)),M(`loaded`)}).catch(t=>{e||(P(i3(t)),M(`error`))}),()=>{e=!0}},[]),(0,R.useEffect)(()=>{fe(n?Q0(n):``)},[n]);let ge=y?.project,_e=y?.selectedPiboSessionId??null,ve=_e&&y?$4(y.sessions,_e):void 0,ye=ve?.profile??Z4(e),be=y?.projectSessions??[],xe=xLe(be,_e),Se=SLe(be),Ce=bLe(y?.projects),we=Ce.active,Te=Ce.archived,Ee=(0,R.useMemo)(()=>y?l3(y.sessions,T):{active:[],archived:[]},[y,T]),De=(0,R.useMemo)(()=>_e&&y?new Set(e3(y.sessions,_e).map(e=>e.piboSessionId)):OLe,[y,_e]),Oe=(0,R.useMemo)(()=>CLe(e,y),[e,y]),ke=(0,R.useMemo)(()=>Vke({selectedSessionNode:ve,selectedProjectSession:xe,selectedSession:y?.session,selectedProject:ge}),[y?.session,ge,xe,ve]),Ae=(0,R.useMemo)(()=>Q7(ke.viewId),[ke.viewId]),je=async()=>{let e=window.prompt(`Project name`);if(!e)return;let t=window.prompt(`Project folder path (absolute path, e.g. ~/code/my-project or /home/me/code/my-project)`);if(!t)return;let n=window.prompt(`Description (optional)`)??void 0;try{let{project:r}=await rc({name:e,projectFolder:t,createFolder:!0,...n?{description:n}:{}});await he({projectId:r.id}),l(r.id,void 0)}catch(e){v(i3(e))}},Me=async()=>{if(ge){O(!0);try{let e=await oc(ge.id,{profile:ye,workflowId:`simple-chat`});ue(e.session.id),l(ge.id,e.session.id,!1,{closeMobileSidebar:!1}),await he({projectId:ge.id,piboSessionId:e.session.id})}catch(e){v(i3(e))}finally{O(!1)}}},Ne=async()=>{if(!ge)return;let e=F.find(e=>w9(e)===te);if(!e){let e=TLe();ce(e),v(e[0]?.message??`Select a workflow version before creating the Project session.`);return}A(!0),ce([]);try{let t=ne.trim(),n=await Dye(ge.id,{profile:ye,workflowId:e.id,workflowVersion:e.version,...t?{title:t}:{}});L(``),ce([]),l(ge.id,n.session.id,!1,{closeMobileSidebar:!1}),await he({projectId:ge.id,piboSessionId:n.session.id})}catch(e){ce(T9(e)),v(i3(e))}finally{A(!1)}},Pe=async e=>{if(ge){ie(e.piboSessionId);try{let t=ELe((await Mye(ge.id,e.piboSessionId)).projectSession.workflowRunId);oe(n=>({...n,[e.piboSessionId]:t})),v(null),await he({projectId:ge.id,piboSessionId:e.piboSessionId})}catch(t){let n=T9(t);n.length&&oe(t=>({...t,[e.piboSessionId]:DLe(n)})),v(i3(t)),await he({projectId:ge.id,piboSessionId:e.piboSessionId})}finally{ie(null)}}},Fe=async(e,t)=>{try{await sc(e,{title:t}),await he({projectId:ge?.id,piboSessionId:e})}catch(e){v(i3(e))}},Ie=async(e,t)=>{try{await ic(e.id,{name:t}),await he({projectId:ge?.id,piboSessionId:_e??void 0})}catch(e){v(i3(e))}},Le=async(e,t)=>{try{await ic(e.id,{archived:t});let n=await he({projectId:t?void 0:e.id});t&&ge?.id===e.id&&l(n.selectedProjectId,n.selectedPiboSessionId)}catch(e){v(i3(e))}},Re=async e=>{let t=window.prompt(`Type the project name to permanently delete "${e.name}".`);if(t===null)return;let n=window.confirm(`Also delete the real project folder?\n\n${e.projectFolder}`);try{await ac(e.id,{confirmName:t,deleteFiles:n});let r=await he({projectId:ge?.id===e.id?void 0:ge?.id});ge?.id===e.id&&l(r.selectedProjectId,r.selectedPiboSessionId)}catch(e){v(i3(e))}},ze=async e=>{if(!_e)return!1;let t=e.trim().split(/\s+/)[0],n=s.find(e=>e.slash===t);return n?(await yc(_e,n.action),await he({projectId:ge?.id,piboSessionId:_e}),!0):!1},Be=ge&&xe&&Bke(xe)?(0,z.jsx)(pLe,{projectSession:xe,lifecycleEvents:y?.workflowLifecycleEvents??[],starting:re===xe.piboSessionId,message:ae[xe.piboSessionId]??null,onStart:()=>void Pe(xe)}):null;return x&&!y?(0,z.jsx)(`main`,{className:`min-h-0 grid place-items-center text-slate-400`,children:`Loading Projects...`}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/60 min-[981px]:hidden transition-opacity duration-200 ${g?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`,onClick:_}),(0,z.jsx)(cLe,{data:y,selectedProject:ge,selectedPiboSessionId:_e,selectedProjectSession:xe,workflowProjectSessions:Se,activeProjects:we,archivedProjects:Te,sessionGroups:Ee,selectedSessionPathIds:De,autoRenameSessionId:le,creatingSession:D,showArchivedProjects:C,showArchivedSessions:T,mobileSidebarOpen:g,onRefresh:()=>void he(),onCloseMobileSidebar:_,onCreateProject:()=>void je(),onToggleArchivedProjects:()=>{let e=!C;w(e),localStorage.setItem(`pibo.chat.projects.showArchivedProjects`,String(e))},onSelectProject:e=>l(e,void 0),onRenameProject:(e,t)=>void Ie(e,t),onSetProjectArchived:(e,t)=>void Le(e,t),onDeleteArchivedProject:e=>void Re(e),onCreateProjectSession:()=>void Me(),onToggleArchivedSessions:()=>{let e=!T;E(e),localStorage.setItem(`pibo.chat.projects.showArchivedSessions`,String(e))},onSelectSession:e=>l(ge?.id,e),onRenameSession:(e,t)=>void Fe(e,t),onArchiveSession:(e,t)=>void sc(e,{archived:t}).then(()=>he({projectId:ge?.id})),onDeleteSession:e=>void sc(e.piboSessionId,{archived:!0}).then(()=>he({projectId:ge?.id})),onViewContext:u,onAutoRenameConsumed:()=>ue(null)}),(0,z.jsx)(a3,{bootstrap:Oe,selectedPiboSessionId:_e,selectedRoomId:null,selectedRoomArchived:!!ge?.archivedAt,workflowProjectSession:ke.workflowProjectSession,workflowLifecycleEvents:y?.workflowLifecycleEvents??[],projectSessionCreatePanel:ge?(0,z.jsx)(uLe,{project:ge,options:F,selectedOptionKey:te,titleValue:ne,loadState:j,errorMessage:N,creating:k,diagnostics:se,onSelectedOptionChange:e=>{I(e),ce([])},onTitleChange:L,onCreate:()=>void Ne()}):null,workflowStartPanel:Be,selectedSessionProfile:ye,selectedSessionActiveModel:Q4(Oe,ve??{profile:ye}),selectedSessionStatus:ve?.status,sessionViewId:ke.viewId,sessionViews:r,currentSessionView:Ae,allowedSessionViewIds:zke[ke.viewId],creatingSession:D||k,showRawEvents:i,showThinking:a,expandThinking:o,commands:s,skills:c,composerText:de,composerFocusSignal:pe,onComposerTextChange:e=>fe(t=>typeof e==`function`?e(t):e),onToggleRawEvents:f,onToggleThinking:p,onToggleExpandThinking:m,onSessionAgentProfileChange:async e=>{_e&&await gc(_e,{profile:e})},onFork:()=>void 0,onOpenSession:e=>l(ge?.id,e),onSelectSessionView:d,onCommand:ze,onThinkingLevelChange:h,onRefreshTrace:async()=>void 0,onRefreshBootstrap:async()=>{await he({projectId:ge?.id,piboSessionId:_e??void 0})},onSend:async e=>{_e&&(await cc(_e,e,t3()),await he({projectId:ge?.id,piboSessionId:_e}))},onError:v})]})}var E9=`Delete this session`;function ALe({session:e,confirmText:t,deleting:n,onConfirmTextChange:r,onCancel:i,onDelete:a}){return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 grid place-items-center p-4`,children:(0,z.jsxs)(`div`,{className:`w-full max-w-lg border border-red-500/70 bg-[#1a262b] rounded-sm shadow-xl`,children:[(0,z.jsxs)(`div`,{className:`px-4 py-3 border-b border-red-500/50 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{className:`text-sm font-bold uppercase tracking-wider text-red-200`,children:`Delete Session`}),(0,z.jsx)(`div`,{className:`font-mono text-[11px] text-slate-500 truncate`,children:e.piboSessionId})]}),(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,title:`Cancel`,"aria-label":`Cancel`,className:`h-8 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,z.jsx)(Qs,{size:14})})]}),(0,z.jsxs)(`div`,{className:`p-4 grid gap-3`,children:[(0,z.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-100 rounded-sm p-3 text-sm`,children:`This permanently deletes the archived session, its child sessions, and their Chat events. This cannot be undone.`}),(0,z.jsxs)(`div`,{className:`text-sm text-slate-300`,children:[`Type `,(0,z.jsx)(`span`,{className:`font-mono text-red-200`,children:E9}),` to confirm.`]}),(0,z.jsx)(`input`,{value:t,onChange:e=>r(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-red-500`,placeholder:E9,autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`h-8 inline-flex items-center border border-slate-700 rounded-sm px-3 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:`Cancel`}),(0,z.jsxs)(`button`,{type:`button`,onClick:a,disabled:n||t!==E9,className:`h-8 inline-flex items-center gap-2 border border-red-500 rounded-sm px-3 text-red-200 bg-red-500/10 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:14}),`Delete permanently`]})]})]})]})})}function jLe({room:e,confirmName:t,deleting:n,onConfirmNameChange:r,onCancel:i,onDelete:a}){return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 grid place-items-center p-4`,children:(0,z.jsxs)(`div`,{className:`w-full max-w-lg border border-red-500/70 bg-[#1a262b] rounded-sm shadow-xl`,children:[(0,z.jsxs)(`div`,{className:`px-4 py-3 border-b border-red-500/50 flex items-center justify-between gap-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{className:`text-sm font-bold uppercase tracking-wider text-red-200`,children:`Delete Room`}),(0,z.jsx)(`div`,{className:`font-mono text-[11px] text-slate-500 truncate`,children:e.id})]}),(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,title:`Cancel`,"aria-label":`Cancel`,className:`h-8 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,z.jsx)(Qs,{size:14})})]}),(0,z.jsxs)(`div`,{className:`p-4 grid gap-3`,children:[(0,z.jsx)(`div`,{className:`border border-red-500/60 bg-red-500/10 text-red-100 rounded-sm p-3 text-sm`,children:`This permanently deletes the archived room, child rooms, all contained sessions, subagent sessions, and their Chat events. This cannot be undone.`}),(0,z.jsxs)(`div`,{className:`text-sm text-slate-300`,children:[`Type `,(0,z.jsx)(`span`,{className:`font-mono text-red-200`,children:e.name}),` to confirm.`]}),(0,z.jsx)(`input`,{value:t,onChange:e=>r(e.target.value),className:`min-w-0 bg-[#0e1116] border border-slate-700 rounded-sm px-3 py-2 text-sm outline-none focus:border-red-500`,placeholder:e.name,autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:i,disabled:n,className:`h-8 inline-flex items-center border border-slate-700 rounded-sm px-3 text-slate-300 hover:border-[#11a4d4] hover:text-[#11a4d4] disabled:opacity-50`,children:`Cancel`}),(0,z.jsxs)(`button`,{type:`button`,onClick:a,disabled:n||t!==e.name,className:`h-8 inline-flex items-center gap-2 border border-red-500 rounded-sm px-3 text-red-200 bg-red-500/10 disabled:opacity-50`,children:[(0,z.jsx)(qs,{size:14}),`Delete permanently`]})]})]})]})})}var D9=[`sessions`,`projects`,`workflows`,`cron`,`ralph`,`agents`,`context`,`settings`];function MLe(){return(0,z.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,z.jsx)(Js,{size:16}),`Recovery Mode: Main gateway is down. You are connected to a fallback instance.`]})}function NLe({area:e,identity:t,mobileAreaMenuOpen:n,mobileAreaMenuRef:r,totalRoomUnreadCount:i,onOpenMobileSidebar:a,onSelectMainNavArea:o,onToggleMobileAreaMenu:s}){let c=t.email||t.name||t.userId;return(0,z.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,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:a,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,z.jsx)(Es,{size:16})}),(0,z.jsx)(`img`,{src:`/apps/chat/assets/pwa-images/android/launchericon-512x512.png`,alt:`Logo`,className:`h-5 w-auto shrink-0`}),(0,z.jsx)(`div`,{className:`truncate font-extrabold tracking-[0.08em] uppercase text-lg max-[420px]:text-base`,children:`Pibo Chat`})]}),(0,z.jsx)(`nav`,{className:`flex gap-1 max-[1200px]:hidden min-[1201px]:absolute min-[1201px]:left-1/2 min-[1201px]:-translate-x-1/2`,children:D9.map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>o(t),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,z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,z.jsx)(`span`,{children:t}),t===`sessions`?(0,z.jsx)(O9,{count:i}):null]})},t))}),(0,z.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,z.jsx)(Ys,{size:14}),(0,z.jsx)(`span`,{className:`truncate max-[600px]:hidden`,children:c}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void aPe().then(()=>location.reload()),className:`p-1 border border-slate-700 rounded-sm hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Sign out`,"aria-label":`Sign out`,children:(0,z.jsx)(ws,{size:14})}),(0,z.jsxs)(`div`,{className:`relative min-[1201px]:hidden`,ref:r,children:[(0,z.jsx)(`button`,{type:`button`,onClick:s,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-expanded":n,children:(0,z.jsx)(Ss,{size:14})}),n?(0,z.jsx)(`div`,{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`,children:D9.map(t=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>o(t),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`,children:[(0,z.jsx)(`span`,{children:t}),t===`sessions`?(0,z.jsx)(O9,{count:i}):null]},t))}):null]})]})]})}function PLe({message:e,onDismiss:t}){return(0,z.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,z.jsxs)(`div`,{className:`min-w-0 flex items-start gap-2`,children:[(0,z.jsx)(Js,{size:16,className:`mt-0.5 shrink-0 text-red-300`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-red-300`,children:`Session Error`}),(0,z.jsx)(`div`,{className:`break-words`,children:e})]})]}),(0,z.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 FLe({message:e}){return(0,z.jsx)(`div`,{className:`min-h-screen bg-[#101d22] text-slate-300 grid place-items-center`,children:(0,z.jsxs)(`div`,{className:`border border-slate-700 bg-[#1a262b] p-5 rounded-sm`,children:[(0,z.jsx)(`div`,{className:`mb-4 text-sm text-slate-400`,children:e}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>void oPe(),className:`px-3 py-2 bg-[#11a4d4] rounded-sm`,children:`Sign in with Google`})]})})}function ILe(e){return e>99?`99+`:String(e)}function O9({count:e}){return!e||e<=0?null:(0,z.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:ILe(e)})}function k9(e,t){return A9(e,e=>P9(t.sessions[e]))}function LLe(e,t){let n=new Map(t.sessionSnapshots.map(e=>[e.piboSessionId,P9(e)]));return A9(e,e=>n.get(e))}function A9(e,t){return{...e,sessions:e.sessions.map(e=>j9(e,t))}}function j9(e,t){let n=t(e.piboSessionId),r=N9(n,M9(e)),i=r&&r!==e.status?I9(e.lastActivityAt,n?.updatedAt,new Date().toISOString()):I9(e.lastActivityAt,n?.updatedAt);return{...e,status:r??e.status,lastActivityAt:i,children:e.children.map(e=>j9(e,t)),derivedSessions:e.derivedSessions.map(e=>{let n=t(e.piboSessionId),r=N9(n,0),i=!!(r&&r!==e.status);return{...e,status:r??e.status,lastActivityAt:i?I9(e.lastActivityAt,n?.updatedAt,new Date().toISOString()):I9(e.lastActivityAt,n?.updatedAt)}})}}function M9(e){return(e.unreadCount??0)+e.children.reduce((e,t)=>e+M9(t),0)}function N9(e,t){return e?.status===`error`?t>0?`error`:e.isTreeActive?`running`:`idle`:e?.status}function P9(e){let t=F9(e);if(!(!e&&!t))return{status:t,updatedAt:e?.updatedAt,isTreeActive:e?.isTreeActive}}function F9(e){if(e)return e.hasError||e.hasErrorDescendant||e.aggregateStatus===`error`?`error`:e.isTreeActive?`running`:`idle`}function I9(...e){let t,n=-1/0;for(let r of e){if(!r)continue;let e=Date.parse(r);!Number.isFinite(e)||e<n||(t=r,n=e)}return t}function RLe(e,t){if(!e||e.rootPiboSessionId!==t.rootPiboSessionId||e.version!==t.fromVersion)return e;let n={...e.nodes};for(let e of t.removes)delete n[e];for(let e of t.upserts)n[e.id]=e;let r={...e.sessions};for(let e of t.sessionSnapshots)r[e.piboSessionId]=e;return{...e,version:t.toVersion,generatedAt:t.generatedAt,nodes:n,sessions:r}}function L9(e,t,n={}){let r=n.readSessionId?zLe(e.sessions,n.readSessionId):new Set,i=new Map;R9(e.sessions,i);let a=[...r].reduce((e,t)=>e+(i.get(t)??0),0);return{...e,identity:t.identity,session:t.session,room:t.room,selectedRoomId:t.selectedRoomId,selectedPiboSessionId:t.selectedPiboSessionId,latestRoomStreamId:t.latestRoomStreamId,rooms:BLe(e.rooms,t.rooms,t.selectedRoomId,a),sessions:B9(t.sessions,r,i)}}function R9(e,t){for(let n of e)t.set(n.piboSessionId,n.unreadCount??0),R9(n.children,t)}function zLe(e,t){let n=new Set,r=e=>e.piboSessionId===t?(z9(e,n),!0):e.children.some(e=>r(e));for(let t of e)r(t);return n}function z9(e,t){t.add(e.piboSessionId);for(let n of e.children)z9(n,t)}function B9(e,t,n){return e.map(e=>{let r=n.get(e.piboSessionId),i=t.has(e.piboSessionId)?0:e.unreadCount??r??0;return{...e,...i>0?{unreadCount:i}:{unreadCount:void 0},children:B9(e.children,t,n)}})}function BLe(e,t,n,r){let i=new Map;return V9(e,i),H9(t,i,n,r).rooms}function V9(e,t){for(let n of e)t.set(n.id,n.unreadCount??0),V9(n.children??[],t)}function H9(e,t,n,r){let i=!1;return{rooms:e.map(e=>{let a=H9(e.children??[],t,n,r),o=e.id===n||a.selectedRoomFound;i||=o;let s=e.unreadCount??t.get(e.id)??0,c=o&&r>0?Math.max(0,s-r):s;return{...e,...c>0?{unreadCount:c}:{unreadCount:void 0},...e.children?{children:a.rooms}:{}}}),selectedRoomFound:i}}function U9(e,t){if(!t.length)return e;let n=new Set(e.map(e=>e.piboSessionId)),r=t.filter(e=>!n.has(e.piboSessionId));return r.length?[...e,...r]:e}function VLe(e,t){return e.agentCatalog?{...e,agentCatalog:{...e.agentCatalog,mcpServers:e.agentCatalog.mcpServers.map(e=>e.name===t.name?t:e)}}:e}function W9(e,t){if(!e.agentCatalog)return e;let n=e.agentCatalog.piPackages.filter(e=>e.id!==t.id);return{...e,agentCatalog:{...e.agentCatalog,piPackages:J9([...n,t])}}}function G9(e,t){return e.agentCatalog?{...e,agentCatalog:{...e.agentCatalog,piPackages:e.agentCatalog.piPackages.filter(e=>e.id!==t)}}:e}function K9(e,t){if(!e.agentCatalog)return e;let n=e.agentCatalog.userSkills.filter(e=>e.id!==t.id);return{...e,agentCatalog:{...e.agentCatalog,userSkills:J9([...n,t])}}}function q9(e,t){return e.agentCatalog?{...e,agentCatalog:{...e.agentCatalog,userSkills:e.agentCatalog.userSkills.filter(e=>e.id!==t)}}:e}function J9(e){return e.sort((e,t)=>e.name.localeCompare(t.name))}function HLe(e,t){let n=n9(e);return{deletedSessionIds:n,selectedSessionDeleted:t?n.has(t):!1,restoreSelectedPiboSessionId:t}}function ULe(e,t,n){return t?e.includes(t):n}function WLe(e,t){return t?void 0:e??void 0}function GLe(e,t,n){let r=c9(e);return{deletedRoomIds:r,selectedRoomDeleted:t?r.has(t):!1,restoreSelectedRoomId:t,restoreSelectedPiboSessionId:n}}function KLe(e,t){return t===e}function qLe({queryClient:e,bootstrap:t,selectedPiboSessionId:n,selectedRoomId:r,showArchivedRef:i,isSessionsArea:a,loadBootstrap:o,navigateToSelectedSession:s,updateBootstrapCache:c,restoreBootstrapSnapshot:l,setSelectedPiboSessionId:u,setSelectedRoomId:d,setError:f}){let[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(``),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),[x,S]=(0,R.useState)(``),[C,w]=(0,R.useState)(!1),T=e=>{b(e),S(``)},E=()=>{b(null),S(``)},D=async()=>{if(!y)return;w(!0),await e.cancelQueries({queryKey:[`chat`,`bootstrap`]});let d=$7(e,t),p=HLe(y,n);p.selectedSessionDeleted&&u(null),c(e=>OIe(e,p.deletedSessionIds));try{let e=ULe((await _c(y.piboSessionId,x)).deletedSessionIds,n,p.selectedSessionDeleted);e&&u(null);let t=await o(WLe(n,e),i.current,r??void 0,{force:!0});a&&s(t.selectedRoomId,t.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),E(),f(null)}catch(e){l(d),p.selectedSessionDeleted&&u(p.restoreSelectedPiboSessionId),f(e instanceof Error?e.message:String(e))}finally{w(!1)}},O=e=>{m(e),g(``)},k=()=>{m(null),g(``)};return{deleteRoomTarget:p,deleteRoomConfirmName:h,deletingRoom:_,setDeleteRoomConfirmName:g,requestRoomDelete:O,cancelRoomDelete:k,permanentlyDeleteRoom:async()=>{if(!p)return;v(!0),await e.cancelQueries({queryKey:[`chat`,`bootstrap`]});let m=$7(e,t),g=GLe(p,r,n);g.selectedRoomDeleted&&(d(null),u(null)),c(e=>MIe(e,g.deletedRoomIds));try{await hc(p.id,h),KLe(p.id,r)&&(d(null),u(null));let e=await o(void 0,i.current,void 0,{force:!0});a&&s(e.selectedRoomId,e.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),k(),f(null)}catch(e){l(m),g.selectedRoomDeleted&&(d(g.restoreSelectedRoomId),u(g.restoreSelectedPiboSessionId)),f(e instanceof Error?e.message:String(e))}finally{v(!1)}},deleteSessionTarget:y,deleteSessionConfirmText:x,deletingSession:C,setDeleteSessionConfirmText:S,requestSessionDelete:T,cancelSessionDelete:E,permanentlyDeleteSession:D}}var JLe=750,Y9=120,X9=60,YLe=new Set;async function XLe(e,t){let n=nje(t.piboSessionId,t.includeArchived,t.roomId);return await e.removeQueries({queryKey:n,exact:!0}),ec(t.piboSessionId,t.includeArchived,t.roomId,!!t.markRead)}async function Z9(e,t){let n=rje(t.includeArchived,t.roomId,t.piboSessionId);return await e.removeQueries({queryKey:n,exact:!0}),tc(t.piboSessionId,t.includeArchived,t.roomId)}function ZLe({route:e}){let t=ja(),n=Yt(),r=e.area,i=e.area===`sessions`?e.roomId:void 0,a=e.area===`projects`?e.projectId:void 0,o=e.area===`sessions`||e.area===`projects`||e.area===`context`?e.piboSessionId:void 0,s=e.area===`sessions`||e.area===`projects`?e.sessionViewId:void 0,c=e.area===`settings`?e.panel??`general`:`general`,[l,u]=(0,R.useState)(null),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(null),[_,v]=(0,R.useState)(ske),[y,b]=(0,R.useState)(cke),[x,S]=(0,R.useState)(lke),[C,w]=(0,R.useState)(uke),[T,E]=(0,R.useState)(fke),[D,O]=(0,R.useState)(pke),[k,A]=(0,R.useState)(()=>s??t2()),[j,M]=(0,R.useState)(``),[N,P]=(0,R.useState)(0),[F,ee]=(0,R.useState)(!1),te=(0,R.useRef)(!1),[I,ne]=(0,R.useState)(!1),[L,re]=(0,R.useState)(!1),[ie,ae]=(0,R.useState)(Y9),[oe,se]=(0,R.useState)(X9),[ce,le]=(0,R.useState)(null),[ue,de]=(0,R.useState)(null),[fe,pe]=(0,R.useState)(`build-context`),[me,he]=(0,R.useState)(null),[ge,_e]=(0,R.useState)(null),[ve,ye]=(0,R.useState)(!1),[be,xe]=(0,R.useState)(!1),[Se,Ce]=(0,R.useState)(!1),we=(0,R.useRef)(null),[Te,Ee]=(0,R.useState)(null),[De,Oe]=(0,R.useState)(null),[ke,Ae]=(0,R.useState)(()=>Date.now()),je=(0,R.useRef)(C),Me=(0,R.useRef)(null),Ne=(0,R.useRef)(null),Pe=(0,R.useRef)(0),Fe=p??l?.selectedRoomId??null,Ie=Fe&&l?d3(l.rooms,Fe)??l.room:void 0,Le=Ie?m3(Ie):!1;(0,R.useEffect)(()=>{je.current=C},[C]),(0,R.useEffect)(()=>{if(!Se)return;let e=e=>{we.current&&!we.current.contains(e.target)&&Ce(!1)},t=e=>{e.key===`Escape`&&Ce(!1)};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)}},[Se]),(0,R.useEffect)(()=>{Ne.current=l},[l]),(0,R.useEffect)(()=>{ae(Y9),se(X9)},[p,C]),(0,R.useEffect)(()=>{Ae(Date.now())},[l]),(0,R.useEffect)(()=>{if(r!==`sessions`||!d){Oe(null);return}let e,t=t=>{e&&clearTimeout(e),e=setTimeout(()=>{e=void 0,Rc(d).then(e=>{Oe(e),u(t=>t&&k9(t,e))}).catch(()=>void 0)},t)},n=zc(d,{onSnapshot:t=>{e&&=(clearTimeout(e),void 0),Oe(t),u(e=>e&&k9(e,t))},onPatch:e=>{Oe(n=>{let r=RLe(n,e);return n&&r===n&&t(0),r}),u(t=>t&&LLe(t,e))},onError:()=>t(JLe)});return()=>{e&&clearTimeout(e),n()}},[r,d]),(0,R.useEffect)(()=>{let e=l?qje(l.sessions,ke):void 0;if(e===void 0)return;let t=setTimeout(()=>Ae(Date.now()),Math.max(50,e));return()=>clearTimeout(t)},[l,ke]),(0,R.useEffect)(()=>{let e=async()=>{try{let e=await fetch(`/health`,{signal:AbortSignal.timeout(3e3)});e.ok?Ee((await e.json()).mode===`fallback`?`fallback`:`main`):Ee(null)}catch{Ee(null)}};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,R.useEffect)(()=>{if(r!==`sessions`&&r!==`projects`)return;let e=s??t2();A(t=>t===e?t:e)},[r,s]),(0,R.useEffect)(()=>{oke(k)},[k]);let Re=(0,R.useCallback)((e,n=!1,r=k,i={})=>{i.closeMobileSidebar!==!1&&xe(!1),kc(t,e,n,r)},[t,k]),ze=(0,R.useCallback)((e,t,n=!1,r={})=>{if(!t){Re({area:`sessions`,...e?{roomId:e}:{}},n,k,r);return}Re({area:`sessions`,...e?{roomId:e}:{},piboSessionId:t},n,k,r)},[Re,k]),Be=(0,R.useCallback)((e,t,n=!1,r={})=>{if(!t){Re({area:`projects`,...e?{projectId:e}:{}},n,k,r);return}Re({area:`projects`,...e?{projectId:e}:{},piboSessionId:t},n,k,r)},[Re,k]),Ve=(0,R.useCallback)(e=>{pe(`build-context`),Re({area:`context`,piboSessionId:e})},[Re]),He=(0,R.useCallback)(e=>{he(e),pe(`context-files`),Re({area:`context`})},[Re]),Ue=(0,R.useCallback)(e=>{_e(e),pe(`mcp-tools`),Re({area:`context`})},[Re]),We=(0,R.useCallback)(e=>{u(t=>t&&VLe(t,e))},[]),Ge=(0,R.useCallback)(e=>{u(t=>t&&W9(t,e)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&W9(t,e))},[n]),Ke=(0,R.useCallback)(e=>{u(t=>t&&G9(t,e.id)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&G9(t,e.id))},[n]),qe=(0,R.useCallback)(e=>{u(t=>t&&K9(t,e)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&K9(t,e))},[n]),Je=(0,R.useCallback)(e=>{u(t=>t&&q9(t,e)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&q9(t,e))},[n]),Ye=(0,R.useCallback)(async(e,t=je.current,r,i={})=>{let a=Ne.current;if(a&&i.selectSession!==!1&&!i.force){e&&await dc(e);let i=Pe.current+1;Pe.current=i;let o=L9(a,await Z9(n,{piboSessionId:e,includeArchived:t,roomId:r}),{readSessionId:e});return i===Pe.current?(u(o),f(o.selectedPiboSessionId),m(o.selectedRoomId),o):o}let o=Pe.current+1;Pe.current=o;let s=await XLe(n,{piboSessionId:e,includeArchived:t,roomId:r,markRead:i.selectSession!==!1,force:i.force});return o===Pe.current?(u(s),i.selectSession!==!1&&f(s.selectedPiboSessionId),m(s.selectedRoomId),s):s},[n]),Xe=(0,R.useCallback)(async(e,t=je.current,r,i={})=>{let a=Ne.current;if(!a)return Ye(e,t,r,{force:i.force});let o=Pe.current+1;Pe.current=o;let s=L9(a,await Z9(n,{piboSessionId:e,includeArchived:t,roomId:r,force:i.force}),{readSessionId:i.readSessionId});return o===Pe.current?(u(s),f(s.selectedPiboSessionId),m(s.selectedRoomId),s):s},[Ye,n]);(0,R.useEffect)(()=>{if(r!==`sessions`)return;let e=!1,t=window.setInterval(()=>{e||document.hidden||!Ne.current||Xe(d??void 0,je.current,Fe??void 0,{force:!0}).catch(()=>void 0)},2500);return()=>{e=!0,window.clearInterval(t)}},[Fe,r,Xe,d]),(0,R.useEffect)(()=>{let{requestedRoomId:t,requestedPiboSessionId:n}=HIe(e,X0()),r=(t,n=!0)=>{let r=WIe(e,t);r&&ze(r.selectedRoomId,r.selectedPiboSessionId,n)};if(UIe({bootstrap:l,creatingSession:te.current,route:e}))return;let a=l?Xe:Ye;a(n,je.current,t).then(e=>{r(e),g(null)}).catch(s=>{if(e.area===`sessions`&&i&&!o&&n){Z0(i),a(void 0,je.current,i).then(e=>{r(e),g(null)}).catch(e=>g(e instanceof Error?e.message:String(e)));return}if(GIe(e)||!n&&!t){g(s instanceof Error?s.message:String(s));return}mke(),a().then(e=>{r(e),g(null)}).catch(e=>g(e instanceof Error?e.message:String(e)))})},[l,Ye,Xe,ze,e.area,o,i]),(0,R.useEffect)(()=>{!p&&!d||ike({roomId:p??void 0,piboSessionId:d??void 0})},[d,p]),(0,R.useEffect)(()=>{M(d?Q0(d):``)},[d]);let Ze=(0,R.useCallback)(e=>{M(t=>{let n=typeof e==`function`?e(t):e;return d&&$0(d,n),n})},[d]),Qe=(0,R.useMemo)(()=>DIe(),[]),$e=(0,R.useMemo)(()=>Q7(k),[k]);(0,R.useEffect)(()=>{if(!l?.agents.length)return;let e=Z4(l),t=D||e,n=Q9(l.agents,t);if(n){D!==n.name&&(O(n.name),o2(n.name));return}let r=Q9(l.agents,e)?.name??l.agents[0].name;O(r),o2(r)},[l,D]);let et=(0,R.useCallback)(e=>{O(e),o2(e)},[]),tt=(0,R.useCallback)(async e=>{let t=JU(e),r=!1;try{await Promise.all([n.invalidateQueries({queryKey:z4(e),refetchType:`none`}),n.invalidateQueries({queryKey:B4(e),refetchType:`none`})]),await Promise.all([n.refetchQueries({queryKey:z4(e),type:`active`}),n.refetchQueries({queryKey:B4(e),type:`active`})])}catch(e){throw r=!0,e}finally{YU(e,t,r)}},[n]),nt=(0,R.useCallback)(()=>d?tt(d):Promise.resolve(),[tt,d]),rt=(0,R.useCallback)(()=>Xe(d??void 0,je.current,p??void 0,{force:!0}),[Xe,d,p]),it=(0,R.useCallback)(async()=>{g(null);let e=d??void 0;await Ye(e,je.current,p??void 0,{force:!0,selectSession:!1}),e&&await tt(e)},[Ye,tt,d,p]),at=(0,R.useCallback)(e=>{u(t=>t&&e(t)),n.setQueriesData({queryKey:[`chat`,`bootstrap`]},t=>t&&e(t))},[n]),ot=l?.latestRoomStreamId;(0,R.useEffect)(()=>{if(r!==`sessions`||!Fe)return;let e=new URLSearchParams({roomId:Fe});e.set(`mode`,`summary`),e.set(`since`,`${ot??0}:999999`);let t=new EventSource(`/api/chat/events?${e.toString()}`),n,i=()=>{n&&clearTimeout(n),n=setTimeout(()=>{n=void 0,Ye(d??void 0,je.current,Fe,{force:!0,selectSession:!1}).catch(e=>g(i3(e)))},900)};return t.addEventListener(`pibo`,e=>{let t=Yc(e);if(!t||t.type===`ready`)return;let n=t.piboSessionId,r=ol(t);if(n&&r){let e=new Date().toISOString();at(t=>i9(t,n,t=>({...t,status:r,lastActivityAt:e})))}el(t)&&i()}),()=>{n&&clearTimeout(n),t.close()}},[Fe,r,ot,Ye,d,at]);let st=(0,R.useCallback)(e=>{if(e){u(e.localBootstrap);for(let[t,r]of e.queryData)n.setQueryData(t,r)}},[n]),{deleteRoomTarget:ct,deleteRoomConfirmName:lt,deletingRoom:ut,setDeleteRoomConfirmName:dt,requestRoomDelete:ft,cancelRoomDelete:pt,permanentlyDeleteRoom:mt,deleteSessionTarget:ht,deleteSessionConfirmText:gt,deletingSession:_t,setDeleteSessionConfirmText:vt,requestSessionDelete:yt,cancelSessionDelete:bt,permanentlyDeleteSession:xt}=qLe({queryClient:n,bootstrap:l,selectedPiboSessionId:d,selectedRoomId:p,showArchivedRef:je,isSessionsArea:r===`sessions`,loadBootstrap:Ye,navigateToSelectedSession:ze,updateBootstrapCache:at,restoreBootstrapSnapshot:st,setSelectedPiboSessionId:f,setSelectedRoomId:m,setError:g}),St=fn({mutationFn:({profile:e,roomId:t})=>uc(e||void 0,t),onMutate:async({profile:e})=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let t=$7(n,l),r=d,i=`optimistic-session-${t3()}`;return f(i),at(t=>({...e9(t,FIe(i,e||Z4(t))),selectedPiboSessionId:i})),{snapshot:t,tempId:i,previousSelectedPiboSessionId:r}},onError:(e,t,n)=>{st(n?.snapshot),f(n?.previousSelectedPiboSessionId??null)},onSuccess:(e,t,n)=>{f(e.session.id),at(t=>kIe(t,n?.tempId,u9(e.session)))}}),Ct=fn({mutationFn:({piboSessionId:e,title:t})=>gc(e,{title:t}),onMutate:async({piboSessionId:e,title:t})=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let r=$7(n,l);return at(n=>i9(n,e,e=>({...e,title:t||`Untitled Session`}))),{snapshot:r}},onError:(e,t,n)=>st(n?.snapshot),onSuccess:({session:e})=>at(t=>r9(t,e))}),wt=fn({mutationFn:({piboSessionId:e,archived:t})=>gc(e,{archived:t}),onMutate:async({piboSessionId:e,archived:t})=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let r=$7(n,l);return at(n=>i9(n,e,e=>({...e,archived:t,unreadCount:t?0:e.unreadCount}))),{snapshot:r}},onError:(e,t,n)=>st(n?.snapshot),onSuccess:({session:e})=>at(t=>r9(t,e))}),Tt=fn({mutationFn:({piboSessionId:e,text:t,clientTxnId:n,roomId:r,webAnnotationIds:i,fileAttachmentPaths:a})=>vc(e,t,n,r,i,a),onMutate:async({piboSessionId:e})=>{await n.cancelQueries({queryKey:B4(e)}),at(t=>i9(t,e,e=>({...e,status:`running`,lastActivityAt:new Date().toISOString()})))},onError:(e,t)=>{at(e=>i9(e,t.piboSessionId,e=>({...e,status:`error`})))}}),Et=(0,R.useCallback)(async e=>{if(!(!d||!l||e===Z4(l)))try{await gc(d,{profile:e}),et(e);let t=await Ye(d,je.current,p??void 0);r===`sessions`&&ze(t.selectedRoomId,t.selectedPiboSessionId),await tt(d),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},[r,l,Ye,ze,tt,d,p,et]),Dt=(0,R.useMemo)(()=>BIe(l?.capabilities.actions??[]),[l]),Ot=(0,R.useMemo)(()=>VIe(l,d),[l,d]),kt=(0,R.useCallback)(async e=>{(0,Na.flushSync)(()=>{f(e),le(e),xe(!1)}),ze(p??l?.selectedRoomId,e,!1,{closeMobileSidebar:!1});try{await dc(e);let t=await Xe(e,je.current,p??l?.selectedRoomId,{readSessionId:e});ze(t.selectedRoomId,t.selectedPiboSessionId,!0,{closeMobileSidebar:!1})}finally{le(t=>t===e?null:t)}},[l?.selectedRoomId,Xe,ze,p]),At=(0,R.useCallback)(async(e,t={})=>{let n={...t,closeMobileSidebar:!1},r=X0().sessionsByRoom?.[e];m(e),f(r??null);try{let t=await Xe(r,je.current,e);ze(t.selectedRoomId,t.selectedPiboSessionId,!1,n)}catch(t){if(!r)throw t;Z0(e),f(null);let i=await Xe(void 0,je.current,e);ze(i.selectedRoomId,i.selectedPiboSessionId,!1,n)}},[Xe,ze]),jt=async(e=D)=>{if(!(F||Le)){te.current=!0,ee(!0);try{let t=await St.mutateAsync({profile:e,roomId:p??void 0});f(t.session.id),de(t.session.id),ze(p??l?.selectedRoomId??void 0,t.session.id,!1,{closeMobileSidebar:!1});let n=await Ye(t.session.id,je.current,p??void 0,{force:!0});ze(n.selectedRoomId,n.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{te.current=!1,ee(!1)}}},Mt=async()=>{let e=!C;if(w(e),dke(e),!e){re(!1),g(null);return}re(!0);try{let e=await Xe(d??void 0,!0,p??void 0);r===`sessions`&&ze(e.selectedRoomId,e.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}finally{re(!1)}},Nt=async(e,t)=>{try{await Ct.mutateAsync({piboSessionId:e,title:t});let n=await Ye(d??void 0,je.current,p??void 0,{force:!0});r===`sessions`&&await tt(n.selectedPiboSessionId),r===`sessions`&&ze(n.selectedRoomId,n.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},Pt=async(e,t)=>{try{await wt.mutateAsync({piboSessionId:e,archived:t});let n=await Ye(t&&!C&&d===e?void 0:d??void 0,je.current,p??void 0,{force:!0});r===`sessions`&&ze(n.selectedRoomId,n.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},Ft=async()=>{if(ve)return;ye(!0),await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let e=$7(n,l),t=`optimistic-room-${t3()}`,r=NIe(t,`New Chat`);m(t),f(null),at(e=>AIe(e,r));try{let e=await pc({name:`New Chat`});at(n=>jIe(n,t,e.room)),await At(e.room.id,{closeMobileSidebar:!1}),g(null)}catch(t){st(e),m(p),f(d),g(t instanceof Error?t.message:String(t))}finally{ye(!1)}},It=async(e,t)=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let i=$7(n,l);at(n=>a9(n,e,e=>({...e,...t.name===void 0?{}:{name:t.name},...t.topic===void 0?{}:{topic:t.topic??void 0},...t.workspace===void 0?{}:{workspace:t.workspace??void 0},updatedAt:new Date().toISOString()})));try{let{room:n}=await mc(e,t);at(t=>a9(t,e,()=>n));let i=await Ye(d??void 0,je.current,e,{force:!0});r===`sessions`&&ze(i.selectedRoomId,i.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){st(i),g(e instanceof Error?e.message:String(e))}},Lt=async e=>{try{await fc(e);let t=await Ye(d??void 0,je.current,p??void 0,{force:!0,selectSession:!1});r===`sessions`&&ze(t.selectedRoomId,t.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},Rt=async(e,t)=>{await n.cancelQueries({queryKey:[`chat`,`bootstrap`]});let i=$7(n,l);t&&(E(!0),a2(!0)),at(n=>a9(n,e,e=>PIe(e,t)));try{let{room:n}=await mc(e,{archived:t});at(t=>a9(t,e,()=>n));let i=await Ye(d??void 0,je.current,p??void 0,{force:!0});r===`sessions`&&ze(i.selectedRoomId,i.selectedPiboSessionId,!1,{closeMobileSidebar:!1}),g(null)}catch(e){st(i),g(e instanceof Error?e.message:String(e))}},zt=(0,R.useCallback)(async e=>{if(!d||Le)return!1;let t=e.trim().split(/\s+/)[0],n=Dt.find(e=>e.slash===t);if(!n)return!1;if(n.action===`thinking-show`){let e=!_;return v(e),n2(e),!0}if(n.action===`download`){let n=IIe(e.slice(t.length));if(!n)return g(`Usage: /download <path>`),!0;try{await Pc(n,{piboSessionId:d,roomId:p??void 0}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}return!0}let i=LIe(n.action,e.slice(t.length).trim()),a=zIe(await yc(d,n.action,i));if((n.action===`session.clone`||n.action===`session.fork`)&&a)await kt(a);else{let e=await Ye(d,je.current,p??void 0);r===`sessions`&&ze(e.selectedRoomId,e.selectedPiboSessionId),await tt(d)}return!0},[r,Ye,ze,tt,kt,d,Le,p,_,Dt]),Bt=(0,R.useCallback)(async e=>{if(!d||Le)return;let t=RIe(await yc(d,`session.fork`,{entryId:e}));if(t?.result.cancelled)return;if(!t)throw Error(`Unexpected fork action response`);let n=typeof t.result.selectedText==`string`?t.result.selectedText:void 0;n!==void 0&&t.result.piboSessionId&&$0(t.result.piboSessionId,n),t.result.piboSessionId&&await kt(t.result.piboSessionId),n!==void 0&&(M(n),P(e=>e+1))},[kt,d,Le]),Vt=(0,R.useCallback)(e=>void kt(e),[kt]),Ht=(0,R.useCallback)(e=>{if(A(e),r===`projects`){Re({area:`projects`,...a?{projectId:a}:{},...o?{piboSessionId:o}:{}},!1,e);return}r===`sessions`&&Re({area:`sessions`,...p?{roomId:p}:{},...d?{piboSessionId:d}:{}},!1,e)},[r,Re,o,a,d,p]),Ut=(0,R.useMemo)(()=>l?l3(l.sessions,C):{active:[],archived:[]},[l?.sessions,C]),Wt=(0,R.useMemo)(()=>Jje(Ut.active,ie,d),[Ut.active,d,ie]),Gt=(0,R.useMemo)(()=>C?Ut.archived.slice(0,oe):[],[Ut.archived,C,oe]),Kt=Ut.active.length>Wt.length,qt=C&&Ut.archived.length>Gt.length,Jt=(0,R.useMemo)(()=>d?new Set(e3(l?.sessions??[],d).map(e=>e.piboSessionId)):YLe,[l?.sessions,d]),Xt=(0,R.useCallback)(async e=>{if(!Fe)return;let t=(e?Gt:Wt).at(-1)?.piboSessionId;e?re(!0):ne(!0);try{let r=e?X9:Y9,i=await n.fetchQuery({queryKey:aje(Fe,e,t,r),queryFn:()=>lc({roomId:Fe,piboSessionId:d??void 0,archived:e,cursor:t,limit:r}),staleTime:3e4,gcTime:30*6e4});u(e=>e&&{...e,sessions:U9(e.sessions,i.sessions)}),e?se(e=>e+r):ae(e=>e+r)}finally{e?re(!1):ne(!1)}},[Fe,n,d,Wt,Gt]);if(h&&!l)return(0,z.jsx)(FLe,{message:h});if(!l)return(0,z.jsx)(`div`,{className:`min-h-screen bg-[#101d22] text-slate-300 grid place-items-center`,children:`Loading Pibo Chat...`});let Zt=d?$4(l.sessions,d):void 0,Qt=d?De?.sessions[d]:void 0,$t=De?.rootPiboSessionId?De.sessions[De.rootPiboSessionId]:void 0,en=Q4(l,Zt??{profile:Z4(l),parentId:l.session?.parentId}),tn=Yje(l.rooms),nn=[...new Set([...l.agents.map(e=>e.name),...l.customAgents.map(e=>e.profileName)])],rn=Eje(l);return(0,z.jsxs)(z.Fragment,{children:[Te===`fallback`?(0,z.jsx)(MLe,{}):null,(0,z.jsxs)(`div`,{"data-pibo-debug":`chat-app`,"data-pibo-area":r,"data-pibo-room-id":p??l.selectedRoomId??void 0,"data-pibo-selected-session-id":d??l.selectedPiboSessionId??void 0,className:`h-dvh overflow-hidden bg-[#101d22] text-slate-200 grid grid-rows-[auto_auto_1fr]`,children:[(0,z.jsx)(NLe,{area:r,identity:rn,mobileAreaMenuOpen:Se,mobileAreaMenuRef:we,totalRoomUnreadCount:tn,onOpenMobileSidebar:()=>xe(!0),onSelectMainNavArea:e=>{if(Ce(!1),e===`sessions`){ze(p??l.selectedRoomId,d??l.selectedPiboSessionId);return}if(e===`projects`){Re({area:`projects`});return}Re({area:e})},onToggleMobileAreaMenu:()=>Ce(e=>!e)}),(0,z.jsx)(`div`,{children:h?(0,z.jsx)(PLe,{message:h,onDismiss:()=>g(null)}):null}),(0,z.jsx)(`div`,{"data-pibo-debug":`route-shell`,"data-pibo-area":r,"data-pibo-room-id":p??l.selectedRoomId??void 0,"data-pibo-selected-session-id":d??void 0,className:`min-h-0 ${r===`agents`||r===`workflows`||r===`cron`||r===`ralph`?`h-full overflow-hidden`:`grid ${(r===`sessions`||r===`projects`)&&x?`grid-cols-[300px_minmax(0,1fr)_320px] max-[980px]:grid-cols-1`:`grid-cols-[300px_minmax(0,1fr)] max-[980px]:grid-cols-1`}`}`,children:r===`cron`?(0,z.jsx)(zve,{bootstrap:l,mobileSidebarOpen:be,onCloseMobileSidebar:()=>xe(!1)}):r===`ralph`?(0,z.jsx)(fye,{bootstrap:l,mobileSidebarOpen:be,onCloseMobileSidebar:()=>xe(!1)}):r===`agents`?(0,z.jsx)(QOe,{agents:l.agents,initialCustomAgents:l.customAgents,initialCatalog:l.agentCatalog,modelCatalog:l.modelCatalog,onSelect:et,onCreateSession:e=>void jt(e),onEditContextFile:He,onEditMcpServer:Ue,onAgentsChanged:()=>void Ye(d??void 0,je.current,p??void 0,{selectSession:!1}),creatingSession:F||Le}):r===`workflows`?(0,z.jsx)(SOe,{draftId:e.area===`workflows`?e.draftId:void 0,viewWorkflowId:e.area===`workflows`?e.viewWorkflowId:void 0,viewWorkflowVersion:e.area===`workflows`?e.viewWorkflowVersion:void 0}):r===`projects`?(0,z.jsx)(kLe,{baseBootstrap:l,routeProjectId:a,routePiboSessionId:o,sessionViews:Qe,showRawEvents:x,showThinking:_,expandThinking:y,commands:Dt,skills:Ot,mobileSidebarOpen:be,onCloseMobileSidebar:()=>xe(!1),onNavigate:Be,onViewContext:Ve,onSelectSessionView:Ht,onToggleRawEvents:()=>{let e=!x;S(e),i2(e)},onToggleThinking:()=>{let e=!_;v(e),n2(e)},onToggleExpandThinking:()=>{let e=!y;b(e),r2(e)},onThinkingLevelChange:e=>void yc(o??``,`thinking`,{level:e}),onError:g}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/60 min-[981px]:hidden transition-opacity duration-200 ${be?`opacity-100 pointer-events-auto`:`opacity-0 pointer-events-none`}`,onClick:()=>xe(!1)}),(0,z.jsxs)(`aside`,{"data-pibo-debug":`sidebar-shell`,"data-pibo-area":r,"data-pibo-room-id":p??l.selectedRoomId??void 0,"data-pibo-selected-session-id":d??void 0,"data-pibo-state":be?`open`:`closed`,className:`min-h-0 overflow-hidden flex flex-col bg-[#1a262b] border-r border-slate-800 max-[980px]:fixed max-[980px]:left-0 max-[980px]:top-0 max-[980px]:bottom-0 max-[980px]:z-40 max-[980px]:w-[280px] max-[980px]:transition-transform max-[980px]:duration-200 ${be?`max-[980px]:translate-x-0`:`max-[980px]:-translate-x-full`}`,children:[(0,z.jsxs)(`div`,{className:`h-11 px-3 border-b border-slate-800 flex items-center justify-between text-xs font-bold uppercase tracking-wider max-[980px]:h-auto max-[980px]:py-2 max-[980px]:flex-wrap`,children:[(0,z.jsx)(`span`,{children:r}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r===`sessions`?(0,z.jsx)(`button`,{type:`button`,onClick:()=>void Ye(d??void 0,je.current,p??void 0,{force:!0}).then(e=>{d&&tt(d),r===`sessions`&&ze(e.selectedRoomId,e.selectedPiboSessionId)}),title:`Refresh`,"aria-label":`Refresh`,className:`p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,children:(0,z.jsx)(Ls,{size:13})}):null,(0,z.jsx)(`button`,{type:`button`,onClick:()=>xe(!1),className:`min-[981px]:hidden p-1 border border-slate-700 rounded-sm text-slate-400 hover:border-[#11a4d4] hover:text-[#11a4d4]`,title:`Close sidebar`,"aria-label":`Close sidebar`,children:(0,z.jsx)(Qs,{size:13})})]})]}),r===`sessions`?(0,z.jsx)(tMe,{bootstrap:l,selectedRoomId:p,selectedPiboSessionId:d,showArchivedRooms:T,onToggleArchivedRooms:()=>{let e=!T;E(e),a2(e)},creatingRoom:ve,onCreateRoom:()=>Ft(),onSelectRoom:At,onUpdateRoom:It,onArchiveRoom:Rt,onReadAllRoom:Lt,onDeleteRoom:ft,newSessionProfile:D,onNewSessionProfileChange:et,selectedRoomArchived:Le,creatingSession:F,onCreateSession:()=>jt(),showArchived:C,onToggleArchivedSessions:Mt,loadingArchivedSessions:L,visibleActiveSessions:Wt,visibleArchivedSessions:Gt,totalActiveSessionCount:Ut.active.length,totalArchivedSessionCount:Ut.archived.length,hasMoreActiveSessions:Kt,hasMoreArchivedSessions:qt,loadingActiveSessions:I,sessionListScrollRef:Me,onLoadMoreSessions:Xt,signalNow:ke,selectedSessionPathIds:Jt,onSelectSession:kt,onRenameSession:Nt,onArchiveSession:Pt,onDeleteSession:yt,onViewContext:Ve,loadingPiboSessionId:ce,autoRenameSessionId:ue,onAutoRenameConsumed:()=>de(null)}):r===`context`?(0,z.jsx)(jve,{activePanel:fe,onSelect:pe,toolCount:l.agentCatalog?.piboTools.length??0,mcpServerCount:l.agentCatalog?.mcpServers.length??0}):(0,z.jsx)(KIe,{activePanel:c,onSelect:e=>Re({area:`settings`,panel:e}),piPackageCount:l.agentCatalog?.piPackages.length??0,userSkillCount:l.agentCatalog?.userSkills.length??0})]}),r===`sessions`?(0,z.jsx)(a3,{bootstrap:l,selectedPiboSessionId:d,selectedRoomId:p,selectedRoomArchived:Le,selectedSessionProfile:Zt?.profile??Z4(l),selectedSessionActiveModel:en,selectedSessionStatus:F9(Qt??$t)??Zt?.status,selectedSessionSignal:Qt,sessionViewId:k,sessionViews:Qe,currentSessionView:$e,creatingSession:F,showRawEvents:x,showThinking:_,expandThinking:y,commands:Dt,skills:Ot,composerText:j,composerFocusSignal:N,onComposerTextChange:Ze,onToggleRawEvents:()=>{let e=!x;S(e),i2(e)},onToggleThinking:()=>{let e=!_;v(e),n2(e)},onToggleExpandThinking:()=>{let e=!y;b(e),r2(e)},onSessionAgentProfileChange:e=>void Et(e),onFork:Bt,onOpenSession:Vt,onSelectSessionView:Ht,onCommand:zt,onThinkingLevelChange:e=>void zt(`/thinking ${e}`),onRefreshTrace:nt,onRefreshBootstrap:rt,onSend:async(e,t,n,r)=>{if(!(!d||Le))try{await Tt.mutateAsync({piboSessionId:d,text:e,clientTxnId:r??t3(),roomId:p??void 0,webAnnotationIds:t,fileAttachmentPaths:n}),await Ye(d,je.current,p??void 0,{force:!0}),g(null)}catch(e){g(e instanceof Error?e.message:String(e))}},onError:g}):(0,z.jsx)(`main`,{className:`min-h-0 flex flex-col`,children:r===`context`?fe===`pibo-tools`?(0,z.jsx)(BW,{tools:l.agentCatalog?.piboTools??[]}):fe===`mcp-tools`?(0,z.jsx)(eG,{servers:l.agentCatalog?.mcpServers??[],selectedServerName:ge,onServerSaved:We}):fe===`build-context`?(0,z.jsx)(bve,{piboSessionId:o??null}):fe===`base-prompt`?(0,z.jsx)(Hge,{}):fe===`compaction-prompt`?(0,z.jsx)(Gge,{}):(0,z.jsx)(Tge,{agentProfiles:nn,selectedFileKey:me}):(0,z.jsx)(YIe,{activePanel:c,showThinking:_,setShowThinking:v,expandThinking:y,setExpandThinking:b,modelDefaults:l.modelDefaults,modelCatalog:l.modelCatalog,onModelDefaultsChanged:e=>{u(t=>t&&{...t,modelDefaults:e})},piPackages:l.agentCatalog?.piPackages,onPiPackageChanged:Ge,onPiPackageRemoved:Ke,userSkills:l.agentCatalog?.userSkills,onUserSkillChanged:qe,onUserSkillRemoved:Je,piboSessionId:d,onProviderAuthChanged:it})}),ct?(0,z.jsx)(jLe,{room:ct,confirmName:lt,deleting:ut,onConfirmNameChange:dt,onCancel:pt,onDelete:()=>void mt()}):null,ht?(0,z.jsx)(ALe,{session:ht,confirmText:gt,deleting:_t,onConfirmTextChange:vt,onCancel:bt,onDelete:()=>void xt()}):null]})})]})]})}function Q9(e,t){return e.find(e=>e.name===t||e.aliases.includes(t))}var QLe=new Gt({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1}}});function $Le(){let e=ho({select:e=>({pathname:e.location.pathname,search:e.location.search})});return(0,z.jsx)(ZLe,{route:Dc(e.pathname,e.search)})}var $9=Xa({component:$Le}),eRe=Ja({getParentRoute:()=>$9,path:`/`}),tRe=Ja({getParentRoute:()=>$9,path:`sessions/$piboSessionId`}),nRe=Ja({getParentRoute:()=>$9,path:`rooms/$roomId`}),rRe=Ja({getParentRoute:()=>$9,path:`rooms/$roomId/sessions/$piboSessionId`}),iRe=Ja({getParentRoute:()=>$9,path:`projects`}),aRe=Ja({getParentRoute:()=>$9,path:`projects/$projectId`}),oRe=Ja({getParentRoute:()=>$9,path:`projects/$projectId/sessions/$piboSessionId`}),sRe=Ja({getParentRoute:()=>$9,path:`workflows`}),cRe=Ja({getParentRoute:()=>$9,path:`workflows/drafts/$draftId`}),lRe=Ja({getParentRoute:()=>$9,path:`workflows/view/$workflowId/$workflowVersion`}),uRe=Ja({getParentRoute:()=>$9,path:`agents`}),dRe=Ja({getParentRoute:()=>$9,path:`cron`}),fRe=Ja({getParentRoute:()=>$9,path:`ralph`}),pRe=Ja({getParentRoute:()=>$9,path:`context`}),mRe=Ja({getParentRoute:()=>$9,path:`settings`}),hRe=Ja({getParentRoute:()=>$9,path:`settings/shortcuts`}),gRe=Ja({getParentRoute:()=>$9,path:`settings/pi-packages`}),_Re=Ja({getParentRoute:()=>$9,path:`settings/skills`}),vRe=Ja({getParentRoute:()=>$9,path:`settings/providers`}),yRe=uo({routeTree:$9.addChildren([eRe,tRe,nRe,rRe,iRe,aRe,oRe,sRe,cRe,lRe,uRe,dRe,fRe,pRe,mRe,hRe,gRe,_Re,vRe]),basepath:`/apps/chat`});`serviceWorker`in navigator&&window.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/apps/chat/sw.js`).catch(()=>{})}),(0,$s.createRoot)(document.getElementById(`root`)).render((0,z.jsx)(R.StrictMode,{children:(0,z.jsx)(Xt,{client:QLe,children:(0,z.jsx)(mo,{router:yRe})})}));export{rfe as i,tP as n,xde as r,$N as t};
|