friend-assistant 0.1.79 → 0.1.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jarvisTree-CX2xpGQL.js","assets/jarvis-ui-DdDqAnS8.js","assets/jarvis-ui-CbruVJnv.css","assets/OrgParts-CUFZmjwg.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/jarvisTree-Ysieqypf.js","assets/jarvis-ui-DmnSOb4G.js","assets/jarvis-ui-CbruVJnv.css","assets/OrgParts-B8_VJBRh.js"])))=>i.map(i=>d[i]);
2
2
  var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,o)=>(o=n==null?{}:e(i(n)),c(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n)),u=(e=>typeof require<`u`?require:typeof Proxy<`u`?new Proxy(e,{get:(e,t)=>(typeof require<`u`?require:e)[t]}):e)(function(e){if(typeof require<`u`)return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")});(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var d=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.for(`react.view_transition`),m=Symbol.iterator;function h(e){return typeof e!=`object`||!e?null:(e=m&&e[m]||e[`@@iterator`],typeof e==`function`?e:null)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_=Object.assign,v={};function y(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}y.prototype.isReactComponent={},y.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},y.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function b(){}b.prototype=y.prototype;function x(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}var S=x.prototype=new b;S.constructor=x,_(S,y.prototype),S.isPureReactComponent=!0;var C=Array.isArray;function w(){}var T={H:null,A:null,T:null,S:null},E=Object.prototype.hasOwnProperty;function D(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function O(e,t){return D(e.type,t,e.props)}function k(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function A(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var j=/\/+/g;function ee(e,t){return typeof e==`object`&&e&&e.key!=null?A(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(w,w):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+ee(e,0):a,C(o)?(i=``,c!=null&&(i=c.replace(j,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(k(o)&&(o=O(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(j,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(C(e))for(var u=0;u<e.length;u++)a=e[u],s=l+ee(a,u),c+=N(a,r,i,s,o);else if(u=h(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+ee(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result,n=t();n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t,n.status===void 0&&(n.status=`fulfilled`,n.value=t))},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t,n.status===void 0&&(n.status=`rejected`,n.reason=t))}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var te=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function ne(e){var t=T.T,n={};n.types=t===null?null:t.types,T.T=n;try{var r=e(),i=T.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(w,te)}catch(e){te(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),T.T=t}}function re(e){var t=T.T;if(t!==null){var n=t.types;n===null?t.types=[e]:n.indexOf(e)===-1&&n.push(e)}else ne(re.bind(null,e))}var I={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!k(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=I,e.Component=y,e.Fragment=r,e.Profiler=a,e.PureComponent=x,e.StrictMode=i,e.Suspense=l,e.ViewTransition=p,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=T,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return T.H.useMemoCache(e)}},e.addTransitionType=re,e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=_({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!E.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return D(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)E.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return D(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=k,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=ne,e.unstable_useCacheRefresh=function(){return T.H.useCacheRefresh()},e.use=function(e){return T.H.use(e)},e.useActionState=function(e,t,n){return T.H.useActionState(e,t,n)},e.useCallback=function(e,t){return T.H.useCallback(e,t)},e.useContext=function(e){return T.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return T.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return T.H.useEffect(e,t)},e.useEffectEvent=function(e){return T.H.useEffectEvent(e)},e.useId=function(){return T.H.useId()},e.useImperativeHandle=function(e,t,n){return T.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return T.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return T.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return T.H.useMemo(e,t)},e.useOptimistic=function(e,t){return T.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return T.H.useReducer(e,t,n)},e.useRef=function(e){return T.H.useRef(e)},e.useState=function(e){return T.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return T.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return T.H.useTransition()},e.version=`19.3.0`})),f=o(((e,t)=>{t.exports=d()})),p=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),m=o(((e,t)=>{t.exports=p()})),h=o((e=>{var t=f();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.0`})),g=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=h()})),_=o((e=>{var t=m(),n=f(),r=g();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}function p(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&p(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function h(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function _(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function v(e){var t=[null,null],n=h(e);return n===null||y(t,e,n.child,{foundSelf:!1}),t}function y(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&y(e,t,n.child,r))return!0;n=n.sibling}return!1}function b(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var x=null,S=null;function C(e,t,n){return e===n||e===t&&(x=e,!0)}function w(e,t,n){return e===n?(S=e,!1):e===t&&(S!==null&&(x=e),!0)}function T(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function E(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var D=Object.assign,O=Symbol.for(`react.element`),k=Symbol.for(`react.transitional.element`),A=Symbol.for(`react.portal`),j=Symbol.for(`react.fragment`),ee=Symbol.for(`react.strict_mode`),M=Symbol.for(`react.profiler`),N=Symbol.for(`react.consumer`),P=Symbol.for(`react.context`),F=Symbol.for(`react.forward_ref`),te=Symbol.for(`react.suspense`),ne=Symbol.for(`react.suspense_list`),re=Symbol.for(`react.memo`),I=Symbol.for(`react.lazy`),ie=Symbol.for(`react.activity`),ae=Symbol.for(`react.legacy_hidden`),oe=Symbol.for(`react.memo_cache_sentinel`),se=Symbol.for(`react.view_transition`),ce=Symbol.for(`react.recoverable`),le=Symbol.iterator;function L(e){return typeof e!=`object`||!e?null:(e=le&&e[le]||e[`@@iterator`],typeof e==`function`?e:null)}var ue=Symbol.for(`react.client.reference`);function de(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ue?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case j:return`Fragment`;case M:return`Profiler`;case ee:return`StrictMode`;case te:return`Suspense`;case ne:return`SuspenseList`;case ie:return`Activity`;case se:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case A:return`Portal`;case P:return e.displayName||`Context`;case N:return(e._context.displayName||`Context`)+`.Consumer`;case F:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case re:return t=e.displayName||null,t===null?de(e.type)||`Memo`:t;case I:t=e._payload,e=e._init;try{return de(e(t))}catch{}}return null}var R=Array.isArray,z=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,fe={pending:!1,data:null,method:null,action:null},pe=[],me=-1;function he(e){return{current:e}}function ge(e){0>me||(e.current=pe[me],pe[me]=null,me--)}function V(e,t){me++,pe[me]=e.current,e.current=t}var _e=he(null),ve=he(null),ye=he(null),H=he(null);function be(e,t){switch(V(ye,t),V(ve,e),V(_e,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?fp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=fp(t),e=pp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ge(_e),V(_e,e)}function U(){ge(_e),ge(ve),ge(ye)}function xe(e){var t=e.memoizedState;t!==null&&(ch._currentValue=t.memoizedState,V(H,e)),t=_e.current;var n=pp(t,e.type);t!==n&&(V(ve,e),V(_e,n))}function Se(e){ve.current===e&&(ge(_e),ge(ve)),H.current===e&&(ge(H),ch._currentValue=fe)}var Ce,we;function Te(e){if(Ce===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Ce=t&&t[1]||``,we=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+Ce+e+we}var Ee=!1;function De(e,t){if(!e||Ee)return``;Ee=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -4388,7 +4388,7 @@ void main() {
4388
4388
  `,SS=class{host;core;renderer;scene=new sg;camera=new jv(-1,1,1,-1,0,1);material;geometry=new G_(2,2);raf=0;last=0;ro;disposed=!1;constructor(e,t,n){this.host=e,this.core=new tp({reducedMotion:n}),this.renderer=new pS({alpha:!0,antialias:!1}),this.renderer.setClearColor(0,0),this.renderer.domElement.style.cssText=`width:100%;height:100%;display:block`,e.appendChild(this.renderer.domElement),this.material=new ev({vertexShader:bS,fragmentShader:xS,transparent:!0,depthWrite:!1,blending:2,uniforms:{uPhase:{value:0},uAmp:{value:0},uBright:{value:.85},uNoise:{value:.05},uTighten:{value:0},uAspect:{value:1},uColor:{value:new ag(t)}}}),this.scene.add(new T_(this.geometry,this.material)),this.ro=new ResizeObserver(()=>this.resize()),this.ro.observe(e),this.resize(),this.raf=requestAnimationFrame(this.frame)}resize(){let e=Math.max(1,this.host.clientWidth),t=Math.max(1,this.host.clientHeight);this.renderer.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),this.renderer.setSize(e,t,!1),this.material.uniforms.uAspect.value=e/t}frame=e=>{if(this.disposed)return;if(this.raf=requestAnimationFrame(this.frame),document.hidden){this.last=e;return}let t=this.last?Math.min((e-this.last)/1e3,.1):.016;this.last=e,this.core.tick(t);let n=this.core.uniforms(),r=this.material.uniforms;r.uPhase.value=n.phase,r.uAmp.value=n.amplitude,r.uBright.value=n.brightness,r.uNoise.value=n.noise,r.uTighten.value=n.tighten,this.renderer.render(this.scene,this.camera)};setState(e){this.core.setState(e)}setAmplitude(e){this.core.setAmplitude(e)}setMode(e){this.resize()}setAccent(e){this.material.uniforms.uColor.value.set(e)}setIntensity(e){this.core.setIntensity(e)}dispose(){this.disposed=!0,cancelAnimationFrame(this.raf),this.ro.disconnect(),this.geometry.dispose(),this.material.dispose(),this.renderer.dispose(),this.renderer.domElement.remove()}},CS=e=>Number.isFinite(e)?e:0;function wS(e,t,n,r){let i=CS(t),a=Math.min(1,Math.max(0,CS(n))),o=Math.min(1,Math.max(0,CS(r)));return Array.from({length:Math.max(0,Math.floor(e))},(e,t)=>{let n=.12+.18*(.5+.5*Math.sin(t*.31+i*2.2))+o*(.5+.5*Math.sin(t*.9+i*4)),r=a*(.35+.65*(.5+.5*Math.sin(t*2.1+i*9)));return Math.min(1,Math.max(0,n+r))})}var TS=96,ES=class{host;core;canvas=document.createElement(`canvas`);ctx;raf=0;last=0;ro=null;disposed=!1;accent;constructor(e,t,n){this.host=e,this.core=new tp({reducedMotion:n}),this.accent=t,this.canvas.style.cssText=`width:100%;height:100%;display:block`,this.ctx=this.canvas.getContext(`2d`),e.appendChild(this.canvas),this.ctx&&(typeof ResizeObserver<`u`&&(this.ro=new ResizeObserver(()=>this.resize()),this.ro.observe(e)),this.resize(),this.raf=requestAnimationFrame(this.frame))}resize(){let e=Math.min(window.devicePixelRatio||1,2);this.canvas.width=Math.max(1,this.host.clientWidth)*e,this.canvas.height=Math.max(1,this.host.clientHeight)*e}frame=e=>{if(this.disposed||!this.ctx)return;if(this.raf=requestAnimationFrame(this.frame),document.hidden){this.last=e;return}let t=this.last?Math.min((e-this.last)/1e3,.1):.016;this.last=e,this.core.tick(t);let n=this.core.uniforms(),r=this.ctx,{width:i,height:a}=this.canvas,o=Math.min(i,a);r.clearRect(0,0,i,a);let s=o*.27*(1-n.tighten),c=o*.2,l=wS(TS,n.phase,n.amplitude,n.noise);r.save(),r.translate(i/2,a/2),r.rotate(n.angle),r.lineCap=`round`,r.strokeStyle=this.accent,r.shadowColor=this.accent,r.shadowBlur=o*.02*n.brightness,r.lineWidth=Math.max(2,o*.008);let u=this.core.state===`thinking`;for(let e=0;e<TS;e++){let t=e/TS*Math.PI*2,i=u?.25+.75*Math.abs(Math.sin((t-n.phase*2)/2)):1;r.globalAlpha=Math.min(1,(.35+l[e]*.65)*n.brightness*i);let a=o*.012+l[e]*c;r.beginPath(),r.moveTo(Math.cos(t)*s,Math.sin(t)*s),r.lineTo(Math.cos(t)*(s+a),Math.sin(t)*(s+a)),r.stroke()}r.globalAlpha=.28*n.brightness,r.shadowBlur=0,r.lineWidth=Math.max(1,o*.003),r.beginPath(),r.arc(0,0,s*.9,0,Math.PI*2),r.stroke(),r.restore()};setState(e){this.core.setState(e)}setAmplitude(e){this.core.setAmplitude(e)}setMode(e){this.resize()}setAccent(e){this.accent=e}setIntensity(e){this.core.setIntensity(e)}dispose(){this.disposed=!0,cancelAnimationFrame(this.raf),this.ro?.disconnect(),this.canvas.remove()}};function DS(e,t,n){let r=Zf({...n.env??Qf(),reducedMotion:n.reducedMotion}),i=()=>new yS(t,r||8e3,n.accent,n.reducedMotion);if(e===`ring`)return new ES(t,n.accent,n.reducedMotion);if(r===0)return i();try{return e===`orb`?new SS(t,n.accent,n.reducedMotion):new vS(t,r,n.accent,n.reducedMotion)}catch{return i()}}function OS({state:e,amplitude:t,pulse:n=0,mode:r,accent:i=`#3fd8ff`,style:a=`sphere`,intensity:o=.6,scale:s=1}){let c=(0,y.useRef)(null),l=(0,y.useRef)(null),u=(0,y.useRef)({state:e,amplitude:t,mode:r,accent:i,intensity:o});return u.current={state:e,amplitude:t,mode:r,accent:i,intensity:o},(0,y.useEffect)(()=>{let e=u.current,t=DS(a,c.current,{accent:e.accent,reducedMotion:Qf().reducedMotion});return t.setState(e.state),t.setAmplitude(e.amplitude),t.setIntensity(e.intensity),t.setMode(e.mode),l.current=t,()=>{t.dispose(),l.current=null}},[a]),(0,y.useEffect)(()=>l.current?.setState(e),[e]),(0,y.useEffect)(()=>l.current?.setAmplitude(t),[t,n]),(0,y.useEffect)(()=>l.current?.setMode(r),[r]),(0,y.useEffect)(()=>l.current?.setAccent(i),[i]),(0,y.useEffect)(()=>l.current?.setIntensity(o),[o]),(0,w.jsx)(`div`,{ref:c,"data-presence":!0,"data-mode":r,"data-style":a,"data-state":e,"data-amplitude":t.toFixed(2),className:`presence presence-${r}`,style:r===`full`&&s!==1?{transform:`scale(${s})`}:void 0,"aria-hidden":`true`})}var kS=e=>.25+Math.min(1,Math.max(0,e))/.7*.75;function AS({look:e}){let[t,n]=(0,y.useState)(.4),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(.3+Math.random()*.5),i(e=>e+1)},600);return()=>clearInterval(e)},[]);let a=kS(e.reactivity);return(0,w.jsxs)(`div`,{className:`look-preview`,"data-testid":`look-preview`,role:`img`,"aria-label":`Preview of the voice presence`,children:[e.ambient&&(0,w.jsx)(`div`,{className:`look-preview-glow`,style:{opacity:.35+.65*e.intensity,"--accent":e.accent}}),(0,w.jsx)(`div`,{className:`look-preview-stage`,style:{"--accent":e.accent},children:(0,w.jsx)(OS,{state:`speaking`,amplitude:Math.min(1,t*a),pulse:r,mode:`full`,accent:e.accent,style:e.style,intensity:e.intensity,scale:e.size})}),e.captions&&(0,w.jsx)(`p`,{className:`look-preview-caption captions-${e.captionSize}`,children:`This is how my words will look.`})]})}var jS=class extends Error{constructor(){super(`The audit area is locked. Enter your PIN.`)}},MS=e=>{let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&r!==``&&t.set(n,String(r));let n=t.toString();return n?`?${n}`:``};function NS(e=fetch){let t=null,n=async(n,r={})=>{let i;try{i=await e(n,{...r,headers:{...r.headers,...t?{"x-audit-unlock":t}:{}}})}catch{throw Error(`Could not reach Friend. Check the connection.`)}return i},r=async(e,r)=>{let i=await n(e,r),a={};try{a=await i.json()}catch{}if(i.status===403&&a.error===`locked`)throw t=null,new jS;if(!i.ok)throw Error(a.error??(i.status===401?`Please sign in again.`:`The request failed (${i.status}).`));return a};return{async unlock(e){t=(await r(`/api/audit/unlock`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({pin:e})})).token},search:e=>r(`/api/audit${MS(e)}`),tree:async e=>(await r(`/api/audit/request/${encodeURIComponent(e)}`)).tree,attention:async(e=24)=>(await r(`/api/audit/attention?hours=${e}`)).rows,verify:()=>r(`/api/audit/verify`),status:()=>r(`/api/audit/status`),async download(e,r){let i=await n(`/api/audit/export${MS({...e,format:r})}`);if(i.status===403)throw t=null,new jS;if(!i.ok)throw Error(`The export failed (${i.status}).`);let a=/filename="([^"]+)"/.exec(i.headers.get(`content-disposition`)??``)?.[1]??`friend-audit.${r}`,o=URL.createObjectURL(await i.blob()),s=document.createElement(`a`);s.href=o,s.download=a,s.click(),URL.revokeObjectURL(o)}}}var PS=[{id:`1h`,label:`Last hour`,ms:36e5},{id:`24h`,label:`Last 24 hours`,ms:864e5},{id:`7d`,label:`Last 7 days`,ms:6048e5},{id:`30d`,label:`Last 30 days`,ms:2592e6},{id:`all`,label:`Everything kept`,ms:null}],FS=[`owner`,`assistant`,`worker`,`system`,`outsider`],IS=[`approvals`,`tools`,`workers`,`logins`,`messages`,`settings`,`system`,`other`],LS=[`refused`,`failed`,`waiting`,`done`,`started`],RS=400,zS=100,BS=e=>new Date(e).toISOString().replace(`T`,` `).slice(0,19);function VS({text:e}){let[t,n]=(0,y.useState)(!1);return e.length<=RS||t?(0,w.jsx)(w.Fragment,{children:e}):(0,w.jsxs)(w.Fragment,{children:[e.slice(0,RS),`…`,` `,(0,w.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(!0),children:`show more`})]})}function HS({nodes:e}){return(0,w.jsx)(`ol`,{className:`audit-tree`,children:e.map(e=>(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`span`,{children:[`#`,e.row.id,` `,BS(e.row.ts),` `,e.row.actorKind,` `,e.row.actorId,` `,(0,w.jsx)(`b`,{children:e.row.kind}),` `,e.row.target,` `,e.row.outcome&&`[${e.row.outcome}]`]}),e.children.length>0&&(0,w.jsx)(HS,{nodes:e.children})]},e.row.id))})}function US({api:e,settings:t,onSettings:n}){let r=(0,y.useRef)(e??NS()).current,[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)({when:`24h`,who:``,actorId:``,kind:``,result:``,q:``}),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)([]),[v,b]=(0,y.useState)({total:0,refused:0,failed:0}),[S,C]=(0,y.useState)(null),[T,E]=(0,y.useState)(null),[D,O]=(0,y.useState)(null),k=(0,y.useRef)(0),A=(0,y.useCallback)(e=>e instanceof jS?(a(!1),_([]),O(null),l(null),!0):(l(e.message),!1),[]),j=(e={})=>{let t=PS.find(e=>e.id===f.when);return{...t?.ms?{from:Date.now()-t.ms}:{},...f.who?{actorKind:f.who}:{},...f.actorId?{actorId:f.actorId}:{},...f.kind?{group:f.kind}:{},...f.result?{outcome:f.result}:{},...f.q?{q:f.q}:{},limit:zS,...e}};(0,y.useEffect)(()=>{if(!i)return;let e=++k.current;(async()=>{try{if(m===`attention`){let t=await r.attention();e===k.current&&(_(t),b({total:t.length,refused:t.filter(e=>e.outcome===`refused`).length,failed:t.filter(e=>e.outcome===`failed`).length}),l(null));return}let t=await r.search(j());e===k.current&&(_(t.rows),b(t.counts),l(null))}catch(t){e===k.current&&A(t)}})()},[i,f,m,r]),(0,y.useEffect)(()=>{i&&r.status().then(C,e=>void A(e))},[i,r,A]);let ee=async()=>{if(!(u||o.length<6)){d(!0);try{await r.unlock(o),a(!0),l(null)}catch(e){l(e.message)}finally{s(``),d(!1)}}};if(!i)return(0,w.jsxs)(`div`,{className:`settings-section`,children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to open the audit log. It shows what you, your assistant and your workers did, and stays open for a few minutes.`}),c&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:c}),(0,w.jsx)(F,{pin:o,onChange:s,onSubmit:()=>void ee()}),(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u||o.length<6,onClick:()=>void ee(),children:`Open`})]});let M=e=>{h(`all`),p({...f,...e})},N=async e=>{try{O({id:e,nodes:await r.tree(e)})}catch(e){A(e)}},P=async()=>{try{let e=g.at(-1),t=await r.search(j({before:e?.id}));_([...g,...t.rows])}catch(e){A(e)}},te=async e=>{try{await r.download(j({limit:void 0}),e)}catch(e){A(e)}};return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`approval-actions`,role:`group`,"aria-label":`Quick views`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:m===`all`&&!f.actorId?`primary`:void 0,onClick:()=>(h(`all`),p({when:`24h`,who:``,actorId:``,kind:``,result:``,q:``})),children:`Today`}),(0,w.jsx)(`button`,{type:`button`,style:x,className:m===`attention`?`primary`:void 0,onClick:()=>h(`attention`),children:`Needs attention`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>M({kind:`approvals`,actorId:``,who:``}),children:`Approvals`}),(S?.workers??[]).map(e=>(0,w.jsx)(`button`,{type:`button`,style:x,className:f.actorId===e.id?`primary`:void 0,onClick:()=>M({who:`worker`,actorId:e.id,kind:``}),children:e.name},e.id))]}),(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsxs)(`label`,{children:[`When`,(0,w.jsx)(`select`,{value:f.when,onChange:e=>M({when:e.target.value}),children:PS.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.label},e.id))})]}),(0,w.jsxs)(`label`,{children:[`Who`,(0,w.jsxs)(`select`,{value:f.who,onChange:e=>M({who:e.target.value,actorId:``}),children:[(0,w.jsx)(`option`,{value:``,children:`Everyone`}),FS.map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))]})]}),(0,w.jsxs)(`label`,{children:[`Kind`,(0,w.jsxs)(`select`,{value:f.kind,onChange:e=>M({kind:e.target.value}),children:[(0,w.jsx)(`option`,{value:``,children:`All kinds`}),IS.map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))]})]}),(0,w.jsxs)(`label`,{children:[`Result`,(0,w.jsxs)(`select`,{value:f.result,onChange:e=>M({result:e.target.value}),children:[(0,w.jsx)(`option`,{value:``,children:`Any result`}),LS.map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))]})]}),(0,w.jsxs)(`label`,{children:[`Search`,(0,w.jsx)(`input`,{type:`text`,value:f.q,maxLength:200,onChange:e=>M({q:e.target.value})})]})]}),c&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:c}),(0,w.jsxs)(`p`,{className:`auth-note`,children:[v.total,` entries, `,v.refused,` refused, `,v.failed,` failed`]}),(0,w.jsxs)(`table`,{className:`usage-table audit-table`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{children:`#`}),(0,w.jsx)(`th`,{children:`Time (UTC)`}),(0,w.jsx)(`th`,{children:`Who`}),(0,w.jsx)(`th`,{children:`What`}),(0,w.jsx)(`th`,{children:`Target`}),(0,w.jsx)(`th`,{children:`Result`}),(0,w.jsx)(`th`,{children:`Details`}),(0,w.jsx)(`th`,{})]})}),(0,w.jsx)(`tbody`,{children:g.map(e=>(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`td`,{children:e.id}),(0,w.jsx)(`td`,{children:BS(e.ts)}),(0,w.jsxs)(`td`,{children:[e.actorKind,` `,e.actorId]}),(0,w.jsx)(`td`,{children:e.kind}),(0,w.jsx)(`td`,{children:(0,w.jsx)(VS,{text:e.target})}),(0,w.jsx)(`td`,{children:e.outcome}),(0,w.jsx)(`td`,{children:(0,w.jsx)(VS,{text:JSON.stringify(e.detail)})}),(0,w.jsx)(`td`,{children:e.requestId&&(0,w.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>void N(e.requestId),children:`Follow this request`})})]},e.id))})]}),m===`all`&&g.length>=zS&&(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>void P(),children:`Load more`}),D&&(0,w.jsxs)(`section`,{"aria-label":`Request ${D.id}`,className:`settings-section`,children:[(0,w.jsxs)(`h3`,{children:[`Request `,D.id]}),D.nodes.length?(0,w.jsx)(HS,{nodes:D.nodes}):(0,w.jsx)(`p`,{className:`auth-note`,children:`Nothing else was recorded for this request.`}),(0,w.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>O(null),children:`Close`})]}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>void r.verify().then(E,e=>void A(e)),children:`Verify chain`}),[`csv`,`html`,`json`].map(e=>(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>void te(e),children:e===`csv`?`CSV`:e===`html`?`Report (HTML)`:`JSON`},e))]}),T&&(0,w.jsx)(`p`,{className:T.ok?`auth-note`:`auth-error`,children:T.ok?`Chain OK (${T.rows} chained entries).`:`Chain broken at entry ${T.brokenAt} (${T.reason}). Something changed the log.`}),t&&n&&(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`Audit settings`,children:[(0,w.jsx)(`h3`,{children:`Keeping the log`}),(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsxs)(`label`,{children:[`Days kept (0 keeps everything)`,(0,w.jsx)(`input`,{type:`number`,min:0,max:3650,value:t.keepDays,onChange:e=>n({keepDays:Math.min(3650,Math.max(0,Math.round(Number(e.target.value)||0)))})})]}),(0,w.jsxs)(`label`,{children:[`Daily seal at (empty turns it off)`,(0,w.jsx)(`input`,{type:`text`,value:t.sealAt,placeholder:`09:00`,maxLength:5,onChange:e=>n({sealAt:e.target.value})})]}),(0,w.jsxs)(`label`,{children:[`Minutes open after the PIN`,(0,w.jsx)(`input`,{type:`number`,min:1,max:120,value:t.unlockMinutes,onChange:e=>n({unlockMinutes:Math.min(120,Math.max(1,Math.round(Number(e.target.value)||1)))})})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t.archive,onChange:e=>n({archive:e.target.checked})}),(0,w.jsx)(`span`,{children:`Keep a checkable archive of what is removed`})]})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Changing these needs your PIN when you save. The seal is a one-line fingerprint of the log sent to your phone once a day, so the log cannot be rewritten without you noticing.`})]}),S&&(0,w.jsxs)(`p`,{className:`auth-note`,children:[S.rows,` entries kept (`,S.keepDays?`${S.keepDays} days`:`no limit`,`). `,S.lastSeal?`Last seal: ${BS(S.lastSeal.at)} UTC.`:`No seal has been made yet.`]})]})}var WS=[{id:`off`,name:`Off`,text:`Friend never starts a conversation. It only answers, and reminds you of what you asked.`},{id:`low`,name:`Low`,text:`Friend speaks first only about what you asked for: a task that is long overdue.`},{id:`medium`,name:`Medium`,text:`Also a morning check-in and an evening check-in, and a word about anything in memory dated today or tomorrow.`},{id:`high`,name:`High`,text:`Also a gentle check-in when you have been silent for a long time, like a friend who notices.`}],GS=e=>e.trim()===``||!Number.isFinite(Number(e))?0:Math.round(Number(e));function KS({label:e,hint:t,children:n}){return(0,w.jsxs)(`label`,{className:`of-field`,children:[(0,w.jsx)(`span`,{className:`of-label`,children:e}),n,t&&(0,w.jsx)(`small`,{className:`of-hint`,children:t})]})}function qS({code:e,title:t,note:n,children:r}){return(0,w.jsxs)(`section`,{className:`of-card`,children:[(0,w.jsxs)(`header`,{className:`of-card-head`,children:[(0,w.jsx)(`span`,{className:`of-code`,children:e}),(0,w.jsx)(`h4`,{children:t})]}),n&&(0,w.jsx)(`p`,{className:`of-note`,children:n}),(0,w.jsx)(`div`,{className:`of-card-body`,children:r})]})}var JS=e=>e.dailyCap<1||e.dailyCap>20||e.minGapMin<5||e.minGapMin>720||e.silenceHours<2||e.silenceHours>72;function YS({proactive:e,onChange:t}){let n=e.level===`off`;return(0,w.jsxs)(`div`,{className:`of-tab`,"data-on":n?`false`:`true`,children:[(0,w.jsxs)(`section`,{className:`of-hero`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`of-code`,children:`FRIEND · HEARTBEAT`}),(0,w.jsx)(`h3`,{children:`Friend speaks first`}),(0,w.jsx)(`p`,{className:`of-note`,children:`Today Friend only answers. With the heartbeat on, it can start the conversation when it has something worth saying. Every minute it quietly checks for a reason (a task long overdue, the morning, the evening, a note in memory with today's date, a long silence). Only when it finds one, and your limits below allow it, does it ask the model whether to say anything, and the model can only choose words: it cannot run tools or change anything. It never cuts in while you are talking.`})]}),(0,w.jsx)(`b`,{className:`of-state`,children:n?`OFF`:e.level.toUpperCase()})]}),(0,w.jsx)(qS,{code:`01`,title:`How much`,note:`Pick how often Friend may reach out. You can change it, or turn it off, at any time.`,children:(0,w.jsx)(`div`,{className:`of-levels`,role:`radiogroup`,"aria-label":`How much Friend speaks first`,children:WS.map(n=>(0,w.jsxs)(`label`,{className:`of-level`,"data-on":e.level===n.id?`true`:`false`,children:[(0,w.jsx)(`input`,{type:`radio`,name:`hb-level`,checked:e.level===n.id,onChange:()=>t({level:n.id})}),(0,w.jsx)(`b`,{children:n.name}),(0,w.jsx)(`small`,{className:`of-hint`,children:n.text})]},n.id))})}),(0,w.jsx)(qS,{code:`02`,title:`Times`,note:`Friend does not contact you at all during quiet hours.`,children:(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsx)(KS,{label:`Quiet from`,children:(0,w.jsx)(`input`,{type:`time`,value:e.quietFrom,disabled:n,onChange:e=>e.target.value&&t({quietFrom:e.target.value})})}),(0,w.jsx)(KS,{label:`Quiet until`,children:(0,w.jsx)(`input`,{type:`time`,value:e.quietTo,disabled:n,onChange:e=>e.target.value&&t({quietTo:e.target.value})})}),(0,w.jsx)(KS,{label:`Morning check-in from`,hint:`Medium and high.`,children:(0,w.jsx)(`input`,{type:`time`,value:e.morningAt,disabled:n,onChange:e=>e.target.value&&t({morningAt:e.target.value})})}),(0,w.jsx)(KS,{label:`Evening check-in from`,hint:`Medium and high.`,children:(0,w.jsx)(`input`,{type:`time`,value:e.eveningAt,disabled:n,onChange:e=>e.target.value&&t({eveningAt:e.target.value})})})]})}),(0,w.jsx)(qS,{code:`03`,title:`Limits`,note:`So it never becomes a nuisance.`,children:(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsx)(KS,{label:`Most contacts in a day`,hint:`From 1 to 20.`,children:(0,w.jsx)(`input`,{type:`number`,min:1,max:20,value:e.dailyCap,disabled:n,onChange:e=>t({dailyCap:GS(e.target.value)})})}),(0,w.jsx)(KS,{label:`Least minutes between two`,hint:`From 5 to 720.`,children:(0,w.jsx)(`input`,{type:`number`,min:5,max:720,value:e.minGapMin,disabled:n,onChange:e=>t({minGapMin:GS(e.target.value)})})}),(0,w.jsx)(KS,{label:`Hours of silence before a check-in`,hint:`High only. From 2 to 72.`,children:(0,w.jsx)(`input`,{type:`number`,min:2,max:72,value:e.silenceHours,disabled:n||e.level!==`high`,onChange:e=>t({silenceHours:GS(e.target.value)})})})]})}),(0,w.jsxs)(qS,{code:`04`,title:`How it reaches you`,children:[(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.speak,disabled:n,onChange:e=>t({speak:e.target.checked})}),` Say it aloud as well as on the screen`,(0,w.jsx)(`small`,{className:`of-hint`,children:`Off by default, so it never startles you. It always appears on the screen when one is open.`})]}),(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.phone,disabled:n,onChange:e=>t({phone:e.target.checked})}),` When no screen is open, message my phone`,(0,w.jsx)(`small`,{className:`of-hint`,children:`Needs Telegram installed and linked (Plugins). Without it, Friend waits until a screen is open.`})]})]})]})}function XS({label:e,hint:t,children:n}){return(0,w.jsxs)(`label`,{className:`of-field`,children:[(0,w.jsx)(`span`,{className:`of-label`,children:e}),n,t&&(0,w.jsx)(`small`,{className:`of-hint`,children:t})]})}function ZS({code:e,title:t,note:n,children:r}){return(0,w.jsxs)(`section`,{className:`of-card`,children:[(0,w.jsxs)(`header`,{className:`of-card-head`,children:[(0,w.jsx)(`span`,{className:`of-code`,children:e}),(0,w.jsx)(`h4`,{children:t})]}),n&&(0,w.jsx)(`p`,{className:`of-note`,children:n}),(0,w.jsx)(`div`,{className:`of-card-body`,children:r})]})}var QS=e=>e.trim()===``||!Number.isFinite(Number(e))?0:Math.round(Number(e));function $S({memory:e,onChange:t}){return(0,w.jsxs)(`div`,{className:`of-tab`,"data-on":e.enabled?`true`:`false`,children:[(0,w.jsxs)(`section`,{className:`of-hero`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`of-code`,children:`FRIEND · MEMORY`}),(0,w.jsx)(`h3`,{children:`What Friend remembers`}),(0,w.jsxs)(`p`,{className:`of-note`,children:[`Friend keeps what it knows about you as small notes in folders it makes itself, with one index to start from. The notes are plain files in your Friend data folder (open them with any editor, or see them with `,(0,w.jsx)(`b`,{children:`friend memory list`}),` in the terminal). Only the index goes into each conversation, so memory can grow without making every answer slower or dearer. Everything in a note is data about you, never an instruction.`]})]}),(0,w.jsxs)(`label`,{className:`of-switch`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>t({enabled:e.target.checked})}),(0,w.jsx)(`span`,{className:`of-track`,"aria-hidden":`true`,children:(0,w.jsx)(`i`,{})}),(0,w.jsx)(`span`,{className:`of-switch-text`,children:`Keep memory as a tree of notes`}),(0,w.jsx)(`b`,{className:`of-state`,children:e.enabled?`ON`:`OFF`})]})]}),(0,w.jsxs)(ZS,{code:`01`,title:`Saving by itself`,note:`Friend can notice what is worth keeping while you talk, so you do not have to say 'remember this'. It never keeps passwords, PINs, keys, card numbers or codes.`,children:[(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.autoSave===`on`,disabled:!e.enabled,onChange:e=>t({autoSave:e.target.checked?`on`:`off`})}),` Save what is worth keeping, by itself`,(0,w.jsx)(`small`,{className:`of-hint`,children:`After you have been quiet for a while, one separate step reads what was said and writes short notes: facts about you, decisions, corrections, where your projects stand. Small talk is not kept. Off means Friend saves only when you ask.`})]}),(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.showSaved,disabled:!e.enabled||e.autoSave===`off`,onChange:e=>t({showSaved:e.target.checked})}),` Tell me what was remembered`,(0,w.jsx)(`small`,{className:`of-hint`,children:`A short line on the screen, for example "Remembered: family/priya.md".`})]}),(0,w.jsx)(`div`,{className:`of-grid`,children:(0,w.jsx)(XS,{label:`Wait after I stop talking (seconds)`,hint:`How long you must be quiet before it saves. From 10 to 3600.`,children:(0,w.jsx)(`input`,{type:`number`,min:10,max:3600,value:e.saveDelaySec,disabled:!e.enabled||e.autoSave===`off`,onChange:e=>t({saveDelaySec:QS(e.target.value)})})})})]}),(0,w.jsx)(ZS,{code:`02`,title:`Keeping it in order`,note:`Quick notes land in an inbox. Friend can file them into topic folders (family, work, projects and so on), give them short titles, link notes that belong together and merge duplicates, so memory reads like a small wiki.`,children:(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.autoTidy,disabled:!e.enabled,onChange:e=>t({autoTidy:e.target.checked})}),` Tidy notes into topics, by itself`,(0,w.jsx)(`small`,{className:`of-hint`,children:`When a few notes have collected, and after Friend starts. You can also say "tidy my memory" at any time.`})]})}),(0,w.jsx)(ZS,{code:`03`,title:`What it sees every turn`,note:`Friend always sees the top of the memory index and opens a folder only when a question needs it.`,children:(0,w.jsx)(`div`,{className:`of-grid`,children:(0,w.jsx)(XS,{label:`Index size (characters)`,hint:`The most of the index put in every conversation. A bigger index shows more of your memory at once but costs more each turn. From 400 to 6000.`,children:(0,w.jsx)(`input`,{type:`number`,min:400,max:6e3,step:100,value:e.maxIndexChars,disabled:!e.enabled,onChange:e=>t({maxIndexChars:QS(e.target.value)})})})})})]})}var eC=5,tC=40,nC=e=>e.split(`
4389
4389
  `).map(e=>e.trim()).filter(Boolean),rC=e=>{try{return new RegExp(e,`i`),!0}catch{return!1}},iC=(e,t,n,r)=>ed.test(n)?r.includes(n)?`${e} ${t} has the same id as an earlier one (${n}).`:null:`${e} ${t}: the id must be lowercase letters, digits or dashes, up to 24 characters, starting with a letter or digit.`;function aC(e,t){let n=e[t],r=[iC(`Project`,t+1,n.id,e.slice(0,t).map(e=>e.id))];return n.name.trim()||r.push(`Project ${t+1} needs a name.`),n.folder.trim()||r.push(`Project ${t+1} needs a folder.`),n.extraFolders.length>eC&&r.push(`Project ${t+1} can have at most ${eC} extra folders.`),r.filter(e=>!!e)}function oC(e){return e.flatMap((e,t)=>rC(e)?[]:[`Line ${t+1}: ${e} is not a valid pattern.`])}function sC(e){return[...e.projects.flatMap((t,n)=>aC(e.projects,n)),...oC(e.policy.denyCommands),...e.policy.allowTools.length>tC?[`At most ${tC} tools can be let through.`]:[],...e.policy.denyCommands.length>tC?[`At most ${tC} command patterns can be refused.`]:[]]}function cC({label:e,hint:t,children:n,wide:r=!1}){return(0,w.jsxs)(`label`,{className:`of-field${r?` of-wide`:``}`,children:[(0,w.jsx)(`span`,{className:`of-label`,children:e}),n,t&&(0,w.jsx)(`small`,{className:`of-hint`,children:t})]})}function lC({value:e,onChange:t,label:n,rows:r}){let[i,a]=(0,y.useState)(e.join(`
4390
4390
  `));return(0,y.useEffect)(()=>{a(t=>JSON.stringify(nC(t))===JSON.stringify(e)?t:e.join(`
4391
- `))},[e]),(0,w.jsx)(`textarea`,{rows:r,spellCheck:!1,...n?{"aria-label":n}:{},value:i,onChange:e=>{a(e.target.value),t(nC(e.target.value))}})}var uC=({list:e})=>(0,w.jsx)(w.Fragment,{children:e.map(e=>(0,w.jsx)(`p`,{className:`of-problem`,"data-problem":``,children:e},e))});function dC({code:e,title:t,note:n,children:r}){return(0,w.jsxs)(`section`,{className:`of-card`,children:[(0,w.jsxs)(`header`,{className:`of-card-head`,children:[(0,w.jsx)(`span`,{className:`of-code`,children:e}),(0,w.jsx)(`h4`,{children:t})]}),n&&(0,w.jsx)(`p`,{className:`of-note`,children:n}),(0,w.jsx)(`div`,{className:`of-card-body`,children:r})]})}var fC=[{id:`low`,name:`Low`,text:`Friend asks you for every request a worker makes that is not on your let-through list.`},{id:`medium`,name:`Medium`,text:`Friend answers the ordinary requests itself. Anything that looks dangerous (deleting files, installing, force pushes) still asks you, with your PIN.`},{id:`judge`,name:`Your assistant decides`,text:`Friend weighs each request like a careful senior engineer: it allows what the ticket needs and refuses what could harm, and the feed shows its reason. If it cannot decide, you are asked. The refusals below still hold.`},{id:`hybrid`,name:`Quick check, then your assistant`,text:`Cheaper than letting her answer everything. A quick separate check allows the clearly fine requests (it costs almost nothing); anything dangerous, refused or unsure goes to your assistant herself, who answers with all she knows. A request repeated for the same ticket gets the same answer. If she cannot answer, you are asked.`},{id:`self`,name:`Your assistant, herself`,text:`Your assistant answers each request in her own conversation, with all she knows about you and your projects. A worker waits until she answers; if she is busy it waits for her to be free, and nothing is skipped. If she cannot answer after the tries below, you are asked.`},{id:`high`,name:`High`,text:`Friend answers every request itself, even dangerous ones, so you are not asked. The refusals below still hold.`}],pC=e=>String(e).padStart(2,`0`);function mC({office:e,onChange:t}){let n=(n,r)=>t({projects:e.projects.map((e,t)=>t===n?{...e,...r}:e)}),r=e=>e.trim()===``||!Number.isFinite(Number(e))?0:Number(e),i=e.policy.denyCommands;return(0,w.jsxs)(`div`,{className:`of-tab`,"data-on":e.enabled?`true`:`false`,children:[(0,w.jsxs)(`section`,{className:`of-hero`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`of-code`,children:`FRIEND · OFFICE`}),(0,w.jsx)(`h3`,{children:`Hired workers`}),(0,w.jsx)(`p`,{className:`of-note`,children:`Friend can hire workers: separate Claude Code sessions that work in your project folders, one ticket at a time. Workers use the Claude Code program and model chosen under Model, and their risky steps ask you first, unless you let Friend decide (How much Friend decides, below). Switched off, no worker runs. On the orbital screen, hired workers take the place of the quick-launch buttons. Friend hires and manages the team himself: he decides the jobs, the instructions and who reports to whom. To see who is hired, click the name in the middle of the orbital screen.`})]}),(0,w.jsxs)(`label`,{className:`of-switch`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>t({enabled:e.target.checked})}),(0,w.jsx)(`span`,{className:`of-track`,"aria-hidden":`true`,children:(0,w.jsx)(`i`,{})}),(0,w.jsx)(`span`,{className:`of-switch-text`,children:`Turn the Office on`}),(0,w.jsx)(`b`,{className:`of-state`,children:e.enabled?`ONLINE`:`OFFLINE`})]})]}),(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.notifyFriend,onChange:e=>t({notifyFriend:e.target.checked})}),` Tell Friend when a worker finishes`,(0,w.jsx)(`small`,{className:`of-hint`,children:`Friend is told when a ticket is done or stuck, says so, and can review it and give the next ticket, so the work keeps moving. Switch it off and he only knows what you ask him.`})]}),(0,w.jsx)(dC,{code:`00`,title:`How much Friend decides`,note:`When a worker asks to do something (run a command, write a file), who answers. Friend always refuses what is outside the project folders, what changes the files that control a worker, and the commands you list under Rules.`,children:(0,w.jsx)(`div`,{className:`of-levels`,role:`radiogroup`,"aria-label":`How much Friend decides`,children:fC.map(n=>(0,w.jsxs)(`label`,{className:`of-level`,"data-on":e.autonomy===n.id?`true`:`false`,children:[(0,w.jsx)(`input`,{type:`radio`,name:`of-autonomy`,checked:e.autonomy===n.id,onChange:()=>t({autonomy:n.id})}),(0,w.jsx)(`b`,{children:n.name}),(0,w.jsx)(`small`,{className:`of-hint`,children:n.text})]},n.id))})}),(0,w.jsx)(dC,{code:`01`,title:`Limits`,note:`How many workers run, how long they may take to start, and when they stop.`,children:(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsx)(cC,{label:`Most workers at once`,hint:`The others wait their turn. From 1 to 8.`,children:(0,w.jsx)(`input`,{type:`number`,min:1,max:8,value:e.maxConcurrent,onChange:e=>t({maxConcurrent:r(e.target.value)})})}),(0,w.jsx)(cC,{label:`Start timeout (seconds)`,hint:`How long a worker may take to start before it is given up on. From 10 to 600.`,children:(0,w.jsx)(`input`,{type:`number`,min:10,max:600,value:e.startTimeoutSec,onChange:e=>t({startTimeoutSec:r(e.target.value)})})}),(0,w.jsx)(cC,{label:`Times the assistant is asked`,hint:`With 'Your assistant, herself': how many times she is asked about one request before you are asked instead. From 1 to 10.`,children:(0,w.jsx)(`input`,{type:`number`,min:1,max:10,value:e.decideTries,onChange:e=>t({decideTries:Math.min(10,Math.max(1,r(e.target.value)))})})}),(0,w.jsx)(cC,{label:`Pause at (% of the five-hour window)`,hint:`When your Claude subscription window is this full, workers wait until it resets. 0 means never pause.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:100,value:Math.round(e.pauseAtWindow*100),onChange:e=>t({pauseAtWindow:Math.min(100,Math.max(0,r(e.target.value)))/100})})}),(0,w.jsx)(cC,{label:`Limit per worker (tokens)`,hint:`A worker stops when it has used this many. 0 means no limit.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,step:1e3,value:e.budget.perWorkerTokens,onChange:n=>t({budget:{...e.budget,perWorkerTokens:r(n.target.value)}})})}),(0,w.jsx)(cC,{label:`Limit in total (tokens)`,hint:`All workers together. 0 means no limit.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,step:1e3,value:e.budget.totalTokens,onChange:n=>t({budget:{...e.budget,totalTokens:r(n.target.value)}})})})]})}),(0,w.jsxs)(dC,{code:`02`,title:`Projects`,note:`A project is a folder workers may work in. A worker never goes outside it and its extra folders.`,children:[e.projects.map((r,i)=>(0,w.jsxs)(`fieldset`,{className:`of-item`,children:[(0,w.jsxs)(`legend`,{children:[(0,w.jsxs)(`span`,{className:`of-code`,children:[`PROJECT `,pC(i+1)]}),` `,r.name||r.id||`new`]}),(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsx)(cC,{label:`Id`,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} id`,value:r.id,maxLength:24,onChange:e=>n(i,{id:e.target.value})})}),(0,w.jsx)(cC,{label:`Name`,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} name`,value:r.name,maxLength:60,onChange:e=>n(i,{name:e.target.value})})})]}),(0,w.jsx)(cC,{label:`Folder`,wide:!0,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} folder`,value:r.folder,maxLength:260,onChange:e=>n(i,{folder:e.target.value})})}),(0,w.jsx)(cC,{label:`Goal`,hint:`One line workers are told about this project.`,wide:!0,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} goal`,value:r.goal,maxLength:500,onChange:e=>n(i,{goal:e.target.value})})}),(0,w.jsx)(cC,{label:`Extra folders (one per line)`,hint:`Up to five more folders workers may read and change.`,wide:!0,children:(0,w.jsx)(lC,{label:`Project ${i+1} extra folders`,rows:2,value:r.extraFolders,onChange:e=>n(i,{extraFolders:e})})}),(0,w.jsx)(uC,{list:aC(e.projects,i)}),(0,w.jsx)(`button`,{type:`button`,className:`of-remove`,"aria-label":`Remove project ${i+1}`,onClick:()=>t({projects:e.projects.filter((e,t)=>t!==i)}),children:`Remove`})]},i)),(0,w.jsx)(`button`,{type:`button`,className:`of-add`,onClick:()=>t({projects:[...e.projects,{id:``,name:``,folder:``,goal:``,extraFolders:[]}]}),children:`+ Add a project`})]}),(0,w.jsxs)(dC,{code:`03`,title:`Rules`,note:`What the gate does with a worker's request, before it ever reaches you.`,children:[(0,w.jsx)(cC,{label:`Let through without asking (one tool name per line)`,hint:`Claude Code tools a worker may use inside its folders without asking you, such as Read. Anything else asks.`,wide:!0,children:(0,w.jsx)(lC,{rows:4,value:e.policy.allowTools,onChange:n=>t({policy:{...e.policy,allowTools:n}})})}),(0,w.jsx)(cC,{label:`Always refuse (one pattern per line)`,hint:`Commands that match one of these are refused, even if you would say yes. Each line is a regular expression, matched without regard to capital letters.`,wide:!0,children:(0,w.jsx)(lC,{rows:4,value:i,onChange:n=>t({policy:{...e.policy,denyCommands:n}})})}),(0,w.jsx)(uC,{list:oC(i)})]})]})}var hC=async e=>{let t;try{t=await fetch(`/api/account/secret`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}catch{throw Error(`Could not reach Friend. Check the connection.`)}let n={};try{n=await t.json()}catch{}if(!t.ok){let e=typeof n.triesLeft==`number`&&n.triesLeft>0?` ${n.triesLeft} ${n.triesLeft===1?`try`:`tries`} left.`:``;throw Error((n.error??(t.status===401?`Please sign in again.`:`The request failed (${t.status}).`))+e)}return{signedOutOthers:!!n.signedOutOthers}};function gC({change:e=hC}){let[t,n]=(0,y.useState)(``),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),_=r!==``||a!==``,v=s!==``||l!==``,b=async()=>{if(m(null),g(null),!t)return m(`Type your current password.`);if(!_&&!v)return m(`Type a new password or a new PIN.`);if(_&&r.length<8)return m(`The new password must be at least 8 characters.`);if(_&&r!==a)return m(`The two new passwords are not the same.`);if(v&&!/^\d{6,}$/.test(s))return m(`The new PIN must be at least 6 digits.`);if(v&&s!==l)return m(`The two new PINs are not the same.`);f(!0);try{let a=await e({current:t,..._?{newPassword:r}:{},...v?{newPin:s}:{}});g([_&&`Password changed.`,v&&`PIN changed.`,_&&a.signedOutOthers&&`Other browsers and phones were signed out.`].filter(Boolean).join(` `)),n(``),i(``),o(``),c(``),u(``)}catch(e){m(e.message),n(``)}finally{f(!1)}};return(0,w.jsxs)(`form`,{className:`settings-section`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,w.jsx)(`h3`,{children:`Password and PIN`}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Change either one or both. Your current password is always needed. Forgot it? On this PC run: friend password`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Current password`}),(0,w.jsx)(`input`,{type:`password`,autoComplete:`current-password`,value:t,disabled:d,onChange:e=>n(e.target.value),style:x})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New password`}),(0,w.jsx)(`input`,{type:`password`,autoComplete:`new-password`,value:r,disabled:d,onChange:e=>i(e.target.value),style:x})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New password again`}),(0,w.jsx)(`input`,{type:`password`,autoComplete:`new-password`,value:a,disabled:d,onChange:e=>o(e.target.value),style:x})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New PIN`}),(0,w.jsx)(`input`,{type:`password`,inputMode:`numeric`,autoComplete:`off`,value:s,disabled:d,onChange:e=>c(e.target.value.replace(/\D/g,``)),style:x})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`The PIN is at least 6 digits. It is asked before risky actions.`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New PIN again`}),(0,w.jsx)(`input`,{type:`password`,inputMode:`numeric`,autoComplete:`off`,value:l,disabled:d,onChange:e=>u(e.target.value.replace(/\D/g,``)),style:x})]}),p&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:p}),h&&(0,w.jsx)(`p`,{role:`status`,className:`auth-note`,children:h}),(0,w.jsx)(`button`,{type:`submit`,className:`primary`,style:x,disabled:d,children:d?`Saving…`:`Change`})]})}var _C=[{id:`read`,label:`Read only`,note:`Friend can look at your portfolio, funds, positions and orders, and send you reports. It cannot place, change or cancel any order. This is the only level in this version.`,locked:!1},{id:`orders`,label:`Orders with my confirmation (later version)`,note:`Friend would prepare an order and wait for you to confirm it with your PIN.`,locked:!0},{id:`limits`,label:`Orders within limits (later version)`,note:`Friend would place small orders on its own, inside limits you set.`,locked:!0}];function vC({level:e=`read`}){return(0,w.jsxs)(`div`,{className:`settings-section`,role:`radiogroup`,"aria-label":`What Friend may do with money`,children:[(0,w.jsx)(`h3`,{children:`What may Friend do with your trading account?`}),_C.map(t=>(0,w.jsxs)(`label`,{className:`settings-check`,style:{alignItems:`flex-start`,opacity:t.locked?.55:1},children:[(0,w.jsx)(`input`,{type:`radio`,name:`trading`,value:t.id,checked:!t.locked&&e===t.id,disabled:t.locked,readOnly:!0,onChange:()=>{}}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:t.label}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:t.note})]})]},t.id)),(0,w.jsx)(`small`,{className:`auth-note`,children:`The assistant can never change this, even with your PIN. Orders will only arrive in a later version, with their own safeguards.`})]})}var yC=async()=>{let e=await fetch(`/api/music/host/check`,{cache:`no-store`});if(!e.ok)throw Error(e.status===401?`Please sign in again.`:`The request failed (${e.status}).`);return await e.json()},bC=[`system`,`voice`,`network`,`feed`,`radar`,`tickets`,`approval`],xC={system:`System (processor and memory)`,voice:`Voice (sound bars)`,network:`Network`,feed:`Activity feed`,radar:`Devices (radar)`,tickets:`Tickets`,budget:`Budget`,approval:`Approvals`,usage:`Usage ring`},SC={url:`Open an address`,prompt:`Ask the assistant`,panel:`Open a panel`,music:`Control the music`},CC=e=>e===`panel`?Nu[0]:e===`music`?Pu[0]:``;function wC({music:e,hud:t,onMusic:n,onHud:r,checkHost:i=yC}){let[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),l=()=>{c(!0),o(null),i().then(e=>o(e.found?`mpv ${e.version} found (${e.path}).`:e.install)).catch(e=>o(e.message)).finally(()=>c(!1))},u=t.tidy??{dockAfterSeconds:40,maxChips:null,autoTidy:!0},d=t.launcher,f=(e,t)=>r({launcher:d.map((n,r)=>r===e?{...n,...t}:n)}),p=(e,t)=>{let n=e+t;if(n<0||n>=d.length)return;let i=[...d];[i[e],i[n]]=[i[n],i[e]],r({launcher:i})};return(0,w.jsxs)(`div`,{className:`settings-section`,children:[(0,w.jsx)(`h3`,{children:`Music player`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Music folder`}),(0,w.jsx)(`input`,{type:`text`,value:e.folder,placeholder:`C:\\Users\\you\\Music`,onChange:e=>n({folder:e.target.value})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`A folder on the PC that runs Friend. Its sub-folders are searched too. Saving checks that it exists.`})]}),(0,w.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`File types to look for`}),ju.map(t=>(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.extensions.includes(t),onChange:r=>{let i=r.target.checked?[...e.extensions,t]:e.extensions.filter(e=>e!==t);i.length&&n({extensions:ju.filter(e=>i.includes(e))})}}),(0,w.jsx)(`span`,{children:t})]},t))]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsxs)(`span`,{children:[`Start volume (`,e.volume,`%)`]}),(0,w.jsx)(`input`,{type:`range`,min:Mu.volume.min,max:Mu.volume.max,value:e.volume,onChange:e=>n({volume:Number(e.target.value)})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Repeat`}),(0,w.jsxs)(`select`,{value:e.repeat,onChange:e=>n({repeat:e.target.value}),children:[(0,w.jsx)(`option`,{value:`off`,children:`Off`}),(0,w.jsx)(`option`,{value:`all`,children:`The whole list`}),(0,w.jsx)(`option`,{value:`one`,children:`One track`})]})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Starts as`}),(0,w.jsxs)(`select`,{value:e.startView,onChange:e=>n({startView:e.target.value}),children:[(0,w.jsx)(`option`,{value:`mini`,children:`Small player`}),(0,w.jsx)(`option`,{value:`full`,children:`Big player with the playlist`})]})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.shuffle,onChange:e=>n({shuffle:e.target.checked})}),(0,w.jsx)(`span`,{children:`Shuffle`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.visualizer,onChange:e=>n({visualizer:e.target.checked})}),(0,w.jsx)(`span`,{children:`Moving bars around the dial`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Where music comes from, when the assistant is not told`}),(0,w.jsxs)(`select`,{value:e.defaultSource,onChange:e=>n({defaultSource:e.target.value}),children:[(0,w.jsx)(`option`,{value:`local`,children:`The music folder`}),(0,w.jsx)(`option`,{value:`spotify`,children:`Spotify`}),(0,w.jsx)(`option`,{value:`soundcloud`,children:`SoundCloud`}),(0,w.jsx)(`option`,{value:`audius`,children:`Audius`}),(0,w.jsx)(`option`,{value:`any`,children:`All`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Spotify, SoundCloud and Audius are added from Plugins. Playing from Spotify needs Spotify Premium on your account.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Most results from a service such as Spotify`}),(0,w.jsx)(`input`,{type:`number`,min:Mu.searchLimit.min,max:Mu.searchLimit.max,value:e.searchLimit,onChange:e=>n({searchLimit:Number(e.target.value)})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Where the sound comes out`}),(0,w.jsxs)(`select`,{value:e.output,onChange:e=>n({output:e.target.value}),children:[(0,w.jsx)(`option`,{value:`screen`,children:`The screen (the browser plays it)`}),(0,w.jsx)(`option`,{value:`host`,children:`This PC's speakers (no browser needed)`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`The PC's speakers play your folder's music through mpv, a free player you install once. Spotify plays on a Spotify device you name below.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Program that plays the folder's music on the PC (empty: find mpv automatically)`}),(0,w.jsx)(`input`,{type:`text`,value:e.hostPlayer,maxLength:260,placeholder:`mpv`,onChange:e=>n({hostPlayer:e.target.value})}),Lu(e.hostPlayer.trim())&&(0,w.jsx)(`small`,{role:`alert`,className:`auth-error`,children:Lu(e.hostPlayer.trim())})]}),(0,w.jsxs)(`div`,{className:`settings-field`,children:[(0,w.jsx)(`button`,{type:`button`,disabled:s,onClick:l,children:`Check mpv`}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Looks for mpv with the saved program setting, or automatically when it is empty.`}),a&&(0,w.jsx)(`small`,{role:`status`,className:`auth-note`,children:a})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Spotify device on the PC to play on`}),(0,w.jsx)(`input`,{type:`text`,value:e.spotifyDevice,maxLength:100,placeholder:`the name Spotify shows for that device`,onChange:e=>n({spotifyDevice:e.target.value})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Most tracks to list`}),(0,w.jsx)(`input`,{type:`number`,min:Mu.maxTracks.min,max:Mu.maxTracks.max,value:e.maxTracks,onChange:e=>n({maxTracks:Number(e.target.value)})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`How many folders deep to search`}),(0,w.jsx)(`input`,{type:`number`,min:Mu.scanDepth.min,max:Mu.scanDepth.max,value:e.scanDepth,onChange:e=>n({scanDepth:Number(e.target.value)})})]}),(0,w.jsx)(`h3`,{children:`Screen layout`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Screen layout`}),(0,w.jsxs)(`select`,{value:t.layout,onChange:e=>r({layout:e.target.value}),children:[(0,w.jsx)(`option`,{value:`classic`,children:`Classic (the orb with floating cards)`}),(0,w.jsx)(`option`,{value:`orbital`,children:`Orbital (a heads-up display around the orb)`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Orbital draws rings, an orbit of your quick-launch buttons and live instruments around the orb. Classic is the screen you know.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Density`}),(0,w.jsxs)(`select`,{value:t.density,disabled:t.layout!==`orbital`,onChange:e=>r({density:e.target.value}),children:[(0,w.jsx)(`option`,{value:`calm`,children:`Calm (the orb, the orbit and the message bar)`}),(0,w.jsx)(`option`,{value:`standard`,children:`Standard (the orb, the orbit, the budget ring and the usage line)`}),(0,w.jsx)(`option`,{value:`full`,children:`Full (the same, plus anything added later)`})]})]}),(0,w.jsxs)(`fieldset`,{className:`settings-field`,disabled:t.layout!==`orbital`,children:[(0,w.jsx)(`legend`,{children:`Instruments`}),Bu.map(e=>(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,"data-testid":`hud-widget-${e}`,disabled:t.layout!==`orbital`,checked:bC.includes(e)?t.widgets[e]===!0:t.widgets[e]!==!1,onChange:n=>r({widgets:{...t.widgets,[e]:n.target.checked}})}),(0,w.jsx)(`span`,{children:xC[e]})]},e)),(0,w.jsx)(`small`,{className:`auth-note`,children:`The live instruments (system, voice, network, activity, devices, tickets) and the approvals box are not on the screen until Friend brings them up (ask it, for example "show my system"); it puts them away when you ask or clear the screen. Tick one to keep it on the screen always. A box you switch off stays off. A waiting approval is always shown.`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,"data-testid":`hud-preview`,disabled:t.layout!==`orbital`,checked:t.preview===!0,onChange:e=>r({preview:e.target.checked})}),(0,w.jsx)(`span`,{children:`Show sample data (workers, tickets, budget and feed filled in, labelled SAMPLE, to preview the look)`})]}),(0,w.jsx)(`h3`,{children:`Screen tidy`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:u.autoTidy,onChange:e=>r({tidy:{...u,autoTidy:e.target.checked}})}),(0,w.jsx)(`span`,{children:`Tidy the screen by itself (put finished cards away as small chips)`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Put cards away after (seconds, 0 keeps them)`}),(0,w.jsx)(`input`,{type:`number`,min:0,max:3600,value:u.dockAfterSeconds,disabled:!u.autoTidy,onChange:e=>r({tidy:{...u,dockAfterSeconds:Number(e.target.value)}})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`A card is never put away before there was time to read it. A chip comes back as a card when you tap it.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Most chips in the strip`}),(0,w.jsxs)(`select`,{value:u.maxChips===null?`auto`:String(u.maxChips),onChange:e=>r({tidy:{...u,maxChips:e.target.value===`auto`?null:Number(e.target.value)}}),children:[(0,w.jsx)(`option`,{value:`auto`,children:`By screen (desktop 7, tablet and phone 5)`}),[3,4,5,6,7,8,10,12].map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))]})]}),(0,w.jsx)(`h3`,{children:`Screen widgets`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Name on the profile tag`}),(0,w.jsx)(`input`,{type:`text`,maxLength:24,value:t.terminalLabel,onChange:e=>r({terminalLabel:e.target.value})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Animations`}),(0,w.jsxs)(`select`,{value:t.animations,onChange:e=>r({animations:e.target.value}),children:[(0,w.jsx)(`option`,{value:`full`,children:`Full`}),(0,w.jsx)(`option`,{value:`reduced`,children:`Reduced (only answers to hover and press)`}),(0,w.jsx)(`option`,{value:`off`,children:`Off`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`If the device is set to reduce motion, the screen stays still whatever this says.`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t.clock.hour12,onChange:e=>r({clock:{...t.clock,hour12:e.target.checked}})}),(0,w.jsx)(`span`,{children:`12-hour clock`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t.clock.seconds,onChange:e=>r({clock:{...t.clock,seconds:e.target.checked}})}),(0,w.jsx)(`span`,{children:`Show seconds`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Date language (empty: the device's own)`}),(0,w.jsx)(`input`,{type:`text`,value:t.clock.locale,maxLength:35,placeholder:`en-GB`,onChange:e=>r({clock:{...t.clock,locale:e.target.value}})})]}),(0,w.jsx)(`h3`,{children:`Quick-launch buttons`}),d.length===0&&(0,w.jsx)(`small`,{className:`auth-note`,children:`No buttons yet.`}),d.map((e,t)=>{let n=Iu(e);return(0,w.jsxs)(`div`,{className:`settings-field`,role:`group`,"aria-label":`Button ${t+1}`,children:[(0,w.jsxs)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`},children:[(0,w.jsx)(`input`,{type:`text`,"aria-label":`Icon`,style:{width:56},value:e.icon,onChange:e=>f(t,{icon:e.target.value})}),(0,w.jsx)(`input`,{type:`text`,"aria-label":`Label`,maxLength:24,style:{flex:1,minWidth:100},value:e.label,onChange:e=>f(t,{label:e.target.value})}),(0,w.jsx)(`select`,{"aria-label":`What it does`,value:e.action.type,onChange:e=>{let n=e.target.value;f(t,{action:{type:n,value:CC(n)}})},children:Object.keys(SC).map(e=>(0,w.jsx)(`option`,{value:e,children:SC[e]},e))})]}),(0,w.jsxs)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`},children:[e.action.type===`panel`||e.action.type===`music`?(0,w.jsx)(`select`,{"aria-label":`Which`,style:{flex:1},value:e.action.value,onChange:n=>f(t,{action:{...e.action,value:n.target.value}}),children:(e.action.type===`panel`?Nu:Pu).map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))}):(0,w.jsx)(`input`,{type:`text`,"aria-label":e.action.type===`url`?`Address`:`Question`,style:{flex:1},value:e.action.value,placeholder:e.action.type===`url`?`https://…`:`What should it ask?`,onChange:n=>f(t,{action:{...e.action,value:n.target.value}})}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Move up`,disabled:t===0,onClick:()=>p(t,-1),children:`↑`}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Move down`,disabled:t===d.length-1,onClick:()=>p(t,1),children:`↓`}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Remove button`,onClick:()=>r({launcher:d.filter((e,n)=>n!==t)}),children:`Remove`})]}),n&&(0,w.jsx)(`small`,{role:`alert`,className:`auth-error`,children:n})]},e.id??t)}),(0,w.jsxs)(`button`,{type:`button`,disabled:d.length>=12,onClick:()=>r({launcher:[...d,{label:`New`,icon:`+`,action:{type:`panel`,value:`chat`}}]}),children:[`Add a button (`,d.length,`/`,12,`)`]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`The assistant can never change the music folder, these buttons or the animations, even with your PIN.`})]})}var TC=[`#3fd8ff`,`#2b7bff`,`#a066ff`,`#ff6fae`,`#ff5a5a`,`#ff9b3d`,`#ffd23d`,`#3dff8c`,`#e8f4ff`],EC=[{id:`sphere`,name:`Sphere`,note:`A cloud of particles`},{id:`orb`,name:`Orb`,note:`A glowing plasma ball`},{id:`ring`,name:`Ring`,note:`Radial bars, like a voice meter`}],DC=(e,t)=>e.style===t.style&&e.accent.toLowerCase()===t.accent&&Math.abs(e.intensity-t.intensity)<.005;async function OC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:`The request failed (${n.status}).`));return r}var kC={summary:e=>OC(`/api/usage?days=${e}`),clear:()=>OC(`/api/usage`,{method:`DELETE`})},AC=[7,30,90],jC=e=>e.toLocaleString(`en-US`);function MC(e){return e>=1e6?`${+(e/1e6).toFixed(1)}M`:e>=1e3?`${+(e/1e3).toFixed(1)}K`:String(e)}var NC={voice:`Voice`,chat:`Chat`,task:`Scheduled tasks`,channel:`Messages (WhatsApp, Telegram…)`,other:`Other`};function PC({api:e=kC}){let[t,n]=(0,y.useState)(7),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),d=(0,y.useRef)(!0),f=(0,y.useCallback)(async t=>{try{let n=await e.summary(t);d.current&&(i(n),o(null))}catch(e){d.current&&o(e.message)}},[e]);(0,y.useEffect)(()=>(d.current=!0,f(t),()=>{d.current=!1}),[f,t]);let p=async()=>{try{let n=await e.clear();if(!d.current)return;c(`Removed ${n.removed} saved counts.`),u(!1),await f(t)}catch(e){d.current&&o(e.message)}},m=r?Math.max(1,...r.days.map(e=>e.input+e.output)):1,h=!!r&&r.total.turns===0;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`approval-actions`,role:`group`,"aria-label":`How far back`,children:AC.map(e=>(0,w.jsxs)(`button`,{type:`button`,style:x,className:t===e?`primary`:void 0,"aria-pressed":t===e,onClick:()=>n(e),children:[e,` days`]},e))}),a&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:a}),r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`usage-totals`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`strong`,{children:MC(r.total.input)}),(0,w.jsx)(`span`,{children:`Sent to the model`})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`strong`,{children:MC(r.total.output)}),(0,w.jsx)(`span`,{children:`Written back`})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`strong`,{children:r.total.turns}),(0,w.jsx)(`span`,{children:`Answers`})]})]}),h?(0,w.jsx)(`p`,{className:`auth-note`,children:`Nothing counted yet. Once Friend has answered, the tokens it used show up here.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`usage-bars`,"aria-hidden":!1,children:r.days.map(e=>{let t=e.input+e.output;return(0,w.jsxs)(`div`,{className:`usage-bar-col`,children:[(0,w.jsx)(`div`,{role:`img`,"aria-label":`${e.day}: ${jC(t)} tokens on ${e.turns} answers`,className:`usage-bar`,style:{height:`${Math.max(t>0?4:1,Math.round(t/m*100))}%`},title:`${e.day}: ${jC(t)} tokens`}),r.days.length<=31&&(0,w.jsx)(`span`,{className:`usage-bar-day`,children:e.day.slice(8)})]},e.day)})}),(0,w.jsxs)(`table`,{className:`usage-table`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{scope:`col`,children:`Day`}),(0,w.jsx)(`th`,{scope:`col`,children:`Sent`}),(0,w.jsx)(`th`,{scope:`col`,children:`Written`}),(0,w.jsx)(`th`,{scope:`col`,children:`Answers`})]})}),(0,w.jsx)(`tbody`,{children:[...r.days].reverse().map(e=>(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{scope:`row`,children:e.day}),(0,w.jsx)(`td`,{children:jC(e.input)}),(0,w.jsx)(`td`,{children:jC(e.output)}),(0,w.jsx)(`td`,{children:e.turns})]},e.day))})]}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`By model`}),(0,w.jsx)(`ul`,{className:`usage-list`,children:r.byModel.map(e=>(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`span`,{children:[e.provider,` / `,e.model]}),(0,w.jsxs)(`span`,{children:[MC(e.input+e.output),` tokens · `,e.turns,` answers`]})]},`${e.provider}/${e.model}`))}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`By where it came from`}),(0,w.jsx)(`ul`,{className:`usage-list`,children:r.bySource.map(e=>(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`span`,{children:NC[e.source]??e.source}),(0,w.jsxs)(`span`,{children:[MC(e.input+e.output),` tokens · `,e.turns,` answers`]})]},e.source))})]})]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Friend keeps counts only: the day, the model, and how many tokens. Never what was said. Counts older than a year are removed by themselves.`}),s&&(0,w.jsx)(`p`,{className:`auth-note`,children:s}),(0,w.jsx)(`div`,{className:`approval-actions`,children:l?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,onClick:()=>void p(),children:`Yes, clear them`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>u(!1),children:`Keep them`})]}):(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>u(!0),children:`Clear saved counts`})})]})}async function FC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var IC=e=>({method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),LC={info:()=>FC(`/api/conversation`),compact:()=>FC(`/api/conversation/compact`,IC({})),clear:e=>FC(`/api/conversation/clear`,IC({pin:e}))},RC=[5e4,1e5,2e5,4e5,8e5];function zC({api:e=LC,autoCompact:t,limit:n,onChange:r}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=(0,y.useRef)(!0),_=(0,y.useCallback)(async()=>{try{let t=await e.info();g.current&&a(t)}catch(e){g.current&&p(e.message)}},[e]);(0,y.useEffect)(()=>(g.current=!0,_(),()=>{g.current=!1}),[_]);let v=async e=>{d(!0),p(null),h(null);try{let t=await e();if(!g.current)return;t.ok?h(t.message):p(t.message),s(!1),await _()}catch(e){g.current&&p(e.message)}finally{g.current&&(d(!1),l(``))}};if(o)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to start fresh. Friend keeps its notes and memory, but forgets the earlier conversation.`}),(0,w.jsx)(F,{pin:c,onChange:l,onSubmit:()=>!u&&c.length>=6&&void v(()=>e.clear(c))}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u||c.length<6,onClick:()=>void v(()=>e.clear(c)),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{s(!1),l(``),p(null)},children:`Back`})]})]});let b=RC.includes(n)?RC:[...RC,n].sort((e,t)=>e-t);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Conversation memory`}),i&&!i.supported?(0,w.jsx)(`p`,{className:`auth-note`,children:`This model does not keep a conversation of its own: Friend sends it the recent messages each time, so there is nothing to tidy.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:i?`Claude is holding about ${MC(i.contextTokens)} tokens of conversation${i.contextTokens===0?` (it counts again after the next answer)`:``}. It reads all of it for every answer, so a long one uses a lot of your plan.`:`Checking…`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>r({autoCompact:e.target.checked})}),` Tidy up by itself`]}),(0,w.jsxs)(`label`,{className:`settings-check`,style:{marginTop:6},children:[`When it grows past`,` `,(0,w.jsx)(`select`,{value:n,onChange:e=>r({compactAtTokens:Number(e.target.value)}),disabled:!t,children:b.map(e=>(0,w.jsxs)(`option`,{value:e,children:[MC(e),` tokens`]},e))})]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Tidying up writes short notes on what you were doing and starts a fresh conversation from them, before the next answer. Friend keeps its saved notes either way.`}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,disabled:u||!i,onClick:()=>void v(()=>e.compact()),children:`Tidy up now`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:u||!i,onClick:()=>s(!0),children:`Start fresh`})]})]}),m&&(0,w.jsx)(`p`,{className:`auth-note`,children:m}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f})]})}async function BC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var VC=e=>({method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),HC={list:()=>BC(`/api/people`),remove:async(e,t)=>void await BC(`/api/people/remove`,VC({id:e,pin:t})),forgetAll:async e=>void await BC(`/api/people/forget`,VC({pin:e}))};function UC({api:e=HC}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=(0,y.useRef)(!0),f=(0,y.useCallback)(async()=>{try{let t=await e.list();d.current&&n(t)}catch(e){d.current&&u(e.message)}},[e]);(0,y.useEffect)(()=>(d.current=!0,f(),()=>{d.current=!1}),[f]);let p=async()=>{if(!(!r||s||a.length<6)){c(!0),u(null);try{if(r.kind===`one`?await e.remove(r.person.id,a):await e.forgetAll(a),!d.current)return;i(null),await f()}catch(e){d.current&&u(e.message)}finally{d.current&&(c(!1),o(``))}}};return r?(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`Forget people`,children:[(0,w.jsx)(`p`,{className:`auth-note`,children:r.kind===`one`?`Enter your PIN to forget ${r.person.name}. Their saved face numbers and the notes about them are deleted.`:`Enter your PIN to forget everyone. All saved face numbers and the notes about them are deleted.`}),(0,w.jsx)(F,{pin:a,onChange:o,onSubmit:()=>void p()}),l&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:l}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:s||a.length<6,onClick:()=>void p(),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{i(null),o(``),u(null)},children:`Back`})]})]}):(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`People Friend remembers`,children:[(0,w.jsx)(`h3`,{children:`People Friend remembers`}),t&&t.length===0&&(0,w.jsx)(`p`,{className:`auth-note`,children:`Friend does not remember anyone yet. Say "this is Priya, my sister" while she is in front of the camera and Friend asks for your PIN.`}),t?.map(e=>(0,w.jsxs)(`div`,{className:`settings-check`,style:{justifyContent:`space-between`},children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.name}),e.relation?` (${e.relation})`:``,!e.usable&&(0,w.jsx)(`small`,{className:`auth-note`,children:` Their saved face cannot be read any more: introduce them again.`})]}),(0,w.jsx)(`button`,{type:`button`,style:x,"aria-label":`Remove ${e.name}`,onClick:()=>i({kind:`one`,person:e}),children:`Remove`})]},e.id)),t&&t.length>0&&(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>i({kind:`all`}),children:`Forget everyone`})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Face data is sensitive personal data. Introduce only people who know and agree, and not children. Friend keeps 128 numbers about a face, encrypted on this PC, never the picture, and never uses a face to approve anything.`}),l&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:l})]})}var WC=[{id:`duckduckgo`,label:`DuckDuckGo (free, no key)`},{id:`brave`,label:`Brave Search (your key)`},{id:`tavily`,label:`Tavily (your key)`},{id:`searxng`,label:`SearXNG (your own server)`}];function GC({label:e,hint:t,children:n}){return(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:e}),n,t&&(0,w.jsx)(`small`,{className:`auth-note`,children:t})]})}function KC({web:e,saved:t,braveKey:n,tavilyKey:r,onChange:i,onBraveKey:a,onTavilyKey:o}){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Searching the web`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>i({enabled:e.target.checked})}),` Let Friend search the web`]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Gives every model web.search (a list of results) and web.read (the text of one page), for prices, news and anything else that changes. They run on this PC with no browser. Friend will never take orders from a page, and it will not open addresses on this PC or your network.`}),(0,w.jsx)(GC,{label:`Search source`,children:(0,w.jsx)(`select`,{value:e.provider,disabled:!e.enabled,onChange:e=>i({provider:e.target.value}),children:WC.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),e.provider===`brave`&&(0,w.jsx)(GC,{label:`Brave key`,hint:t.braveKeySet?`A key is saved. Type a new one only to replace it.`:`From your Brave Search API account.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:t.braveKeySet?`saved`:``,value:n,onChange:e=>a(e.target.value)})}),e.provider===`tavily`&&(0,w.jsx)(GC,{label:`Tavily key`,hint:t.tavilyKeySet?`A key is saved. Type a new one only to replace it.`:`From your Tavily account.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:t.tavilyKeySet?`saved`:``,value:r,onChange:e=>o(e.target.value)})}),e.provider===`searxng`&&(0,w.jsx)(GC,{label:`SearXNG address`,hint:`For example http://localhost:8080. It must allow the JSON format.`,children:(0,w.jsx)(`input`,{value:e.searxngUrl,onChange:e=>i({searxngUrl:e.target.value})})}),e.provider!==`duckduckgo`&&(0,w.jsx)(`p`,{className:`auth-note`,children:`If this source cannot answer, Friend tries DuckDuckGo once and says so.`})]})}async function qC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var JC=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),YC={get:()=>qC(`/api/soul`),save:(e,t)=>qC(`/api/soul`,JC(`PUT`,{text:e,pin:t})),restore:(e,t)=>qC(`/api/soul/restore`,JC(`POST`,{to:e,pin:t}))};function XC({api:e=YC}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(!0),g=(0,y.useCallback)(async()=>{try{let t=await e.get();if(!h.current)return;n(t),i(t.text)}catch(e){h.current&&f(e.message)}},[e]);(0,y.useEffect)(()=>(h.current=!0,g(),()=>{h.current=!1}),[g]);let _=async()=>{if(a){u(!0),f(null);try{let t=a.kind===`save`?await e.save(r,s):await e.restore(a.to,s);if(!h.current)return;n(t),i(t.text),m(a.kind===`save`?`Saved. The assistant uses it from its next reply.`:a.to==="default"?`Back to the default soul.`:`Back to the earlier soul.`),o(null)}catch(e){h.current&&f(e.message)}finally{h.current&&(u(!1),c(``))}}};if(a)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:a.kind===`save`?`Enter your PIN to change who the assistant is.`:a.to==="default"?`Enter your PIN to put the original default soul back.`:`Enter your PIN to bring back the earlier soul.`}),(0,w.jsx)(F,{pin:s,onChange:c,onSubmit:()=>!l&&s.length>=6&&void _()}),d&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:d}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:l||s.length<6,onClick:()=>void _(),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{o(null),c(``),f(null)},children:`Back`})]})]});let v=t?.max??3e3,b=!!t&&r.trim()!==t.text.trim();return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Soul`}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Who your assistant is: its purpose, character, manner, gender and how it speaks to you. It is read on every request and kept in memory as soul.md. You can change it here, or just tell the assistant ("be more direct", "you are my study coach"). Its safety rules and your approvals are not part of it and cannot be loosened by it.`}),(0,w.jsx)(`textarea`,{"aria-label":`Soul`,className:`soul-text`,rows:16,value:r,maxLength:v,onChange:e=>i(e.target.value),style:{width:`100%`,fontFamily:`inherit`}}),(0,w.jsxs)(`p`,{className:`auth-note`,children:[r.length,` of `,v,` characters`,t?.isDefault?`. This is the default soul.`:`.`]}),p&&(0,w.jsx)(`p`,{role:`status`,children:p}),d&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:d}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:l||!b||!r.trim(),onClick:()=>o({kind:`save`}),children:`Save soul`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:l||!b,onClick:()=>i(t?.text??``),children:`Undo my edits`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:l||!t||t.versions.length===0,onClick:()=>o({kind:`restore`,to:`previous`}),children:`Bring back the earlier soul`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:l||!t||t.isDefault,onClick:()=>o({kind:`restore`,to:`default`}),children:`Reset to default`})]})]})}async function ZC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var QC=e=>({method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),$C={info:()=>ZC(`/api/system`),check:()=>ZC(`/api/system/update/check`,QC({})),update:e=>ZC(`/api/system/update/apply`,QC({pin:e})),setAutostart:(e,t)=>ZC(`/api/system/autostart`,QC({enabled:e,pin:t}))},ew=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function tw({api:e=$C,auto:t,onAuto:n,pollMs:r=0}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=(0,y.useRef)(!0),_=(0,y.useCallback)(async()=>{try{let t=await e.info();g.current&&a(t)}catch(e){g.current&&p(e.message)}},[e]);(0,y.useEffect)(()=>{g.current=!0,_();let e=r>0?setInterval(()=>void _(),r):null;return()=>{g.current=!1,e&&clearInterval(e)}},[_,r]);let v=async()=>{if(o){d(!0),p(null);try{let t=o.kind===`autostart`?await e.setAutostart(o.enabled,c):await e.update(c);if(!g.current)return;h(t.message),s(null),await _()}catch(e){g.current&&p(e.message)}finally{g.current&&(d(!1),l(``))}}},b=async()=>{d(!0),p(null),h(null);try{let t=await e.check();g.current&&a(e=>e&&{...e,update:t})}catch(e){g.current&&p(e.message)}finally{g.current&&d(!1)}};if(o)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:o.kind===`update`?`Enter your PIN to update Friend now. It restarts in a moment.`:o.enabled?`Enter your PIN to start Friend by itself when this computer starts.`:`Enter your PIN to stop starting Friend with this computer.`}),(0,w.jsx)(F,{pin:c,onChange:l,onSubmit:()=>!u&&c.length>=6&&void v()}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u||c.length<6,onClick:()=>void v(),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{s(null),l(``),p(null)},children:`Back`})]})]});let S=i?.update;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Start with the computer`}),i&&(i.autostart.supported?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:i.autostart.enabled?`Friend starts by itself when you sign in to this computer, so you never have to start it after a restart.`:`Friend does not start by itself yet: after a restart you start it yourself.`}),(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,className:i.autostart.enabled?void 0:`primary`,disabled:u,onClick:()=>s({kind:`autostart`,enabled:!i.autostart.enabled}),children:i.autostart.enabled?`Stop starting Friend with this computer`:`Start Friend when this computer starts`})})]}):(0,w.jsx)(`p`,{className:`auth-note`,children:`Starting Friend by itself is not supported on this computer.`})),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Updates`}),i&&S&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`auth-note`,children:[`Friend `,i.version,`.`,` `,S.applying?`Updating Friend to ${S.latest??`the newest version`}…`:S.available?`Friend ${S.latest} is available.`:S.latest?`Up to date.`:`Not checked yet.`,S.checkedAt?` (looked at ${ew(S.checkedAt)})`:``]}),S.error&&(0,w.jsx)(`p`,{className:`auth-error`,children:S.error}),S.available&&!S.canApply&&!S.applying&&(0,w.jsx)(`p`,{className:`auth-note`,children:`This Friend is running in a terminal, so it cannot restart itself. Close it and run: friend upgrade`}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,disabled:u||S.applying,onClick:()=>void b(),children:`Check for updates`}),S.available&&S.canApply&&!S.applying&&(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u,onClick:()=>s({kind:`update`}),children:`Update now`})]})]}),(0,w.jsxs)(`label`,{className:`settings-check`,style:{marginTop:10},children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked)}),` Update Friend by itself`]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Looks for a newer Friend when it starts, then every few hours, and installs it while Friend is not busy. Switch it off to update only when you press Update now (or run friend upgrade).`}),m&&(0,w.jsx)(`p`,{className:`auth-note`,children:m}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f})]})}var nw=[{id:`manual`,label:`Ask me (manual)`,note:`Friend asks before anything that changes your PC or leaves the safe zone. The most careful.`},{id:`edits`,label:`Auto-approve file work (edits)`,note:`Reading and writing files, and the sandboxed code runner, go ahead without asking. Commands still ask.`},{id:`auto`,label:`Auto-approve everything safe (auto)`,note:`Commands, files and tools go ahead without asking. The most convenient, and the most trust: Friend acts on its own.`}],rw=[{id:`auto`,label:`Automatic`,note:`Uses Docker when it is installed and running, otherwise the sandbox built into Friend. Nothing to install.`},{id:`sandbox`,label:`Built-in sandbox`,note:`Always the sandbox that comes with Friend: JavaScript, Python (standard library) and a basic shell, with no network and no access to your files.`},{id:`docker`,label:`Docker`,note:`Always a Docker container (needs Docker installed and running). A real shell and any program the container image has.`}],iw=[{id:`claude-code`,label:`Claude subscription (Claude Code)`,note:`Uses the Claude Code app you are signed in to. No API key.`},{id:`claude`,label:`Claude API key`,note:`Pay per use with an Anthropic API key.`},{id:`ollama`,label:`Local model (Ollama)`,note:`Runs on this PC. Free and private, but slower.`},{id:`openai`,label:`OpenAI-compatible server (OmniRoute, LM Studio…)`,note:`Any server that speaks the OpenAI chat API. OmniRoute is one address that routes to many models, many of them free.`}],aw={"voice.enabled":`Speech on/off`};function ow({label:e,children:t,hint:n}){return(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:e}),t,n&&(0,w.jsx)(`small`,{className:`auth-note`,children:n})]})}function sw({api:e=Wd,onClose:t,initialTab:n=`model`,preview:r=Gd,variant:i=`classic`}){let[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(n),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,S]=(0,y.useState)(!1),[C,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,ee]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,te]=(0,y.useState)(null),ne=(0,y.useRef)(!0);(0,y.useEffect)(()=>(ne.current=!0,e.get().then(e=>{ne.current&&(o(e),c(structuredClone(e)))}).catch(e=>ne.current&&k(e.message)),()=>{ne.current=!1}),[e]);let re=(e,n=!1,r={})=>i===`holo`?(0,w.jsx)(j,{label:`Settings`,title:r.title??ze.find(e=>e.id===l)?.label??`Settings`,page:r.page,help:r.help,onApply:r.onApply,onUndo:r.onUndo,dirty:r.dirty,busy:E,onDone:t,children:e}):(0,w.jsxs)(`div`,{className:`approval settings glass${n?` settings-wide`:``}`,role:`dialog`,"aria-label":`Settings`,style:{pointerEvents:`auto`},children:[(0,w.jsx)(`div`,{className:`approval-head`,children:(0,w.jsx)(`span`,{className:`approval-title`,children:`Settings`})}),e]});if(!s||!a)return re((0,w.jsxs)(w.Fragment,{children:[O?(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O}):(0,w.jsx)(`p`,{className:`auth-note`,children:`Loading…`}),(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,onClick:t,children:`Close`})})]}));let I=Kd(a,s,d,p,{brave:h,tavily:_}),ie=Object.keys(I).length>0,ae=s.memory,oe=ae?ae.saveDelaySec<10||ae.saveDelaySec>3600||ae.maxIndexChars<400||ae.maxIndexChars>6e3:!1,se=s.proactive?JS(s.proactive):!1,ce=s.office?sC(s.office).length>0:!1,le=(e,t,n)=>c({...s,[e]:{...s[e],[t]:n}}),L=s.look,ue=(e,t)=>{t&&(N(e),te(e===`main`?null:`The first time, the voice downloads (about 64 MB). Please wait…`),r(t).then(()=>ne.current&&te(`Playing…`)).catch(e=>ne.current&&te(e.message)).finally(()=>ne.current&&N(null)))},de=async t=>{k(null),D(!0);try{let n=await e.save(I,t);if(!ne.current)return;o(n.settings),c(structuredClone(n.settings)),f(``),m(``),g(``),v(``),S(!1);let r=I.voice&&I.voice.ttsVoice!==void 0,i=I.voice&&I.voice.sttModel!==void 0;ee(n.restart.length?`Saved. Restart Friend for: ${n.restart.map(e=>aw[e]??e).join(`, `)}.`:i?`Saved. The listening model is being downloaded in the background (the first time only); Friend keeps listening with the old one and tells you when the new one is ready.`:r?`Saved. The new voice is loading; you will get a message when it is ready (the first time it downloads about 60 MB).`:Hd(I)?`Saved. It is in use now.`:`Saved. Every open screen has changed.`)}catch(e){ne.current&&k(e.message)}finally{ne.current&&(D(!1),T(``))}};if(b)return re((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to save these changes.`}),(0,w.jsx)(F,{pin:C,onChange:T,onSubmit:()=>!E&&void de(C)}),O&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:E||C.length<6,onClick:()=>void de(C),children:`Save`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{S(!1),T(``),k(null)},children:`Back`})]})]}));let R=iw.find(e=>e.id===s.provider),z=e=>{let t=ze.findIndex(e=>e.id===l),n=e.key===`ArrowDown`||e.key===`ArrowRight`?(t+1)%ze.length:e.key===`ArrowUp`||e.key===`ArrowLeft`?(t+ze.length-1)%ze.length:e.key===`Home`?0:e.key===`End`?ze.length-1:-1;n<0||(e.preventDefault(),u(ze[n].id),document.getElementById(`settings-tab-${ze[n].id}`)?.focus())},B=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Where Friend thinks`}),(0,w.jsx)(ow,{label:`Model provider`,hint:R.note,children:(0,w.jsx)(`select`,{value:s.provider,onChange:e=>c({...s,provider:e.target.value}),children:iw.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),s.provider===`claude-code`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(ow,{label:`Claude model`,hint:`sonnet, haiku, opus, or a full model name`,children:[(0,w.jsx)(`input`,{list:`cc-models`,value:s.claudeCode.model,onChange:e=>le(`claudeCode`,`model`,e.target.value)}),(0,w.jsxs)(`datalist`,{id:`cc-models`,children:[(0,w.jsx)(`option`,{value:`sonnet`}),(0,w.jsx)(`option`,{value:`haiku`}),(0,w.jsx)(`option`,{value:`opus`})]})]}),(0,w.jsx)(ow,{label:`If Claude is unavailable`,hint:`For example when the plan's usage limit is reached.`,children:(0,w.jsxs)(`select`,{value:s.claudeCode.fallback,onChange:e=>le(`claudeCode`,`fallback`,e.target.value),children:[(0,w.jsx)(`option`,{value:`ollama`,children:`Answer with the local model (Ollama)`}),(0,w.jsx)(`option`,{value:`none`,children:`Show an error`})]})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.claudeCode.webSearch??!0,onChange:e=>le(`claudeCode`,`webSearch`,e.target.checked)}),` Let Claude search the web`]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`For prices, news and anything else that changes: Claude looks it up instead of answering from memory. Only searching, never opening pages on this PC.`}),(0,w.jsx)(ow,{label:`Claude Code command`,hint:`Leave as it is unless the program is somewhere else.`,children:(0,w.jsx)(`input`,{value:s.claudeCode.command,onChange:e=>le(`claudeCode`,`command`,e.target.value)})}),(0,w.jsx)(zC,{autoCompact:s.session?.autoCompact??!0,limit:s.session?.compactAtTokens??1e5,onChange:e=>c({...s,session:{autoCompact:!0,compactAtTokens:1e5,...s.session,...e}})})]}),s.provider===`claude`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(ow,{label:`Claude model`,children:(0,w.jsx)(`input`,{value:s.model,onChange:e=>c({...s,model:e.target.value})})}),(0,w.jsx)(ow,{label:`API key`,hint:a.apiKeySet?`A key is saved. Type a new one only to replace it.`:`No key saved yet.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:a.apiKeySet?`saved`:`sk-ant-…`,value:d,onChange:e=>f(e.target.value)})})]}),s.provider===`openai`&&s.openai&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(ow,{label:`Server address`,hint:`Ends in /v1. OmniRoute: http://localhost:20128/v1 (install it with npm install -g omniroute, then run omniroute).`,children:(0,w.jsx)(`input`,{value:s.openai.url,onChange:e=>c({...s,openai:{...s.openai,url:e.target.value}})})}),(0,w.jsx)(ow,{label:`Model`,hint:`The name that server knows. OmniRoute answers to auto.`,children:(0,w.jsx)(`input`,{value:s.openai.model,onChange:e=>c({...s,openai:{...s.openai,model:e.target.value}})})}),(0,w.jsx)(ow,{label:`API key`,hint:a.openai?.apiKeySet?`A key is saved. Type a new one only to replace it.`:`Leave empty if the server asks for none.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:a.openai?.apiKeySet?`saved`:``,value:p,onChange:e=>m(e.target.value)})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.openai.vision,onChange:e=>c({...s,openai:{...s.openai,vision:e.target.checked}})}),` This model can look at pictures`]})]}),(s.provider===`ollama`||s.provider===`claude-code`&&s.claudeCode.fallback===`ollama`)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Local model (Ollama)`}),(0,w.jsx)(ow,{label:`Address`,children:(0,w.jsx)(`input`,{value:s.ollama.url,onChange:e=>le(`ollama`,`url`,e.target.value)})}),(0,w.jsx)(ow,{label:`Model`,children:(0,w.jsx)(`input`,{value:s.ollama.model,onChange:e=>le(`ollama`,`model`,e.target.value)})}),(0,w.jsx)(ow,{label:`Memory window (tokens)`,children:(0,w.jsx)(`input`,{type:`number`,min:1024,max:131072,step:1024,value:s.ollama.contextTokens,onChange:e=>le(`ollama`,`contextTokens`,Number(e.target.value))})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.ollama.vision,onChange:e=>le(`ollama`,`vision`,e.target.checked)}),` This model can look at pictures`]})]}),s.web&&a.web&&(0,w.jsx)(KC,{web:s.web,saved:a.web,braveKey:h,tavilyKey:_,onChange:e=>c({...s,web:{...s.web,...e}}),onBraveKey:g,onTavilyKey:v})]}),fe=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Speaking and listening`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.voice.speakTyped,onChange:e=>le(`voice`,`speakTyped`,e.target.checked)}),` Also speak the replies to typed messages`]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.voice.duck??!0,onChange:e=>le(`voice`,`duck`,e.target.checked)}),` Turn music and video down while I talk and while Friend speaks`]}),(0,w.jsx)(ow,{label:`Volume while talking: ${s.voice.duckPercent??25}%`,hint:`How loud music and video are then, compared with how loud you have them. They come back as they were when nothing is happening.`,children:(0,w.jsx)(`input`,{type:`range`,min:0,max:100,step:5,value:s.voice.duckPercent??25,disabled:s.voice.duck===!1,onChange:e=>le(`voice`,`duckPercent`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`Spoken language`,hint:`Leave empty to detect it by itself: best when you mix English, Hindi and Marathi. Or force one: en, hi, mr.`,children:(0,w.jsx)(`input`,{value:s.voice.language??``,maxLength:10,onChange:e=>le(`voice`,`language`,e.target.value.trim()===``?null:e.target.value.trim())})}),(0,w.jsx)(ow,{label:`Speaking voice`,hint:`Female or male. The first time a voice is used it downloads about 60 MB, then it works without internet.`,children:(0,w.jsxs)(`select`,{value:s.voice.ttsVoice,onChange:e=>le(`voice`,`ttsVoice`,e.target.value),children:[(0,w.jsx)(`optgroup`,{label:`Female`,children:Ku.filter(e=>e.gender===`female`).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,w.jsx)(`optgroup`,{label:`Male`,children:Ku.filter(e=>e.gender===`male`).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,w.jsx)(`optgroup`,{label:`Original`,children:(0,w.jsxs)(`option`,{value:Yu.id,children:[Yu.name,` · `,Yu.accent,` · `,Yu.note]})}),!Xu(s.voice.ttsVoice)&&(0,w.jsx)(`optgroup`,{label:`Other`,children:(0,w.jsx)(`option`,{value:s.voice.ttsVoice,children:s.voice.ttsVoice})})]})}),(0,w.jsx)(ow,{label:`Hindi voice`,hint:`Reads Hindi (Devanagari) text; English words in the same sentence still use the voice above. The first time it downloads about 64 MB.`,children:(0,w.jsxs)(`select`,{value:s.voice.hindiVoice??``,onChange:e=>le(`voice`,`hindiVoice`,e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Same as the voice above`}),qu.map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.gender,e.note?` · ${e.note}`:``]},e.id))]})}),(0,w.jsx)(ow,{label:`Marathi voice`,hint:`Reads Marathi text. Friend tells Marathi from Hindi by the words used.`,children:(0,w.jsxs)(`select`,{value:s.voice.marathiVoice??``,onChange:e=>le(`voice`,`marathiVoice`,e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Same as the voice above`}),Ju.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,w.jsxs)(`div`,{className:`voice-hear`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,disabled:M!==null,onClick:()=>ue(`main`,s.voice.ttsVoice),children:M===`main`?`Loading the voice…`:`Hear it`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:M!==null||!s.voice.hindiVoice,onClick:()=>ue(`hindi`,s.voice.hindiVoice??``),children:M===`hindi`?`Loading the voice…`:`Hear the Hindi voice`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:M!==null||!s.voice.marathiVoice,onClick:()=>ue(`marathi`,s.voice.marathiVoice??``),children:M===`marathi`?`Loading the voice…`:`Hear the Marathi voice`}),P&&(0,w.jsx)(`small`,{className:`auth-note`,role:`status`,children:P})]}),(0,w.jsx)(ow,{label:`Listening model`,hint:`Bigger hears more accurately, from further away and in Hindi and Marathi, but is slower. It downloads once, in the background, and Friend keeps listening meanwhile. No restart.`,children:(0,w.jsxs)(`select`,{value:s.voice.sttModel,onChange:e=>le(`voice`,`sttModel`,e.target.value),children:[!Zu.some(e=>e.id===s.voice.sttModel)&&(0,w.jsx)(`option`,{value:s.voice.sttModel,children:s.voice.sttModel}),Zu.map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,Qu(e.mb).replace(`about `,``),` · `,e.note]},e.id))]})}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Who is speaking`}),(0,w.jsx)(ow,{label:`"It is me" match level: ${s.voice.accept.toFixed(2)}`,hint:`Higher is stricter. Only matters after you enrolled your voice.`,children:(0,w.jsx)(`input`,{type:`range`,min:.3,max:.95,step:.01,value:s.voice.accept,onChange:e=>le(`voice`,`accept`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`"Ask for my PIN" level: ${s.voice.challenge.toFixed(2)}`,hint:`Voices between this and the level above must be confirmed with the PIN.`,children:(0,w.jsx)(`input`,{type:`range`,min:.2,max:.9,step:.01,value:s.voice.challenge,onChange:e=>le(`voice`,`challenge`,Number(e.target.value))})})]}),pe=(0,w.jsxs)(`div`,{className:`look-tab`,children:[(0,w.jsxs)(`div`,{className:`look-side`,children:[(0,w.jsx)(AS,{look:L}),(0,w.jsx)(`p`,{className:`auth-note`,children:`This is a live preview. Nothing changes on the screen until you save.`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>c({...s,look:{...zd}}),children:`Back to the default look`})]}),(0,w.jsxs)(`div`,{className:`look-controls`,children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Themes`}),(0,w.jsx)(`div`,{className:`theme-grid`,role:`group`,"aria-label":`Themes`,children:$u.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`theme-card${DC(L,e)?` on`:``}`,"aria-pressed":DC(L,e),style:{"--swatch":e.accent},onClick:()=>c({...s,look:{...L,style:e.style,accent:e.accent,intensity:e.intensity}}),children:[(0,w.jsx)(`i`,{"aria-hidden":`true`}),(0,w.jsx)(`b`,{children:e.name}),(0,w.jsx)(`small`,{children:e.style})]},e.id))}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Shape`}),(0,w.jsx)(`div`,{className:`style-row`,role:`radiogroup`,"aria-label":`Style`,children:EC.map(e=>(0,w.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":L.style===e.id,className:`style-choice${L.style===e.id?` on`:``}`,onClick:()=>le(`look`,`style`,e.id),children:[(0,w.jsx)(`b`,{children:e.name}),(0,w.jsx)(`small`,{children:e.note})]},e.id))}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Colour and light`}),(0,w.jsxs)(`div`,{className:`swatch-row`,role:`group`,"aria-label":`Colour`,children:[TC.map(e=>(0,w.jsx)(`button`,{type:`button`,"aria-label":`Colour ${e}`,"aria-pressed":L.accent.toLowerCase()===e,className:`swatch${L.accent.toLowerCase()===e?` on`:``}`,style:{background:e},onClick:()=>le(`look`,`accent`,e)},e)),(0,w.jsxs)(`label`,{className:`swatch-custom`,children:[(0,w.jsx)(`span`,{children:`Other`}),(0,w.jsx)(`input`,{type:`color`,"aria-label":`Pick another colour`,value:L.accent,onChange:e=>le(`look`,`accent`,e.target.value.toLowerCase())})]})]}),(0,w.jsx)(ow,{label:`Brightness: ${Math.round(L.intensity*100)}%`,children:(0,w.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:L.intensity,onChange:e=>le(`look`,`intensity`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`Size: ${Math.round(L.size*100)}%`,hint:`How big it is in the middle of the screen.`,children:(0,w.jsx)(`input`,{type:`range`,min:.5,max:1.5,step:.05,value:L.size,onChange:e=>le(`look`,`size`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`Reaction to my voice: ${Math.round(L.reactivity*100)}%`,hint:`Low is calm, high moves a lot when anyone speaks.`,children:(0,w.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:L.reactivity,onChange:e=>le(`look`,`reactivity`,Number(e.target.value))})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:L.ambient,onChange:e=>le(`look`,`ambient`,e.target.checked)}),` Soft glow behind everything`]}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Words on the screen`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:L.captions,onChange:e=>le(`look`,`captions`,e.target.checked)}),` Show the live words while Friend speaks`]}),(0,w.jsx)(ow,{label:`Caption size`,children:(0,w.jsxs)(`select`,{value:L.captionSize,disabled:!L.captions,onChange:e=>le(`look`,`captionSize`,e.target.value),children:[(0,w.jsx)(`option`,{value:`small`,children:`Small`}),(0,w.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,w.jsx)(`option`,{value:`large`,children:`Large`})]})}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`What is on the screen`}),(0,w.jsx)(ow,{label:`Your name`,hint:`Shown on the badge in the corner, next to the shield, while you are signed in. Empty shows Owner.`,children:(0,w.jsx)(`input`,{value:s.ownerName??``,maxLength:40,placeholder:`Owner`,onChange:e=>c({...s,ownerName:e.target.value})})}),(0,w.jsx)(ow,{label:`View`,hint:`Minimal: only the voice presence. Companion: plus a status line and a clock. Workspace: also the chat and the schedule. Drag any panel to move it.`,children:(0,w.jsxs)(`select`,{value:s.view,onChange:e=>c({...s,view:e.target.value}),children:[(0,w.jsx)(`option`,{value:`minimal`,children:`Minimal`}),(0,w.jsx)(`option`,{value:`companion`,children:`Companion`}),(0,w.jsx)(`option`,{value:`workspace`,children:`Workspace`})]})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:L.aiMayChange,onChange:e=>le(`look`,`aiMayChange`,e.target.checked)}),` Let the AI change the shape, colour and brightness to suit a topic`]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Off keeps exactly the look you chose. You can still ask it to change the look yourself.`})]})]}),me=s.approvals??`manual`,he=e=>c({...s,phoneApprovals:{...s.phoneApprovals,...e}}),ge=(0,w.jsxs)(`div`,{className:`settings-section`,role:`radiogroup`,"aria-label":`How much Friend asks before acting`,children:[(0,w.jsx)(`h3`,{children:`How much should Friend ask?`}),nw.map(e=>(0,w.jsxs)(`label`,{className:`settings-check`,style:{alignItems:`flex-start`},children:[(0,w.jsx)(`input`,{type:`radio`,name:`approvals`,value:e.id,checked:me===e.id,onChange:()=>c({...s,approvals:e.id})}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.label}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:e.note})]})]},e.id)),(0,w.jsx)(`small`,{className:`auth-note`,children:`Whatever you pick, these still ask: risky commands (they need your PIN), the camera, adding connectors or plugins, and anything in Friend's own data folder. Changing this needs your PIN.`}),(0,w.jsxs)(`div`,{className:`settings-section`,role:`radiogroup`,"aria-label":`Where code runs`,children:[(0,w.jsx)(`h3`,{children:`Where does the code Friend writes run?`}),rw.map(e=>(0,w.jsxs)(`label`,{className:`settings-check`,style:{alignItems:`flex-start`},children:[(0,w.jsx)(`input`,{type:`radio`,name:`codeRunner`,value:e.id,checked:(s.codeRunner??`auto`)===e.id,onChange:()=>c({...s,codeRunner:e.id})}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.label}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:e.note})]})]},e.id))]}),(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`The eye`,children:[(0,w.jsx)(`h3`,{children:`The eye: let Friend look by itself`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.eye?.on??!1,onChange:e=>c({...s,eye:{autoOffMinutes:120,...s.eye,on:e.target.checked}})}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:`Eye on`}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:`While it is on, Friend uses the camera whenever it needs to (and when in doubt) without asking each time, but only when you talk to it at this screen. Never from Telegram, Alexa, guests or workers. The camera light shows whenever the camera is open. Switching on needs your PIN; switching off does not. It is always off after a restart or when you sign out.`})]})]}),(0,w.jsx)(ow,{label:`Switch off by itself after (minutes, 0 = never)`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:1440,value:s.eye?.autoOffMinutes??120,onChange:e=>c({...s,eye:{on:s.eye?.on??!1,autoOffMinutes:Math.min(1440,Math.max(0,Math.round(Number(e.target.value)||0)))}})})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Pictures go to the AI model you chose. With Claude they are sent to Anthropic; with a local Ollama vision model they stay on this PC. Nothing from a picture is kept.`})]}),(0,w.jsx)(UC,{}),s.phoneApprovals&&(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`Asking on your phone`,children:[(0,w.jsx)(`h3`,{children:`When you are away from the screen`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.phoneApprovals.enabled,onChange:e=>he({enabled:e.target.checked})}),(0,w.jsx)(`span`,{children:`Ask me on my phone (Telegram or WhatsApp, once linked)`})]}),(0,w.jsx)(ow,{label:`Ask on`,children:(0,w.jsxs)(`select`,{value:s.phoneApprovals.channel,onChange:e=>he({channel:e.target.value}),children:[(0,w.jsx)(`option`,{value:`auto`,children:`Telegram, else WhatsApp`}),(0,w.jsx)(`option`,{value:`telegram`,children:`Telegram only`}),(0,w.jsx)(`option`,{value:`whatsapp`,children:`WhatsApp only`})]})}),(0,w.jsx)(ow,{label:`Group questions that pile up (seconds)`,hint:`0 to 30. While one question waits on your phone, newer ones are gathered for this long and sent as one message, so they come together. 0 sends each by itself.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:30,value:s.phoneApprovals.batchSec,onChange:e=>he({batchSec:Math.min(30,Math.max(0,Math.round(Number(e.target.value)||0)))})})}),(0,w.jsx)(ow,{label:`Wait for the screen first (seconds)`,hint:`0 to 110. Used when a screen is open; with none open the phone is asked at once.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:110,value:s.phoneApprovals.delaySec,onChange:e=>he({delaySec:Math.min(110,Math.max(0,Math.round(Number(e.target.value)||0)))})})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.phoneApprovals.buttons,onChange:e=>he({buttons:e.target.checked})}),(0,w.jsx)(`span`,{children:`Telegram: show Allow and Deny buttons (otherwise reply YES or NO)`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.phoneApprovals.allowRisky,onChange:e=>he({allowRisky:e.target.checked})}),(0,w.jsx)(`span`,{children:`Also let the phone answer the camera and the Office's requests`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`With no screen open the question goes to your phone at once; with one open, after the wait above. Whichever you answer first wins. Anything that needs your PIN is never asked on the phone, and "always allow" is only on the screen.`})]})]}),V=(0,w.jsxs)(w.Fragment,{children:[l===`model`&&B,l===`voice`&&fe,l===`look`&&pe,l===`approvals`&&ge,l===`trading`&&(0,w.jsx)(vC,{level:s.trading?.level??`read`}),l===`widgets`&&s.music&&s.hud&&(0,w.jsx)(wC,{music:s.music,hud:s.hud,onMusic:e=>c({...s,music:{...s.music,...e}}),onHud:e=>c({...s,hud:{...s.hud,...e}})}),l===`system`&&(0,w.jsx)(tw,{auto:s.updates?.auto??!0,onAuto:e=>c({...s,updates:{auto:e}})}),l===`office`&&s.office&&(0,w.jsx)(mC,{office:s.office,onChange:e=>c({...s,office:{...s.office,...e}})}),l===`memory`&&s.memory&&(0,w.jsx)($S,{memory:s.memory,onChange:e=>c({...s,memory:{...s.memory,...e}})}),l===`heartbeat`&&s.proactive&&(0,w.jsx)(YS,{proactive:s.proactive,onChange:e=>c({...s,proactive:{...s.proactive,...e}})}),l===`soul`&&(0,w.jsx)(XC,{}),l===`audit`&&(0,w.jsx)(US,{...s.audit?{settings:s.audit,onSettings:e=>c({...s,audit:{...s.audit,...e}})}:{}}),l===`usage`&&(0,w.jsx)(PC,{}),l===`security`&&(0,w.jsx)(gC,{})]}),_e=()=>{ce||oe||se||(ee(null),k(null),Hd(I)?S(!0):de())},ve=()=>{c(structuredClone(a)),f(``),m(``),g(``),v(``)},ye=(0,w.jsxs)(w.Fragment,{children:[A&&!ie&&(0,w.jsx)(`p`,{className:`auth-note`,children:A}),O&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O})]});if(i===`holo`){let e=ze.findIndex(e=>e.id===l),t=e=>u(ze[(e+ze.length)%ze.length].id);return re((0,w.jsxs)(w.Fragment,{children:[V,ye]}),!0,{title:ze[e].label,page:{index:e,total:ze.length,onPrev:()=>t(e-1),onNext:()=>t(e+1)},dirty:ie,onApply:_e,onUndo:ve,help:(0,w.jsxs)(w.Fragment,{children:[`Fill in the settings and press `,(0,w.jsx)(`b`,{children:`Apply`}),` to save them. Network, folders and safety rules are not here on purpose: change those in the terminal with friend config set.`]})})}return re((0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`settings-layout`,children:[(0,w.jsx)(`div`,{className:`settings-tabs`,role:`tablist`,"aria-label":`Settings sections`,"aria-orientation":`vertical`,onKeyDown:z,children:ze.map(e=>(0,w.jsxs)(`button`,{id:`settings-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":l===e.id,"aria-controls":`settings-panel-${e.id}`,tabIndex:l===e.id?0:-1,className:`settings-tab${l===e.id?` on`:``}`,onClick:()=>u(e.id),children:[(0,w.jsx)(`b`,{children:e.label}),(0,w.jsx)(`small`,{children:e.note})]},e.id))}),(0,w.jsx)(`div`,{className:`settings-body`,role:`tabpanel`,id:`settings-panel-${l}`,"aria-labelledby":`settings-tab-${l}`,children:V})]}),A&&!ie&&(0,w.jsx)(`p`,{className:`auth-note`,children:A}),O&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:!ie||E||ce||oe||se,onClick:_e,children:ie&&!Hd(I)?`Save`:`Save…`}),ie&&(0,w.jsx)(`button`,{type:`button`,style:x,onClick:ve,children:`Undo changes`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:t,children:`Close`})]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Network, folders and safety rules are not here on purpose. Change those in the terminal: friend config set.`})]}),!0)}var cw=e=>{try{return Gu(e)}catch{return{label:e.id.slice(0,24)}}};function lw({chips:e,onRestore:t}){return e.length===0?null:(0,w.jsx)(`nav`,{className:`chip-strip`,"aria-label":`Put away`,children:e.map(e=>{let{label:n,value:r}=cw(e);return(0,w.jsxs)(`button`,{type:`button`,className:`chip`,"data-chip":e.id,"aria-label":`Show ${n}`,title:`Show ${n}`,onClick:()=>t(e.id),children:[(0,w.jsx)(`span`,{className:`chip-label`,children:n}),r!==void 0&&(0,w.jsx)(`span`,{className:`chip-value`,children:r})]},e.id)})})}var uw=e=>e instanceof HTMLElement&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable);function dw({onSend:e,requestOpen:t,slash:n,onOpenChange:r,hud:i}){let a=!!i,[o,s]=(0,y.useState)(!1),c=(0,y.useRef)(r);c.current=r,(0,y.useEffect)(()=>c.current?.(!a&&o),[o,a]);let[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(0),p=(0,y.useRef)(null);if((0,y.useEffect)(()=>{t<=0||(a?p.current?.focus():s(!0))},[t]),(0,y.useEffect)(()=>{let e=e=>{!a&&o||uw(e.target)||e.ctrlKey||e.metaKey||e.altKey||e.code!==`Space`&&e.key!==` `&&e.key.length===1&&(e.preventDefault(),u(e.key),f(0),a?p.current?.focus():s(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,a]),(0,y.useEffect)(()=>{o&&p.current?.focus()},[o]),!o&&!a)return null;let m=n?L(n.commands,l):[],h=m[Math.min(d,Math.max(m.length-1,0))],g=()=>{u(``),f(0),s(!1),a&&p.current?.blur()},_=()=>{let t=l.trim();if(n&&le(t)){let e=/^\/\S*\s/.test(t);n.run(!e&&h?`/${h.name}`:t)}else t&&e(de(t));g()};return(0,w.jsxs)(`form`,{className:`command-bar${a?` command-bar-hud`:``}`,style:i?.style,onSubmit:e=>{e.preventDefault(),_()},children:[m.length>0&&(0,w.jsx)(`ul`,{className:`slash-list`,role:`listbox`,"aria-label":`Commands`,children:m.map((e,t)=>(0,w.jsxs)(`li`,{role:`option`,"aria-selected":e===h,className:e===h?`on`:void 0,onMouseDown:n=>{n.preventDefault(),u(`/${e.name} `),p.current?.focus(),f(t)},children:[(0,w.jsxs)(`b`,{children:[`/`,e.name]}),e.usage&&(0,w.jsx)(`i`,{children:e.usage}),(0,w.jsx)(`span`,{children:e.description})]},e.name))}),(0,w.jsx)(`input`,{ref:p,...a?{"data-space-talks":``}:{},"aria-label":`Message`,value:l,placeholder:i?`▸ ask ${i.name} anything…`:`Talk to me… or type / for commands`,autoComplete:`off`,onChange:e=>{u(e.target.value),f(0)},onKeyDown:e=>{e.key===`Escape`?(e.stopPropagation(),g()):m.length>0&&(e.key===`ArrowDown`||e.key===`ArrowUp`)?(e.preventDefault(),f(t=>(t+(e.key===`ArrowDown`?1:m.length-1))%m.length)):e.key===`Tab`&&h&&(e.preventDefault(),u(`/${h.name} `))}}),(0,w.jsx)(`button`,{type:`submit`,"aria-label":`Send`,children:`↵`})]})}var fw=1600,pw=.31,mw=[-90,-30,30,150,210],hw=120,gw=12;function _w(e,t){return Math.min(e/fw,t/900)}function vw(e,t,n,r,i){let a=_w(r,i);return{x:bw((e===`left`?0:e===`right`?r-fw*a:(r-fw*a)/2)+t*a),y:bw((i-900*a)/2+n*a)}}function yw(e,t){return Math.max(hw,300*_w(e,t))}var bw=e=>Math.round(e*100)/100;function xw(e,t,n){let r=Math.max(0,Math.min(gw,Math.floor(e))),i=yw(t,n);return Array.from({length:r},(e,a)=>{let o=r<=mw.length?mw[a]:-90+a*360/r,s=o*Math.PI/180;return{x:bw(t/2+i*Math.cos(s)),y:bw(n/2+i*Math.sin(s)),angle:o}})}function Sw(e,t){return{cx:e/2,cy:t/2,r:yw(e,t)+40}}function Cw(e,t){return e<=899?`compact`:`orbit`}var ww={width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0},Tw=(e,t)=>e===`listening`?t?`Listening… tap to send`:`Listening… let go to send`:e===`transcribing`?`Understanding…`:e===`speaking`?`Tap to talk over me`:`Hold to talk, or tap once`;function Ew({voice:e,mode:t,onType:n,onMenu:r}){let i=(0,y.useRef)(null),a=(0,y.useRef)(!1),[o,s]=(0,y.useState)(!1),c=e=>{a.current=e,s(e)},l=(0,y.useRef)(t);l.current=t,(0,y.useEffect)(()=>{t!==`listening`&&!i.current&&c(!1)},[t]);let u=t=>{if((t.pointerType!==`mouse`||t.button===0)&&!i.current){if(a.current&&l.current===`listening`){c(!1),e.pressEnd();return}c(!1),i.current={at:Date.now(),id:t.pointerId};try{t.currentTarget.setPointerCapture?.(t.pointerId)}catch{}e.pressStart()}},d=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,Date.now()-n.at>=450?e.pressEnd():c(!0))},f=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,c(!1),e.blur?.())},p=t===`listening`;return(0,w.jsxs)(`div`,{className:`touch-controls`,"data-testid":`touch-controls`,children:[(0,w.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Open the menu`,onClick:r,children:(0,w.jsx)(`svg`,{...ww,children:(0,w.jsx)(`path`,{d:`M4 7h16M4 12h16M4 17h16`})})}),(0,w.jsxs)(`div`,{className:`touch-talk`,children:[(0,w.jsx)(`button`,{type:`button`,className:`touch-mic${p?` on`:``}`,"aria-label":`Talk to Friend`,"aria-pressed":p,onPointerDown:u,onPointerUp:d,onPointerCancel:f,onContextMenu:e=>e.preventDefault(),children:(0,w.jsxs)(`svg`,{...ww,width:30,height:30,children:[(0,w.jsx)(`rect`,{x:`9`,y:`3`,width:`6`,height:`11`,rx:`3`}),(0,w.jsx)(`path`,{d:`M5 11a7 7 0 0 0 14 0M12 18v3`})]})}),(0,w.jsx)(`span`,{className:`touch-hint`,"aria-live":`polite`,children:Tw(t,o)})]}),(0,w.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Type a message`,onClick:n,children:(0,w.jsxs)(`svg`,{...ww,children:[(0,w.jsx)(`rect`,{x:`3`,y:`6`,width:`18`,height:`12`,rx:`2`}),(0,w.jsx)(`path`,{d:`M7 10h.01M11 10h.01M15 10h.01M7 14h10`})]})})]})}function Dw(e,t){this.v=e,this.k=t}function Ow(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function kw(e){if(Array.isArray(e))return e}function Aw(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function jw(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4391
+ `))},[e]),(0,w.jsx)(`textarea`,{rows:r,spellCheck:!1,...n?{"aria-label":n}:{},value:i,onChange:e=>{a(e.target.value),t(nC(e.target.value))}})}var uC=({list:e})=>(0,w.jsx)(w.Fragment,{children:e.map(e=>(0,w.jsx)(`p`,{className:`of-problem`,"data-problem":``,children:e},e))});function dC({code:e,title:t,note:n,children:r}){return(0,w.jsxs)(`section`,{className:`of-card`,children:[(0,w.jsxs)(`header`,{className:`of-card-head`,children:[(0,w.jsx)(`span`,{className:`of-code`,children:e}),(0,w.jsx)(`h4`,{children:t})]}),n&&(0,w.jsx)(`p`,{className:`of-note`,children:n}),(0,w.jsx)(`div`,{className:`of-card-body`,children:r})]})}var fC=[{id:`low`,name:`Low`,text:`Friend asks you for every request a worker makes that is not on your let-through list.`},{id:`medium`,name:`Medium`,text:`Friend answers the ordinary requests itself. Anything that looks dangerous (deleting files, installing, force pushes) still asks you, with your PIN.`},{id:`judge`,name:`Your assistant decides`,text:`Friend weighs each request like a careful senior engineer: it allows what the ticket needs and refuses what could harm, and the feed shows its reason. If it cannot decide, you are asked. The refusals below still hold.`},{id:`hybrid`,name:`Quick check, then your assistant`,text:`Cheaper than letting her answer everything. A quick separate check allows the clearly fine requests (it costs almost nothing); anything dangerous, refused or unsure goes to your assistant herself, who answers with all she knows. A request repeated for the same ticket gets the same answer. If she cannot answer, you are asked.`},{id:`self`,name:`Your assistant, herself`,text:`Your assistant answers each request in her own conversation, with all she knows about you and your projects. A worker waits until she answers; if she is busy it waits for her to be free, and nothing is skipped. If she cannot answer after the tries below, you are asked.`},{id:`high`,name:`High`,text:`Friend answers every request itself, even dangerous ones, so you are not asked. The refusals below still hold.`}],pC=e=>String(e).padStart(2,`0`);function mC({office:e,onChange:t}){let n=(n,r)=>t({projects:e.projects.map((e,t)=>t===n?{...e,...r}:e)}),r=e=>e.trim()===``||!Number.isFinite(Number(e))?0:Number(e),i=e.policy.denyCommands;return(0,w.jsxs)(`div`,{className:`of-tab`,"data-on":e.enabled?`true`:`false`,children:[(0,w.jsxs)(`section`,{className:`of-hero`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`of-code`,children:`FRIEND · OFFICE`}),(0,w.jsx)(`h3`,{children:`Hired workers`}),(0,w.jsx)(`p`,{className:`of-note`,children:`Friend can hire workers: separate Claude Code sessions that work in your project folders, one ticket at a time. Workers use the Claude Code program and model chosen under Model, and their risky steps ask you first, unless you let Friend decide (How much Friend decides, below). Switched off, no worker runs. On the orbital screen, hired workers take the place of the quick-launch buttons. Friend hires and manages the team himself: he decides the jobs, the instructions and who reports to whom. To see who is hired, click the name in the middle of the orbital screen.`})]}),(0,w.jsxs)(`label`,{className:`of-switch`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>t({enabled:e.target.checked})}),(0,w.jsx)(`span`,{className:`of-track`,"aria-hidden":`true`,children:(0,w.jsx)(`i`,{})}),(0,w.jsx)(`span`,{className:`of-switch-text`,children:`Turn the Office on`}),(0,w.jsx)(`b`,{className:`of-state`,children:e.enabled?`ONLINE`:`OFFLINE`})]})]}),(0,w.jsxs)(`label`,{className:`of-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.notifyFriend,onChange:e=>t({notifyFriend:e.target.checked})}),` Tell Friend when a worker finishes`,(0,w.jsx)(`small`,{className:`of-hint`,children:`Friend is told when a ticket is done or stuck, says so, and can review it and give the next ticket, so the work keeps moving. Switch it off and he only knows what you ask him.`})]}),(0,w.jsx)(dC,{code:`00`,title:`How much Friend decides`,note:`When a worker asks to do something (run a command, write a file), who answers. Friend always refuses what is outside the project folders, what changes the files that control a worker, and the commands you list under Rules.`,children:(0,w.jsx)(`div`,{className:`of-levels`,role:`radiogroup`,"aria-label":`How much Friend decides`,children:fC.map(n=>(0,w.jsxs)(`label`,{className:`of-level`,"data-on":e.autonomy===n.id?`true`:`false`,children:[(0,w.jsx)(`input`,{type:`radio`,name:`of-autonomy`,checked:e.autonomy===n.id,onChange:()=>t({autonomy:n.id})}),(0,w.jsx)(`b`,{children:n.name}),(0,w.jsx)(`small`,{className:`of-hint`,children:n.text})]},n.id))})}),(0,w.jsx)(dC,{code:`01`,title:`Limits`,note:`How many workers run, how long they may take to start, and when they stop.`,children:(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsx)(cC,{label:`Most workers at once`,hint:`The others wait their turn. From 1 to 8.`,children:(0,w.jsx)(`input`,{type:`number`,min:1,max:8,value:e.maxConcurrent,onChange:e=>t({maxConcurrent:r(e.target.value)})})}),(0,w.jsx)(cC,{label:`Start timeout (seconds)`,hint:`How long a worker may take to start before it is given up on. From 10 to 600.`,children:(0,w.jsx)(`input`,{type:`number`,min:10,max:600,value:e.startTimeoutSec,onChange:e=>t({startTimeoutSec:r(e.target.value)})})}),(0,w.jsx)(cC,{label:`Times the assistant is asked`,hint:`With 'Your assistant, herself': how many times she is asked about one request before you are asked instead. From 1 to 10.`,children:(0,w.jsx)(`input`,{type:`number`,min:1,max:10,value:e.decideTries,onChange:e=>t({decideTries:Math.min(10,Math.max(1,r(e.target.value)))})})}),(0,w.jsx)(cC,{label:`Pause at (% of the five-hour window)`,hint:`When your Claude subscription window is this full, workers wait until it resets. 0 means never pause.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:100,value:Math.round(e.pauseAtWindow*100),onChange:e=>t({pauseAtWindow:Math.min(100,Math.max(0,r(e.target.value)))/100})})}),(0,w.jsx)(cC,{label:`Limit per worker (tokens)`,hint:`A worker stops when it has used this many. 0 means no limit.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,step:1e3,value:e.budget.perWorkerTokens,onChange:n=>t({budget:{...e.budget,perWorkerTokens:r(n.target.value)}})})}),(0,w.jsx)(cC,{label:`Limit in total (tokens)`,hint:`All workers together. 0 means no limit.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,step:1e3,value:e.budget.totalTokens,onChange:n=>t({budget:{...e.budget,totalTokens:r(n.target.value)}})})})]})}),(0,w.jsxs)(dC,{code:`02`,title:`Projects`,note:`A project is a folder workers may work in. A worker never goes outside it and its extra folders.`,children:[e.projects.map((r,i)=>(0,w.jsxs)(`fieldset`,{className:`of-item`,children:[(0,w.jsxs)(`legend`,{children:[(0,w.jsxs)(`span`,{className:`of-code`,children:[`PROJECT `,pC(i+1)]}),` `,r.name||r.id||`new`]}),(0,w.jsxs)(`div`,{className:`of-grid`,children:[(0,w.jsx)(cC,{label:`Id`,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} id`,value:r.id,maxLength:24,onChange:e=>n(i,{id:e.target.value})})}),(0,w.jsx)(cC,{label:`Name`,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} name`,value:r.name,maxLength:60,onChange:e=>n(i,{name:e.target.value})})})]}),(0,w.jsx)(cC,{label:`Folder`,wide:!0,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} folder`,value:r.folder,maxLength:260,onChange:e=>n(i,{folder:e.target.value})})}),(0,w.jsx)(cC,{label:`Goal`,hint:`One line workers are told about this project.`,wide:!0,children:(0,w.jsx)(`input`,{"aria-label":`Project ${i+1} goal`,value:r.goal,maxLength:500,onChange:e=>n(i,{goal:e.target.value})})}),(0,w.jsx)(cC,{label:`Extra folders (one per line)`,hint:`Up to five more folders workers may read and change.`,wide:!0,children:(0,w.jsx)(lC,{label:`Project ${i+1} extra folders`,rows:2,value:r.extraFolders,onChange:e=>n(i,{extraFolders:e})})}),(0,w.jsx)(uC,{list:aC(e.projects,i)}),(0,w.jsx)(`button`,{type:`button`,className:`of-remove`,"aria-label":`Remove project ${i+1}`,onClick:()=>t({projects:e.projects.filter((e,t)=>t!==i)}),children:`Remove`})]},i)),(0,w.jsx)(`button`,{type:`button`,className:`of-add`,onClick:()=>t({projects:[...e.projects,{id:``,name:``,folder:``,goal:``,extraFolders:[]}]}),children:`+ Add a project`})]}),(0,w.jsxs)(dC,{code:`03`,title:`Rules`,note:`What the gate does with a worker's request, before it ever reaches you.`,children:[(0,w.jsx)(cC,{label:`Let through without asking (one tool name per line)`,hint:`Claude Code tools a worker may use inside its folders without asking you, such as Read. Anything else asks.`,wide:!0,children:(0,w.jsx)(lC,{rows:4,value:e.policy.allowTools,onChange:n=>t({policy:{...e.policy,allowTools:n}})})}),(0,w.jsx)(cC,{label:`Always refuse (one pattern per line)`,hint:`Commands that match one of these are refused, even if you would say yes. Each line is a regular expression, matched without regard to capital letters.`,wide:!0,children:(0,w.jsx)(lC,{rows:4,value:i,onChange:n=>t({policy:{...e.policy,denyCommands:n}})})}),(0,w.jsx)(uC,{list:oC(i)})]})]})}var hC=async e=>{let t;try{t=await fetch(`/api/account/secret`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}catch{throw Error(`Could not reach Friend. Check the connection.`)}let n={};try{n=await t.json()}catch{}if(!t.ok){let e=typeof n.triesLeft==`number`&&n.triesLeft>0?` ${n.triesLeft} ${n.triesLeft===1?`try`:`tries`} left.`:``;throw Error((n.error??(t.status===401?`Please sign in again.`:`The request failed (${t.status}).`))+e)}return{signedOutOthers:!!n.signedOutOthers}};function gC({change:e=hC}){let[t,n]=(0,y.useState)(``),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),_=r!==``||a!==``,v=s!==``||l!==``,b=async()=>{if(m(null),g(null),!t)return m(`Type your current password.`);if(!_&&!v)return m(`Type a new password or a new PIN.`);if(_&&r.length<8)return m(`The new password must be at least 8 characters.`);if(_&&r!==a)return m(`The two new passwords are not the same.`);if(v&&!/^\d{6,}$/.test(s))return m(`The new PIN must be at least 6 digits.`);if(v&&s!==l)return m(`The two new PINs are not the same.`);f(!0);try{let a=await e({current:t,..._?{newPassword:r}:{},...v?{newPin:s}:{}});g([_&&`Password changed.`,v&&`PIN changed.`,_&&a.signedOutOthers&&`Other browsers and phones were signed out.`].filter(Boolean).join(` `)),n(``),i(``),o(``),c(``),u(``)}catch(e){m(e.message),n(``)}finally{f(!1)}};return(0,w.jsxs)(`form`,{className:`settings-section`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,w.jsx)(`h3`,{children:`Password and PIN`}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Change either one or both. Your current password is always needed. Forgot it? On this PC run: friend password`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Current password`}),(0,w.jsx)(`input`,{type:`password`,autoComplete:`current-password`,value:t,disabled:d,onChange:e=>n(e.target.value),style:x})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New password`}),(0,w.jsx)(`input`,{type:`password`,autoComplete:`new-password`,value:r,disabled:d,onChange:e=>i(e.target.value),style:x})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New password again`}),(0,w.jsx)(`input`,{type:`password`,autoComplete:`new-password`,value:a,disabled:d,onChange:e=>o(e.target.value),style:x})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New PIN`}),(0,w.jsx)(`input`,{type:`password`,inputMode:`numeric`,autoComplete:`off`,value:s,disabled:d,onChange:e=>c(e.target.value.replace(/\D/g,``)),style:x})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`The PIN is at least 6 digits. It is asked before risky actions.`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`New PIN again`}),(0,w.jsx)(`input`,{type:`password`,inputMode:`numeric`,autoComplete:`off`,value:l,disabled:d,onChange:e=>u(e.target.value.replace(/\D/g,``)),style:x})]}),p&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:p}),h&&(0,w.jsx)(`p`,{role:`status`,className:`auth-note`,children:h}),(0,w.jsx)(`button`,{type:`submit`,className:`primary`,style:x,disabled:d,children:d?`Saving…`:`Change`})]})}var _C=[{id:`read`,label:`Read only`,note:`Friend can look at your portfolio, funds, positions and orders, and send you reports. It cannot place, change or cancel any order. This is the only level in this version.`,locked:!1},{id:`orders`,label:`Orders with my confirmation (later version)`,note:`Friend would prepare an order and wait for you to confirm it with your PIN.`,locked:!0},{id:`limits`,label:`Orders within limits (later version)`,note:`Friend would place small orders on its own, inside limits you set.`,locked:!0}];function vC({level:e=`read`}){return(0,w.jsxs)(`div`,{className:`settings-section`,role:`radiogroup`,"aria-label":`What Friend may do with money`,children:[(0,w.jsx)(`h3`,{children:`What may Friend do with your trading account?`}),_C.map(t=>(0,w.jsxs)(`label`,{className:`settings-check`,style:{alignItems:`flex-start`,opacity:t.locked?.55:1},children:[(0,w.jsx)(`input`,{type:`radio`,name:`trading`,value:t.id,checked:!t.locked&&e===t.id,disabled:t.locked,readOnly:!0,onChange:()=>{}}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:t.label}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:t.note})]})]},t.id)),(0,w.jsx)(`small`,{className:`auth-note`,children:`The assistant can never change this, even with your PIN. Orders will only arrive in a later version, with their own safeguards.`})]})}var yC=async()=>{let e=await fetch(`/api/music/host/check`,{cache:`no-store`});if(!e.ok)throw Error(e.status===401?`Please sign in again.`:`The request failed (${e.status}).`);return await e.json()},bC=[`system`,`voice`,`network`,`feed`,`radar`,`tickets`,`approval`],xC={system:`System (processor and memory)`,voice:`Voice (sound bars)`,network:`Network`,feed:`Activity feed`,radar:`Devices (radar)`,tickets:`Tickets`,budget:`Budget`,approval:`Approvals`,usage:`Usage ring`},SC={url:`Open an address`,prompt:`Ask the assistant`,panel:`Open a panel`,music:`Control the music`},CC=e=>e===`panel`?Nu[0]:e===`music`?Pu[0]:``;function wC({music:e,hud:t,onMusic:n,onHud:r,checkHost:i=yC}){let[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),l=()=>{c(!0),o(null),i().then(e=>o(e.found?`mpv ${e.version} found (${e.path}).`:e.install)).catch(e=>o(e.message)).finally(()=>c(!1))},u=t.tidy??{dockAfterSeconds:40,maxChips:null,autoTidy:!0},d=t.launcher,f=(e,t)=>r({launcher:d.map((n,r)=>r===e?{...n,...t}:n)}),p=(e,t)=>{let n=e+t;if(n<0||n>=d.length)return;let i=[...d];[i[e],i[n]]=[i[n],i[e]],r({launcher:i})};return(0,w.jsxs)(`div`,{className:`settings-section`,children:[(0,w.jsx)(`h3`,{children:`Music player`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Music folder`}),(0,w.jsx)(`input`,{type:`text`,value:e.folder,placeholder:`C:\\Users\\you\\Music`,onChange:e=>n({folder:e.target.value})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`A folder on the PC that runs Friend. Its sub-folders are searched too. Saving checks that it exists.`})]}),(0,w.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`File types to look for`}),ju.map(t=>(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.extensions.includes(t),onChange:r=>{let i=r.target.checked?[...e.extensions,t]:e.extensions.filter(e=>e!==t);i.length&&n({extensions:ju.filter(e=>i.includes(e))})}}),(0,w.jsx)(`span`,{children:t})]},t))]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsxs)(`span`,{children:[`Start volume (`,e.volume,`%)`]}),(0,w.jsx)(`input`,{type:`range`,min:Mu.volume.min,max:Mu.volume.max,value:e.volume,onChange:e=>n({volume:Number(e.target.value)})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Repeat`}),(0,w.jsxs)(`select`,{value:e.repeat,onChange:e=>n({repeat:e.target.value}),children:[(0,w.jsx)(`option`,{value:`off`,children:`Off`}),(0,w.jsx)(`option`,{value:`all`,children:`The whole list`}),(0,w.jsx)(`option`,{value:`one`,children:`One track`})]})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Starts as`}),(0,w.jsxs)(`select`,{value:e.startView,onChange:e=>n({startView:e.target.value}),children:[(0,w.jsx)(`option`,{value:`mini`,children:`Small player`}),(0,w.jsx)(`option`,{value:`full`,children:`Big player with the playlist`})]})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.shuffle,onChange:e=>n({shuffle:e.target.checked})}),(0,w.jsx)(`span`,{children:`Shuffle`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.visualizer,onChange:e=>n({visualizer:e.target.checked})}),(0,w.jsx)(`span`,{children:`Moving bars around the dial`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Where music comes from, when the assistant is not told`}),(0,w.jsxs)(`select`,{value:e.defaultSource,onChange:e=>n({defaultSource:e.target.value}),children:[(0,w.jsx)(`option`,{value:`local`,children:`The music folder`}),(0,w.jsx)(`option`,{value:`spotify`,children:`Spotify`}),(0,w.jsx)(`option`,{value:`soundcloud`,children:`SoundCloud`}),(0,w.jsx)(`option`,{value:`audius`,children:`Audius`}),(0,w.jsx)(`option`,{value:`any`,children:`All`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Spotify, SoundCloud and Audius are added from Plugins. Playing from Spotify needs Spotify Premium on your account.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Most results from a service such as Spotify`}),(0,w.jsx)(`input`,{type:`number`,min:Mu.searchLimit.min,max:Mu.searchLimit.max,value:e.searchLimit,onChange:e=>n({searchLimit:Number(e.target.value)})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Where the sound comes out`}),(0,w.jsxs)(`select`,{value:e.output,onChange:e=>n({output:e.target.value}),children:[(0,w.jsx)(`option`,{value:`screen`,children:`The screen (the browser plays it)`}),(0,w.jsx)(`option`,{value:`host`,children:`This PC's speakers (no browser needed)`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`The PC's speakers play your folder's music through mpv, a free player you install once. Spotify plays on a Spotify device you name below.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Program that plays the folder's music on the PC (empty: find mpv automatically)`}),(0,w.jsx)(`input`,{type:`text`,value:e.hostPlayer,maxLength:260,placeholder:`mpv`,onChange:e=>n({hostPlayer:e.target.value})}),Lu(e.hostPlayer.trim())&&(0,w.jsx)(`small`,{role:`alert`,className:`auth-error`,children:Lu(e.hostPlayer.trim())})]}),(0,w.jsxs)(`div`,{className:`settings-field`,children:[(0,w.jsx)(`button`,{type:`button`,disabled:s,onClick:l,children:`Check mpv`}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Looks for mpv with the saved program setting, or automatically when it is empty.`}),a&&(0,w.jsx)(`small`,{role:`status`,className:`auth-note`,children:a})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Spotify device on the PC to play on`}),(0,w.jsx)(`input`,{type:`text`,value:e.spotifyDevice,maxLength:100,placeholder:`the name Spotify shows for that device`,onChange:e=>n({spotifyDevice:e.target.value})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Most tracks to list`}),(0,w.jsx)(`input`,{type:`number`,min:Mu.maxTracks.min,max:Mu.maxTracks.max,value:e.maxTracks,onChange:e=>n({maxTracks:Number(e.target.value)})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`How many folders deep to search`}),(0,w.jsx)(`input`,{type:`number`,min:Mu.scanDepth.min,max:Mu.scanDepth.max,value:e.scanDepth,onChange:e=>n({scanDepth:Number(e.target.value)})})]}),(0,w.jsx)(`h3`,{children:`Screen layout`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Screen layout`}),(0,w.jsxs)(`select`,{value:t.layout,onChange:e=>r({layout:e.target.value}),children:[(0,w.jsx)(`option`,{value:`classic`,children:`Classic (the orb with floating cards)`}),(0,w.jsx)(`option`,{value:`orbital`,children:`Orbital (a heads-up display around the orb)`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Orbital draws rings, an orbit of your quick-launch buttons and live instruments around the orb. Classic is the screen you know.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Density`}),(0,w.jsxs)(`select`,{value:t.density,disabled:t.layout!==`orbital`,onChange:e=>r({density:e.target.value}),children:[(0,w.jsx)(`option`,{value:`calm`,children:`Calm (the orb, the orbit and the message bar)`}),(0,w.jsx)(`option`,{value:`standard`,children:`Standard (the orb, the orbit, the budget ring and the usage line)`}),(0,w.jsx)(`option`,{value:`full`,children:`Full (the same, plus anything added later)`})]})]}),(0,w.jsxs)(`fieldset`,{className:`settings-field`,disabled:t.layout!==`orbital`,children:[(0,w.jsx)(`legend`,{children:`Instruments`}),Bu.map(e=>(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,"data-testid":`hud-widget-${e}`,disabled:t.layout!==`orbital`,checked:bC.includes(e)?t.widgets[e]===!0:t.widgets[e]!==!1,onChange:n=>r({widgets:{...t.widgets,[e]:n.target.checked}})}),(0,w.jsx)(`span`,{children:xC[e]})]},e)),(0,w.jsx)(`small`,{className:`auth-note`,children:`The live instruments (system, voice, network, activity, devices, tickets) and the approvals box are not on the screen until Friend brings them up (ask it, for example "show my system"); it puts them away when you ask or clear the screen. Tick one to keep it on the screen always. A box you switch off stays off. A waiting approval is always shown.`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,"data-testid":`hud-preview`,disabled:t.layout!==`orbital`,checked:t.preview===!0,onChange:e=>r({preview:e.target.checked})}),(0,w.jsx)(`span`,{children:`Show sample data (workers, tickets, budget and feed filled in, labelled SAMPLE, to preview the look)`})]}),(0,w.jsx)(`h3`,{children:`Screen tidy`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:u.autoTidy,onChange:e=>r({tidy:{...u,autoTidy:e.target.checked}})}),(0,w.jsx)(`span`,{children:`Tidy the screen by itself (put finished cards away as small chips)`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Put cards away after (seconds, 0 keeps them)`}),(0,w.jsx)(`input`,{type:`number`,min:0,max:3600,value:u.dockAfterSeconds,disabled:!u.autoTidy,onChange:e=>r({tidy:{...u,dockAfterSeconds:Number(e.target.value)}})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`A card is never put away before there was time to read it. A chip comes back as a card when you tap it.`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Most chips in the strip`}),(0,w.jsxs)(`select`,{value:u.maxChips===null?`auto`:String(u.maxChips),onChange:e=>r({tidy:{...u,maxChips:e.target.value===`auto`?null:Number(e.target.value)}}),children:[(0,w.jsx)(`option`,{value:`auto`,children:`By screen (desktop 7, tablet and phone 5)`}),[3,4,5,6,7,8,10,12].map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))]})]}),(0,w.jsx)(`h3`,{children:`Screen widgets`}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Name on the profile tag`}),(0,w.jsx)(`input`,{type:`text`,maxLength:24,value:t.terminalLabel,onChange:e=>r({terminalLabel:e.target.value})})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Animations`}),(0,w.jsxs)(`select`,{value:t.animations,onChange:e=>r({animations:e.target.value}),children:[(0,w.jsx)(`option`,{value:`full`,children:`Full`}),(0,w.jsx)(`option`,{value:`reduced`,children:`Reduced (only answers to hover and press)`}),(0,w.jsx)(`option`,{value:`off`,children:`Off`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`If the device is set to reduce motion, the screen stays still whatever this says.`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t.clock.hour12,onChange:e=>r({clock:{...t.clock,hour12:e.target.checked}})}),(0,w.jsx)(`span`,{children:`12-hour clock`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t.clock.seconds,onChange:e=>r({clock:{...t.clock,seconds:e.target.checked}})}),(0,w.jsx)(`span`,{children:`Show seconds`})]}),(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Date language (empty: the device's own)`}),(0,w.jsx)(`input`,{type:`text`,value:t.clock.locale,maxLength:35,placeholder:`en-GB`,onChange:e=>r({clock:{...t.clock,locale:e.target.value}})})]}),(0,w.jsx)(`h3`,{children:`Quick-launch buttons`}),d.length===0&&(0,w.jsx)(`small`,{className:`auth-note`,children:`No buttons yet.`}),d.map((e,t)=>{let n=Iu(e);return(0,w.jsxs)(`div`,{className:`settings-field`,role:`group`,"aria-label":`Button ${t+1}`,children:[(0,w.jsxs)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`},children:[(0,w.jsx)(`input`,{type:`text`,"aria-label":`Icon`,style:{width:56},value:e.icon,onChange:e=>f(t,{icon:e.target.value})}),(0,w.jsx)(`input`,{type:`text`,"aria-label":`Label`,maxLength:24,style:{flex:1,minWidth:100},value:e.label,onChange:e=>f(t,{label:e.target.value})}),(0,w.jsx)(`select`,{"aria-label":`What it does`,value:e.action.type,onChange:e=>{let n=e.target.value;f(t,{action:{type:n,value:CC(n)}})},children:Object.keys(SC).map(e=>(0,w.jsx)(`option`,{value:e,children:SC[e]},e))})]}),(0,w.jsxs)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`},children:[e.action.type===`panel`||e.action.type===`music`?(0,w.jsx)(`select`,{"aria-label":`Which`,style:{flex:1},value:e.action.value,onChange:n=>f(t,{action:{...e.action,value:n.target.value}}),children:(e.action.type===`panel`?Nu:Pu).map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))}):(0,w.jsx)(`input`,{type:`text`,"aria-label":e.action.type===`url`?`Address`:`Question`,style:{flex:1},value:e.action.value,placeholder:e.action.type===`url`?`https://…`:`What should it ask?`,onChange:n=>f(t,{action:{...e.action,value:n.target.value}})}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Move up`,disabled:t===0,onClick:()=>p(t,-1),children:`↑`}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Move down`,disabled:t===d.length-1,onClick:()=>p(t,1),children:`↓`}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Remove button`,onClick:()=>r({launcher:d.filter((e,n)=>n!==t)}),children:`Remove`})]}),n&&(0,w.jsx)(`small`,{role:`alert`,className:`auth-error`,children:n})]},e.id??t)}),(0,w.jsxs)(`button`,{type:`button`,disabled:d.length>=12,onClick:()=>r({launcher:[...d,{label:`New`,icon:`+`,action:{type:`panel`,value:`chat`}}]}),children:[`Add a button (`,d.length,`/`,12,`)`]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`The assistant can never change the music folder, these buttons or the animations, even with your PIN.`})]})}var TC=[`#3fd8ff`,`#2b7bff`,`#a066ff`,`#ff6fae`,`#ff5a5a`,`#ff9b3d`,`#ffd23d`,`#3dff8c`,`#e8f4ff`],EC=[{id:`sphere`,name:`Sphere`,note:`A cloud of particles`},{id:`orb`,name:`Orb`,note:`A glowing plasma ball`},{id:`ring`,name:`Ring`,note:`Radial bars, like a voice meter`}],DC=(e,t)=>e.style===t.style&&e.accent.toLowerCase()===t.accent&&Math.abs(e.intensity-t.intensity)<.005;async function OC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:`The request failed (${n.status}).`));return r}var kC={summary:e=>OC(`/api/usage?days=${e}`),clear:()=>OC(`/api/usage`,{method:`DELETE`})},AC=[7,30,90],jC=e=>e.toLocaleString(`en-US`);function MC(e){return e>=1e6?`${+(e/1e6).toFixed(1)}M`:e>=1e3?`${+(e/1e3).toFixed(1)}K`:String(e)}var NC={voice:`Voice`,chat:`Chat`,task:`Scheduled tasks`,channel:`Messages (WhatsApp, Telegram…)`,other:`Other`};function PC({api:e=kC}){let[t,n]=(0,y.useState)(7),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),d=(0,y.useRef)(!0),f=(0,y.useCallback)(async t=>{try{let n=await e.summary(t);d.current&&(i(n),o(null))}catch(e){d.current&&o(e.message)}},[e]);(0,y.useEffect)(()=>(d.current=!0,f(t),()=>{d.current=!1}),[f,t]);let p=async()=>{try{let n=await e.clear();if(!d.current)return;c(`Removed ${n.removed} saved counts.`),u(!1),await f(t)}catch(e){d.current&&o(e.message)}},m=r?Math.max(1,...r.days.map(e=>e.input+e.output)):1,h=!!r&&r.total.turns===0;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`approval-actions`,role:`group`,"aria-label":`How far back`,children:AC.map(e=>(0,w.jsxs)(`button`,{type:`button`,style:x,className:t===e?`primary`:void 0,"aria-pressed":t===e,onClick:()=>n(e),children:[e,` days`]},e))}),a&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:a}),r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`usage-totals`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`strong`,{children:MC(r.total.input)}),(0,w.jsx)(`span`,{children:`Sent to the model`})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`strong`,{children:MC(r.total.output)}),(0,w.jsx)(`span`,{children:`Written back`})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`strong`,{children:r.total.turns}),(0,w.jsx)(`span`,{children:`Answers`})]})]}),h?(0,w.jsx)(`p`,{className:`auth-note`,children:`Nothing counted yet. Once Friend has answered, the tokens it used show up here.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`usage-bars`,"aria-hidden":!1,children:r.days.map(e=>{let t=e.input+e.output;return(0,w.jsxs)(`div`,{className:`usage-bar-col`,children:[(0,w.jsx)(`div`,{role:`img`,"aria-label":`${e.day}: ${jC(t)} tokens on ${e.turns} answers`,className:`usage-bar`,style:{height:`${Math.max(t>0?4:1,Math.round(t/m*100))}%`},title:`${e.day}: ${jC(t)} tokens`}),r.days.length<=31&&(0,w.jsx)(`span`,{className:`usage-bar-day`,children:e.day.slice(8)})]},e.day)})}),(0,w.jsxs)(`table`,{className:`usage-table`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{scope:`col`,children:`Day`}),(0,w.jsx)(`th`,{scope:`col`,children:`Sent`}),(0,w.jsx)(`th`,{scope:`col`,children:`Written`}),(0,w.jsx)(`th`,{scope:`col`,children:`Answers`})]})}),(0,w.jsx)(`tbody`,{children:[...r.days].reverse().map(e=>(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{scope:`row`,children:e.day}),(0,w.jsx)(`td`,{children:jC(e.input)}),(0,w.jsx)(`td`,{children:jC(e.output)}),(0,w.jsx)(`td`,{children:e.turns})]},e.day))})]}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`By model`}),(0,w.jsx)(`ul`,{className:`usage-list`,children:r.byModel.map(e=>(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`span`,{children:[e.provider,` / `,e.model]}),(0,w.jsxs)(`span`,{children:[MC(e.input+e.output),` tokens · `,e.turns,` answers`]})]},`${e.provider}/${e.model}`))}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`By where it came from`}),(0,w.jsx)(`ul`,{className:`usage-list`,children:r.bySource.map(e=>(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`span`,{children:NC[e.source]??e.source}),(0,w.jsxs)(`span`,{children:[MC(e.input+e.output),` tokens · `,e.turns,` answers`]})]},e.source))})]})]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Friend keeps counts only: the day, the model, and how many tokens. Never what was said. Counts older than a year are removed by themselves.`}),s&&(0,w.jsx)(`p`,{className:`auth-note`,children:s}),(0,w.jsx)(`div`,{className:`approval-actions`,children:l?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,onClick:()=>void p(),children:`Yes, clear them`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>u(!1),children:`Keep them`})]}):(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>u(!0),children:`Clear saved counts`})})]})}async function FC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var IC=e=>({method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),LC={info:()=>FC(`/api/conversation`),compact:()=>FC(`/api/conversation/compact`,IC({})),clear:e=>FC(`/api/conversation/clear`,IC({pin:e}))},RC=[5e4,1e5,2e5,4e5,8e5];function zC({api:e=LC,autoCompact:t,limit:n,onChange:r}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=(0,y.useRef)(!0),_=(0,y.useCallback)(async()=>{try{let t=await e.info();g.current&&a(t)}catch(e){g.current&&p(e.message)}},[e]);(0,y.useEffect)(()=>(g.current=!0,_(),()=>{g.current=!1}),[_]);let v=async e=>{d(!0),p(null),h(null);try{let t=await e();if(!g.current)return;t.ok?h(t.message):p(t.message),s(!1),await _()}catch(e){g.current&&p(e.message)}finally{g.current&&(d(!1),l(``))}};if(o)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to start fresh. Friend keeps its notes and memory, but forgets the earlier conversation.`}),(0,w.jsx)(F,{pin:c,onChange:l,onSubmit:()=>!u&&c.length>=6&&void v(()=>e.clear(c))}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u||c.length<6,onClick:()=>void v(()=>e.clear(c)),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{s(!1),l(``),p(null)},children:`Back`})]})]});let b=RC.includes(n)?RC:[...RC,n].sort((e,t)=>e-t);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Conversation memory`}),i&&!i.supported?(0,w.jsx)(`p`,{className:`auth-note`,children:`This model does not keep a conversation of its own: Friend sends it the recent messages each time, so there is nothing to tidy.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:i?`Claude is holding about ${MC(i.contextTokens)} tokens of conversation${i.contextTokens===0?` (it counts again after the next answer)`:``}. It reads all of it for every answer, so a long one uses a lot of your plan.`:`Checking…`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>r({autoCompact:e.target.checked})}),` Tidy up by itself`]}),(0,w.jsxs)(`label`,{className:`settings-check`,style:{marginTop:6},children:[`When it grows past`,` `,(0,w.jsx)(`select`,{value:n,onChange:e=>r({compactAtTokens:Number(e.target.value)}),disabled:!t,children:b.map(e=>(0,w.jsxs)(`option`,{value:e,children:[MC(e),` tokens`]},e))})]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Tidying up writes short notes on what you were doing and starts a fresh conversation from them, before the next answer. Friend keeps its saved notes either way.`}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,disabled:u||!i,onClick:()=>void v(()=>e.compact()),children:`Tidy up now`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:u||!i,onClick:()=>s(!0),children:`Start fresh`})]})]}),m&&(0,w.jsx)(`p`,{className:`auth-note`,children:m}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f})]})}async function BC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var VC=e=>({method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),HC={list:()=>BC(`/api/people`),remove:async(e,t)=>void await BC(`/api/people/remove`,VC({id:e,pin:t})),forgetAll:async e=>void await BC(`/api/people/forget`,VC({pin:e}))};function UC({api:e=HC}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=(0,y.useRef)(!0),f=(0,y.useCallback)(async()=>{try{let t=await e.list();d.current&&n(t)}catch(e){d.current&&u(e.message)}},[e]);(0,y.useEffect)(()=>(d.current=!0,f(),()=>{d.current=!1}),[f]);let p=async()=>{if(!(!r||s||a.length<6)){c(!0),u(null);try{if(r.kind===`one`?await e.remove(r.person.id,a):await e.forgetAll(a),!d.current)return;i(null),await f()}catch(e){d.current&&u(e.message)}finally{d.current&&(c(!1),o(``))}}};return r?(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`Forget people`,children:[(0,w.jsx)(`p`,{className:`auth-note`,children:r.kind===`one`?`Enter your PIN to forget ${r.person.name}. Their saved face numbers and the notes about them are deleted.`:`Enter your PIN to forget everyone. All saved face numbers and the notes about them are deleted.`}),(0,w.jsx)(F,{pin:a,onChange:o,onSubmit:()=>void p()}),l&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:l}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:s||a.length<6,onClick:()=>void p(),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{i(null),o(``),u(null)},children:`Back`})]})]}):(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`People Friend remembers`,children:[(0,w.jsx)(`h3`,{children:`People Friend remembers`}),t&&t.length===0&&(0,w.jsx)(`p`,{className:`auth-note`,children:`Friend does not remember anyone yet. Say "this is Priya, my sister" while she is in front of the camera and Friend asks for your PIN.`}),t?.map(e=>(0,w.jsxs)(`div`,{className:`settings-check`,style:{justifyContent:`space-between`},children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.name}),e.relation?` (${e.relation})`:``,!e.usable&&(0,w.jsx)(`small`,{className:`auth-note`,children:` Their saved face cannot be read any more: introduce them again.`})]}),(0,w.jsx)(`button`,{type:`button`,style:x,"aria-label":`Remove ${e.name}`,onClick:()=>i({kind:`one`,person:e}),children:`Remove`})]},e.id)),t&&t.length>0&&(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>i({kind:`all`}),children:`Forget everyone`})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Face data is sensitive personal data. Introduce only people who know and agree, and not children. Friend keeps 128 numbers about a face, encrypted on this PC, never the picture, and never uses a face to approve anything.`}),l&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:l})]})}var WC=[{id:`duckduckgo`,label:`DuckDuckGo (free, no key)`},{id:`brave`,label:`Brave Search (your key)`},{id:`tavily`,label:`Tavily (your key)`},{id:`searxng`,label:`SearXNG (your own server)`}];function GC({label:e,hint:t,children:n}){return(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:e}),n,t&&(0,w.jsx)(`small`,{className:`auth-note`,children:t})]})}function KC({web:e,saved:t,braveKey:n,tavilyKey:r,onChange:i,onBraveKey:a,onTavilyKey:o}){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Searching the web`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>i({enabled:e.target.checked})}),` Let Friend search the web`]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Gives every model web.search (a list of results) and web.read (the text of one page), for prices, news and anything else that changes. They run on this PC with no browser. Friend will never take orders from a page, and it will not open addresses on this PC or your network.`}),(0,w.jsx)(GC,{label:`Search source`,children:(0,w.jsx)(`select`,{value:e.provider,disabled:!e.enabled,onChange:e=>i({provider:e.target.value}),children:WC.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),e.provider===`brave`&&(0,w.jsx)(GC,{label:`Brave key`,hint:t.braveKeySet?`A key is saved. Type a new one only to replace it.`:`From your Brave Search API account.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:t.braveKeySet?`saved`:``,value:n,onChange:e=>a(e.target.value)})}),e.provider===`tavily`&&(0,w.jsx)(GC,{label:`Tavily key`,hint:t.tavilyKeySet?`A key is saved. Type a new one only to replace it.`:`From your Tavily account.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:t.tavilyKeySet?`saved`:``,value:r,onChange:e=>o(e.target.value)})}),e.provider===`searxng`&&(0,w.jsx)(GC,{label:`SearXNG address`,hint:`For example http://localhost:8080. It must allow the JSON format.`,children:(0,w.jsx)(`input`,{value:e.searxngUrl,onChange:e=>i({searxngUrl:e.target.value})})}),e.provider!==`duckduckgo`&&(0,w.jsx)(`p`,{className:`auth-note`,children:`If this source cannot answer, Friend tries DuckDuckGo once and says so.`})]})}async function qC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var JC=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),YC={get:()=>qC(`/api/soul`),save:(e,t)=>qC(`/api/soul`,JC(`PUT`,{text:e,pin:t})),restore:(e,t)=>qC(`/api/soul/restore`,JC(`POST`,{to:e,pin:t}))};function XC({api:e=YC}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(!0),g=(0,y.useCallback)(async()=>{try{let t=await e.get();if(!h.current)return;n(t),i(t.text)}catch(e){h.current&&f(e.message)}},[e]);(0,y.useEffect)(()=>(h.current=!0,g(),()=>{h.current=!1}),[g]);let _=async()=>{if(a){u(!0),f(null);try{let t=a.kind===`save`?await e.save(r,s):await e.restore(a.to,s);if(!h.current)return;n(t),i(t.text),m(a.kind===`save`?`Saved. The assistant uses it from its next reply.`:a.to==="default"?`Back to the default soul.`:`Back to the earlier soul.`),o(null)}catch(e){h.current&&f(e.message)}finally{h.current&&(u(!1),c(``))}}};if(a)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:a.kind===`save`?`Enter your PIN to change who the assistant is.`:a.to==="default"?`Enter your PIN to put the original default soul back.`:`Enter your PIN to bring back the earlier soul.`}),(0,w.jsx)(F,{pin:s,onChange:c,onSubmit:()=>!l&&s.length>=6&&void _()}),d&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:d}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:l||s.length<6,onClick:()=>void _(),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{o(null),c(``),f(null)},children:`Back`})]})]});let v=t?.max??3e3,b=!!t&&r.trim()!==t.text.trim();return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Soul`}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Who your assistant is: its purpose, character, manner, gender and how it speaks to you. It is read on every request and kept in memory as soul.md. You can change it here, or just tell the assistant ("be more direct", "you are my study coach"). Its safety rules and your approvals are not part of it and cannot be loosened by it.`}),(0,w.jsx)(`textarea`,{"aria-label":`Soul`,className:`soul-text`,rows:16,value:r,maxLength:v,onChange:e=>i(e.target.value),style:{width:`100%`,fontFamily:`inherit`}}),(0,w.jsxs)(`p`,{className:`auth-note`,children:[r.length,` of `,v,` characters`,t?.isDefault?`. This is the default soul.`:`.`]}),p&&(0,w.jsx)(`p`,{role:`status`,children:p}),d&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:d}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:l||!b||!r.trim(),onClick:()=>o({kind:`save`}),children:`Save soul`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:l||!b,onClick:()=>i(t?.text??``),children:`Undo my edits`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:l||!t||t.versions.length===0,onClick:()=>o({kind:`restore`,to:`previous`}),children:`Bring back the earlier soul`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:l||!t||t.isDefault,onClick:()=>o({kind:`restore`,to:`default`}),children:`Reset to default`})]})]})}async function ZC(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}let r={};try{r=await n.json()}catch{}if(!n.ok)throw Error(r.error??(n.status===401?`Please sign in again.`:n.status===403?`Incorrect PIN`:`The request failed (${n.status}).`));return r}var QC=e=>({method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),$C={info:()=>ZC(`/api/system`),check:()=>ZC(`/api/system/update/check`,QC({})),update:e=>ZC(`/api/system/update/apply`,QC({pin:e})),setAutostart:(e,t)=>ZC(`/api/system/autostart`,QC({enabled:e,pin:t}))},ew=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function tw({api:e=$C,auto:t,onAuto:n,pollMs:r=0}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=(0,y.useRef)(!0),_=(0,y.useCallback)(async()=>{try{let t=await e.info();g.current&&a(t)}catch(e){g.current&&p(e.message)}},[e]);(0,y.useEffect)(()=>{g.current=!0,_();let e=r>0?setInterval(()=>void _(),r):null;return()=>{g.current=!1,e&&clearInterval(e)}},[_,r]);let v=async()=>{if(o){d(!0),p(null);try{let t=o.kind===`autostart`?await e.setAutostart(o.enabled,c):await e.update(c);if(!g.current)return;h(t.message),s(null),await _()}catch(e){g.current&&p(e.message)}finally{g.current&&(d(!1),l(``))}}},b=async()=>{d(!0),p(null),h(null);try{let t=await e.check();g.current&&a(e=>e&&{...e,update:t})}catch(e){g.current&&p(e.message)}finally{g.current&&d(!1)}};if(o)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:o.kind===`update`?`Enter your PIN to update Friend now. It restarts in a moment.`:o.enabled?`Enter your PIN to start Friend by itself when this computer starts.`:`Enter your PIN to stop starting Friend with this computer.`}),(0,w.jsx)(F,{pin:c,onChange:l,onSubmit:()=>!u&&c.length>=6&&void v()}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u||c.length<6,onClick:()=>void v(),children:`Continue`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{s(null),l(``),p(null)},children:`Back`})]})]});let S=i?.update;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Start with the computer`}),i&&(i.autostart.supported?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:i.autostart.enabled?`Friend starts by itself when you sign in to this computer, so you never have to start it after a restart.`:`Friend does not start by itself yet: after a restart you start it yourself.`}),(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,className:i.autostart.enabled?void 0:`primary`,disabled:u,onClick:()=>s({kind:`autostart`,enabled:!i.autostart.enabled}),children:i.autostart.enabled?`Stop starting Friend with this computer`:`Start Friend when this computer starts`})})]}):(0,w.jsx)(`p`,{className:`auth-note`,children:`Starting Friend by itself is not supported on this computer.`})),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Updates`}),i&&S&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`auth-note`,children:[`Friend `,i.version,`.`,` `,S.applying?`Updating Friend to ${S.latest??`the newest version`}…`:S.available?`Friend ${S.latest} is available.`:S.latest?`Up to date.`:`Not checked yet.`,S.checkedAt?` (looked at ${ew(S.checkedAt)})`:``]}),S.error&&(0,w.jsx)(`p`,{className:`auth-error`,children:S.error}),S.available&&!S.canApply&&!S.applying&&(0,w.jsx)(`p`,{className:`auth-note`,children:`This Friend is running in a terminal, so it cannot restart itself. Close it and run: friend upgrade`}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,disabled:u||S.applying,onClick:()=>void b(),children:`Check for updates`}),S.available&&S.canApply&&!S.applying&&(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:u,onClick:()=>s({kind:`update`}),children:`Update now`})]})]}),(0,w.jsxs)(`label`,{className:`settings-check`,style:{marginTop:10},children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked)}),` Update Friend by itself`]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Looks for a newer Friend when it starts, then every few hours, and installs it while Friend is not busy. Switch it off to update only when you press Update now (or run friend upgrade).`}),m&&(0,w.jsx)(`p`,{className:`auth-note`,children:m}),f&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:f})]})}var nw=[{id:`manual`,label:`Ask me (manual)`,note:`Friend asks before anything that changes your PC or leaves the safe zone. The most careful.`},{id:`edits`,label:`Auto-approve file work (edits)`,note:`Reading and writing files, and the sandboxed code runner, go ahead without asking. Commands still ask.`},{id:`auto`,label:`Auto-approve everything safe (auto)`,note:`Commands, files and tools go ahead without asking. The most convenient, and the most trust: Friend acts on its own.`}],rw=[{id:`auto`,label:`Automatic`,note:`Uses Docker when it is installed and running, otherwise the sandbox built into Friend. Nothing to install.`},{id:`sandbox`,label:`Built-in sandbox`,note:`Always the sandbox that comes with Friend: JavaScript, Python (standard library) and a basic shell, with no network and no access to your files.`},{id:`docker`,label:`Docker`,note:`Always a Docker container (needs Docker installed and running). A real shell and any program the container image has.`}],iw=[{id:`claude-code`,label:`Claude subscription (Claude Code)`,note:`Uses the Claude Code app you are signed in to. No API key.`},{id:`claude`,label:`Claude API key`,note:`Pay per use with an Anthropic API key.`},{id:`ollama`,label:`Local model (Ollama)`,note:`Runs on this PC. Free and private, but slower.`},{id:`openai`,label:`OpenAI-compatible server (OmniRoute, LM Studio…)`,note:`Any server that speaks the OpenAI chat API. OmniRoute is one address that routes to many models, many of them free.`}],aw={"voice.enabled":`Speech on/off`};function ow({label:e,children:t,hint:n}){return(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:e}),t,n&&(0,w.jsx)(`small`,{className:`auth-note`,children:n})]})}function sw({api:e=Wd,onClose:t,initialTab:n=`model`,preview:r=Gd,variant:i=`classic`}){let[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(n),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,S]=(0,y.useState)(!1),[C,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,ee]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,te]=(0,y.useState)(null),ne=(0,y.useRef)(!0);(0,y.useEffect)(()=>(ne.current=!0,e.get().then(e=>{ne.current&&(o(e),c(structuredClone(e)))}).catch(e=>ne.current&&k(e.message)),()=>{ne.current=!1}),[e]);let re=(e,n=!1,r={})=>i===`holo`?(0,w.jsx)(j,{label:`Settings`,title:r.title??ze.find(e=>e.id===l)?.label??`Settings`,page:r.page,help:r.help,onApply:r.onApply,onUndo:r.onUndo,dirty:r.dirty,busy:E,onDone:t,children:e}):(0,w.jsxs)(`div`,{className:`approval settings glass${n?` settings-wide`:``}`,role:`dialog`,"aria-label":`Settings`,style:{pointerEvents:`auto`},children:[(0,w.jsx)(`div`,{className:`approval-head`,children:(0,w.jsx)(`span`,{className:`approval-title`,children:`Settings`})}),e]});if(!s||!a)return re((0,w.jsxs)(w.Fragment,{children:[O?(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O}):(0,w.jsx)(`p`,{className:`auth-note`,children:`Loading…`}),(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,onClick:t,children:`Close`})})]}));let I=Kd(a,s,d,p,{brave:h,tavily:_}),ie=Object.keys(I).length>0,ae=s.memory,oe=ae?ae.saveDelaySec<10||ae.saveDelaySec>3600||ae.maxIndexChars<400||ae.maxIndexChars>6e3:!1,se=s.proactive?JS(s.proactive):!1,ce=s.office?sC(s.office).length>0:!1,le=(e,t,n)=>c({...s,[e]:{...s[e],[t]:n}}),L=s.look,ue=(e,t)=>{t&&(N(e),te(e===`main`?null:`The first time, the voice downloads (about 64 MB). Please wait…`),r(t).then(()=>ne.current&&te(`Playing…`)).catch(e=>ne.current&&te(e.message)).finally(()=>ne.current&&N(null)))},de=async t=>{k(null),D(!0);try{let n=await e.save(I,t);if(!ne.current)return;o(n.settings),c(structuredClone(n.settings)),f(``),m(``),g(``),v(``),S(!1);let r=I.voice&&I.voice.ttsVoice!==void 0,i=I.voice&&I.voice.sttModel!==void 0;ee(n.restart.length?`Saved. Restart Friend for: ${n.restart.map(e=>aw[e]??e).join(`, `)}.`:i?`Saved. The listening model is being downloaded in the background (the first time only); Friend keeps listening with the old one and tells you when the new one is ready.`:r?`Saved. The new voice is loading; you will get a message when it is ready (the first time it downloads about 60 MB).`:Hd(I)?`Saved. It is in use now.`:`Saved. Every open screen has changed.`)}catch(e){ne.current&&k(e.message)}finally{ne.current&&(D(!1),T(``))}};if(b)return re((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to save these changes.`}),(0,w.jsx)(F,{pin:C,onChange:T,onSubmit:()=>!E&&void de(C)}),O&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:E||C.length<6,onClick:()=>void de(C),children:`Save`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{S(!1),T(``),k(null)},children:`Back`})]})]}));let R=iw.find(e=>e.id===s.provider),z=e=>{let t=ze.findIndex(e=>e.id===l),n=e.key===`ArrowDown`||e.key===`ArrowRight`?(t+1)%ze.length:e.key===`ArrowUp`||e.key===`ArrowLeft`?(t+ze.length-1)%ze.length:e.key===`Home`?0:e.key===`End`?ze.length-1:-1;n<0||(e.preventDefault(),u(ze[n].id),document.getElementById(`settings-tab-${ze[n].id}`)?.focus())},B=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Where Friend thinks`}),(0,w.jsx)(ow,{label:`Model provider`,hint:R.note,children:(0,w.jsx)(`select`,{value:s.provider,onChange:e=>c({...s,provider:e.target.value}),children:iw.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),s.provider===`claude-code`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(ow,{label:`Claude model`,hint:`sonnet, haiku, opus, or a full model name`,children:[(0,w.jsx)(`input`,{list:`cc-models`,value:s.claudeCode.model,onChange:e=>le(`claudeCode`,`model`,e.target.value)}),(0,w.jsxs)(`datalist`,{id:`cc-models`,children:[(0,w.jsx)(`option`,{value:`sonnet`}),(0,w.jsx)(`option`,{value:`haiku`}),(0,w.jsx)(`option`,{value:`opus`})]})]}),(0,w.jsx)(ow,{label:`If Claude is unavailable`,hint:`For example when the plan's usage limit is reached.`,children:(0,w.jsxs)(`select`,{value:s.claudeCode.fallback,onChange:e=>le(`claudeCode`,`fallback`,e.target.value),children:[(0,w.jsx)(`option`,{value:`ollama`,children:`Answer with the local model (Ollama)`}),(0,w.jsx)(`option`,{value:`none`,children:`Show an error`})]})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.claudeCode.webSearch??!0,onChange:e=>le(`claudeCode`,`webSearch`,e.target.checked)}),` Let Claude search the web`]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`For prices, news and anything else that changes: Claude looks it up instead of answering from memory. Only searching, never opening pages on this PC.`}),(0,w.jsx)(ow,{label:`Claude Code command`,hint:`Leave as it is unless the program is somewhere else.`,children:(0,w.jsx)(`input`,{value:s.claudeCode.command,onChange:e=>le(`claudeCode`,`command`,e.target.value)})}),(0,w.jsx)(zC,{autoCompact:s.session?.autoCompact??!0,limit:s.session?.compactAtTokens??1e5,onChange:e=>c({...s,session:{autoCompact:!0,compactAtTokens:1e5,...s.session,...e}})})]}),s.provider===`claude`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(ow,{label:`Claude model`,children:(0,w.jsx)(`input`,{value:s.model,onChange:e=>c({...s,model:e.target.value})})}),(0,w.jsx)(ow,{label:`API key`,hint:a.apiKeySet?`A key is saved. Type a new one only to replace it.`:`No key saved yet.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:a.apiKeySet?`saved`:`sk-ant-…`,value:d,onChange:e=>f(e.target.value)})})]}),s.provider===`openai`&&s.openai&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(ow,{label:`Server address`,hint:`Ends in /v1. OmniRoute: http://localhost:20128/v1 (install it with npm install -g omniroute, then run omniroute).`,children:(0,w.jsx)(`input`,{value:s.openai.url,onChange:e=>c({...s,openai:{...s.openai,url:e.target.value}})})}),(0,w.jsx)(ow,{label:`Model`,hint:`The name that server knows. OmniRoute answers to auto.`,children:(0,w.jsx)(`input`,{value:s.openai.model,onChange:e=>c({...s,openai:{...s.openai,model:e.target.value}})})}),(0,w.jsx)(ow,{label:`API key`,hint:a.openai?.apiKeySet?`A key is saved. Type a new one only to replace it.`:`Leave empty if the server asks for none.`,children:(0,w.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:a.openai?.apiKeySet?`saved`:``,value:p,onChange:e=>m(e.target.value)})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.openai.vision,onChange:e=>c({...s,openai:{...s.openai,vision:e.target.checked}})}),` This model can look at pictures`]})]}),(s.provider===`ollama`||s.provider===`claude-code`&&s.claudeCode.fallback===`ollama`)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Local model (Ollama)`}),(0,w.jsx)(ow,{label:`Address`,children:(0,w.jsx)(`input`,{value:s.ollama.url,onChange:e=>le(`ollama`,`url`,e.target.value)})}),(0,w.jsx)(ow,{label:`Model`,children:(0,w.jsx)(`input`,{value:s.ollama.model,onChange:e=>le(`ollama`,`model`,e.target.value)})}),(0,w.jsx)(ow,{label:`Memory window (tokens)`,children:(0,w.jsx)(`input`,{type:`number`,min:1024,max:131072,step:1024,value:s.ollama.contextTokens,onChange:e=>le(`ollama`,`contextTokens`,Number(e.target.value))})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.ollama.vision,onChange:e=>le(`ollama`,`vision`,e.target.checked)}),` This model can look at pictures`]})]}),s.web&&a.web&&(0,w.jsx)(KC,{web:s.web,saved:a.web,braveKey:h,tavilyKey:_,onChange:e=>c({...s,web:{...s.web,...e}}),onBraveKey:g,onTavilyKey:v})]}),fe=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Speaking and listening`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.voice.speakTyped,onChange:e=>le(`voice`,`speakTyped`,e.target.checked)}),` Also speak the replies to typed messages`]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.voice.duck??!0,onChange:e=>le(`voice`,`duck`,e.target.checked)}),` Turn music and video down while I talk and while Friend speaks`]}),(0,w.jsx)(ow,{label:`Volume while talking: ${s.voice.duckPercent??25}%`,hint:`How loud music and video are then, compared with how loud you have them. They come back as they were when nothing is happening.`,children:(0,w.jsx)(`input`,{type:`range`,min:0,max:100,step:5,value:s.voice.duckPercent??25,disabled:s.voice.duck===!1,onChange:e=>le(`voice`,`duckPercent`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`Spoken language`,hint:`Leave empty to detect it by itself: best when you mix English, Hindi and Marathi. Or force one: en, hi, mr.`,children:(0,w.jsx)(`input`,{value:s.voice.language??``,maxLength:10,onChange:e=>le(`voice`,`language`,e.target.value.trim()===``?null:e.target.value.trim())})}),(0,w.jsx)(ow,{label:`Speaking voice`,hint:`Female or male. The first time a voice is used it downloads about 60 MB, then it works without internet.`,children:(0,w.jsxs)(`select`,{value:s.voice.ttsVoice,onChange:e=>le(`voice`,`ttsVoice`,e.target.value),children:[(0,w.jsx)(`optgroup`,{label:`Female`,children:Ku.filter(e=>e.gender===`female`).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,w.jsx)(`optgroup`,{label:`Male`,children:Ku.filter(e=>e.gender===`male`).map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,w.jsx)(`optgroup`,{label:`Original`,children:(0,w.jsxs)(`option`,{value:Yu.id,children:[Yu.name,` · `,Yu.accent,` · `,Yu.note]})}),!Xu(s.voice.ttsVoice)&&(0,w.jsx)(`optgroup`,{label:`Other`,children:(0,w.jsx)(`option`,{value:s.voice.ttsVoice,children:s.voice.ttsVoice})})]})}),(0,w.jsx)(ow,{label:`Hindi voice`,hint:`Reads Hindi (Devanagari) text; English words in the same sentence still use the voice above. The first time it downloads about 64 MB.`,children:(0,w.jsxs)(`select`,{value:s.voice.hindiVoice??``,onChange:e=>le(`voice`,`hindiVoice`,e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Same as the voice above`}),qu.map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.gender,e.note?` · ${e.note}`:``]},e.id))]})}),(0,w.jsx)(ow,{label:`Marathi voice`,hint:`Reads Marathi text. Friend tells Marathi from Hindi by the words used.`,children:(0,w.jsxs)(`select`,{value:s.voice.marathiVoice??``,onChange:e=>le(`voice`,`marathiVoice`,e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Same as the voice above`}),Ju.map(e=>(0,w.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,w.jsxs)(`div`,{className:`voice-hear`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,disabled:M!==null,onClick:()=>ue(`main`,s.voice.ttsVoice),children:M===`main`?`Loading the voice…`:`Hear it`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:M!==null||!s.voice.hindiVoice,onClick:()=>ue(`hindi`,s.voice.hindiVoice??``),children:M===`hindi`?`Loading the voice…`:`Hear the Hindi voice`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:M!==null||!s.voice.marathiVoice,onClick:()=>ue(`marathi`,s.voice.marathiVoice??``),children:M===`marathi`?`Loading the voice…`:`Hear the Marathi voice`}),P&&(0,w.jsx)(`small`,{className:`auth-note`,role:`status`,children:P})]}),(0,w.jsx)(ow,{label:`Listening model`,hint:`Bigger hears more accurately, from further away and in Hindi and Marathi, but is slower. It downloads once, in the background, and Friend keeps listening meanwhile. No restart.`,children:(0,w.jsxs)(`select`,{value:s.voice.sttModel,onChange:e=>le(`voice`,`sttModel`,e.target.value),children:[!Zu.some(e=>e.id===s.voice.sttModel)&&(0,w.jsx)(`option`,{value:s.voice.sttModel,children:s.voice.sttModel}),Zu.map(e=>(0,w.jsxs)(`option`,{value:e.id,children:[e.name,` · `,Qu(e.mb).replace(`about `,``),` · `,e.note]},e.id))]})}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Who is speaking`}),(0,w.jsx)(ow,{label:`"It is me" match level: ${s.voice.accept.toFixed(2)}`,hint:`Higher is stricter. Only matters after you enrolled your voice.`,children:(0,w.jsx)(`input`,{type:`range`,min:.3,max:.95,step:.01,value:s.voice.accept,onChange:e=>le(`voice`,`accept`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`"Ask for my PIN" level: ${s.voice.challenge.toFixed(2)}`,hint:`Voices between this and the level above must be confirmed with the PIN.`,children:(0,w.jsx)(`input`,{type:`range`,min:.2,max:.9,step:.01,value:s.voice.challenge,onChange:e=>le(`voice`,`challenge`,Number(e.target.value))})})]}),pe=(0,w.jsxs)(`div`,{className:`look-tab`,children:[(0,w.jsxs)(`div`,{className:`look-side`,children:[(0,w.jsx)(AS,{look:L}),(0,w.jsx)(`p`,{className:`auth-note`,children:`This is a live preview. Nothing changes on the screen until you save.`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>c({...s,look:{...zd}}),children:`Back to the default look`})]}),(0,w.jsxs)(`div`,{className:`look-controls`,children:[(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Themes`}),(0,w.jsx)(`div`,{className:`theme-grid`,role:`group`,"aria-label":`Themes`,children:$u.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`theme-card${DC(L,e)?` on`:``}`,"aria-pressed":DC(L,e),style:{"--swatch":e.accent},onClick:()=>c({...s,look:{...L,style:e.style,accent:e.accent,intensity:e.intensity}}),children:[(0,w.jsx)(`i`,{"aria-hidden":`true`}),(0,w.jsx)(`b`,{children:e.name}),(0,w.jsx)(`small`,{children:e.style})]},e.id))}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Shape`}),(0,w.jsx)(`div`,{className:`style-row`,role:`radiogroup`,"aria-label":`Style`,children:EC.map(e=>(0,w.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":L.style===e.id,className:`style-choice${L.style===e.id?` on`:``}`,onClick:()=>le(`look`,`style`,e.id),children:[(0,w.jsx)(`b`,{children:e.name}),(0,w.jsx)(`small`,{children:e.note})]},e.id))}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Colour and light`}),(0,w.jsxs)(`div`,{className:`swatch-row`,role:`group`,"aria-label":`Colour`,children:[TC.map(e=>(0,w.jsx)(`button`,{type:`button`,"aria-label":`Colour ${e}`,"aria-pressed":L.accent.toLowerCase()===e,className:`swatch${L.accent.toLowerCase()===e?` on`:``}`,style:{background:e},onClick:()=>le(`look`,`accent`,e)},e)),(0,w.jsxs)(`label`,{className:`swatch-custom`,children:[(0,w.jsx)(`span`,{children:`Other`}),(0,w.jsx)(`input`,{type:`color`,"aria-label":`Pick another colour`,value:L.accent,onChange:e=>le(`look`,`accent`,e.target.value.toLowerCase())})]})]}),(0,w.jsx)(ow,{label:`Brightness: ${Math.round(L.intensity*100)}%`,children:(0,w.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:L.intensity,onChange:e=>le(`look`,`intensity`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`Size: ${Math.round(L.size*100)}%`,hint:`How big it is in the middle of the screen.`,children:(0,w.jsx)(`input`,{type:`range`,min:.5,max:1.5,step:.05,value:L.size,onChange:e=>le(`look`,`size`,Number(e.target.value))})}),(0,w.jsx)(ow,{label:`Reaction to my voice: ${Math.round(L.reactivity*100)}%`,hint:`Low is calm, high moves a lot when anyone speaks.`,children:(0,w.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:L.reactivity,onChange:e=>le(`look`,`reactivity`,Number(e.target.value))})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:L.ambient,onChange:e=>le(`look`,`ambient`,e.target.checked)}),` Soft glow behind everything`]}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`Words on the screen`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:L.captions,onChange:e=>le(`look`,`captions`,e.target.checked)}),` Show the live words while Friend speaks`]}),(0,w.jsx)(ow,{label:`Caption size`,children:(0,w.jsxs)(`select`,{value:L.captionSize,disabled:!L.captions,onChange:e=>le(`look`,`captionSize`,e.target.value),children:[(0,w.jsx)(`option`,{value:`small`,children:`Small`}),(0,w.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,w.jsx)(`option`,{value:`large`,children:`Large`})]})}),(0,w.jsx)(`h4`,{className:`plugins-heading`,children:`What is on the screen`}),(0,w.jsx)(ow,{label:`Your name`,hint:`Shown on the badge in the corner, next to the shield, while you are signed in. Empty shows Owner.`,children:(0,w.jsx)(`input`,{value:s.ownerName??``,maxLength:40,placeholder:`Owner`,onChange:e=>c({...s,ownerName:e.target.value})})}),(0,w.jsx)(ow,{label:`View`,hint:`Minimal: only the voice presence. Companion: plus a status line and a clock. Workspace: also the chat and the schedule. Drag any panel to move it.`,children:(0,w.jsxs)(`select`,{value:s.view,onChange:e=>c({...s,view:e.target.value}),children:[(0,w.jsx)(`option`,{value:`minimal`,children:`Minimal`}),(0,w.jsx)(`option`,{value:`companion`,children:`Companion`}),(0,w.jsx)(`option`,{value:`workspace`,children:`Workspace`})]})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:L.aiMayChange,onChange:e=>le(`look`,`aiMayChange`,e.target.checked)}),` Let the AI change the shape, colour and brightness to suit a topic`]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Off keeps exactly the look you chose. You can still ask it to change the look yourself.`})]})]}),me=s.approvals??`manual`,he=e=>c({...s,phoneApprovals:{...s.phoneApprovals,...e}}),ge=(0,w.jsxs)(`div`,{className:`settings-section`,role:`radiogroup`,"aria-label":`How much Friend asks before acting`,children:[(0,w.jsx)(`h3`,{children:`How much should Friend ask?`}),nw.map(e=>(0,w.jsxs)(`label`,{className:`settings-check`,style:{alignItems:`flex-start`},children:[(0,w.jsx)(`input`,{type:`radio`,name:`approvals`,value:e.id,checked:me===e.id,onChange:()=>c({...s,approvals:e.id})}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.label}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:e.note})]})]},e.id)),(0,w.jsx)(`small`,{className:`auth-note`,children:`Whatever you pick, these still ask: risky commands (they need your PIN), the camera, adding connectors or plugins, and anything in Friend's own data folder. Changing this needs your PIN.`}),(0,w.jsxs)(`div`,{className:`settings-section`,role:`radiogroup`,"aria-label":`Where code runs`,children:[(0,w.jsx)(`h3`,{children:`Where does the code Friend writes run?`}),rw.map(e=>(0,w.jsxs)(`label`,{className:`settings-check`,style:{alignItems:`flex-start`},children:[(0,w.jsx)(`input`,{type:`radio`,name:`codeRunner`,value:e.id,checked:(s.codeRunner??`auto`)===e.id,onChange:()=>c({...s,codeRunner:e.id})}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.label}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:e.note})]})]},e.id))]}),(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`The eye`,children:[(0,w.jsx)(`h3`,{children:`The eye: let Friend look by itself`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.eye?.on??!1,onChange:e=>c({...s,eye:{autoOffMinutes:120,...s.eye,on:e.target.checked}})}),(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:`Eye on`}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`auth-note`,children:`While it is on, Friend uses the camera whenever it needs to (and when in doubt) without asking each time, but only when you talk to it at this screen. Never from Telegram, Alexa, guests or workers. The camera light shows whenever the camera is open. Switching on needs your PIN; switching off does not. It is always off after a restart or when you sign out.`})]})]}),(0,w.jsx)(ow,{label:`Switch off by itself after (minutes, 0 = never)`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:1440,value:s.eye?.autoOffMinutes??120,onChange:e=>c({...s,eye:{on:s.eye?.on??!1,autoOffMinutes:Math.min(1440,Math.max(0,Math.round(Number(e.target.value)||0)))}})})}),(0,w.jsx)(`small`,{className:`auth-note`,children:`Pictures go to the AI model you chose. With Claude they are sent to Anthropic; with a local Ollama vision model they stay on this PC. Nothing from a picture is kept.`})]}),(0,w.jsx)(UC,{}),s.phoneApprovals&&(0,w.jsxs)(`div`,{className:`settings-section`,"aria-label":`Asking on your phone`,children:[(0,w.jsx)(`h3`,{children:`When you are away from the screen`}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.phoneApprovals.enabled,onChange:e=>he({enabled:e.target.checked})}),(0,w.jsx)(`span`,{children:`Ask me on my phone (Telegram or WhatsApp, once linked)`})]}),(0,w.jsx)(ow,{label:`Ask on`,children:(0,w.jsxs)(`select`,{value:s.phoneApprovals.channel,onChange:e=>he({channel:e.target.value}),children:[(0,w.jsx)(`option`,{value:`auto`,children:`Telegram, else WhatsApp`}),(0,w.jsx)(`option`,{value:`telegram`,children:`Telegram only`}),(0,w.jsx)(`option`,{value:`whatsapp`,children:`WhatsApp only`})]})}),(0,w.jsx)(ow,{label:`Group questions that pile up (seconds)`,hint:`0 to 30. While one question waits on your phone, newer ones are gathered for this long and sent as one message, so they come together. 0 sends each by itself.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:30,value:s.phoneApprovals.batchSec,onChange:e=>he({batchSec:Math.min(30,Math.max(0,Math.round(Number(e.target.value)||0)))})})}),(0,w.jsx)(ow,{label:`Wait for the screen first (seconds)`,hint:`0 to 110. Used when a screen is open; with none open the phone is asked at once.`,children:(0,w.jsx)(`input`,{type:`number`,min:0,max:110,value:s.phoneApprovals.delaySec,onChange:e=>he({delaySec:Math.min(110,Math.max(0,Math.round(Number(e.target.value)||0)))})})}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.phoneApprovals.buttons,onChange:e=>he({buttons:e.target.checked})}),(0,w.jsx)(`span`,{children:`Telegram: show Allow and Deny buttons (otherwise reply YES or NO)`})]}),(0,w.jsxs)(`label`,{className:`settings-check`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:s.phoneApprovals.allowRisky,onChange:e=>he({allowRisky:e.target.checked})}),(0,w.jsx)(`span`,{children:`Also let the phone answer the camera and the Office's requests`})]}),(0,w.jsx)(`small`,{className:`auth-note`,children:`With no screen open the question goes to your phone at once; with one open, after the wait above. Whichever you answer first wins. Anything that needs your PIN is never asked on the phone, and "always allow" is only on the screen.`})]})]}),V=(0,w.jsxs)(w.Fragment,{children:[l===`model`&&B,l===`voice`&&fe,l===`look`&&pe,l===`approvals`&&ge,l===`trading`&&(0,w.jsx)(vC,{level:s.trading?.level??`read`}),l===`widgets`&&s.music&&s.hud&&(0,w.jsx)(wC,{music:s.music,hud:s.hud,onMusic:e=>c({...s,music:{...s.music,...e}}),onHud:e=>c({...s,hud:{...s.hud,...e}})}),l===`system`&&(0,w.jsx)(tw,{auto:s.updates?.auto??!0,onAuto:e=>c({...s,updates:{auto:e}})}),l===`office`&&s.office&&(0,w.jsx)(mC,{office:s.office,onChange:e=>c({...s,office:{...s.office,...e}})}),l===`memory`&&s.memory&&(0,w.jsx)($S,{memory:s.memory,onChange:e=>c({...s,memory:{...s.memory,...e}})}),l===`heartbeat`&&s.proactive&&(0,w.jsx)(YS,{proactive:s.proactive,onChange:e=>c({...s,proactive:{...s.proactive,...e}})}),l===`soul`&&(0,w.jsx)(XC,{}),l===`audit`&&(0,w.jsx)(US,{...s.audit?{settings:s.audit,onSettings:e=>c({...s,audit:{...s.audit,...e}})}:{}}),l===`usage`&&(0,w.jsx)(PC,{}),l===`security`&&(0,w.jsx)(gC,{})]}),_e=()=>{ce||oe||se||(ee(null),k(null),Hd(I)?S(!0):de())},ve=()=>{c(structuredClone(a)),f(``),m(``),g(``),v(``)},ye=(0,w.jsxs)(w.Fragment,{children:[A&&!ie&&(0,w.jsx)(`p`,{className:`auth-note`,children:A}),O&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O})]});if(i===`holo`){let e=ze.findIndex(e=>e.id===l),t=e=>u(ze[(e+ze.length)%ze.length].id);return re((0,w.jsxs)(w.Fragment,{children:[V,ye]}),!0,{title:ze[e].label,page:{index:e,total:ze.length,onPrev:()=>t(e-1),onNext:()=>t(e+1)},dirty:ie,onApply:_e,onUndo:ve,help:(0,w.jsxs)(w.Fragment,{children:[`Fill in the settings and press `,(0,w.jsx)(`b`,{children:`Apply`}),` to save them. Network, folders and safety rules are not here on purpose: change those in the terminal with friend config set.`]})})}return re((0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`settings-layout`,children:[(0,w.jsx)(`div`,{className:`settings-tabs`,role:`tablist`,"aria-label":`Settings sections`,"aria-orientation":`vertical`,onKeyDown:z,children:ze.map(e=>(0,w.jsxs)(`button`,{id:`settings-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":l===e.id,"aria-controls":`settings-panel-${e.id}`,tabIndex:l===e.id?0:-1,className:`settings-tab${l===e.id?` on`:``}`,onClick:()=>u(e.id),children:[(0,w.jsx)(`b`,{children:e.label}),(0,w.jsx)(`small`,{children:e.note})]},e.id))}),(0,w.jsx)(`div`,{className:`settings-body`,role:`tabpanel`,id:`settings-panel-${l}`,"aria-labelledby":`settings-tab-${l}`,children:V})]}),A&&!ie&&(0,w.jsx)(`p`,{className:`auth-note`,children:A}),O&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:O}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:!ie||E||ce||oe||se,onClick:_e,children:ie&&!Hd(I)?`Save`:`Save…`}),ie&&(0,w.jsx)(`button`,{type:`button`,style:x,onClick:ve,children:`Undo changes`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:t,children:`Close`})]}),(0,w.jsx)(`p`,{className:`auth-note`,children:`Network, folders and safety rules are not here on purpose. Change those in the terminal: friend config set.`})]}),!0)}var cw=e=>{try{return Gu(e)}catch{return{label:e.id.slice(0,24)}}};function lw({chips:e,onRestore:t,panelsOpen:n}){if(e.length===0)return null;let r={left:n?.tasks?`30%`:`24%`,right:n?.chat?`32%`:`24%`};return(0,w.jsx)(`nav`,{className:`chip-strip`,"aria-label":`Put away`,style:r,children:e.map(e=>{let{label:n,value:r}=cw(e);return(0,w.jsxs)(`button`,{type:`button`,className:`chip`,"data-chip":e.id,"aria-label":`Show ${n}`,title:`Show ${n}`,onClick:()=>t(e.id),children:[(0,w.jsx)(`span`,{className:`chip-label`,children:n}),r!==void 0&&(0,w.jsx)(`span`,{className:`chip-value`,children:r})]},e.id)})})}var uw=e=>e instanceof HTMLElement&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable);function dw({onSend:e,requestOpen:t,slash:n,onOpenChange:r,hud:i}){let a=!!i,[o,s]=(0,y.useState)(!1),c=(0,y.useRef)(r);c.current=r,(0,y.useEffect)(()=>c.current?.(!a&&o),[o,a]);let[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(0),p=(0,y.useRef)(null);if((0,y.useEffect)(()=>{t<=0||(a?p.current?.focus():s(!0))},[t]),(0,y.useEffect)(()=>{let e=e=>{!a&&o||uw(e.target)||e.ctrlKey||e.metaKey||e.altKey||e.code!==`Space`&&e.key!==` `&&e.key.length===1&&(e.preventDefault(),u(e.key),f(0),a?p.current?.focus():s(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,a]),(0,y.useEffect)(()=>{o&&p.current?.focus()},[o]),!o&&!a)return null;let m=n?L(n.commands,l):[],h=m[Math.min(d,Math.max(m.length-1,0))],g=()=>{u(``),f(0),s(!1),a&&p.current?.blur()},_=()=>{let t=l.trim();if(n&&le(t)){let e=/^\/\S*\s/.test(t);n.run(!e&&h?`/${h.name}`:t)}else t&&e(de(t));g()};return(0,w.jsxs)(`form`,{className:`command-bar${a?` command-bar-hud`:``}`,style:i?.style,onSubmit:e=>{e.preventDefault(),_()},children:[m.length>0&&(0,w.jsx)(`ul`,{className:`slash-list`,role:`listbox`,"aria-label":`Commands`,children:m.map((e,t)=>(0,w.jsxs)(`li`,{role:`option`,"aria-selected":e===h,className:e===h?`on`:void 0,onMouseDown:n=>{n.preventDefault(),u(`/${e.name} `),p.current?.focus(),f(t)},children:[(0,w.jsxs)(`b`,{children:[`/`,e.name]}),e.usage&&(0,w.jsx)(`i`,{children:e.usage}),(0,w.jsx)(`span`,{children:e.description})]},e.name))}),(0,w.jsx)(`input`,{ref:p,...a?{"data-space-talks":``}:{},"aria-label":`Message`,value:l,placeholder:i?`▸ ask ${i.name} anything…`:`Talk to me… or type / for commands`,autoComplete:`off`,onChange:e=>{u(e.target.value),f(0)},onKeyDown:e=>{e.key===`Escape`?(e.stopPropagation(),g()):m.length>0&&(e.key===`ArrowDown`||e.key===`ArrowUp`)?(e.preventDefault(),f(t=>(t+(e.key===`ArrowDown`?1:m.length-1))%m.length)):e.key===`Tab`&&h&&(e.preventDefault(),u(`/${h.name} `))}}),(0,w.jsx)(`button`,{type:`submit`,"aria-label":`Send`,children:`↵`})]})}var fw=1600,pw=.31,mw=[-90,-30,30,150,210],hw=120,gw=12;function _w(e,t){return Math.min(e/fw,t/900)}function vw(e,t,n,r,i){let a=_w(r,i);return{x:bw((e===`left`?0:e===`right`?r-fw*a:(r-fw*a)/2)+t*a),y:bw((i-900*a)/2+n*a)}}function yw(e,t){return Math.max(hw,300*_w(e,t))}var bw=e=>Math.round(e*100)/100;function xw(e,t,n){let r=Math.max(0,Math.min(gw,Math.floor(e))),i=yw(t,n);return Array.from({length:r},(e,a)=>{let o=r<=mw.length?mw[a]:-90+a*360/r,s=o*Math.PI/180;return{x:bw(t/2+i*Math.cos(s)),y:bw(n/2+i*Math.sin(s)),angle:o}})}function Sw(e,t){return{cx:e/2,cy:t/2,r:yw(e,t)+40}}function Cw(e,t){return e<=899?`compact`:`orbit`}var ww={width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0},Tw=(e,t)=>e===`listening`?t?`Listening… tap to send`:`Listening… let go to send`:e===`transcribing`?`Understanding…`:e===`speaking`?`Tap to talk over me`:`Hold to talk, or tap once`;function Ew({voice:e,mode:t,onType:n,onMenu:r}){let i=(0,y.useRef)(null),a=(0,y.useRef)(!1),[o,s]=(0,y.useState)(!1),c=e=>{a.current=e,s(e)},l=(0,y.useRef)(t);l.current=t,(0,y.useEffect)(()=>{t!==`listening`&&!i.current&&c(!1)},[t]);let u=t=>{if((t.pointerType!==`mouse`||t.button===0)&&!i.current){if(a.current&&l.current===`listening`){c(!1),e.pressEnd();return}c(!1),i.current={at:Date.now(),id:t.pointerId};try{t.currentTarget.setPointerCapture?.(t.pointerId)}catch{}e.pressStart()}},d=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,Date.now()-n.at>=450?e.pressEnd():c(!0))},f=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,c(!1),e.blur?.())},p=t===`listening`;return(0,w.jsxs)(`div`,{className:`touch-controls`,"data-testid":`touch-controls`,children:[(0,w.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Open the menu`,onClick:r,children:(0,w.jsx)(`svg`,{...ww,children:(0,w.jsx)(`path`,{d:`M4 7h16M4 12h16M4 17h16`})})}),(0,w.jsxs)(`div`,{className:`touch-talk`,children:[(0,w.jsx)(`button`,{type:`button`,className:`touch-mic${p?` on`:``}`,"aria-label":`Talk to Friend`,"aria-pressed":p,onPointerDown:u,onPointerUp:d,onPointerCancel:f,onContextMenu:e=>e.preventDefault(),children:(0,w.jsxs)(`svg`,{...ww,width:30,height:30,children:[(0,w.jsx)(`rect`,{x:`9`,y:`3`,width:`6`,height:`11`,rx:`3`}),(0,w.jsx)(`path`,{d:`M5 11a7 7 0 0 0 14 0M12 18v3`})]})}),(0,w.jsx)(`span`,{className:`touch-hint`,"aria-live":`polite`,children:Tw(t,o)})]}),(0,w.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Type a message`,onClick:n,children:(0,w.jsxs)(`svg`,{...ww,children:[(0,w.jsx)(`rect`,{x:`3`,y:`6`,width:`18`,height:`12`,rx:`2`}),(0,w.jsx)(`path`,{d:`M7 10h.01M11 10h.01M15 10h.01M7 14h10`})]})})]})}function Dw(e,t){this.v=e,this.k=t}function Ow(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function kw(e){if(Array.isArray(e))return e}function Aw(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function jw(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4392
4392
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Mw(e,t){return kw(e)||Aw(e,t)||Nw(e,t)||jw()}function Nw(e,t){if(e){if(typeof e==`string`)return Ow(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ow(e,t):void 0}}function Pw(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof Dw;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}Pw.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},Pw.prototype.next=function(e){return this._invoke(`next`,e)},Pw.prototype.throw=function(e){return this._invoke(`throw`,e)},Pw.prototype.return=function(e){return this._invoke(`return`,e)};var Fw=Object.entries,Iw=Object.setPrototypeOf,Lw=Object.isFrozen,Rw=Object.getPrototypeOf,zw=Object.getOwnPropertyDescriptor,Bw=Object.freeze,Vw=Object.seal,Hw=Object.create,Uw=typeof Reflect<`u`&&Reflect,Ww=Uw.apply,Gw=Uw.construct;Bw||=function(e){return e},Vw||=function(e){return e},Ww||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},Gw||=function(e){return new e(...[...arguments].slice(1))};var Kw=fT(Array.prototype.forEach);Array.prototype.indexOf;var qw=fT(Array.prototype.lastIndexOf),Jw=fT(Array.prototype.pop),Yw=fT(Array.prototype.push);Array.prototype.slice;var Xw=fT(Array.prototype.splice),Zw=Array.isArray,Qw=fT(String.prototype.toLowerCase),$w=fT(String.prototype.toString),eT=fT(String.prototype.match),tT=fT(String.prototype.replace),nT=fT(String.prototype.indexOf),rT=fT(String.prototype.trim),iT=fT(Number.prototype.toString),aT=fT(Boolean.prototype.toString),oT=typeof BigInt>`u`?null:fT(BigInt.prototype.toString),sT=typeof Symbol>`u`?null:fT(Symbol.prototype.toString),cT=fT(Object.prototype.hasOwnProperty),lT=fT(Object.prototype.toString),uT=fT(RegExp.prototype.test),dT=pT(TypeError);function fT(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return Ww(e,t,n)}}function pT(e){return function(){return Gw(e,[...arguments])}}function mT(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Qw;if(Iw&&Iw(e,null),!Zw(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(Lw(t)||(t[r]=e),i=e)}e[i]=!0}return e}function hT(e){for(let t=0;t<e.length;t++)cT(e,t)||(e[t]=null);return e}function gT(e){let t=Hw(null);for(let r of Fw(e)){var n=Mw(r,2);let i=n[0],a=n[1];cT(e,i)&&(t[i]=Zw(a)?hT(a):a&&typeof a==`object`&&a.constructor===Object?gT(a):a)}return t}function _T(e){switch(typeof e){case`string`:return e;case`number`:return iT(e);case`boolean`:return aT(e);case`bigint`:return oT?oT(e):`0`;case`symbol`:return sT?sT(e):`Symbol()`;case`undefined`:return lT(e);case`function`:case`object`:{if(e===null)return lT(e);let t=e,n=vT(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:lT(e)}return lT(e)}default:return lT(e)}}function vT(e,t){for(;e!==null;){let n=zw(e,t);if(n){if(n.get)return fT(n.get);if(typeof n.value==`function`)return fT(n.value)}e=Rw(e)}function n(){return null}return n}function yT(e){try{return uT(e,``),!0}catch{return!1}}var bT=Bw(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),xT=Bw(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),ST=Bw([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),CT=Bw([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),wT=Bw(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),TT=Bw([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),ET=Bw([`#text`]),DT=Bw(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),OT=Bw(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),kT=Bw(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),AT=Bw([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),jT=Vw(/{{[\w\W]*|^[\w\W]*}}/g),MT=Vw(/<%[\w\W]*|^[\w\W]*%>/g),NT=Vw(/\${[\w\W]*/g),PT=Vw(/^data-[\-\w.\u00B7-\uFFFF]+$/),FT=Vw(/^aria-[\-\w]+$/),IT=Vw(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),LT=Vw(/^(?:\w+script|data):/i),RT=Vw(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),zT=Vw(/^html$/i),BT=Vw(/^[a-z][.\w]*(-[.\w]+)+$/i),VT=Vw(/<[/\w!]/g),HT=Vw(/<[/\w]/g),UT=Vw(/<\/no(script|embed|frames)/i),WT=Vw(/\/>/i),GT={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},KT=[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`],qT=Bw(mT({},KT)),JT=function(){let e={};return Kw(KT,t=>{e[t]=Vw(RegExp(`</`+t+`(?=[\\t\\n\\f\\r />])`,`i`))}),Bw(e)}(),YT=function(){return typeof window>`u`?null:window},XT=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},ZT=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},QT=function(e,t,n,r){return cT(e,t)&&Zw(e[t])?mT(r.base?gT(r.base):{},e[t],r.transform):n},$T=function(e,t,n){let r=cT(e,t)?e[t]:void 0;return r&&typeof r==`object`?gT(r):n()};function eE(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:YT(),t=e=>eE(e);if(t.version=`3.4.16`,t.removed=[],!e||!e.document||e.document.nodeType!==GT.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=vT(d,`cloneNode`),p=vT(d,`remove`),m=vT(d,`removeAttributeNode`),h=vT(d,`nextSibling`),g=vT(d,`childNodes`),_=vT(d,`parentNode`),v=vT(d,`shadowRoot`),y=vT(d,`attributes`),b=o&&o.prototype?vT(o.prototype,`nodeType`):null,x=o&&o.prototype?vT(o.prototype,`nodeName`):null,S=o&&o.prototype?vT(o.prototype,`ownerDocument`):null,C=function(e){return b?b(e):e.nodeType},w=function(e){return x?x(e):e.nodeName};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let T,E=``,D,O=!1,k=0,A=function(){if(k>0)throw dT(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},j=function(e){A(),k++;try{return T.createHTML(e)}finally{k--}},ee=function(e){A(),k++;try{return T.createScriptURL(e)}finally{k--}},M=function(){return O||=(D=XT(u,i),!0),D},N=n,P=N.implementation,F=N.createNodeIterator,te=N.createDocumentFragment,ne=N.getElementsByTagName,re=r.importNode,I=ZT();t.isSupported=typeof Fw==`function`&&typeof _==`function`&&P&&P.createHTMLDocument!==void 0;let ie=jT,ae=MT,oe=NT,se=PT,ce=FT,le=LT,L=RT,ue=BT,de=IT,R=null,z=mT({},[...bT,...xT,...ST,...wT,...ET]),B=null,fe=mT({},[...DT,...OT,...kT,...AT]),pe=Object.seal(Hw(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),me=null,he=null,ge=Object.seal(Hw(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),V=!0,_e=!0,ve=!1,ye=!0,H=!1,be=!0,U=!1,xe=!1,Se=null,Ce=null,we=!1,Te=!1,Ee=!1,De=!1,Oe=!0,ke=!1,Ae=`user-content-`,je=!0,Me=!1,Ne={},Pe=null,Fe=mT({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Ie=null,Le=mT({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Re=null,ze=mT({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Be=`http://www.w3.org/1998/Math/MathML`,Ve=`http://www.w3.org/2000/svg`,He=`http://www.w3.org/1999/xhtml`,Ue=He,We=!1,Ge=null,Ke=mT({},[Be,Ve,He],$w),qe=Bw([`mi`,`mo`,`mn`,`ms`,`mtext`]),Je=mT({},qe),Ye=Bw([`annotation-xml`]),Xe=mT({},Ye),Ze=mT({},[`title`,`style`,`font`,`a`,`script`]),Qe=null,$e=[`application/xhtml+xml`,`text/html`],et=null,tt=null,nt=n.createElement(`form`),rt=function(e){return e instanceof RegExp||e instanceof Function},it=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(tt&&tt===e)return;(!e||typeof e!=`object`)&&(e={}),e=gT(e),Qe=$e.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,et=Qe===`application/xhtml+xml`?$w:Qw,R=QT(e,`ALLOWED_TAGS`,z,{transform:et}),B=QT(e,`ALLOWED_ATTR`,fe,{transform:et}),Ge=QT(e,`ALLOWED_NAMESPACES`,Ke,{transform:$w}),Re=QT(e,`ADD_URI_SAFE_ATTR`,ze,{transform:et,base:ze}),Ie=QT(e,`ADD_DATA_URI_TAGS`,Le,{transform:et,base:Le}),Pe=QT(e,`FORBID_CONTENTS`,Fe,{transform:et}),me=QT(e,`FORBID_TAGS`,gT({}),{transform:et}),he=QT(e,`FORBID_ATTR`,gT({}),{transform:et}),Ne=cT(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?gT(e.USE_PROFILES):e.USE_PROFILES:!1,V=e.ALLOW_ARIA_ATTR!==!1,_e=e.ALLOW_DATA_ATTR!==!1,ve=e.ALLOW_UNKNOWN_PROTOCOLS||!1,ye=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,H=e.SAFE_FOR_TEMPLATES||!1,be=e.SAFE_FOR_XML!==!1,U=e.WHOLE_DOCUMENT||!1,Te=e.RETURN_DOM||!1,Ee=e.RETURN_DOM_FRAGMENT||!1,De=e.RETURN_TRUSTED_TYPE||!1,we=e.FORCE_BODY||!1,Oe=e.SANITIZE_DOM!==!1,ke=e.SANITIZE_NAMED_PROPS||!1,je=e.KEEP_CONTENT!==!1,Me=e.IN_PLACE||!1,de=yT(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:IT,Ue=typeof e.NAMESPACE==`string`?e.NAMESPACE:He,Je=$T(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>mT({},qe)),Xe=$T(e,`HTML_INTEGRATION_POINTS`,()=>mT({},Ye));let t=$T(e,`CUSTOM_ELEMENT_HANDLING`,()=>Hw(null));if(pe=Hw(null),cT(t,`tagNameCheck`)&&rt(t.tagNameCheck)&&(pe.tagNameCheck=t.tagNameCheck),cT(t,`attributeNameCheck`)&&rt(t.attributeNameCheck)&&(pe.attributeNameCheck=t.attributeNameCheck),cT(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(pe.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),Vw(pe),H&&(_e=!1),Ee&&(Te=!0),Ne&&(R=mT({},ET),B=Hw(null),Ne.html===!0&&(mT(R,bT),mT(B,DT)),Ne.svg===!0&&(mT(R,xT),mT(B,OT),mT(B,AT)),Ne.svgFilters===!0&&(mT(R,ST),mT(B,OT),mT(B,AT)),Ne.mathMl===!0&&(mT(R,wT),mT(B,kT),mT(B,AT))),ge.tagCheck=null,ge.attributeCheck=null,cT(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?ge.tagCheck=e.ADD_TAGS:Zw(e.ADD_TAGS)&&(R===z&&(R=gT(R)),mT(R,e.ADD_TAGS,et))),cT(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?ge.attributeCheck=e.ADD_ATTR:Zw(e.ADD_ATTR)&&(B===fe&&(B=gT(B)),mT(B,e.ADD_ATTR,et))),cT(e,`ADD_FORBID_CONTENTS`)&&Zw(e.ADD_FORBID_CONTENTS)&&(Pe===Fe&&(Pe=gT(Pe)),mT(Pe,e.ADD_FORBID_CONTENTS,et)),je&&(R[`#text`]=!0),U&&mT(R,[`html`,`head`,`body`]),R.table&&(mT(R,[`tbody`]),delete me.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw dT(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw dT(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=T;T=e.TRUSTED_TYPES_POLICY;try{E=j(``)}catch(e){throw T=t,e}}else e.TRUSTED_TYPES_POLICY===null?(T=void 0,E=``):(T===void 0&&(T=M()),T&&typeof E==`string`&&(E=j(``)));Bw&&Bw(e),tt=e},at=mT({},[...xT,...ST,...CT]),ot=mT({},[...wT,...TT]),st=function(e,t,n){return t.namespaceURI===He?e===`svg`:t.namespaceURI===Be?e===`svg`&&(n===`annotation-xml`||Je[n]):!!at[e]},ct=function(e,t,n){return t.namespaceURI===He?e===`math`:t.namespaceURI===Ve?e===`math`&&Xe[n]:!!ot[e]},lt=function(e,t,n){return t.namespaceURI===Ve&&!Xe[n]||t.namespaceURI===Be&&!Je[n]?!1:!ot[e]&&(Ze[e]||!at[e])},ut=function(e){let t=_(e);(!t||!t.tagName)&&(t={namespaceURI:Ue,tagName:`template`});let n=Qw(e.tagName),r=Qw(t.tagName);return Ge[e.namespaceURI]?e.namespaceURI===Ve?st(n,t,r):e.namespaceURI===Be?ct(n,t,r):e.namespaceURI===He?lt(n,t,r):!!(Qe===`application/xhtml+xml`&&Ge[e.namespaceURI]):!1},dt=function(e){Yw(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw dT(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},ft=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},pt=function(e){gt(e);let t=g(e);if(t){let e=[];Kw(t,t=>{Yw(e,t)}),Kw(e,e=>{try{p(e)}catch{}})}let n=y(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&ft(e,r,i)}},mt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}Yw(t.removed,{attribute:r||null,from:n});try{r?m(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(Te||Ee)try{dt(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},ht=function(e){let t=y(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||B[et(i)]||ft(e,r,i)}},gt=function(e){let t=[e];for(;t.length>0;){let e=t.pop();C(e)===GT.element&&ht(e);let n=g(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},_t=function(e,t){return be?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},vt=function(e){if(!be)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=C(e);if(n===GT.processingInstruction||n===GT.comment&&uT(HT,e.data)){try{p(e)}catch{}continue}if(n===GT.element){let t=e,n=et(w(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&_t(`for`,n)&&t.removeAttribute(`for`)}catch{}}let r=g(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},yt=function(e){let t=null,r=null;if(we)e=`<remove></remove>`+e;else{let t=eT(e,/^[\r\n\t ]+/);r=t&&t[0]}Qe===`application/xhtml+xml`&&Ue===He&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=T?j(e):e;if(Ue===He)try{t=new l().parseFromString(i,Qe)}catch{}if(!t||!t.documentElement){t=P.createDocument(Ue,`template`,null);try{t.documentElement.innerHTML=We?E:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Ue===He?ne.call(t,U?`html`:`body`)[0]:U?t.documentElement:a},bt=function(e){let t=S?S(e):e.ownerDocument;return F.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},xt=function(e){return e=tT(e,ie,` `),e=tT(e,ae,` `),e=tT(e,oe,` `),e},St=function(e){e.normalize();let t=S?S(e):e.ownerDocument,n=F.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=xt(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&Kw(i,e=>{wt(e.content)&&St(e.content)})},Ct=function(e){let t=x?x(e):null;return typeof t!=`string`||et(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==y(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==b(e)||e.childNodes!==g(e)},wt=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return b(e)===GT.documentFragment}catch{return!1}},Tt=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return typeof b(e)==`number`}catch{return!1}};function Et(e,n,r){e.length!==0&&Kw(e,e=>{e.call(t,n,r,tt)})}let Dt=function(e,t){return!!(be&&e.hasChildNodes()&&!Tt(e.firstElementChild)&&uT(VT,e.textContent)&&uT(VT,e.innerHTML)||be&&e.namespaceURI===He&&qT[t]&&(Tt(e.firstElementChild)||typeof e.textContent==`string`&&uT(JT[t],e.textContent))||e.nodeType===GT.processingInstruction||be&&e.nodeType===GT.comment&&uT(HT,e.data))},Ot=function(e,t){return e instanceof RegExp?uT(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},kt=function(e,t,n){if(!me[t]&&Ft(t)&&Ot(pe.tagNameCheck,t))return!1;if(je&&!Pe[t]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return dt(e),!0},At=function(e,t,n,r){return e.length===0?t:t===n||t===r?gT(t):t},jt=function(e,t){return e===t||_(e)!==null?!1:(Me&&gt(e),!0)},Mt=function(e,n){if(Et(I.beforeSanitizeElements,e,null),jt(e,n))return!0;if(Ct(e))return dt(e),!0;let r=et(w(e));if(R=At(I.uponSanitizeElement,R,z,Se),Et(I.uponSanitizeElement,e,{tagName:r,allowedTags:R}),jt(e,n))return!0;if(Dt(e,r))return dt(e),!0;if(me[r]||!(ge.tagCheck instanceof Function&&ge.tagCheck(r))&&!R[r]){let t=kt(e,r,n);return t===!1&&(Et(I.afterSanitizeElements,e,null),jt(e,n))?!0:t}if(C(e)===GT.element&&!ut(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&uT(UT,e.innerHTML))return dt(e),!0;if(H&&e.nodeType===GT.text){let n=xt(e.textContent);e.textContent!==n&&(Yw(t.removed,{element:e.cloneNode()}),e.textContent=n)}return Et(I.afterSanitizeElements,e,null),jt(e,n)},Nt=function(e,t,r){if(he[t]||_t(t,e)||Oe&&(t===`id`||t===`name`)&&(r in n||r in nt))return!1;let i=B[t]||ge.attributeCheck instanceof Function&&ge.attributeCheck(t,e);return _e&&uT(se,t)||V&&uT(ce,t)?!0:i?Re[t]||uT(de,tT(r,L,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&nT(r,`data:`)===0&&Ie[e]||ve&&!uT(le,tT(r,L,``))?!0:!r:Ft(e)&&Ot(pe.tagNameCheck,e)&&Ot(pe.attributeNameCheck,t,e)||t===`is`&&pe.allowCustomizedBuiltInElements&&Ot(pe.tagNameCheck,r)},Pt=mT({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Ft=function(e){return!Pt[Qw(e)]&&uT(ue,e)},It=function(e,t,n,r){if(T&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return j(r);case`TrustedScriptURL`:return ee(r)}return r},Lt=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Ct(e)||(dt(e),!1)}catch{return mt(t,e),!1}},Rt=function(e,n){if(Et(I.beforeSanitizeAttributes,e,null),jt(e,n))return;let r=e.attributes;if(!r||Ct(e))return;B=At(I.uponSanitizeAttribute,B,fe,Ce);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:B,forceKeepAttr:void 0},a=r.length,o=et(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=et(s),d=l,f=s===`value`?d:rT(d),p=!1;if(i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,Et(I.uponSanitizeAttribute,e,i),f=i.attrValue,ke&&(u===`id`||u===`name`)&&nT(f,Ae)!==0&&(mt(s,e,n),f=Ae+f,p=!0),be&&uT(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,f)){mt(s,e,n);continue}if(u===`attributename`&&eT(f,`href`)){mt(s,e,n);continue}if(!i.forceKeepAttr){if(!i.keepAttr){mt(s,e,n);continue}if(!ye&&uT(WT,f)){mt(s,e,n);continue}if(H&&(f=xt(f)),!Nt(o,u,f)){mt(s,e,n);continue}f=It(o,u,c,f),f!==d&&Lt(e,s,c,f)&&p&&Jw(t.removed)}}Et(I.afterSanitizeAttributes,e,null),jt(e,n)},zt=function(e){let t=null,n=bt(e);for(Et(I.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(Et(I.uponSanitizeShadowNode,t,null),Mt(t,e),Rt(t,e),wt(t.content)&&zt(t.content),C(t)===GT.element){let e=v(t);wt(e)&&(Bt(e),zt(e))}Et(I.afterSanitizeShadowDOM,e,null)},Bt=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){zt(e.shadow);continue}let n=e.node,r=C(n)===GT.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=x?x(n):null;if(typeof e==`string`&&et(e)===`template`){let e=n.content;wt(e)&&t.push({node:e,shadow:null})}}if(r){let e=v(n);wt(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(We=!e,We&&(e=`<!-->`),typeof e!=`string`&&!Tt(e)&&(e=_T(e),typeof e!=`string`))throw dT(`dirty is not a string, aborting`);if(!t.isSupported)return e;xe?(R=Se,B=Ce):it(n),(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&(R=gT(R)),I.uponSanitizeAttribute.length>0&&(B=gT(B)),t.removed=[];let c=Me&&typeof e!=`string`&&Tt(e);if(c){vt(e);let t=w(e);if(typeof t==`string`){let n=et(t);if(!R[n]||me[n])throw pt(e),dT(`root node is forbidden and cannot be sanitized in-place`)}if(Ct(e))throw pt(e),dT(`root node is clobbered and cannot be sanitized in-place`);try{Bt(e)}catch(t){throw pt(e),t}}else if(Tt(e))i=yt(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===GT.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Bt(i);else{if(!Te&&!H&&!U&&e.indexOf(`<`)===-1)return T&&De?j(e):e;if(i=yt(e),!i)return Te?null:De?E:``}i&&we&&dt(i.firstChild);let l=c?e:i;try{let e=bt(l);for(;o=e.nextNode();)Mt(o,l),Rt(o,l),wt(o.content)&&zt(o.content)}catch(n){throw c&&(pt(e),Kw(t.removed,e=>{e.element&&gt(e.element)})),n}if(c){let n=!1;if(Kw(t.removed,t=>{t.element&&(t.element===e&&(n=!0),gt(t.element))}),n)throw dT(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return H&&St(e),e}if(Te){if(H&&St(i),Ee)for(s=te.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(B.shadowroot||B.shadowrootmode)&&(s=re.call(r,s,!0)),s}let u=U?i.outerHTML:i.innerHTML;return U&&R[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&uT(zT,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
4393
4393
  `+u),H&&(u=xt(u)),T&&De?j(u):u},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};it(e),xe=!0,Se=R,Ce=B},t.clearConfig=function(){tt=null,xe=!1,Se=null,Ce=null,T=D,E=``},t.isValidAttribute=function(e,t,n){tt||it({});let r=et(e),i=et(t);return Nt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&cT(I,e)&&Yw(I[e],t)},t.removeHook=function(e,t){if(cT(I,e)){if(t!==void 0){let n=qw(I[e],t);return n===-1?void 0:Xw(I[e],n,1)[0]}return Jw(I[e])}},t.removeHooks=function(e){cT(I,e)&&(I[e]=[])},t.removeAllHooks=function(){I=ZT()},t}var tE=eE();function nE(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var rE=nE();function iE(e){rE=e}var aE={exec:()=>null};function oE(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function sE(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(lE.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var cE=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),lE={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:oE(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:oE(e=>RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:oE(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:oE(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:oE(e=>RegExp(`^ {0,${e}}(?:</?(?:${wE})(?: +|$|/?>)|<(?:script|pre|style|textarea|!--))`,`i`)),blockquoteBeginRegex:oE(e=>RegExp(`^ {0,${e}}>`))},uE=/^(?:[ \t]*(?:\n|$))+/,dE=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,fE=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,pE=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,mE=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hE=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,gE=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_E=sE(gE).replace(/bull/g,hE).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),vE=sE(gE).replace(/bull/g,hE).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),yE=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,bE=/^[^\n]+/,xE=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,SE=sE(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,xE).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),CE=sE(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,hE).getRegex(),wE=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,TE=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,EE=sE(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,TE).replace(`tag`,wE).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),DE=e=>sE(yE).replace(`hr`,pE).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,e).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,wE).getRegex(),OE=DE(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),kE=DE(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),AE={blockquote:sE(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,kE).getRegex(),code:dE,def:SE,fences:fE,heading:mE,hr:pE,html:EE,lheading:_E,list:CE,newline:uE,paragraph:OE,table:aE,text:bE},jE=sE(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,pE).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,wE).getRegex(),ME={...AE,lheading:vE,table:jE,paragraph:sE(yE).replace(`hr`,pE).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,jE).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,wE).getRegex()},NE={...AE,html:sE(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,TE).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:aE,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:sE(yE).replace(`hr`,pE).replace(`heading`,` *#{1,6} *[^
4394
4394
  ]`).replace(`lheading`,_E).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},PE=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,FE=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,IE=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,LE=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,RE=/[\p{P}\p{S}]/u,zE=/[\s\p{P}\p{S}]/u,BE=/[^\s\p{P}\p{S}]/u,VE=sE(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,zE).getRegex(),HE=/[\p{Pi}\p{Ps}"']/u,UE=/(?!~)[\p{P}\p{S}]/u,WE=/(?!~)[\s\p{P}\p{S}]/u,GE=/(?:[^\s\p{P}\p{S}]|~)/u,KE=sE(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,cE?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),qE=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,JE=sE(qE,`u`).replace(/punct/g,RE).getRegex(),YE=sE(qE,`u`).replace(/punct/g,UE).getRegex(),XE=sE(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,`u`).replace(/openQuote/g,HE).replace(/punct/g,RE).getRegex(),ZE=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,QE=sE(ZE,`gu`).replace(/notPunctSpace/g,BE).replace(/punctSpace/g,zE).replace(/punct/g,RE).getRegex(),$E=sE(ZE,`gu`).replace(/notPunctSpace/g,GE).replace(/punctSpace/g,WE).replace(/punct/g,UE).getRegex(),eD=sE(`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,BE).replace(/punctSpace/g,zE).replace(/punct/g,RE).getRegex(),tD=sE(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,BE).replace(/punctSpace/g,zE).replace(/punct/g,RE).getRegex(),nD=sE(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,BE).replace(/punctSpace/g,zE).replace(/punct/g,RE).getRegex(),rD=sE(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,RE).getRegex(),iD=sE(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,BE).replace(/punctSpace/g,zE).replace(/punct/g,RE).getRegex(),aD=sE(/\\(punct)/,`gu`).replace(/punct/g,RE).getRegex(),oD=sE(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),sD=sE(TE).replace(`(?:-->|$)`,`-->`).getRegex(),cD=sE(`^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,sD).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),lD=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,uD=sE(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace(`brackets`,lD).getRegex(),dD=sE(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace(`label`,uD).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),fD=sE(/^!?\[(label)\]\[(ref)\]/).replace(`label`,uD).replace(`ref`,xE).getRegex(),pD=sE(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,xE).getRegex(),mD=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,hD=sE(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace(`brackets`,lD).getRegex(),gD=sE(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,sE(/^!?\[(label)\]\[(ref)\]/).replace(`label`,hD).replace(`ref`,mD).getRegex()).replace(`nolink`,sE(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,mD).getRegex()).getRegex(),_D=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,vD=sE(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),yD={_backpedal:aE,anyPunctuation:aD,autolink:oD,blockSkip:KE,br:IE,code:FE,del:aE,delLDelim:aE,delRDelim:aE,emStrongLDelim:JE,emStrongRDelimAst:QE,emStrongRDelimUnd:tD,escape:PE,link:dD,nolink:pD,punctuation:VE,reflink:fD,reflinkSearch:gD,tag:cD,text:LE,url:aE},bD={...yD,emStrongLDelim:XE,emStrongRDelimAst:eD,emStrongRDelimUnd:nD,link:sE(/^!?\[(label)\]\((.*?)\)/).replace(`label`,uD).getRegex(),reflink:sE(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,uD).getRegex()},xD={...yD,emStrongRDelimAst:$E,emStrongLDelim:YE,delLDelim:rD,delRDelim:iD,url:sE(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`emailProtocol`,vD).replace(`protocol`,_D).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:sE(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace(`protocol`,_D).replace(/emailProtocol/g,/(?:mailto|xmpp):/).getRegex()},SD={...xD,br:sE(IE).replace(`{2,}`,`*`).getRegex(),text:sE(xD.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},CD={normal:AE,gfm:ME,pedantic:NE},wD={normal:yD,gfm:xD,breaks:SD,pedantic:bD},TD={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},ED=e=>TD[e];function DD(e,t){if(t){if(lE.escapeTest.test(e))return e.replace(lE.escapeReplace,ED)}else if(lE.escapeTestNoEncode.test(e))return e.replace(lE.escapeReplaceNoEncode,ED);return e}function OD(e){return e.replace(lE.numericCharacterReference,(e,t,n)=>{let r=t===void 0?Number.parseInt(n,16):Number.parseInt(t,10);return r===0||r>1114111||r>=55296&&r<=57343?`�`:String.fromCodePoint(r)})}function kD(e){try{e=encodeURI(e).replace(lE.percentDecode,`%`)}catch{return null}return e}function AD(e,t){let n=e.replace(lE.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(lE.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``)}for(;r<n.length;r++)n[r]=n[r].trim().replace(lE.slashPipe,`|`);return n}function jD(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function MD(e){let t=e.split(`
@@ -4456,5 +4456,5 @@ ${this.parser.parse(e)}</blockquote>
4456
4456
  ${e}</tr>
4457
4457
  `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
4458
4458
  `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${DD(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,text:n,tokens:r,autolink:i}){let a=i?DD(n,!0):this.parser.parseInline(r),o=kD(e);if(o===null)return a;e=DD(o,i);let s=`<a href="`+e+`"`;return t&&(s+=` title="`+DD(t)+`"`),s+=`>`+a+`</a>`,s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=kD(e);if(i===null)return DD(n);e=i;let a=`<img src="${DD(e)}" alt="${DD(n)}"`;return t&&(a+=` title="${DD(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:DD(e.text)}},HD=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},UD=class e{options;renderer;textRenderer;constructor(e){this.options=e||rE,this.options.renderer=this.options.renderer||new VD,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new HD}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`checkbox`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`checkbox`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},WD=class{options;block;constructor(e){this.options=e||rE}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?BD.lex:BD.lexInline}provideParser(e=this.block){return e?UD.parse:UD.parseInline}},GD=new class{defaults=nE();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=UD;Renderer=VD;TextRenderer=HD;Lexer=BD;Tokenizer=zD;Hooks=WD;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new VD(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new zD(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new WD;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=WD.passThroughHooks.has(n)?e=>{if(this.defaults.async&&WD.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return BD.lex(e,t??this.defaults)}parser(e,t){return UD.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?BD.lex:BD.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?UD.parse:UD.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?BD.lex:BD.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?UD.parse:UD.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
4459
- Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+DD(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function KD(e,t){return GD.parse(e,t)}KD.options=KD.setOptions=function(e){return GD.setOptions(e),KD.defaults=GD.defaults,iE(KD.defaults),KD},KD.getDefaults=nE,KD.defaults=rE;function qD(...e){return GD.use(...e),KD.defaults=GD.defaults,iE(KD.defaults),KD}KD.use=qD,KD.walkTokens=function(e,t){return GD.walkTokens(e,t)},KD.parseInline=GD.parseInline,KD.Parser=UD,KD.parser=UD.parse,KD.Renderer=VD,KD.TextRenderer=HD,KD.Lexer=BD,KD.lexer=BD.lex,KD.Tokenizer=zD,KD.Hooks=WD,KD.parse=KD,KD.options,KD.setOptions,KD.walkTokens,KD.parseInline,UD.parse,BD.lex;var JD=!1;function YD(){JD||(JD=!0,tE.addHook(`afterSanitizeAttributes`,e=>{e instanceof Element&&e.tagName===`A`&&(e.setAttribute(`rel`,`noopener noreferrer`),e.setAttribute(`target`,`_blank`))}))}function XD(e){YD();let t=KD.parse(e,{async:!1,breaks:!0});return tE.sanitize(t,{ALLOWED_TAGS:[`p`,`br`,`strong`,`em`,`code`,`pre`,`ul`,`ol`,`li`,`a`,`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`blockquote`,`hr`,`del`,`table`,`thead`,`tbody`,`tr`,`th`,`td`],ALLOWED_ATTR:[`href`,`rel`,`target`],ALLOWED_URI_REGEXP:/^(?:https?:|mailto:)/i})}var ZD=e=>Number.isFinite(e);function QD(e){let t=Math.floor(Math.log10(e)),n=e/10**t;return(n<=1?1:n<=2?2:n<=2.5?2.5:n<=5?5:10)*10**t}function $D(e,t,n=5){let r=ZD(e)?e:0,i=ZD(t)?t:r+1;r>i&&([r,i]=[i,r]),r===i&&(i=r+(Math.abs(r)||1));let a=QD((i-r)/Math.max(1,n-1)),o=Math.floor(r/a)*a,s=Math.ceil(i/a)*a,c=[];for(let e=o;e<=s+a/2;e+=a)c.push(Math.round(e*1e9)/1e9);return{min:o,max:s,ticks:c}}function eO(e,t){let[n,r]=e,[i,a]=t;return r===n?()=>i:e=>i+(e-n)/(r-n)*(a-i)}function tO(e){return e.map(([e,t],n)=>`${n===0?`M`:`L`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function nO(e,t,n,r,i){let a=r=>{let i=r*Math.PI/180;return`${(e+n*Math.cos(i)).toFixed(2)} ${(t+n*Math.sin(i)).toFixed(2)}`},o=+(Math.abs(i-r)>180);return`M ${a(r)} A ${n} ${n} 0 ${o} 1 ${a(i)}`}function rO(e,t,n){return!ZD(e)||!ZD(t)||!ZD(n)||n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))*240}function iO(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=Math.hypot(i,a);if(o===0||o<=n+r)return{from:{...e},to:{...t}};let s=i/o,c=a/o;return{from:{x:e.x+s*n,y:e.y+c*n},to:{x:t.x-s*r,y:t.y-c*r}}}function aO(e,t,n){if(e<=0)return[];if(e===1)return[{x:t/2,y:n/2}];let r=Math.min(t,n)*.36;return Array.from({length:e},(i,a)=>{let o=-Math.PI/2+a*2*Math.PI/e;return{x:t/2+r*Math.cos(o),y:n/2+r*Math.sin(o)}})}var oO=e=>typeof e==`object`&&!!e&&!Array.isArray(e),sO=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,cO=e=>Array.isArray(e)?e:[],lO=e=>typeof e==`number`?Number.isFinite(e)?e:null:typeof e==`string`&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):null,uO=(e,t)=>e.length>t?e.slice(0,t)+`…`:e,dO=[`var(--accent)`,`#ffb454`,`#7b8cff`,`#5ef0b0`,`#ff6b7a`,`#c792ea`],fO=({text:e})=>e?(0,w.jsx)(`h3`,{className:`obj-title`,children:e}):null,pO=({text:e=`No data`})=>(0,w.jsx)(`p`,{className:`obj-empty`,children:e}),mO=400,hO=220,gO={l:44,r:12,t:10,b:28};function _O({props:e}){let t=e.kind===`bar`||e.kind===`area`?e.kind:`line`,n=cO(e.labels).slice(0,120).map(sO),r=cO(e.series).slice(0,6).map((e,t)=>{let n=oO(e)?e:{},r=cO(n.values).slice(0,120).map((e,t)=>({idx:t,v:lO(e)})).filter(e=>e.v!==null);return{name:sO(n.name)||`series ${t+1}`,points:r}}).filter(e=>e.points.length>0);if(r.length===0)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(pO,{})]});let i=r.flatMap(e=>e.points.map(e=>e.v)),a=Math.min(...i),o=Math.max(...i),s=$D(t===`line`?a:Math.min(0,a),t===`line`?o:Math.max(0,o),5),c=Math.max(n.length,...r.map(e=>e.points[e.points.length-1].idx+1),2),l=eO([s.min,s.max],[hO-gO.b,gO.t]),u=eO([0,c-1],[gO.l,mO-gO.r]),d=(mO-gO.l-gO.r)/c,f=Math.max(1,d*.7/r.length),p=(e,t)=>gO.l+e*d+d*.15+t*f,m=Math.max(1,Math.ceil(c/6)),h=sO(e.unit);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsxs)(`svg`,{className:`obj-chart`,viewBox:`0 0 ${mO} ${hO}`,role:`img`,"aria-label":sO(e.title)||`chart`,children:[s.ticks.map(e=>(0,w.jsxs)(`g`,{children:[(0,w.jsx)(`line`,{className:`grid`,x1:gO.l,x2:mO-gO.r,y1:l(e),y2:l(e)}),(0,w.jsxs)(`text`,{className:`tick`,x:gO.l-6,y:l(e)+3,textAnchor:`end`,children:[e,h&&e===s.max?h:``]})]},e)),Array.from({length:c},(e,t)=>t).filter(e=>e%m===0&&n[e]).map(e=>(0,w.jsx)(`text`,{className:`tick`,x:t===`bar`?p(e,0)+f*r.length/2:u(e),y:212,textAnchor:`middle`,children:uO(n[e],8)},e)),r.map((e,n)=>{let r=dO[n%dO.length];if(t===`bar`)return(0,w.jsx)(`g`,{children:e.points.map(e=>(0,w.jsx)(`rect`,{className:`bar`,x:p(e.idx,n),y:Math.min(l(e.v),l(0)),width:f,height:Math.abs(l(e.v)-l(0)),fill:r},e.idx))},n);let i=e.points.map(e=>[u(e.idx),l(e.v)]),a=tO(i),o=`${a} L${i[i.length-1][0].toFixed(2)} ${l(s.min).toFixed(2)} L${i[0][0].toFixed(2)} ${l(s.min).toFixed(2)} Z`;return(0,w.jsxs)(`g`,{children:[t===`area`&&(0,w.jsx)(`path`,{className:`series-area`,d:o,fill:r,opacity:.18}),(0,w.jsx)(`path`,{className:`series-line`,d:a,fill:`none`,stroke:r,strokeWidth:2,strokeLinejoin:`round`})]},n)})]}),r.length>1&&(0,w.jsx)(`ul`,{className:`legend`,children:r.map((e,t)=>(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`i`,{style:{background:dO[t%dO.length]}}),(0,w.jsx)(`span`,{children:e.name})]},t))})]})}function vO({props:e}){let t=lO(e.min)??0,n=lO(e.max)??100,r=lO(e.value)??t,i=rO(r,t,n),a=i/240;return(0,w.jsxs)(`div`,{className:`obj-gauge ${a>.95?`gauge-crit`:a>.8?`gauge-warn`:``}`,children:[(0,w.jsxs)(`svg`,{viewBox:`0 0 200 150`,role:`img`,"aria-label":`${sO(e.label)} ${r}`,children:[(0,w.jsx)(`path`,{className:`track`,d:nO(100,100,70,150,390),fill:`none`,strokeWidth:12,strokeLinecap:`round`}),i>0&&(0,w.jsx)(`path`,{className:`value`,d:nO(100,100,70,150,150+i),fill:`none`,strokeWidth:12,strokeLinecap:`round`})]}),(0,w.jsxs)(`div`,{className:`gauge-read`,children:[(0,w.jsx)(`span`,{className:`gauge-value`,children:String(Math.round(r*100)/100)}),sO(e.unit)&&(0,w.jsx)(`small`,{className:`gauge-unit`,children:sO(e.unit)})]}),(0,w.jsx)(`span`,{className:`obj-label`,children:sO(e.label)})]})}function yO({props:e}){let t=cO(e.items).slice(0,30).map(e=>oO(e)?e:{}).map(e=>({time:sO(e.time),title:sO(e.title),detail:sO(e.detail)})).filter(e=>e.title||e.time);return t.length===0?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(pO,{text:`Nothing to show`})]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(`ol`,{className:`obj-timeline`,children:t.map((e,t)=>(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`time`,{children:e.time}),(0,w.jsx)(`strong`,{children:e.title}),e.detail&&(0,w.jsx)(`span`,{children:e.detail})]},t))})]})}var bO=400,xO=300,SO=12;function CO({props:e}){let t=(0,y.useId)(),n=new Set,r=[];for(let t of cO(e.nodes)){let e=oO(t)?t:{},i=sO(e.id);if(i&&!n.has(i)&&(n.add(i),r.push({id:i,label:sO(e.label)||i}),r.length>=40))break}if(r.length===0)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(pO,{text:`Nothing to show`})]});let i=new Map(r.map((e,t)=>[e.id,aO(r.length,bO,xO)[t]])),a=[];for(let t of cO(e.edges)){let e=oO(t)?t:{},n=sO(e.from),r=sO(e.to);if(i.has(n)&&i.has(r)&&n!==r&&(a.push({from:n,to:r,label:sO(e.label)}),a.length>=80))break}return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsxs)(`svg`,{className:`obj-graph`,viewBox:`0 0 ${bO} ${xO}`,role:`img`,"aria-label":sO(e.title)||`graph`,children:[(0,w.jsx)(`defs`,{children:(0,w.jsx)(`marker`,{id:t,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,w.jsx)(`path`,{d:`M0 0 L10 5 L0 10 z`,className:`arrow`})})}),a.map((e,n)=>{let{from:r,to:a}=iO(i.get(e.from),i.get(e.to),14,17),o=(r.x+a.x)/2+(bO/2-(r.x+a.x)/2)*.25,s=(r.y+a.y)/2+(xO/2-(r.y+a.y)/2)*.25;return(0,w.jsxs)(`g`,{children:[(0,w.jsx)(`path`,{className:`edge`,d:`M ${r.x.toFixed(1)} ${r.y.toFixed(1)} Q ${o.toFixed(1)} ${s.toFixed(1)} ${a.x.toFixed(1)} ${a.y.toFixed(1)}`,fill:`none`,markerEnd:`url(#${t})`}),e.label&&(0,w.jsx)(`text`,{className:`edge-label`,x:o,y:s,textAnchor:`middle`,children:uO(e.label,12)})]},n)}),r.map(e=>{let t=i.get(e.id);return(0,w.jsxs)(`g`,{children:[(0,w.jsx)(`circle`,{className:`node`,cx:t.x,cy:t.y,r:SO}),(0,w.jsx)(`text`,{className:`node-label`,x:t.x,y:t.y+26,textAnchor:`middle`,children:uO(e.label,18)})]},e.id)})]})]})}var wO=30,TO=e=>Number.isFinite(e)?Math.max(0,Math.min(1,e)):1,EO=new class{current=1;goal=1;from=1;steps=1;n=0;timer=null;subs=new Set;get level(){return this.current}set(e,t=250){if(this.goal=TO(e),t<=0||this.goal===this.current){this.stop(),this.move(this.goal);return}this.from=this.current,this.steps=Math.max(1,Math.ceil(t/wO)),this.n=0,this.timer??=setInterval(()=>this.tick(),wO)}subscribe(e){return this.subs.add(e),()=>void this.subs.delete(e)}tick(){this.n++,this.n>=this.steps?(this.stop(),this.move(this.goal)):this.move(this.from+(this.goal-this.from)*this.n/this.steps)}stop(){this.timer&&clearInterval(this.timer),this.timer=null}move(e){if(e!==this.current){this.current=e;for(let t of[...this.subs])t(e)}}};function DO(e,t=EO){let n=e.volume,r=e.volume,i=!0,a=t=>{i&&(r=TO(n*t),e.volume=r)},o=()=>{if(!i||Math.abs(e.volume-r)<=.002)return;let a=t.level;a>.001&&(n=TO(e.volume/a)),r=e.volume};e.addEventListener(`volumechange`,o);let s=t.subscribe(a);return a(t.level),()=>{i=!1,s(),e.removeEventListener(`volumechange`,o),e.volume=n}}var OO=`https://www.youtube-nocookie.com`;function kO(e,t=EO,n=window){let r=100,i=null,a=!1,o=!0,s=!1,c=t=>e.contentWindow?.postMessage(JSON.stringify(t),OO),l=()=>c({event:`listening`,id:1,channel:`widget`}),u=e=>{i=e,c({event:`command`,func:`setVolume`,args:[e]})},d=e=>{o&&(e<.999?(a=!0,u(Math.round(r*e))):a&&(a=!1,u(Math.round(r))))},f=n=>{if(!o||n.source!==e.contentWindow)return;let c;try{c=JSON.parse(String(n.data)).info}catch{return}if(typeof c?.volume!=`number`)return;s=!0;let l=c.volume;if(i!==null&&Math.abs(l-i)<=1)return;let u=t.level;r=a&&u>.001?l/u:l,i=l};n.addEventListener(`message`,f),e.addEventListener?.(`load`,l),l();let p=setInterval(()=>s?clearInterval(p):l(),1e3),m=t.subscribe(d);return d(t.level),()=>{o=!1,clearInterval(p),m(),n.removeEventListener(`message`,f),e.removeEventListener?.(`load`,l),a&&AO(e,r)}}function AO(e,t){try{e.contentWindow?.postMessage(JSON.stringify({event:`command`,func:`setVolume`,args:[Math.round(t)]}),OO)}catch{}}var jO=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,MO=e=>Array.isArray(e)?e:[],NO=e=>typeof e==`object`&&e?e:{},PO=/^\/api\/media\/[0-9a-f]{32}$/,FO=e=>typeof e==`string`&&PO.test(e)?e:null,IO=/^\/api\/video\/[0-9a-f]{32}$/,LO=e=>typeof e==`string`&&IO.test(e)?e:null,RO=({props:e})=>jO(e.title)?(0,w.jsx)(`h3`,{className:`obj-title`,children:jO(e.title)}):null;function zO({props:e}){let t=(0,y.useMemo)(()=>XD(jO(e.text)),[e.text]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(RO,{props:e}),(0,w.jsx)(`div`,{className:`obj-md obj-doc`,dangerouslySetInnerHTML:{__html:t}})]})}function BO({props:e}){let t=Math.min(100,Math.max(0,Number(e.value)||0));return(0,w.jsxs)(`div`,{className:`obj-progress`,children:[(0,w.jsxs)(`div`,{className:`obj-progress-head`,children:[(0,w.jsx)(`span`,{className:`obj-label`,children:jO(e.label)}),(0,w.jsxs)(`span`,{className:`obj-progress-pct`,children:[Math.round(t),`%`]})]}),(0,w.jsx)(`div`,{className:`obj-progress-bar`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(t),"aria-label":jO(e.label)||`Progress`,children:(0,w.jsx)(`i`,{style:{width:`${t}%`}})}),jO(e.detail)&&(0,w.jsx)(`span`,{className:`obj-progress-detail`,children:jO(e.detail)})]})}function VO({props:e}){let t=MO(e.items).map(e=>NO(typeof e==`object`&&e?e:{text:e})),n=t.filter(e=>e.done===!0).length;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(RO,{props:e}),(0,w.jsx)(`ul`,{className:`obj-checklist`,children:t.map((e,t)=>(0,w.jsxs)(`li`,{className:e.done===!0?`done`:void 0,children:[(0,w.jsx)(`span`,{className:`box`,"aria-hidden":`true`,children:e.done===!0?`✓`:``}),(0,w.jsx)(`span`,{children:jO(e.text)})]},t))}),t.length>0&&(0,w.jsxs)(`small`,{className:`obj-progress-detail`,children:[n,` of `,t.length,` done`]})]})}function HO({props:e}){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(RO,{props:e}),(0,w.jsx)(`dl`,{className:`obj-kv`,children:MO(e.rows).map((e,t)=>{let n=NO(e);return(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:jO(n.key)}),(0,w.jsx)(`dd`,{children:jO(n.value)})]},t)})})]})}var UO=e=>String(Math.floor(e)).padStart(2,`0`);function WO(e){let t=Math.max(0,Math.ceil(e));return`${UO(t/3600)}:${UO(t%3600/60)}:${UO(t%60)}`}function GO({props:e}){let t=(0,y.useRef)(null);if(t.current===null){let n=typeof e.to==`string`?Date.parse(e.to):NaN,r=Number(e.seconds);t.current=Number.isFinite(n)?n:Date.now()+(Number.isFinite(r)?r:0)*1e3}let[n,r]=(0,y.useState)(Date.now());(0,y.useEffect)(()=>{let e=setInterval(()=>r(Date.now()),250);return()=>clearInterval(e)},[]);let i=(t.current-n)/1e3;return(0,w.jsxs)(`div`,{className:`obj-countdown${i<=0?` done`:``}`,children:[(0,w.jsx)(`span`,{className:`obj-label`,children:jO(e.title)||jO(e.label)}),(0,w.jsx)(`span`,{className:`obj-countdown-time`,role:`timer`,children:WO(i)})]})}function KO({props:e}){let t=FO(e.src);return(0,w.jsxs)(`div`,{className:`obj-media`,children:[(0,w.jsx)(RO,{props:e}),t?(0,w.jsx)(`img`,{src:t,alt:jO(e.title)||`Picture`,loading:`lazy`}):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This picture is not available.`})]})}function qO({src:e,web:t,title:n}){let[r,i]=(0,y.useState)(t?`loading`:`ready`),a=(0,y.useRef)(null);return(0,y.useEffect)(()=>a.current?DO(a.current):void 0,[r===`failed`]),r===`failed`?(0,w.jsx)(`p`,{className:`obj-empty`,children:`This video could not be played. Ask Friend to try again, or to play it in a window on the PC.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`video`,{ref:a,src:e,controls:!0,playsInline:!0,autoPlay:t,preload:t?`auto`:`metadata`,"aria-label":n,onLoadedData:()=>i(`ready`),onError:()=>i(`failed`)}),t&&r===`loading`&&(0,w.jsx)(`p`,{className:`obj-empty`,children:`Preparing the video…`})]})}var JO=/^[A-Za-z0-9_-]{11}$/;function YO({id:e,start:t,title:n}){let[r,i]=(0,y.useState)(!1),a=(0,y.useRef)(null);(0,y.useEffect)(()=>a.current?kO(a.current):void 0,[e]);let o=new URLSearchParams({autoplay:`1`,rel:`0`,playsinline:`1`,modestbranding:`1`,enablejsapi:`1`});return t>0&&o.set(`start`,String(t)),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`iframe`,{ref:a,className:`obj-youtube`,src:`https://www.youtube-nocookie.com/embed/${e}?${o.toString()}`,title:n,allow:`autoplay; encrypted-media; fullscreen; picture-in-picture`,allowFullScreen:!0,referrerPolicy:`strict-origin-when-cross-origin`,onLoad:()=>i(!0)}),!r&&(0,w.jsx)(`p`,{className:`obj-empty`,children:`Loading the player…`})]})}function XO({props:e}){if(e.embed!==void 0){let t=typeof e.embed==`string`&&JO.test(e.embed)?e.embed:null,n=typeof e.start==`number`&&e.start>0&&e.start<=86400?Math.floor(e.start):0;return(0,w.jsxs)(`div`,{className:`obj-media obj-media-fill`,children:[(0,w.jsx)(RO,{props:e}),t?(0,w.jsx)(YO,{id:t,start:n,title:jO(e.title)||`YouTube video`},`${t}-${n}`):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This clip is not available.`})]})}let t=LO(e.src),n=t??FO(e.src);return(0,w.jsxs)(`div`,{className:`obj-media`,children:[(0,w.jsx)(RO,{props:e}),n?(0,w.jsx)(qO,{src:n,web:t!==null,title:jO(e.title)||`Video`},n):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This clip is not available.`})]})}function ZO({props:e}){let t=FO(e.src);return(0,w.jsxs)(`div`,{className:`obj-media obj-pdf`,children:[(0,w.jsx)(RO,{props:e}),t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`iframe`,{src:t,title:jO(e.title)||`Document`}),(0,w.jsx)(`a`,{className:`obj-open`,href:t,target:`_blank`,rel:`noopener noreferrer`,children:`Open in a new tab`})]}):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This document is not available.`})]})}function QO({props:e}){let t=MO(e.items).map(NO).filter(e=>FO(e.src)),[n,r]=(0,y.useState)(0),i=Math.min(n,Math.max(0,t.length-1)),a=t[i];if(!a)return(0,w.jsx)(`p`,{className:`obj-empty`,children:`Nothing to show.`});let o=FO(a.src),s=a.kind===`video`;return(0,w.jsxs)(`div`,{className:`obj-media obj-gallery`,children:[(0,w.jsx)(RO,{props:e}),s?(0,w.jsx)(`video`,{src:o,controls:!0,playsInline:!0,preload:`metadata`},o):(0,w.jsx)(`img`,{src:o,alt:jO(a.caption)||`Picture ${i+1}`},o),(0,w.jsxs)(`div`,{className:`obj-gallery-bar`,children:[(0,w.jsx)(`button`,{type:`button`,"aria-label":`Previous`,disabled:t.length<2,onClick:()=>r((i+t.length-1)%t.length),children:`‹`}),(0,w.jsxs)(`span`,{children:[jO(a.caption),(0,w.jsxs)(`small`,{children:[i+1,` / `,t.length]})]}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Next`,disabled:t.length<2,onClick:()=>r((i+1)%t.length),children:`›`})]})]})}var $O=[`default-src 'none'`,`script-src 'unsafe-inline'`,`style-src 'unsafe-inline'`,`img-src data: blob:`,`form-action 'none'`,`base-uri 'none'`].join(`; `),ek=`html,body{margin:0;min-height:100%;background:#050b10;color:var(--ink,#d8f6ff);font:15px/1.5 var(--ui,system-ui,sans-serif)}`,tk=[`--accent`,`--ink`,`--muted`,`--ok`,`--warn`,`--bad`,`--glass`,`--edge`,`--ui`,`--mono`],nk=/^[\w\s#().,%'"/-]+$/;function rk(){if(typeof document>`u`)return``;let e=getComputedStyle(document.documentElement),t=tk.map(t=>[t,e.getPropertyValue(t).trim()]).filter(([,e])=>e&&nk.test(e));return t.length?`:root{${t.map(([e,t])=>`${e}:${t}`).join(`;`)}}`:``}function ik(e,t=``){return`<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${$O}"><meta name="viewport" content="width=device-width,initial-scale=1"><style>${t}${ek}</style></head><body>${e}</body></html>`}function ak({props:e}){let t=typeof e.html==`string`?e.html:``,n=typeof e.title==`string`?e.title:``,r=(0,y.useMemo)(()=>ik(t,rk()),[t]);return(0,w.jsxs)(`div`,{className:`obj-sandbox`,children:[n&&(0,w.jsx)(`h3`,{className:`obj-title`,children:n}),(0,w.jsx)(`iframe`,{title:n||`Page made by Friend`,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,allow:``,srcDoc:r})]})}var ok=`modulepreload`,sk=function(e){return`/`+e},ck={},lk=function(e){return e.pathname.endsWith(`.css`)},uk=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=sk(t,n);let r=s(t);if(r.href in ck)return;ck[r.href]=!0;let i=lk(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:ok,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},dk=(0,y.lazy)(()=>uk(()=>import(`./jarvisTree-CX2xpGQL.js`),__vite__mapDeps([0,1,2])));function fk({type:e,props:t}){let n=vu(e,t);return n?(0,w.jsx)(`p`,{className:`obj-empty`,children:n}):(0,w.jsx)(`div`,{className:`obj-jarvis`,children:(0,w.jsx)(y.Suspense,{fallback:(0,w.jsx)(`p`,{className:`obj-empty`,children:`Loading…`}),children:(0,w.jsx)(dk,{node:mu(e,t)})})})}var pk=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,mk=e=>Array.isArray(e)?e:[];function hk({props:e}){let t=(0,y.useMemo)(()=>XD(pk(e.text)),[e.text]);return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-md`,dangerouslySetInnerHTML:{__html:t}})]})}function gk({props:e}){return(0,w.jsxs)(`div`,{className:`obj-stat`,children:[(0,w.jsx)(`span`,{className:`obj-label`,children:pk(e.label)}),(0,w.jsxs)(`span`,{className:`obj-value`,children:[(0,w.jsx)(`span`,{children:pk(e.value)}),pk(e.unit)&&(0,w.jsx)(`small`,{children:pk(e.unit)})]}),pk(e.delta)&&(0,w.jsx)(`span`,{className:`obj-delta`,children:pk(e.delta)})]})}function _k({props:e}){return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`ul`,{className:`obj-list`,children:mk(e.items).map((e,t)=>{let n=typeof e==`object`&&e?e:{text:e};return(0,w.jsx)(`li`,{className:n.done?`done`:void 0,children:pk(n.text)},t)})})]})}function vk({props:e}){let t=mk(e.columns),n=mk(e.rows);return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-table-wrap`,children:(0,w.jsxs)(`table`,{className:`obj-table`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsx)(`tr`,{children:t.map((e,t)=>(0,w.jsx)(`th`,{children:pk(e)},t))})}),(0,w.jsx)(`tbody`,{children:n.map((e,t)=>(0,w.jsx)(`tr`,{children:mk(e).map((e,t)=>(0,w.jsx)(`td`,{children:pk(e)},t))},t))})]})})]})}function yk({props:e}){return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`pre`,{className:`obj-code`,"data-lang":pk(e.language),children:(0,w.jsx)(`code`,{children:pk(e.code)})})]})}function bk({part:e}){let t=typeof e==`object`&&e?e:{},n=typeof t.type==`string`?t.type:``;if(n===`group`||n===`tabs`||n===`sandbox`)return null;let r=Tk[n];return r?(0,w.jsx)(`div`,{className:`obj-part obj-part-${n}`,children:(0,w.jsx)(r,{props:typeof t.props==`object`&&t.props!==null?t.props:{}})}):null}function xk({props:e}){let t=e.layout===`row`||e.layout===`column`?e.layout:`grid`;return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-group obj-group-${t}`,children:mk(e.items).map((e,t)=>(0,w.jsx)(bk,{part:e},t))})]})}function Sk({props:e}){let t=mk(e.tabs).map(e=>typeof e==`object`&&e?e:{}),[n,r]=(0,y.useState)(0),i=Math.min(n,Math.max(0,t.length-1));return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-tabs`,role:`tablist`,children:t.map((e,t)=>(0,w.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t===i,className:t===i?`on`:void 0,onClick:()=>r(t),children:pk(e.title)||`Tab ${t+1}`},t))}),t[i]&&(0,w.jsx)(bk,{part:t[i]})]})}var Ck={card:hk,stat:gk,list:_k,table:vk,code:yk,chart:_O,gauge:vO,timeline:yO,graph:CO,sandbox:ak,markdown:zO,image:KO,video:XO,pdf:ZO,gallery:QO,group:xk,tabs:Sk,progress:BO,checklist:VO,countdown:GO,kv:HO},wk=Object.fromEntries(fu.map(e=>[e,({props:t})=>(0,w.jsx)(fk,{type:e,props:t})])),Tk={...Ck,...wk};function Ek(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=new Set;for(let t of e){if(i.has(t.object.id))continue;i.add(t.object.id);let e=n.get(t.object.id);r.push(e?{object:e,leaving:!1}:{object:t.object,leaving:!0})}for(let e of t)i.has(e.id)||(i.add(e.id),r.push({object:e,leaving:!1}));return r}function Dk(e,t){let[n,r]=(0,y.useState)(()=>e.map(e=>({object:e,leaving:!1}))),i=(0,y.useRef)(new Map);return(0,y.useEffect)(()=>{r(n=>{let a=Ek(n,e),o=new Set(n.filter(e=>e.leaving).map(e=>e.object.id));for(let e of a){let n=i.current.get(e.object.id);if(!e.leaving)n&&clearTimeout(n),i.current.delete(e.object.id);else if(!o.has(e.object.id)&&!n){let n=e.object.id;i.current.set(n,setTimeout(()=>{i.current.delete(n),r(e=>e.filter(e=>!(e.object.id===n&&e.leaving)))},Math.max(t,0)))}}return t<=0?a.filter(e=>!e.leaving):a})},[e,t]),(0,y.useEffect)(()=>()=>{for(let e of i.current.values())clearTimeout(e);i.current.clear()},[]),n}var Ok=.12,kk=.1,Ak=.02,jk=(e,t,n)=>Math.min(Math.max(e,t),n);function Mk(e){let t=jk(e.w,Ok,1),n=jk(e.h,kk,1);return{x:jk(e.x,0,1-t),y:jk(e.y,0,1-n),w:t,h:n}}function Nk(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return n.width<=0||n.height<=0?null:Mk({x:(r.left-n.left)/n.width,y:(r.top-n.top)/n.height,w:r.width/n.width,h:r.height/n.height})}function Pk(e,t,n){let r=(0,y.useRef)(null),[i,a]=(0,y.useState)(null),o=(0,y.useCallback)((n,r)=>{let i=Mk(r);t({type:`object.place`,id:n,placement:{x:i.x,y:i.y,w:i.w,h:i.h}}),e({type:`stage.move`,objectId:n,rect:i})},[e,t]),s=(0,y.useCallback)((e,t,i)=>{if(e.pointerType===`mouse`&&e.button!==0)return;let o=n(),s=e.currentTarget.closest(`[data-object]`);if(!o||!s||r.current)return;let c=Nk(s,o);if(!c)return;let l=o.getBoundingClientRect();r.current={id:t.id,mode:i,pointer:e.pointerId,startX:e.clientX,startY:e.clientY,from:c,stageW:l.width,stageH:l.height};try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}e.stopPropagation(),e.preventDefault(),a({id:t.id,box:c})},[n]),c=(e,t)=>{let n=(t.clientX-e.startX)/e.stageW,r=(t.clientY-e.startY)/e.stageH;return e.mode===`move`?Mk({...e.from,x:e.from.x+n,y:e.from.y+r}):Mk({...e.from,w:e.from.w+n,h:e.from.h+r})};return{preview:i,begin:s,move:(0,y.useCallback)(e=>{let t=r.current;t&&t.pointer===e.pointerId&&a({id:t.id,box:c(t,e)})},[]),end:(0,y.useCallback)((e,t)=>{let n=r.current;n&&n.pointer===e.pointerId&&(r.current=null,a(null),t||o(n.id,c(n,e)))},[o]),key:(0,y.useCallback)((e,t)=>{let r={ArrowLeft:[-.02,0],ArrowRight:[Ak,0],ArrowUp:[0,-.02],ArrowDown:[0,Ak]}[e.key],i=n(),a=e.currentTarget.closest(`[data-object]`);if(!r||!i||!a)return;let s=Nk(a,i);s&&(e.preventDefault(),o(t.id,e.shiftKey?{...s,w:s.w+r[0],h:s.h+r[1]}:{...s,x:s.x+r[0],y:s.y+r[1]}))},[o,n])}}function Fk(e,t){if(e===`auto`)return{position:`relative`};if(t.w<600)return{position:`relative`,width:`100%`};let[n,r,i,a]=typeof e==`string`?Au[e]:[e.x*100,e.y*100,e.w*100,e.h*100],o={position:`absolute`,left:`${n}%`,top:`${r}%`,width:`${i}%`};return e===`top`||e===`bottom`?{...o,maxHeight:`${a}%`}:{...o,height:`${a}%`}}var Ik=350,Lk=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,Rk=class extends y.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}};function zk(){let e=()=>({w:window.innerWidth,h:window.innerHeight}),[t,n]=(0,y.useState)(e);return(0,y.useEffect)(()=>{let t=()=>n(e());return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[]),t}var Bk=350;function Vk({state:e,send:t,dispatch:n,voice:r,slash:i,onMenu:a,hudLayer:o}){let s=zk(),[c,l]=(0,y.useState)(0),[u,d]=(0,y.useState)(!1),f=pe(),p=s.w<600,m=e.scene===`focus`||e.scene===`multi`,h=o&&Cw(s.w,s.h)===`orbit`?(()=>{let t=_w(s.w,s.h),n=vw(`centre`,552,828,s.w,s.h);return{name:e.assistantName||`friend`,style:{left:n.x,top:n.y,width:378*t,height:36*t,"--ob-s":t}}})():void 0,g={"--accent":e.mood.accent,"--intensity":e.mood.intensity},_=e.voice.mode,v=_===`listening`?`listening`:_===`speaking`?`speaking`:_===`transcribing`?`thinking`:e.presence.state,b=kS(e.look.reactivity),x=Math.min(1,(_===`listening`||_===`speaking`?e.voice.level:e.presence.amplitude)*b),S=(0,y.useRef)({timer:null,down:!1,talking:!1,id:null}),C=e=>{if(!(e.target===e.currentTarget||e.target.closest(`[data-presence]`))||e.pointerType===`mouse`&&e.button!==0)return;let t=S.current;if(!(t.down&&t.id!==null&&e.pointerId!==t.id)){t.timer&&clearTimeout(t.timer),t.down=!0,t.talking=!1,t.id=typeof e.pointerId==`number`?e.pointerId:null;try{t.id!==null&&e.currentTarget.setPointerCapture?.(t.id)}catch{}t.timer=r?setTimeout(()=>{t.down&&(t.talking=!0,r.pressStart())},Bk):null}},T=(e,t)=>{let n=S.current;n.down&&(n.id===null||typeof e.pointerId!=`number`||e.pointerId===n.id)&&(n.down=!1,n.id=null,n.timer&&clearTimeout(n.timer),n.timer=null,n.talking?(n.talking=!1,t?r?.blur?.():r?.pressEnd()):t||l(e=>e+1))},E=(0,y.useRef)(null),D=Pk(t,n,()=>E.current),O=(0,y.useMemo)(()=>e.objects.filter(e=>!e.docked),[e.objects]),k=(0,y.useMemo)(()=>e.objects.filter(e=>e.docked),[e.objects]),A=Dk(O,Lk()?0:Ik),j=A.filter(e=>e.object.layer===`overlay`),ee=A.filter(e=>e.object.layer!==`overlay`&&e.object.placement===`auto`),M=A.filter(e=>e.object.layer!==`overlay`&&e.object.placement!==`auto`),N=({object:e,leaving:r})=>{let i=Tk[e.type];if(!i)return null;let a=e.layer===`overlay`,o=!p&&!r&&!a,c=D.preview?.id===e.id?D.preview.box:null,l=c?{x:c.x,y:c.y,w:c.w,h:c.h}:e.placement;return(0,w.jsxs)(`section`,{"data-object":e.id,className:`obj glass${pu(e.type)?` obj-bare`:``}${e.style===`alert`?` alert`:``}${a?` overlay`:``}${e.pinned?` pinned`:``}${c?` dragging`:``}${r?` leaving`:``}`,style:a?void 0:Fk(l,s),children:[o&&(0,w.jsx)(`div`,{className:`obj-grip`,role:`button`,tabIndex:0,"aria-label":`Move ${e.id}. Drag, or use the arrow keys; hold Shift to resize.`,...pu(e.type)?{"data-label":typeof e.props.title==`string`&&e.props.title.trim()?e.props.title.trim().slice(0,40):e.id}:{},onPointerDown:t=>D.begin(t,e,`move`),onPointerMove:D.move,onPointerUp:e=>D.end(e,!1),onPointerCancel:e=>D.end(e,!0),onKeyDown:t=>D.key(t,e)}),!a&&(0,w.jsx)(`button`,{className:`obj-pin${e.pinned?` on`:``}`,"aria-label":e.pinned?`Unpin ${e.id}`:`Pin ${e.id} to the screen`,"aria-pressed":!!e.pinned,title:e.pinned?`Pinned: stays on the screen. Click to unpin.`:`Pin: keep this on the screen.`,disabled:r,onClick:()=>t({type:`stage.pin`,objectId:e.id,pinned:!e.pinned}),children:(0,w.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:e.pinned?`currentColor`:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,w.jsx)(`path`,{d:`M12 17v5M9 3h6l-1 7 3 3H7l3-3-1-7z`})})}),(0,w.jsx)(`button`,{className:`obj-close`,"aria-label":`Dismiss ${e.id}`,title:e.pinned?`Remove this widget`:`Dismiss`,disabled:r,onClick:()=>{t({type:`stage.event`,objectId:e.id,event:`dismiss`}),n({type:`object.dismiss`,id:e.id})},children:`×`}),o&&(0,w.jsx)(`div`,{className:`obj-resize`,"aria-hidden":`true`,onPointerDown:t=>D.begin(t,e,`resize`),onPointerMove:D.move,onPointerUp:e=>D.end(e,!1),onPointerCancel:e=>D.end(e,!0)}),(0,w.jsx)(Rk,{children:(0,w.jsx)(i,{props:e.props})})]},e.id)};return(0,w.jsxs)(`div`,{ref:E,"data-testid":`stage`,className:`stage`,style:g,onPointerDown:C,onPointerUp:e=>T(e,!1),onPointerCancel:e=>T(e,!0),onContextMenu:e=>r&&e.preventDefault(),children:[e.look.ambient&&(0,w.jsx)(`div`,{className:`ambient`,"aria-hidden":`true`,style:{opacity:.35+.65*e.mood.intensity}}),(0,w.jsx)(OS,{state:v,amplitude:x,pulse:e.presence.pulse,mode:m&&!o?`corner`:`full`,accent:e.mood.accent,style:e.presence.style,intensity:e.mood.intensity,scale:e.look.size}),o,(0,w.jsxs)(`div`,{className:p?`objects objects-stack`:`objects`,style:{zIndex:10},children:[(0,w.jsx)(lw,{chips:k,onRestore:e=>t({type:`stage.dock`,objectId:e,docked:!1})}),ee.length>0&&(0,w.jsx)(`div`,{className:`auto-grid`,children:ee.map(N)}),M.map(N)]}),j.length>0&&(0,w.jsxs)(`div`,{className:`overlay-layer`,"data-testid":`overlay`,children:[(0,w.jsx)(`div`,{className:`overlay-backdrop`,onClick:()=>j.forEach(({object:e})=>{t({type:`stage.event`,objectId:e.id,event:`dismiss`}),n({type:`object.dismiss`,id:e.id})})}),j.map(N)]}),e.look.captions&&e.captions&&(0,w.jsx)(`p`,{className:`captions captions-${e.look.captionSize}${e.captionDone?` done`:``}`,"aria-live":`polite`,children:e.captions}),f&&r&&!u&&(0,w.jsx)(Ew,{voice:r,mode:_,onType:()=>l(e=>e+1),onMenu:()=>a?.()}),(0,w.jsx)(dw,{requestOpen:c,slash:i,onOpenChange:d,onSend:e=>t({type:`chat.send`,text:e}),...h?{hud:h}:{}})]})}function Hk(){let e=()=>Math.random().toString(36).slice(2,12)+Date.now().toString(36);try{let t=sessionStorage.getItem(`friend.tab`);return t||(t=e(),sessionStorage.setItem(`friend.tab`,t)),t}catch{return e()}}function Uk(){return`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`}function Wk(e=Uk()){let t=null,n=`connecting`,r=!1,i=0,a=!1,o=Hk(),s=null,c=new Set,l=new Set,u=e=>{n=e,l.forEach(t=>t(e))};function d(){if(r)return;u(`connecting`);let n=new WebSocket(`${e}${e.includes(`?`)?`&`:`?`}tab=${o}${a?`&takeover=1`:``}`);t=n,n.onopen=()=>{i=0,a=!1,u(`open`)},n.onmessage=e=>{try{let t=JSON.parse(String(e.data));c.forEach(e=>e(t))}catch{}},n.onclose=e=>{if(!r){if(e.code===4401)return u(`unauthorized`);if(e.code===4409||e.code===4410)return u(`elsewhere`);u(`closed`),s=setTimeout(d,Math.min(500*2**i++,8e3))}},n.onerror=()=>{}}return d(),{send(e){t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify(e))},onMessage(e){return c.add(e),()=>c.delete(e)},onState(e){return l.add(e),()=>l.delete(e)},state:()=>n,takeOver(){r||n!==`elsewhere`||(a=!0,i=0,d())},close(){r=!0,s&&clearTimeout(s),t?.close()}}}var Gk={scene:`conversation`,objects:[],widgets:[],captions:``,captionDone:!0,presence:{state:`idle`,style:`sphere`,amplitude:0,pulse:0},mood:{accent:`#3fd8ff`,intensity:.6},approval:null,alerts:[],connection:`connecting`,chat:[],chatLive:!1,view:`companion`,look:{size:1,reactivity:.7,ambient:!0,captions:!0,captionSize:`medium`},viewKnown:!1,busy:!1,activity:null,deviceOnline:!1,voice:{mode:`idle`,level:0,available:!1,enrolled:!1},challenge:null,camera:{enabled:!1,stream:null},speaker:null,ownerName:``,assistantName:``,hud:null,music:null,hostMusic:null,musicCmd:null,uiOpen:null,stats:null,office:{enabled:!1,workers:[],tickets:[],quota:{fiveHour:null,sevenDay:null},feed:{}}},Kk=200,qk=e=>e.length>Kk?e.slice(-200):e,Jk=0,Yk=e=>Math.min(1,Math.max(0,e));function Xk(e,t){switch(t.cmd){case`scene`:return{...e,scene:t.mode};case`show`:{let n=e.objects.findIndex(e=>e.id===t.object.id),r=n===-1?[...e.objects,t.object]:e.objects.map((e,r)=>r===n?t.object:e);return{...e,objects:r}}case`update`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,props:{...e.props,...t.props}}:e)};case`hide`:return{...e,objects:e.objects.filter(e=>e.id!==t.id)};case`dock`:return{...e,objects:e.objects.map(e=>e.id===t.id?t.docked?{...e,docked:!0}:(({docked:e,...t})=>t)(e):e)};case`clear`:return{...e,objects:e.objects.filter(e=>e.pinned),widgets:t.keepInstruments?e.widgets:[],scene:`conversation`};case`widget`:{let n=t.reset?[]:e.widgets.filter(e=>!(t.hide??[]).includes(e));return{...e,widgets:[...n,...(t.show??[]).filter(e=>!n.includes(e))]}}case`pin`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,pinned:!0}:e)};case`unpin`:return{...e,objects:e.objects.map(e=>e.id===t.id?(({pinned:e,...t})=>t)(e):e)};case`place`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,placement:t.placement}:e)};case`presence`:return{...e,presence:{...e.presence,state:t.state??e.presence.state,style:t.style??e.presence.style}};case`mood`:return{...e,mood:{accent:t.accent??e.mood.accent,intensity:t.intensity??e.mood.intensity}}}}function Zk(e,t){let n=t;if(n&&typeof n==`object`){if(n.type===`conn`)return{...e,connection:n.value};if(n.type===`chat.seed`){let t=Array.isArray(n.lines)?n.lines:[];return e.chat.length===0?{...e,chat:qk(t)}:{...e,chat:qk([...t,...e.chat])}}if(n.type===`alert.add`)return{...e,alerts:[...e.alerts.slice(-3),{id:++Jk,level:n.level,text:n.text}]};if(n.type===`camera.enable`)return{...e,camera:{enabled:n.value,stream:n.value?e.camera.stream:null}};if(n.type===`camera.open`)return{...e,camera:{...e.camera,stream:n.stream}};if(n.type===`camera.still`)return{...e,camera:{...e.camera,still:{url:n.url,note:n.note}}};if(n.type===`camera.still.clear`)return{...e,camera:{...e.camera,still:null}};if(n.type===`camera.closed`)return{...e,camera:{...e.camera,stream:null}};if(n.type===`challenge.dismiss`)return e.challenge?.id===n.id?{...e,challenge:null}:e;if(n.type===`voice.mode`)return{...e,voice:{...e.voice,mode:n.mode,level:n.mode===`idle`?0:e.voice.level}};if(n.type===`voice.level`){let t=Number.isFinite(n.level)?Math.min(1,Math.max(0,n.level)):0;return{...e,voice:{...e.voice,level:t}}}if(n.type===`object.dismiss`)return{...e,objects:e.objects.filter(e=>e.id!==n.id)};if(n.type===`object.place`)return{...e,objects:e.objects.map(e=>e.id===n.id?{...e,placement:n.placement}:e)};if(n.type===`alert.dismiss`)return{...e,alerts:e.alerts.filter(e=>e.id!==n.id)}}let r=Cd.safeParse(t);if(!r.success)return e;let i=r.data;switch(i.type){case`snapshot`:return{...e,scene:i.stage.scene,objects:i.stage.objects,widgets:i.stage.widgets??[],presence:{...e.presence,state:i.stage.presence.state,style:i.stage.presence.style},mood:i.stage.mood,approval:i.pendingApproval??null};case`stage`:return Xk(e,i.command);case`chat.user`:return{...e,chat:qk([...e.chat,{role:`user`,text:i.text}]),chatLive:!1};case`ui.open`:return{...e,uiOpen:{n:(e.uiOpen?.n??0)+1,...i.integration?{integration:i.integration}:{}}};case`ui`:return{...e,view:i.view,look:i.look??e.look,ownerName:i.ownerName??e.ownerName,assistantName:i.assistantName??e.assistantName,hud:i.hud??e.hud,music:i.music??e.music,viewKnown:!0};case`music.host`:return{...e,hostMusic:i.state};case`music.command`:{let{type:t,...n}=i;return{...e,musicCmd:{n:(e.musicCmd?.n??0)+1,command:n}}}case`caption.delta`:{let t=e.captionDone,n=e.chat.at(-1),r=e.chatLive&&n?.role===`assistant`?[...e.chat.slice(0,-1),{role:`assistant`,text:n.text+i.text}]:qk([...e.chat,{role:`assistant`,text:i.text}]);return{...e,chat:r,chatLive:!0,captions:(t?``:e.captions)+i.text,captionDone:!1,presence:{...e.presence,amplitude:Yk(.3+i.text.length*.04),pulse:e.presence.pulse+1}}}case`caption.end`:return{...e,chatLive:!1,captionDone:!0,presence:{...e.presence,amplitude:0}};case`approval.request`:{let{type:t,...n}=i;return{...e,approval:n}}case`approval.resolved`:return e.approval?.id===i.id?{...e,approval:null}:e;case`alert`:return{...e,alerts:[...e.alerts.slice(-3),{id:++Jk,level:i.level,text:i.text}]};case`activity`:return{...e,activity:i.text};case`office.state`:{let t={};for(let n of i.workers)e.office.feed[n.id]&&(t[n.id]=e.office.feed[n.id]);return{...e,office:{enabled:i.enabled,workers:i.workers,tickets:i.tickets,quota:i.quota,feed:t}}}case`office.feed`:{if(!e.office.workers.some(e=>e.id===i.workerId))return e;let t={at:i.at,kind:i.kind,text:i.text},n=[...e.office.feed[i.workerId]??[],t].slice(-60);return{...e,office:{...e.office,feed:{...e.office.feed,[i.workerId]:n}}}}case`hud.stats`:return{...e,stats:{cpu:i.cpu,ramUsed:i.ramUsed,ramTotal:i.ramTotal,netDown:i.netDown,netUp:i.netUp,at:Date.now()}};case`status`:return{...e,busy:i.busy,activity:i.busy?e.activity:null,deviceOnline:i.deviceOnline,voice:{...e.voice,available:i.voiceAvailable??e.voice.available,enrolled:i.voiceEnrolled??e.voice.enrolled}};case`error`:return{...e,alerts:[...e.alerts.slice(-3),{id:++Jk,level:`error`,text:i.message}]};case`voice.heard`:return{...e,captions:i.trust===`guest`?`Guest: ${i.text}`:i.trust===`member`&&i.speaker?`${i.speaker}: ${i.text}`:i.text,captionDone:!0,speaker:{name:i.trust===`member`?i.speaker??null:null,trust:i.trust??`unverified`,seq:(e.speaker?.seq??0)+1}};case`voice.challenge`:return{...e,challenge:{id:i.id,text:i.text}};case`voice.challenge.end`:return e.challenge?.id===i.id?{...e,challenge:null}:e;case`audio.chunk`:case`audio.stop`:case`audio.duck`:return e;case`camera.request`:case`camera.cancel`:case`screen.request`:case`screen.cancel`:case`screen.check`:return e}}var Qk=1024,$k=.8,eA=300;function tA(e,t){let n=Math.min(1,Qk/Math.max(e,t));return{width:Math.round(e*n),height:Math.round(t*n)}}function nA(e){let t=e?.name;return t===`NotAllowedError`||t===`SecurityError`?`permission`:t===`NotFoundError`||t===`OverconstrainedError`?`no-camera`:`busy`}async function rA(){if(!navigator.mediaDevices?.getUserMedia)throw Object.assign(Error(`This browser cannot use the camera here (use localhost or HTTPS).`),{name:`NotFoundError`});return navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280}},audio:!1})}async function iA(e,t=eA){let n=document.createElement(`video`);n.muted=!0,n.playsInline=!0,n.srcObject=e,await n.play(),await new Promise(e=>setTimeout(e,t));let{width:r,height:i}=tA(n.videoWidth||640,n.videoHeight||480),a=document.createElement(`canvas`);return a.width=r,a.height=i,a.getContext(`2d`).drawImage(n,0,0,r,i),n.srcObject=null,new Promise((e,t)=>a.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,$k))}async function aA(e,t,n,r=eA){let i=document.createElement(`video`);i.muted=!0,i.playsInline=!0,i.srcObject=e,await i.play(),await new Promise(e=>setTimeout(e,r));let{width:a,height:o}=tA(i.videoWidth||640,i.videoHeight||480),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=t>1?n*1e3/(t-1):0,l=[];try{for(let e=0;e<t;e++)e>0&&await new Promise(e=>setTimeout(e,c)),s.getContext(`2d`).drawImage(i,0,0,a,o),l.push(await new Promise((e,t)=>s.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,$k)))}finally{i.srcObject=null}return l}var oA=class{opts;active=null;shown=null;constructor(e){this.opts=e}async handle(e){if(e.type===`camera.cancel`){let t=this.active;t&&t.id===e.id&&(t.cancelled=!0,this.release(t));return}if(!this.opts.enabled())return this.opts.send({type:`camera.denied`,id:e.id,reason:`off`});if(this.active)return this.opts.send({type:`camera.denied`,id:e.id,reason:`busy`});this.clearStill();let t={id:e.id,cancelled:!1,stream:null,opened:!1,released:!1};this.active=t;try{let n=await(this.opts.open??rA)();if(t.stream=n,t.cancelled){n.getTracks().forEach(e=>e.stop());return}t.opened=!0,this.opts.dispatch({type:`camera.open`,stream:n});let r=typeof e.frames==`number`&&e.frames>1?{frames:Math.min(12,Math.round(e.frames)),seconds:Math.min(10,Math.max(1,Math.round(e.seconds??5)))}:null,i=r?await(this.opts.frames??((e,t,n)=>aA(e,t,n)))(n,r.frames,r.seconds):[await(this.opts.frame??(e=>iA(e)))(n)];if(t.cancelled)return;this.release(t);let a=i[Math.floor(i.length/2)],o=!!(e.recognise&&this.opts.faces&&this.opts.sendFaces),s=this.showStill(a,o?`Looking…`:`Looked`);if(o){let t=`No face found`;try{let n=await this.opts.faces(a);n.length?(await this.opts.sendFaces(e.id,n),t=n.length===1?`1 face found`:`${n.length} faces found`):this.opts.faceProblem?.()&&(t=`The face models did not load`)}catch{}s&&this.shown?.url===s&&this.opts.dispatch({type:`camera.still`,url:s,note:t})}try{for(let t of i)await this.opts.upload(e.id,t)}catch{this.opts.dispatch({type:`alert.add`,level:`warn`,text:`Could not send the camera picture to Friend.`})}}catch(n){t.cancelled||this.opts.send({type:`camera.denied`,id:e.id,reason:nA(n)})}finally{this.release(t),this.active===t&&(this.active=null)}}showStill(e,t){try{let n=(this.opts.still??(e=>URL.createObjectURL(e)))(e);this.opts.dispatch({type:`camera.still`,url:n,note:t});let r=setTimeout(()=>this.clearStill(),this.opts.holdMs??5e3);return this.shown={url:n,timer:r},n}catch{return null}}clearStill(){let e=this.shown;e&&(this.shown=null,clearTimeout(e.timer),this.opts.dispatch({type:`camera.still.clear`}),(this.opts.release??(e=>URL.revokeObjectURL(e)))(e.url))}dispose(){this.clearStill();let e=this.active;e&&(e.cancelled=!0,this.release(e))}release(e){e.released||(e.released=!0,e.stream?.getTracks().forEach(e=>e.stop()),e.opened&&this.opts.dispatch({type:`camera.closed`}))}},sA=[8,16,32],cA=e=>e<0?0:e>1?1:e;function lA(e){let t=Math.min(640/e.width,640/e.height),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t)),i=409600,a=new Float32Array(3*i);for(let o=0;o<r;o++){let r=Math.min(e.height-1,(o+.5)/t-.5),s=Math.max(0,Math.floor(r)),c=Math.min(e.height-1,s+1),l=Math.max(0,r-s);for(let r=0;r<n;r++){let n=Math.min(e.width-1,(r+.5)/t-.5),u=Math.max(0,Math.floor(n)),d=Math.min(e.width-1,u+1),f=Math.max(0,n-u),p=(t,n,r)=>e.data[(n*e.width+t)*4+r];for(let e=0;e<3;e++){let t=p(u,s,e)*(1-f)+p(d,s,e)*f,n=p(u,c,e)*(1-f)+p(d,c,e)*f;a[(2-e)*i+o*640+r]=t*(1-l)+n*l}}}return{tensor:a,scale:t}}var uA=(e,t)=>{let[n,r,i,a]=e.box,[o,s,c,l]=t.box,u=Math.min(n+i,o+c)-Math.max(n,o),d=Math.min(r+a,s+l)-Math.max(r,s);if(u<=0||d<=0)return 0;let f=u*d;return f/(i*a+c*l-f)};function dA(e,t,n=.7,r=.3){let i=[];for(let r of sA){let a=640/r,o=e[`cls_${r}`].data,s=e[`obj_${r}`].data,c=e[`bbox_${r}`].data,l=e[`kps_${r}`].data;for(let e=0;e<a*a;e++){let u=Math.sqrt(cA(o[e])*cA(s[e]));if(u<n)continue;let d=Math.floor(e/a),f=e%a,p=(f+c[e*4])*r,m=(d+c[e*4+1])*r,h=Math.exp(c[e*4+2])*r,g=Math.exp(c[e*4+3])*r,_=[];for(let n=0;n<5;n++)_.push([(l[e*10+n*2]+f)*r/t,(l[e*10+n*2+1]+d)*r/t]);i.push({box:[(p-h/2)/t,(m-g/2)/t,h/t,g/t],score:u,landmarks:_})}}i.sort((e,t)=>t.score-e.score);let a=[];for(let e of i)a.every(t=>uA(t,e)<r)&&a.push(e);return a}async function fA(e,t,n,r=.7){let{tensor:i,scale:a}=lA(n);return dA(await t.run({[t.inputNames[0]]:new e.Tensor(`float32`,i,[1,3,640,640])}),a,r)}var pA=[[38.2946,51.6963],[73.5318,51.5014],[56.0252,71.7366],[41.5493,92.3655],[70.7299,92.2041]];function mA(e){let t=e.length,n=e.reduce((e,t)=>e+t[0],0)/t,r=e.reduce((e,t)=>e+t[1],0)/t,i=pA.reduce((e,t)=>e+t[0],0)/t,a=pA.reduce((e,t)=>e+t[1],0)/t,o=0,s=0,c=0;for(let l=0;l<t;l++){let t=e[l][0]-n,u=e[l][1]-r,d=pA[l][0]-i,f=pA[l][1]-a;o+=t*d+u*f,s+=t*f-u*d,c+=t*t+u*u}let l=o/c,u=s/c;return[l,u,i-(l*n-u*r),a-(u*n+l*r)]}function hA(e,t){let[n,r,i,a]=mA(t),o=n*n+r*r,s=12544,c=new Float32Array(3*s);for(let t=0;t<112;t++)for(let l=0;l<112;l++){let u=l-i,d=t-a,f=(n*u+r*d)/o,p=(-r*u+n*d)/o,m=Math.floor(f),h=Math.floor(p),g=f-m,_=p-h;for(let n=0;n<3;n++){let r=(t,r)=>{let i=Math.min(e.width-1,Math.max(0,t)),a=Math.min(e.height-1,Math.max(0,r));return e.data[(a*e.width+i)*4+n]},i=r(m,h)*(1-g)+r(m+1,h)*g,a=r(m,h+1)*(1-g)+r(m+1,h+1)*g;c[n*s+t*112+l]=i*(1-_)+a*_}}return c}async function gA(e,t,n,r){let i=hA(n,r.landmarks),a=await t.run({[t.inputNames[0]]:new e.Tensor(`float32`,i,[1,3,112,112])});return Array.from(a[t.outputNames[0]].data)}var _A=5,vA=60;function yA(e,t=_A,n=vA){return e.filter(e=>Math.min(e.box[2],e.box[3])>=n).sort((e,t)=>t.box[2]*t.box[3]-e.box[2]*e.box[3]).slice(0,t)}var bA=class{deps;loaded=null;failed=!1;constructor(e){this.deps=e}async find(e){try{this.loaded??=this.deps.load();let{ort:t,yunet:n,sface:r}=await this.loaded,i=await this.deps.decode(e),a=yA(await fA(t,n,i)),o=[];for(let e of a)o.push(await gA(t,r,i,e));return this.failed=!1,o}catch{return this.loaded=null,this.failed=!0,[]}}};async function xA(e){let t=await createImageBitmap(e),n=document.createElement(`canvas`);n.width=t.width,n.height=t.height;let r=n.getContext(`2d`);r.drawImage(t,0,0),t.close?.();let i=r.getImageData(0,0,n.width,n.height);return{data:i.data,width:i.width,height:i.height}}var SA={mjs:`/ort/ort-wasm-simd-threaded.mjs`,wasm:`/ort/ort-wasm-simd-threaded.wasm`};function CA(){return new bA({decode:xA,load:async()=>{let e=await uk(()=>import(`./ort.bundle.min-CGCwMY8z.js`),[]);e.env.wasm.wasmPaths={...SA},e.env.wasm.numThreads=1;let t=async t=>e.InferenceSession.create(new Uint8Array(await(await fetch(t)).arrayBuffer()),{executionProviders:[`wasm`]});return{ort:e,yunet:await t(`/models/yunet.onnx`),sface:await t(`/models/sface.onnx`)}}})}function wA(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;let n=document.implementation.createHTMLDocument(),r=n.createElement(`base`),i=n.createElement(`a`);return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}var TA=(()=>{let e=0,t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function EA(e){let t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}var DA=null;function OA(e={}){return DA||(e.includeStyleProperties?(DA=e.includeStyleProperties,DA):(DA=EA(window.getComputedStyle(document.documentElement)),DA))}function kA(e,t){let n=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return n?parseFloat(n.replace(`px`,``)):0}function AA(e){let t=kA(e,`border-left-width`),n=kA(e,`border-right-width`);return e.clientWidth+t+n}function jA(e){let t=kA(e,`border-top-width`),n=kA(e,`border-bottom-width`);return e.clientHeight+t+n}function MA(e,t={}){return{width:t.width||AA(e),height:t.height||jA(e)}}function NA(){let e,t;try{t=process}catch{}let n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}var PA=16384;function FA(e){(e.width>PA||e.height>PA)&&(e.width>PA&&e.height>PA?e.width>e.height?(e.height*=PA/e.width,e.width=PA):(e.width*=PA/e.height,e.height=PA):e.width>PA?(e.height*=PA/e.width,e.width=PA):(e.width*=PA/e.height,e.height=PA))}function IA(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin=`anonymous`,r.decoding=`async`,r.src=e})}async function LA(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(e=>`data:image/svg+xml;charset=utf-8,${e}`)}async function RA(e,t,n){let r=`http://www.w3.org/2000/svg`,i=document.createElementNS(r,`svg`),a=document.createElementNS(r,`foreignObject`);return i.setAttribute(`width`,`${t}`),i.setAttribute(`height`,`${n}`),i.setAttribute(`viewBox`,`0 0 ${t} ${n}`),a.setAttribute(`width`,`100%`),a.setAttribute(`height`,`100%`),a.setAttribute(`x`,`0`),a.setAttribute(`y`,`0`),a.setAttribute(`externalResourcesRequired`,`true`),i.appendChild(a),a.appendChild(e),LA(i)}var zA=(e,t)=>{if(e instanceof t)return!0;let n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||zA(n,t)};function BA(e){let t=e.getPropertyValue(`content`);return`${e.cssText} content: '${t.replace(/'|"/g,``)}';`}function VA(e,t){return OA(t).map(t=>`${t}: ${e.getPropertyValue(t)}${e.getPropertyPriority(t)?` !important`:``};`).join(` `)}function HA(e,t,n,r){let i=`.${e}:${t}`,a=n.cssText?BA(n):VA(n,r);return document.createTextNode(`${i}{${a}}`)}function UA(e,t,n,r){let i=window.getComputedStyle(e,n),a=i.getPropertyValue(`content`);if(a===``||a===`none`)return;let o=TA();try{t.className=`${t.className} ${o}`}catch{return}let s=document.createElement(`style`);s.appendChild(HA(o,n,i,r)),t.appendChild(s)}function WA(e,t,n){UA(e,t,`:before`,n),UA(e,t,`:after`,n)}var GA=`application/font-woff`,KA=`image/jpeg`,qA={woff:GA,woff2:GA,ttf:`application/font-truetype`,eot:`application/vnd.ms-fontobject`,png:`image/png`,jpg:KA,jpeg:KA,gif:`image/gif`,tiff:`image/tiff`,svg:`image/svg+xml`,webp:`image/webp`};function JA(e){let t=/\.([^./]*?)$/g.exec(e);return t?t[1]:``}function YA(e){return qA[JA(e).toLowerCase()]||``}function XA(e){return e.split(/,/)[1]}function ZA(e){return e.search(/^(data:)/)!==-1}function QA(e,t){return`data:${t};base64,${e}`}async function $A(e,t,n){let r=await fetch(e,t);if(r.status===404)throw Error(`Resource "${r.url}" not found`);let i=await r.blob();return new Promise((e,t)=>{let a=new FileReader;a.onerror=t,a.onloadend=()=>{try{e(n({res:r,result:a.result}))}catch(e){t(e)}},a.readAsDataURL(i)})}var ej={};function tj(e,t,n){let r=e.replace(/\?.*/,``);return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,``)),t?`[${t}]${r}`:r}async function nj(e,t,n){let r=tj(e,t,n.includeQueryParams);if(ej[r]!=null)return ej[r];n.cacheBust&&(e+=(/\?/.test(e)?`&`:`?`)+new Date().getTime());let i;try{i=QA(await $A(e,n.fetchRequestInit,({res:e,result:n})=>(t||=e.headers.get(`Content-Type`)||``,XA(n))),t)}catch(t){i=n.imagePlaceholder||``;let r=`Failed to fetch resource: ${e}`;t&&(r=typeof t==`string`?t:t.message),r&&console.warn(r)}return ej[r]=i,i}async function rj(e){let t=e.toDataURL();return t===`data:,`?e.cloneNode(!1):IA(t)}async function ij(e,t){if(e.currentSrc){let t=document.createElement(`canvas`),n=t.getContext(`2d`);return t.width=e.clientWidth,t.height=e.clientHeight,n?.drawImage(e,0,0,t.width,t.height),IA(t.toDataURL())}let n=e.poster;return IA(await nj(n,YA(n),t))}async function aj(e,t){try{if(e?.contentDocument?.body)return await hj(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function oj(e,t){return zA(e,HTMLCanvasElement)?rj(e):zA(e,HTMLVideoElement)?ij(e,t):zA(e,HTMLIFrameElement)?aj(e,t):e.cloneNode(cj(e))}var sj=e=>e.tagName!=null&&e.tagName.toUpperCase()===`SLOT`,cj=e=>e.tagName!=null&&e.tagName.toUpperCase()===`SVG`;async function lj(e,t,n){if(cj(t))return t;let r=[];return r=sj(e)&&e.assignedNodes?EA(e.assignedNodes()):zA(e,HTMLIFrameElement)&&e.contentDocument?.body?EA(e.contentDocument.body.childNodes):EA((e.shadowRoot??e).childNodes),r.length===0||zA(e,HTMLVideoElement)||await r.reduce((e,r)=>e.then(()=>hj(r,n)).then(e=>{e&&t.appendChild(e)}),Promise.resolve()),t}function uj(e,t,n){let r=t.style;if(!r)return;let i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):OA(n).forEach(n=>{let a=i.getPropertyValue(n);n===`font-size`&&a.endsWith(`px`)&&(a=`${Math.floor(parseFloat(a.substring(0,a.length-2)))-.1}px`),zA(e,HTMLIFrameElement)&&n===`display`&&a===`inline`&&(a=`block`),n===`d`&&t.getAttribute(`d`)&&(a=`path(${t.getAttribute(`d`)})`),r.setProperty(n,a,i.getPropertyPriority(n))})}function dj(e,t){zA(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),zA(e,HTMLInputElement)&&t.setAttribute(`value`,e.value)}function fj(e,t){if(zA(e,HTMLSelectElement)){let n=t,r=Array.from(n.children).find(t=>e.value===t.getAttribute(`value`));r&&r.setAttribute(`selected`,``)}}function pj(e,t,n){return zA(t,Element)&&(uj(e,t,n),WA(e,t,n),dj(e,t),fj(e,t)),t}async function mj(e,t){let n=e.querySelectorAll?e.querySelectorAll(`use`):[];if(n.length===0)return e;let r={};for(let i=0;i<n.length;i++){let a=n[i].getAttribute(`xlink:href`);if(a){let n=e.querySelector(a),i=document.querySelector(a);!n&&i&&!r[a]&&(r[a]=await hj(i,t,!0))}}let i=Object.values(r);if(i.length){let t=`http://www.w3.org/1999/xhtml`,n=document.createElementNS(t,`svg`);n.setAttribute(`xmlns`,t),n.style.position=`absolute`,n.style.width=`0`,n.style.height=`0`,n.style.overflow=`hidden`,n.style.display=`none`;let r=document.createElementNS(t,`defs`);n.appendChild(r);for(let e=0;e<i.length;e++)r.appendChild(i[e]);e.appendChild(n)}return e}async function hj(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(e=>oj(e,t)).then(n=>lj(e,n,t)).then(n=>pj(e,n,t)).then(e=>mj(e,t))}var gj=/url\((['"]?)([^'"]+?)\1\)/g,_j=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,vj=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function yj(e){let t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,`\\$1`);return RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,`g`)}function bj(e){let t=[];return e.replace(gj,(e,n,r)=>(t.push(r),e)),t.filter(e=>!ZA(e))}async function xj(e,t,n,r,i){try{let a=n?wA(t,n):t,o=YA(t),s;return s=i?QA(await i(a),o):await nj(a,o,r),e.replace(yj(t),`$1${s}$3`)}catch{}return e}function Sj(e,{preferredFontFormat:t}){return t?e.replace(vj,e=>{for(;;){let[n,,r]=_j.exec(e)||[];if(!r)return``;if(r===t)return`src: ${n};`}}):e}function Cj(e){return e.search(gj)!==-1}async function wj(e,t,n){if(!Cj(e))return e;let r=Sj(e,n);return bj(r).reduce((e,r)=>e.then(e=>xj(e,r,t,n)),Promise.resolve(r))}async function Tj(e,t,n){let r=t.style?.getPropertyValue(e);if(r){let i=await wj(r,null,n);return t.style.setProperty(e,i,t.style.getPropertyPriority(e)),!0}return!1}async function Ej(e,t){await Tj(`background`,e,t)||await Tj(`background-image`,e,t),await Tj(`mask`,e,t)||await Tj(`-webkit-mask`,e,t)||await Tj(`mask-image`,e,t)||await Tj(`-webkit-mask-image`,e,t)}async function Dj(e,t){let n=zA(e,HTMLImageElement);if((!n||ZA(e.src))&&(!zA(e,SVGImageElement)||ZA(e.href.baseVal)))return;let r=n?e.src:e.href.baseVal,i=await nj(r,YA(r),t);await new Promise((r,a)=>{e.onload=r,e.onerror=t.onImageErrorHandler?(...e)=>{try{r(t.onImageErrorHandler(...e))}catch(e){a(e)}}:a;let o=e;o.decode&&=r,o.loading===`lazy`&&(o.loading=`eager`),n?(e.srcset=``,e.src=i):e.href.baseVal=i})}async function Oj(e,t){let n=EA(e.childNodes).map(e=>kj(e,t));await Promise.all(n).then(()=>e)}async function kj(e,t){zA(e,Element)&&(await Ej(e,t),await Dj(e,t),await Oj(e,t))}function Aj(e,t){let{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);let r=t.style;return r!=null&&Object.keys(r).forEach(e=>{n[e]=r[e]}),e}var jj={};async function Mj(e){let t=jj[e];return t??(t={url:e,cssText:await(await fetch(e)).text()},jj[e]=t,t)}async function Nj(e,t){let n=e.cssText,r=/url\(["']?([^"')]+)["']?\)/g,i=(n.match(/url\([^)]+\)/g)||[]).map(async i=>{let a=i.replace(r,`$1`);return a.startsWith(`https://`)||(a=new URL(a,e.url).href),$A(a,t.fetchRequestInit,({result:e})=>(n=n.replace(i,`url(${e})`),[i,e]))});return Promise.all(i).then(()=>n)}function Pj(e){if(e==null)return[];let t=[],n=e.replace(/(\/\*[\s\S]*?\*\/)/gi,``),r=RegExp(`((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})`,`gi`);for(;;){let e=r.exec(n);if(e===null)break;t.push(e[0])}n=n.replace(r,``);let i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,a=RegExp(`((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})`,`gi`);for(;;){let e=i.exec(n);if(e===null){if(e=a.exec(n),e===null)break;i.lastIndex=a.lastIndex}else a.lastIndex=i.lastIndex;t.push(e[0])}return t}async function Fj(e,t){let n=[],r=[];return e.forEach(n=>{if(`cssRules`in n)try{EA(n.cssRules||[]).forEach((e,i)=>{if(e.type===CSSRule.IMPORT_RULE){let a=i+1,o=e.href,s=Mj(o).then(e=>Nj(e,t)).then(e=>Pj(e).forEach(e=>{try{n.insertRule(e,e.startsWith(`@import`)?a+=1:n.cssRules.length)}catch(t){console.error(`Error inserting rule from remote css`,{rule:e,error:t})}})).catch(e=>{console.error(`Error loading remote css`,e.toString())});r.push(s)}})}catch(i){let a=e.find(e=>e.href==null)||document.styleSheets[0];n.href!=null&&r.push(Mj(n.href).then(e=>Nj(e,t)).then(e=>Pj(e).forEach(e=>{a.insertRule(e,a.cssRules.length)})).catch(e=>{console.error(`Error loading remote stylesheet`,e)})),console.error(`Error inlining remote css file`,i)}}),Promise.all(r).then(()=>(e.forEach(e=>{if(`cssRules`in e)try{EA(e.cssRules||[]).forEach(e=>{n.push(e)})}catch(t){console.error(`Error while reading CSS rules from ${e.href}`,t)}}),n))}function Ij(e){return e.filter(e=>e.type===CSSRule.FONT_FACE_RULE).filter(e=>Cj(e.style.getPropertyValue(`src`)))}async function Lj(e,t){if(e.ownerDocument==null)throw Error(`Provided element is not within a Document`);return Ij(await Fj(EA(e.ownerDocument.styleSheets),t))}function Rj(e){return e.trim().replace(/["']/g,``)}function zj(e){let t=new Set;function n(e){(e.style.fontFamily||getComputedStyle(e).fontFamily).split(`,`).forEach(e=>{t.add(Rj(e))}),Array.from(e.children).forEach(e=>{e instanceof HTMLElement&&n(e)})}return n(e),t}async function Bj(e,t){let n=await Lj(e,t),r=zj(e);return(await Promise.all(n.filter(e=>r.has(Rj(e.style.fontFamily))).map(e=>{let n=e.parentStyleSheet?e.parentStyleSheet.href:null;return wj(e.cssText,n,t)}))).join(`
4460
- `)}async function Vj(e,t){let n=t.fontEmbedCSS==null?t.skipFonts?null:await Bj(e,t):t.fontEmbedCSS;if(n){let t=document.createElement(`style`),r=document.createTextNode(n);t.appendChild(r),e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}}async function Hj(e,t={}){let{width:n,height:r}=MA(e,t),i=await hj(e,t,!0);return await Vj(i,t),await kj(i,t),Aj(i,t),await RA(i,n,r)}async function Uj(e,t={}){let{width:n,height:r}=MA(e,t),i=await IA(await Hj(e,t)),a=document.createElement(`canvas`),o=a.getContext(`2d`),s=t.pixelRatio||NA(),c=t.canvasWidth||n,l=t.canvasHeight||r;return a.width=c*s,a.height=l*s,t.skipAutoScale||FA(a),a.style.width=`${c}`,a.style.height=`${l}`,t.backgroundColor&&(o.fillStyle=t.backgroundColor,o.fillRect(0,0,a.width,a.height)),o.drawImage(i,0,0,a.width,a.height),a}var Wj=1600,Gj=.85;function Kj(e,t){let n=Math.min(1,Wj/Math.max(e,t,1));return{width:Math.max(1,Math.round(e*n)),height:Math.max(1,Math.round(t*n))}}async function qj(){let e=document.documentElement.getBoundingClientRect(),t=await Uj(document.body,{width:Math.round(e.width),height:Math.round(e.height),pixelRatio:1,backgroundColor:`#050b10`,filter:e=>!(e instanceof HTMLElement&&e.dataset.noCapture!==void 0)}),n=Kj(t.width,t.height),r=document.createElement(`canvas`);return r.width=n.width,r.height=n.height,r.getContext(`2d`).drawImage(t,0,0,n.width,n.height),new Promise((e,t)=>r.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,Gj))}var Jj=class{opts;active=null;constructor(e){this.opts=e}async handle(e){if(e.type===`screen.cancel`){this.active&&this.active.id===e.id&&(this.active.cancelled=!0);return}if(this.active)return this.opts.send({type:`screen.denied`,id:e.id,reason:`busy`});let t={id:e.id,cancelled:!1};this.active=t;try{let n=await(this.opts.capture??qj)();if(t.cancelled)return;try{await this.opts.upload(e.id,n)}catch{this.opts.dispatch({type:`alert.add`,level:`warn`,text:`Could not send the picture of the screen to Friend.`})}}catch(n){t.cancelled||this.opts.send({type:`screen.denied`,id:e.id,reason:Yj(n)})}finally{this.active===t&&(this.active=null)}}dispose(){this.active&&(this.active.cancelled=!0)}};function Yj(e){return e?.name===`NotSupportedError`?`unsupported`:`failed`}var Xj=12,Zj=e=>e.length>200?`${e.slice(0,199)}…`:e,Qj=.2,$j=4,eM=(e,t)=>{let n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x),r=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n<=0||r<=0?0:n*r/Math.max(1,Math.min(e.w*e.h,t.w*t.h))};function tM(e){if(e.objects.length===0)return[`No objects are on the screen.`];let t=[],n=e=>Math.round(e);for(let r of e.objects){r.drawn||t.push(`${r.id}: nothing is drawn in it (an empty box). Hide it, or check its props.`),(r.scrollH-r.h>$j||r.scrollW-r.w>$j)&&t.push(`${r.id}: its content is cut off: it needs about ${n(Math.max(r.scrollW,r.w))}x${n(Math.max(r.scrollH,r.h))} px and the box is ${n(r.w)}x${n(r.h)} px. Make the box bigger or the content smaller.`);let i=Math.max(0,-r.x,-r.y,r.x+r.w-e.view.w,r.y+r.h-e.view.h);i>$j&&t.push(`${r.id}: ${n(i)} px of it is outside the screen. Move it inside.`)}for(let n=0;n<e.objects.length;n++){for(let r=n+1;r<e.objects.length;r++)eM(e.objects[n],e.objects[r])>Qj&&t.push(`${e.objects[n].id} and ${e.objects[r].id} overlap. Move one of them.`);for(let r of e.hud)eM(e.objects[n],r)>Qj&&t.push(`${e.objects[n].id} covers the ${r.id} instrument. Move it to a free place.`)}if(t.length===0)return[`All ${e.objects.length} objects are fully visible, nothing overlaps.`];let r=t.map(Zj);return r.length>Xj?[...r.slice(0,11),`…and ${r.length-11} more problems of the same kind.`]:r}function nM(e,t){let n=e=>{let t=e.getBoundingClientRect();return{x:t.x,y:t.y,w:t.width,h:t.height}},r=[...e.querySelectorAll(`[data-object]`)].filter(e=>!e.classList.contains(`leaving`)).map(e=>({id:e.dataset.object??`?`,...n(e),scrollW:e.scrollWidth,scrollH:e.scrollHeight,drawn:(!e.querySelector(`.obj-jarvis, .obj-empty`)||!e.querySelector(`.obj-empty`))&&((e.textContent??``).replace(/[×📌\s]/g,``).length>0||!!e.querySelector(`svg, canvas, img, video, iframe`))})),i=[...e.querySelectorAll(`.orbital [data-widget]`)].map(e=>({id:e.dataset.widget??`?`,...n(e)}));return{view:{w:t.innerWidth,h:t.innerHeight},objects:r,hud:i}}function rM(e,t){let n=(0,y.useRef)(t);n.current=t;let r=(0,y.useRef)(!1),i=(0,y.useRef)(null);(0,y.useEffect)(()=>{let t=e===`listening`||e===`speaking`;i.current&&clearTimeout(i.current),i.current=null,t?r.current||(r.current=!0,n.current({type:`audio.activity`,active:!0})):r.current&&(i.current=setTimeout(()=>{i.current=null,r.current=!1,n.current({type:`audio.activity`,active:!1})},900))},[e]),(0,y.useEffect)(()=>()=>{i.current&&clearTimeout(i.current),r.current&&(r.current=!1,n.current({type:`audio.activity`,active:!1}))},[])}var iM={401:`Please sign in again.`,413:`That recording was too long.`,409:`Friend is busy with the last request. Try again in a moment.`,429:`You're talking too fast. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function aM(e,t,n){let r;try{r=await fetch(e,{method:`POST`,headers:{"content-type":t.type||`audio/webm`},body:t,signal:n})}catch(e){throw e.name===`AbortError`?e:Error(`Could not reach Friend. Check the connection.`)}if(!r.ok){let e=``;try{e=(await r.json()).error??``}catch{}throw Error(e||iM[r.status]||`The voice request failed (${r.status}).`)}let i=await r.json();return{text:typeof i.text==`string`?i.text:``,wake:i.wake===!0}}async function oM(e,t){return{text:(await aM(`/api/voice/utterance`,e,t)).text}}async function sM(e,t){let n=await aM(`/api/voice/utterance?wake=1`,e,t);return{text:n.text,wake:n.wake===!0}}var cM=null;function lM(){try{cM??=new AudioContext,cM.resume().catch(()=>{});let e=cM.currentTime;for(let[t,n]of[660,990].entries()){let r=cM.createOscillator(),i=cM.createGain();r.frequency.value=n,i.gain.setValueAtTime(0,e+t*.11),i.gain.linearRampToValueAtTime(.18,e+t*.11+.02),i.gain.exponentialRampToValueAtTime(.001,e+t*.11+.14),r.connect(i).connect(cM.destination),r.start(e+t*.11),r.stop(e+t*.11+.16)}}catch{}}var uM=/busy with the last request|talking too fast/i,dM=3e4,fM=50,pM=class{deps;listener=null;awakeNow=!1;showing=!1;busyWithOne=!1;clock=null;meter=null;abort=null;lastAlert=0;constructor(e){this.deps=e}get enabled(){return this.listener!==null}get awake(){return this.awakeNow}async enable(){if(this.listener)return;let e=this.deps.makeListener({onUtterance:e=>void this.heard(e),onError:e=>{this.drop(),this.alert(e,!0)}});try{await e.start()}catch(e){this.alert(e.message,!0);return}this.listener=e}disable(){this.drop()}sync(){let e=this.listener;if(!e)return;let t=this.busyOther();if(e.pause(t),!this.awakeNow||t){this.clearClock(),this.stopMeter();return}this.deps.mode()===`idle`&&this.show(),this.clock||this.startClock(),this.startMeter()}busyOther(){let e=this.deps.mode();return e!==`listening`&&(this.showing=!1),e===`speaking`||e===`transcribing`||e===`listening`&&!this.showing}show(){this.showing=!0,this.deps.dispatch({type:`voice.mode`,mode:`listening`})}wakeUp(e){this.awakeNow=!0,e&&this.deps.chime(),this.clearClock(),this.show(),this.startClock(),this.startMeter()}sleep(){this.awakeNow=!1,this.clearClock(),this.stopMeter(),this.showing&&this.deps.dispatch({type:`voice.mode`,mode:`idle`}),this.showing=!1}drop(){let e=this.listener;this.listener=null,this.abort?.abort(),this.abort=null,this.busyWithOne=!1,this.sleep(),e?.stop()}startClock(){this.clearClock(),this.clock=setTimeout(()=>{this.clock=null,this.sleep()},this.deps.awakeMs??3e4)}clearClock(){this.clock&&clearTimeout(this.clock),this.clock=null}startMeter(){this.meter||=setInterval(()=>this.deps.dispatch({type:`voice.level`,level:this.listener?.level()??0}),fM)}stopMeter(){this.meter&&clearInterval(this.meter),this.meter=null}async heard(e){if(!this.listener||this.busyWithOne||this.busyOther())return;this.busyWithOne=!0;let t=new AbortController;this.abort=t;try{this.awakeNow?await this.request(e,t.signal):await this.check(e,t.signal)}catch(e){e.name!==`AbortError`&&!uM.test(e.message)&&this.alert(e.message,!1)}finally{this.abort===t&&(this.abort=null),this.busyWithOne=!1,this.listener&&this.awakeNow&&(this.clearClock(),this.deps.mode()===`transcribing`&&this.deps.dispatch({type:`voice.mode`,mode:`idle`}),this.sync())}}async check(e,t){let n=await this.deps.wake(e,t);this.listener&&n.wake&&this.wakeUp(!n.text)}async request(e,t){this.clearClock(),this.stopMeter(),this.showing=!1,this.deps.dispatch({type:`voice.mode`,mode:`transcribing`}),await this.deps.command(e,t)}alert(e,t){let n=Date.now();!t&&n-this.lastAlert<dM||(this.lastAlert=n,this.deps.dispatch({type:`alert.add`,level:`error`,text:e}))}},mM=0,hM=new Set;function gM(e){return hM.add(e),()=>hM.delete(e)}var _M=e=>hM.forEach(t=>{try{t(e)}catch{}}),vM=e=>/not compatible|audio capture|audiosession/i.test(String(e?.message??e));function yM(e){try{let t=navigator.audioSession;t&&t.type!==e&&(t.type=e)}catch{}}function bM(){mM===0&&yM(`playback`)}function xM(){mM++,mM===1&&_M(!0),yM(`play-and-record`);let e=!1;return()=>{e||(e=!0,mM=Math.max(0,mM-1),mM===0&&(yM(`playback`),_M(!1)))}}var SM=3,CM=.02,wM=.04,TM=class{minSpeechMs;endSilenceMs;maxMs;floor=null;loudSince=null;speaking=!1;startedAt=0;lastLoud=0;lastFeed=0;speechMs=0;constructor(e={}){this.minSpeechMs=e.minSpeechMs??300,this.endSilenceMs=e.endSilenceMs??800,this.maxMs=e.maxMs??8e3}get inSpeech(){return this.speaking}get maybeSpeech(){return this.loudSince!==null}feed(e,t){this.floor===null&&(this.floor=e);let n=e>Math.max(this.floor*SM+CM,wM),r=Math.min(100,Math.max(0,t-this.lastFeed));if(this.lastFeed=t,!this.speaking)return n?(this.loudSince??=t,t-this.loudSince<this.minSpeechMs?null:(this.speaking=!0,this.startedAt=this.loudSince,this.lastLoud=t,this.speechMs=t-this.loudSince,{type:`start`})):(this.loudSince=null,this.floor+=(e-this.floor)*(e<this.floor?.3:.02),null);n&&(this.lastLoud=t,this.speechMs+=r);let i=t-this.startedAt>=this.maxMs;if(!i&&t-this.lastLoud<this.endSilenceMs)return null;let a={type:`end`,ms:t-this.startedAt,speechMs:this.speechMs,forced:i};return this.speaking=!1,this.loudSince=null,i&&n&&(this.floor=e),a}reset(){this.speaking=!1,this.loudSince=null}},EM=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`],DM=50,OM=2e3,kM=2e3,AM=400,jM=e=>{let t=e?.name;return t===`NotAllowedError`||t===`SecurityError`?`Microphone permission was denied. Allow it in the browser to use hands-free.`:t===`NotFoundError`||t===`OverconstrainedError`?`No microphone was found.`:e?.message||`Could not open the microphone.`},MM=class{opts;stream=null;ctx=null;analyser=null;rec=null;chunks=[];recStartedAt=0;timer=null;seg;leaveSession=null;paused=!1;starting=!1;finishing=!1;opened=!1;now;constructor(e){this.opts=e,this.seg=new TM(e),this.now=e.now??(()=>Date.now())}static supported(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`}get listening(){return this.opened}async start(){if(!(this.opened||this.starting)){this.starting=!0;try{this.leaveSession=xM();try{this.stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})}catch(e){throw this.leaveSession?.(),this.leaveSession=null,Error(jM(e))}for(let e of this.stream.getTracks())e.onended=()=>this.broke(`The microphone stopped working.`);try{this.ctx=new AudioContext,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.ctx.createMediaStreamSource(this.stream).connect(this.analyser),this.ctx.resume().catch(()=>{})}catch{throw this.release(),Error(`This browser cannot listen continuously here.`)}this.seg.reset(),this.beginRecording(),this.opened=!0,this.timer=setInterval(()=>this.tick(),DM)}finally{this.starting=!1}}}stop(){this.opened=!1,this.release()}pause(e){this.paused!==e&&(this.paused=e,this.seg.reset(),!e&&this.opened&&this.restartRecording())}level(){if(!this.analyser)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}tick(){if(!this.opened)return;let e=this.now();if(this.ctx&&this.ctx.state!==`running`&&this.ctx.resume().catch(()=>{}),this.paused){e-this.recStartedAt>=OM&&this.restartRecording();return}let t=this.seg.feed(this.level(),e);t?.type===`end`?this.finish(t.ms,t.speechMs):!t&&!this.seg.inSpeech&&!this.seg.maybeSpeech&&e-this.recStartedAt>=OM&&this.restartRecording()}beginRecording(){if(!this.stream)return;let e=EM.find(e=>MediaRecorder.isTypeSupported(e));this.chunks=[];let t=new MediaRecorder(this.stream,e?{mimeType:e}:void 0);t.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=()=>this.broke(`The microphone stopped working.`),t.start(250),this.rec=t,this.recStartedAt=this.now()}restartRecording(){let e=this.rec;if(this.rec=null,e){e.ondataavailable=null,e.onstop=null,e.onerror=null;try{e.state!==`inactive`&&e.stop()}catch{}}this.opened&&this.beginRecording()}async finish(e,t){let n=this.rec;if(!n||this.finishing)return;this.finishing=!0;let r=n.mimeType||`audio/webm`,i=await new Promise(e=>{let t=!1,i=()=>{t||(t=!0,e(new Blob(this.chunks,{type:r})))},a=setTimeout(i,kM);n.onstop=()=>{clearTimeout(a),i()};try{n.state===`inactive`?i():n.stop()}catch{i()}});this.finishing=!1,this.rec=null,this.opened&&(this.beginRecording(),!this.paused&&e>=AM&&t>=AM/2&&i.size>0&&this.opts.onUtterance(i))}broke(e){this.opened&&(this.stop(),this.opts.onError(e))}release(){if(this.timer&&clearInterval(this.timer),this.timer=null,this.rec){this.rec.ondataavailable=null,this.rec.onstop=null,this.rec.onerror=null;try{this.rec.state!==`inactive`&&this.rec.stop()}catch{}}this.stream?.getTracks().forEach(e=>{e.onended=null,e.stop()}),this.ctx?.close().catch(()=>{}),this.stream=null,this.ctx=null,this.analyser=null,this.rec=null,this.chunks=[],this.leaveSession?.(),this.leaveSession=null}},NM=4096,PM=8,FM=20,IM=6e6;function LM(e){try{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}catch{return null}}var RM=class{ctx=null;analyser=null;pending=new Map;queue=[];current=null;busy=!1;gen=0;isPlaying=!1;unwatch=null;listeners=new Set;unlock(){bM();let e=this.ensureContext();e.state!==`running`&&e.resume().catch(()=>{})}locked(){return!this.ctx||this.ctx.state!==`running`}enqueue(e){if(!Number.isInteger(e.seq)||e.seq<0||e.seq>NM)return;let t=LM(e.data);if(!t)return;let n=this.pending.get(e.id);if(n||(this.pending.size>=PM&&this.pending.delete(this.pending.keys().next().value),n={parts:new Map,lastSeq:null,bytes:0},this.pending.set(e.id,n)),n.bytes+=t.length,n.bytes>IM){this.pending.delete(e.id);return}if(n.parts.set(e.seq,t),e.last&&(n.lastSeq=e.seq),n.lastSeq===null||n.parts.size!==n.lastSeq+1)return;this.pending.delete(e.id);let r=new Uint8Array([...n.parts.values()].reduce((e,t)=>e+t.length,0)),i=0;for(let e=0;e<=n.lastSeq;e++){let t=n.parts.get(e);if(!t)return;r.set(t,i),i+=t.length}for(this.queue.push(r.buffer);this.queue.length>FM;)this.queue.shift();this.pump()}stop(){this.gen++,this.queue=[],this.pending.clear(),this.busy=!1;let e=this.current;if(this.current=null,e){e.onended=null;try{e.stop()}catch{}}this.setPlaying(!1)}dispose(){this.stop(),this.ctx?.close().catch(()=>{}),this.unwatch?.(),this.unwatch=null,this.ctx=null,this.analyser=null}playing(){return this.isPlaying}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}level(){if(!this.analyser||!this.isPlaying)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}ensureContext(){if(!this.ctx){let e=window.AudioContext??window.webkitAudioContext;this.ctx=new e,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.analyser.connect(this.ctx.destination);let t=this.ctx;this.unwatch?.(),this.unwatch=gM(e=>{e&&t.state===`running`?t.suspend().catch(()=>{}):!e&&t.state!==`running`&&t.state!==`closed`&&t.resume().catch(()=>{})})}return this.ctx}setPlaying(e){this.isPlaying!==e&&(this.isPlaying=e,this.listeners.forEach(t=>t(e)))}async pump(){if(this.busy)return;let e=this.queue.shift();if(!e){this.setPlaying(!1);return}this.busy=!0;let t=this.gen;try{let n=this.ensureContext();if(n.state!==`running`){try{await n.resume()}catch{}if(t!==this.gen)return;if(n.state!==`running`){this.queue.unshift(e),this.busy=!1;return}}let r=await n.decodeAudioData(e);if(t!==this.gen)return;let i=n.createBufferSource();i.buffer=r,i.connect(this.analyser),i.onended=()=>{this.current===i&&(this.current=null,this.busy=!1,this.pump())},this.current=i,this.setPlaying(!0),i.start()}catch{if(t!==this.gen)return;this.busy=!1,this.pump()}}},zM=e=>new Promise(t=>setTimeout(t,e)),BM=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`],VM=3e3;function HM(e){let t=e;return t?.name===`NotAllowedError`||t?.name===`SecurityError`?Error(`Microphone permission was denied. Allow it in the browser to talk.`):t?.name===`NotFoundError`||t?.name===`OverconstrainedError`?Error(`No microphone was found.`):Error(t?.message||`Could not open the microphone.`)}var UM=class e{opts;stream=null;rec=null;chunks=[];ctx=null;analyser=null;timer=null;starting=!1;leaveSession=null;constructor(e={}){this.opts=e}static supported(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`}get active(){return this.rec!==null}async start(){if(!(this.rec||this.starting)){if(!e.supported())throw Error(`This browser cannot record audio here (use localhost or HTTPS).`);this.starting=!0;try{this.leaveSession=xM();try{let e=()=>navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});try{this.stream=await e()}catch(t){if(!vM(t))throw t;await zM(250),this.leaveSession?.(),this.leaveSession=xM(),this.stream=await e()}}catch(e){throw this.leaveSession?.(),this.leaveSession=null,HM(e)}try{let e=BM.find(e=>MediaRecorder.isTypeSupported(e));this.chunks=[];let t=new MediaRecorder(this.stream,e?{mimeType:e}:void 0);t.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=()=>this.failed();for(let e of this.stream.getTracks())e.onended=()=>this.failed();this.openMeter(this.stream),t.start(250),this.rec=t,this.opts.maxMs&&(this.timer=setTimeout(()=>{this.timer=null,this.opts.onLimit?.()},this.opts.maxMs))}catch(e){throw this.release(),HM(e)}}finally{this.starting=!1}}}stop(){let e=this.rec;return e?new Promise(t=>{let n=!1,r=null,i=()=>{if(n)return;n=!0,r&&clearTimeout(r);let i=new Blob(this.chunks,{type:e.mimeType||`audio/webm`});this.release(),t(i)};if(r=setTimeout(i,VM),e.onstop=i,e.state===`inactive`)return i();try{e.stop()}catch{i()}}):Promise.reject(Error(`Not recording.`))}cancel(){let e=this.rec;if(e){e.ondataavailable=null,e.onstop=null,e.onerror=null;try{e.state!==`inactive`&&e.stop()}catch{}}this.release()}level(){if(!this.analyser||!this.rec)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}failed(){this.rec&&(this.cancel(),this.opts.onError?.())}openMeter(e){try{this.ctx=new AudioContext,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.ctx.createMediaStreamSource(e).connect(this.analyser)}catch{this.analyser=null}}release(){this.timer&&clearTimeout(this.timer),this.timer=null,this.stream?.getTracks().forEach(e=>{e.onended=null,e.stop()}),this.ctx?.close().catch(()=>{}),this.stream=null,this.rec=null,this.ctx=null,this.analyser=null,this.chunks=[],this.leaveSession?.(),this.leaveSession=null}},WM=2e3,GM=()=>typeof window<`u`&&window.isSecureContext===!1,KM=50,qM=class{deps;recorder;player;mode=`idle`;pressed=!1;disposed=!1;uploads=0;toldAboutSound=!1;quiet=!1;abort=null;poll=null;unsubscribe;constructor(e){this.deps=e;let t=()=>this.recorderFailed();this.recorder=e.recorder??e.makeRecorder?.(t)??new UM({maxMs:6e4,onLimit:()=>void this.pressEnd(),onError:t}),this.player=e.player??new RM,this.unsubscribe=this.player.onChange(e=>{this.mode!==`listening`&&this.mode!==`transcribing`&&this.setMode(e?`speaking`:`idle`)})}async pressStart(){if(!(this.pressed||this.disposed)){if(!this.deps.available()){this.alert(`warn`,`Voice is not available. Run: friend voice setup`);return}if(!(this.deps.supported?.()??UM.supported())){this.alert(`warn`,GM()?`This page is not secure, so the browser blocks the microphone. On the PC run: friend lan https on, restart Friend, and open the https:// address.`:`This browser cannot record audio here (use localhost or HTTPS).`);return}this.pressed=!0,this.player.unlock(),this.player.playing()&&(this.deps.send({type:`voice.interrupt`}),this.player.stop());try{await this.recorder.start()}catch(e){this.pressed=!1,this.alert(`error`,e.message),this.setMode(`idle`);return}if(!this.pressed){this.recorder.cancel(),this.setMode(`idle`);return}this.setMode(`listening`)}}async pressEnd(){if(!this.pressed||(this.pressed=!1,!this.recorder.active))return;let e=await this.recorder.stop();if(e.size<WM){this.alert(`info`,`Hold the key a little longer while you speak.`),this.setMode(`idle`);return}this.setMode(`transcribing`);let t=new AbortController;this.abort=t,this.uploads++;try{let{text:n}=await this.deps.post(e,t.signal);n.trim()||this.alert(`info`,`I didn't catch that.`)}catch(e){e.name!==`AbortError`&&this.alert(`error`,e.message)}finally{this.uploads--,this.abort===t&&(this.abort=null),this.settle()}}blur(){this.pressed&&(this.pressed=!1,this.recorder.cancel(),this.setMode(`idle`))}setQuiet(e){this.quiet=e,e&&this.player.stop()}handleServer(e){if(e.type!==`audio.chunk`)return this.player.stop();this.quiet||(this.player.enqueue(e),!this.toldAboutSound&&this.player.locked?.()&&(this.toldAboutSound=!0,this.deps.dispatch({type:`alert.add`,level:`info`,text:`Sound is blocked by the browser. Click or press a key once anywhere on the page to hear me.`})))}unlock(){this.player.unlock()}dispose(){this.disposed=!0,this.pressed=!1,this.stopPolling(),this.abort?.abort(),this.recorder.cancel(),this.player.stop(),this.player.dispose?.(),this.unsubscribe()}recorderFailed(){this.pressed=!1,this.recorder.cancel(),this.alert(`error`,`The microphone stopped working.`),this.setMode(`idle`)}settle(){this.uploads>0||this.mode!==`transcribing`||this.setMode(this.player.playing()?`speaking`:`idle`)}setMode(e){this.disposed||(this.mode=e,this.deps.dispatch({type:`voice.mode`,mode:e}),e===`listening`||e===`speaking`?this.startPolling():this.stopPolling())}startPolling(){this.stopPolling(),this.poll=setInterval(()=>{let e=this.mode===`listening`?this.recorder.level():this.player.level();this.deps.dispatch({type:`voice.level`,level:e})},KM)}stopPolling(){this.poll&&clearInterval(this.poll),this.poll=null}alert(e,t){this.disposed||this.deps.dispatch({type:`alert.add`,level:e,text:t})}};function JM(e){let[t,n]=(0,y.useReducer)(Zk,Gk),r=(0,y.useRef)(null),i=(0,y.useRef)(null),a=(0,y.useRef)(!1),o=(0,y.useRef)(null),s=(0,y.useRef)(null),[c,l]=(0,y.useState)(!1),u=(0,y.useRef)(e);u.current=e;let d=(0,y.useRef)(t);d.current=t,(0,y.useEffect)(()=>{let e=Wk();r.current=e;let t=new qM({send:t=>e.send(t),dispatch:e=>n(e),post:oM,available:()=>d.current.voice.available});i.current=t,t.setQuiet(a.current);let c=new pM({makeListener:e=>new MM(e),wake:sM,command:oM,mode:()=>d.current.voice.mode,chime:lM,dispatch:e=>n(e)});s.current=c;let f=CA(),p=new oA({send:t=>e.send(t),dispatch:e=>n(e),enabled:()=>d.current.camera.enabled,upload:async(e,t)=>{let n=await fetch(`/api/camera/frame/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`image/jpeg`},body:t});if(!n.ok)throw Error(`upload failed (${n.status})`)},faces:e=>f.find(e),faceProblem:()=>f.failed,sendFaces:async(e,t)=>{await fetch(`/api/camera/faces/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({faces:t})})}});o.current=p;let m=new Jj({send:t=>e.send(t),dispatch:e=>n(e),upload:async(e,t)=>{let n=await fetch(`/api/screen/frame/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`image/jpeg`},body:t});if(!n.ok)throw Error(`upload failed (${n.status})`)}}),h=e.onMessage(r=>{n(r);let i=r?.type,a=r?.id;if((i===`camera.request`||i===`camera.cancel`)&&typeof a==`string`){let{frames:e,seconds:t,recognise:n}=r;p.handle({type:i,id:a,...typeof e==`number`?{frames:e}:{},...typeof t==`number`?{seconds:t}:{},...n===!0?{recognise:!0}:{}})}(i===`screen.request`||i===`screen.cancel`)&&typeof a==`string`&&m.handle({type:i,id:a}),i===`screen.check`&&typeof a==`string`&&setTimeout(()=>e.send({type:`screen.checked`,id:a,lines:tM(nM(document,window))}),500),i===`audio.duck`&&EO.set(r.level??1),(i===`audio.chunk`||i===`audio.stop`)&&t.handleServer(r)}),g=e.onState(e=>{n({type:`conn`,value:e}),e!==`open`&&EO.set(1,0),e===`unauthorized`&&u.current(),e===`elsewhere`&&(c.disable(),l(!1),t.blur(),p.dispose(),m.dispose())});return()=>{h(),g(),c.disable(),s.current=null,t.dispose(),p.dispose(),m.dispose(),e.close(),i.current=null,o.current=null,r.current=null}},[]),(0,y.useEffect)(()=>{t.camera.enabled||o.current?.dispose()},[t.camera.enabled]),(0,y.useEffect)(()=>{s.current?.sync()},[t.voice.mode]);let f=(0,y.useCallback)(async e=>{let t=s.current;if(t){e?await t.enable():t.disable(),l(t.enabled);try{localStorage.setItem(`friend.handsFree`,t.enabled?`1`:`0`)}catch{}}},[]),p=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!p.current&&t.voice.available){p.current=!0;try{localStorage.getItem(`friend.handsFree`)===`1`&&MM.supported()&&f(!0)}catch{}}},[t.voice.available,f]);let m=(0,y.useMemo)(()=>({on:c,supported:MM.supported(),toggle:()=>void f(!s.current?.enabled)}),[c,f]),h=(0,y.useCallback)(e=>r.current?.send(e),[]);return rM(t.voice.mode,h),{state:t,send:h,dispatch:(0,y.useCallback)(e=>n(e),[]),voice:(0,y.useMemo)(()=>({pressStart:()=>void i.current?.pressStart(),pressEnd:()=>void i.current?.pressEnd(),blur:()=>i.current?.blur(),unlock:()=>i.current?.unlock(),setQuiet:e=>{a.current=e,i.current?.setQuiet(e)}}),[]),handsFree:m,useHere:(0,y.useCallback)(()=>r.current?.takeOver(),[]),officeStop:(0,y.useCallback)(e=>h({type:`office.stop`,...e?{workerId:e}:{}}),[h]),officeSay:(0,y.useCallback)((e,t)=>h({type:`office.say`,workerId:e,text:t}),[h])}}var YM={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function XM(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||YM[n.status]||`The request failed (${n.status}).`)}return await n.json()}var ZM=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),QM={state:()=>XM(`/api/voice/enroll`,{}),sample:e=>XM(`/api/voice/enroll/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>XM(`/api/voice/enroll/finish`,ZM(`POST`,{pin:e})),cancel:async()=>{await XM(`/api/voice/enroll/cancel`,ZM(`POST`,{}))},remove:async e=>{await XM(`/api/voice/enroll`,ZM(`DELETE`,{pin:e}))}},$M=[`Friend, good evening. It is a pleasant day to get things done.`,`Open my projects and show me what changed today.`,`My voice is my key, so please remember it well.`,`Check the weather and read me the latest headlines.`,`Always protect the boss, and never trust a stranger.`],eN=15e3;function tN({api:e=QM,createRecorder:t=e=>new UM(e),onClose:n,who:r}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(0),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(`record`),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),S=(0,y.useRef)(!0),C=(0,y.useRef)(null);(0,y.useEffect)(()=>(S.current=!0,e.state().then(e=>{S.current&&(a(e),s(e.samples))}).catch(e=>S.current&&_(e.message)),()=>{S.current=!1,C.current?.cancel(),C.current=null}),[e]);let T=(0,y.useCallback)(async()=>{let t=C.current;if(t){C.current=null,p(!1),h(!0);try{let n=await t.stop(),r=await e.sample(n);if(!S.current)return;s(r.count),l(r.note)}catch(e){S.current&&_(e.message)}finally{S.current&&h(!1)}}},[e]),E=async()=>{_(null),l(null);let e=t({maxMs:eN,onLimit:()=>void T(),onError:()=>{C.current=null,S.current&&(p(!1),_(`The microphone stopped working. Try again.`))}});try{await e.start()}catch(e){S.current&&_(e.message);return}if(!S.current)return e.cancel();C.current=e,p(!0)},D=async e=>{_(null),h(!0);try{await e()}catch(e){S.current&&_(e.message)}finally{S.current&&(h(!1),b(``))}},O=async()=>{C.current?.cancel(),C.current=null,await e.cancel().catch(()=>{}),n()},k=i?.min??3,A=o%$M.length,j=o<$M.length?`Phrase ${o+1} of ${$M.length}`:`Extra recording (${o} so far)`;return(0,w.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Voice enrollment`,style:{pointerEvents:`auto`},children:[(0,w.jsx)(`div`,{className:`approval-head`,children:(0,w.jsx)(`span`,{className:`approval-title`,children:r?`Teach Friend ${r}'s voice`:`Teach Friend your voice`})}),u===`record`&&(0,w.jsxs)(w.Fragment,{children:[!r&&i?.enrolled&&(0,w.jsx)(`p`,{className:`auth-note`,children:`Your voice is already saved. Saving a new one replaces it.`}),r&&(0,w.jsxs)(`p`,{className:`auth-note`,children:[`Hand the device to `,r,`. `,r,` reads each sentence aloud, close to the microphone, in a quiet room.`]}),(0,w.jsxs)(`p`,{className:`auth-note`,children:[j,`. Press Record, read this aloud in a quiet room, then press Stop.`]}),(0,w.jsx)(`pre`,{className:`approval-summary`,"data-testid":`enroll-phrase`,style:{whiteSpace:`pre-wrap`},children:$M[A]}),(0,w.jsxs)(`div`,{role:`status`,className:`auth-note`,children:[o,` recorded`,o>=k?` — enough to save`:` — at least ${k} needed`,`.`,c?` ${c}`:``]}),g&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[f?(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,onClick:()=>void T(),children:`Stop`}):(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:m||!i||o>=(i?.max??8),onClick:()=>void E(),children:m?`Uploading…`:`Record`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:f||m||o<k,onClick:()=>d(`pin-save`),children:r?`Save ${r}'s voice`:`Save my voice`}),!r&&i?.enrolled&&(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,disabled:f||m,onClick:()=>d(`pin-delete`),children:`Delete my voice`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>void O(),children:`Cancel`})]})]}),(u===`pin-save`||u===`pin-delete`)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:u===`pin-save`?r?`Enter your PIN to save ${r}'s voice.`:`Enter your PIN to save your voice.`:`Enter your PIN to delete your saved voice.`}),(0,w.jsx)(F,{pin:v,onChange:b,onSubmit:u===`pin-save`?()=>!m&&void D(async()=>{await e.finish(v),S.current&&d(`saved`)}):void 0}),g&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[u===`pin-save`?(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:m||v.length<6,onClick:()=>void D(async()=>{await e.finish(v),S.current&&d(`saved`)}),children:`Save`}):(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,disabled:m||v.length<6,onClick:()=>void D(async()=>{await e.remove(v),S.current&&d(`deleted`)}),children:`Delete`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{b(``),_(null),d(`record`)},children:`Back`})]})]}),(u===`saved`||u===`deleted`)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:u===`saved`?r?`${r}'s voice is saved. From now on I will know when ${r} is talking.`:`Your voice is saved. From now on I will tell you apart from other speakers.`:`Your voice was deleted. Every voice is treated as yours until you enroll again.`}),(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,onClick:n,children:`Done`})})]})]})}var nN=new Set([`INPUT`,`TEXTAREA`,`SELECT`,`BUTTON`,`A`,`SUMMARY`]),rN=new Set([`button`,`checkbox`,`switch`,`tab`,`menuitem`,`link`,`radio`,`option`,`textbox`,`combobox`,`slider`]),iN=e=>e instanceof HTMLInputElement&&e.hasAttribute(`data-space-talks`)&&e.value===``,aN=e=>!iN(e)&&e instanceof HTMLElement&&(nN.has(e.tagName)||e.isContentEditable||rN.has(e.getAttribute(`role`)??``)),oN=e=>e.code===`Space`||e.key===` `;function sN(e){let t=(0,y.useRef)(e);t.current=e,(0,y.useEffect)(()=>{let e=!1,n=n=>{!oN(n)||n.ctrlKey||n.metaKey||n.altKey||aN(n.target)||aN(document.activeElement)||(n.preventDefault(),!(n.repeat||e)&&(e=!0,t.current.pressStart()))},r=n=>{oN(n)&&e&&(e=!1,n.preventDefault(),t.current.pressEnd())},i=()=>{e=!1,t.current.blur()},a=()=>{document.hidden&&i()},o=e=>{if(e.detail===0||!(e.target instanceof Element))return;let t=e.target.closest(`button, [role=button], summary, a`);t instanceof HTMLElement&&setTimeout(()=>{document.activeElement===t&&t.blur()},0)};return document.addEventListener(`click`,o),window.addEventListener(`keydown`,n),window.addEventListener(`keyup`,r),window.addEventListener(`blur`,i),document.addEventListener(`visibilitychange`,a),()=>{document.removeEventListener(`click`,o),window.removeEventListener(`keydown`,n),window.removeEventListener(`keyup`,r),window.removeEventListener(`blur`,i),document.removeEventListener(`visibilitychange`,a)}},[])}function cN(e){let t=(0,y.useRef)(e);t.current=e,(0,y.useEffect)(()=>{let e=()=>t.current.unlock(),n=[`pointerdown`,`keydown`,`touchend`];for(let t of n)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of n)window.removeEventListener(t,e)}},[])}function lN({onUseHere:e}){return(0,w.jsx)(`div`,{className:`elsewhere`,role:`alertdialog`,"aria-labelledby":`elsewhere-title`,"data-testid":`elsewhere`,children:(0,w.jsxs)(`div`,{className:`elsewhere-card`,children:[(0,w.jsx)(`h2`,{id:`elsewhere-title`,children:`Friend is open in another window`}),(0,w.jsx)(`p`,{children:`Friend works in one window at a time. Click “Use here” to use it in this window instead; the other one will stop.`}),(0,w.jsx)(`button`,{type:`button`,className:`elsewhere-btn`,onClick:e,autoFocus:!0,children:`Use here`})]})})}function uN(e,t,n){let r=Math.max(100,Math.round(e)),i=Math.max(100,Math.round(t));return{width:r,height:i,kind:r<=599?`phone`:n||r<1024?`tablet`:`desktop`,orientation:i>r?`portrait`:`landscape`,touch:n}}var dN=()=>typeof matchMedia==`function`&&matchMedia(`(pointer: coarse)`).matches;function fN(){return uN(window.innerWidth,window.innerHeight,dN())}var pN=(e,t)=>!!e&&e.width===t.width&&e.height===t.height&&e.kind===t.kind&&e.orientation===t.orientation&&e.touch===t.touch;function mN(e,t){let n=(0,y.useRef)(null),r=(0,y.useRef)(e);r.current=e,(0,y.useEffect)(()=>{if(t!==`open`){n.current=null;return}let e=()=>{let e=fN();pN(n.current,e)||(n.current=e,r.current({type:`ui.screen`,...e}))};e();let i=null,a=()=>{i&&clearTimeout(i),i=setTimeout(e,400)};return window.addEventListener(`resize`,a),window.addEventListener(`orientationchange`,a),()=>{i&&clearTimeout(i),window.removeEventListener(`resize`,a),window.removeEventListener(`orientationchange`,a)}},[t])}var hN={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function gN(e,t={}){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||hN[n.status]||`The request failed (${n.status}).`)}return await n.json()}var _N=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),vN={overview:()=>gN(`/api/voice/people`),begin:e=>gN(`/api/voice/people/begin`,_N(`POST`,{name:e})),recording:{state:async()=>(await gN(`/api/voice/people`)).enrolling??{enrolled:!1,samples:0,min:3,max:8},sample:e=>gN(`/api/voice/people/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>gN(`/api/voice/people/finish`,_N(`POST`,{pin:e})),cancel:async()=>{await gN(`/api/voice/people/cancel`,_N(`POST`,{}))},remove:async()=>{}},removePerson:async(e,t)=>{await gN(`/api/voice/people/${e}`,_N(`DELETE`,{pin:t}))}};function yN({api:e=vN,createRecorder:t,onClose:n}){let[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)({kind:`list`}),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(!0),g=(0,y.useCallback)(()=>{e.overview().then(e=>h.current&&i(e)).catch(e=>h.current&&m(e.message))},[e]);(0,y.useEffect)(()=>(h.current=!0,g(),()=>{h.current=!1}),[g]);let _=async()=>{m(null),f(!0);try{let t=await e.begin(s.trim());h.current&&o({kind:`record`,name:t.name})}catch(e){h.current&&m(e.message)}finally{h.current&&f(!1)}},v=async t=>{m(null),f(!0);try{if(await e.removePerson(t.id,l),!h.current)return;o({kind:`list`}),g()}catch(e){h.current&&m(e.message)}finally{h.current&&(f(!1),u(``))}};return a.kind===`record`?(0,w.jsx)(tN,{api:e.recording,who:a.name,...t?{createRecorder:t}:{},onClose:()=>{c(``),o({kind:`list`}),g()}}):(0,w.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Family voices`,style:{pointerEvents:`auto`},children:[(0,w.jsx)(`div`,{className:`approval-head`,children:(0,w.jsx)(`span`,{className:`approval-title`,children:`Family voices`})}),a.kind===`list`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Friend knows your voice. Add the people at home, so it knows who is talking and answers them by name. They can chat and ask for the weather, but cannot use your PC or see your private things.`}),r&&!r.ownerEnrolled&&(0,w.jsx)(`p`,{className:`auth-note`,children:`First teach Friend your own voice (Esc, then Enroll my voice).`}),r&&r.people.length===0&&r.ownerEnrolled&&(0,w.jsx)(`p`,{className:`auth-note`,children:`Nobody added yet.`}),r&&r.people.length>0&&(0,w.jsx)(`ul`,{className:`household-list`,"aria-label":`People Friend knows`,children:r.people.map(e=>(0,w.jsxs)(`li`,{className:`household-row`,children:[(0,w.jsx)(`span`,{children:e.name}),(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,onClick:()=>o({kind:`remove`,person:e}),"aria-label":`Remove ${e.name}`,children:`Remove`})]},e.id))}),r&&r.ownerEnrolled&&r.people.length<r.max&&(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Add a person`}),(0,w.jsx)(`input`,{value:s,maxLength:40,placeholder:`Name, for example Priya`,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s.trim()&&!d&&void _()})]}),p&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:p}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[r&&r.ownerEnrolled&&r.people.length<r.max&&(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:d||!s.trim(),onClick:()=>void _(),children:`Record their voice`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:n,children:`Close`})]})]}),a.kind===`remove`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`auth-note`,children:[`Enter your PIN to remove `,a.person.name,`’s voice. Friend will treat their voice as a stranger’s.`]}),(0,w.jsx)(F,{pin:l,onChange:u}),p&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:p}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,disabled:d||l.length<6,onClick:()=>void v(a.person),children:`Remove`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{u(``),m(null),o({kind:`list`})},children:`Back`})]})]})]})}var bN=`▌▍▎▏█▓▒░<>/\\|+-=*#%&0123456789ABCDEF`;function xN(e,t,n=Math.random){let r=[...e];if(t>=1)return e;let i=Math.floor(r.length*Math.max(0,t));return r.map((e,t)=>t<i||e===` `?e:bN[Math.floor(n()*36)]).join(``)}var SN=e=>e.length===0?0:Math.min(24,Math.max(6,Math.ceil([...e].length/2)));function CN(e,t){let[n,r]=(0,y.useState)(e),i=(0,y.useRef)(e);return(0,y.useEffect)(()=>{if(!t||e===i.current){i.current=e,r(e);return}i.current=e;let n=SN(e);if(n===0){r(e);return}let a=0,o=setInterval(()=>{a++,r(xN(e,a/n)),a>=n&&clearInterval(o)},320/n);return()=>clearInterval(o)},[e,t]),n}function wN(e){let t=e.currentTarget,n=t.getBoundingClientRect(),r=document.createElement(`span`);r.className=`hud-ripple`;let i=Math.max(n.width,n.height)*2;r.style.width=r.style.height=`${i}px`,r.style.left=`${e.clientX-n.left-i/2}px`,r.style.top=`${e.clientY-n.top-i/2}px`,t.appendChild(r),r.addEventListener(`animationend`,()=>r.remove(),{once:!0}),setTimeout(()=>r.remove(),900)}function TN({items:e,animations:t,onAction:n}){let[r,i]=(0,y.useState)(null),a=(0,y.useRef)(void 0);if((0,y.useEffect)(()=>()=>clearTimeout(a.current),[]),e.length===0)return null;let o=e=>{t!==`off`&&(i(e.id),clearTimeout(a.current),a.current=setTimeout(()=>i(null),650)),n(e)};return(0,w.jsxs)(Ce,{id:`launcher`,label:`Quick launch`,wholeBox:!0,testId:`launcher`,className:`hud hud-launcher${t===`full`?` hud-boot`:``}`,children:[(0,w.jsx)(`div`,{className:`hud-kicker`,children:`Quick launch`}),(0,w.jsx)(`ul`,{className:`hud-stack`,children:e.map((e,n)=>(0,w.jsx)(`li`,{className:`hud-tab hud-cut${r===e.id?` engaged`:``}${t===`full`?` hud-boot`:``}`,style:{"--i":n+1},children:(0,w.jsxs)(`button`,{type:`button`,className:`hud-tab-main`,"aria-label":e.label,onPointerDown:t===`off`?void 0:wN,onClick:()=>o(e),children:[(0,w.jsx)(`span`,{className:`hud-icon`,"aria-hidden":`true`,children:e.icon}),(0,w.jsx)(`span`,{className:`hud-tab-label`,children:e.label}),(0,w.jsx)(`span`,{className:`hud-tab-engaged`,"aria-hidden":`true`,children:`ENGAGED`}),(0,w.jsx)(`span`,{className:`hud-sweep`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`hud-scan`,"aria-hidden":`true`})]})},e.id))})]})}var EN=class extends y.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}};function DN(e){let t=()=>({w:window.innerWidth,h:window.innerHeight}),[n,r]=(0,y.useState)(t);return(0,y.useEffect)(()=>{if(e)return;let n=()=>r(t());return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)},[e]),e??n}var ON=(0,y.lazy)(()=>uk(()=>import(`./jarvisTree-CX2xpGQL.js`),__vite__mapDeps([0,1,2])));function kN({node:e,children:t}){return vu(e.c,{...e.p??{},...e.kids?{kids:e.kids}:{}})?(0,w.jsx)(w.Fragment,{children:t}):(0,w.jsx)(`div`,{className:`ob-jlive`,children:(0,w.jsx)(y.Suspense,{fallback:t,children:(0,w.jsx)(ON,{node:e})})})}function AN(e,t,n=24){let[r,i]=(0,y.useState)([]),a=(0,y.useRef)(void 0),o=(0,y.useRef)(0);return(0,y.useEffect)(()=>{if(a.current===t)return;a.current=t;let r=Date.now();r-o.current<1e3||(o.current=r,i(t=>[...t,e].slice(-n)))},[e,t,n]),r}var jN=(e,t=0,n=100)=>Number.isFinite(e)?Math.min(n,Math.max(t,e)):t,MN=e=>e?{x:e.x,y:e.y,width:e.w,height:e.h}:{};function NN(){return(0,w.jsx)(`svg`,{width:`0`,height:`0`,"aria-hidden":`true`,style:{position:`absolute`},children:(0,w.jsxs)(`defs`,{children:[(0,w.jsxs)(`filter`,{id:`ob-glow`,x:`-50%`,y:`-50%`,width:`200%`,height:`200%`,children:[(0,w.jsx)(`feGaussianBlur`,{stdDeviation:`3`,result:`b`}),(0,w.jsxs)(`feMerge`,{children:[(0,w.jsx)(`feMergeNode`,{in:`b`}),(0,w.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]}),(0,w.jsxs)(`filter`,{id:`ob-glow2`,x:`-50%`,y:`-50%`,width:`200%`,height:`200%`,children:[(0,w.jsx)(`feGaussianBlur`,{stdDeviation:`7`,result:`b`}),(0,w.jsxs)(`feMerge`,{children:[(0,w.jsx)(`feMergeNode`,{in:`b`}),(0,w.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]}),(0,w.jsxs)(`radialGradient`,{id:`ob-orbg`,cx:`50%`,cy:`45%`,r:`55%`,children:[(0,w.jsx)(`stop`,{offset:`0`,stopColor:`#cffafe`}),(0,w.jsx)(`stop`,{offset:`0.25`,stopColor:`#22d3ee`}),(0,w.jsx)(`stop`,{offset:`0.6`,stopColor:`#0e7490`}),(0,w.jsx)(`stop`,{offset:`1`,stopColor:`#042f3c`})]}),(0,w.jsxs)(`linearGradient`,{id:`ob-sweep`,x1:`0`,y1:`0`,x2:`1`,y2:`0`,children:[(0,w.jsx)(`stop`,{offset:`0`,stopColor:`#22d3ee`,stopOpacity:`0`}),(0,w.jsx)(`stop`,{offset:`1`,stopColor:`#22d3ee`,stopOpacity:`0.7`})]}),(0,w.jsxs)(`linearGradient`,{id:`ob-fade`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,w.jsx)(`stop`,{offset:`0`,stopColor:`#010609`}),(0,w.jsx)(`stop`,{offset:`0.15`,stopColor:`#010609`,stopOpacity:`0`}),(0,w.jsx)(`stop`,{offset:`0.85`,stopColor:`#010609`,stopOpacity:`0`}),(0,w.jsx)(`stop`,{offset:`1`,stopColor:`#010609`})]})]})})}function PN({variant:e=`chamfer`,tone:t=`cyan`,title:n,running:r=!1,className:i=``,style:a,children:o,...s}){return(0,w.jsxs)(`section`,{...s,className:`ob-frame ob-v-${e} ${i}`.trim(),"data-tone":t,...r?{"data-running":``}:{},style:a,children:[n&&(0,w.jsx)(`header`,{className:`ob-frame-title`,children:n}),(0,w.jsx)(`div`,{className:`ob-frame-body`,children:o})]})}var FN=`M60 170A90 90 0 0 1 240 170`,IN=`M76 170A74 74 0 0 1 224 170`;function LN({value:e,inner:t,label:n=`Gauge`,tone:r=`cyan`,frame:i}){let a=Math.round(jN(e));return(0,w.jsxs)(`svg`,{className:i?void 0:`ob-svg`,...MN(i),viewBox:`0 0 300 190`,role:`img`,"aria-label":`${n} ${a}%`,"data-value":a,"data-tone":r,children:[(0,w.jsx)(`path`,{d:FN,className:`ob-track`,strokeWidth:`14`,pathLength:100}),(0,w.jsx)(`path`,{d:FN,className:`ob-fill`,strokeWidth:`14`,pathLength:100,strokeDasharray:`${a} 100`,"data-arc":`outer`}),t!==void 0&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:IN,className:`ob-track`,strokeWidth:`6`,pathLength:100}),(0,w.jsx)(`path`,{d:IN,className:`ob-fill`,strokeWidth:`6`,pathLength:100,strokeDasharray:`${Math.round(jN(t))} 100`,stroke:`#a78bfa`,"data-arc":`inner`})]})]})}function RN({levels:e,tone:t=`cyan`,frame:n}){let r=Math.max(1,e.length)*12;return(0,w.jsx)(`svg`,{className:n?void 0:`ob-svg`,...MN(n),viewBox:`0 0 ${r} 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,"data-tone":t,children:e.map((e,t)=>(0,w.jsx)(`rect`,{className:`ob-eq`,x:t*12,y:0,width:8,height:100,style:{"--lv":Math.max(.05,jN(e,0,1)),animationDelay:`${-(t*.37%.9)}s`,transform:`scaleY(${Math.max(.05,jN(e,0,1))})`}},t))})}var zN=`M0 40H40L52 20L66 62L80 8L96 52L108 40H190L202 28L214 48L226 40H300`;function BN({tone:e=`cyan`,frame:t}){return(0,w.jsxs)(`svg`,{className:t?void 0:`ob-svg`,...MN(t),viewBox:`0 0 300 70`,"aria-hidden":`true`,"data-tone":e,children:[(0,w.jsx)(`path`,{className:`ob-ecg-base`,d:zN}),(0,w.jsx)(`path`,{className:`ob-ecg`,d:zN})]})}function VN({blips:e,frame:t}){return(0,w.jsxs)(`svg`,{className:t?void 0:`ob-svg`,...MN(t),viewBox:`-120 -120 240 240`,role:`img`,"aria-label":`Devices: ${e.map(e=>e.label).join(`, `)||`none`}`,children:[(0,w.jsxs)(`g`,{fill:`none`,stroke:`var(--ob-line)`,children:[(0,w.jsx)(`circle`,{r:`110`}),(0,w.jsx)(`circle`,{r:`73`}),(0,w.jsx)(`circle`,{r:`36`}),(0,w.jsx)(`line`,{x1:`-110`,x2:`110`}),(0,w.jsx)(`line`,{y1:`-110`,y2:`110`})]}),(0,w.jsx)(`circle`,{r:`110`,fill:`none`,stroke:`#67e8f9`,strokeWidth:`2`,strokeDasharray:`1 9`}),(0,w.jsxs)(`g`,{className:`ob-sweep`,children:[(0,w.jsx)(`path`,{d:`M0 0L110 0A110 110 0 0 0 95 -55Z`,fill:`url(#ob-sweep)`}),(0,w.jsx)(`line`,{x2:`110`,stroke:`#67e8f9`,strokeWidth:`2`})]}),e.map(e=>{let t=e.angle*Math.PI/180,n=Math.cos(t)*jN(e.distance,0,1)*100,r=-Math.sin(t)*jN(e.distance,0,1)*100;return(0,w.jsxs)(`g`,{"data-blip":``,...e.dim?{"data-dim":``}:{},children:[(0,w.jsx)(`circle`,{className:`ob-blip${e.warn?` ob-blip-warn`:``}`,cx:n,cy:r,r:`5`}),(0,w.jsx)(`text`,{x:n+9,y:r+4,fontSize:`11`,fill:`currentColor`,opacity:e.dim?.5:1,children:e.label})]},e.label)})]})}var HN={done:`var(--ob-green)`,doing:`var(--ob-cyan)`,review:`var(--ob-orange)`,todo:`var(--ob-dim)`},UN=e=>e%2==0?6:5;function WN({cells:e,placeholder:t=!1,frame:n}){t&&(e=Array.from({length:11},()=>({status:`todo`})));let r=[],i=0,a=0;for(let t of e)a>=UN(i)&&(i++,a=0),r.push({x:20+a*40+i%2*20,y:20+i*35,status:t.status}),a++;let o=r.length?i+1:1;return(0,w.jsx)(`svg`,{className:n?void 0:`ob-svg`,...MN(n),viewBox:`0 0 260 ${o*35+10}`,"aria-hidden":`true`,...t?{"data-placeholder":``}:{},children:r.map((e,t)=>(0,w.jsx)(`polygon`,{"data-status":e.status,points:`-20,0 -10,-17.3 10,-17.3 20,0 10,17.3 -10,17.3`,transform:`translate(${e.x} ${e.y})`,fill:`none`,stroke:HN[e.status],strokeWidth:`1.6`,className:e.status===`review`?`ob-pulse`:void 0},t))})}function GN({rings:e,placeholder:t=!1,frame:n}){t&&(e=[{value:0},{value:0},{value:0}]);let r=t?{"aria-hidden":!0,"data-placeholder":``}:{role:`img`,"aria-label":e.map(e=>`${e.label??`ring`} ${Math.round(jN(e.value))}%`).join(`, `)||`no data`};return(0,w.jsx)(`svg`,{className:n?void 0:`ob-svg`,...MN(n),viewBox:`-50 -50 100 100`,...r,children:e.map((e,t)=>{let n=38-t*12;if(n<=2)return null;let r=Math.round(jN(e.value));return(0,w.jsxs)(`g`,{"data-tone":e.tone??`cyan`,transform:`rotate(-90)`,children:[(0,w.jsx)(`circle`,{r:n,className:`ob-track`,strokeWidth:`8`}),(0,w.jsx)(`circle`,{r:n,className:`ob-fill`,strokeWidth:`8`,pathLength:100,strokeDasharray:`${r} 100`,"data-ring":t,"data-value":r})]},t)})})}function KN({value:e,segments:t=60,radius:n=205,size:r=460}){let i=Math.round(t*jN(e)/100),a=r/2;return(0,w.jsx)(`svg`,{className:`ob-svg`,viewBox:`0 0 ${r} ${r}`,"aria-hidden":`true`,children:Array.from({length:t},(e,r)=>{let o=(-90+r*360/t)*Math.PI/180,[s,c]=[n-7,n+7];return(0,w.jsx)(`line`,{className:`ob-seg`,"data-seg":``,"data-on":r<i?`true`:`false`,x1:a+s*Math.cos(o),y1:a+s*Math.sin(o),x2:a+c*Math.cos(o),y2:a+c*Math.sin(o)},r)})})}var qN={running:`green`,waiting:`orange`,idle:`cyan`,add:`cyan`};function JN({label:e,glyph:t,caption:n,detail:r,status:i=`idle`,onClick:a,x:o,y:s}){let c=o!==void 0&&s!==void 0?{left:o,top:s}:void 0;return(0,w.jsxs)(`button`,{type:`button`,className:`ob-node`,"data-tone":qN[i],"data-status":i,"aria-label":r?`${e}, ${r}`:e,title:e,style:c,onClick:a,children:[(0,w.jsxs)(`svg`,{viewBox:`-34 -30 68 60`,"aria-hidden":`true`,children:[(0,w.jsx)(`polygon`,{points:`-34,0 -17,-29.4 17,-29.4 34,0 17,29.4 -17,29.4`}),(0,w.jsx)(`text`,{className:`ob-node-label${t?` ob-glyph`:``}`,children:t??(e.length>6?`${e.slice(0,5)}…`:e)})]}),n&&(0,w.jsx)(`span`,{className:`ob-node-caption`,children:n})]})}function YN({x1:e,y1:t,x2:n,y2:r,tone:i=`cyan`,flowing:a=!0}){return(0,w.jsx)(`line`,{className:`ob-link${a?` ob-flow`:``}`,"data-tone":i,x1:e,y1:t,x2:n,y2:r})}var XN=1e4;function ZN({stats:e,now:t=Date.now()}){let n=e?Math.round(e.cpu):0,r=e&&e.ramTotal>0?Math.round(100*e.ramUsed/e.ramTotal):0,i=!!e&&t-e.at>1e4;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 300 220`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`12`,y:`8`,children:`SYSTEM · CPU / RAM`}),(0,w.jsx)(`path`,{className:`ob-bracket`,d:`M0 20H20M0 20V40M300 20H280M300 20V40`}),(0,w.jsx)(LN,{value:n,inner:r,label:`CPU`,frame:{x:0,y:20,w:300,h:190}}),e?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`text`,{className:`ob-big`,x:`150`,y:`170`,textAnchor:`middle`,children:[n,`%`]}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`150`,y:`192`,textAnchor:`middle`,children:[`CPU · RAM `,r,`%`,i?` · STALE`:``]})]}):(0,w.jsx)(`text`,{className:`ob-dim`,x:`150`,y:`180`,textAnchor:`middle`,children:`Waiting for data`})]})}function QN(e){if(e<1024)return`${Math.round(e)} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(1)} ${t[r]}`}function $N({stats:e,now:t=Date.now()}){let n=!!e&&e.netDown===0&&e.netUp===0,r=!!e&&t-e.at>1e4;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 300 110`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`0`,y:`8`,children:`NETWORK`}),(0,w.jsx)(BN,{frame:{x:0,y:20,w:300,h:70}}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`0`,y:`104`,children:[e?n?`n/a`:`↓ ${QN(e.netDown)}/s ↑ ${QN(e.netUp)}/s`:`Waiting for data`,r?` · stale`:``]})]})}var eP=e=>Math.max(0,Math.min(100,Math.round(e))),tP=(e,t,n=`200px`)=>({c:`JGaugeChart`,p:{value:eP(e),min:0,max:100,size:n,label:t,displayValue:`${eP(e)}%`,showNeedle:!1,showTicks:!1,showMinMax:!1}}),nP=(e,t=`260px`)=>({c:`JSparkline`,p:{data:e.length>1?e:[0,0],showArea:!0,showTrend:!1,height:`48px`,width:t}});function rP({node:e}){return(0,w.jsx)(kN,{node:e,children:(0,w.jsx)(`span`,{className:`ob-pic-wait`})})}function iP({k:e,v:t,tone:n}){return(0,w.jsxs)(`p`,{className:`ob-fact${n?` ob-fact-${n}`:``}`,children:[(0,w.jsx)(`span`,{children:e}),(0,w.jsx)(`b`,{children:t})]})}var aP=({children:e})=>(0,w.jsx)(`p`,{className:`ob-say`,children:e}),oP=({children:e})=>(0,w.jsx)(`p`,{className:`ob-sub ob-head`,children:e}),sP=e=>e<5e3?`just now`:e<6e4?`${Math.round(e/1e3)} s ago`:`${Math.round(e/6e4)} min ago`;function cP({stats:e,cpuHist:t,ramHist:n}){let r=e?eP(e.cpu):0,i=e&&e.ramTotal>0?eP(100*e.ramUsed/e.ramTotal):0;if(!e)return(0,w.jsx)(aP,{children:`Waiting for the first reading from this PC.`});let a=Date.now()-e.at>XN,o=r>85||i>92?`The PC is under heavy load. If it feels slow, close big programs or browser tabs you are not using.`:r>60||i>80?`Busy, but fine. Nothing needs doing unless it feels slow.`:`Light load. There is plenty of room for more work.`;return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsxs)(`div`,{className:`ob-pics`,children:[(0,w.jsx)(rP,{node:tP(r,`CPU`)}),(0,w.jsx)(rP,{node:tP(i,`Memory`)})]}),(0,w.jsx)(iP,{k:`Processor now`,v:`${r}%`,tone:r>85?`warn`:void 0}),(0,w.jsx)(iP,{k:`Memory now`,v:`${i}% (${QN(e.ramUsed)} of ${QN(e.ramTotal)})`,tone:i>92?`warn`:void 0}),(0,w.jsx)(iP,{k:`Memory free`,v:QN(Math.max(0,e.ramTotal-e.ramUsed))}),(0,w.jsx)(iP,{k:`Last reading`,v:a?`${sP(Date.now()-e.at)} (stale: the PC agent may be off)`:sP(Date.now()-e.at),tone:a?`warn`:`ok`}),(0,w.jsx)(oP,{children:`Last minute or so`}),(0,w.jsxs)(`div`,{className:`ob-pics`,children:[(0,w.jsx)(rP,{node:nP(t,`230px`)}),(0,w.jsx)(rP,{node:nP(n,`230px`)})]}),(0,w.jsx)(`p`,{className:`ob-trend`,children:`processor, then memory`}),(0,w.jsx)(aP,{children:o})]})}function lP({voice:e,lastHeard:t}){let n=e.mode!==`idle`||e.level>.05,r={idle:`Waiting`,listening:`Listening to you`,transcribing:`Turning your words into text`,speaking:`Speaking`}[e.mode];return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsx)(rP,{node:{c:`JWaveform`,p:{barCount:36,height:`64px`,active:n}}}),(0,w.jsx)(iP,{k:`Doing now`,v:r,tone:n?`ok`:void 0}),(0,w.jsx)(iP,{k:`Sound level`,v:`${Math.round(e.level*100)}%`}),(0,w.jsx)(iP,{k:`Voice on this PC`,v:e.available?`ready`:`not set up`,tone:e.available?`ok`:`warn`}),(0,w.jsx)(iP,{k:`Your voice enrolled`,v:e.enrolled?`yes: strangers are recognised`:`no`}),t&&(0,w.jsx)(iP,{k:`You last said`,v:t.length>90?`${t.slice(0,89)}…`:t}),(0,w.jsx)(aP,{children:e.available?`Hold Space (or press and hold the talk button) and speak; let go to send. Friend answers aloud when you spoke to it.`:`Voice is not set up on this PC yet. Run friend voice setup in the terminal, then restart Friend.`})]})}function uP({stats:e,down:t,up:n}){if(!e)return(0,w.jsx)(aP,{children:`Waiting for the first reading from this PC.`});let r=e.netDown===0&&e.netUp===0;return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsxs)(`div`,{className:`ob-pics`,children:[(0,w.jsx)(rP,{node:nP(t,`260px`)}),(0,w.jsx)(rP,{node:nP(n,`260px`)})]}),(0,w.jsx)(`p`,{className:`ob-trend`,children:`downloading, then uploading`}),(0,w.jsx)(iP,{k:`Download now`,v:r?`n/a`:`${QN(e.netDown)}/s`}),(0,w.jsx)(iP,{k:`Upload now`,v:r?`n/a`:`${QN(e.netUp)}/s`}),(0,w.jsx)(iP,{k:`Fastest download seen`,v:t.length?`${QN(Math.max(...t))}/s`:`n/a`}),(0,w.jsx)(iP,{k:`Fastest upload seen`,v:n.length?`${QN(Math.max(...n))}/s`:`n/a`}),(0,w.jsx)(aP,{children:r?`This PC does not report network speed, or nothing is moving right now.`:`The speed of everything on this PC, not only Friend. A busy line usually means a download, an update or a video.`})]})}function dP({deviceOnline:e,voiceAvailable:t}){let n=(e,t,n,r)=>(0,w.jsxs)(`div`,{className:`ob-device`,children:[(0,w.jsx)(iP,{k:e,v:t?`online`:`offline`,tone:t?`ok`:`warn`}),(0,w.jsx)(`p`,{className:`ob-say ob-small`,children:t?n:r})]},e);return(0,w.jsxs)(`div`,{className:`ob-details`,children:[n(`This screen`,!0,`You are looking at it: Friend shows pictures, captions and these instruments here.`,``),n(`PC agent`,e,`Runs commands and reads files on this PC when you ask, after your approval.`,`Friend cannot run commands or read files on this PC until the agent is running again (friend start).`),n(`Voice`,t,`Listens when you hold Space and speaks the answers.`,`Voice is not set up on this PC yet (friend voice setup).`)]})}function fP({office:e}){if(!e.enabled)return(0,w.jsx)(aP,{children:`The Office is switched off, so there are no workers or tickets. Turn it on in Settings, Office, then ask Friend to hire someone.`});let t=t=>e.tickets.filter(e=>e.status===t).length,n=t=>e.workers.find(e=>e.id===t)?.name??(t||`nobody yet`),r=[...e.tickets].sort((e,t)=>t.id-e.id).slice(0,8);return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsx)(iP,{k:`Done`,v:t(`done`),tone:`ok`}),(0,w.jsx)(iP,{k:`Being worked on`,v:t(`doing`)}),(0,w.jsx)(iP,{k:`Waiting for review`,v:t(`review`)+t(`blocked`),tone:t(`review`)+t(`blocked`)>0?`warn`:void 0}),(0,w.jsx)(iP,{k:`Not started`,v:t(`todo`)}),(0,w.jsx)(oP,{children:`Newest tickets`}),r.length===0&&(0,w.jsx)(aP,{children:`No tickets yet. Ask Friend to give a worker something to do.`}),r.map(e=>(0,w.jsxs)(`p`,{className:`ob-li ob-wrap`,children:[`#`,e.id,` · `,e.title,` · `,e.status,` · `,n(e.workerId)]},e.id))]})}var pP=!1;typeof document<`u`&&(document.addEventListener(`keydown`,()=>pP=!0,!0),document.addEventListener(`pointerdown`,()=>pP=!1,!0),document.addEventListener(`mousedown`,()=>pP=!1,!0));var mP=()=>pP,hP={starting:`running`,running:`running`,waiting:`waiting`,idle:`idle`,paused:`idle`,stopped:`idle`,failed:`idle`};function gP(e,t){let n=e.slice(0,5).map(e=>({id:e.id,label:e.name,glyph:e.name.slice(0,6).toUpperCase(),caption:e.name,status:hP[e.status],detail:e.detail||e.status,kind:`worker`}));return t&&e.length<5&&n.push({id:`hire`,label:`Hire a worker`,glyph:`+`,caption:`HIRE WORKER`,status:`add`,detail:`HIRE WORKER`,kind:`hire`}),n}var _P={done:`done`,doing:`doing`,review:`review`,blocked:`review`,todo:`todo`},vP=[`done`,`doing`,`review`,`todo`];function yP(e){return[...e].sort((e,t)=>e.id-t.id).slice(-11).map(e=>({status:_P[e.status]})).sort((e,t)=>vP.indexOf(e.status)-vP.indexOf(t.status))}function bP(e){let t=[...new Set(e.map(e=>e.projectId))];if(t.length!==0)return t.length===1?t[0]:`${t.length} projects`}var xP=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e);function SP(e){let t=e=>e.name.slice(0,6).toUpperCase(),n=e.filter(e=>e.budget!==null&&e.budget>0);if(n.length>0)return n.slice(0,3).map(e=>{let n=jN(e.tokens/e.budget*100);return{label:t(e),value:n,text:`${Math.round(n)}%`}});let r=Math.max(0,...e.map(e=>e.tokens));return[...e].sort((e,t)=>t.tokens-e.tokens).slice(0,3).map(e=>({label:t(e),value:r>0?jN(Math.max(+(e.tokens>0),Math.round(e.tokens/r*100))):0,text:xP(e.tokens)}))}var CP={tool:`green`,result:`green`,approval:`orange`,error:`orange`,text:`plain`};function wP(e,t){if(e!==`idle`||!t.enabled)return e;if(t.workers.some(e=>e.status===`waiting`))return`needs you`;let n=t.workers.filter(e=>e.status===`running`||e.status===`starting`).length;return n>0?`working · ${n}`:e}function TP(e,t,n=8){return t.flatMap(t=>(e[t.id]??[]).map(e=>({...e,name:t.name.slice(0,6).toUpperCase().padEnd(7)}))).sort((e,t)=>e.at-t.at).slice(-n).map(e=>({text:`${e.name}${e.text}`,tone:CP[e.kind]??`plain`}))}var EP=e=>{let t=Math.max(1,Math.round(e/6e4));return t>=60?`${Math.floor(t/60)}H ${String(t%60).padStart(2,`0`)}M`.replace(/ 0(\d)M/,` $1M`):`${t}M`};function DP(e,t,n){let r=e.fiveHour;return r&&r.resetsAt*1e3>n?{value:Math.round(jN(r.utilization*100)),reset:EP(r.resetsAt*1e3-n),real:!0}:{value:t,reset:null,real:!1}}function OP(e){let t=new Map(e.map(e=>[e.id,e])),n=e=>{let n=new Set([e.id]);for(let r=e.managerId;r&&t.has(r);r=t.get(r).managerId){if(n.has(r))return r===e.id;n.add(r)}return!1},r=e=>e.managerId&&t.has(e.managerId)&&!n(e)?e.managerId:`friend`,i=new Map;for(let t of e)i.set(r(t),[...i.get(r(t))??[],t]);let a=new Map,o=e=>{let t=i.get(e)??[],n=t.length===0?190:Math.max(190,t.reduce((e,t)=>e+o(t.id),0)+(t.length-1)*26);return a.set(e,n),n};o(`friend`);let s=[],c=[],l=0,u=(e,n,r)=>{l=Math.max(l,r);let o=i.get(e)??[],d=r*134,f;if(o.length===0)f=n+(a.get(e)-190)/2;else{let t=n,i=o.map(e=>{let n=u(e.id,t,r+1);return t+=a.get(e.id)+26,n});f=(i[0]+i[i.length-1])/2;for(let[t,n]of o.entries())c.push({from:e,to:n.id,x1:f+95,y1:d+78,x2:i[t]+95,y2:d+78+56})}return s.push({id:e,x:f,y:d,worker:e===`friend`?null:t.get(e)}),f};return u(`friend`,0,0),{nodes:s,edges:c,width:a.get(`friend`),height:(l+1)*78+l*56}}var kP=[{id:`system`,title:`System`,anchor:`left`,box:{x:40,y:70,w:300,h:220},tone:`cyan`,minDensity:`standard`},{id:`voice`,title:`Voice`,anchor:`left`,box:{x:40,y:310,w:300,h:150},tone:`cyan`,minDensity:`standard`},{id:`network`,title:`Network`,anchor:`left`,box:{x:40,y:480,w:300,h:110},tone:`cyan`,minDensity:`standard`},{id:`feed`,title:`Activity`,anchor:`left`,box:{x:40,y:650,w:430,h:210},tone:`green`,minDensity:`standard`},{id:`radar`,title:`Devices`,anchor:`right`,box:{x:1310,y:60,w:250,h:270},tone:`cyan`,minDensity:`standard`},{id:`tickets`,title:`Tickets`,anchor:`right`,box:{x:1300,y:320,w:270,h:160},tone:`green`,minDensity:`standard`},{id:`budget`,title:`Budget`,anchor:`right`,box:{x:1300,y:480,w:270,h:110},tone:`cyan`,minDensity:`standard`},{id:`approval`,title:`Approvals`,anchor:`right`,box:{x:1180,y:650,w:380,h:210},tone:`orange`,minDensity:`standard`},{id:`usage`,title:`Usage`,anchor:`centre`,box:{x:700,y:215,w:200,h:30},tone:`cyan`,minDensity:`calm`}];if(kP.length!==Bu.length)throw Error(`the widget registry and HUD_WIDGET_IDS differ`);var AP={calm:0,standard:1,full:2},jP=[`system`,`voice`,`network`,`feed`,`radar`,`tickets`];function MP(e,t,n,r,i=[],a=!1){return kP.filter(n=>{if(n.id===`approval`&&r)return!0;let o=t[n.id];return o===!1?!1:a?!0:n.id===`approval`?o===!0:jP.includes(n.id)?o===!0||i.includes(n.id):o===!0||AP[e]>=AP[n.minDensity]})}function NP({rings:e=[]}){let t=e.length===0;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 270 110`,children:[(0,w.jsx)(GN,{rings:e.map((e,t)=>({value:e.value,label:e.label,tone:[`cyan`,`cyan`,`green`][t]??`cyan`})),placeholder:t,frame:{x:-10,y:-10,w:100,h:100}}),(0,w.jsx)(`text`,{className:`ob-lab`,x:`104`,y:`26`,children:`BUDGET`}),t?(0,w.jsx)(`text`,{className:`ob-sm`,x:`104`,y:`46`,children:`No workers yet`}):e.slice(0,3).map((e,t)=>(0,w.jsxs)(`text`,{className:`ob-sm`,x:`104`,y:46+t*18,children:[e.label,` `,e.text??`${Math.round(e.value)}%`]},e.label))]})}var PP=8,FP=46,IP=e=>e.length>FP?`${e.slice(0,45)}…`:e;function LP({lines:e,activity:t,busy:n,limit:r=PP,marquee:i=!1}){let a=Math.min(r,PP-+!!n),o=i?e:e.slice(-a),s=`M0 0H400L430 30V210H0Z`,c=(e,t,n)=>(0,w.jsxs)(`text`,{className:`tone`in e?`ob-sm ${e.tone===`green`?`ob-grn`:e.tone===`orange`?`ob-org`:``}`.trim():e.role===`user`?`ob-sm`:`ob-sm ob-grn`,x:`22`,y:t,children:[`tone`in e?``:e.role===`user`?`▸ `:`◂ `,IP(e.text)]},n);return(0,w.jsxs)(`svg`,{className:`ob-wsvg ob-feed-svg`,viewBox:`0 0 430 210`,"aria-live":`polite`,children:[(0,w.jsx)(`defs`,{children:(0,w.jsx)(`clipPath`,{id:`ob-feed-clip`,children:(0,w.jsx)(`rect`,{x:`0`,y:`38`,width:`430`,height:`168`})})}),(0,w.jsx)(`path`,{className:`ob-feed-frame`,d:s}),(0,w.jsx)(`path`,{className:`ob-feed-run`,d:s,pathLength:100}),(0,w.jsx)(`text`,{className:`ob-lab`,x:`16`,y:`18`,children:`WORKER FEED · LIVE`}),(0,w.jsx)(`circle`,{className:`ob-pulse`,cx:`410`,cy:`14`,r:`4`,fill:`#34d399`}),o.length===0&&!n&&(0,w.jsx)(`text`,{className:`ob-dim`,x:`22`,y:`60`,children:`Nothing yet`}),(0,w.jsx)(`g`,{clipPath:`url(#ob-feed-clip)`,children:i?(0,w.jsx)(`g`,{className:`ob-feed-scroll`,style:{"--n":o.length*20},children:[0,1].flatMap(e=>o.map((t,n)=>c(t,56+(e*o.length+n)*20,`${e}-${n}`)))}):(0,w.jsxs)(`g`,{className:`ob-feed-in`,children:[o.map((e,t)=>c(e,56+t*20,String(t))),n&&(0,w.jsxs)(`text`,{className:`ob-sm ob-org`,x:`22`,y:56+o.length*20,children:[`⚙ `,IP(t??`Working…`)]})]},`${e.length}:${o.at(-1)?.text??``}`)}),(0,w.jsx)(`rect`,{className:`ob-feed-fade`,x:`1`,y:`38`,width:`428`,height:`168`,fill:`url(#ob-fade)`,pointerEvents:`none`})]})}function RP({lines:e,activity:t,busy:n,workers:r=[]}){let i=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let e=i.current;e&&(e.scrollTop=e.scrollHeight)},[e.length,r.length]),(0,w.jsxs)(`div`,{className:`ob-feed`,"aria-live":`polite`,ref:i,children:[e.length===0&&r.length===0&&!n&&(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Nothing yet`}),r.map((e,t)=>(0,w.jsx)(`p`,{className:`ob-li${e.tone===`green`?` ob-live`:e.tone===`orange`?` ob-warn`:``}`,children:e.text},`w${t}`)),e.slice(-200).map((e,t)=>(0,w.jsxs)(`p`,{className:`ob-li ${e.role===`user`?`ob-user`:``}`,children:[e.role===`user`?`▸ `:`◂ `,e.text]},t)),n&&(0,w.jsxs)(`p`,{className:`ob-li ob-live`,children:[`⚙ `,t??`Working…`]})]})}var zP={system:`How hard this PC is working: the arc and the first row are the processor, the second row is the memory, and below are the memory figures.`,voice:`The sound Friend is hearing or speaking, live.`,network:`How fast data moves in and out of this PC. Some PCs do not report it.`,feed:`The conversation and what Friend is doing right now.`,radar:`The things Friend can reach: this screen, the PC's agent and the voice. A dim one is offline.`,tickets:`The work given to hired workers, one cell each. Switch the Office on in Settings to hire workers.`,budget:`How much of each worker's limit is used. Limits are set in Settings, Office.`,approval:`Something is waiting for your answer.`,usage:`Today's usage compared with your busiest day of the last 30.`},BP={voice:`Voice`,chat:`Chat`,task:`Scheduled tasks`,channel:`Messages`,other:`Other`};function VP({api:e}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let t=!0;return e.summary(30).then(e=>t&&n(e)).catch(()=>t&&i(!0)),()=>{t=!1}},[e]),r?(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Could not read the usage`}):t?t.bySource.length===0?(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`No usage yet`}):(0,w.jsx)(`div`,{className:`ob-usage-detail`,children:t.bySource.map(e=>(0,w.jsxs)(`p`,{className:`ob-li`,children:[BP[e.source]??e.source,` · `,MC(e.input+e.output),` tokens · `,e.turns,` turns`]},e.source))}):(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Reading…`})}var HP={cpu:[],ram:[],down:[],up:[]};function UP({id:e,state:t,rect:n,usageApi:r=kC,readings:i=HP,onClose:a}){let o=(0,y.useRef)(null);(0,y.useEffect)(()=>{mP()&&o.current?.focus()},[e]);let s=kP.find(t=>t.id===e)?.title??e,c=(()=>{switch(e){case`system`:return(0,w.jsx)(cP,{stats:t.stats,cpuHist:i.cpu,ramHist:i.ram});case`network`:return(0,w.jsx)(uP,{stats:t.stats,down:i.down,up:i.up});case`radar`:return(0,w.jsx)(dP,{deviceOnline:t.deviceOnline,voiceAvailable:t.voice.available});case`voice`:return(0,w.jsx)(lP,{voice:t.voice,lastHeard:[...t.chat].reverse().find(e=>e.role===`user`)?.text??null});case`feed`:return(0,w.jsx)(RP,{lines:t.chat,activity:t.activity,busy:t.busy,workers:t.office.enabled?TP(t.office.feed,t.office.workers,60):[]});case`tickets`:return(0,w.jsx)(fP,{office:t.office});case`budget`:return(0,w.jsx)(NP,{rings:SP(t.office.workers)});case`usage`:return(0,w.jsx)(VP,{api:r});default:return null}})();return(0,w.jsxs)(PN,{variant:`chamfer`,running:!0,title:s,className:`ob-expanded ob-hit`,style:{position:`absolute`,left:n.x,top:n.y,width:n.width,height:n.height},role:`dialog`,"aria-label":s,children:[(0,w.jsx)(`button`,{ref:o,type:`button`,className:`ob-close`,"aria-label":`Close`,onClick:a,children:`×`}),(0,w.jsx)(`div`,{className:`ob-expanded-body`,children:c}),(0,w.jsx)(`p`,{className:`ob-explain`,children:zP[e]})]})}var WP=e=>Math.max(0,Math.min(100,Math.round(e))),GP=(e,t,n=`cyan`)=>({c:`JHudFrameCard`,p:{title:e,color:n,showStatusDot:!0,width:`100%`},kids:t}),KP=(e,t,n,r)=>({c:`JDataRow`,p:{label:e,value:t,...n===void 0?{}:{barPercent:WP(n)},...r?{state:r}:{}}});function qP(e,t=!1){let n=e?WP(e.cpu):0,r=e&&e.ramTotal>0?WP(100*e.ramUsed/e.ramTotal):0;return GP(`System`,[{c:`Row`,p:{gap:12},kids:[{c:`JGaugeChart`,p:{value:n,min:0,max:100,size:t?`190px`:`150px`,label:`CPU`,displayValue:`${n}%`,showNeedle:!1,showTicks:!1,showMinMax:!1}},{c:`Column`,p:{gap:6},kids:e?[KP(`CPU`,`${n}%`,n,n>85?`warning`:void 0),KP(`RAM`,`${r}%`,r,r>90?`warning`:void 0),...t?[KP(`RAM USED`,QN(e.ramUsed)),KP(`RAM TOTAL`,QN(e.ramTotal))]:[]]:[`Waiting for data`]}]}])}function JP(e,t){let n=t!==`idle`||e>.05;return GP(`Voice`,[{c:`JWaveform`,p:{barCount:28,height:`48px`,active:n}},{c:`JStatusPill`,p:{state:n?`active`:`success`},kids:[n?String(t):`quiet`]}])}function YP(e,t){let n=!!e&&e.netDown===0&&e.netUp===0;return GP(`Network`,[{c:`Row`,p:{gap:12},kids:[{c:`JSparkline`,p:{data:t.length>1?t:[0,0],showArea:!0,height:`40px`,width:`130px`}},{c:`Column`,p:{gap:4},kids:e?n?[`n/a on this PC`]:[KP(`DOWN`,`${QN(e.netDown)}/s`),KP(`UP`,`${QN(e.netUp)}/s`)]:[`Waiting for data`]}]}])}function XP(e,t,n){let r=e.slice(-6).map((e,t)=>({id:`l${t}`,message:e.text.slice(0,120),level:e.tone===`orange`?`warn`:`info`}));return n&&t&&r.push({id:`now`,message:t,level:`info`}),GP(`Activity`,[{c:`JActivityFeed`,p:{items:r.length?r:[{id:`none`,message:`Nothing yet`,level:`info`}],maxRows:6,showTime:!1,showSource:!1}}],`green`)}function ZP(e,t){let n=(e,t)=>({c:`JStatusPill`,p:{state:t?`active`:`error`},kids:[`${e} ${t?`online`:`offline`}`]});return GP(`Devices`,[{c:`Column`,p:{gap:8},kids:[n(`This screen`,!0),n(`PC agent`,e),n(`Voice`,t)]}])}function QP(e,t){let n=t=>e.filter(e=>e.status===t).length,r=e.length,i=e=>r?100*e/r:0;return GP(t?`Tickets: ${t}`:`Tickets`,r?[KP(`DONE`,String(n(`done`)),i(n(`done`)),`success`),KP(`DOING`,String(n(`doing`)),i(n(`doing`))),KP(`REVIEW`,String(n(`review`)),i(n(`review`)),`warning`),KP(`TODO`,String(n(`todo`)),i(n(`todo`)))]:[`No tickets yet`],`green`)}function $P({worker:e,feed:t,rect:n,send:r,onClose:i}){let a=(0,y.useRef)(null),o=(0,y.useRef)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(!1);(0,y.useEffect)(()=>{mP()&&a.current?.focus()},[e.id]),(0,y.useEffect)(()=>{let e=o.current;e&&(e.scrollTop=e.scrollHeight)},[t.length]);let d=()=>{let t=s.trim();t&&(r({type:`office.say`,workerId:e.id,text:t}),c(``))},f=e.status===`starting`||e.status===`running`||e.status===`waiting`;return(0,w.jsxs)(PN,{variant:`chamfer`,running:!0,title:e.name,className:`ob-expanded ob-hit`,style:{position:`absolute`,left:n.x,top:n.y,width:n.width,height:n.height},role:`dialog`,"aria-label":e.name,children:[(0,w.jsx)(`button`,{ref:a,type:`button`,className:`ob-close`,"aria-label":`Close`,onClick:i,children:`×`}),(0,w.jsxs)(`div`,{className:`ob-expanded-body ob-worker`,children:[(0,w.jsxs)(`p`,{className:`ob-li`,children:[e.status,e.detail?` · ${e.detail}`:``]}),(0,w.jsxs)(`p`,{className:`ob-li ob-sub`,children:[`Tokens `,e.tokens,e.budget?` of ${e.budget}`:``]}),(0,w.jsx)(`div`,{className:`ob-worker-log`,ref:o,"aria-live":`polite`,children:t.length===0?(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Nothing yet`}):t.map((e,t)=>(0,w.jsx)(`p`,{"data-feed-line":``,"data-kind":e.kind,className:`ob-li${e.kind===`tool`||e.kind===`result`?` ob-live`:``}`,children:e.text},`${e.at}-${t}`))})]}),(0,w.jsxs)(`form`,{className:`ob-worker-say`,onSubmit:e=>{e.preventDefault(),d()},children:[(0,w.jsx)(`input`,{type:`text`,"aria-label":`Say to ${e.name}`,placeholder:`Say to ${e.name}`,value:s,maxLength:2e3,onChange:e=>c(e.target.value)}),(0,w.jsx)(`button`,{type:`submit`,children:`Send`}),(0,w.jsx)(`button`,{type:`button`,className:`ob-stop`,disabled:!f,onClick:()=>r({type:`office.stop`,workerId:e.id}),children:`Stop`}),(0,w.jsx)(`button`,{type:`button`,className:`ob-stop`,onClick:()=>l?r({type:`office.fire`,workerId:e.id}):u(!0),onBlur:()=>u(!1),children:l?`Confirm remove`:`Remove`})]})]})}var eF=(0,y.lazy)(()=>uk(()=>import(`./OrgParts-CUFZmjwg.js`).then(e=>({default:e.OrgCanvas})),__vite__mapDeps([3,1,2])));function tF({workers:e,name:t,rect:n,onWorker:r,onClose:i}){let a=(0,y.useRef)(null);return(0,y.useEffect)(()=>{mP()&&a.current?.focus()},[]),(0,w.jsxs)(PN,{variant:`chamfer`,running:!0,title:`Office team`,className:`ob-expanded ob-hit`,style:{position:`absolute`,left:n.x,top:n.y,width:n.width,height:n.height},role:`dialog`,"aria-label":`Office team`,children:[(0,w.jsx)(`button`,{ref:a,type:`button`,className:`ob-close`,"aria-label":`Close`,onClick:i,children:`×`}),(0,w.jsx)(`div`,{className:`ob-expanded-body ob-org-body`,children:(0,w.jsx)(y.Suspense,{fallback:(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Drawing the team…`}),children:(0,w.jsx)(eF,{workers:e,name:t,onWorker:r})})}),(0,w.jsx)(`ul`,{className:`ob-org-lines`,"aria-label":`Who reports to whom`,children:e.map(n=>(0,w.jsxs)(`li`,{children:[n.name,` reports to `,n.managerId&&e.find(e=>e.id===n.managerId)?.name||t]},n.id))})]})}var nF=[{id:`code`,label:`CODE`,status:`running`,detail:`▶ Hero.tsx · 62%`,at:{x:800,y:108,anchor:`middle`}},{id:`test`,label:`TEST`,status:`running`,detail:`▶ 12/12 passing`,at:{x:1135,y:268,anchor:`start`}},{id:`rev`,label:`REV`,status:`waiting`,detail:`⏸ needs approval`,at:{x:1135,y:632,anchor:`start`}},{id:`hire`,label:`+`,status:`add`,detail:`HIRE WORKER`,at:{x:465,y:632,anchor:`end`}},{id:`arch`,label:`ARCH`,status:`idle`,detail:`idle`,at:{x:465,y:268,anchor:`end`}}],rF=[{text:`CODE ▶ edit src/Hero.tsx`,tone:`green`},{text:`CODE + 42 lines - 6 lines`,tone:`plain`},{text:`TEST ▶ pnpm test`,tone:`green`},{text:`TEST 12 passed · 0 failed`,tone:`plain`},{text:`REV ⏸ wants: npm install`,tone:`orange`},{text:`CODE ▶ edit src/Nav.tsx`,tone:`green`},{text:`CODE + 18 lines`,tone:`plain`}],iF=(e,t)=>Array.from({length:t},()=>({status:e})),aF=[...iF(`done`,3),...iF(`doing`,3),...iF(`review`,1),...iF(`todo`,4)],oF=[{label:`CODE`,value:42},{label:`TEST`,value:70},{label:`REV`,value:25}],sF=[{angle:49,distance:.64,label:`PC`},{angle:207,distance:.67,label:`PHONE`},{angle:286,distance:.73,label:`ALEXA?`,warn:!0}],cF={id:`sample`,tool:`shell.run`,summary:`npm install --save zod`,tier:`T2`,needsPin:!1},lF=e=>({cpu:38,ramUsed:61,ramTotal:100,netDown:2516582.4,netUp:314572.8,at:e});function uF({approval:e,send:t}){return e?(0,w.jsx)(dF,{approval:e,send:t}):(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`None waiting`})}function dF({approval:e,send:t}){let{pin:n,setPin:r,respond:i,canApprove:a}=mt(e,t);return(0,w.jsxs)(`div`,{className:`ob-approval`,role:`alertdialog`,"aria-label":`Approval needed`,children:[(0,w.jsxs)(`svg`,{className:`ob-tri`,viewBox:`0 0 56 52`,"aria-hidden":`true`,children:[(0,w.jsx)(`path`,{d:`M4 48L28 4L52 48Z`}),(0,w.jsx)(`text`,{x:`28`,y:`42`,textAnchor:`middle`,children:`!`})]}),(0,w.jsxs)(`div`,{className:`ob-appr-text`,children:[(0,w.jsxs)(`span`,{className:`ob-appr-title`,children:[`APPROVAL NEEDED `,(0,w.jsx)(`span`,{className:`tier tier-${e.tier}`,children:e.tier})]}),!e.tool.startsWith(`office.`)&&(0,w.jsxs)(`span`,{className:`ob-appr-sub`,children:[e.tool,` wants to run:`]}),(0,w.jsx)(`pre`,{className:`ob-summary`,"data-testid":`approval-summary`,children:e.summary})]}),e.needsPin&&(0,w.jsx)(F,{pin:n,onChange:r,onSubmit:()=>a&&i(`approve`)}),(0,w.jsxs)(`div`,{className:`ob-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`ob-btn ob-yes`,disabled:!a,onClick:()=>i(`approve`),children:`Approve`}),e.tier===`T2`&&!e.needsPin&&!e.origin&&e.tool!==`camera.snap`&&e.tool!==`camera.watch`&&!e.tool.startsWith(`office.`)&&(0,w.jsx)(`button`,{type:`button`,className:`ob-btn`,onClick:()=>i(`approve_always`),children:`Always allow`}),(0,w.jsx)(`button`,{type:`button`,className:`ob-btn ob-no`,onClick:()=>i(`deny`),children:`Deny`})]})]})}function fF({deviceOnline:e,voiceAvailable:t,blips:n}){return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 250 270`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`20`,y:`21`,children:`DEVICES · RADAR`}),(0,w.jsx)(VN,{frame:{x:10,y:25,w:240,h:240},blips:n??[{angle:40,distance:.45,label:`This screen`},{angle:150,distance:.7,label:`PC`,dim:!e},{angle:250,distance:.6,label:`Voice`,dim:!t}]})]})}var pF=[{status:`done`,label:`DONE`},{status:`doing`,label:`DOING`},{status:`review`,label:`REVIEW`},{status:`todo`,label:`TODO`}];function mF({cells:e=[],project:t}){let n=e.length===0;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 270 160`,children:[(0,w.jsxs)(`text`,{className:`ob-lab`,x:`0`,y:`8`,children:[`TICKETS · `,t??`no workers yet`]}),(0,w.jsx)(WN,{cells:e,placeholder:n,frame:{x:0,y:20,w:260,h:80}}),(0,w.jsx)(`text`,{className:`ob-dim`,x:`0`,y:`130`,children:pF.map(t=>`■ ${t.label} ${e.filter(e=>e.status===t.status).length}`).join(` `)})]})}var hF=Array.from({length:20},(e,t)=>.35+.65*Math.abs(Math.sin(t*1.7+1))),gF=.45;function _F({level:e,mode:t}){let n=jN(e,0,1),r=Math.max(gF,n),i=Math.round(n*5);return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 300 160`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`0`,y:`8`,children:`VOICE · SPECTRUM`}),(0,w.jsx)(`line`,{className:`ob-ecg-base`,x1:`0`,x2:`300`,y1:`130`,y2:`130`}),(0,w.jsx)(RN,{levels:hF.map(e=>r*e),frame:{x:0,y:40,w:240,h:90}}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`0`,y:`150`,children:[`MIC `,`▮`.repeat(i),`▯`.repeat(5-i),` · `,t]})]})}function vF(){let[e,t]=(0,y.useState)(()=>typeof document<`u`&&document.hidden);return(0,y.useEffect)(()=>{let e=()=>t(document.hidden);return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),e}function yF(e){let[t,n]=(0,y.useState)(()=>new Date);return(0,y.useEffect)(()=>{let t=setInterval(()=>n(new Date),e);return()=>clearInterval(t)},[e]),t}var bF=e=>[...e.toUpperCase()].join(` `).replace(/\s{2,}/g,` `),xF=e=>t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},SF=e=>bt({connection:e.connection,deviceOnline:e.deviceOnline,approval:e.approval,voiceMode:e.voice.mode,busy:e.busy,activity:e.activity}).text;function CF(e,t){let n=t.stats;switch(e){case`system`:return n?`CPU ${Math.round(n.cpu)}% · RAM ${n.ramTotal>0?Math.round(100*n.ramUsed/n.ramTotal):0}%`:`Waiting for data`;case`voice`:return t.voice.mode;case`network`:return n?n.netDown===0&&n.netUp===0?`n/a`:`↓ ${Math.round(n.netDown/1024)} KB/s ↑ ${Math.round(n.netUp/1024)} KB/s`:`Waiting for data`;case`feed`:return t.chat.at(-1)?.text??`Nothing yet`;case`radar`:return[`This screen`,t.deviceOnline?`PC`:null,t.voice.available?`Voice`:null].filter(Boolean).join(` · `);case`approval`:return`None waiting`;default:return t.office.enabled&&t.office.workers.length>0?`${t.office.workers.length} worker${t.office.workers.length===1?``:`s`}`:`No workers yet`}}function wF({usage:e,reset:t=null,real:n=!1,style:r,onClick:i}){let a=typeof e==`number`&&Number.isFinite(e);return(0,w.jsxs)(`button`,{type:`button`,className:`ob-usage-label ob-hit`,"data-widget":`usage`,title:n?`How full your Claude subscription's five-hour window is`:`Today's usage compared with your busiest day of the last 30`,style:r,onClick:i,"aria-label":a?n?`Usage ${Math.round(e)} percent of the five-hour window${t?`, resets in ${t}`:``}`:`Usage ${Math.round(e)} percent of your busiest day`:`Usage, no data yet`,children:[`USAGE `,a?`${Math.round(e)}%`:`—`,t?` · RESET ${t}`:``]})}function TF({hud:e,state:t,preview:n}){let r=yF(e.clock.seconds?1e3:15e3),i=e.clock.locale||void 0,a=r.toLocaleTimeString(i,{hour:`2-digit`,minute:`2-digit`,...e.clock.seconds?{second:`2-digit`}:{},hour12:e.clock.hour12}),o=r.toLocaleDateString(i,{weekday:`short`,day:`2-digit`,month:`short`}),s=`M330 44H560L590 20H1010L1040 44H1270`,c=t.connection===`open`;return(0,w.jsxs)(`g`,{"data-testid":`orbital-topbar`,children:[(0,w.jsx)(`path`,{className:`ob-topbar-base`,d:s}),(0,w.jsx)(`path`,{className:`ob-topbar-run`,d:s,pathLength:100}),(0,w.jsx)(`text`,{className:`ob-title`,x:`800`,y:`40`,textAnchor:`middle`,children:bF(t.assistantName||`Assistant`)}),n&&(0,w.jsx)(`text`,{className:`ob-sample-tag`,x:`800`,y:`62`,textAnchor:`middle`,children:`SAMPLE DATA · NOT REAL`}),(0,w.jsx)(`circle`,{className:c?`ob-pulse`:void 0,cx:`30`,cy:`34`,r:`4`,fill:c?`#34d399`:`#fb923c`}),(0,w.jsxs)(`text`,{className:`ob-lab`,x:`40`,y:`38`,children:[(t.assistantName||`FRIEND`).toUpperCase(),` · `,c?`ONLINE`:`OFFLINE`]}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`40`,y:`58`,children:[e.terminalLabel,` · VOICE · `,t.voice.mode,` LINK · `,typeof location>`u`?``:location.host]}),(0,w.jsxs)(`text`,{className:`ob-lab`,x:`1560`,y:`38`,textAnchor:`end`,children:[a,` · `,o]})]})}function EF({hud:e,state:t,usage:n=null,viewport:r,usageApi:i,send:a=()=>{},onHire:o,onLaunch:s,onExpand:c}){let{w:l,h:u}=DN(r),d=vF(),f=Cw(l,u),p=e.preview===!0&&f===`orbit`,m=MP(p?`full`:e.density,e.widgets,f,t.approval!==null,t.widgets,p),h=p?{...t,stats:lF(Date.now()),voice:{...t.voice,mode:`listening`,level:.85}}:t,g=t.approval!==null,_=t.approval?.needsPin===!0,v=e=>e.id===`approval`?g?`orange`:`cyan`:e.tone,[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(null),[T,E]=(0,y.useState)(!1),D=yF(3e4),O=h.stats&&h.stats.ramTotal>0?Math.round(100*h.stats.ramUsed/h.stats.ramTotal):0,k={cpu:AN(h.stats?Math.round(h.stats.cpu):0,h.stats?.at,60),ram:AN(O,h.stats?.at,60),down:AN(h.stats?.netDown??0,h.stats?.at,60),up:AN(h.stats?.netUp??0,h.stats?.at,60)},A=k.down.slice(-24),j=(0,y.useRef)(null),ee=(0,y.useCallback)(()=>{x(null),C(null),E(!1),mP()&&j.current?.focus(),j.current=null},[]),M=e=>()=>{b===null&&S===null&&!T&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null),C(null),E(!1),x(e),c({kind:`widget`,id:e})};(0,y.useEffect)(()=>{if(b===null&&S===null&&!T||g)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),ee())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[b,S,T,g,ee]);let N=f===`compact`?l-16:Math.max(280,Math.min(760,l*.62)),P={x:(l-N)/2,y:u*.14,width:N,height:Math.max(220,Math.min(560,u*.7))},F=g?null:b,te=F&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-hit`,onPointerDown:e=>{e.stopPropagation(),ee()}}),(0,w.jsx)(EN,{children:(0,w.jsx)(UP,{id:F,state:t,rect:P,readings:k,...i?{usageApi:i}:{},onClose:ee})})]}),ne=t.office.enabled&&!p,re=g||!ne?void 0:t.office.workers.find(e=>e.id===S),I=e=>{b===null&&S===null&&!T&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null),x(null),E(!1),C(e)},ie=ne&&t.office.workers.length>0,ae=()=>{b===null&&S===null&&!T&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null),x(null),C(null),E(!0)},oe={...P,x:Math.max(8,P.x-60),width:Math.min(l-16,P.width+120)},se=T&&ie&&!g&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-hit`,onPointerDown:e=>{e.stopPropagation(),ee()}}),(0,w.jsx)(EN,{children:(0,w.jsx)(tF,{workers:t.office.workers,name:t.assistantName||`Friend`,rect:oe,onWorker:I,onClose:ee})})]}),ce=re&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-hit`,onPointerDown:e=>{e.stopPropagation(),ee()}}),(0,w.jsx)(EN,{children:(0,w.jsx)($P,{worker:re,feed:t.office.feed[re.id]??[],rect:P,send:a,onClose:ee})})]}),le=f===`compact`?l-16:Math.max(340,Math.min(480,l*.34)),L=Math.min(u-16,_?Math.max(300,Math.min(520,u*.7)):Math.max(260,Math.min(420,u*.55))),ue={x:(l-le)/2,y:(u-L)/2,width:le,height:L},de=g,R=de&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-modal-backdrop`}),(0,w.jsx)(EN,{children:(0,w.jsx)(PN,{"data-widget":`approval`,variant:`octagon`,tone:`orange`,title:`Approvals`,running:!0,className:`ob-zone ob-hit ob-static ob-modal`,style:{position:`absolute`,left:ue.x,top:ue.y,width:ue.width,height:ue.height},children:(0,w.jsx)(uF,{approval:t.approval,send:a})})})]}),z={className:`orbital`,"data-testid":`orbital`,"data-mode":f,"data-hud-anim":e.animations,...d?{"data-paused":``}:{}},B=m.some(e=>e.id===`usage`),fe=p?{value:42,reset:null,real:!1}:DP(t.office.quota,n,D.getTime()),pe=e=>{switch(e){case`system`:return(0,w.jsx)(kN,{node:qP(h.stats),children:(0,w.jsx)(ZN,{stats:h.stats})});case`network`:return(0,w.jsx)(kN,{node:YP(h.stats,A),children:(0,w.jsx)($N,{stats:h.stats})});case`radar`:return p?(0,w.jsx)(fF,{deviceOnline:h.deviceOnline,voiceAvailable:h.voice.available,blips:sF}):(0,w.jsx)(kN,{node:ZP(h.deviceOnline,h.voice.available),children:(0,w.jsx)(fF,{deviceOnline:h.deviceOnline,voiceAvailable:h.voice.available})});case`voice`:return(0,w.jsx)(kN,{node:JP(h.voice.level,h.voice.mode),children:(0,w.jsx)(_F,{level:h.voice.level,mode:h.voice.mode})});case`feed`:{let e=ne?TP(t.office.feed,t.office.workers):[],n=p?rF:e.length>0?e:h.chat,r=(0,w.jsx)(LP,{lines:n,activity:h.activity,busy:p||e.length>0?!1:h.busy,marquee:p});if(p)return r;let i=e.length>0?e:h.chat.map(e=>({text:`${e.role===`user`?`You`:`Friend`}: ${e.text}`,tone:`plain`}));return(0,w.jsx)(kN,{node:XP(i,h.activity,h.busy),children:r})}case`tickets`:{if(p)return(0,w.jsx)(mF,{cells:aF,project:`landing-page`});let e=ne?yP(t.office.tickets):[],n=ne?bP(t.office.tickets):void 0;return(0,w.jsx)(kN,{node:QP(e,n),children:(0,w.jsx)(mF,{...ne?{cells:e,...n?{project:n}:{}}:{}})})}case`budget`:return(0,w.jsx)(NP,{...p?{rings:oF}:ne?{rings:SP(t.office.workers)}:{}});default:return null}};if(f===`compact`){let n=e=>(0,w.jsx)(EN,{children:(0,w.jsx)(PN,{"data-widget":e.id,variant:`chamfer`,tone:v(e),title:e.title,className:`ob-zone ob-hit`,style:{minWidth:170,height:100,flex:`none`},role:`button`,tabIndex:0,"aria-label":e.title,onClick:M(e.id),onKeyDown:xF(M(e.id)),children:(0,w.jsx)(`p`,{className:`ob-li`,children:CF(e.id,t)})})},e.id);return(0,w.jsxs)(`div`,{...z,children:[(0,w.jsx)(NN,{}),(0,w.jsxs)(`div`,{className:`ob-chips`,children:[ie&&(0,w.jsxs)(`button`,{type:`button`,className:`ob-chip ob-hit`,onClick:ae,children:[`Team · `,t.office.workers.length]}),ne&&t.office.workers.map(e=>(0,w.jsx)(`button`,{type:`button`,className:`ob-chip ob-hit`,onClick:()=>I(e.id),children:e.name},e.id)),e.launcher.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`ob-chip ob-hit`,onClick:()=>s(e),children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:e.icon}),` `,e.label]},e.id))]}),(0,w.jsx)(`p`,{className:`ob-compact-status`,children:SF(t)}),(0,w.jsxs)(`div`,{className:`ob-strip`,children:[m.filter(e=>e.anchor!==`centre`&&!(e.id===`approval`&&g)).map(n),B&&(0,w.jsx)(wF,{usage:fe.value,reset:fe.reset,real:fe.real,onClick:M(`usage`)})]}),te,ce,se,R]})}let me=_w(l,u),he=Sw(fw,900),ge=e.launcher.map(e=>({id:e.id,label:e.label,glyph:e.icon,caption:e.label,status:`idle`,onClick:()=>s(e)})),V=ne?gP(t.office.workers,!0):[],_e=e=>({id:e.id,label:e.label,glyph:e.glyph,caption:e.caption,status:e.status,onClick:()=>o?.()}),ve=V.map((e,t)=>e.kind===`hire`?_e(e):{id:e.id,label:e.label,glyph:e.glyph,caption:e.caption,status:e.status,detail:e.detail,...nF[t]?{at:nF[t].at}:{},onClick:()=>I(e.id)}),ye=p?nF.map(e=>({id:e.id,label:e.label,glyph:e.label,status:e.status,detail:e.detail,at:e.at,onClick:()=>{}})):ne?t.office.workers.length>0?ve:[...ge,...ve]:ge,H=xw(ye.length,fw,900),be=fe.value,U=(e,t,n)=>{let r=vw(e,0,0,l,u);return(0,w.jsx)(`div`,{className:`ob-canvas ob-canvas-${t}`,style:{left:r.x,top:r.y,width:fw,height:900,transform:`scale(${me})`},children:n})},xe=e=>{let n={left:e.box.x,top:e.box.y,width:e.box.w,height:e.box.h};return e.id===`approval`?de?null:(0,w.jsx)(EN,{children:(0,w.jsx)(`div`,{"data-widget":`approval`,className:`ob-w ob-hit ob-static`,style:n,children:g?(0,w.jsx)(PN,{variant:`octagon`,tone:`orange`,running:!0,className:`ob-approval-frame`,children:(0,w.jsx)(uF,{approval:t.approval,send:a})}):p?(0,w.jsx)(PN,{variant:`octagon`,tone:`orange`,running:!0,className:`ob-approval-frame`,children:(0,w.jsx)(uF,{approval:cF,send:()=>{}})}):(0,w.jsx)(PN,{variant:`bracket`,title:`Approvals`,children:(0,w.jsx)(uF,{approval:null,send:a})})})},e.id):(0,w.jsx)(EN,{children:(0,w.jsx)(`div`,{"data-widget":e.id,className:`ob-w ob-hit`,style:n,role:`button`,tabIndex:0,"aria-label":e.title,onClick:M(e.id),onKeyDown:xF(M(e.id)),children:pe(e.id)})},e.id)},Se=e=>m.filter(t=>t.anchor===e),Ce=(t.assistantName||`FRIEND`).toUpperCase(),we=Math.min(1,Math.max(0,t.voice.level,t.presence.amplitude)),Te=vw(`centre`,0,0,l,u);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-base`,"aria-hidden":`true`,children:(0,w.jsx)(`div`,{className:`ob-canvas`,style:{left:Te.x,top:Te.y,width:fw,height:900,transform:`scale(${me})`},children:(0,w.jsx)(`svg`,{className:`ob-scene`,width:fw,height:900,viewBox:`0 0 ${fw} 900`,children:(0,w.jsx)(`g`,{className:`ob-disc-wrap`,style:{transform:`scale(${Number((1+.18*we).toFixed(3))})`},children:(0,w.jsx)(`circle`,{className:`ob-disc ob-breathe`,cx:he.cx,cy:he.cy,r:`104`,fill:`url(#ob-orbg)`,filter:`url(#ob-glow2)`})})})})}),(0,w.jsxs)(`div`,{...z,style:{"--s":me},children:[(0,w.jsx)(NN,{}),(0,w.jsx)(`div`,{className:`ob-bg`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-tl`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-tr`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-bl`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-br`,"aria-hidden":`true`}),U(`centre`,`centre`,(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`svg`,{className:`ob-scene`,width:fw,height:900,viewBox:`0 0 ${fw} 900`,"aria-hidden":`true`,children:[(0,w.jsx)(EN,{children:(0,w.jsx)(TF,{hud:e,state:h,preview:p})}),(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`104`,className:`ob-orb-ring`}),(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`104`,className:`ob-ping`}),(0,w.jsx)(`g`,{className:`ob-spin ob-fast`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`128`,className:`ob-ring-dash`})}),(0,w.jsx)(`g`,{className:`ob-spin ob-reverse`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`150`,className:`ob-ring-long`})}),(0,w.jsx)(`g`,{className:`ob-spin`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`172`,className:`ob-ring-thin`})}),(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:300,className:`ob-orbit`}),(0,w.jsx)(`g`,{className:`ob-spin ob-reverse ob-slow`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`330`,className:`ob-ring-outer`})}),H.map((e,t)=>{let n={x:Math.cos(e.angle*Math.PI/180),y:Math.sin(e.angle*Math.PI/180)};return(0,w.jsx)(YN,{tone:ye[t].status===`waiting`?`orange`:`cyan`,x1:he.cx+n.x*104,y1:he.cy+n.y*104,x2:he.cx+n.x*266,y2:he.cy+n.y*266},ye[t].id)}),ye.map(e=>e.at&&e.detail&&(0,w.jsx)(`text`,{className:`ob-node-detail${e.status===`running`?` ob-grn`:e.status===`waiting`?` ob-org`:``}`,x:e.at.x,y:e.at.y,textAnchor:e.at.anchor,children:e.detail},e.id))]}),ie&&(0,w.jsxs)(`button`,{type:`button`,className:`ob-team-btn ob-hit`,style:{left:he.cx,top:he.cy+52},onClick:ae,children:[`TEAM · `,t.office.workers.length]}),(0,w.jsxs)(`div`,{className:`ob-orb-label`,style:{left:he.cx,top:he.cy},"aria-hidden":`true`,children:[(0,w.jsx)(`b`,{children:Ce}),(0,w.jsx)(`small`,{children:wP(t.voice.mode,p?{enabled:!1,workers:[]}:t.office)})]}),B&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-usage-ring`,style:{left:he.cx-230,top:he.cy-230,width:460,height:460},children:(0,w.jsx)(KN,{value:be??0,radius:205,size:460})}),(0,w.jsx)(wF,{usage:be,reset:fe.reset,real:fe.real,style:{position:`absolute`,left:800,top:692,transform:`translate(-50%, -50%)`},onClick:M(`usage`)})]}),H.map((e,t)=>{let n=ye[t];return(0,w.jsx)(EN,{children:(0,w.jsx)(JN,{x:e.x,y:e.y,label:n.label,glyph:n.glyph,status:n.status,...n.caption?{caption:n.caption}:{},...n.detail?{detail:n.detail}:{},onClick:n.onClick})},n.id)}),(0,w.jsx)(`div`,{className:`ob-cmd`,"aria-hidden":`true`,children:(0,w.jsx)(`small`,{children:`[ HOLD TO TALK ]`})})]})),U(`left`,`left`,Se(`left`).map(xe)),U(`right`,`right`,Se(`right`).map(xe)),te,ce,se,R]})]})}var DF=3e5,OF=(e=new Date)=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,kF={today:0,peak:0,share:null,error:!1};function AF(e=kC,t=!0){let[n,r]=(0,y.useState)(kF);return(0,y.useEffect)(()=>{if(!t)return;let n=!0,i=()=>e.summary(30).then(e=>{if(!n)return;let t=e.days.map(e=>({day:e.day,n:e.input+e.output})),i=Math.max(0,...t.map(e=>e.n)),a=t.find(e=>e.day===OF())?.n??0;r({today:a,peak:i,share:i>0?Math.min(1,Math.max(0,a/i)):null,error:!1})}).catch(()=>n&&r({...kF,error:!0}));i();let a=setInterval(()=>void i(),DF);return()=>{n=!1,clearInterval(a)}},[e,t]),n}var jF=(e,t=18)=>(0,w.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:e}),MF=()=>jF((0,w.jsx)(`path`,{d:`M7 4.5v15l12-7.5z`,fill:`currentColor`})),NF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,fill:`currentColor`}),(0,w.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,fill:`currentColor`})]})),PF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M5 5v14l10-7z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`M18 5v14`})]})),FF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M19 5v14L9 12z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`M6 5v14`})]})),IF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M3 7h3.5c3 0 4 2 5.5 5s2.500 5 5.500 5H21`}),(0,w.jsx)(`path`,{d:`M3 17h3.5c1.500 0 2.500-.6 3.400-1.800M13.500 8.800C14.500 7.600 15.500 7 17 7h4`}),(0,w.jsx)(`path`,{d:`m18.500 4.500 2.500 2.500-2.500 2.500M18.500 14.500l2.500 2.500-2.500 2.500`})]})),LF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M17 3l3 3-3 3`}),(0,w.jsx)(`path`,{d:`M4 11V9a3 3 0 0 1 3-3h13M7 21l-3-3 3-3`}),(0,w.jsx)(`path`,{d:`M20 13v2a3 3 0 0 1-3 3H4`})]})),RF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M4 9.500v5h3.500L12 18.500v-13L7.500 9.500z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`M15.500 9a4 4 0 0 1 0 6M18 6.500a7.500 7.500 0 0 1 0 11`})]})),zF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M4 9.500v5h3.500L12 18.500v-13L7.500 9.500z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`m16 9 5 6M21 9l-5 6`})]})),BF=()=>jF((0,w.jsx)(`path`,{d:`M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5`})),VF=()=>jF((0,w.jsx)(`path`,{d:`M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5`})),HF=()=>jF((0,w.jsx)(`path`,{d:`M6 6l12 12M18 6 6 18`})),UF=()=>jF((0,w.jsx)(`path`,{d:`M9 18V6l10-2v12`}),22),WF=56,GF=()=>({bars:new Float32Array(WF),bass:0,left:0,right:0});function KF(e,t,n,r,i){let a=n?.82:.9;if(t&&n){t.getByteFrequencyData(i);let n=Math.min(i.length,96);for(let t=0;t<WF;t++){let r=Math.min(n-1,Math.floor((t/WF)**1.6*n));e.bars[t]=Math.max((i[r]??0)/255,e.bars[t]*a)}}else if(n)for(let t=0;t<WF;t++)e.bars[t]=Math.max(.12+.28*Math.abs(Math.sin(r/420+t*.55)*Math.cos(r/900+t*.21)),e.bars[t]*a);else for(let t=0;t<WF;t++)e.bars[t]=e.bars[t]*a;let o=0;for(let t=0;t<6;t++)o+=e.bars[t];e.bass=Math.min(1,o/6*1.15);let s=0,c=0;for(let t=0;t<WF/2;t++)s+=e.bars[t],c+=e.bars[t+WF/2];e.left=Math.min(1,s/(WF/2)*1.6),e.right=Math.min(1,c/(WF/2)*3.2)}function qF({progress:e,playing:t,cover:n,analyser:r,levels:i,visualizer:a,animate:o,size:s}){let c=(0,y.useRef)(null),l=(0,y.useRef)(null),u=(0,y.useRef)(new Uint8Array(new ArrayBuffer(128)));(0,y.useEffect)(()=>{let e=c.current,n=e?.getContext(`2d`);if(!e||!n||!o)return;let d=0,f=Math.min(2,window.devicePixelRatio||1);e.width=e.height=Math.round(s*f);let p=getComputedStyle(e).getPropertyValue(`--accent`).trim()||`#3fd8ff`,m=e=>{if(KF(i,r,t,e,u.current),l.current?.style.setProperty(`--bass`,i.bass.toFixed(3)),n.setTransform(f,0,0,f,0,0),n.clearRect(0,0,s,s),a){let e=s/2,t=s*.335,r=s*.135;n.lineCap=`round`,n.lineWidth=Math.max(1.5,s/90);for(let a=0;a<WF;a++){let o=a/WF*Math.PI*2-Math.PI/2,s=i.bars[a],c=2+s*r;n.strokeStyle=p,n.globalAlpha=.35+s*.65,n.beginPath(),n.moveTo(e+Math.cos(o)*t,e+Math.sin(o)*t),n.lineTo(e+Math.cos(o)*(t+c),e+Math.sin(o)*(t+c)),n.stroke()}n.globalAlpha=1}(t||!i.bars.every(e=>e<.01)||a)&&(d=requestAnimationFrame(m))};return d=requestAnimationFrame(m),()=>cancelAnimationFrame(d)},[r,t,a,o,s,i]);let d=Math.max(0,Math.min(1,e))*100;return(0,w.jsxs)(`div`,{ref:l,className:`hud-dial${t?` playing`:``}`,style:{width:s,height:s},role:`img`,"aria-label":`Playback dial`,children:[(0,w.jsxs)(`svg`,{className:`hud-dial-svg`,viewBox:`0 0 200 200`,"aria-hidden":`true`,children:[(0,w.jsx)(`circle`,{className:`hud-dial-ticks`,cx:`100`,cy:`100`,r:`96`}),(0,w.jsx)(`circle`,{className:`hud-dial-track`,cx:`100`,cy:`100`,r:`88`}),(0,w.jsx)(`circle`,{className:`hud-dial-arc`,cx:`100`,cy:`100`,r:`88`,pathLength:`100`,strokeDasharray:`${d} 100`,transform:`rotate(-90 100 100)`}),(0,w.jsx)(`circle`,{className:`hud-dial-inner`,cx:`100`,cy:`100`,r:`62`}),(0,w.jsxs)(`g`,{className:`hud-needle`,children:[(0,w.jsx)(`line`,{x1:`100`,y1:`100`,x2:`100`,y2:`14`}),(0,w.jsx)(`circle`,{cx:`100`,cy:`14`,r:`2.500`})]})]}),(0,w.jsx)(`canvas`,{ref:c,className:`hud-spectrum`,style:{width:s,height:s},"aria-hidden":`true`}),(0,w.jsx)(`div`,{className:`hud-cover`,style:n?{backgroundImage:`url("${n}")`}:void 0,children:!n&&(0,w.jsx)(UF,{})})]})}var JF=e=>{let t=Math.max(0,Math.floor(Number.isFinite(e)?e:0));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},YF=new Map,XF=e=>{let t=pd(e);return t&&t.source===`local`?t.id:null},ZF=e=>pd(e)?.source===`spotify`,QF=e=>pd(e)?.source===`soundcloud`,$F=e=>pd(e)?.source===`audius`,eI={spotify:`Spotify`,soundcloud:`SoundCloud`,audius:`Audius`};function tI(e){let[t,n]=(0,y.useState)(e?YF.get(e)??!1:!1);return(0,y.useEffect)(()=>{if(!e)return n(!1);if(YF.has(e))return n(YF.get(e));let t=!0,r=new Image;r.onload=()=>{YF.set(e,!0),t&&n(!0)},r.onerror=()=>{YF.set(e,!1),t&&n(!1)};let i=XF(e);return i?(r.src=`/api/music/cover/${i}`,()=>{t=!1}):n(!1)},[e]),e&&t?`/api/music/cover/${XF(e)}`:null}async function nI(e,t){let n=await fetch(`/api/music/library?q=${encodeURIComponent(e)}&limit=${t}`);return n.ok?await n.json():{tracks:[],total:0}}function rI(){let[e,t]=(0,y.useState)(null);return(0,y.useEffect)(()=>{let e=!0;return fetch(`/api/music/sources`).then(e=>e.ok?e.json():null).then(n=>{let r={};for(let e of[`spotify`,`soundcloud`,`audius`]){let t=n?.sources?.find(t=>t.id===e)?.status;t&&(r[e]={connected:t.connected,needs:t.needs})}e&&n&&t(r)}).catch(()=>{}),()=>{e=!1}},[]),e}async function iI(e,t,n){let r=await fetch(`/api/music/search?q=${encodeURIComponent(t)}&source=${e}&limit=${n}`);if(!r.ok)return{tracks:[],total:0};let i=((await r.json()).tracks??[]).map(e=>({id:e.ref,title:e.title,artist:e.artist,album:e.album,durationSec:e.durationSec}));return{tracks:i,total:i.length}}var aI=e=>({id:e.id,title:e.title,artist:e.artist,album:e.album,durationSec:e.durationSec});function oI({levels:e,animate:t,side:n}){let r=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!t)return;let i=0,a=r.current,o=()=>{if(a){let t=n===`left`?e.left:e.right,r=Math.round(t*12);a.querySelectorAll(`i`).forEach((e,t)=>e.classList.toggle(`on`,t<r))}i=requestAnimationFrame(o)};return i=requestAnimationFrame(o),()=>cancelAnimationFrame(i)},[e,t,n]),(0,w.jsx)(`div`,{ref:r,className:`hud-levels ${n}`,"aria-hidden":`true`,children:Array.from({length:12},(e,t)=>(0,w.jsx)(`i`,{},t))})}function sI({player:e,anim:t}){let{state:n,dispatch:r}=e,i=(0,y.useCallback)(async()=>{if(n.queue.length>0)return r({type:`resume`});let e=await nI(``,500);r({type:`play`,tracks:e.tracks.map(aI),mode:`replace`,...n.shuffle?{shuffle:!0}:{}})},[n.queue.length,n.shuffle,r]),a=e=>n=>{t!==`off`&&wN(n),e()};return(0,w.jsxs)(`div`,{className:`hud-controls`,role:`group`,"aria-label":`Player controls`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Shuffle`,"aria-pressed":n.shuffle,title:`Shuffle`,onClick:()=>r({type:`shuffle`}),children:(0,w.jsx)(IF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Previous track`,title:`Previous`,onPointerDown:a(()=>{}),onClick:()=>r({type:`previous`}),children:(0,w.jsx)(FF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn hud-btn-main`,"aria-label":n.playing?`Pause`:`Play`,title:n.playing?`Pause`:`Play`,onPointerDown:a(()=>{}),onClick:()=>n.playing?r({type:`pause`}):void i(),children:n.playing?(0,w.jsx)(NF,{}):(0,w.jsx)(MF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Next track`,title:`Next`,onPointerDown:a(()=>{}),onClick:()=>r({type:`next`}),children:(0,w.jsx)(PF,{})}),(0,w.jsxs)(`button`,{type:`button`,className:`hud-btn${n.repeat===`off`?``:` on`}`,"aria-label":`Repeat: ${n.repeat}`,title:`Repeat: ${n.repeat}`,onClick:()=>r({type:`repeat`,mode:n.repeat===`off`?`all`:n.repeat===`all`?`one`:`off`}),children:[(0,w.jsx)(LF,{}),n.repeat===`one`&&(0,w.jsx)(`sup`,{children:`1`})]})]})}function cI({player:e}){let{state:t,dispatch:n}=e,r=t.duration>0?t.position/t.duration*100:0;return(0,w.jsxs)(`div`,{className:`hud-timeline`,children:[(0,w.jsx)(`span`,{className:`hud-time`,children:JF(t.position)}),(0,w.jsx)(`input`,{type:`range`,className:`hud-range`,"aria-label":`Position`,min:0,max:Math.max(1,Math.floor(t.duration)),step:1,value:Math.min(Math.floor(t.position),Math.max(1,Math.floor(t.duration))),style:{"--fill":`${r}%`},disabled:t.duration<=0,onChange:e=>n({type:`seek`,seconds:Number(e.target.value)})}),(0,w.jsxs)(`span`,{className:`hud-time`,children:[`-`,JF(Math.max(0,t.duration-t.position))]})]})}function lI({player:e}){let{state:t,dispatch:n}=e;return(0,w.jsxs)(`div`,{className:`hud-volume`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":t.muted?`Unmute`:`Mute`,onClick:()=>n({type:`mute`}),children:t.muted||t.volume===0?(0,w.jsx)(zF,{}):(0,w.jsx)(RF,{})}),(0,w.jsx)(`input`,{type:`range`,className:`hud-range`,"aria-label":`Volume`,min:0,max:100,value:t.muted?0:t.volume,style:{"--fill":`${t.muted?0:t.volume}%`},onChange:e=>n({type:`volume`,level:Number(e.target.value)})})]})}function uI({player:e,anim:t}){let{state:n,dispatch:r}=e,[i,a]=(0,y.useState)(n.queue.length?`queue`:`library`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`folder`),[u,d]=(0,y.useState)(null),f=rI(),p=[`spotify`,`soundcloud`,`audius`].filter(e=>f?.[e]?.connected),m=c!==`folder`&&p.includes(c)?c:null,h=m?f?.[m]?.needs:null;(0,y.useEffect)(()=>{if(i!==`library`)return;let e=!0;if(m&&!o.trim()){d(null);return}let t=()=>m?iI(m,o.trim(),30):nI(o,100),n=setTimeout(()=>void t().then(t=>e&&d(t)),o?250:0);return()=>{e=!1,clearTimeout(n)}},[i,o,m]);let g=i===`queue`?n.queue.map((e,t)=>({track:e,index:t})):(u?.tracks??[]).map((e,t)=>({track:aI(e),index:t}));return(0,w.jsxs)(`div`,{className:`hud-playlist`,children:[(0,w.jsxs)(`div`,{className:`hud-tabs`,role:`tablist`,children:[[`queue`,`library`].map(e=>(0,w.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===e,className:`hud-chip${i===e?` on`:``}`,onClick:()=>a(e),children:e===`queue`?`Queue (${n.queue.length})`:`Library`},e)),i===`queue`&&n.queue.length>0&&(0,w.jsx)(`button`,{type:`button`,className:`hud-chip`,onClick:()=>r({type:`clear`}),children:`Clear`})]}),i===`library`&&p.length>0&&(0,w.jsx)(`div`,{className:`hud-tabs`,role:`tablist`,"aria-label":`Where to look`,children:[`folder`,...p].map(e=>(0,w.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":c===e,className:`hud-chip${c===e?` on`:``}`,onClick:()=>{l(e),d(null)},children:e===`folder`?`Folder`:eI[e]},e))}),i===`library`&&(0,w.jsx)(`input`,{className:`hud-search`,type:`search`,placeholder:`Search title, artist or album`,"aria-label":`Search the music`,value:o,onChange:e=>s(e.target.value)}),(0,w.jsxs)(`ul`,{className:`hud-list`,children:[g.length===0&&(0,w.jsx)(`li`,{className:`hud-empty`,children:i===`queue`?`The queue is empty.`:m&&!o.trim()?`Type to search ${eI[m]}.`:u?`No music matches.`:`Loading…`}),i===`library`&&m&&h&&(0,w.jsx)(`li`,{className:`hud-empty`,children:h}),g.map(({track:e,index:a},o)=>{let s=i===`queue`&&a===n.index;return(0,w.jsxs)(`li`,{className:`hud-tab hud-cut${s?` current`:``}${t===`full`?` hud-boot`:``}`,style:{"--i":Math.min(o,12)},children:[(0,w.jsxs)(`button`,{type:`button`,className:`hud-tab-main`,"aria-current":s?`true`:void 0,onPointerDown:t===`off`?void 0:wN,onClick:()=>r(i===`queue`?{type:`jump`,index:a}:{type:`play`,tracks:(u?.tracks??[]).map(aI),mode:`replace`,start:a}),children:[(0,w.jsx)(`span`,{className:`hud-tab-title`,children:e.title}),(0,w.jsxs)(`small`,{children:[e.artist||e.album,ZF(e.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SPOTIFY`}),QF(e.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SOUNDCLOUD`}),$F(e.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`AUDIUS`})]})]}),i===`library`&&(0,w.jsx)(`button`,{type:`button`,className:`hud-mini`,"aria-label":`Add ${e.title} to the queue`,title:`Add to the queue`,onClick:()=>r({type:`play`,tracks:[e],mode:`add`}),children:`+`}),i===`queue`&&(0,w.jsx)(`button`,{type:`button`,className:`hud-mini`,"aria-label":`Remove ${e.title} from the queue`,title:`Remove`,onClick:()=>r({type:`remove`,index:a}),children:`×`})]},`${e.id}-${a}`)})]})]})}function dI({player:e,music:t,animations:n}){let{state:r,dispatch:i,current:a,blocked:o,notice:s,analyser:c,unlock:l}=e,u=(0,y.useMemo)(GF,[]),d=tI(a?.id),f=r.view===`full`,p=CN(a?.title??``,n===`full`);if(!t?.folderSet||r.view===`hidden`)return null;let m=r.duration>0?r.position/r.duration:0,h=n!==`off`;return(0,w.jsxs)(Ce,{id:`music`,label:`Music player`,wholeBox:!0,testId:`music`,className:`hud hud-music hud-cut ${f?`full`:`mini`}${r.playing?` playing`:``}${n===`full`?` hud-boot`:``}`,children:[(0,w.jsxs)(`header`,{className:`hud-music-head`,children:[(0,w.jsx)(`span`,{className:`hud-kicker`,children:`Media player`}),(0,w.jsxs)(`span`,{className:`hud-head-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":f?`Smaller player`:`Bigger player`,title:f?`Smaller`:`Bigger`,onClick:()=>i({type:`view`,view:f?`mini`:`full`}),children:f?(0,w.jsx)(VF,{}):(0,w.jsx)(BF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Hide the player`,title:`Hide (the music keeps playing)`,onClick:()=>i({type:`view`,view:`hidden`}),children:(0,w.jsx)(HF,{})})]})]}),(0,w.jsxs)(`div`,{className:`hud-music-body`,children:[(0,w.jsxs)(`div`,{className:`hud-music-left`,children:[f&&(0,w.jsx)(oI,{levels:u,animate:h,side:`left`}),(0,w.jsx)(qF,{progress:m,playing:r.playing,cover:d,analyser:c,levels:u,visualizer:t.visualizer,animate:h,size:f?250:112}),f&&(0,w.jsx)(oI,{levels:u,animate:h,side:`right`})]}),(0,w.jsxs)(`div`,{className:`hud-music-main`,children:[(0,w.jsxs)(`div`,{className:`hud-now`,"aria-live":`polite`,children:[(0,w.jsx)(`b`,{className:`hud-title`,children:a?p:`Nothing playing`}),(0,w.jsxs)(`small`,{className:`hud-sub`,children:[a?[a.artist,a.album].filter(Boolean).join(` — `):`Press play, or ask for some music.`,a&&ZF(a.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SPOTIFY`}),a&&QF(a.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SOUNDCLOUD`}),a&&$F(a.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`AUDIUS`}),e.remote&&(0,w.jsx)(`em`,{className:`hud-source`,children:`THIS PC`})]})]}),(0,w.jsx)(cI,{player:e}),(0,w.jsx)(sI,{player:e,anim:n}),f&&(0,w.jsx)(lI,{player:e}),s&&(0,w.jsx)(`p`,{className:`hud-notice`,role:`status`,children:s}),o&&(0,w.jsx)(`button`,{type:`button`,className:`hud-unlock`,onClick:l,children:`Tap to enable sound`})]}),f&&(0,w.jsx)(uI,{player:e,anim:n})]})]})}var fI=/^spotify:/,pI=class{local;makeSpotify;active;spotify=null;listeners=new Map;wrapped=new Map;vol=1;mute=!1;pre=``;constructor(e,t){this.local=e,this.makeSpotify=t,this.active=e}get element(){return this.local}get error(){return this.active.error??null}wrap(e){let t=this.wrapped.get(e);return t||(t={local:()=>{this.active===this.local&&e()},spot:()=>{this.spotify&&this.active===this.spotify&&e()}},this.wrapped.set(e,t)),t}spot(){if(!this.spotify){let e=this.makeSpotify();e.volume=this.vol,e.muted=this.mute,e.preload=this.pre;for(let[t,n]of this.listeners)for(let r of n)e.addEventListener(t,this.wrap(r).spot);this.spotify=e}return this.spotify}dispose(){this.spotify?.dispose?.(),this.spotify=null,this.active=this.local}get src(){return this.active.src}set src(e){let t=fI.test(e)?this.spot():this.local;t===this.active?e===``&&this.active.pause():(this.active.pause(),this.active=t),this.active.src=e}get currentTime(){return this.active.currentTime}set currentTime(e){this.active.currentTime=e}get duration(){return this.active.duration}get paused(){return this.active.paused}get volume(){return this.vol}set volume(e){this.vol=e,this.local.volume=e,this.spotify&&(this.spotify.volume=e)}get muted(){return this.mute}set muted(e){this.mute=e,this.local.muted=e,this.spotify&&(this.spotify.muted=e)}get preload(){return this.pre}set preload(e){this.pre=e,this.local.preload=e,this.spotify&&(this.spotify.preload=e)}play(){return this.active.play()}pause(){this.active.pause()}addEventListener(e,t){let n=this.listeners.get(e);n||this.listeners.set(e,n=new Set),n.add(t);let r=this.wrap(t);this.local.addEventListener(e,r.local),this.spotify?.addEventListener(e,r.spot)}removeEventListener(e,t){this.listeners.get(e)?.delete(t);let n=this.wrap(t);this.local.removeEventListener(e,n.local),this.spotify?.removeEventListener(e,n.spot)}},mI=/^spotify:([A-Za-z0-9_-]{1,64})$/,hI=`Spotify Premium is needed to play on this screen.`;async function gI(){let e=await fetch(`/api/music/spotify/token`,{cache:`no-store`});if(!e.ok)throw Error(`Spotify is not connected.`);return(await e.json()).accessToken}function _I(){let e=window;return e.Spotify?Promise.resolve(e.Spotify):new Promise((t,n)=>{e.onSpotifyWebPlaybackSDKReady=()=>e.Spotify?t(e.Spotify):n(Error(`no sdk`));let r=document.createElement(`script`);r.src=`https://sdk.scdn.co/spotify-player.js`,r.async=!0,r.onerror=()=>n(Error(`blocked`)),document.head.appendChild(r)})}function vI(e){let t=e.fetch??((...e)=>fetch(...e)),n=e.now??Date.now,r=new Map,i=null,a=null,o=null,s=null,c=!1,l=null,u=null,d=0,f=0,p=0,m=!0,h=1,g=!1,_,v=e=>{for(let t of r.get(e)??[])t()},y=()=>g?0:h,b=()=>{_&&clearInterval(_),_=void 0},x=()=>{_||=setInterval(()=>v(`timeupdate`),250)},S={error:null,preload:``,get src(){return s??``},set src(e){let t=mI.exec(e);c=e!==``&&!t,s=t?e:null,l=null,u=null,d=0,p=0,S.error=null,t||b()},get currentTime(){return m?d:d+(n()-f)/1e3},set currentTime(e){d=e,f=n(),i?.seek(Math.round(e*1e3)).catch(()=>{})},get duration(){return p},get paused(){return m},get volume(){return h},set volume(e){h=e,i?.setVolume(y()).catch(()=>{})},get muted(){return g},set muted(e){g=e,i?.setVolume(y()).catch(()=>{})},async play(){if(c||!s)throw Error(`That is not a Spotify track.`);let r=mI.exec(s),a=s,o=await T();if(s!==a)return;if(l===s){await i?.resume().catch(()=>{}),m=!1,f=n(),x();return}let u=await e.getToken().catch(()=>null);if(!u)throw C(`Spotify is not connected. Connect it in Plugins, Spotify.`);let d;try{d=await t(`https://api.spotify.com/v1/me/player/play?device_id=${encodeURIComponent(o)}`,{method:`PUT`,headers:{authorization:`Bearer ${u}`,"content-type":`application/json`},body:JSON.stringify({uris:[`spotify:track:${r[1]}`]})})}catch{throw C(`Friend could not reach Spotify right now.`)}if(d.status===403)throw C(hI);if(d.status===401)throw C(`Spotify sign-in has ended. Reconnect Spotify in Plugins, Spotify.`);if(d.status===404)throw C(`Spotify could not find this screen or that track.`);if(d.status===429)throw C(`Spotify is asking Friend to slow down. Try again in a minute.`);if(!d.ok)throw C(`Spotify could not play that.`);s===a&&(l=a,m=!1,f=n(),x())},pause(){m=!0,d+=(n()-f)/1e3,f=n(),b(),i?.pause().catch(()=>{})},dispose(){b();try{i?.disconnect()}catch{}i=null,a=null,s=null,l=null},addEventListener(e,t){let n=r.get(e);n||r.set(e,n=new Set),n.add(t)},removeEventListener(e,t){r.get(e)?.delete(t)}};function C(e){S.error=e,m=!0,b(),v(`error`);let t=Error(e),n=o;return o=null,n?.reject(t),t}function w(e){if(!e)return;d=e.position/1e3,f=n(),p=e.duration/1e3,m=e.paused,v(`timeupdate`),v(`loadedmetadata`),v(`durationchange`);let t=s?mI.exec(s)?.[1]:void 0;t&&e.paused&&e.position===0&&u!==s&&(e.track_window.previous_tracks??[]).some(e=>e.id===t)&&(u=s,b(),v(`ended`))}function T(){if(a)return Promise.resolve(a);if(o)return o.promise;let t,n,r=new Promise((e,r)=>{t=e,n=r}),s={promise:r,resolve:t,reject:n};o=s;let c=setTimeout(()=>{o===s&&C(`Spotify's player did not start. Check that this browser allows Spotify's player, then try again.`)},e.readyTimeoutMs??15e3),l=()=>clearTimeout(c);return r.then(l,l),(async()=>{try{if(!i){let t;try{t=await(e.loadSdk??_I)()}catch{o===s&&C(`Spotify's player could not be loaded. Check that nothing blocks sdk.scdn.co.`);return}let n=new t.Player({name:e.deviceName??`Friend`,volume:y(),getOAuthToken:t=>{e.getToken().then(t,()=>{})}});i=n,n.addListener(`ready`,(e=>{a=e.device_id;let t=o;o=null,t?.resolve(e.device_id)})),n.addListener(`not_ready`,(()=>{a=null})),n.addListener(`player_state_changed`,(e=>w(e))),n.addListener(`account_error`,(()=>void C(hI))),n.addListener(`authentication_error`,(()=>void C(`Spotify sign-in has ended. Reconnect Spotify in Plugins, Spotify.`))),n.addListener(`initialization_error`,(()=>void C(`Spotify's player does not work in this browser.`))),n.addListener(`playback_error`,(()=>void C(`Spotify could not play that.`)))}!await i.connect()&&o===s&&C(`Spotify's player could not connect.`)}catch{o===s&&C(`Spotify's player could not connect.`)}})(),r}return S}var yI=e=>{let t=pd(e);return t?t.source===`local`?`/api/music/track/${t.id}`:t.source===`soundcloud`||t.source===`audius`?`/api/music/stream/${e}`:e:`/api/music/track/${e}`},bI=(e,t)=>Id(e,t),xI=`friend.music`,SI=1e3,CI=1.5,wI=()=>{try{return JSON.parse(localStorage.getItem(xI)??`{}`)}catch{return{}}},TI=e=>{try{localStorage.setItem(xI,JSON.stringify({volume:e.volume,muted:e.muted,shuffle:e.shuffle,repeat:e.repeat,view:e.view}))}catch{}};function EI({music:e,cmd:t,send:n,connection:r,createAudio:i,createSpotify:a,remote:o=!1}){let[s,c]=(0,y.useReducer)(bI,void 0,()=>{let e=wI();return Md({volume:e.volume??70,shuffle:e.shuffle??!1,repeat:e.repeat??`all`,view:e.view??`mini`})}),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=(0,y.useRef)(!1),_=(0,y.useRef)(s);_.current=s;let v=(0,y.useRef)(!1),b=(0,y.useRef)(null),x=(0,y.useRef)(0),S=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!e||S.current)return;S.current=!0;let t=wI();c({type:`volume`,level:t.volume??e.volume}),c({type:`repeat`,mode:t.repeat??e.repeat}),(t.shuffle??e.shuffle)&&c({type:`shuffle`,on:!0}),c({type:`view`,view:t.view??e.startView}),t.muted&&c({type:`mute`,on:!0})},[e]);let C=()=>{if(!h.current){let e=new pI(i?i():new Audio,a??(()=>vI({getToken:gI})));e.preload=`auto`,h.current=e}return h.current},w=(0,y.useRef)(!1),T=(0,y.useCallback)(()=>{let e=h.current;if(e&&e.src){w.current=!0;try{let t=e.play();t&&typeof t.then==`function`?t.then(()=>{w.current=!1,u(!1)},()=>{w.current=!1;let e=h.current?.error??null;e?f(e):u(!0)}):(w.current=!1,u(!1))}catch{w.current=!1,u(!0)}E.current||O()}},[]),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=()=>{let e=h.current,t=e instanceof pI?e.element:e,n=typeof window<`u`?window.AudioContext??window.webkitAudioContext:void 0;if(t&&n&&typeof t.play==`function`)try{let e=new n;D.current=e;let r=e.createMediaElementSource(t),i=e.createAnalyser();i.fftSize=256,i.smoothingTimeConstant=.82,r.connect(i),i.connect(e.destination),E.current=!0,m(i)}catch{E.current=!0}};(0,y.useEffect)(()=>{if(o)return;let e=C(),t=0,n=()=>{let n=Date.now();n-t<250||(t=n,c({type:`time`,position:e.currentTime||0,duration:Number.isFinite(e.duration)?e.duration:0}))},r=()=>c({type:`time`,position:e.currentTime||0,duration:Number.isFinite(e.duration)?e.duration:0}),i=()=>c({type:`ended`}),a=()=>{let t=e.error??null;f(t),c(t?{type:`pause`}:{type:`failed`})};return e.addEventListener(`timeupdate`,n),e.addEventListener(`loadedmetadata`,r),e.addEventListener(`durationchange`,r),e.addEventListener(`ended`,i),e.addEventListener(`error`,a),()=>{e.removeEventListener(`timeupdate`,n),e.removeEventListener(`loadedmetadata`,r),e.removeEventListener(`durationchange`,r),e.removeEventListener(`ended`,i),e.removeEventListener(`error`,a),e.pause(),D.current?.close().catch(()=>{}),D.current=null,e.dispose(),b.current=null,h.current=null,E.current=!1,m(null)}},[o]),(0,y.useEffect)(()=>{o&&c({type:`stop`})},[o]);let k=s.index>=0?s.queue[s.index]??null:null;(0,y.useEffect)(()=>{let e=h.current;if(o||!e)return;let t=k?.id??null;if(t!==b.current){if(b.current=t,!t){e.pause(),e.src=``;return}f(null),e.src=yI(t),s.playing&&T()}},[k?.id,s.playing,T,o]),(0,y.useEffect)(()=>{let e=h.current;!o&&e&&e.src&&(s.playing&&e.paused&&!g.current&&!w.current?T():!s.playing&&!e.paused&&e.pause())},[s.playing,s.position,T,o]),(0,y.useEffect)(()=>{let e=h.current;e&&(e.volume=s.volume/100*EO.level,e.muted=s.muted)},[s.volume,s.muted]),(0,y.useEffect)(()=>EO.subscribe(e=>{let t=h.current;t&&(t.volume=_.current.volume/100*e)}),[]),(0,y.useEffect)(()=>{let e=h.current;e&&e.src&&Math.abs((e.currentTime||0)-s.position)>CI&&(e.currentTime=s.position)},[s.position]),(0,y.useEffect)(()=>TI(s),[s.volume,s.muted,s.shuffle,s.repeat,s.view]),(0,y.useEffect)(()=>{if(!t||t.n===x.current)return;x.current=t.n;let e=Ld(t.command);e&&c(e)},[t]),(0,y.useEffect)(()=>{let e=()=>{v.current=!0,g.current&&T()};return window.addEventListener(`pointerdown`,e,{passive:!0}),window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,e)}},[T]),g.current=l;let A=(0,y.useRef)(0);return(0,y.useEffect)(()=>{if(r!==`open`||o)return;let e=()=>{let e=_.current,t=e.index>=0?e.queue[e.index]:void 0;A.current=Date.now(),n({type:`music.state`,state:{playing:e.playing,trackId:t?.id??null,title:t?.title??``,artist:t?.artist??``,album:t?.album??``,position:e.position,duration:e.duration,volume:e.volume,muted:e.muted,shuffle:e.shuffle,repeat:e.repeat,view:e.view,queue:e.queue.slice(0,50).map(e=>({id:e.id,title:e.title.slice(0,200)})),index:e.index,active:(typeof document>`u`||document.visibilityState===`visible`)&&v.current}})};e();let t=setInterval(()=>s.playing&&Date.now()-A.current>=SI&&e(),SI);return()=>clearInterval(t)},[r,o,k?.id,s.playing,s.volume,s.muted,s.shuffle,s.repeat,s.view,s.queue.length,s.index]),(0,y.useEffect)(()=>{let e=typeof navigator<`u`?navigator.mediaSession:void 0;if(e&&!o)try{k&&typeof MediaMetadata<`u`&&(e.metadata=new MediaMetadata({title:k.title,artist:k.artist,album:k.album,artwork:[{src:`/api/music/cover/${k.id}`}]})),e.playbackState=s.playing?`playing`:k?`paused`:`none`,e.setActionHandler(`play`,()=>c({type:`resume`})),e.setActionHandler(`pause`,()=>c({type:`pause`})),e.setActionHandler(`previoustrack`,()=>c({type:`previous`})),e.setActionHandler(`nexttrack`,()=>c({type:`next`})),e.setActionHandler(`seekto`,e=>typeof e.seekTime==`number`&&c({type:`seek`,seconds:e.seekTime}))}catch{}},[k?.id,s.playing,o]),{remote:!1,state:s,dispatch:c,current:k,blocked:l,notice:d,analyser:p,unlock:T,audio:h}}function DI(e,t){if(!e)return{state:{queue:[],index:-1,playing:!1,position:0,duration:0,volume:70,muted:!1,shuffle:!1,repeat:`all`,view:t},current:null};let n=e.queue.map((t,n)=>n===e.index?{id:t.id,title:e.title||t.title,artist:e.artist,album:e.album,durationSec:e.duration>0?e.duration:null}:{id:t.id,title:t.title,artist:``,album:``,durationSec:null});return{state:{queue:n,index:e.index,playing:e.playing,position:e.position,duration:e.duration,volume:e.volume,muted:e.muted,shuffle:e.shuffle,repeat:e.repeat,view:t},current:e.index>=0?n[e.index]??null:null}}function OI({local:e,host:t,send:n}){let r=e.state.view,{state:i,current:a}=(0,y.useMemo)(()=>DI(t,r),[t,r]),o=e.dispatch,s=(0,y.useCallback)(e=>{if(e.type===`view`)return o(e);let t=Rd(e);t&&n({type:`music.remote`,command:t})},[o,n]);return(0,y.useMemo)(()=>({...e,remote:!0,state:i,dispatch:s,current:a,blocked:!1,notice:null,analyser:null,unlock:()=>{}}),[e,i,s,a])}function kI(e){let t=new URLSearchParams(e).get(`music`);return t===`connected`?{level:`info`,text:`Spotify is connected. Ask Friend to play something.`}:t===`failed`?{level:`warn`,text:`Spotify did not connect. Open Plugins, Spotify and press Connect again.`}:null}function AI({onSignedOut:e}){let{state:t,send:n,dispatch:r,voice:i,handsFree:a,useHere:o}=JM(e);sN(i),cN(i),mN(n,t.connection);let[s,c]=(0,y.useState)(Ne),l=(0,y.useCallback)(e=>{Pe(e),c(e)},[]),[u,d]=(0,y.useState)(Ie),f=(0,y.useCallback)(e=>{Le(e),d(e)},[]);(0,y.useEffect)(()=>i.setQuiet(u),[i,u]);let[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(void 0),[S,C]=(0,y.useState)(null),[T,E]=(0,y.useState)(Ae),D=e=>{je(e),E(e)},O=T===`orb`?st:Re,[k,A]=(0,y.useState)(!1),[j,ee]=(0,y.useState)(0),[M,N]=(0,y.useState)(null),P=U(t.view),F=t.music?.output===`host`,te=EI({music:t.music,cmd:t.musicCmd,send:n,connection:t.connection,remote:F}),ne=OI({local:te,host:t.hostMusic,send:n}),re=F?ne:te,I=t.hud?.animations??`full`,ie=e=>{let{type:i,value:a}=e.action;if(i===`url`)window.open(a,`_blank`,`noopener,noreferrer`);else if(i===`prompt`)n({type:`chat.send`,text:a});else if(i===`music`||i===`panel`&&a===`music`){if(!t.music?.folderSet){r({type:`alert.add`,level:`info`,text:`No music folder is chosen yet. Pick one in Settings, Widgets, and the player opens.`}),C(`widgets`);return}if(i===`panel`){P.toggle(`music`,!0),re.state.view===`hidden`&&re.dispatch({type:`view`,view:`mini`});return}let e=Ld({action:a});e&&re.dispatch(e)}else a===`plugins`?v(!0):a===`settings`?C(`model`):(a===`chat`||a===`tasks`)&&P.toggle(a,!0)},ae=t.viewKnown&&t.hud?.layout===`orbital`,oe=AF(void 0,ae),se=DN(),le=Cw(se.w,se.h)===`orbit`,L=(0,y.useMemo)(()=>{let e=s?{...t,objects:[],captions:``}:t,n=t.voice.mode===`listening`||t.voice.mode===`transcribing`||t.voice.mode===`speaking`||t.busy;return ae&&le&&!n?{...e,look:{...e.look,size:e.look.size*pw}}:e},[s,t,ae,le]),ue=(0,y.useRef)(!1);(0,y.useEffect)(()=>{ue.current||!t.voice.available||t.voice.enrolled||(ue.current=!0,r({type:`alert.add`,level:`info`,text:`Voice recognition is not set up. Press Esc, then Enroll my voice.`}))},[t.voice.available,t.voice.enrolled,r]);let de=pe(),R=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!de||R.current||t.connection!==`open`)return;R.current=!0;let e=!1;try{e=localStorage.getItem(`friend.touchHint`)===`1`,localStorage.setItem(`friend.touchHint`,`1`)}catch{}e||r({type:`alert.add`,level:`info`,text:`Hold the round mic button to talk, or tap it once to start and again to send. The keyboard button types; the menu button opens settings.`})},[de,t.connection,r]);let fe=t.uiOpen?.n??0,me=t.uiOpen?.integration;(0,y.useEffect)(()=>{fe!==0&&(x(me),v(!0))},[fe,me]);let he=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(he.current)return;he.current=!0;let e=kI(window.location.search);e&&(r({type:`alert.add`,level:e.level,text:e.text}),window.history.replaceState(null,``,window.location.pathname))},[r]);let ge=(0,y.useRef)(!1);(0,y.useEffect)(()=>{ge.current||t.connection!==`open`||(ge.current=!0,fetch(`/api/history`).then(e=>e.ok?e.json():[]).then(e=>r({type:`chat.seed`,lines:e})).catch(()=>{}))},[t.connection,r]),(0,y.useEffect)(()=>{t.connection===`open`&&n({type:`ui.panels`,open:[...P.show.chat?[`chat`]:[],...P.show.tasks?[`tasks`]:[]]})},[t.connection,P.show.chat,P.show.tasks,n]);let V=(0,y.useRef)(!1);(0,y.useEffect)(()=>{t.viewKnown&&t.view===`minimal`&&!V.current&&(V.current=!0,r({type:`alert.add`,level:`info`,text:`The view is Minimal, so the status line and clock are hidden. Press Esc, then View, to bring them back.`}))},[t.viewKnown,t.view,r]);let _e=e=>{Wd.save({view:e}).catch(e=>r({type:`alert.add`,level:`warn`,text:e.message}))},ve=(0,y.useMemo)(()=>z({notify:e=>r({type:`alert.add`,level:`info`,text:e}),openSettings:()=>C(`model`),openLook:()=>C(`look`),openConnectors:()=>A(!0),openPlugins:()=>v(!0),openVoice:t.voice.available?()=>m(!0):null,muted:s,setMuted:l,quiet:u,setQuiet:f,cameraOn:t.camera.enabled,setCamera:e=>r({type:`camera.enable`,value:e}),clearScreen:()=>{for(let e of t.objects)n({type:`stage.event`,objectId:e.id,event:`dismiss`})},statusLine:()=>bt({connection:t.connection,deviceOnline:t.deviceOnline,approval:t.approval,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity}).text,endSession:t=>{fetch(t===`lock`?`/api/lock`:`/api/logout`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).catch(()=>{}).finally(e)},panelOn:e=>P.show[e],setPanel:(e,t)=>P.toggle(e,t),view:t.view,setView:_e,openHelp:N,resetLayout:()=>{be(),window.location.reload()}}),[r,n,s,e,P.show,P.toggle,t.view,t.voice.available,t.voice.mode,t.camera.enabled,t.objects,t.connection,t.deviceOnline,t.approval,t.busy,t.activity]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Vk,{state:L,send:n,dispatch:r,voice:i,slash:ve,onMenu:()=>ee(e=>e+1),hudLayer:ae&&t.hud?(0,w.jsx)(EN,{children:(0,w.jsx)(EF,{hud:t.hud,state:t,usage:oe.share===null?null:oe.share*100,send:n,onHire:()=>C(`office`),onLaunch:ie,onExpand:()=>{}})}):null}),(0,w.jsxs)(Ct,{approval:t.approval,challenge:t.challenge,cameraStream:t.camera.stream,cameraStill:t.camera.still??null,alerts:t.alerts,connection:t.connection,deviceOnline:t.deviceOnline,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity,showStatus:t.viewKnown&&P.show.status&&!ae,showClock:t.viewKnown&&P.show.clock&&!ae,profile:t.viewKnown&&P.show.profile&&!ae?{ownerName:t.ownerName,speaker:t.speaker}:null,assistantName:t.assistantName,hud:t.hud,hudApproval:ae,send:n,dispatch:r,children:[t.viewKnown&&P.show.chat&&(0,w.jsx)(we,{lines:t.chat,live:t.chatLive,onSend:e=>n({type:`chat.send`,text:e}),onClose:()=>P.toggle(`chat`,!1)}),t.viewKnown&&P.show.tasks&&(0,w.jsx)(De,{busy:t.busy,onClose:()=>P.toggle(`tasks`,!1)}),t.viewKnown&&P.show.launcher&&t.hud&&!ae&&(0,w.jsx)(TN,{items:t.hud.launcher,animations:I,onAction:ie}),t.viewKnown&&P.show.music&&(0,w.jsx)(dI,{player:re,music:t.music,animations:I}),p&&(0,w.jsx)(tN,{onClose:()=>m(!1)}),h&&(0,w.jsx)(yN,{onClose:()=>g(!1)}),_&&(0,w.jsx)(Xf,{variant:T===`orb`?`holo`:`classic`,...b?{initialConfigure:b}:{},onClose:()=>{v(!1),x(void 0)}}),S&&(0,w.jsx)(sw,{initialTab:S,variant:T===`orb`?`holo`:`classic`,onClose:()=>C(null)}),k&&(0,w.jsx)(ce,{variant:T===`orb`?`holo`:`classic`,onClose:()=>A(!1)}),M&&(0,w.jsx)(B,{commands:M,onClose:()=>N(null)})]}),(0,w.jsx)(O,{voiceMode:t.voice.mode,busy:t.busy,onClassic:()=>D(`classic`),onOrb:()=>D(`orb`),muted:s,onToggleMute:()=>l(!s),quiet:u,onToggleQuiet:()=>f(!u),onSignedOut:e,voiceAvailable:t.voice.available,voiceEnrolled:t.voice.enrolled,onEnroll:()=>m(!0),onHousehold:()=>g(!0),handsFreeOn:a.on,onToggleHandsFree:a.supported?a.toggle:void 0,assistantName:t.assistantName,onPlugins:()=>v(!0),onSettings:e=>C(e??`model`),onConnectors:()=>A(!0),cameraOn:t.camera.enabled,onToggleCamera:()=>r({type:`camera.enable`,value:!t.camera.enabled}),chatOn:P.show.chat,onToggleChat:()=>P.toggle(`chat`),tasksOn:P.show.tasks,onToggleTasks:()=>P.toggle(`tasks`),musicOn:P.show.music,onToggleMusic:()=>P.toggle(`music`),launcherOn:P.show.launcher,onToggleLauncher:()=>P.toggle(`launcher`),view:t.view,onView:_e,openRequest:j}),t.connection===`elsewhere`&&(0,w.jsx)(lN,{onUseHere:o})]})}function jI(){let[e,t]=(0,y.useState)(`loading`);return(0,y.useEffect)(()=>{let e=!0,n=n=>e&&t(n);return(async()=>{try{if(!(await(await fetch(`/api/state`)).json()).hasOwner)return n(`setup`);let e=await(await fetch(`/api/session`,{cache:`no-store`})).json();n(e.signedIn===!0?`stage`:`login`)}catch{n(`login`)}})(),()=>{e=!1}},[]),e===`loading`?(0,w.jsx)(`div`,{className:`boot`,"aria-busy":`true`}):e===`setup`?(0,w.jsx)(D,{onDone:()=>t(`login`)}):e===`login`?(0,w.jsx)(E,{onLoggedIn:()=>t(`stage`)}):(0,w.jsx)(AI,{onSignedOut:()=>t(`login`)})}(0,b.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(y.StrictMode,{children:(0,w.jsx)(jI,{})}));export{g as a,u as c,C as i,l,uk as n,f as o,du as r,s,OP as t};
4459
+ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+DD(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function KD(e,t){return GD.parse(e,t)}KD.options=KD.setOptions=function(e){return GD.setOptions(e),KD.defaults=GD.defaults,iE(KD.defaults),KD},KD.getDefaults=nE,KD.defaults=rE;function qD(...e){return GD.use(...e),KD.defaults=GD.defaults,iE(KD.defaults),KD}KD.use=qD,KD.walkTokens=function(e,t){return GD.walkTokens(e,t)},KD.parseInline=GD.parseInline,KD.Parser=UD,KD.parser=UD.parse,KD.Renderer=VD,KD.TextRenderer=HD,KD.Lexer=BD,KD.lexer=BD.lex,KD.Tokenizer=zD,KD.Hooks=WD,KD.parse=KD,KD.options,KD.setOptions,KD.walkTokens,KD.parseInline,UD.parse,BD.lex;var JD=!1;function YD(){JD||(JD=!0,tE.addHook(`afterSanitizeAttributes`,e=>{e instanceof Element&&e.tagName===`A`&&(e.setAttribute(`rel`,`noopener noreferrer`),e.setAttribute(`target`,`_blank`))}))}function XD(e){YD();let t=KD.parse(e,{async:!1,breaks:!0});return tE.sanitize(t,{ALLOWED_TAGS:[`p`,`br`,`strong`,`em`,`code`,`pre`,`ul`,`ol`,`li`,`a`,`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`blockquote`,`hr`,`del`,`table`,`thead`,`tbody`,`tr`,`th`,`td`],ALLOWED_ATTR:[`href`,`rel`,`target`],ALLOWED_URI_REGEXP:/^(?:https?:|mailto:)/i})}var ZD=e=>Number.isFinite(e);function QD(e){let t=Math.floor(Math.log10(e)),n=e/10**t;return(n<=1?1:n<=2?2:n<=2.5?2.5:n<=5?5:10)*10**t}function $D(e,t,n=5){let r=ZD(e)?e:0,i=ZD(t)?t:r+1;r>i&&([r,i]=[i,r]),r===i&&(i=r+(Math.abs(r)||1));let a=QD((i-r)/Math.max(1,n-1)),o=Math.floor(r/a)*a,s=Math.ceil(i/a)*a,c=[];for(let e=o;e<=s+a/2;e+=a)c.push(Math.round(e*1e9)/1e9);return{min:o,max:s,ticks:c}}function eO(e,t){let[n,r]=e,[i,a]=t;return r===n?()=>i:e=>i+(e-n)/(r-n)*(a-i)}function tO(e){return e.map(([e,t],n)=>`${n===0?`M`:`L`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function nO(e,t,n,r,i){let a=r=>{let i=r*Math.PI/180;return`${(e+n*Math.cos(i)).toFixed(2)} ${(t+n*Math.sin(i)).toFixed(2)}`},o=+(Math.abs(i-r)>180);return`M ${a(r)} A ${n} ${n} 0 ${o} 1 ${a(i)}`}function rO(e,t,n){return!ZD(e)||!ZD(t)||!ZD(n)||n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))*240}function iO(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=Math.hypot(i,a);if(o===0||o<=n+r)return{from:{...e},to:{...t}};let s=i/o,c=a/o;return{from:{x:e.x+s*n,y:e.y+c*n},to:{x:t.x-s*r,y:t.y-c*r}}}function aO(e,t,n){if(e<=0)return[];if(e===1)return[{x:t/2,y:n/2}];let r=Math.min(t,n)*.36;return Array.from({length:e},(i,a)=>{let o=-Math.PI/2+a*2*Math.PI/e;return{x:t/2+r*Math.cos(o),y:n/2+r*Math.sin(o)}})}var oO=e=>typeof e==`object`&&!!e&&!Array.isArray(e),sO=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,cO=e=>Array.isArray(e)?e:[],lO=e=>typeof e==`number`?Number.isFinite(e)?e:null:typeof e==`string`&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):null,uO=(e,t)=>e.length>t?e.slice(0,t)+`…`:e,dO=[`var(--accent)`,`#ffb454`,`#7b8cff`,`#5ef0b0`,`#ff6b7a`,`#c792ea`],fO=({text:e})=>e?(0,w.jsx)(`h3`,{className:`obj-title`,children:e}):null,pO=({text:e=`No data`})=>(0,w.jsx)(`p`,{className:`obj-empty`,children:e}),mO=400,hO=220,gO={l:44,r:12,t:10,b:28};function _O({props:e}){let t=e.kind===`bar`||e.kind===`area`?e.kind:`line`,n=cO(e.labels).slice(0,120).map(sO),r=cO(e.series).slice(0,6).map((e,t)=>{let n=oO(e)?e:{},r=cO(n.values).slice(0,120).map((e,t)=>({idx:t,v:lO(e)})).filter(e=>e.v!==null);return{name:sO(n.name)||`series ${t+1}`,points:r}}).filter(e=>e.points.length>0);if(r.length===0)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(pO,{})]});let i=r.flatMap(e=>e.points.map(e=>e.v)),a=Math.min(...i),o=Math.max(...i),s=$D(t===`line`?a:Math.min(0,a),t===`line`?o:Math.max(0,o),5),c=Math.max(n.length,...r.map(e=>e.points[e.points.length-1].idx+1),2),l=eO([s.min,s.max],[hO-gO.b,gO.t]),u=eO([0,c-1],[gO.l,mO-gO.r]),d=(mO-gO.l-gO.r)/c,f=Math.max(1,d*.7/r.length),p=(e,t)=>gO.l+e*d+d*.15+t*f,m=Math.max(1,Math.ceil(c/6)),h=sO(e.unit);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsxs)(`svg`,{className:`obj-chart`,viewBox:`0 0 ${mO} ${hO}`,role:`img`,"aria-label":sO(e.title)||`chart`,children:[s.ticks.map(e=>(0,w.jsxs)(`g`,{children:[(0,w.jsx)(`line`,{className:`grid`,x1:gO.l,x2:mO-gO.r,y1:l(e),y2:l(e)}),(0,w.jsxs)(`text`,{className:`tick`,x:gO.l-6,y:l(e)+3,textAnchor:`end`,children:[e,h&&e===s.max?h:``]})]},e)),Array.from({length:c},(e,t)=>t).filter(e=>e%m===0&&n[e]).map(e=>(0,w.jsx)(`text`,{className:`tick`,x:t===`bar`?p(e,0)+f*r.length/2:u(e),y:212,textAnchor:`middle`,children:uO(n[e],8)},e)),r.map((e,n)=>{let r=dO[n%dO.length];if(t===`bar`)return(0,w.jsx)(`g`,{children:e.points.map(e=>(0,w.jsx)(`rect`,{className:`bar`,x:p(e.idx,n),y:Math.min(l(e.v),l(0)),width:f,height:Math.abs(l(e.v)-l(0)),fill:r},e.idx))},n);let i=e.points.map(e=>[u(e.idx),l(e.v)]),a=tO(i),o=`${a} L${i[i.length-1][0].toFixed(2)} ${l(s.min).toFixed(2)} L${i[0][0].toFixed(2)} ${l(s.min).toFixed(2)} Z`;return(0,w.jsxs)(`g`,{children:[t===`area`&&(0,w.jsx)(`path`,{className:`series-area`,d:o,fill:r,opacity:.18}),(0,w.jsx)(`path`,{className:`series-line`,d:a,fill:`none`,stroke:r,strokeWidth:2,strokeLinejoin:`round`})]},n)})]}),r.length>1&&(0,w.jsx)(`ul`,{className:`legend`,children:r.map((e,t)=>(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`i`,{style:{background:dO[t%dO.length]}}),(0,w.jsx)(`span`,{children:e.name})]},t))})]})}function vO({props:e}){let t=lO(e.min)??0,n=lO(e.max)??100,r=lO(e.value)??t,i=rO(r,t,n),a=i/240;return(0,w.jsxs)(`div`,{className:`obj-gauge ${a>.95?`gauge-crit`:a>.8?`gauge-warn`:``}`,children:[(0,w.jsxs)(`svg`,{viewBox:`0 0 200 150`,role:`img`,"aria-label":`${sO(e.label)} ${r}`,children:[(0,w.jsx)(`path`,{className:`track`,d:nO(100,100,70,150,390),fill:`none`,strokeWidth:12,strokeLinecap:`round`}),i>0&&(0,w.jsx)(`path`,{className:`value`,d:nO(100,100,70,150,150+i),fill:`none`,strokeWidth:12,strokeLinecap:`round`})]}),(0,w.jsxs)(`div`,{className:`gauge-read`,children:[(0,w.jsx)(`span`,{className:`gauge-value`,children:String(Math.round(r*100)/100)}),sO(e.unit)&&(0,w.jsx)(`small`,{className:`gauge-unit`,children:sO(e.unit)})]}),(0,w.jsx)(`span`,{className:`obj-label`,children:sO(e.label)})]})}function yO({props:e}){let t=cO(e.items).slice(0,30).map(e=>oO(e)?e:{}).map(e=>({time:sO(e.time),title:sO(e.title),detail:sO(e.detail)})).filter(e=>e.title||e.time);return t.length===0?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(pO,{text:`Nothing to show`})]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(`ol`,{className:`obj-timeline`,children:t.map((e,t)=>(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`time`,{children:e.time}),(0,w.jsx)(`strong`,{children:e.title}),e.detail&&(0,w.jsx)(`span`,{children:e.detail})]},t))})]})}var bO=400,xO=300,SO=12;function CO({props:e}){let t=(0,y.useId)(),n=new Set,r=[];for(let t of cO(e.nodes)){let e=oO(t)?t:{},i=sO(e.id);if(i&&!n.has(i)&&(n.add(i),r.push({id:i,label:sO(e.label)||i}),r.length>=40))break}if(r.length===0)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsx)(pO,{text:`Nothing to show`})]});let i=new Map(r.map((e,t)=>[e.id,aO(r.length,bO,xO)[t]])),a=[];for(let t of cO(e.edges)){let e=oO(t)?t:{},n=sO(e.from),r=sO(e.to);if(i.has(n)&&i.has(r)&&n!==r&&(a.push({from:n,to:r,label:sO(e.label)}),a.length>=80))break}return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fO,{text:sO(e.title)}),(0,w.jsxs)(`svg`,{className:`obj-graph`,viewBox:`0 0 ${bO} ${xO}`,role:`img`,"aria-label":sO(e.title)||`graph`,children:[(0,w.jsx)(`defs`,{children:(0,w.jsx)(`marker`,{id:t,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,w.jsx)(`path`,{d:`M0 0 L10 5 L0 10 z`,className:`arrow`})})}),a.map((e,n)=>{let{from:r,to:a}=iO(i.get(e.from),i.get(e.to),14,17),o=(r.x+a.x)/2+(bO/2-(r.x+a.x)/2)*.25,s=(r.y+a.y)/2+(xO/2-(r.y+a.y)/2)*.25;return(0,w.jsxs)(`g`,{children:[(0,w.jsx)(`path`,{className:`edge`,d:`M ${r.x.toFixed(1)} ${r.y.toFixed(1)} Q ${o.toFixed(1)} ${s.toFixed(1)} ${a.x.toFixed(1)} ${a.y.toFixed(1)}`,fill:`none`,markerEnd:`url(#${t})`}),e.label&&(0,w.jsx)(`text`,{className:`edge-label`,x:o,y:s,textAnchor:`middle`,children:uO(e.label,12)})]},n)}),r.map(e=>{let t=i.get(e.id);return(0,w.jsxs)(`g`,{children:[(0,w.jsx)(`circle`,{className:`node`,cx:t.x,cy:t.y,r:SO}),(0,w.jsx)(`text`,{className:`node-label`,x:t.x,y:t.y+26,textAnchor:`middle`,children:uO(e.label,18)})]},e.id)})]})]})}var wO=30,TO=e=>Number.isFinite(e)?Math.max(0,Math.min(1,e)):1,EO=new class{current=1;goal=1;from=1;steps=1;n=0;timer=null;subs=new Set;get level(){return this.current}set(e,t=250){if(this.goal=TO(e),t<=0||this.goal===this.current){this.stop(),this.move(this.goal);return}this.from=this.current,this.steps=Math.max(1,Math.ceil(t/wO)),this.n=0,this.timer??=setInterval(()=>this.tick(),wO)}subscribe(e){return this.subs.add(e),()=>void this.subs.delete(e)}tick(){this.n++,this.n>=this.steps?(this.stop(),this.move(this.goal)):this.move(this.from+(this.goal-this.from)*this.n/this.steps)}stop(){this.timer&&clearInterval(this.timer),this.timer=null}move(e){if(e!==this.current){this.current=e;for(let t of[...this.subs])t(e)}}};function DO(e,t=EO){let n=e.volume,r=e.volume,i=!0,a=t=>{i&&(r=TO(n*t),e.volume=r)},o=()=>{if(!i||Math.abs(e.volume-r)<=.002)return;let a=t.level;a>.001&&(n=TO(e.volume/a)),r=e.volume};e.addEventListener(`volumechange`,o);let s=t.subscribe(a);return a(t.level),()=>{i=!1,s(),e.removeEventListener(`volumechange`,o),e.volume=n}}var OO=`https://www.youtube-nocookie.com`;function kO(e,t=EO,n=window){let r=100,i=null,a=!1,o=!0,s=!1,c=t=>e.contentWindow?.postMessage(JSON.stringify(t),OO),l=()=>c({event:`listening`,id:1,channel:`widget`}),u=e=>{i=e,c({event:`command`,func:`setVolume`,args:[e]})},d=e=>{o&&(e<.999?(a=!0,u(Math.round(r*e))):a&&(a=!1,u(Math.round(r))))},f=n=>{if(!o||n.source!==e.contentWindow)return;let c;try{c=JSON.parse(String(n.data)).info}catch{return}if(typeof c?.volume!=`number`)return;s=!0;let l=c.volume;if(i!==null&&Math.abs(l-i)<=1)return;let u=t.level;r=a&&u>.001?l/u:l,i=l};n.addEventListener(`message`,f),e.addEventListener?.(`load`,l),l();let p=setInterval(()=>s?clearInterval(p):l(),1e3),m=t.subscribe(d);return d(t.level),()=>{o=!1,clearInterval(p),m(),n.removeEventListener(`message`,f),e.removeEventListener?.(`load`,l),a&&AO(e,r)}}function AO(e,t){try{e.contentWindow?.postMessage(JSON.stringify({event:`command`,func:`setVolume`,args:[Math.round(t)]}),OO)}catch{}}var jO=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,MO=e=>Array.isArray(e)?e:[],NO=e=>typeof e==`object`&&e?e:{},PO=/^\/api\/media\/[0-9a-f]{32}$/,FO=e=>typeof e==`string`&&PO.test(e)?e:null,IO=/^\/api\/video\/[0-9a-f]{32}$/,LO=e=>typeof e==`string`&&IO.test(e)?e:null,RO=({props:e})=>jO(e.title)?(0,w.jsx)(`h3`,{className:`obj-title`,children:jO(e.title)}):null;function zO({props:e}){let t=(0,y.useMemo)(()=>XD(jO(e.text)),[e.text]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(RO,{props:e}),(0,w.jsx)(`div`,{className:`obj-md obj-doc`,dangerouslySetInnerHTML:{__html:t}})]})}function BO({props:e}){let t=Math.min(100,Math.max(0,Number(e.value)||0));return(0,w.jsxs)(`div`,{className:`obj-progress`,children:[(0,w.jsxs)(`div`,{className:`obj-progress-head`,children:[(0,w.jsx)(`span`,{className:`obj-label`,children:jO(e.label)}),(0,w.jsxs)(`span`,{className:`obj-progress-pct`,children:[Math.round(t),`%`]})]}),(0,w.jsx)(`div`,{className:`obj-progress-bar`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(t),"aria-label":jO(e.label)||`Progress`,children:(0,w.jsx)(`i`,{style:{width:`${t}%`}})}),jO(e.detail)&&(0,w.jsx)(`span`,{className:`obj-progress-detail`,children:jO(e.detail)})]})}function VO({props:e}){let t=MO(e.items).map(e=>NO(typeof e==`object`&&e?e:{text:e})),n=t.filter(e=>e.done===!0).length;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(RO,{props:e}),(0,w.jsx)(`ul`,{className:`obj-checklist`,children:t.map((e,t)=>(0,w.jsxs)(`li`,{className:e.done===!0?`done`:void 0,children:[(0,w.jsx)(`span`,{className:`box`,"aria-hidden":`true`,children:e.done===!0?`✓`:``}),(0,w.jsx)(`span`,{children:jO(e.text)})]},t))}),t.length>0&&(0,w.jsxs)(`small`,{className:`obj-progress-detail`,children:[n,` of `,t.length,` done`]})]})}function HO({props:e}){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(RO,{props:e}),(0,w.jsx)(`dl`,{className:`obj-kv`,children:MO(e.rows).map((e,t)=>{let n=NO(e);return(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:jO(n.key)}),(0,w.jsx)(`dd`,{children:jO(n.value)})]},t)})})]})}var UO=e=>String(Math.floor(e)).padStart(2,`0`);function WO(e){let t=Math.max(0,Math.ceil(e));return`${UO(t/3600)}:${UO(t%3600/60)}:${UO(t%60)}`}function GO({props:e}){let t=(0,y.useRef)(null);if(t.current===null){let n=typeof e.to==`string`?Date.parse(e.to):NaN,r=Number(e.seconds);t.current=Number.isFinite(n)?n:Date.now()+(Number.isFinite(r)?r:0)*1e3}let[n,r]=(0,y.useState)(Date.now());(0,y.useEffect)(()=>{let e=setInterval(()=>r(Date.now()),250);return()=>clearInterval(e)},[]);let i=(t.current-n)/1e3;return(0,w.jsxs)(`div`,{className:`obj-countdown${i<=0?` done`:``}`,children:[(0,w.jsx)(`span`,{className:`obj-label`,children:jO(e.title)||jO(e.label)}),(0,w.jsx)(`span`,{className:`obj-countdown-time`,role:`timer`,children:WO(i)})]})}function KO({props:e}){let t=FO(e.src);return(0,w.jsxs)(`div`,{className:`obj-media`,children:[(0,w.jsx)(RO,{props:e}),t?(0,w.jsx)(`img`,{src:t,alt:jO(e.title)||`Picture`,loading:`lazy`}):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This picture is not available.`})]})}function qO({src:e,web:t,title:n}){let[r,i]=(0,y.useState)(t?`loading`:`ready`),a=(0,y.useRef)(null);return(0,y.useEffect)(()=>a.current?DO(a.current):void 0,[r===`failed`]),r===`failed`?(0,w.jsx)(`p`,{className:`obj-empty`,children:`This video could not be played. Ask Friend to try again, or to play it in a window on the PC.`}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`video`,{ref:a,src:e,controls:!0,playsInline:!0,autoPlay:t,preload:t?`auto`:`metadata`,"aria-label":n,onLoadedData:()=>i(`ready`),onError:()=>i(`failed`)}),t&&r===`loading`&&(0,w.jsx)(`p`,{className:`obj-empty`,children:`Preparing the video…`})]})}var JO=/^[A-Za-z0-9_-]{11}$/;function YO({id:e,start:t,title:n}){let[r,i]=(0,y.useState)(!1),a=(0,y.useRef)(null);(0,y.useEffect)(()=>a.current?kO(a.current):void 0,[e]);let o=new URLSearchParams({autoplay:`1`,rel:`0`,playsinline:`1`,modestbranding:`1`,enablejsapi:`1`});return t>0&&o.set(`start`,String(t)),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`iframe`,{ref:a,className:`obj-youtube`,src:`https://www.youtube-nocookie.com/embed/${e}?${o.toString()}`,title:n,allow:`autoplay; encrypted-media; fullscreen; picture-in-picture`,allowFullScreen:!0,referrerPolicy:`strict-origin-when-cross-origin`,onLoad:()=>i(!0)}),!r&&(0,w.jsx)(`p`,{className:`obj-empty`,children:`Loading the player…`})]})}function XO({props:e}){if(e.embed!==void 0){let t=typeof e.embed==`string`&&JO.test(e.embed)?e.embed:null,n=typeof e.start==`number`&&e.start>0&&e.start<=86400?Math.floor(e.start):0;return(0,w.jsxs)(`div`,{className:`obj-media obj-media-fill`,children:[(0,w.jsx)(RO,{props:e}),t?(0,w.jsx)(YO,{id:t,start:n,title:jO(e.title)||`YouTube video`},`${t}-${n}`):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This clip is not available.`})]})}let t=LO(e.src),n=t??FO(e.src);return(0,w.jsxs)(`div`,{className:`obj-media`,children:[(0,w.jsx)(RO,{props:e}),n?(0,w.jsx)(qO,{src:n,web:t!==null,title:jO(e.title)||`Video`},n):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This clip is not available.`})]})}function ZO({props:e}){let t=FO(e.src);return(0,w.jsxs)(`div`,{className:`obj-media obj-pdf`,children:[(0,w.jsx)(RO,{props:e}),t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`iframe`,{src:t,title:jO(e.title)||`Document`}),(0,w.jsx)(`a`,{className:`obj-open`,href:t,target:`_blank`,rel:`noopener noreferrer`,children:`Open in a new tab`})]}):(0,w.jsx)(`p`,{className:`obj-empty`,children:`This document is not available.`})]})}function QO({props:e}){let t=MO(e.items).map(NO).filter(e=>FO(e.src)),[n,r]=(0,y.useState)(0),i=Math.min(n,Math.max(0,t.length-1)),a=t[i];if(!a)return(0,w.jsx)(`p`,{className:`obj-empty`,children:`Nothing to show.`});let o=FO(a.src),s=a.kind===`video`;return(0,w.jsxs)(`div`,{className:`obj-media obj-gallery`,children:[(0,w.jsx)(RO,{props:e}),s?(0,w.jsx)(`video`,{src:o,controls:!0,playsInline:!0,preload:`metadata`},o):(0,w.jsx)(`img`,{src:o,alt:jO(a.caption)||`Picture ${i+1}`},o),(0,w.jsxs)(`div`,{className:`obj-gallery-bar`,children:[(0,w.jsx)(`button`,{type:`button`,"aria-label":`Previous`,disabled:t.length<2,onClick:()=>r((i+t.length-1)%t.length),children:`‹`}),(0,w.jsxs)(`span`,{children:[jO(a.caption),(0,w.jsxs)(`small`,{children:[i+1,` / `,t.length]})]}),(0,w.jsx)(`button`,{type:`button`,"aria-label":`Next`,disabled:t.length<2,onClick:()=>r((i+1)%t.length),children:`›`})]})]})}var $O=[`default-src 'none'`,`script-src 'unsafe-inline'`,`style-src 'unsafe-inline'`,`img-src data: blob:`,`form-action 'none'`,`base-uri 'none'`].join(`; `),ek=`html,body{margin:0;min-height:100%;background:#050b10;color:var(--ink,#d8f6ff);font:15px/1.5 var(--ui,system-ui,sans-serif)}`,tk=[`--accent`,`--ink`,`--muted`,`--ok`,`--warn`,`--bad`,`--glass`,`--edge`,`--ui`,`--mono`],nk=/^[\w\s#().,%'"/-]+$/;function rk(){if(typeof document>`u`)return``;let e=getComputedStyle(document.documentElement),t=tk.map(t=>[t,e.getPropertyValue(t).trim()]).filter(([,e])=>e&&nk.test(e));return t.length?`:root{${t.map(([e,t])=>`${e}:${t}`).join(`;`)}}`:``}function ik(e,t=``){return`<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${$O}"><meta name="viewport" content="width=device-width,initial-scale=1"><style>${t}${ek}</style></head><body>${e}</body></html>`}function ak({props:e}){let t=typeof e.html==`string`?e.html:``,n=typeof e.title==`string`?e.title:``,r=(0,y.useMemo)(()=>ik(t,rk()),[t]);return(0,w.jsxs)(`div`,{className:`obj-sandbox`,children:[n&&(0,w.jsx)(`h3`,{className:`obj-title`,children:n}),(0,w.jsx)(`iframe`,{title:n||`Page made by Friend`,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,allow:``,srcDoc:r})]})}var ok=`modulepreload`,sk=function(e){return`/`+e},ck={},lk=function(e){return e.pathname.endsWith(`.css`)},uk=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=sk(t,n);let r=s(t);if(r.href in ck)return;ck[r.href]=!0;let i=lk(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:ok,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},dk=(0,y.lazy)(()=>uk(()=>import(`./jarvisTree-Ysieqypf.js`),__vite__mapDeps([0,1,2])));function fk({type:e,props:t}){let n=vu(e,t);return n?(0,w.jsx)(`p`,{className:`obj-empty`,children:n}):(0,w.jsx)(`div`,{className:`obj-jarvis`,children:(0,w.jsx)(y.Suspense,{fallback:(0,w.jsx)(`p`,{className:`obj-empty`,children:`Loading…`}),children:(0,w.jsx)(dk,{node:mu(e,t)})})})}var pk=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,mk=e=>Array.isArray(e)?e:[];function hk({props:e}){let t=(0,y.useMemo)(()=>XD(pk(e.text)),[e.text]);return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-md`,dangerouslySetInnerHTML:{__html:t}})]})}function gk({props:e}){return(0,w.jsxs)(`div`,{className:`obj-stat`,children:[(0,w.jsx)(`span`,{className:`obj-label`,children:pk(e.label)}),(0,w.jsxs)(`span`,{className:`obj-value`,children:[(0,w.jsx)(`span`,{children:pk(e.value)}),pk(e.unit)&&(0,w.jsx)(`small`,{children:pk(e.unit)})]}),pk(e.delta)&&(0,w.jsx)(`span`,{className:`obj-delta`,children:pk(e.delta)})]})}function _k({props:e}){return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`ul`,{className:`obj-list`,children:mk(e.items).map((e,t)=>{let n=typeof e==`object`&&e?e:{text:e};return(0,w.jsx)(`li`,{className:n.done?`done`:void 0,children:pk(n.text)},t)})})]})}function vk({props:e}){let t=mk(e.columns),n=mk(e.rows);return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-table-wrap`,children:(0,w.jsxs)(`table`,{className:`obj-table`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsx)(`tr`,{children:t.map((e,t)=>(0,w.jsx)(`th`,{children:pk(e)},t))})}),(0,w.jsx)(`tbody`,{children:n.map((e,t)=>(0,w.jsx)(`tr`,{children:mk(e).map((e,t)=>(0,w.jsx)(`td`,{children:pk(e)},t))},t))})]})})]})}function yk({props:e}){return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`pre`,{className:`obj-code`,"data-lang":pk(e.language),children:(0,w.jsx)(`code`,{children:pk(e.code)})})]})}function bk({part:e}){let t=typeof e==`object`&&e?e:{},n=typeof t.type==`string`?t.type:``;if(n===`group`||n===`tabs`||n===`sandbox`)return null;let r=Tk[n];return r?(0,w.jsx)(`div`,{className:`obj-part obj-part-${n}`,children:(0,w.jsx)(r,{props:typeof t.props==`object`&&t.props!==null?t.props:{}})}):null}function xk({props:e}){let t=e.layout===`row`||e.layout===`column`?e.layout:`grid`;return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-group obj-group-${t}`,children:mk(e.items).map((e,t)=>(0,w.jsx)(bk,{part:e},t))})]})}function Sk({props:e}){let t=mk(e.tabs).map(e=>typeof e==`object`&&e?e:{}),[n,r]=(0,y.useState)(0),i=Math.min(n,Math.max(0,t.length-1));return(0,w.jsxs)(w.Fragment,{children:[pk(e.title)&&(0,w.jsx)(`h3`,{className:`obj-title`,children:pk(e.title)}),(0,w.jsx)(`div`,{className:`obj-tabs`,role:`tablist`,children:t.map((e,t)=>(0,w.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t===i,className:t===i?`on`:void 0,onClick:()=>r(t),children:pk(e.title)||`Tab ${t+1}`},t))}),t[i]&&(0,w.jsx)(bk,{part:t[i]})]})}var Ck={card:hk,stat:gk,list:_k,table:vk,code:yk,chart:_O,gauge:vO,timeline:yO,graph:CO,sandbox:ak,markdown:zO,image:KO,video:XO,pdf:ZO,gallery:QO,group:xk,tabs:Sk,progress:BO,checklist:VO,countdown:GO,kv:HO},wk=Object.fromEntries(fu.map(e=>[e,({props:t})=>(0,w.jsx)(fk,{type:e,props:t})])),Tk={...Ck,...wk};function Ek(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=new Set;for(let t of e){if(i.has(t.object.id))continue;i.add(t.object.id);let e=n.get(t.object.id);r.push(e?{object:e,leaving:!1}:{object:t.object,leaving:!0})}for(let e of t)i.has(e.id)||(i.add(e.id),r.push({object:e,leaving:!1}));return r}function Dk(e,t){let[n,r]=(0,y.useState)(()=>e.map(e=>({object:e,leaving:!1}))),i=(0,y.useRef)(new Map);return(0,y.useEffect)(()=>{r(n=>{let a=Ek(n,e),o=new Set(n.filter(e=>e.leaving).map(e=>e.object.id));for(let e of a){let n=i.current.get(e.object.id);if(!e.leaving)n&&clearTimeout(n),i.current.delete(e.object.id);else if(!o.has(e.object.id)&&!n){let n=e.object.id;i.current.set(n,setTimeout(()=>{i.current.delete(n),r(e=>e.filter(e=>!(e.object.id===n&&e.leaving)))},Math.max(t,0)))}}return t<=0?a.filter(e=>!e.leaving):a})},[e,t]),(0,y.useEffect)(()=>()=>{for(let e of i.current.values())clearTimeout(e);i.current.clear()},[]),n}var Ok=.12,kk=.1,Ak=.02,jk=(e,t,n)=>Math.min(Math.max(e,t),n);function Mk(e){let t=jk(e.w,Ok,1),n=jk(e.h,kk,1);return{x:jk(e.x,0,1-t),y:jk(e.y,0,1-n),w:t,h:n}}function Nk(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return n.width<=0||n.height<=0?null:Mk({x:(r.left-n.left)/n.width,y:(r.top-n.top)/n.height,w:r.width/n.width,h:r.height/n.height})}function Pk(e,t,n){let r=(0,y.useRef)(null),[i,a]=(0,y.useState)(null),o=(0,y.useCallback)((n,r)=>{let i=Mk(r);t({type:`object.place`,id:n,placement:{x:i.x,y:i.y,w:i.w,h:i.h}}),e({type:`stage.move`,objectId:n,rect:i})},[e,t]),s=(0,y.useCallback)((e,t,i)=>{if(e.pointerType===`mouse`&&e.button!==0)return;let o=n(),s=e.currentTarget.closest(`[data-object]`);if(!o||!s||r.current)return;let c=Nk(s,o);if(!c)return;let l=o.getBoundingClientRect();r.current={id:t.id,mode:i,pointer:e.pointerId,startX:e.clientX,startY:e.clientY,from:c,stageW:l.width,stageH:l.height};try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}e.stopPropagation(),e.preventDefault(),a({id:t.id,box:c})},[n]),c=(e,t)=>{let n=(t.clientX-e.startX)/e.stageW,r=(t.clientY-e.startY)/e.stageH;return e.mode===`move`?Mk({...e.from,x:e.from.x+n,y:e.from.y+r}):Mk({...e.from,w:e.from.w+n,h:e.from.h+r})};return{preview:i,begin:s,move:(0,y.useCallback)(e=>{let t=r.current;t&&t.pointer===e.pointerId&&a({id:t.id,box:c(t,e)})},[]),end:(0,y.useCallback)((e,t)=>{let n=r.current;n&&n.pointer===e.pointerId&&(r.current=null,a(null),t||o(n.id,c(n,e)))},[o]),key:(0,y.useCallback)((e,t)=>{let r={ArrowLeft:[-.02,0],ArrowRight:[Ak,0],ArrowUp:[0,-.02],ArrowDown:[0,Ak]}[e.key],i=n(),a=e.currentTarget.closest(`[data-object]`);if(!r||!i||!a)return;let s=Nk(a,i);s&&(e.preventDefault(),o(t.id,e.shiftKey?{...s,w:s.w+r[0],h:s.h+r[1]}:{...s,x:s.x+r[0],y:s.y+r[1]}))},[o,n])}}function Fk(e,t){if(e===`auto`)return{position:`relative`};if(t.w<600)return{position:`relative`,width:`100%`};let[n,r,i,a]=typeof e==`string`?Au[e]:[e.x*100,e.y*100,e.w*100,e.h*100],o={position:`absolute`,left:`${n}%`,top:`${r}%`,width:`${i}%`};return e===`top`||e===`bottom`?{...o,maxHeight:`${a}%`}:{...o,height:`${a}%`}}var Ik=350,Lk=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,Rk=class extends y.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}};function zk(){let e=()=>({w:window.innerWidth,h:window.innerHeight}),[t,n]=(0,y.useState)(e);return(0,y.useEffect)(()=>{let t=()=>n(e());return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[]),t}var Bk=350;function Vk({state:e,send:t,dispatch:n,voice:r,slash:i,onMenu:a,hudLayer:o,panelsOpen:s}){let c=zk(),[l,u]=(0,y.useState)(0),[d,f]=(0,y.useState)(!1),p=pe(),m=c.w<600,h=e.scene===`focus`||e.scene===`multi`,g=o&&Cw(c.w,c.h)===`orbit`?(()=>{let t=_w(c.w,c.h),n=vw(`centre`,552,828,c.w,c.h);return{name:e.assistantName||`friend`,style:{left:n.x,top:n.y,width:378*t,height:36*t,"--ob-s":t}}})():void 0,_={"--accent":e.mood.accent,"--intensity":e.mood.intensity},v=e.voice.mode,b=v===`listening`?`listening`:v===`speaking`?`speaking`:v===`transcribing`?`thinking`:e.presence.state,x=kS(e.look.reactivity),S=Math.min(1,(v===`listening`||v===`speaking`?e.voice.level:e.presence.amplitude)*x),C=(0,y.useRef)({timer:null,down:!1,talking:!1,id:null}),T=e=>{if(!(e.target===e.currentTarget||e.target.closest(`[data-presence]`))||e.pointerType===`mouse`&&e.button!==0)return;let t=C.current;if(!(t.down&&t.id!==null&&e.pointerId!==t.id)){t.timer&&clearTimeout(t.timer),t.down=!0,t.talking=!1,t.id=typeof e.pointerId==`number`?e.pointerId:null;try{t.id!==null&&e.currentTarget.setPointerCapture?.(t.id)}catch{}t.timer=r?setTimeout(()=>{t.down&&(t.talking=!0,r.pressStart())},Bk):null}},E=(e,t)=>{let n=C.current;n.down&&(n.id===null||typeof e.pointerId!=`number`||e.pointerId===n.id)&&(n.down=!1,n.id=null,n.timer&&clearTimeout(n.timer),n.timer=null,n.talking?(n.talking=!1,t?r?.blur?.():r?.pressEnd()):t||u(e=>e+1))},D=(0,y.useRef)(null),O=Pk(t,n,()=>D.current),k=(0,y.useMemo)(()=>e.objects.filter(e=>!e.docked),[e.objects]),A=(0,y.useMemo)(()=>e.objects.filter(e=>e.docked),[e.objects]),j=Dk(k,Lk()?0:Ik),ee=j.filter(e=>e.object.layer===`overlay`),M=j.filter(e=>e.object.layer!==`overlay`&&e.object.placement===`auto`),N=j.filter(e=>e.object.layer!==`overlay`&&e.object.placement!==`auto`),P=({object:e,leaving:r})=>{let i=Tk[e.type];if(!i)return null;let a=e.layer===`overlay`,o=!m&&!r&&!a,s=O.preview?.id===e.id?O.preview.box:null,l=s?{x:s.x,y:s.y,w:s.w,h:s.h}:e.placement;return(0,w.jsxs)(`section`,{"data-object":e.id,className:`obj glass${pu(e.type)?` obj-bare`:``}${e.style===`alert`?` alert`:``}${a?` overlay`:``}${e.pinned?` pinned`:``}${s?` dragging`:``}${r?` leaving`:``}`,style:a?void 0:Fk(l,c),children:[o&&(0,w.jsx)(`div`,{className:`obj-grip`,role:`button`,tabIndex:0,"aria-label":`Move ${e.id}. Drag, or use the arrow keys; hold Shift to resize.`,...pu(e.type)?{"data-label":typeof e.props.title==`string`&&e.props.title.trim()?e.props.title.trim().slice(0,40):e.id}:{},onPointerDown:t=>O.begin(t,e,`move`),onPointerMove:O.move,onPointerUp:e=>O.end(e,!1),onPointerCancel:e=>O.end(e,!0),onKeyDown:t=>O.key(t,e)}),!a&&(0,w.jsx)(`button`,{className:`obj-pin${e.pinned?` on`:``}`,"aria-label":e.pinned?`Unpin ${e.id}`:`Pin ${e.id} to the screen`,"aria-pressed":!!e.pinned,title:e.pinned?`Pinned: stays on the screen. Click to unpin.`:`Pin: keep this on the screen.`,disabled:r,onClick:()=>t({type:`stage.pin`,objectId:e.id,pinned:!e.pinned}),children:(0,w.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:e.pinned?`currentColor`:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,w.jsx)(`path`,{d:`M12 17v5M9 3h6l-1 7 3 3H7l3-3-1-7z`})})}),(0,w.jsx)(`button`,{className:`obj-close`,"aria-label":`Dismiss ${e.id}`,title:e.pinned?`Remove this widget`:`Dismiss`,disabled:r,onClick:()=>{t({type:`stage.event`,objectId:e.id,event:`dismiss`}),n({type:`object.dismiss`,id:e.id})},children:`×`}),o&&(0,w.jsx)(`div`,{className:`obj-resize`,"aria-hidden":`true`,onPointerDown:t=>O.begin(t,e,`resize`),onPointerMove:O.move,onPointerUp:e=>O.end(e,!1),onPointerCancel:e=>O.end(e,!0)}),(0,w.jsx)(Rk,{children:(0,w.jsx)(i,{props:e.props})})]},e.id)};return(0,w.jsxs)(`div`,{ref:D,"data-testid":`stage`,className:`stage`,style:_,onPointerDown:T,onPointerUp:e=>E(e,!1),onPointerCancel:e=>E(e,!0),onContextMenu:e=>r&&e.preventDefault(),children:[e.look.ambient&&(0,w.jsx)(`div`,{className:`ambient`,"aria-hidden":`true`,style:{opacity:.35+.65*e.mood.intensity}}),(0,w.jsx)(OS,{state:b,amplitude:S,pulse:e.presence.pulse,mode:h&&!o?`corner`:`full`,accent:e.mood.accent,style:e.presence.style,intensity:e.mood.intensity,scale:e.look.size}),o,(0,w.jsxs)(`div`,{className:m?`objects objects-stack`:`objects`,style:{zIndex:10},children:[(0,w.jsx)(lw,{chips:A,panelsOpen:s,onRestore:e=>t({type:`stage.dock`,objectId:e,docked:!1})}),M.length>0&&(0,w.jsx)(`div`,{className:`auto-grid`,children:M.map(P)}),N.map(P)]}),ee.length>0&&(0,w.jsxs)(`div`,{className:`overlay-layer`,"data-testid":`overlay`,children:[(0,w.jsx)(`div`,{className:`overlay-backdrop`,onClick:()=>ee.forEach(({object:e})=>{t({type:`stage.event`,objectId:e.id,event:`dismiss`}),n({type:`object.dismiss`,id:e.id})})}),ee.map(P)]}),e.look.captions&&e.captions&&(0,w.jsx)(`p`,{className:`captions captions-${e.look.captionSize}${e.captionDone?` done`:``}`,"aria-live":`polite`,children:e.captions}),p&&r&&!d&&(0,w.jsx)(Ew,{voice:r,mode:v,onType:()=>u(e=>e+1),onMenu:()=>a?.()}),(0,w.jsx)(dw,{requestOpen:l,slash:i,onOpenChange:f,onSend:e=>t({type:`chat.send`,text:e}),...g?{hud:g}:{}})]})}function Hk(){let e=()=>Math.random().toString(36).slice(2,12)+Date.now().toString(36);try{let t=sessionStorage.getItem(`friend.tab`);return t||(t=e(),sessionStorage.setItem(`friend.tab`,t)),t}catch{return e()}}function Uk(){return`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`}function Wk(e=Uk()){let t=null,n=`connecting`,r=!1,i=0,a=!1,o=Hk(),s=null,c=new Set,l=new Set,u=e=>{n=e,l.forEach(t=>t(e))};function d(){if(r)return;u(`connecting`);let n=new WebSocket(`${e}${e.includes(`?`)?`&`:`?`}tab=${o}${a?`&takeover=1`:``}`);t=n,n.onopen=()=>{i=0,a=!1,u(`open`)},n.onmessage=e=>{try{let t=JSON.parse(String(e.data));c.forEach(e=>e(t))}catch{}},n.onclose=e=>{if(!r){if(e.code===4401)return u(`unauthorized`);if(e.code===4409||e.code===4410)return u(`elsewhere`);u(`closed`),s=setTimeout(d,Math.min(500*2**i++,8e3))}},n.onerror=()=>{}}return d(),{send(e){t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify(e))},onMessage(e){return c.add(e),()=>c.delete(e)},onState(e){return l.add(e),()=>l.delete(e)},state:()=>n,takeOver(){r||n!==`elsewhere`||(a=!0,i=0,d())},close(){r=!0,s&&clearTimeout(s),t?.close()}}}var Gk={scene:`conversation`,objects:[],widgets:[],captions:``,captionDone:!0,presence:{state:`idle`,style:`sphere`,amplitude:0,pulse:0},mood:{accent:`#3fd8ff`,intensity:.6},approval:null,alerts:[],connection:`connecting`,chat:[],chatLive:!1,view:`companion`,look:{size:1,reactivity:.7,ambient:!0,captions:!0,captionSize:`medium`},viewKnown:!1,busy:!1,activity:null,deviceOnline:!1,voice:{mode:`idle`,level:0,available:!1,enrolled:!1},challenge:null,camera:{enabled:!1,stream:null},speaker:null,ownerName:``,assistantName:``,hud:null,music:null,hostMusic:null,musicCmd:null,uiOpen:null,stats:null,office:{enabled:!1,workers:[],tickets:[],quota:{fiveHour:null,sevenDay:null},feed:{}}},Kk=200,qk=e=>e.length>Kk?e.slice(-200):e,Jk=0,Yk=e=>Math.min(1,Math.max(0,e));function Xk(e,t){switch(t.cmd){case`scene`:return{...e,scene:t.mode};case`show`:{let n=e.objects.findIndex(e=>e.id===t.object.id),r=n===-1?[...e.objects,t.object]:e.objects.map((e,r)=>r===n?t.object:e);return{...e,objects:r}}case`update`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,props:{...e.props,...t.props}}:e)};case`hide`:return{...e,objects:e.objects.filter(e=>e.id!==t.id)};case`dock`:return{...e,objects:e.objects.map(e=>e.id===t.id?t.docked?{...e,docked:!0}:(({docked:e,...t})=>t)(e):e)};case`clear`:return{...e,objects:e.objects.filter(e=>e.pinned),widgets:t.keepInstruments?e.widgets:[],scene:`conversation`};case`widget`:{let n=t.reset?[]:e.widgets.filter(e=>!(t.hide??[]).includes(e));return{...e,widgets:[...n,...(t.show??[]).filter(e=>!n.includes(e))]}}case`pin`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,pinned:!0}:e)};case`unpin`:return{...e,objects:e.objects.map(e=>e.id===t.id?(({pinned:e,...t})=>t)(e):e)};case`place`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,placement:t.placement}:e)};case`presence`:return{...e,presence:{...e.presence,state:t.state??e.presence.state,style:t.style??e.presence.style}};case`mood`:return{...e,mood:{accent:t.accent??e.mood.accent,intensity:t.intensity??e.mood.intensity}}}}function Zk(e,t){let n=t;if(n&&typeof n==`object`){if(n.type===`conn`)return{...e,connection:n.value};if(n.type===`chat.seed`){let t=Array.isArray(n.lines)?n.lines:[];return e.chat.length===0?{...e,chat:qk(t)}:{...e,chat:qk([...t,...e.chat])}}if(n.type===`alert.add`)return{...e,alerts:[...e.alerts.slice(-3),{id:++Jk,level:n.level,text:n.text}]};if(n.type===`camera.enable`)return{...e,camera:{enabled:n.value,stream:n.value?e.camera.stream:null}};if(n.type===`camera.open`)return{...e,camera:{...e.camera,stream:n.stream}};if(n.type===`camera.still`)return{...e,camera:{...e.camera,still:{url:n.url,note:n.note}}};if(n.type===`camera.still.clear`)return{...e,camera:{...e.camera,still:null}};if(n.type===`camera.closed`)return{...e,camera:{...e.camera,stream:null}};if(n.type===`challenge.dismiss`)return e.challenge?.id===n.id?{...e,challenge:null}:e;if(n.type===`voice.mode`)return{...e,voice:{...e.voice,mode:n.mode,level:n.mode===`idle`?0:e.voice.level}};if(n.type===`voice.level`){let t=Number.isFinite(n.level)?Math.min(1,Math.max(0,n.level)):0;return{...e,voice:{...e.voice,level:t}}}if(n.type===`object.dismiss`)return{...e,objects:e.objects.filter(e=>e.id!==n.id)};if(n.type===`object.place`)return{...e,objects:e.objects.map(e=>e.id===n.id?{...e,placement:n.placement}:e)};if(n.type===`alert.dismiss`)return{...e,alerts:e.alerts.filter(e=>e.id!==n.id)}}let r=Cd.safeParse(t);if(!r.success)return e;let i=r.data;switch(i.type){case`snapshot`:return{...e,scene:i.stage.scene,objects:i.stage.objects,widgets:i.stage.widgets??[],presence:{...e.presence,state:i.stage.presence.state,style:i.stage.presence.style},mood:i.stage.mood,approval:i.pendingApproval??null};case`stage`:return Xk(e,i.command);case`chat.user`:return{...e,chat:qk([...e.chat,{role:`user`,text:i.text}]),chatLive:!1};case`ui.open`:return{...e,uiOpen:{n:(e.uiOpen?.n??0)+1,...i.integration?{integration:i.integration}:{}}};case`ui`:return{...e,view:i.view,look:i.look??e.look,ownerName:i.ownerName??e.ownerName,assistantName:i.assistantName??e.assistantName,hud:i.hud??e.hud,music:i.music??e.music,viewKnown:!0};case`music.host`:return{...e,hostMusic:i.state};case`music.command`:{let{type:t,...n}=i;return{...e,musicCmd:{n:(e.musicCmd?.n??0)+1,command:n}}}case`caption.delta`:{let t=e.captionDone,n=e.chat.at(-1),r=e.chatLive&&n?.role===`assistant`?[...e.chat.slice(0,-1),{role:`assistant`,text:n.text+i.text}]:qk([...e.chat,{role:`assistant`,text:i.text}]);return{...e,chat:r,chatLive:!0,captions:(t?``:e.captions)+i.text,captionDone:!1,presence:{...e.presence,amplitude:Yk(.3+i.text.length*.04),pulse:e.presence.pulse+1}}}case`caption.end`:return{...e,chatLive:!1,captionDone:!0,presence:{...e.presence,amplitude:0}};case`approval.request`:{let{type:t,...n}=i;return{...e,approval:n}}case`approval.resolved`:return e.approval?.id===i.id?{...e,approval:null}:e;case`alert`:return{...e,alerts:[...e.alerts.slice(-3),{id:++Jk,level:i.level,text:i.text}]};case`activity`:return{...e,activity:i.text};case`office.state`:{let t={};for(let n of i.workers)e.office.feed[n.id]&&(t[n.id]=e.office.feed[n.id]);return{...e,office:{enabled:i.enabled,workers:i.workers,tickets:i.tickets,quota:i.quota,feed:t}}}case`office.feed`:{if(!e.office.workers.some(e=>e.id===i.workerId))return e;let t={at:i.at,kind:i.kind,text:i.text},n=[...e.office.feed[i.workerId]??[],t].slice(-60);return{...e,office:{...e.office,feed:{...e.office.feed,[i.workerId]:n}}}}case`hud.stats`:return{...e,stats:{cpu:i.cpu,ramUsed:i.ramUsed,ramTotal:i.ramTotal,netDown:i.netDown,netUp:i.netUp,at:Date.now()}};case`status`:return{...e,busy:i.busy,activity:i.busy?e.activity:null,deviceOnline:i.deviceOnline,voice:{...e.voice,available:i.voiceAvailable??e.voice.available,enrolled:i.voiceEnrolled??e.voice.enrolled}};case`error`:return{...e,alerts:[...e.alerts.slice(-3),{id:++Jk,level:`error`,text:i.message}]};case`voice.heard`:return{...e,captions:i.trust===`guest`?`Guest: ${i.text}`:i.trust===`member`&&i.speaker?`${i.speaker}: ${i.text}`:i.text,captionDone:!0,speaker:{name:i.trust===`member`?i.speaker??null:null,trust:i.trust??`unverified`,seq:(e.speaker?.seq??0)+1}};case`voice.challenge`:return{...e,challenge:{id:i.id,text:i.text}};case`voice.challenge.end`:return e.challenge?.id===i.id?{...e,challenge:null}:e;case`audio.chunk`:case`audio.stop`:case`audio.duck`:return e;case`camera.request`:case`camera.cancel`:case`screen.request`:case`screen.cancel`:case`screen.check`:return e}}var Qk=1024,$k=.8,eA=300;function tA(e,t){let n=Math.min(1,Qk/Math.max(e,t));return{width:Math.round(e*n),height:Math.round(t*n)}}function nA(e){let t=e?.name;return t===`NotAllowedError`||t===`SecurityError`?`permission`:t===`NotFoundError`||t===`OverconstrainedError`?`no-camera`:`busy`}async function rA(){if(!navigator.mediaDevices?.getUserMedia)throw Object.assign(Error(`This browser cannot use the camera here (use localhost or HTTPS).`),{name:`NotFoundError`});return navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280}},audio:!1})}async function iA(e,t=eA){let n=document.createElement(`video`);n.muted=!0,n.playsInline=!0,n.srcObject=e,await n.play(),await new Promise(e=>setTimeout(e,t));let{width:r,height:i}=tA(n.videoWidth||640,n.videoHeight||480),a=document.createElement(`canvas`);return a.width=r,a.height=i,a.getContext(`2d`).drawImage(n,0,0,r,i),n.srcObject=null,new Promise((e,t)=>a.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,$k))}async function aA(e,t,n,r=eA){let i=document.createElement(`video`);i.muted=!0,i.playsInline=!0,i.srcObject=e,await i.play(),await new Promise(e=>setTimeout(e,r));let{width:a,height:o}=tA(i.videoWidth||640,i.videoHeight||480),s=document.createElement(`canvas`);s.width=a,s.height=o;let c=t>1?n*1e3/(t-1):0,l=[];try{for(let e=0;e<t;e++)e>0&&await new Promise(e=>setTimeout(e,c)),s.getContext(`2d`).drawImage(i,0,0,a,o),l.push(await new Promise((e,t)=>s.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,$k)))}finally{i.srcObject=null}return l}var oA=class{opts;active=null;shown=null;constructor(e){this.opts=e}async handle(e){if(e.type===`camera.cancel`){let t=this.active;t&&t.id===e.id&&(t.cancelled=!0,this.release(t));return}if(!this.opts.enabled())return this.opts.send({type:`camera.denied`,id:e.id,reason:`off`});if(this.active)return this.opts.send({type:`camera.denied`,id:e.id,reason:`busy`});this.clearStill();let t={id:e.id,cancelled:!1,stream:null,opened:!1,released:!1};this.active=t;try{let n=await(this.opts.open??rA)();if(t.stream=n,t.cancelled){n.getTracks().forEach(e=>e.stop());return}t.opened=!0,this.opts.dispatch({type:`camera.open`,stream:n});let r=typeof e.frames==`number`&&e.frames>1?{frames:Math.min(12,Math.round(e.frames)),seconds:Math.min(10,Math.max(1,Math.round(e.seconds??5)))}:null,i=r?await(this.opts.frames??((e,t,n)=>aA(e,t,n)))(n,r.frames,r.seconds):[await(this.opts.frame??(e=>iA(e)))(n)];if(t.cancelled)return;this.release(t);let a=i[Math.floor(i.length/2)],o=!!(e.recognise&&this.opts.faces&&this.opts.sendFaces),s=this.showStill(a,o?`Looking…`:`Looked`);if(o){let t=`No face found`;try{let n=await this.opts.faces(a);n.length?(await this.opts.sendFaces(e.id,n),t=n.length===1?`1 face found`:`${n.length} faces found`):this.opts.faceProblem?.()&&(t=`The face models did not load`)}catch{}s&&this.shown?.url===s&&this.opts.dispatch({type:`camera.still`,url:s,note:t})}try{for(let t of i)await this.opts.upload(e.id,t)}catch{this.opts.dispatch({type:`alert.add`,level:`warn`,text:`Could not send the camera picture to Friend.`})}}catch(n){t.cancelled||this.opts.send({type:`camera.denied`,id:e.id,reason:nA(n)})}finally{this.release(t),this.active===t&&(this.active=null)}}showStill(e,t){try{let n=(this.opts.still??(e=>URL.createObjectURL(e)))(e);this.opts.dispatch({type:`camera.still`,url:n,note:t});let r=setTimeout(()=>this.clearStill(),this.opts.holdMs??5e3);return this.shown={url:n,timer:r},n}catch{return null}}clearStill(){let e=this.shown;e&&(this.shown=null,clearTimeout(e.timer),this.opts.dispatch({type:`camera.still.clear`}),(this.opts.release??(e=>URL.revokeObjectURL(e)))(e.url))}dispose(){this.clearStill();let e=this.active;e&&(e.cancelled=!0,this.release(e))}release(e){e.released||(e.released=!0,e.stream?.getTracks().forEach(e=>e.stop()),e.opened&&this.opts.dispatch({type:`camera.closed`}))}},sA=[8,16,32],cA=e=>e<0?0:e>1?1:e;function lA(e){let t=Math.min(640/e.width,640/e.height),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t)),i=409600,a=new Float32Array(3*i);for(let o=0;o<r;o++){let r=Math.min(e.height-1,(o+.5)/t-.5),s=Math.max(0,Math.floor(r)),c=Math.min(e.height-1,s+1),l=Math.max(0,r-s);for(let r=0;r<n;r++){let n=Math.min(e.width-1,(r+.5)/t-.5),u=Math.max(0,Math.floor(n)),d=Math.min(e.width-1,u+1),f=Math.max(0,n-u),p=(t,n,r)=>e.data[(n*e.width+t)*4+r];for(let e=0;e<3;e++){let t=p(u,s,e)*(1-f)+p(d,s,e)*f,n=p(u,c,e)*(1-f)+p(d,c,e)*f;a[(2-e)*i+o*640+r]=t*(1-l)+n*l}}}return{tensor:a,scale:t}}var uA=(e,t)=>{let[n,r,i,a]=e.box,[o,s,c,l]=t.box,u=Math.min(n+i,o+c)-Math.max(n,o),d=Math.min(r+a,s+l)-Math.max(r,s);if(u<=0||d<=0)return 0;let f=u*d;return f/(i*a+c*l-f)};function dA(e,t,n=.7,r=.3){let i=[];for(let r of sA){let a=640/r,o=e[`cls_${r}`].data,s=e[`obj_${r}`].data,c=e[`bbox_${r}`].data,l=e[`kps_${r}`].data;for(let e=0;e<a*a;e++){let u=Math.sqrt(cA(o[e])*cA(s[e]));if(u<n)continue;let d=Math.floor(e/a),f=e%a,p=(f+c[e*4])*r,m=(d+c[e*4+1])*r,h=Math.exp(c[e*4+2])*r,g=Math.exp(c[e*4+3])*r,_=[];for(let n=0;n<5;n++)_.push([(l[e*10+n*2]+f)*r/t,(l[e*10+n*2+1]+d)*r/t]);i.push({box:[(p-h/2)/t,(m-g/2)/t,h/t,g/t],score:u,landmarks:_})}}i.sort((e,t)=>t.score-e.score);let a=[];for(let e of i)a.every(t=>uA(t,e)<r)&&a.push(e);return a}async function fA(e,t,n,r=.7){let{tensor:i,scale:a}=lA(n);return dA(await t.run({[t.inputNames[0]]:new e.Tensor(`float32`,i,[1,3,640,640])}),a,r)}var pA=[[38.2946,51.6963],[73.5318,51.5014],[56.0252,71.7366],[41.5493,92.3655],[70.7299,92.2041]];function mA(e){let t=e.length,n=e.reduce((e,t)=>e+t[0],0)/t,r=e.reduce((e,t)=>e+t[1],0)/t,i=pA.reduce((e,t)=>e+t[0],0)/t,a=pA.reduce((e,t)=>e+t[1],0)/t,o=0,s=0,c=0;for(let l=0;l<t;l++){let t=e[l][0]-n,u=e[l][1]-r,d=pA[l][0]-i,f=pA[l][1]-a;o+=t*d+u*f,s+=t*f-u*d,c+=t*t+u*u}let l=o/c,u=s/c;return[l,u,i-(l*n-u*r),a-(u*n+l*r)]}function hA(e,t){let[n,r,i,a]=mA(t),o=n*n+r*r,s=12544,c=new Float32Array(3*s);for(let t=0;t<112;t++)for(let l=0;l<112;l++){let u=l-i,d=t-a,f=(n*u+r*d)/o,p=(-r*u+n*d)/o,m=Math.floor(f),h=Math.floor(p),g=f-m,_=p-h;for(let n=0;n<3;n++){let r=(t,r)=>{let i=Math.min(e.width-1,Math.max(0,t)),a=Math.min(e.height-1,Math.max(0,r));return e.data[(a*e.width+i)*4+n]},i=r(m,h)*(1-g)+r(m+1,h)*g,a=r(m,h+1)*(1-g)+r(m+1,h+1)*g;c[n*s+t*112+l]=i*(1-_)+a*_}}return c}async function gA(e,t,n,r){let i=hA(n,r.landmarks),a=await t.run({[t.inputNames[0]]:new e.Tensor(`float32`,i,[1,3,112,112])});return Array.from(a[t.outputNames[0]].data)}var _A=5,vA=60;function yA(e,t=_A,n=vA){return e.filter(e=>Math.min(e.box[2],e.box[3])>=n).sort((e,t)=>t.box[2]*t.box[3]-e.box[2]*e.box[3]).slice(0,t)}var bA=class{deps;loaded=null;failed=!1;constructor(e){this.deps=e}async find(e){try{this.loaded??=this.deps.load();let{ort:t,yunet:n,sface:r}=await this.loaded,i=await this.deps.decode(e),a=yA(await fA(t,n,i)),o=[];for(let e of a)o.push(await gA(t,r,i,e));return this.failed=!1,o}catch{return this.loaded=null,this.failed=!0,[]}}};async function xA(e){let t=await createImageBitmap(e),n=document.createElement(`canvas`);n.width=t.width,n.height=t.height;let r=n.getContext(`2d`);r.drawImage(t,0,0),t.close?.();let i=r.getImageData(0,0,n.width,n.height);return{data:i.data,width:i.width,height:i.height}}var SA={mjs:`/ort/ort-wasm-simd-threaded.mjs`,wasm:`/ort/ort-wasm-simd-threaded.wasm`};function CA(){return new bA({decode:xA,load:async()=>{let e=await uk(()=>import(`./ort.bundle.min-2v35unQc.js`),[]);e.env.wasm.wasmPaths={...SA},e.env.wasm.numThreads=1;let t=async t=>e.InferenceSession.create(new Uint8Array(await(await fetch(t)).arrayBuffer()),{executionProviders:[`wasm`]});return{ort:e,yunet:await t(`/models/yunet.onnx`),sface:await t(`/models/sface.onnx`)}}})}function wA(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;let n=document.implementation.createHTMLDocument(),r=n.createElement(`base`),i=n.createElement(`a`);return n.head.appendChild(r),n.body.appendChild(i),t&&(r.href=t),i.href=e,i.href}var TA=(()=>{let e=0,t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function EA(e){let t=[];for(let n=0,r=e.length;n<r;n++)t.push(e[n]);return t}var DA=null;function OA(e={}){return DA||(e.includeStyleProperties?(DA=e.includeStyleProperties,DA):(DA=EA(window.getComputedStyle(document.documentElement)),DA))}function kA(e,t){let n=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return n?parseFloat(n.replace(`px`,``)):0}function AA(e){let t=kA(e,`border-left-width`),n=kA(e,`border-right-width`);return e.clientWidth+t+n}function jA(e){let t=kA(e,`border-top-width`),n=kA(e,`border-bottom-width`);return e.clientHeight+t+n}function MA(e,t={}){return{width:t.width||AA(e),height:t.height||jA(e)}}function NA(){let e,t;try{t=process}catch{}let n=t&&t.env?t.env.devicePixelRatio:null;return n&&(e=parseInt(n,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}var PA=16384;function FA(e){(e.width>PA||e.height>PA)&&(e.width>PA&&e.height>PA?e.width>e.height?(e.height*=PA/e.width,e.width=PA):(e.width*=PA/e.height,e.height=PA):e.width>PA?(e.height*=PA/e.width,e.width=PA):(e.width*=PA/e.height,e.height=PA))}function IA(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>{r.decode().then(()=>{requestAnimationFrame(()=>t(r))})},r.onerror=n,r.crossOrigin=`anonymous`,r.decoding=`async`,r.src=e})}async function LA(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(e=>`data:image/svg+xml;charset=utf-8,${e}`)}async function RA(e,t,n){let r=`http://www.w3.org/2000/svg`,i=document.createElementNS(r,`svg`),a=document.createElementNS(r,`foreignObject`);return i.setAttribute(`width`,`${t}`),i.setAttribute(`height`,`${n}`),i.setAttribute(`viewBox`,`0 0 ${t} ${n}`),a.setAttribute(`width`,`100%`),a.setAttribute(`height`,`100%`),a.setAttribute(`x`,`0`),a.setAttribute(`y`,`0`),a.setAttribute(`externalResourcesRequired`,`true`),i.appendChild(a),a.appendChild(e),LA(i)}var zA=(e,t)=>{if(e instanceof t)return!0;let n=Object.getPrototypeOf(e);return n===null?!1:n.constructor.name===t.name||zA(n,t)};function BA(e){let t=e.getPropertyValue(`content`);return`${e.cssText} content: '${t.replace(/'|"/g,``)}';`}function VA(e,t){return OA(t).map(t=>`${t}: ${e.getPropertyValue(t)}${e.getPropertyPriority(t)?` !important`:``};`).join(` `)}function HA(e,t,n,r){let i=`.${e}:${t}`,a=n.cssText?BA(n):VA(n,r);return document.createTextNode(`${i}{${a}}`)}function UA(e,t,n,r){let i=window.getComputedStyle(e,n),a=i.getPropertyValue(`content`);if(a===``||a===`none`)return;let o=TA();try{t.className=`${t.className} ${o}`}catch{return}let s=document.createElement(`style`);s.appendChild(HA(o,n,i,r)),t.appendChild(s)}function WA(e,t,n){UA(e,t,`:before`,n),UA(e,t,`:after`,n)}var GA=`application/font-woff`,KA=`image/jpeg`,qA={woff:GA,woff2:GA,ttf:`application/font-truetype`,eot:`application/vnd.ms-fontobject`,png:`image/png`,jpg:KA,jpeg:KA,gif:`image/gif`,tiff:`image/tiff`,svg:`image/svg+xml`,webp:`image/webp`};function JA(e){let t=/\.([^./]*?)$/g.exec(e);return t?t[1]:``}function YA(e){return qA[JA(e).toLowerCase()]||``}function XA(e){return e.split(/,/)[1]}function ZA(e){return e.search(/^(data:)/)!==-1}function QA(e,t){return`data:${t};base64,${e}`}async function $A(e,t,n){let r=await fetch(e,t);if(r.status===404)throw Error(`Resource "${r.url}" not found`);let i=await r.blob();return new Promise((e,t)=>{let a=new FileReader;a.onerror=t,a.onloadend=()=>{try{e(n({res:r,result:a.result}))}catch(e){t(e)}},a.readAsDataURL(i)})}var ej={};function tj(e,t,n){let r=e.replace(/\?.*/,``);return n&&(r=e),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,``)),t?`[${t}]${r}`:r}async function nj(e,t,n){let r=tj(e,t,n.includeQueryParams);if(ej[r]!=null)return ej[r];n.cacheBust&&(e+=(/\?/.test(e)?`&`:`?`)+new Date().getTime());let i;try{i=QA(await $A(e,n.fetchRequestInit,({res:e,result:n})=>(t||=e.headers.get(`Content-Type`)||``,XA(n))),t)}catch(t){i=n.imagePlaceholder||``;let r=`Failed to fetch resource: ${e}`;t&&(r=typeof t==`string`?t:t.message),r&&console.warn(r)}return ej[r]=i,i}async function rj(e){let t=e.toDataURL();return t===`data:,`?e.cloneNode(!1):IA(t)}async function ij(e,t){if(e.currentSrc){let t=document.createElement(`canvas`),n=t.getContext(`2d`);return t.width=e.clientWidth,t.height=e.clientHeight,n?.drawImage(e,0,0,t.width,t.height),IA(t.toDataURL())}let n=e.poster;return IA(await nj(n,YA(n),t))}async function aj(e,t){try{if(e?.contentDocument?.body)return await hj(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function oj(e,t){return zA(e,HTMLCanvasElement)?rj(e):zA(e,HTMLVideoElement)?ij(e,t):zA(e,HTMLIFrameElement)?aj(e,t):e.cloneNode(cj(e))}var sj=e=>e.tagName!=null&&e.tagName.toUpperCase()===`SLOT`,cj=e=>e.tagName!=null&&e.tagName.toUpperCase()===`SVG`;async function lj(e,t,n){if(cj(t))return t;let r=[];return r=sj(e)&&e.assignedNodes?EA(e.assignedNodes()):zA(e,HTMLIFrameElement)&&e.contentDocument?.body?EA(e.contentDocument.body.childNodes):EA((e.shadowRoot??e).childNodes),r.length===0||zA(e,HTMLVideoElement)||await r.reduce((e,r)=>e.then(()=>hj(r,n)).then(e=>{e&&t.appendChild(e)}),Promise.resolve()),t}function uj(e,t,n){let r=t.style;if(!r)return;let i=window.getComputedStyle(e);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):OA(n).forEach(n=>{let a=i.getPropertyValue(n);n===`font-size`&&a.endsWith(`px`)&&(a=`${Math.floor(parseFloat(a.substring(0,a.length-2)))-.1}px`),zA(e,HTMLIFrameElement)&&n===`display`&&a===`inline`&&(a=`block`),n===`d`&&t.getAttribute(`d`)&&(a=`path(${t.getAttribute(`d`)})`),r.setProperty(n,a,i.getPropertyPriority(n))})}function dj(e,t){zA(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),zA(e,HTMLInputElement)&&t.setAttribute(`value`,e.value)}function fj(e,t){if(zA(e,HTMLSelectElement)){let n=t,r=Array.from(n.children).find(t=>e.value===t.getAttribute(`value`));r&&r.setAttribute(`selected`,``)}}function pj(e,t,n){return zA(t,Element)&&(uj(e,t,n),WA(e,t,n),dj(e,t),fj(e,t)),t}async function mj(e,t){let n=e.querySelectorAll?e.querySelectorAll(`use`):[];if(n.length===0)return e;let r={};for(let i=0;i<n.length;i++){let a=n[i].getAttribute(`xlink:href`);if(a){let n=e.querySelector(a),i=document.querySelector(a);!n&&i&&!r[a]&&(r[a]=await hj(i,t,!0))}}let i=Object.values(r);if(i.length){let t=`http://www.w3.org/1999/xhtml`,n=document.createElementNS(t,`svg`);n.setAttribute(`xmlns`,t),n.style.position=`absolute`,n.style.width=`0`,n.style.height=`0`,n.style.overflow=`hidden`,n.style.display=`none`;let r=document.createElementNS(t,`defs`);n.appendChild(r);for(let e=0;e<i.length;e++)r.appendChild(i[e]);e.appendChild(n)}return e}async function hj(e,t,n){return!n&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(e=>oj(e,t)).then(n=>lj(e,n,t)).then(n=>pj(e,n,t)).then(e=>mj(e,t))}var gj=/url\((['"]?)([^'"]+?)\1\)/g,_j=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,vj=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function yj(e){let t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,`\\$1`);return RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,`g`)}function bj(e){let t=[];return e.replace(gj,(e,n,r)=>(t.push(r),e)),t.filter(e=>!ZA(e))}async function xj(e,t,n,r,i){try{let a=n?wA(t,n):t,o=YA(t),s;return s=i?QA(await i(a),o):await nj(a,o,r),e.replace(yj(t),`$1${s}$3`)}catch{}return e}function Sj(e,{preferredFontFormat:t}){return t?e.replace(vj,e=>{for(;;){let[n,,r]=_j.exec(e)||[];if(!r)return``;if(r===t)return`src: ${n};`}}):e}function Cj(e){return e.search(gj)!==-1}async function wj(e,t,n){if(!Cj(e))return e;let r=Sj(e,n);return bj(r).reduce((e,r)=>e.then(e=>xj(e,r,t,n)),Promise.resolve(r))}async function Tj(e,t,n){let r=t.style?.getPropertyValue(e);if(r){let i=await wj(r,null,n);return t.style.setProperty(e,i,t.style.getPropertyPriority(e)),!0}return!1}async function Ej(e,t){await Tj(`background`,e,t)||await Tj(`background-image`,e,t),await Tj(`mask`,e,t)||await Tj(`-webkit-mask`,e,t)||await Tj(`mask-image`,e,t)||await Tj(`-webkit-mask-image`,e,t)}async function Dj(e,t){let n=zA(e,HTMLImageElement);if((!n||ZA(e.src))&&(!zA(e,SVGImageElement)||ZA(e.href.baseVal)))return;let r=n?e.src:e.href.baseVal,i=await nj(r,YA(r),t);await new Promise((r,a)=>{e.onload=r,e.onerror=t.onImageErrorHandler?(...e)=>{try{r(t.onImageErrorHandler(...e))}catch(e){a(e)}}:a;let o=e;o.decode&&=r,o.loading===`lazy`&&(o.loading=`eager`),n?(e.srcset=``,e.src=i):e.href.baseVal=i})}async function Oj(e,t){let n=EA(e.childNodes).map(e=>kj(e,t));await Promise.all(n).then(()=>e)}async function kj(e,t){zA(e,Element)&&(await Ej(e,t),await Dj(e,t),await Oj(e,t))}function Aj(e,t){let{style:n}=e;t.backgroundColor&&(n.backgroundColor=t.backgroundColor),t.width&&(n.width=`${t.width}px`),t.height&&(n.height=`${t.height}px`);let r=t.style;return r!=null&&Object.keys(r).forEach(e=>{n[e]=r[e]}),e}var jj={};async function Mj(e){let t=jj[e];return t??(t={url:e,cssText:await(await fetch(e)).text()},jj[e]=t,t)}async function Nj(e,t){let n=e.cssText,r=/url\(["']?([^"')]+)["']?\)/g,i=(n.match(/url\([^)]+\)/g)||[]).map(async i=>{let a=i.replace(r,`$1`);return a.startsWith(`https://`)||(a=new URL(a,e.url).href),$A(a,t.fetchRequestInit,({result:e})=>(n=n.replace(i,`url(${e})`),[i,e]))});return Promise.all(i).then(()=>n)}function Pj(e){if(e==null)return[];let t=[],n=e.replace(/(\/\*[\s\S]*?\*\/)/gi,``),r=RegExp(`((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})`,`gi`);for(;;){let e=r.exec(n);if(e===null)break;t.push(e[0])}n=n.replace(r,``);let i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,a=RegExp(`((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})`,`gi`);for(;;){let e=i.exec(n);if(e===null){if(e=a.exec(n),e===null)break;i.lastIndex=a.lastIndex}else a.lastIndex=i.lastIndex;t.push(e[0])}return t}async function Fj(e,t){let n=[],r=[];return e.forEach(n=>{if(`cssRules`in n)try{EA(n.cssRules||[]).forEach((e,i)=>{if(e.type===CSSRule.IMPORT_RULE){let a=i+1,o=e.href,s=Mj(o).then(e=>Nj(e,t)).then(e=>Pj(e).forEach(e=>{try{n.insertRule(e,e.startsWith(`@import`)?a+=1:n.cssRules.length)}catch(t){console.error(`Error inserting rule from remote css`,{rule:e,error:t})}})).catch(e=>{console.error(`Error loading remote css`,e.toString())});r.push(s)}})}catch(i){let a=e.find(e=>e.href==null)||document.styleSheets[0];n.href!=null&&r.push(Mj(n.href).then(e=>Nj(e,t)).then(e=>Pj(e).forEach(e=>{a.insertRule(e,a.cssRules.length)})).catch(e=>{console.error(`Error loading remote stylesheet`,e)})),console.error(`Error inlining remote css file`,i)}}),Promise.all(r).then(()=>(e.forEach(e=>{if(`cssRules`in e)try{EA(e.cssRules||[]).forEach(e=>{n.push(e)})}catch(t){console.error(`Error while reading CSS rules from ${e.href}`,t)}}),n))}function Ij(e){return e.filter(e=>e.type===CSSRule.FONT_FACE_RULE).filter(e=>Cj(e.style.getPropertyValue(`src`)))}async function Lj(e,t){if(e.ownerDocument==null)throw Error(`Provided element is not within a Document`);return Ij(await Fj(EA(e.ownerDocument.styleSheets),t))}function Rj(e){return e.trim().replace(/["']/g,``)}function zj(e){let t=new Set;function n(e){(e.style.fontFamily||getComputedStyle(e).fontFamily).split(`,`).forEach(e=>{t.add(Rj(e))}),Array.from(e.children).forEach(e=>{e instanceof HTMLElement&&n(e)})}return n(e),t}async function Bj(e,t){let n=await Lj(e,t),r=zj(e);return(await Promise.all(n.filter(e=>r.has(Rj(e.style.fontFamily))).map(e=>{let n=e.parentStyleSheet?e.parentStyleSheet.href:null;return wj(e.cssText,n,t)}))).join(`
4460
+ `)}async function Vj(e,t){let n=t.fontEmbedCSS==null?t.skipFonts?null:await Bj(e,t):t.fontEmbedCSS;if(n){let t=document.createElement(`style`),r=document.createTextNode(n);t.appendChild(r),e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}}async function Hj(e,t={}){let{width:n,height:r}=MA(e,t),i=await hj(e,t,!0);return await Vj(i,t),await kj(i,t),Aj(i,t),await RA(i,n,r)}async function Uj(e,t={}){let{width:n,height:r}=MA(e,t),i=await IA(await Hj(e,t)),a=document.createElement(`canvas`),o=a.getContext(`2d`),s=t.pixelRatio||NA(),c=t.canvasWidth||n,l=t.canvasHeight||r;return a.width=c*s,a.height=l*s,t.skipAutoScale||FA(a),a.style.width=`${c}`,a.style.height=`${l}`,t.backgroundColor&&(o.fillStyle=t.backgroundColor,o.fillRect(0,0,a.width,a.height)),o.drawImage(i,0,0,a.width,a.height),a}var Wj=1600,Gj=.85;function Kj(e,t){let n=Math.min(1,Wj/Math.max(e,t,1));return{width:Math.max(1,Math.round(e*n)),height:Math.max(1,Math.round(t*n))}}async function qj(){let e=document.documentElement.getBoundingClientRect(),t=await Uj(document.body,{width:Math.round(e.width),height:Math.round(e.height),pixelRatio:1,backgroundColor:`#050b10`,filter:e=>!(e instanceof HTMLElement&&e.dataset.noCapture!==void 0)}),n=Kj(t.width,t.height),r=document.createElement(`canvas`);return r.width=n.width,r.height=n.height,r.getContext(`2d`).drawImage(t,0,0,n.width,n.height),new Promise((e,t)=>r.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,Gj))}var Jj=class{opts;active=null;constructor(e){this.opts=e}async handle(e){if(e.type===`screen.cancel`){this.active&&this.active.id===e.id&&(this.active.cancelled=!0);return}if(this.active)return this.opts.send({type:`screen.denied`,id:e.id,reason:`busy`});let t={id:e.id,cancelled:!1};this.active=t;try{let n=await(this.opts.capture??qj)();if(t.cancelled)return;try{await this.opts.upload(e.id,n)}catch{this.opts.dispatch({type:`alert.add`,level:`warn`,text:`Could not send the picture of the screen to Friend.`})}}catch(n){t.cancelled||this.opts.send({type:`screen.denied`,id:e.id,reason:Yj(n)})}finally{this.active===t&&(this.active=null)}}dispose(){this.active&&(this.active.cancelled=!0)}};function Yj(e){return e?.name===`NotSupportedError`?`unsupported`:`failed`}var Xj=12,Zj=e=>e.length>200?`${e.slice(0,199)}…`:e,Qj=.2,$j=4,eM=(e,t)=>{let n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x),r=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n<=0||r<=0?0:n*r/Math.max(1,Math.min(e.w*e.h,t.w*t.h))};function tM(e){if(e.objects.length===0)return[`No objects are on the screen.`];let t=[],n=e=>Math.round(e);for(let r of e.objects){r.drawn||t.push(`${r.id}: nothing is drawn in it (an empty box). Hide it, or check its props.`),(r.scrollH-r.h>$j||r.scrollW-r.w>$j)&&t.push(`${r.id}: its content is cut off: it needs about ${n(Math.max(r.scrollW,r.w))}x${n(Math.max(r.scrollH,r.h))} px and the box is ${n(r.w)}x${n(r.h)} px. Make the box bigger or the content smaller.`);let i=Math.max(0,-r.x,-r.y,r.x+r.w-e.view.w,r.y+r.h-e.view.h);i>$j&&t.push(`${r.id}: ${n(i)} px of it is outside the screen. Move it inside.`)}for(let n=0;n<e.objects.length;n++){for(let r=n+1;r<e.objects.length;r++)eM(e.objects[n],e.objects[r])>Qj&&t.push(`${e.objects[n].id} and ${e.objects[r].id} overlap. Move one of them.`);for(let r of e.hud)eM(e.objects[n],r)>Qj&&t.push(`${e.objects[n].id} covers the ${r.id} instrument. Move it to a free place.`)}if(t.length===0)return[`All ${e.objects.length} objects are fully visible, nothing overlaps.`];let r=t.map(Zj);return r.length>Xj?[...r.slice(0,11),`…and ${r.length-11} more problems of the same kind.`]:r}function nM(e,t){let n=e=>{let t=e.getBoundingClientRect();return{x:t.x,y:t.y,w:t.width,h:t.height}},r=[...e.querySelectorAll(`[data-object]`)].filter(e=>!e.classList.contains(`leaving`)).map(e=>({id:e.dataset.object??`?`,...n(e),scrollW:e.scrollWidth,scrollH:e.scrollHeight,drawn:(!e.querySelector(`.obj-jarvis, .obj-empty`)||!e.querySelector(`.obj-empty`))&&((e.textContent??``).replace(/[×📌\s]/g,``).length>0||!!e.querySelector(`svg, canvas, img, video, iframe`))})),i=[...e.querySelectorAll(`.orbital [data-widget]`)].map(e=>({id:e.dataset.widget??`?`,...n(e)}));return{view:{w:t.innerWidth,h:t.innerHeight},objects:r,hud:i}}function rM(e,t){let n=(0,y.useRef)(t);n.current=t;let r=(0,y.useRef)(!1),i=(0,y.useRef)(null);(0,y.useEffect)(()=>{let t=e===`listening`||e===`speaking`;i.current&&clearTimeout(i.current),i.current=null,t?r.current||(r.current=!0,n.current({type:`audio.activity`,active:!0})):r.current&&(i.current=setTimeout(()=>{i.current=null,r.current=!1,n.current({type:`audio.activity`,active:!1})},900))},[e]),(0,y.useEffect)(()=>()=>{i.current&&clearTimeout(i.current),r.current&&(r.current=!1,n.current({type:`audio.activity`,active:!1}))},[])}var iM={401:`Please sign in again.`,413:`That recording was too long.`,409:`Friend is busy with the last request. Try again in a moment.`,429:`You're talking too fast. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function aM(e,t,n){let r;try{r=await fetch(e,{method:`POST`,headers:{"content-type":t.type||`audio/webm`},body:t,signal:n})}catch(e){throw e.name===`AbortError`?e:Error(`Could not reach Friend. Check the connection.`)}if(!r.ok){let e=``;try{e=(await r.json()).error??``}catch{}throw Error(e||iM[r.status]||`The voice request failed (${r.status}).`)}let i=await r.json();return{text:typeof i.text==`string`?i.text:``,wake:i.wake===!0}}async function oM(e,t){return{text:(await aM(`/api/voice/utterance`,e,t)).text}}async function sM(e,t){let n=await aM(`/api/voice/utterance?wake=1`,e,t);return{text:n.text,wake:n.wake===!0}}var cM=null;function lM(){try{cM??=new AudioContext,cM.resume().catch(()=>{});let e=cM.currentTime;for(let[t,n]of[660,990].entries()){let r=cM.createOscillator(),i=cM.createGain();r.frequency.value=n,i.gain.setValueAtTime(0,e+t*.11),i.gain.linearRampToValueAtTime(.18,e+t*.11+.02),i.gain.exponentialRampToValueAtTime(.001,e+t*.11+.14),r.connect(i).connect(cM.destination),r.start(e+t*.11),r.stop(e+t*.11+.16)}}catch{}}var uM=/busy with the last request|talking too fast/i,dM=3e4,fM=50,pM=class{deps;listener=null;awakeNow=!1;showing=!1;busyWithOne=!1;clock=null;meter=null;abort=null;lastAlert=0;constructor(e){this.deps=e}get enabled(){return this.listener!==null}get awake(){return this.awakeNow}async enable(){if(this.listener)return;let e=this.deps.makeListener({onUtterance:e=>void this.heard(e),onError:e=>{this.drop(),this.alert(e,!0)}});try{await e.start()}catch(e){this.alert(e.message,!0);return}this.listener=e}disable(){this.drop()}sync(){let e=this.listener;if(!e)return;let t=this.busyOther();if(e.pause(t),!this.awakeNow||t){this.clearClock(),this.stopMeter();return}this.deps.mode()===`idle`&&this.show(),this.clock||this.startClock(),this.startMeter()}busyOther(){let e=this.deps.mode();return e!==`listening`&&(this.showing=!1),e===`speaking`||e===`transcribing`||e===`listening`&&!this.showing}show(){this.showing=!0,this.deps.dispatch({type:`voice.mode`,mode:`listening`})}wakeUp(e){this.awakeNow=!0,e&&this.deps.chime(),this.clearClock(),this.show(),this.startClock(),this.startMeter()}sleep(){this.awakeNow=!1,this.clearClock(),this.stopMeter(),this.showing&&this.deps.dispatch({type:`voice.mode`,mode:`idle`}),this.showing=!1}drop(){let e=this.listener;this.listener=null,this.abort?.abort(),this.abort=null,this.busyWithOne=!1,this.sleep(),e?.stop()}startClock(){this.clearClock(),this.clock=setTimeout(()=>{this.clock=null,this.sleep()},this.deps.awakeMs??3e4)}clearClock(){this.clock&&clearTimeout(this.clock),this.clock=null}startMeter(){this.meter||=setInterval(()=>this.deps.dispatch({type:`voice.level`,level:this.listener?.level()??0}),fM)}stopMeter(){this.meter&&clearInterval(this.meter),this.meter=null}async heard(e){if(!this.listener||this.busyWithOne||this.busyOther())return;this.busyWithOne=!0;let t=new AbortController;this.abort=t;try{this.awakeNow?await this.request(e,t.signal):await this.check(e,t.signal)}catch(e){e.name!==`AbortError`&&!uM.test(e.message)&&this.alert(e.message,!1)}finally{this.abort===t&&(this.abort=null),this.busyWithOne=!1,this.listener&&this.awakeNow&&(this.clearClock(),this.deps.mode()===`transcribing`&&this.deps.dispatch({type:`voice.mode`,mode:`idle`}),this.sync())}}async check(e,t){let n=await this.deps.wake(e,t);this.listener&&n.wake&&this.wakeUp(!n.text)}async request(e,t){this.clearClock(),this.stopMeter(),this.showing=!1,this.deps.dispatch({type:`voice.mode`,mode:`transcribing`}),await this.deps.command(e,t)}alert(e,t){let n=Date.now();!t&&n-this.lastAlert<dM||(this.lastAlert=n,this.deps.dispatch({type:`alert.add`,level:`error`,text:e}))}},mM=0,hM=new Set;function gM(e){return hM.add(e),()=>hM.delete(e)}var _M=e=>hM.forEach(t=>{try{t(e)}catch{}}),vM=e=>/not compatible|audio capture|audiosession/i.test(String(e?.message??e));function yM(e){try{let t=navigator.audioSession;t&&t.type!==e&&(t.type=e)}catch{}}function bM(){mM===0&&yM(`playback`)}function xM(){mM++,mM===1&&_M(!0),yM(`play-and-record`);let e=!1;return()=>{e||(e=!0,mM=Math.max(0,mM-1),mM===0&&(yM(`playback`),_M(!1)))}}var SM=3,CM=.02,wM=.04,TM=class{minSpeechMs;endSilenceMs;maxMs;floor=null;loudSince=null;speaking=!1;startedAt=0;lastLoud=0;lastFeed=0;speechMs=0;constructor(e={}){this.minSpeechMs=e.minSpeechMs??300,this.endSilenceMs=e.endSilenceMs??800,this.maxMs=e.maxMs??8e3}get inSpeech(){return this.speaking}get maybeSpeech(){return this.loudSince!==null}feed(e,t){this.floor===null&&(this.floor=e);let n=e>Math.max(this.floor*SM+CM,wM),r=Math.min(100,Math.max(0,t-this.lastFeed));if(this.lastFeed=t,!this.speaking)return n?(this.loudSince??=t,t-this.loudSince<this.minSpeechMs?null:(this.speaking=!0,this.startedAt=this.loudSince,this.lastLoud=t,this.speechMs=t-this.loudSince,{type:`start`})):(this.loudSince=null,this.floor+=(e-this.floor)*(e<this.floor?.3:.02),null);n&&(this.lastLoud=t,this.speechMs+=r);let i=t-this.startedAt>=this.maxMs;if(!i&&t-this.lastLoud<this.endSilenceMs)return null;let a={type:`end`,ms:t-this.startedAt,speechMs:this.speechMs,forced:i};return this.speaking=!1,this.loudSince=null,i&&n&&(this.floor=e),a}reset(){this.speaking=!1,this.loudSince=null}},EM=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`],DM=50,OM=2e3,kM=2e3,AM=400,jM=e=>{let t=e?.name;return t===`NotAllowedError`||t===`SecurityError`?`Microphone permission was denied. Allow it in the browser to use hands-free.`:t===`NotFoundError`||t===`OverconstrainedError`?`No microphone was found.`:e?.message||`Could not open the microphone.`},MM=class{opts;stream=null;ctx=null;analyser=null;rec=null;chunks=[];recStartedAt=0;timer=null;seg;leaveSession=null;paused=!1;starting=!1;finishing=!1;opened=!1;now;constructor(e){this.opts=e,this.seg=new TM(e),this.now=e.now??(()=>Date.now())}static supported(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`}get listening(){return this.opened}async start(){if(!(this.opened||this.starting)){this.starting=!0;try{this.leaveSession=xM();try{this.stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})}catch(e){throw this.leaveSession?.(),this.leaveSession=null,Error(jM(e))}for(let e of this.stream.getTracks())e.onended=()=>this.broke(`The microphone stopped working.`);try{this.ctx=new AudioContext,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.ctx.createMediaStreamSource(this.stream).connect(this.analyser),this.ctx.resume().catch(()=>{})}catch{throw this.release(),Error(`This browser cannot listen continuously here.`)}this.seg.reset(),this.beginRecording(),this.opened=!0,this.timer=setInterval(()=>this.tick(),DM)}finally{this.starting=!1}}}stop(){this.opened=!1,this.release()}pause(e){this.paused!==e&&(this.paused=e,this.seg.reset(),!e&&this.opened&&this.restartRecording())}level(){if(!this.analyser)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}tick(){if(!this.opened)return;let e=this.now();if(this.ctx&&this.ctx.state!==`running`&&this.ctx.resume().catch(()=>{}),this.paused){e-this.recStartedAt>=OM&&this.restartRecording();return}let t=this.seg.feed(this.level(),e);t?.type===`end`?this.finish(t.ms,t.speechMs):!t&&!this.seg.inSpeech&&!this.seg.maybeSpeech&&e-this.recStartedAt>=OM&&this.restartRecording()}beginRecording(){if(!this.stream)return;let e=EM.find(e=>MediaRecorder.isTypeSupported(e));this.chunks=[];let t=new MediaRecorder(this.stream,e?{mimeType:e}:void 0);t.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=()=>this.broke(`The microphone stopped working.`),t.start(250),this.rec=t,this.recStartedAt=this.now()}restartRecording(){let e=this.rec;if(this.rec=null,e){e.ondataavailable=null,e.onstop=null,e.onerror=null;try{e.state!==`inactive`&&e.stop()}catch{}}this.opened&&this.beginRecording()}async finish(e,t){let n=this.rec;if(!n||this.finishing)return;this.finishing=!0;let r=n.mimeType||`audio/webm`,i=await new Promise(e=>{let t=!1,i=()=>{t||(t=!0,e(new Blob(this.chunks,{type:r})))},a=setTimeout(i,kM);n.onstop=()=>{clearTimeout(a),i()};try{n.state===`inactive`?i():n.stop()}catch{i()}});this.finishing=!1,this.rec=null,this.opened&&(this.beginRecording(),!this.paused&&e>=AM&&t>=AM/2&&i.size>0&&this.opts.onUtterance(i))}broke(e){this.opened&&(this.stop(),this.opts.onError(e))}release(){if(this.timer&&clearInterval(this.timer),this.timer=null,this.rec){this.rec.ondataavailable=null,this.rec.onstop=null,this.rec.onerror=null;try{this.rec.state!==`inactive`&&this.rec.stop()}catch{}}this.stream?.getTracks().forEach(e=>{e.onended=null,e.stop()}),this.ctx?.close().catch(()=>{}),this.stream=null,this.ctx=null,this.analyser=null,this.rec=null,this.chunks=[],this.leaveSession?.(),this.leaveSession=null}},NM=4096,PM=8,FM=20,IM=6e6;function LM(e){try{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}catch{return null}}var RM=class{ctx=null;analyser=null;pending=new Map;queue=[];current=null;busy=!1;gen=0;isPlaying=!1;unwatch=null;listeners=new Set;unlock(){bM();let e=this.ensureContext();e.state!==`running`&&e.resume().catch(()=>{})}locked(){return!this.ctx||this.ctx.state!==`running`}enqueue(e){if(!Number.isInteger(e.seq)||e.seq<0||e.seq>NM)return;let t=LM(e.data);if(!t)return;let n=this.pending.get(e.id);if(n||(this.pending.size>=PM&&this.pending.delete(this.pending.keys().next().value),n={parts:new Map,lastSeq:null,bytes:0},this.pending.set(e.id,n)),n.bytes+=t.length,n.bytes>IM){this.pending.delete(e.id);return}if(n.parts.set(e.seq,t),e.last&&(n.lastSeq=e.seq),n.lastSeq===null||n.parts.size!==n.lastSeq+1)return;this.pending.delete(e.id);let r=new Uint8Array([...n.parts.values()].reduce((e,t)=>e+t.length,0)),i=0;for(let e=0;e<=n.lastSeq;e++){let t=n.parts.get(e);if(!t)return;r.set(t,i),i+=t.length}for(this.queue.push(r.buffer);this.queue.length>FM;)this.queue.shift();this.pump()}stop(){this.gen++,this.queue=[],this.pending.clear(),this.busy=!1;let e=this.current;if(this.current=null,e){e.onended=null;try{e.stop()}catch{}}this.setPlaying(!1)}dispose(){this.stop(),this.ctx?.close().catch(()=>{}),this.unwatch?.(),this.unwatch=null,this.ctx=null,this.analyser=null}playing(){return this.isPlaying}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}level(){if(!this.analyser||!this.isPlaying)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}ensureContext(){if(!this.ctx){let e=window.AudioContext??window.webkitAudioContext;this.ctx=new e,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.analyser.connect(this.ctx.destination);let t=this.ctx;this.unwatch?.(),this.unwatch=gM(e=>{e&&t.state===`running`?t.suspend().catch(()=>{}):!e&&t.state!==`running`&&t.state!==`closed`&&t.resume().catch(()=>{})})}return this.ctx}setPlaying(e){this.isPlaying!==e&&(this.isPlaying=e,this.listeners.forEach(t=>t(e)))}async pump(){if(this.busy)return;let e=this.queue.shift();if(!e){this.setPlaying(!1);return}this.busy=!0;let t=this.gen;try{let n=this.ensureContext();if(n.state!==`running`){try{await n.resume()}catch{}if(t!==this.gen)return;if(n.state!==`running`){this.queue.unshift(e),this.busy=!1;return}}let r=await n.decodeAudioData(e);if(t!==this.gen)return;let i=n.createBufferSource();i.buffer=r,i.connect(this.analyser),i.onended=()=>{this.current===i&&(this.current=null,this.busy=!1,this.pump())},this.current=i,this.setPlaying(!0),i.start()}catch{if(t!==this.gen)return;this.busy=!1,this.pump()}}},zM=e=>new Promise(t=>setTimeout(t,e)),BM=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`],VM=3e3;function HM(e){let t=e;return t?.name===`NotAllowedError`||t?.name===`SecurityError`?Error(`Microphone permission was denied. Allow it in the browser to talk.`):t?.name===`NotFoundError`||t?.name===`OverconstrainedError`?Error(`No microphone was found.`):Error(t?.message||`Could not open the microphone.`)}var UM=class e{opts;stream=null;rec=null;chunks=[];ctx=null;analyser=null;timer=null;starting=!1;leaveSession=null;constructor(e={}){this.opts=e}static supported(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`}get active(){return this.rec!==null}async start(){if(!(this.rec||this.starting)){if(!e.supported())throw Error(`This browser cannot record audio here (use localhost or HTTPS).`);this.starting=!0;try{this.leaveSession=xM();try{let e=()=>navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});try{this.stream=await e()}catch(t){if(!vM(t))throw t;await zM(250),this.leaveSession?.(),this.leaveSession=xM(),this.stream=await e()}}catch(e){throw this.leaveSession?.(),this.leaveSession=null,HM(e)}try{let e=BM.find(e=>MediaRecorder.isTypeSupported(e));this.chunks=[];let t=new MediaRecorder(this.stream,e?{mimeType:e}:void 0);t.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=()=>this.failed();for(let e of this.stream.getTracks())e.onended=()=>this.failed();this.openMeter(this.stream),t.start(250),this.rec=t,this.opts.maxMs&&(this.timer=setTimeout(()=>{this.timer=null,this.opts.onLimit?.()},this.opts.maxMs))}catch(e){throw this.release(),HM(e)}}finally{this.starting=!1}}}stop(){let e=this.rec;return e?new Promise(t=>{let n=!1,r=null,i=()=>{if(n)return;n=!0,r&&clearTimeout(r);let i=new Blob(this.chunks,{type:e.mimeType||`audio/webm`});this.release(),t(i)};if(r=setTimeout(i,VM),e.onstop=i,e.state===`inactive`)return i();try{e.stop()}catch{i()}}):Promise.reject(Error(`Not recording.`))}cancel(){let e=this.rec;if(e){e.ondataavailable=null,e.onstop=null,e.onerror=null;try{e.state!==`inactive`&&e.stop()}catch{}}this.release()}level(){if(!this.analyser||!this.rec)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}failed(){this.rec&&(this.cancel(),this.opts.onError?.())}openMeter(e){try{this.ctx=new AudioContext,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.ctx.createMediaStreamSource(e).connect(this.analyser)}catch{this.analyser=null}}release(){this.timer&&clearTimeout(this.timer),this.timer=null,this.stream?.getTracks().forEach(e=>{e.onended=null,e.stop()}),this.ctx?.close().catch(()=>{}),this.stream=null,this.rec=null,this.ctx=null,this.analyser=null,this.chunks=[],this.leaveSession?.(),this.leaveSession=null}},WM=2e3,GM=()=>typeof window<`u`&&window.isSecureContext===!1,KM=50,qM=class{deps;recorder;player;mode=`idle`;pressed=!1;disposed=!1;uploads=0;toldAboutSound=!1;quiet=!1;abort=null;poll=null;unsubscribe;constructor(e){this.deps=e;let t=()=>this.recorderFailed();this.recorder=e.recorder??e.makeRecorder?.(t)??new UM({maxMs:6e4,onLimit:()=>void this.pressEnd(),onError:t}),this.player=e.player??new RM,this.unsubscribe=this.player.onChange(e=>{this.mode!==`listening`&&this.mode!==`transcribing`&&this.setMode(e?`speaking`:`idle`)})}async pressStart(){if(!(this.pressed||this.disposed)){if(!this.deps.available()){this.alert(`warn`,`Voice is not available. Run: friend voice setup`);return}if(!(this.deps.supported?.()??UM.supported())){this.alert(`warn`,GM()?`This page is not secure, so the browser blocks the microphone. On the PC run: friend lan https on, restart Friend, and open the https:// address.`:`This browser cannot record audio here (use localhost or HTTPS).`);return}this.pressed=!0,this.player.unlock(),this.player.playing()&&(this.deps.send({type:`voice.interrupt`}),this.player.stop());try{await this.recorder.start()}catch(e){this.pressed=!1,this.alert(`error`,e.message),this.setMode(`idle`);return}if(!this.pressed){this.recorder.cancel(),this.setMode(`idle`);return}this.setMode(`listening`)}}async pressEnd(){if(!this.pressed||(this.pressed=!1,!this.recorder.active))return;let e=await this.recorder.stop();if(e.size<WM){this.alert(`info`,`Hold the key a little longer while you speak.`),this.setMode(`idle`);return}this.setMode(`transcribing`);let t=new AbortController;this.abort=t,this.uploads++;try{let{text:n}=await this.deps.post(e,t.signal);n.trim()||this.alert(`info`,`I didn't catch that.`)}catch(e){e.name!==`AbortError`&&this.alert(`error`,e.message)}finally{this.uploads--,this.abort===t&&(this.abort=null),this.settle()}}blur(){this.pressed&&(this.pressed=!1,this.recorder.cancel(),this.setMode(`idle`))}setQuiet(e){this.quiet=e,e&&this.player.stop()}handleServer(e){if(e.type!==`audio.chunk`)return this.player.stop();this.quiet||(this.player.enqueue(e),!this.toldAboutSound&&this.player.locked?.()&&(this.toldAboutSound=!0,this.deps.dispatch({type:`alert.add`,level:`info`,text:`Sound is blocked by the browser. Click or press a key once anywhere on the page to hear me.`})))}unlock(){this.player.unlock()}dispose(){this.disposed=!0,this.pressed=!1,this.stopPolling(),this.abort?.abort(),this.recorder.cancel(),this.player.stop(),this.player.dispose?.(),this.unsubscribe()}recorderFailed(){this.pressed=!1,this.recorder.cancel(),this.alert(`error`,`The microphone stopped working.`),this.setMode(`idle`)}settle(){this.uploads>0||this.mode!==`transcribing`||this.setMode(this.player.playing()?`speaking`:`idle`)}setMode(e){this.disposed||(this.mode=e,this.deps.dispatch({type:`voice.mode`,mode:e}),e===`listening`||e===`speaking`?this.startPolling():this.stopPolling())}startPolling(){this.stopPolling(),this.poll=setInterval(()=>{let e=this.mode===`listening`?this.recorder.level():this.player.level();this.deps.dispatch({type:`voice.level`,level:e})},KM)}stopPolling(){this.poll&&clearInterval(this.poll),this.poll=null}alert(e,t){this.disposed||this.deps.dispatch({type:`alert.add`,level:e,text:t})}};function JM(e){let[t,n]=(0,y.useReducer)(Zk,Gk),r=(0,y.useRef)(null),i=(0,y.useRef)(null),a=(0,y.useRef)(!1),o=(0,y.useRef)(null),s=(0,y.useRef)(null),[c,l]=(0,y.useState)(!1),u=(0,y.useRef)(e);u.current=e;let d=(0,y.useRef)(t);d.current=t,(0,y.useEffect)(()=>{let e=Wk();r.current=e;let t=new qM({send:t=>e.send(t),dispatch:e=>n(e),post:oM,available:()=>d.current.voice.available});i.current=t,t.setQuiet(a.current);let c=new pM({makeListener:e=>new MM(e),wake:sM,command:oM,mode:()=>d.current.voice.mode,chime:lM,dispatch:e=>n(e)});s.current=c;let f=CA(),p=new oA({send:t=>e.send(t),dispatch:e=>n(e),enabled:()=>d.current.camera.enabled,upload:async(e,t)=>{let n=await fetch(`/api/camera/frame/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`image/jpeg`},body:t});if(!n.ok)throw Error(`upload failed (${n.status})`)},faces:e=>f.find(e),faceProblem:()=>f.failed,sendFaces:async(e,t)=>{await fetch(`/api/camera/faces/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({faces:t})})}});o.current=p;let m=new Jj({send:t=>e.send(t),dispatch:e=>n(e),upload:async(e,t)=>{let n=await fetch(`/api/screen/frame/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`image/jpeg`},body:t});if(!n.ok)throw Error(`upload failed (${n.status})`)}}),h=e.onMessage(r=>{n(r);let i=r?.type,a=r?.id;if((i===`camera.request`||i===`camera.cancel`)&&typeof a==`string`){let{frames:e,seconds:t,recognise:n}=r;p.handle({type:i,id:a,...typeof e==`number`?{frames:e}:{},...typeof t==`number`?{seconds:t}:{},...n===!0?{recognise:!0}:{}})}(i===`screen.request`||i===`screen.cancel`)&&typeof a==`string`&&m.handle({type:i,id:a}),i===`screen.check`&&typeof a==`string`&&setTimeout(()=>e.send({type:`screen.checked`,id:a,lines:tM(nM(document,window))}),500),i===`audio.duck`&&EO.set(r.level??1),(i===`audio.chunk`||i===`audio.stop`)&&t.handleServer(r)}),g=e.onState(e=>{n({type:`conn`,value:e}),e!==`open`&&EO.set(1,0),e===`unauthorized`&&u.current(),e===`elsewhere`&&(c.disable(),l(!1),t.blur(),p.dispose(),m.dispose())});return()=>{h(),g(),c.disable(),s.current=null,t.dispose(),p.dispose(),m.dispose(),e.close(),i.current=null,o.current=null,r.current=null}},[]),(0,y.useEffect)(()=>{t.camera.enabled||o.current?.dispose()},[t.camera.enabled]),(0,y.useEffect)(()=>{s.current?.sync()},[t.voice.mode]);let f=(0,y.useCallback)(async e=>{let t=s.current;if(t){e?await t.enable():t.disable(),l(t.enabled);try{localStorage.setItem(`friend.handsFree`,t.enabled?`1`:`0`)}catch{}}},[]),p=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!p.current&&t.voice.available){p.current=!0;try{localStorage.getItem(`friend.handsFree`)===`1`&&MM.supported()&&f(!0)}catch{}}},[t.voice.available,f]);let m=(0,y.useMemo)(()=>({on:c,supported:MM.supported(),toggle:()=>void f(!s.current?.enabled)}),[c,f]),h=(0,y.useCallback)(e=>r.current?.send(e),[]);return rM(t.voice.mode,h),{state:t,send:h,dispatch:(0,y.useCallback)(e=>n(e),[]),voice:(0,y.useMemo)(()=>({pressStart:()=>void i.current?.pressStart(),pressEnd:()=>void i.current?.pressEnd(),blur:()=>i.current?.blur(),unlock:()=>i.current?.unlock(),setQuiet:e=>{a.current=e,i.current?.setQuiet(e)}}),[]),handsFree:m,useHere:(0,y.useCallback)(()=>r.current?.takeOver(),[]),officeStop:(0,y.useCallback)(e=>h({type:`office.stop`,...e?{workerId:e}:{}}),[h]),officeSay:(0,y.useCallback)((e,t)=>h({type:`office.say`,workerId:e,text:t}),[h])}}var YM={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function XM(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||YM[n.status]||`The request failed (${n.status}).`)}return await n.json()}var ZM=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),QM={state:()=>XM(`/api/voice/enroll`,{}),sample:e=>XM(`/api/voice/enroll/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>XM(`/api/voice/enroll/finish`,ZM(`POST`,{pin:e})),cancel:async()=>{await XM(`/api/voice/enroll/cancel`,ZM(`POST`,{}))},remove:async e=>{await XM(`/api/voice/enroll`,ZM(`DELETE`,{pin:e}))}},$M=[`Friend, good evening. It is a pleasant day to get things done.`,`Open my projects and show me what changed today.`,`My voice is my key, so please remember it well.`,`Check the weather and read me the latest headlines.`,`Always protect the boss, and never trust a stranger.`],eN=15e3;function tN({api:e=QM,createRecorder:t=e=>new UM(e),onClose:n,who:r}){let[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(0),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(`record`),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),S=(0,y.useRef)(!0),C=(0,y.useRef)(null);(0,y.useEffect)(()=>(S.current=!0,e.state().then(e=>{S.current&&(a(e),s(e.samples))}).catch(e=>S.current&&_(e.message)),()=>{S.current=!1,C.current?.cancel(),C.current=null}),[e]);let T=(0,y.useCallback)(async()=>{let t=C.current;if(t){C.current=null,p(!1),h(!0);try{let n=await t.stop(),r=await e.sample(n);if(!S.current)return;s(r.count),l(r.note)}catch(e){S.current&&_(e.message)}finally{S.current&&h(!1)}}},[e]),E=async()=>{_(null),l(null);let e=t({maxMs:eN,onLimit:()=>void T(),onError:()=>{C.current=null,S.current&&(p(!1),_(`The microphone stopped working. Try again.`))}});try{await e.start()}catch(e){S.current&&_(e.message);return}if(!S.current)return e.cancel();C.current=e,p(!0)},D=async e=>{_(null),h(!0);try{await e()}catch(e){S.current&&_(e.message)}finally{S.current&&(h(!1),b(``))}},O=async()=>{C.current?.cancel(),C.current=null,await e.cancel().catch(()=>{}),n()},k=i?.min??3,A=o%$M.length,j=o<$M.length?`Phrase ${o+1} of ${$M.length}`:`Extra recording (${o} so far)`;return(0,w.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Voice enrollment`,style:{pointerEvents:`auto`},children:[(0,w.jsx)(`div`,{className:`approval-head`,children:(0,w.jsx)(`span`,{className:`approval-title`,children:r?`Teach Friend ${r}'s voice`:`Teach Friend your voice`})}),u===`record`&&(0,w.jsxs)(w.Fragment,{children:[!r&&i?.enrolled&&(0,w.jsx)(`p`,{className:`auth-note`,children:`Your voice is already saved. Saving a new one replaces it.`}),r&&(0,w.jsxs)(`p`,{className:`auth-note`,children:[`Hand the device to `,r,`. `,r,` reads each sentence aloud, close to the microphone, in a quiet room.`]}),(0,w.jsxs)(`p`,{className:`auth-note`,children:[j,`. Press Record, read this aloud in a quiet room, then press Stop.`]}),(0,w.jsx)(`pre`,{className:`approval-summary`,"data-testid":`enroll-phrase`,style:{whiteSpace:`pre-wrap`},children:$M[A]}),(0,w.jsxs)(`div`,{role:`status`,className:`auth-note`,children:[o,` recorded`,o>=k?` — enough to save`:` — at least ${k} needed`,`.`,c?` ${c}`:``]}),g&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[f?(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,onClick:()=>void T(),children:`Stop`}):(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:m||!i||o>=(i?.max??8),onClick:()=>void E(),children:m?`Uploading…`:`Record`}),(0,w.jsx)(`button`,{type:`button`,style:x,disabled:f||m||o<k,onClick:()=>d(`pin-save`),children:r?`Save ${r}'s voice`:`Save my voice`}),!r&&i?.enrolled&&(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,disabled:f||m,onClick:()=>d(`pin-delete`),children:`Delete my voice`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>void O(),children:`Cancel`})]})]}),(u===`pin-save`||u===`pin-delete`)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:u===`pin-save`?r?`Enter your PIN to save ${r}'s voice.`:`Enter your PIN to save your voice.`:`Enter your PIN to delete your saved voice.`}),(0,w.jsx)(F,{pin:v,onChange:b,onSubmit:u===`pin-save`?()=>!m&&void D(async()=>{await e.finish(v),S.current&&d(`saved`)}):void 0}),g&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[u===`pin-save`?(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:m||v.length<6,onClick:()=>void D(async()=>{await e.finish(v),S.current&&d(`saved`)}),children:`Save`}):(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,disabled:m||v.length<6,onClick:()=>void D(async()=>{await e.remove(v),S.current&&d(`deleted`)}),children:`Delete`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{b(``),_(null),d(`record`)},children:`Back`})]})]}),(u===`saved`||u===`deleted`)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:u===`saved`?r?`${r}'s voice is saved. From now on I will know when ${r} is talking.`:`Your voice is saved. From now on I will tell you apart from other speakers.`:`Your voice was deleted. Every voice is treated as yours until you enroll again.`}),(0,w.jsx)(`div`,{className:`approval-actions`,children:(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,onClick:n,children:`Done`})})]})]})}var nN=new Set([`INPUT`,`TEXTAREA`,`SELECT`,`BUTTON`,`A`,`SUMMARY`]),rN=new Set([`button`,`checkbox`,`switch`,`tab`,`menuitem`,`link`,`radio`,`option`,`textbox`,`combobox`,`slider`]),iN=e=>e instanceof HTMLInputElement&&e.hasAttribute(`data-space-talks`)&&e.value===``,aN=e=>!iN(e)&&e instanceof HTMLElement&&(nN.has(e.tagName)||e.isContentEditable||rN.has(e.getAttribute(`role`)??``)),oN=e=>e.code===`Space`||e.key===` `;function sN(e){let t=(0,y.useRef)(e);t.current=e,(0,y.useEffect)(()=>{let e=!1,n=n=>{!oN(n)||n.ctrlKey||n.metaKey||n.altKey||aN(n.target)||aN(document.activeElement)||(n.preventDefault(),!(n.repeat||e)&&(e=!0,t.current.pressStart()))},r=n=>{oN(n)&&e&&(e=!1,n.preventDefault(),t.current.pressEnd())},i=()=>{e=!1,t.current.blur()},a=()=>{document.hidden&&i()},o=e=>{if(e.detail===0||!(e.target instanceof Element))return;let t=e.target.closest(`button, [role=button], summary, a`);t instanceof HTMLElement&&setTimeout(()=>{document.activeElement===t&&t.blur()},0)};return document.addEventListener(`click`,o),window.addEventListener(`keydown`,n),window.addEventListener(`keyup`,r),window.addEventListener(`blur`,i),document.addEventListener(`visibilitychange`,a),()=>{document.removeEventListener(`click`,o),window.removeEventListener(`keydown`,n),window.removeEventListener(`keyup`,r),window.removeEventListener(`blur`,i),document.removeEventListener(`visibilitychange`,a)}},[])}function cN(e){let t=(0,y.useRef)(e);t.current=e,(0,y.useEffect)(()=>{let e=()=>t.current.unlock(),n=[`pointerdown`,`keydown`,`touchend`];for(let t of n)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of n)window.removeEventListener(t,e)}},[])}function lN({onUseHere:e}){return(0,w.jsx)(`div`,{className:`elsewhere`,role:`alertdialog`,"aria-labelledby":`elsewhere-title`,"data-testid":`elsewhere`,children:(0,w.jsxs)(`div`,{className:`elsewhere-card`,children:[(0,w.jsx)(`h2`,{id:`elsewhere-title`,children:`Friend is open in another window`}),(0,w.jsx)(`p`,{children:`Friend works in one window at a time. Click “Use here” to use it in this window instead; the other one will stop.`}),(0,w.jsx)(`button`,{type:`button`,className:`elsewhere-btn`,onClick:e,autoFocus:!0,children:`Use here`})]})})}function uN(e,t,n){let r=Math.max(100,Math.round(e)),i=Math.max(100,Math.round(t));return{width:r,height:i,kind:r<=599?`phone`:n||r<1024?`tablet`:`desktop`,orientation:i>r?`portrait`:`landscape`,touch:n}}var dN=()=>typeof matchMedia==`function`&&matchMedia(`(pointer: coarse)`).matches;function fN(){return uN(window.innerWidth,window.innerHeight,dN())}var pN=(e,t)=>!!e&&e.width===t.width&&e.height===t.height&&e.kind===t.kind&&e.orientation===t.orientation&&e.touch===t.touch;function mN(e,t){let n=(0,y.useRef)(null),r=(0,y.useRef)(e);r.current=e,(0,y.useEffect)(()=>{if(t!==`open`){n.current=null;return}let e=()=>{let e=fN();pN(n.current,e)||(n.current=e,r.current({type:`ui.screen`,...e}))};e();let i=null,a=()=>{i&&clearTimeout(i),i=setTimeout(e,400)};return window.addEventListener(`resize`,a),window.addEventListener(`orientationchange`,a),()=>{i&&clearTimeout(i),window.removeEventListener(`resize`,a),window.removeEventListener(`orientationchange`,a)}},[t])}var hN={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function gN(e,t={}){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||hN[n.status]||`The request failed (${n.status}).`)}return await n.json()}var _N=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),vN={overview:()=>gN(`/api/voice/people`),begin:e=>gN(`/api/voice/people/begin`,_N(`POST`,{name:e})),recording:{state:async()=>(await gN(`/api/voice/people`)).enrolling??{enrolled:!1,samples:0,min:3,max:8},sample:e=>gN(`/api/voice/people/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>gN(`/api/voice/people/finish`,_N(`POST`,{pin:e})),cancel:async()=>{await gN(`/api/voice/people/cancel`,_N(`POST`,{}))},remove:async()=>{}},removePerson:async(e,t)=>{await gN(`/api/voice/people/${e}`,_N(`DELETE`,{pin:t}))}};function yN({api:e=vN,createRecorder:t,onClose:n}){let[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)({kind:`list`}),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(!0),g=(0,y.useCallback)(()=>{e.overview().then(e=>h.current&&i(e)).catch(e=>h.current&&m(e.message))},[e]);(0,y.useEffect)(()=>(h.current=!0,g(),()=>{h.current=!1}),[g]);let _=async()=>{m(null),f(!0);try{let t=await e.begin(s.trim());h.current&&o({kind:`record`,name:t.name})}catch(e){h.current&&m(e.message)}finally{h.current&&f(!1)}},v=async t=>{m(null),f(!0);try{if(await e.removePerson(t.id,l),!h.current)return;o({kind:`list`}),g()}catch(e){h.current&&m(e.message)}finally{h.current&&(f(!1),u(``))}};return a.kind===`record`?(0,w.jsx)(tN,{api:e.recording,who:a.name,...t?{createRecorder:t}:{},onClose:()=>{c(``),o({kind:`list`}),g()}}):(0,w.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Family voices`,style:{pointerEvents:`auto`},children:[(0,w.jsx)(`div`,{className:`approval-head`,children:(0,w.jsx)(`span`,{className:`approval-title`,children:`Family voices`})}),a.kind===`list`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`auth-note`,children:`Friend knows your voice. Add the people at home, so it knows who is talking and answers them by name. They can chat and ask for the weather, but cannot use your PC or see your private things.`}),r&&!r.ownerEnrolled&&(0,w.jsx)(`p`,{className:`auth-note`,children:`First teach Friend your own voice (Esc, then Enroll my voice).`}),r&&r.people.length===0&&r.ownerEnrolled&&(0,w.jsx)(`p`,{className:`auth-note`,children:`Nobody added yet.`}),r&&r.people.length>0&&(0,w.jsx)(`ul`,{className:`household-list`,"aria-label":`People Friend knows`,children:r.people.map(e=>(0,w.jsxs)(`li`,{className:`household-row`,children:[(0,w.jsx)(`span`,{children:e.name}),(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,onClick:()=>o({kind:`remove`,person:e}),"aria-label":`Remove ${e.name}`,children:`Remove`})]},e.id))}),r&&r.ownerEnrolled&&r.people.length<r.max&&(0,w.jsxs)(`label`,{className:`settings-field`,children:[(0,w.jsx)(`span`,{children:`Add a person`}),(0,w.jsx)(`input`,{value:s,maxLength:40,placeholder:`Name, for example Priya`,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s.trim()&&!d&&void _()})]}),p&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:p}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[r&&r.ownerEnrolled&&r.people.length<r.max&&(0,w.jsx)(`button`,{type:`button`,style:x,className:`primary`,disabled:d||!s.trim(),onClick:()=>void _(),children:`Record their voice`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:n,children:`Close`})]})]}),a.kind===`remove`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`auth-note`,children:[`Enter your PIN to remove `,a.person.name,`’s voice. Friend will treat their voice as a stranger’s.`]}),(0,w.jsx)(F,{pin:l,onChange:u}),p&&(0,w.jsx)(`p`,{role:`alert`,className:`auth-error`,children:p}),(0,w.jsxs)(`div`,{className:`approval-actions`,children:[(0,w.jsx)(`button`,{type:`button`,style:x,className:`danger`,disabled:d||l.length<6,onClick:()=>void v(a.person),children:`Remove`}),(0,w.jsx)(`button`,{type:`button`,style:x,onClick:()=>{u(``),m(null),o({kind:`list`})},children:`Back`})]})]})]})}var bN=`▌▍▎▏█▓▒░<>/\\|+-=*#%&0123456789ABCDEF`;function xN(e,t,n=Math.random){let r=[...e];if(t>=1)return e;let i=Math.floor(r.length*Math.max(0,t));return r.map((e,t)=>t<i||e===` `?e:bN[Math.floor(n()*36)]).join(``)}var SN=e=>e.length===0?0:Math.min(24,Math.max(6,Math.ceil([...e].length/2)));function CN(e,t){let[n,r]=(0,y.useState)(e),i=(0,y.useRef)(e);return(0,y.useEffect)(()=>{if(!t||e===i.current){i.current=e,r(e);return}i.current=e;let n=SN(e);if(n===0){r(e);return}let a=0,o=setInterval(()=>{a++,r(xN(e,a/n)),a>=n&&clearInterval(o)},320/n);return()=>clearInterval(o)},[e,t]),n}function wN(e){let t=e.currentTarget,n=t.getBoundingClientRect(),r=document.createElement(`span`);r.className=`hud-ripple`;let i=Math.max(n.width,n.height)*2;r.style.width=r.style.height=`${i}px`,r.style.left=`${e.clientX-n.left-i/2}px`,r.style.top=`${e.clientY-n.top-i/2}px`,t.appendChild(r),r.addEventListener(`animationend`,()=>r.remove(),{once:!0}),setTimeout(()=>r.remove(),900)}function TN({items:e,animations:t,onAction:n}){let[r,i]=(0,y.useState)(null),a=(0,y.useRef)(void 0);if((0,y.useEffect)(()=>()=>clearTimeout(a.current),[]),e.length===0)return null;let o=e=>{t!==`off`&&(i(e.id),clearTimeout(a.current),a.current=setTimeout(()=>i(null),650)),n(e)};return(0,w.jsxs)(Ce,{id:`launcher`,label:`Quick launch`,wholeBox:!0,testId:`launcher`,className:`hud hud-launcher${t===`full`?` hud-boot`:``}`,children:[(0,w.jsx)(`div`,{className:`hud-kicker`,children:`Quick launch`}),(0,w.jsx)(`ul`,{className:`hud-stack`,children:e.map((e,n)=>(0,w.jsx)(`li`,{className:`hud-tab hud-cut${r===e.id?` engaged`:``}${t===`full`?` hud-boot`:``}`,style:{"--i":n+1},children:(0,w.jsxs)(`button`,{type:`button`,className:`hud-tab-main`,"aria-label":e.label,onPointerDown:t===`off`?void 0:wN,onClick:()=>o(e),children:[(0,w.jsx)(`span`,{className:`hud-icon`,"aria-hidden":`true`,children:e.icon}),(0,w.jsx)(`span`,{className:`hud-tab-label`,children:e.label}),(0,w.jsx)(`span`,{className:`hud-tab-engaged`,"aria-hidden":`true`,children:`ENGAGED`}),(0,w.jsx)(`span`,{className:`hud-sweep`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`hud-scan`,"aria-hidden":`true`})]})},e.id))})]})}var EN=class extends y.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}};function DN(e){let t=()=>({w:window.innerWidth,h:window.innerHeight}),[n,r]=(0,y.useState)(t);return(0,y.useEffect)(()=>{if(e)return;let n=()=>r(t());return window.addEventListener(`resize`,n),()=>window.removeEventListener(`resize`,n)},[e]),e??n}var ON=(0,y.lazy)(()=>uk(()=>import(`./jarvisTree-Ysieqypf.js`),__vite__mapDeps([0,1,2])));function kN({node:e,children:t}){return vu(e.c,{...e.p??{},...e.kids?{kids:e.kids}:{}})?(0,w.jsx)(w.Fragment,{children:t}):(0,w.jsx)(`div`,{className:`ob-jlive`,children:(0,w.jsx)(y.Suspense,{fallback:t,children:(0,w.jsx)(ON,{node:e})})})}function AN(e,t,n=24){let[r,i]=(0,y.useState)([]),a=(0,y.useRef)(void 0),o=(0,y.useRef)(0);return(0,y.useEffect)(()=>{if(a.current===t)return;a.current=t;let r=Date.now();r-o.current<1e3||(o.current=r,i(t=>[...t,e].slice(-n)))},[e,t,n]),r}var jN=(e,t=0,n=100)=>Number.isFinite(e)?Math.min(n,Math.max(t,e)):t,MN=e=>e?{x:e.x,y:e.y,width:e.w,height:e.h}:{};function NN(){return(0,w.jsx)(`svg`,{width:`0`,height:`0`,"aria-hidden":`true`,style:{position:`absolute`},children:(0,w.jsxs)(`defs`,{children:[(0,w.jsxs)(`filter`,{id:`ob-glow`,x:`-50%`,y:`-50%`,width:`200%`,height:`200%`,children:[(0,w.jsx)(`feGaussianBlur`,{stdDeviation:`3`,result:`b`}),(0,w.jsxs)(`feMerge`,{children:[(0,w.jsx)(`feMergeNode`,{in:`b`}),(0,w.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]}),(0,w.jsxs)(`filter`,{id:`ob-glow2`,x:`-50%`,y:`-50%`,width:`200%`,height:`200%`,children:[(0,w.jsx)(`feGaussianBlur`,{stdDeviation:`7`,result:`b`}),(0,w.jsxs)(`feMerge`,{children:[(0,w.jsx)(`feMergeNode`,{in:`b`}),(0,w.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]}),(0,w.jsxs)(`radialGradient`,{id:`ob-orbg`,cx:`50%`,cy:`45%`,r:`55%`,children:[(0,w.jsx)(`stop`,{offset:`0`,stopColor:`#cffafe`}),(0,w.jsx)(`stop`,{offset:`0.25`,stopColor:`#22d3ee`}),(0,w.jsx)(`stop`,{offset:`0.6`,stopColor:`#0e7490`}),(0,w.jsx)(`stop`,{offset:`1`,stopColor:`#042f3c`})]}),(0,w.jsxs)(`linearGradient`,{id:`ob-sweep`,x1:`0`,y1:`0`,x2:`1`,y2:`0`,children:[(0,w.jsx)(`stop`,{offset:`0`,stopColor:`#22d3ee`,stopOpacity:`0`}),(0,w.jsx)(`stop`,{offset:`1`,stopColor:`#22d3ee`,stopOpacity:`0.7`})]}),(0,w.jsxs)(`linearGradient`,{id:`ob-fade`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,w.jsx)(`stop`,{offset:`0`,stopColor:`#010609`}),(0,w.jsx)(`stop`,{offset:`0.15`,stopColor:`#010609`,stopOpacity:`0`}),(0,w.jsx)(`stop`,{offset:`0.85`,stopColor:`#010609`,stopOpacity:`0`}),(0,w.jsx)(`stop`,{offset:`1`,stopColor:`#010609`})]})]})})}function PN({variant:e=`chamfer`,tone:t=`cyan`,title:n,running:r=!1,className:i=``,style:a,children:o,...s}){return(0,w.jsxs)(`section`,{...s,className:`ob-frame ob-v-${e} ${i}`.trim(),"data-tone":t,...r?{"data-running":``}:{},style:a,children:[n&&(0,w.jsx)(`header`,{className:`ob-frame-title`,children:n}),(0,w.jsx)(`div`,{className:`ob-frame-body`,children:o})]})}var FN=`M60 170A90 90 0 0 1 240 170`,IN=`M76 170A74 74 0 0 1 224 170`;function LN({value:e,inner:t,label:n=`Gauge`,tone:r=`cyan`,frame:i}){let a=Math.round(jN(e));return(0,w.jsxs)(`svg`,{className:i?void 0:`ob-svg`,...MN(i),viewBox:`0 0 300 190`,role:`img`,"aria-label":`${n} ${a}%`,"data-value":a,"data-tone":r,children:[(0,w.jsx)(`path`,{d:FN,className:`ob-track`,strokeWidth:`14`,pathLength:100}),(0,w.jsx)(`path`,{d:FN,className:`ob-fill`,strokeWidth:`14`,pathLength:100,strokeDasharray:`${a} 100`,"data-arc":`outer`}),t!==void 0&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:IN,className:`ob-track`,strokeWidth:`6`,pathLength:100}),(0,w.jsx)(`path`,{d:IN,className:`ob-fill`,strokeWidth:`6`,pathLength:100,strokeDasharray:`${Math.round(jN(t))} 100`,stroke:`#a78bfa`,"data-arc":`inner`})]})]})}function RN({levels:e,tone:t=`cyan`,frame:n}){let r=Math.max(1,e.length)*12;return(0,w.jsx)(`svg`,{className:n?void 0:`ob-svg`,...MN(n),viewBox:`0 0 ${r} 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,"data-tone":t,children:e.map((e,t)=>(0,w.jsx)(`rect`,{className:`ob-eq`,x:t*12,y:0,width:8,height:100,style:{"--lv":Math.max(.05,jN(e,0,1)),animationDelay:`${-(t*.37%.9)}s`,transform:`scaleY(${Math.max(.05,jN(e,0,1))})`}},t))})}var zN=`M0 40H40L52 20L66 62L80 8L96 52L108 40H190L202 28L214 48L226 40H300`;function BN({tone:e=`cyan`,frame:t}){return(0,w.jsxs)(`svg`,{className:t?void 0:`ob-svg`,...MN(t),viewBox:`0 0 300 70`,"aria-hidden":`true`,"data-tone":e,children:[(0,w.jsx)(`path`,{className:`ob-ecg-base`,d:zN}),(0,w.jsx)(`path`,{className:`ob-ecg`,d:zN})]})}function VN({blips:e,frame:t}){return(0,w.jsxs)(`svg`,{className:t?void 0:`ob-svg`,...MN(t),viewBox:`-120 -120 240 240`,role:`img`,"aria-label":`Devices: ${e.map(e=>e.label).join(`, `)||`none`}`,children:[(0,w.jsxs)(`g`,{fill:`none`,stroke:`var(--ob-line)`,children:[(0,w.jsx)(`circle`,{r:`110`}),(0,w.jsx)(`circle`,{r:`73`}),(0,w.jsx)(`circle`,{r:`36`}),(0,w.jsx)(`line`,{x1:`-110`,x2:`110`}),(0,w.jsx)(`line`,{y1:`-110`,y2:`110`})]}),(0,w.jsx)(`circle`,{r:`110`,fill:`none`,stroke:`#67e8f9`,strokeWidth:`2`,strokeDasharray:`1 9`}),(0,w.jsxs)(`g`,{className:`ob-sweep`,children:[(0,w.jsx)(`path`,{d:`M0 0L110 0A110 110 0 0 0 95 -55Z`,fill:`url(#ob-sweep)`}),(0,w.jsx)(`line`,{x2:`110`,stroke:`#67e8f9`,strokeWidth:`2`})]}),e.map(e=>{let t=e.angle*Math.PI/180,n=Math.cos(t)*jN(e.distance,0,1)*100,r=-Math.sin(t)*jN(e.distance,0,1)*100;return(0,w.jsxs)(`g`,{"data-blip":``,...e.dim?{"data-dim":``}:{},children:[(0,w.jsx)(`circle`,{className:`ob-blip${e.warn?` ob-blip-warn`:``}`,cx:n,cy:r,r:`5`}),(0,w.jsx)(`text`,{x:n+9,y:r+4,fontSize:`11`,fill:`currentColor`,opacity:e.dim?.5:1,children:e.label})]},e.label)})]})}var HN={done:`var(--ob-green)`,doing:`var(--ob-cyan)`,review:`var(--ob-orange)`,todo:`var(--ob-dim)`},UN=e=>e%2==0?6:5;function WN({cells:e,placeholder:t=!1,frame:n}){t&&(e=Array.from({length:11},()=>({status:`todo`})));let r=[],i=0,a=0;for(let t of e)a>=UN(i)&&(i++,a=0),r.push({x:20+a*40+i%2*20,y:20+i*35,status:t.status}),a++;let o=r.length?i+1:1;return(0,w.jsx)(`svg`,{className:n?void 0:`ob-svg`,...MN(n),viewBox:`0 0 260 ${o*35+10}`,"aria-hidden":`true`,...t?{"data-placeholder":``}:{},children:r.map((e,t)=>(0,w.jsx)(`polygon`,{"data-status":e.status,points:`-20,0 -10,-17.3 10,-17.3 20,0 10,17.3 -10,17.3`,transform:`translate(${e.x} ${e.y})`,fill:`none`,stroke:HN[e.status],strokeWidth:`1.6`,className:e.status===`review`?`ob-pulse`:void 0},t))})}function GN({rings:e,placeholder:t=!1,frame:n}){t&&(e=[{value:0},{value:0},{value:0}]);let r=t?{"aria-hidden":!0,"data-placeholder":``}:{role:`img`,"aria-label":e.map(e=>`${e.label??`ring`} ${Math.round(jN(e.value))}%`).join(`, `)||`no data`};return(0,w.jsx)(`svg`,{className:n?void 0:`ob-svg`,...MN(n),viewBox:`-50 -50 100 100`,...r,children:e.map((e,t)=>{let n=38-t*12;if(n<=2)return null;let r=Math.round(jN(e.value));return(0,w.jsxs)(`g`,{"data-tone":e.tone??`cyan`,transform:`rotate(-90)`,children:[(0,w.jsx)(`circle`,{r:n,className:`ob-track`,strokeWidth:`8`}),(0,w.jsx)(`circle`,{r:n,className:`ob-fill`,strokeWidth:`8`,pathLength:100,strokeDasharray:`${r} 100`,"data-ring":t,"data-value":r})]},t)})})}function KN({value:e,segments:t=60,radius:n=205,size:r=460}){let i=Math.round(t*jN(e)/100),a=r/2;return(0,w.jsx)(`svg`,{className:`ob-svg`,viewBox:`0 0 ${r} ${r}`,"aria-hidden":`true`,children:Array.from({length:t},(e,r)=>{let o=(-90+r*360/t)*Math.PI/180,[s,c]=[n-7,n+7];return(0,w.jsx)(`line`,{className:`ob-seg`,"data-seg":``,"data-on":r<i?`true`:`false`,x1:a+s*Math.cos(o),y1:a+s*Math.sin(o),x2:a+c*Math.cos(o),y2:a+c*Math.sin(o)},r)})})}var qN={running:`green`,waiting:`orange`,idle:`cyan`,add:`cyan`};function JN({label:e,glyph:t,caption:n,detail:r,status:i=`idle`,onClick:a,x:o,y:s}){let c=o!==void 0&&s!==void 0?{left:o,top:s}:void 0;return(0,w.jsxs)(`button`,{type:`button`,className:`ob-node`,"data-tone":qN[i],"data-status":i,"aria-label":r?`${e}, ${r}`:e,title:e,style:c,onClick:a,children:[(0,w.jsxs)(`svg`,{viewBox:`-34 -30 68 60`,"aria-hidden":`true`,children:[(0,w.jsx)(`polygon`,{points:`-34,0 -17,-29.4 17,-29.4 34,0 17,29.4 -17,29.4`}),(0,w.jsx)(`text`,{className:`ob-node-label${t?` ob-glyph`:``}`,children:t??(e.length>6?`${e.slice(0,5)}…`:e)})]}),n&&(0,w.jsx)(`span`,{className:`ob-node-caption`,children:n})]})}function YN({x1:e,y1:t,x2:n,y2:r,tone:i=`cyan`,flowing:a=!0}){return(0,w.jsx)(`line`,{className:`ob-link${a?` ob-flow`:``}`,"data-tone":i,x1:e,y1:t,x2:n,y2:r})}var XN=1e4;function ZN({stats:e,now:t=Date.now()}){let n=e?Math.round(e.cpu):0,r=e&&e.ramTotal>0?Math.round(100*e.ramUsed/e.ramTotal):0,i=!!e&&t-e.at>1e4;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 300 220`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`12`,y:`8`,children:`SYSTEM · CPU / RAM`}),(0,w.jsx)(`path`,{className:`ob-bracket`,d:`M0 20H20M0 20V40M300 20H280M300 20V40`}),(0,w.jsx)(LN,{value:n,inner:r,label:`CPU`,frame:{x:0,y:20,w:300,h:190}}),e?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`text`,{className:`ob-big`,x:`150`,y:`170`,textAnchor:`middle`,children:[n,`%`]}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`150`,y:`192`,textAnchor:`middle`,children:[`CPU · RAM `,r,`%`,i?` · STALE`:``]})]}):(0,w.jsx)(`text`,{className:`ob-dim`,x:`150`,y:`180`,textAnchor:`middle`,children:`Waiting for data`})]})}function QN(e){if(e<1024)return`${Math.round(e)} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(1)} ${t[r]}`}function $N({stats:e,now:t=Date.now()}){let n=!!e&&e.netDown===0&&e.netUp===0,r=!!e&&t-e.at>1e4;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 300 110`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`0`,y:`8`,children:`NETWORK`}),(0,w.jsx)(BN,{frame:{x:0,y:20,w:300,h:70}}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`0`,y:`104`,children:[e?n?`n/a`:`↓ ${QN(e.netDown)}/s ↑ ${QN(e.netUp)}/s`:`Waiting for data`,r?` · stale`:``]})]})}var eP=e=>Math.max(0,Math.min(100,Math.round(e))),tP=(e,t,n=`200px`)=>({c:`JGaugeChart`,p:{value:eP(e),min:0,max:100,size:n,label:t,displayValue:`${eP(e)}%`,showNeedle:!1,showTicks:!1,showMinMax:!1}}),nP=(e,t=`260px`)=>({c:`JSparkline`,p:{data:e.length>1?e:[0,0],showArea:!0,showTrend:!1,height:`48px`,width:t}});function rP({node:e}){return(0,w.jsx)(kN,{node:e,children:(0,w.jsx)(`span`,{className:`ob-pic-wait`})})}function iP({k:e,v:t,tone:n}){return(0,w.jsxs)(`p`,{className:`ob-fact${n?` ob-fact-${n}`:``}`,children:[(0,w.jsx)(`span`,{children:e}),(0,w.jsx)(`b`,{children:t})]})}var aP=({children:e})=>(0,w.jsx)(`p`,{className:`ob-say`,children:e}),oP=({children:e})=>(0,w.jsx)(`p`,{className:`ob-sub ob-head`,children:e}),sP=e=>e<5e3?`just now`:e<6e4?`${Math.round(e/1e3)} s ago`:`${Math.round(e/6e4)} min ago`;function cP({stats:e,cpuHist:t,ramHist:n}){let r=e?eP(e.cpu):0,i=e&&e.ramTotal>0?eP(100*e.ramUsed/e.ramTotal):0;if(!e)return(0,w.jsx)(aP,{children:`Waiting for the first reading from this PC.`});let a=Date.now()-e.at>XN,o=r>85||i>92?`The PC is under heavy load. If it feels slow, close big programs or browser tabs you are not using.`:r>60||i>80?`Busy, but fine. Nothing needs doing unless it feels slow.`:`Light load. There is plenty of room for more work.`;return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsxs)(`div`,{className:`ob-pics`,children:[(0,w.jsx)(rP,{node:tP(r,`CPU`)}),(0,w.jsx)(rP,{node:tP(i,`Memory`)})]}),(0,w.jsx)(iP,{k:`Processor now`,v:`${r}%`,tone:r>85?`warn`:void 0}),(0,w.jsx)(iP,{k:`Memory now`,v:`${i}% (${QN(e.ramUsed)} of ${QN(e.ramTotal)})`,tone:i>92?`warn`:void 0}),(0,w.jsx)(iP,{k:`Memory free`,v:QN(Math.max(0,e.ramTotal-e.ramUsed))}),(0,w.jsx)(iP,{k:`Last reading`,v:a?`${sP(Date.now()-e.at)} (stale: the PC agent may be off)`:sP(Date.now()-e.at),tone:a?`warn`:`ok`}),(0,w.jsx)(oP,{children:`Last minute or so`}),(0,w.jsxs)(`div`,{className:`ob-pics`,children:[(0,w.jsx)(rP,{node:nP(t,`230px`)}),(0,w.jsx)(rP,{node:nP(n,`230px`)})]}),(0,w.jsx)(`p`,{className:`ob-trend`,children:`processor, then memory`}),(0,w.jsx)(aP,{children:o})]})}function lP({voice:e,lastHeard:t}){let n=e.mode!==`idle`||e.level>.05,r={idle:`Waiting`,listening:`Listening to you`,transcribing:`Turning your words into text`,speaking:`Speaking`}[e.mode];return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsx)(rP,{node:{c:`JWaveform`,p:{barCount:36,height:`64px`,active:n}}}),(0,w.jsx)(iP,{k:`Doing now`,v:r,tone:n?`ok`:void 0}),(0,w.jsx)(iP,{k:`Sound level`,v:`${Math.round(e.level*100)}%`}),(0,w.jsx)(iP,{k:`Voice on this PC`,v:e.available?`ready`:`not set up`,tone:e.available?`ok`:`warn`}),(0,w.jsx)(iP,{k:`Your voice enrolled`,v:e.enrolled?`yes: strangers are recognised`:`no`}),t&&(0,w.jsx)(iP,{k:`You last said`,v:t.length>90?`${t.slice(0,89)}…`:t}),(0,w.jsx)(aP,{children:e.available?`Hold Space (or press and hold the talk button) and speak; let go to send. Friend answers aloud when you spoke to it.`:`Voice is not set up on this PC yet. Run friend voice setup in the terminal, then restart Friend.`})]})}function uP({stats:e,down:t,up:n}){if(!e)return(0,w.jsx)(aP,{children:`Waiting for the first reading from this PC.`});let r=e.netDown===0&&e.netUp===0;return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsxs)(`div`,{className:`ob-pics`,children:[(0,w.jsx)(rP,{node:nP(t,`260px`)}),(0,w.jsx)(rP,{node:nP(n,`260px`)})]}),(0,w.jsx)(`p`,{className:`ob-trend`,children:`downloading, then uploading`}),(0,w.jsx)(iP,{k:`Download now`,v:r?`n/a`:`${QN(e.netDown)}/s`}),(0,w.jsx)(iP,{k:`Upload now`,v:r?`n/a`:`${QN(e.netUp)}/s`}),(0,w.jsx)(iP,{k:`Fastest download seen`,v:t.length?`${QN(Math.max(...t))}/s`:`n/a`}),(0,w.jsx)(iP,{k:`Fastest upload seen`,v:n.length?`${QN(Math.max(...n))}/s`:`n/a`}),(0,w.jsx)(aP,{children:r?`This PC does not report network speed, or nothing is moving right now.`:`The speed of everything on this PC, not only Friend. A busy line usually means a download, an update or a video.`})]})}function dP({deviceOnline:e,voiceAvailable:t}){let n=(e,t,n,r)=>(0,w.jsxs)(`div`,{className:`ob-device`,children:[(0,w.jsx)(iP,{k:e,v:t?`online`:`offline`,tone:t?`ok`:`warn`}),(0,w.jsx)(`p`,{className:`ob-say ob-small`,children:t?n:r})]},e);return(0,w.jsxs)(`div`,{className:`ob-details`,children:[n(`This screen`,!0,`You are looking at it: Friend shows pictures, captions and these instruments here.`,``),n(`PC agent`,e,`Runs commands and reads files on this PC when you ask, after your approval.`,`Friend cannot run commands or read files on this PC until the agent is running again (friend start).`),n(`Voice`,t,`Listens when you hold Space and speaks the answers.`,`Voice is not set up on this PC yet (friend voice setup).`)]})}function fP({office:e}){if(!e.enabled)return(0,w.jsx)(aP,{children:`The Office is switched off, so there are no workers or tickets. Turn it on in Settings, Office, then ask Friend to hire someone.`});let t=t=>e.tickets.filter(e=>e.status===t).length,n=t=>e.workers.find(e=>e.id===t)?.name??(t||`nobody yet`),r=[...e.tickets].sort((e,t)=>t.id-e.id).slice(0,8);return(0,w.jsxs)(`div`,{className:`ob-details`,children:[(0,w.jsx)(iP,{k:`Done`,v:t(`done`),tone:`ok`}),(0,w.jsx)(iP,{k:`Being worked on`,v:t(`doing`)}),(0,w.jsx)(iP,{k:`Waiting for review`,v:t(`review`)+t(`blocked`),tone:t(`review`)+t(`blocked`)>0?`warn`:void 0}),(0,w.jsx)(iP,{k:`Not started`,v:t(`todo`)}),(0,w.jsx)(oP,{children:`Newest tickets`}),r.length===0&&(0,w.jsx)(aP,{children:`No tickets yet. Ask Friend to give a worker something to do.`}),r.map(e=>(0,w.jsxs)(`p`,{className:`ob-li ob-wrap`,children:[`#`,e.id,` · `,e.title,` · `,e.status,` · `,n(e.workerId)]},e.id))]})}var pP=!1;typeof document<`u`&&(document.addEventListener(`keydown`,()=>pP=!0,!0),document.addEventListener(`pointerdown`,()=>pP=!1,!0),document.addEventListener(`mousedown`,()=>pP=!1,!0));var mP=()=>pP,hP={starting:`running`,running:`running`,waiting:`waiting`,idle:`idle`,paused:`idle`,stopped:`idle`,failed:`idle`};function gP(e,t){let n=e.slice(0,5).map(e=>({id:e.id,label:e.name,glyph:e.name.slice(0,6).toUpperCase(),caption:e.name,status:hP[e.status],detail:e.detail||e.status,kind:`worker`}));return t&&e.length<5&&n.push({id:`hire`,label:`Hire a worker`,glyph:`+`,caption:`HIRE WORKER`,status:`add`,detail:`HIRE WORKER`,kind:`hire`}),n}var _P={done:`done`,doing:`doing`,review:`review`,blocked:`review`,todo:`todo`},vP=[`done`,`doing`,`review`,`todo`];function yP(e){return[...e].sort((e,t)=>e.id-t.id).slice(-11).map(e=>({status:_P[e.status]})).sort((e,t)=>vP.indexOf(e.status)-vP.indexOf(t.status))}function bP(e){let t=[...new Set(e.map(e=>e.projectId))];if(t.length!==0)return t.length===1?t[0]:`${t.length} projects`}var xP=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e);function SP(e){let t=e=>e.name.slice(0,6).toUpperCase(),n=e.filter(e=>e.budget!==null&&e.budget>0);if(n.length>0)return n.slice(0,3).map(e=>{let n=jN(e.tokens/e.budget*100);return{label:t(e),value:n,text:`${Math.round(n)}%`}});let r=Math.max(0,...e.map(e=>e.tokens));return[...e].sort((e,t)=>t.tokens-e.tokens).slice(0,3).map(e=>({label:t(e),value:r>0?jN(Math.max(+(e.tokens>0),Math.round(e.tokens/r*100))):0,text:xP(e.tokens)}))}var CP={tool:`green`,result:`green`,approval:`orange`,error:`orange`,text:`plain`};function wP(e,t){if(e!==`idle`||!t.enabled)return e;if(t.workers.some(e=>e.status===`waiting`))return`needs you`;let n=t.workers.filter(e=>e.status===`running`||e.status===`starting`).length;return n>0?`working · ${n}`:e}function TP(e,t,n=8){return t.flatMap(t=>(e[t.id]??[]).map(e=>({...e,name:t.name.slice(0,6).toUpperCase().padEnd(7)}))).sort((e,t)=>e.at-t.at).slice(-n).map(e=>({text:`${e.name}${e.text}`,tone:CP[e.kind]??`plain`}))}var EP=e=>{let t=Math.max(1,Math.round(e/6e4));return t>=60?`${Math.floor(t/60)}H ${String(t%60).padStart(2,`0`)}M`.replace(/ 0(\d)M/,` $1M`):`${t}M`};function DP(e,t,n){let r=e.fiveHour;return r&&r.resetsAt*1e3>n?{value:Math.round(jN(r.utilization*100)),reset:EP(r.resetsAt*1e3-n),real:!0}:{value:t,reset:null,real:!1}}function OP(e){let t=new Map(e.map(e=>[e.id,e])),n=e=>{let n=new Set([e.id]);for(let r=e.managerId;r&&t.has(r);r=t.get(r).managerId){if(n.has(r))return r===e.id;n.add(r)}return!1},r=e=>e.managerId&&t.has(e.managerId)&&!n(e)?e.managerId:`friend`,i=new Map;for(let t of e)i.set(r(t),[...i.get(r(t))??[],t]);let a=new Map,o=e=>{let t=i.get(e)??[],n=t.length===0?190:Math.max(190,t.reduce((e,t)=>e+o(t.id),0)+(t.length-1)*26);return a.set(e,n),n};o(`friend`);let s=[],c=[],l=0,u=(e,n,r)=>{l=Math.max(l,r);let o=i.get(e)??[],d=r*134,f;if(o.length===0)f=n+(a.get(e)-190)/2;else{let t=n,i=o.map(e=>{let n=u(e.id,t,r+1);return t+=a.get(e.id)+26,n});f=(i[0]+i[i.length-1])/2;for(let[t,n]of o.entries())c.push({from:e,to:n.id,x1:f+95,y1:d+78,x2:i[t]+95,y2:d+78+56})}return s.push({id:e,x:f,y:d,worker:e===`friend`?null:t.get(e)}),f};return u(`friend`,0,0),{nodes:s,edges:c,width:a.get(`friend`),height:(l+1)*78+l*56}}var kP=[{id:`system`,title:`System`,anchor:`left`,box:{x:40,y:70,w:300,h:220},tone:`cyan`,minDensity:`standard`},{id:`voice`,title:`Voice`,anchor:`left`,box:{x:40,y:310,w:300,h:150},tone:`cyan`,minDensity:`standard`},{id:`network`,title:`Network`,anchor:`left`,box:{x:40,y:480,w:300,h:110},tone:`cyan`,minDensity:`standard`},{id:`feed`,title:`Activity`,anchor:`left`,box:{x:40,y:650,w:430,h:210},tone:`green`,minDensity:`standard`},{id:`radar`,title:`Devices`,anchor:`right`,box:{x:1310,y:60,w:250,h:270},tone:`cyan`,minDensity:`standard`},{id:`tickets`,title:`Tickets`,anchor:`right`,box:{x:1300,y:320,w:270,h:160},tone:`green`,minDensity:`standard`},{id:`budget`,title:`Budget`,anchor:`right`,box:{x:1300,y:480,w:270,h:110},tone:`cyan`,minDensity:`standard`},{id:`approval`,title:`Approvals`,anchor:`right`,box:{x:1180,y:650,w:380,h:210},tone:`orange`,minDensity:`standard`},{id:`usage`,title:`Usage`,anchor:`centre`,box:{x:700,y:215,w:200,h:30},tone:`cyan`,minDensity:`calm`}];if(kP.length!==Bu.length)throw Error(`the widget registry and HUD_WIDGET_IDS differ`);var AP={calm:0,standard:1,full:2},jP=[`system`,`voice`,`network`,`feed`,`radar`,`tickets`];function MP(e,t,n,r,i=[],a=!1){return kP.filter(n=>{if(n.id===`approval`&&r)return!0;let o=t[n.id];return o===!1?!1:a?!0:n.id===`approval`?o===!0:jP.includes(n.id)?o===!0||i.includes(n.id):o===!0||AP[e]>=AP[n.minDensity]})}function NP({rings:e=[]}){let t=e.length===0;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 270 110`,children:[(0,w.jsx)(GN,{rings:e.map((e,t)=>({value:e.value,label:e.label,tone:[`cyan`,`cyan`,`green`][t]??`cyan`})),placeholder:t,frame:{x:-10,y:-10,w:100,h:100}}),(0,w.jsx)(`text`,{className:`ob-lab`,x:`104`,y:`26`,children:`BUDGET`}),t?(0,w.jsx)(`text`,{className:`ob-sm`,x:`104`,y:`46`,children:`No workers yet`}):e.slice(0,3).map((e,t)=>(0,w.jsxs)(`text`,{className:`ob-sm`,x:`104`,y:46+t*18,children:[e.label,` `,e.text??`${Math.round(e.value)}%`]},e.label))]})}var PP=8,FP=46,IP=e=>e.length>FP?`${e.slice(0,45)}…`:e;function LP({lines:e,activity:t,busy:n,limit:r=PP,marquee:i=!1}){let a=Math.min(r,PP-+!!n),o=i?e:e.slice(-a),s=`M0 0H400L430 30V210H0Z`,c=(e,t,n)=>(0,w.jsxs)(`text`,{className:`tone`in e?`ob-sm ${e.tone===`green`?`ob-grn`:e.tone===`orange`?`ob-org`:``}`.trim():e.role===`user`?`ob-sm`:`ob-sm ob-grn`,x:`22`,y:t,children:[`tone`in e?``:e.role===`user`?`▸ `:`◂ `,IP(e.text)]},n);return(0,w.jsxs)(`svg`,{className:`ob-wsvg ob-feed-svg`,viewBox:`0 0 430 210`,"aria-live":`polite`,children:[(0,w.jsx)(`defs`,{children:(0,w.jsx)(`clipPath`,{id:`ob-feed-clip`,children:(0,w.jsx)(`rect`,{x:`0`,y:`38`,width:`430`,height:`168`})})}),(0,w.jsx)(`path`,{className:`ob-feed-frame`,d:s}),(0,w.jsx)(`path`,{className:`ob-feed-run`,d:s,pathLength:100}),(0,w.jsx)(`text`,{className:`ob-lab`,x:`16`,y:`18`,children:`WORKER FEED · LIVE`}),(0,w.jsx)(`circle`,{className:`ob-pulse`,cx:`410`,cy:`14`,r:`4`,fill:`#34d399`}),o.length===0&&!n&&(0,w.jsx)(`text`,{className:`ob-dim`,x:`22`,y:`60`,children:`Nothing yet`}),(0,w.jsx)(`g`,{clipPath:`url(#ob-feed-clip)`,children:i?(0,w.jsx)(`g`,{className:`ob-feed-scroll`,style:{"--n":o.length*20},children:[0,1].flatMap(e=>o.map((t,n)=>c(t,56+(e*o.length+n)*20,`${e}-${n}`)))}):(0,w.jsxs)(`g`,{className:`ob-feed-in`,children:[o.map((e,t)=>c(e,56+t*20,String(t))),n&&(0,w.jsxs)(`text`,{className:`ob-sm ob-org`,x:`22`,y:56+o.length*20,children:[`⚙ `,IP(t??`Working…`)]})]},`${e.length}:${o.at(-1)?.text??``}`)}),(0,w.jsx)(`rect`,{className:`ob-feed-fade`,x:`1`,y:`38`,width:`428`,height:`168`,fill:`url(#ob-fade)`,pointerEvents:`none`})]})}function RP({lines:e,activity:t,busy:n,workers:r=[]}){let i=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let e=i.current;e&&(e.scrollTop=e.scrollHeight)},[e.length,r.length]),(0,w.jsxs)(`div`,{className:`ob-feed`,"aria-live":`polite`,ref:i,children:[e.length===0&&r.length===0&&!n&&(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Nothing yet`}),r.map((e,t)=>(0,w.jsx)(`p`,{className:`ob-li${e.tone===`green`?` ob-live`:e.tone===`orange`?` ob-warn`:``}`,children:e.text},`w${t}`)),e.slice(-200).map((e,t)=>(0,w.jsxs)(`p`,{className:`ob-li ${e.role===`user`?`ob-user`:``}`,children:[e.role===`user`?`▸ `:`◂ `,e.text]},t)),n&&(0,w.jsxs)(`p`,{className:`ob-li ob-live`,children:[`⚙ `,t??`Working…`]})]})}var zP={system:`How hard this PC is working: the arc and the first row are the processor, the second row is the memory, and below are the memory figures.`,voice:`The sound Friend is hearing or speaking, live.`,network:`How fast data moves in and out of this PC. Some PCs do not report it.`,feed:`The conversation and what Friend is doing right now.`,radar:`The things Friend can reach: this screen, the PC's agent and the voice. A dim one is offline.`,tickets:`The work given to hired workers, one cell each. Switch the Office on in Settings to hire workers.`,budget:`How much of each worker's limit is used. Limits are set in Settings, Office.`,approval:`Something is waiting for your answer.`,usage:`Today's usage compared with your busiest day of the last 30.`},BP={voice:`Voice`,chat:`Chat`,task:`Scheduled tasks`,channel:`Messages`,other:`Other`};function VP({api:e}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let t=!0;return e.summary(30).then(e=>t&&n(e)).catch(()=>t&&i(!0)),()=>{t=!1}},[e]),r?(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Could not read the usage`}):t?t.bySource.length===0?(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`No usage yet`}):(0,w.jsx)(`div`,{className:`ob-usage-detail`,children:t.bySource.map(e=>(0,w.jsxs)(`p`,{className:`ob-li`,children:[BP[e.source]??e.source,` · `,MC(e.input+e.output),` tokens · `,e.turns,` turns`]},e.source))}):(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Reading…`})}var HP={cpu:[],ram:[],down:[],up:[]};function UP({id:e,state:t,rect:n,usageApi:r=kC,readings:i=HP,onClose:a}){let o=(0,y.useRef)(null);(0,y.useEffect)(()=>{mP()&&o.current?.focus()},[e]);let s=kP.find(t=>t.id===e)?.title??e,c=(()=>{switch(e){case`system`:return(0,w.jsx)(cP,{stats:t.stats,cpuHist:i.cpu,ramHist:i.ram});case`network`:return(0,w.jsx)(uP,{stats:t.stats,down:i.down,up:i.up});case`radar`:return(0,w.jsx)(dP,{deviceOnline:t.deviceOnline,voiceAvailable:t.voice.available});case`voice`:return(0,w.jsx)(lP,{voice:t.voice,lastHeard:[...t.chat].reverse().find(e=>e.role===`user`)?.text??null});case`feed`:return(0,w.jsx)(RP,{lines:t.chat,activity:t.activity,busy:t.busy,workers:t.office.enabled?TP(t.office.feed,t.office.workers,60):[]});case`tickets`:return(0,w.jsx)(fP,{office:t.office});case`budget`:return(0,w.jsx)(NP,{rings:SP(t.office.workers)});case`usage`:return(0,w.jsx)(VP,{api:r});default:return null}})();return(0,w.jsxs)(PN,{variant:`chamfer`,running:!0,title:s,className:`ob-expanded ob-hit`,style:{position:`absolute`,left:n.x,top:n.y,width:n.width,height:n.height},role:`dialog`,"aria-label":s,children:[(0,w.jsx)(`button`,{ref:o,type:`button`,className:`ob-close`,"aria-label":`Close`,onClick:a,children:`×`}),(0,w.jsx)(`div`,{className:`ob-expanded-body`,children:c}),(0,w.jsx)(`p`,{className:`ob-explain`,children:zP[e]})]})}var WP=e=>Math.max(0,Math.min(100,Math.round(e))),GP=(e,t,n=`cyan`)=>({c:`JHudFrameCard`,p:{title:e,color:n,showStatusDot:!0,width:`100%`},kids:t}),KP=(e,t,n,r)=>({c:`JDataRow`,p:{label:e,value:t,...n===void 0?{}:{barPercent:WP(n)},...r?{state:r}:{}}});function qP(e,t=!1){let n=e?WP(e.cpu):0,r=e&&e.ramTotal>0?WP(100*e.ramUsed/e.ramTotal):0;return GP(`System`,[{c:`Row`,p:{gap:12},kids:[{c:`JGaugeChart`,p:{value:n,min:0,max:100,size:t?`190px`:`150px`,label:`CPU`,displayValue:`${n}%`,showNeedle:!1,showTicks:!1,showMinMax:!1}},{c:`Column`,p:{gap:6},kids:e?[KP(`CPU`,`${n}%`,n,n>85?`warning`:void 0),KP(`RAM`,`${r}%`,r,r>90?`warning`:void 0),...t?[KP(`RAM USED`,QN(e.ramUsed)),KP(`RAM TOTAL`,QN(e.ramTotal))]:[]]:[`Waiting for data`]}]}])}function JP(e,t){let n=t!==`idle`||e>.05;return GP(`Voice`,[{c:`JWaveform`,p:{barCount:28,height:`48px`,active:n}},{c:`JStatusPill`,p:{state:n?`active`:`success`},kids:[n?String(t):`quiet`]}])}function YP(e,t){let n=!!e&&e.netDown===0&&e.netUp===0;return GP(`Network`,[{c:`Row`,p:{gap:12},kids:[{c:`JSparkline`,p:{data:t.length>1?t:[0,0],showArea:!0,height:`40px`,width:`130px`}},{c:`Column`,p:{gap:4},kids:e?n?[`n/a on this PC`]:[KP(`DOWN`,`${QN(e.netDown)}/s`),KP(`UP`,`${QN(e.netUp)}/s`)]:[`Waiting for data`]}]}])}function XP(e,t,n){let r=e.slice(-6).map((e,t)=>({id:`l${t}`,message:e.text.slice(0,120),level:e.tone===`orange`?`warn`:`info`}));return n&&t&&r.push({id:`now`,message:t,level:`info`}),GP(`Activity`,[{c:`JActivityFeed`,p:{items:r.length?r:[{id:`none`,message:`Nothing yet`,level:`info`}],maxRows:6,showTime:!1,showSource:!1}}],`green`)}function ZP(e,t){let n=(e,t)=>({c:`JStatusPill`,p:{state:t?`active`:`error`},kids:[`${e} ${t?`online`:`offline`}`]});return GP(`Devices`,[{c:`Column`,p:{gap:8},kids:[n(`This screen`,!0),n(`PC agent`,e),n(`Voice`,t)]}])}function QP(e,t){let n=t=>e.filter(e=>e.status===t).length,r=e.length,i=e=>r?100*e/r:0;return GP(t?`Tickets: ${t}`:`Tickets`,r?[KP(`DONE`,String(n(`done`)),i(n(`done`)),`success`),KP(`DOING`,String(n(`doing`)),i(n(`doing`))),KP(`REVIEW`,String(n(`review`)),i(n(`review`)),`warning`),KP(`TODO`,String(n(`todo`)),i(n(`todo`)))]:[`No tickets yet`],`green`)}function $P({worker:e,feed:t,rect:n,send:r,onClose:i}){let a=(0,y.useRef)(null),o=(0,y.useRef)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(!1);(0,y.useEffect)(()=>{mP()&&a.current?.focus()},[e.id]),(0,y.useEffect)(()=>{let e=o.current;e&&(e.scrollTop=e.scrollHeight)},[t.length]);let d=()=>{let t=s.trim();t&&(r({type:`office.say`,workerId:e.id,text:t}),c(``))},f=e.status===`starting`||e.status===`running`||e.status===`waiting`;return(0,w.jsxs)(PN,{variant:`chamfer`,running:!0,title:e.name,className:`ob-expanded ob-hit`,style:{position:`absolute`,left:n.x,top:n.y,width:n.width,height:n.height},role:`dialog`,"aria-label":e.name,children:[(0,w.jsx)(`button`,{ref:a,type:`button`,className:`ob-close`,"aria-label":`Close`,onClick:i,children:`×`}),(0,w.jsxs)(`div`,{className:`ob-expanded-body ob-worker`,children:[(0,w.jsxs)(`p`,{className:`ob-li`,children:[e.status,e.detail?` · ${e.detail}`:``]}),(0,w.jsxs)(`p`,{className:`ob-li ob-sub`,children:[`Tokens `,e.tokens,e.budget?` of ${e.budget}`:``]}),(0,w.jsx)(`div`,{className:`ob-worker-log`,ref:o,"aria-live":`polite`,children:t.length===0?(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Nothing yet`}):t.map((e,t)=>(0,w.jsx)(`p`,{"data-feed-line":``,"data-kind":e.kind,className:`ob-li${e.kind===`tool`||e.kind===`result`?` ob-live`:``}`,children:e.text},`${e.at}-${t}`))})]}),(0,w.jsxs)(`form`,{className:`ob-worker-say`,onSubmit:e=>{e.preventDefault(),d()},children:[(0,w.jsx)(`input`,{type:`text`,"aria-label":`Say to ${e.name}`,placeholder:`Say to ${e.name}`,value:s,maxLength:2e3,onChange:e=>c(e.target.value)}),(0,w.jsx)(`button`,{type:`submit`,children:`Send`}),(0,w.jsx)(`button`,{type:`button`,className:`ob-stop`,disabled:!f,onClick:()=>r({type:`office.stop`,workerId:e.id}),children:`Stop`}),(0,w.jsx)(`button`,{type:`button`,className:`ob-stop`,onClick:()=>l?r({type:`office.fire`,workerId:e.id}):u(!0),onBlur:()=>u(!1),children:l?`Confirm remove`:`Remove`})]})]})}var eF=(0,y.lazy)(()=>uk(()=>import(`./OrgParts-B8_VJBRh.js`).then(e=>({default:e.OrgCanvas})),__vite__mapDeps([3,1,2])));function tF({workers:e,name:t,rect:n,onWorker:r,onClose:i}){let a=(0,y.useRef)(null);return(0,y.useEffect)(()=>{mP()&&a.current?.focus()},[]),(0,w.jsxs)(PN,{variant:`chamfer`,running:!0,title:`Office team`,className:`ob-expanded ob-hit`,style:{position:`absolute`,left:n.x,top:n.y,width:n.width,height:n.height},role:`dialog`,"aria-label":`Office team`,children:[(0,w.jsx)(`button`,{ref:a,type:`button`,className:`ob-close`,"aria-label":`Close`,onClick:i,children:`×`}),(0,w.jsx)(`div`,{className:`ob-expanded-body ob-org-body`,children:(0,w.jsx)(y.Suspense,{fallback:(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`Drawing the team…`}),children:(0,w.jsx)(eF,{workers:e,name:t,onWorker:r})})}),(0,w.jsx)(`ul`,{className:`ob-org-lines`,"aria-label":`Who reports to whom`,children:e.map(n=>(0,w.jsxs)(`li`,{children:[n.name,` reports to `,n.managerId&&e.find(e=>e.id===n.managerId)?.name||t]},n.id))})]})}var nF=[{id:`code`,label:`CODE`,status:`running`,detail:`▶ Hero.tsx · 62%`,at:{x:800,y:108,anchor:`middle`}},{id:`test`,label:`TEST`,status:`running`,detail:`▶ 12/12 passing`,at:{x:1135,y:268,anchor:`start`}},{id:`rev`,label:`REV`,status:`waiting`,detail:`⏸ needs approval`,at:{x:1135,y:632,anchor:`start`}},{id:`hire`,label:`+`,status:`add`,detail:`HIRE WORKER`,at:{x:465,y:632,anchor:`end`}},{id:`arch`,label:`ARCH`,status:`idle`,detail:`idle`,at:{x:465,y:268,anchor:`end`}}],rF=[{text:`CODE ▶ edit src/Hero.tsx`,tone:`green`},{text:`CODE + 42 lines - 6 lines`,tone:`plain`},{text:`TEST ▶ pnpm test`,tone:`green`},{text:`TEST 12 passed · 0 failed`,tone:`plain`},{text:`REV ⏸ wants: npm install`,tone:`orange`},{text:`CODE ▶ edit src/Nav.tsx`,tone:`green`},{text:`CODE + 18 lines`,tone:`plain`}],iF=(e,t)=>Array.from({length:t},()=>({status:e})),aF=[...iF(`done`,3),...iF(`doing`,3),...iF(`review`,1),...iF(`todo`,4)],oF=[{label:`CODE`,value:42},{label:`TEST`,value:70},{label:`REV`,value:25}],sF=[{angle:49,distance:.64,label:`PC`},{angle:207,distance:.67,label:`PHONE`},{angle:286,distance:.73,label:`ALEXA?`,warn:!0}],cF={id:`sample`,tool:`shell.run`,summary:`npm install --save zod`,tier:`T2`,needsPin:!1},lF=e=>({cpu:38,ramUsed:61,ramTotal:100,netDown:2516582.4,netUp:314572.8,at:e});function uF({approval:e,send:t}){return e?(0,w.jsx)(dF,{approval:e,send:t}):(0,w.jsx)(`p`,{className:`ob-li ob-sub`,children:`None waiting`})}function dF({approval:e,send:t}){let{pin:n,setPin:r,respond:i,canApprove:a}=mt(e,t);return(0,w.jsxs)(`div`,{className:`ob-approval`,role:`alertdialog`,"aria-label":`Approval needed`,children:[(0,w.jsxs)(`svg`,{className:`ob-tri`,viewBox:`0 0 56 52`,"aria-hidden":`true`,children:[(0,w.jsx)(`path`,{d:`M4 48L28 4L52 48Z`}),(0,w.jsx)(`text`,{x:`28`,y:`42`,textAnchor:`middle`,children:`!`})]}),(0,w.jsxs)(`div`,{className:`ob-appr-text`,children:[(0,w.jsxs)(`span`,{className:`ob-appr-title`,children:[`APPROVAL NEEDED `,(0,w.jsx)(`span`,{className:`tier tier-${e.tier}`,children:e.tier})]}),!e.tool.startsWith(`office.`)&&(0,w.jsxs)(`span`,{className:`ob-appr-sub`,children:[e.tool,` wants to run:`]}),(0,w.jsx)(`pre`,{className:`ob-summary`,"data-testid":`approval-summary`,children:e.summary})]}),e.needsPin&&(0,w.jsx)(F,{pin:n,onChange:r,onSubmit:()=>a&&i(`approve`)}),(0,w.jsxs)(`div`,{className:`ob-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`ob-btn ob-yes`,disabled:!a,onClick:()=>i(`approve`),children:`Approve`}),e.tier===`T2`&&!e.needsPin&&!e.origin&&e.tool!==`camera.snap`&&e.tool!==`camera.watch`&&!e.tool.startsWith(`office.`)&&(0,w.jsx)(`button`,{type:`button`,className:`ob-btn`,onClick:()=>i(`approve_always`),children:`Always allow`}),(0,w.jsx)(`button`,{type:`button`,className:`ob-btn ob-no`,onClick:()=>i(`deny`),children:`Deny`})]})]})}function fF({deviceOnline:e,voiceAvailable:t,blips:n}){return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 250 270`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`20`,y:`21`,children:`DEVICES · RADAR`}),(0,w.jsx)(VN,{frame:{x:10,y:25,w:240,h:240},blips:n??[{angle:40,distance:.45,label:`This screen`},{angle:150,distance:.7,label:`PC`,dim:!e},{angle:250,distance:.6,label:`Voice`,dim:!t}]})]})}var pF=[{status:`done`,label:`DONE`},{status:`doing`,label:`DOING`},{status:`review`,label:`REVIEW`},{status:`todo`,label:`TODO`}];function mF({cells:e=[],project:t}){let n=e.length===0;return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 270 160`,children:[(0,w.jsxs)(`text`,{className:`ob-lab`,x:`0`,y:`8`,children:[`TICKETS · `,t??`no workers yet`]}),(0,w.jsx)(WN,{cells:e,placeholder:n,frame:{x:0,y:20,w:260,h:80}}),(0,w.jsx)(`text`,{className:`ob-dim`,x:`0`,y:`130`,children:pF.map(t=>`■ ${t.label} ${e.filter(e=>e.status===t.status).length}`).join(` `)})]})}var hF=Array.from({length:20},(e,t)=>.35+.65*Math.abs(Math.sin(t*1.7+1))),gF=.45;function _F({level:e,mode:t}){let n=jN(e,0,1),r=Math.max(gF,n),i=Math.round(n*5);return(0,w.jsxs)(`svg`,{className:`ob-wsvg`,viewBox:`0 0 300 160`,children:[(0,w.jsx)(`text`,{className:`ob-lab`,x:`0`,y:`8`,children:`VOICE · SPECTRUM`}),(0,w.jsx)(`line`,{className:`ob-ecg-base`,x1:`0`,x2:`300`,y1:`130`,y2:`130`}),(0,w.jsx)(RN,{levels:hF.map(e=>r*e),frame:{x:0,y:40,w:240,h:90}}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`0`,y:`150`,children:[`MIC `,`▮`.repeat(i),`▯`.repeat(5-i),` · `,t]})]})}function vF(){let[e,t]=(0,y.useState)(()=>typeof document<`u`&&document.hidden);return(0,y.useEffect)(()=>{let e=()=>t(document.hidden);return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),e}function yF(e){let[t,n]=(0,y.useState)(()=>new Date);return(0,y.useEffect)(()=>{let t=setInterval(()=>n(new Date),e);return()=>clearInterval(t)},[e]),t}var bF=e=>[...e.toUpperCase()].join(` `).replace(/\s{2,}/g,` `),xF=e=>t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},SF=e=>bt({connection:e.connection,deviceOnline:e.deviceOnline,approval:e.approval,voiceMode:e.voice.mode,busy:e.busy,activity:e.activity}).text;function CF(e,t){let n=t.stats;switch(e){case`system`:return n?`CPU ${Math.round(n.cpu)}% · RAM ${n.ramTotal>0?Math.round(100*n.ramUsed/n.ramTotal):0}%`:`Waiting for data`;case`voice`:return t.voice.mode;case`network`:return n?n.netDown===0&&n.netUp===0?`n/a`:`↓ ${Math.round(n.netDown/1024)} KB/s ↑ ${Math.round(n.netUp/1024)} KB/s`:`Waiting for data`;case`feed`:return t.chat.at(-1)?.text??`Nothing yet`;case`radar`:return[`This screen`,t.deviceOnline?`PC`:null,t.voice.available?`Voice`:null].filter(Boolean).join(` · `);case`approval`:return`None waiting`;default:return t.office.enabled&&t.office.workers.length>0?`${t.office.workers.length} worker${t.office.workers.length===1?``:`s`}`:`No workers yet`}}function wF({usage:e,reset:t=null,real:n=!1,style:r,onClick:i}){let a=typeof e==`number`&&Number.isFinite(e);return(0,w.jsxs)(`button`,{type:`button`,className:`ob-usage-label ob-hit`,"data-widget":`usage`,title:n?`How full your Claude subscription's five-hour window is`:`Today's usage compared with your busiest day of the last 30`,style:r,onClick:i,"aria-label":a?n?`Usage ${Math.round(e)} percent of the five-hour window${t?`, resets in ${t}`:``}`:`Usage ${Math.round(e)} percent of your busiest day`:`Usage, no data yet`,children:[`USAGE `,a?`${Math.round(e)}%`:`—`,t?` · RESET ${t}`:``]})}function TF({hud:e,state:t,preview:n}){let r=yF(e.clock.seconds?1e3:15e3),i=e.clock.locale||void 0,a=r.toLocaleTimeString(i,{hour:`2-digit`,minute:`2-digit`,...e.clock.seconds?{second:`2-digit`}:{},hour12:e.clock.hour12}),o=r.toLocaleDateString(i,{weekday:`short`,day:`2-digit`,month:`short`}),s=`M330 44H560L590 20H1010L1040 44H1270`,c=t.connection===`open`;return(0,w.jsxs)(`g`,{"data-testid":`orbital-topbar`,children:[(0,w.jsx)(`path`,{className:`ob-topbar-base`,d:s}),(0,w.jsx)(`path`,{className:`ob-topbar-run`,d:s,pathLength:100}),(0,w.jsx)(`text`,{className:`ob-title`,x:`800`,y:`40`,textAnchor:`middle`,children:bF(t.assistantName||`Assistant`)}),n&&(0,w.jsx)(`text`,{className:`ob-sample-tag`,x:`800`,y:`62`,textAnchor:`middle`,children:`SAMPLE DATA · NOT REAL`}),(0,w.jsx)(`circle`,{className:c?`ob-pulse`:void 0,cx:`30`,cy:`34`,r:`4`,fill:c?`#34d399`:`#fb923c`}),(0,w.jsxs)(`text`,{className:`ob-lab`,x:`40`,y:`38`,children:[(t.assistantName||`FRIEND`).toUpperCase(),` · `,c?`ONLINE`:`OFFLINE`]}),(0,w.jsxs)(`text`,{className:`ob-dim`,x:`40`,y:`58`,children:[e.terminalLabel,` · VOICE · `,t.voice.mode,` LINK · `,typeof location>`u`?``:location.host]}),(0,w.jsxs)(`text`,{className:`ob-lab`,x:`1560`,y:`38`,textAnchor:`end`,children:[a,` · `,o]})]})}function EF({hud:e,state:t,usage:n=null,viewport:r,usageApi:i,send:a=()=>{},onHire:o,onLaunch:s,onExpand:c}){let{w:l,h:u}=DN(r),d=vF(),f=Cw(l,u),p=e.preview===!0&&f===`orbit`,m=MP(p?`full`:e.density,e.widgets,f,t.approval!==null,t.widgets,p),h=p?{...t,stats:lF(Date.now()),voice:{...t.voice,mode:`listening`,level:.85}}:t,g=t.approval!==null,_=t.approval?.needsPin===!0,v=e=>e.id===`approval`?g?`orange`:`cyan`:e.tone,[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(null),[T,E]=(0,y.useState)(!1),D=yF(3e4),O=h.stats&&h.stats.ramTotal>0?Math.round(100*h.stats.ramUsed/h.stats.ramTotal):0,k={cpu:AN(h.stats?Math.round(h.stats.cpu):0,h.stats?.at,60),ram:AN(O,h.stats?.at,60),down:AN(h.stats?.netDown??0,h.stats?.at,60),up:AN(h.stats?.netUp??0,h.stats?.at,60)},A=k.down.slice(-24),j=(0,y.useRef)(null),ee=(0,y.useCallback)(()=>{x(null),C(null),E(!1),mP()&&j.current?.focus(),j.current=null},[]),M=e=>()=>{b===null&&S===null&&!T&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null),C(null),E(!1),x(e),c({kind:`widget`,id:e})};(0,y.useEffect)(()=>{if(b===null&&S===null&&!T||g)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),ee())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[b,S,T,g,ee]);let N=f===`compact`?l-16:Math.max(280,Math.min(760,l*.62)),P={x:(l-N)/2,y:u*.14,width:N,height:Math.max(220,Math.min(560,u*.7))},F=g?null:b,te=F&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-hit`,onPointerDown:e=>{e.stopPropagation(),ee()}}),(0,w.jsx)(EN,{children:(0,w.jsx)(UP,{id:F,state:t,rect:P,readings:k,...i?{usageApi:i}:{},onClose:ee})})]}),ne=t.office.enabled&&!p,re=g||!ne?void 0:t.office.workers.find(e=>e.id===S),I=e=>{b===null&&S===null&&!T&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null),x(null),E(!1),C(e)},ie=ne&&t.office.workers.length>0,ae=()=>{b===null&&S===null&&!T&&(j.current=document.activeElement instanceof HTMLElement?document.activeElement:null),x(null),C(null),E(!0)},oe={...P,x:Math.max(8,P.x-60),width:Math.min(l-16,P.width+120)},se=T&&ie&&!g&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-hit`,onPointerDown:e=>{e.stopPropagation(),ee()}}),(0,w.jsx)(EN,{children:(0,w.jsx)(tF,{workers:t.office.workers,name:t.assistantName||`Friend`,rect:oe,onWorker:I,onClose:ee})})]}),ce=re&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-hit`,onPointerDown:e=>{e.stopPropagation(),ee()}}),(0,w.jsx)(EN,{children:(0,w.jsx)($P,{worker:re,feed:t.office.feed[re.id]??[],rect:P,send:a,onClose:ee})})]}),le=f===`compact`?l-16:Math.max(340,Math.min(480,l*.34)),L=Math.min(u-16,_?Math.max(300,Math.min(520,u*.7)):Math.max(260,Math.min(420,u*.55))),ue={x:(l-le)/2,y:(u-L)/2,width:le,height:L},de=g,R=de&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-backdrop ob-modal-backdrop`}),(0,w.jsx)(EN,{children:(0,w.jsx)(PN,{"data-widget":`approval`,variant:`octagon`,tone:`orange`,title:`Approvals`,running:!0,className:`ob-zone ob-hit ob-static ob-modal`,style:{position:`absolute`,left:ue.x,top:ue.y,width:ue.width,height:ue.height},children:(0,w.jsx)(uF,{approval:t.approval,send:a})})})]}),z={className:`orbital`,"data-testid":`orbital`,"data-mode":f,"data-hud-anim":e.animations,...d?{"data-paused":``}:{}},B=m.some(e=>e.id===`usage`),fe=p?{value:42,reset:null,real:!1}:DP(t.office.quota,n,D.getTime()),pe=e=>{switch(e){case`system`:return(0,w.jsx)(kN,{node:qP(h.stats),children:(0,w.jsx)(ZN,{stats:h.stats})});case`network`:return(0,w.jsx)(kN,{node:YP(h.stats,A),children:(0,w.jsx)($N,{stats:h.stats})});case`radar`:return p?(0,w.jsx)(fF,{deviceOnline:h.deviceOnline,voiceAvailable:h.voice.available,blips:sF}):(0,w.jsx)(kN,{node:ZP(h.deviceOnline,h.voice.available),children:(0,w.jsx)(fF,{deviceOnline:h.deviceOnline,voiceAvailable:h.voice.available})});case`voice`:return(0,w.jsx)(kN,{node:JP(h.voice.level,h.voice.mode),children:(0,w.jsx)(_F,{level:h.voice.level,mode:h.voice.mode})});case`feed`:{let e=ne?TP(t.office.feed,t.office.workers):[],n=p?rF:e.length>0?e:h.chat,r=(0,w.jsx)(LP,{lines:n,activity:h.activity,busy:p||e.length>0?!1:h.busy,marquee:p});if(p)return r;let i=e.length>0?e:h.chat.map(e=>({text:`${e.role===`user`?`You`:`Friend`}: ${e.text}`,tone:`plain`}));return(0,w.jsx)(kN,{node:XP(i,h.activity,h.busy),children:r})}case`tickets`:{if(p)return(0,w.jsx)(mF,{cells:aF,project:`landing-page`});let e=ne?yP(t.office.tickets):[],n=ne?bP(t.office.tickets):void 0;return(0,w.jsx)(kN,{node:QP(e,n),children:(0,w.jsx)(mF,{...ne?{cells:e,...n?{project:n}:{}}:{}})})}case`budget`:return(0,w.jsx)(NP,{...p?{rings:oF}:ne?{rings:SP(t.office.workers)}:{}});default:return null}};if(f===`compact`){let n=e=>(0,w.jsx)(EN,{children:(0,w.jsx)(PN,{"data-widget":e.id,variant:`chamfer`,tone:v(e),title:e.title,className:`ob-zone ob-hit`,style:{minWidth:170,height:100,flex:`none`},role:`button`,tabIndex:0,"aria-label":e.title,onClick:M(e.id),onKeyDown:xF(M(e.id)),children:(0,w.jsx)(`p`,{className:`ob-li`,children:CF(e.id,t)})})},e.id);return(0,w.jsxs)(`div`,{...z,children:[(0,w.jsx)(NN,{}),(0,w.jsxs)(`div`,{className:`ob-chips`,children:[ie&&(0,w.jsxs)(`button`,{type:`button`,className:`ob-chip ob-hit`,onClick:ae,children:[`Team · `,t.office.workers.length]}),ne&&t.office.workers.map(e=>(0,w.jsx)(`button`,{type:`button`,className:`ob-chip ob-hit`,onClick:()=>I(e.id),children:e.name},e.id)),e.launcher.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`ob-chip ob-hit`,onClick:()=>s(e),children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:e.icon}),` `,e.label]},e.id))]}),(0,w.jsx)(`p`,{className:`ob-compact-status`,children:SF(t)}),(0,w.jsxs)(`div`,{className:`ob-strip`,children:[m.filter(e=>e.anchor!==`centre`&&!(e.id===`approval`&&g)).map(n),B&&(0,w.jsx)(wF,{usage:fe.value,reset:fe.reset,real:fe.real,onClick:M(`usage`)})]}),te,ce,se,R]})}let me=_w(l,u),he=Sw(fw,900),ge=e.launcher.map(e=>({id:e.id,label:e.label,glyph:e.icon,caption:e.label,status:`idle`,onClick:()=>s(e)})),V=ne?gP(t.office.workers,!0):[],_e=e=>({id:e.id,label:e.label,glyph:e.glyph,caption:e.caption,status:e.status,onClick:()=>o?.()}),ve=V.map((e,t)=>e.kind===`hire`?_e(e):{id:e.id,label:e.label,glyph:e.glyph,caption:e.caption,status:e.status,detail:e.detail,...nF[t]?{at:nF[t].at}:{},onClick:()=>I(e.id)}),ye=p?nF.map(e=>({id:e.id,label:e.label,glyph:e.label,status:e.status,detail:e.detail,at:e.at,onClick:()=>{}})):ne?t.office.workers.length>0?ve:[...ge,...ve]:ge,H=xw(ye.length,fw,900),be=fe.value,U=(e,t,n)=>{let r=vw(e,0,0,l,u);return(0,w.jsx)(`div`,{className:`ob-canvas ob-canvas-${t}`,style:{left:r.x,top:r.y,width:fw,height:900,transform:`scale(${me})`},children:n})},xe=e=>{let n={left:e.box.x,top:e.box.y,width:e.box.w,height:e.box.h};return e.id===`approval`?de?null:(0,w.jsx)(EN,{children:(0,w.jsx)(`div`,{"data-widget":`approval`,className:`ob-w ob-hit ob-static`,style:n,children:g?(0,w.jsx)(PN,{variant:`octagon`,tone:`orange`,running:!0,className:`ob-approval-frame`,children:(0,w.jsx)(uF,{approval:t.approval,send:a})}):p?(0,w.jsx)(PN,{variant:`octagon`,tone:`orange`,running:!0,className:`ob-approval-frame`,children:(0,w.jsx)(uF,{approval:cF,send:()=>{}})}):(0,w.jsx)(PN,{variant:`bracket`,title:`Approvals`,children:(0,w.jsx)(uF,{approval:null,send:a})})})},e.id):(0,w.jsx)(EN,{children:(0,w.jsx)(`div`,{"data-widget":e.id,className:`ob-w ob-hit`,style:n,role:`button`,tabIndex:0,"aria-label":e.title,onClick:M(e.id),onKeyDown:xF(M(e.id)),children:pe(e.id)})},e.id)},Se=e=>m.filter(t=>t.anchor===e),Ce=(t.assistantName||`FRIEND`).toUpperCase(),we=Math.min(1,Math.max(0,t.voice.level,t.presence.amplitude)),Te=vw(`centre`,0,0,l,u);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-base`,"aria-hidden":`true`,children:(0,w.jsx)(`div`,{className:`ob-canvas`,style:{left:Te.x,top:Te.y,width:fw,height:900,transform:`scale(${me})`},children:(0,w.jsx)(`svg`,{className:`ob-scene`,width:fw,height:900,viewBox:`0 0 ${fw} 900`,children:(0,w.jsx)(`g`,{className:`ob-disc-wrap`,style:{transform:`scale(${Number((1+.18*we).toFixed(3))})`},children:(0,w.jsx)(`circle`,{className:`ob-disc ob-breathe`,cx:he.cx,cy:he.cy,r:`104`,fill:`url(#ob-orbg)`,filter:`url(#ob-glow2)`})})})})}),(0,w.jsxs)(`div`,{...z,style:{"--s":me},children:[(0,w.jsx)(NN,{}),(0,w.jsx)(`div`,{className:`ob-bg`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-tl`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-tr`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-bl`,"aria-hidden":`true`}),(0,w.jsx)(`span`,{className:`ob-corner ob-br`,"aria-hidden":`true`}),U(`centre`,`centre`,(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`svg`,{className:`ob-scene`,width:fw,height:900,viewBox:`0 0 ${fw} 900`,"aria-hidden":`true`,children:[(0,w.jsx)(EN,{children:(0,w.jsx)(TF,{hud:e,state:h,preview:p})}),(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`104`,className:`ob-orb-ring`}),(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`104`,className:`ob-ping`}),(0,w.jsx)(`g`,{className:`ob-spin ob-fast`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`128`,className:`ob-ring-dash`})}),(0,w.jsx)(`g`,{className:`ob-spin ob-reverse`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`150`,className:`ob-ring-long`})}),(0,w.jsx)(`g`,{className:`ob-spin`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`172`,className:`ob-ring-thin`})}),(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:300,className:`ob-orbit`}),(0,w.jsx)(`g`,{className:`ob-spin ob-reverse ob-slow`,children:(0,w.jsx)(`circle`,{cx:he.cx,cy:he.cy,r:`330`,className:`ob-ring-outer`})}),H.map((e,t)=>{let n={x:Math.cos(e.angle*Math.PI/180),y:Math.sin(e.angle*Math.PI/180)};return(0,w.jsx)(YN,{tone:ye[t].status===`waiting`?`orange`:`cyan`,x1:he.cx+n.x*104,y1:he.cy+n.y*104,x2:he.cx+n.x*266,y2:he.cy+n.y*266},ye[t].id)}),ye.map(e=>e.at&&e.detail&&(0,w.jsx)(`text`,{className:`ob-node-detail${e.status===`running`?` ob-grn`:e.status===`waiting`?` ob-org`:``}`,x:e.at.x,y:e.at.y,textAnchor:e.at.anchor,children:e.detail},e.id))]}),ie&&(0,w.jsxs)(`button`,{type:`button`,className:`ob-team-btn ob-hit`,style:{left:he.cx,top:he.cy+52},onClick:ae,children:[`TEAM · `,t.office.workers.length]}),(0,w.jsxs)(`div`,{className:`ob-orb-label`,style:{left:he.cx,top:he.cy},"aria-hidden":`true`,children:[(0,w.jsx)(`b`,{children:Ce}),(0,w.jsx)(`small`,{children:wP(t.voice.mode,p?{enabled:!1,workers:[]}:t.office)})]}),B&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`ob-usage-ring`,style:{left:he.cx-230,top:he.cy-230,width:460,height:460},children:(0,w.jsx)(KN,{value:be??0,radius:205,size:460})}),(0,w.jsx)(wF,{usage:be,reset:fe.reset,real:fe.real,style:{position:`absolute`,left:800,top:692,transform:`translate(-50%, -50%)`},onClick:M(`usage`)})]}),H.map((e,t)=>{let n=ye[t];return(0,w.jsx)(EN,{children:(0,w.jsx)(JN,{x:e.x,y:e.y,label:n.label,glyph:n.glyph,status:n.status,...n.caption?{caption:n.caption}:{},...n.detail?{detail:n.detail}:{},onClick:n.onClick})},n.id)}),(0,w.jsx)(`div`,{className:`ob-cmd`,"aria-hidden":`true`,children:(0,w.jsx)(`small`,{children:`[ HOLD TO TALK ]`})})]})),U(`left`,`left`,Se(`left`).map(xe)),U(`right`,`right`,Se(`right`).map(xe)),te,ce,se,R]})]})}var DF=3e5,OF=(e=new Date)=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,kF={today:0,peak:0,share:null,error:!1};function AF(e=kC,t=!0){let[n,r]=(0,y.useState)(kF);return(0,y.useEffect)(()=>{if(!t)return;let n=!0,i=()=>e.summary(30).then(e=>{if(!n)return;let t=e.days.map(e=>({day:e.day,n:e.input+e.output})),i=Math.max(0,...t.map(e=>e.n)),a=t.find(e=>e.day===OF())?.n??0;r({today:a,peak:i,share:i>0?Math.min(1,Math.max(0,a/i)):null,error:!1})}).catch(()=>n&&r({...kF,error:!0}));i();let a=setInterval(()=>void i(),DF);return()=>{n=!1,clearInterval(a)}},[e,t]),n}var jF=(e,t=18)=>(0,w.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:e}),MF=()=>jF((0,w.jsx)(`path`,{d:`M7 4.5v15l12-7.5z`,fill:`currentColor`})),NF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,fill:`currentColor`}),(0,w.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,fill:`currentColor`})]})),PF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M5 5v14l10-7z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`M18 5v14`})]})),FF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M19 5v14L9 12z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`M6 5v14`})]})),IF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M3 7h3.5c3 0 4 2 5.5 5s2.500 5 5.500 5H21`}),(0,w.jsx)(`path`,{d:`M3 17h3.5c1.500 0 2.500-.6 3.400-1.800M13.500 8.800C14.500 7.600 15.500 7 17 7h4`}),(0,w.jsx)(`path`,{d:`m18.500 4.500 2.500 2.500-2.500 2.500M18.500 14.500l2.500 2.500-2.500 2.500`})]})),LF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M17 3l3 3-3 3`}),(0,w.jsx)(`path`,{d:`M4 11V9a3 3 0 0 1 3-3h13M7 21l-3-3 3-3`}),(0,w.jsx)(`path`,{d:`M20 13v2a3 3 0 0 1-3 3H4`})]})),RF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M4 9.500v5h3.500L12 18.500v-13L7.500 9.500z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`M15.500 9a4 4 0 0 1 0 6M18 6.500a7.500 7.500 0 0 1 0 11`})]})),zF=()=>jF((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`path`,{d:`M4 9.500v5h3.500L12 18.500v-13L7.500 9.500z`,fill:`currentColor`}),(0,w.jsx)(`path`,{d:`m16 9 5 6M21 9l-5 6`})]})),BF=()=>jF((0,w.jsx)(`path`,{d:`M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5`})),VF=()=>jF((0,w.jsx)(`path`,{d:`M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5`})),HF=()=>jF((0,w.jsx)(`path`,{d:`M6 6l12 12M18 6 6 18`})),UF=()=>jF((0,w.jsx)(`path`,{d:`M9 18V6l10-2v12`}),22),WF=56,GF=()=>({bars:new Float32Array(WF),bass:0,left:0,right:0});function KF(e,t,n,r,i){let a=n?.82:.9;if(t&&n){t.getByteFrequencyData(i);let n=Math.min(i.length,96);for(let t=0;t<WF;t++){let r=Math.min(n-1,Math.floor((t/WF)**1.6*n));e.bars[t]=Math.max((i[r]??0)/255,e.bars[t]*a)}}else if(n)for(let t=0;t<WF;t++)e.bars[t]=Math.max(.12+.28*Math.abs(Math.sin(r/420+t*.55)*Math.cos(r/900+t*.21)),e.bars[t]*a);else for(let t=0;t<WF;t++)e.bars[t]=e.bars[t]*a;let o=0;for(let t=0;t<6;t++)o+=e.bars[t];e.bass=Math.min(1,o/6*1.15);let s=0,c=0;for(let t=0;t<WF/2;t++)s+=e.bars[t],c+=e.bars[t+WF/2];e.left=Math.min(1,s/(WF/2)*1.6),e.right=Math.min(1,c/(WF/2)*3.2)}function qF({progress:e,playing:t,cover:n,analyser:r,levels:i,visualizer:a,animate:o,size:s}){let c=(0,y.useRef)(null),l=(0,y.useRef)(null),u=(0,y.useRef)(new Uint8Array(new ArrayBuffer(128)));(0,y.useEffect)(()=>{let e=c.current,n=e?.getContext(`2d`);if(!e||!n||!o)return;let d=0,f=Math.min(2,window.devicePixelRatio||1);e.width=e.height=Math.round(s*f);let p=getComputedStyle(e).getPropertyValue(`--accent`).trim()||`#3fd8ff`,m=e=>{if(KF(i,r,t,e,u.current),l.current?.style.setProperty(`--bass`,i.bass.toFixed(3)),n.setTransform(f,0,0,f,0,0),n.clearRect(0,0,s,s),a){let e=s/2,t=s*.335,r=s*.135;n.lineCap=`round`,n.lineWidth=Math.max(1.5,s/90);for(let a=0;a<WF;a++){let o=a/WF*Math.PI*2-Math.PI/2,s=i.bars[a],c=2+s*r;n.strokeStyle=p,n.globalAlpha=.35+s*.65,n.beginPath(),n.moveTo(e+Math.cos(o)*t,e+Math.sin(o)*t),n.lineTo(e+Math.cos(o)*(t+c),e+Math.sin(o)*(t+c)),n.stroke()}n.globalAlpha=1}(t||!i.bars.every(e=>e<.01)||a)&&(d=requestAnimationFrame(m))};return d=requestAnimationFrame(m),()=>cancelAnimationFrame(d)},[r,t,a,o,s,i]);let d=Math.max(0,Math.min(1,e))*100;return(0,w.jsxs)(`div`,{ref:l,className:`hud-dial${t?` playing`:``}`,style:{width:s,height:s},role:`img`,"aria-label":`Playback dial`,children:[(0,w.jsxs)(`svg`,{className:`hud-dial-svg`,viewBox:`0 0 200 200`,"aria-hidden":`true`,children:[(0,w.jsx)(`circle`,{className:`hud-dial-ticks`,cx:`100`,cy:`100`,r:`96`}),(0,w.jsx)(`circle`,{className:`hud-dial-track`,cx:`100`,cy:`100`,r:`88`}),(0,w.jsx)(`circle`,{className:`hud-dial-arc`,cx:`100`,cy:`100`,r:`88`,pathLength:`100`,strokeDasharray:`${d} 100`,transform:`rotate(-90 100 100)`}),(0,w.jsx)(`circle`,{className:`hud-dial-inner`,cx:`100`,cy:`100`,r:`62`}),(0,w.jsxs)(`g`,{className:`hud-needle`,children:[(0,w.jsx)(`line`,{x1:`100`,y1:`100`,x2:`100`,y2:`14`}),(0,w.jsx)(`circle`,{cx:`100`,cy:`14`,r:`2.500`})]})]}),(0,w.jsx)(`canvas`,{ref:c,className:`hud-spectrum`,style:{width:s,height:s},"aria-hidden":`true`}),(0,w.jsx)(`div`,{className:`hud-cover`,style:n?{backgroundImage:`url("${n}")`}:void 0,children:!n&&(0,w.jsx)(UF,{})})]})}var JF=e=>{let t=Math.max(0,Math.floor(Number.isFinite(e)?e:0));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},YF=new Map,XF=e=>{let t=pd(e);return t&&t.source===`local`?t.id:null},ZF=e=>pd(e)?.source===`spotify`,QF=e=>pd(e)?.source===`soundcloud`,$F=e=>pd(e)?.source===`audius`,eI={spotify:`Spotify`,soundcloud:`SoundCloud`,audius:`Audius`};function tI(e){let[t,n]=(0,y.useState)(e?YF.get(e)??!1:!1);return(0,y.useEffect)(()=>{if(!e)return n(!1);if(YF.has(e))return n(YF.get(e));let t=!0,r=new Image;r.onload=()=>{YF.set(e,!0),t&&n(!0)},r.onerror=()=>{YF.set(e,!1),t&&n(!1)};let i=XF(e);return i?(r.src=`/api/music/cover/${i}`,()=>{t=!1}):n(!1)},[e]),e&&t?`/api/music/cover/${XF(e)}`:null}async function nI(e,t){let n=await fetch(`/api/music/library?q=${encodeURIComponent(e)}&limit=${t}`);return n.ok?await n.json():{tracks:[],total:0}}function rI(){let[e,t]=(0,y.useState)(null);return(0,y.useEffect)(()=>{let e=!0;return fetch(`/api/music/sources`).then(e=>e.ok?e.json():null).then(n=>{let r={};for(let e of[`spotify`,`soundcloud`,`audius`]){let t=n?.sources?.find(t=>t.id===e)?.status;t&&(r[e]={connected:t.connected,needs:t.needs})}e&&n&&t(r)}).catch(()=>{}),()=>{e=!1}},[]),e}async function iI(e,t,n){let r=await fetch(`/api/music/search?q=${encodeURIComponent(t)}&source=${e}&limit=${n}`);if(!r.ok)return{tracks:[],total:0};let i=((await r.json()).tracks??[]).map(e=>({id:e.ref,title:e.title,artist:e.artist,album:e.album,durationSec:e.durationSec}));return{tracks:i,total:i.length}}var aI=e=>({id:e.id,title:e.title,artist:e.artist,album:e.album,durationSec:e.durationSec});function oI({levels:e,animate:t,side:n}){let r=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!t)return;let i=0,a=r.current,o=()=>{if(a){let t=n===`left`?e.left:e.right,r=Math.round(t*12);a.querySelectorAll(`i`).forEach((e,t)=>e.classList.toggle(`on`,t<r))}i=requestAnimationFrame(o)};return i=requestAnimationFrame(o),()=>cancelAnimationFrame(i)},[e,t,n]),(0,w.jsx)(`div`,{ref:r,className:`hud-levels ${n}`,"aria-hidden":`true`,children:Array.from({length:12},(e,t)=>(0,w.jsx)(`i`,{},t))})}function sI({player:e,anim:t}){let{state:n,dispatch:r}=e,i=(0,y.useCallback)(async()=>{if(n.queue.length>0)return r({type:`resume`});let e=await nI(``,500);r({type:`play`,tracks:e.tracks.map(aI),mode:`replace`,...n.shuffle?{shuffle:!0}:{}})},[n.queue.length,n.shuffle,r]),a=e=>n=>{t!==`off`&&wN(n),e()};return(0,w.jsxs)(`div`,{className:`hud-controls`,role:`group`,"aria-label":`Player controls`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Shuffle`,"aria-pressed":n.shuffle,title:`Shuffle`,onClick:()=>r({type:`shuffle`}),children:(0,w.jsx)(IF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Previous track`,title:`Previous`,onPointerDown:a(()=>{}),onClick:()=>r({type:`previous`}),children:(0,w.jsx)(FF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn hud-btn-main`,"aria-label":n.playing?`Pause`:`Play`,title:n.playing?`Pause`:`Play`,onPointerDown:a(()=>{}),onClick:()=>n.playing?r({type:`pause`}):void i(),children:n.playing?(0,w.jsx)(NF,{}):(0,w.jsx)(MF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Next track`,title:`Next`,onPointerDown:a(()=>{}),onClick:()=>r({type:`next`}),children:(0,w.jsx)(PF,{})}),(0,w.jsxs)(`button`,{type:`button`,className:`hud-btn${n.repeat===`off`?``:` on`}`,"aria-label":`Repeat: ${n.repeat}`,title:`Repeat: ${n.repeat}`,onClick:()=>r({type:`repeat`,mode:n.repeat===`off`?`all`:n.repeat===`all`?`one`:`off`}),children:[(0,w.jsx)(LF,{}),n.repeat===`one`&&(0,w.jsx)(`sup`,{children:`1`})]})]})}function cI({player:e}){let{state:t,dispatch:n}=e,r=t.duration>0?t.position/t.duration*100:0;return(0,w.jsxs)(`div`,{className:`hud-timeline`,children:[(0,w.jsx)(`span`,{className:`hud-time`,children:JF(t.position)}),(0,w.jsx)(`input`,{type:`range`,className:`hud-range`,"aria-label":`Position`,min:0,max:Math.max(1,Math.floor(t.duration)),step:1,value:Math.min(Math.floor(t.position),Math.max(1,Math.floor(t.duration))),style:{"--fill":`${r}%`},disabled:t.duration<=0,onChange:e=>n({type:`seek`,seconds:Number(e.target.value)})}),(0,w.jsxs)(`span`,{className:`hud-time`,children:[`-`,JF(Math.max(0,t.duration-t.position))]})]})}function lI({player:e}){let{state:t,dispatch:n}=e;return(0,w.jsxs)(`div`,{className:`hud-volume`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":t.muted?`Unmute`:`Mute`,onClick:()=>n({type:`mute`}),children:t.muted||t.volume===0?(0,w.jsx)(zF,{}):(0,w.jsx)(RF,{})}),(0,w.jsx)(`input`,{type:`range`,className:`hud-range`,"aria-label":`Volume`,min:0,max:100,value:t.muted?0:t.volume,style:{"--fill":`${t.muted?0:t.volume}%`},onChange:e=>n({type:`volume`,level:Number(e.target.value)})})]})}function uI({player:e,anim:t}){let{state:n,dispatch:r}=e,[i,a]=(0,y.useState)(n.queue.length?`queue`:`library`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`folder`),[u,d]=(0,y.useState)(null),f=rI(),p=[`spotify`,`soundcloud`,`audius`].filter(e=>f?.[e]?.connected),m=c!==`folder`&&p.includes(c)?c:null,h=m?f?.[m]?.needs:null;(0,y.useEffect)(()=>{if(i!==`library`)return;let e=!0;if(m&&!o.trim()){d(null);return}let t=()=>m?iI(m,o.trim(),30):nI(o,100),n=setTimeout(()=>void t().then(t=>e&&d(t)),o?250:0);return()=>{e=!1,clearTimeout(n)}},[i,o,m]);let g=i===`queue`?n.queue.map((e,t)=>({track:e,index:t})):(u?.tracks??[]).map((e,t)=>({track:aI(e),index:t}));return(0,w.jsxs)(`div`,{className:`hud-playlist`,children:[(0,w.jsxs)(`div`,{className:`hud-tabs`,role:`tablist`,children:[[`queue`,`library`].map(e=>(0,w.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":i===e,className:`hud-chip${i===e?` on`:``}`,onClick:()=>a(e),children:e===`queue`?`Queue (${n.queue.length})`:`Library`},e)),i===`queue`&&n.queue.length>0&&(0,w.jsx)(`button`,{type:`button`,className:`hud-chip`,onClick:()=>r({type:`clear`}),children:`Clear`})]}),i===`library`&&p.length>0&&(0,w.jsx)(`div`,{className:`hud-tabs`,role:`tablist`,"aria-label":`Where to look`,children:[`folder`,...p].map(e=>(0,w.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":c===e,className:`hud-chip${c===e?` on`:``}`,onClick:()=>{l(e),d(null)},children:e===`folder`?`Folder`:eI[e]},e))}),i===`library`&&(0,w.jsx)(`input`,{className:`hud-search`,type:`search`,placeholder:`Search title, artist or album`,"aria-label":`Search the music`,value:o,onChange:e=>s(e.target.value)}),(0,w.jsxs)(`ul`,{className:`hud-list`,children:[g.length===0&&(0,w.jsx)(`li`,{className:`hud-empty`,children:i===`queue`?`The queue is empty.`:m&&!o.trim()?`Type to search ${eI[m]}.`:u?`No music matches.`:`Loading…`}),i===`library`&&m&&h&&(0,w.jsx)(`li`,{className:`hud-empty`,children:h}),g.map(({track:e,index:a},o)=>{let s=i===`queue`&&a===n.index;return(0,w.jsxs)(`li`,{className:`hud-tab hud-cut${s?` current`:``}${t===`full`?` hud-boot`:``}`,style:{"--i":Math.min(o,12)},children:[(0,w.jsxs)(`button`,{type:`button`,className:`hud-tab-main`,"aria-current":s?`true`:void 0,onPointerDown:t===`off`?void 0:wN,onClick:()=>r(i===`queue`?{type:`jump`,index:a}:{type:`play`,tracks:(u?.tracks??[]).map(aI),mode:`replace`,start:a}),children:[(0,w.jsx)(`span`,{className:`hud-tab-title`,children:e.title}),(0,w.jsxs)(`small`,{children:[e.artist||e.album,ZF(e.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SPOTIFY`}),QF(e.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SOUNDCLOUD`}),$F(e.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`AUDIUS`})]})]}),i===`library`&&(0,w.jsx)(`button`,{type:`button`,className:`hud-mini`,"aria-label":`Add ${e.title} to the queue`,title:`Add to the queue`,onClick:()=>r({type:`play`,tracks:[e],mode:`add`}),children:`+`}),i===`queue`&&(0,w.jsx)(`button`,{type:`button`,className:`hud-mini`,"aria-label":`Remove ${e.title} from the queue`,title:`Remove`,onClick:()=>r({type:`remove`,index:a}),children:`×`})]},`${e.id}-${a}`)})]})]})}function dI({player:e,music:t,animations:n}){let{state:r,dispatch:i,current:a,blocked:o,notice:s,analyser:c,unlock:l}=e,u=(0,y.useMemo)(GF,[]),d=tI(a?.id),f=r.view===`full`,p=CN(a?.title??``,n===`full`);if(!t?.folderSet||r.view===`hidden`)return null;let m=r.duration>0?r.position/r.duration:0,h=n!==`off`;return(0,w.jsxs)(Ce,{id:`music`,label:`Music player`,wholeBox:!0,testId:`music`,className:`hud hud-music hud-cut ${f?`full`:`mini`}${r.playing?` playing`:``}${n===`full`?` hud-boot`:``}`,children:[(0,w.jsxs)(`header`,{className:`hud-music-head`,children:[(0,w.jsx)(`span`,{className:`hud-kicker`,children:`Media player`}),(0,w.jsxs)(`span`,{className:`hud-head-actions`,children:[(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":f?`Smaller player`:`Bigger player`,title:f?`Smaller`:`Bigger`,onClick:()=>i({type:`view`,view:f?`mini`:`full`}),children:f?(0,w.jsx)(VF,{}):(0,w.jsx)(BF,{})}),(0,w.jsx)(`button`,{type:`button`,className:`hud-btn`,"aria-label":`Hide the player`,title:`Hide (the music keeps playing)`,onClick:()=>i({type:`view`,view:`hidden`}),children:(0,w.jsx)(HF,{})})]})]}),(0,w.jsxs)(`div`,{className:`hud-music-body`,children:[(0,w.jsxs)(`div`,{className:`hud-music-left`,children:[f&&(0,w.jsx)(oI,{levels:u,animate:h,side:`left`}),(0,w.jsx)(qF,{progress:m,playing:r.playing,cover:d,analyser:c,levels:u,visualizer:t.visualizer,animate:h,size:f?250:112}),f&&(0,w.jsx)(oI,{levels:u,animate:h,side:`right`})]}),(0,w.jsxs)(`div`,{className:`hud-music-main`,children:[(0,w.jsxs)(`div`,{className:`hud-now`,"aria-live":`polite`,children:[(0,w.jsx)(`b`,{className:`hud-title`,children:a?p:`Nothing playing`}),(0,w.jsxs)(`small`,{className:`hud-sub`,children:[a?[a.artist,a.album].filter(Boolean).join(` — `):`Press play, or ask for some music.`,a&&ZF(a.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SPOTIFY`}),a&&QF(a.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`SOUNDCLOUD`}),a&&$F(a.id)&&(0,w.jsx)(`em`,{className:`hud-source`,children:`AUDIUS`}),e.remote&&(0,w.jsx)(`em`,{className:`hud-source`,children:`THIS PC`})]})]}),(0,w.jsx)(cI,{player:e}),(0,w.jsx)(sI,{player:e,anim:n}),f&&(0,w.jsx)(lI,{player:e}),s&&(0,w.jsx)(`p`,{className:`hud-notice`,role:`status`,children:s}),o&&(0,w.jsx)(`button`,{type:`button`,className:`hud-unlock`,onClick:l,children:`Tap to enable sound`})]}),f&&(0,w.jsx)(uI,{player:e,anim:n})]})]})}var fI=/^spotify:/,pI=class{local;makeSpotify;active;spotify=null;listeners=new Map;wrapped=new Map;vol=1;mute=!1;pre=``;constructor(e,t){this.local=e,this.makeSpotify=t,this.active=e}get element(){return this.local}get error(){return this.active.error??null}wrap(e){let t=this.wrapped.get(e);return t||(t={local:()=>{this.active===this.local&&e()},spot:()=>{this.spotify&&this.active===this.spotify&&e()}},this.wrapped.set(e,t)),t}spot(){if(!this.spotify){let e=this.makeSpotify();e.volume=this.vol,e.muted=this.mute,e.preload=this.pre;for(let[t,n]of this.listeners)for(let r of n)e.addEventListener(t,this.wrap(r).spot);this.spotify=e}return this.spotify}dispose(){this.spotify?.dispose?.(),this.spotify=null,this.active=this.local}get src(){return this.active.src}set src(e){let t=fI.test(e)?this.spot():this.local;t===this.active?e===``&&this.active.pause():(this.active.pause(),this.active=t),this.active.src=e}get currentTime(){return this.active.currentTime}set currentTime(e){this.active.currentTime=e}get duration(){return this.active.duration}get paused(){return this.active.paused}get volume(){return this.vol}set volume(e){this.vol=e,this.local.volume=e,this.spotify&&(this.spotify.volume=e)}get muted(){return this.mute}set muted(e){this.mute=e,this.local.muted=e,this.spotify&&(this.spotify.muted=e)}get preload(){return this.pre}set preload(e){this.pre=e,this.local.preload=e,this.spotify&&(this.spotify.preload=e)}play(){return this.active.play()}pause(){this.active.pause()}addEventListener(e,t){let n=this.listeners.get(e);n||this.listeners.set(e,n=new Set),n.add(t);let r=this.wrap(t);this.local.addEventListener(e,r.local),this.spotify?.addEventListener(e,r.spot)}removeEventListener(e,t){this.listeners.get(e)?.delete(t);let n=this.wrap(t);this.local.removeEventListener(e,n.local),this.spotify?.removeEventListener(e,n.spot)}},mI=/^spotify:([A-Za-z0-9_-]{1,64})$/,hI=`Spotify Premium is needed to play on this screen.`;async function gI(){let e=await fetch(`/api/music/spotify/token`,{cache:`no-store`});if(!e.ok)throw Error(`Spotify is not connected.`);return(await e.json()).accessToken}function _I(){let e=window;return e.Spotify?Promise.resolve(e.Spotify):new Promise((t,n)=>{e.onSpotifyWebPlaybackSDKReady=()=>e.Spotify?t(e.Spotify):n(Error(`no sdk`));let r=document.createElement(`script`);r.src=`https://sdk.scdn.co/spotify-player.js`,r.async=!0,r.onerror=()=>n(Error(`blocked`)),document.head.appendChild(r)})}function vI(e){let t=e.fetch??((...e)=>fetch(...e)),n=e.now??Date.now,r=new Map,i=null,a=null,o=null,s=null,c=!1,l=null,u=null,d=0,f=0,p=0,m=!0,h=1,g=!1,_,v=e=>{for(let t of r.get(e)??[])t()},y=()=>g?0:h,b=()=>{_&&clearInterval(_),_=void 0},x=()=>{_||=setInterval(()=>v(`timeupdate`),250)},S={error:null,preload:``,get src(){return s??``},set src(e){let t=mI.exec(e);c=e!==``&&!t,s=t?e:null,l=null,u=null,d=0,p=0,S.error=null,t||b()},get currentTime(){return m?d:d+(n()-f)/1e3},set currentTime(e){d=e,f=n(),i?.seek(Math.round(e*1e3)).catch(()=>{})},get duration(){return p},get paused(){return m},get volume(){return h},set volume(e){h=e,i?.setVolume(y()).catch(()=>{})},get muted(){return g},set muted(e){g=e,i?.setVolume(y()).catch(()=>{})},async play(){if(c||!s)throw Error(`That is not a Spotify track.`);let r=mI.exec(s),a=s,o=await T();if(s!==a)return;if(l===s){await i?.resume().catch(()=>{}),m=!1,f=n(),x();return}let u=await e.getToken().catch(()=>null);if(!u)throw C(`Spotify is not connected. Connect it in Plugins, Spotify.`);let d;try{d=await t(`https://api.spotify.com/v1/me/player/play?device_id=${encodeURIComponent(o)}`,{method:`PUT`,headers:{authorization:`Bearer ${u}`,"content-type":`application/json`},body:JSON.stringify({uris:[`spotify:track:${r[1]}`]})})}catch{throw C(`Friend could not reach Spotify right now.`)}if(d.status===403)throw C(hI);if(d.status===401)throw C(`Spotify sign-in has ended. Reconnect Spotify in Plugins, Spotify.`);if(d.status===404)throw C(`Spotify could not find this screen or that track.`);if(d.status===429)throw C(`Spotify is asking Friend to slow down. Try again in a minute.`);if(!d.ok)throw C(`Spotify could not play that.`);s===a&&(l=a,m=!1,f=n(),x())},pause(){m=!0,d+=(n()-f)/1e3,f=n(),b(),i?.pause().catch(()=>{})},dispose(){b();try{i?.disconnect()}catch{}i=null,a=null,s=null,l=null},addEventListener(e,t){let n=r.get(e);n||r.set(e,n=new Set),n.add(t)},removeEventListener(e,t){r.get(e)?.delete(t)}};function C(e){S.error=e,m=!0,b(),v(`error`);let t=Error(e),n=o;return o=null,n?.reject(t),t}function w(e){if(!e)return;d=e.position/1e3,f=n(),p=e.duration/1e3,m=e.paused,v(`timeupdate`),v(`loadedmetadata`),v(`durationchange`);let t=s?mI.exec(s)?.[1]:void 0;t&&e.paused&&e.position===0&&u!==s&&(e.track_window.previous_tracks??[]).some(e=>e.id===t)&&(u=s,b(),v(`ended`))}function T(){if(a)return Promise.resolve(a);if(o)return o.promise;let t,n,r=new Promise((e,r)=>{t=e,n=r}),s={promise:r,resolve:t,reject:n};o=s;let c=setTimeout(()=>{o===s&&C(`Spotify's player did not start. Check that this browser allows Spotify's player, then try again.`)},e.readyTimeoutMs??15e3),l=()=>clearTimeout(c);return r.then(l,l),(async()=>{try{if(!i){let t;try{t=await(e.loadSdk??_I)()}catch{o===s&&C(`Spotify's player could not be loaded. Check that nothing blocks sdk.scdn.co.`);return}let n=new t.Player({name:e.deviceName??`Friend`,volume:y(),getOAuthToken:t=>{e.getToken().then(t,()=>{})}});i=n,n.addListener(`ready`,(e=>{a=e.device_id;let t=o;o=null,t?.resolve(e.device_id)})),n.addListener(`not_ready`,(()=>{a=null})),n.addListener(`player_state_changed`,(e=>w(e))),n.addListener(`account_error`,(()=>void C(hI))),n.addListener(`authentication_error`,(()=>void C(`Spotify sign-in has ended. Reconnect Spotify in Plugins, Spotify.`))),n.addListener(`initialization_error`,(()=>void C(`Spotify's player does not work in this browser.`))),n.addListener(`playback_error`,(()=>void C(`Spotify could not play that.`)))}!await i.connect()&&o===s&&C(`Spotify's player could not connect.`)}catch{o===s&&C(`Spotify's player could not connect.`)}})(),r}return S}var yI=e=>{let t=pd(e);return t?t.source===`local`?`/api/music/track/${t.id}`:t.source===`soundcloud`||t.source===`audius`?`/api/music/stream/${e}`:e:`/api/music/track/${e}`},bI=(e,t)=>Id(e,t),xI=`friend.music`,SI=1e3,CI=1.5,wI=()=>{try{return JSON.parse(localStorage.getItem(xI)??`{}`)}catch{return{}}},TI=e=>{try{localStorage.setItem(xI,JSON.stringify({volume:e.volume,muted:e.muted,shuffle:e.shuffle,repeat:e.repeat,view:e.view}))}catch{}};function EI({music:e,cmd:t,send:n,connection:r,createAudio:i,createSpotify:a,remote:o=!1}){let[s,c]=(0,y.useReducer)(bI,void 0,()=>{let e=wI();return Md({volume:e.volume??70,shuffle:e.shuffle??!1,repeat:e.repeat??`all`,view:e.view??`mini`})}),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=(0,y.useRef)(!1),_=(0,y.useRef)(s);_.current=s;let v=(0,y.useRef)(!1),b=(0,y.useRef)(null),x=(0,y.useRef)(0),S=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!e||S.current)return;S.current=!0;let t=wI();c({type:`volume`,level:t.volume??e.volume}),c({type:`repeat`,mode:t.repeat??e.repeat}),(t.shuffle??e.shuffle)&&c({type:`shuffle`,on:!0}),c({type:`view`,view:t.view??e.startView}),t.muted&&c({type:`mute`,on:!0})},[e]);let C=()=>{if(!h.current){let e=new pI(i?i():new Audio,a??(()=>vI({getToken:gI})));e.preload=`auto`,h.current=e}return h.current},w=(0,y.useRef)(!1),T=(0,y.useCallback)(()=>{let e=h.current;if(e&&e.src){w.current=!0;try{let t=e.play();t&&typeof t.then==`function`?t.then(()=>{w.current=!1,u(!1)},()=>{w.current=!1;let e=h.current?.error??null;e?f(e):u(!0)}):(w.current=!1,u(!1))}catch{w.current=!1,u(!0)}E.current||O()}},[]),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=()=>{let e=h.current,t=e instanceof pI?e.element:e,n=typeof window<`u`?window.AudioContext??window.webkitAudioContext:void 0;if(t&&n&&typeof t.play==`function`)try{let e=new n;D.current=e;let r=e.createMediaElementSource(t),i=e.createAnalyser();i.fftSize=256,i.smoothingTimeConstant=.82,r.connect(i),i.connect(e.destination),E.current=!0,m(i)}catch{E.current=!0}};(0,y.useEffect)(()=>{if(o)return;let e=C(),t=0,n=()=>{let n=Date.now();n-t<250||(t=n,c({type:`time`,position:e.currentTime||0,duration:Number.isFinite(e.duration)?e.duration:0}))},r=()=>c({type:`time`,position:e.currentTime||0,duration:Number.isFinite(e.duration)?e.duration:0}),i=()=>c({type:`ended`}),a=()=>{let t=e.error??null;f(t),c(t?{type:`pause`}:{type:`failed`})};return e.addEventListener(`timeupdate`,n),e.addEventListener(`loadedmetadata`,r),e.addEventListener(`durationchange`,r),e.addEventListener(`ended`,i),e.addEventListener(`error`,a),()=>{e.removeEventListener(`timeupdate`,n),e.removeEventListener(`loadedmetadata`,r),e.removeEventListener(`durationchange`,r),e.removeEventListener(`ended`,i),e.removeEventListener(`error`,a),e.pause(),D.current?.close().catch(()=>{}),D.current=null,e.dispose(),b.current=null,h.current=null,E.current=!1,m(null)}},[o]),(0,y.useEffect)(()=>{o&&c({type:`stop`})},[o]);let k=s.index>=0?s.queue[s.index]??null:null;(0,y.useEffect)(()=>{let e=h.current;if(o||!e)return;let t=k?.id??null;if(t!==b.current){if(b.current=t,!t){e.pause(),e.src=``;return}f(null),e.src=yI(t),s.playing&&T()}},[k?.id,s.playing,T,o]),(0,y.useEffect)(()=>{let e=h.current;!o&&e&&e.src&&(s.playing&&e.paused&&!g.current&&!w.current?T():!s.playing&&!e.paused&&e.pause())},[s.playing,s.position,T,o]),(0,y.useEffect)(()=>{let e=h.current;e&&(e.volume=s.volume/100*EO.level,e.muted=s.muted)},[s.volume,s.muted]),(0,y.useEffect)(()=>EO.subscribe(e=>{let t=h.current;t&&(t.volume=_.current.volume/100*e)}),[]),(0,y.useEffect)(()=>{let e=h.current;e&&e.src&&Math.abs((e.currentTime||0)-s.position)>CI&&(e.currentTime=s.position)},[s.position]),(0,y.useEffect)(()=>TI(s),[s.volume,s.muted,s.shuffle,s.repeat,s.view]),(0,y.useEffect)(()=>{if(!t||t.n===x.current)return;x.current=t.n;let e=Ld(t.command);e&&c(e)},[t]),(0,y.useEffect)(()=>{let e=()=>{v.current=!0,g.current&&T()};return window.addEventListener(`pointerdown`,e,{passive:!0}),window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,e)}},[T]),g.current=l;let A=(0,y.useRef)(0);return(0,y.useEffect)(()=>{if(r!==`open`||o)return;let e=()=>{let e=_.current,t=e.index>=0?e.queue[e.index]:void 0;A.current=Date.now(),n({type:`music.state`,state:{playing:e.playing,trackId:t?.id??null,title:t?.title??``,artist:t?.artist??``,album:t?.album??``,position:e.position,duration:e.duration,volume:e.volume,muted:e.muted,shuffle:e.shuffle,repeat:e.repeat,view:e.view,queue:e.queue.slice(0,50).map(e=>({id:e.id,title:e.title.slice(0,200)})),index:e.index,active:(typeof document>`u`||document.visibilityState===`visible`)&&v.current}})};e();let t=setInterval(()=>s.playing&&Date.now()-A.current>=SI&&e(),SI);return()=>clearInterval(t)},[r,o,k?.id,s.playing,s.volume,s.muted,s.shuffle,s.repeat,s.view,s.queue.length,s.index]),(0,y.useEffect)(()=>{let e=typeof navigator<`u`?navigator.mediaSession:void 0;if(e&&!o)try{k&&typeof MediaMetadata<`u`&&(e.metadata=new MediaMetadata({title:k.title,artist:k.artist,album:k.album,artwork:[{src:`/api/music/cover/${k.id}`}]})),e.playbackState=s.playing?`playing`:k?`paused`:`none`,e.setActionHandler(`play`,()=>c({type:`resume`})),e.setActionHandler(`pause`,()=>c({type:`pause`})),e.setActionHandler(`previoustrack`,()=>c({type:`previous`})),e.setActionHandler(`nexttrack`,()=>c({type:`next`})),e.setActionHandler(`seekto`,e=>typeof e.seekTime==`number`&&c({type:`seek`,seconds:e.seekTime}))}catch{}},[k?.id,s.playing,o]),{remote:!1,state:s,dispatch:c,current:k,blocked:l,notice:d,analyser:p,unlock:T,audio:h}}function DI(e,t){if(!e)return{state:{queue:[],index:-1,playing:!1,position:0,duration:0,volume:70,muted:!1,shuffle:!1,repeat:`all`,view:t},current:null};let n=e.queue.map((t,n)=>n===e.index?{id:t.id,title:e.title||t.title,artist:e.artist,album:e.album,durationSec:e.duration>0?e.duration:null}:{id:t.id,title:t.title,artist:``,album:``,durationSec:null});return{state:{queue:n,index:e.index,playing:e.playing,position:e.position,duration:e.duration,volume:e.volume,muted:e.muted,shuffle:e.shuffle,repeat:e.repeat,view:t},current:e.index>=0?n[e.index]??null:null}}function OI({local:e,host:t,send:n}){let r=e.state.view,{state:i,current:a}=(0,y.useMemo)(()=>DI(t,r),[t,r]),o=e.dispatch,s=(0,y.useCallback)(e=>{if(e.type===`view`)return o(e);let t=Rd(e);t&&n({type:`music.remote`,command:t})},[o,n]);return(0,y.useMemo)(()=>({...e,remote:!0,state:i,dispatch:s,current:a,blocked:!1,notice:null,analyser:null,unlock:()=>{}}),[e,i,s,a])}function kI(e){let t=new URLSearchParams(e).get(`music`);return t===`connected`?{level:`info`,text:`Spotify is connected. Ask Friend to play something.`}:t===`failed`?{level:`warn`,text:`Spotify did not connect. Open Plugins, Spotify and press Connect again.`}:null}function AI({onSignedOut:e}){let{state:t,send:n,dispatch:r,voice:i,handsFree:a,useHere:o}=JM(e);sN(i),cN(i),mN(n,t.connection);let[s,c]=(0,y.useState)(Ne),l=(0,y.useCallback)(e=>{Pe(e),c(e)},[]),[u,d]=(0,y.useState)(Ie),f=(0,y.useCallback)(e=>{Le(e),d(e)},[]);(0,y.useEffect)(()=>i.setQuiet(u),[i,u]);let[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(void 0),[S,C]=(0,y.useState)(null),[T,E]=(0,y.useState)(Ae),D=e=>{je(e),E(e)},O=T===`orb`?st:Re,[k,A]=(0,y.useState)(!1),[j,ee]=(0,y.useState)(0),[M,N]=(0,y.useState)(null),P=U(t.view),F=t.music?.output===`host`,te=EI({music:t.music,cmd:t.musicCmd,send:n,connection:t.connection,remote:F}),ne=OI({local:te,host:t.hostMusic,send:n}),re=F?ne:te,I=t.hud?.animations??`full`,ie=e=>{let{type:i,value:a}=e.action;if(i===`url`)window.open(a,`_blank`,`noopener,noreferrer`);else if(i===`prompt`)n({type:`chat.send`,text:a});else if(i===`music`||i===`panel`&&a===`music`){if(!t.music?.folderSet){r({type:`alert.add`,level:`info`,text:`No music folder is chosen yet. Pick one in Settings, Widgets, and the player opens.`}),C(`widgets`);return}if(i===`panel`){P.toggle(`music`,!0),re.state.view===`hidden`&&re.dispatch({type:`view`,view:`mini`});return}let e=Ld({action:a});e&&re.dispatch(e)}else a===`plugins`?v(!0):a===`settings`?C(`model`):(a===`chat`||a===`tasks`)&&P.toggle(a,!0)},ae=t.viewKnown&&t.hud?.layout===`orbital`,oe=AF(void 0,ae),se=DN(),le=Cw(se.w,se.h)===`orbit`,L=(0,y.useMemo)(()=>{let e=s?{...t,objects:[],captions:``}:t,n=t.voice.mode===`listening`||t.voice.mode===`transcribing`||t.voice.mode===`speaking`||t.busy;return ae&&le&&!n?{...e,look:{...e.look,size:e.look.size*pw}}:e},[s,t,ae,le]),ue=(0,y.useRef)(!1);(0,y.useEffect)(()=>{ue.current||!t.voice.available||t.voice.enrolled||(ue.current=!0,r({type:`alert.add`,level:`info`,text:`Voice recognition is not set up. Press Esc, then Enroll my voice.`}))},[t.voice.available,t.voice.enrolled,r]);let de=pe(),R=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!de||R.current||t.connection!==`open`)return;R.current=!0;let e=!1;try{e=localStorage.getItem(`friend.touchHint`)===`1`,localStorage.setItem(`friend.touchHint`,`1`)}catch{}e||r({type:`alert.add`,level:`info`,text:`Hold the round mic button to talk, or tap it once to start and again to send. The keyboard button types; the menu button opens settings.`})},[de,t.connection,r]);let fe=t.uiOpen?.n??0,me=t.uiOpen?.integration;(0,y.useEffect)(()=>{fe!==0&&(x(me),v(!0))},[fe,me]);let he=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(he.current)return;he.current=!0;let e=kI(window.location.search);e&&(r({type:`alert.add`,level:e.level,text:e.text}),window.history.replaceState(null,``,window.location.pathname))},[r]);let ge=(0,y.useRef)(!1);(0,y.useEffect)(()=>{ge.current||t.connection!==`open`||(ge.current=!0,fetch(`/api/history`).then(e=>e.ok?e.json():[]).then(e=>r({type:`chat.seed`,lines:e})).catch(()=>{}))},[t.connection,r]),(0,y.useEffect)(()=>{t.connection===`open`&&n({type:`ui.panels`,open:[...P.show.chat?[`chat`]:[],...P.show.tasks?[`tasks`]:[]]})},[t.connection,P.show.chat,P.show.tasks,n]);let V=(0,y.useRef)(!1);(0,y.useEffect)(()=>{t.viewKnown&&t.view===`minimal`&&!V.current&&(V.current=!0,r({type:`alert.add`,level:`info`,text:`The view is Minimal, so the status line and clock are hidden. Press Esc, then View, to bring them back.`}))},[t.viewKnown,t.view,r]);let _e=e=>{Wd.save({view:e}).catch(e=>r({type:`alert.add`,level:`warn`,text:e.message}))},ve=(0,y.useMemo)(()=>z({notify:e=>r({type:`alert.add`,level:`info`,text:e}),openSettings:()=>C(`model`),openLook:()=>C(`look`),openConnectors:()=>A(!0),openPlugins:()=>v(!0),openVoice:t.voice.available?()=>m(!0):null,muted:s,setMuted:l,quiet:u,setQuiet:f,cameraOn:t.camera.enabled,setCamera:e=>r({type:`camera.enable`,value:e}),clearScreen:()=>{for(let e of t.objects)n({type:`stage.event`,objectId:e.id,event:`dismiss`})},statusLine:()=>bt({connection:t.connection,deviceOnline:t.deviceOnline,approval:t.approval,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity}).text,endSession:t=>{fetch(t===`lock`?`/api/lock`:`/api/logout`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).catch(()=>{}).finally(e)},panelOn:e=>P.show[e],setPanel:(e,t)=>P.toggle(e,t),view:t.view,setView:_e,openHelp:N,resetLayout:()=>{be(),window.location.reload()}}),[r,n,s,e,P.show,P.toggle,t.view,t.voice.available,t.voice.mode,t.camera.enabled,t.objects,t.connection,t.deviceOnline,t.approval,t.busy,t.activity]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Vk,{state:L,panelsOpen:{chat:P.show.chat,tasks:P.show.tasks},send:n,dispatch:r,voice:i,slash:ve,onMenu:()=>ee(e=>e+1),hudLayer:ae&&t.hud?(0,w.jsx)(EN,{children:(0,w.jsx)(EF,{hud:t.hud,state:t,usage:oe.share===null?null:oe.share*100,send:n,onHire:()=>C(`office`),onLaunch:ie,onExpand:()=>{}})}):null}),(0,w.jsxs)(Ct,{approval:t.approval,challenge:t.challenge,cameraStream:t.camera.stream,cameraStill:t.camera.still??null,alerts:t.alerts,connection:t.connection,deviceOnline:t.deviceOnline,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity,showStatus:t.viewKnown&&P.show.status&&!ae,showClock:t.viewKnown&&P.show.clock&&!ae,profile:t.viewKnown&&P.show.profile&&!ae?{ownerName:t.ownerName,speaker:t.speaker}:null,assistantName:t.assistantName,hud:t.hud,hudApproval:ae,send:n,dispatch:r,children:[t.viewKnown&&P.show.chat&&(0,w.jsx)(we,{lines:t.chat,live:t.chatLive,onSend:e=>n({type:`chat.send`,text:e}),onClose:()=>P.toggle(`chat`,!1)}),t.viewKnown&&P.show.tasks&&(0,w.jsx)(De,{busy:t.busy,onClose:()=>P.toggle(`tasks`,!1)}),t.viewKnown&&P.show.launcher&&t.hud&&!ae&&(0,w.jsx)(TN,{items:t.hud.launcher,animations:I,onAction:ie}),t.viewKnown&&P.show.music&&(0,w.jsx)(dI,{player:re,music:t.music,animations:I}),p&&(0,w.jsx)(tN,{onClose:()=>m(!1)}),h&&(0,w.jsx)(yN,{onClose:()=>g(!1)}),_&&(0,w.jsx)(Xf,{variant:T===`orb`?`holo`:`classic`,...b?{initialConfigure:b}:{},onClose:()=>{v(!1),x(void 0)}}),S&&(0,w.jsx)(sw,{initialTab:S,variant:T===`orb`?`holo`:`classic`,onClose:()=>C(null)}),k&&(0,w.jsx)(ce,{variant:T===`orb`?`holo`:`classic`,onClose:()=>A(!1)}),M&&(0,w.jsx)(B,{commands:M,onClose:()=>N(null)})]}),(0,w.jsx)(O,{voiceMode:t.voice.mode,busy:t.busy,onClassic:()=>D(`classic`),onOrb:()=>D(`orb`),muted:s,onToggleMute:()=>l(!s),quiet:u,onToggleQuiet:()=>f(!u),onSignedOut:e,voiceAvailable:t.voice.available,voiceEnrolled:t.voice.enrolled,onEnroll:()=>m(!0),onHousehold:()=>g(!0),handsFreeOn:a.on,onToggleHandsFree:a.supported?a.toggle:void 0,assistantName:t.assistantName,onPlugins:()=>v(!0),onSettings:e=>C(e??`model`),onConnectors:()=>A(!0),cameraOn:t.camera.enabled,onToggleCamera:()=>r({type:`camera.enable`,value:!t.camera.enabled}),chatOn:P.show.chat,onToggleChat:()=>P.toggle(`chat`),tasksOn:P.show.tasks,onToggleTasks:()=>P.toggle(`tasks`),musicOn:P.show.music,onToggleMusic:()=>P.toggle(`music`),launcherOn:P.show.launcher,onToggleLauncher:()=>P.toggle(`launcher`),view:t.view,onView:_e,openRequest:j}),t.connection===`elsewhere`&&(0,w.jsx)(lN,{onUseHere:o})]})}function jI(){let[e,t]=(0,y.useState)(`loading`);return(0,y.useEffect)(()=>{let e=!0,n=n=>e&&t(n);return(async()=>{try{if(!(await(await fetch(`/api/state`)).json()).hasOwner)return n(`setup`);let e=await(await fetch(`/api/session`,{cache:`no-store`})).json();n(e.signedIn===!0?`stage`:`login`)}catch{n(`login`)}})(),()=>{e=!1}},[]),e===`loading`?(0,w.jsx)(`div`,{className:`boot`,"aria-busy":`true`}):e===`setup`?(0,w.jsx)(D,{onDone:()=>t(`login`)}):e===`login`?(0,w.jsx)(E,{onLoggedIn:()=>t(`stage`)}):(0,w.jsx)(AI,{onSignedOut:()=>t(`login`)})}(0,b.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(y.StrictMode,{children:(0,w.jsx)(jI,{})}));export{g as a,u as c,C as i,l,uk as n,f as o,du as r,s,OP as t};