From 1b45023dba23a1b4c217077fdb8dc0d16bf41176 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Tue, 21 Jul 2026 15:09:32 -0700 Subject: [PATCH] fix(admin): source scoping + redirect URIs in admin OAuth registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Takeover of #1558 (rebased onto master, admin/dist + admin-embedded regenerated so asset hashes match; source changes salvaged intact): - /admin/api/register-client now accepts source_id + federated_read (snake and camel case), validated fail-closed against the registered source list via the new normalizeAdminClientSourceScope (src/core/admin-source-scope.ts) before reaching registerClientManual β€” unknown or malformed ids are a 400, never a silently-hardcoded 'default'. Fixes #1490. - New requireAdmin-gated GET /admin/api/sources feeds the Register Agent form; the form now has a Write Source select + Read Sources checkboxes, and the agents table/drawer show each client's scope. - #1036: the Register Agent form now has a Redirect URIs textarea (one per line). When present, the POST carries redirectUris plus the authorization_code + refresh_token grants, mirroring the CLI's --redirect-uri grant-inference convention (src/commands/auth.ts). Backend plumbing already existed; this was UI-only. Tests: test/admin-source-scope.test.ts (normalization matrix), test/oauth.test.ts (registerClientManual persists source scope into AuthInfo), test/fix-wave-structural.test.ts (endpoint + form pins for #1490 and #1036). Co-authored-by: flamerged Co-Authored-By: Claude Fable 5 --- admin/dist/assets/index-CoGEje3-.js | 56 ------------------ admin/dist/assets/index-CzLjRij_.js | 57 +++++++++++++++++++ admin/dist/index.html | 2 +- admin/src/api.ts | 1 + admin/src/pages/Agents.tsx | 88 ++++++++++++++++++++++++++++- src/admin-embedded.ts | 6 +- src/commands/serve-http.ts | 33 ++++++++++- src/core/admin-source-scope.ts | 51 +++++++++++++++++ test/admin-source-scope.test.ts | 44 +++++++++++++++ test/fix-wave-structural.test.ts | 26 +++++++++ test/oauth.test.ts | 24 ++++++++ 11 files changed, 326 insertions(+), 62 deletions(-) delete mode 100644 admin/dist/assets/index-CoGEje3-.js create mode 100644 admin/dist/assets/index-CzLjRij_.js create mode 100644 src/core/admin-source-scope.ts create mode 100644 test/admin-source-scope.test.ts diff --git a/admin/dist/assets/index-CoGEje3-.js b/admin/dist/assets/index-CoGEje3-.js deleted file mode 100644 index 0f8a5879d..000000000 --- a/admin/dist/assets/index-CoGEje3-.js +++ /dev/null @@ -1,56 +0,0 @@ -(function(){const D=document.createElement("link").relList;if(D&&D.supports&&D.supports("modulepreload"))return;for(const E of document.querySelectorAll('link[rel="modulepreload"]'))h(E);new MutationObserver(E=>{for(const N of E)if(N.type==="childList")for(const C of N.addedNodes)C.tagName==="LINK"&&C.rel==="modulepreload"&&h(C)}).observe(document,{childList:!0,subtree:!0});function O(E){const N={};return E.integrity&&(N.integrity=E.integrity),E.referrerPolicy&&(N.referrerPolicy=E.referrerPolicy),E.crossOrigin==="use-credentials"?N.credentials="include":E.crossOrigin==="anonymous"?N.credentials="omit":N.credentials="same-origin",N}function h(E){if(E.ep)return;E.ep=!0;const N=O(E);fetch(E.href,N)}})();function Md(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var ff={exports:{}},jn={};/** - * @license React - * react-jsx-runtime.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var gd;function ey(){if(gd)return jn;gd=1;var o=Symbol.for("react.transitional.element"),D=Symbol.for("react.fragment");function O(h,E,N){var C=null;if(N!==void 0&&(C=""+N),E.key!==void 0&&(C=""+E.key),"key"in E){N={};for(var Q in E)Q!=="key"&&(N[Q]=E[Q])}else N=E;return E=N.ref,{$$typeof:o,type:h,key:C,ref:E!==void 0?E:null,props:N}}return jn.Fragment=D,jn.jsx=O,jn.jsxs=O,jn}var Sd;function ay(){return Sd||(Sd=1,ff.exports=ey()),ff.exports}var c=ay(),sf={exports:{}},V={};/** - * @license React - * react.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var pd;function ny(){if(pd)return V;pd=1;var o=Symbol.for("react.transitional.element"),D=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),h=Symbol.for("react.strict_mode"),E=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),C=Symbol.for("react.context"),Q=Symbol.for("react.forward_ref"),_=Symbol.for("react.suspense"),b=Symbol.for("react.memo"),H=Symbol.for("react.lazy"),M=Symbol.for("react.activity"),A=Symbol.iterator;function I(d){return d===null||typeof d!="object"?null:(d=A&&d[A]||d["@@iterator"],typeof d=="function"?d:null)}var L={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},nl=Object.assign,tl={};function bl(d,z,R){this.props=d,this.context=z,this.refs=tl,this.updater=R||L}bl.prototype.isReactComponent={},bl.prototype.setState=function(d,z){if(typeof d!="object"&&typeof d!="function"&&d!=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,d,z,"setState")},bl.prototype.forceUpdate=function(d){this.updater.enqueueForceUpdate(this,d,"forceUpdate")};function Ml(){}Ml.prototype=bl.prototype;function Gl(d,z,R){this.props=d,this.context=z,this.refs=tl,this.updater=R||L}var rt=Gl.prototype=new Ml;rt.constructor=Gl,nl(rt,bl.prototype),rt.isPureReactComponent=!0;var _t=Array.isArray;function Ll(){}var el={H:null,A:null,T:null,S:null},Vl=Object.prototype.hasOwnProperty;function Et(d,z,R){var q=R.ref;return{$$typeof:o,type:d,key:z,ref:q!==void 0?q:null,props:R}}function Le(d,z){return Et(d.type,z,d.props)}function Ot(d){return typeof d=="object"&&d!==null&&d.$$typeof===o}function Kl(d){var z={"=":"=0",":":"=2"};return"$"+d.replace(/[=:]/g,function(R){return z[R]})}var Te=/\/+/g;function Ut(d,z){return typeof d=="object"&&d!==null&&d.key!=null?Kl(""+d.key):z.toString(36)}function jt(d){switch(d.status){case"fulfilled":return d.value;case"rejected":throw d.reason;default:switch(typeof d.status=="string"?d.then(Ll,Ll):(d.status="pending",d.then(function(z){d.status==="pending"&&(d.status="fulfilled",d.value=z)},function(z){d.status==="pending"&&(d.status="rejected",d.reason=z)})),d.status){case"fulfilled":return d.value;case"rejected":throw d.reason}}throw d}function x(d,z,R,q,J){var $=typeof d;($==="undefined"||$==="boolean")&&(d=null);var fl=!1;if(d===null)fl=!0;else switch($){case"bigint":case"string":case"number":fl=!0;break;case"object":switch(d.$$typeof){case o:case D:fl=!0;break;case H:return fl=d._init,x(fl(d._payload),z,R,q,J)}}if(fl)return J=J(d),fl=q===""?"."+Ut(d,0):q,_t(J)?(R="",fl!=null&&(R=fl.replace(Te,"$&/")+"/"),x(J,z,R,"",function(Oa){return Oa})):J!=null&&(Ot(J)&&(J=Le(J,R+(J.key==null||d&&d.key===J.key?"":(""+J.key).replace(Te,"$&/")+"/")+fl)),z.push(J)),1;fl=0;var Ql=q===""?".":q+":";if(_t(d))for(var Tl=0;Tl>>1,yl=x[rl];if(0>>1;rlE(R,Z))qE(J,R)?(x[rl]=J,x[q]=Z,rl=q):(x[rl]=R,x[z]=Z,rl=z);else if(qE(J,Z))x[rl]=J,x[q]=Z,rl=q;else break l}}return U}function E(x,U){var Z=x.sortIndex-U.sortIndex;return Z!==0?Z:x.id-U.id}if(o.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var N=performance;o.unstable_now=function(){return N.now()}}else{var C=Date,Q=C.now();o.unstable_now=function(){return C.now()-Q}}var _=[],b=[],H=1,M=null,A=3,I=!1,L=!1,nl=!1,tl=!1,bl=typeof setTimeout=="function"?setTimeout:null,Ml=typeof clearTimeout=="function"?clearTimeout:null,Gl=typeof setImmediate<"u"?setImmediate:null;function rt(x){for(var U=O(b);U!==null;){if(U.callback===null)h(b);else if(U.startTime<=x)h(b),U.sortIndex=U.expirationTime,D(_,U);else break;U=O(b)}}function _t(x){if(nl=!1,rt(x),!L)if(O(_)!==null)L=!0,Ll||(Ll=!0,Kl());else{var U=O(b);U!==null&&jt(_t,U.startTime-x)}}var Ll=!1,el=-1,Vl=5,Et=-1;function Le(){return tl?!0:!(o.unstable_now()-Etx&&Le());){var rl=M.callback;if(typeof rl=="function"){M.callback=null,A=M.priorityLevel;var yl=rl(M.expirationTime<=x);if(x=o.unstable_now(),typeof yl=="function"){M.callback=yl,rt(x),U=!0;break t}M===O(_)&&h(_),rt(x)}else h(_);M=O(_)}if(M!==null)U=!0;else{var d=O(b);d!==null&&jt(_t,d.startTime-x),U=!1}}break l}finally{M=null,A=Z,I=!1}U=void 0}}finally{U?Kl():Ll=!1}}}var Kl;if(typeof Gl=="function")Kl=function(){Gl(Ot)};else if(typeof MessageChannel<"u"){var Te=new MessageChannel,Ut=Te.port2;Te.port1.onmessage=Ot,Kl=function(){Ut.postMessage(null)}}else Kl=function(){bl(Ot,0)};function jt(x,U){el=bl(function(){x(o.unstable_now())},U)}o.unstable_IdlePriority=5,o.unstable_ImmediatePriority=1,o.unstable_LowPriority=4,o.unstable_NormalPriority=3,o.unstable_Profiling=null,o.unstable_UserBlockingPriority=2,o.unstable_cancelCallback=function(x){x.callback=null},o.unstable_forceFrameRate=function(x){0>x||125rl?(x.sortIndex=Z,D(b,x),O(_)===null&&x===O(b)&&(nl?(Ml(el),el=-1):nl=!0,jt(_t,Z-rl))):(x.sortIndex=yl,D(_,x),L||I||(L=!0,Ll||(Ll=!0,Kl()))),x},o.unstable_shouldYield=Le,o.unstable_wrapCallback=function(x){var U=A;return function(){var Z=A;A=U;try{return x.apply(this,arguments)}finally{A=Z}}}})(df)),df}var jd;function iy(){return jd||(jd=1,rf.exports=uy()),rf.exports}var hf={exports:{}},Xl={};/** - * @license React - * react-dom.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Td;function cy(){if(Td)return Xl;Td=1;var o=mf();function D(_){var b="https://react.dev/errors/"+_;if(1"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(o)}catch(D){console.error(D)}}return o(),hf.exports=cy(),hf.exports}/** - * @license React - * react-dom-client.production.js - * - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */var Ad;function sy(){if(Ad)return Tn;Ad=1;var o=iy(),D=mf(),O=fy();function h(l){var t="https://react.dev/errors/"+l;if(1yl||(l.current=rl[yl],rl[yl]=null,yl--)}function R(l,t){yl++,rl[yl]=l.current,l.current=t}var q=d(null),J=d(null),$=d(null),fl=d(null);function Ql(l,t){switch(R($,t),R(J,l),R(q,null),t.nodeType){case 9:case 11:l=(l=t.documentElement)&&(l=l.namespaceURI)?Xr(l):0;break;default:if(l=t.tagName,t=t.namespaceURI)t=Xr(t),l=Qr(t,l);else switch(l){case"svg":l=1;break;case"math":l=2;break;default:l=0}}z(q),R(q,l)}function Tl(){z(q),z(J),z($)}function Oa(l){l.memoizedState!==null&&R(fl,l);var t=q.current,e=Qr(t,l.type);t!==e&&(R(J,l),R(q,e))}function zn(l){J.current===l&&(z(q),z(J)),fl.current===l&&(z(fl),Sn._currentValue=Z)}var Lu,yf;function ze(l){if(Lu===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Lu=t&&t[1]||"",yf=-1)":-1n||s[a]!==v[n]){var p=` -`+s[a].replace(" at new "," at ");return l.displayName&&p.includes("")&&(p=p.replace("",l.displayName)),p}while(1<=a&&0<=n);break}}}finally{Vu=!1,Error.prepareStackTrace=e}return(e=l?l.displayName||l.name:"")?ze(e):""}function Ud(l,t){switch(l.tag){case 26:case 27:case 5:return ze(l.type);case 16:return ze("Lazy");case 13:return l.child!==t&&t!==null?ze("Suspense Fallback"):ze("Suspense");case 19:return ze("SuspenseList");case 0:case 15:return Ku(l.type,!1);case 11:return Ku(l.type.render,!1);case 1:return Ku(l.type,!0);case 31:return ze("Activity");default:return""}}function vf(l){try{var t="",e=null;do t+=Ud(l,e),e=l,l=l.return;while(l);return t}catch(a){return` -Error generating stack: `+a.message+` -`+a.stack}}var Ju=Object.prototype.hasOwnProperty,wu=o.unstable_scheduleCallback,ku=o.unstable_cancelCallback,Rd=o.unstable_shouldYield,Bd=o.unstable_requestPaint,lt=o.unstable_now,Hd=o.unstable_getCurrentPriorityLevel,gf=o.unstable_ImmediatePriority,Sf=o.unstable_UserBlockingPriority,An=o.unstable_NormalPriority,qd=o.unstable_LowPriority,pf=o.unstable_IdlePriority,Yd=o.log,Gd=o.unstable_setDisableYieldValue,Na=null,tt=null;function It(l){if(typeof Yd=="function"&&Gd(l),tt&&typeof tt.setStrictMode=="function")try{tt.setStrictMode(Na,l)}catch{}}var et=Math.clz32?Math.clz32:Zd,Xd=Math.log,Qd=Math.LN2;function Zd(l){return l>>>=0,l===0?32:31-(Xd(l)/Qd|0)|0}var _n=256,En=262144,On=4194304;function Ae(l){var t=l&42;if(t!==0)return t;switch(l&-l){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return l&261888;case 262144:case 524288:case 1048576:case 2097152:return l&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return l&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return l}}function Nn(l,t,e){var a=l.pendingLanes;if(a===0)return 0;var n=0,u=l.suspendedLanes,i=l.pingedLanes;l=l.warmLanes;var f=a&134217727;return f!==0?(a=f&~u,a!==0?n=Ae(a):(i&=f,i!==0?n=Ae(i):e||(e=f&~l,e!==0&&(n=Ae(e))))):(f=a&~u,f!==0?n=Ae(f):i!==0?n=Ae(i):e||(e=a&~l,e!==0&&(n=Ae(e)))),n===0?0:t!==0&&t!==n&&(t&u)===0&&(u=n&-n,e=t&-t,u>=e||u===32&&(e&4194048)!==0)?t:n}function Ma(l,t){return(l.pendingLanes&~(l.suspendedLanes&~l.pingedLanes)&t)===0}function Ld(l,t){switch(l){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function bf(){var l=On;return On<<=1,(On&62914560)===0&&(On=4194304),l}function $u(l){for(var t=[],e=0;31>e;e++)t.push(l);return t}function Da(l,t){l.pendingLanes|=t,t!==268435456&&(l.suspendedLanes=0,l.pingedLanes=0,l.warmLanes=0)}function Vd(l,t,e,a,n,u){var i=l.pendingLanes;l.pendingLanes=e,l.suspendedLanes=0,l.pingedLanes=0,l.warmLanes=0,l.expiredLanes&=e,l.entangledLanes&=e,l.errorRecoveryDisabledLanes&=e,l.shellSuspendCounter=0;var f=l.entanglements,s=l.expirationTimes,v=l.hiddenUpdates;for(e=i&~e;0"u")return null;try{return l.activeElement||l.body}catch{return l.body}}var Wd=/[\n"\\]/g;function ht(l){return l.replace(Wd,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function ti(l,t,e,a,n,u,i,f){l.name="",i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"?l.type=i:l.removeAttribute("type"),t!=null?i==="number"?(t===0&&l.value===""||l.value!=t)&&(l.value=""+dt(t)):l.value!==""+dt(t)&&(l.value=""+dt(t)):i!=="submit"&&i!=="reset"||l.removeAttribute("value"),t!=null?ei(l,i,dt(t)):e!=null?ei(l,i,dt(e)):a!=null&&l.removeAttribute("value"),n==null&&u!=null&&(l.defaultChecked=!!u),n!=null&&(l.checked=n&&typeof n!="function"&&typeof n!="symbol"),f!=null&&typeof f!="function"&&typeof f!="symbol"&&typeof f!="boolean"?l.name=""+dt(f):l.removeAttribute("name")}function Uf(l,t,e,a,n,u,i,f){if(u!=null&&typeof u!="function"&&typeof u!="symbol"&&typeof u!="boolean"&&(l.type=u),t!=null||e!=null){if(!(u!=="submit"&&u!=="reset"||t!=null)){li(l);return}e=e!=null?""+dt(e):"",t=t!=null?""+dt(t):e,f||t===l.value||(l.value=t),l.defaultValue=t}a=a??n,a=typeof a!="function"&&typeof a!="symbol"&&!!a,l.checked=f?l.checked:!!a,l.defaultChecked=!!a,i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"&&(l.name=i),li(l)}function ei(l,t,e){t==="number"&&Cn(l.ownerDocument)===l||l.defaultValue===""+e||(l.defaultValue=""+e)}function $e(l,t,e,a){if(l=l.options,t){t={};for(var n=0;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ci=!1;if(Ht)try{var Ba={};Object.defineProperty(Ba,"passive",{get:function(){ci=!0}}),window.addEventListener("test",Ba,Ba),window.removeEventListener("test",Ba,Ba)}catch{ci=!1}var le=null,fi=null,Rn=null;function Xf(){if(Rn)return Rn;var l,t=fi,e=t.length,a,n="value"in le?le.value:le.textContent,u=n.length;for(l=0;l=Ya),Jf=" ",wf=!1;function kf(l,t){switch(l){case"keyup":return zh.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function $f(l){return l=l.detail,typeof l=="object"&&"data"in l?l.data:null}var Pe=!1;function _h(l,t){switch(l){case"compositionend":return $f(t);case"keypress":return t.which!==32?null:(wf=!0,Jf);case"textInput":return l=t.data,l===Jf&&wf?null:l;default:return null}}function Eh(l,t){if(Pe)return l==="compositionend"||!hi&&kf(l,t)?(l=Xf(),Rn=fi=le=null,Pe=!1,l):null;switch(l){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:e,offset:t-l};l=a}l:{for(;e;){if(e.nextSibling){e=e.nextSibling;break l}e=e.parentNode}e=void 0}e=as(e)}}function us(l,t){return l&&t?l===t?!0:l&&l.nodeType===3?!1:t&&t.nodeType===3?us(l,t.parentNode):"contains"in l?l.contains(t):l.compareDocumentPosition?!!(l.compareDocumentPosition(t)&16):!1:!1}function is(l){l=l!=null&&l.ownerDocument!=null&&l.ownerDocument.defaultView!=null?l.ownerDocument.defaultView:window;for(var t=Cn(l.document);t instanceof l.HTMLIFrameElement;){try{var e=typeof t.contentWindow.location.href=="string"}catch{e=!1}if(e)l=t.contentWindow;else break;t=Cn(l.document)}return t}function vi(l){var t=l&&l.nodeName&&l.nodeName.toLowerCase();return t&&(t==="input"&&(l.type==="text"||l.type==="search"||l.type==="tel"||l.type==="url"||l.type==="password")||t==="textarea"||l.contentEditable==="true")}var Bh=Ht&&"documentMode"in document&&11>=document.documentMode,la=null,gi=null,Za=null,Si=!1;function cs(l,t,e){var a=e.window===e?e.document:e.nodeType===9?e:e.ownerDocument;Si||la==null||la!==Cn(a)||(a=la,"selectionStart"in a&&vi(a)?a={start:a.selectionStart,end:a.selectionEnd}:(a=(a.ownerDocument&&a.ownerDocument.defaultView||window).getSelection(),a={anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),Za&&Qa(Za,a)||(Za=a,a=Eu(gi,"onSelect"),0>=i,n-=i,Nt=1<<32-et(t)+n|e<k?(ll=Y,Y=null):ll=Y.sibling;var il=g(m,Y,y[k],j);if(il===null){Y===null&&(Y=ll);break}l&&Y&&il.alternate===null&&t(m,Y),r=u(il,r,k),ul===null?G=il:ul.sibling=il,ul=il,Y=ll}if(k===y.length)return e(m,Y),al&&Yt(m,k),G;if(Y===null){for(;kk?(ll=Y,Y=null):ll=Y.sibling;var je=g(m,Y,il.value,j);if(je===null){Y===null&&(Y=ll);break}l&&Y&&je.alternate===null&&t(m,Y),r=u(je,r,k),ul===null?G=je:ul.sibling=je,ul=je,Y=ll}if(il.done)return e(m,Y),al&&Yt(m,k),G;if(Y===null){for(;!il.done;k++,il=y.next())il=T(m,il.value,j),il!==null&&(r=u(il,r,k),ul===null?G=il:ul.sibling=il,ul=il);return al&&Yt(m,k),G}for(Y=a(Y);!il.done;k++,il=y.next())il=S(Y,m,k,il.value,j),il!==null&&(l&&il.alternate!==null&&Y.delete(il.key===null?k:il.key),r=u(il,r,k),ul===null?G=il:ul.sibling=il,ul=il);return l&&Y.forEach(function(ty){return t(m,ty)}),al&&Yt(m,k),G}function ml(m,r,y,j){if(typeof y=="object"&&y!==null&&y.type===nl&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case I:l:{for(var G=y.key;r!==null;){if(r.key===G){if(G=y.type,G===nl){if(r.tag===7){e(m,r.sibling),j=n(r,y.props.children),j.return=m,m=j;break l}}else if(r.elementType===G||typeof G=="object"&&G!==null&&G.$$typeof===Vl&&He(G)===r.type){e(m,r.sibling),j=n(r,y.props),ka(j,y),j.return=m,m=j;break l}e(m,r);break}else t(m,r);r=r.sibling}y.type===nl?(j=De(y.props.children,m.mode,j,y.key),j.return=m,m=j):(j=Vn(y.type,y.key,y.props,null,m.mode,j),ka(j,y),j.return=m,m=j)}return i(m);case L:l:{for(G=y.key;r!==null;){if(r.key===G)if(r.tag===4&&r.stateNode.containerInfo===y.containerInfo&&r.stateNode.implementation===y.implementation){e(m,r.sibling),j=n(r,y.children||[]),j.return=m,m=j;break l}else{e(m,r);break}else t(m,r);r=r.sibling}j=Ai(y,m.mode,j),j.return=m,m=j}return i(m);case Vl:return y=He(y),ml(m,r,y,j)}if(jt(y))return B(m,r,y,j);if(Kl(y)){if(G=Kl(y),typeof G!="function")throw Error(h(150));return y=G.call(y),X(m,r,y,j)}if(typeof y.then=="function")return ml(m,r,Fn(y),j);if(y.$$typeof===Gl)return ml(m,r,wn(m,y),j);In(m,y)}return typeof y=="string"&&y!==""||typeof y=="number"||typeof y=="bigint"?(y=""+y,r!==null&&r.tag===6?(e(m,r.sibling),j=n(r,y),j.return=m,m=j):(e(m,r),j=zi(y,m.mode,j),j.return=m,m=j),i(m)):e(m,r)}return function(m,r,y,j){try{wa=0;var G=ml(m,r,y,j);return ra=null,G}catch(Y){if(Y===oa||Y===$n)throw Y;var ul=nt(29,Y,null,m.mode);return ul.lanes=j,ul.return=m,ul}finally{}}}var Ye=Ms(!0),Ds=Ms(!1),ue=!1;function qi(l){l.updateQueue={baseState:l.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Yi(l,t){l=l.updateQueue,t.updateQueue===l&&(t.updateQueue={baseState:l.baseState,firstBaseUpdate:l.firstBaseUpdate,lastBaseUpdate:l.lastBaseUpdate,shared:l.shared,callbacks:null})}function ie(l){return{lane:l,tag:0,payload:null,callback:null,next:null}}function ce(l,t,e){var a=l.updateQueue;if(a===null)return null;if(a=a.shared,(cl&2)!==0){var n=a.pending;return n===null?t.next=t:(t.next=n.next,n.next=t),a.pending=t,t=Ln(l),ms(l,null,e),t}return Zn(l,a,t,e),Ln(l)}function $a(l,t,e){if(t=t.updateQueue,t!==null&&(t=t.shared,(e&4194048)!==0)){var a=t.lanes;a&=l.pendingLanes,e|=a,t.lanes=e,jf(l,e)}}function Gi(l,t){var e=l.updateQueue,a=l.alternate;if(a!==null&&(a=a.updateQueue,e===a)){var n=null,u=null;if(e=e.firstBaseUpdate,e!==null){do{var i={lane:e.lane,tag:e.tag,payload:e.payload,callback:null,next:null};u===null?n=u=i:u=u.next=i,e=e.next}while(e!==null);u===null?n=u=t:u=u.next=t}else n=u=t;e={baseState:a.baseState,firstBaseUpdate:n,lastBaseUpdate:u,shared:a.shared,callbacks:a.callbacks},l.updateQueue=e;return}l=e.lastBaseUpdate,l===null?e.firstBaseUpdate=t:l.next=t,e.lastBaseUpdate=t}var Xi=!1;function Wa(){if(Xi){var l=sa;if(l!==null)throw l}}function Fa(l,t,e,a){Xi=!1;var n=l.updateQueue;ue=!1;var u=n.firstBaseUpdate,i=n.lastBaseUpdate,f=n.shared.pending;if(f!==null){n.shared.pending=null;var s=f,v=s.next;s.next=null,i===null?u=v:i.next=v,i=s;var p=l.alternate;p!==null&&(p=p.updateQueue,f=p.lastBaseUpdate,f!==i&&(f===null?p.firstBaseUpdate=v:f.next=v,p.lastBaseUpdate=s))}if(u!==null){var T=n.baseState;i=0,p=v=s=null,f=u;do{var g=f.lane&-536870913,S=g!==f.lane;if(S?(P&g)===g:(a&g)===g){g!==0&&g===fa&&(Xi=!0),p!==null&&(p=p.next={lane:0,tag:f.tag,payload:f.payload,callback:null,next:null});l:{var B=l,X=f;g=t;var ml=e;switch(X.tag){case 1:if(B=X.payload,typeof B=="function"){T=B.call(ml,T,g);break l}T=B;break l;case 3:B.flags=B.flags&-65537|128;case 0:if(B=X.payload,g=typeof B=="function"?B.call(ml,T,g):B,g==null)break l;T=M({},T,g);break l;case 2:ue=!0}}g=f.callback,g!==null&&(l.flags|=64,S&&(l.flags|=8192),S=n.callbacks,S===null?n.callbacks=[g]:S.push(g))}else S={lane:g,tag:f.tag,payload:f.payload,callback:f.callback,next:null},p===null?(v=p=S,s=T):p=p.next=S,i|=g;if(f=f.next,f===null){if(f=n.shared.pending,f===null)break;S=f,f=S.next,S.next=null,n.lastBaseUpdate=S,n.shared.pending=null}}while(!0);p===null&&(s=T),n.baseState=s,n.firstBaseUpdate=v,n.lastBaseUpdate=p,u===null&&(n.shared.lanes=0),de|=i,l.lanes=i,l.memoizedState=T}}function Cs(l,t){if(typeof l!="function")throw Error(h(191,l));l.call(t)}function Us(l,t){var e=l.callbacks;if(e!==null)for(l.callbacks=null,l=0;lu?u:8;var i=x.T,f={};x.T=f,uc(l,!1,t,e);try{var s=n(),v=x.S;if(v!==null&&v(f,s),s!==null&&typeof s=="object"&&typeof s.then=="function"){var p=Vh(s,a);ln(l,t,p,st(l))}else ln(l,t,a,st(l))}catch(T){ln(l,t,{then:function(){},status:"rejected",reason:T},st())}finally{U.p=u,i!==null&&f.types!==null&&(i.types=f.types),x.T=i}}function Wh(){}function ac(l,t,e,a){if(l.tag!==5)throw Error(h(476));var n=ro(l).queue;oo(l,n,t,Z,e===null?Wh:function(){return ho(l),e(a)})}function ro(l){var t=l.memoizedState;if(t!==null)return t;t={memoizedState:Z,baseState:Z,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Zt,lastRenderedState:Z},next:null};var e={};return t.next={memoizedState:e,baseState:e,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Zt,lastRenderedState:e},next:null},l.memoizedState=t,l=l.alternate,l!==null&&(l.memoizedState=t),t}function ho(l){var t=ro(l);t.next===null&&(t=l.alternate.memoizedState),ln(l,t.next.queue,{},st())}function nc(){return Hl(Sn)}function mo(){return Al().memoizedState}function yo(){return Al().memoizedState}function Fh(l){for(var t=l.return;t!==null;){switch(t.tag){case 24:case 3:var e=st();l=ie(e);var a=ce(t,l,e);a!==null&&(Il(a,t,e),$a(a,t,e)),t={cache:Ui()},l.payload=t;return}t=t.return}}function Ih(l,t,e){var a=st();e={lane:a,revertLane:0,gesture:null,action:e,hasEagerState:!1,eagerState:null,next:null},fu(l)?go(t,e):(e=ji(l,t,e,a),e!==null&&(Il(e,l,a),So(e,t,a)))}function vo(l,t,e){var a=st();ln(l,t,e,a)}function ln(l,t,e,a){var n={lane:a,revertLane:0,gesture:null,action:e,hasEagerState:!1,eagerState:null,next:null};if(fu(l))go(t,n);else{var u=l.alternate;if(l.lanes===0&&(u===null||u.lanes===0)&&(u=t.lastRenderedReducer,u!==null))try{var i=t.lastRenderedState,f=u(i,e);if(n.hasEagerState=!0,n.eagerState=f,at(f,i))return Zn(l,t,n,0),vl===null&&Qn(),!1}catch{}finally{}if(e=ji(l,t,n,a),e!==null)return Il(e,l,a),So(e,t,a),!0}return!1}function uc(l,t,e,a){if(a={lane:2,revertLane:qc(),gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},fu(l)){if(t)throw Error(h(479))}else t=ji(l,e,a,2),t!==null&&Il(t,l,2)}function fu(l){var t=l.alternate;return l===w||t!==null&&t===w}function go(l,t){ha=tu=!0;var e=l.pending;e===null?t.next=t:(t.next=e.next,e.next=t),l.pending=t}function So(l,t,e){if((e&4194048)!==0){var a=t.lanes;a&=l.pendingLanes,e|=a,t.lanes=e,jf(l,e)}}var tn={readContext:Hl,use:nu,useCallback:xl,useContext:xl,useEffect:xl,useImperativeHandle:xl,useLayoutEffect:xl,useInsertionEffect:xl,useMemo:xl,useReducer:xl,useRef:xl,useState:xl,useDebugValue:xl,useDeferredValue:xl,useTransition:xl,useSyncExternalStore:xl,useId:xl,useHostTransitionStatus:xl,useFormState:xl,useActionState:xl,useOptimistic:xl,useMemoCache:xl,useCacheRefresh:xl};tn.useEffectEvent=xl;var po={readContext:Hl,use:nu,useCallback:function(l,t){return Zl().memoizedState=[l,t===void 0?null:t],l},useContext:Hl,useEffect:to,useImperativeHandle:function(l,t,e){e=e!=null?e.concat([l]):null,iu(4194308,4,uo.bind(null,t,l),e)},useLayoutEffect:function(l,t){return iu(4194308,4,l,t)},useInsertionEffect:function(l,t){iu(4,2,l,t)},useMemo:function(l,t){var e=Zl();t=t===void 0?null:t;var a=l();if(Ge){It(!0);try{l()}finally{It(!1)}}return e.memoizedState=[a,t],a},useReducer:function(l,t,e){var a=Zl();if(e!==void 0){var n=e(t);if(Ge){It(!0);try{e(t)}finally{It(!1)}}}else n=t;return a.memoizedState=a.baseState=n,l={pending:null,lanes:0,dispatch:null,lastRenderedReducer:l,lastRenderedState:n},a.queue=l,l=l.dispatch=Ih.bind(null,w,l),[a.memoizedState,l]},useRef:function(l){var t=Zl();return l={current:l},t.memoizedState=l},useState:function(l){l=Ii(l);var t=l.queue,e=vo.bind(null,w,t);return t.dispatch=e,[l.memoizedState,e]},useDebugValue:tc,useDeferredValue:function(l,t){var e=Zl();return ec(e,l,t)},useTransition:function(){var l=Ii(!1);return l=oo.bind(null,w,l.queue,!0,!1),Zl().memoizedState=l,[!1,l]},useSyncExternalStore:function(l,t,e){var a=w,n=Zl();if(al){if(e===void 0)throw Error(h(407));e=e()}else{if(e=t(),vl===null)throw Error(h(349));(P&127)!==0||Gs(a,t,e)}n.memoizedState=e;var u={value:e,getSnapshot:t};return n.queue=u,to(Qs.bind(null,a,u,l),[l]),a.flags|=2048,ya(9,{destroy:void 0},Xs.bind(null,a,u,e,t),null),e},useId:function(){var l=Zl(),t=vl.identifierPrefix;if(al){var e=Mt,a=Nt;e=(a&~(1<<32-et(a)-1)).toString(32)+e,t="_"+t+"R_"+e,e=eu++,0<\/script>",u=u.removeChild(u.firstChild);break;case"select":u=typeof a.is=="string"?i.createElement("select",{is:a.is}):i.createElement("select"),a.multiple?u.multiple=!0:a.size&&(u.size=a.size);break;default:u=typeof a.is=="string"?i.createElement(n,{is:a.is}):i.createElement(n)}}u[Rl]=t,u[Jl]=a;l:for(i=t.child;i!==null;){if(i.tag===5||i.tag===6)u.appendChild(i.stateNode);else if(i.tag!==4&&i.tag!==27&&i.child!==null){i.child.return=i,i=i.child;continue}if(i===t)break l;for(;i.sibling===null;){if(i.return===null||i.return===t)break l;i=i.return}i.sibling.return=i.return,i=i.sibling}t.stateNode=u;l:switch(Yl(u,n,a),n){case"button":case"input":case"select":case"textarea":a=!!a.autoFocus;break l;case"img":a=!0;break l;default:a=!1}a&&Vt(t)}}return Sl(t),pc(t,t.type,l===null?null:l.memoizedProps,t.pendingProps,e),null;case 6:if(l&&t.stateNode!=null)l.memoizedProps!==a&&Vt(t);else{if(typeof a!="string"&&t.stateNode===null)throw Error(h(166));if(l=$.current,ia(t)){if(l=t.stateNode,e=t.memoizedProps,a=null,n=Bl,n!==null)switch(n.tag){case 27:case 5:a=n.memoizedProps}l[Rl]=t,l=!!(l.nodeValue===e||a!==null&&a.suppressHydrationWarning===!0||Yr(l.nodeValue,e)),l||ae(t,!0)}else l=Ou(l).createTextNode(a),l[Rl]=t,t.stateNode=l}return Sl(t),null;case 31:if(e=t.memoizedState,l===null||l.memoizedState!==null){if(a=ia(t),e!==null){if(l===null){if(!a)throw Error(h(318));if(l=t.memoizedState,l=l!==null?l.dehydrated:null,!l)throw Error(h(557));l[Rl]=t}else Ce(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;Sl(t),l=!1}else e=Ni(),l!==null&&l.memoizedState!==null&&(l.memoizedState.hydrationErrors=e),l=!0;if(!l)return t.flags&256?(it(t),t):(it(t),null);if((t.flags&128)!==0)throw Error(h(558))}return Sl(t),null;case 13:if(a=t.memoizedState,l===null||l.memoizedState!==null&&l.memoizedState.dehydrated!==null){if(n=ia(t),a!==null&&a.dehydrated!==null){if(l===null){if(!n)throw Error(h(318));if(n=t.memoizedState,n=n!==null?n.dehydrated:null,!n)throw Error(h(317));n[Rl]=t}else Ce(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;Sl(t),n=!1}else n=Ni(),l!==null&&l.memoizedState!==null&&(l.memoizedState.hydrationErrors=n),n=!0;if(!n)return t.flags&256?(it(t),t):(it(t),null)}return it(t),(t.flags&128)!==0?(t.lanes=e,t):(e=a!==null,l=l!==null&&l.memoizedState!==null,e&&(a=t.child,n=null,a.alternate!==null&&a.alternate.memoizedState!==null&&a.alternate.memoizedState.cachePool!==null&&(n=a.alternate.memoizedState.cachePool.pool),u=null,a.memoizedState!==null&&a.memoizedState.cachePool!==null&&(u=a.memoizedState.cachePool.pool),u!==n&&(a.flags|=2048)),e!==l&&e&&(t.child.flags|=8192),hu(t,t.updateQueue),Sl(t),null);case 4:return Tl(),l===null&&Qc(t.stateNode.containerInfo),Sl(t),null;case 10:return Xt(t.type),Sl(t),null;case 19:if(z(zl),a=t.memoizedState,a===null)return Sl(t),null;if(n=(t.flags&128)!==0,u=a.rendering,u===null)if(n)an(a,!1);else{if(jl!==0||l!==null&&(l.flags&128)!==0)for(l=t.child;l!==null;){if(u=lu(l),u!==null){for(t.flags|=128,an(a,!1),l=u.updateQueue,t.updateQueue=l,hu(t,l),t.subtreeFlags=0,l=e,e=t.child;e!==null;)ys(e,l),e=e.sibling;return R(zl,zl.current&1|2),al&&Yt(t,a.treeForkCount),t.child}l=l.sibling}a.tail!==null&<()>Su&&(t.flags|=128,n=!0,an(a,!1),t.lanes=4194304)}else{if(!n)if(l=lu(u),l!==null){if(t.flags|=128,n=!0,l=l.updateQueue,t.updateQueue=l,hu(t,l),an(a,!0),a.tail===null&&a.tailMode==="hidden"&&!u.alternate&&!al)return Sl(t),null}else 2*lt()-a.renderingStartTime>Su&&e!==536870912&&(t.flags|=128,n=!0,an(a,!1),t.lanes=4194304);a.isBackwards?(u.sibling=t.child,t.child=u):(l=a.last,l!==null?l.sibling=u:t.child=u,a.last=u)}return a.tail!==null?(l=a.tail,a.rendering=l,a.tail=l.sibling,a.renderingStartTime=lt(),l.sibling=null,e=zl.current,R(zl,n?e&1|2:e&1),al&&Yt(t,a.treeForkCount),l):(Sl(t),null);case 22:case 23:return it(t),Zi(),a=t.memoizedState!==null,l!==null?l.memoizedState!==null!==a&&(t.flags|=8192):a&&(t.flags|=8192),a?(e&536870912)!==0&&(t.flags&128)===0&&(Sl(t),t.subtreeFlags&6&&(t.flags|=8192)):Sl(t),e=t.updateQueue,e!==null&&hu(t,e.retryQueue),e=null,l!==null&&l.memoizedState!==null&&l.memoizedState.cachePool!==null&&(e=l.memoizedState.cachePool.pool),a=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(a=t.memoizedState.cachePool.pool),a!==e&&(t.flags|=2048),l!==null&&z(Be),null;case 24:return e=null,l!==null&&(e=l.memoizedState.cache),t.memoizedState.cache!==e&&(t.flags|=2048),Xt(_l),Sl(t),null;case 25:return null;case 30:return null}throw Error(h(156,t.tag))}function am(l,t){switch(Ei(t),t.tag){case 1:return l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 3:return Xt(_l),Tl(),l=t.flags,(l&65536)!==0&&(l&128)===0?(t.flags=l&-65537|128,t):null;case 26:case 27:case 5:return zn(t),null;case 31:if(t.memoizedState!==null){if(it(t),t.alternate===null)throw Error(h(340));Ce()}return l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 13:if(it(t),l=t.memoizedState,l!==null&&l.dehydrated!==null){if(t.alternate===null)throw Error(h(340));Ce()}return l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 19:return z(zl),null;case 4:return Tl(),null;case 10:return Xt(t.type),null;case 22:case 23:return it(t),Zi(),l!==null&&z(Be),l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 24:return Xt(_l),null;case 25:return null;default:return null}}function Lo(l,t){switch(Ei(t),t.tag){case 3:Xt(_l),Tl();break;case 26:case 27:case 5:zn(t);break;case 4:Tl();break;case 31:t.memoizedState!==null&&it(t);break;case 13:it(t);break;case 19:z(zl);break;case 10:Xt(t.type);break;case 22:case 23:it(t),Zi(),l!==null&&z(Be);break;case 24:Xt(_l)}}function nn(l,t){try{var e=t.updateQueue,a=e!==null?e.lastEffect:null;if(a!==null){var n=a.next;e=n;do{if((e.tag&l)===l){a=void 0;var u=e.create,i=e.inst;a=u(),i.destroy=a}e=e.next}while(e!==n)}}catch(f){ol(t,t.return,f)}}function oe(l,t,e){try{var a=t.updateQueue,n=a!==null?a.lastEffect:null;if(n!==null){var u=n.next;a=u;do{if((a.tag&l)===l){var i=a.inst,f=i.destroy;if(f!==void 0){i.destroy=void 0,n=t;var s=e,v=f;try{v()}catch(p){ol(n,s,p)}}}a=a.next}while(a!==u)}}catch(p){ol(t,t.return,p)}}function Vo(l){var t=l.updateQueue;if(t!==null){var e=l.stateNode;try{Us(t,e)}catch(a){ol(l,l.return,a)}}}function Ko(l,t,e){e.props=Xe(l.type,l.memoizedProps),e.state=l.memoizedState;try{e.componentWillUnmount()}catch(a){ol(l,t,a)}}function un(l,t){try{var e=l.ref;if(e!==null){switch(l.tag){case 26:case 27:case 5:var a=l.stateNode;break;case 30:a=l.stateNode;break;default:a=l.stateNode}typeof e=="function"?l.refCleanup=e(a):e.current=a}}catch(n){ol(l,t,n)}}function Dt(l,t){var e=l.ref,a=l.refCleanup;if(e!==null)if(typeof a=="function")try{a()}catch(n){ol(l,t,n)}finally{l.refCleanup=null,l=l.alternate,l!=null&&(l.refCleanup=null)}else if(typeof e=="function")try{e(null)}catch(n){ol(l,t,n)}else e.current=null}function Jo(l){var t=l.type,e=l.memoizedProps,a=l.stateNode;try{l:switch(t){case"button":case"input":case"select":case"textarea":e.autoFocus&&a.focus();break l;case"img":e.src?a.src=e.src:e.srcSet&&(a.srcset=e.srcSet)}}catch(n){ol(l,l.return,n)}}function bc(l,t,e){try{var a=l.stateNode;Am(a,l.type,e,t),a[Jl]=t}catch(n){ol(l,l.return,n)}}function wo(l){return l.tag===5||l.tag===3||l.tag===26||l.tag===27&&ge(l.type)||l.tag===4}function xc(l){l:for(;;){for(;l.sibling===null;){if(l.return===null||wo(l.return))return null;l=l.return}for(l.sibling.return=l.return,l=l.sibling;l.tag!==5&&l.tag!==6&&l.tag!==18;){if(l.tag===27&&ge(l.type)||l.flags&2||l.child===null||l.tag===4)continue l;l.child.return=l,l=l.child}if(!(l.flags&2))return l.stateNode}}function jc(l,t,e){var a=l.tag;if(a===5||a===6)l=l.stateNode,t?(e.nodeType===9?e.body:e.nodeName==="HTML"?e.ownerDocument.body:e).insertBefore(l,t):(t=e.nodeType===9?e.body:e.nodeName==="HTML"?e.ownerDocument.body:e,t.appendChild(l),e=e._reactRootContainer,e!=null||t.onclick!==null||(t.onclick=Bt));else if(a!==4&&(a===27&&ge(l.type)&&(e=l.stateNode,t=null),l=l.child,l!==null))for(jc(l,t,e),l=l.sibling;l!==null;)jc(l,t,e),l=l.sibling}function mu(l,t,e){var a=l.tag;if(a===5||a===6)l=l.stateNode,t?e.insertBefore(l,t):e.appendChild(l);else if(a!==4&&(a===27&&ge(l.type)&&(e=l.stateNode),l=l.child,l!==null))for(mu(l,t,e),l=l.sibling;l!==null;)mu(l,t,e),l=l.sibling}function ko(l){var t=l.stateNode,e=l.memoizedProps;try{for(var a=l.type,n=t.attributes;n.length;)t.removeAttributeNode(n[0]);Yl(t,a,e),t[Rl]=l,t[Jl]=e}catch(u){ol(l,l.return,u)}}var Kt=!1,Nl=!1,Tc=!1,$o=typeof WeakSet=="function"?WeakSet:Set,Ul=null;function nm(l,t){if(l=l.containerInfo,Vc=Bu,l=is(l),vi(l)){if("selectionStart"in l)var e={start:l.selectionStart,end:l.selectionEnd};else l:{e=(e=l.ownerDocument)&&e.defaultView||window;var a=e.getSelection&&e.getSelection();if(a&&a.rangeCount!==0){e=a.anchorNode;var n=a.anchorOffset,u=a.focusNode;a=a.focusOffset;try{e.nodeType,u.nodeType}catch{e=null;break l}var i=0,f=-1,s=-1,v=0,p=0,T=l,g=null;t:for(;;){for(var S;T!==e||n!==0&&T.nodeType!==3||(f=i+n),T!==u||a!==0&&T.nodeType!==3||(s=i+a),T.nodeType===3&&(i+=T.nodeValue.length),(S=T.firstChild)!==null;)g=T,T=S;for(;;){if(T===l)break t;if(g===e&&++v===n&&(f=i),g===u&&++p===a&&(s=i),(S=T.nextSibling)!==null)break;T=g,g=T.parentNode}T=S}e=f===-1||s===-1?null:{start:f,end:s}}else e=null}e=e||{start:0,end:0}}else e=null;for(Kc={focusedElem:l,selectionRange:e},Bu=!1,Ul=t;Ul!==null;)if(t=Ul,l=t.child,(t.subtreeFlags&1028)!==0&&l!==null)l.return=t,Ul=l;else for(;Ul!==null;){switch(t=Ul,u=t.alternate,l=t.flags,t.tag){case 0:if((l&4)!==0&&(l=t.updateQueue,l=l!==null?l.events:null,l!==null))for(e=0;e title"))),Yl(u,a,e),u[Rl]=l,Cl(u),a=u;break l;case"link":var i=td("link","href",n).get(a+(e.href||""));if(i){for(var f=0;fml&&(i=ml,ml=X,X=i);var m=ns(f,X),r=ns(f,ml);if(m&&r&&(S.rangeCount!==1||S.anchorNode!==m.node||S.anchorOffset!==m.offset||S.focusNode!==r.node||S.focusOffset!==r.offset)){var y=T.createRange();y.setStart(m.node,m.offset),S.removeAllRanges(),X>ml?(S.addRange(y),S.extend(r.node,r.offset)):(y.setEnd(r.node,r.offset),S.addRange(y))}}}}for(T=[],S=f;S=S.parentNode;)S.nodeType===1&&T.push({element:S,left:S.scrollLeft,top:S.scrollTop});for(typeof f.focus=="function"&&f.focus(),f=0;fe?32:e,x.T=null,e=Mc,Mc=null;var u=me,i=Wt;if(Dl=0,ba=me=null,Wt=0,(cl&6)!==0)throw Error(h(331));var f=cl;if(cl|=4,ir(u.current),ar(u,u.current,i,e),cl=f,dn(0,!1),tt&&typeof tt.onPostCommitFiberRoot=="function")try{tt.onPostCommitFiberRoot(Na,u)}catch{}return!0}finally{U.p=n,x.T=a,zr(l,t)}}function _r(l,t,e){t=yt(e,t),t=sc(l.stateNode,t,2),l=ce(l,t,2),l!==null&&(Da(l,2),Ct(l))}function ol(l,t,e){if(l.tag===3)_r(l,l,e);else for(;t!==null;){if(t.tag===3){_r(t,l,e);break}else if(t.tag===1){var a=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof a.componentDidCatch=="function"&&(he===null||!he.has(a))){l=yt(e,l),e=Eo(2),a=ce(t,e,2),a!==null&&(Oo(e,a,t,l),Da(a,2),Ct(a));break}}t=t.return}}function Rc(l,t,e){var a=l.pingCache;if(a===null){a=l.pingCache=new cm;var n=new Set;a.set(t,n)}else n=a.get(t),n===void 0&&(n=new Set,a.set(t,n));n.has(e)||(_c=!0,n.add(e),l=dm.bind(null,l,t,e),t.then(l,l))}function dm(l,t,e){var a=l.pingCache;a!==null&&a.delete(t),l.pingedLanes|=l.suspendedLanes&e,l.warmLanes&=~e,vl===l&&(P&e)===e&&(jl===4||jl===3&&(P&62914560)===P&&300>lt()-gu?(cl&2)===0&&xa(l,0):Ec|=e,pa===P&&(pa=0)),Ct(l)}function Er(l,t){t===0&&(t=bf()),l=Me(l,t),l!==null&&(Da(l,t),Ct(l))}function hm(l){var t=l.memoizedState,e=0;t!==null&&(e=t.retryLane),Er(l,e)}function mm(l,t){var e=0;switch(l.tag){case 31:case 13:var a=l.stateNode,n=l.memoizedState;n!==null&&(e=n.retryLane);break;case 19:a=l.stateNode;break;case 22:a=l.stateNode._retryCache;break;default:throw Error(h(314))}a!==null&&a.delete(t),Er(l,e)}function ym(l,t){return wu(l,t)}var zu=null,Ta=null,Bc=!1,Au=!1,Hc=!1,ve=0;function Ct(l){l!==Ta&&l.next===null&&(Ta===null?zu=Ta=l:Ta=Ta.next=l),Au=!0,Bc||(Bc=!0,gm())}function dn(l,t){if(!Hc&&Au){Hc=!0;do for(var e=!1,a=zu;a!==null;){if(l!==0){var n=a.pendingLanes;if(n===0)var u=0;else{var i=a.suspendedLanes,f=a.pingedLanes;u=(1<<31-et(42|l)+1)-1,u&=n&~(i&~f),u=u&201326741?u&201326741|1:u?u|2:0}u!==0&&(e=!0,Dr(a,u))}else u=P,u=Nn(a,a===vl?u:0,a.cancelPendingCommit!==null||a.timeoutHandle!==-1),(u&3)===0||Ma(a,u)||(e=!0,Dr(a,u));a=a.next}while(e);Hc=!1}}function vm(){Or()}function Or(){Au=Bc=!1;var l=0;ve!==0&&Em()&&(l=ve);for(var t=lt(),e=null,a=zu;a!==null;){var n=a.next,u=Nr(a,t);u===0?(a.next=null,e===null?zu=n:e.next=n,n===null&&(Ta=e)):(e=a,(l!==0||(u&3)!==0)&&(Au=!0)),a=n}Dl!==0&&Dl!==5||dn(l),ve!==0&&(ve=0)}function Nr(l,t){for(var e=l.suspendedLanes,a=l.pingedLanes,n=l.expirationTimes,u=l.pendingLanes&-62914561;0f)break;var p=s.transferSize,T=s.initiatorType;p&&Gr(T)&&(s=s.responseEnd,i+=p*(s"u"?null:document;function Fr(l,t,e){var a=za;if(a&&typeof t=="string"&&t){var n=ht(t);n='link[rel="'+l+'"][href="'+n+'"]',typeof e=="string"&&(n+='[crossorigin="'+e+'"]'),Wr.has(n)||(Wr.add(n),l={rel:l,crossOrigin:e,href:t},a.querySelector(n)===null&&(t=a.createElement("link"),Yl(t,"link",l),Cl(t),a.head.appendChild(t)))}}function Hm(l){Ft.D(l),Fr("dns-prefetch",l,null)}function qm(l,t){Ft.C(l,t),Fr("preconnect",l,t)}function Ym(l,t,e){Ft.L(l,t,e);var a=za;if(a&&l&&t){var n='link[rel="preload"][as="'+ht(t)+'"]';t==="image"&&e&&e.imageSrcSet?(n+='[imagesrcset="'+ht(e.imageSrcSet)+'"]',typeof e.imageSizes=="string"&&(n+='[imagesizes="'+ht(e.imageSizes)+'"]')):n+='[href="'+ht(l)+'"]';var u=n;switch(t){case"style":u=Aa(l);break;case"script":u=_a(l)}xt.has(u)||(l=M({rel:"preload",href:t==="image"&&e&&e.imageSrcSet?void 0:l,as:t},e),xt.set(u,l),a.querySelector(n)!==null||t==="style"&&a.querySelector(vn(u))||t==="script"&&a.querySelector(gn(u))||(t=a.createElement("link"),Yl(t,"link",l),Cl(t),a.head.appendChild(t)))}}function Gm(l,t){Ft.m(l,t);var e=za;if(e&&l){var a=t&&typeof t.as=="string"?t.as:"script",n='link[rel="modulepreload"][as="'+ht(a)+'"][href="'+ht(l)+'"]',u=n;switch(a){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":u=_a(l)}if(!xt.has(u)&&(l=M({rel:"modulepreload",href:l},t),xt.set(u,l),e.querySelector(n)===null)){switch(a){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(e.querySelector(gn(u)))return}a=e.createElement("link"),Yl(a,"link",l),Cl(a),e.head.appendChild(a)}}}function Xm(l,t,e){Ft.S(l,t,e);var a=za;if(a&&l){var n=we(a).hoistableStyles,u=Aa(l);t=t||"default";var i=n.get(u);if(!i){var f={loading:0,preload:null};if(i=a.querySelector(vn(u)))f.loading=5;else{l=M({rel:"stylesheet",href:l,"data-precedence":t},e),(e=xt.get(u))&&Ic(l,e);var s=i=a.createElement("link");Cl(s),Yl(s,"link",l),s._p=new Promise(function(v,p){s.onload=v,s.onerror=p}),s.addEventListener("load",function(){f.loading|=1}),s.addEventListener("error",function(){f.loading|=2}),f.loading|=4,Mu(i,t,a)}i={type:"stylesheet",instance:i,count:1,state:f},n.set(u,i)}}}function Qm(l,t){Ft.X(l,t);var e=za;if(e&&l){var a=we(e).hoistableScripts,n=_a(l),u=a.get(n);u||(u=e.querySelector(gn(n)),u||(l=M({src:l,async:!0},t),(t=xt.get(n))&&Pc(l,t),u=e.createElement("script"),Cl(u),Yl(u,"link",l),e.head.appendChild(u)),u={type:"script",instance:u,count:1,state:null},a.set(n,u))}}function Zm(l,t){Ft.M(l,t);var e=za;if(e&&l){var a=we(e).hoistableScripts,n=_a(l),u=a.get(n);u||(u=e.querySelector(gn(n)),u||(l=M({src:l,async:!0,type:"module"},t),(t=xt.get(n))&&Pc(l,t),u=e.createElement("script"),Cl(u),Yl(u,"link",l),e.head.appendChild(u)),u={type:"script",instance:u,count:1,state:null},a.set(n,u))}}function Ir(l,t,e,a){var n=(n=$.current)?Nu(n):null;if(!n)throw Error(h(446));switch(l){case"meta":case"title":return null;case"style":return typeof e.precedence=="string"&&typeof e.href=="string"?(t=Aa(e.href),e=we(n).hoistableStyles,a=e.get(t),a||(a={type:"style",instance:null,count:0,state:null},e.set(t,a)),a):{type:"void",instance:null,count:0,state:null};case"link":if(e.rel==="stylesheet"&&typeof e.href=="string"&&typeof e.precedence=="string"){l=Aa(e.href);var u=we(n).hoistableStyles,i=u.get(l);if(i||(n=n.ownerDocument||n,i={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},u.set(l,i),(u=n.querySelector(vn(l)))&&!u._p&&(i.instance=u,i.state.loading=5),xt.has(l)||(e={rel:"preload",as:"style",href:e.href,crossOrigin:e.crossOrigin,integrity:e.integrity,media:e.media,hrefLang:e.hrefLang,referrerPolicy:e.referrerPolicy},xt.set(l,e),u||Lm(n,l,e,i.state))),t&&a===null)throw Error(h(528,""));return i}if(t&&a!==null)throw Error(h(529,""));return null;case"script":return t=e.async,e=e.src,typeof e=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=_a(e),e=we(n).hoistableScripts,a=e.get(t),a||(a={type:"script",instance:null,count:0,state:null},e.set(t,a)),a):{type:"void",instance:null,count:0,state:null};default:throw Error(h(444,l))}}function Aa(l){return'href="'+ht(l)+'"'}function vn(l){return'link[rel="stylesheet"]['+l+"]"}function Pr(l){return M({},l,{"data-precedence":l.precedence,precedence:null})}function Lm(l,t,e,a){l.querySelector('link[rel="preload"][as="style"]['+t+"]")?a.loading=1:(t=l.createElement("link"),a.preload=t,t.addEventListener("load",function(){return a.loading|=1}),t.addEventListener("error",function(){return a.loading|=2}),Yl(t,"link",e),Cl(t),l.head.appendChild(t))}function _a(l){return'[src="'+ht(l)+'"]'}function gn(l){return"script[async]"+l}function ld(l,t,e){if(t.count++,t.instance===null)switch(t.type){case"style":var a=l.querySelector('style[data-href~="'+ht(e.href)+'"]');if(a)return t.instance=a,Cl(a),a;var n=M({},e,{"data-href":e.href,"data-precedence":e.precedence,href:null,precedence:null});return a=(l.ownerDocument||l).createElement("style"),Cl(a),Yl(a,"style",n),Mu(a,e.precedence,l),t.instance=a;case"stylesheet":n=Aa(e.href);var u=l.querySelector(vn(n));if(u)return t.state.loading|=4,t.instance=u,Cl(u),u;a=Pr(e),(n=xt.get(n))&&Ic(a,n),u=(l.ownerDocument||l).createElement("link"),Cl(u);var i=u;return i._p=new Promise(function(f,s){i.onload=f,i.onerror=s}),Yl(u,"link",a),t.state.loading|=4,Mu(u,e.precedence,l),t.instance=u;case"script":return u=_a(e.src),(n=l.querySelector(gn(u)))?(t.instance=n,Cl(n),n):(a=e,(n=xt.get(u))&&(a=M({},e),Pc(a,n)),l=l.ownerDocument||l,n=l.createElement("script"),Cl(n),Yl(n,"link",a),l.head.appendChild(n),t.instance=n);case"void":return null;default:throw Error(h(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(a=t.instance,t.state.loading|=4,Mu(a,e.precedence,l));return t.instance}function Mu(l,t,e){for(var a=e.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),n=a.length?a[a.length-1]:null,u=n,i=0;i title"):null)}function Vm(l,t,e){if(e===1||t.itemProp!=null)return!1;switch(l){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;switch(t.rel){case"stylesheet":return l=t.disabled,typeof t.precedence=="string"&&l==null;default:return!0}case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function ad(l){return!(l.type==="stylesheet"&&(l.state.loading&3)===0)}function Km(l,t,e,a){if(e.type==="stylesheet"&&(typeof a.media!="string"||matchMedia(a.media).matches!==!1)&&(e.state.loading&4)===0){if(e.instance===null){var n=Aa(a.href),u=t.querySelector(vn(n));if(u){t=u._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(l.count++,l=Cu.bind(l),t.then(l,l)),e.state.loading|=4,e.instance=u,Cl(u);return}u=t.ownerDocument||t,a=Pr(a),(n=xt.get(n))&&Ic(a,n),u=u.createElement("link"),Cl(u);var i=u;i._p=new Promise(function(f,s){i.onload=f,i.onerror=s}),Yl(u,"link",a),e.instance=u}l.stylesheets===null&&(l.stylesheets=new Map),l.stylesheets.set(e,t),(t=e.state.preload)&&(e.state.loading&3)===0&&(l.count++,e=Cu.bind(l),t.addEventListener("load",e),t.addEventListener("error",e))}}var lf=0;function Jm(l,t){return l.stylesheets&&l.count===0&&Ru(l,l.stylesheets),0lf?50:800)+t);return l.unsuspend=e,function(){l.unsuspend=null,clearTimeout(a),clearTimeout(n)}}:null}function Cu(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Ru(this,this.stylesheets);else if(this.unsuspend){var l=this.unsuspend;this.unsuspend=null,l()}}}var Uu=null;function Ru(l,t){l.stylesheets=null,l.unsuspend!==null&&(l.count++,Uu=new Map,t.forEach(wm,l),Uu=null,Cu.call(l))}function wm(l,t){if(!(t.state.loading&4)){var e=Uu.get(l);if(e)var a=e.get(null);else{e=new Map,Uu.set(l,e);for(var n=l.querySelectorAll("link[data-precedence],style[data-precedence]"),u=0;u"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(o)}catch(D){console.error(D)}}return o(),of.exports=sy(),of.exports}var ry=oy();const dy=Md(ry),Cd="";async function ot(o,D){const O=await fetch(`${Cd}${o}`,{...D,credentials:"same-origin",headers:{"Content-Type":"application/json",...D==null?void 0:D.headers}});if(O.status===401)throw window.location.hash="#login",new Error("Unauthorized");if(!O.ok){const h=await O.json().catch(()=>({}));throw new Error(h.error||`HTTP ${O.status}`)}return O.json()}async function hy(o){const D=await fetch(`${Cd}${o}`,{credentials:"same-origin"});if(D.status===401)throw window.location.hash="#login",new Error("Unauthorized");if(!D.ok)throw new Error(`HTTP ${D.status}`);return D.text()}const Pl={login:o=>ot("/admin/login",{method:"POST",body:JSON.stringify({token:o})}),signOutEverywhere:()=>ot("/admin/api/sign-out-everywhere",{method:"POST"}),stats:()=>ot("/admin/api/stats"),health:()=>ot("/admin/api/health-indicators"),agents:()=>ot("/admin/api/agents"),requests:(o=1,D="")=>ot(`/admin/api/requests?page=${o}${D}`),apiKeys:()=>ot("/admin/api/api-keys"),createApiKey:o=>ot("/admin/api/api-keys",{method:"POST",body:JSON.stringify({name:o})}),revokeApiKey:o=>ot("/admin/api/api-keys/revoke",{method:"POST",body:JSON.stringify({name:o})}),updateClientTtl:(o,D)=>ot("/admin/api/update-client-ttl",{method:"POST",body:JSON.stringify({clientId:o,tokenTtl:D})}),revokeClient:o=>ot("/admin/api/revoke-client",{method:"POST",body:JSON.stringify({clientId:o})}),calibrationProfile:o=>ot(`/admin/api/calibration/profile${o?`?holder=${encodeURIComponent(o)}`:""}`),calibrationChart:(o,D)=>hy(`/admin/api/calibration/charts/${encodeURIComponent(o)}${D?`?holder=${encodeURIComponent(D)}`:""}`),jobsWatch:()=>ot("/admin/api/jobs/watch")};function my({onLogin:o}){const[D,O]=K.useState(""),[h,E]=K.useState(""),[N,C]=K.useState(!1),Q=async _=>{_.preventDefault(),E(""),C(!0);try{await Pl.login(D),O(""),o()}catch{E("Invalid token.")}finally{C(!1)}};return c.jsx("div",{className:"login-page",children:c.jsxs("div",{className:"login-box",children:[c.jsx("div",{className:"login-logo",children:"GBrain"}),c.jsxs("div",{style:{background:"rgba(136, 170, 255, 0.08)",border:"1px solid rgba(136, 170, 255, 0.2)",borderRadius:8,padding:"14px 16px",marginBottom:20,fontSize:13,lineHeight:1.5,color:"var(--text-secondary)"},children:[c.jsx("div",{style:{fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"πŸ”’ This is a protected dashboard"}),"Ask your AI agent for the admin login link:",c.jsx("div",{style:{background:"rgba(0,0,0,0.3)",borderRadius:6,padding:"8px 12px",marginTop:8,fontFamily:"var(--font-mono)",fontSize:12,color:"#88aaff",wordBreak:"break-all"},children:'"Give me the GBrain admin login link"'}),c.jsx("div",{style:{marginTop:8,fontSize:12,color:"var(--text-muted)"},children:"Each link is single-use. Your agent generates a fresh one each time."})]}),c.jsxs("details",{style:{marginBottom:16},children:[c.jsx("summary",{style:{cursor:"pointer",fontSize:13,color:"var(--text-muted)"},children:"Or paste bootstrap token manually"}),c.jsxs("form",{onSubmit:Q,style:{marginTop:12},children:[c.jsx("div",{style:{marginBottom:12},children:c.jsx("input",{type:"password",placeholder:"Admin Token",value:D,onChange:_=>O(_.target.value)})}),c.jsx("button",{className:"btn btn-primary",style:{width:"100%"},disabled:N,children:N?"Authenticating...":"Submit"}),h&&c.jsx("div",{className:"login-error",children:h})]})]})]})})}function yy(){const[o,D]=K.useState({connected_agents:0,requests_today:0,active_tokens:0}),[O,h]=K.useState({expiring_soon:0,error_rate:"0%"}),[E,N]=K.useState([]),[C,Q]=K.useState("connecting"),_=K.useRef(null);K.useEffect(()=>{Pl.stats().then(D).catch(()=>{}),Pl.health().then(h).catch(()=>{});const H=new EventSource("/admin/events",{withCredentials:!0});_.current=H,H.onopen=()=>Q("connected"),H.onmessage=A=>{try{const I=JSON.parse(A.data);N(L=>[I,...L].slice(0,50))}catch{}},H.onerror=()=>{Q("disconnected"),setTimeout(()=>{Q("connecting"),H.close()},3e3)};const M=setInterval(()=>{Pl.stats().then(D).catch(()=>{}),Pl.health().then(h).catch(()=>{})},3e4);return()=>{H.close(),clearInterval(M)}},[]);const b=H=>{const M=Date.now()-new Date(H).getTime();return M<6e4?`${Math.floor(M/1e3)}s ago`:M<36e5?`${Math.floor(M/6e4)} min ago`:`${Math.floor(M/36e5)}h ago`};return c.jsxs(c.Fragment,{children:[c.jsx("h1",{className:"page-title",children:"Dashboard"}),c.jsxs("div",{style:{display:"flex",gap:24},children:[c.jsxs("div",{style:{flex:1},children:[c.jsxs("div",{className:"metrics",children:[c.jsxs("div",{className:"metric",children:[c.jsx("div",{className:"metric-value",children:o.connected_agents}),c.jsx("div",{className:"metric-label",children:"Connected Agents"})]}),c.jsxs("div",{className:"metric",children:[c.jsx("div",{className:"metric-value",children:o.requests_today}),c.jsx("div",{className:"metric-label",children:"Requests Today"})]}),c.jsxs("div",{className:"metric",children:[c.jsx("div",{className:"metric-value",children:o.active_tokens}),c.jsx("div",{className:"metric-label",children:"Active Tokens"})]})]}),c.jsxs("h2",{className:"section-title",children:["Live Activity",c.jsx("span",{style:{marginLeft:8,fontSize:10,color:C==="connected"?"var(--success)":C==="connecting"?"var(--warning)":"var(--error)"},children:C==="connected"?"● connected":C==="connecting"?"● connecting...":"● disconnected"})]}),c.jsx("div",{className:"feed",children:E.length===0?c.jsx("div",{className:"feed-empty",children:C==="connected"?"No requests yet. Agents will appear when they connect.":"Connecting..."}):c.jsxs("table",{children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Agent"}),c.jsx("th",{children:"Operation"}),c.jsx("th",{children:"Scopes"}),c.jsx("th",{children:"Latency"}),c.jsx("th",{children:"Status"}),c.jsx("th",{children:"Time"})]})}),c.jsx("tbody",{children:E.map((H,M)=>c.jsxs("tr",{children:[c.jsx("td",{className:"mono",children:H.agent}),c.jsx("td",{className:"mono",children:H.operation}),c.jsx("td",{children:H.scopes.split(",").map(A=>c.jsx("span",{className:`badge badge-${A.trim()}`,style:{marginRight:4},children:A.trim()},A))}),c.jsxs("td",{className:"mono",children:[H.latency_ms," ms"]}),c.jsx("td",{children:c.jsx("span",{className:`badge badge-${H.status}`,children:H.status})}),c.jsx("td",{style:{color:"var(--text-secondary)"},children:b(H.timestamp)})]},M))})]})})]}),c.jsxs("div",{style:{width:220},children:[c.jsx("h2",{className:"section-title",children:"Token Health"}),c.jsxs("div",{className:"health-panel",children:[c.jsxs("div",{className:"health-row",children:[c.jsx("span",{style:{color:"var(--warning)"},children:"Expiring Soon"}),c.jsx("span",{className:"mono",children:O.expiring_soon})]}),c.jsxs("div",{className:"health-row",children:[c.jsx("span",{style:{color:"var(--error)"},children:"Error Rate"}),c.jsx("span",{className:"mono",children:O.error_rate})]})]})]})]})]})}const Ed=["admin","agent","read","sources_admin","users_admin","write"];function vy(o){const D=Math.floor((Date.now()-o.getTime())/1e3);return D<60?"just now":D<3600?`${Math.floor(D/60)}m ago`:D<86400?`${Math.floor(D/3600)}h ago`:`${Math.floor(D/86400)}d ago`}function gy(){const[o,D]=K.useState([]),[O,h]=K.useState(!0),[E,N]=K.useState(!1),[C,Q]=K.useState(null),[_,b]=K.useState(!1),[H,M]=K.useState(null),[A,I]=K.useState(null);K.useEffect(()=>{L()},[]);const L=()=>{Pl.agents().then(D).catch(()=>{})};return c.jsxs(c.Fragment,{children:[c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:24},children:[c.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"Agents"}),c.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[c.jsxs("label",{style:{fontSize:13,color:"var(--text-secondary)",display:"flex",alignItems:"center",gap:6,cursor:"pointer"},children:[c.jsx("input",{type:"checkbox",checked:O,onChange:nl=>h(nl.target.checked)})," Hide revoked"]}),c.jsx("button",{className:"btn btn-secondary",onClick:()=>b(!0),children:"+ API Key"}),c.jsx("button",{className:"btn btn-primary",onClick:()=>N(!0),children:"+ OAuth Client"})]})]}),(()=>{const nl=o.filter(tl=>!O||tl.status!=="revoked");return o.length===0?c.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--text-muted)"},children:"No agents registered. Register your first agent to get started."}):nl.length===0?c.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--text-muted)"},children:'All agents are revoked. Uncheck "Hide revoked" to view them.'}):c.jsxs(c.Fragment,{children:[c.jsxs("table",{children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Name"}),c.jsx("th",{children:"Type"}),c.jsx("th",{children:"Scopes"}),c.jsx("th",{children:"Status"}),c.jsx("th",{children:"Requests"}),c.jsx("th",{children:"Last Used"})]})}),c.jsx("tbody",{children:nl.map(tl=>c.jsxs("tr",{onClick:()=>I(tl),style:{cursor:"pointer"},children:[c.jsx("td",{style:{fontWeight:500},children:tl.name||tl.client_name}),c.jsx("td",{children:c.jsx("span",{className:`badge ${tl.auth_type==="oauth"?"badge-read":"badge-write"}`,style:{fontSize:11},children:tl.auth_type==="oauth"?"OAuth":"API Key"})}),c.jsx("td",{children:(tl.scope||"").split(" ").filter(Boolean).map(bl=>c.jsx("span",{className:`badge badge-${bl}`,style:{marginRight:4},children:bl},bl))}),c.jsx("td",{children:c.jsx("span",{className:`badge ${tl.status==="active"?"badge-success":"badge-danger"}`,children:tl.status})}),c.jsxs("td",{children:[c.jsx("span",{style:{fontWeight:500},children:tl.requests_today||0}),c.jsxs("span",{style:{color:"var(--text-muted)",fontSize:12},children:[" / ",tl.total_requests||0]})]}),c.jsx("td",{style:{color:"var(--text-secondary)"},children:tl.last_used_at?vy(new Date(tl.last_used_at)):"Never"})]},tl.id))})]}),c.jsxs("div",{style:{color:"var(--text-muted)",fontSize:13,marginTop:12},children:[o.filter(tl=>tl.status==="active").length," active / ",o.length," total"]})]})})(),E&&c.jsx(by,{onClose:()=>N(!1),onRegistered:nl=>{N(!1),Q(nl),L()}}),C&&c.jsx(xy,{credentials:C,onClose:()=>Q(null)}),A&&c.jsx(jy,{agent:A,onClose:()=>I(null),onRevoked:L}),_&&c.jsx(Sy,{onClose:()=>b(!1),onCreated:nl=>{b(!1),M(nl),L()}}),H&&c.jsx(py,{token:H,onClose:()=>M(null)})]})}function Sy({onClose:o,onCreated:D}){const[O,h]=K.useState(""),[E,N]=K.useState(!1),[C,Q]=K.useState(""),_=async b=>{if(b.preventDefault(),!O.trim()){Q("Name required");return}N(!0);try{const H=await Pl.createApiKey(O.trim());D({name:H.name,token:H.token})}catch(H){Q(H instanceof Error?H.message:"Failed")}finally{N(!1)}};return c.jsx("div",{className:"modal-overlay",onClick:o,children:c.jsxs("form",{className:"modal",onClick:b=>b.stopPropagation(),onSubmit:_,children:[c.jsx("div",{className:"modal-title",children:"Create API Key"}),c.jsx("p",{style:{color:"var(--text-secondary)",fontSize:13,marginBottom:16},children:"API keys use simple bearer token auth. They grant full read+write+admin access. For scoped access, use OAuth clients instead."}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Key Name"}),c.jsx("input",{placeholder:"e.g. claude-code-local",value:O,onChange:b=>h(b.target.value),autoFocus:!0})]}),C&&c.jsx("div",{style:{color:"var(--error)",fontSize:13,marginBottom:12},children:C}),c.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",className:"btn btn-secondary",onClick:o,children:"Cancel"}),c.jsx("button",{type:"submit",className:"btn btn-primary",disabled:E,children:E?"Creating...":"Create Key"})]})]})})}function py({token:o,onClose:D}){const O=h=>navigator.clipboard.writeText(h);return c.jsx("div",{className:"modal-overlay",children:c.jsxs("div",{className:"modal",style:{maxWidth:560},children:[c.jsxs("div",{style:{textAlign:"center",marginBottom:16},children:[c.jsx("div",{style:{fontSize:36,color:"var(--success)",marginBottom:8},children:"βœ“"}),c.jsx("div",{style:{fontSize:20,fontWeight:600},children:"API Key Created"})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Name"}),c.jsx("div",{className:"code-block",children:c.jsx("span",{children:o.name})})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Bearer Token"}),c.jsxs("div",{className:"code-block",children:[c.jsx("span",{children:o.token}),c.jsx("button",{className:"copy-btn",onClick:()=>O(o.token),children:"Copy"})]})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Usage"}),c.jsxs("div",{className:"code-block",children:[c.jsx("pre",{style:{whiteSpace:"pre-wrap",margin:0,fontSize:12},children:`Authorization: Bearer ${o.token}`}),c.jsx("button",{className:"copy-btn",onClick:()=>O(`Authorization: Bearer ${o.token}`),children:"Copy"})]})]}),c.jsx("div",{className:"warning-bar",children:"Save this token now. It will not be shown again."}),c.jsx("div",{style:{display:"flex",gap:12,justifyContent:"flex-end",marginTop:20},children:c.jsx("button",{className:"btn btn-primary",onClick:D,children:"Done"})})]})})}function by({onClose:o,onRegistered:D}){const[O,h]=K.useState(""),[E,N]=K.useState(()=>Object.fromEntries(Ed.map(L=>[L,L==="read"]))),[C,Q]=K.useState("86400"),[_,b]=K.useState(!1),[H,M]=K.useState(""),A=[{label:"1 hour",value:"3600"},{label:"24 hours",value:"86400"},{label:"7 days",value:"604800"},{label:"30 days",value:"2592000"},{label:"1 year",value:"31536000"},{label:"No expiry",value:"0"}],I=async L=>{if(L.preventDefault(),!O.trim()){M("Name required");return}b(!0),M("");try{const nl=Object.entries(E).filter(([,Ml])=>Ml).map(([Ml])=>Ml).join(" "),tl=await fetch("/admin/api/register-client",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O.trim(),scopes:nl,tokenTtl:C==="0"?31536e4:Number(C)})});if(!tl.ok)throw new Error("Registration failed");const bl=await tl.json();D({clientId:bl.clientId,clientSecret:bl.clientSecret,name:O.trim()})}catch(nl){M(nl instanceof Error?nl.message:"Registration failed")}finally{b(!1)}};return c.jsx("div",{className:"modal-overlay",onClick:o,children:c.jsxs("form",{className:"modal",onClick:L=>L.stopPropagation(),onSubmit:I,children:[c.jsx("div",{className:"modal-title",children:"Register Agent"}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Agent Name"}),c.jsx("input",{placeholder:"e.g. perplexity-production",value:O,onChange:L=>h(L.target.value),autoFocus:!0})]}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Scopes"}),c.jsx("div",{className:"checkbox-group",children:Ed.map(L=>c.jsxs("label",{className:"checkbox-label",children:[c.jsx("input",{type:"checkbox",checked:E[L],onChange:nl=>N(tl=>({...tl,[L]:nl.target.checked}))}),L]},L))})]}),c.jsxs("div",{style:{marginBottom:20},children:[c.jsx("label",{children:"Token Lifetime"}),c.jsx("select",{value:C,onChange:L=>Q(L.target.value),style:{width:"100%",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:6,padding:"6px 10px",fontSize:14},children:A.map(L=>c.jsx("option",{value:L.value,children:L.label},L.value))})]}),H&&c.jsx("div",{style:{color:"var(--error)",fontSize:13,marginBottom:12},children:H}),c.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",className:"btn btn-secondary",onClick:o,children:"Cancel"}),c.jsx("button",{type:"submit",className:"btn btn-primary",disabled:_,children:_?"Registering...":"Register"})]})]})})}function xy({credentials:o,onClose:D}){const O=E=>navigator.clipboard.writeText(E),h=()=>{const E=new Blob([JSON.stringify(o,null,2)],{type:"application/json"}),N=URL.createObjectURL(E),C=document.createElement("a");C.href=N,C.download=`${o.name}-credentials.json`,C.click(),URL.revokeObjectURL(N)};return c.jsx("div",{className:"modal-overlay",children:c.jsxs("div",{className:"modal",style:{maxWidth:560},children:[c.jsxs("div",{style:{textAlign:"center",marginBottom:16},children:[c.jsx("div",{style:{fontSize:36,color:"var(--success)",marginBottom:8},children:"βœ“"}),c.jsx("div",{style:{fontSize:20,fontWeight:600},children:"Agent Registered"})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Client ID"}),c.jsxs("div",{className:"code-block",children:[c.jsx("span",{children:o.clientId}),c.jsx("button",{className:"copy-btn",onClick:()=>O(o.clientId),children:"Copy"})]})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Client Secret"}),c.jsxs("div",{className:"code-block",children:[c.jsx("span",{children:o.clientSecret}),c.jsx("button",{className:"copy-btn",onClick:()=>O(o.clientSecret),children:"Copy"})]})]}),c.jsx("div",{className:"warning-bar",children:"Save this secret now. It will not be shown again."}),c.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"flex-end",marginTop:20},children:[c.jsx("button",{className:"btn btn-secondary",onClick:h,children:"Download as JSON"}),c.jsx("button",{className:"btn btn-primary",onClick:D,children:"Done"})]})]})})}function jy({agent:o,onClose:D,onRevoked:O}){const[h,E]=K.useState("claude-code"),N=M=>navigator.clipboard.writeText(M),C=window.location.origin,Q=o.id||o.client_id||"",_=o.auth_type==="oauth",b=o.name||o.client_name||"unknown",H={"claude-code":_?["The user wants to connect GBrain MCP to your context. Here's how.","","# Step 1 β€” read the client secret from the operator without putting it in shell history.","# read -s suppresses the echo; export keeps it scoped to this shell session.",'read -rs -p "Client Secret: " GBRAIN_CS && echo',"","# Step 2 β€” mint a token and register GBrain in one go.",`claude mcp add --transport http gbrain ${C}/mcp \\`,` --header "Authorization: Bearer $(curl -s -X POST ${C}/token \\`," -d 'grant_type=client_credentials' \\",` -d 'client_id=${Q}' \\`,' --data-urlencode "client_secret=$GBRAIN_CS" \\',` -d 'scope=${o.scope||"read write"}' | jq -r .access_token)"`,"","# Step 3 β€” clear the secret from this shell.","unset GBRAIN_CS","",`The token will last ${o.token_ttl?o.token_ttl>=86400?Math.floor(o.token_ttl/86400)+" days":Math.floor(o.token_ttl/3600)+" hours":"1 hour (default)"}.`,"","─── Fallback: 2-step curl + paste ───","","If your shell doesn't support read -s, mint the token first, then paste:","",`curl -s -X POST ${C}/token \\`," -d 'grant_type=client_credentials' \\",` -d 'client_id=${Q}' \\`," -d 'client_secret=PASTE_YOUR_CLIENT_SECRET_HERE' \\",` -d 'scope=${o.scope||"read write"}' | jq -r .access_token`,"",`claude mcp add --transport http gbrain ${C}/mcp \\`,' --header "Authorization: Bearer PASTE_TOKEN_FROM_ABOVE"',"","# Then run: history -d $((HISTCMD-1)) # zsh: print -s -- '' && fc -p"].join(` -`):["The user wants to connect GBrain MCP to your context. Here's how.","","Run this command in terminal to register GBrain:","",`claude mcp add --transport http gbrain ${C}/mcp \\`,' --header "Authorization: Bearer PASTE_YOUR_API_KEY_HERE"',"",`Replace PASTE_YOUR_API_KEY_HERE with the API key shown when "${b}" was created.`,"API keys never expire."].join(` -`),chatgpt:["The user wants to connect GBrain MCP to ChatGPT.","","1. Open ChatGPT > Settings > Tools & Integrations > Add MCP Server","2. Enter this URL β€” ChatGPT will auto-discover the OAuth configuration:","",` ${C}/.well-known/oauth-authorization-server`,"","3. When prompted for credentials:",` Client ID: ${Q}`," Client Secret: (the secret from agent registration)"," Grant Type: client_credentials",` Scope: ${o.scope||"read write"}`].join(` -`),"claude-cowork":["The user wants to connect GBrain MCP to Claude.ai.","","1. Open claude.ai > Settings > Connected Apps > Add MCP Server",`2. Server URL: ${C}/mcp`,"3. When prompted for auth:",` Token endpoint: ${C}/token`,` Client ID: ${Q}`," Client Secret: (the secret from agent registration)",` Scope: ${o.scope||"read write"}`,"",`Discovery URL: ${C}/.well-known/oauth-authorization-server`].join(` -`),cursor:_?["The user wants to connect GBrain MCP to Cursor.","","Cursor supports OAuth for remote MCP. Add to .cursor/mcp.json:","","{",' "mcpServers": {',' "gbrain": {',` "url": "${C}/mcp",`,' "transport": "sse"'," }"," }","}","","Cursor will auto-discover OAuth via:",`${C}/.well-known/oauth-authorization-server`,"",`When prompted: Client ID ${Q}, use the secret from registration.`].join(` -`):["The user wants to connect GBrain MCP to Cursor.","","Add to .cursor/mcp.json:","","{",' "mcpServers": {',' "gbrain": {',` "url": "${C}/mcp",`,' "transport": "sse",',' "headers": {',' "Authorization": "Bearer PASTE_YOUR_API_KEY_HERE"'," }"," }"," }","}","",`Replace PASTE_YOUR_API_KEY_HERE with the API key shown when "${b}" was created.`].join(` -`),perplexity:["The user wants to connect GBrain MCP to Perplexity.","","1. Go to Settings > Connectors > Add MCP",`2. Server URL: ${C}/mcp`,`3. Client ID: ${Q}`,"4. Client Secret: (the secret from agent registration)"].join(` -`),json:JSON.stringify({server_url:C+"/mcp",token_url:C+"/token",discovery_url:C+"/.well-known/oauth-authorization-server",client_id:Q,client_name:b,auth_type:o.auth_type,scope:o.scope},null,2)};return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"drawer-overlay",onClick:D}),c.jsxs("div",{className:"drawer",children:[c.jsx("button",{className:"drawer-close",onClick:D,children:"βœ•"}),c.jsx("div",{style:{fontSize:18,fontWeight:600,marginBottom:4},children:o.name||o.client_name}),c.jsx("span",{className:`badge ${o.status==="active"?"badge-success":"badge-danger"}`,children:o.status}),c.jsx("div",{className:"section-title",children:"Details"}),c.jsxs("div",{style:{display:"grid",gridTemplateColumns:"100px 1fr",gap:"6px 12px",fontSize:13},children:[c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Client ID"}),c.jsxs("span",{className:"mono",children:[(o.id||o.id||o.client_id||"").substring(0,24),"..."]}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Scopes"}),c.jsx("span",{children:(o.scope||"").split(" ").filter(Boolean).map(M=>c.jsx("span",{className:`badge badge-${M}`,style:{marginRight:4},children:M},M))}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Registered"}),c.jsx("span",{children:new Date(o.created_at).toLocaleDateString()}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Token TTL"}),c.jsx("span",{children:o.token_ttl?o.token_ttl>=31536e3?"No expiry":o.token_ttl>=86400?`${Math.floor(o.token_ttl/86400)}d`:o.token_ttl>=3600?`${Math.floor(o.token_ttl/3600)}h`:`${o.token_ttl}s`:"1h (default)"})]}),c.jsx("div",{className:"section-title",children:"Config Export"}),c.jsxs("div",{className:"tabs",style:{flexWrap:"wrap"},children:[c.jsx("div",{className:`tab ${h==="claude-code"?"active":""}`,onClick:()=>E("claude-code"),children:"Claude Code"}),c.jsx("div",{className:`tab ${h==="chatgpt"?"active":""}`,onClick:()=>E("chatgpt"),children:"ChatGPT"}),c.jsx("div",{className:`tab ${h==="claude-cowork"?"active":""}`,onClick:()=>E("claude-cowork"),children:"Claude.ai"}),c.jsx("div",{className:`tab ${h==="cursor"?"active":""}`,onClick:()=>E("cursor"),children:"Cursor"}),c.jsx("div",{className:`tab ${h==="perplexity"?"active":""}`,onClick:()=>E("perplexity"),children:"Perplexity"}),c.jsx("div",{className:`tab ${h==="json"?"active":""}`,onClick:()=>E("json"),children:"JSON"})]}),(()=>{if(!_&&new Set(["chatgpt","claude-cowork","perplexity"]).has(h)){const A={chatgpt:"ChatGPT","claude-cowork":"Claude.ai",perplexity:"Perplexity"}[h]||h;return c.jsxs("div",{style:{background:"rgba(255, 200, 100, 0.08)",border:"1px solid rgba(255, 200, 100, 0.2)",borderRadius:8,padding:"14px 16px",marginTop:12,fontSize:13,lineHeight:1.6,color:"var(--text-secondary)"},children:[c.jsxs("div",{style:{fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:[A," requires an OAuth client"]}),A," only supports OAuth 2.0 (client_credentials). API keys use raw bearer tokens, which ",A," does not accept. Register a separate OAuth client and use that to connect this AI."]})}return c.jsxs("div",{className:"code-block",children:[c.jsx("pre",{style:{whiteSpace:"pre-wrap",margin:0},children:H[h]}),c.jsx("button",{className:"copy-btn",onClick:()=>N(H[h]),children:"Copy"})]})})(),c.jsxs("div",{style:{marginTop:32},children:[o.status==="active"&&c.jsx("button",{className:"btn btn-danger",onClick:async()=>{if(confirm(`Revoke ${o.name||o.client_name}? All active tokens will be invalidated.`))try{o.auth_type==="oauth"?await Pl.revokeClient(o.id||o.client_id||""):await Pl.revokeApiKey(o.name||""),O(),D()}catch(M){alert("Revoke failed: "+(M instanceof Error?M.message:"unknown error"))}},children:"Revoke Agent"}),o.status==="revoked"&&c.jsx("span",{style:{color:"var(--text-muted)",fontSize:13},children:"This agent has been revoked."})]})]})]})}function Ty(){const[o,D]=K.useState({rows:[],total:0,page:1,pages:1}),[O,h]=K.useState(1),[E,N]=K.useState("all"),[C,Q]=K.useState(null);K.useEffect(()=>{_(O)},[O,E]);const _=A=>{const I=E!=="all"?`&agent=${encodeURIComponent(E)}`:"";Pl.requests(A,I).then(D).catch(()=>{})},b=A=>{const I=Date.now()-new Date(A).getTime();return I<6e4?`${Math.floor(I/1e3)}s ago`:I<36e5?`${Math.floor(I/6e4)} min ago`:I<864e5?`${Math.floor(I/36e5)}h ago`:new Date(A).toLocaleDateString()},H=A=>{if(!A)return null;const{query:I,slug:L,partial:nl,limit:tl,...bl}=A,Ml=[];return I&&Ml.push(`"${I}"`),L&&Ml.push(L),nl&&Ml.push(`~${nl}`),tl&&Ml.push(`limit=${tl}`),Object.keys(bl).length>0&&Ml.push(`+${Object.keys(bl).length} params`),Ml.join(" ")},M=new Map;return o.rows.forEach(A=>{A.token_name&&M.set(A.token_name,A.agent_name||A.token_name)}),c.jsxs(c.Fragment,{children:[c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:24},children:[c.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"Request Log"}),c.jsxs("select",{value:E,onChange:A=>{N(A.target.value),h(1)},style:{background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:6,padding:"4px 8px",fontSize:13},children:[c.jsx("option",{value:"all",children:"All agents"}),[...M.entries()].map(([A,I])=>c.jsx("option",{value:A,children:I},A))]})]}),o.rows.length===0?c.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--text-muted)"},children:"No requests yet."}):c.jsxs(c.Fragment,{children:[c.jsxs("table",{children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Time"}),c.jsx("th",{children:"Agent"}),c.jsx("th",{children:"Operation"}),c.jsx("th",{children:"Params"}),c.jsx("th",{children:"Latency"}),c.jsx("th",{children:"Status"})]})}),c.jsx("tbody",{children:o.rows.map(A=>c.jsxs(Dd.Fragment,{children:[c.jsxs("tr",{onClick:()=>Q(C===A.id?null:A.id),style:{cursor:"pointer"},children:[c.jsx("td",{style:{color:"var(--text-secondary)",whiteSpace:"nowrap"},children:b(A.created_at)}),c.jsx("td",{children:c.jsx("a",{style:{color:"var(--text-link, #88aaff)",cursor:"pointer",textDecoration:"none",fontWeight:500},onClick:I=>{I.stopPropagation(),N(A.token_name),h(1)},children:A.agent_name||A.token_name})}),c.jsx("td",{className:"mono",children:A.operation}),c.jsx("td",{style:{color:"var(--text-secondary)",fontSize:12,maxWidth:200,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:H(A.params)}),c.jsxs("td",{className:"mono",children:[A.latency_ms,"ms"]}),c.jsx("td",{children:c.jsx("span",{className:`badge badge-${A.status}`,children:A.status})})]}),C===A.id&&c.jsx("tr",{children:c.jsx("td",{colSpan:6,style:{background:"var(--bg-secondary, #0f0f1a)",padding:16},children:c.jsxs("div",{style:{display:"grid",gridTemplateColumns:"100px 1fr",gap:"6px 12px",fontSize:13},children:[c.jsx("span",{style:{color:"var(--text-muted)"},children:"Time"}),c.jsx("span",{children:new Date(A.created_at).toLocaleString()}),c.jsx("span",{style:{color:"var(--text-muted)"},children:"Agent"}),c.jsx("span",{className:"mono",children:A.token_name}),c.jsx("span",{style:{color:"var(--text-muted)"},children:"Operation"}),c.jsx("span",{className:"mono",children:A.operation}),c.jsx("span",{style:{color:"var(--text-muted)"},children:"Latency"}),c.jsxs("span",{children:[A.latency_ms,"ms"]}),A.params&&c.jsxs(c.Fragment,{children:[c.jsx("span",{style:{color:"var(--text-muted)"},children:"Params"}),c.jsx("pre",{className:"mono",style:{margin:0,whiteSpace:"pre-wrap",fontSize:12},children:JSON.stringify(A.params,null,2)})]}),A.error_message&&c.jsxs(c.Fragment,{children:[c.jsx("span",{style:{color:"var(--error, #ff6b6b)"},children:"Error"}),c.jsx("span",{style:{color:"var(--error, #ff6b6b)"},children:A.error_message})]})]})})})]},A.id))})]}),c.jsxs("div",{className:"pagination",children:[c.jsxs("span",{children:["Page ",o.page," of ",o.pages," (",o.total," total)"]}),c.jsxs("div",{style:{display:"flex",gap:8},children:[c.jsx("button",{disabled:o.page<=1,onClick:()=>h(A=>A-1),children:"Previous"}),c.jsx("button",{disabled:o.page>=o.pages,onClick:()=>h(A=>A+1),children:"Next"})]})]})]})]})}function zy({markup:o}){return c.jsx("div",{style:{width:"100%",overflow:"auto"},dangerouslySetInnerHTML:{__html:o}})}function Zu({type:o,ariaLabel:D}){const[O,h]=K.useState(""),[E,N]=K.useState("");return K.useEffect(()=>{let C=!1;return Pl.calibrationChart(o).then(Q=>{C||h(Q)}).catch(Q=>{C||N(Q.message??"fetch failed")}),()=>{C=!0}},[o]),E?c.jsxs("div",{style:{padding:16,color:"var(--error)"},role:"alert",children:[D,": ",E]}):O?c.jsx(zy,{markup:O}):c.jsxs("div",{style:{padding:16,color:"var(--text-muted)"},children:[D," loading..."]})}function Ay(){const[o,D]=K.useState(null),[O,h]=K.useState(!0),[E,N]=K.useState("");if(K.useEffect(()=>{Pl.calibrationProfile().then(_=>{D(_),h(!1)}).catch(_=>{N(_.message??"fetch failed"),h(!1)})},[]),O)return c.jsx("div",{style:{padding:24,color:"var(--text-secondary)"},children:"Loading calibration profile…"});if(E)return c.jsxs("div",{style:{padding:24,color:"var(--error)"},role:"alert",children:["Could not load calibration profile: ",E]});if(!o)return c.jsxs("div",{style:{padding:24,maxWidth:700},children:[c.jsx("h1",{style:{marginBottom:16},children:"Calibration"}),c.jsx("p",{style:{color:"var(--text-secondary)"},children:"No calibration profile yet. Builds after 5+ resolved takes."}),c.jsx("pre",{style:{background:"var(--bg-secondary)",padding:12,borderRadius:4,color:"var(--text-primary)",marginTop:12,fontFamily:"var(--font-mono)"},children:"gbrain dream --phase calibration_profile"})]});const C=new Date(o.generated_at),Q=Math.floor((Date.now()-C.getTime())/(1e3*60*60*24));return c.jsxs("div",{style:{padding:32,maxWidth:720},children:[c.jsx("h1",{style:{marginBottom:8},children:"Calibration"}),c.jsxs("div",{style:{color:"var(--text-muted)",fontSize:13,marginBottom:24},children:["Holder: ",o.holder," Β· ","Updated ",Q===0?"today":`${Q}d ago`,o.published&&" Β· published",o.grade_completion<.9&&` Β· ~${Math.round(o.grade_completion*100)}% graded`,!o.voice_gate_passed&&" Β· voice gate fell back to template"]}),c.jsx("section",{style:{marginBottom:32},children:c.jsx(Zu,{type:"brier-trend",ariaLabel:"Brier trend"})}),c.jsxs("section",{style:{marginBottom:32},children:[c.jsx("h2",{style:{fontSize:14,color:"var(--text-secondary)",marginBottom:12,fontWeight:400},children:"Pattern statements"}),c.jsx(Zu,{type:"pattern-statements",ariaLabel:"Pattern statements"})]}),c.jsx("section",{style:{marginBottom:32},children:c.jsx(Zu,{type:"domain-bars",ariaLabel:"Per-domain accuracy"})}),c.jsx("section",{style:{marginBottom:32},children:c.jsx(Zu,{type:"abandoned-threads",ariaLabel:"Abandoned threads"})}),o.active_bias_tags.length>0&&c.jsxs("section",{style:{marginBottom:32,color:"var(--text-muted)",fontSize:13},children:["Active bias tags: ",o.active_bias_tags.join(", ")]})]})}function _y(o){return o===0?"var(--accent-success, #2ea043)":o>=100?"var(--accent-danger, #f85149)":"var(--accent-warn, #d29922)"}function Od(o){return`$${(o/100).toFixed(2)}`}function Ey(){const[o,D]=K.useState(null),[O,h]=K.useState(null);if(K.useEffect(()=>{let N=!0,C=null;const Q=async()=>{try{const _=await Pl.jobsWatch();N&&(D(_),h(null))}catch(_){N&&h(_ instanceof Error?_.message:String(_))}N&&(C=setTimeout(Q,1e3))};return Q(),()=>{N=!1,C&&clearTimeout(C)}},[]),O)return c.jsxs("div",{style:{padding:24,color:"var(--accent-danger, #f85149)"},children:[c.jsx("h2",{children:"Jobs Watch β€” error"}),c.jsx("pre",{style:{whiteSpace:"pre-wrap"},children:O})]});if(!o)return c.jsx("div",{style:{padding:24,color:"var(--text-muted, #777)"},children:"Loading jobs watch…"});const E=new Date(o.ts_ms).toLocaleTimeString();return c.jsxs("div",{style:{padding:24,fontFamily:'var(--font-mono, "JetBrains Mono", monospace)'},children:[c.jsxs("h1",{style:{fontSize:18,marginBottom:4},children:["Jobs Watch",c.jsxs("span",{style:{marginLeft:12,color:"var(--text-muted, #777)",fontSize:12,fontWeight:"normal"},children:["updated ",E]})]}),c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Queue"}),c.jsxs("div",{children:["waiting=",c.jsx("b",{children:o.queue_health.waiting})," ","active=",c.jsx("b",{children:o.queue_health.active})," ","stalled=",c.jsx("b",{style:{color:o.queue_health.stalled>0?"var(--accent-warn, #d29922)":void 0},children:o.queue_health.stalled})]})]}),o.by_type.length>0&&c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"By type (24h)"}),c.jsxs("table",{style:{borderCollapse:"collapse"},children:[c.jsx("thead",{children:c.jsxs("tr",{style:{color:"var(--text-muted, #777)",fontSize:12},children:[c.jsx("th",{style:{textAlign:"left",padding:"4px 12px 4px 0"},children:"name"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"total"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"done"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"fail"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"dead"})]})}),c.jsx("tbody",{children:o.by_type.slice(0,6).map(N=>c.jsxs("tr",{children:[c.jsx("td",{style:{padding:"4px 12px 4px 0"},children:N.name}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.total}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.completed}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.failed}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.dead})]},N.name))})]})]}),c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Lease pressure (1h)"}),c.jsxs("div",{style:{color:_y(o.lease_pressure_1h)},children:[o.lease_pressure_1h," bounce",o.lease_pressure_1h===1?"":"s"]})]}),o.top_errors.length>0&&c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Top errors (24h)"}),c.jsx("table",{style:{borderCollapse:"collapse"},children:c.jsx("tbody",{children:o.top_errors.slice(0,5).map(N=>c.jsxs("tr",{children:[c.jsxs("td",{style:{textAlign:"right",padding:"4px 12px 4px 0",color:"var(--text-muted, #777)"},children:[N.count,"Γ—"]}),c.jsx("td",{style:{padding:"4px 12px 4px 0"},children:N.cluster})]},N.cluster))})})]}),o.budget_owners.length>0&&c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Budget owners"}),c.jsxs("table",{style:{borderCollapse:"collapse"},children:[c.jsx("thead",{children:c.jsxs("tr",{style:{color:"var(--text-muted, #777)",fontSize:12},children:[c.jsx("th",{style:{textAlign:"left",padding:"4px 12px 4px 0"},children:"owner"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"spent"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"remaining"})]})}),c.jsx("tbody",{children:o.budget_owners.slice(0,5).map(N=>c.jsxs("tr",{children:[c.jsx("td",{style:{padding:"4px 12px 4px 0"},children:N.owner_id}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:Od(N.total_spent_cents)}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:Od(N.remaining_cents)})]},N.owner_id))})]})]})]})}function Nd(){const o=window.location.hash.replace("#","")||"dashboard";return["login","dashboard","agents","log","calibration","jobs"].includes(o)?o:"dashboard"}function Oy(){const[o,D]=K.useState(Nd);K.useEffect(()=>{const E=()=>D(Nd());return window.addEventListener("hashchange",E),()=>window.removeEventListener("hashchange",E)},[]);const O=E=>{window.location.hash=E,D(E)};if(o==="login")return c.jsx(my,{onLogin:()=>O("dashboard")});const h=async()=>{if(confirm("Sign out every active admin session, including other browsers and tabs? Each one will need to re-authenticate via a fresh magic link.")){try{await Pl.signOutEverywhere()}catch{}O("login")}};return c.jsxs("div",{className:"app",children:[c.jsxs("nav",{className:"sidebar",children:[c.jsx("div",{className:"sidebar-logo",children:"GBrain"}),c.jsxs("div",{className:"sidebar-nav",children:[c.jsx("a",{className:`nav-item ${o==="dashboard"?"active":""}`,onClick:()=>O("dashboard"),children:"Dashboard"}),c.jsx("a",{className:`nav-item ${o==="agents"?"active":""}`,onClick:()=>O("agents"),children:"Agents"}),c.jsx("a",{className:`nav-item ${o==="log"?"active":""}`,onClick:()=>O("log"),children:"Request Log"}),c.jsx("a",{className:`nav-item ${o==="calibration"?"active":""}`,onClick:()=>O("calibration"),children:"Calibration"}),c.jsx("a",{className:`nav-item ${o==="jobs"?"active":""}`,onClick:()=>O("jobs"),children:"Jobs Watch"})]}),c.jsx("div",{style:{marginTop:"auto",padding:"16px 12px",borderTop:"1px solid var(--border)"},children:c.jsx("button",{onClick:h,style:{background:"transparent",border:"1px solid var(--border)",color:"var(--text-secondary)",padding:"6px 10px",borderRadius:6,fontSize:12,cursor:"pointer",width:"100%"},title:"Revoke every active admin session β€” every browser, every tab",children:"Sign out everywhere"})})]}),c.jsxs("main",{className:"main",children:[o==="dashboard"&&c.jsx(yy,{}),o==="agents"&&c.jsx(gy,{}),o==="log"&&c.jsx(Ty,{}),o==="calibration"&&c.jsx(Ay,{}),o==="jobs"&&c.jsx(Ey,{})]})]})}dy.createRoot(document.getElementById("root")).render(c.jsx(Dd.StrictMode,{children:c.jsx(Oy,{})})); diff --git a/admin/dist/assets/index-CzLjRij_.js b/admin/dist/assets/index-CzLjRij_.js new file mode 100644 index 000000000..b49849eeb --- /dev/null +++ b/admin/dist/assets/index-CzLjRij_.js @@ -0,0 +1,57 @@ +(function(){const M=document.createElement("link").relList;if(M&&M.supports&&M.supports("modulepreload"))return;for(const E of document.querySelectorAll('link[rel="modulepreload"]'))h(E);new MutationObserver(E=>{for(const N of E)if(N.type==="childList")for(const C of N.addedNodes)C.tagName==="LINK"&&C.rel==="modulepreload"&&h(C)}).observe(document,{childList:!0,subtree:!0});function O(E){const N={};return E.integrity&&(N.integrity=E.integrity),E.referrerPolicy&&(N.referrerPolicy=E.referrerPolicy),E.crossOrigin==="use-credentials"?N.credentials="include":E.crossOrigin==="anonymous"?N.credentials="omit":N.credentials="same-origin",N}function h(E){if(E.ep)return;E.ep=!0;const N=O(E);fetch(E.href,N)}})();function Md(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var ff={exports:{}},jn={};/** + * @license React + * react-jsx-runtime.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var gd;function ey(){if(gd)return jn;gd=1;var o=Symbol.for("react.transitional.element"),M=Symbol.for("react.fragment");function O(h,E,N){var C=null;if(N!==void 0&&(C=""+N),E.key!==void 0&&(C=""+E.key),"key"in E){N={};for(var L in E)L!=="key"&&(N[L]=E[L])}else N=E;return E=N.ref,{$$typeof:o,type:h,key:C,ref:E!==void 0?E:null,props:N}}return jn.Fragment=M,jn.jsx=O,jn.jsxs=O,jn}var Sd;function ay(){return Sd||(Sd=1,ff.exports=ey()),ff.exports}var c=ay(),sf={exports:{}},J={};/** + * @license React + * react.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var pd;function ny(){if(pd)return J;pd=1;var o=Symbol.for("react.transitional.element"),M=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),h=Symbol.for("react.strict_mode"),E=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),C=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),A=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),D=Symbol.for("react.activity"),_=Symbol.iterator;function W(d){return d===null||typeof d!="object"?null:(d=_&&d[_]||d["@@iterator"],typeof d=="function"?d:null)}var yl={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},il=Object.assign,el={};function xl(d,z,R){this.props=d,this.context=z,this.refs=el,this.updater=R||yl}xl.prototype.isReactComponent={},xl.prototype.setState=function(d,z){if(typeof d!="object"&&typeof d!="function"&&d!=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,d,z,"setState")},xl.prototype.forceUpdate=function(d){this.updater.enqueueForceUpdate(this,d,"forceUpdate")};function Bl(){}Bl.prototype=xl.prototype;function Al(d,z,R){this.props=d,this.context=z,this.refs=el,this.updater=R||yl}var $l=Al.prototype=new Bl;$l.constructor=Al,il($l,xl.prototype),$l.isPureReactComponent=!0;var mt=Array.isArray;function G(){}var Q={H:null,A:null,T:null,S:null},Sl=Object.prototype.hasOwnProperty;function Yl(d,z,R){var q=R.ref;return{$$typeof:o,type:d,key:z,ref:q!==void 0?q:null,props:R}}function yt(d,z){return Yl(d.type,z,d.props)}function Vl(d){return typeof d=="object"&&d!==null&&d.$$typeof===o}function jl(d){var z={"=":"=0",":":"=2"};return"$"+d.replace(/[=:]/g,function(R){return z[R]})}var ze=/\/+/g;function Rt(d,z){return typeof d=="object"&&d!==null&&d.key!=null?jl(""+d.key):z.toString(36)}function At(d){switch(d.status){case"fulfilled":return d.value;case"rejected":throw d.reason;default:switch(typeof d.status=="string"?d.then(G,G):(d.status="pending",d.then(function(z){d.status==="pending"&&(d.status="fulfilled",d.value=z)},function(z){d.status==="pending"&&(d.status="rejected",d.reason=z)})),d.status){case"fulfilled":return d.value;case"rejected":throw d.reason}}throw d}function b(d,z,R,q,w){var F=typeof d;(F==="undefined"||F==="boolean")&&(d=null);var fl=!1;if(d===null)fl=!0;else switch(F){case"bigint":case"string":case"number":fl=!0;break;case"object":switch(d.$$typeof){case o:case M:fl=!0;break;case B:return fl=d._init,b(fl(d._payload),z,R,q,w)}}if(fl)return w=w(d),fl=q===""?"."+Rt(d,0):q,mt(w)?(R="",fl!=null&&(R=fl.replace(ze,"$&/")+"/"),b(w,z,R,"",function(Oa){return Oa})):w!=null&&(Vl(w)&&(w=yt(w,R+(w.key==null||d&&d.key===w.key?"":(""+w.key).replace(ze,"$&/")+"/")+fl)),z.push(w)),1;fl=0;var Jl=q===""?".":q+":";if(mt(d))for(var El=0;El>>1,vl=b[rl];if(0>>1;rlE(R,K))qE(w,R)?(b[rl]=w,b[q]=K,rl=q):(b[rl]=R,b[z]=K,rl=z);else if(qE(w,K))b[rl]=w,b[q]=K,rl=q;else break l}}return U}function E(b,U){var K=b.sortIndex-U.sortIndex;return K!==0?K:b.id-U.id}if(o.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var N=performance;o.unstable_now=function(){return N.now()}}else{var C=Date,L=C.now();o.unstable_now=function(){return C.now()-L}}var A=[],x=[],B=1,D=null,_=3,W=!1,yl=!1,il=!1,el=!1,xl=typeof setTimeout=="function"?setTimeout:null,Bl=typeof clearTimeout=="function"?clearTimeout:null,Al=typeof setImmediate<"u"?setImmediate:null;function $l(b){for(var U=O(x);U!==null;){if(U.callback===null)h(x);else if(U.startTime<=b)h(x),U.sortIndex=U.expirationTime,M(A,U);else break;U=O(x)}}function mt(b){if(il=!1,$l(b),!yl)if(O(A)!==null)yl=!0,G||(G=!0,jl());else{var U=O(x);U!==null&&At(mt,U.startTime-b)}}var G=!1,Q=-1,Sl=5,Yl=-1;function yt(){return el?!0:!(o.unstable_now()-Ylb&&yt());){var rl=D.callback;if(typeof rl=="function"){D.callback=null,_=D.priorityLevel;var vl=rl(D.expirationTime<=b);if(b=o.unstable_now(),typeof vl=="function"){D.callback=vl,$l(b),U=!0;break t}D===O(A)&&h(A),$l(b)}else h(A);D=O(A)}if(D!==null)U=!0;else{var d=O(x);d!==null&&At(mt,d.startTime-b),U=!1}}break l}finally{D=null,_=K,W=!1}U=void 0}}finally{U?jl():G=!1}}}var jl;if(typeof Al=="function")jl=function(){Al(Vl)};else if(typeof MessageChannel<"u"){var ze=new MessageChannel,Rt=ze.port2;ze.port1.onmessage=Vl,jl=function(){Rt.postMessage(null)}}else jl=function(){xl(Vl,0)};function At(b,U){Q=xl(function(){b(o.unstable_now())},U)}o.unstable_IdlePriority=5,o.unstable_ImmediatePriority=1,o.unstable_LowPriority=4,o.unstable_NormalPriority=3,o.unstable_Profiling=null,o.unstable_UserBlockingPriority=2,o.unstable_cancelCallback=function(b){b.callback=null},o.unstable_forceFrameRate=function(b){0>b||125rl?(b.sortIndex=K,M(x,b),O(A)===null&&b===O(x)&&(il?(Bl(Q),Q=-1):il=!0,At(mt,K-rl))):(b.sortIndex=vl,M(A,b),yl||W||(yl=!0,G||(G=!0,jl()))),b},o.unstable_shouldYield=yt,o.unstable_wrapCallback=function(b){var U=_;return function(){var K=_;_=U;try{return b.apply(this,arguments)}finally{_=K}}}})(df)),df}var jd;function iy(){return jd||(jd=1,rf.exports=uy()),rf.exports}var hf={exports:{}},Kl={};/** + * @license React + * react-dom.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var Td;function cy(){if(Td)return Kl;Td=1;var o=mf();function M(A){var x="https://react.dev/errors/"+A;if(1"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(o)}catch(M){console.error(M)}}return o(),hf.exports=cy(),hf.exports}/** + * @license React + * react-dom-client.production.js + * + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */var _d;function sy(){if(_d)return Tn;_d=1;var o=iy(),M=mf(),O=fy();function h(l){var t="https://react.dev/errors/"+l;if(1vl||(l.current=rl[vl],rl[vl]=null,vl--)}function R(l,t){vl++,rl[vl]=l.current,l.current=t}var q=d(null),w=d(null),F=d(null),fl=d(null);function Jl(l,t){switch(R(F,t),R(w,l),R(q,null),t.nodeType){case 9:case 11:l=(l=t.documentElement)&&(l=l.namespaceURI)?Xr(l):0;break;default:if(l=t.tagName,t=t.namespaceURI)t=Xr(t),l=Qr(t,l);else switch(l){case"svg":l=1;break;case"math":l=2;break;default:l=0}}z(q),R(q,l)}function El(){z(q),z(w),z(F)}function Oa(l){l.memoizedState!==null&&R(fl,l);var t=q.current,e=Qr(t,l.type);t!==e&&(R(w,l),R(q,e))}function zn(l){w.current===l&&(z(q),z(w)),fl.current===l&&(z(fl),Sn._currentValue=K)}var Lu,yf;function _e(l){if(Lu===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Lu=t&&t[1]||"",yf=-1)":-1n||s[a]!==v[n]){var p=` +`+s[a].replace(" at new "," at ");return l.displayName&&p.includes("")&&(p=p.replace("",l.displayName)),p}while(1<=a&&0<=n);break}}}finally{Vu=!1,Error.prepareStackTrace=e}return(e=l?l.displayName||l.name:"")?_e(e):""}function Ud(l,t){switch(l.tag){case 26:case 27:case 5:return _e(l.type);case 16:return _e("Lazy");case 13:return l.child!==t&&t!==null?_e("Suspense Fallback"):_e("Suspense");case 19:return _e("SuspenseList");case 0:case 15:return Ku(l.type,!1);case 11:return Ku(l.type.render,!1);case 1:return Ku(l.type,!0);case 31:return _e("Activity");default:return""}}function vf(l){try{var t="",e=null;do t+=Ud(l,e),e=l,l=l.return;while(l);return t}catch(a){return` +Error generating stack: `+a.message+` +`+a.stack}}var Ju=Object.prototype.hasOwnProperty,wu=o.unstable_scheduleCallback,ku=o.unstable_cancelCallback,Rd=o.unstable_shouldYield,Bd=o.unstable_requestPaint,nt=o.unstable_now,Hd=o.unstable_getCurrentPriorityLevel,gf=o.unstable_ImmediatePriority,Sf=o.unstable_UserBlockingPriority,_n=o.unstable_NormalPriority,qd=o.unstable_LowPriority,pf=o.unstable_IdlePriority,Yd=o.log,Gd=o.unstable_setDisableYieldValue,Na=null,ut=null;function Pt(l){if(typeof Yd=="function"&&Gd(l),ut&&typeof ut.setStrictMode=="function")try{ut.setStrictMode(Na,l)}catch{}}var it=Math.clz32?Math.clz32:Zd,Xd=Math.log,Qd=Math.LN2;function Zd(l){return l>>>=0,l===0?32:31-(Xd(l)/Qd|0)|0}var An=256,En=262144,On=4194304;function Ae(l){var t=l&42;if(t!==0)return t;switch(l&-l){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return l&261888;case 262144:case 524288:case 1048576:case 2097152:return l&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return l&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return l}}function Nn(l,t,e){var a=l.pendingLanes;if(a===0)return 0;var n=0,u=l.suspendedLanes,i=l.pingedLanes;l=l.warmLanes;var f=a&134217727;return f!==0?(a=f&~u,a!==0?n=Ae(a):(i&=f,i!==0?n=Ae(i):e||(e=f&~l,e!==0&&(n=Ae(e))))):(f=a&~u,f!==0?n=Ae(f):i!==0?n=Ae(i):e||(e=a&~l,e!==0&&(n=Ae(e)))),n===0?0:t!==0&&t!==n&&(t&u)===0&&(u=n&-n,e=t&-t,u>=e||u===32&&(e&4194048)!==0)?t:n}function Ma(l,t){return(l.pendingLanes&~(l.suspendedLanes&~l.pingedLanes)&t)===0}function Ld(l,t){switch(l){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function bf(){var l=On;return On<<=1,(On&62914560)===0&&(On=4194304),l}function $u(l){for(var t=[],e=0;31>e;e++)t.push(l);return t}function Da(l,t){l.pendingLanes|=t,t!==268435456&&(l.suspendedLanes=0,l.pingedLanes=0,l.warmLanes=0)}function Vd(l,t,e,a,n,u){var i=l.pendingLanes;l.pendingLanes=e,l.suspendedLanes=0,l.pingedLanes=0,l.warmLanes=0,l.expiredLanes&=e,l.entangledLanes&=e,l.errorRecoveryDisabledLanes&=e,l.shellSuspendCounter=0;var f=l.entanglements,s=l.expirationTimes,v=l.hiddenUpdates;for(e=i&~e;0"u")return null;try{return l.activeElement||l.body}catch{return l.body}}var Wd=/[\n"\\]/g;function gt(l){return l.replace(Wd,function(t){return"\\"+t.charCodeAt(0).toString(16)+" "})}function ti(l,t,e,a,n,u,i,f){l.name="",i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"?l.type=i:l.removeAttribute("type"),t!=null?i==="number"?(t===0&&l.value===""||l.value!=t)&&(l.value=""+vt(t)):l.value!==""+vt(t)&&(l.value=""+vt(t)):i!=="submit"&&i!=="reset"||l.removeAttribute("value"),t!=null?ei(l,i,vt(t)):e!=null?ei(l,i,vt(e)):a!=null&&l.removeAttribute("value"),n==null&&u!=null&&(l.defaultChecked=!!u),n!=null&&(l.checked=n&&typeof n!="function"&&typeof n!="symbol"),f!=null&&typeof f!="function"&&typeof f!="symbol"&&typeof f!="boolean"?l.name=""+vt(f):l.removeAttribute("name")}function Uf(l,t,e,a,n,u,i,f){if(u!=null&&typeof u!="function"&&typeof u!="symbol"&&typeof u!="boolean"&&(l.type=u),t!=null||e!=null){if(!(u!=="submit"&&u!=="reset"||t!=null)){li(l);return}e=e!=null?""+vt(e):"",t=t!=null?""+vt(t):e,f||t===l.value||(l.value=t),l.defaultValue=t}a=a??n,a=typeof a!="function"&&typeof a!="symbol"&&!!a,l.checked=f?l.checked:!!a,l.defaultChecked=!!a,i!=null&&typeof i!="function"&&typeof i!="symbol"&&typeof i!="boolean"&&(l.name=i),li(l)}function ei(l,t,e){t==="number"&&Cn(l.ownerDocument)===l||l.defaultValue===""+e||(l.defaultValue=""+e)}function $e(l,t,e,a){if(l=l.options,t){t={};for(var n=0;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),ci=!1;if(qt)try{var Ba={};Object.defineProperty(Ba,"passive",{get:function(){ci=!0}}),window.addEventListener("test",Ba,Ba),window.removeEventListener("test",Ba,Ba)}catch{ci=!1}var te=null,fi=null,Rn=null;function Xf(){if(Rn)return Rn;var l,t=fi,e=t.length,a,n="value"in te?te.value:te.textContent,u=n.length;for(l=0;l=Ya),Jf=" ",wf=!1;function kf(l,t){switch(l){case"keyup":return zh.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function $f(l){return l=l.detail,typeof l=="object"&&"data"in l?l.data:null}var Pe=!1;function Ah(l,t){switch(l){case"compositionend":return $f(t);case"keypress":return t.which!==32?null:(wf=!0,Jf);case"textInput":return l=t.data,l===Jf&&wf?null:l;default:return null}}function Eh(l,t){if(Pe)return l==="compositionend"||!hi&&kf(l,t)?(l=Xf(),Rn=fi=te=null,Pe=!1,l):null;switch(l){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:e,offset:t-l};l=a}l:{for(;e;){if(e.nextSibling){e=e.nextSibling;break l}e=e.parentNode}e=void 0}e=as(e)}}function us(l,t){return l&&t?l===t?!0:l&&l.nodeType===3?!1:t&&t.nodeType===3?us(l,t.parentNode):"contains"in l?l.contains(t):l.compareDocumentPosition?!!(l.compareDocumentPosition(t)&16):!1:!1}function is(l){l=l!=null&&l.ownerDocument!=null&&l.ownerDocument.defaultView!=null?l.ownerDocument.defaultView:window;for(var t=Cn(l.document);t instanceof l.HTMLIFrameElement;){try{var e=typeof t.contentWindow.location.href=="string"}catch{e=!1}if(e)l=t.contentWindow;else break;t=Cn(l.document)}return t}function vi(l){var t=l&&l.nodeName&&l.nodeName.toLowerCase();return t&&(t==="input"&&(l.type==="text"||l.type==="search"||l.type==="tel"||l.type==="url"||l.type==="password")||t==="textarea"||l.contentEditable==="true")}var Bh=qt&&"documentMode"in document&&11>=document.documentMode,la=null,gi=null,Za=null,Si=!1;function cs(l,t,e){var a=e.window===e?e.document:e.nodeType===9?e:e.ownerDocument;Si||la==null||la!==Cn(a)||(a=la,"selectionStart"in a&&vi(a)?a={start:a.selectionStart,end:a.selectionEnd}:(a=(a.ownerDocument&&a.ownerDocument.defaultView||window).getSelection(),a={anchorNode:a.anchorNode,anchorOffset:a.anchorOffset,focusNode:a.focusNode,focusOffset:a.focusOffset}),Za&&Qa(Za,a)||(Za=a,a=Eu(gi,"onSelect"),0>=i,n-=i,Mt=1<<32-it(t)+n|e<$?(tl=Y,Y=null):tl=Y.sibling;var ul=g(m,Y,y[$],j);if(ul===null){Y===null&&(Y=tl);break}l&&Y&&ul.alternate===null&&t(m,Y),r=u(ul,r,$),nl===null?X=ul:nl.sibling=ul,nl=ul,Y=tl}if($===y.length)return e(m,Y),al&&Gt(m,$),X;if(Y===null){for(;$$?(tl=Y,Y=null):tl=Y.sibling;var Te=g(m,Y,ul.value,j);if(Te===null){Y===null&&(Y=tl);break}l&&Y&&Te.alternate===null&&t(m,Y),r=u(Te,r,$),nl===null?X=Te:nl.sibling=Te,nl=Te,Y=tl}if(ul.done)return e(m,Y),al&&Gt(m,$),X;if(Y===null){for(;!ul.done;$++,ul=y.next())ul=T(m,ul.value,j),ul!==null&&(r=u(ul,r,$),nl===null?X=ul:nl.sibling=ul,nl=ul);return al&&Gt(m,$),X}for(Y=a(Y);!ul.done;$++,ul=y.next())ul=S(Y,m,$,ul.value,j),ul!==null&&(l&&ul.alternate!==null&&Y.delete(ul.key===null?$:ul.key),r=u(ul,r,$),nl===null?X=ul:nl.sibling=ul,nl=ul);return l&&Y.forEach(function(ty){return t(m,ty)}),al&&Gt(m,$),X}function ml(m,r,y,j){if(typeof y=="object"&&y!==null&&y.type===il&&y.key===null&&(y=y.props.children),typeof y=="object"&&y!==null){switch(y.$$typeof){case W:l:{for(var X=y.key;r!==null;){if(r.key===X){if(X=y.type,X===il){if(r.tag===7){e(m,r.sibling),j=n(r,y.props.children),j.return=m,m=j;break l}}else if(r.elementType===X||typeof X=="object"&&X!==null&&X.$$typeof===Sl&&qe(X)===r.type){e(m,r.sibling),j=n(r,y.props),ka(j,y),j.return=m,m=j;break l}e(m,r);break}else t(m,r);r=r.sibling}y.type===il?(j=Ce(y.props.children,m.mode,j,y.key),j.return=m,m=j):(j=Vn(y.type,y.key,y.props,null,m.mode,j),ka(j,y),j.return=m,m=j)}return i(m);case yl:l:{for(X=y.key;r!==null;){if(r.key===X)if(r.tag===4&&r.stateNode.containerInfo===y.containerInfo&&r.stateNode.implementation===y.implementation){e(m,r.sibling),j=n(r,y.children||[]),j.return=m,m=j;break l}else{e(m,r);break}else t(m,r);r=r.sibling}j=_i(y,m.mode,j),j.return=m,m=j}return i(m);case Sl:return y=qe(y),ml(m,r,y,j)}if(At(y))return H(m,r,y,j);if(jl(y)){if(X=jl(y),typeof X!="function")throw Error(h(150));return y=X.call(y),Z(m,r,y,j)}if(typeof y.then=="function")return ml(m,r,Fn(y),j);if(y.$$typeof===Al)return ml(m,r,wn(m,y),j);In(m,y)}return typeof y=="string"&&y!==""||typeof y=="number"||typeof y=="bigint"?(y=""+y,r!==null&&r.tag===6?(e(m,r.sibling),j=n(r,y),j.return=m,m=j):(e(m,r),j=zi(y,m.mode,j),j.return=m,m=j),i(m)):e(m,r)}return function(m,r,y,j){try{wa=0;var X=ml(m,r,y,j);return ra=null,X}catch(Y){if(Y===oa||Y===$n)throw Y;var nl=ft(29,Y,null,m.mode);return nl.lanes=j,nl.return=m,nl}finally{}}}var Ge=Ms(!0),Ds=Ms(!1),ie=!1;function qi(l){l.updateQueue={baseState:l.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Yi(l,t){l=l.updateQueue,t.updateQueue===l&&(t.updateQueue={baseState:l.baseState,firstBaseUpdate:l.firstBaseUpdate,lastBaseUpdate:l.lastBaseUpdate,shared:l.shared,callbacks:null})}function ce(l){return{lane:l,tag:0,payload:null,callback:null,next:null}}function fe(l,t,e){var a=l.updateQueue;if(a===null)return null;if(a=a.shared,(cl&2)!==0){var n=a.pending;return n===null?t.next=t:(t.next=n.next,n.next=t),a.pending=t,t=Ln(l),ms(l,null,e),t}return Zn(l,a,t,e),Ln(l)}function $a(l,t,e){if(t=t.updateQueue,t!==null&&(t=t.shared,(e&4194048)!==0)){var a=t.lanes;a&=l.pendingLanes,e|=a,t.lanes=e,jf(l,e)}}function Gi(l,t){var e=l.updateQueue,a=l.alternate;if(a!==null&&(a=a.updateQueue,e===a)){var n=null,u=null;if(e=e.firstBaseUpdate,e!==null){do{var i={lane:e.lane,tag:e.tag,payload:e.payload,callback:null,next:null};u===null?n=u=i:u=u.next=i,e=e.next}while(e!==null);u===null?n=u=t:u=u.next=t}else n=u=t;e={baseState:a.baseState,firstBaseUpdate:n,lastBaseUpdate:u,shared:a.shared,callbacks:a.callbacks},l.updateQueue=e;return}l=e.lastBaseUpdate,l===null?e.firstBaseUpdate=t:l.next=t,e.lastBaseUpdate=t}var Xi=!1;function Wa(){if(Xi){var l=sa;if(l!==null)throw l}}function Fa(l,t,e,a){Xi=!1;var n=l.updateQueue;ie=!1;var u=n.firstBaseUpdate,i=n.lastBaseUpdate,f=n.shared.pending;if(f!==null){n.shared.pending=null;var s=f,v=s.next;s.next=null,i===null?u=v:i.next=v,i=s;var p=l.alternate;p!==null&&(p=p.updateQueue,f=p.lastBaseUpdate,f!==i&&(f===null?p.firstBaseUpdate=v:f.next=v,p.lastBaseUpdate=s))}if(u!==null){var T=n.baseState;i=0,p=v=s=null,f=u;do{var g=f.lane&-536870913,S=g!==f.lane;if(S?(ll&g)===g:(a&g)===g){g!==0&&g===fa&&(Xi=!0),p!==null&&(p=p.next={lane:0,tag:f.tag,payload:f.payload,callback:null,next:null});l:{var H=l,Z=f;g=t;var ml=e;switch(Z.tag){case 1:if(H=Z.payload,typeof H=="function"){T=H.call(ml,T,g);break l}T=H;break l;case 3:H.flags=H.flags&-65537|128;case 0:if(H=Z.payload,g=typeof H=="function"?H.call(ml,T,g):H,g==null)break l;T=D({},T,g);break l;case 2:ie=!0}}g=f.callback,g!==null&&(l.flags|=64,S&&(l.flags|=8192),S=n.callbacks,S===null?n.callbacks=[g]:S.push(g))}else S={lane:g,tag:f.tag,payload:f.payload,callback:f.callback,next:null},p===null?(v=p=S,s=T):p=p.next=S,i|=g;if(f=f.next,f===null){if(f=n.shared.pending,f===null)break;S=f,f=S.next,S.next=null,n.lastBaseUpdate=S,n.shared.pending=null}}while(!0);p===null&&(s=T),n.baseState=s,n.firstBaseUpdate=v,n.lastBaseUpdate=p,u===null&&(n.shared.lanes=0),he|=i,l.lanes=i,l.memoizedState=T}}function Cs(l,t){if(typeof l!="function")throw Error(h(191,l));l.call(t)}function Us(l,t){var e=l.callbacks;if(e!==null)for(l.callbacks=null,l=0;lu?u:8;var i=b.T,f={};b.T=f,uc(l,!1,t,e);try{var s=n(),v=b.S;if(v!==null&&v(f,s),s!==null&&typeof s=="object"&&typeof s.then=="function"){var p=Vh(s,a);ln(l,t,p,ht(l))}else ln(l,t,a,ht(l))}catch(T){ln(l,t,{then:function(){},status:"rejected",reason:T},ht())}finally{U.p=u,i!==null&&f.types!==null&&(i.types=f.types),b.T=i}}function Wh(){}function ac(l,t,e,a){if(l.tag!==5)throw Error(h(476));var n=ro(l).queue;oo(l,n,t,K,e===null?Wh:function(){return ho(l),e(a)})}function ro(l){var t=l.memoizedState;if(t!==null)return t;t={memoizedState:K,baseState:K,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Lt,lastRenderedState:K},next:null};var e={};return t.next={memoizedState:e,baseState:e,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:Lt,lastRenderedState:e},next:null},l.memoizedState=t,l=l.alternate,l!==null&&(l.memoizedState=t),t}function ho(l){var t=ro(l);t.next===null&&(t=l.alternate.memoizedState),ln(l,t.next.queue,{},ht())}function nc(){return Ql(Sn)}function mo(){return Nl().memoizedState}function yo(){return Nl().memoizedState}function Fh(l){for(var t=l.return;t!==null;){switch(t.tag){case 24:case 3:var e=ht();l=ce(e);var a=fe(t,l,e);a!==null&&(et(a,t,e),$a(a,t,e)),t={cache:Ui()},l.payload=t;return}t=t.return}}function Ih(l,t,e){var a=ht();e={lane:a,revertLane:0,gesture:null,action:e,hasEagerState:!1,eagerState:null,next:null},fu(l)?go(t,e):(e=ji(l,t,e,a),e!==null&&(et(e,l,a),So(e,t,a)))}function vo(l,t,e){var a=ht();ln(l,t,e,a)}function ln(l,t,e,a){var n={lane:a,revertLane:0,gesture:null,action:e,hasEagerState:!1,eagerState:null,next:null};if(fu(l))go(t,n);else{var u=l.alternate;if(l.lanes===0&&(u===null||u.lanes===0)&&(u=t.lastRenderedReducer,u!==null))try{var i=t.lastRenderedState,f=u(i,e);if(n.hasEagerState=!0,n.eagerState=f,ct(f,i))return Zn(l,t,n,0),gl===null&&Qn(),!1}catch{}finally{}if(e=ji(l,t,n,a),e!==null)return et(e,l,a),So(e,t,a),!0}return!1}function uc(l,t,e,a){if(a={lane:2,revertLane:qc(),gesture:null,action:a,hasEagerState:!1,eagerState:null,next:null},fu(l)){if(t)throw Error(h(479))}else t=ji(l,e,a,2),t!==null&&et(t,l,2)}function fu(l){var t=l.alternate;return l===k||t!==null&&t===k}function go(l,t){ha=tu=!0;var e=l.pending;e===null?t.next=t:(t.next=e.next,e.next=t),l.pending=t}function So(l,t,e){if((e&4194048)!==0){var a=t.lanes;a&=l.pendingLanes,e|=a,t.lanes=e,jf(l,e)}}var tn={readContext:Ql,use:nu,useCallback:zl,useContext:zl,useEffect:zl,useImperativeHandle:zl,useLayoutEffect:zl,useInsertionEffect:zl,useMemo:zl,useReducer:zl,useRef:zl,useState:zl,useDebugValue:zl,useDeferredValue:zl,useTransition:zl,useSyncExternalStore:zl,useId:zl,useHostTransitionStatus:zl,useFormState:zl,useActionState:zl,useOptimistic:zl,useMemoCache:zl,useCacheRefresh:zl};tn.useEffectEvent=zl;var po={readContext:Ql,use:nu,useCallback:function(l,t){return wl().memoizedState=[l,t===void 0?null:t],l},useContext:Ql,useEffect:to,useImperativeHandle:function(l,t,e){e=e!=null?e.concat([l]):null,iu(4194308,4,uo.bind(null,t,l),e)},useLayoutEffect:function(l,t){return iu(4194308,4,l,t)},useInsertionEffect:function(l,t){iu(4,2,l,t)},useMemo:function(l,t){var e=wl();t=t===void 0?null:t;var a=l();if(Xe){Pt(!0);try{l()}finally{Pt(!1)}}return e.memoizedState=[a,t],a},useReducer:function(l,t,e){var a=wl();if(e!==void 0){var n=e(t);if(Xe){Pt(!0);try{e(t)}finally{Pt(!1)}}}else n=t;return a.memoizedState=a.baseState=n,l={pending:null,lanes:0,dispatch:null,lastRenderedReducer:l,lastRenderedState:n},a.queue=l,l=l.dispatch=Ih.bind(null,k,l),[a.memoizedState,l]},useRef:function(l){var t=wl();return l={current:l},t.memoizedState=l},useState:function(l){l=Ii(l);var t=l.queue,e=vo.bind(null,k,t);return t.dispatch=e,[l.memoizedState,e]},useDebugValue:tc,useDeferredValue:function(l,t){var e=wl();return ec(e,l,t)},useTransition:function(){var l=Ii(!1);return l=oo.bind(null,k,l.queue,!0,!1),wl().memoizedState=l,[!1,l]},useSyncExternalStore:function(l,t,e){var a=k,n=wl();if(al){if(e===void 0)throw Error(h(407));e=e()}else{if(e=t(),gl===null)throw Error(h(349));(ll&127)!==0||Gs(a,t,e)}n.memoizedState=e;var u={value:e,getSnapshot:t};return n.queue=u,to(Qs.bind(null,a,u,l),[l]),a.flags|=2048,ya(9,{destroy:void 0},Xs.bind(null,a,u,e,t),null),e},useId:function(){var l=wl(),t=gl.identifierPrefix;if(al){var e=Dt,a=Mt;e=(a&~(1<<32-it(a)-1)).toString(32)+e,t="_"+t+"R_"+e,e=eu++,0<\/script>",u=u.removeChild(u.firstChild);break;case"select":u=typeof a.is=="string"?i.createElement("select",{is:a.is}):i.createElement("select"),a.multiple?u.multiple=!0:a.size&&(u.size=a.size);break;default:u=typeof a.is=="string"?i.createElement(n,{is:a.is}):i.createElement(n)}}u[Gl]=t,u[Wl]=a;l:for(i=t.child;i!==null;){if(i.tag===5||i.tag===6)u.appendChild(i.stateNode);else if(i.tag!==4&&i.tag!==27&&i.child!==null){i.child.return=i,i=i.child;continue}if(i===t)break l;for(;i.sibling===null;){if(i.return===null||i.return===t)break l;i=i.return}i.sibling.return=i.return,i=i.sibling}t.stateNode=u;l:switch(Ll(u,n,a),n){case"button":case"input":case"select":case"textarea":a=!!a.autoFocus;break l;case"img":a=!0;break l;default:a=!1}a&&Kt(t)}}return bl(t),pc(t,t.type,l===null?null:l.memoizedProps,t.pendingProps,e),null;case 6:if(l&&t.stateNode!=null)l.memoizedProps!==a&&Kt(t);else{if(typeof a!="string"&&t.stateNode===null)throw Error(h(166));if(l=F.current,ia(t)){if(l=t.stateNode,e=t.memoizedProps,a=null,n=Xl,n!==null)switch(n.tag){case 27:case 5:a=n.memoizedProps}l[Gl]=t,l=!!(l.nodeValue===e||a!==null&&a.suppressHydrationWarning===!0||Yr(l.nodeValue,e)),l||ne(t,!0)}else l=Ou(l).createTextNode(a),l[Gl]=t,t.stateNode=l}return bl(t),null;case 31:if(e=t.memoizedState,l===null||l.memoizedState!==null){if(a=ia(t),e!==null){if(l===null){if(!a)throw Error(h(318));if(l=t.memoizedState,l=l!==null?l.dehydrated:null,!l)throw Error(h(557));l[Gl]=t}else Ue(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;bl(t),l=!1}else e=Ni(),l!==null&&l.memoizedState!==null&&(l.memoizedState.hydrationErrors=e),l=!0;if(!l)return t.flags&256?(ot(t),t):(ot(t),null);if((t.flags&128)!==0)throw Error(h(558))}return bl(t),null;case 13:if(a=t.memoizedState,l===null||l.memoizedState!==null&&l.memoizedState.dehydrated!==null){if(n=ia(t),a!==null&&a.dehydrated!==null){if(l===null){if(!n)throw Error(h(318));if(n=t.memoizedState,n=n!==null?n.dehydrated:null,!n)throw Error(h(317));n[Gl]=t}else Ue(),(t.flags&128)===0&&(t.memoizedState=null),t.flags|=4;bl(t),n=!1}else n=Ni(),l!==null&&l.memoizedState!==null&&(l.memoizedState.hydrationErrors=n),n=!0;if(!n)return t.flags&256?(ot(t),t):(ot(t),null)}return ot(t),(t.flags&128)!==0?(t.lanes=e,t):(e=a!==null,l=l!==null&&l.memoizedState!==null,e&&(a=t.child,n=null,a.alternate!==null&&a.alternate.memoizedState!==null&&a.alternate.memoizedState.cachePool!==null&&(n=a.alternate.memoizedState.cachePool.pool),u=null,a.memoizedState!==null&&a.memoizedState.cachePool!==null&&(u=a.memoizedState.cachePool.pool),u!==n&&(a.flags|=2048)),e!==l&&e&&(t.child.flags|=8192),hu(t,t.updateQueue),bl(t),null);case 4:return El(),l===null&&Qc(t.stateNode.containerInfo),bl(t),null;case 10:return Qt(t.type),bl(t),null;case 19:if(z(Ol),a=t.memoizedState,a===null)return bl(t),null;if(n=(t.flags&128)!==0,u=a.rendering,u===null)if(n)an(a,!1);else{if(_l!==0||l!==null&&(l.flags&128)!==0)for(l=t.child;l!==null;){if(u=lu(l),u!==null){for(t.flags|=128,an(a,!1),l=u.updateQueue,t.updateQueue=l,hu(t,l),t.subtreeFlags=0,l=e,e=t.child;e!==null;)ys(e,l),e=e.sibling;return R(Ol,Ol.current&1|2),al&&Gt(t,a.treeForkCount),t.child}l=l.sibling}a.tail!==null&&nt()>Su&&(t.flags|=128,n=!0,an(a,!1),t.lanes=4194304)}else{if(!n)if(l=lu(u),l!==null){if(t.flags|=128,n=!0,l=l.updateQueue,t.updateQueue=l,hu(t,l),an(a,!0),a.tail===null&&a.tailMode==="hidden"&&!u.alternate&&!al)return bl(t),null}else 2*nt()-a.renderingStartTime>Su&&e!==536870912&&(t.flags|=128,n=!0,an(a,!1),t.lanes=4194304);a.isBackwards?(u.sibling=t.child,t.child=u):(l=a.last,l!==null?l.sibling=u:t.child=u,a.last=u)}return a.tail!==null?(l=a.tail,a.rendering=l,a.tail=l.sibling,a.renderingStartTime=nt(),l.sibling=null,e=Ol.current,R(Ol,n?e&1|2:e&1),al&&Gt(t,a.treeForkCount),l):(bl(t),null);case 22:case 23:return ot(t),Zi(),a=t.memoizedState!==null,l!==null?l.memoizedState!==null!==a&&(t.flags|=8192):a&&(t.flags|=8192),a?(e&536870912)!==0&&(t.flags&128)===0&&(bl(t),t.subtreeFlags&6&&(t.flags|=8192)):bl(t),e=t.updateQueue,e!==null&&hu(t,e.retryQueue),e=null,l!==null&&l.memoizedState!==null&&l.memoizedState.cachePool!==null&&(e=l.memoizedState.cachePool.pool),a=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(a=t.memoizedState.cachePool.pool),a!==e&&(t.flags|=2048),l!==null&&z(He),null;case 24:return e=null,l!==null&&(e=l.memoizedState.cache),t.memoizedState.cache!==e&&(t.flags|=2048),Qt(Ml),bl(t),null;case 25:return null;case 30:return null}throw Error(h(156,t.tag))}function am(l,t){switch(Ei(t),t.tag){case 1:return l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 3:return Qt(Ml),El(),l=t.flags,(l&65536)!==0&&(l&128)===0?(t.flags=l&-65537|128,t):null;case 26:case 27:case 5:return zn(t),null;case 31:if(t.memoizedState!==null){if(ot(t),t.alternate===null)throw Error(h(340));Ue()}return l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 13:if(ot(t),l=t.memoizedState,l!==null&&l.dehydrated!==null){if(t.alternate===null)throw Error(h(340));Ue()}return l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 19:return z(Ol),null;case 4:return El(),null;case 10:return Qt(t.type),null;case 22:case 23:return ot(t),Zi(),l!==null&&z(He),l=t.flags,l&65536?(t.flags=l&-65537|128,t):null;case 24:return Qt(Ml),null;case 25:return null;default:return null}}function Lo(l,t){switch(Ei(t),t.tag){case 3:Qt(Ml),El();break;case 26:case 27:case 5:zn(t);break;case 4:El();break;case 31:t.memoizedState!==null&&ot(t);break;case 13:ot(t);break;case 19:z(Ol);break;case 10:Qt(t.type);break;case 22:case 23:ot(t),Zi(),l!==null&&z(He);break;case 24:Qt(Ml)}}function nn(l,t){try{var e=t.updateQueue,a=e!==null?e.lastEffect:null;if(a!==null){var n=a.next;e=n;do{if((e.tag&l)===l){a=void 0;var u=e.create,i=e.inst;a=u(),i.destroy=a}e=e.next}while(e!==n)}}catch(f){ol(t,t.return,f)}}function re(l,t,e){try{var a=t.updateQueue,n=a!==null?a.lastEffect:null;if(n!==null){var u=n.next;a=u;do{if((a.tag&l)===l){var i=a.inst,f=i.destroy;if(f!==void 0){i.destroy=void 0,n=t;var s=e,v=f;try{v()}catch(p){ol(n,s,p)}}}a=a.next}while(a!==u)}}catch(p){ol(t,t.return,p)}}function Vo(l){var t=l.updateQueue;if(t!==null){var e=l.stateNode;try{Us(t,e)}catch(a){ol(l,l.return,a)}}}function Ko(l,t,e){e.props=Qe(l.type,l.memoizedProps),e.state=l.memoizedState;try{e.componentWillUnmount()}catch(a){ol(l,t,a)}}function un(l,t){try{var e=l.ref;if(e!==null){switch(l.tag){case 26:case 27:case 5:var a=l.stateNode;break;case 30:a=l.stateNode;break;default:a=l.stateNode}typeof e=="function"?l.refCleanup=e(a):e.current=a}}catch(n){ol(l,t,n)}}function Ct(l,t){var e=l.ref,a=l.refCleanup;if(e!==null)if(typeof a=="function")try{a()}catch(n){ol(l,t,n)}finally{l.refCleanup=null,l=l.alternate,l!=null&&(l.refCleanup=null)}else if(typeof e=="function")try{e(null)}catch(n){ol(l,t,n)}else e.current=null}function Jo(l){var t=l.type,e=l.memoizedProps,a=l.stateNode;try{l:switch(t){case"button":case"input":case"select":case"textarea":e.autoFocus&&a.focus();break l;case"img":e.src?a.src=e.src:e.srcSet&&(a.srcset=e.srcSet)}}catch(n){ol(l,l.return,n)}}function bc(l,t,e){try{var a=l.stateNode;_m(a,l.type,e,t),a[Wl]=t}catch(n){ol(l,l.return,n)}}function wo(l){return l.tag===5||l.tag===3||l.tag===26||l.tag===27&&Se(l.type)||l.tag===4}function xc(l){l:for(;;){for(;l.sibling===null;){if(l.return===null||wo(l.return))return null;l=l.return}for(l.sibling.return=l.return,l=l.sibling;l.tag!==5&&l.tag!==6&&l.tag!==18;){if(l.tag===27&&Se(l.type)||l.flags&2||l.child===null||l.tag===4)continue l;l.child.return=l,l=l.child}if(!(l.flags&2))return l.stateNode}}function jc(l,t,e){var a=l.tag;if(a===5||a===6)l=l.stateNode,t?(e.nodeType===9?e.body:e.nodeName==="HTML"?e.ownerDocument.body:e).insertBefore(l,t):(t=e.nodeType===9?e.body:e.nodeName==="HTML"?e.ownerDocument.body:e,t.appendChild(l),e=e._reactRootContainer,e!=null||t.onclick!==null||(t.onclick=Ht));else if(a!==4&&(a===27&&Se(l.type)&&(e=l.stateNode,t=null),l=l.child,l!==null))for(jc(l,t,e),l=l.sibling;l!==null;)jc(l,t,e),l=l.sibling}function mu(l,t,e){var a=l.tag;if(a===5||a===6)l=l.stateNode,t?e.insertBefore(l,t):e.appendChild(l);else if(a!==4&&(a===27&&Se(l.type)&&(e=l.stateNode),l=l.child,l!==null))for(mu(l,t,e),l=l.sibling;l!==null;)mu(l,t,e),l=l.sibling}function ko(l){var t=l.stateNode,e=l.memoizedProps;try{for(var a=l.type,n=t.attributes;n.length;)t.removeAttributeNode(n[0]);Ll(t,a,e),t[Gl]=l,t[Wl]=e}catch(u){ol(l,l.return,u)}}var Jt=!1,Ul=!1,Tc=!1,$o=typeof WeakSet=="function"?WeakSet:Set,ql=null;function nm(l,t){if(l=l.containerInfo,Vc=Bu,l=is(l),vi(l)){if("selectionStart"in l)var e={start:l.selectionStart,end:l.selectionEnd};else l:{e=(e=l.ownerDocument)&&e.defaultView||window;var a=e.getSelection&&e.getSelection();if(a&&a.rangeCount!==0){e=a.anchorNode;var n=a.anchorOffset,u=a.focusNode;a=a.focusOffset;try{e.nodeType,u.nodeType}catch{e=null;break l}var i=0,f=-1,s=-1,v=0,p=0,T=l,g=null;t:for(;;){for(var S;T!==e||n!==0&&T.nodeType!==3||(f=i+n),T!==u||a!==0&&T.nodeType!==3||(s=i+a),T.nodeType===3&&(i+=T.nodeValue.length),(S=T.firstChild)!==null;)g=T,T=S;for(;;){if(T===l)break t;if(g===e&&++v===n&&(f=i),g===u&&++p===a&&(s=i),(S=T.nextSibling)!==null)break;T=g,g=T.parentNode}T=S}e=f===-1||s===-1?null:{start:f,end:s}}else e=null}e=e||{start:0,end:0}}else e=null;for(Kc={focusedElem:l,selectionRange:e},Bu=!1,ql=t;ql!==null;)if(t=ql,l=t.child,(t.subtreeFlags&1028)!==0&&l!==null)l.return=t,ql=l;else for(;ql!==null;){switch(t=ql,u=t.alternate,l=t.flags,t.tag){case 0:if((l&4)!==0&&(l=t.updateQueue,l=l!==null?l.events:null,l!==null))for(e=0;e title"))),Ll(u,a,e),u[Gl]=l,Hl(u),a=u;break l;case"link":var i=td("link","href",n).get(a+(e.href||""));if(i){for(var f=0;fml&&(i=ml,ml=Z,Z=i);var m=ns(f,Z),r=ns(f,ml);if(m&&r&&(S.rangeCount!==1||S.anchorNode!==m.node||S.anchorOffset!==m.offset||S.focusNode!==r.node||S.focusOffset!==r.offset)){var y=T.createRange();y.setStart(m.node,m.offset),S.removeAllRanges(),Z>ml?(S.addRange(y),S.extend(r.node,r.offset)):(y.setEnd(r.node,r.offset),S.addRange(y))}}}}for(T=[],S=f;S=S.parentNode;)S.nodeType===1&&T.push({element:S,left:S.scrollLeft,top:S.scrollTop});for(typeof f.focus=="function"&&f.focus(),f=0;fe?32:e,b.T=null,e=Mc,Mc=null;var u=ye,i=Ft;if(Rl=0,ba=ye=null,Ft=0,(cl&6)!==0)throw Error(h(331));var f=cl;if(cl|=4,ir(u.current),ar(u,u.current,i,e),cl=f,dn(0,!1),ut&&typeof ut.onPostCommitFiberRoot=="function")try{ut.onPostCommitFiberRoot(Na,u)}catch{}return!0}finally{U.p=n,b.T=a,zr(l,t)}}function Ar(l,t,e){t=pt(e,t),t=sc(l.stateNode,t,2),l=fe(l,t,2),l!==null&&(Da(l,2),Ut(l))}function ol(l,t,e){if(l.tag===3)Ar(l,l,e);else for(;t!==null;){if(t.tag===3){Ar(t,l,e);break}else if(t.tag===1){var a=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof a.componentDidCatch=="function"&&(me===null||!me.has(a))){l=pt(e,l),e=Eo(2),a=fe(t,e,2),a!==null&&(Oo(e,a,t,l),Da(a,2),Ut(a));break}}t=t.return}}function Rc(l,t,e){var a=l.pingCache;if(a===null){a=l.pingCache=new cm;var n=new Set;a.set(t,n)}else n=a.get(t),n===void 0&&(n=new Set,a.set(t,n));n.has(e)||(Ac=!0,n.add(e),l=dm.bind(null,l,t,e),t.then(l,l))}function dm(l,t,e){var a=l.pingCache;a!==null&&a.delete(t),l.pingedLanes|=l.suspendedLanes&e,l.warmLanes&=~e,gl===l&&(ll&e)===e&&(_l===4||_l===3&&(ll&62914560)===ll&&300>nt()-gu?(cl&2)===0&&xa(l,0):Ec|=e,pa===ll&&(pa=0)),Ut(l)}function Er(l,t){t===0&&(t=bf()),l=De(l,t),l!==null&&(Da(l,t),Ut(l))}function hm(l){var t=l.memoizedState,e=0;t!==null&&(e=t.retryLane),Er(l,e)}function mm(l,t){var e=0;switch(l.tag){case 31:case 13:var a=l.stateNode,n=l.memoizedState;n!==null&&(e=n.retryLane);break;case 19:a=l.stateNode;break;case 22:a=l.stateNode._retryCache;break;default:throw Error(h(314))}a!==null&&a.delete(t),Er(l,e)}function ym(l,t){return wu(l,t)}var zu=null,Ta=null,Bc=!1,_u=!1,Hc=!1,ge=0;function Ut(l){l!==Ta&&l.next===null&&(Ta===null?zu=Ta=l:Ta=Ta.next=l),_u=!0,Bc||(Bc=!0,gm())}function dn(l,t){if(!Hc&&_u){Hc=!0;do for(var e=!1,a=zu;a!==null;){if(l!==0){var n=a.pendingLanes;if(n===0)var u=0;else{var i=a.suspendedLanes,f=a.pingedLanes;u=(1<<31-it(42|l)+1)-1,u&=n&~(i&~f),u=u&201326741?u&201326741|1:u?u|2:0}u!==0&&(e=!0,Dr(a,u))}else u=ll,u=Nn(a,a===gl?u:0,a.cancelPendingCommit!==null||a.timeoutHandle!==-1),(u&3)===0||Ma(a,u)||(e=!0,Dr(a,u));a=a.next}while(e);Hc=!1}}function vm(){Or()}function Or(){_u=Bc=!1;var l=0;ge!==0&&Em()&&(l=ge);for(var t=nt(),e=null,a=zu;a!==null;){var n=a.next,u=Nr(a,t);u===0?(a.next=null,e===null?zu=n:e.next=n,n===null&&(Ta=e)):(e=a,(l!==0||(u&3)!==0)&&(_u=!0)),a=n}Rl!==0&&Rl!==5||dn(l),ge!==0&&(ge=0)}function Nr(l,t){for(var e=l.suspendedLanes,a=l.pingedLanes,n=l.expirationTimes,u=l.pendingLanes&-62914561;0f)break;var p=s.transferSize,T=s.initiatorType;p&&Gr(T)&&(s=s.responseEnd,i+=p*(s"u"?null:document;function Fr(l,t,e){var a=za;if(a&&typeof t=="string"&&t){var n=gt(t);n='link[rel="'+l+'"][href="'+n+'"]',typeof e=="string"&&(n+='[crossorigin="'+e+'"]'),Wr.has(n)||(Wr.add(n),l={rel:l,crossOrigin:e,href:t},a.querySelector(n)===null&&(t=a.createElement("link"),Ll(t,"link",l),Hl(t),a.head.appendChild(t)))}}function Hm(l){It.D(l),Fr("dns-prefetch",l,null)}function qm(l,t){It.C(l,t),Fr("preconnect",l,t)}function Ym(l,t,e){It.L(l,t,e);var a=za;if(a&&l&&t){var n='link[rel="preload"][as="'+gt(t)+'"]';t==="image"&&e&&e.imageSrcSet?(n+='[imagesrcset="'+gt(e.imageSrcSet)+'"]',typeof e.imageSizes=="string"&&(n+='[imagesizes="'+gt(e.imageSizes)+'"]')):n+='[href="'+gt(l)+'"]';var u=n;switch(t){case"style":u=_a(l);break;case"script":u=Aa(l)}_t.has(u)||(l=D({rel:"preload",href:t==="image"&&e&&e.imageSrcSet?void 0:l,as:t},e),_t.set(u,l),a.querySelector(n)!==null||t==="style"&&a.querySelector(vn(u))||t==="script"&&a.querySelector(gn(u))||(t=a.createElement("link"),Ll(t,"link",l),Hl(t),a.head.appendChild(t)))}}function Gm(l,t){It.m(l,t);var e=za;if(e&&l){var a=t&&typeof t.as=="string"?t.as:"script",n='link[rel="modulepreload"][as="'+gt(a)+'"][href="'+gt(l)+'"]',u=n;switch(a){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":u=Aa(l)}if(!_t.has(u)&&(l=D({rel:"modulepreload",href:l},t),_t.set(u,l),e.querySelector(n)===null)){switch(a){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(e.querySelector(gn(u)))return}a=e.createElement("link"),Ll(a,"link",l),Hl(a),e.head.appendChild(a)}}}function Xm(l,t,e){It.S(l,t,e);var a=za;if(a&&l){var n=we(a).hoistableStyles,u=_a(l);t=t||"default";var i=n.get(u);if(!i){var f={loading:0,preload:null};if(i=a.querySelector(vn(u)))f.loading=5;else{l=D({rel:"stylesheet",href:l,"data-precedence":t},e),(e=_t.get(u))&&Ic(l,e);var s=i=a.createElement("link");Hl(s),Ll(s,"link",l),s._p=new Promise(function(v,p){s.onload=v,s.onerror=p}),s.addEventListener("load",function(){f.loading|=1}),s.addEventListener("error",function(){f.loading|=2}),f.loading|=4,Mu(i,t,a)}i={type:"stylesheet",instance:i,count:1,state:f},n.set(u,i)}}}function Qm(l,t){It.X(l,t);var e=za;if(e&&l){var a=we(e).hoistableScripts,n=Aa(l),u=a.get(n);u||(u=e.querySelector(gn(n)),u||(l=D({src:l,async:!0},t),(t=_t.get(n))&&Pc(l,t),u=e.createElement("script"),Hl(u),Ll(u,"link",l),e.head.appendChild(u)),u={type:"script",instance:u,count:1,state:null},a.set(n,u))}}function Zm(l,t){It.M(l,t);var e=za;if(e&&l){var a=we(e).hoistableScripts,n=Aa(l),u=a.get(n);u||(u=e.querySelector(gn(n)),u||(l=D({src:l,async:!0,type:"module"},t),(t=_t.get(n))&&Pc(l,t),u=e.createElement("script"),Hl(u),Ll(u,"link",l),e.head.appendChild(u)),u={type:"script",instance:u,count:1,state:null},a.set(n,u))}}function Ir(l,t,e,a){var n=(n=F.current)?Nu(n):null;if(!n)throw Error(h(446));switch(l){case"meta":case"title":return null;case"style":return typeof e.precedence=="string"&&typeof e.href=="string"?(t=_a(e.href),e=we(n).hoistableStyles,a=e.get(t),a||(a={type:"style",instance:null,count:0,state:null},e.set(t,a)),a):{type:"void",instance:null,count:0,state:null};case"link":if(e.rel==="stylesheet"&&typeof e.href=="string"&&typeof e.precedence=="string"){l=_a(e.href);var u=we(n).hoistableStyles,i=u.get(l);if(i||(n=n.ownerDocument||n,i={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},u.set(l,i),(u=n.querySelector(vn(l)))&&!u._p&&(i.instance=u,i.state.loading=5),_t.has(l)||(e={rel:"preload",as:"style",href:e.href,crossOrigin:e.crossOrigin,integrity:e.integrity,media:e.media,hrefLang:e.hrefLang,referrerPolicy:e.referrerPolicy},_t.set(l,e),u||Lm(n,l,e,i.state))),t&&a===null)throw Error(h(528,""));return i}if(t&&a!==null)throw Error(h(529,""));return null;case"script":return t=e.async,e=e.src,typeof e=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=Aa(e),e=we(n).hoistableScripts,a=e.get(t),a||(a={type:"script",instance:null,count:0,state:null},e.set(t,a)),a):{type:"void",instance:null,count:0,state:null};default:throw Error(h(444,l))}}function _a(l){return'href="'+gt(l)+'"'}function vn(l){return'link[rel="stylesheet"]['+l+"]"}function Pr(l){return D({},l,{"data-precedence":l.precedence,precedence:null})}function Lm(l,t,e,a){l.querySelector('link[rel="preload"][as="style"]['+t+"]")?a.loading=1:(t=l.createElement("link"),a.preload=t,t.addEventListener("load",function(){return a.loading|=1}),t.addEventListener("error",function(){return a.loading|=2}),Ll(t,"link",e),Hl(t),l.head.appendChild(t))}function Aa(l){return'[src="'+gt(l)+'"]'}function gn(l){return"script[async]"+l}function ld(l,t,e){if(t.count++,t.instance===null)switch(t.type){case"style":var a=l.querySelector('style[data-href~="'+gt(e.href)+'"]');if(a)return t.instance=a,Hl(a),a;var n=D({},e,{"data-href":e.href,"data-precedence":e.precedence,href:null,precedence:null});return a=(l.ownerDocument||l).createElement("style"),Hl(a),Ll(a,"style",n),Mu(a,e.precedence,l),t.instance=a;case"stylesheet":n=_a(e.href);var u=l.querySelector(vn(n));if(u)return t.state.loading|=4,t.instance=u,Hl(u),u;a=Pr(e),(n=_t.get(n))&&Ic(a,n),u=(l.ownerDocument||l).createElement("link"),Hl(u);var i=u;return i._p=new Promise(function(f,s){i.onload=f,i.onerror=s}),Ll(u,"link",a),t.state.loading|=4,Mu(u,e.precedence,l),t.instance=u;case"script":return u=Aa(e.src),(n=l.querySelector(gn(u)))?(t.instance=n,Hl(n),n):(a=e,(n=_t.get(u))&&(a=D({},e),Pc(a,n)),l=l.ownerDocument||l,n=l.createElement("script"),Hl(n),Ll(n,"link",a),l.head.appendChild(n),t.instance=n);case"void":return null;default:throw Error(h(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(a=t.instance,t.state.loading|=4,Mu(a,e.precedence,l));return t.instance}function Mu(l,t,e){for(var a=e.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),n=a.length?a[a.length-1]:null,u=n,i=0;i title"):null)}function Vm(l,t,e){if(e===1||t.itemProp!=null)return!1;switch(l){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;switch(t.rel){case"stylesheet":return l=t.disabled,typeof t.precedence=="string"&&l==null;default:return!0}case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function ad(l){return!(l.type==="stylesheet"&&(l.state.loading&3)===0)}function Km(l,t,e,a){if(e.type==="stylesheet"&&(typeof a.media!="string"||matchMedia(a.media).matches!==!1)&&(e.state.loading&4)===0){if(e.instance===null){var n=_a(a.href),u=t.querySelector(vn(n));if(u){t=u._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(l.count++,l=Cu.bind(l),t.then(l,l)),e.state.loading|=4,e.instance=u,Hl(u);return}u=t.ownerDocument||t,a=Pr(a),(n=_t.get(n))&&Ic(a,n),u=u.createElement("link"),Hl(u);var i=u;i._p=new Promise(function(f,s){i.onload=f,i.onerror=s}),Ll(u,"link",a),e.instance=u}l.stylesheets===null&&(l.stylesheets=new Map),l.stylesheets.set(e,t),(t=e.state.preload)&&(e.state.loading&3)===0&&(l.count++,e=Cu.bind(l),t.addEventListener("load",e),t.addEventListener("error",e))}}var lf=0;function Jm(l,t){return l.stylesheets&&l.count===0&&Ru(l,l.stylesheets),0lf?50:800)+t);return l.unsuspend=e,function(){l.unsuspend=null,clearTimeout(a),clearTimeout(n)}}:null}function Cu(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)Ru(this,this.stylesheets);else if(this.unsuspend){var l=this.unsuspend;this.unsuspend=null,l()}}}var Uu=null;function Ru(l,t){l.stylesheets=null,l.unsuspend!==null&&(l.count++,Uu=new Map,t.forEach(wm,l),Uu=null,Cu.call(l))}function wm(l,t){if(!(t.state.loading&4)){var e=Uu.get(l);if(e)var a=e.get(null);else{e=new Map,Uu.set(l,e);for(var n=l.querySelectorAll("link[data-precedence],style[data-precedence]"),u=0;u"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(o)}catch(M){console.error(M)}}return o(),of.exports=sy(),of.exports}var ry=oy();const dy=Md(ry),Cd="";async function at(o,M){const O=await fetch(`${Cd}${o}`,{...M,credentials:"same-origin",headers:{"Content-Type":"application/json",...M==null?void 0:M.headers}});if(O.status===401)throw window.location.hash="#login",new Error("Unauthorized");if(!O.ok){const h=await O.json().catch(()=>({}));throw new Error(h.error||`HTTP ${O.status}`)}return O.json()}async function hy(o){const M=await fetch(`${Cd}${o}`,{credentials:"same-origin"});if(M.status===401)throw window.location.hash="#login",new Error("Unauthorized");if(!M.ok)throw new Error(`HTTP ${M.status}`);return M.text()}const kl={login:o=>at("/admin/login",{method:"POST",body:JSON.stringify({token:o})}),signOutEverywhere:()=>at("/admin/api/sign-out-everywhere",{method:"POST"}),stats:()=>at("/admin/api/stats"),health:()=>at("/admin/api/health-indicators"),agents:()=>at("/admin/api/agents"),sources:()=>at("/admin/api/sources"),requests:(o=1,M="")=>at(`/admin/api/requests?page=${o}${M}`),apiKeys:()=>at("/admin/api/api-keys"),createApiKey:o=>at("/admin/api/api-keys",{method:"POST",body:JSON.stringify({name:o})}),revokeApiKey:o=>at("/admin/api/api-keys/revoke",{method:"POST",body:JSON.stringify({name:o})}),updateClientTtl:(o,M)=>at("/admin/api/update-client-ttl",{method:"POST",body:JSON.stringify({clientId:o,tokenTtl:M})}),revokeClient:o=>at("/admin/api/revoke-client",{method:"POST",body:JSON.stringify({clientId:o})}),calibrationProfile:o=>at(`/admin/api/calibration/profile${o?`?holder=${encodeURIComponent(o)}`:""}`),calibrationChart:(o,M)=>hy(`/admin/api/calibration/charts/${encodeURIComponent(o)}${M?`?holder=${encodeURIComponent(M)}`:""}`),jobsWatch:()=>at("/admin/api/jobs/watch")};function my({onLogin:o}){const[M,O]=V.useState(""),[h,E]=V.useState(""),[N,C]=V.useState(!1),L=async A=>{A.preventDefault(),E(""),C(!0);try{await kl.login(M),O(""),o()}catch{E("Invalid token.")}finally{C(!1)}};return c.jsx("div",{className:"login-page",children:c.jsxs("div",{className:"login-box",children:[c.jsx("div",{className:"login-logo",children:"GBrain"}),c.jsxs("div",{style:{background:"rgba(136, 170, 255, 0.08)",border:"1px solid rgba(136, 170, 255, 0.2)",borderRadius:8,padding:"14px 16px",marginBottom:20,fontSize:13,lineHeight:1.5,color:"var(--text-secondary)"},children:[c.jsx("div",{style:{fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"πŸ”’ This is a protected dashboard"}),"Ask your AI agent for the admin login link:",c.jsx("div",{style:{background:"rgba(0,0,0,0.3)",borderRadius:6,padding:"8px 12px",marginTop:8,fontFamily:"var(--font-mono)",fontSize:12,color:"#88aaff",wordBreak:"break-all"},children:'"Give me the GBrain admin login link"'}),c.jsx("div",{style:{marginTop:8,fontSize:12,color:"var(--text-muted)"},children:"Each link is single-use. Your agent generates a fresh one each time."})]}),c.jsxs("details",{style:{marginBottom:16},children:[c.jsx("summary",{style:{cursor:"pointer",fontSize:13,color:"var(--text-muted)"},children:"Or paste bootstrap token manually"}),c.jsxs("form",{onSubmit:L,style:{marginTop:12},children:[c.jsx("div",{style:{marginBottom:12},children:c.jsx("input",{type:"password",placeholder:"Admin Token",value:M,onChange:A=>O(A.target.value)})}),c.jsx("button",{className:"btn btn-primary",style:{width:"100%"},disabled:N,children:N?"Authenticating...":"Submit"}),h&&c.jsx("div",{className:"login-error",children:h})]})]})]})})}function yy(){const[o,M]=V.useState({connected_agents:0,requests_today:0,active_tokens:0}),[O,h]=V.useState({expiring_soon:0,error_rate:"0%"}),[E,N]=V.useState([]),[C,L]=V.useState("connecting"),A=V.useRef(null);V.useEffect(()=>{kl.stats().then(M).catch(()=>{}),kl.health().then(h).catch(()=>{});const B=new EventSource("/admin/events",{withCredentials:!0});A.current=B,B.onopen=()=>L("connected"),B.onmessage=_=>{try{const W=JSON.parse(_.data);N(yl=>[W,...yl].slice(0,50))}catch{}},B.onerror=()=>{L("disconnected"),setTimeout(()=>{L("connecting"),B.close()},3e3)};const D=setInterval(()=>{kl.stats().then(M).catch(()=>{}),kl.health().then(h).catch(()=>{})},3e4);return()=>{B.close(),clearInterval(D)}},[]);const x=B=>{const D=Date.now()-new Date(B).getTime();return D<6e4?`${Math.floor(D/1e3)}s ago`:D<36e5?`${Math.floor(D/6e4)} min ago`:`${Math.floor(D/36e5)}h ago`};return c.jsxs(c.Fragment,{children:[c.jsx("h1",{className:"page-title",children:"Dashboard"}),c.jsxs("div",{style:{display:"flex",gap:24},children:[c.jsxs("div",{style:{flex:1},children:[c.jsxs("div",{className:"metrics",children:[c.jsxs("div",{className:"metric",children:[c.jsx("div",{className:"metric-value",children:o.connected_agents}),c.jsx("div",{className:"metric-label",children:"Connected Agents"})]}),c.jsxs("div",{className:"metric",children:[c.jsx("div",{className:"metric-value",children:o.requests_today}),c.jsx("div",{className:"metric-label",children:"Requests Today"})]}),c.jsxs("div",{className:"metric",children:[c.jsx("div",{className:"metric-value",children:o.active_tokens}),c.jsx("div",{className:"metric-label",children:"Active Tokens"})]})]}),c.jsxs("h2",{className:"section-title",children:["Live Activity",c.jsx("span",{style:{marginLeft:8,fontSize:10,color:C==="connected"?"var(--success)":C==="connecting"?"var(--warning)":"var(--error)"},children:C==="connected"?"● connected":C==="connecting"?"● connecting...":"● disconnected"})]}),c.jsx("div",{className:"feed",children:E.length===0?c.jsx("div",{className:"feed-empty",children:C==="connected"?"No requests yet. Agents will appear when they connect.":"Connecting..."}):c.jsxs("table",{children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Agent"}),c.jsx("th",{children:"Operation"}),c.jsx("th",{children:"Scopes"}),c.jsx("th",{children:"Latency"}),c.jsx("th",{children:"Status"}),c.jsx("th",{children:"Time"})]})}),c.jsx("tbody",{children:E.map((B,D)=>c.jsxs("tr",{children:[c.jsx("td",{className:"mono",children:B.agent}),c.jsx("td",{className:"mono",children:B.operation}),c.jsx("td",{children:B.scopes.split(",").map(_=>c.jsx("span",{className:`badge badge-${_.trim()}`,style:{marginRight:4},children:_.trim()},_))}),c.jsxs("td",{className:"mono",children:[B.latency_ms," ms"]}),c.jsx("td",{children:c.jsx("span",{className:`badge badge-${B.status}`,children:B.status})}),c.jsx("td",{style:{color:"var(--text-secondary)"},children:x(B.timestamp)})]},D))})]})})]}),c.jsxs("div",{style:{width:220},children:[c.jsx("h2",{className:"section-title",children:"Token Health"}),c.jsxs("div",{className:"health-panel",children:[c.jsxs("div",{className:"health-row",children:[c.jsx("span",{style:{color:"var(--warning)"},children:"Expiring Soon"}),c.jsx("span",{className:"mono",children:O.expiring_soon})]}),c.jsxs("div",{className:"health-row",children:[c.jsx("span",{style:{color:"var(--error)"},children:"Error Rate"}),c.jsx("span",{className:"mono",children:O.error_rate})]})]})]})]})]})}const Ed=["admin","agent","read","sources_admin","users_admin","write"];function vy(o){const M=Math.floor((Date.now()-o.getTime())/1e3);return M<60?"just now":M<3600?`${Math.floor(M/60)}m ago`:M<86400?`${Math.floor(M/3600)}h ago`:`${Math.floor(M/86400)}d ago`}function gy(){const[o,M]=V.useState([]),[O,h]=V.useState(!0),[E,N]=V.useState(!1),[C,L]=V.useState(null),[A,x]=V.useState(!1),[B,D]=V.useState(null),[_,W]=V.useState(null);V.useEffect(()=>{yl()},[]);const yl=()=>{kl.agents().then(M).catch(()=>{})};return c.jsxs(c.Fragment,{children:[c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:24},children:[c.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"Agents"}),c.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[c.jsxs("label",{style:{fontSize:13,color:"var(--text-secondary)",display:"flex",alignItems:"center",gap:6,cursor:"pointer"},children:[c.jsx("input",{type:"checkbox",checked:O,onChange:il=>h(il.target.checked)})," Hide revoked"]}),c.jsx("button",{className:"btn btn-secondary",onClick:()=>x(!0),children:"+ API Key"}),c.jsx("button",{className:"btn btn-primary",onClick:()=>N(!0),children:"+ OAuth Client"})]})]}),(()=>{const il=o.filter(el=>!O||el.status!=="revoked");return o.length===0?c.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--text-muted)"},children:"No agents registered. Register your first agent to get started."}):il.length===0?c.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--text-muted)"},children:'All agents are revoked. Uncheck "Hide revoked" to view them.'}):c.jsxs(c.Fragment,{children:[c.jsxs("table",{children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Name"}),c.jsx("th",{children:"Type"}),c.jsx("th",{children:"Scopes"}),c.jsx("th",{children:"Source"}),c.jsx("th",{children:"Status"}),c.jsx("th",{children:"Requests"}),c.jsx("th",{children:"Last Used"})]})}),c.jsx("tbody",{children:il.map(el=>c.jsxs("tr",{onClick:()=>W(el),style:{cursor:"pointer"},children:[c.jsx("td",{style:{fontWeight:500},children:el.name||el.client_name}),c.jsx("td",{children:c.jsx("span",{className:`badge ${el.auth_type==="oauth"?"badge-read":"badge-write"}`,style:{fontSize:11},children:el.auth_type==="oauth"?"OAuth":"API Key"})}),c.jsx("td",{children:(el.scope||"").split(" ").filter(Boolean).map(xl=>c.jsx("span",{className:`badge badge-${xl}`,style:{marginRight:4},children:xl},xl))}),c.jsx("td",{className:"mono",style:{fontSize:12,color:"var(--text-secondary)"},children:el.auth_type==="oauth"?el.source_id||"default":"all"}),c.jsx("td",{children:c.jsx("span",{className:`badge ${el.status==="active"?"badge-success":"badge-danger"}`,children:el.status})}),c.jsxs("td",{children:[c.jsx("span",{style:{fontWeight:500},children:el.requests_today||0}),c.jsxs("span",{style:{color:"var(--text-muted)",fontSize:12},children:[" / ",el.total_requests||0]})]}),c.jsx("td",{style:{color:"var(--text-secondary)"},children:el.last_used_at?vy(new Date(el.last_used_at)):"Never"})]},el.id))})]}),c.jsxs("div",{style:{color:"var(--text-muted)",fontSize:13,marginTop:12},children:[o.filter(el=>el.status==="active").length," active / ",o.length," total"]})]})})(),E&&c.jsx(by,{onClose:()=>N(!1),onRegistered:il=>{N(!1),L(il),yl()}}),C&&c.jsx(xy,{credentials:C,onClose:()=>L(null)}),_&&c.jsx(jy,{agent:_,onClose:()=>W(null),onRevoked:yl}),A&&c.jsx(Sy,{onClose:()=>x(!1),onCreated:il=>{x(!1),D(il),yl()}}),B&&c.jsx(py,{token:B,onClose:()=>D(null)})]})}function Sy({onClose:o,onCreated:M}){const[O,h]=V.useState(""),[E,N]=V.useState(!1),[C,L]=V.useState(""),A=async x=>{if(x.preventDefault(),!O.trim()){L("Name required");return}N(!0);try{const B=await kl.createApiKey(O.trim());M({name:B.name,token:B.token})}catch(B){L(B instanceof Error?B.message:"Failed")}finally{N(!1)}};return c.jsx("div",{className:"modal-overlay",onClick:o,children:c.jsxs("form",{className:"modal",onClick:x=>x.stopPropagation(),onSubmit:A,children:[c.jsx("div",{className:"modal-title",children:"Create API Key"}),c.jsx("p",{style:{color:"var(--text-secondary)",fontSize:13,marginBottom:16},children:"API keys use simple bearer token auth. They grant full read+write+admin access. For scoped access, use OAuth clients instead."}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Key Name"}),c.jsx("input",{placeholder:"e.g. claude-code-local",value:O,onChange:x=>h(x.target.value),autoFocus:!0})]}),C&&c.jsx("div",{style:{color:"var(--error)",fontSize:13,marginBottom:12},children:C}),c.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",className:"btn btn-secondary",onClick:o,children:"Cancel"}),c.jsx("button",{type:"submit",className:"btn btn-primary",disabled:E,children:E?"Creating...":"Create Key"})]})]})})}function py({token:o,onClose:M}){const O=h=>navigator.clipboard.writeText(h);return c.jsx("div",{className:"modal-overlay",children:c.jsxs("div",{className:"modal",style:{maxWidth:560},children:[c.jsxs("div",{style:{textAlign:"center",marginBottom:16},children:[c.jsx("div",{style:{fontSize:36,color:"var(--success)",marginBottom:8},children:"βœ“"}),c.jsx("div",{style:{fontSize:20,fontWeight:600},children:"API Key Created"})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Name"}),c.jsx("div",{className:"code-block",children:c.jsx("span",{children:o.name})})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Bearer Token"}),c.jsxs("div",{className:"code-block",children:[c.jsx("span",{children:o.token}),c.jsx("button",{className:"copy-btn",onClick:()=>O(o.token),children:"Copy"})]})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Usage"}),c.jsxs("div",{className:"code-block",children:[c.jsx("pre",{style:{whiteSpace:"pre-wrap",margin:0,fontSize:12},children:`Authorization: Bearer ${o.token}`}),c.jsx("button",{className:"copy-btn",onClick:()=>O(`Authorization: Bearer ${o.token}`),children:"Copy"})]})]}),c.jsx("div",{className:"warning-bar",children:"Save this token now. It will not be shown again."}),c.jsx("div",{style:{display:"flex",gap:12,justifyContent:"flex-end",marginTop:20},children:c.jsx("button",{className:"btn btn-primary",onClick:M,children:"Done"})})]})})}function by({onClose:o,onRegistered:M}){const[O,h]=V.useState(""),[E,N]=V.useState(()=>Object.fromEntries(Ed.map(G=>[G,G==="read"]))),[C,L]=V.useState("86400"),[A,x]=V.useState(""),[B,D]=V.useState([{id:"default",name:"default"}]),[_,W]=V.useState("default"),[yl,il]=V.useState({default:!0}),[el,xl]=V.useState(!1),[Bl,Al]=V.useState("");V.useEffect(()=>{kl.sources().then(G=>{const Q=G.length>0?G:[{id:"default",name:"default"}],Sl=Q.some(Yl=>Yl.id===_)?_:Q[0].id;D(Q),W(Sl),il(Yl=>{const yt=Object.fromEntries(Q.map(Vl=>[Vl.id,!!Yl[Vl.id]]));return yt[Sl]=!0,yt})}).catch(()=>{})},[]);const $l=[{label:"1 hour",value:"3600"},{label:"24 hours",value:"86400"},{label:"7 days",value:"604800"},{label:"30 days",value:"2592000"},{label:"1 year",value:"31536000"},{label:"No expiry",value:"0"}],mt=async G=>{if(G.preventDefault(),!O.trim()){Al("Name required");return}xl(!0),Al("");try{const Q=Object.entries(E).filter(([,jl])=>jl).map(([jl])=>jl).join(" "),Sl=B.map(jl=>jl.id).filter(jl=>yl[jl]);if(Sl.length===0){Al("Select at least one read source"),xl(!1);return}const Yl=A.split(` +`).map(jl=>jl.trim()).filter(Boolean),yt=await fetch("/admin/api/register-client",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O.trim(),scopes:Q,tokenTtl:C==="0"?31536e4:Number(C),source_id:_,federated_read:Sl,...Yl.length>0?{redirectUris:Yl,grantTypes:["authorization_code","refresh_token"]}:{}})});if(!yt.ok)throw new Error("Registration failed");const Vl=await yt.json();M({clientId:Vl.clientId,clientSecret:Vl.clientSecret,name:O.trim()})}catch(Q){Al(Q instanceof Error?Q.message:"Registration failed")}finally{xl(!1)}};return c.jsx("div",{className:"modal-overlay",onClick:o,children:c.jsxs("form",{className:"modal",onClick:G=>G.stopPropagation(),onSubmit:mt,children:[c.jsx("div",{className:"modal-title",children:"Register Agent"}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Agent Name"}),c.jsx("input",{placeholder:"e.g. perplexity-production",value:O,onChange:G=>h(G.target.value),autoFocus:!0})]}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Scopes"}),c.jsx("div",{className:"checkbox-group",children:Ed.map(G=>c.jsxs("label",{className:"checkbox-label",children:[c.jsx("input",{type:"checkbox",checked:E[G],onChange:Q=>N(Sl=>({...Sl,[G]:Q.target.checked}))}),G]},G))})]}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Write Source"}),c.jsx("select",{value:_,onChange:G=>{const Q=G.target.value;W(Q),il(Sl=>({...Sl,[Q]:!0}))},style:{width:"100%",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:6,padding:"6px 10px",fontSize:14},children:B.map(G=>c.jsx("option",{value:G.id,children:G.name&&G.name!==G.id?`${G.id} (${G.name})`:G.id},G.id))})]}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsx("label",{children:"Read Sources"}),c.jsx("div",{className:"checkbox-group",children:B.map(G=>c.jsxs("label",{className:"checkbox-label",children:[c.jsx("input",{type:"checkbox",checked:!!yl[G.id],onChange:Q=>il(Sl=>({...Sl,[G.id]:Q.target.checked}))}),G.name&&G.name!==G.id?`${G.id} (${G.name})`:G.id]},G.id))})]}),c.jsxs("div",{style:{marginBottom:16},children:[c.jsxs("label",{children:["Redirect URIs ",c.jsx("span",{style:{color:"var(--text-secondary)",fontWeight:400},children:"(optional, one per line β€” enables authorization_code flow)"})]}),c.jsx("textarea",{placeholder:"https://example.com/callback",value:A,onChange:G=>x(G.target.value),rows:2,style:{width:"100%",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:6,padding:"6px 10px",fontSize:13,fontFamily:"inherit",resize:"vertical"}})]}),c.jsxs("div",{style:{marginBottom:20},children:[c.jsx("label",{children:"Token Lifetime"}),c.jsx("select",{value:C,onChange:G=>L(G.target.value),style:{width:"100%",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:6,padding:"6px 10px",fontSize:14},children:$l.map(G=>c.jsx("option",{value:G.value,children:G.label},G.value))})]}),Bl&&c.jsx("div",{style:{color:"var(--error)",fontSize:13,marginBottom:12},children:Bl}),c.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",className:"btn btn-secondary",onClick:o,children:"Cancel"}),c.jsx("button",{type:"submit",className:"btn btn-primary",disabled:el,children:el?"Registering...":"Register"})]})]})})}function xy({credentials:o,onClose:M}){const O=E=>navigator.clipboard.writeText(E),h=()=>{const E=new Blob([JSON.stringify(o,null,2)],{type:"application/json"}),N=URL.createObjectURL(E),C=document.createElement("a");C.href=N,C.download=`${o.name}-credentials.json`,C.click(),URL.revokeObjectURL(N)};return c.jsx("div",{className:"modal-overlay",children:c.jsxs("div",{className:"modal",style:{maxWidth:560},children:[c.jsxs("div",{style:{textAlign:"center",marginBottom:16},children:[c.jsx("div",{style:{fontSize:36,color:"var(--success)",marginBottom:8},children:"βœ“"}),c.jsx("div",{style:{fontSize:20,fontWeight:600},children:"Agent Registered"})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Client ID"}),c.jsxs("div",{className:"code-block",children:[c.jsx("span",{children:o.clientId}),c.jsx("button",{className:"copy-btn",onClick:()=>O(o.clientId),children:"Copy"})]})]}),c.jsxs("div",{style:{marginBottom:12},children:[c.jsx("label",{style:{fontSize:12},children:"Client Secret"}),c.jsxs("div",{className:"code-block",children:[c.jsx("span",{children:o.clientSecret}),c.jsx("button",{className:"copy-btn",onClick:()=>O(o.clientSecret),children:"Copy"})]})]}),c.jsx("div",{className:"warning-bar",children:"Save this secret now. It will not be shown again."}),c.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"flex-end",marginTop:20},children:[c.jsx("button",{className:"btn btn-secondary",onClick:h,children:"Download as JSON"}),c.jsx("button",{className:"btn btn-primary",onClick:M,children:"Done"})]})]})})}function jy({agent:o,onClose:M,onRevoked:O}){const[h,E]=V.useState("claude-code"),N=D=>navigator.clipboard.writeText(D),C=window.location.origin,L=o.id||o.client_id||"",A=o.auth_type==="oauth",x=o.name||o.client_name||"unknown",B={"claude-code":A?["The user wants to connect GBrain MCP to your context. Here's how.","","# Step 1 β€” read the client secret from the operator without putting it in shell history.","# read -s suppresses the echo; export keeps it scoped to this shell session.",'read -rs -p "Client Secret: " GBRAIN_CS && echo',"","# Step 2 β€” mint a token and register GBrain in one go.",`claude mcp add --transport http gbrain ${C}/mcp \\`,` --header "Authorization: Bearer $(curl -s -X POST ${C}/token \\`," -d 'grant_type=client_credentials' \\",` -d 'client_id=${L}' \\`,' --data-urlencode "client_secret=$GBRAIN_CS" \\',` -d 'scope=${o.scope||"read write"}' | jq -r .access_token)"`,"","# Step 3 β€” clear the secret from this shell.","unset GBRAIN_CS","",`The token will last ${o.token_ttl?o.token_ttl>=86400?Math.floor(o.token_ttl/86400)+" days":Math.floor(o.token_ttl/3600)+" hours":"1 hour (default)"}.`,"","─── Fallback: 2-step curl + paste ───","","If your shell doesn't support read -s, mint the token first, then paste:","",`curl -s -X POST ${C}/token \\`," -d 'grant_type=client_credentials' \\",` -d 'client_id=${L}' \\`," -d 'client_secret=PASTE_YOUR_CLIENT_SECRET_HERE' \\",` -d 'scope=${o.scope||"read write"}' | jq -r .access_token`,"",`claude mcp add --transport http gbrain ${C}/mcp \\`,' --header "Authorization: Bearer PASTE_TOKEN_FROM_ABOVE"',"","# Then run: history -d $((HISTCMD-1)) # zsh: print -s -- '' && fc -p"].join(` +`):["The user wants to connect GBrain MCP to your context. Here's how.","","Run this command in terminal to register GBrain:","",`claude mcp add --transport http gbrain ${C}/mcp \\`,' --header "Authorization: Bearer PASTE_YOUR_API_KEY_HERE"',"",`Replace PASTE_YOUR_API_KEY_HERE with the API key shown when "${x}" was created.`,"API keys never expire."].join(` +`),chatgpt:["The user wants to connect GBrain MCP to ChatGPT.","","1. Open ChatGPT > Settings > Tools & Integrations > Add MCP Server","2. Enter this URL β€” ChatGPT will auto-discover the OAuth configuration:","",` ${C}/.well-known/oauth-authorization-server`,"","3. When prompted for credentials:",` Client ID: ${L}`," Client Secret: (the secret from agent registration)"," Grant Type: client_credentials",` Scope: ${o.scope||"read write"}`].join(` +`),"claude-cowork":["The user wants to connect GBrain MCP to Claude.ai.","","1. Open claude.ai > Settings > Connected Apps > Add MCP Server",`2. Server URL: ${C}/mcp`,"3. When prompted for auth:",` Token endpoint: ${C}/token`,` Client ID: ${L}`," Client Secret: (the secret from agent registration)",` Scope: ${o.scope||"read write"}`,"",`Discovery URL: ${C}/.well-known/oauth-authorization-server`].join(` +`),cursor:A?["The user wants to connect GBrain MCP to Cursor.","","Cursor supports OAuth for remote MCP. Add to .cursor/mcp.json:","","{",' "mcpServers": {',' "gbrain": {',` "url": "${C}/mcp",`,' "transport": "sse"'," }"," }","}","","Cursor will auto-discover OAuth via:",`${C}/.well-known/oauth-authorization-server`,"",`When prompted: Client ID ${L}, use the secret from registration.`].join(` +`):["The user wants to connect GBrain MCP to Cursor.","","Add to .cursor/mcp.json:","","{",' "mcpServers": {',' "gbrain": {',` "url": "${C}/mcp",`,' "transport": "sse",',' "headers": {',' "Authorization": "Bearer PASTE_YOUR_API_KEY_HERE"'," }"," }"," }","}","",`Replace PASTE_YOUR_API_KEY_HERE with the API key shown when "${x}" was created.`].join(` +`),perplexity:["The user wants to connect GBrain MCP to Perplexity.","","1. Go to Settings > Connectors > Add MCP",`2. Server URL: ${C}/mcp`,`3. Client ID: ${L}`,"4. Client Secret: (the secret from agent registration)"].join(` +`),json:JSON.stringify({server_url:C+"/mcp",token_url:C+"/token",discovery_url:C+"/.well-known/oauth-authorization-server",client_id:L,client_name:x,auth_type:o.auth_type,scope:o.scope,source_id:o.source_id,federated_read:o.federated_read},null,2)};return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"drawer-overlay",onClick:M}),c.jsxs("div",{className:"drawer",children:[c.jsx("button",{className:"drawer-close",onClick:M,children:"βœ•"}),c.jsx("div",{style:{fontSize:18,fontWeight:600,marginBottom:4},children:o.name||o.client_name}),c.jsx("span",{className:`badge ${o.status==="active"?"badge-success":"badge-danger"}`,children:o.status}),c.jsx("div",{className:"section-title",children:"Details"}),c.jsxs("div",{style:{display:"grid",gridTemplateColumns:"100px 1fr",gap:"6px 12px",fontSize:13},children:[c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Client ID"}),c.jsxs("span",{className:"mono",children:[(o.id||o.id||o.client_id||"").substring(0,24),"..."]}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Scopes"}),c.jsx("span",{children:(o.scope||"").split(" ").filter(Boolean).map(D=>c.jsx("span",{className:`badge badge-${D}`,style:{marginRight:4},children:D},D))}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Write Source"}),c.jsx("span",{className:"mono",children:o.source_id||(A?"default":"all")}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Read Sources"}),c.jsx("span",{className:"mono",children:A?o.federated_read&&o.federated_read.length>0?o.federated_read.join(", "):o.source_id||"default":"all"}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Registered"}),c.jsx("span",{children:new Date(o.created_at).toLocaleDateString()}),c.jsx("span",{style:{color:"var(--text-secondary)"},children:"Token TTL"}),c.jsx("span",{children:o.token_ttl?o.token_ttl>=31536e3?"No expiry":o.token_ttl>=86400?`${Math.floor(o.token_ttl/86400)}d`:o.token_ttl>=3600?`${Math.floor(o.token_ttl/3600)}h`:`${o.token_ttl}s`:"1h (default)"})]}),c.jsx("div",{className:"section-title",children:"Config Export"}),c.jsxs("div",{className:"tabs",style:{flexWrap:"wrap"},children:[c.jsx("div",{className:`tab ${h==="claude-code"?"active":""}`,onClick:()=>E("claude-code"),children:"Claude Code"}),c.jsx("div",{className:`tab ${h==="chatgpt"?"active":""}`,onClick:()=>E("chatgpt"),children:"ChatGPT"}),c.jsx("div",{className:`tab ${h==="claude-cowork"?"active":""}`,onClick:()=>E("claude-cowork"),children:"Claude.ai"}),c.jsx("div",{className:`tab ${h==="cursor"?"active":""}`,onClick:()=>E("cursor"),children:"Cursor"}),c.jsx("div",{className:`tab ${h==="perplexity"?"active":""}`,onClick:()=>E("perplexity"),children:"Perplexity"}),c.jsx("div",{className:`tab ${h==="json"?"active":""}`,onClick:()=>E("json"),children:"JSON"})]}),(()=>{if(!A&&new Set(["chatgpt","claude-cowork","perplexity"]).has(h)){const _={chatgpt:"ChatGPT","claude-cowork":"Claude.ai",perplexity:"Perplexity"}[h]||h;return c.jsxs("div",{style:{background:"rgba(255, 200, 100, 0.08)",border:"1px solid rgba(255, 200, 100, 0.2)",borderRadius:8,padding:"14px 16px",marginTop:12,fontSize:13,lineHeight:1.6,color:"var(--text-secondary)"},children:[c.jsxs("div",{style:{fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:[_," requires an OAuth client"]}),_," only supports OAuth 2.0 (client_credentials). API keys use raw bearer tokens, which ",_," does not accept. Register a separate OAuth client and use that to connect this AI."]})}return c.jsxs("div",{className:"code-block",children:[c.jsx("pre",{style:{whiteSpace:"pre-wrap",margin:0},children:B[h]}),c.jsx("button",{className:"copy-btn",onClick:()=>N(B[h]),children:"Copy"})]})})(),c.jsxs("div",{style:{marginTop:32},children:[o.status==="active"&&c.jsx("button",{className:"btn btn-danger",onClick:async()=>{if(confirm(`Revoke ${o.name||o.client_name}? All active tokens will be invalidated.`))try{o.auth_type==="oauth"?await kl.revokeClient(o.id||o.client_id||""):await kl.revokeApiKey(o.name||""),O(),M()}catch(D){alert("Revoke failed: "+(D instanceof Error?D.message:"unknown error"))}},children:"Revoke Agent"}),o.status==="revoked"&&c.jsx("span",{style:{color:"var(--text-muted)",fontSize:13},children:"This agent has been revoked."})]})]})]})}function Ty(){const[o,M]=V.useState({rows:[],total:0,page:1,pages:1}),[O,h]=V.useState(1),[E,N]=V.useState("all"),[C,L]=V.useState(null);V.useEffect(()=>{A(O)},[O,E]);const A=_=>{const W=E!=="all"?`&agent=${encodeURIComponent(E)}`:"";kl.requests(_,W).then(M).catch(()=>{})},x=_=>{const W=Date.now()-new Date(_).getTime();return W<6e4?`${Math.floor(W/1e3)}s ago`:W<36e5?`${Math.floor(W/6e4)} min ago`:W<864e5?`${Math.floor(W/36e5)}h ago`:new Date(_).toLocaleDateString()},B=_=>{if(!_)return null;const{query:W,slug:yl,partial:il,limit:el,...xl}=_,Bl=[];return W&&Bl.push(`"${W}"`),yl&&Bl.push(yl),il&&Bl.push(`~${il}`),el&&Bl.push(`limit=${el}`),Object.keys(xl).length>0&&Bl.push(`+${Object.keys(xl).length} params`),Bl.join(" ")},D=new Map;return o.rows.forEach(_=>{_.token_name&&D.set(_.token_name,_.agent_name||_.token_name)}),c.jsxs(c.Fragment,{children:[c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:24},children:[c.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"Request Log"}),c.jsxs("select",{value:E,onChange:_=>{N(_.target.value),h(1)},style:{background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:6,padding:"4px 8px",fontSize:13},children:[c.jsx("option",{value:"all",children:"All agents"}),[...D.entries()].map(([_,W])=>c.jsx("option",{value:_,children:W},_))]})]}),o.rows.length===0?c.jsx("div",{style:{textAlign:"center",padding:48,color:"var(--text-muted)"},children:"No requests yet."}):c.jsxs(c.Fragment,{children:[c.jsxs("table",{children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Time"}),c.jsx("th",{children:"Agent"}),c.jsx("th",{children:"Operation"}),c.jsx("th",{children:"Params"}),c.jsx("th",{children:"Latency"}),c.jsx("th",{children:"Status"})]})}),c.jsx("tbody",{children:o.rows.map(_=>c.jsxs(Dd.Fragment,{children:[c.jsxs("tr",{onClick:()=>L(C===_.id?null:_.id),style:{cursor:"pointer"},children:[c.jsx("td",{style:{color:"var(--text-secondary)",whiteSpace:"nowrap"},children:x(_.created_at)}),c.jsx("td",{children:c.jsx("a",{style:{color:"var(--text-link, #88aaff)",cursor:"pointer",textDecoration:"none",fontWeight:500},onClick:W=>{W.stopPropagation(),N(_.token_name),h(1)},children:_.agent_name||_.token_name})}),c.jsx("td",{className:"mono",children:_.operation}),c.jsx("td",{style:{color:"var(--text-secondary)",fontSize:12,maxWidth:200,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:B(_.params)}),c.jsxs("td",{className:"mono",children:[_.latency_ms,"ms"]}),c.jsx("td",{children:c.jsx("span",{className:`badge badge-${_.status}`,children:_.status})})]}),C===_.id&&c.jsx("tr",{children:c.jsx("td",{colSpan:6,style:{background:"var(--bg-secondary, #0f0f1a)",padding:16},children:c.jsxs("div",{style:{display:"grid",gridTemplateColumns:"100px 1fr",gap:"6px 12px",fontSize:13},children:[c.jsx("span",{style:{color:"var(--text-muted)"},children:"Time"}),c.jsx("span",{children:new Date(_.created_at).toLocaleString()}),c.jsx("span",{style:{color:"var(--text-muted)"},children:"Agent"}),c.jsx("span",{className:"mono",children:_.token_name}),c.jsx("span",{style:{color:"var(--text-muted)"},children:"Operation"}),c.jsx("span",{className:"mono",children:_.operation}),c.jsx("span",{style:{color:"var(--text-muted)"},children:"Latency"}),c.jsxs("span",{children:[_.latency_ms,"ms"]}),_.params&&c.jsxs(c.Fragment,{children:[c.jsx("span",{style:{color:"var(--text-muted)"},children:"Params"}),c.jsx("pre",{className:"mono",style:{margin:0,whiteSpace:"pre-wrap",fontSize:12},children:JSON.stringify(_.params,null,2)})]}),_.error_message&&c.jsxs(c.Fragment,{children:[c.jsx("span",{style:{color:"var(--error, #ff6b6b)"},children:"Error"}),c.jsx("span",{style:{color:"var(--error, #ff6b6b)"},children:_.error_message})]})]})})})]},_.id))})]}),c.jsxs("div",{className:"pagination",children:[c.jsxs("span",{children:["Page ",o.page," of ",o.pages," (",o.total," total)"]}),c.jsxs("div",{style:{display:"flex",gap:8},children:[c.jsx("button",{disabled:o.page<=1,onClick:()=>h(_=>_-1),children:"Previous"}),c.jsx("button",{disabled:o.page>=o.pages,onClick:()=>h(_=>_+1),children:"Next"})]})]})]})]})}function zy({markup:o}){return c.jsx("div",{style:{width:"100%",overflow:"auto"},dangerouslySetInnerHTML:{__html:o}})}function Zu({type:o,ariaLabel:M}){const[O,h]=V.useState(""),[E,N]=V.useState("");return V.useEffect(()=>{let C=!1;return kl.calibrationChart(o).then(L=>{C||h(L)}).catch(L=>{C||N(L.message??"fetch failed")}),()=>{C=!0}},[o]),E?c.jsxs("div",{style:{padding:16,color:"var(--error)"},role:"alert",children:[M,": ",E]}):O?c.jsx(zy,{markup:O}):c.jsxs("div",{style:{padding:16,color:"var(--text-muted)"},children:[M," loading..."]})}function _y(){const[o,M]=V.useState(null),[O,h]=V.useState(!0),[E,N]=V.useState("");if(V.useEffect(()=>{kl.calibrationProfile().then(A=>{M(A),h(!1)}).catch(A=>{N(A.message??"fetch failed"),h(!1)})},[]),O)return c.jsx("div",{style:{padding:24,color:"var(--text-secondary)"},children:"Loading calibration profile…"});if(E)return c.jsxs("div",{style:{padding:24,color:"var(--error)"},role:"alert",children:["Could not load calibration profile: ",E]});if(!o)return c.jsxs("div",{style:{padding:24,maxWidth:700},children:[c.jsx("h1",{style:{marginBottom:16},children:"Calibration"}),c.jsx("p",{style:{color:"var(--text-secondary)"},children:"No calibration profile yet. Builds after 5+ resolved takes."}),c.jsx("pre",{style:{background:"var(--bg-secondary)",padding:12,borderRadius:4,color:"var(--text-primary)",marginTop:12,fontFamily:"var(--font-mono)"},children:"gbrain dream --phase calibration_profile"})]});const C=new Date(o.generated_at),L=Math.floor((Date.now()-C.getTime())/(1e3*60*60*24));return c.jsxs("div",{style:{padding:32,maxWidth:720},children:[c.jsx("h1",{style:{marginBottom:8},children:"Calibration"}),c.jsxs("div",{style:{color:"var(--text-muted)",fontSize:13,marginBottom:24},children:["Holder: ",o.holder," Β· ","Updated ",L===0?"today":`${L}d ago`,o.published&&" Β· published",o.grade_completion<.9&&` Β· ~${Math.round(o.grade_completion*100)}% graded`,!o.voice_gate_passed&&" Β· voice gate fell back to template"]}),c.jsx("section",{style:{marginBottom:32},children:c.jsx(Zu,{type:"brier-trend",ariaLabel:"Brier trend"})}),c.jsxs("section",{style:{marginBottom:32},children:[c.jsx("h2",{style:{fontSize:14,color:"var(--text-secondary)",marginBottom:12,fontWeight:400},children:"Pattern statements"}),c.jsx(Zu,{type:"pattern-statements",ariaLabel:"Pattern statements"})]}),c.jsx("section",{style:{marginBottom:32},children:c.jsx(Zu,{type:"domain-bars",ariaLabel:"Per-domain accuracy"})}),c.jsx("section",{style:{marginBottom:32},children:c.jsx(Zu,{type:"abandoned-threads",ariaLabel:"Abandoned threads"})}),o.active_bias_tags.length>0&&c.jsxs("section",{style:{marginBottom:32,color:"var(--text-muted)",fontSize:13},children:["Active bias tags: ",o.active_bias_tags.join(", ")]})]})}function Ay(o){return o===0?"var(--accent-success, #2ea043)":o>=100?"var(--accent-danger, #f85149)":"var(--accent-warn, #d29922)"}function Od(o){return`$${(o/100).toFixed(2)}`}function Ey(){const[o,M]=V.useState(null),[O,h]=V.useState(null);if(V.useEffect(()=>{let N=!0,C=null;const L=async()=>{try{const A=await kl.jobsWatch();N&&(M(A),h(null))}catch(A){N&&h(A instanceof Error?A.message:String(A))}N&&(C=setTimeout(L,1e3))};return L(),()=>{N=!1,C&&clearTimeout(C)}},[]),O)return c.jsxs("div",{style:{padding:24,color:"var(--accent-danger, #f85149)"},children:[c.jsx("h2",{children:"Jobs Watch β€” error"}),c.jsx("pre",{style:{whiteSpace:"pre-wrap"},children:O})]});if(!o)return c.jsx("div",{style:{padding:24,color:"var(--text-muted, #777)"},children:"Loading jobs watch…"});const E=new Date(o.ts_ms).toLocaleTimeString();return c.jsxs("div",{style:{padding:24,fontFamily:'var(--font-mono, "JetBrains Mono", monospace)'},children:[c.jsxs("h1",{style:{fontSize:18,marginBottom:4},children:["Jobs Watch",c.jsxs("span",{style:{marginLeft:12,color:"var(--text-muted, #777)",fontSize:12,fontWeight:"normal"},children:["updated ",E]})]}),c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Queue"}),c.jsxs("div",{children:["waiting=",c.jsx("b",{children:o.queue_health.waiting})," ","active=",c.jsx("b",{children:o.queue_health.active})," ","stalled=",c.jsx("b",{style:{color:o.queue_health.stalled>0?"var(--accent-warn, #d29922)":void 0},children:o.queue_health.stalled})]})]}),o.by_type.length>0&&c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"By type (24h)"}),c.jsxs("table",{style:{borderCollapse:"collapse"},children:[c.jsx("thead",{children:c.jsxs("tr",{style:{color:"var(--text-muted, #777)",fontSize:12},children:[c.jsx("th",{style:{textAlign:"left",padding:"4px 12px 4px 0"},children:"name"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"total"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"done"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"fail"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"dead"})]})}),c.jsx("tbody",{children:o.by_type.slice(0,6).map(N=>c.jsxs("tr",{children:[c.jsx("td",{style:{padding:"4px 12px 4px 0"},children:N.name}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.total}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.completed}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.failed}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:N.dead})]},N.name))})]})]}),c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Lease pressure (1h)"}),c.jsxs("div",{style:{color:Ay(o.lease_pressure_1h)},children:[o.lease_pressure_1h," bounce",o.lease_pressure_1h===1?"":"s"]})]}),o.top_errors.length>0&&c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Top errors (24h)"}),c.jsx("table",{style:{borderCollapse:"collapse"},children:c.jsx("tbody",{children:o.top_errors.slice(0,5).map(N=>c.jsxs("tr",{children:[c.jsxs("td",{style:{textAlign:"right",padding:"4px 12px 4px 0",color:"var(--text-muted, #777)"},children:[N.count,"Γ—"]}),c.jsx("td",{style:{padding:"4px 12px 4px 0"},children:N.cluster})]},N.cluster))})})]}),o.budget_owners.length>0&&c.jsxs("section",{style:{marginTop:24},children:[c.jsx("h2",{style:{fontSize:14,marginBottom:8},children:"Budget owners"}),c.jsxs("table",{style:{borderCollapse:"collapse"},children:[c.jsx("thead",{children:c.jsxs("tr",{style:{color:"var(--text-muted, #777)",fontSize:12},children:[c.jsx("th",{style:{textAlign:"left",padding:"4px 12px 4px 0"},children:"owner"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"spent"}),c.jsx("th",{style:{textAlign:"right",padding:"4px 12px"},children:"remaining"})]})}),c.jsx("tbody",{children:o.budget_owners.slice(0,5).map(N=>c.jsxs("tr",{children:[c.jsx("td",{style:{padding:"4px 12px 4px 0"},children:N.owner_id}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:Od(N.total_spent_cents)}),c.jsx("td",{style:{textAlign:"right",padding:"4px 12px"},children:Od(N.remaining_cents)})]},N.owner_id))})]})]})]})}function Nd(){const o=window.location.hash.replace("#","")||"dashboard";return["login","dashboard","agents","log","calibration","jobs"].includes(o)?o:"dashboard"}function Oy(){const[o,M]=V.useState(Nd);V.useEffect(()=>{const E=()=>M(Nd());return window.addEventListener("hashchange",E),()=>window.removeEventListener("hashchange",E)},[]);const O=E=>{window.location.hash=E,M(E)};if(o==="login")return c.jsx(my,{onLogin:()=>O("dashboard")});const h=async()=>{if(confirm("Sign out every active admin session, including other browsers and tabs? Each one will need to re-authenticate via a fresh magic link.")){try{await kl.signOutEverywhere()}catch{}O("login")}};return c.jsxs("div",{className:"app",children:[c.jsxs("nav",{className:"sidebar",children:[c.jsx("div",{className:"sidebar-logo",children:"GBrain"}),c.jsxs("div",{className:"sidebar-nav",children:[c.jsx("a",{className:`nav-item ${o==="dashboard"?"active":""}`,onClick:()=>O("dashboard"),children:"Dashboard"}),c.jsx("a",{className:`nav-item ${o==="agents"?"active":""}`,onClick:()=>O("agents"),children:"Agents"}),c.jsx("a",{className:`nav-item ${o==="log"?"active":""}`,onClick:()=>O("log"),children:"Request Log"}),c.jsx("a",{className:`nav-item ${o==="calibration"?"active":""}`,onClick:()=>O("calibration"),children:"Calibration"}),c.jsx("a",{className:`nav-item ${o==="jobs"?"active":""}`,onClick:()=>O("jobs"),children:"Jobs Watch"})]}),c.jsx("div",{style:{marginTop:"auto",padding:"16px 12px",borderTop:"1px solid var(--border)"},children:c.jsx("button",{onClick:h,style:{background:"transparent",border:"1px solid var(--border)",color:"var(--text-secondary)",padding:"6px 10px",borderRadius:6,fontSize:12,cursor:"pointer",width:"100%"},title:"Revoke every active admin session β€” every browser, every tab",children:"Sign out everywhere"})})]}),c.jsxs("main",{className:"main",children:[o==="dashboard"&&c.jsx(yy,{}),o==="agents"&&c.jsx(gy,{}),o==="log"&&c.jsx(Ty,{}),o==="calibration"&&c.jsx(_y,{}),o==="jobs"&&c.jsx(Ey,{})]})]})}dy.createRoot(document.getElementById("root")).render(c.jsx(Dd.StrictMode,{children:c.jsx(Oy,{})})); diff --git a/admin/dist/index.html b/admin/dist/index.html index 5456a1cab..95f22a21f 100644 --- a/admin/dist/index.html +++ b/admin/dist/index.html @@ -7,7 +7,7 @@ - + diff --git a/admin/src/api.ts b/admin/src/api.ts index 9cf24a9ee..ca0efc158 100644 --- a/admin/src/api.ts +++ b/admin/src/api.ts @@ -39,6 +39,7 @@ export const api = { stats: () => apiFetch('/admin/api/stats'), health: () => apiFetch('/admin/api/health-indicators'), agents: () => apiFetch('/admin/api/agents'), + sources: () => apiFetch('/admin/api/sources'), requests: (page = 1, qs = '') => apiFetch(`/admin/api/requests?page=${page}${qs}`), apiKeys: () => apiFetch('/admin/api/api-keys'), createApiKey: (name: string) => apiFetch('/admin/api/api-keys', { method: 'POST', body: JSON.stringify({ name }) }), diff --git a/admin/src/pages/Agents.tsx b/admin/src/pages/Agents.tsx index c0680006c..ac30fc4b7 100644 --- a/admin/src/pages/Agents.tsx +++ b/admin/src/pages/Agents.tsx @@ -23,9 +23,16 @@ interface Agent { total_requests: number; requests_today: number; token_ttl: number | null; + source_id: string | null; + federated_read: string[] | null; status: 'active' | 'revoked'; } +interface SourceOption { + id: string; + name: string | null; +} + interface ApiKey { id: string; name: string; @@ -88,6 +95,7 @@ export function AgentsPage() { Name Type Scopes + Source Status Requests Last Used @@ -108,6 +116,9 @@ export function AgentsPage() { {s} ))} + + {a.auth_type === 'oauth' ? (a.source_id || 'default') : 'all'} + {a.status} @@ -257,9 +268,29 @@ function RegisterModal({ onClose, onRegistered }: { Object.fromEntries(ALLOWED_SCOPES_LIST.map(s => [s, s === 'read'])) as Record, ); const [ttl, setTtl] = useState('86400'); // 24h default + const [redirectUris, setRedirectUris] = useState(''); + const [sources, setSources] = useState([{ id: 'default', name: 'default' }]); + const [sourceId, setSourceId] = useState('default'); + const [readSources, setReadSources] = useState>({ default: true }); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); + useEffect(() => { + api.sources() + .then((rows: SourceOption[]) => { + const nextSources = rows.length > 0 ? rows : [{ id: 'default', name: 'default' }]; + const nextSourceId = nextSources.some(s => s.id === sourceId) ? sourceId : nextSources[0].id; + setSources(nextSources); + setSourceId(nextSourceId); + setReadSources(prev => { + const next = Object.fromEntries(nextSources.map(s => [s.id, Boolean(prev[s.id])])) as Record; + next[nextSourceId] = true; + return next; + }); + }) + .catch(() => {}); + }, []); + const ttlOptions = [ { label: '1 hour', value: '3600' }, { label: '24 hours', value: '86400' }, @@ -277,11 +308,24 @@ function RegisterModal({ onClose, onRegistered }: { try { // Use the CLI registration endpoint (POST to admin API) const selectedScopes = Object.entries(scopes).filter(([, v]) => v).map(([k]) => k).join(' '); + const federatedRead = sources.map(s => s.id).filter(id => readSources[id]); + if (federatedRead.length === 0) { setError('Select at least one read source'); setLoading(false); return; } + // #1036: redirect URIs, one per line. Mirrors the CLI convention + // (src/commands/auth.ts): presence of redirect URIs implies + // authorization_code + refresh_token grants unless the user had none. + const uris = redirectUris.split('\n').map(u => u.trim()).filter(Boolean); const res = await fetch('/admin/api/register-client', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ name: name.trim(), scopes: selectedScopes, tokenTtl: ttl === '0' ? 315360000 : Number(ttl) }), + body: JSON.stringify({ + name: name.trim(), + scopes: selectedScopes, + tokenTtl: ttl === '0' ? 315360000 : Number(ttl), + source_id: sourceId, + federated_read: federatedRead, + ...(uris.length > 0 ? { redirectUris: uris, grantTypes: ['authorization_code', 'refresh_token'] } : {}), + }), }); if (!res.ok) throw new Error('Registration failed'); const data = await res.json(); @@ -312,6 +356,42 @@ function RegisterModal({ onClose, onRegistered }: { ))} +
+ + +
+
+ +
+ {sources.map(s => ( + + ))} +
+
+
+ +