var BankmlSpaceUIF=function(ae){"use strict";var qa={exports:{}},Oo={},eu={exports:{}},ee={};/** * @license React * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Tr=Symbol.for("react.element"),zp=Symbol.for("react.portal"),Dp=Symbol.for("react.fragment"),Ip=Symbol.for("react.strict_mode"),Ap=Symbol.for("react.profiler"),Fp=Symbol.for("react.provider"),Hp=Symbol.for("react.context"),Up=Symbol.for("react.forward_ref"),Bp=Symbol.for("react.suspense"),Wp=Symbol.for("react.memo"),Vp=Symbol.for("react.lazy"),tu=Symbol.iterator;function Kp(e){return e===null||typeof e!="object"?null:(e=tu&&e[tu]||e["@@iterator"],typeof e=="function"?e:null)}var nu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},ru=Object.assign,ou={};function Gn(e,t,n){this.props=e,this.context=t,this.refs=ou,this.updater=n||nu}Gn.prototype.isReactComponent={},Gn.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): 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")},Gn.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function iu(){}iu.prototype=Gn.prototype;function hs(e,t,n){this.props=e,this.context=t,this.refs=ou,this.updater=n||nu}var gs=hs.prototype=new iu;gs.constructor=hs,ru(gs,Gn.prototype),gs.isPureReactComponent=!0;var su=Array.isArray,lu=Object.prototype.hasOwnProperty,ys={current:null},au={key:!0,ref:!0,__self:!0,__source:!0};function uu(e,t,n){var r,o={},i=null,s=null;if(t!=null)for(r in t.ref!==void 0&&(s=t.ref),t.key!==void 0&&(i=""+t.key),t)lu.call(t,r)&&!au.hasOwnProperty(r)&&(o[r]=t[r]);var l=arguments.length-2;if(l===1)o.children=n;else if(1>>1,te=D[G];if(0>>1;Go(_e,B))Weo(Ve,_e)?(D[G]=Ve,D[We]=B,G=We):(D[G]=_e,D[ve]=B,G=ve);else if(Weo(Ve,B))D[G]=Ve,D[We]=B,G=We;else break e}}return I}function o(D,I){var B=D.sortIndex-I.sortIndex;return B!==0?B:D.id-I.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var s=Date,l=s.now();e.unstable_now=function(){return s.now()-l}}var a=[],f=[],v=1,g=null,m=3,y=!1,k=!1,x=!1,w=typeof setTimeout=="function"?setTimeout:null,u=typeof clearTimeout=="function"?clearTimeout:null,d=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function p(D){for(var I=n(f);I!==null;){if(I.callback===null)r(f);else if(I.startTime<=D)r(f),I.sortIndex=I.expirationTime,t(a,I);else break;I=n(f)}}function S(D){if(x=!1,p(D),!k)if(n(a)!==null)k=!0,X($);else{var I=n(f);I!==null&&Y(S,I.startTime-D)}}function $(D,I){k=!1,x&&(x=!1,u(M),M=-1),y=!0;var B=m;try{for(p(I),g=n(a);g!==null&&(!(g.expirationTime>I)||D&&!F());){var G=g.callback;if(typeof G=="function"){g.callback=null,m=g.priorityLevel;var te=G(g.expirationTime<=I);I=e.unstable_now(),typeof te=="function"?g.callback=te:g===n(a)&&r(a),p(I)}else r(a);g=n(a)}if(g!==null)var Ae=!0;else{var ve=n(f);ve!==null&&Y(S,ve.startTime-I),Ae=!1}return Ae}finally{g=null,m=B,y=!1}}var P=!1,C=null,M=-1,N=5,O=-1;function F(){return!(e.unstable_now()-OD||125G?(D.sortIndex=B,t(f,D),n(a)===null&&D===n(f)&&(x?(u(M),M=-1):x=!0,Y(S,B-G))):(D.sortIndex=te,t(a,D),k||y||(k=!0,X($))),D},e.unstable_shouldYield=F,e.unstable_wrapCallback=function(D){var I=m;return function(){var B=m;m=I;try{return D.apply(this,arguments)}finally{m=B}}}})(hu),mu.exports=hu;var rm=mu.exports;/** * @license React * react-dom.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var om=h,et=rm;function z(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Ss=Object.prototype.hasOwnProperty,im=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,yu={},vu={};function sm(e){return Ss.call(vu,e)?!0:Ss.call(yu,e)?!1:im.test(e)?vu[e]=!0:(yu[e]=!0,!1)}function lm(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function am(e,t,n,r){if(t===null||typeof t>"u"||lm(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function He(e,t,n,r,o,i,s){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=i,this.removeEmptyString=s}var Me={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Me[e]=new He(e,0,!1,e,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Me[t]=new He(t,1,!1,e[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(e){Me[e]=new He(e,2,!1,e.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Me[e]=new He(e,2,!1,e,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){Me[e]=new He(e,3,!1,e.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(e){Me[e]=new He(e,3,!0,e,null,!1,!1)}),["capture","download"].forEach(function(e){Me[e]=new He(e,4,!1,e,null,!1,!1)}),["cols","rows","size","span"].forEach(function(e){Me[e]=new He(e,6,!1,e,null,!1,!1)}),["rowSpan","start"].forEach(function(e){Me[e]=new He(e,5,!1,e.toLowerCase(),null,!1,!1)});var xs=/[\-:]([a-z])/g;function Es(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(xs,Es);Me[t]=new He(t,1,!1,e,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(xs,Es);Me[t]=new He(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(xs,Es);Me[t]=new He(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(e){Me[e]=new He(e,1,!1,e.toLowerCase(),null,!1,!1)}),Me.xlinkHref=new He("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(e){Me[e]=new He(e,1,!1,e.toLowerCase(),null,!0,!0)});function Cs(e,t,n,r){var o=Me.hasOwnProperty(t)?Me[t]:null;(o!==null?o.type!==0:r||!(2l||o[s]!==i[l]){var a=` `+o[s].replace(" at new "," at ");return e.displayName&&a.includes("")&&(a=a.replace("",e.displayName)),a}while(1<=s&&0<=l);break}}}finally{Ts=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?Or(e):""}function um(e){switch(e.tag){case 5:return Or(e.type);case 16:return Or("Lazy");case 13:return Or("Suspense");case 19:return Or("SuspenseList");case 0:case 2:case 15:return e=Rs(e.type,!1),e;case 11:return e=Rs(e.type.render,!1),e;case 1:return e=Rs(e.type,!0),e;default:return""}}function bs(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case qn:return"Fragment";case Zn:return"Portal";case js:return"Profiler";case Ns:return"StrictMode";case _s:return"Suspense";case Ls:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case ku:return(e.displayName||"Context")+".Consumer";case wu:return(e._context.displayName||"Context")+".Provider";case $s:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Ps:return t=e.displayName||null,t!==null?t:bs(e.type)||"Memo";case Zt:t=e._payload,e=e._init;try{return bs(e(t))}catch{}}return null}function cm(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return bs(t);case 8:return t===Ns?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function qt(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Eu(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function dm(e){var t=Eu(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var o=n.get,i=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return o.call(this)},set:function(s){r=""+s,i.call(this,s)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Fo(e){e._valueTracker||(e._valueTracker=dm(e))}function Cu(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=Eu(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Ho(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Os(e,t){var n=t.checked;return pe({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Nu(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=qt(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function ju(e,t){t=t.checked,t!=null&&Cs(e,"checked",t,!1)}function zs(e,t){ju(e,t);var n=qt(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Ds(e,t.type,n):t.hasOwnProperty("defaultValue")&&Ds(e,t.type,qt(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function $u(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Ds(e,t,n){(t!=="number"||Ho(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var zr=Array.isArray;function er(e,t,n,r){if(e=e.options,t){t={};for(var o=0;o"+t.valueOf().toString()+"",t=Uo.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Dr(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Ir={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},fm=["Webkit","ms","Moz","O"];Object.keys(Ir).forEach(function(e){fm.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Ir[t]=Ir[e]})});function Ru(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Ir.hasOwnProperty(e)&&Ir[e]?(""+t).trim():t+"px"}function bu(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=Ru(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,o):e[n]=o}}var pm=pe({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Fs(e,t){if(t){if(pm[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(z(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(z(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(z(61))}if(t.style!=null&&typeof t.style!="object")throw Error(z(62))}}function Hs(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Us=null;function Bs(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Ws=null,tr=null,nr=null;function Ou(e){if(e=so(e)){if(typeof Ws!="function")throw Error(z(280));var t=e.stateNode;t&&(t=di(t),Ws(e.stateNode,e.type,t))}}function zu(e){tr?nr?nr.push(e):nr=[e]:tr=e}function Du(){if(tr){var e=tr,t=nr;if(nr=tr=null,Ou(e),t)for(e=0;e>>=0,e===0?32:31-(Cm(e)/Nm|0)|0}var Yo=64,Qo=4194304;function Ur(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Xo(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,o=e.suspendedLanes,i=e.pingedLanes,s=n&268435455;if(s!==0){var l=s&~o;l!==0?r=Ur(l):(i&=s,i!==0&&(r=Ur(i)))}else s=n&~o,s!==0?r=Ur(s):i!==0&&(r=Ur(i));if(r===0)return 0;if(t!==0&&t!==r&&!(t&o)&&(o=r&-r,i=t&-t,o>=i||o===16&&(i&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function Br(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-gt(t),e[t]=n}function Lm(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Jr),dc=" ",fc=!1;function pc(e,t){switch(e){case"keyup":return rh.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function mc(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ir=!1;function ih(e,t){switch(e){case"compositionend":return mc(t);case"keypress":return t.which!==32?null:(fc=!0,dc);case"textInput":return e=t.data,e===dc&&fc?null:e;default:return null}}function sh(e,t){if(ir)return e==="compositionend"||!al&&pc(e,t)?(e=ic(),ei=nl=on=null,ir=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Sc(n)}}function Ec(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Ec(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function Cc(){for(var e=window,t=Ho();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Ho(e.document)}return t}function dl(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function hh(e){var t=Cc(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&Ec(n.ownerDocument.documentElement,n)){if(r!==null&&dl(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var o=n.textContent.length,i=Math.min(r.start,o);r=r.end===void 0?i:Math.min(r.end,o),!e.extend&&i>r&&(o=r,r=i,i=o),o=xc(n,i);var s=xc(n,r);o&&s&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==s.node||e.focusOffset!==s.offset)&&(t=t.createRange(),t.setStart(o.node,o.offset),e.removeAllRanges(),i>r?(e.addRange(t),e.extend(s.node,s.offset)):(t.setEnd(s.node,s.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,sr=null,fl=null,to=null,pl=!1;function Nc(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;pl||sr==null||sr!==Ho(r)||(r=sr,"selectionStart"in r&&dl(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),to&&eo(to,r)||(to=r,r=ai(fl,"onSelect"),0dr||(e.current=Nl[dr],Nl[dr]=null,dr--)}function ue(e,t){dr++,Nl[dr]=e.current,e.current=t}var un={},be=an(un),Ke=an(!1),_n=un;function fr(e,t){var n=e.type.contextTypes;if(!n)return un;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var o={},i;for(i in n)o[i]=t[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=o),o}function Ye(e){return e=e.childContextTypes,e!=null}function fi(){de(Ke),de(be)}function Fc(e,t,n){if(be.current!==un)throw Error(z(168));ue(be,t),ue(Ke,n)}function Hc(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var o in r)if(!(o in t))throw Error(z(108,cm(e)||"Unknown",o));return pe({},n,r)}function pi(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||un,_n=be.current,ue(be,e),ue(Ke,Ke.current),!0}function Uc(e,t,n){var r=e.stateNode;if(!r)throw Error(z(169));n?(e=Hc(e,t,_n),r.__reactInternalMemoizedMergedChildContext=e,de(Ke),de(be),ue(be,e)):de(Ke),ue(Ke,n)}var Ut=null,mi=!1,jl=!1;function Bc(e){Ut===null?Ut=[e]:Ut.push(e)}function $h(e){mi=!0,Bc(e)}function cn(){if(!jl&&Ut!==null){jl=!0;var e=0,t=le;try{var n=Ut;for(le=1;e>=s,o-=s,Bt=1<<32-gt(t)+o|n<M?(N=C,C=null):N=C.sibling;var O=m(u,C,p[M],S);if(O===null){C===null&&(C=N);break}e&&C&&O.alternate===null&&t(u,C),d=i(O,d,M),P===null?$=O:P.sibling=O,P=O,C=N}if(M===p.length)return n(u,C),fe&&Pn(u,M),$;if(C===null){for(;MM?(N=C,C=null):N=C.sibling;var F=m(u,C,O.value,S);if(F===null){C===null&&(C=N);break}e&&C&&F.alternate===null&&t(u,C),d=i(F,d,M),P===null?$=F:P.sibling=F,P=F,C=N}if(O.done)return n(u,C),fe&&Pn(u,M),$;if(C===null){for(;!O.done;M++,O=p.next())O=g(u,O.value,S),O!==null&&(d=i(O,d,M),P===null?$=O:P.sibling=O,P=O);return fe&&Pn(u,M),$}for(C=r(u,C);!O.done;M++,O=p.next())O=y(C,u,M,O.value,S),O!==null&&(e&&O.alternate!==null&&C.delete(O.key===null?M:O.key),d=i(O,d,M),P===null?$=O:P.sibling=O,P=O);return e&&C.forEach(function(K){return t(u,K)}),fe&&Pn(u,M),$}function w(u,d,p,S){if(typeof p=="object"&&p!==null&&p.type===qn&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case Ao:e:{for(var $=p.key,P=d;P!==null;){if(P.key===$){if($=p.type,$===qn){if(P.tag===7){n(u,P.sibling),d=o(P,p.props.children),d.return=u,u=d;break e}}else if(P.elementType===$||typeof $=="object"&&$!==null&&$.$$typeof===Zt&&Xc($)===P.type){n(u,P.sibling),d=o(P,p.props),d.ref=lo(u,P,p),d.return=u,u=d;break e}n(u,P);break}else t(u,P);P=P.sibling}p.type===qn?(d=In(p.props.children,u.mode,S,p.key),d.return=u,u=d):(S=Ui(p.type,p.key,p.props,null,u.mode,S),S.ref=lo(u,d,p),S.return=u,u=S)}return s(u);case Zn:e:{for(P=p.key;d!==null;){if(d.key===P)if(d.tag===4&&d.stateNode.containerInfo===p.containerInfo&&d.stateNode.implementation===p.implementation){n(u,d.sibling),d=o(d,p.children||[]),d.return=u,u=d;break e}else{n(u,d);break}else t(u,d);d=d.sibling}d=Ea(p,u.mode,S),d.return=u,u=d}return s(u);case Zt:return P=p._init,w(u,d,P(p._payload),S)}if(zr(p))return k(u,d,p,S);if(br(p))return x(u,d,p,S);vi(u,p)}return typeof p=="string"&&p!==""||typeof p=="number"?(p=""+p,d!==null&&d.tag===6?(n(u,d.sibling),d=o(d,p),d.return=u,u=d):(n(u,d),d=xa(p,u.mode,S),d.return=u,u=d),s(u)):n(u,d)}return w}var gr=Gc(!0),Jc=Gc(!1),wi=an(null),ki=null,yr=null,Tl=null;function Rl(){Tl=yr=ki=null}function bl(e){var t=wi.current;de(wi),e._currentValue=t}function Ol(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function vr(e,t){ki=e,Tl=yr=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Qe=!0),e.firstContext=null)}function ct(e){var t=e._currentValue;if(Tl!==e)if(e={context:e,memoizedValue:t,next:null},yr===null){if(ki===null)throw Error(z(308));yr=e,ki.dependencies={lanes:0,firstContext:e}}else yr=yr.next=e;return t}var Mn=null;function zl(e){Mn===null?Mn=[e]:Mn.push(e)}function Zc(e,t,n,r){var o=t.interleaved;return o===null?(n.next=n,zl(t)):(n.next=o.next,o.next=n),t.interleaved=n,Vt(e,r)}function Vt(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var dn=!1;function Dl(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function qc(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Kt(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function fn(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,oe&2){var o=r.pending;return o===null?t.next=t:(t.next=o.next,o.next=t),r.pending=t,Vt(e,n)}return o=r.interleaved,o===null?(t.next=t,zl(r)):(t.next=o.next,o.next=t),r.interleaved=t,Vt(e,n)}function Si(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Js(e,n)}}function ed(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var o=null,i=null;if(n=n.firstBaseUpdate,n!==null){do{var s={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};i===null?o=i=s:i=i.next=s,n=n.next}while(n!==null);i===null?o=i=t:i=i.next=t}else o=i=t;n={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function xi(e,t,n,r){var o=e.updateQueue;dn=!1;var i=o.firstBaseUpdate,s=o.lastBaseUpdate,l=o.shared.pending;if(l!==null){o.shared.pending=null;var a=l,f=a.next;a.next=null,s===null?i=f:s.next=f,s=a;var v=e.alternate;v!==null&&(v=v.updateQueue,l=v.lastBaseUpdate,l!==s&&(l===null?v.firstBaseUpdate=f:l.next=f,v.lastBaseUpdate=a))}if(i!==null){var g=o.baseState;s=0,v=f=a=null,l=i;do{var m=l.lane,y=l.eventTime;if((r&m)===m){v!==null&&(v=v.next={eventTime:y,lane:0,tag:l.tag,payload:l.payload,callback:l.callback,next:null});e:{var k=e,x=l;switch(m=t,y=n,x.tag){case 1:if(k=x.payload,typeof k=="function"){g=k.call(y,g,m);break e}g=k;break e;case 3:k.flags=k.flags&-65537|128;case 0:if(k=x.payload,m=typeof k=="function"?k.call(y,g,m):k,m==null)break e;g=pe({},g,m);break e;case 2:dn=!0}}l.callback!==null&&l.lane!==0&&(e.flags|=64,m=o.effects,m===null?o.effects=[l]:m.push(l))}else y={eventTime:y,lane:m,tag:l.tag,payload:l.payload,callback:l.callback,next:null},v===null?(f=v=y,a=g):v=v.next=y,s|=m;if(l=l.next,l===null){if(l=o.shared.pending,l===null)break;m=l,l=m.next,m.next=null,o.lastBaseUpdate=m,o.shared.pending=null}}while(!0);if(v===null&&(a=g),o.baseState=a,o.firstBaseUpdate=f,o.lastBaseUpdate=v,t=o.shared.interleaved,t!==null){o=t;do s|=o.lane,o=o.next;while(o!==t)}else i===null&&(o.shared.lanes=0);bn|=s,e.lanes=s,e.memoizedState=g}}function td(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Ul.transition;Ul.transition={};try{e(!1),t()}finally{le=n,Ul.transition=r}}function kd(){return dt().memoizedState}function Mh(e,t,n){var r=gn(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Sd(e))xd(t,n);else if(n=Zc(e,t,n,r),n!==null){var o=Be();xt(n,e,r,o),Ed(n,t,r)}}function Th(e,t,n){var r=gn(e),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Sd(e))xd(t,o);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=t.lastRenderedReducer,i!==null))try{var s=t.lastRenderedState,l=i(s,n);if(o.hasEagerState=!0,o.eagerState=l,yt(l,s)){var a=t.interleaved;a===null?(o.next=o,zl(t)):(o.next=a.next,a.next=o),t.interleaved=o;return}}catch{}finally{}n=Zc(e,t,o,r),n!==null&&(o=Be(),xt(n,e,r,o),Ed(n,t,r))}}function Sd(e){var t=e.alternate;return e===he||t!==null&&t===he}function xd(e,t){fo=Ni=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Ed(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Js(e,n)}}var _i={readContext:ct,useCallback:Oe,useContext:Oe,useEffect:Oe,useImperativeHandle:Oe,useInsertionEffect:Oe,useLayoutEffect:Oe,useMemo:Oe,useReducer:Oe,useRef:Oe,useState:Oe,useDebugValue:Oe,useDeferredValue:Oe,useTransition:Oe,useMutableSource:Oe,useSyncExternalStore:Oe,useId:Oe,unstable_isNewReconciler:!1},Rh={readContext:ct,useCallback:function(e,t){return Mt().memoizedState=[e,t===void 0?null:t],e},useContext:ct,useEffect:fd,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,ji(4194308,4,hd.bind(null,t,e),n)},useLayoutEffect:function(e,t){return ji(4194308,4,e,t)},useInsertionEffect:function(e,t){return ji(4,2,e,t)},useMemo:function(e,t){var n=Mt();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Mt();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=Mh.bind(null,he,e),[r.memoizedState,e]},useRef:function(e){var t=Mt();return e={current:e},t.memoizedState=e},useState:cd,useDebugValue:Xl,useDeferredValue:function(e){return Mt().memoizedState=e},useTransition:function(){var e=cd(!1),t=e[0];return e=Ph.bind(null,e[1]),Mt().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=he,o=Mt();if(fe){if(n===void 0)throw Error(z(407));n=n()}else{if(n=t(),$e===null)throw Error(z(349));Rn&30||id(r,t,n)}o.memoizedState=n;var i={value:n,getSnapshot:t};return o.queue=i,fd(ld.bind(null,r,i,e),[e]),r.flags|=2048,ho(9,sd.bind(null,r,i,n,t),void 0,null),n},useId:function(){var e=Mt(),t=$e.identifierPrefix;if(fe){var n=Wt,r=Bt;n=(r&~(1<<32-gt(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=po++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=s.createElement(n,{is:r.is}):(e=s.createElement(n),n==="select"&&(s=e,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):e=s.createElementNS(e,n),e[Lt]=t,e[io]=r,Bd(e,t,!1,!1),t.stateNode=e;e:{switch(s=Hs(n,r),n){case"dialog":ce("cancel",e),ce("close",e),o=r;break;case"iframe":case"object":case"embed":ce("load",e),o=r;break;case"video":case"audio":for(o=0;oEr&&(t.flags|=128,r=!0,go(i,!1),t.lanes=4194304)}else{if(!r)if(e=Ei(s),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),go(i,!0),i.tail===null&&i.tailMode==="hidden"&&!s.alternate&&!fe)return ze(t),null}else 2*we()-i.renderingStartTime>Er&&n!==1073741824&&(t.flags|=128,r=!0,go(i,!1),t.lanes=4194304);i.isBackwards?(s.sibling=t.child,t.child=s):(n=i.last,n!==null?n.sibling=s:t.child=s,i.last=s)}return i.tail!==null?(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=we(),t.sibling=null,n=me.current,ue(me,r?n&1|2:n&1),t):(ze(t),null);case 22:case 23:return wa(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?ot&1073741824&&(ze(t),t.subtreeFlags&6&&(t.flags|=8192)):ze(t),null;case 24:return null;case 25:return null}throw Error(z(156,t.tag))}function Hh(e,t){switch(_l(t),t.tag){case 1:return Ye(t.type)&&fi(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return wr(),de(Ke),de(be),Hl(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Al(t),null;case 13:if(de(me),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(z(340));hr()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return de(me),null;case 4:return wr(),null;case 10:return bl(t.type._context),null;case 22:case 23:return wa(),null;case 24:return null;default:return null}}var Ti=!1,De=!1,Uh=typeof WeakSet=="function"?WeakSet:Set,U=null;function Sr(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){ye(e,t,r)}else n.current=null}function la(e,t,n){try{n()}catch(r){ye(e,t,r)}}var Kd=!1;function Bh(e,t){if(wl=Zo,e=Cc(),dl(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var o=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{n.nodeType,i.nodeType}catch{n=null;break e}var s=0,l=-1,a=-1,f=0,v=0,g=e,m=null;t:for(;;){for(var y;g!==n||o!==0&&g.nodeType!==3||(l=s+o),g!==i||r!==0&&g.nodeType!==3||(a=s+r),g.nodeType===3&&(s+=g.nodeValue.length),(y=g.firstChild)!==null;)m=g,g=y;for(;;){if(g===e)break t;if(m===n&&++f===o&&(l=s),m===i&&++v===r&&(a=s),(y=g.nextSibling)!==null)break;g=m,m=g.parentNode}g=y}n=l===-1||a===-1?null:{start:l,end:a}}else n=null}n=n||{start:0,end:0}}else n=null;for(kl={focusedElem:e,selectionRange:n},Zo=!1,U=t;U!==null;)if(t=U,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,U=e;else for(;U!==null;){t=U;try{var k=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(k!==null){var x=k.memoizedProps,w=k.memoizedState,u=t.stateNode,d=u.getSnapshotBeforeUpdate(t.elementType===t.type?x:wt(t.type,x),w);u.__reactInternalSnapshotBeforeUpdate=d}break;case 3:var p=t.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(z(163))}}catch(S){ye(t,t.return,S)}if(e=t.sibling,e!==null){e.return=t.return,U=e;break}U=t.return}return k=Kd,Kd=!1,k}function yo(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var o=r=r.next;do{if((o.tag&e)===e){var i=o.destroy;o.destroy=void 0,i!==void 0&&la(t,n,i)}o=o.next}while(o!==r)}}function Ri(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function aa(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function Yd(e){var t=e.alternate;t!==null&&(e.alternate=null,Yd(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Lt],delete t[io],delete t[Cl],delete t[Nh],delete t[jh])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Qd(e){return e.tag===5||e.tag===3||e.tag===4}function Xd(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Qd(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function ua(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=ci));else if(r!==4&&(e=e.child,e!==null))for(ua(e,t,n),e=e.sibling;e!==null;)ua(e,t,n),e=e.sibling}function ca(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(ca(e,t,n),e=e.sibling;e!==null;)ca(e,t,n),e=e.sibling}var Te=null,kt=!1;function pn(e,t,n){for(n=n.child;n!==null;)Gd(e,t,n),n=n.sibling}function Gd(e,t,n){if(_t&&typeof _t.onCommitFiberUnmount=="function")try{_t.onCommitFiberUnmount(Ko,n)}catch{}switch(n.tag){case 5:De||Sr(n,t);case 6:var r=Te,o=kt;Te=null,pn(e,t,n),Te=r,kt=o,Te!==null&&(kt?(e=Te,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Te.removeChild(n.stateNode));break;case 18:Te!==null&&(kt?(e=Te,n=n.stateNode,e.nodeType===8?El(e.parentNode,n):e.nodeType===1&&El(e,n),Qr(e)):El(Te,n.stateNode));break;case 4:r=Te,o=kt,Te=n.stateNode.containerInfo,kt=!0,pn(e,t,n),Te=r,kt=o;break;case 0:case 11:case 14:case 15:if(!De&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var i=o,s=i.destroy;i=i.tag,s!==void 0&&(i&2||i&4)&&la(n,t,s),o=o.next}while(o!==r)}pn(e,t,n);break;case 1:if(!De&&(Sr(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){ye(n,t,l)}pn(e,t,n);break;case 21:pn(e,t,n);break;case 22:n.mode&1?(De=(r=De)||n.memoizedState!==null,pn(e,t,n),De=r):pn(e,t,n);break;default:pn(e,t,n)}}function Jd(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Uh),t.forEach(function(r){var o=Zh.bind(null,e,r);n.has(r)||(n.add(r),r.then(o,o))})}}function St(e,t){var n=t.deletions;if(n!==null)for(var r=0;ro&&(o=s),r&=~i}if(r=o,r=we()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Vh(r/1960))-r,10e?16:e,hn===null)var r=!1;else{if(e=hn,hn=null,Ii=0,oe&6)throw Error(z(331));var o=oe;for(oe|=4,U=e.current;U!==null;){var i=U,s=i.child;if(U.flags&16){var l=i.deletions;if(l!==null){for(var a=0;awe()-pa?zn(e,0):fa|=n),Ge(e,t)}function df(e,t){t===0&&(e.mode&1?(t=Qo,Qo<<=1,!(Qo&130023424)&&(Qo=4194304)):t=1);var n=Be();e=Vt(e,t),e!==null&&(Br(e,t,n),Ge(e,n))}function Jh(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),df(e,n)}function Zh(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,o=e.memoizedState;o!==null&&(n=o.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(z(314))}r!==null&&r.delete(t),df(e,n)}var ff;ff=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Ke.current)Qe=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Qe=!1,Ah(e,t,n);Qe=!!(e.flags&131072)}else Qe=!1,fe&&t.flags&1048576&&Wc(t,gi,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Mi(e,t),e=t.pendingProps;var o=fr(t,be.current);vr(t,n),o=Wl(null,t,r,e,o,n);var i=Vl();return t.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Ye(r)?(i=!0,pi(t)):i=!1,t.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,Dl(t),o.updater=Li,t.stateNode=o,o._reactInternals=t,Jl(t,r,e,n),t=ta(null,t,r,!0,i,n)):(t.tag=0,fe&&i&&$l(t),Ue(null,t,o,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Mi(e,t),e=t.pendingProps,o=r._init,r=o(r._payload),t.type=r,o=t.tag=eg(r),e=wt(r,e),o){case 0:t=ea(null,t,r,e,n);break e;case 1:t=Dd(null,t,r,e,n);break e;case 11:t=Td(null,t,r,e,n);break e;case 14:t=Rd(null,t,r,wt(r.type,e),n);break e}throw Error(z(306,r,""))}return t;case 0:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:wt(r,o),ea(e,t,r,o,n);case 1:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:wt(r,o),Dd(e,t,r,o,n);case 3:e:{if(Id(t),e===null)throw Error(z(387));r=t.pendingProps,i=t.memoizedState,o=i.element,qc(e,t),xi(t,r,null,n);var s=t.memoizedState;if(r=s.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},t.updateQueue.baseState=i,t.memoizedState=i,t.flags&256){o=kr(Error(z(423)),t),t=Ad(e,t,r,n,o);break e}else if(r!==o){o=kr(Error(z(424)),t),t=Ad(e,t,r,n,o);break e}else for(rt=ln(t.stateNode.containerInfo.firstChild),nt=t,fe=!0,vt=null,n=Jc(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(hr(),r===o){t=Yt(e,t,n);break e}Ue(e,t,r,n)}t=t.child}return t;case 5:return nd(t),e===null&&Pl(t),r=t.type,o=t.pendingProps,i=e!==null?e.memoizedProps:null,s=o.children,Sl(r,o)?s=null:i!==null&&Sl(r,i)&&(t.flags|=32),zd(e,t),Ue(e,t,s,n),t.child;case 6:return e===null&&Pl(t),null;case 13:return Fd(e,t,n);case 4:return Il(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=gr(t,null,r,n):Ue(e,t,r,n),t.child;case 11:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:wt(r,o),Td(e,t,r,o,n);case 7:return Ue(e,t,t.pendingProps,n),t.child;case 8:return Ue(e,t,t.pendingProps.children,n),t.child;case 12:return Ue(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,o=t.pendingProps,i=t.memoizedProps,s=o.value,ue(wi,r._currentValue),r._currentValue=s,i!==null)if(yt(i.value,s)){if(i.children===o.children&&!Ke.current){t=Yt(e,t,n);break e}}else for(i=t.child,i!==null&&(i.return=t);i!==null;){var l=i.dependencies;if(l!==null){s=i.child;for(var a=l.firstContext;a!==null;){if(a.context===r){if(i.tag===1){a=Kt(-1,n&-n),a.tag=2;var f=i.updateQueue;if(f!==null){f=f.shared;var v=f.pending;v===null?a.next=a:(a.next=v.next,v.next=a),f.pending=a}}i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),Ol(i.return,n,t),l.lanes|=n;break}a=a.next}}else if(i.tag===10)s=i.type===t.type?null:i.child;else if(i.tag===18){if(s=i.return,s===null)throw Error(z(341));s.lanes|=n,l=s.alternate,l!==null&&(l.lanes|=n),Ol(s,n,t),s=i.sibling}else s=i.child;if(s!==null)s.return=i;else for(s=i;s!==null;){if(s===t){s=null;break}if(i=s.sibling,i!==null){i.return=s.return,s=i;break}s=s.return}i=s}Ue(e,t,o.children,n),t=t.child}return t;case 9:return o=t.type,r=t.pendingProps.children,vr(t,n),o=ct(o),r=r(o),t.flags|=1,Ue(e,t,r,n),t.child;case 14:return r=t.type,o=wt(r,t.pendingProps),o=wt(r.type,o),Rd(e,t,r,o,n);case 15:return bd(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:wt(r,o),Mi(e,t),t.tag=1,Ye(r)?(e=!0,pi(t)):e=!1,vr(t,n),Nd(t,r,o),Jl(t,r,o,n),ta(null,t,r,!0,e,n);case 19:return Ud(e,t,n);case 22:return Od(e,t,n)}throw Error(z(156,t.tag))};function pf(e,t){return Vu(e,t)}function qh(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function pt(e,t,n,r){return new qh(e,t,n,r)}function Sa(e){return e=e.prototype,!(!e||!e.isReactComponent)}function eg(e){if(typeof e=="function")return Sa(e)?1:0;if(e!=null){if(e=e.$$typeof,e===$s)return 11;if(e===Ps)return 14}return 2}function vn(e,t){var n=e.alternate;return n===null?(n=pt(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function Ui(e,t,n,r,o,i){var s=2;if(r=e,typeof e=="function")Sa(e)&&(s=1);else if(typeof e=="string")s=5;else e:switch(e){case qn:return In(n.children,o,i,t);case Ns:s=8,o|=8;break;case js:return e=pt(12,n,t,o|2),e.elementType=js,e.lanes=i,e;case _s:return e=pt(13,n,t,o),e.elementType=_s,e.lanes=i,e;case Ls:return e=pt(19,n,t,o),e.elementType=Ls,e.lanes=i,e;case Su:return Bi(n,o,i,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case wu:s=10;break e;case ku:s=9;break e;case $s:s=11;break e;case Ps:s=14;break e;case Zt:s=16,r=null;break e}throw Error(z(130,e==null?e:typeof e,""))}return t=pt(s,n,t,o),t.elementType=e,t.type=r,t.lanes=i,t}function In(e,t,n,r){return e=pt(7,e,r,t),e.lanes=n,e}function Bi(e,t,n,r){return e=pt(22,e,r,t),e.elementType=Su,e.lanes=n,e.stateNode={isHidden:!1},e}function xa(e,t,n){return e=pt(6,e,null,t),e.lanes=n,e}function Ea(e,t,n){return t=pt(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function tg(e,t,n,r,o){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Gs(0),this.expirationTimes=Gs(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Gs(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function Ca(e,t,n,r,o,i,s,l,a){return e=new tg(e,t,n,l,a),t===1?(t=1,i===!0&&(t|=8)):t=0,i=pt(3,null,null,t),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Dl(i),e}function ng(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(wf)}catch(e){console.error(e)}}wf(),pu.exports=qe;var wn=pu.exports,kf=wn;ks.createRoot=kf.createRoot,ks.hydrateRoot=kf.hydrateRoot;function Ie(e,t){try{const n=window.localStorage.getItem(e);return n?JSON.parse(n):t}catch{return t}}function Je(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch{}}function Gi(e,t){if(!(t in e))return e;const{[t]:n,...r}=e;return r}function Sf(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"action"}function _a(e){return{id:e.id,label:e.label,icon:e.icon,command:e.command??Sf(e.label),description:e.kind==="send"?`send "${e.payload}"`:`run "${e.payload}"`,run(t){const n=t.args.length?" "+t.args.join(" "):"";e.kind==="send"?t.send(e.payload+n):e.payload.split(";").forEach(r=>r.trim()&&t.runCommand(r.trim()+n))}}}function lg(e={}){const t=e.storageKey?`uif:${e.storageKey}:actions`:null,r={...{order:[],hidden:[],custom:[],floating:{}},...t?Ie(t,{}):{}},o=new Map;let i=[...r.order],s=[...r.hidden],l=[...r.custom],a={...r.floating};const f=[],v=new Set;let g=0;const m=()=>{t&&Je(t,{order:i,hidden:s,custom:l,floating:a})},y=()=>{g++,m(),v.forEach(w=>w())},k=w=>{!f.includes(w.id)&&!l.some(u=>u.id===w.id)&&f.push(w.id),!(i.includes(w.id)||s.includes(w.id)||a[w.id])&&(w.defaultHidden?s.push(w.id):i.push(w.id))},x={register(w){o.set(w.id,w),k(w),y()},unregister(w){o.delete(w),y()},get:w=>o.get(w),find(w){var d;const u=w.toLowerCase();for(const p of o.values())if(p.command.toLowerCase()===u||(d=p.aliases)!=null&&d.some(S=>S.toLowerCase()===u))return p},all:()=>[...o.values()],visible:()=>i.map(w=>o.get(w)).filter(w=>!!w),hidden:()=>s.map(w=>o.get(w)).filter(w=>!!w),reorder(w,u){const d=x.visible().map($=>$.id);if(w<0||w>=d.length||u<0||u>=d.length||w===u)return;const[p]=d.splice(w,1);d.splice(u,0,p);const S=i.filter($=>!o.has($));i=[...d,...S],y()},hide(w){!i.includes(w)&&!a[w]||(i=i.filter(u=>u!==w),a=Gi(a,w),s=[...s.filter(u=>u!==w),w],y())},show(w,u){s=s.filter(p=>p!==w),a=Gi(a,w);const d=x.visible().map(p=>p.id).filter(p=>p!==w);d.splice(u??d.length,0,w),i=[...d,...i.filter(p=>!o.has(p)&&p!==w)],y()},addCustom(w){const u=Sf(w.label);let d=u;for(let $=2;x.find(d);$++)d=`${u}-${$}`;const p={id:`custom-${d}-${Date.now().toString(36)}`,label:w.label.trim(),command:d,icon:w.icon||void 0,kind:w.kind??"command",payload:w.payload};l=[...l,p];const S=_a(p);return o.set(S.id,S),i.push(S.id),y(),S},removeCustom(w){l=l.filter(u=>u.id!==w),o.delete(w),i=i.filter(u=>u!==w),s=s.filter(u=>u!==w),a=Gi(a,w),y()},floating:()=>Object.entries(a).map(([w,u])=>({action:o.get(w),at:u})).filter(w=>!!w.action),float(w,u){o.has(w)&&(i=i.filter(d=>d!==w),s=s.filter(d=>d!==w),a={...Gi(a,w),[w]:{x:Math.round(u.x),y:Math.round(u.y)}},y())},dockAt(w,u){o.has(w)&&x.show(w,u)},snapshot:()=>({order:[...i],hidden:[...s],custom:l.map(w=>({...w})),floating:Object.fromEntries(Object.entries(a).map(([w,u])=>[w,{...u}]))}),restore(w){for(const u of l)o.delete(u.id);l=w.custom.map(u=>({...u}));for(const u of l)o.set(u.id,_a(u));i=[...w.order],s=[...w.hidden],a={...w.floating};for(const u of f){const d=o.get(u);d&&k(d)}y()},reset(){const w=f.filter(u=>o.has(u));i=w.filter(u=>{var d;return!((d=o.get(u))!=null&&d.defaultHidden)}),s=[...w.filter(u=>{var d;return(d=o.get(u))==null?void 0:d.defaultHidden}),...l.map(u=>u.id)],a={},y()},isCustom:w=>l.some(u=>u.id===w),subscribe(w){return v.add(w),()=>v.delete(w)},version:()=>g};for(const w of l)o.set(w.id,_a(w));for(const w of e.actions??[])o.set(w.id,w),k(w);return x}function ag(e,t){const n=e.snapshot(),r=t.filter(o=>!(o in n.floating));return{...n,order:r,hidden:e.all().map(o=>o.id).filter(o=>!r.includes(o)&&!(o in n.floating))}}const xf=(e,t)=>{if(!(t in e))return e;const{[t]:n,...r}=e;return r};function ug(e,t){return{vis:e.order.filter(t),pending:e.order.filter(n=>!t(n))}}function Ef(e,t,n,r){const{vis:o,pending:i}=ug({...e,order:e.order.filter(l=>l!==t)},n),s=Math.max(0,Math.min(r??o.length,o.length));return o.splice(s,0,t),{...e,order:[...o,...i],hidden:e.hidden.filter(l=>l!==t),floating:xf(e.floating,t)}}function cg(e,t){return!e.order.includes(t)&&!(t in e.floating)?null:{...e,order:e.order.filter(n=>n!==t),floating:xf(e.floating,t),hidden:[...e.hidden.filter(n=>n!==t),t]}}function dg(e,t,n,r){return!e.order.includes(t)||!n(t)?null:Ef(e,t,n,r)}const fg=["top","bottom","left","right"];function xo(e,t){const n=e.outputs.resolve(e.args[0]);return n||e.print(`${t}: no output ${e.args[0]?`"${e.args[0]}"`:"is active"}`,"err"),n}const pg=[{id:"spawn",label:"Spawn output",command:"spawn",aliases:["new"],icon:"⊞",description:"spawn [title] [--window] [--screen N] [--present] [--speak] - open a new output, here or on another monitor, display or the speakers",builtin:!0,async run(e){const t=[],n={};for(let o=0;ol.id===o))==null?void 0:s.speak;e.print(e.outputs.setSpeak(o,n?n==="on":!i))}},{id:"present",label:"Present output",command:"present",aliases:["cast"],icon:"📺",description:"present [output] - show an output on another display or cast device (Presentation API)",builtin:!0,defaultHidden:!0,async run(e){const t=e.outputs.resolve(e.args.join(" ")||void 0);if(!t)return e.print("present: no output is active","err");e.print(await e.outputs.present(t))}},{id:"popout",label:"Pop out",command:"popout",aliases:["pop"],icon:"⧉",description:"popout [output] [--screen N] - move an output into its own window, on monitor N if given",builtin:!0,defaultHidden:!0,run(e){const t=e.args.indexOf("--screen"),n=t>=0?Number(e.args[t+1]):void 0;if(t>=0&&(!Number.isInteger(n)||n<1))return e.print("popout: --screen needs a monitor number","err");const r=(t>=0?[...e.args.slice(0,t),...e.args.slice(t+2)]:e.args).join(" "),o=e.outputs.resolve(r||void 0);if(!o)return e.print(`popout: no output ${r?`"${r}"`:"is active"}`,"err");const i=e.outputs.popOut(o,{screen:n});i&&e.print(i,"err")}},{id:"close",label:"Close output",command:"close",icon:"⊠",description:"close [output|all] - close an output field, or every one",builtin:!0,defaultHidden:!0,run(e){if(e.args[0]==="all"){const n=e.outputs.list().length;return e.outputs.closeAll(),e.print(`closed ${n} output${n===1?"":"s"}`)}const t=xo(e,"close");t&&e.outputs.close(t)}},{id:"max",label:"Fill the screen",command:"max",aliases:["maximize"],icon:"⤢",description:"max [output] - fill the screen with an output, or shrink it back (double-click its header does the same)",builtin:!0,defaultHidden:!0,run(e){const t=xo(e,"max");t&&e.outputs.maximize(t)}},{id:"tile",label:"Tile outputs",command:"tile",icon:"▦",description:"tile - arrange the outputs in a grid that fills the screen",builtin:!0,defaultHidden:!0,run(e){e.outputs.tile()}},{id:"cascade",label:"Cascade outputs",command:"cascade",icon:"◪",description:"cascade - stack the outputs, each a step down and right",builtin:!0,defaultHidden:!0,run(e){e.outputs.cascade()}},{id:"rename",label:"Rename output",command:"rename",icon:"✎",description:"rename - rename an output field",builtin:!0,defaultHidden:!0,run(e){const[t,...n]=e.args,r=n.join(" ").trim();if(!t||!r)return e.print("rename: usage rename ","err");const o=e.outputs.resolve(t);if(!o)return e.print(`rename: no output "${t}"`,"err");e.outputs.rename(o,r),e.print(`renamed ${t} to ${r}`)}},{id:"ping",label:"Ping output",command:"ping",icon:"◎",description:"ping [output] - flash an output so you can find it",builtin:!0,defaultHidden:!0,run(e){const t=xo(e,"ping");t&&e.outputs.ping(t)}},{id:"outputs",label:"List outputs",command:"outputs",aliases:["ls"],icon:"☷",description:"outputs - list output fields",builtin:!0,defaultHidden:!0,run(e){const t=e.outputs.list();if(!t.length)return e.print("no outputs");t.forEach((n,r)=>e.print(`${r+1} ${n.id} ${n.title} [${n.placement}]${n.id===e.outputs.activeId?" *":""}`))}},{id:"screens",label:"Screens",command:"screens",icon:"▭",description:"screens - allow pop-outs to open on other monitors",builtin:!0,defaultHidden:!0,async run(e){await e.requestScreens();const t=e.outputs.screens();t==null||t.forEach(n=>e.print(`${n.index} ${n.label} ${n.width}×${n.height}${n.primary?" primary":""}${n.current?" (this window)":""}`)),t&&e.print("spawn --screen N opens an output on monitor N")}},{id:"mode",label:"Toggle mode",command:"mode",aliases:["chat","t"],icon:"T",description:"mode [chat|terminal|persona] - switch between chat (generic), terminal and the persona mode",builtin:!0,defaultHidden:!0,run(e){const t=e.args[0];e.setMode(t==="chat"?"chat":t==="terminal"?"terminal":t==="persona"?"persona":"toggle")}},{id:"clear",label:"Clear",command:"clear",aliases:["cls"],icon:"⌫",description:"clear [output|all] - clear the terminal log, an output, or every output",builtin:!0,defaultHidden:!0,run(e){if(!e.args[0])return e.clearLog();if(e.args[0]==="all")return e.outputs.clearAll();const t=xo(e,"clear");t&&e.outputs.clear(t)}},{id:"profile",label:"Layouts",command:"profile",aliases:["layout"],icon:"▦",description:"profile [list|save <name>|load <name>|delete <name>|export [name]] - saved layouts (.profile)",builtin:!0,defaultHidden:!0,run(e){const[t="list",...n]=e.args,r=n.join(" ").trim(),{layout:o}=e;switch(t){case"list":{const i=o.list();e.print(i.length?i.map(s=>s===o.active?`* ${s}`:` ${s}`).join(` `):"no saved layouts");return}case"save":if(!r)return e.print("profile: usage profile save <name>","err");e.print(`saved "${o.save(r).name}"`);return;case"load":return r?o.load(r)?e.print(`loaded "${r}"`):e.print(`profile: no layout "${r}"`,"err"):e.print("profile: usage profile load <name>","err");case"delete":return o.remove(r)?e.print(`deleted "${r}"`):e.print(`profile: no layout "${r}"`,"err");case"export":o.exportProfile(r||void 0),e.print(`exported ${r||"the current layout"}`);return;default:return o.load(e.args.join(" "))?e.print(`loaded "${e.args.join(" ")}"`):e.print(`profile: unknown "${t}"`,"err")}}},{id:"reset",label:"Reset layout",command:"reset",icon:"↺",description:"reset - back to the standard layout (saved layouts are kept)",builtin:!0,defaultHidden:!0,run(e){e.layout.reset(),e.print("reset to the standard layout")}},{id:"remember",label:"Remember",command:"remember",icon:"◈",description:"remember <text> - add a note to .memory",builtin:!0,defaultHidden:!0,async run(e){const t=e.args.join(" ").trim();if(!t)return e.print("remember: usage remember <text>","err");await e.remember(t),e.print("remembered")}},{id:"rack",label:"Rack",command:"rack",icon:"▥",description:'rack [t] [add <command> [n]|remove <command>|move <command> <n>|reset] - the buttons on the bar (the chat bar; "rack t …" the T-mode bar); kept',builtin:!0,defaultHidden:!0,run(e){const t=[...e.args],n={t:"terminal",terminal:"terminal",chat:"chat",ask:"chat",persona:"persona"},r=t[0]&&n[t[0].toLowerCase()]?n[t.shift().toLowerCase()]:"chat",o=r==="terminal"?"the T-mode rack":r==="persona"?"the persona rack":"the rack",[i="list",s,l]=t,a=x=>!!e.registry.get(x),f=x=>x?e.registry.find(x)??e.registry.get(x):void 0,v=e.bar.faces,g=v.get(r),m=x=>{const w=e.registry.get(x);return w?`${typeof w.icon=="string"?w.icon+" ":""}${w.command}`:x},y=x=>{const w=Number(x);return Number.isInteger(w)&&w>=1?w-1:void 0},k=r===e.bar.face?"":` (it shows in ${r==="terminal"?"T mode":r==="persona"?"the persona mode":"ask mode: > to go back"})`;switch(i){case"list":case"ls":{const x=g.order.filter(a);e.print(`${o}: ${x.length?x.map((d,p)=>`${p+1} ${m(d)}`).join(" · "):"empty"} · then + (always there: T · ▤ windows · responses)`);const w=Object.keys(g.floating).filter(a);w.length&&e.print(`floating on the page: ${w.map(m).join(" · ")}`);const u=e.registry.all().map(d=>d.id).filter(d=>!x.includes(d)&&!w.includes(d));e.print(`available: ${u.map(d=>e.registry.get(d).command).join(" ")||"none"}`),e.print(`rack${r==="chat"?"":" t"} add <command> [n] · rack remove <command> · rack move <command> <n> · rack reset`);return}case"add":{const x=f(s);return x?l!==void 0&&y(l)===void 0?e.print("rack add: the position is a number, 1 for the first","err"):(v.set(r,Ef(g,x.id,a,y(l))),e.print(`racked ${m(x.id)} on ${o}${l?` at ${l}`:""}${k}`)):e.print(`rack add: no command "${s??""}" (rack lists them)`,"err")}case"remove":case"rm":{const x=f(s);if(!x)return e.print(`rack remove: no command "${s??""}"`,"err");const w=cg(g,x.id);return w?(v.set(r,w),e.print(`took ${m(x.id)} off ${o}; still a command, and in + to add back`)):e.print(`rack remove: ${x.command} is not on ${o}`,"err")}case"move":case"mv":{const x=f(s),w=y(l);if(!x||w===void 0)return e.print("rack move: usage rack move <command> <position> (1 is the first)","err");const u=dg(g,x.id,a,w);return u?(v.set(r,u),e.print(`moved ${m(x.id)} to ${w+1} on ${o}`)):e.print(`rack move: ${x.command} is not on ${o} (rack add ${x.command} ${l})`,"err")}case"reset":return v.set(r,v.standard(r)),e.print(`${o} is back to its standard buttons${k}`);default:return e.print(`rack: unknown "${i}" (rack · rack add · rack remove · rack move · rack reset)`,"err")}}},{id:"actions",label:"List actions",command:"actions",icon:"≡",description:"actions - list every action and its command",builtin:!0,defaultHidden:!0,run(e){const t=new Set(e.registry.visible().map(n=>n.id));e.registry.all().forEach(n=>e.print(`${t.has(n.id)?"●":"○"} ${n.command.padEnd(10)} ${n.label}`))}},{id:"help",label:"Help",command:"help",aliases:["?"],icon:"?",description:"help - list commands",builtin:!0,defaultHidden:!0,run(e){e.registry.all().forEach(t=>e.print(t.description??`${t.command} - ${t.label}`)),e.print("hold any button to rearrange; drag it off the bar to hide it")}}],mg={chat:["spawn","strings","home","dock","popout","rename","clear","outputs"],terminal:["ping","diag","outputs","screens","close","clear","win-history","win-memory","win-prompt"]};function hg(e){const t=[],n=/"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|(\S+)/g;let r;for(;r=n.exec(e);){const o=r[1]??r[2];t.push(o!==void 0?o.replace(/\\(.)/g,"$1"):r[3])}return t}function gg(e,t){const n=hg(e.trim().replace(/^\//,""));if(!n.length)return null;const[r,...o]=n;return{name:r,args:o,action:t.find(r)}}const Ji=(e,t,n)=>Math.max(t,Math.min(n,e)),La=60;function Zi(e,t){return{x:Ji(e.x,La-t,window.innerWidth-La),y:Ji(e.y,0,window.innerHeight-La/2)}}function Cf(e,t,n,r,o){const{minWidth:i,minHeight:s}=o,l=o.maxWidth??1/0,a=o.maxHeight??1/0,f=t==="tl"||t==="bl",v=t==="tl"||t==="tr",g=f?e.x+e.width:window.innerWidth-e.x,m=v?e.y+e.height:window.innerHeight-e.y,y=Ji(e.width+(f?-n:n),i,Math.max(i,Math.min(l,g))),k=Ji(e.height+(v?-r:r),s,Math.max(s,Math.min(a,m)));return{x:f?e.x+e.width-y:e.x,y:v?e.y+e.height-k:e.y,width:y,height:k}}const yg=10,vg=50,wg={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},qi="Arrow keys move; Alt+arrow keys resize; hold Shift for larger steps";function es(e){const[t,n]=h.useState(()=>Zi(e.initialPosition,e.initialSize.width)),[r,o]=h.useState(e.initialSize),[i,s]=h.useState(null),l=h.useRef({opts:e,position:t,size:r});l.current={opts:e,position:t,size:r};const a=h.useCallback((g,m)=>{if(l.current.opts.draggable===!1||g.button!==0)return;const{position:y,size:k}=l.current;m&&n(m),s({kind:"drag",startX:g.clientX,startY:g.clientY,...y,...m??{},...k}),g.preventDefault()},[]),f=h.useCallback((g,m)=>{if(l.current.opts.resizable===!1)return;const{position:y,size:k}=l.current;s({kind:"resize",corner:m,startX:g.clientX,startY:g.clientY,...y,...k}),g.stopPropagation(),g.preventDefault()},[]);h.useEffect(()=>{if(!i)return;const g=y=>{const k=y.clientX-i.startX,x=y.clientY-i.startY;if(i.kind==="drag"){n(Zi({x:i.x+k,y:i.y+x},i.width));return}const w=Cf(i,i.corner??"br",k,x,l.current.opts);o({width:w.width,height:w.height}),n({x:w.x,y:w.y})},m=()=>{var w;s(null);const{position:y,size:k,opts:x}=l.current;(w=x.onCommit)==null||w.call(x,{...y,...k},i.kind)};return document.addEventListener("pointermove",g),document.addEventListener("pointerup",m),()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",m)}},[i]);const v=h.useCallback(g=>{var S;const m=wg[g.key];if(!m||g.ctrlKey||g.metaKey)return;const{opts:y,position:k,size:x}=l.current,w=g.shiftKey?vg:yg,[u,d]=[m[0]*w,m[1]*w];let p;if(g.altKey){if(y.resizable===!1)return;p=Cf({...k,...x},"br",u,d,y)}else{if(y.draggable===!1)return;p={...Zi({x:k.x+u,y:k.y+d},x.width),...x}}g.preventDefault(),n({x:p.x,y:p.y}),o({width:p.width,height:p.height}),(S=y.onCommit)==null||S.call(y,p,"key")},[]);return h.useEffect(()=>{const g=()=>n(m=>{const y=Zi(m,l.current.size.width);return y.x===m.x&&y.y===m.y?m:y});return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]),{position:t,size:r,setPosition:n,setSize:o,isDragging:(i==null?void 0:i.kind)==="drag",isResizing:(i==null?void 0:i.kind)==="resize",startDrag:a,startResize:f,onHandleKeyDown:v}}const Nf=({children:e,onClick:t,className:n="",disabled:r,variant:o="default",size:i="default",...s})=>{const l="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",a={default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},f={default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"};return c.jsx("button",{onClick:t,disabled:r,className:`${l} ${a[o]} ${f[i]} ${n}`,...s,children:e})},kg=()=>c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M4 12h15M13 5l7 7-7 7"})}),Sg=()=>c.jsx("span",{className:"inline-block w-4 h-4 text-green-400 font-mono font-bold",children:">"}),xg=()=>c.jsx("span",{className:"inline-block w-4 h-4 text-blue-600 font-bold",children:"T"}),Eg=6,Cg=3;function jf(e,t){return document.elementsFromPoint(e,t).some(n=>{var r;return((r=n.dataset)==null?void 0:r.uifTrash)!==void 0})}function $f(e,t,n,r=-1){let o=0;return e.querySelectorAll("[data-uif-item]").forEach(i=>{if(Number(i.dataset.uifItem)===r)return;const s=i.getBoundingClientRect();s.width===0&&s.height===0||(n>s.bottom||n>=s.top&&t>s.left+s.width/2)&&o++}),o}function Ng({containerRef:e,onReorder:t,onRemove:n,onDropOutside:r,holdMs:o=400,removeDistance:i=40}){const[s,l]=h.useState(!1),[a,f]=h.useState(null),v=h.useRef(s);v.current=s;const g=h.useRef(!1),m=h.useRef(),y=h.useRef({onReorder:t,onRemove:n,onDropOutside:r});y.current={onReorder:t,onRemove:n,onDropOutside:r},h.useEffect(()=>()=>{var p;return(p=m.current)==null?void 0:p.call(m)},[]);const k=h.useCallback((p,S,$)=>{const P=e.current,C=jf(p,S);if(!P)return{target:0,outside:!1,overTrash:C};const M=P.getBoundingClientRect(),N=p<M.left-i||p>M.right+i||S<M.top-i||S>M.bottom+i;return{target:$f(P,p,S,$),outside:N,overTrash:C}},[e,i]),x=h.useCallback((p,S)=>{var X;if(p.button!==0)return;(X=m.current)==null||X.call(m);const P=p.currentTarget.getBoundingClientRect(),C={x:p.clientX,y:p.clientY};let M=v.current,N=!1,O=C;const F=()=>{N=!0,g.current=!0,f({index:S,x:O.x,y:O.y,offsetX:C.x-P.left,offsetY:C.y-P.top,width:P.width,height:P.height,...k(O.x,O.y,S)})},K=M?void 0:window.setTimeout(()=>{var Y;M=!0,g.current=!0,l(!0),(Y=navigator.vibrate)==null||Y.call(navigator,15)},o),Q=Y=>{O={x:Y.clientX,y:Y.clientY};const D=Math.hypot(O.x-C.x,O.y-C.y);if(!M){D>Eg&&(clearTimeout(K),J());return}if(!N){D>Cg&&F();return}Y.preventDefault(),f(I=>I&&{...I,x:O.x,y:O.y,...k(O.x,O.y,S)})},V=()=>{if(clearTimeout(K),J(),!N)return;const Y=k(O.x,O.y,S);f(null);const{onDropOutside:D,onRemove:I,onReorder:B}=y.current;Y.overTrash?I(S):Y.outside?D?D(S,{x:O.x-(C.x-P.left),y:O.y-(C.y-P.top)}):I(S):Y.target!==S&&B(S,Y.target)},J=()=>{document.removeEventListener("pointermove",Q),document.removeEventListener("pointerup",V),document.removeEventListener("pointercancel",V),m.current=void 0};document.addEventListener("pointermove",Q,{passive:!1}),document.addEventListener("pointerup",V),document.addEventListener("pointercancel",V),m.current=()=>{clearTimeout(K),J()}},[o,k]),w=h.useCallback(p=>{if(g.current){g.current=!1;return}v.current||p()},[]),u=h.useCallback(p=>requestAnimationFrame(()=>{var S,$;return($=(S=e.current)==null?void 0:S.querySelector(`[data-uif-item="${p}"]`))==null?void 0:$.focus()}),[e]),d=h.useCallback((p,S,$)=>{if(!v.current)return;const P=p.key==="ArrowLeft"||p.key==="ArrowUp"?-1:p.key==="ArrowRight"||p.key==="ArrowDown"?1:0;if(P){const C=S+P;C>=0&&C<$&&(y.current.onReorder(S,C),u(C))}else if(p.key==="Delete"||p.key==="Backspace")y.current.onRemove(S),u(Math.max(0,S-1));else if(p.key==="Escape"||p.key==="Enter")l(!1);else return;p.preventDefault()},[u]);return{arranging:s,setArranging:l,drag:a,onPointerDown:x,onKeyDown:d,guardClick:w}}function _f(e){const t=new Set,n=typeof BroadcastChannel<"u"?new BroadcastChannel(`uif:${e}`):null;return n&&(n.onmessage=r=>t.forEach(o=>o(r.data))),{post:r=>n==null?void 0:n.postMessage(r),on(r){return t.add(r),()=>t.delete(r)},close:()=>n==null?void 0:n.close()}}const ts="uif-output",Pa="uif-key";function Lf(){return typeof window<"u"&&new URLSearchParams(window.location.search).has(ts)}const Pf=/^[a-z][\w.-]{0,40}$/;function jg(e){return{id:`win-${e.id}`,label:e.file,command:e.id,aliases:e.file.startsWith(".")?[e.file]:[],icon:e.icon,description:`${e.id} [open|close] - the ${e.file} window: ${e.summary.toLowerCase()}`,builtin:!0,defaultHidden:!0,run(t){const n=t.args[0];n==="open"?t.windows.show(e.id):n==="close"?t.windows.hide(e.id):t.windows.toggle(e.id)}}}function $g(e){const t=new Set,n=[];for(const r of e)for(const o of r.windows??[]){if(!Pf.test(o.id))throw new Error(`module ${r.id}: window id "${o.id}" is not valid (a-z, digits, _ . -)`);if(t.has(o.id))throw new Error(`module ${r.id}: window id "${o.id}" is already taken`);t.add(o.id),n.push(o)}return n}const An="standard",Nr=".profile",_g=["chat","terminal","persona"],Lg=["top","bottom","left","right"],jr=e=>typeof e=="number"&&Number.isFinite(e),kn=e=>typeof e=="string",Mf=e=>Array.isArray(e)&&e.every(kn),Et=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Pg(e){return!Et(e)||!kn(e.id)||!kn(e.label)||!kn(e.payload)||e.kind!=="command"&&e.kind!=="send"?null:{id:e.id,label:e.label,payload:e.payload,kind:e.kind,command:kn(e.command)?e.command:void 0,icon:kn(e.icon)?e.icon:void 0}}function Mg(e,t="imported"){const n=y=>{throw new Error(`not a valid ${Nr} file: ${y}`)};if(!Et(e))return n("expected a JSON object");if(e["uif.profile"]!==1)return n('missing "uif.profile": 1');const r=Et(e.actions)?e.actions:n('missing "actions"');if(!Mf(r.order)||!Mf(r.hidden))return n('"actions.order" and "actions.hidden" must be string lists');const o=Array.isArray(r.custom)?r.custom.map(Pg):[];if(o.some(y=>y===null))return n("a custom action is malformed");const i={};if(Et(r.floating))for(const[y,k]of Object.entries(r.floating)){if(!Et(k)||!jr(k.x)||!jr(k.y))return n(`floating position for "${y}" is malformed`);i[y]={x:k.x,y:k.y}}const s=Et(e.hub)?e.hub:n('missing "hub"');if(![s.x,s.y,s.width,s.height].every(jr))return n('"hub" needs numeric x, y, width, height');const l=_g.includes(s.mode)?s.mode:"chat",a=Lg.includes(s.docked)?s.docked:null,f=["auto","stacked","sideways"].find(y=>y===s.arrange)??"auto";let v=null;if(Et(s.isolated)){const y=s.isolated;if(!jr(y.x)||!jr(y.y))return n('"hub.isolated" needs numeric x and y');v={x:y.x,y:y.y,vertical:y.vertical===!0}}const g={};if(Et(e.windows)){for(const[y,k]of Object.entries(e.windows))if(Pf.test(y)){if(!Et(k)||![k.x,k.y,k.width,k.height].every(jr))return n(`window "${y}" is malformed`);g[y]={x:k.x,y:k.y,width:k.width,height:k.height}}}const m={};if(Et(e.parts))for(const[y,k]of Object.entries(e.parts))Et(k)&&(m[y]=k);return{"uif.profile":1,...Object.keys(m).length?{parts:m}:{},name:kn(e.name)&&e.name.trim()?e.name.trim():t,savedAt:kn(e.savedAt)?e.savedAt:new Date().toISOString(),actions:{order:r.order,hidden:r.hidden,custom:o,floating:i},hub:{x:s.x,y:s.y,width:s.width,height:s.height,mode:l,docked:a,arrange:f,isolated:v},strings:e.strings===!0,windows:g}}function Tg(e){return(e.trim().replace(/[^\w.-]+/g,"-").replace(/^-+|-+$/g,"")||"layout")+Nr}function Rg(e){return JSON.stringify(e,null,2)+` `}const bg=[{corner:"tl",label:"top-left"},{corner:"tr",label:"top-right"},{corner:"bl",label:"bottom-left"},{corner:"br",label:"bottom-right"}];function Ma({onStart:e}){return c.jsx(c.Fragment,{children:bg.map(({corner:t,label:n})=>c.jsx("div",{className:`uif-corner corner-tab ${t}`,onPointerDown:r=>e(r,t),title:`Resize from the ${n} corner`,"aria-hidden":"true"},t))})}function Tf({field:e,active:t,flash:n,popped:r,onHeaderPointerDown:o,onHeaderKeyDown:i,onRename:s,onSubmit:l,onRemember:a,onPopOut:f,onSpeak:v,onHome:g,onMaximize:m,onClose:y}){const[k,x]=h.useState({}),w=h.useRef(null),[u,d]=h.useState(!1),[p,S]=h.useState(""),$=e.messages.some(N=>N.pending),P=N=>{d(!1),N!==null&&N.trim()&&N.trim()!==e.title&&(s==null||s(N))},C=N=>{N.preventDefault(),!(!p.trim()||$)&&(l==null||l(p),S(""))},M=e.messages[e.messages.length-1];return h.useEffect(()=>{const N=w.current;N&&(N.scrollTop=N.scrollHeight)},[e.messages.length,M==null?void 0:M.text]),c.jsxs(c.Fragment,{children:[n>0&&c.jsx("div",{className:"uif-flash",style:{"--uif-color":e.color}},n),c.jsxs("div",{className:`uif-output-header ${$?"is-busy":""}`,onPointerDown:u?void 0:o,onKeyDown:u?void 0:i,onDoubleClick:N=>{!u&&m&&!N.target.closest(".uif-output-title, .uif-output-buttons")&&m()},tabIndex:i?0:void 0,role:i?"group":void 0,"aria-label":i?`${e.title} output. ${qi}`:void 0,children:[c.jsx("span",{className:"uif-output-dot",style:{background:e.color}}),c.jsx("span",{className:"uif-output-avatar","aria-hidden":"true"}),u?c.jsx("input",{className:"uif-output-rename",defaultValue:e.title,"aria-label":"Output name",autoFocus:!0,onFocus:N=>N.currentTarget.select(),onPointerDown:N=>N.stopPropagation(),onKeyDown:N=>{N.stopPropagation(),N.key==="Enter"&&P(N.currentTarget.value),N.key==="Escape"&&P(null)},onBlur:N=>P(N.currentTarget.value)}):c.jsx("span",{className:"uif-output-title",title:s?"Double-click to rename":void 0,onDoubleClick:s?()=>d(!0):void 0,children:e.title}),t&&c.jsx("span",{className:"uif-output-badge",children:"active"}),c.jsxs("span",{className:"uif-output-buttons",onPointerDown:N=>N.stopPropagation(),children:[v&&c.jsx("button",{type:"button",className:e.speak?"is-on":"",title:e.speak?"Stop reading replies aloud":"Read replies aloud","aria-pressed":!!e.speak,onClick:v,children:e.speak?"🔊":"🔈"}),f&&c.jsx("button",{type:"button",title:"Pop out to a window",onClick:f,children:"⧉"}),g&&c.jsx("button",{type:"button",title:r?"Call home":"Back beside the field",onClick:g,children:"⌂"}),m&&c.jsx("button",{type:"button",title:e.maximized?"Shrink back (or double-click the header, or Esc)":"Fill the screen (or double-click the header)","aria-pressed":!!e.maximized,onClick:m,children:e.maximized?"⤡":"⤢"}),c.jsx("button",{type:"button",title:"Close",onClick:y,children:"✕"})]})]}),c.jsxs("div",{className:"uif-output-body",ref:w,children:[e.messages.length===0&&c.jsx("div",{className:"uif-output-empty",children:"No messages yet."}),e.messages.map(N=>{if(N.role==="system"&&!N.text&&!N.pending)return null;const O=a&&N.role==="assistant"&&!N.pending&&!N.undelivered&&N.text,F=c.jsxs("div",{className:["uif-msg",`uif-msg-${N.role}`,N.kind&&`is-${N.kind}`,N.tone&&`is-${N.tone}`,N.undelivered&&"is-undelivered"].filter(Boolean).join(" "),children:[N.text,N.pending&&c.jsx("span",{className:"uif-caret",children:"▍"}),N.media&&c.jsxs("span",{className:"uif-msg-media",children:[N.media.kind==="video"?c.jsx("video",{src:N.media.url,controls:!0,playsInline:!0,loop:!0,className:"uif-media","aria-label":N.text||"video"}):c.jsx("img",{src:N.media.url,alt:N.text||"image",className:"uif-media"}),c.jsx("a",{className:"uif-media-save",href:N.media.url,download:N.media.name||(N.media.kind==="video"?"video.mp4":"image.png"),children:"⤓ save"})]}),N.silent&&e.speak&&c.jsxs("span",{className:"uif-msg-silent",title:"Not read aloud: the engine did not vouch for this reply","aria-label":"not read aloud",children:[" ","🔇"]})]},N.id);return O?c.jsxs("div",{className:"uif-msg-row",children:[F,c.jsx("button",{type:"button",className:`uif-msg-keep ${k[N.id]?"is-kept":""}`,title:k[N.id]?"Kept in .memory":"Keep this reply in .memory","aria-label":"Remember this reply",disabled:k[N.id],onClick:()=>{a(N.text),x(K=>({...K,[N.id]:!0}))},children:"◈"})]},N.id):F})]}),l&&c.jsxs("form",{className:"uif-output-reply",onSubmit:C,children:[c.jsx("input",{value:p,onChange:N=>S(N.target.value),placeholder:`Reply in ${e.title}…`,"aria-label":`Message ${e.title}`,className:"uif-output-reply-input"}),c.jsx("button",{type:"submit",disabled:!p.trim()||$,"aria-label":"Send",children:"➤"})]})]})}function Og({field:e}){const{outputs:t,setRect:n,flashes:r,raise:o,zIndexOf:i,sendTo:s,context:l}=Rt(),{position:a,size:f,setPosition:v,setSize:g,startDrag:m,startResize:y,onHandleKeyDown:k,isDragging:x}=es({initialPosition:{x:e.rect.x,y:e.rect.y},initialSize:{width:e.rect.width,height:e.rect.height},minWidth:220,minHeight:120,onCommit:d=>n(e.id,d)});h.useEffect(()=>{v({x:e.rect.x,y:e.rect.y}),g({width:e.rect.width,height:e.rect.height})},[e.rect,v,g]);const w=t.activeId===e.id,u=!!e.maximized;return h.useEffect(()=>{if(!u)return;const d=p=>{p.key==="Escape"&&t.activeId===e.id&&t.maximize(e.id,!1)};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[u,e.id,t]),c.jsxs("div",{className:`uif-output ${w?"is-active":""} ${x?"is-dragging":""} ${u?"is-maximized":""}`,"data-uif-output":e.id,style:{left:u?0:a.x,top:u?0:a.y,width:u?"100vw":f.width,height:u?"100vh":f.height,zIndex:i(e.id),"--uif-color":e.color},onPointerDownCapture:()=>{t.setActive(e.id),o(e.id)},children:[c.jsx(Tf,{field:e,active:w,flash:r[e.id]??0,onHeaderPointerDown:u?void 0:m,onHeaderKeyDown:k,onMaximize:()=>t.maximize(e.id),onRename:d=>t.rename(e.id,d),onSubmit:d=>s(d,e.id),onRemember:d=>void l.remember(d,"response"),onPopOut:()=>t.popOut(e.id),onSpeak:()=>t.setSpeak(e.id,!e.speak),onClose:()=>t.close(e.id)}),!u&&c.jsx(Ma,{onStart:y})]})}const $r=28;function Rf(e,t,n,r){const o=(n-e)*.5;return`M${e},${t} C${e+o},${t} ${n-o},${r} ${n},${r}`}function zg(e,t){const n=window.innerWidth,r=window.innerHeight,o=n/2,i=r/2,s=Math.atan2(t-i,e-o);if(e>=$r&&e<=n-$r&&t>=$r&&t<=r-$r)return{x:e,y:t,angle:s};const l=e-o,a=t-i,f=Math.min(l?(o-$r)/Math.abs(l):1/0,a?(i-$r)/Math.abs(a):1/0);return{x:o+l*f,y:i+a*f,angle:s}}function Dg(){const{fields:e,hubRef:t,outputs:n}=Rt(),[r,o]=h.useState([]),[i,s]=h.useState([]),l=h.useRef(e);return l.current=e,h.useEffect(()=>{let a=0,f="";const v=()=>{var p;a=requestAnimationFrame(v);const g=(p=t.current)==null?void 0:p.getBoundingClientRect();if(!g)return;const m=g.left+g.width/2,y=g.top+g.height/2,k=[],x=[],w=window.screenX+(window.outerWidth-window.innerWidth)/2,u=window.screenY+(window.outerHeight-window.innerHeight);l.current.forEach((S,$)=>{if(S.placement==="inline"){const P=document.querySelector(`[data-uif-output="${S.id}"]`);if(!P)return;const C=P.getBoundingClientRect(),M=C.left+C.width/2<m,N=M?g.left:g.right,O=M?C.right:C.left;k.push({id:S.id,color:S.color,d:Rf(N,y,O,C.top+16)})}else{const P=S.screenGeom,C=P?P.x+P.width/2-w:window.innerWidth+400,M=P?P.y+P.height/2-u:window.innerHeight/2+$*40,N=zg(C,M);x.push({id:S.id,title:S.title,color:S.color,...N}),k.push({id:S.id,color:S.color,d:Rf(m,y,N.x,N.y),dashed:!0})}});const d=JSON.stringify([k,x]);d!==f&&(f=d,o(k),s(x))};return v(),()=>cancelAnimationFrame(a)},[t]),c.jsxs(c.Fragment,{children:[c.jsx("svg",{className:"uif-tethers","aria-hidden":"true",children:r.map(a=>c.jsx("path",{d:a.d,stroke:a.color,strokeDasharray:a.dashed?"6 6":void 0,className:a.dashed?"uif-tether is-remote":"uif-tether"},a.id))}),i.map(a=>c.jsxs("button",{type:"button",className:"uif-beacon",style:{left:a.x,top:a.y,"--uif-color":a.color},title:`${a.title}: click to find it, double-click to call it home`,onClick:()=>n.ping(a.id),onDoubleClick:()=>n.callHome(a.id),children:[c.jsx("span",{className:"uif-beacon-arrow",style:{transform:`rotate(${a.angle}rad)`},children:"➤"}),c.jsx("span",{className:"uif-beacon-label",children:a.title})]},a.id))]})}const Ig=` MEMORY — notes the operator kept from earlier conversations. They are context, not evidence: cite them as the operator's notes, never as findings. `,Ag=2400;function Fg(e,t=Ag){if(!e.some(o=>o.source.kind!=="delivery"))return"";const n=[];let r=0;for(const o of[...e].filter(i=>i.source.kind!=="delivery").sort((i,s)=>s.ts-i.ts)){const i=`- ${o.text.replace(/\s+/g," ").trim()}`;if(r+i.length+1>t)break;n.push(i),r+=i.length+1}return n.length?Ig+n.join(` `):""}async function Hg(e,t,n=Date.now()/1e3){const r=typeof e.ts=="number"?e.ts:n,o=t.replace(/\s+/g," ").trim();return JSON.stringify({...e,ts:r,at:new Date(r*1e3).toISOString(),text:o,sha256:await Ra(o),source:{kind:"delivery"}})}function ns(e){let t;try{t=JSON.parse(e)}catch{throw new Error("not a valid .persona file: it is not JSON")}if(!t||typeof t!="object"||Array.isArray(t))throw new Error("not a valid .persona file: expected a JSON object");const n=t;if(n.system_prompt!==void 0&&typeof n.system_prompt!="string")throw new Error('not a valid .persona file: "system_prompt" must be text');if(n.behavioral_traits!==void 0&&!(Array.isArray(n.behavioral_traits)&&n.behavioral_traits.every(r=>typeof r=="string")))throw new Error('not a valid .persona file: "behavioral_traits" must be a list of text');return n}const Ug=new Set(["high","critical"]);function Bg(e){const t=e.awareness,n=t&&typeof t=="object"?t.facts:void 0;return Array.isArray(n)?n.map(r=>typeof r=="string"?r:r&&typeof r=="object"?r.fact:void 0).filter(r=>typeof r=="string"&&!!r.trim()).map(r=>r.trim()):[]}function bf(e){var i;const t=[];(i=e.behavioral_traits)!=null&&i.length&&t.push(`Behavioural traits: ${e.behavioral_traits.join(", ")}`);const n=Object.entries(e.beliefs??{}).filter(([,s])=>s===!0).map(([s])=>s.replace(/_/g," "));n.length&&t.push(`Operating beliefs: ${n.join(", ")}`);const r=Object.entries(e.desires??{}).filter(([,s])=>{const l=typeof s=="string"?s:s&&typeof s=="object"?s.priority:void 0;return typeof l=="string"&&Ug.has(l.toLowerCase())}).map(([s])=>s.replace(/_/g," "));r.length&&t.push(`Priorities: ${r.join(", ")}`);const o=Bg(e);return o.length&&t.push(`What I know about myself: ${o.map(s=>`- ${s}`).join(` `)}`),t}const Wg=["general","reasoning","code_generation","simple_chat"],Vg=`model_facet: uif.default task_class: general # general | reasoning | code_generation | simple_chat logical_model: auto pinned: false `;function Kg(e){const t=e.trim();if(t==="true")return!0;if(t==="false")return!1;if(t==="null"||t==="~"||t==="")return null;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);const n=/^(['"])(.*)\1$/.exec(t);return n?n[2]:t}function Of(e){const t={};let n=null,r=[];const o=()=>{n&&(t[n]=r.join(` `)),n=null,r=[]};for(const i of e.split(/\r?\n/)){if(/^\s*(#.*)?$/.test(i))continue;if(/^\s/.test(i)){n&&r.push(i);continue}o();const s=/^([A-Za-z_][\w.-]*)\s*:\s*(.*)$/.exec(i);if(!s)throw new Error(`not a valid .model file: cannot read "${i.trim()}"`);const l=s[2].replace(/\s+#.*$/,"");l.trim()===""?n=s[1]:t[s[1]]=Kg(l)}return o(),t}function Yg(e,t,n){const r=String(n),o=new RegExp(`^(${t.replace(/[.]/g,"\\.")}\\s*:\\s*)([^#\\n]*?)(\\s*#.*)?$`,"m");return o.test(e)?e.replace(o,(i,s,l,a)=>`${s}${r}${a??""}`):`${e.replace(/\s*$/,` `)}${t}: ${r} `}function Ta(e){const t=typeof e.logical_model=="string"&&e.logical_model?e.logical_model:"auto";return e.pinned?`${t} (pinned)`:`${t} · ${e.task_class??"general"}`}function rs(e,t,n){const r=[];return e.split(/\r?\n/).forEach((o,i)=>{if(!o.trim())return;let s;try{s=JSON.parse(o)}catch{throw new Error(`not a valid ${t} file: line ${i+1} is not JSON`)}const l=s&&typeof s=="object"&&!Array.isArray(s)?n(s):null;if(!l)throw new Error(`not a valid ${t} file: line ${i+1} is missing required fields`);r.push(l)}),r}const zf=e=>typeof e.user=="string"&&typeof e.assistant=="string"?{...e,ts:typeof e.ts=="number"?e.ts:Date.now()/1e3}:null,Df=e=>{if(typeof e.text!="string")return null;const t=typeof e.ts=="number"?e.ts:Date.now()/1e3,n=e.source&&typeof e.source=="object"?e.source:{kind:"typed"};return{ts:t,at:typeof e.at=="string"?e.at:new Date(t*1e3).toISOString(),text:e.text,sha256:typeof e.sha256=="string"?e.sha256:"",source:n.kind==="response"||n.kind==="delivery"?n:{...n,kind:"typed"}}},If=new TextEncoder;async function Ra(e){const t=typeof e=="string"?If.encode(e):e,n=await crypto.subtle.digest("SHA-256",t);return[...new Uint8Array(n)].map(r=>r.toString(16).padStart(2,"0")).join("")}async function Af(...e){const t=new Uint8Array(e.reduce((r,o)=>r+o.length,0));let n=0;for(const r of e)t.set(r,n),n+=r.length;return new Uint8Array(await crypto.subtle.digest("SHA-256",t))}const Qg="rfc6962-sha256";async function Xg(e){const t=i=>[...i].map(s=>s.toString(16).padStart(2,"0")).join(""),n=e.filter(i=>i.trim());if(!n.length)return null;const r=await Promise.all(n.map(i=>Af(new Uint8Array([0]),If.encode(i)))),o=async i=>{if(i.length===1)return i[0];let s=1;for(;s*2<i.length;)s*=2;const[l,a]=await Promise.all([o(i.slice(0,s)),o(i.slice(s))]);return Af(new Uint8Array([1]),l,a)};return t(await o(r))}async function Gg(e,t){const n=t.filter(r=>r.trim());return{file:e,records:n.length,merkle_root:await Xg(n),scheme:Qg,file_sha256:n.length?await Ra(n.map(r=>r+` `).join("")):null}}const Jg=12,Zg=4e3,Ff=(e,t=Zg)=>e.length>t?e.slice(0,t)+"…":e;function Hf(e){var v;const{prompt:t,persona:n,source:r,memory:o}=e,i=(v=n==null?void 0:n.system_prompt)==null?void 0:v.trim();let s,l;r==="persona"&&i?(s=i,l="persona.system_prompt"):t.trim()?(s=t.trim(),l=".prompt"):i?(s=i,l="persona.system_prompt"):(s="",l="none");const a=n?bf(n):[];return{system:([s,...a].filter(Boolean).join(` `)+Fg(o)).trim(),promptSource:l}}function qg(e,t,n,r=Jg){const o=[];e&&o.push({role:"system",content:e});for(const i of t.slice(-r))o.push({role:"user",content:Ff(i.user)},{role:"assistant",content:Ff(i.assistant)});return o.push({role:"user",content:n}),o}const ey=["history","memory","prompt","persona","model"],ba={history:{file:".history",icon:"⟲",summary:"Every message sent and received, across outputs"},memory:{file:".memory",icon:"◈",summary:"Long-term notes given to the model with every message"},prompt:{file:".prompt",icon:"¶",summary:"The system prompt sent with every message"},persona:{file:".persona",icon:"☺",summary:"Who the model speaks as"},model:{file:".model",icon:"⚙",summary:"Which model answers, and its settings"}},Uf={width:420,height:360};function ty({info:e,rect:t,onRect:n,onClose:r,children:o}){const{raise:i,zIndexOf:s}=Rt(),l=e.id,a=`win:${l}`,[f,v]=h.useState(null),g=h.useMemo(()=>function({children:$}){return f?wn.createPortal($,f):null},[f]),{position:m,size:y,setPosition:k,setSize:x,startDrag:w,startResize:u,onHandleKeyDown:d,isDragging:p}=es({initialPosition:{x:t.x,y:t.y},initialSize:{width:t.width,height:t.height},minWidth:280,minHeight:180,onCommit:n});return h.useEffect(()=>{k({x:t.x,y:t.y}),x({width:t.width,height:t.height})},[t,k,x]),c.jsxs("section",{className:`uif-window uif-window-${l} ${p?"is-dragging":""}`,"data-uif-window":l,"aria-label":e.file,style:{left:m.x,top:m.y,width:y.width,height:y.height,zIndex:s(a)},onPointerDownCapture:()=>i(a),onKeyDown:S=>{S.key==="Escape"&&S.target===S.currentTarget.querySelector(".uif-window-title")&&r()},children:[c.jsxs("header",{className:"uif-window-title",onPointerDown:w,onKeyDown:d,tabIndex:0,"aria-label":`${e.file} window. ${qi}. Escape closes.`,children:[c.jsx("span",{className:"uif-window-icon","aria-hidden":"true",children:e.icon}),c.jsx("span",{className:"uif-window-name",children:e.file}),c.jsx("span",{className:"uif-window-summary",children:e.summary}),c.jsxs("span",{className:"uif-window-tools",onPointerDown:S=>S.stopPropagation(),children:[c.jsx("span",{className:"uif-window-tools-slot",ref:v}),c.jsx("button",{type:"button",title:"Close","aria-label":`Close ${e.file}`,onClick:r,children:"✕"})]})]}),c.jsx("div",{className:"uif-window-body",children:o(g)}),c.jsx(Ma,{onStart:u})]})}const ny={history:".history,.jsonl,application/json",memory:".memory,.jsonl,application/json",prompt:".prompt,.txt,text/plain",persona:".persona,.json,application/json",model:".model,.yaml,.yml,text/plain"};function ry(e,t){const n=URL.createObjectURL(new Blob([t],{type:"text/plain"})),r=document.createElement("a");r.href=n,r.download=e,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}function oy(){const e=Rt(),{windows:t}=e;return c.jsx(c.Fragment,{children:t.defs.filter(n=>t.open[n.id]).map(n=>{const r=()=>t.hide(n.id);return c.jsx(ty,{info:n,rect:t.open[n.id],onRect:o=>t.setRect(n.id,o),onClose:r,children:o=>c.jsx(n.Body,{uif:e,close:r,Tools:o})},n.id)})})}function iy({kind:e,Tools:t}){const{context:n,storageKey:r}=Rt(),[o,i]=h.useState(null),s=h.useRef(null),l=`${r}${ba[e].file}`;h.useEffect(()=>{if(!o)return;const f=setTimeout(()=>i(null),4e3);return()=>clearTimeout(f)},[o]);const a=async f=>{var g;const v=(g=f.target.files)==null?void 0:g[0];if(f.target.value="",!!v)try{i({text:n.importText(e,await v.text())})}catch(m){i({text:m.message,error:!0})}};return c.jsxs(c.Fragment,{children:[c.jsxs(t,{children:[c.jsx("button",{type:"button",title:`Import a ${ba[e].file} file`,"aria-label":"Import",onClick:()=>{var f;return(f=s.current)==null?void 0:f.click()},children:"⤒"}),c.jsx("button",{type:"button",title:`Download ${l}`,"aria-label":"Export",onClick:()=>ry(l,n.fileText(e)),children:"⤓"}),c.jsx("input",{ref:s,type:"file",accept:ny[e],hidden:!0,onChange:a,"data-uif-import":e})]}),e==="history"&&c.jsx(ay,{context:n}),e==="memory"&&c.jsx(uy,{context:n}),e==="prompt"&&c.jsx(cy,{context:n}),e==="persona"&&c.jsx(dy,{context:n}),e==="model"&&c.jsx(fy,{context:n}),o&&c.jsx("p",{className:`uif-window-note ${o.error?"is-error":""}`,role:"status",children:o.text})]})}const sy={id:"context",label:"Context",windows:ey.map(e=>({id:e,...ba[e],Body:({Tools:t})=>c.jsx(iy,{kind:e,Tools:t}),detail:t=>{const n=t.context;switch(e){case"history":return`${n.history.length} exchange${n.history.length===1?"":"s"}`;case"memory":return`${n.memory.length} note${n.memory.length===1?"":"s"}`;case"prompt":return n.prompt.trim()?`${n.prompt.trim().length} chars`:"empty";case"persona":return n.persona?String(n.persona.name??n.persona.persona??"set"):"none";case"model":return String(n.model.logical_model??"auto")}}}))};function Bf({file:e,lines:t}){const[n,r]=h.useState(null);return h.useEffect(()=>{let o=!0;return Gg(e,t).then(i=>o&&r(i)).catch(()=>o&&r(null)),()=>{o=!1}},[e,t]),n?c.jsxs("footer",{className:"uif-window-commit",title:"Merkle root over the JSONL lines (rfc6962-sha256), the same commitment bankml computes",children:[n.records," record",n.records===1?"":"s",n.merkle_root&&c.jsxs(c.Fragment,{children:[" · root ",c.jsxs("code",{"data-uif-root":n.merkle_root,children:[n.merkle_root.slice(0,16),"…"]}),c.jsx("button",{type:"button",className:"uif-link",onClick:()=>{var o;return(o=navigator.clipboard)==null?void 0:o.writeText(n.merkle_root)},children:"copy"})]})]}):null}function Wf({label:e,onConfirm:t}){const[n,r]=h.useState(!1);return h.useEffect(()=>{if(!n)return;const o=setTimeout(()=>r(!1),3e3);return()=>clearTimeout(o)},[n]),c.jsx("button",{type:"button",className:`uif-button is-quiet ${n?"is-danger":""}`,onClick:()=>{n?(r(!1),t()):r(!0)},children:n?`Really ${e.toLowerCase()}?`:e})}function ly(e){return new Date(e*1e3).toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ay({context:e}){const[t,n]=h.useState(""),r=h.useRef(null),o=h.useMemo(()=>{const i=t.trim().toLowerCase(),s=e.history.map((l,a)=>({h:l,i:a}));return i?s.filter(({h:l})=>`${l.user} ${l.assistant} ${l.output??""}`.toLowerCase().includes(i)):s},[e.history,t]);return h.useEffect(()=>{const i=r.current;i&&!t&&(i.scrollTop=i.scrollHeight)},[o.length,t]),c.jsxs("div",{className:"uif-window-stack",children:[c.jsxs("div",{className:"uif-window-row",children:[c.jsx("input",{className:"uif-input",value:t,onChange:i=>n(i.target.value),placeholder:"Search .history…","aria-label":"Search history"}),c.jsx(Wf,{label:"Clear",onConfirm:e.clearHistory})]}),o.length===0?c.jsx("p",{className:"uif-window-empty",children:t?"Nothing matches.":"No exchanges yet. Messages you send in chat are recorded here."}):c.jsx("ol",{className:"uif-history",ref:r,children:o.map(({h:i,i:s})=>c.jsxs("li",{className:"uif-history-item",children:[c.jsxs("div",{className:"uif-history-meta",children:[ly(i.ts),i.output&&c.jsxs("span",{children:[" · ",i.output]}),i.model&&c.jsxs("span",{children:[" · ",i.model]}),i.receipt!==void 0&&c.jsxs("span",{className:"uif-history-receipt",title:JSON.stringify(i.receipt,null,2),children:[" ","· receipt"]})]}),c.jsx("div",{className:"uif-msg uif-msg-user",children:i.user}),c.jsx("div",{className:"uif-msg uif-msg-assistant",children:i.assistant})]},s))}),c.jsx(Bf,{file:".history",lines:e.historyLines})]})}function uy({context:e}){const[t,n]=h.useState(""),r=e.memory.map((i,s)=>({n:i,i:s})).reverse(),o=async i=>{i.preventDefault(),t.trim()&&(await e.remember(t),n(""))};return c.jsxs("div",{className:"uif-window-stack",children:[c.jsxs("form",{className:"uif-window-row",onSubmit:o,children:[c.jsx("input",{className:"uif-input",value:t,onChange:i=>n(i.target.value),placeholder:"Add a note to remember…","aria-label":"New memory note"}),c.jsx("button",{type:"submit",className:"uif-button",disabled:!t.trim(),children:"Remember"})]}),r.length===0?c.jsx("p",{className:"uif-window-empty",children:"No notes. Add one here, or press ◈ on a reply to keep it."}):c.jsx("ul",{className:"uif-memory",children:r.map(({n:i,i:s})=>c.jsxs("li",{className:"uif-memory-item",children:[c.jsx("span",{className:`uif-memory-kind is-${i.source.kind}`,title:i.source.kind==="delivery"?"how an answer was delivered: kept, never sent to the model":i.source.kind==="response"?"kept from a reply":"typed",children:i.source.kind==="delivery"?"⏱":i.source.kind==="response"?"◈":"✎"}),c.jsx("span",{className:"uif-memory-text",children:i.text}),c.jsx("button",{type:"button",className:"uif-link",title:"Forget this note","aria-label":"Forget",onClick:()=>e.forget(s),children:"✕"})]},`${i.sha256}-${s}`))}),c.jsxs("div",{className:"uif-window-row is-end",children:[c.jsx("span",{className:"uif-window-hint",children:"Notes (✎ ◈) are sent with every message, newest first, up to 2,400 characters; deliveries (⏱) are kept, never sent."}),c.jsx(Wf,{label:"Clear",onConfirm:e.clearMemory})]}),c.jsx(Bf,{file:".memory",lines:e.memoryLines})]})}function cy({context:e}){var i,s;const[t,n]=h.useState(!1),r=!!((s=(i=e.persona)==null?void 0:i.system_prompt)!=null&&s.trim()),o=Hf({prompt:e.prompt,persona:e.persona,source:e.promptSource,memory:e.memory});return c.jsxs("div",{className:"uif-window-stack",children:[c.jsx("textarea",{className:"uif-input uif-window-text",value:e.prompt,onChange:l=>e.setPrompt(l.target.value),placeholder:"You are … (the system prompt sent with every message)","aria-label":"System prompt",spellCheck:!0}),c.jsxs("fieldset",{className:"uif-window-choice",children:[c.jsx("legend",{children:"When the persona has its own system prompt"}),c.jsxs("label",{children:[c.jsx("input",{type:"radio",name:"uif-prompt-source",checked:e.promptSource==="persona",onChange:()=>e.setPromptSource("persona")}),"use the persona's",r?"":" (none set)"]}),c.jsxs("label",{children:[c.jsx("input",{type:"radio",name:"uif-prompt-source",checked:e.promptSource==="prompt",onChange:()=>e.setPromptSource("prompt")}),"use this .prompt"]})]}),c.jsxs("button",{type:"button",className:"uif-link is-left",onClick:()=>n(l=>!l),"aria-expanded":t,children:[t?"▾":"▸"," What the model receives (",o.promptSource,e.memory.length?" + memory":"",")"]}),t&&c.jsx("pre",{className:"uif-window-preview",children:o.system||"(empty: no system prompt)"})]})}function dy({context:e}){const[t,n]=h.useState(e.personaText),[r,o]=h.useState(null);h.useEffect(()=>n(e.personaText),[e.personaText]);const i=e.persona,s=t!==e.personaText,l=f=>{if(n(f),!f.trim())return o(null);try{ns(f),o(null)}catch(v){o(v.message)}},a=()=>{try{e.setPersonaText(t),o(null)}catch(f){o(f.message)}};return c.jsxs("div",{className:"uif-window-stack",children:[i?c.jsxs("div",{className:"uif-persona-card",children:[c.jsx("strong",{children:i.name??i.persona??"Unnamed persona"}),i.role&&c.jsx("span",{className:"uif-persona-role",children:i.role}),i.description&&c.jsx("p",{children:i.description}),bf(i).map(f=>c.jsx("p",{className:"uif-persona-line",children:f},f)),c.jsx("p",{className:"uif-window-hint",children:i.system_prompt?"Has its own system prompt.":"No system prompt of its own; the .prompt is used."})]}):c.jsx("p",{className:"uif-window-empty",children:"No persona. Import a .persona file (mindX v1 or boardroom) or paste its JSON below."}),c.jsx("textarea",{className:`uif-input uif-window-text is-code ${r?"is-invalid":""}`,value:t,onChange:f=>l(f.target.value),placeholder:'{ "name": "Savante", "system_prompt": "You are …" }',"aria-label":"Persona JSON","aria-invalid":!!r,spellCheck:!1}),r&&c.jsx("p",{className:"uif-window-note is-error",children:r}),c.jsxs("div",{className:"uif-window-row is-end",children:[c.jsx("button",{type:"button",className:"uif-button is-quiet",disabled:!s,onClick:()=>l(e.personaText),children:"Revert"}),c.jsx("button",{type:"button",className:"uif-button",disabled:!s||!!r,onClick:a,children:t.trim()?"Apply":"Clear persona"})]})]})}function fy({context:e}){const t=e.model,n=(r,o)=>e.setModelText(Yg(e.modelText,r,o));return c.jsxs("div",{className:"uif-window-stack",children:[c.jsxs("div",{className:"uif-model-grid",children:[c.jsxs("label",{children:["logical_model",c.jsx("input",{className:"uif-input",value:String(t.logical_model??""),onChange:r=>n("logical_model",r.target.value||"auto")})]}),c.jsxs("label",{children:["task_class",c.jsx("select",{className:"uif-input",value:String(t.task_class??"general"),onChange:r=>n("task_class",r.target.value),children:Wg.map(r=>c.jsx("option",{children:r},r))})]}),c.jsxs("label",{children:["model_facet",c.jsx("input",{className:"uif-input",value:String(t.model_facet??""),onChange:r=>n("model_facet",r.target.value)})]}),c.jsxs("label",{className:"uif-model-pin",children:[c.jsx("input",{type:"checkbox",checked:t.pinned===!0,onChange:r=>n("pinned",r.target.checked)}),"pinned"]})]}),c.jsx("p",{className:"uif-window-hint",children:e.modelError?c.jsx("span",{className:"is-error",children:e.modelError}):c.jsxs(c.Fragment,{children:["Messages go out as ",c.jsx("b",{children:Ta(t)}),". Your onSend reads this from meta.context.model."]})}),c.jsx("textarea",{className:`uif-input uif-window-text is-code ${e.modelError?"is-invalid":""}`,value:e.modelText,onChange:r=>e.setModelText(r.target.value),"aria-label":".model YAML",spellCheck:!1})]})}function Vf(e){return e.split(/\r?\n/).filter(t=>t.trim())}function py(e){const t=S=>`uif:${e}:${S}`,[n,r]=h.useState(()=>Ie(t("history"),[])),[o,i]=h.useState(()=>Ie(t("memory"),[])),[s,l]=h.useState(()=>Ie(t("prompt"),"")),[a,f]=h.useState(()=>Ie(t("promptSource"),"persona")),[v,g]=h.useState(()=>Ie(t("persona"),"")),[m,y]=h.useState(()=>Ie(t("model"),Vg)),k=h.useCallback((S,$)=>P=>{$(P),Je(`uif:${e}:${S}`,P)},[e]),x=h.useMemo(()=>{try{return rs(n.join(` `),".history",zf)}catch{return[]}},[n]),w=h.useMemo(()=>{try{return rs(o.join(` `),".memory",Df)}catch{return[]}},[o]),u=h.useMemo(()=>{if(!v.trim())return null;try{return ns(v)}catch{return null}},[v]),{model:d,modelError:p}=h.useMemo(()=>{try{return{model:Of(m),modelError:null}}catch(S){return{model:{},modelError:S.message}}},[m]);return h.useMemo(()=>{const S=k("history",r),$=k("memory",i),P=k("prompt",l),C=k("promptSource",f),M=k("persona",g),N=k("model",y),O=K=>r(Q=>{const V=[...Q,...K].slice(-2e3);return Je(t("history"),V),V}),F=K=>i(Q=>{const V=[...Q,...K].slice(-500);return Je(t("memory"),V),V});return{history:x,historyLines:n,appendHistory:K=>O([JSON.stringify(K)]),clearHistory:()=>S([]),memory:w,memoryLines:o,async remember(K,Q="typed"){const V=K.trim();if(!V)return;const J=Date.now()/1e3,X={ts:J,at:new Date(J*1e3).toISOString(),text:V,sha256:await Ra(V),source:{kind:Q}};F([JSON.stringify(X)])},async keep(K,Q){F([await Hg(K,Q)])},clearMemory:()=>$([]),forget(K){i(Q=>{const V=Q.filter((J,X)=>X!==K);return Je(t("memory"),V),V})},prompt:s,setPrompt:P,promptSource:a,setPromptSource:C,personaText:v,persona:u,setPersonaText(K){K.trim()&&ns(K),M(K)},modelText:m,model:d,modelError:p,setModelText:N,forSend(K,Q){const{system:V,promptSource:J}=Hf({prompt:s,persona:u,source:a,memory:w}),Y=x.filter(D=>D.output_id===Q).slice(-12);return{system:V,messages:qg(V,Y,K),promptSource:J,prompt:s,persona:u,memory:w,model:d,modelText:m,history:Y}},fileText(K){switch(K){case"history":return n.length?n.join(` `)+` `:"";case"memory":return o.length?o.join(` `)+` `:"";case"prompt":return s;case"persona":return v;case"model":return m}},importText(K,Q){switch(K){case"history":{const V=rs(Q,".history",zf);return O(Vf(Q)),`added ${V.length} exchange(s)`}case"memory":{const V=rs(Q,".memory",Df);return F(Vf(Q)),`added ${V.length} note(s)`}case"prompt":return P(Q),"prompt replaced";case"persona":{const V=ns(Q);return M(Q),`persona set to ${V.name??V.persona??"unnamed"}`}case"model":{const V=Of(Q);return N(Q),`model set to ${Ta(V)}`}}}}},[x,n,w,o,s,a,v,u,m,d,p,k])}const Kf=["#22d3ee","#f472b6","#a3e635","#fbbf24","#a78bfa","#fb923c"],Oa={width:360,height:240},os="__hub",my=1e3,za=h.createContext(null);function Rt(){const e=h.useContext(za);if(!e)throw new Error("useUIF must be used inside <UIFProvider> or <UltimateBar>");return e}function hy(){return h.useContext(za)}function gy(e){return h.useSyncExternalStore(e.subscribe,e.version,e.version)}let yy=0;const Yf=e=>`${e}${Date.now().toString(36)}${(yy++).toString(36)}`;function vy(e){return Ie(`uif:${e}:outputs`,[]).map(t=>({...t,messages:t.messages.map(n=>({...n,pending:!1}))}))}function Qf({children:e,storageKey:t="default",popoutUrl:n,defaultStrings:r=!1,actions:o,modules:i,outputTop:s,outputArea:l}){const a=h.useMemo(()=>[sy,...i??[]],[]),f=h.useMemo(()=>$g(a),[a]),v=h.useMemo(()=>lg({actions:[...pg,...f.map(jg),...a.flatMap(E=>E.actions??[]),...o??[]],storageKey:t}),[t]),g=h.useMemo(()=>_f(t),[t]);h.useEffect(()=>()=>g.close(),[g]);const[m,y]=h.useState(()=>vy(t)),k=h.useRef(m),x=h.useCallback(E=>{k.current=typeof E=="function"?E(k.current):E,y(k.current)},[]),w=h.useCallback((E,j)=>x(R=>R.map(b=>b.id===E?j(b):b)),[x]),[u,d]=h.useState(()=>{var E;return((E=m[m.length-1])==null?void 0:E.id)??null}),p=h.useRef(u);p.current=u;const[S,$]=h.useState(()=>Ie(`uif:${t}:strings`,r)),P=h.useCallback(E=>$(j=>{const R=E==="toggle"?!j:E;return Je(`uif:${t}:strings`,R),R}),[t]),[C,M]=h.useState({}),[N,O]=h.useState(()=>[...m.map(E=>E.id),os]),F=h.useCallback(E=>O(j=>j[j.length-1]===E?j:[...j.filter(R=>R!==E),E]),[]),K=h.useCallback(E=>my+Math.max(0,N.indexOf(E)),[N]),Q=h.useRef(null),V=h.useRef(new Map),J=h.useRef(null),X=h.useRef(new Map),Y=h.useRef(new Set),D=h.useRef(s);D.current=s;const I=h.useRef(l);I.current=l;const B=h.useCallback(E=>{var Wn,us,_o;const j=(Wn=I.current)==null?void 0:Wn.call(I),R=Math.max(0,(j==null?void 0:j.left)??0),b=Math.min(window.innerWidth,(j==null?void 0:j.right)??window.innerWidth),_=j&&b-R>=240?{lo:R,hi:b}:{lo:0,hi:window.innerWidth},A=((us=Q.current)==null?void 0:us.getBoundingClientRect())??{left:(_.lo+_.hi)/2-300,right:(_.lo+_.hi)/2+300,top:window.innerHeight-160,bottom:window.innerHeight-30,width:600},{width:H,height:q}=Oa,Z=12;if(A.left-24-H<_.lo+8&&_.hi-A.right-24-H<8){const st=Math.min(E,4)*24,Lo=Math.min(Math.round(A.width),_.hi-_.lo-32),Po=Math.max(_.lo+16,Math.min(Math.round(A.left)+st,_.hi-Lo-16));if(A.top<240){const Mo=Math.round(A.bottom)+12+st;return{x:Po,y:Mo,width:Lo,height:Math.max(160,Math.min(560,window.innerHeight-Mo-16))}}const Vn=Math.max(8,Math.min(((_o=D.current)==null?void 0:_o.call(D))??8,A.top-220))+8,lt=Math.max(160,Math.min(560,Math.round(A.top)-12-Vn-st));return{x:Po,y:Math.max(8,Math.min(Vn+st,window.innerHeight-lt-8)),width:Lo,height:lt}}const re=Math.max(1,Math.floor((window.innerHeight-Z)/(q+Z))),Le=Math.floor(E/re),Pe=E%re,ie=Math.max(0,Math.floor((_.hi-A.right-24)/(H+Z)));let ht=Le<ie?A.right+24+Le*(H+Z):A.left-24-H-(Le-ie)*(H+Z);ht=Math.max(_.lo+8,Math.min(ht,_.hi-H-8));const Bn=Math.max(8,Math.min(Z+Pe*(q+Z),window.innerHeight-q-8));return{x:ht,y:Bn,width:H,height:q}},[]),G=h.useCallback(E=>{const j=E==="all"?k.current.map(b=>b.id):[E],R=E==="all"?0:k.current.filter(b=>b.placement==="inline"&&b.id!==E).length;j.forEach((b,_)=>{var q;const A=R+_;g.post({type:"out:home",id:b}),(q=V.current.get(b))==null||q.close(),V.current.delete(b);const H=X.current.get(b);X.current.delete(b),H&&H.state!=="terminated"&&H.terminate(),w(b,Z=>({...Z,placement:"inline",presented:!1,screenGeom:void 0,rect:B(A)}))}),M(b=>Object.fromEntries([...Object.entries(b),...j.map(_=>[_,(b[_]??0)+1])]))},[g,w,B]),te=h.useRef(null),Ae=h.useRef(null),ve=h.useMemo(()=>({list:()=>k.current,get activeId(){return p.current},setActive:E=>d(E),spawn(E,j){const R=k.current.length,b=Yf("o");return x(_=>[..._,{id:b,title:E||`Output ${R+1}`,color:Kf[R%Kf.length],placement:"inline",rect:B(_.filter(A=>A.placement==="inline").length),messages:[]}]),d(b),p.current=b,F(b),j&&queueMicrotask(()=>{var _,A,H;j.speak&&((_=te.current)==null||_.setSpeak(b,!0)),j.present?(A=te.current)==null||A.present(b):(j.screen!==void 0||j.window)&&((H=te.current)==null||H.popOut(b,{screen:j.screen}))}),b},close(E){var R,b;g.post({type:"out:home",id:E}),(R=V.current.get(E))==null||R.close(),V.current.delete(E);const j=X.current.get(E);if(X.current.delete(E),j&&j.state!=="terminated"&&j.terminate(),x(_=>_.filter(A=>A.id!==E)),O(_=>_.filter(A=>A!==E)),p.current===E){const _=k.current;d(((b=_[_.length-1])==null?void 0:b.id)??null)}},popOut(E,j){if(!k.current.find(ie=>ie.id===E))return;const b=k.current.filter(ie=>ie.placement==="popout").length,{width:_,height:A}=Oa;let H=window.screenX+window.outerWidth+20+b*30,q=window.screenY+60+b*30;const Z=J.current;let re;if((j==null?void 0:j.screen)!==void 0){const ie=Z==null?void 0:Z.screens[j.screen-1];ie?(H=ie.availLeft+40+b*30,q=ie.availTop+40+b*30):re=Z?`there is no screen ${j.screen} (this machine has ${Z.screens.length}); it opened beside this window`:`screen ${j.screen} needs screen access first (run "screens"); it opened beside this window`}else if(Z){const ie=Z.currentScreen,ht=Z.screens.filter(Wn=>Wn.availLeft!==ie.availLeft||Wn.availTop!==ie.availTop),Bn=ht[b%Math.max(ht.length,1)]??ie;H=Bn.availLeft+40+b*30,q=Bn.availTop+40+b*30}const Le=new URL(n??window.location.href,window.location.href);Le.searchParams.set(ts,E),Le.searchParams.set(Pa,t);const Pe=window.open(Le.toString(),`uif-${t}-${E}`,`popup,width=${_+40},height=${A+120},left=${Math.round(H)},top=${Math.round(q)}`);return Pe?(V.current.set(E,Pe),w(E,ie=>({...ie,placement:"popout"})),re):"the browser blocked the window (allow pop-ups for this page)"},async present(E){const j=window.PresentationRequest;if(!j)return"this browser cannot present to another display (the Presentation API is missing; Chrome has it)";if(!k.current.some(b=>b.id===E))return"no such output";const R=new URL(n??window.location.href,window.location.href);R.searchParams.set(ts,E),R.searchParams.set(Pa,t);try{const b=await new j([R.toString()]).start();X.current.set(E,b),w(E,A=>({...A,placement:"popout",presented:!0}));const _=()=>{X.current.get(E)===b&&(X.current.delete(E),G(E))};return b.addEventListener("terminate",_),b.addEventListener("close",_),b.addEventListener("message",A=>{var H;try{(H=Ae.current)==null||H.call(Ae,JSON.parse(String(A.data)))}catch{}}),"presented on the chosen display"}catch(b){return`not presented: ${b.message||b}`}},setSpeak(E,j){var b;if(j&&!("speechSynthesis"in window))return"this browser cannot speak (no speech synthesis)";const R=k.current.find(_=>_.id===E);return R?(j?R.messages.forEach(_=>Y.current.add(_.id)):(b=window.speechSynthesis)==null||b.cancel(),w(E,_=>({..._,speak:j})),j?`replies in ${R.title} will be read aloud`:`${R.title} is quiet`):"no such output"},screens(){const E=J.current;return E?E.screens.map((j,R)=>({index:R+1,label:j.label||`screen ${R+1}`,primary:!!j.isPrimary,current:j.availLeft===E.currentScreen.availLeft&&j.availTop===E.currentScreen.availTop,width:j.availWidth,height:j.availHeight})):null},callHome:G,closeAll(){var j;for(const R of[...k.current])g.post({type:"out:home",id:R.id}),(j=V.current.get(R.id))==null||j.close(),V.current.delete(R.id);const E=new Set(k.current.map(R=>R.id));x(()=>[]),O(R=>R.filter(b=>!E.has(b))),d(null),p.current=null},clearAll(){x(E=>E.map(j=>({...j,messages:[]})))},maximize(E,j){w(E,R=>({...R,maximized:j??!R.maximized})),F(E)},tile(){const E=k.current.filter(q=>q.placement==="inline"),j=E.length;if(!j)return;const R=8,b=Math.ceil(Math.sqrt(j*window.innerWidth/Math.max(1,window.innerHeight))),_=Math.ceil(j/b),A=Math.floor((window.innerWidth-R*(b+1))/b),H=Math.floor((window.innerHeight-R*(_+1))/_);E.forEach((q,Z)=>w(q.id,re=>({...re,maximized:!1,rect:{x:R+Z%b*(A+R),y:R+Math.floor(Z/b)*(H+R),width:A,height:H}})))},cascade(){const E=k.current.filter(_=>_.placement==="inline"),{width:j,height:R}=Oa,b=32;E.forEach((_,A)=>{const H=A%Math.max(1,Math.floor((window.innerHeight-R)/b));w(_.id,q=>({...q,maximized:!1,rect:{x:16+H*b,y:16+H*b,width:j,height:R}})),F(_.id)})},ping(E){var j;M(R=>({...R,[E]:(R[E]??0)+1})),g.post({type:"out:ping",id:E}),(j=V.current.get(E))==null||j.focus()},clear(E){w(E,j=>({...j,messages:[]}))},rename(E,j){const R=j.trim();R&&w(E,b=>({...b,title:R}))},append(E,j){const R=Yf("m");return w(E,b=>({...b,messages:[...b.messages,{...j,id:R}]})),R},update(E,j,R){w(E,b=>({...b,messages:b.messages.map(_=>_.id===j?{..._,...R}:_)}))},resolve(E){var b,_,A;const j=k.current;if(!E)return p.current??((b=j[j.length-1])==null?void 0:b.id);if(/^\d+$/.test(E))return(_=j[Number(E)-1])==null?void 0:_.id;const R=E.toLowerCase();return(A=j.find(H=>H.id===E)??j.find(H=>H.title.toLowerCase()===R))==null?void 0:A.id}}),[g,G,x,w,n,F,B,t]);te.current=ve;const _e=h.useRef(null),We=h.useCallback(E=>(_e.current=E,()=>{_e.current===E&&(_e.current=null)}),[]),Ve=h.useCallback((E,j)=>{E.trim()&&(_e.current?_e.current(E,j):ve.append(j,{role:"user",text:E}))},[ve]),bt=py(t),[mt,Se]=h.useState(()=>{const E=Ie(`uif:${t}:windows`,{});return Object.fromEntries(Object.entries(E).filter(([j])=>f.some(R=>R.id===j)))});h.useEffect(()=>Je(`uif:${t}:windows`,mt),[mt,t]);const as=h.useRef(mt);as.current=mt;const Co=h.useCallback(E=>{var Le;const j=Math.min(Uf.width,window.innerWidth-32),{height:R}=Uf,b=12,_=Math.max(1,Math.floor((window.innerWidth-b)/(j+b))),A=_===1?Math.round((window.innerWidth-j)/2):b,H=_===1?Math.max(b,Math.min(((Le=D.current)==null?void 0:Le.call(D))??b,window.innerHeight-R-b)):b,q=Math.max(1,Math.floor((window.innerHeight-H)/(R+b))),Z=Pe=>E.some(ie=>Pe.x<ie.x+ie.width&&ie.x<Pe.x+Pe.width&&Pe.y<ie.y+ie.height&&ie.y<Pe.y+Pe.height);for(let Pe=0;Pe<q;Pe++)for(let ie=0;ie<_;ie++){const ht={x:A+ie*(j+b),y:H+Pe*(R+b),width:j,height:R};if(!Z(ht))return ht}const re=E.length;return{x:Math.min(b+re*32,window.innerWidth-j-b),y:Math.min(b+re*32,window.innerHeight-R-b),width:j,height:R}},[]),Ct=h.useMemo(()=>({defs:f,open:mt,isOpen:E=>!!mt[E],show:E=>{F(`win:${E}`),Se(j=>j[E]?j:{...j,[E]:Co(Object.values(j))})},hide:E=>Se(j=>{if(!j[E])return j;const R={...j};return delete R[E],R}),toggle:E=>{mt[E]||F(`win:${E}`),Se(j=>{if(j[E]){const R={...j};return delete R[E],R}return{...j,[E]:Co(Object.values(j))}})},setRect:(E,j)=>Se(R=>R[E]?{...R,[E]:j}:R)}),[mt,F,Co,f]),Nt=h.useRef(null),Ot=h.useCallback(E=>(Nt.current=E,()=>{Nt.current===E&&(Nt.current=null)}),[]),se=h.useCallback(()=>Nt.current,[]),Xt=h.useRef(new Map),Ce=h.useCallback((E,j)=>(Xt.current.set(E,j),()=>{Xt.current.get(E)===j&&Xt.current.delete(E)}),[]),[Un,zt]=h.useState(()=>Ie(`uif:${t}:profiles`,{})),[xn,it]=h.useState(()=>Ie(`uif:${t}:profile`,null)),Ze=h.useRef(Un);Ze.current=Un;const En=h.useRef(S);En.current=S;const Pr=h.useCallback(E=>{Ze.current=E,zt(E),Je(`uif:${t}:profiles`,E)},[t]),Gt=h.useCallback(E=>{it(E),Je(`uif:${t}:profile`,E)},[t]),No=h.useMemo(()=>{const E=_=>{var A;return{"uif.profile":1,name:_,savedAt:new Date().toISOString(),actions:v.snapshot(),hub:((A=Nt.current)==null?void 0:A.get())??{x:0,y:0,width:600,height:120,mode:"chat",docked:null},strings:En.current,windows:as.current,...Xt.current.size?{parts:Object.fromEntries([...Xt.current].map(([H,q])=>[H,q.get()]))}:{}}},j=_=>{var A;v.restore(_.actions),(A=Nt.current)==null||A.set(_.hub),P(_.strings),Se(_.windows??{});for(const[H,q]of Xt.current)_.parts&&H in _.parts&&q.set(_.parts[H])},R=()=>{var _;v.reset(),(_=Nt.current)==null||_.set(null),P(r),Se({});for(const A of Xt.current.values())A.set(null);Gt(An)},b=_=>{const A=URL.createObjectURL(new Blob([Rg(_)],{type:"application/json"})),H=document.createElement("a");H.href=A,H.download=Tg(_.name),document.body.appendChild(H),H.click(),H.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)};return{list:()=>Object.keys(Ze.current).sort(),active:xn,capture:E,save(_){const A=_.trim();if(!A||A===An)throw new Error(`"${An}" is the built-in layout; pick another name`);const H=E(A);return Pr({...Ze.current,[A]:H}),Gt(A),H},load(_){if(_===An)return R(),!0;const A=Ze.current[_];return A?(j(A),Gt(_),!0):!1},remove(_){if(!Ze.current[_])return!1;const{[_]:A,...H}=Ze.current;return Pr(H),xn===_&&Gt(null),!0},reset:R,exportProfile(_){const A=_?Ze.current[_]:void 0;if(_&&!A&&_!==xn)throw new Error(`no profile "${_}"`);b(A??E(_??xn??"layout"))},importProfile(_,A){let H;try{H=JSON.parse(_)}catch{throw new Error("not a valid .profile file: it is not JSON")}const q=(A==null?void 0:A.replace(/\.profile$|\.json$/i,""))||"imported",Z=Mg(H,q),re=Z.name===An?`${An}-imported`:Z.name,Le={...Z,name:re};return Pr({...Ze.current,[re]:Le}),j(Le),Gt(re),re}}},[xn,r,Gt,v,P,Pr]),jo=h.useCallback((E,j)=>w(E,R=>({...R,rect:j})),[w]),Dt=h.useCallback(async()=>{const E=window;if(!E.getScreenDetails)return"this browser cannot place windows on other screens";try{return J.current=await E.getScreenDetails(),`${J.current.screens.length} screen(s) available for pop-outs`}catch{return"screen access was denied"}},[]);h.useEffect(()=>{!window.getScreenDetails||!navigator.permissions||navigator.permissions.query({name:"window-management"}).then(j=>{j.state==="granted"&&Dt()}).catch(()=>{})},[Dt]),h.useEffect(()=>{const E=setTimeout(()=>Je(`uif:${t}:outputs`,m.map(j=>({...j,messages:j.messages.slice(-200)}))),300);return()=>clearTimeout(E)},[m,t]),h.useEffect(()=>{m.filter(E=>E.placement==="popout").forEach(E=>{const j={type:"out:state",id:E.id,field:E,active:E.id===u};g.post(j);const R=X.current.get(E.id);(R==null?void 0:R.state)==="connected"&&R.send(JSON.stringify(j))})},[m,u,g]),h.useEffect(()=>{const E=typeof window<"u"?window.speechSynthesis:void 0;if(E){for(const j of m)if(j.speak)for(const R of j.messages)R.role!=="assistant"||R.pending||R.silent||!R.text.trim()||Y.current.has(R.id)||(Y.current.add(R.id),E.speak(new SpeechSynthesisUtterance(R.text)))}},[m]),h.useEffect(()=>{const E=new Set,j=_=>{if(!("id"in _))return;const A=k.current.find(H=>H.id===_.id);switch(_.type){case"out:hello":{E.add(_.id);const H=(A==null?void 0:A.placement)==="popout"?{type:"out:state",id:_.id,field:A,active:_.id===p.current}:{type:"out:home",id:_.id};g.post(H);const q=X.current.get(_.id);(q==null?void 0:q.state)==="connected"&&q.send(JSON.stringify(H));break}case"out:geom":{E.add(_.id);const H=A==null?void 0:A.screenGeom;A&&(!H||H.x!==_.geom.x||H.y!==_.geom.y||H.width!==_.geom.width||H.height!==_.geom.height)&&w(_.id,q=>({...q,screenGeom:_.geom}));break}case"out:bye":setTimeout(()=>{const H=k.current.find(Z=>Z.id===_.id),q=V.current.get(_.id);(H==null?void 0:H.placement)==="popout"&&(!q||q.closed)&&G(_.id)},300);break;case"out:request-home":G(_.id);break;case"out:request-close":ve.close(_.id);break;case"out:request-rename":ve.rename(_.id,_.title);break;case"out:input":Ve(_.text,_.id);break;case"out:remember":bt.remember(_.text,"response");break}},R=g.on(j);Ae.current=j,g.post({type:"hub:hello"});const b=setTimeout(()=>{k.current.filter(_=>_.placement==="popout"&&!E.has(_.id)&&!V.current.has(_.id)).forEach(_=>G(_.id))},1500);return()=>{R(),clearTimeout(b)}},[g,G,ve,w,Ve,bt]);const $o=h.useMemo(()=>({registry:v,outputs:ve,fields:m,strings:S,setStrings:P,hubRef:Q,flashes:C,setRect:jo,requestScreens:Dt,bus:g,storageKey:t,raise:F,zIndexOf:K,sendTo:Ve,registerSender:We,layout:No,windows:Ct,context:bt,registerHubLayout:Ot,hubLayout:se,registerProfilePart:Ce}),[v,ve,m,S,P,C,jo,Dt,g,t,F,K,Ve,We,No,Ct,bt,Ot,se,Ce]);return c.jsxs(za.Provider,{value:$o,children:[e,m.filter(E=>E.placement==="inline").map(E=>c.jsx(Og,{field:E},E.id)),c.jsx(oy,{}),S&&c.jsx(Dg,{})]})}const wy=400,ky=6,Xf=36,Sy=10,xy=50;function Da(e){return{x:Math.max(0,Math.min(e.x,window.innerWidth-Xf)),y:Math.max(0,Math.min(e.y,window.innerHeight-Xf))}}function Ey(e,t,n,r=24){if(!e)return!1;const o=e.getBoundingClientRect();return t>=o.left-r&&t<=o.right+r&&n>=o.top-r&&n<=o.bottom+r}function Cy(e){const t=e.registry.floating(),[,n]=h.useState(0);return h.useEffect(()=>{const r=()=>n(o=>o+1);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),t.length?wn.createPortal(c.jsx(c.Fragment,{children:t.map(({action:r,at:o})=>c.jsx(Ny,{action:r,at:Da(o),...e},r.id))}),document.body):null}function Ny({action:e,at:t,registry:n,barRef:r,arranging:o,pressed:i,onRun:s,onDragChange:l,zIndex:a}){const[f,v]=h.useState(null),[g,m]=h.useState({overBar:!1,overTrash:!1}),y=h.useRef(!1),k=h.useRef(),x=h.useRef(l);x.current=l,h.useEffect(()=>()=>{var p;return(p=k.current)==null?void 0:p.call(k)},[]);const w=p=>{var V;if(p.button!==0)return;(V=k.current)==null||V.call(k);const S={x:p.clientX,y:p.clientY},$={x:S.x-t.x,y:S.y-t.y};let P=o,C=!1,M=S;const N=P?void 0:window.setTimeout(()=>{var J;P=!0,y.current=!0,(J=navigator.vibrate)==null||J.call(navigator,15)},wy),O=J=>({overBar:Ey(r.current,J.x,J.y),overTrash:jf(J.x,J.y)}),F=J=>{M={x:J.clientX,y:J.clientY};const X=Math.hypot(M.x-S.x,M.y-S.y);if(!P){X>ky&&(clearTimeout(N),Q());return}if(!C&&X<=3)return;C=!0,y.current=!0,J.preventDefault();const Y=O(M);v({x:M.x-$.x,y:M.y-$.y}),m(Y),x.current({id:e.id,...Y})},K=()=>{if(clearTimeout(N),Q(),!C)return;const J=O(M);v(null),m({overBar:!1,overTrash:!1}),x.current(null),J.overTrash?n.hide(e.id):J.overBar&&r.current?n.dockAt(e.id,$f(r.current,M.x,M.y)):n.float(e.id,Da({x:M.x-$.x,y:M.y-$.y}))},Q=()=>{document.removeEventListener("pointermove",F),document.removeEventListener("pointerup",K),document.removeEventListener("pointercancel",K),k.current=void 0};document.addEventListener("pointermove",F,{passive:!1}),document.addEventListener("pointerup",K),document.addEventListener("pointercancel",K),k.current=()=>{clearTimeout(N),Q()}},u=p=>{const S=p.shiftKey?xy:Sy,$={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};if($[p.key])n.float(e.id,Da({x:t.x+$[p.key][0]*S,y:t.y+$[p.key][1]*S}));else if(p.key==="Delete"||p.key==="Backspace")n.hide(e.id);else if(p.key==="Home")n.dockAt(e.id);else return;p.preventDefault()},d=f??t;return c.jsx("button",{type:"button",className:["uif-action","uif-action-floating",o?"is-arranging":"",f?"is-moving":"",g.overTrash?"is-removing":"",g.overBar?"is-docking":"",i[e.id]?"is-pressed":""].filter(Boolean).join(" "),style:{left:d.x,top:d.y,zIndex:a},"aria-pressed":e.id in i?!!i[e.id]:void 0,"aria-label":e.label,title:`${e.label} (${e.command}) - hold to move; arrow keys move, Home returns it to the bar, Delete hides it`,"data-uif-floating":e.id,onPointerDown:w,onKeyDown:u,onClick:()=>{if(y.current){y.current=!1;return}s(e)},onContextMenu:p=>p.preventDefault(),children:c.jsx("span",{className:"uif-action-icon",children:e.icon??e.label.slice(0,1).toUpperCase()})})}function jy({layout:e}){const[t,n]=h.useState(""),[r,o]=h.useState(null),i=h.useRef(null),s=e.list(),l=v=>{try{o({text:v()})}catch(g){o({text:g.message,error:!0})}},a=v=>{v.preventDefault(),t.trim()&&l(()=>{const g=e.save(t);return n(""),`saved "${g.name}"`})},f=async v=>{var y;const g=(y=v.target.files)==null?void 0:y[0];if(v.target.value="",!g)return;const m=await g.text();l(()=>`imported and applied "${e.importProfile(m,g.name)}"`)};return c.jsxs("div",{className:"uif-palette-layout",role:"tabpanel",children:[c.jsxs("div",{className:"uif-palette-row",children:[c.jsx("strong",{children:"Layout"}),c.jsx("span",{className:"uif-palette-active",children:e.active?`active: ${e.active}`:"not saved yet"})]}),s.length>0&&c.jsx("ul",{className:"uif-palette-list",children:s.map(v=>c.jsxs("li",{className:v===e.active?"is-active":"",children:[c.jsxs("button",{type:"button",className:"uif-palette-item",title:"Apply this layout",onClick:()=>l(()=>(e.load(v),`loaded "${v}"`)),children:[c.jsx("span",{children:v}),c.jsx("code",{children:Nr})]}),c.jsx("button",{type:"button",className:"uif-link",title:`Download ${v}${Nr}`,onClick:()=>l(()=>(e.exportProfile(v),`exported "${v}"`)),children:"⤓"}),c.jsx("button",{type:"button",className:"uif-link",title:"Delete this layout",onClick:()=>l(()=>(e.remove(v),`deleted "${v}"`)),children:"✕"})]},v))}),c.jsxs("form",{className:"uif-palette-fields",onSubmit:a,children:[c.jsx("input",{value:t,onChange:v=>n(v.target.value),placeholder:"Save layout as…","aria-label":"Layout name",className:"uif-input"}),c.jsx("button",{type:"submit",className:"uif-button",disabled:!t.trim(),children:"Save"})]}),c.jsxs("div",{className:"uif-palette-fields",children:[c.jsxs("button",{type:"button",className:"uif-button is-quiet",onClick:()=>{var v;return(v=i.current)==null?void 0:v.click()},children:["Import ",Nr]}),c.jsx("button",{type:"button",className:"uif-button is-quiet",onClick:()=>l(()=>(e.exportProfile(),"exported the current layout")),children:"Export current"}),c.jsx("button",{type:"button",className:"uif-button is-quiet",title:"Put every button, the field and the strings back to the standard layout. Saved layouts are kept.",onClick:()=>l(()=>(e.reset(),`reset to the ${An} layout`)),children:"Reset"})]}),c.jsx("input",{ref:i,type:"file",accept:`${Nr},application/json,.json`,hidden:!0,onChange:f}),r&&c.jsx("p",{className:`uif-palette-note ${r.error?"is-error":""}`,role:"status",children:r.text})]})}const Gf=1900;function Ia({action:e}){return c.jsx("span",{className:"uif-action-icon",children:e.icon??e.label.slice(0,1).toUpperCase()})}function $y({registry:e,layout:t,onRun:n,pressed:r={},vertical:o=!1,rolling:i=!1}){gy(e);const s=e.visible(),l=h.useRef(null),a=h.useRef(null),[f,v]=h.useState(!1);h.useEffect(()=>{const N=a.current;if(!N||typeof ResizeObserver>"u")return;const O=()=>v(N.scrollWidth>N.clientWidth+1),F=new ResizeObserver(O);return F.observe(N),O(),()=>F.disconnect()});const[g,m]=h.useState(!1),[y,k]=h.useState(null),{arranging:x,setArranging:w,drag:u,onPointerDown:d,onKeyDown:p,guardClick:S}=Ng({containerRef:l,onReorder:(N,O)=>e.reorder(N,O),onRemove:N=>{const O=s[N];O&&e.hide(O.id)},onDropOutside:(N,O)=>{const F=s[N];F&&e.float(F.id,O)}});h.useEffect(()=>{if(!g&&!x)return;const N=O=>{var F;(F=l.current)!=null&&F.contains(O.target)||(m(!1),w(!1))};return document.addEventListener("pointerdown",N),()=>document.removeEventListener("pointerdown",N)},[g,x,w]);const $=s.map((N,O)=>c.jsx("button",{type:"button","data-uif-item":O,className:`uif-action ${x?"is-arranging":""} ${(u==null?void 0:u.index)===O?"is-dragged":""} ${r[N.id]?"is-pressed":""}`,"aria-pressed":N.id in r?!!r[N.id]:void 0,title:`${N.label} (${N.command})${x?"":" - hold to rearrange"}`,"aria-label":N.label,onPointerDown:F=>d(F,O),onKeyDown:F=>p(F,O,s.length),onClick:()=>S(()=>n(N)),onContextMenu:F=>F.preventDefault(),children:c.jsx(Ia,{action:N})},N.id));if(u&&!u.outside&&!u.overTrash){const O=$.filter((K,Q)=>Q!==u.index)[u.target],F=O?$.indexOf(O):$.length;$.splice(F,0,c.jsx("span",{className:"uif-action-slot",style:{width:u.width}},"__slot"))}const P=u?s[u.index]:void 0,C=!!u||!!y,M=u!=null&&u.overTrash?"release to hide":u!=null&&u.outside?"release to place it here":"drag to move · drop anywhere to place · drop on the trash to hide";return c.jsxs("div",{className:`uif-actionbar ${x?"is-arranging":""} ${y!=null&&y.overBar?"is-drop-target":""} ${o?"is-vertical":""} ${i?"is-rolling":""}`,ref:l,role:"toolbar","aria-label":"Actions","aria-orientation":o?"vertical":"horizontal",children:[c.jsx("div",{className:`uif-actionbar-items ${f?"is-overflowing":""}`,ref:a,children:$}),x?c.jsx("button",{type:"button",className:"uif-action uif-action-done",onClick:()=>w(!1),children:"Done"}):c.jsx("button",{type:"button",className:"uif-action uif-action-add",title:"Add actions, arrange, layouts","aria-expanded":g,onClick:()=>m(N=>!N),children:"+"}),x&&c.jsx("span",{className:"uif-arrange-hint",children:M}),P&&u&&wn.createPortal(c.jsx("div",{className:`uif-action uif-action-ghost ${u.overTrash?"is-removing":u.outside?"is-placing":""}`,style:{left:u.x-u.offsetX,top:u.y-u.offsetY,width:u.width,height:u.height},children:c.jsx(Ia,{action:P})}),document.body),C&&wn.createPortal(c.jsx("div",{"data-uif-trash":"",className:`uif-trash ${u!=null&&u.overTrash||y!=null&&y.overTrash?"is-hot":""}`,style:{zIndex:Gf+1},children:"🗑 Drop here to hide"}),document.body),c.jsx(Cy,{registry:e,barRef:l,arranging:x,pressed:r,onRun:n,onDragChange:k,zIndex:Gf}),g&&!x&&c.jsx(Ly,{registry:e,layout:t,onArrange:()=>{m(!1),w(!0)},onClose:()=>m(!1)})]})}const _y=[["actions","Actions"],["new","New"],["layout","Layout"]];let Jf="actions";function Ly({registry:e,layout:t,onArrange:n,onClose:r}){const o=e.hidden(),[i,s]=h.useState(Jf),l=u=>{Jf=u,s(u)},[a,f]=h.useState(""),[v,g]=h.useState(""),[m,y]=h.useState("command"),[k,x]=h.useState(""),w=u=>{u.preventDefault(),!(!a.trim()||!k.trim())&&(e.addCustom({label:a,icon:v.trim(),kind:m,payload:k.trim()}),f(""),g(""),x(""))};return c.jsxs("div",{className:"uif-palette",onKeyDown:u=>u.key==="Escape"&&r(),children:[c.jsx("div",{className:"uif-palette-tabs",role:"tablist","aria-label":"Palette",children:_y.map(([u,d])=>c.jsx("button",{type:"button",role:"tab","aria-selected":i===u,className:`uif-palette-tab ${i===u?"is-active":""}`,onClick:()=>l(u),children:d},u))}),i==="actions"&&c.jsxs("div",{role:"tabpanel",className:"uif-palette-panel",children:[c.jsxs("div",{className:"uif-palette-row",children:[c.jsx("strong",{children:"Actions"}),c.jsx("button",{type:"button",className:"uif-link",onClick:n,children:"Arrange…"})]}),o.length>0?c.jsx("ul",{className:"uif-palette-list",children:o.map(u=>c.jsxs("li",{children:[c.jsxs("button",{type:"button",className:"uif-palette-item",onClick:()=>e.show(u.id),title:"Add to the bar",children:[c.jsx(Ia,{action:u}),c.jsx("span",{children:u.label}),c.jsx("code",{children:u.command})]}),e.isCustom(u.id)&&c.jsx("button",{type:"button",className:"uif-link",title:"Delete this action",onClick:()=>e.removeCustom(u.id),children:"✕"})]},u.id))}):c.jsx("p",{className:"uif-palette-note",children:"Every action is on the bar."})]}),i==="new"&&c.jsx("div",{role:"tabpanel",className:"uif-palette-panel",children:c.jsxs("form",{className:"uif-palette-form",onSubmit:w,children:[c.jsxs("div",{className:"uif-palette-fields",children:[c.jsx("input",{value:v,onChange:u=>g(u.target.value),placeholder:"★",maxLength:2,"aria-label":"Icon",className:"uif-input uif-input-icon"}),c.jsx("input",{value:a,onChange:u=>f(u.target.value),placeholder:"Label","aria-label":"Label",className:"uif-input",autoFocus:!0})]}),c.jsxs("div",{className:"uif-palette-fields",children:[c.jsxs("select",{value:m,onChange:u=>y(u.target.value),"aria-label":"Kind",className:"uif-input",children:[c.jsx("option",{value:"command",children:"runs command"}),c.jsx("option",{value:"send",children:"sends text"})]}),c.jsx("input",{value:k,onChange:u=>x(u.target.value),placeholder:m==="command"?"spawn logs; strings on":"Summarize the last reply","aria-label":m==="command"?"Command":"Text",className:"uif-input"})]}),c.jsx("button",{type:"submit",className:"uif-button",disabled:!a.trim()||!k.trim(),children:"Add to bar"})]})}),i==="layout"&&c.jsx(jy,{layout:t})]})}function Py(){const e=Rt(),{windows:t}=e,[n,r]=h.useState(!1),o=h.useRef(null);return h.useEffect(()=>{if(!n)return;const i=s=>{var l;(l=o.current)!=null&&l.contains(s.target)||r(!1)};return document.addEventListener("pointerdown",i),()=>document.removeEventListener("pointerdown",i)},[n]),c.jsxs("div",{className:"uif-windows-menu",ref:o,children:[c.jsx("button",{type:"button",className:`uif-windows-toggle ${n?"is-open":""}`,"aria-haspopup":"menu","aria-expanded":n,"aria-label":"Windows",title:`Windows: ${t.defs.map(i=>i.file).join(" ")}`,onClick:()=>r(i=>!i),children:"▤"}),n&&c.jsx("div",{className:"uif-windows-list",role:"menu","aria-label":"Windows",onKeyDown:i=>i.key==="Escape"&&r(!1),children:t.defs.map(({id:i,icon:s,file:l,detail:a})=>c.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":t.isOpen(i),className:`uif-windows-item ${t.isOpen(i)?"is-open":""}`,onClick:()=>{t.toggle(i),r(!1)},children:[c.jsx("span",{className:"uif-windows-icon","aria-hidden":"true",children:s}),c.jsx("span",{className:"uif-windows-file",children:l}),c.jsx("span",{className:"uif-windows-detail",children:(a==null?void 0:a(e))??""}),c.jsx("span",{className:"uif-windows-check","aria-hidden":"true",children:t.isOpen(i)?"●":""})]},i))})]})}const Zf="uif:responses:settings",My={textSize:"m",answerIn:"active",openMaximized:!1,details:!1},Ty={s:"12.5px",m:"14px",l:"16px",xl:"19px"};let Fn={...My,...Ie(Zf,{})};const Aa=new Set;function qf(e){typeof document<"u"&&document.documentElement.style.setProperty("--uif-output-font",Ty[e.textSize])}qf(Fn);const Sn={get:()=>Fn,set(e){Fn={...Fn,...e},Je(Zf,Fn),qf(Fn),Aa.forEach(t=>t(Fn))},subscribe(e){return Aa.add(e),()=>void Aa.delete(e)}};function Ry(){const{outputs:e}=Rt(),[t,n]=h.useState(!1),[r,o]=h.useState(Sn.get()),i=h.useRef(null);h.useEffect(()=>Sn.subscribe(o),[]),h.useEffect(()=>{if(!t)return;const m=y=>{var k;(k=i.current)!=null&&k.contains(y.target)||n(!1)};return document.addEventListener("pointerdown",m),()=>document.removeEventListener("pointerdown",m)},[t]);const s=e.list(),l=s.length,a=s.find(m=>m.id===e.activeId),f=m=>()=>{m(),n(!1)},v=m=>Sn.set(m),g=(m,y,k,x=!1,w=!1)=>c.jsxs("button",{type:"button",role:"menuitem",className:`uif-windows-item ${w?"is-danger":""}`,disabled:x,onClick:f(k),children:[c.jsx("span",{className:"uif-windows-file",children:m}),c.jsx("span",{className:"uif-windows-detail",children:y})]});return c.jsxs("div",{className:"uif-windows-menu uif-responses-menu",ref:i,children:[c.jsxs("button",{type:"button",className:`uif-windows-toggle ${t?"is-open":""}`,"aria-haspopup":"menu","aria-expanded":t,"aria-label":`Response windows (${l})`,title:`Response windows: ${l} open — tile, cascade, close all, settings`,onClick:()=>n(m=>!m),children:["❏",l>0&&c.jsx("span",{className:"uif-responses-count",children:l})]}),t&&c.jsxs("div",{className:"uif-windows-list uif-responses-list",role:"menu","aria-label":"Response windows",onKeyDown:m=>m.key==="Escape"&&n(!1),children:[c.jsxs("div",{className:"uif-menu-head",children:["Response windows · ",l," open"]}),g("New window","spawn",()=>{const m=e.spawn();r.openMaximized&&e.maximize(m,!0)}),g("Tile","fill the screen, side by side",()=>e.tile(),l===0),g("Cascade","stacked, a step apart",()=>e.cascade(),l===0),g("Call all home","back beside the field",()=>e.callHome("all"),l===0),g(a!=null&&a.maximized?"Shrink back":"Fill the screen",a?`the active one: ${a.title}`:"no active window",()=>a&&e.maximize(a.id),!a),g("Clear all","empty every window",()=>e.clearAll(),l===0),g("Close all",`${l} window${l===1?"":"s"}`,()=>e.closeAll(),l===0,!0),c.jsx("div",{className:"uif-menu-head",children:"Settings"}),c.jsxs("div",{className:"uif-menu-row",role:"group","aria-label":"Text size",children:[c.jsx("span",{children:"Text"}),["s","m","l","xl"].map(m=>c.jsx("button",{type:"button","aria-pressed":r.textSize===m,className:r.textSize===m?"is-on":"",onClick:()=>v({textSize:m}),children:m.toUpperCase()},m))]}),c.jsxs("div",{className:"uif-menu-row",role:"group","aria-label":"Answers go",children:[c.jsx("span",{children:"Answers"}),c.jsx("button",{type:"button","aria-pressed":r.answerIn==="active",className:r.answerIn==="active"?"is-on":"",onClick:()=>v({answerIn:"active"}),children:"active window"}),c.jsx("button",{type:"button","aria-pressed":r.answerIn==="new",className:r.answerIn==="new"?"is-on":"",onClick:()=>v({answerIn:"new"}),children:"new window each"})]}),c.jsxs("label",{className:"uif-menu-row uif-menu-check",children:[c.jsx("input",{type:"checkbox",checked:r.openMaximized,onChange:m=>v({openMaximized:m.target.checked})})," new windows fill the screen"]}),c.jsxs("label",{className:"uif-menu-row uif-menu-check",title:"Off: the details are still kept in .memory and in the T-mode log (last)",children:[c.jsx("input",{type:"checkbox",checked:r.details,onChange:m=>v({details:m.target.checked})})," show delivery details under answers"]}),c.jsx("div",{className:"uif-menu-foot",children:"double-click a window's header: fill the screen / shrink back · Esc shrinks · T mode: close all, tile, cascade, max"})]})]})}const by=6;function Oy({holdMs:e=400,onMove:t,onDrop:n,onTap:r}){const[o,i]=h.useState(null),s=h.useRef({onMove:t,onDrop:n,onTap:r});s.current={onMove:t,onDrop:n,onTap:r};const l=h.useRef();return h.useEffect(()=>()=>{var f;return(f=l.current)==null?void 0:f.call(l)},[]),{onPointerDown:h.useCallback(f=>{var S;if(f.button!==0)return;f.preventDefault(),f.stopPropagation(),(S=l.current)==null||S.call(l);const v=f.currentTarget.getBoundingClientRect(),g={x:f.clientX,y:f.clientY},m={offsetX:g.x-v.left,offsetY:g.y-v.top};let y=e===0,k=!1,x=g;const w=y?void 0:window.setTimeout(()=>{var P,C,M;y=!0,(P=navigator.vibrate)==null||P.call(navigator,15);const $={...x,...m};i($),(M=(C=s.current).onMove)==null||M.call(C,$)},e),u=$=>{var C,M;if(x={x:$.clientX,y:$.clientY},!y){Math.hypot(x.x-g.x,x.y-g.y)>by&&(clearTimeout(w),k=!0,p());return}$.preventDefault();const P={...x,...m};i(P),(M=(C=s.current).onMove)==null||M.call(C,P)},d=()=>{var $,P;clearTimeout(w),p(),y?(i(null),s.current.onDrop({...x,...m})):k||(P=($=s.current).onTap)==null||P.call($)},p=()=>{document.removeEventListener("pointermove",u),document.removeEventListener("pointerup",d),document.removeEventListener("pointercancel",d),l.current=void 0};document.addEventListener("pointermove",u,{passive:!1}),document.addEventListener("pointerup",d),document.addEventListener("pointercancel",d),l.current=()=>{clearTimeout(w),p()}},[e]),dragging:o}}const Fa="__bar";function zy({state:e,onChange:t,children:n}){const{hubRef:r,raise:o,zIndexOf:i}=Rt(),{position:s,setPosition:l,startDrag:a,onHandleKeyDown:f,isDragging:v}=es({initialPosition:{x:e.x,y:e.y},initialSize:{width:60,height:60},minWidth:60,maxWidth:4e3,minHeight:40,maxHeight:4e3,resizable:!1,onCommit:y=>{var u;const k=(u=r.current)==null?void 0:u.getBoundingClientRect(),x=y.x+20,w=y.y+20;k&&x>=k.left&&x<=k.right&&w>=k.top&&w<=k.bottom?t(null):t({...e,x:Math.round(y.x),y:Math.round(y.y)})}});h.useEffect(()=>{l({x:e.x,y:e.y})},[e.x,e.y,l]),h.useEffect(()=>o(Fa),[o]);const g=h.useRef(null),m=()=>{const y=g.current;if(!y||v)return;const k=y.getBoundingClientRect(),x=Math.max(4,Math.min(k.left,window.innerWidth-k.width-4)),w=Math.max(4,Math.min(k.top,window.innerHeight-k.height-4));(Math.abs(x-k.left)>.5||Math.abs(w-k.top)>.5)&&l({x,y:w})};return h.useLayoutEffect(m),h.useEffect(()=>(window.addEventListener("resize",m),()=>window.removeEventListener("resize",m))),wn.createPortal(c.jsxs("div",{ref:g,className:`uif-isolated-bar ${e.vertical?"is-vertical":""} ${v?"is-dragging":""}`,style:{left:s.x,top:s.y,zIndex:i(Fa)},onPointerDownCapture:()=>o(Fa),role:"toolbar","aria-label":"Button row, taken out of the field",children:[c.jsxs("span",{className:"uif-isolated-tools",children:[c.jsx("button",{type:"button",className:"uif-bar-grip",onPointerDown:a,onKeyDown:f,title:"Drag to move; drop it on the field to put it back. Arrow keys move it.","aria-label":"Move the button row (drop on the field to join it)",children:"⠿"}),c.jsx("button",{type:"button",className:"uif-bar-tool",title:e.vertical?"Lay it flat":"Stand it up (sideways)","aria-label":e.vertical?"Horizontal button row":"Vertical button row",onClick:()=>t({...e,vertical:!e.vertical}),children:e.vertical?"⇆":"⇅"}),c.jsx("button",{type:"button",className:"uif-bar-tool",title:"Put it back in the field","aria-label":"Join the field",onClick:()=>t(null),children:"⤓"})]}),n]}),document.body)}const Dy=28;function ep(e,t,n=Dy){const r=[["top",e.y],["bottom",t.height-(e.y+e.height)],["left",e.x],["right",t.width-(e.x+e.width)]];let o=null;for(const i of r)i[1]<=n&&(!o||i[1]<o[1])&&(o=i);return o?o[0]:null}const tp=()=>{if(typeof window>"u")return null;const e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null};function Iy(e=typeof navigator<"u"?navigator.userAgent:""){return/Edg\//.test(e)?"Edge sends the audio to Microsoft's speech service; this page records and sends nothing.":/Chrome\//.test(e)||/CriOS/.test(e)?"Chrome sends the audio to Google's speech service; this page records and sends nothing.":/Safari\//.test(e)?"Safari uses Apple's speech recognition (on this device where it can); this page records and sends nothing.":"Your browser's own speech engine hears it; this page records and sends nothing."}function Ay(e,t){const[n]=h.useState(()=>e&&!!tp()),[r,o]=h.useState(!1),i=h.useRef(null),s=h.useRef(t);s.current=t;const l=h.useCallback(()=>{var f;(f=i.current)==null||f.stop()},[]),a=h.useCallback(()=>{if(i.current){i.current.stop();return}const f=tp();if(!f)return;const v=new f;v.lang=navigator.language||"en-US",v.interimResults=!1,v.continuous=!1,v.onresult=g=>{let m="";for(let y=g.resultIndex;y<g.results.length;y++)g.results[y].isFinal&&(m+=g.results[y][0].transcript);m.trim()&&s.current(m.trim())},v.onend=()=>{i.current=null,o(!1)},v.onerror=()=>{i.current=null,o(!1)},i.current=v,o(!0);try{v.start()}catch{i.current=null,o(!1)}},[]);return h.useEffect(()=>()=>{var f;return(f=i.current)==null?void 0:f.abort()},[]),{available:n,listening:r,toggle:a,stop:l}}const Fy=104,np="(max-width: 640px), (pointer: coarse) and (max-width: 900px)";function Hy(){const e=()=>{var r;return{width:typeof window<"u"?window.innerWidth:1024,handheld:typeof window<"u"&&!!((r=window.matchMedia)!=null&&r.call(window,np).matches)}},[t,n]=h.useState(e);return h.useEffect(()=>{const r=()=>n(e());return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]),t}function Uy(e){return!!e&&typeof e[Symbol.asyncIterator]=="function"}const By=e=>hy()?c.jsx(rp,{...e}):c.jsx(Qf,{storageKey:e.storageKey,popoutUrl:e.popoutUrl,defaultStrings:e.defaultStrings,modules:e.modules,children:c.jsx(rp,{...e})}),rp=({value:e,onChange:t,onSend:n,onCommand:r,onAction:o,onModeChange:i,actions:s,isLoading:l=!1,className:a="",placeholder:f,terminalPlaceholder:v,disabled:g=!1,mode:m="chat",initialPosition:y,initialSize:k={width:600,height:120},minWidth:x=300,maxWidth:w,minHeight:u=60,maxHeight:d,draggable:p=!0,resizable:S=!0,dockable:$=!0,modeBar:P,persona:C,glowEffect:M=!0,glassEffect:N=!0,voice:O=!0,autoGrow:F=!0,focusKeys:K=!0,left:Q,right:V})=>{var Lp,Pp;const J=Rt(),{registry:X,outputs:Y,strings:D,setStrings:I,hubRef:B,requestScreens:G,storageKey:te,raise:Ae,zIndexOf:ve,registerSender:_e,layout:We,registerHubLayout:Ve,context:bt}=J,mt=`uif:${te}:hub`,[Se]=h.useState(()=>Ie(mt,{})),[as,Co]=h.useState(""),Ct=e??as,Nt=h.useRef(Ct);Nt.current=Ct;const Ot=h.useCallback(L=>{e===void 0&&Co(L),t==null||t(L)},[e,t]),[se,Xt]=h.useState(Se.mode??(m==="text"?"chat":m)),[Ce,Un]=h.useState(Se.docked!==void 0?Se.docked:typeof window<"u"&&((Lp=window.matchMedia)!=null&&Lp.call(window,np).matches)&&$?"bottom":null),[zt,xn]=h.useState(Se.arrange??"auto"),[it,Ze]=h.useState(Se.isolated??null),En=Hy(),[Pr,Gt]=h.useState(!1),[No,jo]=h.useState(!1),Dt=h.useRef(null),[$o,E]=h.useState([]),[j,R]=h.useState(null),b=h.useRef([]),_=h.useRef(-1),A=h.useRef(null),H=h.useRef(null),q=h.useRef(0),{position:Z,size:re,setPosition:Le,setSize:Pe,isDragging:ie,isResizing:ht,startDrag:Bn,startResize:Wn,onHandleKeyDown:us}=es({initialPosition:Se.x!==void 0&&Se.y!==void 0?{x:Se.x,y:Se.y}:y??{x:window.innerWidth/2-k.width/2,y:window.innerHeight/2-k.height/2},initialSize:Se.width&&Se.height?{width:Se.width,height:Se.height}:k,minWidth:x,maxWidth:w,minHeight:u,maxHeight:d,draggable:p,resizable:S,onCommit:(L,T)=>_o.current(L,T)}),_o=h.useRef(()=>{});h.useEffect(()=>{ie||ht||Je(mt,{x:Z.x,y:Z.y,width:re.width,height:re.height,mode:se,docked:Ce,arrange:zt,isolated:it})},[mt,Z,re,se,Ce,zt,it,ie,ht]),h.useEffect(()=>(s==null||s.forEach(L=>X.register(L)),()=>s==null?void 0:s.forEach(L=>X.unregister(L.id))),[s,X]);const st=h.useRef(null),[Lo,Po]=h.useState(!1);h.useEffect(()=>X.subscribe(()=>{st.current&&Je(`uif:${te}:bar:${st.current}`,X.snapshot())}),[X,te]);const Vn=h.useCallback(L=>ag(X,(P==null?void 0:P[L])??mg[L==="terminal"?"terminal":"chat"]),[X,P]);h.useEffect(()=>{if(st.current===se)return;const L=st.current===null,T=Ie(`uif:${te}:bar:${se}`,null);if(st.current=se,X.restore(T?{...T,custom:X.snapshot().custom}:Vn(se)),L)return;Po(!0);const W=setTimeout(()=>Po(!1),720);return()=>clearTimeout(W)},[se,X,te]),h.useEffect(()=>{var L;(L=A.current)==null||L.focus()},[se]),h.useEffect(()=>{const L=H.current;L&&(L.scrollTop=L.scrollHeight)},[$o]),h.useEffect(()=>{if(!j)return;const L=setTimeout(()=>R(null),3500);return()=>clearTimeout(L)},[j]);const lt=h.useCallback((L,T="out")=>{const W={id:q.current++,kind:T,text:L};E(ne=>[...ne.slice(-299),W]),T!=="cmd"&&R(W)},[]),Mo=h.useCallback((L,T)=>{const W={id:q.current++,kind:"out",text:L,sections:T};E(ne=>[...ne.slice(-299),W])},[]),gp=h.useRef("chat"),yp=h.useRef("chat"),Ya=h.useCallback(()=>{M&&(Gt(!0),setTimeout(()=>Gt(!1),500))},[M]),Jt=h.useCallback(L=>{Xt(T=>{T!=="terminal"&&(gp.current=T);const W=L==="toggle"?T==="terminal"?gp.current:"terminal":L==="persona"&&!C?T:L;return W!==T&&(i==null||i(W)),W})},[i,C]),vp=h.useCallback(L=>{$&&(Un(L),L===null&&Le({x:window.innerWidth/2-re.width/2,y:window.innerHeight/2-re.height/2}))},[$,Le,re.width,re.height]);_o.current=(L,T)=>{if(T!=="drag"||!$)return;const W=ep(L,{width:window.innerWidth,height:window.innerHeight});W&&Un(W)};const cs=ie&&$?ep({...Z,...re},{width:En.width,height:window.innerHeight}):null,To=h.useCallback(async(L,T)=>{var bp,Op;if(!L.trim())return;const W=T?null:/^@(\S+)\s+([\s\S]+)$/.exec(L);let ne=T;if(ne)Y.setActive(ne);else if(W)L=W[2],ne=Y.resolve(W[1])??Y.spawn(W[1]),Y.setActive(ne),Ae(ne);else{const ge=Sn.get().answerIn==="new";ne=(ge?void 0:Y.resolve(void 0))??Y.spawn(),(ge||!Y.list().some(It=>It.id===ne&&It.messages.length))&&Sn.get().openMaximized&&Y.maximize(ne,!0)}Y.append(ne,{role:"user",text:L}),Ya();const jt=bt.forSend(L,ne),$t=ne,Mp={},Ja=ge=>{var It;return ge&&!ms.undelivered&&bt.appendHistory({ts:Date.now()/1e3,session:te,output:(It=Y.list().find(bo=>bo.id===$t))==null?void 0:It.title,output_id:$t,user:L,assistant:ge,prompt:jt.promptSource,model:Ta(jt.model),...Mp})},ms={};let Za=null;const Iv=ge=>{Object.assign(ms,ge),Za&&Y.update($t,Za,ge)},Tp=new AbortController,Xn=n==null?void 0:n(L,{outputId:ne,mode:yp.current,context:jt,annotate:ge=>Object.assign(Mp,ge),markReply:Iv,signal:Tp.signal});if(Xn===void 0)return;if(typeof Xn=="string"){Y.append(ne,{role:"assistant",text:Xn,...ms}),Ja(Xn);return}const Mr=Y.append(ne,{role:"assistant",text:"",pending:!0,...ms});Za=Mr,jo(!0);let Rp=()=>{};const Av=new Promise(ge=>{Rp=()=>{Tp.abort(),ge("stop")}});Dt.current=Rp;try{if(Uy(Xn)){let ge="";const It=Xn[Symbol.asyncIterator]();for(;;){const bo=await Promise.race([It.next(),Av]);if(bo==="stop"){(Op=(bp=It.return)==null?void 0:bp.call(It,void 0))==null||Op.catch(()=>{}),Y.update(ne,Mr,{pending:!1,undelivered:!0,...ge?{}:{text:"Stopped before the model wrote anything."}}),Y.append(ne,{role:"system",kind:"delivery",tone:"bad",text:"stopped by you: not delivered in full, not kept in .history"});return}if(bo.done)break;ge+=bo.value,Y.update(ne,Mr,{text:ge})}Y.update(ne,Mr,{pending:!1}),Ja(ge)}else{const ge=await Xn;Y.update(ne,Mr,{text:ge??"",pending:!1}),Ja(ge??"")}}catch(ge){Y.update(ne,Mr,{text:`Error: ${ge.message??ge}`,pending:!1,undelivered:!0})}finally{Dt.current=null,jo(!1)}},[n,Y,Ae,Ya,bt,te]);h.useEffect(()=>_e((L,T)=>void To(L,T)),[_e,To]);const wp=h.useRef({position:Z,size:re,mode:se,docked:Ce,arrangement:zt,isolated:it});wp.current={position:Z,size:re,mode:se,docked:Ce,arrangement:zt,isolated:it};const kp=m==="text"?"chat":m;h.useEffect(()=>Ve({get:()=>{const L=wp.current;return{...L.position,...L.size,mode:L.mode,docked:L.docked,arrange:L.arrangement,isolated:L.isolated}},set:L=>{const T=L??{...y??{x:window.innerWidth/2-k.width/2,y:window.innerHeight/2-k.height/2},...k,mode:kp,docked:null,arrange:"auto",isolated:null};Pe({width:T.width,height:T.height}),Le({x:Math.max(60-T.width,Math.min(T.x,window.innerWidth-60)),y:Math.max(0,Math.min(T.y,window.innerHeight-30))}),Un($?T.docked:null),Jt(T.mode),xn(T.arrange??"auto"),Ze(T.isolated??null)}}),[Ve,y,k,kp,Le,Pe,Jt,$]);const Sp=h.useRef(null),ds=h.useCallback((L,T)=>{var $t;const W=($t=B.current)==null?void 0:$t.getBoundingClientRect(),ne=(T==null?void 0:T.x)??(W?W.left:16),jt=(T==null?void 0:T.y)??(W?Math.max(8,W.top-56):16);Ze({x:Math.round(Math.max(0,ne)),y:Math.round(Math.max(0,jt)),vertical:L})},[B]),Kn=Oy({onDrop:L=>{var ne;const T=(ne=B.current)==null?void 0:ne.getBoundingClientRect();T&&L.x>=T.left-24&&L.x<=T.right+24&&L.y>=T.top-24&&L.y<=T.bottom+24||ds(!1,{x:L.x-L.offsetX,y:L.y-L.offsetY})},onTap:()=>lt("hold the grip, then drag the button row out of the field (or type: isolate)")}),xp=h.useRef(()=>{}),fs=h.useCallback(L=>({args:L,print:lt,printSections:Mo,clearLog:()=>E([]),send:T=>void To(T),runCommand:T=>xp.current(T),mode:se,setMode:Jt,docked:Ce,dock:vp,strings:D,setStrings:I,outputs:Y,registry:X,layout:We,windows:J.windows,remember:T=>bt.remember(T),bar:{isolated:!!it,isolate:T=>ds((T==null?void 0:T.vertical)??!1),join:()=>Ze(null),arrangement:zt,arrange:xn,face:st.current??se,faces:{get:T=>T===st.current?X.snapshot():(()=>{const W=Ie(`uif:${te}:bar:${T}`,null);return W?{...W,custom:X.snapshot().custom}:Vn(T)})(),set:(T,W)=>T===st.current?X.restore(W):Je(`uif:${te}:bar:${T}`,W),standard:Vn}},requestScreens:async()=>lt(await G())}),[lt,Mo,To,se,Jt,Ce,vp,D,I,Y,X,We,J.windows,bt,G,it,zt,ds,te,Vn]),Qa=h.useCallback(async(L,T=[])=>{try{await L.run(fs(T)),o==null||o(L,T)}catch(W){lt(`${L.command}: ${W.message??W}`,"err")}},[fs,o,lt]),Ep=h.useCallback(L=>{lt(`❯ ${L}`,"cmd");const T=gg(L,X);if(!T)return;if(T.action)return void Qa(T.action,T.args);const W=r==null?void 0:r(T.name,T.args,fs(T.args));typeof W=="string"?lt(W):r||lt(`unknown command: ${T.name} (try help)`,"err")},[fs,r,lt,X,Qa]);xp.current=Ep;const Cp=()=>{const L=Ct;if(L.trim()){if(se!=="terminal"&&L.trim()==="T"||se==="terminal"&&L.trim()===">"){Jt("toggle"),Ot("");return}if(C&&L.trim().toLowerCase()===C.label.toLowerCase()&&se!=="persona"){Jt("persona"),Ot("");return}if(se==="persona"&&L.trim()===">"){Jt("chat"),Ot("");return}se==="terminal"||L.startsWith("/")?(b.current=[...b.current.filter(T=>T!==L),L].slice(-100),_.current=-1,Ep(L.trim()),Ya()):To(L),Ot("")}},Rv=L=>{if(L.key==="Enter"&&!L.shiftKey&&!L.nativeEvent.isComposing&&L.nativeEvent.keyCode!==229){L.preventDefault(),Cp();return}if(se!=="terminal"||Ct.includes(` `)||L.key!=="ArrowUp"&&L.key!=="ArrowDown")return;const T=b.current;if(!T.length)return;L.preventDefault();let W=_.current;L.key==="ArrowUp"?W=W===-1?T.length-1:Math.max(0,W-1):W=W===-1||W+1>=T.length?-1:W+1,_.current=W,Ot(W===-1?"":T[W])},bv=h.useCallback(L=>{B.current=L},[B]),Ov=Math.max(8,Math.min(Z.x,En.width-Math.min(re.width,Math.max(200,En.width-16))-8)),Np=typeof window<"u"?Math.max(8,Math.min(Z.y,window.innerHeight-re.height-8)):Z.y;let Ro={left:Ov,top:Np};Ce==="top"&&(Ro={top:0,left:"50%",transform:"translateX(-50%)"}),Ce==="bottom"&&(Ro={bottom:0,left:"50%",transform:"translateX(-50%)"}),Ce==="left"&&(Ro={left:0,top:"50%",transform:"translateY(-50%)"}),Ce==="right"&&(Ro={right:0,top:"50%",transform:"translateY(-50%)"});const zv=l||No,Ne=se==="terminal";yp.current=se;const Xa=zt==="sideways"||zt==="auto"&&re.height<Fy,ps=Math.max(200,En.width-16),[Yn,jp]=h.useState(!1);h.useEffect(()=>{if(!Yn)return;const L=T=>{T.key==="Escape"&&jp(!1)};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[Yn]),h.useEffect(()=>{if(!K)return;const L=T=>{var $t;const W=T.target,ne=!!W&&(W.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(W.tagName));!((T.ctrlKey||T.metaKey)&&!T.altKey&&T.key.toLowerCase()==="k")&&(T.key!=="/"||ne||T.ctrlKey||T.metaKey||T.altKey)||T.isComposing||(T.preventDefault(),($t=A.current)==null||$t.focus())};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[K]);const[Ga,$p]=h.useState(0),Qn=h.useRef(0);h.useEffect(()=>{const L=A.current;if(!F||!L||Yn||Xa||!Ct){Qn.current&&(Qn.current=0,$p(0));return}const T=L.scrollHeight-L.clientHeight,W=Math.max(0,Math.round(window.innerHeight*.45)-re.height),ne=Math.max(0,Math.min(W,Qn.current+T));if(Math.abs(ne-Qn.current)>2||T<0&&Qn.current>0){const jt=T<0?Math.max(0,Qn.current+T):ne;Qn.current=jt,$p(jt)}},[Ct,F,Yn,Xa,re.height]);const Cn=Ay(O,L=>Ot((Nt.current?Nt.current.replace(/\s*$/," "):"")+L)),Dv=["ultimate-input-field",Pr?"animate-glow":"",Ce?`transition-all is-docked docked-${Ce}`:"",cs?`is-drawn-${cs}`:"",Yn?"is-maximized":"",Ne?"terminal-glass":N?"glass-effect":"",Ne?"is-terminal":"is-chat",se==="persona"?"is-persona":"",Xa?"is-sideways":"is-stacked",En.handheld?"is-handheld":"",it?"has-isolated-bar":"",a].filter(Boolean).join(" "),_p=L=>c.jsx($y,{registry:X,layout:We,onRun:T=>void Qa(T),vertical:L,rolling:Lo,pressed:{strings:D,dock:!!Ce,...Object.fromEntries(J.windows.defs.map(T=>[`win-${T.id}`,J.windows.isOpen(T.id)]))}});return c.jsxs("div",{ref:bv,className:Dv,style:Yn?{left:0,top:0,right:"auto",bottom:"auto",transform:"none",width:"100vw",height:"100vh",maxWidth:"none",zIndex:ve(os)}:{...Ro,...Ga&&!Ce?{top:Math.max(8,Math.min(Np,window.innerHeight-re.height-Ga-8))}:{},width:Math.min(re.width,ps),height:re.height+Ga,minWidth:Math.min(x,ps),maxWidth:w===void 0?ps:Math.min(w,ps),minHeight:u,zIndex:ve(os)},onPointerDownCapture:()=>Ae(os),children:[Ne&&c.jsxs("div",{className:"uif-termlog",ref:H,role:"log","aria-live":"polite",children:[$o.length===0&&c.jsx("div",{className:"uif-termline is-dim",children:"T mode: type a command, or help"}),$o.map(L=>{var T;return c.jsxs("div",{className:`uif-termline is-${L.kind} ${L.sections?"is-report":""}`,children:[L.text,(T=L.sections)==null?void 0:T.map((W,ne)=>c.jsxs("details",{className:`uif-termsection is-${W.level??"ok"}`,open:W.open,children:[c.jsxs("summary",{children:[c.jsx("span",{className:"uif-termmark","aria-hidden":"true",children:W.level==="bad"?"✗":W.level==="warn"?"!":"✓"}),W.title,c.jsx("span",{className:"uif-termhint",children:W.level??"ok"})]}),W.lines.map((jt,$t)=>c.jsx("div",{className:"uif-termsub",children:jt},$t))]},ne))]},L.id)})]}),cs&&wn.createPortal(c.jsx("div",{className:`uif-dock-hint is-${cs}`,"aria-hidden":"true"}),document.body),p&&c.jsx("div",{className:`drag-handle ${ie?"dragging":""}`,onPointerDown:Yn?void 0:L=>{if(!Ce)return Bn(L);const T=L.currentTarget.closest(".ultimate-input-field").getBoundingClientRect();Un(null),Bn(L,{x:T.left,y:T.top})},onDoubleClick:()=>jp(L=>!L),onKeyDown:us,tabIndex:0,role:"group","aria-label":`Input field. ${qi}; double-click to fill the screen or shrink back`,title:`${qi}. Double-click: fill the screen / shrink back (Esc)`,children:c.jsx("div",{className:"drag-indicator"})}),c.jsxs("div",{className:"uif-row",children:[Q&&c.jsx("div",{className:"uif-modules uif-modules-left",children:Q}),c.jsxs("div",{className:"uif-core",children:[c.jsxs("div",{className:`uif-prompt ${Cn.available&&!Ne?"has-mic":""}`,children:[Ne&&c.jsx("span",{className:"uif-prompt-sigil",children:"❯"}),c.jsx("textarea",{ref:A,value:Ct,onChange:L=>Ot(L.target.value),onKeyDown:Rv,placeholder:Ne?v||"Enter a command — help · > for ask mode":se==="persona"&&C?C.placeholder||`${C.label} mode · > for the generic ask · T for terminal mode`:f||"Message… @output to target · /command to run · T for terminal mode",disabled:g,spellCheck:!Ne,enterKeyHint:Ne?"go":"send","aria-label":Ne?"Command":"Message",className:`ultimate-textarea ${Ne?"terminal-mode":"text-mode"} ${ie?"pointer-events-none":""}`}),Cn.available&&!Ne&&c.jsx("button",{type:"button",className:`uif-mic ${Cn.listening?"is-on":""}`,"aria-pressed":Cn.listening,onClick:Cn.toggle,title:Cn.listening?"Listening — press to stop":`Speak instead of typing (off until pressed). ${Iy()}`,"aria-label":Cn.listening?"Stop voice input":"Voice input",children:c.jsx("span",{"aria-hidden":"true",children:Cn.listening?"●":"🎤"})})]}),c.jsxs("div",{className:"ultimate-controls",children:[c.jsxs("div",{className:"ultimate-controls-left",children:[c.jsx(Nf,{variant:"ghost",size:"icon",className:`uif-mode-toggle ${Ne?"is-terminal":""}`,onClick:()=>Jt("toggle"),type:"button",title:Ne?"> : back to ask mode":"T : terminal mode","aria-label":Ne?"Switch to ask mode":"Switch to terminal mode",children:Ne?c.jsx(Sg,{}):c.jsx(xg,{})}),C&&c.jsx("button",{type:"button",className:`uif-persona-toggle ${se==="persona"?"is-on":""}`,"aria-pressed":se==="persona",onClick:()=>Jt(se==="persona"?"chat":"persona"),title:se==="persona"?`${C.label} mode · press for the generic ask mode (or type >)`:C.title||`${C.label} mode (or type ${C.label})`,children:C.label}),c.jsx(Py,{}),c.jsx(Ry,{}),!it&&c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",className:`uif-bar-grip ${Kn.dragging?"is-dragging":""}`,onPointerDown:Kn.onPointerDown,onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),ds(!1))},title:"Hold, then drag the button row out of the field","aria-label":"Button row: hold and drag to take it out of the field (Enter does it)",children:"⠿"}),c.jsx("div",{className:"uif-bar-slot",ref:Sp,children:_p(!1)})]})]}),j&&!Ne&&c.jsx("span",{className:`uif-status is-${j.kind}`,children:j.text}),No&&!Ne?c.jsx("button",{type:"button",className:"uif-stop",onClick:()=>{var L;return(L=Dt.current)==null?void 0:L.call(Dt)},title:"Stop this answer","aria-label":"Stop",children:c.jsx("span",{"aria-hidden":"true",children:"■"})}):c.jsx(Nf,{variant:"default",size:"icon",className:"uif-send",onClick:Cp,disabled:g||zv&&!Ne||!Ct.trim(),type:"button","aria-label":Ne?"Run":"Send",children:c.jsx(kg,{})})]})]}),V&&c.jsx("div",{className:"uif-modules uif-modules-right",children:V})]}),!Ce&&S&&c.jsx(Ma,{onStart:Wn}),it&&c.jsx(zy,{state:it,onChange:Ze,children:_p(it.vertical)}),Kn.dragging&&wn.createPortal(c.jsx("div",{className:"uif-bar-ghost",style:{left:Kn.dragging.x-Kn.dragging.offsetX,top:Kn.dragging.y-Kn.dragging.offsetY,width:((Pp=Sp.current)==null?void 0:Pp.offsetWidth)??200},children:"button row"}),document.body)]})};function Wy({storageKey:e,popoutUrl:t,defaultStrings:n,modules:r,outputTop:o,outputArea:i,children:s,...l}){return c.jsxs(Qf,{storageKey:e,popoutUrl:t,defaultStrings:n,modules:r,outputTop:o,outputArea:i,children:[c.jsx(By,{...l}),s]})}function Vy(){const e=h.useMemo(()=>new URLSearchParams(window.location.search),[]),t=e.get(ts)??"",n=h.useMemo(()=>_f(e.get(Pa)??"default"),[e]),[r,o]=h.useState(null),[i,s]=h.useState(!1),[l,a]=h.useState(0),[f,v]=h.useState(!1),g=h.useRef([]),m=h.useCallback(y=>{n.post(y),g.current.forEach(k=>k.state!=="closed"&&k.state!=="terminated"&&k.send(JSON.stringify(y)))},[n]);return h.useEffect(()=>{var P;const y=(P=navigator.presentation)==null?void 0:P.receiver,k=C=>M=>{const N=M;g.current.push(N),N.addEventListener("message",O=>{try{C(JSON.parse(String(O.data)))}catch{}}),N.send(JSON.stringify({type:"out:hello",id:t}))},x=n.on(C=>w(C));y==null||y.connectionList.then(C=>{C.connections.forEach(k(w)),C.addEventListener("connectionavailable",M=>k(w)(M.connection))});function w(C){if(C.type==="hub:hello")return m({type:"out:hello",id:t});!("id"in C)||C.id!==t||(C.type==="out:state"?(o(C.field),s(C.active),v(!1)):C.type==="out:home"?window.close():C.type==="out:ping"&&(a(M=>M+1),window.focus()))}m({type:"out:hello",id:t});let u="";const d=()=>{const C={x:window.screenX,y:window.screenY,width:window.outerWidth,height:window.outerHeight},M=JSON.stringify(C);M!==u&&(u=M,m({type:"out:geom",id:t,geom:C}))};d();const p=setInterval(d,500),S=setTimeout(()=>v(!0),2e3),$=()=>m({type:"out:bye",id:t});return window.addEventListener("pagehide",$),()=>{x(),clearInterval(p),clearTimeout(S),window.removeEventListener("pagehide",$),n.close()}},[n,t,m]),h.useEffect(()=>{r&&(document.title=r.title)},[r==null?void 0:r.title]),r?c.jsx("div",{className:`uif-output uif-output-window ${i?"is-active":""}`,style:{"--uif-color":r.color},children:c.jsx(Tf,{field:r,active:i,flash:l,popped:!0,onRename:y=>m({type:"out:request-rename",id:t,title:y}),onSubmit:y=>m({type:"out:input",id:t,text:y}),onRemember:y=>m({type:"out:remember",id:t,text:y}),onHome:()=>m({type:"out:request-home",id:t}),onClose:()=>m({type:"out:request-close",id:t})})}):c.jsx("div",{className:"uif-output uif-output-window",children:c.jsx("div",{className:"uif-output-empty",children:f?"The input field this output belongs to is not open.":"Connecting…"})})}const Ky="No delivery from the model: it counted no completion tokens, so there is no answer to show.",Yy="No delivery from the model: it wrote no answer text (only reasoning, or nothing), so there is no answer to show.";function Qy(e,t=typeof location<"u"?location.origin:"this page"){const n=String(e);return/\b402\b|credit|payment required/i.test(n)?"Your Hugging Face Inference Providers credits appear to be spent for this period.":/\b404\b|not supported|no provider|model not found/i.test(n)?"No live provider serves that model: choose another in the .model window (owner/name).":/127\.0\.0\.1|localhost|loopback|local network|private network|your bankML/i.test(n)?`The browser may be keeping this page from 127.0.0.1: allow it to reach apps and services on this device (the local-network permission), and start serve with --allow-origin ${t}.`:/free CPU|hf\.space|gradio|mindXhfgradio/i.test(n)?"The free CPU Space did not answer: it may be waking up or busy — ask again in a minute, or use browseML (bankML in this browser).":/credential module|not signed in/i.test(n)?"Sign in (or paste a token) in the Hugging Face tab, or use the free CPU tab.":/download|browseml|dynamically imported|sha256|quota ?exceeded/i.test(n)?'The download failed: check the connection and press "Download and verify" in the browseML tab to try again.':/failed to fetch|networkerror|load failed|network/i.test(n)?"The network request failed: check the connection and ask again.":""}function Xy(e,t){const n=e.width<640,r=n?Math.max(260,e.width-32):Math.min(760,e.width-32),o=n?132:120,i=e.height-(n?150:170),s=t?Math.min(t.bottom+12,e.height-o-8):i;return{narrow:n,width:r,height:o,x:Math.max(8,(e.width-r)/2),y:Math.max(n?8:80,Math.round(s))}}function Gy(e,t){return e?{"--uif-avatar":`url("${new URL(e,t).href.replace(/["\\\n]/g,encodeURIComponent)}")`,"--uif-avatar-display":"inline-block"}:{"--uif-avatar":"none","--uif-avatar-display":"none"}}function Jy(){const e=typeof window<"u"?window.visualViewport:null;if(!e)return()=>{};const t=()=>{const n=Math.max(0,window.innerHeight-e.height-e.offsetTop);document.documentElement.style.setProperty("--uif-kb",`${Math.round(n)}px`)};return e.addEventListener("resize",t),e.addEventListener("scroll",t),t(),()=>{e.removeEventListener("resize",t),e.removeEventListener("scroll",t)}}const Zy="bankml-creds.js",op="bankmlcreds:ready",is=()=>typeof window<"u"&&window.bankmlCreds||null;let ss=null;function qy(e=Zy,t=8e3){return is()?Promise.resolve(is()):ss||(ss=new Promise(n=>{const r=()=>{clearTimeout(o),window.removeEventListener(op,r),n(is())},o=setTimeout(r,t);window.addEventListener(op,r);const i=document.createElement("script");i.type="module",i.src=new URL(e,location.href).href,i.dataset.bankmlCreds="",i.onerror=r,i.onload=r,document.head.appendChild(i)}),ss)}const ev="Core MIT. The credential module (bankml-creds.js: Hugging Face sign-in, the token, the only code that sends it) is GPL-3.0-only, in its own file the core never imports — bankML's rule for code that holds a secret: every build that contains it must publish its source.";async function tv(e){const t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return[...new Uint8Array(t)].map(n=>n.toString(16).padStart(2,"0")).join("")}const nv=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,8,1,6,0,65,1,253,15,11]),rv=new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,1,253,15,65,1,253,15,253,133,2,11]),ip=e=>{try{return typeof WebAssembly=="object"&&WebAssembly.validate(e)}catch{return!1}};function ov(e=globalThis){var r,o;const t=e.navigator,n=e;return{wasm:typeof WebAssembly=="object",simd:ip(nv),relaxedSimd:ip(rv),isolated:!!n.crossOriginIsolated&&typeof n.SharedArrayBuffer<"u",cores:(t==null?void 0:t.hardwareConcurrency)||null,memoryGB:(t==null?void 0:t.deviceMemory)||null,speech:n.SpeechRecognition?"standard":n.webkitSpeechRecognition?"webkit":null,storage:!!((r=t==null?void 0:t.storage)!=null&&r.estimate),persist:!!((o=t==null?void 0:t.storage)!=null&&o.persist)}}const Ha=248302272,sp=2*28*8*128*2,iv=96e6,lp=e=>Ha+e*sp+iv;function sv(e,t={}){const n=[];if(!e.wasm||!e.simd)return n.push({level:"bad",text:"browseML is unavailable in this browser: it needs WebAssembly SIMD, which this browser does not have. The free CPU tab answers without it."}),n;n.push(e.isolated?{level:"ok",text:`threads: yes — this page is cross-origin isolated, so bankML can use up to ${Math.min(8,e.cores??1)} of ${e.cores??"?"} cores`}:{level:"warn",text:"threads: one — this page is not cross-origin isolated (no SharedArrayBuffer), so bankML runs on one thread: slower, same answer"}),n.push(e.relaxedSimd?{level:"ok",text:"relaxed SIMD: compiled here; bankML uses it only where it is exact (it checks when it opens), else plain SIMD"}:{level:"ok",text:"relaxed SIMD: not in this browser; bankML uses plain SIMD (exact, a little slower)"});const r=Ha;t.available!=null?n.push(t.available>=r*1.1?{level:"ok",text:`storage: ${_r(t.available)} available here for the ${_r(r)} model`}:{level:"bad",text:`storage: only ${_r(t.available)} available here; the model needs ${_r(r)}`}):e.storage||n.push({level:"warn",text:"storage: this browser does not say how much room there is; the download may fail if it is full"});const o=t.ctx??4096,i=ap(e.memoryGB),s=lp(o);return i!==null&&o>i?n.push({level:"warn",text:`memory: this ${t.phone?"phone":"device"} reports ${e.memoryGB} GB; keep the context at ${i} tokens or less (now ${o}, about ${_r(s)}, an estimate), or the browser may close the tab. Or use the free CPU tab.`}):e.memoryGB!==null&&e.memoryGB*1e9<s*2.5&&n.push({level:"warn",text:`memory: this ${t.phone?"phone":"device"} reports ${e.memoryGB} GB; browseML needs about ${_r(s)} (an estimate) — the tab may be closed by the browser. A smaller context helps, or use the free CPU tab.`}),n}const _r=e=>e>0&&e<1e5?`${(e/1e3).toFixed(1)} KB`:`${(e/1e6).toFixed(e<1e7?1:0)} MB`;function ap(e){return e==null?null:e<=2?1024:e<=4?2048:null}function lv(e){const t=(e.uaPlatform||"").toLowerCase(),n=(e.platform||"").toLowerCase(),r=(e.userAgent||"").toLowerCase();return/ipad/.test(n)||/ipad/.test(r)||n==="macintel"&&(e.maxTouchPoints??0)>1?"tablet":/iphone|ipod/.test(n)||/iphone|ipod/.test(r)?"phone":t==="android"||/android/.test(r)?e.mobile===!1||!/mobile/.test(r)&&e.mobile!==!0?"tablet":"phone":e.mobile?"phone":t==="chrome os"||t==="chromeos"||/cros/.test(r)?"chromeos":t==="windows"||/^win/.test(n)||/windows/.test(r)?"windows":t==="macos"||/^mac/.test(n)||/mac os x/.test(r)?"mac":t==="linux"||/linux/.test(n)||/linux|x11/.test(r)?(e.architecture?e.architecture==="arm":/aarch64|arm/.test(n)||/aarch64|armv/.test(r))?"linux-arm":"linux-x64":"unknown"}async function av(e=navigator){var r;const t=e.userAgentData;let n={};try{n=await((r=t==null?void 0:t.getHighEntropyValues)==null?void 0:r.call(t,["architecture","bitness"]))??{}}catch{}return{uaPlatform:t==null?void 0:t.platform,mobile:t==null?void 0:t.mobile,architecture:n.architecture,bitness:n.bitness,platform:e.platform,userAgent:e.userAgent,maxTouchPoints:e.maxTouchPoints}}const Ua={"linux-x64":"Linux on x86-64","linux-arm":"Linux on ARM",windows:"Windows",mac:"macOS",chromeos:"ChromeOS",phone:"a phone",tablet:"a tablet",unknown:"this computer"},uv=["https://pythai-bankml.static.hf.space","https://pythai-ultimate-bankml-ui.static.hf.space"];function up(e){return uv.includes(e)?["./install.sh start --space # lets bankML's Hugging Face pages reach your serve"]:["./install.sh stop # the installer started serve for this computer only","target/release/bankml serve .models/Bonsai-8B-Q1_0.gguf \\"," --fork ~/.local/share/bankml/forks/Bonsai-8B-Q1_0.gguf.FORK.json \\",` --native --listen 127.0.0.1:18093 --allow-origin ${e}`]}const cv="git clone https://github.com/cryptoAGI/bankml && cd bankml && ./install.sh";function dv(e){return["git clone https://github.com/cryptoAGI/bankml && cd bankml","cargo build --release # Rust 1.99 (rustup fetches it); bankML has no crates","python3 sAGI/models.py import bonsai-8b # 1.16 GB, its sha256 checked, the FORK.json pin written","target/release/bankml serve .models/Bonsai-8B-Q1_0.gguf \\"," --fork ~/.local/share/bankml/forks/Bonsai-8B-Q1_0.gguf.FORK.json \\",` --native --listen 127.0.0.1:18093 --allow-origin ${e}`]}function fv(e,t){const n=[cv,...up(t)];switch(e){case"linux-x64":return{platform:e,verdict:"fast",lede:"Linux on x86-64: bankML builds and runs here with its fast kernels (AVX2).",commands:n,notes:["The installer needs Rust 1.99+, Python 3.10+, git and curl, and no sudo. It downloads and verifies Bonsai-8B (1.16 GB)."],suggest:[]};case"windows":return{platform:e,verdict:"fast",lede:"Windows: bankML runs in WSL2 (Linux inside Windows), with its fast kernels.",commands:["wsl --install -d Ubuntu # in PowerShell, once; then open Ubuntu",...n],notes:["WSL2 forwards 127.0.0.1 to Windows, so this page reaches serve at 127.0.0.1:18093.","Run the commands inside the Ubuntu window, not in PowerShell."],suggest:[]};case"mac":case"linux-arm":return{platform:e,verdict:"slow",lede:`${Ua[e]}: bankML builds and runs, but without its fast kernels yet (NEON is on the 0.5.0 road): answers are slow. browseML in this browser is the easier way for now.`,commands:dv(t),notes:["./install.sh is for Linux on x86-64 (and WSL2) only: here it stops at its checks. These steps build bankML and serve with its own engine (--native), no llama.cpp needed.","You need Rust (https://rustup.rs), Python 3.10+, git and about 3 GB of disk."],suggest:["browse","space"]};case"chromeos":return{platform:e,verdict:"slow",lede:"ChromeOS: bankML runs in the Linux development environment (Crostini) when it is on; on x86-64 with its fast kernels.",commands:n,notes:["Settings → Advanced → Developers → Linux development environment, then these commands in its Terminal."],suggest:["browse"]};case"phone":case"tablet":return{platform:e,verdict:"no",lede:`On ${Ua[e]}: not yet. Use browseML (bankML in this browser) or the free CPU tab.`,commands:[],notes:[],suggest:["browse","space"]};default:return{platform:e,verdict:"slow",lede:"This browser does not say what machine it is on. On Linux x86-64 (or Windows with WSL2):",commands:n,notes:[],suggest:["browse"]}}}function pv(e,t){return[`Is it running? ${t.replace(/^https?:\/\//,"")} must answer: ./install.sh status`,'The browser asks once whether this page may reach "apps and services on this device" (local network access): allow it. If you blocked it, allow it in the site settings (the icon left of the address).',`Was serve started with --allow-origin ${e}? Without it the browser hides the answers from this page.`,"Safari keeps an https page from reaching http://127.0.0.1 (mixed content): use Chrome, Edge or Firefox for your own bankML, or browseML here."]}const mv=e=>import(e),hv="https://cdn.jsdelivr.net/npm/@gradio/client@2.7.0/+esm",Hn="Gregory-L/mindXhfgradio",gv={ternary:"ternary-bonsai-8b (CPU llama.cpp)",bonsai:"bonsai-8b (1-bit, CPU llama.cpp)"},yv={ternary:"Ternary-Bonsai-8B",bonsai:"Bonsai-8B (1-bit)"},cp=384,vv="browseml:settings",wv=[1024,2048,4096,8192],kv=[128,256,384,512,1024,2048],Ba={ctx:4096,maxTokens:cp};function dp(e,t=null){const n=e&&typeof e=="object"?e:{},r=ap(t),o=r!==null?Math.min(Ba.ctx,r):Ba.ctx,i=l=>typeof l=="number"&&Number.isInteger(l)?l:null,s=i(n.threads);return{threads:s!==null&&s>=1&&s<=64?s:null,ctx:wv.includes(i(n.ctx)??-1)?n.ctx:o,maxTokens:kv.includes(i(n.maxTokens)??-1)?n.maxTokens:Ba.maxTokens,removeAfterSession:n.removeAfterSession===!0}}function fp(){try{const e=navigator.deviceMemory;return typeof e=="number"?e:null}catch{return null}}(()=>{try{return dp(JSON.parse(localStorage.getItem(vv)||"{}"),fp())}catch{return dp({},fp())}})();const Sv="Bonsai on Hugging Face's free CPU — llama.cpp, not bankML's engine, no receipt",xv="bankML on Hugging Face's free CPU — a receipt on the answer, checked here",Wa=` — sAGI`,Ev=e=>{const t=String(e??"");return typeof DOMParser>"u"?t.replace(/<[^>]*>/g," ").replace(/&/g,"&").replace(/\s+/g," ").trim():new DOMParser().parseFromString(t.replace(/</g," <"),"text/html").body.textContent.replace(/\s+/g," ").trim()};function Va(e,t){const n=e.indexOf(Wa);if(n>=0)return{answer:e.slice(0,n),footer:e.slice(n+2).trim()};if(!t){for(let r=Math.min(e.length,Wa.length-1);r>0;r--)if(Wa.startsWith(e.slice(-r)))return{answer:e.slice(0,-r),footer:""}}return{answer:e,footer:""}}function pp(e){var n;const t=r=>{const o=e.match(r);return o?Number(o[1]):void 0};return{prompt:t(/prompt\s+(\d+)/),completion:t(/completion\s+(\d+)/),tps:t(/([\d.]+)\s*tok\/s/),seconds:t(/tok\/s in ([\d.]+)\s*s/),on:(n=(e.match(/tok\/s in [\d.]+\s*s on (.+?)(?:\s+context\b|\s+model\b|$)/)||[])[1])==null?void 0:n.trim(),first:t(/first token\s+([\d.]+)\s*s/),stopped:(e.match(/stopped on\s+(\w+)/)||[])[1]}}function mp(e,t,n="none"){const r=`${e.prompt??"?"} prompt → ${e.completion??0} completion tokens`,o=n==="ok"?"✓ receipt: the answer matches its sha256":n==="bad"?"✗ receipt: the answer does NOT match its sha256":"no receipt (not bankML)";return`delivered by the model — ${r}`+(e.tps!==void 0?` · ${e.tps} tok/s`:"")+(e.first!==void 0?` · first token ${e.first} s`:"")+` · ${t} on ${e.on||"cpu"} · free public CPU (${Hn}) · ${o}`}function hp(e){for(const t of e){let n=t;if(typeof t=="string"&&/^\s*\{/.test(t))try{n=JSON.parse(t)}catch{continue}if(!(!n||typeof n!="object")){if(n.bankml_receipt&&typeof n.bankml_receipt=="object")return n.bankml_receipt;if(typeof n.response_sha256=="string"&&typeof n.model_sha256=="string")return n}}return null}let Eo=null,Lr=null;async function Cv(e){var t;if(Lr!==null)return Lr;try{const n=await e.view_api();Lr=!!((t=n==null?void 0:n.named_endpoints)!=null&&t["/bankml"])}catch{Lr=!1}return Lr}const Nv=()=>Lr===!0;async function*jv(e,t,n,r,o="ternary",i=cp,s=()=>{}){const l=Date.now();let a=!1,f="",v=l,g=0;const m=setInterval(()=>{!a&&!f&&Date.now()-l>8e3&&(a=!0,s("the free CPU is waking up or busy: a cold Space may take minutes (it loads the model first)"));const y=Math.round((Date.now()-v)/1e3);f&&y>=30&&y-g>=15&&(g=y,s(`no word from the free CPU for ${y} s: it may be busy or the connection dropped — Stop, then ask again, or use browseML`))},1e3);try{if(!Eo){s(`connecting to the free CPU (${Hn})…`);const{Client:F}=await mv(hv);Eo=await F.connect(Hn,{events:["data","status"]})}const y=await Cv(Eo),k=t.slice(-6).map(F=>`${F.role==="user"?"Visitor":"You"}: ${F.content.slice(0,600)}`).join(` `),x=e.slice(0,3500)+(y?"":` WHERE THIS REPLY COMES FROM: you speak for bankML, but this reply is generated by Bonsai on Hugging Face's free public CPU (the Space ${Hn}, llama.cpp), not by bankML's engine: no bankML arithmetic and no receipt. If asked what is running, say so.`)+(k?` THE CONVERSATION SO FAR: ${k}`:""),w=y?Eo.submit("/bankml",{system:x,text:n,npred:Math.min(i,512)}):Eo.submit("/mindx",{system:x,text:n,where:gv[o],bz_persona:"the system box above",npred:Math.min(i,512),temp:.6,top_p:.9,rg_use:!1});let u="",d="",p=[];for await(const F of w){if(v=Date.now(),g=0,F.type==="status"){if(F.stage==="error")throw new Error(F.message||"the free CPU Space reported an error");if(F.stage==="complete")break;F.stage==="pending"&&!f&&s(`queued on the free CPU${F.position!=null?` (position ${F.position+1}${F.queue_size?` of ${F.queue_size}`:""})`:""}…`)}if(F.type==="data"){p=F.data,u=String(p[0]??""),d=Ev(p[1]),!f&&!u&&s(d?`the free CPU: ${d}`:"the free CPU is reading the prompt…");const{answer:K}=Va(u,!1);K.startsWith(f)&&K.length>f.length&&(yield K.slice(f.length),f=K)}}const{answer:S,footer:$}=Va(u,!0);S.startsWith(f)&&S.length>f.length&&(yield S.slice(f.length),f=S);const P=pp(d),C=P.completion??0,M=y?hp(p):null,N=!!M&&await tv(S)===M.response_sha256,O=y?"bankML":yv[o];r({ok:N,receipt:M,usage:{prompt_tokens:P.prompt,completion_tokens:C,finish:P.stopped},footer:$||void 0,delivery:mp(P,O,y?N?"ok":"bad":"none"),line:y?`${N?"✓":"✗"} receipt · bankML on the free CPU (${Hn}) · ${C} tokens`:`not bankML · ${O} on the free public CPU (${Hn}, llama.cpp) · ${C} tokens${P.tps?` · ${P.tps} tok/s`:""} · no receipt · free`})}finally{clearInterval(m)}}function $v({into:e,context:t}){const n=Rt();return e.current=n.outputs,t.current=n.context,null}const Ka={idle:"receipt —",ok:"✓ receipt",bad:"✗ receipt",none:"no delivery",noReceipt:"no receipt"},ls=[];function _v(e){const t=[{id:"details",label:"Delivery details",command:"details",icon:"ⓘ",builtin:!0,defaultHidden:!0,description:"details [on|off] - everything about each delivery under the answer (off: the one-line verdict; all of it is kept in .memory and the log)",run(n){const r=n.args[0]==="on"?!0:n.args[0]==="off"?!1:!Sn.get().details;Sn.set({details:r}),n.print(`delivery details under answers: ${r?"shown":"the one-line verdict only (all of it in .memory; `last` prints it)"}`)}},{id:"last",label:"Last deliveries",command:"last",aliases:["deliveries"],icon:"⏱",builtin:!0,defaultHidden:!0,description:"last [n] - how the last n answers were delivered (default 1)",run(n){const r=Math.max(1,Math.min(20,Number(n.args[0])||1)),o=ls.slice(-r);if(!o.length)return n.print("no answers yet");for(const i of o)n.print(i.details||i.line,i.ok?"out":"err")}}];return e.ping&&t.push({id:"ping",label:"Ping the engine",command:"ping",icon:"◎",builtin:!0,description:"ping [output] - time round trips to whoever answers (or flash an output)",async run(n){if(n.args[0]){const o=n.outputs.resolve(n.args[0]);o?n.outputs.ping(o):n.print(`ping: no output "${n.args[0]}"`,"err");return}const r=await e.ping();n.print(r.line,r.ok?"out":"err")}}),e.diag&&t.push({id:"diag",label:"Diagnostics",command:"diag",aliases:["sys","hw"],icon:"⚕",builtin:!0,description:"diag - this computer and the engine: cores, threads, memory, storage, speed",async run(n){const r=await e.diag();n.printSections(r.title,r.sections.map(o=>({...o,open:o.level!=="ok"})))}}),t}async function*Lv(e,t,n){let r=0,o=0,i="";try{for await(const s of e)r+=1,i+=s,o||(o=window.setTimeout(()=>{o=0,t(r)},200)),yield s}catch(s){const l=String((s==null?void 0:s.message)||s),a=Qy(l);throw new Error(a?`${l} ${a}`:l)}finally{window.clearTimeout(o),t(null)}n(i)}const Pv=(e,t)=>{var n;return(!!e.trim()||!!t.media)&&((n=t.usage)==null?void 0:n.completion_tokens)!==0};function Mv({engine:e,placeholder:t,terminalPlaceholder:n,anchor:r,modeBar:o,storageKey:i="bankml-space",persona:s,mode:l,pill:a=Ka}){const f=h.useRef(null),v=h.useRef(null),[g]=h.useState(()=>[..._v(e),...e.actions??[]]),m=h.useRef(new Map),[y,k]=h.useState(null),[x,w]=h.useState(e.status()),[u,d]=h.useState(null);h.useEffect(()=>Jy(),[]),h.useEffect(()=>{var M;(M=e.onStatus)==null||M.call(e,()=>w(e.status()));const C=setInterval(()=>w(e.status()),3e3);return()=>clearInterval(C)},[e]);const p=C=>{let M=m.current.get(C);return M||m.current.set(C,M=[]),M},[S]=h.useState(()=>Xy({width:window.innerWidth,height:window.innerHeight},r==null?void 0:r.getBoundingClientRect())),{narrow:$,width:P}=S;return c.jsx(Wy,{storageKey:$?`${i}-narrow`:i,actions:g,onSend:(C,{outputId:M,mode:N,markReply:O})=>{var Y,D;let F=null;const K=I=>{const B=f.current;B&&(F?B.update(M,F,{text:I,kind:"status",tone:"working"}):F=B.append(M,{role:"system",text:I,kind:"status",tone:"working"}))};let Q=null,V=null;const J=()=>{var ve;if(!Q||V===null)return;const I=Q,B=Pv(V,I);k({v:I,delivered:B});const G=f.current;if(!B){O({text:((ve=I.usage)==null?void 0:ve.completion_tokens)===0?Ky:Yy,undelivered:!0,silent:!0});const _e=I.usage,Ve={text:`no delivery from the model — ${(_e==null?void 0:_e.completion_tokens)!==void 0?`${_e.prompt_tokens??"?"} prompt → ${_e.completion_tokens} completion tokens`:"no answer text"}`,kind:"delivery",tone:"bad"};G&&F?G.update(M,F,Ve):G&&G.append(M,{role:"system",...Ve});return}const te=Sn.get().details&&I.details||I.line,Ae={text:te,kind:"delivery",tone:I.ok?"ok":"bad"};G&&F?G.update(M,F,Ae):G&&te&&G.append(M,{role:"system",...Ae})},X=e.ask(p(M),C,I=>{var G;ls.push(I),ls.length>50&&ls.shift();const B=f.current;B&&I.media&&B.append(M,{role:"assistant",text:I.media.caption??"",media:{kind:I.media.kind,url:I.media.url,name:I.media.name}}),I.record&&((G=v.current)==null||G.keep({...I.record,question:I.record.question??C},I.line)),Q=I,J()},(D=(Y=f.current)==null?void 0:Y.list().find(I=>I.id===M))==null?void 0:D.title,K,N==="persona"?"persona":"chat");return Lv(X,d,I=>{V=I,J()})},placeholder:t,terminalPlaceholder:n,modeBar:o,persona:s,mode:l,initialSize:{width:P,height:S.height},minWidth:$?260:300,initialPosition:{x:S.x,y:S.y},left:$?void 0:c.jsx("span",{className:"bk-uif-pill is-answerer",title:x,children:x}),right:$?void 0:u!==null?c.jsxs("span",{className:"bk-uif-pill is-answerer",title:"the answer is streaming",children:["streaming · ",u," pieces"]}):c.jsx("span",{className:"bk-uif-pill "+(y?y.delivered&&y.v.ok?"ok":y.delivered&&y.v.receipt===!1?"":"bad":""),title:(y==null?void 0:y.v.line)||"no answer yet",children:y?y.delivered?y.v.ok?a.ok:y.v.receipt===!1?a.noReceipt??Ka.noReceipt:a.bad:a.none??Ka.none:a.idle}),children:c.jsx($v,{into:f,context:v})})}function Tv(e,t,n={}){for(const[o,i]of Object.entries(Gy(n.avatar,location.href)))document.documentElement.style.setProperty(o,i);const r=ks.createRoot(e);return r.render(Lf()?c.jsx(Vy,{}):c.jsx(Mv,{engine:t,placeholder:n.placeholder||"Ask bankML",terminalPlaceholder:n.terminalPlaceholder,anchor:n.anchor,modeBar:n.modeBar,storageKey:n.storageKey,persona:n.persona,mode:n.mode,pill:n.pill})),r}return ae.FREE_SPACE=Hn,ae.KV_BYTES_PER_TOKEN=sp,ae.LICENCE_LINE=ev,ae.MODEL_BYTES=Ha,ae.PLATFORM_NAME=Ua,ae.SPACE_BANKML=xv,ae.SPACE_HONEST=Sv,ae.askSpace=jv,ae.browseVerdicts=sv,ae.creds=is,ae.findReceipt=hp,ae.installPlan=fv,ae.isOutputWindow=Lf,ae.loadCreds=qy,ae.mount=Tv,ae.parseStats=pp,ae.ramEstimate=lp,ae.readCaps=ov,ae.readHints=av,ae.recognise=lv,ae.serveLines=up,ae.spaceDelivery=mp,ae.spaceIsBankml=Nv,ae.splitFooter=Va,ae.unreachableReasons=pv,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"}),ae}({});