@abstractframework/observer 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/dist/assets/index-1Y-bFEjo.js +141 -0
- package/dist/assets/index-1Y-bFEjo.js.map +1 -0
- package/dist/assets/index-B2bF2L6k.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/dist/assets/index-BHHnK0PW.css +0 -1
- package/dist/assets/index-BNRMqyx3.js +0 -140
- package/dist/assets/index-BNRMqyx3.js.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var Xx=Object.defineProperty;var Jx=(e,t,n)=>t in e?Xx(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var hs=(e,t,n)=>Jx(e,typeof t!="symbol"?t+"":t,n);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))i(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const u of l.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&i(u)}).observe(document,{childList:!0,subtree:!0});function n(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerPolicy&&(l.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?l.credentials="include":a.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function i(a){if(a.ep)return;a.ep=!0;const l=n(a);fetch(a.href,l)}})();function mg(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ih={exports:{}},xd={},Dh={exports:{}},Ht={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var Xg;function Zx(){if(Xg)return Ht;Xg=1;var e=Symbol.for("react.element"),t=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),p=Symbol.for("react.memo"),g=Symbol.for("react.lazy"),v=Symbol.iterator;function w(E){return E===null||typeof E!="object"?null:(E=v&&E[v]||E["@@iterator"],typeof E=="function"?E:null)}var x={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},N=Object.assign,S={};function R(E,X,ne){this.props=E,this.context=X,this.refs=S,this.updater=ne||x}R.prototype.isReactComponent={},R.prototype.setState=function(E,X){if(typeof E!="object"&&typeof E!="function"&&E!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,E,X,"setState")},R.prototype.forceUpdate=function(E){this.updater.enqueueForceUpdate(this,E,"forceUpdate")};function T(){}T.prototype=R.prototype;function z(E,X,ne){this.props=E,this.context=X,this.refs=S,this.updater=ne||x}var H=z.prototype=new T;H.constructor=z,N(H,R.prototype),H.isPureReactComponent=!0;var D=Array.isArray,G=Object.prototype.hasOwnProperty,Q={current:null},Y={key:!0,ref:!0,__self:!0,__source:!0};function ee(E,X,ne){var ie,de={},xe=null,be=null;if(X!=null)for(ie in X.ref!==void 0&&(be=X.ref),X.key!==void 0&&(xe=""+X.key),X)G.call(X,ie)&&!Y.hasOwnProperty(ie)&&(de[ie]=X[ie]);var Ee=arguments.length-2;if(Ee===1)de.children=ne;else if(1<Ee){for(var Oe=Array(Ee),He=0;He<Ee;He++)Oe[He]=arguments[He+2];de.children=Oe}if(E&&E.defaultProps)for(ie in Ee=E.defaultProps,Ee)de[ie]===void 0&&(de[ie]=Ee[ie]);return{$$typeof:e,type:E,key:xe,ref:be,props:de,_owner:Q.current}}function ae(E,X){return{$$typeof:e,type:E.type,key:X,ref:E.ref,props:E.props,_owner:E._owner}}function le(E){return typeof E=="object"&&E!==null&&E.$$typeof===e}function ge(E){var X={"=":"=0",":":"=2"};return"$"+E.replace(/[=:]/g,function(ne){return X[ne]})}var F=/\/+/g;function C(E,X){return typeof E=="object"&&E!==null&&E.key!=null?ge(""+E.key):X.toString(36)}function k(E,X,ne,ie,de){var xe=typeof E;(xe==="undefined"||xe==="boolean")&&(E=null);var be=!1;if(E===null)be=!0;else switch(xe){case"string":case"number":be=!0;break;case"object":switch(E.$$typeof){case e:case t:be=!0}}if(be)return be=E,de=de(be),E=ie===""?"."+C(be,0):ie,D(de)?(ne="",E!=null&&(ne=E.replace(F,"$&/")+"/"),k(de,X,ne,"",function(He){return He})):de!=null&&(le(de)&&(de=ae(de,ne+(!de.key||be&&be.key===de.key?"":(""+de.key).replace(F,"$&/")+"/")+E)),X.push(de)),1;if(be=0,ie=ie===""?".":ie+":",D(E))for(var Ee=0;Ee<E.length;Ee++){xe=E[Ee];var Oe=ie+C(xe,Ee);be+=k(xe,X,ne,Oe,de)}else if(Oe=w(E),typeof Oe=="function")for(E=Oe.call(E),Ee=0;!(xe=E.next()).done;)xe=xe.value,Oe=ie+C(xe,Ee++),be+=k(xe,X,ne,Oe,de);else if(xe==="object")throw X=String(E),Error("Objects are not valid as a React child (found: "+(X==="[object Object]"?"object with keys {"+Object.keys(E).join(", ")+"}":X)+"). If you meant to render a collection of children, use an array instead.");return be}function I(E,X,ne){if(E==null)return E;var ie=[],de=0;return k(E,ie,"","",function(xe){return X.call(ne,xe,de++)}),ie}function P(E){if(E._status===-1){var X=E._result;X=X(),X.then(function(ne){(E._status===0||E._status===-1)&&(E._status=1,E._result=ne)},function(ne){(E._status===0||E._status===-1)&&(E._status=2,E._result=ne)}),E._status===-1&&(E._status=0,E._result=X)}if(E._status===1)return E._result.default;throw E._result}var K={current:null},L={transition:null},O={ReactCurrentDispatcher:K,ReactCurrentBatchConfig:L,ReactCurrentOwner:Q};function q(){throw Error("act(...) is not supported in production builds of React.")}return Ht.Children={map:I,forEach:function(E,X,ne){I(E,function(){X.apply(this,arguments)},ne)},count:function(E){var X=0;return I(E,function(){X++}),X},toArray:function(E){return I(E,function(X){return X})||[]},only:function(E){if(!le(E))throw Error("React.Children.only expected to receive a single React element child.");return E}},Ht.Component=R,Ht.Fragment=n,Ht.Profiler=a,Ht.PureComponent=z,Ht.StrictMode=i,Ht.Suspense=m,Ht.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=O,Ht.act=q,Ht.cloneElement=function(E,X,ne){if(E==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+E+".");var ie=N({},E.props),de=E.key,xe=E.ref,be=E._owner;if(X!=null){if(X.ref!==void 0&&(xe=X.ref,be=Q.current),X.key!==void 0&&(de=""+X.key),E.type&&E.type.defaultProps)var Ee=E.type.defaultProps;for(Oe in X)G.call(X,Oe)&&!Y.hasOwnProperty(Oe)&&(ie[Oe]=X[Oe]===void 0&&Ee!==void 0?Ee[Oe]:X[Oe])}var Oe=arguments.length-2;if(Oe===1)ie.children=ne;else if(1<Oe){Ee=Array(Oe);for(var He=0;He<Oe;He++)Ee[He]=arguments[He+2];ie.children=Ee}return{$$typeof:e,type:E.type,key:de,ref:xe,props:ie,_owner:be}},Ht.createContext=function(E){return E={$$typeof:u,_currentValue:E,_currentValue2:E,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},E.Provider={$$typeof:l,_context:E},E.Consumer=E},Ht.createElement=ee,Ht.createFactory=function(E){var X=ee.bind(null,E);return X.type=E,X},Ht.createRef=function(){return{current:null}},Ht.forwardRef=function(E){return{$$typeof:d,render:E}},Ht.isValidElement=le,Ht.lazy=function(E){return{$$typeof:g,_payload:{_status:-1,_result:E},_init:P}},Ht.memo=function(E,X){return{$$typeof:p,type:E,compare:X===void 0?null:X}},Ht.startTransition=function(E){var X=L.transition;L.transition={};try{E()}finally{L.transition=X}},Ht.unstable_act=q,Ht.useCallback=function(E,X){return K.current.useCallback(E,X)},Ht.useContext=function(E){return K.current.useContext(E)},Ht.useDebugValue=function(){},Ht.useDeferredValue=function(E){return K.current.useDeferredValue(E)},Ht.useEffect=function(E,X){return K.current.useEffect(E,X)},Ht.useId=function(){return K.current.useId()},Ht.useImperativeHandle=function(E,X,ne){return K.current.useImperativeHandle(E,X,ne)},Ht.useInsertionEffect=function(E,X){return K.current.useInsertionEffect(E,X)},Ht.useLayoutEffect=function(E,X){return K.current.useLayoutEffect(E,X)},Ht.useMemo=function(E,X){return K.current.useMemo(E,X)},Ht.useReducer=function(E,X,ne){return K.current.useReducer(E,X,ne)},Ht.useRef=function(E){return K.current.useRef(E)},Ht.useState=function(E){return K.current.useState(E)},Ht.useSyncExternalStore=function(E,X,ne){return K.current.useSyncExternalStore(E,X,ne)},Ht.useTransition=function(){return K.current.useTransition()},Ht.version="18.3.1",Ht}var Jg;function Qd(){return Jg||(Jg=1,Dh.exports=Zx()),Dh.exports}/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.production.min.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var Zg;function Qx(){if(Zg)return xd;Zg=1;var e=Qd(),t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,a=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function u(d,m,p){var g,v={},w=null,x=null;p!==void 0&&(w=""+p),m.key!==void 0&&(w=""+m.key),m.ref!==void 0&&(x=m.ref);for(g in m)i.call(m,g)&&!l.hasOwnProperty(g)&&(v[g]=m[g]);if(d&&d.defaultProps)for(g in m=d.defaultProps,m)v[g]===void 0&&(v[g]=m[g]);return{$$typeof:t,type:d,key:w,ref:x,props:v,_owner:a.current}}return xd.Fragment=n,xd.jsx=u,xd.jsxs=u,xd}var Qg;function eb(){return Qg||(Qg=1,Ih.exports=Qx()),Ih.exports}var r=eb(),_=Qd();const pe=mg(_);var um={},zh={exports:{}},Es={},Fh={exports:{}},Bh={};/**
|
|
18
|
+
* @license React
|
|
19
|
+
* scheduler.production.min.js
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/var ep;function tb(){return ep||(ep=1,(function(e){function t(L,O){var q=L.length;L.push(O);e:for(;0<q;){var E=q-1>>>1,X=L[E];if(0<a(X,O))L[E]=O,L[q]=X,q=E;else break e}}function n(L){return L.length===0?null:L[0]}function i(L){if(L.length===0)return null;var O=L[0],q=L.pop();if(q!==O){L[0]=q;e:for(var E=0,X=L.length,ne=X>>>1;E<ne;){var ie=2*(E+1)-1,de=L[ie],xe=ie+1,be=L[xe];if(0>a(de,q))xe<X&&0>a(be,de)?(L[E]=be,L[xe]=q,E=xe):(L[E]=de,L[ie]=q,E=ie);else if(xe<X&&0>a(be,q))L[E]=be,L[xe]=q,E=xe;else break e}}return O}function a(L,O){var q=L.sortIndex-O.sortIndex;return q!==0?q:L.id-O.id}if(typeof performance=="object"&&typeof performance.now=="function"){var l=performance;e.unstable_now=function(){return l.now()}}else{var u=Date,d=u.now();e.unstable_now=function(){return u.now()-d}}var m=[],p=[],g=1,v=null,w=3,x=!1,N=!1,S=!1,R=typeof setTimeout=="function"?setTimeout:null,T=typeof clearTimeout=="function"?clearTimeout:null,z=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function H(L){for(var O=n(p);O!==null;){if(O.callback===null)i(p);else if(O.startTime<=L)i(p),O.sortIndex=O.expirationTime,t(m,O);else break;O=n(p)}}function D(L){if(S=!1,H(L),!N)if(n(m)!==null)N=!0,P(G);else{var O=n(p);O!==null&&K(D,O.startTime-L)}}function G(L,O){N=!1,S&&(S=!1,T(ee),ee=-1),x=!0;var q=w;try{for(H(O),v=n(m);v!==null&&(!(v.expirationTime>O)||L&&!ge());){var E=v.callback;if(typeof E=="function"){v.callback=null,w=v.priorityLevel;var X=E(v.expirationTime<=O);O=e.unstable_now(),typeof X=="function"?v.callback=X:v===n(m)&&i(m),H(O)}else i(m);v=n(m)}if(v!==null)var ne=!0;else{var ie=n(p);ie!==null&&K(D,ie.startTime-O),ne=!1}return ne}finally{v=null,w=q,x=!1}}var Q=!1,Y=null,ee=-1,ae=5,le=-1;function ge(){return!(e.unstable_now()-le<ae)}function F(){if(Y!==null){var L=e.unstable_now();le=L;var O=!0;try{O=Y(!0,L)}finally{O?C():(Q=!1,Y=null)}}else Q=!1}var C;if(typeof z=="function")C=function(){z(F)};else if(typeof MessageChannel<"u"){var k=new MessageChannel,I=k.port2;k.port1.onmessage=F,C=function(){I.postMessage(null)}}else C=function(){R(F,0)};function P(L){Y=L,Q||(Q=!0,C())}function K(L,O){ee=R(function(){L(e.unstable_now())},O)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(L){L.callback=null},e.unstable_continueExecution=function(){N||x||(N=!0,P(G))},e.unstable_forceFrameRate=function(L){0>L||125<L?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):ae=0<L?Math.floor(1e3/L):5},e.unstable_getCurrentPriorityLevel=function(){return w},e.unstable_getFirstCallbackNode=function(){return n(m)},e.unstable_next=function(L){switch(w){case 1:case 2:case 3:var O=3;break;default:O=w}var q=w;w=O;try{return L()}finally{w=q}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(L,O){switch(L){case 1:case 2:case 3:case 4:case 5:break;default:L=3}var q=w;w=L;try{return O()}finally{w=q}},e.unstable_scheduleCallback=function(L,O,q){var E=e.unstable_now();switch(typeof q=="object"&&q!==null?(q=q.delay,q=typeof q=="number"&&0<q?E+q:E):q=E,L){case 1:var X=-1;break;case 2:X=250;break;case 5:X=1073741823;break;case 4:X=1e4;break;default:X=5e3}return X=q+X,L={id:g++,callback:O,priorityLevel:L,startTime:q,expirationTime:X,sortIndex:-1},q>E?(L.sortIndex=q,t(p,L),n(m)===null&&L===n(p)&&(S?(T(ee),ee=-1):S=!0,K(D,q-E))):(L.sortIndex=X,t(m,L),N||x||(N=!0,P(G))),L},e.unstable_shouldYield=ge,e.unstable_wrapCallback=function(L){var O=w;return function(){var q=w;w=O;try{return L.apply(this,arguments)}finally{w=q}}}})(Bh)),Bh}var tp;function nb(){return tp||(tp=1,Fh.exports=tb()),Fh.exports}/**
|
|
26
|
+
* @license React
|
|
27
|
+
* react-dom.production.min.js
|
|
28
|
+
*
|
|
29
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
30
|
+
*
|
|
31
|
+
* This source code is licensed under the MIT license found in the
|
|
32
|
+
* LICENSE file in the root directory of this source tree.
|
|
33
|
+
*/var np;function rb(){if(np)return Es;np=1;var e=Qd(),t=nb();function n(s){for(var o="https://reactjs.org/docs/error-decoder.html?invariant="+s,c=1;c<arguments.length;c++)o+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+s+"; visit "+o+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var i=new Set,a={};function l(s,o){u(s,o),u(s+"Capture",o)}function u(s,o){for(a[s]=o,s=0;s<o.length;s++)i.add(o[s])}var d=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),m=Object.prototype.hasOwnProperty,p=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,g={},v={};function w(s){return m.call(v,s)?!0:m.call(g,s)?!1:p.test(s)?v[s]=!0:(g[s]=!0,!1)}function x(s,o,c,f){if(c!==null&&c.type===0)return!1;switch(typeof o){case"function":case"symbol":return!0;case"boolean":return f?!1:c!==null?!c.acceptsBooleans:(s=s.toLowerCase().slice(0,5),s!=="data-"&&s!=="aria-");default:return!1}}function N(s,o,c,f){if(o===null||typeof o>"u"||x(s,o,c,f))return!0;if(f)return!1;if(c!==null)switch(c.type){case 3:return!o;case 4:return o===!1;case 5:return isNaN(o);case 6:return isNaN(o)||1>o}return!1}function S(s,o,c,f,y,b,A){this.acceptsBooleans=o===2||o===3||o===4,this.attributeName=f,this.attributeNamespace=y,this.mustUseProperty=c,this.propertyName=s,this.type=o,this.sanitizeURL=b,this.removeEmptyString=A}var R={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(s){R[s]=new S(s,0,!1,s,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(s){var o=s[0];R[o]=new S(o,1,!1,s[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(s){R[s]=new S(s,2,!1,s.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(s){R[s]=new S(s,2,!1,s,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(s){R[s]=new S(s,3,!1,s.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(s){R[s]=new S(s,3,!0,s,null,!1,!1)}),["capture","download"].forEach(function(s){R[s]=new S(s,4,!1,s,null,!1,!1)}),["cols","rows","size","span"].forEach(function(s){R[s]=new S(s,6,!1,s,null,!1,!1)}),["rowSpan","start"].forEach(function(s){R[s]=new S(s,5,!1,s.toLowerCase(),null,!1,!1)});var T=/[\-:]([a-z])/g;function z(s){return s[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(s){var o=s.replace(T,z);R[o]=new S(o,1,!1,s,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(s){var o=s.replace(T,z);R[o]=new S(o,1,!1,s,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(s){var o=s.replace(T,z);R[o]=new S(o,1,!1,s,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(s){R[s]=new S(s,1,!1,s.toLowerCase(),null,!1,!1)}),R.xlinkHref=new S("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(s){R[s]=new S(s,1,!1,s.toLowerCase(),null,!0,!0)});function H(s,o,c,f){var y=R.hasOwnProperty(o)?R[o]:null;(y!==null?y.type!==0:f||!(2<o.length)||o[0]!=="o"&&o[0]!=="O"||o[1]!=="n"&&o[1]!=="N")&&(N(o,c,y,f)&&(c=null),f||y===null?w(o)&&(c===null?s.removeAttribute(o):s.setAttribute(o,""+c)):y.mustUseProperty?s[y.propertyName]=c===null?y.type===3?!1:"":c:(o=y.attributeName,f=y.attributeNamespace,c===null?s.removeAttribute(o):(y=y.type,c=y===3||y===4&&c===!0?"":""+c,f?s.setAttributeNS(f,o,c):s.setAttribute(o,c))))}var D=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,G=Symbol.for("react.element"),Q=Symbol.for("react.portal"),Y=Symbol.for("react.fragment"),ee=Symbol.for("react.strict_mode"),ae=Symbol.for("react.profiler"),le=Symbol.for("react.provider"),ge=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),k=Symbol.for("react.suspense_list"),I=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),K=Symbol.for("react.offscreen"),L=Symbol.iterator;function O(s){return s===null||typeof s!="object"?null:(s=L&&s[L]||s["@@iterator"],typeof s=="function"?s:null)}var q=Object.assign,E;function X(s){if(E===void 0)try{throw Error()}catch(c){var o=c.stack.trim().match(/\n( *(at )?)/);E=o&&o[1]||""}return`
|
|
34
|
+
`+E+s}var ne=!1;function ie(s,o){if(!s||ne)return"";ne=!0;var c=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(o)if(o=function(){throw Error()},Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(_e){var f=_e}Reflect.construct(s,[],o)}else{try{o.call()}catch(_e){f=_e}s.call(o.prototype)}else{try{throw Error()}catch(_e){f=_e}s()}}catch(_e){if(_e&&f&&typeof _e.stack=="string"){for(var y=_e.stack.split(`
|
|
35
|
+
`),b=f.stack.split(`
|
|
36
|
+
`),A=y.length-1,J=b.length-1;1<=A&&0<=J&&y[A]!==b[J];)J--;for(;1<=A&&0<=J;A--,J--)if(y[A]!==b[J]){if(A!==1||J!==1)do if(A--,J--,0>J||y[A]!==b[J]){var te=`
|
|
37
|
+
`+y[A].replace(" at new "," at ");return s.displayName&&te.includes("<anonymous>")&&(te=te.replace("<anonymous>",s.displayName)),te}while(1<=A&&0<=J);break}}}finally{ne=!1,Error.prepareStackTrace=c}return(s=s?s.displayName||s.name:"")?X(s):""}function de(s){switch(s.tag){case 5:return X(s.type);case 16:return X("Lazy");case 13:return X("Suspense");case 19:return X("SuspenseList");case 0:case 2:case 15:return s=ie(s.type,!1),s;case 11:return s=ie(s.type.render,!1),s;case 1:return s=ie(s.type,!0),s;default:return""}}function xe(s){if(s==null)return null;if(typeof s=="function")return s.displayName||s.name||null;if(typeof s=="string")return s;switch(s){case Y:return"Fragment";case Q:return"Portal";case ae:return"Profiler";case ee:return"StrictMode";case C:return"Suspense";case k:return"SuspenseList"}if(typeof s=="object")switch(s.$$typeof){case ge:return(s.displayName||"Context")+".Consumer";case le:return(s._context.displayName||"Context")+".Provider";case F:var o=s.render;return s=s.displayName,s||(s=o.displayName||o.name||"",s=s!==""?"ForwardRef("+s+")":"ForwardRef"),s;case I:return o=s.displayName||null,o!==null?o:xe(s.type)||"Memo";case P:o=s._payload,s=s._init;try{return xe(s(o))}catch{}}return null}function be(s){var o=s.type;switch(s.tag){case 24:return"Cache";case 9:return(o.displayName||"Context")+".Consumer";case 10:return(o._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return s=o.render,s=s.displayName||s.name||"",o.displayName||(s!==""?"ForwardRef("+s+")":"ForwardRef");case 7:return"Fragment";case 5:return o;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return xe(o);case 8:return o===ee?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof o=="function")return o.displayName||o.name||null;if(typeof o=="string")return o}return null}function Ee(s){switch(typeof s){case"boolean":case"number":case"string":case"undefined":return s;case"object":return s;default:return""}}function Oe(s){var o=s.type;return(s=s.nodeName)&&s.toLowerCase()==="input"&&(o==="checkbox"||o==="radio")}function He(s){var o=Oe(s)?"checked":"value",c=Object.getOwnPropertyDescriptor(s.constructor.prototype,o),f=""+s[o];if(!s.hasOwnProperty(o)&&typeof c<"u"&&typeof c.get=="function"&&typeof c.set=="function"){var y=c.get,b=c.set;return Object.defineProperty(s,o,{configurable:!0,get:function(){return y.call(this)},set:function(A){f=""+A,b.call(this,A)}}),Object.defineProperty(s,o,{enumerable:c.enumerable}),{getValue:function(){return f},setValue:function(A){f=""+A},stopTracking:function(){s._valueTracker=null,delete s[o]}}}}function Ke(s){s._valueTracker||(s._valueTracker=He(s))}function Ct(s){if(!s)return!1;var o=s._valueTracker;if(!o)return!0;var c=o.getValue(),f="";return s&&(f=Oe(s)?s.checked?"true":"false":s.value),s=f,s!==c?(o.setValue(s),!0):!1}function pt(s){if(s=s||(typeof document<"u"?document:void 0),typeof s>"u")return null;try{return s.activeElement||s.body}catch{return s.body}}function gt(s,o){var c=o.checked;return q({},o,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:c??s._wrapperState.initialChecked})}function yt(s,o){var c=o.defaultValue==null?"":o.defaultValue,f=o.checked!=null?o.checked:o.defaultChecked;c=Ee(o.value!=null?o.value:c),s._wrapperState={initialChecked:f,initialValue:c,controlled:o.type==="checkbox"||o.type==="radio"?o.checked!=null:o.value!=null}}function nt(s,o){o=o.checked,o!=null&&H(s,"checked",o,!1)}function $e(s,o){nt(s,o);var c=Ee(o.value),f=o.type;if(c!=null)f==="number"?(c===0&&s.value===""||s.value!=c)&&(s.value=""+c):s.value!==""+c&&(s.value=""+c);else if(f==="submit"||f==="reset"){s.removeAttribute("value");return}o.hasOwnProperty("value")?ot(s,o.type,c):o.hasOwnProperty("defaultValue")&&ot(s,o.type,Ee(o.defaultValue)),o.checked==null&&o.defaultChecked!=null&&(s.defaultChecked=!!o.defaultChecked)}function Re(s,o,c){if(o.hasOwnProperty("value")||o.hasOwnProperty("defaultValue")){var f=o.type;if(!(f!=="submit"&&f!=="reset"||o.value!==void 0&&o.value!==null))return;o=""+s._wrapperState.initialValue,c||o===s.value||(s.value=o),s.defaultValue=o}c=s.name,c!==""&&(s.name=""),s.defaultChecked=!!s._wrapperState.initialChecked,c!==""&&(s.name=c)}function ot(s,o,c){(o!=="number"||pt(s.ownerDocument)!==s)&&(c==null?s.defaultValue=""+s._wrapperState.initialValue:s.defaultValue!==""+c&&(s.defaultValue=""+c))}var he=Array.isArray;function Pe(s,o,c,f){if(s=s.options,o){o={};for(var y=0;y<c.length;y++)o["$"+c[y]]=!0;for(c=0;c<s.length;c++)y=o.hasOwnProperty("$"+s[c].value),s[c].selected!==y&&(s[c].selected=y),y&&f&&(s[c].defaultSelected=!0)}else{for(c=""+Ee(c),o=null,y=0;y<s.length;y++){if(s[y].value===c){s[y].selected=!0,f&&(s[y].defaultSelected=!0);return}o!==null||s[y].disabled||(o=s[y])}o!==null&&(o.selected=!0)}}function Ve(s,o){if(o.dangerouslySetInnerHTML!=null)throw Error(n(91));return q({},o,{value:void 0,defaultValue:void 0,children:""+s._wrapperState.initialValue})}function Rt(s,o){var c=o.value;if(c==null){if(c=o.children,o=o.defaultValue,c!=null){if(o!=null)throw Error(n(92));if(he(c)){if(1<c.length)throw Error(n(93));c=c[0]}o=c}o==null&&(o=""),c=o}s._wrapperState={initialValue:Ee(c)}}function Xt(s,o){var c=Ee(o.value),f=Ee(o.defaultValue);c!=null&&(c=""+c,c!==s.value&&(s.value=c),o.defaultValue==null&&s.defaultValue!==c&&(s.defaultValue=c)),f!=null&&(s.defaultValue=""+f)}function fn(s){var o=s.textContent;o===s._wrapperState.initialValue&&o!==""&&o!==null&&(s.value=o)}function Ft(s){switch(s){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function At(s,o){return s==null||s==="http://www.w3.org/1999/xhtml"?Ft(o):s==="http://www.w3.org/2000/svg"&&o==="foreignObject"?"http://www.w3.org/1999/xhtml":s}var sn,zn=(function(s){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(o,c,f,y){MSApp.execUnsafeLocalFunction(function(){return s(o,c,f,y)})}:s})(function(s,o){if(s.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in s)s.innerHTML=o;else{for(sn=sn||document.createElement("div"),sn.innerHTML="<svg>"+o.valueOf().toString()+"</svg>",o=sn.firstChild;s.firstChild;)s.removeChild(s.firstChild);for(;o.firstChild;)s.appendChild(o.firstChild)}});function $t(s,o){if(o){var c=s.firstChild;if(c&&c===s.lastChild&&c.nodeType===3){c.nodeValue=o;return}}s.textContent=o}var pn={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Pn=["Webkit","ms","Moz","O"];Object.keys(pn).forEach(function(s){Pn.forEach(function(o){o=o+s.charAt(0).toUpperCase()+s.substring(1),pn[o]=pn[s]})});function Cn(s,o,c){return o==null||typeof o=="boolean"||o===""?"":c||typeof o!="number"||o===0||pn.hasOwnProperty(s)&&pn[s]?(""+o).trim():o+"px"}function yn(s,o){s=s.style;for(var c in o)if(o.hasOwnProperty(c)){var f=c.indexOf("--")===0,y=Cn(c,o[c],f);c==="float"&&(c="cssFloat"),f?s.setProperty(c,y):s[c]=y}}var Mn=q({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function mn(s,o){if(o){if(Mn[s]&&(o.children!=null||o.dangerouslySetInnerHTML!=null))throw Error(n(137,s));if(o.dangerouslySetInnerHTML!=null){if(o.children!=null)throw Error(n(60));if(typeof o.dangerouslySetInnerHTML!="object"||!("__html"in o.dangerouslySetInnerHTML))throw Error(n(61))}if(o.style!=null&&typeof o.style!="object")throw Error(n(62))}}function br(s,o){if(s.indexOf("-")===-1)return typeof o.is=="string";switch(s){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Hn=null;function Qn(s){return s=s.target||s.srcElement||window,s.correspondingUseElement&&(s=s.correspondingUseElement),s.nodeType===3?s.parentNode:s}var ys=null,qn=null,oe=null;function ve(s){if(s=hl(s)){if(typeof ys!="function")throw Error(n(280));var o=s.stateNode;o&&(o=ba(o),ys(s.stateNode,s.type,o))}}function qe(s){qn?oe?oe.push(s):oe=[s]:qn=s}function We(){if(qn){var s=qn,o=oe;if(oe=qn=null,ve(s),o)for(s=0;s<o.length;s++)ve(o[s])}}function et(s,o){return s(o)}function at(){}var Nt=!1;function xt(s,o,c){if(Nt)return s(o,c);Nt=!0;try{return et(s,o,c)}finally{Nt=!1,(qn!==null||oe!==null)&&(at(),We())}}function Wt(s,o){var c=s.stateNode;if(c===null)return null;var f=ba(c);if(f===null)return null;c=f[o];e:switch(o){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(f=!f.disabled)||(s=s.type,f=!(s==="button"||s==="input"||s==="select"||s==="textarea")),s=!f;break e;default:s=!1}if(s)return null;if(c&&typeof c!="function")throw Error(n(231,o,typeof c));return c}var lt=!1;if(d)try{var Vt={};Object.defineProperty(Vt,"passive",{get:function(){lt=!0}}),window.addEventListener("test",Vt,Vt),window.removeEventListener("test",Vt,Vt)}catch{lt=!1}function It(s,o,c,f,y,b,A,J,te){var _e=Array.prototype.slice.call(arguments,3);try{o.apply(c,_e)}catch(Me){this.onError(Me)}}var jt=!1,ft=null,Mt=!1,Ce=null,Ut={onError:function(s){jt=!0,ft=s}};function St(s,o,c,f,y,b,A,J,te){jt=!1,ft=null,It.apply(Ut,arguments)}function nn(s,o,c,f,y,b,A,J,te){if(St.apply(this,arguments),jt){if(jt){var _e=ft;jt=!1,ft=null}else throw Error(n(198));Mt||(Mt=!0,Ce=_e)}}function kt(s){var o=s,c=s;if(s.alternate)for(;o.return;)o=o.return;else{s=o;do o=s,(o.flags&4098)!==0&&(c=o.return),s=o.return;while(s)}return o.tag===3?c:null}function er(s){if(s.tag===13){var o=s.memoizedState;if(o===null&&(s=s.alternate,s!==null&&(o=s.memoizedState)),o!==null)return o.dehydrated}return null}function tr(s){if(kt(s)!==s)throw Error(n(188))}function Ur(s){var o=s.alternate;if(!o){if(o=kt(s),o===null)throw Error(n(188));return o!==s?null:s}for(var c=s,f=o;;){var y=c.return;if(y===null)break;var b=y.alternate;if(b===null){if(f=y.return,f!==null){c=f;continue}break}if(y.child===b.child){for(b=y.child;b;){if(b===c)return tr(y),s;if(b===f)return tr(y),o;b=b.sibling}throw Error(n(188))}if(c.return!==f.return)c=y,f=b;else{for(var A=!1,J=y.child;J;){if(J===c){A=!0,c=y,f=b;break}if(J===f){A=!0,f=y,c=b;break}J=J.sibling}if(!A){for(J=b.child;J;){if(J===c){A=!0,c=b,f=y;break}if(J===f){A=!0,f=b,c=y;break}J=J.sibling}if(!A)throw Error(n(189))}}if(c.alternate!==f)throw Error(n(190))}if(c.tag!==3)throw Error(n(188));return c.stateNode.current===c?s:o}function jr(s){return s=Ur(s),s!==null?Zr(s):null}function Zr(s){if(s.tag===5||s.tag===6)return s;for(s=s.child;s!==null;){var o=Zr(s);if(o!==null)return o;s=s.sibling}return null}var Wr=t.unstable_scheduleCallback,Gi=t.unstable_cancelCallback,ye=t.unstable_shouldYield,Vn=t.unstable_requestPaint,cn=t.unstable_now,Ki=t.unstable_getCurrentPriorityLevel,vi=t.unstable_ImmediatePriority,vs=t.unstable_UserBlockingPriority,Qr=t.unstable_NormalPriority,Ts=t.unstable_LowPriority,rt=t.unstable_IdlePriority,Qt=null,ur=null;function Js(s){if(ur&&typeof ur.onCommitFiberRoot=="function")try{ur.onCommitFiberRoot(Qt,s,void 0,(s.current.flags&128)===128)}catch{}}var nr=Math.clz32?Math.clz32:Qo,Yi=Math.log,Xi=Math.LN2;function Qo(s){return s>>>=0,s===0?32:31-(Yi(s)/Xi|0)|0}var In=64,es=4194304;function $n(s){switch(s&-s){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return s&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return s&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return s}}function ts(s,o){var c=s.pendingLanes;if(c===0)return 0;var f=0,y=s.suspendedLanes,b=s.pingedLanes,A=c&268435455;if(A!==0){var J=A&~y;J!==0?f=$n(J):(b&=A,b!==0&&(f=$n(b)))}else A=c&~y,A!==0?f=$n(A):b!==0&&(f=$n(b));if(f===0)return 0;if(o!==0&&o!==f&&(o&y)===0&&(y=f&-f,b=o&-o,y>=b||y===16&&(b&4194240)!==0))return o;if((f&4)!==0&&(f|=c&16),o=s.entangledLanes,o!==0)for(s=s.entanglements,o&=f;0<o;)c=31-nr(o),y=1<<c,f|=s[c],o&=~y;return f}function Ji(s,o){switch(s){case 1:case 2:case 4:return o+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return o+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function Kn(s,o){for(var c=s.suspendedLanes,f=s.pingedLanes,y=s.expirationTimes,b=s.pendingLanes;0<b;){var A=31-nr(b),J=1<<A,te=y[A];te===-1?((J&c)===0||(J&f)!==0)&&(y[A]=Ji(J,o)):te<=o&&(s.expiredLanes|=J),b&=~J}}function Hr(s){return s=s.pendingLanes&-1073741825,s!==0?s:s&1073741824?1073741824:0}function rr(){var s=In;return In<<=1,(In&4194240)===0&&(In=64),s}function Rs(s){for(var o=[],c=0;31>c;c++)o.push(s);return o}function dr(s,o,c){s.pendingLanes|=o,o!==536870912&&(s.suspendedLanes=0,s.pingedLanes=0),s=s.eventTimes,o=31-nr(o),s[o]=c}function ea(s,o){var c=s.pendingLanes&~o;s.pendingLanes=o,s.suspendedLanes=0,s.pingedLanes=0,s.expiredLanes&=o,s.mutableReadLanes&=o,s.entangledLanes&=o,o=s.entanglements;var f=s.eventTimes;for(s=s.expirationTimes;0<c;){var y=31-nr(c),b=1<<y;o[y]=0,f[y]=-1,s[y]=-1,c&=~b}}function Zi(s,o){var c=s.entangledLanes|=o;for(s=s.entanglements;c;){var f=31-nr(c),y=1<<f;y&o|s[f]&o&&(s[f]|=o),c&=~y}}var en=0;function sl(s){return s&=-s,1<s?4<s?(s&268435455)!==0?16:536870912:4:1}var wi,ns,Sr,ta,ws,Zs=!1,xi=[],qr=null,kr=null,xs=null,Vr=new Map,bi=new Map,rs=[],fr="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function ji(s,o){switch(s){case"focusin":case"focusout":qr=null;break;case"dragenter":case"dragleave":kr=null;break;case"mouseover":case"mouseout":xs=null;break;case"pointerover":case"pointerout":Vr.delete(o.pointerId);break;case"gotpointercapture":case"lostpointercapture":bi.delete(o.pointerId)}}function fo(s,o,c,f,y,b){return s===null||s.nativeEvent!==b?(s={blockedOn:o,domEventName:c,eventSystemFlags:f,nativeEvent:b,targetContainers:[y]},o!==null&&(o=hl(o),o!==null&&ns(o)),s):(s.eventSystemFlags|=f,o=s.targetContainers,y!==null&&o.indexOf(y)===-1&&o.push(y),s)}function il(s,o,c,f,y){switch(o){case"focusin":return qr=fo(qr,s,o,c,f,y),!0;case"dragenter":return kr=fo(kr,s,o,c,f,y),!0;case"mouseover":return xs=fo(xs,s,o,c,f,y),!0;case"pointerover":var b=y.pointerId;return Vr.set(b,fo(Vr.get(b)||null,s,o,c,f,y)),!0;case"gotpointercapture":return b=y.pointerId,bi.set(b,fo(bi.get(b)||null,s,o,c,f,y)),!0}return!1}function Gr(s){var o=Fs(s.target);if(o!==null){var c=kt(o);if(c!==null){if(o=c.tag,o===13){if(o=er(c),o!==null){s.blockedOn=o,ws(s.priority,function(){Sr(c)});return}}else if(o===3&&c.stateNode.current.memoizedState.isDehydrated){s.blockedOn=c.tag===3?c.stateNode.containerInfo:null;return}}}s.blockedOn=null}function mo(s){if(s.blockedOn!==null)return!1;for(var o=s.targetContainers;0<o.length;){var c=re(s.domEventName,s.eventSystemFlags,o[0],s.nativeEvent);if(c===null){c=s.nativeEvent;var f=new c.constructor(c.type,c);Hn=f,c.target.dispatchEvent(f),Hn=null}else return o=hl(c),o!==null&&ns(o),s.blockedOn=c,!1;o.shift()}return!0}function Ls(s,o,c){mo(s)&&c.delete(o)}function oc(){Zs=!1,qr!==null&&mo(qr)&&(qr=null),kr!==null&&mo(kr)&&(kr=null),xs!==null&&mo(xs)&&(xs=null),Vr.forEach(Ls),bi.forEach(Ls)}function ss(s,o){s.blockedOn===o&&(s.blockedOn=null,Zs||(Zs=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,oc)))}function Qi(s){function o(y){return ss(y,s)}if(0<xi.length){ss(xi[0],s);for(var c=1;c<xi.length;c++){var f=xi[c];f.blockedOn===s&&(f.blockedOn=null)}}for(qr!==null&&ss(qr,s),kr!==null&&ss(kr,s),xs!==null&&ss(xs,s),Vr.forEach(o),bi.forEach(o),c=0;c<rs.length;c++)f=rs[c],f.blockedOn===s&&(f.blockedOn=null);for(;0<rs.length&&(c=rs[0],c.blockedOn===null);)Gr(c),c.blockedOn===null&&rs.shift()}var Lr=D.ReactCurrentBatchConfig,ho=!0;function _o(s,o,c,f){var y=en,b=Lr.transition;Lr.transition=null;try{en=1,eo(s,o,c,f)}finally{en=y,Lr.transition=b}}function go(s,o,c,f){var y=en,b=Lr.transition;Lr.transition=null;try{en=4,eo(s,o,c,f)}finally{en=y,Lr.transition=b}}function eo(s,o,c,f){if(ho){var y=re(s,o,c,f);if(y===null)pa(s,o,f,B,c),ji(s,f);else if(il(y,s,o,c,f))f.stopPropagation();else if(ji(s,f),o&4&&-1<fr.indexOf(s)){for(;y!==null;){var b=hl(y);if(b!==null&&wi(b),b=re(s,o,c,f),b===null&&pa(s,o,f,B,c),b===y)break;y=b}y!==null&&f.stopPropagation()}else pa(s,o,f,null,c)}}var B=null;function re(s,o,c,f){if(B=null,s=Qn(f),s=Fs(s),s!==null)if(o=kt(s),o===null)s=null;else if(c=o.tag,c===13){if(s=er(o),s!==null)return s;s=null}else if(c===3){if(o.stateNode.current.memoizedState.isDehydrated)return o.tag===3?o.stateNode.containerInfo:null;s=null}else o!==s&&(s=null);return B=s,null}function we(s){switch(s){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(Ki()){case vi:return 1;case vs:return 4;case Qr:case Ts:return 16;case rt:return 536870912;default:return 16}default:return 16}}var Se=null,je=null,Fe=null;function mt(){if(Fe)return Fe;var s,o=je,c=o.length,f,y="value"in Se?Se.value:Se.textContent,b=y.length;for(s=0;s<c&&o[s]===y[s];s++);var A=c-s;for(f=1;f<=A&&o[c-f]===y[b-f];f++);return Fe=y.slice(s,1<f?1-f:void 0)}function it(s){var o=s.keyCode;return"charCode"in s?(s=s.charCode,s===0&&o===13&&(s=13)):s=o,s===10&&(s=13),32<=s||s===13?s:0}function ct(){return!0}function Bt(){return!1}function Lt(s){function o(c,f,y,b,A){this._reactName=c,this._targetInst=y,this.type=f,this.nativeEvent=b,this.target=A,this.currentTarget=null;for(var J in s)s.hasOwnProperty(J)&&(c=s[J],this[J]=c?c(b):b[J]);return this.isDefaultPrevented=(b.defaultPrevented!=null?b.defaultPrevented:b.returnValue===!1)?ct:Bt,this.isPropagationStopped=Bt,this}return q(o.prototype,{preventDefault:function(){this.defaultPrevented=!0;var c=this.nativeEvent;c&&(c.preventDefault?c.preventDefault():typeof c.returnValue!="unknown"&&(c.returnValue=!1),this.isDefaultPrevented=ct)},stopPropagation:function(){var c=this.nativeEvent;c&&(c.stopPropagation?c.stopPropagation():typeof c.cancelBubble!="unknown"&&(c.cancelBubble=!0),this.isPropagationStopped=ct)},persist:function(){},isPersistent:ct}),o}var sr={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(s){return s.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},Dt=Lt(sr),Kt=q({},sr,{view:0,detail:0}),hn=Lt(Kt),_n,mr,Nr,Qs=q({},Kt,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:ju,button:0,buttons:0,relatedTarget:function(s){return s.relatedTarget===void 0?s.fromElement===s.srcElement?s.toElement:s.fromElement:s.relatedTarget},movementX:function(s){return"movementX"in s?s.movementX:(s!==Nr&&(Nr&&s.type==="mousemove"?(_n=s.screenX-Nr.screenX,mr=s.screenY-Nr.screenY):mr=_n=0,Nr=s),_n)},movementY:function(s){return"movementY"in s?s.movementY:mr}}),na=Lt(Qs),ra=q({},Qs,{dataTransfer:0}),yu=Lt(ra),ac=q({},Kt,{relatedTarget:0}),sa=Lt(ac),lc=q({},sr,{animationName:0,elapsedTime:0,pseudoElement:0}),sf=Lt(lc),po=q({},sr,{clipboardData:function(s){return"clipboardData"in s?s.clipboardData:window.clipboardData}}),of=Lt(po),vu=q({},sr,{data:0}),cc=Lt(vu),wu={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},xu={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},hh={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function bu(s){var o=this.nativeEvent;return o.getModifierState?o.getModifierState(s):(s=hh[s])?!!o[s]:!1}function ju(){return bu}var af=q({},Kt,{key:function(s){if(s.key){var o=wu[s.key]||s.key;if(o!=="Unidentified")return o}return s.type==="keypress"?(s=it(s),s===13?"Enter":String.fromCharCode(s)):s.type==="keydown"||s.type==="keyup"?xu[s.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:ju,charCode:function(s){return s.type==="keypress"?it(s):0},keyCode:function(s){return s.type==="keydown"||s.type==="keyup"?s.keyCode:0},which:function(s){return s.type==="keypress"?it(s):s.type==="keydown"||s.type==="keyup"?s.keyCode:0}}),Su=Lt(af),Jt=q({},Qs,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),uc=Lt(Jt),_h=q({},Kt,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:ju}),ku=Lt(_h),gh=q({},sr,{propertyName:0,elapsedTime:0,pseudoElement:0}),Nu=Lt(gh),ph=q({},Qs,{deltaX:function(s){return"deltaX"in s?s.deltaX:"wheelDeltaX"in s?-s.wheelDeltaX:0},deltaY:function(s){return"deltaY"in s?s.deltaY:"wheelDeltaY"in s?-s.wheelDeltaY:"wheelDelta"in s?-s.wheelDelta:0},deltaZ:0,deltaMode:0}),hr=Lt(ph),Os=[9,13,27,32],yo=d&&"CompositionEvent"in window,ol=null;d&&"documentMode"in document&&(ol=document.documentMode);var al=d&&"TextEvent"in window&&!ol,dc=d&&(!yo||ol&&8<ol&&11>=ol),lf=" ",Cu=!1;function fc(s,o){switch(s){case"keyup":return Os.indexOf(o.keyCode)!==-1;case"keydown":return o.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function mc(s){return s=s.detail,typeof s=="object"&&"data"in s?s.data:null}var vo=!1;function hc(s,o){switch(s){case"compositionend":return mc(o);case"keypress":return o.which!==32?null:(Cu=!0,lf);case"textInput":return s=o.data,s===lf&&Cu?null:s;default:return null}}function cf(s,o){if(vo)return s==="compositionend"||!yo&&fc(s,o)?(s=mt(),Fe=je=Se=null,vo=!1,s):null;switch(s){case"paste":return null;case"keypress":if(!(o.ctrlKey||o.altKey||o.metaKey)||o.ctrlKey&&o.altKey){if(o.char&&1<o.char.length)return o.char;if(o.which)return String.fromCharCode(o.which)}return null;case"compositionend":return dc&&o.locale!=="ko"?null:o.data;default:return null}}var uf={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function df(s){var o=s&&s.nodeName&&s.nodeName.toLowerCase();return o==="input"?!!uf[s.type]:o==="textarea"}function ll(s,o,c,f){qe(f),o=ya(o,"onChange"),0<o.length&&(c=new Dt("onChange","change",null,c,f),s.push({event:c,listeners:o}))}var ia=null,wo=null;function yh(s){ga(s,0)}function oa(s){var o=ii(s);if(Ct(o))return s}function vh(s,o){if(s==="change")return o}var $u=!1;if(d){var Eu;if(d){var cl="oninput"in document;if(!cl){var ff=document.createElement("div");ff.setAttribute("oninput","return;"),cl=typeof ff.oninput=="function"}Eu=cl}else Eu=!1;$u=Eu&&(!document.documentMode||9<document.documentMode)}function _c(){ia&&(ia.detachEvent("onpropertychange",mf),wo=ia=null)}function mf(s){if(s.propertyName==="value"&&oa(wo)){var o=[];ll(o,wo,s,Qn(s)),xt(yh,o)}}function wh(s,o,c){s==="focusin"?(_c(),ia=o,wo=c,ia.attachEvent("onpropertychange",mf)):s==="focusout"&&_c()}function xh(s){if(s==="selectionchange"||s==="keyup"||s==="keydown")return oa(wo)}function aa(s,o){if(s==="click")return oa(o)}function hf(s,o){if(s==="input"||s==="change")return oa(o)}function gc(s,o){return s===o&&(s!==0||1/s===1/o)||s!==s&&o!==o}var Ps=typeof Object.is=="function"?Object.is:gc;function to(s,o){if(Ps(s,o))return!0;if(typeof s!="object"||s===null||typeof o!="object"||o===null)return!1;var c=Object.keys(s),f=Object.keys(o);if(c.length!==f.length)return!1;for(f=0;f<c.length;f++){var y=c[f];if(!m.call(o,y)||!Ps(s[y],o[y]))return!1}return!0}function xo(s){for(;s&&s.firstChild;)s=s.firstChild;return s}function la(s,o){var c=xo(s);s=0;for(var f;c;){if(c.nodeType===3){if(f=s+c.textContent.length,s<=o&&f>=o)return{node:c,offset:o-s};s=f}e:{for(;c;){if(c.nextSibling){c=c.nextSibling;break e}c=c.parentNode}c=void 0}c=xo(c)}}function bo(s,o){return s&&o?s===o?!0:s&&s.nodeType===3?!1:o&&o.nodeType===3?bo(s,o.parentNode):"contains"in s?s.contains(o):s.compareDocumentPosition?!!(s.compareDocumentPosition(o)&16):!1:!1}function ca(){for(var s=window,o=pt();o instanceof s.HTMLIFrameElement;){try{var c=typeof o.contentWindow.location.href=="string"}catch{c=!1}if(c)s=o.contentWindow;else break;o=pt(s.document)}return o}function ua(s){var o=s&&s.nodeName&&s.nodeName.toLowerCase();return o&&(o==="input"&&(s.type==="text"||s.type==="search"||s.type==="tel"||s.type==="url"||s.type==="password")||o==="textarea"||s.contentEditable==="true")}function Au(s){var o=ca(),c=s.focusedElem,f=s.selectionRange;if(o!==c&&c&&c.ownerDocument&&bo(c.ownerDocument.documentElement,c)){if(f!==null&&ua(c)){if(o=f.start,s=f.end,s===void 0&&(s=o),"selectionStart"in c)c.selectionStart=o,c.selectionEnd=Math.min(s,c.value.length);else if(s=(o=c.ownerDocument||document)&&o.defaultView||window,s.getSelection){s=s.getSelection();var y=c.textContent.length,b=Math.min(f.start,y);f=f.end===void 0?b:Math.min(f.end,y),!s.extend&&b>f&&(y=f,f=b,b=y),y=la(c,b);var A=la(c,f);y&&A&&(s.rangeCount!==1||s.anchorNode!==y.node||s.anchorOffset!==y.offset||s.focusNode!==A.node||s.focusOffset!==A.offset)&&(o=o.createRange(),o.setStart(y.node,y.offset),s.removeAllRanges(),b>f?(s.addRange(o),s.extend(A.node,A.offset)):(o.setEnd(A.node,A.offset),s.addRange(o)))}}for(o=[],s=c;s=s.parentNode;)s.nodeType===1&&o.push({element:s,left:s.scrollLeft,top:s.scrollTop});for(typeof c.focus=="function"&&c.focus(),c=0;c<o.length;c++)s=o[c],s.element.scrollLeft=s.left,s.element.scrollTop=s.top}}var _f=d&&"documentMode"in document&&11>=document.documentMode,ei=null,pc=null,Si=null,da=!1;function gf(s,o,c){var f=c.window===c?c.document:c.nodeType===9?c:c.ownerDocument;da||ei==null||ei!==pt(f)||(f=ei,"selectionStart"in f&&ua(f)?f={start:f.selectionStart,end:f.selectionEnd}:(f=(f.ownerDocument&&f.ownerDocument.defaultView||window).getSelection(),f={anchorNode:f.anchorNode,anchorOffset:f.anchorOffset,focusNode:f.focusNode,focusOffset:f.focusOffset}),Si&&to(Si,f)||(Si=f,f=ya(pc,"onSelect"),0<f.length&&(o=new Dt("onSelect","select",null,o,c),s.push({event:o,listeners:f}),o.target=ei)))}function ul(s,o){var c={};return c[s.toLowerCase()]=o.toLowerCase(),c["Webkit"+s]="webkit"+o,c["Moz"+s]="moz"+o,c}var fa={animationend:ul("Animation","AnimationEnd"),animationiteration:ul("Animation","AnimationIteration"),animationstart:ul("Animation","AnimationStart"),transitionend:ul("Transition","TransitionEnd")},Mu={},dl={};d&&(dl=document.createElement("div").style,"AnimationEvent"in window||(delete fa.animationend.animation,delete fa.animationiteration.animation,delete fa.animationstart.animation),"TransitionEvent"in window||delete fa.transitionend.transition);function bs(s){if(Mu[s])return Mu[s];if(!fa[s])return s;var o=fa[s],c;for(c in o)if(o.hasOwnProperty(c)&&c in dl)return Mu[s]=o[c];return s}var jo=bs("animationend"),pf=bs("animationiteration"),fl=bs("animationstart"),yf=bs("transitionend"),yc=new Map,ma="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function Yn(s,o){yc.set(s,o),l(o,[s])}for(var ti=0;ti<ma.length;ti++){var ha=ma[ti],_a=ha.toLowerCase(),Tu=ha[0].toUpperCase()+ha.slice(1);Yn(_a,"on"+Tu)}Yn(jo,"onAnimationEnd"),Yn(pf,"onAnimationIteration"),Yn(fl,"onAnimationStart"),Yn("dblclick","onDoubleClick"),Yn("focusin","onFocus"),Yn("focusout","onBlur"),Yn(yf,"onTransitionEnd"),u("onMouseEnter",["mouseout","mouseover"]),u("onMouseLeave",["mouseout","mouseover"]),u("onPointerEnter",["pointerout","pointerover"]),u("onPointerLeave",["pointerout","pointerover"]),l("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),l("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),l("onBeforeInput",["compositionend","keypress","textInput","paste"]),l("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),l("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),l("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var ki="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),Ni=new Set("cancel close invalid load scroll toggle".split(" ").concat(ki));function ml(s,o,c){var f=s.type||"unknown-event";s.currentTarget=c,nn(f,o,void 0,s),s.currentTarget=null}function ga(s,o){o=(o&4)!==0;for(var c=0;c<s.length;c++){var f=s[c],y=f.event;f=f.listeners;e:{var b=void 0;if(o)for(var A=f.length-1;0<=A;A--){var J=f[A],te=J.instance,_e=J.currentTarget;if(J=J.listener,te!==b&&y.isPropagationStopped())break e;ml(y,J,_e),b=te}else for(A=0;A<f.length;A++){if(J=f[A],te=J.instance,_e=J.currentTarget,J=J.listener,te!==b&&y.isPropagationStopped())break e;ml(y,J,_e),b=te}}}if(Mt)throw s=Ce,Mt=!1,Ce=null,s}function on(s,o){var c=o[bc];c===void 0&&(c=o[bc]=new Set);var f=s+"__bubble";c.has(f)||(So(o,s,2,!1),c.add(f))}function ni(s,o,c){var f=0;o&&(f|=4),So(c,s,f,o)}var _r="_reactListening"+Math.random().toString(36).slice(2);function Is(s){if(!s[_r]){s[_r]=!0,i.forEach(function(c){c!=="selectionchange"&&(Ni.has(c)||ni(c,!1,s),ni(c,!0,s))});var o=s.nodeType===9?s:s.ownerDocument;o===null||o[_r]||(o[_r]=!0,ni("selectionchange",!1,o))}}function So(s,o,c,f){switch(we(o)){case 1:var y=_o;break;case 4:y=go;break;default:y=eo}c=y.bind(null,o,c,s),y=void 0,!lt||o!=="touchstart"&&o!=="touchmove"&&o!=="wheel"||(y=!0),f?y!==void 0?s.addEventListener(o,c,{capture:!0,passive:y}):s.addEventListener(o,c,!0):y!==void 0?s.addEventListener(o,c,{passive:y}):s.addEventListener(o,c,!1)}function pa(s,o,c,f,y){var b=f;if((o&1)===0&&(o&2)===0&&f!==null)e:for(;;){if(f===null)return;var A=f.tag;if(A===3||A===4){var J=f.stateNode.containerInfo;if(J===y||J.nodeType===8&&J.parentNode===y)break;if(A===4)for(A=f.return;A!==null;){var te=A.tag;if((te===3||te===4)&&(te=A.stateNode.containerInfo,te===y||te.nodeType===8&&te.parentNode===y))return;A=A.return}for(;J!==null;){if(A=Fs(J),A===null)return;if(te=A.tag,te===5||te===6){f=b=A;continue e}J=J.parentNode}}f=f.return}xt(function(){var _e=b,Me=Qn(c),Te=[];e:{var Ae=yc.get(s);if(Ae!==void 0){var Ye=Dt,Ze=s;switch(s){case"keypress":if(it(c)===0)break e;case"keydown":case"keyup":Ye=Su;break;case"focusin":Ze="focus",Ye=sa;break;case"focusout":Ze="blur",Ye=sa;break;case"beforeblur":case"afterblur":Ye=sa;break;case"click":if(c.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":Ye=na;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Ye=yu;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Ye=ku;break;case jo:case pf:case fl:Ye=sf;break;case yf:Ye=Nu;break;case"scroll":Ye=hn;break;case"wheel":Ye=hr;break;case"copy":case"cut":case"paste":Ye=of;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Ye=uc}var Qe=(o&4)!==0,Zn=!Qe&&s==="scroll",ce=Qe?Ae!==null?Ae+"Capture":null:Ae;Qe=[];for(var se=_e,fe;se!==null;){fe=se;var De=fe.stateNode;if(fe.tag===5&&De!==null&&(fe=De,ce!==null&&(De=Wt(se,ce),De!=null&&Qe.push(Ds(se,De,fe)))),Zn)break;se=se.return}0<Qe.length&&(Ae=new Ye(Ae,Ze,null,c,Me),Te.push({event:Ae,listeners:Qe}))}}if((o&7)===0){e:{if(Ae=s==="mouseover"||s==="pointerover",Ye=s==="mouseout"||s==="pointerout",Ae&&c!==Hn&&(Ze=c.relatedTarget||c.fromElement)&&(Fs(Ze)||Ze[Ei]))break e;if((Ye||Ae)&&(Ae=Me.window===Me?Me:(Ae=Me.ownerDocument)?Ae.defaultView||Ae.parentWindow:window,Ye?(Ze=c.relatedTarget||c.toElement,Ye=_e,Ze=Ze?Fs(Ze):null,Ze!==null&&(Zn=kt(Ze),Ze!==Zn||Ze.tag!==5&&Ze.tag!==6)&&(Ze=null)):(Ye=null,Ze=_e),Ye!==Ze)){if(Qe=na,De="onMouseLeave",ce="onMouseEnter",se="mouse",(s==="pointerout"||s==="pointerover")&&(Qe=uc,De="onPointerLeave",ce="onPointerEnter",se="pointer"),Zn=Ye==null?Ae:ii(Ye),fe=Ze==null?Ae:ii(Ze),Ae=new Qe(De,se+"leave",Ye,c,Me),Ae.target=Zn,Ae.relatedTarget=fe,De=null,Fs(Me)===_e&&(Qe=new Qe(ce,se+"enter",Ze,c,Me),Qe.target=fe,Qe.relatedTarget=Zn,De=Qe),Zn=De,Ye&&Ze)t:{for(Qe=Ye,ce=Ze,se=0,fe=Qe;fe;fe=Ci(fe))se++;for(fe=0,De=ce;De;De=Ci(De))fe++;for(;0<se-fe;)Qe=Ci(Qe),se--;for(;0<fe-se;)ce=Ci(ce),fe--;for(;se--;){if(Qe===ce||ce!==null&&Qe===ce.alternate)break t;Qe=Ci(Qe),ce=Ci(ce)}Qe=null}else Qe=null;Ye!==null&&zs(Te,Ae,Ye,Qe,!1),Ze!==null&&Zn!==null&&zs(Te,Zn,Ze,Qe,!0)}}e:{if(Ae=_e?ii(_e):window,Ye=Ae.nodeName&&Ae.nodeName.toLowerCase(),Ye==="select"||Ye==="input"&&Ae.type==="file")var tt=vh;else if(df(Ae))if($u)tt=hf;else{tt=xh;var ht=wh}else(Ye=Ae.nodeName)&&Ye.toLowerCase()==="input"&&(Ae.type==="checkbox"||Ae.type==="radio")&&(tt=aa);if(tt&&(tt=tt(s,_e))){ll(Te,tt,c,Me);break e}ht&&ht(s,Ae,_e),s==="focusout"&&(ht=Ae._wrapperState)&&ht.controlled&&Ae.type==="number"&&ot(Ae,"number",Ae.value)}switch(ht=_e?ii(_e):window,s){case"focusin":(df(ht)||ht.contentEditable==="true")&&(ei=ht,pc=_e,Si=null);break;case"focusout":Si=pc=ei=null;break;case"mousedown":da=!0;break;case"contextmenu":case"mouseup":case"dragend":da=!1,gf(Te,c,Me);break;case"selectionchange":if(_f)break;case"keydown":case"keyup":gf(Te,c,Me)}var _t;if(yo)e:{switch(s){case"compositionstart":var bt="onCompositionStart";break e;case"compositionend":bt="onCompositionEnd";break e;case"compositionupdate":bt="onCompositionUpdate";break e}bt=void 0}else vo?fc(s,c)&&(bt="onCompositionEnd"):s==="keydown"&&c.keyCode===229&&(bt="onCompositionStart");bt&&(dc&&c.locale!=="ko"&&(vo||bt!=="onCompositionStart"?bt==="onCompositionEnd"&&vo&&(_t=mt()):(Se=Me,je="value"in Se?Se.value:Se.textContent,vo=!0)),ht=ya(_e,bt),0<ht.length&&(bt=new cc(bt,s,null,c,Me),Te.push({event:bt,listeners:ht}),_t?bt.data=_t:(_t=mc(c),_t!==null&&(bt.data=_t)))),(_t=al?hc(s,c):cf(s,c))&&(_e=ya(_e,"onBeforeInput"),0<_e.length&&(Me=new cc("onBeforeInput","beforeinput",null,c,Me),Te.push({event:Me,listeners:_e}),Me.data=_t))}ga(Te,o)})}function Ds(s,o,c){return{instance:s,listener:o,currentTarget:c}}function ya(s,o){for(var c=o+"Capture",f=[];s!==null;){var y=s,b=y.stateNode;y.tag===5&&b!==null&&(y=b,b=Wt(s,c),b!=null&&f.unshift(Ds(s,b,y)),b=Wt(s,o),b!=null&&f.push(Ds(s,b,y))),s=s.return}return f}function Ci(s){if(s===null)return null;do s=s.return;while(s&&s.tag!==5);return s||null}function zs(s,o,c,f,y){for(var b=o._reactName,A=[];c!==null&&c!==f;){var J=c,te=J.alternate,_e=J.stateNode;if(te!==null&&te===f)break;J.tag===5&&_e!==null&&(J=_e,y?(te=Wt(c,b),te!=null&&A.unshift(Ds(c,te,J))):y||(te=Wt(c,b),te!=null&&A.push(Ds(c,te,J)))),c=c.return}A.length!==0&&s.push({event:o,listeners:A})}var no=/\r\n?/g,ri=/\u0000|\uFFFD/g;function Ru(s){return(typeof s=="string"?s:""+s).replace(no,`
|
|
38
|
+
`).replace(ri,"")}function va(s,o,c){if(o=Ru(o),Ru(s)!==o&&c)throw Error(n(425))}function vc(){}var wa=null,wc=null;function ko(s,o){return s==="textarea"||s==="noscript"||typeof o.children=="string"||typeof o.children=="number"||typeof o.dangerouslySetInnerHTML=="object"&&o.dangerouslySetInnerHTML!==null&&o.dangerouslySetInnerHTML.__html!=null}var xc=typeof setTimeout=="function"?setTimeout:void 0,Lu=typeof clearTimeout=="function"?clearTimeout:void 0,Ou=typeof Promise=="function"?Promise:void 0,vf=typeof queueMicrotask=="function"?queueMicrotask:typeof Ou<"u"?function(s){return Ou.resolve(null).then(s).catch(wf)}:xc;function wf(s){setTimeout(function(){throw s})}function Pu(s,o){var c=o,f=0;do{var y=c.nextSibling;if(s.removeChild(c),y&&y.nodeType===8)if(c=y.data,c==="/$"){if(f===0){s.removeChild(y),Qi(o);return}f--}else c!=="$"&&c!=="$?"&&c!=="$!"||f++;c=y}while(c);Qi(o)}function $i(s){for(;s!=null;s=s.nextSibling){var o=s.nodeType;if(o===1||o===3)break;if(o===8){if(o=s.data,o==="$"||o==="$!"||o==="$?")break;if(o==="/$")return null}}return s}function xf(s){s=s.previousSibling;for(var o=0;s;){if(s.nodeType===8){var c=s.data;if(c==="$"||c==="$!"||c==="$?"){if(o===0)return s;o--}else c==="/$"&&o++}s=s.previousSibling}return null}var No=Math.random().toString(36).slice(2),si="__reactFiber$"+No,xa="__reactProps$"+No,Ei="__reactContainer$"+No,bc="__reactEvents$"+No,bh="__reactListeners$"+No,bf="__reactHandles$"+No;function Fs(s){var o=s[si];if(o)return o;for(var c=s.parentNode;c;){if(o=c[Ei]||c[si]){if(c=o.alternate,o.child!==null||c!==null&&c.child!==null)for(s=xf(s);s!==null;){if(c=s[si])return c;s=xf(s)}return o}s=c,c=s.parentNode}return null}function hl(s){return s=s[si]||s[Ei],!s||s.tag!==5&&s.tag!==6&&s.tag!==13&&s.tag!==3?null:s}function ii(s){if(s.tag===5||s.tag===6)return s.stateNode;throw Error(n(33))}function ba(s){return s[xa]||null}var ja=[],Co=-1;function is(s){return{current:s}}function bn(s){0>Co||(s.current=ja[Co],ja[Co]=null,Co--)}function un(s,o){Co++,ja[Co]=s.current,s.current=o}var ro={},Fn=is(ro),Kr=is(!1),oi=ro;function Sa(s,o){var c=s.type.contextTypes;if(!c)return ro;var f=s.stateNode;if(f&&f.__reactInternalMemoizedUnmaskedChildContext===o)return f.__reactInternalMemoizedMaskedChildContext;var y={},b;for(b in c)y[b]=o[b];return f&&(s=s.stateNode,s.__reactInternalMemoizedUnmaskedChildContext=o,s.__reactInternalMemoizedMaskedChildContext=y),y}function Bn(s){return s=s.childContextTypes,s!=null}function _l(){bn(Kr),bn(Fn)}function ka(s,o,c){if(Fn.current!==ro)throw Error(n(168));un(Fn,o),un(Kr,c)}function Na(s,o,c){var f=s.stateNode;if(o=o.childContextTypes,typeof f.getChildContext!="function")return c;f=f.getChildContext();for(var y in f)if(!(y in o))throw Error(n(108,be(s)||"Unknown",y));return q({},c,f)}function gl(s){return s=(s=s.stateNode)&&s.__reactInternalMemoizedMergedChildContext||ro,oi=Fn.current,un(Fn,s),un(Kr,Kr.current),!0}function jc(s,o,c){var f=s.stateNode;if(!f)throw Error(n(169));c?(s=Na(s,o,oi),f.__reactInternalMemoizedMergedChildContext=s,bn(Kr),bn(Fn),un(Fn,s)):bn(Kr),un(Kr,c)}var os=null,Ca=!1,so=!1;function Sc(s){os===null?os=[s]:os.push(s)}function jh(s){Ca=!0,Sc(s)}function Bs(){if(!so&&os!==null){so=!0;var s=0,o=en;try{var c=os;for(en=1;s<c.length;s++){var f=c[s];do f=f(!0);while(f!==null)}os=null,Ca=!1}catch(y){throw os!==null&&(os=os.slice(s+1)),Wr(vi,Bs),y}finally{en=o,so=!1}}return null}var $o=[],$a=0,kc=null,ai=0,vn=[],Or=0,Ai=null,Mi=1,Ti="";function li(s,o){$o[$a++]=ai,$o[$a++]=kc,kc=s,ai=o}function jf(s,o,c){vn[Or++]=Mi,vn[Or++]=Ti,vn[Or++]=Ai,Ai=s;var f=Mi;s=Ti;var y=32-nr(f)-1;f&=~(1<<y),c+=1;var b=32-nr(o)+y;if(30<b){var A=y-y%5;b=(f&(1<<A)-1).toString(32),f>>=A,y-=A,Mi=1<<32-nr(o)+y|c<<y|f,Ti=b+s}else Mi=1<<b|c<<y|f,Ti=s}function Eo(s){s.return!==null&&(li(s,1),jf(s,1,0))}function Nc(s){for(;s===kc;)kc=$o[--$a],$o[$a]=null,ai=$o[--$a],$o[$a]=null;for(;s===Ai;)Ai=vn[--Or],vn[Or]=null,Ti=vn[--Or],vn[Or]=null,Mi=vn[--Or],vn[Or]=null}var gr=null,Yr=null,jn=!1,Us=null;function Iu(s,o){var c=Ar(5,null,null,0);c.elementType="DELETED",c.stateNode=o,c.return=s,o=s.deletions,o===null?(s.deletions=[c],s.flags|=16):o.push(c)}function Du(s,o){switch(s.tag){case 5:var c=s.type;return o=o.nodeType!==1||c.toLowerCase()!==o.nodeName.toLowerCase()?null:o,o!==null?(s.stateNode=o,gr=s,Yr=$i(o.firstChild),!0):!1;case 6:return o=s.pendingProps===""||o.nodeType!==3?null:o,o!==null?(s.stateNode=o,gr=s,Yr=null,!0):!1;case 13:return o=o.nodeType!==8?null:o,o!==null?(c=Ai!==null?{id:Mi,overflow:Ti}:null,s.memoizedState={dehydrated:o,treeContext:c,retryLane:1073741824},c=Ar(18,null,null,0),c.stateNode=o,c.return=s,s.child=c,gr=s,Yr=null,!0):!1;default:return!1}}function Cc(s){return(s.mode&1)!==0&&(s.flags&128)===0}function zu(s){if(jn){var o=Yr;if(o){var c=o;if(!Du(s,o)){if(Cc(s))throw Error(n(418));o=$i(c.nextSibling);var f=gr;o&&Du(s,o)?Iu(f,c):(s.flags=s.flags&-4097|2,jn=!1,gr=s)}}else{if(Cc(s))throw Error(n(418));s.flags=s.flags&-4097|2,jn=!1,gr=s}}}function Fu(s){for(s=s.return;s!==null&&s.tag!==5&&s.tag!==3&&s.tag!==13;)s=s.return;gr=s}function Ao(s){if(s!==gr)return!1;if(!jn)return Fu(s),jn=!0,!1;var o;if((o=s.tag!==3)&&!(o=s.tag!==5)&&(o=s.type,o=o!=="head"&&o!=="body"&&!ko(s.type,s.memoizedProps)),o&&(o=Yr)){if(Cc(s))throw Sf(),Error(n(418));for(;o;)Iu(s,o),o=$i(o.nextSibling)}if(Fu(s),s.tag===13){if(s=s.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(n(317));e:{for(s=s.nextSibling,o=0;s;){if(s.nodeType===8){var c=s.data;if(c==="/$"){if(o===0){Yr=$i(s.nextSibling);break e}o--}else c!=="$"&&c!=="$!"&&c!=="$?"||o++}s=s.nextSibling}Yr=null}}else Yr=gr?$i(s.stateNode.nextSibling):null;return!0}function Sf(){for(var s=Yr;s;)s=$i(s.nextSibling)}function Ea(){Yr=gr=null,jn=!1}function Bu(s){Us===null?Us=[s]:Us.push(s)}var Sh=D.ReactCurrentBatchConfig;function Mo(s,o,c){if(s=c.ref,s!==null&&typeof s!="function"&&typeof s!="object"){if(c._owner){if(c=c._owner,c){if(c.tag!==1)throw Error(n(309));var f=c.stateNode}if(!f)throw Error(n(147,s));var y=f,b=""+s;return o!==null&&o.ref!==null&&typeof o.ref=="function"&&o.ref._stringRef===b?o.ref:(o=function(A){var J=y.refs;A===null?delete J[b]:J[b]=A},o._stringRef=b,o)}if(typeof s!="string")throw Error(n(284));if(!c._owner)throw Error(n(290,s))}return s}function $c(s,o){throw s=Object.prototype.toString.call(o),Error(n(31,s==="[object Object]"?"object with keys {"+Object.keys(o).join(", ")+"}":s))}function Ec(s){var o=s._init;return o(s._payload)}function kf(s){function o(ce,se){if(s){var fe=ce.deletions;fe===null?(ce.deletions=[se],ce.flags|=16):fe.push(se)}}function c(ce,se){if(!s)return null;for(;se!==null;)o(ce,se),se=se.sibling;return null}function f(ce,se){for(ce=new Map;se!==null;)se.key!==null?ce.set(se.key,se):ce.set(se.index,se),se=se.sibling;return ce}function y(ce,se){return ce=Ha(ce,se),ce.index=0,ce.sibling=null,ce}function b(ce,se,fe){return ce.index=fe,s?(fe=ce.alternate,fe!==null?(fe=fe.index,fe<se?(ce.flags|=2,se):fe):(ce.flags|=2,se)):(ce.flags|=1048576,se)}function A(ce){return s&&ce.alternate===null&&(ce.flags|=2),ce}function J(ce,se,fe,De){return se===null||se.tag!==6?(se=Mh(fe,ce.mode,De),se.return=ce,se):(se=y(se,fe),se.return=ce,se)}function te(ce,se,fe,De){var tt=fe.type;return tt===Y?Me(ce,se,fe.props.children,De,fe.key):se!==null&&(se.elementType===tt||typeof tt=="object"&&tt!==null&&tt.$$typeof===P&&Ec(tt)===se.type)?(De=y(se,fe.props),De.ref=Mo(ce,se,fe),De.return=ce,De):(De=nm(fe.type,fe.key,fe.props,null,ce.mode,De),De.ref=Mo(ce,se,fe),De.return=ce,De)}function _e(ce,se,fe,De){return se===null||se.tag!==4||se.stateNode.containerInfo!==fe.containerInfo||se.stateNode.implementation!==fe.implementation?(se=Th(fe,ce.mode,De),se.return=ce,se):(se=y(se,fe.children||[]),se.return=ce,se)}function Me(ce,se,fe,De,tt){return se===null||se.tag!==7?(se=Hl(fe,ce.mode,De,tt),se.return=ce,se):(se=y(se,fe),se.return=ce,se)}function Te(ce,se,fe){if(typeof se=="string"&&se!==""||typeof se=="number")return se=Mh(""+se,ce.mode,fe),se.return=ce,se;if(typeof se=="object"&&se!==null){switch(se.$$typeof){case G:return fe=nm(se.type,se.key,se.props,null,ce.mode,fe),fe.ref=Mo(ce,null,se),fe.return=ce,fe;case Q:return se=Th(se,ce.mode,fe),se.return=ce,se;case P:var De=se._init;return Te(ce,De(se._payload),fe)}if(he(se)||O(se))return se=Hl(se,ce.mode,fe,null),se.return=ce,se;$c(ce,se)}return null}function Ae(ce,se,fe,De){var tt=se!==null?se.key:null;if(typeof fe=="string"&&fe!==""||typeof fe=="number")return tt!==null?null:J(ce,se,""+fe,De);if(typeof fe=="object"&&fe!==null){switch(fe.$$typeof){case G:return fe.key===tt?te(ce,se,fe,De):null;case Q:return fe.key===tt?_e(ce,se,fe,De):null;case P:return tt=fe._init,Ae(ce,se,tt(fe._payload),De)}if(he(fe)||O(fe))return tt!==null?null:Me(ce,se,fe,De,null);$c(ce,fe)}return null}function Ye(ce,se,fe,De,tt){if(typeof De=="string"&&De!==""||typeof De=="number")return ce=ce.get(fe)||null,J(se,ce,""+De,tt);if(typeof De=="object"&&De!==null){switch(De.$$typeof){case G:return ce=ce.get(De.key===null?fe:De.key)||null,te(se,ce,De,tt);case Q:return ce=ce.get(De.key===null?fe:De.key)||null,_e(se,ce,De,tt);case P:var ht=De._init;return Ye(ce,se,fe,ht(De._payload),tt)}if(he(De)||O(De))return ce=ce.get(fe)||null,Me(se,ce,De,tt,null);$c(se,De)}return null}function Ze(ce,se,fe,De){for(var tt=null,ht=null,_t=se,bt=se=0,Mr=null;_t!==null&&bt<fe.length;bt++){_t.index>bt?(Mr=_t,_t=null):Mr=_t.sibling;var an=Ae(ce,_t,fe[bt],De);if(an===null){_t===null&&(_t=Mr);break}s&&_t&&an.alternate===null&&o(ce,_t),se=b(an,se,bt),ht===null?tt=an:ht.sibling=an,ht=an,_t=Mr}if(bt===fe.length)return c(ce,_t),jn&&li(ce,bt),tt;if(_t===null){for(;bt<fe.length;bt++)_t=Te(ce,fe[bt],De),_t!==null&&(se=b(_t,se,bt),ht===null?tt=_t:ht.sibling=_t,ht=_t);return jn&&li(ce,bt),tt}for(_t=f(ce,_t);bt<fe.length;bt++)Mr=Ye(_t,ce,bt,fe[bt],De),Mr!==null&&(s&&Mr.alternate!==null&&_t.delete(Mr.key===null?bt:Mr.key),se=b(Mr,se,bt),ht===null?tt=Mr:ht.sibling=Mr,ht=Mr);return s&&_t.forEach(function(qa){return o(ce,qa)}),jn&&li(ce,bt),tt}function Qe(ce,se,fe,De){var tt=O(fe);if(typeof tt!="function")throw Error(n(150));if(fe=tt.call(fe),fe==null)throw Error(n(151));for(var ht=tt=null,_t=se,bt=se=0,Mr=null,an=fe.next();_t!==null&&!an.done;bt++,an=fe.next()){_t.index>bt?(Mr=_t,_t=null):Mr=_t.sibling;var qa=Ae(ce,_t,an.value,De);if(qa===null){_t===null&&(_t=Mr);break}s&&_t&&qa.alternate===null&&o(ce,_t),se=b(qa,se,bt),ht===null?tt=qa:ht.sibling=qa,ht=qa,_t=Mr}if(an.done)return c(ce,_t),jn&&li(ce,bt),tt;if(_t===null){for(;!an.done;bt++,an=fe.next())an=Te(ce,an.value,De),an!==null&&(se=b(an,se,bt),ht===null?tt=an:ht.sibling=an,ht=an);return jn&&li(ce,bt),tt}for(_t=f(ce,_t);!an.done;bt++,an=fe.next())an=Ye(_t,ce,bt,an.value,De),an!==null&&(s&&an.alternate!==null&&_t.delete(an.key===null?bt:an.key),se=b(an,se,bt),ht===null?tt=an:ht.sibling=an,ht=an);return s&&_t.forEach(function(Yx){return o(ce,Yx)}),jn&&li(ce,bt),tt}function Zn(ce,se,fe,De){if(typeof fe=="object"&&fe!==null&&fe.type===Y&&fe.key===null&&(fe=fe.props.children),typeof fe=="object"&&fe!==null){switch(fe.$$typeof){case G:e:{for(var tt=fe.key,ht=se;ht!==null;){if(ht.key===tt){if(tt=fe.type,tt===Y){if(ht.tag===7){c(ce,ht.sibling),se=y(ht,fe.props.children),se.return=ce,ce=se;break e}}else if(ht.elementType===tt||typeof tt=="object"&&tt!==null&&tt.$$typeof===P&&Ec(tt)===ht.type){c(ce,ht.sibling),se=y(ht,fe.props),se.ref=Mo(ce,ht,fe),se.return=ce,ce=se;break e}c(ce,ht);break}else o(ce,ht);ht=ht.sibling}fe.type===Y?(se=Hl(fe.props.children,ce.mode,De,fe.key),se.return=ce,ce=se):(De=nm(fe.type,fe.key,fe.props,null,ce.mode,De),De.ref=Mo(ce,se,fe),De.return=ce,ce=De)}return A(ce);case Q:e:{for(ht=fe.key;se!==null;){if(se.key===ht)if(se.tag===4&&se.stateNode.containerInfo===fe.containerInfo&&se.stateNode.implementation===fe.implementation){c(ce,se.sibling),se=y(se,fe.children||[]),se.return=ce,ce=se;break e}else{c(ce,se);break}else o(ce,se);se=se.sibling}se=Th(fe,ce.mode,De),se.return=ce,ce=se}return A(ce);case P:return ht=fe._init,Zn(ce,se,ht(fe._payload),De)}if(he(fe))return Ze(ce,se,fe,De);if(O(fe))return Qe(ce,se,fe,De);$c(ce,fe)}return typeof fe=="string"&&fe!==""||typeof fe=="number"?(fe=""+fe,se!==null&&se.tag===6?(c(ce,se.sibling),se=y(se,fe),se.return=ce,ce=se):(c(ce,se),se=Mh(fe,ce.mode,De),se.return=ce,ce=se),A(ce)):c(ce,se)}return Zn}var To=kf(!0),Nf=kf(!1),Aa=is(null),Le=null,Tn=null,Ac=null;function Uu(){Ac=Tn=Le=null}function Wu(s){var o=Aa.current;bn(Aa),s._currentValue=o}function Hu(s,o,c){for(;s!==null;){var f=s.alternate;if((s.childLanes&o)!==o?(s.childLanes|=o,f!==null&&(f.childLanes|=o)):f!==null&&(f.childLanes&o)!==o&&(f.childLanes|=o),s===c)break;s=s.return}}function Ro(s,o){Le=s,Ac=Tn=null,s=s.dependencies,s!==null&&s.firstContext!==null&&((s.lanes&o)!==0&&(On=!0),s.firstContext=null)}function as(s){var o=s._currentValue;if(Ac!==s)if(s={context:s,memoizedValue:o,next:null},Tn===null){if(Le===null)throw Error(n(308));Tn=s,Le.dependencies={lanes:0,firstContext:s}}else Tn=Tn.next=s;return o}var Lo=null;function Ma(s){Lo===null?Lo=[s]:Lo.push(s)}function Cr(s,o,c,f){var y=o.interleaved;return y===null?(c.next=c,Ma(o)):(c.next=y.next,y.next=c),o.interleaved=c,Ot(s,f)}function Ot(s,o){s.lanes|=o;var c=s.alternate;for(c!==null&&(c.lanes|=o),c=s,s=s.return;s!==null;)s.childLanes|=o,c=s.alternate,c!==null&&(c.childLanes|=o),c=s,s=s.return;return c.tag===3?c.stateNode:null}var Rn=!1;function pl(s){s.updateQueue={baseState:s.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function qu(s,o){s=s.updateQueue,o.updateQueue===s&&(o.updateQueue={baseState:s.baseState,firstBaseUpdate:s.firstBaseUpdate,lastBaseUpdate:s.lastBaseUpdate,shared:s.shared,effects:s.effects})}function ls(s,o){return{eventTime:s,lane:o,tag:0,payload:null,callback:null,next:null}}function Ri(s,o,c){var f=s.updateQueue;if(f===null)return null;if(f=f.shared,(Yt&2)!==0){var y=f.pending;return y===null?o.next=o:(o.next=y.next,y.next=o),f.pending=o,Ot(s,c)}return y=f.interleaved,y===null?(o.next=o,Ma(f)):(o.next=y.next,y.next=o),f.interleaved=o,Ot(s,c)}function st(s,o,c){if(o=o.updateQueue,o!==null&&(o=o.shared,(c&4194240)!==0)){var f=o.lanes;f&=s.pendingLanes,c|=f,o.lanes=c,Zi(s,c)}}function Cf(s,o){var c=s.updateQueue,f=s.alternate;if(f!==null&&(f=f.updateQueue,c===f)){var y=null,b=null;if(c=c.firstBaseUpdate,c!==null){do{var A={eventTime:c.eventTime,lane:c.lane,tag:c.tag,payload:c.payload,callback:c.callback,next:null};b===null?y=b=A:b=b.next=A,c=c.next}while(c!==null);b===null?y=b=o:b=b.next=o}else y=b=o;c={baseState:f.baseState,firstBaseUpdate:y,lastBaseUpdate:b,shared:f.shared,effects:f.effects},s.updateQueue=c;return}s=c.lastBaseUpdate,s===null?c.firstBaseUpdate=o:s.next=o,c.lastBaseUpdate=o}function Ta(s,o,c,f){var y=s.updateQueue;Rn=!1;var b=y.firstBaseUpdate,A=y.lastBaseUpdate,J=y.shared.pending;if(J!==null){y.shared.pending=null;var te=J,_e=te.next;te.next=null,A===null?b=_e:A.next=_e,A=te;var Me=s.alternate;Me!==null&&(Me=Me.updateQueue,J=Me.lastBaseUpdate,J!==A&&(J===null?Me.firstBaseUpdate=_e:J.next=_e,Me.lastBaseUpdate=te))}if(b!==null){var Te=y.baseState;A=0,Me=_e=te=null,J=b;do{var Ae=J.lane,Ye=J.eventTime;if((f&Ae)===Ae){Me!==null&&(Me=Me.next={eventTime:Ye,lane:0,tag:J.tag,payload:J.payload,callback:J.callback,next:null});e:{var Ze=s,Qe=J;switch(Ae=o,Ye=c,Qe.tag){case 1:if(Ze=Qe.payload,typeof Ze=="function"){Te=Ze.call(Ye,Te,Ae);break e}Te=Ze;break e;case 3:Ze.flags=Ze.flags&-65537|128;case 0:if(Ze=Qe.payload,Ae=typeof Ze=="function"?Ze.call(Ye,Te,Ae):Ze,Ae==null)break e;Te=q({},Te,Ae);break e;case 2:Rn=!0}}J.callback!==null&&J.lane!==0&&(s.flags|=64,Ae=y.effects,Ae===null?y.effects=[J]:Ae.push(J))}else Ye={eventTime:Ye,lane:Ae,tag:J.tag,payload:J.payload,callback:J.callback,next:null},Me===null?(_e=Me=Ye,te=Te):Me=Me.next=Ye,A|=Ae;if(J=J.next,J===null){if(J=y.shared.pending,J===null)break;Ae=J,J=Ae.next,Ae.next=null,y.lastBaseUpdate=Ae,y.shared.pending=null}}while(!0);if(Me===null&&(te=Te),y.baseState=te,y.firstBaseUpdate=_e,y.lastBaseUpdate=Me,o=y.shared.interleaved,o!==null){y=o;do A|=y.lane,y=y.next;while(y!==o)}else b===null&&(y.shared.lanes=0);Pi|=A,s.lanes=A,s.memoizedState=Te}}function $f(s,o,c){if(s=o.effects,o.effects=null,s!==null)for(o=0;o<s.length;o++){var f=s[o],y=f.callback;if(y!==null){if(f.callback=null,f=c,typeof y!="function")throw Error(n(191,y));y.call(f)}}}var yl={},Ws=is(yl),vl=is(yl),wl=is(yl);function Oo(s){if(s===yl)throw Error(n(174));return s}function xl(s,o){switch(un(wl,o),un(vl,s),un(Ws,yl),s=o.nodeType,s){case 9:case 11:o=(o=o.documentElement)?o.namespaceURI:At(null,"");break;default:s=s===8?o.parentNode:o,o=s.namespaceURI||null,s=s.tagName,o=At(o,s)}bn(Ws),un(Ws,o)}function Hs(){bn(Ws),bn(vl),bn(wl)}function Ef(s){Oo(wl.current);var o=Oo(Ws.current),c=At(o,s.type);o!==c&&(un(vl,s),un(Ws,c))}function js(s){vl.current===s&&(bn(Ws),bn(vl))}var Zt=is(0);function bl(s){for(var o=s;o!==null;){if(o.tag===13){var c=o.memoizedState;if(c!==null&&(c=c.dehydrated,c===null||c.data==="$?"||c.data==="$!"))return o}else if(o.tag===19&&o.memoizedProps.revealOrder!==void 0){if((o.flags&128)!==0)return o}else if(o.child!==null){o.child.return=o,o=o.child;continue}if(o===s)break;for(;o.sibling===null;){if(o.return===null||o.return===s)return null;o=o.return}o.sibling.return=o.return,o=o.sibling}return null}var Vu=[];function Gu(){for(var s=0;s<Vu.length;s++)Vu[s]._workInProgressVersionPrimary=null;Vu.length=0}var Mc=D.ReactCurrentDispatcher,Tc=D.ReactCurrentBatchConfig,Li=0,Ln=null,Tt=null,Xn=null,Ra=!1,ir=!1,La=0,jl=0;function or(){throw Error(n(321))}function Po(s,o){if(o===null)return!1;for(var c=0;c<o.length&&c<s.length;c++)if(!Ps(s[c],o[c]))return!1;return!0}function Sl(s,o,c,f,y,b){if(Li=b,Ln=o,o.memoizedState=null,o.updateQueue=null,o.lanes=0,Mc.current=s===null||s.memoizedState===null?Df:zf,s=c(f,y),ir){b=0;do{if(ir=!1,La=0,25<=b)throw Error(n(301));b+=1,Xn=Tt=null,o.updateQueue=null,Mc.current=Ff,s=c(f,y)}while(ir)}if(Mc.current=ui,o=Tt!==null&&Tt.next!==null,Li=0,Xn=Tt=Ln=null,Ra=!1,o)throw Error(n(300));return s}function Ku(){var s=La!==0;return La=0,s}function ci(){var s={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Xn===null?Ln.memoizedState=Xn=s:Xn=Xn.next=s,Xn}function Ss(){if(Tt===null){var s=Ln.alternate;s=s!==null?s.memoizedState:null}else s=Tt.next;var o=Xn===null?Ln.memoizedState:Xn.next;if(o!==null)Xn=o,Tt=s;else{if(s===null)throw Error(n(310));Tt=s,s={memoizedState:Tt.memoizedState,baseState:Tt.baseState,baseQueue:Tt.baseQueue,queue:Tt.queue,next:null},Xn===null?Ln.memoizedState=Xn=s:Xn=Xn.next=s}return Xn}function Io(s,o){return typeof o=="function"?o(s):o}function kl(s){var o=Ss(),c=o.queue;if(c===null)throw Error(n(311));c.lastRenderedReducer=s;var f=Tt,y=f.baseQueue,b=c.pending;if(b!==null){if(y!==null){var A=y.next;y.next=b.next,b.next=A}f.baseQueue=y=b,c.pending=null}if(y!==null){b=y.next,f=f.baseState;var J=A=null,te=null,_e=b;do{var Me=_e.lane;if((Li&Me)===Me)te!==null&&(te=te.next={lane:0,action:_e.action,hasEagerState:_e.hasEagerState,eagerState:_e.eagerState,next:null}),f=_e.hasEagerState?_e.eagerState:s(f,_e.action);else{var Te={lane:Me,action:_e.action,hasEagerState:_e.hasEagerState,eagerState:_e.eagerState,next:null};te===null?(J=te=Te,A=f):te=te.next=Te,Ln.lanes|=Me,Pi|=Me}_e=_e.next}while(_e!==null&&_e!==b);te===null?A=f:te.next=J,Ps(f,o.memoizedState)||(On=!0),o.memoizedState=f,o.baseState=A,o.baseQueue=te,c.lastRenderedState=f}if(s=c.interleaved,s!==null){y=s;do b=y.lane,Ln.lanes|=b,Pi|=b,y=y.next;while(y!==s)}else y===null&&(c.lanes=0);return[o.memoizedState,c.dispatch]}function Yu(s){var o=Ss(),c=o.queue;if(c===null)throw Error(n(311));c.lastRenderedReducer=s;var f=c.dispatch,y=c.pending,b=o.memoizedState;if(y!==null){c.pending=null;var A=y=y.next;do b=s(b,A.action),A=A.next;while(A!==y);Ps(b,o.memoizedState)||(On=!0),o.memoizedState=b,o.baseQueue===null&&(o.baseState=b),c.lastRenderedState=b}return[b,f]}function Rc(){}function Af(s,o){var c=Ln,f=Ss(),y=o(),b=!Ps(f.memoizedState,y);if(b&&(f.memoizedState=y,On=!0),f=f.queue,Zu(Un.bind(null,c,f,s),[s]),f.getSnapshot!==o||b||Xn!==null&&Xn.memoizedState.tag&1){if(c.flags|=2048,Nl(9,Do.bind(null,c,f,y,o),void 0,null),Jn===null)throw Error(n(349));(Li&30)!==0||ks(c,o,y)}return y}function ks(s,o,c){s.flags|=16384,s={getSnapshot:o,value:c},o=Ln.updateQueue,o===null?(o={lastEffect:null,stores:null},Ln.updateQueue=o,o.stores=[s]):(c=o.stores,c===null?o.stores=[s]:c.push(s))}function Do(s,o,c,f){o.value=c,o.getSnapshot=f,Xu(o)&&Ju(s)}function Un(s,o,c){return c(function(){Xu(o)&&Ju(s)})}function Xu(s){var o=s.getSnapshot;s=s.value;try{var c=o();return!Ps(s,c)}catch{return!0}}function Ju(s){var o=Ot(s,1);o!==null&&$s(o,s,1,-1)}function Mf(s){var o=ci();return typeof s=="function"&&(s=s()),o.memoizedState=o.baseState=s,s={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Io,lastRenderedState:s},o.queue=s,s=s.dispatch=Nh.bind(null,Ln,s),[o.memoizedState,s]}function Nl(s,o,c,f){return s={tag:s,create:o,destroy:c,deps:f,next:null},o=Ln.updateQueue,o===null?(o={lastEffect:null,stores:null},Ln.updateQueue=o,o.lastEffect=s.next=s):(c=o.lastEffect,c===null?o.lastEffect=s.next=s:(f=c.next,c.next=s,s.next=f,o.lastEffect=s)),s}function Tf(){return Ss().memoizedState}function Cl(s,o,c,f){var y=ci();Ln.flags|=s,y.memoizedState=Nl(1|o,c,void 0,f===void 0?null:f)}function $l(s,o,c,f){var y=Ss();f=f===void 0?null:f;var b=void 0;if(Tt!==null){var A=Tt.memoizedState;if(b=A.destroy,f!==null&&Po(f,A.deps)){y.memoizedState=Nl(o,c,b,f);return}}Ln.flags|=s,y.memoizedState=Nl(1|o,c,b,f)}function Rf(s,o){return Cl(8390656,8,s,o)}function Zu(s,o){return $l(2048,8,s,o)}function Gt(s,o){return $l(4,2,s,o)}function Sn(s,o){return $l(4,4,s,o)}function Xr(s,o){if(typeof o=="function")return s=s(),o(s),function(){o(null)};if(o!=null)return s=s(),o.current=s,function(){o.current=null}}function Lc(s,o,c){return c=c!=null?c.concat([s]):null,$l(4,4,Xr.bind(null,o,s),c)}function Oa(){}function Qu(s,o){var c=Ss();o=o===void 0?null:o;var f=c.memoizedState;return f!==null&&o!==null&&Po(o,f[1])?f[0]:(c.memoizedState=[s,o],s)}function Lf(s,o){var c=Ss();o=o===void 0?null:o;var f=c.memoizedState;return f!==null&&o!==null&&Po(o,f[1])?f[0]:(s=s(),c.memoizedState=[s,o],s)}function Of(s,o,c){return(Li&21)===0?(s.baseState&&(s.baseState=!1,On=!0),s.memoizedState=c):(Ps(c,o)||(c=rr(),Ln.lanes|=c,Pi|=c,s.baseState=!0),o)}function Pf(s,o){var c=en;en=c!==0&&4>c?c:4,s(!0);var f=Tc.transition;Tc.transition={};try{s(!1),o()}finally{en=c,Tc.transition=f}}function Pa(){return Ss().memoizedState}function kh(s,o,c){var f=Di(s);if(c={lane:f,action:c,hasEagerState:!1,eagerState:null,next:null},If(s))ed(o,c);else if(c=Cr(s,o,c,f),c!==null){var y=Er();$s(c,s,f,y),td(c,o,f)}}function Nh(s,o,c){var f=Di(s),y={lane:f,action:c,hasEagerState:!1,eagerState:null,next:null};if(If(s))ed(o,y);else{var b=s.alternate;if(s.lanes===0&&(b===null||b.lanes===0)&&(b=o.lastRenderedReducer,b!==null))try{var A=o.lastRenderedState,J=b(A,c);if(y.hasEagerState=!0,y.eagerState=J,Ps(J,A)){var te=o.interleaved;te===null?(y.next=y,Ma(o)):(y.next=te.next,te.next=y),o.interleaved=y;return}}catch{}finally{}c=Cr(s,o,y,f),c!==null&&(y=Er(),$s(c,s,f,y),td(c,o,f))}}function If(s){var o=s.alternate;return s===Ln||o!==null&&o===Ln}function ed(s,o){ir=Ra=!0;var c=s.pending;c===null?o.next=o:(o.next=c.next,c.next=o),s.pending=o}function td(s,o,c){if((c&4194240)!==0){var f=o.lanes;f&=s.pendingLanes,c|=f,o.lanes=c,Zi(s,c)}}var ui={readContext:as,useCallback:or,useContext:or,useEffect:or,useImperativeHandle:or,useInsertionEffect:or,useLayoutEffect:or,useMemo:or,useReducer:or,useRef:or,useState:or,useDebugValue:or,useDeferredValue:or,useTransition:or,useMutableSource:or,useSyncExternalStore:or,useId:or,unstable_isNewReconciler:!1},Df={readContext:as,useCallback:function(s,o){return ci().memoizedState=[s,o===void 0?null:o],s},useContext:as,useEffect:Rf,useImperativeHandle:function(s,o,c){return c=c!=null?c.concat([s]):null,Cl(4194308,4,Xr.bind(null,o,s),c)},useLayoutEffect:function(s,o){return Cl(4194308,4,s,o)},useInsertionEffect:function(s,o){return Cl(4,2,s,o)},useMemo:function(s,o){var c=ci();return o=o===void 0?null:o,s=s(),c.memoizedState=[s,o],s},useReducer:function(s,o,c){var f=ci();return o=c!==void 0?c(o):o,f.memoizedState=f.baseState=o,s={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:s,lastRenderedState:o},f.queue=s,s=s.dispatch=kh.bind(null,Ln,s),[f.memoizedState,s]},useRef:function(s){var o=ci();return s={current:s},o.memoizedState=s},useState:Mf,useDebugValue:Oa,useDeferredValue:function(s){return ci().memoizedState=s},useTransition:function(){var s=Mf(!1),o=s[0];return s=Pf.bind(null,s[1]),ci().memoizedState=s,[o,s]},useMutableSource:function(){},useSyncExternalStore:function(s,o,c){var f=Ln,y=ci();if(jn){if(c===void 0)throw Error(n(407));c=c()}else{if(c=o(),Jn===null)throw Error(n(349));(Li&30)!==0||ks(f,o,c)}y.memoizedState=c;var b={value:c,getSnapshot:o};return y.queue=b,Rf(Un.bind(null,f,b,s),[s]),f.flags|=2048,Nl(9,Do.bind(null,f,b,c,o),void 0,null),c},useId:function(){var s=ci(),o=Jn.identifierPrefix;if(jn){var c=Ti,f=Mi;c=(f&~(1<<32-nr(f)-1)).toString(32)+c,o=":"+o+"R"+c,c=La++,0<c&&(o+="H"+c.toString(32)),o+=":"}else c=jl++,o=":"+o+"r"+c.toString(32)+":";return s.memoizedState=o},unstable_isNewReconciler:!1},zf={readContext:as,useCallback:Qu,useContext:as,useEffect:Zu,useImperativeHandle:Lc,useInsertionEffect:Gt,useLayoutEffect:Sn,useMemo:Lf,useReducer:kl,useRef:Tf,useState:function(){return kl(Io)},useDebugValue:Oa,useDeferredValue:function(s){var o=Ss();return Of(o,Tt.memoizedState,s)},useTransition:function(){var s=kl(Io)[0],o=Ss().memoizedState;return[s,o]},useMutableSource:Rc,useSyncExternalStore:Af,useId:Pa,unstable_isNewReconciler:!1},Ff={readContext:as,useCallback:Qu,useContext:as,useEffect:Zu,useImperativeHandle:Lc,useInsertionEffect:Gt,useLayoutEffect:Sn,useMemo:Lf,useReducer:Yu,useRef:Tf,useState:function(){return Yu(Io)},useDebugValue:Oa,useDeferredValue:function(s){var o=Ss();return Tt===null?o.memoizedState=s:Of(o,Tt.memoizedState,s)},useTransition:function(){var s=Yu(Io)[0],o=Ss().memoizedState;return[s,o]},useMutableSource:Rc,useSyncExternalStore:Af,useId:Pa,unstable_isNewReconciler:!1};function Ns(s,o){if(s&&s.defaultProps){o=q({},o),s=s.defaultProps;for(var c in s)o[c]===void 0&&(o[c]=s[c]);return o}return o}function nd(s,o,c,f){o=s.memoizedState,c=c(f,o),c=c==null?o:q({},o,c),s.memoizedState=c,s.lanes===0&&(s.updateQueue.baseState=c)}var Oc={isMounted:function(s){return(s=s._reactInternals)?kt(s)===s:!1},enqueueSetState:function(s,o,c){s=s._reactInternals;var f=Er(),y=Di(s),b=ls(f,y);b.payload=o,c!=null&&(b.callback=c),o=Ri(s,b,y),o!==null&&($s(o,s,y,f),st(o,s,y))},enqueueReplaceState:function(s,o,c){s=s._reactInternals;var f=Er(),y=Di(s),b=ls(f,y);b.tag=1,b.payload=o,c!=null&&(b.callback=c),o=Ri(s,b,y),o!==null&&($s(o,s,y,f),st(o,s,y))},enqueueForceUpdate:function(s,o){s=s._reactInternals;var c=Er(),f=Di(s),y=ls(c,f);y.tag=2,o!=null&&(y.callback=o),o=Ri(s,y,f),o!==null&&($s(o,s,f,c),st(o,s,f))}};function Bf(s,o,c,f,y,b,A){return s=s.stateNode,typeof s.shouldComponentUpdate=="function"?s.shouldComponentUpdate(f,b,A):o.prototype&&o.prototype.isPureReactComponent?!to(c,f)||!to(y,b):!0}function Uf(s,o,c){var f=!1,y=ro,b=o.contextType;return typeof b=="object"&&b!==null?b=as(b):(y=Bn(o)?oi:Fn.current,f=o.contextTypes,b=(f=f!=null)?Sa(s,y):ro),o=new o(c,b),s.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,o.updater=Oc,s.stateNode=o,o._reactInternals=s,f&&(s=s.stateNode,s.__reactInternalMemoizedUnmaskedChildContext=y,s.__reactInternalMemoizedMaskedChildContext=b),o}function Wf(s,o,c,f){s=o.state,typeof o.componentWillReceiveProps=="function"&&o.componentWillReceiveProps(c,f),typeof o.UNSAFE_componentWillReceiveProps=="function"&&o.UNSAFE_componentWillReceiveProps(c,f),o.state!==s&&Oc.enqueueReplaceState(o,o.state,null)}function rd(s,o,c,f){var y=s.stateNode;y.props=c,y.state=s.memoizedState,y.refs={},pl(s);var b=o.contextType;typeof b=="object"&&b!==null?y.context=as(b):(b=Bn(o)?oi:Fn.current,y.context=Sa(s,b)),y.state=s.memoizedState,b=o.getDerivedStateFromProps,typeof b=="function"&&(nd(s,o,b,c),y.state=s.memoizedState),typeof o.getDerivedStateFromProps=="function"||typeof y.getSnapshotBeforeUpdate=="function"||typeof y.UNSAFE_componentWillMount!="function"&&typeof y.componentWillMount!="function"||(o=y.state,typeof y.componentWillMount=="function"&&y.componentWillMount(),typeof y.UNSAFE_componentWillMount=="function"&&y.UNSAFE_componentWillMount(),o!==y.state&&Oc.enqueueReplaceState(y,y.state,null),Ta(s,c,y,f),y.state=s.memoizedState),typeof y.componentDidMount=="function"&&(s.flags|=4194308)}function Ia(s,o){try{var c="",f=o;do c+=de(f),f=f.return;while(f);var y=c}catch(b){y=`
|
|
39
|
+
Error generating stack: `+b.message+`
|
|
40
|
+
`+b.stack}return{value:s,source:o,stack:y,digest:null}}function Pc(s,o,c){return{value:s,source:null,stack:c??null,digest:o??null}}function El(s,o){try{console.error(o.value)}catch(c){setTimeout(function(){throw c})}}var Ch=typeof WeakMap=="function"?WeakMap:Map;function Hf(s,o,c){c=ls(-1,c),c.tag=3,c.payload={element:null};var f=o.value;return c.callback=function(){Uc||(Uc=!0,yd=f),El(s,o)},c}function Al(s,o,c){c=ls(-1,c),c.tag=3;var f=s.type.getDerivedStateFromError;if(typeof f=="function"){var y=o.value;c.payload=function(){return f(y)},c.callback=function(){El(s,o)}}var b=s.stateNode;return b!==null&&typeof b.componentDidCatch=="function"&&(c.callback=function(){El(s,o),typeof f!="function"&&(lo===null?lo=new Set([this]):lo.add(this));var A=o.stack;this.componentDidCatch(o.value,{componentStack:A!==null?A:""})}),c}function qf(s,o,c){var f=s.pingCache;if(f===null){f=s.pingCache=new Ch;var y=new Set;f.set(o,y)}else y=f.get(o),y===void 0&&(y=new Set,f.set(o,y));y.has(c)||(y.add(c),s=Ue.bind(null,s,o,c),o.then(s,s))}function io(s){do{var o;if((o=s.tag===13)&&(o=s.memoizedState,o=o!==null?o.dehydrated!==null:!0),o)return s;s=s.return}while(s!==null);return null}function $r(s,o,c,f,y){return(s.mode&1)===0?(s===o?s.flags|=65536:(s.flags|=128,c.flags|=131072,c.flags&=-52805,c.tag===1&&(c.alternate===null?c.tag=17:(o=ls(-1,1),o.tag=2,Ri(c,o,1))),c.lanes|=1),s):(s.flags|=65536,s.lanes=y,s)}var pr=D.ReactCurrentOwner,On=!1;function Dn(s,o,c,f){o.child=s===null?Nf(o,null,c,f):To(o,s.child,c,f)}function Oi(s,o,c,f,y){c=c.render;var b=o.ref;return Ro(o,y),f=Sl(s,o,c,f,b,y),c=Ku(),s!==null&&!On?(o.updateQueue=s.updateQueue,o.flags&=-2053,s.lanes&=~y,Vs(s,o,y)):(jn&&c&&Eo(o),o.flags|=1,Dn(s,o,f,y),o.child)}function qs(s,o,c,f,y){if(s===null){var b=c.type;return typeof b=="function"&&!Ah(b)&&b.defaultProps===void 0&&c.compare===null&&c.defaultProps===void 0?(o.tag=15,o.type=b,Vf(s,o,b,f,y)):(s=nm(c.type,null,f,o,o.mode,y),s.ref=o.ref,s.return=o,o.child=s)}if(b=s.child,(s.lanes&y)===0){var A=b.memoizedProps;if(c=c.compare,c=c!==null?c:to,c(A,f)&&s.ref===o.ref)return Vs(s,o,y)}return o.flags|=1,s=Ha(b,f),s.ref=o.ref,s.return=o,o.child=s}function Vf(s,o,c,f,y){if(s!==null){var b=s.memoizedProps;if(to(b,f)&&s.ref===o.ref)if(On=!1,o.pendingProps=f=b,(s.lanes&y)!==0)(s.flags&131072)!==0&&(On=!0);else return o.lanes=s.lanes,Vs(s,o,y)}return Tl(s,o,c,f,y)}function Ml(s,o,c){var f=o.pendingProps,y=f.children,b=s!==null?s.memoizedState:null;if(f.mode==="hidden")if((o.mode&1)===0)o.memoizedState={baseLanes:0,cachePool:null,transitions:null},un(Ba,ds),ds|=c;else{if((c&1073741824)===0)return s=b!==null?b.baseLanes|c:c,o.lanes=o.childLanes=1073741824,o.memoizedState={baseLanes:s,cachePool:null,transitions:null},o.updateQueue=null,un(Ba,ds),ds|=s,null;o.memoizedState={baseLanes:0,cachePool:null,transitions:null},f=b!==null?b.baseLanes:c,un(Ba,ds),ds|=f}else b!==null?(f=b.baseLanes|c,o.memoizedState=null):f=c,un(Ba,ds),ds|=f;return Dn(s,o,y,c),o.child}function Gf(s,o){var c=o.ref;(s===null&&c!==null||s!==null&&s.ref!==c)&&(o.flags|=512,o.flags|=2097152)}function Tl(s,o,c,f,y){var b=Bn(c)?oi:Fn.current;return b=Sa(o,b),Ro(o,y),c=Sl(s,o,c,f,b,y),f=Ku(),s!==null&&!On?(o.updateQueue=s.updateQueue,o.flags&=-2053,s.lanes&=~y,Vs(s,o,y)):(jn&&f&&Eo(o),o.flags|=1,Dn(s,o,c,y),o.child)}function Kf(s,o,c,f,y){if(Bn(c)){var b=!0;gl(o)}else b=!1;if(Ro(o,y),o.stateNode===null)Dc(s,o),Uf(o,c,f),rd(o,c,f,y),f=!0;else if(s===null){var A=o.stateNode,J=o.memoizedProps;A.props=J;var te=A.context,_e=c.contextType;typeof _e=="object"&&_e!==null?_e=as(_e):(_e=Bn(c)?oi:Fn.current,_e=Sa(o,_e));var Me=c.getDerivedStateFromProps,Te=typeof Me=="function"||typeof A.getSnapshotBeforeUpdate=="function";Te||typeof A.UNSAFE_componentWillReceiveProps!="function"&&typeof A.componentWillReceiveProps!="function"||(J!==f||te!==_e)&&Wf(o,A,f,_e),Rn=!1;var Ae=o.memoizedState;A.state=Ae,Ta(o,f,A,y),te=o.memoizedState,J!==f||Ae!==te||Kr.current||Rn?(typeof Me=="function"&&(nd(o,c,Me,f),te=o.memoizedState),(J=Rn||Bf(o,c,J,f,Ae,te,_e))?(Te||typeof A.UNSAFE_componentWillMount!="function"&&typeof A.componentWillMount!="function"||(typeof A.componentWillMount=="function"&&A.componentWillMount(),typeof A.UNSAFE_componentWillMount=="function"&&A.UNSAFE_componentWillMount()),typeof A.componentDidMount=="function"&&(o.flags|=4194308)):(typeof A.componentDidMount=="function"&&(o.flags|=4194308),o.memoizedProps=f,o.memoizedState=te),A.props=f,A.state=te,A.context=_e,f=J):(typeof A.componentDidMount=="function"&&(o.flags|=4194308),f=!1)}else{A=o.stateNode,qu(s,o),J=o.memoizedProps,_e=o.type===o.elementType?J:Ns(o.type,J),A.props=_e,Te=o.pendingProps,Ae=A.context,te=c.contextType,typeof te=="object"&&te!==null?te=as(te):(te=Bn(c)?oi:Fn.current,te=Sa(o,te));var Ye=c.getDerivedStateFromProps;(Me=typeof Ye=="function"||typeof A.getSnapshotBeforeUpdate=="function")||typeof A.UNSAFE_componentWillReceiveProps!="function"&&typeof A.componentWillReceiveProps!="function"||(J!==Te||Ae!==te)&&Wf(o,A,f,te),Rn=!1,Ae=o.memoizedState,A.state=Ae,Ta(o,f,A,y);var Ze=o.memoizedState;J!==Te||Ae!==Ze||Kr.current||Rn?(typeof Ye=="function"&&(nd(o,c,Ye,f),Ze=o.memoizedState),(_e=Rn||Bf(o,c,_e,f,Ae,Ze,te)||!1)?(Me||typeof A.UNSAFE_componentWillUpdate!="function"&&typeof A.componentWillUpdate!="function"||(typeof A.componentWillUpdate=="function"&&A.componentWillUpdate(f,Ze,te),typeof A.UNSAFE_componentWillUpdate=="function"&&A.UNSAFE_componentWillUpdate(f,Ze,te)),typeof A.componentDidUpdate=="function"&&(o.flags|=4),typeof A.getSnapshotBeforeUpdate=="function"&&(o.flags|=1024)):(typeof A.componentDidUpdate!="function"||J===s.memoizedProps&&Ae===s.memoizedState||(o.flags|=4),typeof A.getSnapshotBeforeUpdate!="function"||J===s.memoizedProps&&Ae===s.memoizedState||(o.flags|=1024),o.memoizedProps=f,o.memoizedState=Ze),A.props=f,A.state=Ze,A.context=te,f=_e):(typeof A.componentDidUpdate!="function"||J===s.memoizedProps&&Ae===s.memoizedState||(o.flags|=4),typeof A.getSnapshotBeforeUpdate!="function"||J===s.memoizedProps&&Ae===s.memoizedState||(o.flags|=1024),f=!1)}return sd(s,o,c,f,b,y)}function sd(s,o,c,f,y,b){Gf(s,o);var A=(o.flags&128)!==0;if(!f&&!A)return y&&jc(o,c,!1),Vs(s,o,b);f=o.stateNode,pr.current=o;var J=A&&typeof c.getDerivedStateFromError!="function"?null:f.render();return o.flags|=1,s!==null&&A?(o.child=To(o,s.child,null,b),o.child=To(o,null,J,b)):Dn(s,o,J,b),o.memoizedState=f.state,y&&jc(o,c,!0),o.child}function id(s){var o=s.stateNode;o.pendingContext?ka(s,o.pendingContext,o.pendingContext!==o.context):o.context&&ka(s,o.context,!1),xl(s,o.containerInfo)}function oo(s,o,c,f,y){return Ea(),Bu(y),o.flags|=256,Dn(s,o,c,f),o.child}var zo={dehydrated:null,treeContext:null,retryLane:0};function Ic(s){return{baseLanes:s,cachePool:null,transitions:null}}function od(s,o,c){var f=o.pendingProps,y=Zt.current,b=!1,A=(o.flags&128)!==0,J;if((J=A)||(J=s!==null&&s.memoizedState===null?!1:(y&2)!==0),J?(b=!0,o.flags&=-129):(s===null||s.memoizedState!==null)&&(y|=1),un(Zt,y&1),s===null)return zu(o),s=o.memoizedState,s!==null&&(s=s.dehydrated,s!==null)?((o.mode&1)===0?o.lanes=1:s.data==="$!"?o.lanes=8:o.lanes=1073741824,null):(A=f.children,s=f.fallback,b?(f=o.mode,b=o.child,A={mode:"hidden",children:A},(f&1)===0&&b!==null?(b.childLanes=0,b.pendingProps=A):b=rm(A,f,0,null),s=Hl(s,f,c,null),b.return=o,s.return=o,b.sibling=s,o.child=b,o.child.memoizedState=Ic(c),o.memoizedState=zo,s):ad(o,A));if(y=s.memoizedState,y!==null&&(J=y.dehydrated,J!==null))return Da(s,o,A,f,J,y,c);if(b){b=f.fallback,A=o.mode,y=s.child,J=y.sibling;var te={mode:"hidden",children:f.children};return(A&1)===0&&o.child!==y?(f=o.child,f.childLanes=0,f.pendingProps=te,o.deletions=null):(f=Ha(y,te),f.subtreeFlags=y.subtreeFlags&14680064),J!==null?b=Ha(J,b):(b=Hl(b,A,c,null),b.flags|=2),b.return=o,f.return=o,f.sibling=b,o.child=f,f=b,b=o.child,A=s.child.memoizedState,A=A===null?Ic(c):{baseLanes:A.baseLanes|c,cachePool:null,transitions:A.transitions},b.memoizedState=A,b.childLanes=s.childLanes&~c,o.memoizedState=zo,f}return b=s.child,s=b.sibling,f=Ha(b,{mode:"visible",children:f.children}),(o.mode&1)===0&&(f.lanes=c),f.return=o,f.sibling=null,s!==null&&(c=o.deletions,c===null?(o.deletions=[s],o.flags|=16):c.push(s)),o.child=f,o.memoizedState=null,f}function ad(s,o){return o=rm({mode:"visible",children:o},s.mode,0,null),o.return=s,s.child=o}function Rl(s,o,c,f){return f!==null&&Bu(f),To(o,s.child,null,c),s=ad(o,o.pendingProps.children),s.flags|=2,o.memoizedState=null,s}function Da(s,o,c,f,y,b,A){if(c)return o.flags&256?(o.flags&=-257,f=Pc(Error(n(422))),Rl(s,o,A,f)):o.memoizedState!==null?(o.child=s.child,o.flags|=128,null):(b=f.fallback,y=o.mode,f=rm({mode:"visible",children:f.children},y,0,null),b=Hl(b,y,A,null),b.flags|=2,f.return=o,b.return=o,f.sibling=b,o.child=f,(o.mode&1)!==0&&To(o,s.child,null,A),o.child.memoizedState=Ic(A),o.memoizedState=zo,b);if((o.mode&1)===0)return Rl(s,o,A,null);if(y.data==="$!"){if(f=y.nextSibling&&y.nextSibling.dataset,f)var J=f.dgst;return f=J,b=Error(n(419)),f=Pc(b,f,void 0),Rl(s,o,A,f)}if(J=(A&s.childLanes)!==0,On||J){if(f=Jn,f!==null){switch(A&-A){case 4:y=2;break;case 16:y=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:y=32;break;case 536870912:y=268435456;break;default:y=0}y=(y&(f.suspendedLanes|A))!==0?0:y,y!==0&&y!==b.retryLane&&(b.retryLane=y,Ot(s,y),$s(f,s,y,-1))}return Z(),f=Pc(Error(n(421))),Rl(s,o,A,f)}return y.data==="$?"?(o.flags|=128,o.child=s.child,o=wn.bind(null,s),y._reactRetry=o,null):(s=b.treeContext,Yr=$i(y.nextSibling),gr=o,jn=!0,Us=null,s!==null&&(vn[Or++]=Mi,vn[Or++]=Ti,vn[Or++]=Ai,Mi=s.id,Ti=s.overflow,Ai=o),o=ad(o,f.children),o.flags|=4096,o)}function Yf(s,o,c){s.lanes|=o;var f=s.alternate;f!==null&&(f.lanes|=o),Hu(s.return,o,c)}function za(s,o,c,f,y){var b=s.memoizedState;b===null?s.memoizedState={isBackwards:o,rendering:null,renderingStartTime:0,last:f,tail:c,tailMode:y}:(b.isBackwards=o,b.rendering=null,b.renderingStartTime=0,b.last=f,b.tail=c,b.tailMode=y)}function ld(s,o,c){var f=o.pendingProps,y=f.revealOrder,b=f.tail;if(Dn(s,o,f.children,c),f=Zt.current,(f&2)!==0)f=f&1|2,o.flags|=128;else{if(s!==null&&(s.flags&128)!==0)e:for(s=o.child;s!==null;){if(s.tag===13)s.memoizedState!==null&&Yf(s,c,o);else if(s.tag===19)Yf(s,c,o);else if(s.child!==null){s.child.return=s,s=s.child;continue}if(s===o)break e;for(;s.sibling===null;){if(s.return===null||s.return===o)break e;s=s.return}s.sibling.return=s.return,s=s.sibling}f&=1}if(un(Zt,f),(o.mode&1)===0)o.memoizedState=null;else switch(y){case"forwards":for(c=o.child,y=null;c!==null;)s=c.alternate,s!==null&&bl(s)===null&&(y=c),c=c.sibling;c=y,c===null?(y=o.child,o.child=null):(y=c.sibling,c.sibling=null),za(o,!1,y,c,b);break;case"backwards":for(c=null,y=o.child,o.child=null;y!==null;){if(s=y.alternate,s!==null&&bl(s)===null){o.child=y;break}s=y.sibling,y.sibling=c,c=y,y=s}za(o,!0,c,null,b);break;case"together":za(o,!1,null,null,void 0);break;default:o.memoizedState=null}return o.child}function Dc(s,o){(o.mode&1)===0&&s!==null&&(s.alternate=null,o.alternate=null,o.flags|=2)}function Vs(s,o,c){if(s!==null&&(o.dependencies=s.dependencies),Pi|=o.lanes,(c&o.childLanes)===0)return null;if(s!==null&&o.child!==s.child)throw Error(n(153));if(o.child!==null){for(s=o.child,c=Ha(s,s.pendingProps),o.child=c,c.return=o;s.sibling!==null;)s=s.sibling,c=c.sibling=Ha(s,s.pendingProps),c.return=o;c.sibling=null}return o.child}function $h(s,o,c){switch(o.tag){case 3:id(o),Ea();break;case 5:Ef(o);break;case 1:Bn(o.type)&&gl(o);break;case 4:xl(o,o.stateNode.containerInfo);break;case 10:var f=o.type._context,y=o.memoizedProps.value;un(Aa,f._currentValue),f._currentValue=y;break;case 13:if(f=o.memoizedState,f!==null)return f.dehydrated!==null?(un(Zt,Zt.current&1),o.flags|=128,null):(c&o.child.childLanes)!==0?od(s,o,c):(un(Zt,Zt.current&1),s=Vs(s,o,c),s!==null?s.sibling:null);un(Zt,Zt.current&1);break;case 19:if(f=(c&o.childLanes)!==0,(s.flags&128)!==0){if(f)return ld(s,o,c);o.flags|=128}if(y=o.memoizedState,y!==null&&(y.rendering=null,y.tail=null,y.lastEffect=null),un(Zt,Zt.current),f)break;return null;case 22:case 23:return o.lanes=0,Ml(s,o,c)}return Vs(s,o,c)}var Xf,cd,Jr,Fo;Xf=function(s,o){for(var c=o.child;c!==null;){if(c.tag===5||c.tag===6)s.appendChild(c.stateNode);else if(c.tag!==4&&c.child!==null){c.child.return=c,c=c.child;continue}if(c===o)break;for(;c.sibling===null;){if(c.return===null||c.return===o)return;c=c.return}c.sibling.return=c.return,c=c.sibling}},cd=function(){},Jr=function(s,o,c,f){var y=s.memoizedProps;if(y!==f){s=o.stateNode,Oo(Ws.current);var b=null;switch(c){case"input":y=gt(s,y),f=gt(s,f),b=[];break;case"select":y=q({},y,{value:void 0}),f=q({},f,{value:void 0}),b=[];break;case"textarea":y=Ve(s,y),f=Ve(s,f),b=[];break;default:typeof y.onClick!="function"&&typeof f.onClick=="function"&&(s.onclick=vc)}mn(c,f);var A;c=null;for(_e in y)if(!f.hasOwnProperty(_e)&&y.hasOwnProperty(_e)&&y[_e]!=null)if(_e==="style"){var J=y[_e];for(A in J)J.hasOwnProperty(A)&&(c||(c={}),c[A]="")}else _e!=="dangerouslySetInnerHTML"&&_e!=="children"&&_e!=="suppressContentEditableWarning"&&_e!=="suppressHydrationWarning"&&_e!=="autoFocus"&&(a.hasOwnProperty(_e)?b||(b=[]):(b=b||[]).push(_e,null));for(_e in f){var te=f[_e];if(J=y!=null?y[_e]:void 0,f.hasOwnProperty(_e)&&te!==J&&(te!=null||J!=null))if(_e==="style")if(J){for(A in J)!J.hasOwnProperty(A)||te&&te.hasOwnProperty(A)||(c||(c={}),c[A]="");for(A in te)te.hasOwnProperty(A)&&J[A]!==te[A]&&(c||(c={}),c[A]=te[A])}else c||(b||(b=[]),b.push(_e,c)),c=te;else _e==="dangerouslySetInnerHTML"?(te=te?te.__html:void 0,J=J?J.__html:void 0,te!=null&&J!==te&&(b=b||[]).push(_e,te)):_e==="children"?typeof te!="string"&&typeof te!="number"||(b=b||[]).push(_e,""+te):_e!=="suppressContentEditableWarning"&&_e!=="suppressHydrationWarning"&&(a.hasOwnProperty(_e)?(te!=null&&_e==="onScroll"&&on("scroll",s),b||J===te||(b=[])):(b=b||[]).push(_e,te))}c&&(b=b||[]).push("style",c);var _e=b;(o.updateQueue=_e)&&(o.flags|=4)}},Fo=function(s,o,c,f){c!==f&&(o.flags|=4)};function Ll(s,o){if(!jn)switch(s.tailMode){case"hidden":o=s.tail;for(var c=null;o!==null;)o.alternate!==null&&(c=o),o=o.sibling;c===null?s.tail=null:c.sibling=null;break;case"collapsed":c=s.tail;for(var f=null;c!==null;)c.alternate!==null&&(f=c),c=c.sibling;f===null?o||s.tail===null?s.tail=null:s.tail.sibling=null:f.sibling=null}}function yr(s){var o=s.alternate!==null&&s.alternate.child===s.child,c=0,f=0;if(o)for(var y=s.child;y!==null;)c|=y.lanes|y.childLanes,f|=y.subtreeFlags&14680064,f|=y.flags&14680064,y.return=s,y=y.sibling;else for(y=s.child;y!==null;)c|=y.lanes|y.childLanes,f|=y.subtreeFlags,f|=y.flags,y.return=s,y=y.sibling;return s.subtreeFlags|=f,s.childLanes=c,o}function cs(s,o,c){var f=o.pendingProps;switch(Nc(o),o.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return yr(o),null;case 1:return Bn(o.type)&&_l(),yr(o),null;case 3:return f=o.stateNode,Hs(),bn(Kr),bn(Fn),Gu(),f.pendingContext&&(f.context=f.pendingContext,f.pendingContext=null),(s===null||s.child===null)&&(Ao(o)?o.flags|=4:s===null||s.memoizedState.isDehydrated&&(o.flags&256)===0||(o.flags|=1024,Us!==null&&(Vc(Us),Us=null))),cd(s,o),yr(o),null;case 5:js(o);var y=Oo(wl.current);if(c=o.type,s!==null&&o.stateNode!=null)Jr(s,o,c,f,y),s.ref!==o.ref&&(o.flags|=512,o.flags|=2097152);else{if(!f){if(o.stateNode===null)throw Error(n(166));return yr(o),null}if(s=Oo(Ws.current),Ao(o)){f=o.stateNode,c=o.type;var b=o.memoizedProps;switch(f[si]=o,f[xa]=b,s=(o.mode&1)!==0,c){case"dialog":on("cancel",f),on("close",f);break;case"iframe":case"object":case"embed":on("load",f);break;case"video":case"audio":for(y=0;y<ki.length;y++)on(ki[y],f);break;case"source":on("error",f);break;case"img":case"image":case"link":on("error",f),on("load",f);break;case"details":on("toggle",f);break;case"input":yt(f,b),on("invalid",f);break;case"select":f._wrapperState={wasMultiple:!!b.multiple},on("invalid",f);break;case"textarea":Rt(f,b),on("invalid",f)}mn(c,b),y=null;for(var A in b)if(b.hasOwnProperty(A)){var J=b[A];A==="children"?typeof J=="string"?f.textContent!==J&&(b.suppressHydrationWarning!==!0&&va(f.textContent,J,s),y=["children",J]):typeof J=="number"&&f.textContent!==""+J&&(b.suppressHydrationWarning!==!0&&va(f.textContent,J,s),y=["children",""+J]):a.hasOwnProperty(A)&&J!=null&&A==="onScroll"&&on("scroll",f)}switch(c){case"input":Ke(f),Re(f,b,!0);break;case"textarea":Ke(f),fn(f);break;case"select":case"option":break;default:typeof b.onClick=="function"&&(f.onclick=vc)}f=y,o.updateQueue=f,f!==null&&(o.flags|=4)}else{A=y.nodeType===9?y:y.ownerDocument,s==="http://www.w3.org/1999/xhtml"&&(s=Ft(c)),s==="http://www.w3.org/1999/xhtml"?c==="script"?(s=A.createElement("div"),s.innerHTML="<script><\/script>",s=s.removeChild(s.firstChild)):typeof f.is=="string"?s=A.createElement(c,{is:f.is}):(s=A.createElement(c),c==="select"&&(A=s,f.multiple?A.multiple=!0:f.size&&(A.size=f.size))):s=A.createElementNS(s,c),s[si]=o,s[xa]=f,Xf(s,o,!1,!1),o.stateNode=s;e:{switch(A=br(c,f),c){case"dialog":on("cancel",s),on("close",s),y=f;break;case"iframe":case"object":case"embed":on("load",s),y=f;break;case"video":case"audio":for(y=0;y<ki.length;y++)on(ki[y],s);y=f;break;case"source":on("error",s),y=f;break;case"img":case"image":case"link":on("error",s),on("load",s),y=f;break;case"details":on("toggle",s),y=f;break;case"input":yt(s,f),y=gt(s,f),on("invalid",s);break;case"option":y=f;break;case"select":s._wrapperState={wasMultiple:!!f.multiple},y=q({},f,{value:void 0}),on("invalid",s);break;case"textarea":Rt(s,f),y=Ve(s,f),on("invalid",s);break;default:y=f}mn(c,y),J=y;for(b in J)if(J.hasOwnProperty(b)){var te=J[b];b==="style"?yn(s,te):b==="dangerouslySetInnerHTML"?(te=te?te.__html:void 0,te!=null&&zn(s,te)):b==="children"?typeof te=="string"?(c!=="textarea"||te!=="")&&$t(s,te):typeof te=="number"&&$t(s,""+te):b!=="suppressContentEditableWarning"&&b!=="suppressHydrationWarning"&&b!=="autoFocus"&&(a.hasOwnProperty(b)?te!=null&&b==="onScroll"&&on("scroll",s):te!=null&&H(s,b,te,A))}switch(c){case"input":Ke(s),Re(s,f,!1);break;case"textarea":Ke(s),fn(s);break;case"option":f.value!=null&&s.setAttribute("value",""+Ee(f.value));break;case"select":s.multiple=!!f.multiple,b=f.value,b!=null?Pe(s,!!f.multiple,b,!1):f.defaultValue!=null&&Pe(s,!!f.multiple,f.defaultValue,!0);break;default:typeof y.onClick=="function"&&(s.onclick=vc)}switch(c){case"button":case"input":case"select":case"textarea":f=!!f.autoFocus;break e;case"img":f=!0;break e;default:f=!1}}f&&(o.flags|=4)}o.ref!==null&&(o.flags|=512,o.flags|=2097152)}return yr(o),null;case 6:if(s&&o.stateNode!=null)Fo(s,o,s.memoizedProps,f);else{if(typeof f!="string"&&o.stateNode===null)throw Error(n(166));if(c=Oo(wl.current),Oo(Ws.current),Ao(o)){if(f=o.stateNode,c=o.memoizedProps,f[si]=o,(b=f.nodeValue!==c)&&(s=gr,s!==null))switch(s.tag){case 3:va(f.nodeValue,c,(s.mode&1)!==0);break;case 5:s.memoizedProps.suppressHydrationWarning!==!0&&va(f.nodeValue,c,(s.mode&1)!==0)}b&&(o.flags|=4)}else f=(c.nodeType===9?c:c.ownerDocument).createTextNode(f),f[si]=o,o.stateNode=f}return yr(o),null;case 13:if(bn(Zt),f=o.memoizedState,s===null||s.memoizedState!==null&&s.memoizedState.dehydrated!==null){if(jn&&Yr!==null&&(o.mode&1)!==0&&(o.flags&128)===0)Sf(),Ea(),o.flags|=98560,b=!1;else if(b=Ao(o),f!==null&&f.dehydrated!==null){if(s===null){if(!b)throw Error(n(318));if(b=o.memoizedState,b=b!==null?b.dehydrated:null,!b)throw Error(n(317));b[si]=o}else Ea(),(o.flags&128)===0&&(o.memoizedState=null),o.flags|=4;yr(o),b=!1}else Us!==null&&(Vc(Us),Us=null),b=!0;if(!b)return o.flags&65536?o:null}return(o.flags&128)!==0?(o.lanes=c,o):(f=f!==null,f!==(s!==null&&s.memoizedState!==null)&&f&&(o.child.flags|=8192,(o.mode&1)!==0&&(s===null||(Zt.current&1)!==0?kn===0&&(kn=3):Z())),o.updateQueue!==null&&(o.flags|=4),yr(o),null);case 4:return Hs(),cd(s,o),s===null&&Is(o.stateNode.containerInfo),yr(o),null;case 10:return Wu(o.type._context),yr(o),null;case 17:return Bn(o.type)&&_l(),yr(o),null;case 19:if(bn(Zt),b=o.memoizedState,b===null)return yr(o),null;if(f=(o.flags&128)!==0,A=b.rendering,A===null)if(f)Ll(b,!1);else{if(kn!==0||s!==null&&(s.flags&128)!==0)for(s=o.child;s!==null;){if(A=bl(s),A!==null){for(o.flags|=128,Ll(b,!1),f=A.updateQueue,f!==null&&(o.updateQueue=f,o.flags|=4),o.subtreeFlags=0,f=c,c=o.child;c!==null;)b=c,s=f,b.flags&=14680066,A=b.alternate,A===null?(b.childLanes=0,b.lanes=s,b.child=null,b.subtreeFlags=0,b.memoizedProps=null,b.memoizedState=null,b.updateQueue=null,b.dependencies=null,b.stateNode=null):(b.childLanes=A.childLanes,b.lanes=A.lanes,b.child=A.child,b.subtreeFlags=0,b.deletions=null,b.memoizedProps=A.memoizedProps,b.memoizedState=A.memoizedState,b.updateQueue=A.updateQueue,b.type=A.type,s=A.dependencies,b.dependencies=s===null?null:{lanes:s.lanes,firstContext:s.firstContext}),c=c.sibling;return un(Zt,Zt.current&1|2),o.child}s=s.sibling}b.tail!==null&&cn()>Ua&&(o.flags|=128,f=!0,Ll(b,!1),o.lanes=4194304)}else{if(!f)if(s=bl(A),s!==null){if(o.flags|=128,f=!0,c=s.updateQueue,c!==null&&(o.updateQueue=c,o.flags|=4),Ll(b,!0),b.tail===null&&b.tailMode==="hidden"&&!A.alternate&&!jn)return yr(o),null}else 2*cn()-b.renderingStartTime>Ua&&c!==1073741824&&(o.flags|=128,f=!0,Ll(b,!1),o.lanes=4194304);b.isBackwards?(A.sibling=o.child,o.child=A):(c=b.last,c!==null?c.sibling=A:o.child=A,b.last=A)}return b.tail!==null?(o=b.tail,b.rendering=o,b.tail=o.sibling,b.renderingStartTime=cn(),o.sibling=null,c=Zt.current,un(Zt,f?c&1|2:c&1),o):(yr(o),null);case 22:case 23:return M(),f=o.memoizedState!==null,s!==null&&s.memoizedState!==null!==f&&(o.flags|=8192),f&&(o.mode&1)!==0?(ds&1073741824)!==0&&(yr(o),o.subtreeFlags&6&&(o.flags|=8192)):yr(o),null;case 24:return null;case 25:return null}throw Error(n(156,o.tag))}function ud(s,o){switch(Nc(o),o.tag){case 1:return Bn(o.type)&&_l(),s=o.flags,s&65536?(o.flags=s&-65537|128,o):null;case 3:return Hs(),bn(Kr),bn(Fn),Gu(),s=o.flags,(s&65536)!==0&&(s&128)===0?(o.flags=s&-65537|128,o):null;case 5:return js(o),null;case 13:if(bn(Zt),s=o.memoizedState,s!==null&&s.dehydrated!==null){if(o.alternate===null)throw Error(n(340));Ea()}return s=o.flags,s&65536?(o.flags=s&-65537|128,o):null;case 19:return bn(Zt),null;case 4:return Hs(),null;case 10:return Wu(o.type._context),null;case 22:case 23:return M(),null;case 24:return null;default:return null}}var Ol=!1,vr=!1,Eh=typeof WeakSet=="function"?WeakSet:Set,Xe=null;function ar(s,o){var c=s.ref;if(c!==null)if(typeof c=="function")try{c(null)}catch(f){Je(s,o,f)}else c.current=null}function Bo(s,o,c){try{c()}catch(f){Je(s,o,f)}}var dd=!1;function Jf(s,o){if(wa=ho,s=ca(),ua(s)){if("selectionStart"in s)var c={start:s.selectionStart,end:s.selectionEnd};else e:{c=(c=s.ownerDocument)&&c.defaultView||window;var f=c.getSelection&&c.getSelection();if(f&&f.rangeCount!==0){c=f.anchorNode;var y=f.anchorOffset,b=f.focusNode;f=f.focusOffset;try{c.nodeType,b.nodeType}catch{c=null;break e}var A=0,J=-1,te=-1,_e=0,Me=0,Te=s,Ae=null;t:for(;;){for(var Ye;Te!==c||y!==0&&Te.nodeType!==3||(J=A+y),Te!==b||f!==0&&Te.nodeType!==3||(te=A+f),Te.nodeType===3&&(A+=Te.nodeValue.length),(Ye=Te.firstChild)!==null;)Ae=Te,Te=Ye;for(;;){if(Te===s)break t;if(Ae===c&&++_e===y&&(J=A),Ae===b&&++Me===f&&(te=A),(Ye=Te.nextSibling)!==null)break;Te=Ae,Ae=Te.parentNode}Te=Ye}c=J===-1||te===-1?null:{start:J,end:te}}else c=null}c=c||{start:0,end:0}}else c=null;for(wc={focusedElem:s,selectionRange:c},ho=!1,Xe=o;Xe!==null;)if(o=Xe,s=o.child,(o.subtreeFlags&1028)!==0&&s!==null)s.return=o,Xe=s;else for(;Xe!==null;){o=Xe;try{var Ze=o.alternate;if((o.flags&1024)!==0)switch(o.tag){case 0:case 11:case 15:break;case 1:if(Ze!==null){var Qe=Ze.memoizedProps,Zn=Ze.memoizedState,ce=o.stateNode,se=ce.getSnapshotBeforeUpdate(o.elementType===o.type?Qe:Ns(o.type,Qe),Zn);ce.__reactInternalSnapshotBeforeUpdate=se}break;case 3:var fe=o.stateNode.containerInfo;fe.nodeType===1?fe.textContent="":fe.nodeType===9&&fe.documentElement&&fe.removeChild(fe.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(n(163))}}catch(De){Je(o,o.return,De)}if(s=o.sibling,s!==null){s.return=o.return,Xe=s;break}Xe=o.return}return Ze=dd,dd=!1,Ze}function Pl(s,o,c){var f=o.updateQueue;if(f=f!==null?f.lastEffect:null,f!==null){var y=f=f.next;do{if((y.tag&s)===s){var b=y.destroy;y.destroy=void 0,b!==void 0&&Bo(o,c,b)}y=y.next}while(y!==f)}}function Il(s,o){if(o=o.updateQueue,o=o!==null?o.lastEffect:null,o!==null){var c=o=o.next;do{if((c.tag&s)===s){var f=c.create;c.destroy=f()}c=c.next}while(c!==o)}}function Gs(s){var o=s.ref;if(o!==null){var c=s.stateNode;switch(s.tag){case 5:s=c;break;default:s=c}typeof o=="function"?o(s):o.current=s}}function Zf(s){var o=s.alternate;o!==null&&(s.alternate=null,Zf(o)),s.child=null,s.deletions=null,s.sibling=null,s.tag===5&&(o=s.stateNode,o!==null&&(delete o[si],delete o[xa],delete o[bc],delete o[bh],delete o[bf])),s.stateNode=null,s.return=null,s.dependencies=null,s.memoizedProps=null,s.memoizedState=null,s.pendingProps=null,s.stateNode=null,s.updateQueue=null}function Qf(s){return s.tag===5||s.tag===3||s.tag===4}function fd(s){e:for(;;){for(;s.sibling===null;){if(s.return===null||Qf(s.return))return null;s=s.return}for(s.sibling.return=s.return,s=s.sibling;s.tag!==5&&s.tag!==6&&s.tag!==18;){if(s.flags&2||s.child===null||s.tag===4)continue e;s.child.return=s,s=s.child}if(!(s.flags&2))return s.stateNode}}function Dl(s,o,c){var f=s.tag;if(f===5||f===6)s=s.stateNode,o?c.nodeType===8?c.parentNode.insertBefore(s,o):c.insertBefore(s,o):(c.nodeType===8?(o=c.parentNode,o.insertBefore(s,c)):(o=c,o.appendChild(s)),c=c._reactRootContainer,c!=null||o.onclick!==null||(o.onclick=vc));else if(f!==4&&(s=s.child,s!==null))for(Dl(s,o,c),s=s.sibling;s!==null;)Dl(s,o,c),s=s.sibling}function Cs(s,o,c){var f=s.tag;if(f===5||f===6)s=s.stateNode,o?c.insertBefore(s,o):c.appendChild(s);else if(f!==4&&(s=s.child,s!==null))for(Cs(s,o,c),s=s.sibling;s!==null;)Cs(s,o,c),s=s.sibling}var Gn=null,Ks=!1;function Pr(s,o,c){for(c=c.child;c!==null;)zc(s,o,c),c=c.sibling}function zc(s,o,c){if(ur&&typeof ur.onCommitFiberUnmount=="function")try{ur.onCommitFiberUnmount(Qt,c)}catch{}switch(c.tag){case 5:vr||ar(c,o);case 6:var f=Gn,y=Ks;Gn=null,Pr(s,o,c),Gn=f,Ks=y,Gn!==null&&(Ks?(s=Gn,c=c.stateNode,s.nodeType===8?s.parentNode.removeChild(c):s.removeChild(c)):Gn.removeChild(c.stateNode));break;case 18:Gn!==null&&(Ks?(s=Gn,c=c.stateNode,s.nodeType===8?Pu(s.parentNode,c):s.nodeType===1&&Pu(s,c),Qi(s)):Pu(Gn,c.stateNode));break;case 4:f=Gn,y=Ks,Gn=c.stateNode.containerInfo,Ks=!0,Pr(s,o,c),Gn=f,Ks=y;break;case 0:case 11:case 14:case 15:if(!vr&&(f=c.updateQueue,f!==null&&(f=f.lastEffect,f!==null))){y=f=f.next;do{var b=y,A=b.destroy;b=b.tag,A!==void 0&&((b&2)!==0||(b&4)!==0)&&Bo(c,o,A),y=y.next}while(y!==f)}Pr(s,o,c);break;case 1:if(!vr&&(ar(c,o),f=c.stateNode,typeof f.componentWillUnmount=="function"))try{f.props=c.memoizedProps,f.state=c.memoizedState,f.componentWillUnmount()}catch(J){Je(c,o,J)}Pr(s,o,c);break;case 21:Pr(s,o,c);break;case 22:c.mode&1?(vr=(f=vr)||c.memoizedState!==null,Pr(s,o,c),vr=f):Pr(s,o,c);break;default:Pr(s,o,c)}}function Fc(s){var o=s.updateQueue;if(o!==null){s.updateQueue=null;var c=s.stateNode;c===null&&(c=s.stateNode=new Eh),o.forEach(function(f){var y=En.bind(null,s,f);c.has(f)||(c.add(f),f.then(y,y))})}}function dn(s,o){var c=o.deletions;if(c!==null)for(var f=0;f<c.length;f++){var y=c[f];try{var b=s,A=o,J=A;e:for(;J!==null;){switch(J.tag){case 5:Gn=J.stateNode,Ks=!1;break e;case 3:Gn=J.stateNode.containerInfo,Ks=!0;break e;case 4:Gn=J.stateNode.containerInfo,Ks=!0;break e}J=J.return}if(Gn===null)throw Error(n(160));zc(b,A,y),Gn=null,Ks=!1;var te=y.alternate;te!==null&&(te.return=null),y.return=null}catch(_e){Je(y,o,_e)}}if(o.subtreeFlags&12854)for(o=o.child;o!==null;)Uo(o,s),o=o.sibling}function Uo(s,o){var c=s.alternate,f=s.flags;switch(s.tag){case 0:case 11:case 14:case 15:if(dn(o,s),di(s),f&4){try{Pl(3,s,s.return),Il(3,s)}catch(Qe){Je(s,s.return,Qe)}try{Pl(5,s,s.return)}catch(Qe){Je(s,s.return,Qe)}}break;case 1:dn(o,s),di(s),f&512&&c!==null&&ar(c,c.return);break;case 5:if(dn(o,s),di(s),f&512&&c!==null&&ar(c,c.return),s.flags&32){var y=s.stateNode;try{$t(y,"")}catch(Qe){Je(s,s.return,Qe)}}if(f&4&&(y=s.stateNode,y!=null)){var b=s.memoizedProps,A=c!==null?c.memoizedProps:b,J=s.type,te=s.updateQueue;if(s.updateQueue=null,te!==null)try{J==="input"&&b.type==="radio"&&b.name!=null&&nt(y,b),br(J,A);var _e=br(J,b);for(A=0;A<te.length;A+=2){var Me=te[A],Te=te[A+1];Me==="style"?yn(y,Te):Me==="dangerouslySetInnerHTML"?zn(y,Te):Me==="children"?$t(y,Te):H(y,Me,Te,_e)}switch(J){case"input":$e(y,b);break;case"textarea":Xt(y,b);break;case"select":var Ae=y._wrapperState.wasMultiple;y._wrapperState.wasMultiple=!!b.multiple;var Ye=b.value;Ye!=null?Pe(y,!!b.multiple,Ye,!1):Ae!==!!b.multiple&&(b.defaultValue!=null?Pe(y,!!b.multiple,b.defaultValue,!0):Pe(y,!!b.multiple,b.multiple?[]:"",!1))}y[xa]=b}catch(Qe){Je(s,s.return,Qe)}}break;case 6:if(dn(o,s),di(s),f&4){if(s.stateNode===null)throw Error(n(162));y=s.stateNode,b=s.memoizedProps;try{y.nodeValue=b}catch(Qe){Je(s,s.return,Qe)}}break;case 3:if(dn(o,s),di(s),f&4&&c!==null&&c.memoizedState.isDehydrated)try{Qi(o.containerInfo)}catch(Qe){Je(s,s.return,Qe)}break;case 4:dn(o,s),di(s);break;case 13:dn(o,s),di(s),y=s.child,y.flags&8192&&(b=y.memoizedState!==null,y.stateNode.isHidden=b,!b||y.alternate!==null&&y.alternate.memoizedState!==null||(Ii=cn())),f&4&&Fc(s);break;case 22:if(Me=c!==null&&c.memoizedState!==null,s.mode&1?(vr=(_e=vr)||Me,dn(o,s),vr=_e):dn(o,s),di(s),f&8192){if(_e=s.memoizedState!==null,(s.stateNode.isHidden=_e)&&!Me&&(s.mode&1)!==0)for(Xe=s,Me=s.child;Me!==null;){for(Te=Xe=Me;Xe!==null;){switch(Ae=Xe,Ye=Ae.child,Ae.tag){case 0:case 11:case 14:case 15:Pl(4,Ae,Ae.return);break;case 1:ar(Ae,Ae.return);var Ze=Ae.stateNode;if(typeof Ze.componentWillUnmount=="function"){f=Ae,c=Ae.return;try{o=f,Ze.props=o.memoizedProps,Ze.state=o.memoizedState,Ze.componentWillUnmount()}catch(Qe){Je(f,c,Qe)}}break;case 5:ar(Ae,Ae.return);break;case 22:if(Ae.memoizedState!==null){_d(Te);continue}}Ye!==null?(Ye.return=Ae,Xe=Ye):_d(Te)}Me=Me.sibling}e:for(Me=null,Te=s;;){if(Te.tag===5){if(Me===null){Me=Te;try{y=Te.stateNode,_e?(b=y.style,typeof b.setProperty=="function"?b.setProperty("display","none","important"):b.display="none"):(J=Te.stateNode,te=Te.memoizedProps.style,A=te!=null&&te.hasOwnProperty("display")?te.display:null,J.style.display=Cn("display",A))}catch(Qe){Je(s,s.return,Qe)}}}else if(Te.tag===6){if(Me===null)try{Te.stateNode.nodeValue=_e?"":Te.memoizedProps}catch(Qe){Je(s,s.return,Qe)}}else if((Te.tag!==22&&Te.tag!==23||Te.memoizedState===null||Te===s)&&Te.child!==null){Te.child.return=Te,Te=Te.child;continue}if(Te===s)break e;for(;Te.sibling===null;){if(Te.return===null||Te.return===s)break e;Me===Te&&(Me=null),Te=Te.return}Me===Te&&(Me=null),Te.sibling.return=Te.return,Te=Te.sibling}}break;case 19:dn(o,s),di(s),f&4&&Fc(s);break;case 21:break;default:dn(o,s),di(s)}}function di(s){var o=s.flags;if(o&2){try{e:{for(var c=s.return;c!==null;){if(Qf(c)){var f=c;break e}c=c.return}throw Error(n(160))}switch(f.tag){case 5:var y=f.stateNode;f.flags&32&&($t(y,""),f.flags&=-33);var b=fd(s);Cs(s,b,y);break;case 3:case 4:var A=f.stateNode.containerInfo,J=fd(s);Dl(s,J,A);break;default:throw Error(n(161))}}catch(te){Je(s,s.return,te)}s.flags&=-3}o&4096&&(s.flags&=-4097)}function em(s,o,c){Xe=s,md(s)}function md(s,o,c){for(var f=(s.mode&1)!==0;Xe!==null;){var y=Xe,b=y.child;if(y.tag===22&&f){var A=y.memoizedState!==null||Ol;if(!A){var J=y.alternate,te=J!==null&&J.memoizedState!==null||vr;J=Ol;var _e=vr;if(Ol=A,(vr=te)&&!_e)for(Xe=y;Xe!==null;)A=Xe,te=A.child,A.tag===22&&A.memoizedState!==null?gd(y):te!==null?(te.return=A,Xe=te):gd(y);for(;b!==null;)Xe=b,md(b),b=b.sibling;Xe=y,Ol=J,vr=_e}hd(s)}else(y.subtreeFlags&8772)!==0&&b!==null?(b.return=y,Xe=b):hd(s)}}function hd(s){for(;Xe!==null;){var o=Xe;if((o.flags&8772)!==0){var c=o.alternate;try{if((o.flags&8772)!==0)switch(o.tag){case 0:case 11:case 15:vr||Il(5,o);break;case 1:var f=o.stateNode;if(o.flags&4&&!vr)if(c===null)f.componentDidMount();else{var y=o.elementType===o.type?c.memoizedProps:Ns(o.type,c.memoizedProps);f.componentDidUpdate(y,c.memoizedState,f.__reactInternalSnapshotBeforeUpdate)}var b=o.updateQueue;b!==null&&$f(o,b,f);break;case 3:var A=o.updateQueue;if(A!==null){if(c=null,o.child!==null)switch(o.child.tag){case 5:c=o.child.stateNode;break;case 1:c=o.child.stateNode}$f(o,A,c)}break;case 5:var J=o.stateNode;if(c===null&&o.flags&4){c=J;var te=o.memoizedProps;switch(o.type){case"button":case"input":case"select":case"textarea":te.autoFocus&&c.focus();break;case"img":te.src&&(c.src=te.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(o.memoizedState===null){var _e=o.alternate;if(_e!==null){var Me=_e.memoizedState;if(Me!==null){var Te=Me.dehydrated;Te!==null&&Qi(Te)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(n(163))}vr||o.flags&512&&Gs(o)}catch(Ae){Je(o,o.return,Ae)}}if(o===s){Xe=null;break}if(c=o.sibling,c!==null){c.return=o.return,Xe=c;break}Xe=o.return}}function _d(s){for(;Xe!==null;){var o=Xe;if(o===s){Xe=null;break}var c=o.sibling;if(c!==null){c.return=o.return,Xe=c;break}Xe=o.return}}function gd(s){for(;Xe!==null;){var o=Xe;try{switch(o.tag){case 0:case 11:case 15:var c=o.return;try{Il(4,o)}catch(te){Je(o,c,te)}break;case 1:var f=o.stateNode;if(typeof f.componentDidMount=="function"){var y=o.return;try{f.componentDidMount()}catch(te){Je(o,y,te)}}var b=o.return;try{Gs(o)}catch(te){Je(o,b,te)}break;case 5:var A=o.return;try{Gs(o)}catch(te){Je(o,A,te)}}}catch(te){Je(o,o.return,te)}if(o===s){Xe=null;break}var J=o.sibling;if(J!==null){J.return=o.return,Xe=J;break}Xe=o.return}}var pd=Math.ceil,ao=D.ReactCurrentDispatcher,Fa=D.ReactCurrentOwner,us=D.ReactCurrentBatchConfig,Yt=0,Jn=null,gn=null,wr=0,ds=0,Ba=is(0),kn=0,Wo=null,Pi=0,zl=0,Bc=0,Fl=null,lr=null,Ii=0,Ua=1/0,fs=null,Uc=!1,yd=null,lo=null,Bl=!1,fi=null,Wc=0,Wa=0,Hc=null,Ul=-1,Wl=0;function Er(){return(Yt&6)!==0?cn():Ul!==-1?Ul:Ul=cn()}function Di(s){return(s.mode&1)===0?1:(Yt&2)!==0&&wr!==0?wr&-wr:Sh.transition!==null?(Wl===0&&(Wl=rr()),Wl):(s=en,s!==0||(s=window.event,s=s===void 0?16:we(s.type)),s)}function $s(s,o,c,f){if(50<Wa)throw Wa=0,Hc=null,Error(n(185));dr(s,c,f),((Yt&2)===0||s!==Jn)&&(s===Jn&&((Yt&2)===0&&(zl|=c),kn===4&&zi(s,wr)),Ir(s,f),c===1&&Yt===0&&(o.mode&1)===0&&(Ua=cn()+500,Ca&&Bs()))}function Ir(s,o){var c=s.callbackNode;Kn(s,o);var f=ts(s,s===Jn?wr:0);if(f===0)c!==null&&Gi(c),s.callbackNode=null,s.callbackPriority=0;else if(o=f&-f,s.callbackPriority!==o){if(c!=null&&Gi(c),o===1)s.tag===0?jh(h.bind(null,s)):Sc(h.bind(null,s)),vf(function(){(Yt&6)===0&&Bs()}),c=null;else{switch(sl(f)){case 1:c=vi;break;case 4:c=vs;break;case 16:c=Qr;break;case 536870912:c=rt;break;default:c=Qr}c=ms(c,vd.bind(null,s))}s.callbackPriority=o,s.callbackNode=c}}function vd(s,o){if(Ul=-1,Wl=0,(Yt&6)!==0)throw Error(n(327));var c=s.callbackNode;if(Be()&&s.callbackNode!==c)return null;var f=ts(s,s===Jn?wr:0);if(f===0)return null;if((f&30)!==0||(f&s.expiredLanes)!==0||o)o=ke(s,f);else{o=f;var y=Yt;Yt|=2;var b=V();(Jn!==s||wr!==o)&&(fs=null,Ua=cn()+500,U(s,o));do try{ue();break}catch(J){W(s,J)}while(!0);Uu(),ao.current=b,Yt=y,gn!==null?o=0:(Jn=null,wr=0,o=kn)}if(o!==0){if(o===2&&(y=Hr(s),y!==0&&(f=y,o=qc(s,y))),o===1)throw c=Wo,U(s,0),zi(s,f),Ir(s,cn()),c;if(o===6)zi(s,f);else{if(y=s.current.alternate,(f&30)===0&&!tm(y)&&(o=ke(s,f),o===2&&(b=Hr(s),b!==0&&(f=b,o=qc(s,b))),o===1))throw c=Wo,U(s,0),zi(s,f),Ir(s,cn()),c;switch(s.finishedWork=y,s.finishedLanes=f,o){case 0:case 1:throw Error(n(345));case 2:ze(s,lr,fs);break;case 3:if(zi(s,f),(f&130023424)===f&&(o=Ii+500-cn(),10<o)){if(ts(s,0)!==0)break;if(y=s.suspendedLanes,(y&f)!==f){Er(),s.pingedLanes|=s.suspendedLanes&y;break}s.timeoutHandle=xc(ze.bind(null,s,lr,fs),o);break}ze(s,lr,fs);break;case 4:if(zi(s,f),(f&4194240)===f)break;for(o=s.eventTimes,y=-1;0<f;){var A=31-nr(f);b=1<<A,A=o[A],A>y&&(y=A),f&=~b}if(f=y,f=cn()-f,f=(120>f?120:480>f?480:1080>f?1080:1920>f?1920:3e3>f?3e3:4320>f?4320:1960*pd(f/1960))-f,10<f){s.timeoutHandle=xc(ze.bind(null,s,lr,fs),f);break}ze(s,lr,fs);break;case 5:ze(s,lr,fs);break;default:throw Error(n(329))}}}return Ir(s,cn()),s.callbackNode===c?vd.bind(null,s):null}function qc(s,o){var c=Fl;return s.current.memoizedState.isDehydrated&&(U(s,o).flags|=256),s=ke(s,o),s!==2&&(o=lr,lr=c,o!==null&&Vc(o)),s}function Vc(s){lr===null?lr=s:lr.push.apply(lr,s)}function tm(s){for(var o=s;;){if(o.flags&16384){var c=o.updateQueue;if(c!==null&&(c=c.stores,c!==null))for(var f=0;f<c.length;f++){var y=c[f],b=y.getSnapshot;y=y.value;try{if(!Ps(b(),y))return!1}catch{return!1}}}if(c=o.child,o.subtreeFlags&16384&&c!==null)c.return=o,o=c;else{if(o===s)break;for(;o.sibling===null;){if(o.return===null||o.return===s)return!0;o=o.return}o.sibling.return=o.return,o=o.sibling}}return!0}function zi(s,o){for(o&=~Bc,o&=~zl,s.suspendedLanes|=o,s.pingedLanes&=~o,s=s.expirationTimes;0<o;){var c=31-nr(o),f=1<<c;s[c]=-1,o&=~f}}function h(s){if((Yt&6)!==0)throw Error(n(327));Be();var o=ts(s,0);if((o&1)===0)return Ir(s,cn()),null;var c=ke(s,o);if(s.tag!==0&&c===2){var f=Hr(s);f!==0&&(o=f,c=qc(s,f))}if(c===1)throw c=Wo,U(s,0),zi(s,o),Ir(s,cn()),c;if(c===6)throw Error(n(345));return s.finishedWork=s.current.alternate,s.finishedLanes=o,ze(s,lr,fs),Ir(s,cn()),null}function j(s,o){var c=Yt;Yt|=1;try{return s(o)}finally{Yt=c,Yt===0&&(Ua=cn()+500,Ca&&Bs())}}function $(s){fi!==null&&fi.tag===0&&(Yt&6)===0&&Be();var o=Yt;Yt|=1;var c=us.transition,f=en;try{if(us.transition=null,en=1,s)return s()}finally{en=f,us.transition=c,Yt=o,(Yt&6)===0&&Bs()}}function M(){ds=Ba.current,bn(Ba)}function U(s,o){s.finishedWork=null,s.finishedLanes=0;var c=s.timeoutHandle;if(c!==-1&&(s.timeoutHandle=-1,Lu(c)),gn!==null)for(c=gn.return;c!==null;){var f=c;switch(Nc(f),f.tag){case 1:f=f.type.childContextTypes,f!=null&&_l();break;case 3:Hs(),bn(Kr),bn(Fn),Gu();break;case 5:js(f);break;case 4:Hs();break;case 13:bn(Zt);break;case 19:bn(Zt);break;case 10:Wu(f.type._context);break;case 22:case 23:M()}c=c.return}if(Jn=s,gn=s=Ha(s.current,null),wr=ds=o,kn=0,Wo=null,Bc=zl=Pi=0,lr=Fl=null,Lo!==null){for(o=0;o<Lo.length;o++)if(c=Lo[o],f=c.interleaved,f!==null){c.interleaved=null;var y=f.next,b=c.pending;if(b!==null){var A=b.next;b.next=y,f.next=A}c.pending=f}Lo=null}return s}function W(s,o){do{var c=gn;try{if(Uu(),Mc.current=ui,Ra){for(var f=Ln.memoizedState;f!==null;){var y=f.queue;y!==null&&(y.pending=null),f=f.next}Ra=!1}if(Li=0,Xn=Tt=Ln=null,ir=!1,La=0,Fa.current=null,c===null||c.return===null){kn=1,Wo=o,gn=null;break}e:{var b=s,A=c.return,J=c,te=o;if(o=wr,J.flags|=32768,te!==null&&typeof te=="object"&&typeof te.then=="function"){var _e=te,Me=J,Te=Me.tag;if((Me.mode&1)===0&&(Te===0||Te===11||Te===15)){var Ae=Me.alternate;Ae?(Me.updateQueue=Ae.updateQueue,Me.memoizedState=Ae.memoizedState,Me.lanes=Ae.lanes):(Me.updateQueue=null,Me.memoizedState=null)}var Ye=io(A);if(Ye!==null){Ye.flags&=-257,$r(Ye,A,J,b,o),Ye.mode&1&&qf(b,_e,o),o=Ye,te=_e;var Ze=o.updateQueue;if(Ze===null){var Qe=new Set;Qe.add(te),o.updateQueue=Qe}else Ze.add(te);break e}else{if((o&1)===0){qf(b,_e,o),Z();break e}te=Error(n(426))}}else if(jn&&J.mode&1){var Zn=io(A);if(Zn!==null){(Zn.flags&65536)===0&&(Zn.flags|=256),$r(Zn,A,J,b,o),Bu(Ia(te,J));break e}}b=te=Ia(te,J),kn!==4&&(kn=2),Fl===null?Fl=[b]:Fl.push(b),b=A;do{switch(b.tag){case 3:b.flags|=65536,o&=-o,b.lanes|=o;var ce=Hf(b,te,o);Cf(b,ce);break e;case 1:J=te;var se=b.type,fe=b.stateNode;if((b.flags&128)===0&&(typeof se.getDerivedStateFromError=="function"||fe!==null&&typeof fe.componentDidCatch=="function"&&(lo===null||!lo.has(fe)))){b.flags|=65536,o&=-o,b.lanes|=o;var De=Al(b,J,o);Cf(b,De);break e}}b=b.return}while(b!==null)}Ie(c)}catch(tt){o=tt,gn===c&&c!==null&&(gn=c=c.return);continue}break}while(!0)}function V(){var s=ao.current;return ao.current=ui,s===null?ui:s}function Z(){(kn===0||kn===3||kn===2)&&(kn=4),Jn===null||(Pi&268435455)===0&&(zl&268435455)===0||zi(Jn,wr)}function ke(s,o){var c=Yt;Yt|=2;var f=V();(Jn!==s||wr!==o)&&(fs=null,U(s,o));do try{me();break}catch(y){W(s,y)}while(!0);if(Uu(),Yt=c,ao.current=f,gn!==null)throw Error(n(261));return Jn=null,wr=0,kn}function me(){for(;gn!==null;)Ne(gn)}function ue(){for(;gn!==null&&!ye();)Ne(gn)}function Ne(s){var o=Dr(s.alternate,s,ds);s.memoizedProps=s.pendingProps,o===null?Ie(s):gn=o,Fa.current=null}function Ie(s){var o=s;do{var c=o.alternate;if(s=o.return,(o.flags&32768)===0){if(c=cs(c,o,ds),c!==null){gn=c;return}}else{if(c=ud(c,o),c!==null){c.flags&=32767,gn=c;return}if(s!==null)s.flags|=32768,s.subtreeFlags=0,s.deletions=null;else{kn=6,gn=null;return}}if(o=o.sibling,o!==null){gn=o;return}gn=o=s}while(o!==null);kn===0&&(kn=5)}function ze(s,o,c){var f=en,y=us.transition;try{us.transition=null,en=1,Ge(s,o,c,f)}finally{us.transition=y,en=f}return null}function Ge(s,o,c,f){do Be();while(fi!==null);if((Yt&6)!==0)throw Error(n(327));c=s.finishedWork;var y=s.finishedLanes;if(c===null)return null;if(s.finishedWork=null,s.finishedLanes=0,c===s.current)throw Error(n(177));s.callbackNode=null,s.callbackPriority=0;var b=c.lanes|c.childLanes;if(ea(s,b),s===Jn&&(gn=Jn=null,wr=0),(c.subtreeFlags&2064)===0&&(c.flags&2064)===0||Bl||(Bl=!0,ms(Qr,function(){return Be(),null})),b=(c.flags&15990)!==0,(c.subtreeFlags&15990)!==0||b){b=us.transition,us.transition=null;var A=en;en=1;var J=Yt;Yt|=4,Fa.current=null,Jf(s,c),Uo(c,s),Au(wc),ho=!!wa,wc=wa=null,s.current=c,em(c),Vn(),Yt=J,en=A,us.transition=b}else s.current=c;if(Bl&&(Bl=!1,fi=s,Wc=y),b=s.pendingLanes,b===0&&(lo=null),Js(c.stateNode),Ir(s,cn()),o!==null)for(f=s.onRecoverableError,c=0;c<o.length;c++)y=o[c],f(y.value,{componentStack:y.stack,digest:y.digest});if(Uc)throw Uc=!1,s=yd,yd=null,s;return(Wc&1)!==0&&s.tag!==0&&Be(),b=s.pendingLanes,(b&1)!==0?s===Hc?Wa++:(Wa=0,Hc=s):Wa=0,Bs(),null}function Be(){if(fi!==null){var s=sl(Wc),o=us.transition,c=en;try{if(us.transition=null,en=16>s?16:s,fi===null)var f=!1;else{if(s=fi,fi=null,Wc=0,(Yt&6)!==0)throw Error(n(331));var y=Yt;for(Yt|=4,Xe=s.current;Xe!==null;){var b=Xe,A=b.child;if((Xe.flags&16)!==0){var J=b.deletions;if(J!==null){for(var te=0;te<J.length;te++){var _e=J[te];for(Xe=_e;Xe!==null;){var Me=Xe;switch(Me.tag){case 0:case 11:case 15:Pl(8,Me,b)}var Te=Me.child;if(Te!==null)Te.return=Me,Xe=Te;else for(;Xe!==null;){Me=Xe;var Ae=Me.sibling,Ye=Me.return;if(Zf(Me),Me===_e){Xe=null;break}if(Ae!==null){Ae.return=Ye,Xe=Ae;break}Xe=Ye}}}var Ze=b.alternate;if(Ze!==null){var Qe=Ze.child;if(Qe!==null){Ze.child=null;do{var Zn=Qe.sibling;Qe.sibling=null,Qe=Zn}while(Qe!==null)}}Xe=b}}if((b.subtreeFlags&2064)!==0&&A!==null)A.return=b,Xe=A;else e:for(;Xe!==null;){if(b=Xe,(b.flags&2048)!==0)switch(b.tag){case 0:case 11:case 15:Pl(9,b,b.return)}var ce=b.sibling;if(ce!==null){ce.return=b.return,Xe=ce;break e}Xe=b.return}}var se=s.current;for(Xe=se;Xe!==null;){A=Xe;var fe=A.child;if((A.subtreeFlags&2064)!==0&&fe!==null)fe.return=A,Xe=fe;else e:for(A=se;Xe!==null;){if(J=Xe,(J.flags&2048)!==0)try{switch(J.tag){case 0:case 11:case 15:Il(9,J)}}catch(tt){Je(J,J.return,tt)}if(J===A){Xe=null;break e}var De=J.sibling;if(De!==null){De.return=J.return,Xe=De;break e}Xe=J.return}}if(Yt=y,Bs(),ur&&typeof ur.onPostCommitFiberRoot=="function")try{ur.onPostCommitFiberRoot(Qt,s)}catch{}f=!0}return f}finally{en=c,us.transition=o}}return!1}function tn(s,o,c){o=Ia(c,o),o=Hf(s,o,1),s=Ri(s,o,1),o=Er(),s!==null&&(dr(s,1,o),Ir(s,o))}function Je(s,o,c){if(s.tag===3)tn(s,s,c);else for(;o!==null;){if(o.tag===3){tn(o,s,c);break}else if(o.tag===1){var f=o.stateNode;if(typeof o.type.getDerivedStateFromError=="function"||typeof f.componentDidCatch=="function"&&(lo===null||!lo.has(f))){s=Ia(c,s),s=Al(o,s,1),o=Ri(o,s,1),s=Er(),o!==null&&(dr(o,1,s),Ir(o,s));break}}o=o.return}}function Ue(s,o,c){var f=s.pingCache;f!==null&&f.delete(o),o=Er(),s.pingedLanes|=s.suspendedLanes&c,Jn===s&&(wr&c)===c&&(kn===4||kn===3&&(wr&130023424)===wr&&500>cn()-Ii?U(s,0):Bc|=c),Ir(s,o)}function vt(s,o){o===0&&((s.mode&1)===0?o=1:(o=es,es<<=1,(es&130023424)===0&&(es=4194304)));var c=Er();s=Ot(s,o),s!==null&&(dr(s,o,c),Ir(s,c))}function wn(s){var o=s.memoizedState,c=0;o!==null&&(c=o.retryLane),vt(s,c)}function En(s,o){var c=0;switch(s.tag){case 13:var f=s.stateNode,y=s.memoizedState;y!==null&&(c=y.retryLane);break;case 19:f=s.stateNode;break;default:throw Error(n(314))}f!==null&&f.delete(o),vt(s,c)}var Dr;Dr=function(s,o,c){if(s!==null)if(s.memoizedProps!==o.pendingProps||Kr.current)On=!0;else{if((s.lanes&c)===0&&(o.flags&128)===0)return On=!1,$h(s,o,c);On=(s.flags&131072)!==0}else On=!1,jn&&(o.flags&1048576)!==0&&jf(o,ai,o.index);switch(o.lanes=0,o.tag){case 2:var f=o.type;Dc(s,o),s=o.pendingProps;var y=Sa(o,Fn.current);Ro(o,c),y=Sl(null,o,f,s,y,c);var b=Ku();return o.flags|=1,typeof y=="object"&&y!==null&&typeof y.render=="function"&&y.$$typeof===void 0?(o.tag=1,o.memoizedState=null,o.updateQueue=null,Bn(f)?(b=!0,gl(o)):b=!1,o.memoizedState=y.state!==null&&y.state!==void 0?y.state:null,pl(o),y.updater=Oc,o.stateNode=y,y._reactInternals=o,rd(o,f,s,c),o=sd(null,o,f,!0,b,c)):(o.tag=0,jn&&b&&Eo(o),Dn(null,o,y,c),o=o.child),o;case 16:f=o.elementType;e:{switch(Dc(s,o),s=o.pendingProps,y=f._init,f=y(f._payload),o.type=f,y=o.tag=Ux(f),s=Ns(f,s),y){case 0:o=Tl(null,o,f,s,c);break e;case 1:o=Kf(null,o,f,s,c);break e;case 11:o=Oi(null,o,f,s,c);break e;case 14:o=qs(null,o,f,Ns(f.type,s),c);break e}throw Error(n(306,f,""))}return o;case 0:return f=o.type,y=o.pendingProps,y=o.elementType===f?y:Ns(f,y),Tl(s,o,f,y,c);case 1:return f=o.type,y=o.pendingProps,y=o.elementType===f?y:Ns(f,y),Kf(s,o,f,y,c);case 3:e:{if(id(o),s===null)throw Error(n(387));f=o.pendingProps,b=o.memoizedState,y=b.element,qu(s,o),Ta(o,f,null,c);var A=o.memoizedState;if(f=A.element,b.isDehydrated)if(b={element:f,isDehydrated:!1,cache:A.cache,pendingSuspenseBoundaries:A.pendingSuspenseBoundaries,transitions:A.transitions},o.updateQueue.baseState=b,o.memoizedState=b,o.flags&256){y=Ia(Error(n(423)),o),o=oo(s,o,f,c,y);break e}else if(f!==y){y=Ia(Error(n(424)),o),o=oo(s,o,f,c,y);break e}else for(Yr=$i(o.stateNode.containerInfo.firstChild),gr=o,jn=!0,Us=null,c=Nf(o,null,f,c),o.child=c;c;)c.flags=c.flags&-3|4096,c=c.sibling;else{if(Ea(),f===y){o=Vs(s,o,c);break e}Dn(s,o,f,c)}o=o.child}return o;case 5:return Ef(o),s===null&&zu(o),f=o.type,y=o.pendingProps,b=s!==null?s.memoizedProps:null,A=y.children,ko(f,y)?A=null:b!==null&&ko(f,b)&&(o.flags|=32),Gf(s,o),Dn(s,o,A,c),o.child;case 6:return s===null&&zu(o),null;case 13:return od(s,o,c);case 4:return xl(o,o.stateNode.containerInfo),f=o.pendingProps,s===null?o.child=To(o,null,f,c):Dn(s,o,f,c),o.child;case 11:return f=o.type,y=o.pendingProps,y=o.elementType===f?y:Ns(f,y),Oi(s,o,f,y,c);case 7:return Dn(s,o,o.pendingProps,c),o.child;case 8:return Dn(s,o,o.pendingProps.children,c),o.child;case 12:return Dn(s,o,o.pendingProps.children,c),o.child;case 10:e:{if(f=o.type._context,y=o.pendingProps,b=o.memoizedProps,A=y.value,un(Aa,f._currentValue),f._currentValue=A,b!==null)if(Ps(b.value,A)){if(b.children===y.children&&!Kr.current){o=Vs(s,o,c);break e}}else for(b=o.child,b!==null&&(b.return=o);b!==null;){var J=b.dependencies;if(J!==null){A=b.child;for(var te=J.firstContext;te!==null;){if(te.context===f){if(b.tag===1){te=ls(-1,c&-c),te.tag=2;var _e=b.updateQueue;if(_e!==null){_e=_e.shared;var Me=_e.pending;Me===null?te.next=te:(te.next=Me.next,Me.next=te),_e.pending=te}}b.lanes|=c,te=b.alternate,te!==null&&(te.lanes|=c),Hu(b.return,c,o),J.lanes|=c;break}te=te.next}}else if(b.tag===10)A=b.type===o.type?null:b.child;else if(b.tag===18){if(A=b.return,A===null)throw Error(n(341));A.lanes|=c,J=A.alternate,J!==null&&(J.lanes|=c),Hu(A,c,o),A=b.sibling}else A=b.child;if(A!==null)A.return=b;else for(A=b;A!==null;){if(A===o){A=null;break}if(b=A.sibling,b!==null){b.return=A.return,A=b;break}A=A.return}b=A}Dn(s,o,y.children,c),o=o.child}return o;case 9:return y=o.type,f=o.pendingProps.children,Ro(o,c),y=as(y),f=f(y),o.flags|=1,Dn(s,o,f,c),o.child;case 14:return f=o.type,y=Ns(f,o.pendingProps),y=Ns(f.type,y),qs(s,o,f,y,c);case 15:return Vf(s,o,o.type,o.pendingProps,c);case 17:return f=o.type,y=o.pendingProps,y=o.elementType===f?y:Ns(f,y),Dc(s,o),o.tag=1,Bn(f)?(s=!0,gl(o)):s=!1,Ro(o,c),Uf(o,f,y),rd(o,f,y,c),sd(null,o,f,!0,s,c);case 19:return ld(s,o,c);case 22:return Ml(s,o,c)}throw Error(n(156,o.tag))};function ms(s,o){return Wr(s,o)}function Ys(s,o,c,f){this.tag=s,this.key=c,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=o,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=f,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ar(s,o,c,f){return new Ys(s,o,c,f)}function Ah(s){return s=s.prototype,!(!s||!s.isReactComponent)}function Ux(s){if(typeof s=="function")return Ah(s)?1:0;if(s!=null){if(s=s.$$typeof,s===F)return 11;if(s===I)return 14}return 2}function Ha(s,o){var c=s.alternate;return c===null?(c=Ar(s.tag,o,s.key,s.mode),c.elementType=s.elementType,c.type=s.type,c.stateNode=s.stateNode,c.alternate=s,s.alternate=c):(c.pendingProps=o,c.type=s.type,c.flags=0,c.subtreeFlags=0,c.deletions=null),c.flags=s.flags&14680064,c.childLanes=s.childLanes,c.lanes=s.lanes,c.child=s.child,c.memoizedProps=s.memoizedProps,c.memoizedState=s.memoizedState,c.updateQueue=s.updateQueue,o=s.dependencies,c.dependencies=o===null?null:{lanes:o.lanes,firstContext:o.firstContext},c.sibling=s.sibling,c.index=s.index,c.ref=s.ref,c}function nm(s,o,c,f,y,b){var A=2;if(f=s,typeof s=="function")Ah(s)&&(A=1);else if(typeof s=="string")A=5;else e:switch(s){case Y:return Hl(c.children,y,b,o);case ee:A=8,y|=8;break;case ae:return s=Ar(12,c,o,y|2),s.elementType=ae,s.lanes=b,s;case C:return s=Ar(13,c,o,y),s.elementType=C,s.lanes=b,s;case k:return s=Ar(19,c,o,y),s.elementType=k,s.lanes=b,s;case K:return rm(c,y,b,o);default:if(typeof s=="object"&&s!==null)switch(s.$$typeof){case le:A=10;break e;case ge:A=9;break e;case F:A=11;break e;case I:A=14;break e;case P:A=16,f=null;break e}throw Error(n(130,s==null?s:typeof s,""))}return o=Ar(A,c,o,y),o.elementType=s,o.type=f,o.lanes=b,o}function Hl(s,o,c,f){return s=Ar(7,s,f,o),s.lanes=c,s}function rm(s,o,c,f){return s=Ar(22,s,f,o),s.elementType=K,s.lanes=c,s.stateNode={isHidden:!1},s}function Mh(s,o,c){return s=Ar(6,s,null,o),s.lanes=c,s}function Th(s,o,c){return o=Ar(4,s.children!==null?s.children:[],s.key,o),o.lanes=c,o.stateNode={containerInfo:s.containerInfo,pendingChildren:null,implementation:s.implementation},o}function Wx(s,o,c,f,y){this.tag=o,this.containerInfo=s,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Rs(0),this.expirationTimes=Rs(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Rs(0),this.identifierPrefix=f,this.onRecoverableError=y,this.mutableSourceEagerHydrationData=null}function Rh(s,o,c,f,y,b,A,J,te){return s=new Wx(s,o,c,J,te),o===1?(o=1,b===!0&&(o|=8)):o=0,b=Ar(3,null,null,o),s.current=b,b.stateNode=s,b.memoizedState={element:f,isDehydrated:c,cache:null,transitions:null,pendingSuspenseBoundaries:null},pl(b),s}function Hx(s,o,c){var f=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Q,key:f==null?null:""+f,children:s,containerInfo:o,implementation:c}}function qg(s){if(!s)return ro;s=s._reactInternals;e:{if(kt(s)!==s||s.tag!==1)throw Error(n(170));var o=s;do{switch(o.tag){case 3:o=o.stateNode.context;break e;case 1:if(Bn(o.type)){o=o.stateNode.__reactInternalMemoizedMergedChildContext;break e}}o=o.return}while(o!==null);throw Error(n(171))}if(s.tag===1){var c=s.type;if(Bn(c))return Na(s,c,o)}return o}function Vg(s,o,c,f,y,b,A,J,te){return s=Rh(c,f,!0,s,y,b,A,J,te),s.context=qg(null),c=s.current,f=Er(),y=Di(c),b=ls(f,y),b.callback=o??null,Ri(c,b,y),s.current.lanes=y,dr(s,y,f),Ir(s,f),s}function sm(s,o,c,f){var y=o.current,b=Er(),A=Di(y);return c=qg(c),o.context===null?o.context=c:o.pendingContext=c,o=ls(b,A),o.payload={element:s},f=f===void 0?null:f,f!==null&&(o.callback=f),s=Ri(y,o,A),s!==null&&($s(s,y,A,b),st(s,y,A)),A}function im(s){if(s=s.current,!s.child)return null;switch(s.child.tag){case 5:return s.child.stateNode;default:return s.child.stateNode}}function Gg(s,o){if(s=s.memoizedState,s!==null&&s.dehydrated!==null){var c=s.retryLane;s.retryLane=c!==0&&c<o?c:o}}function Lh(s,o){Gg(s,o),(s=s.alternate)&&Gg(s,o)}function qx(){return null}var Kg=typeof reportError=="function"?reportError:function(s){console.error(s)};function Oh(s){this._internalRoot=s}om.prototype.render=Oh.prototype.render=function(s){var o=this._internalRoot;if(o===null)throw Error(n(409));sm(s,o,null,null)},om.prototype.unmount=Oh.prototype.unmount=function(){var s=this._internalRoot;if(s!==null){this._internalRoot=null;var o=s.containerInfo;$(function(){sm(null,s,null,null)}),o[Ei]=null}};function om(s){this._internalRoot=s}om.prototype.unstable_scheduleHydration=function(s){if(s){var o=ta();s={blockedOn:null,target:s,priority:o};for(var c=0;c<rs.length&&o!==0&&o<rs[c].priority;c++);rs.splice(c,0,s),c===0&&Gr(s)}};function Ph(s){return!(!s||s.nodeType!==1&&s.nodeType!==9&&s.nodeType!==11)}function am(s){return!(!s||s.nodeType!==1&&s.nodeType!==9&&s.nodeType!==11&&(s.nodeType!==8||s.nodeValue!==" react-mount-point-unstable "))}function Yg(){}function Vx(s,o,c,f,y){if(y){if(typeof f=="function"){var b=f;f=function(){var _e=im(A);b.call(_e)}}var A=Vg(o,f,s,0,null,!1,!1,"",Yg);return s._reactRootContainer=A,s[Ei]=A.current,Is(s.nodeType===8?s.parentNode:s),$(),A}for(;y=s.lastChild;)s.removeChild(y);if(typeof f=="function"){var J=f;f=function(){var _e=im(te);J.call(_e)}}var te=Rh(s,0,!1,null,null,!1,!1,"",Yg);return s._reactRootContainer=te,s[Ei]=te.current,Is(s.nodeType===8?s.parentNode:s),$(function(){sm(o,te,c,f)}),te}function lm(s,o,c,f,y){var b=c._reactRootContainer;if(b){var A=b;if(typeof y=="function"){var J=y;y=function(){var te=im(A);J.call(te)}}sm(o,A,s,y)}else A=Vx(c,o,s,y,f);return im(A)}wi=function(s){switch(s.tag){case 3:var o=s.stateNode;if(o.current.memoizedState.isDehydrated){var c=$n(o.pendingLanes);c!==0&&(Zi(o,c|1),Ir(o,cn()),(Yt&6)===0&&(Ua=cn()+500,Bs()))}break;case 13:$(function(){var f=Ot(s,1);if(f!==null){var y=Er();$s(f,s,1,y)}}),Lh(s,1)}},ns=function(s){if(s.tag===13){var o=Ot(s,134217728);if(o!==null){var c=Er();$s(o,s,134217728,c)}Lh(s,134217728)}},Sr=function(s){if(s.tag===13){var o=Di(s),c=Ot(s,o);if(c!==null){var f=Er();$s(c,s,o,f)}Lh(s,o)}},ta=function(){return en},ws=function(s,o){var c=en;try{return en=s,o()}finally{en=c}},ys=function(s,o,c){switch(o){case"input":if($e(s,c),o=c.name,c.type==="radio"&&o!=null){for(c=s;c.parentNode;)c=c.parentNode;for(c=c.querySelectorAll("input[name="+JSON.stringify(""+o)+'][type="radio"]'),o=0;o<c.length;o++){var f=c[o];if(f!==s&&f.form===s.form){var y=ba(f);if(!y)throw Error(n(90));Ct(f),$e(f,y)}}}break;case"textarea":Xt(s,c);break;case"select":o=c.value,o!=null&&Pe(s,!!c.multiple,o,!1)}},et=j,at=$;var Gx={usingClientEntryPoint:!1,Events:[hl,ii,ba,qe,We,j]},wd={findFiberByHostInstance:Fs,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},Kx={bundleType:wd.bundleType,version:wd.version,rendererPackageName:wd.rendererPackageName,rendererConfig:wd.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:D.ReactCurrentDispatcher,findHostInstanceByFiber:function(s){return s=jr(s),s===null?null:s.stateNode},findFiberByHostInstance:wd.findFiberByHostInstance||qx,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var cm=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!cm.isDisabled&&cm.supportsFiber)try{Qt=cm.inject(Kx),ur=cm}catch{}}return Es.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Gx,Es.createPortal=function(s,o){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Ph(o))throw Error(n(200));return Hx(s,o,null,c)},Es.createRoot=function(s,o){if(!Ph(s))throw Error(n(299));var c=!1,f="",y=Kg;return o!=null&&(o.unstable_strictMode===!0&&(c=!0),o.identifierPrefix!==void 0&&(f=o.identifierPrefix),o.onRecoverableError!==void 0&&(y=o.onRecoverableError)),o=Rh(s,1,!1,null,null,c,!1,f,y),s[Ei]=o.current,Is(s.nodeType===8?s.parentNode:s),new Oh(o)},Es.findDOMNode=function(s){if(s==null)return null;if(s.nodeType===1)return s;var o=s._reactInternals;if(o===void 0)throw typeof s.render=="function"?Error(n(188)):(s=Object.keys(s).join(","),Error(n(268,s)));return s=jr(o),s=s===null?null:s.stateNode,s},Es.flushSync=function(s){return $(s)},Es.hydrate=function(s,o,c){if(!am(o))throw Error(n(200));return lm(null,s,o,!0,c)},Es.hydrateRoot=function(s,o,c){if(!Ph(s))throw Error(n(405));var f=c!=null&&c.hydratedSources||null,y=!1,b="",A=Kg;if(c!=null&&(c.unstable_strictMode===!0&&(y=!0),c.identifierPrefix!==void 0&&(b=c.identifierPrefix),c.onRecoverableError!==void 0&&(A=c.onRecoverableError)),o=Vg(o,null,s,1,c??null,y,!1,b,A),s[Ei]=o.current,Is(s),f)for(s=0;s<f.length;s++)c=f[s],y=c._getVersion,y=y(c._source),o.mutableSourceEagerHydrationData==null?o.mutableSourceEagerHydrationData=[c,y]:o.mutableSourceEagerHydrationData.push(c,y);return new om(o)},Es.render=function(s,o,c){if(!am(o))throw Error(n(200));return lm(null,s,o,!1,c)},Es.unmountComponentAtNode=function(s){if(!am(s))throw Error(n(40));return s._reactRootContainer?($(function(){lm(null,null,s,!1,function(){s._reactRootContainer=null,s[Ei]=null})}),!0):!1},Es.unstable_batchedUpdates=j,Es.unstable_renderSubtreeIntoContainer=function(s,o,c,f){if(!am(c))throw Error(n(200));if(s==null||s._reactInternals===void 0)throw Error(n(38));return lm(s,o,c,!1,f)},Es.version="18.3.1-next-f1338f8080-20240426",Es}var rp;function sv(){if(rp)return zh.exports;rp=1;function e(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(t){console.error(t)}}return e(),zh.exports=rb(),zh.exports}var sp;function sb(){if(sp)return um;sp=1;var e=sv();return um.createRoot=e.createRoot,um.hydrateRoot=e.hydrateRoot,um}var ib=sb();const ob=mg(ib);async function iv(e){const t=String(e||"");if(!t)return!1;try{return await navigator.clipboard.writeText(t),!0}catch{try{const n=document.createElement("textarea");return n.value=t,n.style.position="fixed",n.style.left="-9999px",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),!0}catch{return!1}}}const ab=3,lb=Number.MAX_SAFE_INTEGER;function ov(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function av(e){return Array.isArray(e)}function cb(e){const t=e.trim();if(!t)return e;if(t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]"))try{return JSON.parse(t)}catch{return e}return e}function ub(e){if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function tu({kind:e,children:t}){return r.jsx("span",{className:`json-token ${e}`,children:t})}function db(e){const t=JSON.stringify(e.value),n=t.length>96||t.includes("\\n")||t.includes("\\r")||t.includes("\\t"),[i,a]=_.useState(!n||e.expansion_mode==="unfolded");return _.useEffect(()=>{n&&a(e.expansion_mode==="unfolded")},[n,e.expansion_mode,e.expansion_version]),n?r.jsxs("span",{className:`json-string ${i?"open":"collapsed"}`,children:[r.jsx("button",{type:"button",className:"json-string__toggle",onClick:()=>a(l=>!l),"aria-label":i?"Collapse string value":"Expand string value","aria-expanded":i,children:i?"▾":"▸"}),i?r.jsx("span",{className:"json-token string json-string__value",children:t}):r.jsxs("button",{type:"button",className:"json-string__preview",onClick:()=>a(!0),"aria-label":"Expand string value",children:[r.jsx("span",{className:"json-token string json-string__preview_text",children:t}),r.jsx("span",{className:"json-string__suffix",children:"(...)"})]})]}):r.jsx(tu,{kind:"string",children:t})}function fb(e,t,n){return e===null?r.jsx(tu,{kind:"null",children:"null"}):typeof e=="string"?r.jsx(db,{value:e,expansion_mode:t,expansion_version:n}):typeof e=="number"?r.jsx(tu,{kind:"number",children:String(e)}):typeof e=="boolean"?r.jsx(tu,{kind:"boolean",children:e?"true":"false"}):r.jsx(tu,{kind:"string",children:JSON.stringify(String(e))})}function mb(e){return av(e)?e.length===1?"1 item":`${e.length} items`:ov(e)?Object.keys(e).length===1?"1 key":`${Object.keys(e).length} keys`:""}function lv(e){const{label:t,value:n,depth:i,collapse_after_depth:a,expansion_mode:l,expansion_version:u,trailing_comma:d}=e,m=i*14,p=ov(n),g=av(n),v=p||g,w=i<a,[x,N]=_.useState(w);_.useEffect(()=>{N(w)},[w,u]);const S=t?r.jsxs(r.Fragment,{children:[r.jsx(tu,{kind:"key",children:JSON.stringify(t)}),": "]}):null;if(!v)return r.jsxs("div",{className:"json-viewer__line",style:{paddingLeft:m},children:[S,fb(n,l,u),d?",":""]});const R=g?"[":"{",T=g?"]":"}",z=mb(n),H=x?`${R}`:`${R}…${T}${z?` (${z})`:""}`,D=g?n.map((G,Q)=>({key:String(Q),label:void 0,value:G})):Object.entries(n).map(([G,Q])=>({key:G,label:G,value:Q}));return r.jsxs("details",{className:"json-viewer__details",open:x,onToggle:G=>N(G.currentTarget.open),children:[r.jsxs("summary",{className:"json-viewer__summary",style:{paddingLeft:m},children:[S,r.jsx("span",{className:"json-viewer__caret","aria-hidden":"true",children:x?"▾":"▸"}),r.jsx("span",{className:"json-viewer__punct",children:H}),!x&&d?r.jsx("span",{className:"json-viewer__punct",children:","}):null]}),x?r.jsx("div",{className:"json-viewer__children",children:D.length===0?r.jsxs("div",{className:"json-viewer__line",style:{paddingLeft:m},children:[r.jsx("span",{className:"json-viewer__punct",children:T}),d?",":""]}):r.jsxs(r.Fragment,{children:[D.map((G,Q)=>{const Y=Q===D.length-1;return r.jsx(lv,{label:G.label,value:G.value,depth:i+1,collapse_after_depth:a,expansion_mode:l,expansion_version:u,trailing_comma:!Y},`${i}:${t||"root"}:${G.key}`)}),r.jsxs("div",{className:"json-viewer__line",style:{paddingLeft:m},children:[r.jsx("span",{className:"json-viewer__punct",children:T}),d?",":""]})]})}):null]})}function cv(e){const{value:t,className:n,showCopy:i=!0}=e,[a,l]=_.useState({mode:"folded",version:0}),u=typeof e.collapseAfterDepth=="number"&&(Number.isFinite(e.collapseAfterDepth)||e.collapseAfterDepth===1/0)&&e.collapseAfterDepth>=0?e.collapseAfterDepth===1/0?Number.MAX_SAFE_INTEGER:Math.trunc(e.collapseAfterDepth):ab,d=a.mode==="unfolded"?lb:u,m=_.useMemo(()=>typeof t=="string"?cb(t):t,[t]),p=_.useMemo(()=>ub(t),[t]),g=["json-viewer",n].filter(Boolean).join(" ");_.useEffect(()=>{l(w=>({mode:"folded",version:w.version+1}))},[m]);const v=()=>{l(w=>({mode:w.mode==="unfolded"?"folded":"unfolded",version:w.version+1}))};return r.jsxs("div",{className:g,children:[r.jsxs("div",{className:"json-viewer__toolbar",children:[r.jsx("button",{type:"button",className:"json-viewer__btn json-viewer__toggle-all",onClick:v,"aria-expanded":a.mode==="unfolded",children:a.mode==="unfolded"?"Fold all":"Unfold all"}),i?r.jsx("button",{type:"button",className:"json-viewer__btn json-viewer__copy",onClick:()=>void iv(p),children:"Copy"}):null]}),r.jsx("div",{className:"json-viewer__tree",role:"tree","aria-label":"JSON viewer",children:r.jsx(lv,{value:m,depth:0,collapse_after_depth:d,expansion_mode:a.mode,expansion_version:a.version,trailing_comma:!1})})]})}function Uh(e){const t=[],n=String(e??"");let i=0,a="";const l=()=>{a&&(t.push(a),a="")};for(;i<n.length;){const u=n[i];if(u==="`"){const d=n.indexOf("`",i+1);if(d!==-1){l(),t.push(r.jsx("code",{children:n.slice(i+1,d)},`code:${i}`)),i=d+1;continue}}if(u==="*"&&n[i+1]==="*"){const d=n.indexOf("**",i+2);if(d!==-1){l(),t.push(r.jsx("strong",{children:n.slice(i+2,d)},`bold:${i}`)),i=d+2;continue}}a+=u,i+=1}return l(),t}function hb(e){return String(e??"").replace(/\r\n/g,`
|
|
41
|
+
`).replace(/\r/g,`
|
|
42
|
+
`).split(`
|
|
43
|
+
`)}function _b({text:e,className:t}){const n=hb(e),i=[];let a=0;for(;a<n.length;){const u=n[a],d=String(u??"");if(!d.trim()){a+=1;continue}if(d.trim().startsWith("```")){const w=d.trim().replace(/```/g,"").trim(),x=[];for(a+=1;a<n.length&&!String(n[a]??"").trim().startsWith("```");)x.push(String(n[a]??"")),a+=1;a<n.length&&(a+=1);const N=x.join(`
|
|
44
|
+
`);i.push(r.jsx("pre",{className:"mf-md_pre",children:r.jsx("code",{className:w?`language-${w}`:void 0,children:N})},`pre:${a}`));continue}const m=d.match(/^(#{1,3})\s+(.*)$/);if(m){const v=m[1].length,w=m[2]||"",x=Uh(w);v===1?i.push(r.jsx("h1",{children:x},`h1:${a}`)):v===2?i.push(r.jsx("h2",{children:x},`h2:${a}`)):i.push(r.jsx("h3",{children:x},`h3:${a}`)),a+=1;continue}const p=v=>{const w=v.trimStart();return w.startsWith("- ")||w.startsWith("* ")};if(p(d)){const v=[];for(;a<n.length&&p(String(n[a]??""));){const w=String(n[a]??"").trimStart();v.push(w.slice(2)),a+=1}i.push(r.jsx("ul",{className:"mf-md_ul",children:v.map((w,x)=>r.jsx("li",{children:Uh(w)},`li:${a}:${x}`))},`ul:${a}`));continue}const g=[];for(;a<n.length&&String(n[a]??"").trim();)g.push(String(n[a]??"")),a+=1;i.push(r.jsx("p",{className:"mf-md_p",children:g.map((v,w)=>r.jsxs(pe.Fragment,{children:[Uh(v),w<g.length-1?r.jsx("br",{}):null]},`pl:${a}:${w}`))},`p:${a}`))}const l=["mf-md",t].filter(Boolean).join(" ");return r.jsx("div",{className:l,children:i})}const ip="observe";function gs(e){return!e||typeof e!="object"?null:e}function A_(e,t){const n=String(e||"").replace(/\s+/g," ").trim();return n?n.length<=t?n:`${n.slice(0,Math.max(0,t-1)).trimEnd()}…`:""}function op(e){const t=gs(e);if(!t)return null;const n=typeof t.role=="string"?String(t.role).trim():"",i=typeof t.content=="string"?String(t.content):"";if(!n||i==="")return null;const a=typeof t.name=="string"?String(t.name).trim():"";return{role:n,content:i,name:a||void 0}}function gb(e){if(Array.isArray(e)){if(e.length===0)return null;const n=[];for(const i of e){const a=op(i);if(!a)return null;n.push(a)}return n}const t=op(e);return t?[t]:null}function pb(e){const t=String(e||"").trim();if(!t)return null;const n=t[0],i=t[t.length-1];if(!(n==="{"&&i==="}"||n==="["&&i==="]"))return null;try{const l=JSON.parse(t);return l&&typeof l=="object"||Array.isArray(l)?l:null}catch{return null}}function yb(e){const t=String(e||"");return t.trim()?!!(t.includes("```")||/\n\s*#{1,3}\s+/.test(t)||/\n\s*[-*]\s+/.test(t)||/\n\s*\d+[\.\)]\s+/.test(t)||t.includes("**")||t.includes("`")):!1}function ap({text:e}){const t=String(e||""),n=pb(t);if(n!==null)return r.jsx(cv,{value:n});const i=t.trim();return i.startsWith("{")||i.startsWith("[")?r.jsx("pre",{className:"run-details-output",children:t||"(none)"}):t.includes(`
|
|
45
|
+
`)||yb(t)?r.jsx("div",{className:"run-details-output",children:r.jsx(_b,{text:t})}):r.jsx("pre",{className:"run-details-output",children:t||"(none)"})}function uv({value:e}){if(e==null)return r.jsx("pre",{className:"run-details-output",children:"(none)"});const t=gb(e);return t?r.jsx("div",{className:"mf-msg-list",children:t.map((n,i)=>r.jsxs("div",{className:"mf-msg",children:[r.jsxs("div",{className:"mf-msg-meta",children:[r.jsx("span",{className:`mf-msg-role ${n.role}`,children:n.role}),n.name?r.jsx("span",{className:"mf-msg-name",children:n.name}):null]}),r.jsx("div",{className:"mf-msg-content",children:r.jsx(ap,{text:n.content})})]},`${n.role}:${i}`))}):typeof e=="string"?r.jsx(ap,{text:e}):r.jsx(cv,{value:e})}function dv(e){const t=e.effect;return!t||typeof t!="object"?null:t}function el(e){const t=dv(e);return(t&&typeof t.type=="string"?t.type:"")||"effect"}function nh(e){const t=dv(e),n=t==null?void 0:t.payload;return!n||typeof n!="object"?null:n}function hg(e){const t=e.result;return!t||typeof t!="object"?null:t}function fv(e){if(el(e)!=="tool_calls")return[];const n=hg(e),i=n&&Array.isArray(n.results)?n.results:null;if(!i)return[];const a=[];for(const l of i){const u=gs(l);if(!u)continue;const d=typeof u.name=="string"?u.name.trim():"";d&&a.push({call_id:typeof u.call_id=="string"?u.call_id:void 0,name:d,success:!!u.success,output:u.output,error:u.error})}return a}function mv(e){if(el(e)!=="tool_calls")return[];const n=nh(e),i=n&&Array.isArray(n.tool_calls)?n.tool_calls:null;if(!i)return[];const a=[];for(const l of i){const u=gs(l);if(!u)continue;const d=typeof u.name=="string"?u.name.trim():"";if(!d)continue;const m=gs(u.args)||gs(u.arguments)||{};a.push({call_id:typeof u.call_id=="string"?u.call_id:void 0,name:d,args:m})}return a}function rh(e){const t=e.error;if(typeof t=="string")return t.trim();const n=gs(t);if(n){const i=typeof n.message=="string"?n.message.trim():"",a=typeof n.stack=="string"?n.stack.trim():"";return i||a||""}return""}function hv(e){if(!e)return"";const t=e.reasoning;if(typeof t=="string")return t.trim();const n=gs(t);return n&&typeof n.text=="string"?n.text.trim():""}function _v(e){const t=el(e),n=nh(e),i=hg(e),a=(l,u)=>{const d=String(l||"").replace(/\s+/g," ").trim();return d?d.length<=u?d:`${d.slice(0,Math.max(0,u-1)).trimEnd()}…`:""};if(t==="llm_call"){const l=i==null?void 0:i.content,u=typeof l=="string"?l.replace(/\s+/g," ").trim():"",d=hv(i),m=Array.isArray(i==null?void 0:i.tool_calls)?i.tool_calls:null,g=!!(m&&m.length>0)?d||u:u||d;return a(g,220)}if(t==="tool_calls"){const l=i&&Array.isArray(i.results)?i.results:null;if(!l)return"";const u=l.filter(d=>{var m;return((m=gs(d))==null?void 0:m.success)===!1});return u.length>0?`${u.length} tool call(s) failed`:`${l.length} tool call(s) executed`}return t==="ask_user"&&n&&typeof n.prompt=="string"?String(n.prompt).trim():""}function Pm(e){const t=typeof e.status=="string"?e.status:"unknown";return t==="failed"||rh(e.step)?"failed":t}function vb(e){const t=e.map(n=>Pm(n));return t.some(n=>n==="failed")?"failed":t.some(n=>n==="waiting")?"waiting":t.some(n=>n==="running")?"running":"completed"}function Wh(e){return e.filter(t=>!t.hidden)}function wb(e){const t=el(e),n=rh(e);return Wh(t==="llm_call"?[{id:"system",label:"System"},{id:"user",label:"User"},{id:"tools",label:"Tools"},{id:"response",label:"Response"},{id:"reasoning",label:"Reasoning"},{id:"errors",label:"Errors",hidden:!n},{id:"raw",label:"Raw"}]:t==="tool_calls"?[{id:"tools",label:"Tools"},{id:"errors",label:"Errors",hidden:!n},{id:"raw",label:"Raw"}]:[{id:"errors",label:"Errors",hidden:!n},{id:"raw",label:"Raw"}])}function xb(e){const t=el(e);return t==="llm_call"?"user":t==="tool_calls"?"tools":rh(e)?"errors":"raw"}function bb(e){const t=new Map,n=nh(e),i=n&&Array.isArray(n.tools)?n.tools:null;if(!i)return t;for(const a of i){const l=gs(a);if(!l)continue;const u=typeof l.name=="string"?l.name.trim():"";if(!u)continue;const m=(Array.isArray(l.parameters)?l.parameters:[]).map(p=>{const g=gs(p);return(g&&typeof g.id=="string"?g.id.trim():"")||""}).filter(Boolean);t.set(u,m)}return t}function gv(e,t,n){const i=Object.keys(t||{}),a=n&&n.length?n.filter(m=>i.includes(m)):[],l=i.filter(m=>!a.includes(m)).sort(),u=[...a,...l],d=u.slice(0,5).map(m=>{const p=t[m];return typeof p=="string"?`${m}=${JSON.stringify(A_(p,42))}`:typeof p=="number"||typeof p=="boolean"?`${m}=${String(p)}`:p==null?`${m}=null`:`${m}=${A_(JSON.stringify(p),42)}`});return`${e}(${d.join(", ")}${u.length>5?", …":""})`}function jb(e){const t=e.ts?String(e.ts):"";if(!t)return"";try{const n=new Date(t);return Number.isFinite(n.getTime())?n.toLocaleTimeString():""}catch{return""}}function Hh({item:e,label:t,toolDefs:n,defaultOpen:i=!1}){const a=e.step,l=el(a),u=wb(a),d=xb(a),[m,p]=_.useState(d),[g,v]=_.useState(!!i),w=nh(a),x=hg(a),N=rh(a),S=jb(e),R=e.nodeId?String(e.nodeId):"",T=e.runId?String(e.runId):"",z=l==="tool_calls"?mv(a):[],H=l==="tool_calls"?fv(a):[],D=z.map(le=>gv(le.name,le.args,n.get(le.name)||null)),Q=(()=>{if(m==="raw")return a;if(m==="errors")return N||null;if(l==="llm_call"){const le=w||{},ge=typeof le.system_prompt=="string"?String(le.system_prompt):"",F=typeof le.prompt=="string"?String(le.prompt):"",C=gs(x==null?void 0:x.metadata),k=C?gs(C._runtime_observability):null,I=k?gs(k.llm_generate_kwargs):null,P=I&&Array.isArray(I.messages)?I.messages:null,K=C?gs(C._provider_request):null,L=K?gs(K.payload):null,O=L&&Array.isArray(L.messages)?L.messages:null,q=Array.isArray(le.messages)?le.messages:[],E=P||O||q,X=E.filter(ie=>String((ie==null?void 0:ie.role)||"").trim()==="system"),ne=E.filter(ie=>String((ie==null?void 0:ie.role)||"").trim()==="user");if(m==="system"){const ie=[],de=ge.trim(),xe=!!de&&X.some(be=>typeof(be==null?void 0:be.content)=="string"&&String(be.content).trim()===de);return de&&!xe&&ie.push({role:"system",name:"system_prompt",content:ge}),ie.push(...X),ie}if(m==="user"){const ie=[],de=F.trim(),xe=!!de&&ne.some(be=>typeof(be==null?void 0:be.content)=="string"&&String(be.content).trim()===de);return de&&!xe&&ie.push({role:"user",name:"prompt",content:F}),ie.push(...ne),ie}if(m==="tools")return le.tools||[];if(m==="response"){const ie=x==null?void 0:x.content;if(typeof ie=="string"&&ie.trim())return ie;const de=x==null?void 0:x.output;if(de!==void 0)return de;const xe=Array.isArray(x==null?void 0:x.tool_calls)?x.tool_calls:null;return xe&&xe.length?{tool_calls:xe}:x}if(m==="reasoning")return hv(x)||null}return l==="tool_calls"&&m==="tools"?{tool_calls:z,tool_signatures:D,results:H}:a})(),Y=_v(a),ee=Pm(e),ae=ee==="completed"?"OK":ee==="failed"?"ERROR":ee==="waiting"?"WAITING":ee.toUpperCase();return r.jsxs("details",{className:`agent-trace-entry ${ee}`,open:g,onToggle:le=>v(le.currentTarget.open),children:[r.jsxs("summary",{className:"agent-trace-summary",children:[r.jsx("span",{className:`agent-trace-status ${ee}`,children:ae}),r.jsx("span",{className:"agent-cycle-stage","data-stage":t,children:t}),r.jsx("span",{className:"agent-trace-kind",children:l}),S?r.jsx("span",{className:"agent-trace-node",children:S}):null,R?r.jsx("span",{className:"agent-trace-node",children:R}):null,T?r.jsx("span",{className:"agent-trace-run",children:T}):null]}),Y?r.jsx("div",{className:"agent-trace-preview",children:Y}):null,r.jsxs("div",{className:"agent-trace-body",children:[r.jsx("div",{className:"agent-trace-tabs",children:u.map(le=>r.jsx("button",{type:"button",className:`agent-trace-tab ${le.id===m?"active":""}`,onClick:()=>p(le.id),children:le.label},le.id))}),r.jsx(uv,{value:Q})]})]})}function Sb({acts:e}){const t=e.flatMap(l=>fv(l.step)),n=t.filter(l=>l.success===!1),i=n.length?`${n.length} error(s)`:t.length?`${t.length} tool result(s)`:"(none)",a=n.length?"failed":"completed";return r.jsxs("details",{className:`agent-trace-entry ${a}`,open:!1,children:[r.jsxs("summary",{className:"agent-trace-summary",children:[r.jsx("span",{className:`agent-trace-status ${a}`,children:n.length?"ERROR":"OK"}),r.jsx("span",{className:"agent-cycle-stage","data-stage":ip,children:ip}),r.jsx("span",{className:"agent-trace-kind",children:"OBSERVATIONS"}),r.jsx("span",{className:"agent-trace-preview-inline",children:i})]}),r.jsx("div",{className:"agent-observe-body",children:t.length===0?r.jsx("div",{className:"agent-observe-empty",children:"(no tool results)"}):r.jsx("div",{className:"agent-observe-results",children:t.map((l,u)=>{const d=l.success?"completed":"failed",m=l.success?"OK":"ERROR",p=l.success?l.output:l.error??l.output;return r.jsxs("details",{className:`agent-observe-result ${d}`,open:!1,children:[r.jsxs("summary",{className:"agent-observe-summary",children:[r.jsx("span",{className:`agent-trace-status ${d}`,children:m}),r.jsx("span",{className:"agent-observe-name",children:l.name}),l.call_id?r.jsx("span",{className:"agent-observe-callid",children:l.call_id}):null]}),r.jsx(uv,{value:p})]},`${l.name}:${l.call_id||""}:${u}`)})})})]})}function kb({items:e,subRunId:t,title:n,subtitle:i,onOpenSubRun:a,defaultOpenLatest:l=!0}){const u=_.useMemo(()=>{const v=Array.isArray(e)?e.slice():[];return v.sort((w,x)=>{const N=w.ts?new Date(w.ts).getTime():NaN,S=x.ts?new Date(x.ts).getTime():NaN;return Number.isFinite(N)&&Number.isFinite(S)?N-S:0}),v},[e]),d=_.useMemo(()=>{const v=[];let w=null,x=0;for(const N of u){const S=el(N.step);if(S==="llm_call"){x+=1,w={id:`cycle:${N.runId}:${x}:${N.ts||""}`,index:x,items:[N],think:N,acts:[],others:[],status:Pm(N),ts:N.ts},v.push(w);continue}w||(x+=1,w={id:`cycle:${N.runId}:${x}:${N.ts||""}`,index:x,items:[],think:null,acts:[],others:[],status:Pm(N),ts:N.ts},v.push(w)),w.items.push(N),S==="tool_calls"?w.acts.push(N):w.others.push(N),w.status=vb(w.items)}return v},[u]),m=typeof n=="string"&&n.trim()?n.trim():"Agent calls",p=typeof i=="string"&&i.trim()?i.trim():"Live per-effect trace (LLM/tool calls).",g=typeof t=="string"?t.trim():"";return r.jsxs("div",{className:"agent-trace-panel",children:[r.jsxs("div",{className:"agent-trace-header",children:[r.jsx("div",{className:"agent-trace-title",children:m}),r.jsxs("div",{className:"agent-trace-subtitle",children:[p,g?r.jsxs("span",{className:"agent-trace-subrun",children:[" ","sub_run_id: ",g,r.jsx("button",{type:"button",className:"agent-trace-copy",onClick:v=>{v.stopPropagation(),iv(g)},title:`Copy sub_run_id: ${g}`,"aria-label":"Copy sub run id",children:"⧉"}),a?r.jsx("button",{type:"button",className:"agent-trace-open",onClick:v=>{v.stopPropagation(),a()},title:"Open sub-run",children:"Open"}):null]}):null]})]}),u.length===0?r.jsx("div",{className:"agent-trace-empty",children:"No trace entries yet."}):r.jsxs("div",{className:"agent-cycle-list",children:[r.jsxs("div",{className:"agent-cycle-meta",children:[d.length," cycle(s)"]}),d.map(v=>{const w=v.status,x=w==="completed"?"OK":w==="failed"?"ERROR":w==="waiting"?"WAITING":w.toUpperCase(),N=w==="completed"?"✓":w==="failed"?"✗":"",S=N?`${N} ${x}`:x,R=v.think?_v(v.think.step):"",T=v.think?bb(v.think.step):new Map,H=v.acts.flatMap(G=>mv(G.step)).map(G=>gv(G.name,G.args,T.get(G.name)||null)),D=l&&v.index===d.length;return r.jsxs("details",{className:`agent-cycle ${w}`,open:D,children:[r.jsxs("summary",{className:"agent-cycle-summary",children:[r.jsx("span",{className:`agent-trace-status ${w}`,children:S}),r.jsx("span",{className:"agent-cycle-label",children:"cycle"}),r.jsxs("span",{className:"agent-cycle-index",children:["#",v.index]}),H.length?r.jsxs("span",{className:"agent-trace-badges",children:[H.slice(0,3).map(G=>r.jsx("span",{className:"run-metric-badge metric-tool",title:G,children:A_(G,62)},G)),H.length>3?r.jsxs("span",{className:"run-metric-badge metric-tool",children:["+",H.length-3]}):null]}):null,r.jsx("span",{className:"agent-cycle-spacer"}),R?r.jsx("span",{className:"agent-cycle-preview",children:R}):null]}),r.jsxs("div",{className:"agent-cycle-body",children:[v.think?r.jsx(Hh,{item:v.think,label:"think",toolDefs:T,defaultOpen:D}):null,v.acts.map(G=>r.jsx(Hh,{item:G,label:"act",toolDefs:T},G.id)),r.jsx(Sb,{acts:v.acts}),v.others.length?r.jsxs("div",{className:"agent-cycle-others",children:[r.jsx("div",{className:"agent-cycle-others-title",children:"other"}),v.others.map(G=>{const Q=D&&el(G.step)==="answer_user";return r.jsx(Hh,{item:G,label:"other",toolDefs:T,defaultOpen:Q},G.id)})]}):null]})]},v.id)})]})]})}function qi(e){return typeof e=="string"?e.trim():""}function Nb(e){var t;return qi(e.run_id)||qi((t=e.record)==null?void 0:t.run_id)}function M_(e){return qi(e==null?void 0:e.node_id)}const Cb=new Set(["reason","act","observe","thought","think"]);function T_(e){const t=qi(e);if(!t.includes("::"))return t;const n=t.split("::");if(n.length<2)return t;const i=String(n[n.length-1]||"").trim().toLowerCase();return Cb.has(i)?n.slice(0,-1).join("::"):t}function pv(e){var t;return qi((t=e==null?void 0:e.effect)==null?void 0:t.type)}function $b(e){return qi(e==null?void 0:e.status)||"unknown"}function lp(e){return qi(e==null?void 0:e.step_id)}function Eb(e){return qi(e==null?void 0:e.ended_at)||qi(e==null?void 0:e.started_at)}function Ab(e){const t=new Map,n=new Map;for(const a of e){const l=T_(M_(a));if(!l)continue;const u=pv(a);u==="llm_call"?t.set(l,(t.get(l)||0)+1):u==="tool_calls"&&n.set(l,(n.get(l)||0)+1)}const i=a=>{let l="",u=-1;for(const[d,m]of a)m>u&&(l=d,u=m);return l};return i(t)||i(n)||""}function Mb(e,t){const n=qi(t.run_id);if(!n)return{run_id:"",node_id:"",items:[]};const i=(Array.isArray(e)?e:[]).filter(x=>x&&x.record&&Nb(x)===n).map(x=>({cursor:x.cursor,record:x.record})).sort((x,N)=>(x.cursor||0)-(N.cursor||0)),a=i.map(x=>x.record),l=T_(qi(t.node_id)),u=l||Ab(a),d=new Set(["llm_call","tool_calls","ask_user","answer_user"]);let m=i.filter(x=>d.has(pv(x.record)));l&&(m=m.filter(x=>T_(M_(x.record))===l));const p=new Map,g=[];for(const x of m){const N=lp(x.record);if(!N){g.push(x);continue}const S=p.get(N);(!S||(x.cursor||0)>(S.cursor||0))&&p.set(N,x)}const w=[...g,...Array.from(p.values())].sort((x,N)=>(x.cursor||0)-(N.cursor||0)).map(x=>{const N=x.record,S=M_(N)||"(node?)",R=Eb(N),T=lp(N);return{id:`ledger:${n}:${x.cursor}:${T||""}`,runId:n,nodeId:S,ts:R||void 0,status:$b(N),step:N}});return{run_id:n,node_id:u,items:w}}function sh(e){const t=String(e??"").trim();if(!t||!(t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]")))return null;try{return JSON.parse(t)}catch{return null}}function Tb(e){if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Rb(e){const t=String(e.role||"message").trim()||"message",n=String(e.title||"").trim(),i=String(e.ts||"").trim(),a=[t];return n&&a.push(n),i&&a.push(i),a.join(" · ")}function Lb(e){return e.endsWith(`
|
|
46
|
+
`)?e:`${e}
|
|
47
|
+
`}function Ob(e){return String(e||"").trimStart().startsWith("```")}function Pb(e,t){const i=[`# ${String((t==null?void 0:t.heading)||"Chat").trim()||"Chat"}`,""];for(const a of e){const l=Rb(a);i.push(`## ${l}`,"");const u=String(a.content||""),d=sh(u);d!==null&&!Ob(u)?i.push("```json",Tb(d).trimEnd(),"```",""):i.push(Lb(u).trimEnd(),""),i.push("---","")}for(;i.length&&!i[i.length-1].trim();)i.pop();return i.length&&i[i.length-1]==="---"&&i.pop(),`${i.join(`
|
|
48
|
+
`).trimEnd()}
|
|
49
|
+
`}async function nc(e){const t=String(e||"");if(!t)return!1;try{return await navigator.clipboard.writeText(t),!0}catch{try{const n=document.createElement("textarea");return n.value=t,n.style.position="fixed",n.style.left="-9999px",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),!0}catch{return!1}}}function Ib(e){const t=String(e.filename||"").trim()||"export.txt",n=String(e.text||""),i=String(e.mime),a=new Blob([n],{type:i}),l=URL.createObjectURL(a),u=document.createElement("a");u.href=l,u.download=t,document.body.appendChild(u),u.click(),u.remove(),window.setTimeout(()=>URL.revokeObjectURL(l),1e3)}const Db=3,zb=Number.MAX_SAFE_INTEGER;function yv(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function vv(e){return Array.isArray(e)}function Fb(e){if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function nu({kind:e,children:t}){return r.jsx("span",{className:`pc-json-token ${e}`,children:t})}function Bb(e){const t=JSON.stringify(e.value),n=t.length>96||t.includes("\\n")||t.includes("\\r")||t.includes("\\t"),[i,a]=_.useState(!n||e.expansionMode==="unfolded");return _.useEffect(()=>{n&&a(e.expansionMode==="unfolded")},[n,e.expansionMode,e.expansionVersion]),n?r.jsxs("span",{className:`pc-json-string ${i?"open":"collapsed"}`,children:[r.jsx("button",{type:"button",className:"pc-json-string__toggle",onClick:()=>a(l=>!l),"aria-label":i?"Collapse string value":"Expand string value","aria-expanded":i,children:i?"▾":"▸"}),i?r.jsx("span",{className:"pc-json-token string pc-json-string__value",children:t}):r.jsxs("button",{type:"button",className:"pc-json-string__preview",onClick:()=>a(!0),"aria-label":"Expand string value",children:[r.jsx("span",{className:"pc-json-token string pc-json-string__preview_text",children:t}),r.jsx("span",{className:"pc-json-string__suffix",children:"(...)"})]})]}):r.jsx(nu,{kind:"string",children:t})}function Ub(e,t,n){return e===null?r.jsx(nu,{kind:"null",children:"null"}):typeof e=="string"?r.jsx(Bb,{value:e,expansionMode:t,expansionVersion:n}):typeof e=="number"?r.jsx(nu,{kind:"number",children:String(e)}):typeof e=="boolean"?r.jsx(nu,{kind:"boolean",children:e?"true":"false"}):r.jsx(nu,{kind:"string",children:JSON.stringify(String(e))})}function Wb(e){return vv(e)?e.length===1?"1 item":`${e.length} items`:yv(e)?Object.keys(e).length===1?"1 key":`${Object.keys(e).length} keys`:""}function wv(e){const{label:t,value:n,depth:i,collapseAfterDepth:a,expansionMode:l,expansionVersion:u,trailingComma:d}=e,m=i*14,p=yv(n),g=vv(n),v=p||g,w=i<a,[x,N]=_.useState(w);_.useEffect(()=>{N(w)},[w,u]);const S=t?r.jsxs(r.Fragment,{children:[r.jsx(nu,{kind:"key",children:JSON.stringify(t)}),": "]}):null;if(!v)return r.jsxs("div",{className:"pc-json-viewer__line",style:{paddingLeft:m},children:[S,Ub(n,l,u),d?",":""]});const R=g?"[":"{",T=g?"]":"}",z=Wb(n),H=x?`${R}`:`${R}…${T}${z?` (${z})`:""}`,D=g?n.map((G,Q)=>({key:String(Q),label:void 0,value:G})):Object.entries(n).map(([G,Q])=>({key:G,label:G,value:Q}));return r.jsxs("details",{className:"pc-json-viewer__details",open:x,onToggle:G=>N(G.currentTarget.open),children:[r.jsxs("summary",{className:"pc-json-viewer__summary",style:{paddingLeft:m},children:[S,r.jsx("span",{className:"pc-json-viewer__caret","aria-hidden":"true",children:x?"▾":"▸"}),r.jsx("span",{className:"pc-json-viewer__punct",children:H}),!x&&d?r.jsx("span",{className:"pc-json-viewer__punct",children:","}):null]}),x?r.jsx("div",{className:"pc-json-viewer__children",children:D.length===0?r.jsxs("div",{className:"pc-json-viewer__line",style:{paddingLeft:m},children:[r.jsx("span",{className:"pc-json-viewer__punct",children:T}),d?",":""]}):r.jsxs(r.Fragment,{children:[D.map((G,Q)=>{const Y=Q===D.length-1;return r.jsx(wv,{label:G.label,value:G.value,depth:i+1,collapseAfterDepth:a,expansionMode:l,expansionVersion:u,trailingComma:!Y},`${i}:${t||"root"}:${G.key}`)}),r.jsxs("div",{className:"pc-json-viewer__line",style:{paddingLeft:m},children:[r.jsx("span",{className:"pc-json-viewer__punct",children:T}),d?",":""]})]})}):null]})}function Hb(e){const t=e.trim();if(!t)return e;if(t.startsWith("{")&&t.endsWith("}")||t.startsWith("[")&&t.endsWith("]"))try{return JSON.parse(t)}catch{return e}return e}function ps(e){const{value:t,className:n,showCopy:i=!0}=e,[a,l]=_.useState({mode:"folded",version:0}),u=typeof e.collapseAfterDepth=="number"&&(Number.isFinite(e.collapseAfterDepth)||e.collapseAfterDepth===1/0)&&e.collapseAfterDepth>=0?e.collapseAfterDepth===1/0?Number.MAX_SAFE_INTEGER:Math.trunc(e.collapseAfterDepth):Db,d=a.mode==="unfolded"?zb:u,m=_.useMemo(()=>typeof t=="string"?Hb(t):t,[t]),p=_.useMemo(()=>Fb(t),[t]),g=["pc-json-viewer",n].filter(Boolean).join(" ");_.useEffect(()=>{l(w=>({mode:"folded",version:w.version+1}))},[m]);const v=()=>{l(w=>({mode:w.mode==="unfolded"?"folded":"unfolded",version:w.version+1}))};return r.jsxs("div",{className:g,children:[r.jsxs("div",{className:"pc-json-viewer__toolbar",children:[r.jsx("button",{type:"button",className:"pc-btn pc-json-viewer__toggle-all",onClick:v,"aria-expanded":a.mode==="unfolded",children:a.mode==="unfolded"?"Fold all":"Unfold all"}),i?r.jsx("button",{type:"button",className:"pc-btn pc-json-viewer__copy",onClick:()=>void nc(p),children:"Copy JSON"}):null]}),r.jsx("div",{className:"pc-json-viewer__tree",role:"tree","aria-label":"JSON viewer",children:r.jsx(wv,{value:m,depth:0,collapseAfterDepth:d,expansionMode:a.mode,expansionVersion:a.version,trailingComma:!1})})]})}function bd(e,t){const n=String(e??"");if(!t||!t.needles.length)return[n];const i=[],a=n.toLowerCase();let l=0;for(;l<n.length;){let u=-1,d="";for(let g=0;g<t.needlesLower.length;g++){const v=t.needlesLower[g];if(!v)continue;const w=a.indexOf(v,l);if(w===-1)continue;const x=t.needles[g]||"";x&&(u===-1||w<u||w===u&&x.length>d.length)&&(u=w,d=x)}if(u===-1||!d){i.push(n.slice(l));break}u>l&&i.push(n.slice(l,u));const m=t.hits===0&&t.id?t.id:void 0,p=n.slice(u,u+d.length);i.push(r.jsx("span",{id:m,className:t.className,children:p},`hl:${t.hits}`)),t.hits+=1,l=u+d.length}return i}function R_(e){const t=String(e||"").trim();if(t&&/^(https?:|mailto:|tel:|#|\/)/i.test(t))return t}let Jl=null;function qb(e){var i;const t=String(e||"").trim();if(t.startsWith("/")&&!t.startsWith("//")&&!t.startsWith("/\\"))return!0;if(!/^https?:\/\//i.test(t))return!1;const n=typeof window<"u"?(i=window.location)==null?void 0:i.origin:void 0;if(!n||n==="null")return!1;try{return new URL(t).origin===n}catch{return!1}}function xv(e,t,n){return r.jsx("a",{className:"pc-md_link pc-md_image_link",href:t,target:"_blank",rel:"noopener noreferrer",children:`image: ${n||t}`},e)}function Ka(e,t){const n=[],i=String(e??"");let a=0,l="";const u=()=>{if(l){for(const d of bd(l,t))n.push(d);l=""}};for(;a<i.length;){const d=i[a];if(d==="!"&&i[a+1]==="["){const m=i.indexOf("]",a+2);if(m!==-1&&i[m+1]==="("){const p=i.indexOf(")",m+2);if(p!==-1){const g=i.slice(a+2,m),v=R_(i.slice(m+2,p));if(v&&Jl&&!Jl(v)){u(),n.push(xv(`img:${a}`,v,g)),a=p+1;continue}if(v){u(),n.push(r.jsxs("span",{className:"pc-md_image_inline",children:[r.jsx("img",{className:"pc-md_img",src:v,alt:g,loading:"lazy"}),g?r.jsx("span",{className:"pc-md_img_caption",children:t?bd(g,t):g}):null]},`img:${a}`)),a=p+1;continue}}}}if(d==="["){const m=i.indexOf("]",a+1);if(m!==-1&&i[m+1]==="("){const p=i.indexOf(")",m+2);if(p!==-1){const g=i.slice(a+1,m),v=R_(i.slice(m+2,p));if(v){u(),n.push(r.jsx("a",{className:"pc-md_link",href:v,target:v.startsWith("#")?void 0:"_blank",rel:"noreferrer",children:Ka(g,t)},`link:${a}`)),a=p+1;continue}}}}if(d==="`"){const m=i.indexOf("`",a+1);if(m!==-1){u();const p=i.slice(a+1,m);n.push(r.jsx("code",{children:t?bd(p,t):p},`code:${a}`)),a=m+1;continue}}if(d==="*"&&i[a+1]==="*"){const m=i.indexOf("**",a+2);if(m!==-1){u();const p=i.slice(a+2,m);n.push(r.jsx("strong",{children:t?bd(p,t):p},`bold:${a}`)),a=m+2;continue}}if(d==="*"&&i[a+1]!=="*"){const m=i.indexOf("*",a+1);if(m!==-1){u();const p=i.slice(a+1,m);n.push(r.jsx("em",{children:t?bd(p,t):p},`em:${a}`)),a=m+1;continue}}l+=d,a+=1}return u(),n}function Vb(e){return String(e??"").replace(/\r\n/g,`
|
|
50
|
+
`).replace(/\r/g,`
|
|
51
|
+
`).split(`
|
|
52
|
+
`)}function $m(e){const n=String(e??"").match(/^([ \t]*)(?:([-*+])|(\d{1,9})[.)])\s+(.*)$/);return n?{indent:n[1].replace(/\t/g," ").length,ordered:!!n[3],start:n[3]?Math.max(1,parseInt(n[3],10)||1):1,content:n[4]??""}:null}function Gb(e){const t=[];for(const a of e){const l=$m(a);l?t.push(l):t.length>0&&a.trim()&&(t[t.length-1].content+=` ${a.trim()}`)}const n=[],i=[];for(const a of t){for(;i.length>0&&a.indent<i[i.length-1].indent;)i.pop();let l=i.length>0?i[i.length-1]:null;if(l&&a.indent>l.indent){const u=l.node.items,d=u[u.length-1];if(d){const m={ordered:a.ordered,start:a.start,items:[]};d.children.push(m),i.push({indent:a.indent,node:m}),l=i[i.length-1]}}else if(l&&l.node.ordered!==a.ordered){i.pop();const u=i.length>0?i[i.length-1]:null,d={ordered:a.ordered,start:a.start,items:[]};if(u){const m=u.node.items,p=m[m.length-1];p?p.children.push(d):u.node.items.push({content:"",children:[d]})}else n.push(d);i.push({indent:a.indent,node:d}),l=i[i.length-1]}if(!l){const u={ordered:a.ordered,start:a.start,items:[]};n.push(u),i.push({indent:a.indent,node:u}),l=i[i.length-1]}l.node.items.push({content:a.content,children:[]})}return n}function bv(e,t,n){const i=e.items.map((a,l)=>r.jsxs("li",{children:[Ka(a.content,t),a.children.map((u,d)=>bv(u,t,`${n}:${l}:${d}`))]},`${n}:li:${l}`));return e.ordered?r.jsx("ol",{className:"pc-md_ol",start:e.start!==1?e.start:void 0,children:i},n):r.jsx("ul",{className:"pc-md_ul",children:i},n)}function Kb(e,t,n){return Gb(e).map((i,a)=>bv(i,t,`${n}:${a}`))}function cp(e){let t=String(e??"").trim();return t?(t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|").map(n=>String(n??"").trim())):[]}function up(e){let t=String(e??"").trim();if(!t)return!1;t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1));const n=t.split("|").map(i=>String(i??"").trim());return n.length<2?!1:n.every(i=>/^:?-{3,}:?$/.test(i))}const dp=/^(#{1,5})\s+(.*)$/;function fp(e){return e.trim().startsWith("```")}function mp(e){return e.trimStart().startsWith(">")}function pi(e){const t=Jl;Jl=e.images==="link"?e.inlineImage||qb:null;try{return Yb(e)}finally{Jl=t}}function Yb({text:e,className:t,highlight:n,highlights:i,highlightClassName:a,highlightId:l}){const u=Vb(e),d=[],m=[];Array.isArray(i)&&m.push(...i),typeof n=="string"&&n.trim()&&m.push(n);const p=Array.from(new Set(m.map(x=>String(x??"").trim()).filter(Boolean))).filter(x=>x.length>=4),g=p.length?{needles:p,needlesLower:p.map(x=>x.toLowerCase()),className:a||"pc-md_hl",id:l,hits:0}:null;let v=0;for(;v<u.length;){const x=String(u[v]??"");if(!x.trim()){v+=1;continue}const N=x.trim();if(/^([-_*])(\s*\1){2,}$/.test(N)){d.push(r.jsx("hr",{className:"pc-md_hr"},`hr:${v}`)),v+=1;continue}const S=x.match(/^\s*!\[([^\]]*)\]\(([^)]+)\)\s*$/);if(S){const z=R_(S[2]||"");if(z&&Jl&&!Jl(z)){d.push(r.jsx("p",{className:"pc-md_p",children:xv(`img:${v}`,z,S[1]||"")},`p:${v}`)),v+=1;continue}if(z){const H=S[1]||"";d.push(r.jsxs("figure",{className:"pc-md_figure",children:[r.jsx("img",{className:"pc-md_img",src:z,alt:H,loading:"lazy"}),H?r.jsx("figcaption",{children:Ka(H,g)}):null]},`figure:${v}`)),v+=1;continue}}if(fp(x)){const H=x.trim().replace(/```/g,"").trim(),D=[];for(v+=1;v<u.length&&!String(u[v]??"").trim().startsWith("```");)D.push(String(u[v]??"")),v+=1;v<u.length&&(v+=1);const G=D.join(`
|
|
53
|
+
`);d.push(r.jsx("pre",{className:"pc-md_pre",children:r.jsx("code",{className:H?`language-${H}`:void 0,children:G})},`pre:${v}`));continue}const R=x.match(dp);if(R){const z=R[1].length,H=R[2]||"",D=Ka(H,g);z===1?d.push(r.jsx("h1",{children:D},`h1:${v}`)):z===2?d.push(r.jsx("h2",{children:D},`h2:${v}`)):z===3?d.push(r.jsx("h3",{children:D},`h3:${v}`)):z===4?d.push(r.jsx("h4",{children:D},`h4:${v}`)):d.push(r.jsx("h5",{children:D},`h5:${v}`)),v+=1;continue}if(mp(x)){const z=[];for(;v<u.length&&String(u[v]??"").trimStart().startsWith(">");){const D=String(u[v]??"").trimStart();z.push(D.replace(/^>\s?/,"")),v+=1}d.push(r.jsx("blockquote",{className:"pc-md_quote",children:z.map((H,D)=>r.jsxs(pe.Fragment,{children:[Ka(H,g),D<z.length-1?r.jsx("br",{}):null]},`q:${v}:${D}`))},`quote:${v}`));continue}if(x.includes("|")&&v+1<u.length&&up(String(u[v+1]??""))){const z=cp(x),H=Math.max(1,z.length),D=[];for(v+=2;v<u.length;){const G=String(u[v]??"");if(!G.trim()||!G.includes("|"))break;const Q=cp(G),Y=[];for(let ee=0;ee<H;ee++)Y.push(Q[ee]??"");D.push(Y),v+=1}d.push(r.jsx("div",{className:"pc-md_table_wrap",children:r.jsxs("table",{className:"pc-md_table",children:[r.jsx("thead",{children:r.jsx("tr",{children:z.slice(0,H).map((G,Q)=>r.jsx("th",{children:Ka(G,g)},`th:${v}:${Q}`))})}),r.jsx("tbody",{children:D.map((G,Q)=>r.jsx("tr",{children:G.map((Y,ee)=>r.jsx("td",{children:Ka(Y,g)},`td:${v}:${Q}:${ee}`))},`tr:${v}:${Q}`))})]})},`table:${v}`));continue}if($m(x)){const z=[];for(;v<u.length;){const H=String(u[v]??"");if(!H.trim()||H.trimStart().startsWith("```"))break;if($m(H)||/^\s{2,}\S/.test(H)){z.push(H),v+=1;continue}break}d.push(r.jsx(pe.Fragment,{children:Kb(z,g,`list:${v}`)},`list:${v}`));continue}const T=[];for(;v<u.length&&String(u[v]??"").trim()&&!(T.length>0&&$m(String(u[v]??"")));){const z=String(u[v]??"");if(T.length>0&&(dp.test(z)||fp(z)||mp(z))||T.length>0&&z.includes("|")&&v+1<u.length&&up(String(u[v+1]??"")))break;T.push(z),v+=1}d.push(r.jsx("p",{className:"pc-md_p",children:T.map((z,H)=>r.jsxs(pe.Fragment,{children:[Ka(z,g),H<T.length-1?r.jsx("br",{}):null]},`pl:${v}:${H}`))},`p:${v}`))}const w=["pc-md",t].filter(Boolean).join(" ");return r.jsx("div",{className:w,children:d})}function jv(e){const t=String(e.text??""),n=_.useMemo(()=>sh(t),[t]),i=["pc-chat-content",e.className].filter(Boolean).join(" ");return n!==null?r.jsx("div",{className:i,children:r.jsx(ps,{value:n,collapseAfterDepth:e.jsonCollapseAfterDepth})}):e.renderMarkdown?r.jsx("div",{className:i,children:e.renderMarkdown(t)}):r.jsx("div",{className:i,children:r.jsx(pi,{text:t,images:e.images,inlineImage:e.inlineImage})})}const Sv=[{id:"dark",label:"Dark (Abstract)",group:"dark",swatches:["#1a1a2e","#16213e","#0f3460","#e94560","#60a5fa","#27ae60"]},{id:"observer-night",label:"Observer Night",group:"dark",swatches:["#0b0f14","#10161e","#161e28","#e8a54a","#6ea8d8","#7bc98c"]},{id:"catppuccin-mocha",label:"Catppuccin Mocha",group:"dark",swatches:["#1e1e2e","#181825","#313244","#cba6f7","#89b4fa","#a6e3a1"]},{id:"catppuccin-macchiato",label:"Catppuccin Macchiato",group:"dark",swatches:["#24273a","#1e2030","#363a4f","#c6a0f6","#8aadf4","#a6da95"]},{id:"catppuccin-frappe",label:"Catppuccin Frappe",group:"dark",swatches:["#303446","#292c3c","#414559","#ca9ee6","#8caaee","#a6d189"]},{id:"rose-pine",label:"Rose Pine",group:"dark",swatches:["#191724","#1f1d2e","#26233a","#c4a7e7","#31748f","#9ccfd8"]},{id:"rose-pine-moon",label:"Rose Pine Moon",group:"dark",swatches:["#232136","#2a273f","#393552","#c4a7e7","#3e8fb0","#9ccfd8"]},{id:"tokyo-night",label:"Tokyo Night",group:"dark",swatches:["#1a1b26","#24283b","#414868","#7aa2f7","#2ac3de","#9ece6a"]},{id:"nord",label:"Nord",group:"dark",swatches:["#2e3440","#3b4252","#434c5e","#88c0d0","#5e81ac","#a3be8c"]},{id:"one-dark",label:"One Dark",group:"dark",swatches:["#282c34","#21252b","#3a3f4b","#61afef","#c678dd","#98c379"]},{id:"dracula",label:"Dracula",group:"dark",swatches:["#282a36","#343746","#44475a","#ff79c6","#8be9fd","#50fa7b"]},{id:"monokai",label:"Monokai",group:"dark",swatches:["#272822","#2d2e27","#3e3d32","#66d9ef","#a1efe4","#a6e22e"]},{id:"gruvbox",label:"Gruvbox",group:"dark",swatches:["#282828","#3c3836","#504945","#fe8019","#83a598","#b8bb26"]},{id:"solarized-dark",label:"Solarized Dark",group:"dark",swatches:["#002b36","#073642","#0b4b5a","#268bd2","#2aa198","#859900"]},{id:"everforest-dark",label:"Everforest Dark",group:"dark",swatches:["#2b3339","#323c41","#3a464c","#a7c080","#7fbbb3","#a7c080"]},{id:"catppuccin-latte",label:"Catppuccin Latte",group:"light",swatches:["#eff1f5","#e6e9ef","#ccd0da","#8839ef","#1e66f5","#40a02b"]},{id:"rose-pine-dawn",label:"Rose Pine Dawn",group:"light",swatches:["#faf4ed","#fffaf3","#f2e9e1","#907aa9","#56949f","#286983"]},{id:"one-light",label:"One Light",group:"light",swatches:["#fafafa","#ffffff","#e5e5e6","#4078f2","#a626a4","#50a14f"]},{id:"everforest-light",label:"Everforest Light",group:"light",swatches:["#fdf6e3","#fffbef","#e8e0cc","#4f8f5a","#3a94c5","#4f8f5a"]},{id:"solarized-light",label:"Solarized Light",group:"light",swatches:["#fdf6e3","#eee8d5","#e3ddc9","#268bd2","#2aa198","#859900"]},{id:"light",label:"Light",group:"light",swatches:["#f7f7fb","#ffffff","#e6e8f0","#e94560","#2563eb","#16a34a"]}];Sv.map(e=>({id:e.id,label:e.label}));function Xb(e){return`theme-${String(e||"").trim()||"dark"}`}function hp(e){try{const t=document.documentElement,n=Array.from(t.classList).filter(i=>i.startsWith("theme-"));for(const i of n)t.classList.remove(i);t.classList.add(Xb(e))}catch{}}const L_=[{id:"sm",label:"Small",scale:.9},{id:"md",label:"Medium",scale:1},{id:"lg",label:"Large",scale:1.1},{id:"xl",label:"Extra Large",scale:1.2}],O_=[{id:"compact",label:"Compact",density:.85},{id:"standard",label:"Standard",density:1},{id:"spacious",label:"Spacious",density:1.2}];function Jb(e){const t=String(e).trim();return L_.find(n=>n.id===t)||L_[1]}function Zb(e){const t=String(e).trim();return O_.find(n=>n.id===t)||O_[1]}function _p(e){try{const t=document.documentElement,n=Jb(e.font_scale||"md"),i=Zb(e.header_density||"standard");t.style.setProperty("--font-scale",String(n.scale)),t.style.setProperty("--header-density",String(i.density))}catch{}}var kv=sv();function Gc(...e){return e.filter(Boolean).join(" ")}function uu({value:e,options:t,placeholder:n="Select…",disabled:i=!1,loading:a=!1,searchable:l=!0,searchPlaceholder:u="Search…",allowCustom:d=!1,clearable:m=!1,minPopoverWidth:p=240,variant:g="panel",className:v,triggerClassName:w,ariaLabel:x,id:N,includeValueOption:S=!1,onOpen:R,customOptionLabel:T,validateCustomValue:z,onChange:H,renderOption:D,renderValue:G}){const Q=_.useRef(null),Y=_.useRef(null),ee=_.useRef(null),ae=_.useRef(R),le=_.useId(),ge=N||`af-select-${le.replace(/[^a-zA-Z0-9_-]/g,"")}`,F=`${ge}-listbox`,[C,k]=_.useState(!1),[I,P]=_.useState(""),[K,L]=_.useState(0),[O,q]=_.useState("bottom"),[E,X]=_.useState({left:0,top:0,width:0});_.useEffect(()=>{ae.current=R},[R]);const ne=_.useMemo(()=>{if(!S)return t;const he=String(e??"").trim();return!he||t.some(Pe=>Pe.value===he)?t:[...t,{value:he,label:he}]},[S,t,e]),ie=_.useMemo(()=>{const he=String(e??"");return ne.find(Pe=>Pe.value===he)||null},[ne,e]),de=_.useMemo(()=>(ie==null?void 0:ie.label)||String(e||"").trim()||"",[ie,e]),xe=_.useMemo(()=>{const he=I.trim().toLowerCase();return he?ne.filter(Pe=>Pe.label.toLowerCase().includes(he)||Pe.value.toLowerCase().includes(he)):ne},[ne,I]),be=_.useMemo(()=>{if(!d)return null;const he=I.trim();if(!he||ne.some(Rt=>Rt.value===he))return null;const Ve=(z==null?void 0:z(he,{options:ne}))||"";return{value:he,label:T?T(he):`Use "${he}"`,disabled:!!Ve,reason:Ve}},[d,T,ne,I,z]),Ee=_.useMemo(()=>{const he=be?[be,...xe]:xe;if(he.length>0)return he;const Pe=String(e??"").trim();return a&&Pe?[{value:Pe,label:de||Pe}]:he},[be,xe,a,de,e]),Oe=_.useCallback(()=>{const he=Q.current;if(!he)return;const Pe=he.getBoundingClientRect(),Ve=Math.max(Pe.width,p),Rt=Math.max(8,Math.min(Pe.left,window.innerWidth-Ve-8)),Xt=window.innerHeight-Pe.bottom,fn=Pe.top,Ft=Xt>=220||Xt>=fn?"bottom":"top";q(Ft);const At=Ft==="bottom"?Pe.bottom+6:Pe.top-6;X({left:Rt,top:At,width:Ve})},[p]),He=_.useCallback(()=>{k(!1),P("")},[]);_.useEffect(()=>{var he;C&&((he=ae.current)==null||he.call(ae))},[C]),_.useEffect(()=>{if(!C)return;Oe();const he=()=>Oe();return window.addEventListener("resize",he),window.addEventListener("scroll",he,!0),()=>{window.removeEventListener("resize",he),window.removeEventListener("scroll",he,!0)}},[C,Oe]),_.useEffect(()=>{if(!C)return;const he=Pe=>{var Rt,Xt;const Ve=Pe.target;Ve&&((Rt=Q.current)!=null&&Rt.contains(Ve)||(Xt=Y.current)!=null&&Xt.contains(Ve)||He())};return document.addEventListener("mousedown",he,!0),()=>document.removeEventListener("mousedown",he,!0)},[C,He]),_.useEffect(()=>{if(!C)return;const he=Math.max(0,Ee.findIndex(Pe=>Pe.value===e));L(he===-1?0:he),l&&setTimeout(()=>{var Pe;return(Pe=ee.current)==null?void 0:Pe.focus()},0)},[C,l,e,Ee]);const Ke=he=>{var Ve;const Pe=Ee.find(Rt=>Rt.value===he);Pe!=null&&Pe.disabled||(H(he),He(),(Ve=Q.current)==null||Ve.focus())},Ct=he=>{var Pe,Ve;if(he.key==="Escape")return he.preventDefault(),He(),(Pe=Q.current)==null||Pe.focus(),!0;if(he.key==="Tab")return He(),(Ve=Q.current)==null||Ve.focus(),!1;if(he.key==="ArrowDown")return he.preventDefault(),L(Rt=>Math.min(Rt+1,Math.max(0,Ee.length-1))),!0;if(he.key==="ArrowUp")return he.preventDefault(),L(Rt=>Math.max(Rt-1,0)),!0;if(he.key==="Home")return he.preventDefault(),L(0),!0;if(he.key==="End")return he.preventDefault(),L(Math.max(0,Ee.length-1)),!0;if(he.key==="Enter"){he.preventDefault();const Rt=Ee[K];return Rt&&Ke(Rt.value),!0}return!1},pt=he=>{if(!i){if(C){if(Ct(he))return;if(he.key===" "&&!l){he.preventDefault();const Pe=Ee[K];Pe&&Ke(Pe.value)}return}(he.key==="Enter"||he.key===" "||he.key==="ArrowDown"||he.key==="ArrowUp")&&(he.preventDefault(),k(!0))}},gt=!!String(e||"").trim(),yt=gt?de:n,nt=be!=null&&be.disabled?be.reason||"Unavailable":"",$e=C&&Ee.length>0?`${ge}-opt-${K}`:void 0,Re=r.jsx("span",{className:Gc("af-select-value",!gt&&"af-select-value--placeholder"),children:a&&!gt?"Loading…":yt}),ot=G?G(ie,String(e||"")):Re;return r.jsxs("span",{className:Gc("af-select",g==="pin"?"af-select--pin":"af-select--panel",v),children:[r.jsxs("button",{ref:Q,id:ge,type:"button",className:Gc("af-select-trigger",m&>&&"af-select-trigger--clearable",w),disabled:i,onMouseDown:he=>he.stopPropagation(),onClick:he=>{he.stopPropagation(),!i&&k(Pe=>!Pe)},onKeyDown:pt,role:l?void 0:"combobox","aria-haspopup":"listbox","aria-expanded":C,"aria-controls":C?F:void 0,"aria-activedescendant":l?void 0:$e,"aria-label":x,children:[ot,r.jsx("span",{className:Gc("af-select-caret",C&&"af-select-caret--open"),children:"▾"})]}),m&>?r.jsx("button",{type:"button",className:"af-select-clear-btn","aria-label":"Clear selection",disabled:i,onMouseDown:he=>{he.preventDefault(),he.stopPropagation()},onClick:he=>{var Pe;he.preventDefault(),he.stopPropagation(),H(""),He(),(Pe=Q.current)==null||Pe.focus()},title:"Clear",children:"×"}):null,C?kv.createPortal(r.jsxs("div",{ref:Y,className:Gc("af-select-popover",O==="top"&&"af-select-popover--top"),style:{position:"fixed",left:`${E.left}px`,top:`${E.top}px`,width:`${E.width}px`},onMouseDown:he=>he.stopPropagation(),onClick:he=>he.stopPropagation(),onWheel:he=>he.stopPropagation(),onKeyDown:Ct,tabIndex:-1,children:[l?r.jsxs("div",{className:"af-select-search",children:[r.jsx("input",{ref:ee,className:"af-select-search-input",value:I,onChange:he=>P(he.target.value),placeholder:u,onKeyDown:Ct,role:"combobox","aria-expanded":!0,"aria-controls":F,"aria-activedescendant":$e,"aria-invalid":!!nt,"aria-describedby":nt?`${ge}-custom-error`:void 0}),nt?r.jsx("div",{id:`${ge}-custom-error`,className:"af-select-custom-error",role:"alert",children:nt}):null]}):null,r.jsx("div",{className:"af-select-options",role:"listbox",id:F,"aria-label":x,children:a&&Ee.length===0?r.jsx("div",{className:"af-select-empty",children:"Loading…"}):Ee.length===0?r.jsx("div",{className:"af-select-empty",children:"No results"}):Ee.map((he,Pe)=>{var At;const Ve=he.value===e,Rt=Pe===K,Xt=String(he.group||"").trim(),fn=Pe>0?String(((At=Ee[Pe-1])==null?void 0:At.group)||"").trim():"",Ft=!!Xt&&Xt!==fn;return r.jsxs(pe.Fragment,{children:[Ft?r.jsx("div",{className:"af-select-group",role:"presentation",children:Xt}):null,r.jsx("div",{id:`${ge}-opt-${Pe}`,role:"option","aria-selected":Ve,className:Gc("af-select-option",Ve&&"af-select-option--selected",Rt&&"af-select-option--highlighted",he.disabled&&"af-select-option--disabled"),title:he.disabled?he.reason||"Unavailable":void 0,onMouseEnter:()=>L(Pe),onMouseDown:sn=>{sn.preventDefault(),sn.stopPropagation()},onClick:()=>Ke(he.value),"aria-disabled":he.disabled?!0:void 0,children:D?D(he,{selected:Ve,highlighted:Rt}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"af-select-option-label",children:[r.jsx("span",{children:he.label}),he.reason?r.jsx("small",{className:"af-select-option-reason",children:he.reason}):null]}),Ve?r.jsx("span",{className:"af-select-check",children:"✓"}):null]})})]},he.value)})})]}),document.body):null]})}function Qb(e){const t=new Set,n=[];for(const i of e||[]){if(!i||typeof i!="object")continue;const a=String(i.name||"").trim();!a||t.has(a)||(t.add(a),n.push({name:a,display_name:typeof i.display_name=="string"?i.display_name:void 0}))}return n.sort((i,a)=>i.name.localeCompare(a.name)),n}function e0(e){const t=new Set,n=[];for(const i of e||[]){const a=String(i||"").trim();!a||t.has(a)||(t.add(a),n.push(a))}return n.sort(),n}function t0(e){const t=e.disabled===!0,n=e.layout||"stack",i=e.allowGatewayDefault!==!1,a=String(e.gatewayDefaultLabel||"(gateway default)"),l=String(e.providerLabel||"Provider"),u=String(e.modelLabel||"Model"),d=String(e.providerPlaceholder||"(select)"),m=String(e.modelPlaceholder||"(select)"),p=String(e.provider||"").trim(),g=String(e.model||"").trim(),v=Qb(e.providers),w=e0(e.models),x=t||!!e.loadingProviders,N=t||!!e.loadingModels,S=[...i?[{value:"",label:a}]:[],...v.map(T=>({value:T.name,label:T.display_name?`${T.display_name} (${T.name})`:T.name}))],R=[...i?[{value:"",label:a}]:[],...w.map(T=>({value:T,label:T}))];return r.jsxs("div",{className:e.className,style:n==="row"?{display:"flex",gap:"10px",flexWrap:"wrap",alignItems:"flex-start"}:{display:"flex",flexDirection:"column",gap:"10px"},children:[r.jsxs("div",{style:n==="row"?{flex:"1 1 260px",minWidth:240}:void 0,children:[r.jsx("label",{children:l}),r.jsx(uu,{value:p,options:S,placeholder:i?a:d,disabled:x,loading:!!e.loadingProviders,searchable:!0,allowCustom:e.allowCustomProvider===!0,clearable:i,variant:"panel",triggerClassName:e.selectClassName,ariaLabel:l,onChange:T=>e.onChange({provider:String(T||"").trim(),model:""})}),e.loadingProviders?r.jsx("div",{className:"mono muted",style:{fontSize:"12px",marginTop:"6px"},children:"Loading providers…"}):null,e.providerError?r.jsx("div",{className:"mono",style:{color:"var(--error)",fontSize:"12px",marginTop:"6px"},children:e.providerError}):null]}),r.jsxs("div",{style:n==="row"?{flex:"1 1 260px",minWidth:240}:void 0,children:[r.jsx("label",{children:u}),r.jsx(uu,{value:g,options:R,placeholder:i?a:m,disabled:N,loading:!!e.loadingModels,searchable:!0,allowCustom:e.allowCustomModel===!0,clearable:i,variant:"panel",triggerClassName:e.selectClassName,ariaLabel:u,onChange:T=>e.onChange({provider:p,model:String(T||"").trim()})}),e.loadingModels?r.jsx("div",{className:"mono muted",style:{fontSize:"12px",marginTop:"6px"},children:"Loading models…"}):null,e.modelError?r.jsx("div",{className:"mono",style:{color:"var(--error)",fontSize:"12px",marginTop:"6px"},children:e.modelError}):null]})]})}function gp(...e){return e.filter(Boolean).join(" ")}function n0({kicker:e="AbstractGateway connection",title:t="Connect to AbstractGateway",description:n="Sign in with the Gateway user token assigned by the Gateway admin.",statusLabel:i="Gateway token missing",statusTone:a="warn",tokenSourceLabel:l="token: missing",showGatewayUrl:u=!1,gatewayUrl:d="",gatewayUrlPlaceholder:m="http://127.0.0.1:8080",onGatewayUrlChange:p,userId:g,userPlaceholder:v="admin",onUserIdChange:w,token:x,tokenPlaceholder:N="Paste Gateway user token",showToken:S=!1,onTokenChange:R,onShowTokenChange:T,remember:z=!1,rememberLabel:H="Remember this browser",onRememberChange:D,loading:G=!1,submitting:Q=!1,submitDisabled:Y=!1,submitLabel:ee="Sign in",submittingLabel:ae="Signing in...",closeLabel:le="Close",signOutLabel:ge="Sign out",showClose:F=!1,showSignOut:C=!1,error:k,message:I,className:P,onSubmit:K,onClose:L,onSignOut:O}){const q=G||Q,E=q||Y||!String(g||"").trim()||!String(x||"").trim(),X=ne=>{ne.preventDefault(),!E&&K()};return r.jsxs("form",{className:gp("af-gateway-signin",P),onSubmit:X,children:[r.jsxs("div",{className:"af-gateway-signin__hero",children:[r.jsxs("div",{children:[r.jsx("div",{className:"af-gateway-signin__kicker",children:e}),r.jsx("h2",{children:t}),n?r.jsx("p",{children:n}):null]}),r.jsx("div",{className:"af-gateway-signin__mark","aria-hidden":"true",children:"↔"})]}),r.jsxs("div",{className:"af-gateway-signin__status-row",children:[r.jsx("span",{className:gp("af-gateway-signin__status",`af-gateway-signin__status--${a}`),children:i}),l?r.jsx("span",{className:"af-gateway-signin__source",children:l}):null]}),r.jsxs("div",{className:"af-gateway-signin__form",children:[u?r.jsxs(r.Fragment,{children:[r.jsx("label",{className:"af-gateway-signin__label",htmlFor:"gateway-session-url",children:"Gateway URL"}),r.jsx("input",{id:"gateway-session-url",value:d,onChange:ne=>p==null?void 0:p(ne.target.value),placeholder:m,autoComplete:"url",disabled:q})]}):null,r.jsx("label",{className:"af-gateway-signin__label",htmlFor:"gateway-session-user",children:"Gateway user"}),r.jsx("input",{id:"gateway-session-user",value:g,onChange:ne=>w(ne.target.value),placeholder:v,autoComplete:"username",disabled:q}),r.jsx("label",{className:"af-gateway-signin__label",htmlFor:"gateway-session-token",children:"Gateway token"}),r.jsxs("div",{className:"af-gateway-signin__token-input",children:[r.jsx("input",{id:"gateway-session-token",type:S?"text":"password",value:x,onChange:ne=>R(ne.target.value),placeholder:N,autoComplete:"current-password",disabled:q}),r.jsx("button",{className:"af-gateway-signin__secondary",type:"button",onClick:()=>T==null?void 0:T(!S),disabled:q,children:S?"Hide":"Show"})]}),r.jsx("label",{className:"af-gateway-signin__label",children:"Browser session"}),r.jsxs("label",{className:"af-gateway-signin__checkbox",children:[r.jsx("input",{type:"checkbox",checked:!!z,onChange:ne=>D==null?void 0:D(ne.target.checked),disabled:q}),H]})]}),k?r.jsx("div",{className:"af-gateway-signin__message af-gateway-signin__message--error",children:k}):null,!k&&I?r.jsx("div",{className:"af-gateway-signin__message af-gateway-signin__message--ok",children:I}):null,r.jsxs("div",{className:"af-gateway-signin__actions",children:[F?r.jsx("button",{className:"af-gateway-signin__secondary",type:"button",onClick:L,disabled:q,children:le}):null,C?r.jsx("button",{className:"af-gateway-signin__secondary",type:"button",onClick:()=>void(O==null?void 0:O()),disabled:q,children:ge}):null,r.jsx("button",{className:"af-gateway-signin__primary",type:"submit",disabled:E,children:Q?ae:ee})]})]})}function r0(e){return e==="light"?"Light":"Dark"}function s0(e){const t=e.themes&&e.themes.length?e.themes:Sv,n=e.showSwatches!==!1,i=e.variant||"panel",a=_.useMemo(()=>{const u={};for(const d of t)u[d.id]=d;return u},[t]),l=_.useMemo(()=>t.map(u=>({value:u.id,label:u.label,group:r0(u.group)})),[t]);return r.jsx(uu,{value:e.value,options:l,placeholder:e.placeholder||"Select theme…",disabled:e.disabled===!0,searchable:!0,allowCustom:!1,clearable:!1,variant:i,className:e.className,triggerClassName:e.triggerClassName,onChange:u=>e.onChange(String(u||"").trim()),renderValue:(u,d)=>{const m=String(d||"").trim(),p=a[m],g=(p==null?void 0:p.label)||m||e.placeholder||"Select theme…",v=(p==null?void 0:p.swatches)||null,w=!m;return r.jsxs("span",{className:"af-theme-value",children:[r.jsx("span",{className:`af-theme-label ${w?"af-theme-label--placeholder":""}`.trim(),children:g}),n&&v?r.jsx("span",{className:"af-theme-swatches","aria-hidden":"true",children:v.map((x,N)=>r.jsx("span",{className:"af-theme-swatch",style:{background:x}},`${m}:${N}`))}):null]})},renderOption:(u,d)=>{const m=String(u.value||"").trim(),p=a[m],g=(p==null?void 0:p.swatches)||null;return r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"af-theme-option-label",children:u.label}),r.jsxs("span",{className:"af-theme-option-right",children:[n&&g?r.jsx("span",{className:"af-theme-swatches","aria-hidden":"true",children:g.map((v,w)=>r.jsx("span",{className:"af-theme-swatch",style:{background:v}},`${m}:${w}`))}):null,d.selected?r.jsx("span",{className:"af-select-check",children:"✓"}):null]})]})}})}function i0(e){const t=e.scales&&e.scales.length?e.scales:L_,n=e.variant||"panel",i=_.useMemo(()=>t.map(a=>({value:a.id,label:a.label})),[t]);return r.jsx(uu,{value:e.value,options:i,placeholder:e.placeholder||"Font size…",disabled:e.disabled===!0,searchable:!1,allowCustom:!1,clearable:!1,variant:n,className:e.className,triggerClassName:e.triggerClassName,onChange:a=>e.onChange(String(a||"").trim())})}function o0(e){const t=e.densities&&e.densities.length?e.densities:O_,n=e.variant||"panel",i=_.useMemo(()=>t.map(a=>({value:a.id,label:a.label})),[t]);return r.jsx(uu,{value:e.value,options:i,placeholder:e.placeholder||"Header size…",disabled:e.disabled===!0,searchable:!1,allowCustom:!1,clearable:!1,variant:n,className:e.className,triggerClassName:e.triggerClassName,onChange:a=>e.onChange(String(a||"").trim())})}const a0=new Set(["board","inbox","server","agent","playCircle","list","gear"]);function l0(e){switch(e){case"chat":return r.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"});case"plus":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 5v14"}),r.jsx("path",{d:"M5 12h14"})]});case"history":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"12",cy:"12",r:"9"}),r.jsx("path",{d:"M12 7v5l3 3"})]});case"refresh":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M21 12a9 9 0 0 0-15.5-6.4L3 8"}),r.jsx("path",{d:"M3 3v5h5"}),r.jsx("path",{d:"M3 12a9 9 0 0 0 15.5 6.4L21 16"}),r.jsx("path",{d:"M21 21v-5h-5"})]});case"settings":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4 6h16"}),r.jsx("circle",{cx:"8",cy:"6",r:"2"}),r.jsx("path",{d:"M4 12h16"}),r.jsx("circle",{cx:"16",cy:"12",r:"2"}),r.jsx("path",{d:"M4 18h16"}),r.jsx("circle",{cx:"10",cy:"18",r:"2"})]});case"user":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"12",cy:"8",r:"4"}),r.jsx("path",{d:"M4 21a8 8 0 0 1 16 0"})]});case"bot":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 2v3"}),r.jsx("rect",{x:"5",y:"6",width:"14",height:"14",rx:"3"}),r.jsx("circle",{cx:"9",cy:"13",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"15",cy:"13",r:"1",fill:"currentColor",stroke:"none"}),r.jsx("path",{d:"M9 17h6"})]});case"paperclip":return r.jsx("path",{d:"M21.44 11.05l-9.19 9.19a5.5 5.5 0 0 1-7.78-7.78l9.19-9.19a3.5 3.5 0 0 1 4.95 4.95l-9.2 9.19a1.5 1.5 0 0 1-2.12-2.12l8.49-8.48"});case"mic":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3z"}),r.jsx("path",{d:"M19 11a7 7 0 0 1-14 0"}),r.jsx("path",{d:"M12 18v4"}),r.jsx("path",{d:"M8 22h8"})]});case"speaker":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M11 5L6 9H2v6h4l5 4V5z"}),r.jsx("path",{d:"M15.5 8.5a5 5 0 0 1 0 7"}),r.jsx("path",{d:"M18 6a9 9 0 0 1 0 12"})]});case"pause":return r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",fill:"currentColor",stroke:"none"}),r.jsx("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",fill:"currentColor",stroke:"none"})]});case"terminal":return r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",ry:"2"}),r.jsx("path",{d:"M7 9l3 3-3 3"}),r.jsx("path",{d:"M12 15h5"})]});case"edit":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 20h9"}),r.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]});case"download":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),r.jsx("path",{d:"M7 10l5 5 5-5"}),r.jsx("path",{d:"M12 15V3"})]});case"loader":return r.jsx("path",{d:"M21 12a9 9 0 1 1-3.3-6.9"});case"info":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"12",cy:"12",r:"10"}),r.jsx("path",{d:"M12 16v-4"}),r.jsx("circle",{cx:"12",cy:"8",r:"0.75",fill:"currentColor",stroke:"none"})]});case"warning":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 3l10 18H2L12 3z"}),r.jsx("path",{d:"M12 9v4"}),r.jsx("circle",{cx:"12",cy:"17",r:"0.75",fill:"currentColor",stroke:"none"})]});case"error":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"12",cy:"12",r:"10"}),r.jsx("path",{d:"M15 9l-6 6"}),r.jsx("path",{d:"M9 9l6 6"})]});case"copy":return r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),r.jsx("path",{d:"M5 15V5a2 2 0 0 1 2-2h10"})]});case"check":return r.jsx("path",{d:"M20 6L9 17l-5-5"});case"x":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M18 6L6 18"}),r.jsx("path",{d:"M6 6l12 12"})]});case"chevronDown":return r.jsx("path",{d:"M6 9l6 6 6-6"});case"chevronRight":return r.jsx("path",{d:"M9 18l6-6-6-6"});case"trash":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 6h18"}),r.jsx("path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),r.jsx("path",{d:"M6 6l1 16h10l1-16"}),r.jsx("path",{d:"M10 11v6"}),r.jsx("path",{d:"M14 11v6"})]});case"send":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M22 2L11 13"}),r.jsx("path",{d:"M22 2L15 22l-4-9-9-4 20-7z"})]});case"thumbsUp":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M7 10v11"}),r.jsx("path",{d:"M7 10l4.5-8a2 2 0 0 1 3.6 1.5L14 8h5.2a2 2 0 0 1 2 2.4l-1.6 8a2 2 0 0 1-2 1.6H7"})]});case"thumbsDown":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M17 14V3"}),r.jsx("path",{d:"M17 14l-4.5 8a2 2 0 0 1-3.6-1.5L10 16H4.8a2 2 0 0 1-2-2.4l1.6-8a2 2 0 0 1 2-1.6H17"})]});case"thumbsUpFilled":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M7 10v11"}),r.jsx("path",{d:"M7 10l4.5-8a2 2 0 0 1 3.6 1.5L14 8h5.2a2 2 0 0 1 2 2.4l-1.6 8a2 2 0 0 1-2 1.6H7z",fill:"currentColor",stroke:"none"})]});case"thumbsDownFilled":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M17 14V3"}),r.jsx("path",{d:"M17 14l-4.5 8a2 2 0 0 1-3.6-1.5L10 16H4.8a2 2 0 0 1-2-2.4l1.6-8a2 2 0 0 1 2-1.6H17z",fill:"currentColor",stroke:"none"})]});case"board":return r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"1.5",y:"2",width:"3.6",height:"12",rx:"1"}),r.jsx("rect",{x:"6.2",y:"2",width:"3.6",height:"8.5",rx:"1"}),r.jsx("rect",{x:"10.9",y:"2",width:"3.6",height:"5.5",rx:"1"})]});case"inbox":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M2 9.5 L4 3.5 h8 l2 6"}),r.jsx("path",{d:"M2 9.5 v3 h12 v-3"}),r.jsx("path",{d:"M2 9.5 h3.4 l1 1.6 h3.2 l1-1.6 H14"})]});case"server":return r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2",y:"2.5",width:"12",height:"4.6",rx:"1.2"}),r.jsx("rect",{x:"2",y:"8.9",width:"12",height:"4.6",rx:"1.2"}),r.jsx("circle",{cx:"4.6",cy:"4.8",r:"0.8",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"4.6",cy:"11.2",r:"0.8",fill:"currentColor",stroke:"none"})]});case"agent":return r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"3",y:"4.5",width:"10",height:"8",rx:"2"}),r.jsx("path",{d:"M8 4.5V2.2"}),r.jsx("circle",{cx:"8",cy:"1.8",r:"0.9",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"5.8",cy:"8.4",r:"0.9",fill:"currentColor",stroke:"none"}),r.jsx("circle",{cx:"10.2",cy:"8.4",r:"0.9",fill:"currentColor",stroke:"none"})]});case"playCircle":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),r.jsx("path",{d:"M6.5 5.6 L11 8 L6.5 10.4 Z",fill:"currentColor",stroke:"none"})]});case"list":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M2.5 4h11"}),r.jsx("path",{d:"M2.5 8h11"}),r.jsx("path",{d:"M2.5 12h7"})]});case"gear":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"2.2"}),r.jsx("path",{d:"M8 1.6v2"}),r.jsx("path",{d:"M8 12.4v2"}),r.jsx("path",{d:"M1.6 8h2"}),r.jsx("path",{d:"M12.4 8h2"}),r.jsx("path",{d:"M3.5 3.5l1.4 1.4"}),r.jsx("path",{d:"M11.1 11.1l1.4 1.4"}),r.jsx("path",{d:"M12.5 3.5l-1.4 1.4"}),r.jsx("path",{d:"M4.9 11.1l-1.4 1.4"})]});case"sparkle":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),r.jsx("path",{d:"M18.5 15.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8z"})]});case"contrast":return r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"12",cy:"12",r:"9"}),r.jsx("path",{d:"M12 3a9 9 0 0 1 0 18z",fill:"currentColor",stroke:"none"})]});case"logout":return r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),r.jsx("path",{d:"M16 17l5-5-5-5"}),r.jsx("path",{d:"M21 12H9"})]});default:return null}}function Nn({name:e,size:t=16,className:n,title:i,...a}){const l=i?void 0:!0,u=a0.has(e);return r.jsxs("svg",{width:t,height:t,viewBox:u?"0 0 16 16":"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:u?1.4:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,"aria-hidden":l,role:i?"img":"presentation",...a,children:[i?r.jsx("title",{children:i}):null,l0(e)]})}async function P_(e="/api/connection/gateway"){const t=await fetch(e),n=await t.json().catch(()=>null);if(!t.ok){const i=n&&typeof n=="object"&&n.detail?String(n.detail):`HTTP ${t.status}`;throw new Error(i)}return n}async function c0(e,t="/api/connection/gateway"){const n=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),i=await n.json().catch(()=>null);if(!n.ok){const a=i&&typeof i=="object"&&i.detail?String(i.detail):`HTTP ${n.status}`;throw new Error(a)}return i}async function Nv(e="/api/connection/gateway"){const t=await fetch(e,{method:"DELETE"});if(!t.ok){const n=await t.json().catch(()=>({})),i=n&&typeof n=="object"&&n.detail?String(n.detail):`HTTP ${t.status}`;throw new Error(i)}}function qh(e){let t=String(e||"").trim();for(let n=0;n<2&&t;n+=1){try{const l=JSON.parse(t);if(typeof l=="string"&&l!==t){t=l.trim();continue}}catch{}const i=t[0],a=t[t.length-1];if(i==='"'&&a==='"'||i==="'"&&a==="'"){t=t.slice(1,-1).trim();continue}break}return t.replace(/\/+$/,"")}function Cv(e){var l,u;if(!e)return{label:"Signed out",tone:"warn"};if(!e.has_session)return{label:"Signed out",tone:"warn"};const t=e.gateway||{},n=(l=t.principal)==null?void 0:l.user_id,i=(u=t.principal)==null?void 0:u.runtime_id;if(t.ok&&n)return{label:`Signed in as ${n}${i?` · runtime ${i}`:""}`,tone:"ok"};if(t.ok)return{label:"Signed in",tone:"ok"};const a=t.error||t.detail;return typeof a=="string"&&a.trim()?{label:"Session rejected — sign in again",tone:"err"}:{label:"Sign in required",tone:"err"}}function u0(e){const t=e.connectionPath||"/api/connection/gateway",[n,i]=_.useState(!1),[a,l]=_.useState(!1),[u,d]=_.useState(null),[m,p]=_.useState(!1);_.useEffect(()=>{e.isOpen||p(!1)},[e.isOpen]);const[g,v]=_.useState(e.defaultGatewayUrl||"http://127.0.0.1:8080"),[w,x]=_.useState("admin"),[N,S]=_.useState(""),[R,T]=_.useState(!1),[z,H]=_.useState(!0),[D,G]=_.useState(""),[Q,Y]=_.useState(""),ee=_.useMemo(()=>Cv(u),[u]),ae=C=>{var k;d(C),(k=e.onStatusChange)==null||k.call(e,C)},le=_.useRef(!1);if(_.useEffect(()=>{var k;if(!e.isOpen)return;const C=!le.current;if(le.current=!0,C&&e.initialStatus!==void 0&&e.initialStatus!==null){const I=e.initialStatus;ae(I),typeof I.gateway_url=="string"&&I.gateway_url.trim()&&v(qh(I.gateway_url));const P=(k=I.gateway)==null?void 0:k.principal;P!=null&&P.user_id&&x(P.user_id);return}i(!0),G(""),P_(t).then(I=>{var K;ae(I),typeof I.gateway_url=="string"&&I.gateway_url.trim()&&v(qh(I.gateway_url));const P=(K=I.gateway)==null?void 0:K.principal;P!=null&&P.user_id&&x(P.user_id)}).catch(I=>G(`Failed to load connection status: ${String((I==null?void 0:I.message)||I)}`)).finally(()=>i(!1))},[e.isOpen]),_.useEffect(()=>{if(!e.isOpen)return;const C=k=>{k.key==="Escape"&&!k.defaultPrevented&&!e.blocking&&(k.preventDefault(),e.onClose())};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[e.isOpen,e.blocking,e.onClose]),!e.isOpen||m)return null;const ge=async()=>{l(!0),G(""),Y("");try{const C=qh(g);v(C);const k=await c0({gateway_url:C,gateway_user_id:w,gateway_token:N,persist:z},t);ae(k),S(""),p(!0),e.onClose()}catch(C){G(String((C==null?void 0:C.message)||C))}finally{l(!1)}},F=async()=>{l(!0),G(""),Y("");try{await Nv(t),S("");const C=await P_(t).catch(()=>null);ae(C),Y("Signed out. This browser no longer holds a gateway session.")}catch(C){G(String((C==null?void 0:C.message)||C))}finally{l(!1)}};return r.jsx("div",{className:"af-connect-overlay",role:"presentation",onMouseDown:C=>{!e.blocking&&C.target===C.currentTarget&&e.onClose()},children:r.jsx("div",{className:"af-connect-modal",role:"dialog","aria-modal":"true","aria-label":"Gateway connection",children:r.jsx(n0,{kicker:`${e.appName||"AbstractFramework"} connection`,title:"Connect this browser to AbstractGateway",description:"Sign in with a Gateway user token. The app exchanges it for an HTTP-only browser session and never stores the raw token.",statusLabel:ee.label,statusTone:ee.tone,tokenSourceLabel:u!=null&&u.has_session?"token: browser session":"token: missing",showGatewayUrl:!0,gatewayUrl:g,onGatewayUrlChange:C=>v(C),userId:w,onUserIdChange:x,token:N,tokenPlaceholder:u!=null&&u.has_session?"(browser session already signed in)":"Paste Gateway user token",showToken:R,onTokenChange:S,onShowTokenChange:T,remember:z,rememberLabel:"Keep this browser signed in",onRememberChange:H,loading:n,submitting:a,submittingLabel:"Signing in...",showClose:!e.blocking,onClose:e.onClose,showSignOut:!e.blocking&&!!(u!=null&&u.has_session),onSignOut:F,error:D,message:Q,onSubmit:ge})})})}function d0(e){return!!(e&&e.ok===!0&&e.has_session===!0)}function f0(e){const t=e||{},n=t.connectionPath||"/api/connection/gateway",i=t.variant||"dismissable",a=_.useRef(t.onStatusChange);a.current=t.onStatusChange;const l=_.useRef(i);l.current=i;const u=_.useRef(!!t.autoOpenMidSession);u.current=!!t.autoOpenMidSession;const[d,m]=_.useState(null),[p,g]=_.useState("loading"),[v,w]=_.useState(!1),x=_.useRef(!1),N=_.useRef(!1),S=_.useRef("loading"),R=_.useRef("none"),T=_.useRef(!1),z=_.useRef(0),H=_.useCallback(k=>{var P;z.current+=1,m(k),(P=a.current)==null||P.call(a,k);const I=d0(k);if(I)g("connected"),S.current="connected",x.current=!1,R.current="none",N.current||w(!1);else if(k!==null){const K=S.current;g("disconnected"),S.current="disconnected",K!=="disconnected"&&(R.current=T.current?"signout":K==="connected"?"mid":"boot");const L=l.current==="blocking"||R.current!=="mid"||u.current;!x.current&&L&&w(!0)}k!==null&&(N.current=I)},[]),D=_.useCallback(async()=>{const k=z.current;try{const I=await P_(n);if(z.current!==k)return;H(I)}catch{if(z.current!==k)return;H(null)}},[n,H]),[G,Q]=_.useState(!1),[Y,ee]=_.useState(null),ae=_.useCallback(async()=>{Q(!0),ee(null),z.current+=1;let k=null;try{await Nv(n)}catch(I){k=String((I==null?void 0:I.message)||I||"Sign-out request failed")}T.current=!0;try{await D()}finally{T.current=!1}ee(k),Q(!1)},[n,D]),le=_.useRef(!1);_.useEffect(()=>{le.current||(le.current=!0,D())},[D]);const ge=_.useCallback(()=>{w(!0)},[]),F=_.useCallback(()=>{const k=S.current;i==="blocking"&&k==="disconnected"||(k==="disconnected"&&(x.current=!0),w(!1))},[i]),C=_.useMemo(()=>({isOpen:v,onClose:F,blocking:i==="blocking"&&p!=="connected",appName:t.appName,connectionPath:n,defaultGatewayUrl:t.defaultGatewayUrl,initialStatus:d,onStatusChange:H}),[v,F,i,p,t.appName,n,t.defaultGatewayUrl,d,H]);return{status:d,phase:p,connected:p==="connected",modalOpen:v,signingOut:G,signOutError:Y,openModal:ge,refresh:D,signOut:ae,modalProps:C}}function m0(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`steer-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function h0(){const e=[];try{if(typeof document>"u")return e;for(const t of String(document.cookie||"").split(";")){const n=t.indexOf("=");if(n<0||!t.slice(0,n).trim().endsWith("_gateway_csrf"))continue;const a=t.slice(n+1).trim();let l=a;try{l=decodeURIComponent(a)}catch{}l&&!e.includes(l)&&e.push(l)}}catch{}return e}async function _0(e){const t=e.commandsPath||"/api/gateway/commands",n=m0(),i=JSON.stringify({command_id:n,run_id:e.runId,type:"inject_guidance",payload:{guidance:e.guidance}}),a=e.csrfToken!==void 0?[e.csrfToken]:h0();a.length===0&&a.push("");let l=null;for(const u of a){const d=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...u?{"x-abstract-csrf":u}:{}},body:i}),m=await d.json().catch(()=>null);if(!d.ok){const p=m&&typeof m=="object"&&m.detail?String(m.detail):`HTTP ${d.status}`;if(l=new Error(p),d.status===403&&m&&typeof m=="object"&&m.reason_code==="csrf_required")continue;throw l}return{accepted:!!(m!=null&&m.accepted),duplicate:!!(m!=null&&m.duplicate),seq:Number((m==null?void 0:m.seq)??0)}}throw l||new Error("Steer submit failed")}function g0(e){const[t,n]=_.useState(""),[i,a]=_.useState({kind:"idle"}),l=_.useRef(!1),u=_.useRef(0);_.useEffect(()=>{u.current+=1,a({kind:"idle"})},[e.runId]);const d=!e.disabled&&t.trim().length>0&&i.kind!=="sending",m=_.useMemo(()=>e.parked?"Run is waiting — your guidance delivers at its next wake (steers do not wake runs).":"Delivers at the run's next loop boundary.",[e.parked]),p=async()=>{var x;const v=t.trim();if(!v||l.current||e.disabled)return;l.current=!0;const w=u.current;a({kind:"sending"});try{const N=e.submit?await e.submit(e.runId,v):await _0({runId:e.runId,guidance:v,commandsPath:e.commandsPath});if(u.current!==w)return;if(!N.accepted&&!N.duplicate){a({kind:"error",detail:"The gateway did not accept this steer (accepted=false)."});return}a({kind:"queued",seq:N.seq,duplicate:N.duplicate}),n(""),(x=e.onSent)==null||x.call(e,{...N,guidance:v})}catch(N){u.current===w&&a({kind:"error",detail:String((N==null?void 0:N.message)||N)})}finally{l.current=!1}},g=v=>{v.key==="Enter"&&(v.metaKey||v.ctrlKey)&&(v.preventDefault(),p())};return r.jsxs("div",{className:`af-steer${e.className?` ${e.className}`:""}`,children:[r.jsxs("div",{className:"af-steer__row",children:[r.jsx("textarea",{className:"af-steer__input",value:t,rows:2,placeholder:e.placeholder||"Steer this run…","aria-label":e.ariaLabel||"Steer message",disabled:e.disabled||i.kind==="sending",onChange:v=>{n(v.target.value),(i.kind==="error"||i.kind==="queued")&&a({kind:"idle"})},onKeyDown:g}),r.jsx("button",{type:"button",className:"af-steer__send",disabled:!d,onClick:()=>void p(),title:"Send guidance (Cmd/Ctrl+Enter)",children:i.kind==="sending"?"Sending…":"Steer"})]}),r.jsx("div",{className:"af-steer__status",role:"status","aria-live":"polite",children:i.kind==="queued"?r.jsxs("span",{className:"af-steer__ok",children:[i.duplicate?`Already queued (seq ${i.seq}).`:`Queued (seq ${i.seq}).`," ",m," ","Watch for the steer_seen ack in the run ledger."]}):i.kind==="error"?r.jsx("span",{className:"af-steer__err",children:i.detail}):r.jsx("span",{className:"af-steer__hint",children:m})})]})}function p0(e){const t=e.closeOnEscape!==!1,n=_.useRef(null);return _.useEffect(()=>{if(!e.open||!t)return;const i=a=>{a.key!=="Escape"||a.defaultPrevented||(a.preventDefault(),e.onClose())};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[e.open,t,e.onClose]),_.useEffect(()=>{const i=n.current;i&&(e.open?i.removeAttribute("inert"):i.setAttribute("inert",""))},[e.open]),r.jsxs("div",{ref:n,className:`af-drawer${e.open?" af-drawer--open":""}${e.className?` ${e.className}`:""}`,style:{width:e.width||420,top:e.topOffset||0,display:e.open?void 0:"none"},role:"complementary","aria-label":e.label,"aria-hidden":e.open?void 0:!0,children:[e.title!==void 0?r.jsxs("div",{className:"af-drawer__header",children:[r.jsx("div",{className:"af-drawer__title",children:e.title}),r.jsxs("div",{className:"af-drawer__header-actions",children:[e.headerActions,r.jsx("button",{type:"button",className:"af-drawer__close","aria-label":"Close panel",onClick:e.onClose,children:"×"})]})]}):null,r.jsx("div",{className:"af-drawer__body",children:e.children})]})}const y0={name:"AbstractFramework",website:"https://abstractframework.ai",author:"Laurent-Philippe Albou, PhD",years:"2023-2026",copyright:"© 2023-2026 Laurent-Philippe Albou, PhD. Released under the MIT License.",contact_email:"contact@abstractframework.ai"},v0={abstractframework:{name:"AbstractFramework",website:"https://abstractframework.ai",repo:"https://github.com/lpalbou/AbstractFramework",docs:"https://github.com/lpalbou/AbstractFramework/tree/main/docs",issues:"https://github.com/lpalbou/AbstractFramework/issues",feedback:"https://github.com/lpalbou/AbstractFramework/issues/new?labels=feedback"},abstractgateway:{name:"AbstractGateway",website:"https://abstractframework.ai/gateway",repo:"https://github.com/lpalbou/AbstractGateway",docs:"https://www.lpalbou.info/AbstractGateway/",issues:"https://github.com/lpalbou/AbstractGateway/issues",feedback:"https://github.com/lpalbou/AbstractGateway/issues/new?labels=feedback"},abstractcode:{name:"AbstractCode",website:"https://abstractframework.ai/code",repo:"https://github.com/lpalbou/AbstractCode",docs:"https://github.com/lpalbou/AbstractCode/tree/main/docs",issues:"https://github.com/lpalbou/AbstractCode/issues",feedback:"https://github.com/lpalbou/AbstractCode/issues/new?labels=feedback"},abstractassistant:{name:"AbstractAssistant",website:"https://abstractframework.ai/assistant",repo:"https://github.com/lpalbou/AbstractAssistant",docs:"https://github.com/lpalbou/AbstractAssistant/blob/main/docs/README.md",issues:"https://github.com/lpalbou/AbstractAssistant/issues",feedback:"https://github.com/lpalbou/AbstractAssistant/issues/new?labels=feedback"},abstractflow:{name:"AbstractFlow",website:"https://abstractframework.ai/flow",repo:"https://github.com/lpalbou/AbstractFlow",docs:"https://github.com/lpalbou/AbstractFlow#readme",issues:"https://github.com/lpalbou/AbstractFlow/issues",feedback:"https://github.com/lpalbou/AbstractFlow/issues/new?labels=feedback"},abstractcontinuum:{name:"AbstractContinuum",website:"https://abstractframework.ai",repo:"https://github.com/lpalbou/AbstractContinuum",docs:"https://github.com/lpalbou/AbstractContinuum/tree/main/docs",issues:"https://github.com/lpalbou/AbstractContinuum/issues",feedback:"https://github.com/lpalbou/AbstractContinuum/issues/new?labels=feedback"},abstractentity:{name:"AbstractEntity",website:"https://abstractframework.ai",repo:"https://github.com/lpalbou/AbstractEntity",docs:"https://github.com/lpalbou/AbstractEntity/tree/main/docs",issues:"https://github.com/lpalbou/AbstractEntity/issues",feedback:"https://github.com/lpalbou/AbstractEntity/issues/new?labels=feedback"},abstractobserver:{name:"AbstractObserver",website:"https://abstractframework.ai/observer",repo:"https://github.com/lpalbou/AbstractObserver",docs:"https://github.com/lpalbou/AbstractObserver#readme",issues:"https://github.com/lpalbou/AbstractObserver/issues",feedback:"https://github.com/lpalbou/AbstractObserver/issues/new?labels=feedback"},abstractcore:{name:"AbstractCore",website:"https://www.abstractcore.ai",repo:"https://github.com/lpalbou/AbstractCore",docs:"https://github.com/lpalbou/AbstractCore/tree/main/docs",issues:"https://github.com/lpalbou/AbstractCore/issues",feedback:"https://github.com/lpalbou/AbstractCore/issues/new?labels=feedback"},abstractuic:{name:"AbstractUIC",website:"https://abstractframework.ai",repo:"https://github.com/lpalbou/AbstractUIC",docs:"https://github.com/lpalbou/AbstractUIC/tree/main/docs",issues:"https://github.com/lpalbou/AbstractUIC/issues",feedback:"https://github.com/lpalbou/AbstractUIC/issues/new?labels=feedback"}},w0={framework:y0,apps:v0},Im=w0;function x0(){return Object.keys(Im.apps).sort()}function b0(e,t){const n=Object.prototype.hasOwnProperty.call(Im.apps,e)?Im.apps[e]:void 0;if(!n)throw new Error(`appIdentity: unknown application id "${e}" (known: ${x0().join(", ")})`);return{id:e,name:n.name,version:t,website:n.website,repo:n.repo,docs:n.docs,issues:n.issues,feedback:n.feedback}}function j0(e,t){const n=Im.framework,i=[["Application",`${e.name} ${e.version}`],["Part of",`${n.name} — ${n.website}`],["Author",`${n.author} (${n.years})`],["Copyright",n.copyright],["Website",e.website],["Source",e.repo],["Documentation",e.docs],["Report an issue",e.issues],["Give feedback",e.feedback],["Contact",n.contact_email]];for(const[a,l]of t||[])i.push([String(a),String(l)]);return i}function Vh(e){return typeof e=="string"?e.trim():""}function pp(e,t){if(t!=null)return[["Gateway",`unavailable (${String(t).trim()||"unknown error"})`]];const n=e&&typeof e=="object"&&!Array.isArray(e)?e:{},i=Vh(n.abstractgateway);if(!i)return[["Gateway","unavailable (the gateway did not report its version)"]];const a=Vh(n.abstractframework),l=[["Gateway",`AbstractGateway ${i}`],["Gateway framework",a?`AbstractFramework ${a}`:"not installed on the gateway host"]],u=n.packages&&typeof n.packages=="object"&&!Array.isArray(n.packages)?n.packages:{},d=Object.keys(u).filter(m=>m!=="abstractgateway"&&m!=="abstractframework").sort((m,p)=>m<p?-1:m>p?1:0);for(const m of d){const p=Vh(u[m]);p&&l.push([`Gateway package ${m}`,p])}return l}const S0='a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';function k0(e,t,n){if(e.key!=="Tab"||!t)return;const i=Array.from(t.querySelectorAll(S0));if(i.length===0){e.preventDefault();return}const a=i[0],l=i[i.length-1],u=!!n&&t.contains(n);e.shiftKey?(n===a||!u)&&(e.preventDefault(),l.focus()):(n===l||!u)&&(e.preventDefault(),a.focus())}const N0=/https?:\/\/[^\s<>"]+/g;function C0(e,t){if(e==="Contact")return[{text:t,href:`mailto:${t}`}];const n=[];let i=0;for(const a of t.matchAll(N0)){const l=a.index??0;l>i&&n.push({text:t.slice(i,l)}),n.push({text:a[0],href:a[0]}),i=l+a[0].length}return(i<t.length||n.length===0)&&n.push({text:t.slice(i)}),n}function $0({label:e,value:t}){return r.jsx("span",{children:C0(e,t).map((n,i)=>n.href===void 0?r.jsx(pe.Fragment,{children:n.text},i):n.href.startsWith("mailto:")?r.jsx("a",{className:"af-about__link",href:n.href,children:n.text},i):r.jsx("a",{className:"af-about__link",href:n.href,target:"_blank",rel:"noopener noreferrer",children:n.text},i))})}function E0(e){const t=_.useRef(null),n=_.useRef(null),i=_.useId(),a=_.useRef(e.onClose);if(a.current=e.onClose,_.useEffect(()=>{var p;if(!e.open)return;const d=document.activeElement;(p=t.current)==null||p.focus();const m=g=>{if(!g.defaultPrevented){if(g.key==="Escape"){g.preventDefault(),a.current();return}k0(g,n.current,document.activeElement)}};return window.addEventListener("keydown",m),()=>{window.removeEventListener("keydown",m),d&&typeof d.focus=="function"&&d.focus()}},[e.open]),!e.open)return null;const l=e.title||`About ${e.identity.name}`,u=j0(e.identity,e.extraRows);return r.jsx("div",{className:"af-appearance-overlay af-about-overlay",onClick:e.onClose,role:"presentation",children:r.jsxs("div",{ref:n,className:"af-appearance af-about",role:"dialog","aria-modal":"true","aria-labelledby":i,onClick:d=>d.stopPropagation(),children:[r.jsx("div",{className:"af-appearance__title",id:i,children:l}),r.jsx("dl",{className:"af-about__rows",children:u.map(([d,m],p)=>r.jsxs("div",{className:"af-about__row",children:[r.jsx("dt",{className:"af-about__label",children:d}),r.jsx("dd",{className:"af-about__value",children:r.jsx($0,{label:d,value:m})})]},`${p}:${d}`))}),r.jsx("div",{className:"af-appearance__actions",children:r.jsx("button",{ref:t,type:"button",className:"af-appearance__close",onClick:e.onClose,children:"Close"})})]})})}function A0(e){const{connection:t}=e,n=t.phase,i=t.signingOut===!0,[a,l]=_.useState(!1),u=e.about,d=i?"Signing out…":n==="connected"?"Disconnect":n==="loading"?"Connecting…":"Connect",m=n==="connected"?"Disconnect from gateway":n==="loading"?"Checking gateway session…":"Connect to gateway";return r.jsxs("div",{className:`af-topbar${e.className?` ${e.className}`:""}`,role:"group","aria-label":"App actions",children:[e.assistant?r.jsx("button",{type:"button",className:`af-topbar__btn${e.assistant.open?" is-active":""}`,"aria-pressed":e.assistant.open,"aria-label":e.assistant.label||"Open assistant",title:e.assistant.label||"Assistant",onClick:e.assistant.onToggle,children:r.jsx(Nn,{name:"sparkle",size:16})}):null,e.appearance?r.jsx("button",{type:"button",className:"af-topbar__btn","aria-label":e.appearance.label||"Appearance (theme and typography)",title:e.appearance.label||"Appearance",onClick:e.appearance.onOpen,children:r.jsx(Nn,{name:"contrast",size:16})}):null,u?r.jsx("button",{type:"button",className:"af-topbar__btn af-topbar__btn--about","aria-label":u.label||`About ${u.identity.name}`,title:u.label||"About","aria-haspopup":"dialog",onClick:()=>{var p;l(!0),(p=u.onOpen)==null||p.call(u)},children:r.jsx(Nn,{name:"info",size:16})}):null,e.extraActions,r.jsxs("button",{type:"button",className:`af-topbar__pill af-topbar__pill--${n}`,onClick:n==="connected"?t.onDisconnect:t.onConnect,disabled:i,title:m,"aria-label":m,children:[r.jsx("span",{className:`af-topbar__dot af-topbar__dot--${n}`,"aria-hidden":"true"}),r.jsx("span",{className:"af-topbar__pill-label",children:d})]}),u?r.jsx(E0,{open:a,onClose:()=>l(!1),identity:u.identity,extraRows:u.extraRows}):null]})}const Em={theme:"dark",font_scale:"md",header_density:"standard"};function M0(e){const t=e&&typeof e=="object"?e:{};return{theme:typeof t.theme=="string"&&t.theme?t.theme:Em.theme,font_scale:typeof t.font_scale=="string"&&t.font_scale?t.font_scale:Em.font_scale,header_density:typeof t.header_density=="string"&&t.header_density?t.header_density:Em.header_density}}function T0(e){return`af_appearance_${e}_v1`}function R0(e,t){const n=T0(e),i=_.useMemo(()=>({...Em,...(t==null?void 0:t.defaults)||{}}),[JSON.stringify((t==null?void 0:t.defaults)||{})]),[a,l]=_.useState(()=>{let u=i;try{const d=localStorage.getItem(n)??(t!=null&&t.legacyKey?localStorage.getItem(t.legacyKey):null);d&&(u=M0({...i,...JSON.parse(d)}))}catch{}try{hp(u.theme),_p({font_scale:u.font_scale,header_density:u.header_density})}catch{}return u});return _.useEffect(()=>{hp(a.theme),_p({font_scale:a.font_scale,header_density:a.header_density});try{localStorage.setItem(n,JSON.stringify(a))}catch{}},[n,a]),[a,l]}function L0(e){return _.useEffect(()=>{if(!e.open)return;const t=n=>{n.key!=="Escape"||n.defaultPrevented||(n.preventDefault(),e.onClose())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e.open,e.onClose]),e.open?r.jsx("div",{className:"af-appearance-overlay",onClick:e.onClose,role:"presentation",children:r.jsxs("div",{className:"af-appearance",role:"dialog","aria-modal":"true","aria-label":e.title||"Appearance",onClick:t=>t.stopPropagation(),children:[r.jsx("div",{className:"af-appearance__title",children:e.title||"Appearance"}),r.jsx("div",{className:"af-appearance__note",children:e.note||"Stored locally in this browser, per app."}),r.jsxs("div",{className:"af-appearance__grid",children:[r.jsx("label",{className:"af-appearance__label",children:"Theme"}),r.jsx(s0,{value:e.value.theme,onChange:t=>e.onChange({...e.value,theme:t})}),r.jsx("label",{className:"af-appearance__label",children:"Font size"}),r.jsx(i0,{value:e.value.font_scale,onChange:t=>e.onChange({...e.value,font_scale:t})}),r.jsx("label",{className:"af-appearance__label",children:"Header size"}),r.jsx(o0,{value:e.value.header_density,onChange:t=>e.onChange({...e.value,header_density:t})})]}),r.jsx("div",{className:"af-appearance__actions",children:r.jsx("button",{type:"button",className:"af-appearance__close",onClick:e.onClose,children:"Close"})})]})}):null}const O0={diary:"var(--accent)",question:"#e7b45a",dream:"#c084dd",interest:"#7bd88a",lesson:"#6ea8d8",world_model:"#5eead4"};function yp(e){const t=String(e||"");return t.length>14?`${t.slice(0,10)}…${t.slice(-4)}`:t}function Gh(e){const[t,n]=_.useState(!1),[i,a]=_.useState(null),l=_.useRef(!1),u=typeof e.entryId=="string"&&e.entryId.trim()?e.entryId.trim():null,d=e.kind&&O0[e.kind]||"var(--text-muted)",m=_.useCallback(async()=>{if(!(!u||!e.onOpen||l.current)){l.current=!0,n(!0),a(null);try{await e.onOpen(u)}catch(p){a(String((p==null?void 0:p.message)||p||"could not open"))}finally{l.current=!1,n(!1)}}},[u,e.onOpen]);return!u||!e.onOpen?r.jsxs("span",{className:["af-memory-hint","af-memory-hint--text",e.className||""].filter(Boolean).join(" "),title:e.title,children:[r.jsx("span",{className:"af-memory-hint__dot",style:{background:d},"aria-hidden":"true"}),r.jsx("span",{className:"af-memory-hint__label",children:e.label}),u&&e.showId!==!1?r.jsx("code",{className:"af-memory-hint__id",children:yp(u)}):null]}):r.jsxs("span",{className:["af-memory-hint",e.className||""].filter(Boolean).join(" "),children:[r.jsxs("button",{type:"button",className:"af-memory-hint__btn",onClick:()=>void m(),disabled:t,title:e.title||(e.command?e.command:`open ${u}`),"aria-label":`Open ${e.kind||"memory"} entry: ${e.label}`,children:[r.jsx("span",{className:"af-memory-hint__dot",style:{background:d},"aria-hidden":"true"}),r.jsx("span",{className:"af-memory-hint__label",children:e.label}),e.showId!==!1?r.jsx("code",{className:"af-memory-hint__id",children:yp(u)}):null,r.jsx("span",{className:"af-memory-hint__act","aria-hidden":"true",children:t?"…":"↗"})]}),e.command?r.jsx("code",{className:"af-memory-hint__cmd",children:e.command}):null,i?r.jsx("span",{className:"af-memory-hint__err",role:"alert",children:i}):null]})}const Kh="/api/gateway/automations",P0="/api/gateway/trigger-sources";class vp extends Error{constructor(t){super(t.message),this.name="AutomationApiError",this.status=t.status,this.code=t.code,t.field!==void 0&&(this.field=t.field),t.command_id!==void 0&&(this.command_id=t.command_id)}}function I0(e,t){const n=t&&typeof t=="object"?t.detail:void 0;if(n&&typeof n=="object"&&!Array.isArray(n)){const i=n;if(typeof i.reason_code=="string"&&i.reason_code&&typeof i.message=="string"){const a={status:e,code:i.reason_code,message:i.message};return typeof i.field=="string"&&(a.field=i.field),typeof i.command_id=="string"&&(a.command_id=i.command_id),a}}return{status:e,code:"invalid_response",message:`The gateway answered HTTP ${e} without an automation error envelope.`}}function Yh(e){const t=new URLSearchParams;for(const[i,a]of Object.entries(e))a!==void 0&&t.set(i,String(a));const n=t.toString();return n?`?${n}`:""}function D0(){const e=globalThis.crypto;if(!e||typeof e.randomUUID!="function")throw new Error("automations client: crypto.randomUUID is unavailable; pass options.newId");return e.randomUUID()}function z0(e){const t=(e.baseUrl??"").replace(/\/+$/,""),n=e.newId??D0,i=l=>`${Kh}/${encodeURIComponent(l)}`;async function a(l,u,d){const m={accept:"application/json",...e.headers?e.headers():{}},p={method:l,headers:m};d!==void 0&&(m["content-type"]="application/json",p.body=JSON.stringify(d));const g=await e.fetch(`${t}${u}`,p),v=await g.text();let w,x=!1;if(v)try{w=JSON.parse(v),x=!0}catch{x=!1}if(!g.ok)throw new vp(I0(g.status,w));if(!x||w===null||typeof w!="object")throw new vp({status:g.status,code:"invalid_response",message:`The gateway answered ${l} ${u} with a body that is not a JSON object.`});return w}return{listAutomations:(l={})=>a("GET",`${Kh}${Yh({status:l.status,cursor:l.cursor,limit:l.limit})}`),getAutomation:l=>a("GET",i(l)),createAutomation:l=>a("POST",Kh,l),reviseAutomation:(l,u)=>a("PATCH",i(l),{command_id:u.command_id??n(),...u.expected_revision!==void 0?{expected_revision:u.expected_revision}:{},changes:u.changes}),sendAutomationCommand:(l,u)=>a("POST",`${i(l)}/commands`,{command_id:u.command_id??n(),type:u.type,...u.payload!==void 0?{payload:u.payload}:{}}),listOccurrences:(l,u={})=>a("GET",`${i(l)}/occurrences${Yh({cursor:u.cursor,limit:u.limit})}`),discuss:(l,u)=>a("POST",`${i(l)}/discuss`,{request_id:u.request_id??n(),occurrence_index:u.occurrence_index,prompt:u.prompt}),markSeen:(l,u)=>a("POST",`${i(l)}/seen`,{attention_cursor:u}),listAttention:(l,u={})=>a("GET",`${i(l)}/attention${Yh({cursor:u.cursor,limit:u.limit})}`),listTriggerSources:()=>a("GET",P0)}}const F0=/^([1-9][0-9]*)([smhd])$/,B0={s:["second","seconds"],m:["minute","minutes"],h:["hour","hours"],d:["day","days"]};function _g(e){if(typeof e!="string")return null;const t=F0.exec(e);return t?{amount:Number(t[1]),unit:t[2]}:null}function U0(e){const t=_g(e);if(!t)return`every ${e}`;const[n,i]=B0[t.unit];return t.amount===1?`every ${n}`:`every ${t.amount} ${i}`}function tl(e){if(!e)return"";const t=Date.parse(e);if(Number.isNaN(t))return e;const n=new Date(t).toISOString(),i=n.slice(17,19);return`${n.slice(0,10)} ${n.slice(11,16)}${i==="00"?"":`:${i}`} UTC`}function $v(e){const t=e;if(typeof t.every!="string")return t.start_at?`once at ${tl(t.start_at)}`:"once, now";const n=[`${U0(t.every)} (UTC)`];return typeof t.count=="number"&&n.push(`${t.count} ${t.count===1?"run":"runs"} max`),typeof t.until=="string"&&n.push(`until ${tl(t.until)}`),n.join(" · ")}function gg(e){return e.source_id==="schedule"&&e.source_version===1?$v(e.config):e.source_id==="manual"&&e.source_version===1?"manual runs only":`${e.source_id}@${e.source_version}`}function Ev(e){return e==="growing"?"Growing — each run sees the previous runs":"Independent — each run starts fresh"}const W0={active:"Active",paused:"Paused",completed:"Completed",failed:"Failed",archived:"Archived"},Qc={pause:"automation.pause",resume:"automation.resume",run_now:"automation.run_now",stop_current:"automation.stop_current",archive:"automation.archive"},H0=new Set(["running","waiting","backoff"]);function q0(e,t=[]){return e.current_occurrence!=null}function Av(e){const t=e.current_occurrence;if(!t)return null;const n=t.attempt>1?` (attempt ${t.attempt})`:"";return t.status==="backoff"?`Run #${t.index} waiting to retry (attempt ${t.attempt+1})`:t.status==="admitted"?`Run #${t.index} starting${n}`:`Run #${t.index} running${n}`}function Mv(e,t){const n=Date.parse(e);if(Number.isNaN(n))return"";const i=Math.round((n-t)/6e4);if(i<=0)return"due now";if(i<60)return`in ${i} min`;const a=Math.floor(i/60);return a<24?`in ${a} h${i%60?` ${i%60} min`:""}`:`in ${Math.floor(a/24)} d${a%24?` ${a%24} h`:""}`}function pg(e,t=[],n=!1){const i=new Set(e.capabilities),a=e.status,l=q0(e,t),u=(m,p,g)=>n?{enabled:!1,reason:"Working…"}:e.legacy?{enabled:!1,reason:"Legacy schedule: managed with its existing controls."}:i.has(m)?a==="archived"?{enabled:!1,reason:"Archived: history is kept, nothing runs."}:p?{enabled:!0}:{enabled:!1,reason:g}:{enabled:!1,reason:"Not permitted for this automation."},d=a==="active"||a==="paused";return{pause:u("pause",a==="active",a==="paused"?"Already paused.":"The automation has ended."),resume:u("resume",a==="paused",a==="active"?"Already running on schedule.":"The automation has ended."),run_now:u("run_now",d&&!l,l?"An occurrence is in progress.":"The automation has ended."),stop_current:u("stop_current",l,"Nothing is running."),revise:u("revise",!0,""),archive:u("archive",!0,""),discuss:n?{enabled:!1,reason:"Working…"}:e.legacy?{enabled:!1,reason:"Legacy schedule: discussion is not available."}:i.has("discuss")?{enabled:!0}:{enabled:!1,reason:"Discussion is not permitted for this automation."}}}function V0(e){return e.status==="failed"?"failed":e.waits.length>0||e.status==="waiting"?"waiting":e.notify!==null?"notified":e.status==="running"||e.status==="backoff"?"running":"quiet"}function G0(e){return[...e].sort((t,n)=>t.index-n.index).map(t=>{const n=V0(t),i=`${t.attempts} ${t.attempts===1?"attempt":"attempts"}`,a=n==="failed"?`Failed after ${i}`:n==="waiting"?"Waiting for you":n==="notified"?"Notified":n==="running"?"Running":null,l=t.status==="completed"&&t.attempts>1?`completed after ${i}`:t.status;return{row:t,tone:n,notable:n==="failed"||n==="waiting"||n==="notified",badge:a,statusText:l,canDiscuss:!H0.has(t.status)}})}function K0(e){const t=e.attention.items;return t.length?t[t.length-1].cursor:null}function Tv(e){const t=e.attention,n=[];return t.unseen_count>0&&n.push(`${t.unseen_count} unseen`),t.pending_waits>0&&n.push(`${t.pending_waits} waiting for you`),n.length?n.join(" · "):"nothing new"}const Y0={unauthorized:"Sign in to the gateway to manage automations.",forbidden:"You are not allowed to do this with automations.",automation_not_found:"This automation does not exist (or is not yours).",occurrence_not_found:"That occurrence does not exist.",revision_conflict:"The automation changed since this view loaded. Reload it, then try again.",automation_busy:"An occurrence is already running or queued. Wait for it to finish.",invalid_state:"The automation's current state does not allow this.",identity_conflict:"This request id was already used for a different request.",invalid_request:"The gateway rejected the request as malformed.",invalid_definition:"The automation definition is not valid.",unsupported_feature:"The gateway does not support this yet.",unknown_trigger_source:"The gateway does not know this trigger source.",invalid_response:"The gateway gave an unexpected answer.",invalid_payload:"That answer could not be sent."};function Dm(e){return{title:Y0[e.code]??`The gateway refused the request (${e.code}).`,detail:e.message}}function yg(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.status=="number"&&typeof t.code=="string"&&typeof t.message=="string"}function Rv(e){const t=e.trigger.source_id==="schedule"?e.trigger.config.every:void 0;return{title:e.title,every:typeof t=="string"?t:null,context:e.context_mode}}function X0(e,t){const n=[],i={},a=t.title.trim();a?a.length>120?n.push("Title is at most 120 characters."):a!==e.title&&(i.title=a):n.push("Title is required.");const l=Rv(e);return t.every!==l.every&&t.every!==null&&(_g(t.every)?i.trigger={source_id:e.trigger.source_id,source_version:e.trigger.source_version,config:{...e.trigger.config,every:t.every}}:n.push("Interval must be a whole number of minutes, hours or days.")),t.context!==e.context_mode&&(i.context={mode:t.context}),n.length?{errors:n}:Object.keys(i).length?i:null}const J0=[{label:"every 5 minutes",when:{kind:"every",amount:5,unit:"m"}},{label:"every 30 minutes",when:{kind:"every",amount:30,unit:"m"}},{label:"every hour",when:{kind:"every",amount:1,unit:"h"}},{label:"every 8 hours",when:{kind:"every",amount:8,unit:"h"}},{label:"every 24 hours",when:{kind:"every",amount:24,unit:"h"}},{label:"every 7 days",when:{kind:"every",amount:7,unit:"d"}}];function Xh(e){if(!e)return null;const t=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})(:\d{2})?$/.exec(e.trim());if(!t)return null;const n=`${t[1]}T${t[2]}${t[3]??":00"}Z`;return Number.isNaN(Date.parse(n))?null:n}function Z0(e){const t=e.trim().split(`
|
|
54
|
+
`)[0].trim();return t.length>120?`${t.slice(0,119)}…`:t}function Q0(e){const t=[],n={};if(e.when.kind==="once"){const a=Xh(e.when.at);return a?n.start_at=a:t.push("Pick the date and time (UTC) to run once."),{config:n,errors:t}}const i=e.when.amount;if(!Number.isInteger(i)||i<1?t.push("The interval must be a whole number of at least 1."):n.every=`${i}${e.when.unit}`,e.startAt){const a=Xh(e.startAt);a?n.start_at=a:t.push("First run must be a date and time (UTC).")}if(e.count!==void 0&&(!Number.isInteger(e.count)||e.count<1?t.push("Maximum runs must be a whole number of at least 1."):n.count=e.count),e.until){const a=Xh(e.until);a?n.until=a:t.push("Stop at must be a date and time (UTC).")}return{config:n,errors:t}}function Lv(e,t){const n=[];t.target||n.push("Choose what to run.");const i=e.prompt.trim();i||n.push("Write the task to run.");const a=(e.title??"").trim()||Z0(i);a.length>120&&n.push("Title is at most 120 characters.");const{config:l,errors:u}=Q0(e);if(n.push(...u),n.length||!t.target)return{ok:!1,errors:n};const d={...t.target,input_data:{...t.target.input_data??{},prompt:i}};return{ok:!0,body:{request_id:t.requestId,title:a,target:d,trigger:{source_id:"schedule",source_version:1,config:l},context:{mode:e.context},policy:{tool_approval:e.toolApproval??"auto"}}}}const ej="Tools run without asking (you approve them now by creating this automation)";function tj(e){if(e.kind!=="tool_approval"||!Array.isArray(e.details))return null;const t=[];for(const n of e.details){if(!n||typeof n!="object"||Array.isArray(n))return null;const i=n;if(typeof i.name!="string"||!i.arguments||typeof i.arguments!="object"||Array.isArray(i.arguments)||i.call_id!==void 0&&typeof i.call_id!="string")return null;t.push({name:i.name,arguments:i.arguments,...typeof i.call_id=="string"?{call_id:i.call_id}:{}})}return t}function nj(e){const t=e.trim();if(!t)return{ok:!1,error:"Enter a JSON payload."};try{return{ok:!0,payload:JSON.parse(t)}}catch(n){return{ok:!1,error:`The payload is not valid JSON (${n instanceof Error?n.message:String(n)}).`}}}const Ov={ask_user:"Question for you",tool_approval:"Approval needed",event:"Waiting for an event"};class rj{constructor(t){this.mint=t,this.open=new Map}idFor(t){let n=this.open.get(t);return n===void 0&&(n=this.mint(),this.open.set(t,n)),n}settle(t,n){(n.ok||sj(n.error))&&this.open.delete(t)}}function sj(e){return yg(e)&&e.status>0&&e.code!=="invalid_response"}function ij(){const e=globalThis.crypto;if(!e||typeof e.randomUUID!="function")throw new Error("crypto.randomUUID is unavailable; pass newId");return e.randomUUID()}class oj{constructor(){this.acked=null,this.inflight=null,this.failedKey=null,this.failedToken=void 0}next(t,n){return!t||t===this.acked||t===this.inflight||t===this.failedKey&&n===this.failedToken?null:(this.inflight=t,t)}succeeded(t){this.inflight===t&&(this.inflight=null),this.acked=t,this.failedKey=null}failed(t,n){this.inflight===t&&(this.inflight=null),this.failedKey=t,this.failedToken=n}get acknowledged(){return this.acked}}function aj(e,t){if(!e)return null;for(const n of t){const i=e.querySelector(n);if(i&&i.disabled!==!0&&typeof i.focus=="function")return i}return null}const I_="Discuss — fork at this occurrence (own workspace, automation files read-only)",ih=e=>r.jsx("div",{className:"af-auto-text","data-unformatted":"true",children:e});function lj(e){return yg(e)?e:{status:0,code:"client_error",message:e&&typeof e=="object"&&"message"in e?String(e.message):String(e)}}function cj(e,t){const n=e.trigger,i=t.find(a=>a.id===n.source_id&&a.version===n.source_version);return i?"available"in i&&i.available===!1?`Trigger source ${n.source_id}@${n.source_version} is unavailable${i.unavailable_reason?`: ${i.unavailable_reason}`:"."}`:null:`This gateway does not list the trigger source ${n.source_id}@${n.source_version}.`}function uj(e){const t=e.summary,n=Av(t),i=cj(t,e.triggerSources),a=t.next_fire_at?`${tl(t.next_fire_at)} (${Mv(t.next_fire_at,e.nowMs??Date.now())})`:t.status==="paused"?"none while paused":"none scheduled";return r.jsxs("header",{className:"af-auto__head",children:[r.jsxs("div",{className:"af-auto__titlebar",children:[r.jsx("h2",{className:"af-auto__title",id:e.titleId,tabIndex:-1,children:t.title}),r.jsx("span",{className:`af-auto__status af-auto__status--${t.status}`,children:W0[t.status]??t.status}),t.legacy?r.jsx("span",{className:"af-auto__legacy",children:"Legacy schedule"}):null]}),r.jsxs("dl",{className:"af-auto__facts",children:[r.jsx("dt",{children:"When"}),r.jsxs("dd",{"data-fact":"trigger",children:[gg(t.trigger),i?r.jsxs("span",{className:"af-auto__warn",role:"note",children:[" ",i]}):null]}),r.jsx("dt",{children:"Context"}),r.jsx("dd",{"data-fact":"context",children:Ev(t.context_mode)}),n?r.jsxs(r.Fragment,{children:[r.jsx("dt",{children:"Now"}),r.jsx("dd",{"data-fact":"current",className:"is-notable",children:n})]}):null,r.jsx("dt",{children:"Next run"}),r.jsx("dd",{"data-fact":"next",children:a}),r.jsx("dt",{children:"Runs"}),r.jsx("dd",{"data-fact":"count",children:t.occurrence_count}),t.workspace_root?r.jsxs(r.Fragment,{children:[r.jsx("dt",{children:"Workspace"}),r.jsx("dd",{"data-fact":"workspace",children:r.jsx("code",{children:t.workspace_root})})]}):null,r.jsx("dt",{children:"Attention"}),r.jsx("dd",{"data-fact":"attention",className:t.attention.unread||t.attention.pending_waits?"is-notable":void 0,children:Tv(t)}),t.revision!==null?r.jsxs(r.Fragment,{children:[r.jsx("dt",{children:"Revision"}),r.jsx("dd",{"data-fact":"revision",children:t.revision})]}):null]})]})}function dj(e){const t=e.definition,n=e.renderText??ih,i=t.target.input_data.prompt,a=t.policy.retry,l=t.policy.tool_approval;return r.jsxs("details",{className:"af-auto__definition","data-definition-revision":t.revision,children:[r.jsxs("summary",{children:["Definition (revision ",t.revision,")"]}),r.jsxs("dl",{className:"af-auto__facts",children:[r.jsx("dt",{children:"Target"}),r.jsx("dd",{"data-def":"target",children:r.jsx("code",{children:t.target.workflow_id})}),typeof i=="string"&&i?r.jsxs(r.Fragment,{children:[r.jsx("dt",{children:"Task"}),r.jsx("dd",{"data-def":"prompt",children:n(i)})]}):null,r.jsx("dt",{children:"Trigger"}),r.jsxs("dd",{"data-def":"trigger",children:[t.trigger.source_id,"@",t.trigger.source_version," · ",gg(t.trigger),r.jsx("pre",{className:"af-auto__json",children:JSON.stringify(t.trigger.config,null,2)})]}),r.jsx("dt",{children:"Context"}),r.jsx("dd",{"data-def":"context",children:Ev(t.context.mode)}),r.jsx("dt",{children:"Tools"}),r.jsx("dd",{"data-def":"tool_approval",children:l==="ask"?"Ask before each tool call (ask)":l==="auto"?"Run without asking (auto)":String(l)}),r.jsx("dt",{children:"Retries"}),r.jsxs("dd",{"data-def":"retry",children:[a.max_attempts," ",a.max_attempts===1?"attempt":"attempts",", backoff ",a.backoff.initial," ×",a.backoff.factor," up to ",a.backoff.max]}),r.jsx("dt",{children:"Revision"}),r.jsx("dd",{"data-def":"revision",children:t.revision})]})]})}const fj={pause:"Pause",resume:"Resume",run_now:"Run now",stop_current:"Stop current",revise:"Revise",archive:"Archive",discuss:"Discuss"};function mj(e,t,n){const i=new Map;for(const u of t){const d=e[u];if(d.enabled)continue;const m=d.reason??"Not available now.";i.set(m,[...i.get(m)??[],u])}const a=[],l={};return[...i.entries()].forEach(([u,d],m)=>{const p=`${n}-why-${m}`;a.push({id:p,text:`${d.map(g=>fj[g]).join(", ")}: ${u}`});for(const g of d)l[g]=p}),{lines:a,describedBy:l}}function hj(e){const t=pg(e.summary,e.occurrences,e.busy),n=[e.summary.status==="paused"?"resume":"pause","run_now","stop_current","revise","archive"],i=mj(t,n,e.idBase??`af-auto-${e.summary.automation_id}`),a=(l,u,d,m)=>r.jsx("button",{type:"button",className:`af-auto__btn${m!=null&&m.danger?" af-auto__btn--danger":""}`,"data-action":l,disabled:!t[l].enabled,"aria-describedby":i.describedBy[l],"aria-pressed":m==null?void 0:m.pressed,onClick:d,children:u},l);return r.jsxs("div",{className:"af-auto__controls-wrap",children:[r.jsxs("div",{className:"af-auto__controls",role:"toolbar","aria-label":"Automation controls",children:[e.summary.status==="paused"?a("resume","Resume",()=>e.onCommand(Qc.resume)):a("pause","Pause",()=>e.onCommand(Qc.pause)),a("run_now","Run now",()=>e.onCommand(Qc.run_now)),a("stop_current","Stop current",()=>e.onCommand(Qc.stop_current)),a("revise","Revise…",e.onToggleRevise,{pressed:e.reviseOpen}),a("archive","Archive…",e.onAskArchive,{danger:!0})]}),i.lines.length?r.jsx("p",{className:"af-auto__reasons",children:i.lines.map(l=>r.jsx("span",{id:l.id,children:l.text},l.id))}):null,e.summary.status==="paused"&&t.run_now.enabled?r.jsx("p",{className:"af-auto__hint",children:"Paused: scheduled runs are skipped. Run now works and keeps it paused."}):null,e.confirmingArchive?r.jsxs("div",{className:"af-auto__confirm",role:"group","aria-label":"Confirm archive",children:[r.jsxs("p",{children:["Archive “",e.summary.title,"”? Its history stays readable; it will not run again. The current run, if any, finishes."]}),r.jsxs("div",{className:"af-auto__row",children:[r.jsx("button",{type:"button",className:"af-auto__btn af-auto__btn--danger","data-action":"archive-confirm",disabled:!t.archive.enabled,onClick:()=>e.onCommand(Qc.archive),children:"Archive"}),r.jsx("button",{type:"button",className:"af-auto__btn","data-action":"archive-cancel",onClick:e.onCancelArchive,children:"Keep it"})]})]}):null]})}const wp=[["m","minutes"],["h","hours"],["d","days"]];function _j(e,t){const n=m=>{const p=e.elements.namedItem(m);return p&&typeof p.value=="string"?p.value:null},i=n("every_amount"),a=n("every_unit"),l=i!==null&&a!==null?`${i.trim()}${a}`:t.every,u=e.elements.namedItem("context"),d=u&&(u.value==="growing"||u.value==="independent")?u.value:t.context;return{title:n("title")??t.title,every:l,context:d}}function gj(e){const t=Rv(e.summary),n=t.every?_g(t.every):null,i=n&&n.unit==="s"?[["s","seconds"],...wp]:wp,a=`af-auto-revise-${e.summary.automation_id}`;return r.jsxs("form",{className:"af-auto__revise","aria-label":"Revise automation",onSubmit:l=>{l.preventDefault(),e.onSubmit(_j(l.currentTarget,t))},children:[r.jsxs("label",{className:"af-auto__field",htmlFor:`${a}-title`,children:[r.jsx("span",{children:"Title"}),r.jsx("input",{id:`${a}-title`,name:"title",defaultValue:t.title,maxLength:120,required:!0})]}),n?r.jsxs("fieldset",{className:"af-auto__field",children:[r.jsx("legend",{children:"Repeat every (UTC)"}),r.jsxs("div",{className:"af-auto__row",children:[r.jsx("input",{name:"every_amount",type:"number",min:1,step:1,defaultValue:n.amount,"aria-label":"Interval amount"}),r.jsx("select",{name:"every_unit",defaultValue:n.unit,"aria-label":"Interval unit",children:i.map(([l,u])=>r.jsx("option",{value:l,children:u},l))})]})]}):r.jsx("p",{className:"af-auto__hint",children:"This trigger has no interval to revise."}),r.jsxs("fieldset",{className:"af-auto__field",children:[r.jsx("legend",{children:"Context"}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"context",value:"independent",defaultChecked:t.context==="independent"})," Independent — each run starts fresh"]}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"context",value:"growing",defaultChecked:t.context==="growing"})," Growing — each run sees the previous runs"]})]}),r.jsx("p",{className:"af-auto__hint",children:"Changes apply from the next run; a new interval never fires past ticks."}),e.errors.length?r.jsx("ul",{className:"af-auto__form-errors",role:"alert",children:e.errors.map(l=>r.jsx("li",{children:l},l))}):null,r.jsxs("div",{className:"af-auto__row",children:[r.jsx("button",{type:"submit",className:"af-auto__btn af-auto__btn--primary","data-action":"revise-submit",disabled:e.busy,children:"Save revision"}),r.jsx("button",{type:"button",className:"af-auto__btn","data-action":"revise-cancel",onClick:e.onCancel,children:"Cancel"})]})]})}function D_(e,t){const n=e.elements.namedItem(t);return n&&typeof n.value=="string"?n.value.trim():""}function pj(e){const t=e.wait,n=`${e.idBase}-${t.run_id}-${t.wait_key}-prompt`,i=u=>e.onAnswerWait(t.run_id,t.wait_key,u),a=e.renderText??ih,l=u=>r.jsxs("div",{className:"af-auto-wait__prompt",id:n,children:[r.jsx("span",{className:"af-auto-wait__kind",children:Ov[t.kind]??"Waiting"}),t.prompt?a(t.prompt):r.jsxs("span",{children:[" ",u]})]});if(t.kind==="tool_approval"){const u=tj(t);return r.jsxs("div",{className:"af-auto-wait af-auto-wait--tool_approval",role:"group","data-wait-key":t.wait_key,"data-wait-kind":t.kind,"aria-labelledby":n,children:[l("A tool call needs your approval."),u&&u.length?r.jsx("ul",{className:"af-auto-wait__calls","aria-label":"Tool calls to approve",children:u.map((d,m)=>r.jsxs("li",{"data-tool":d.name,children:[r.jsx("code",{className:"af-auto-wait__tool",children:d.name}),r.jsx("pre",{className:"af-auto-wait__args",children:JSON.stringify(d.arguments,null,2)})]},d.call_id??`${d.name}:${m}`))}):r.jsx("p",{className:"af-auto__hint",children:"The gateway did not list the tool calls; open the run to see them before approving."}),r.jsxs("div",{className:"af-auto__row",children:[r.jsx("button",{type:"button",className:"af-auto__btn af-auto__btn--primary","data-action":"wait-approve",disabled:e.busy,onClick:()=>i({approved:!0}),children:"Approve"}),r.jsx("button",{type:"button",className:"af-auto__btn af-auto__btn--danger","data-action":"wait-deny",disabled:e.busy,onClick:()=>i({approved:!1}),children:"Deny"})]})]})}return t.kind==="event"?r.jsxs("form",{className:"af-auto-wait af-auto-wait--event","data-wait-key":t.wait_key,"data-wait-kind":t.kind,"aria-labelledby":n,onSubmit:u=>{var m;u.preventDefault();const d=nj(D_(u.currentTarget,"payload"));d.ok?i({payload:d.payload}):(m=e.onWaitError)==null||m.call(e,d.error)},children:[l("The run waits for an event."),r.jsx("textarea",{name:"payload",rows:3,"aria-label":"Event payload (JSON)",placeholder:'{"key": "value"}',disabled:e.busy}),r.jsx("div",{className:"af-auto__row",children:r.jsx("button",{type:"submit",className:"af-auto__btn af-auto__btn--primary","data-action":"wait-send-event",disabled:e.busy,children:"Send event"})})]}):t.kind==="ask_user"?r.jsxs("form",{className:"af-auto-wait af-auto-wait--ask_user","data-wait-key":t.wait_key,"data-wait-kind":t.kind,"aria-labelledby":n,onSubmit:u=>{u.preventDefault();const d=D_(u.currentTarget,"response");d&&i({response:d})},children:[l("The run is waiting for your input."),t.choices&&t.choices.length?r.jsx("div",{className:"af-auto__row",role:"group","aria-label":"Choices",children:t.choices.map(u=>r.jsx("button",{type:"button",className:"af-auto__btn","data-action":"wait-choice",disabled:e.busy,onClick:()=>i({response:u}),children:u},u))}):null,r.jsxs("div",{className:"af-auto__row",children:[r.jsx("input",{name:"response","aria-label":"Your answer",placeholder:"Your answer",disabled:e.busy}),r.jsx("button",{type:"submit",className:"af-auto__btn af-auto__btn--primary","data-action":"wait-answer",disabled:e.busy,children:"Answer"})]})]}):r.jsxs("div",{className:"af-auto-wait",role:"group","data-wait-key":t.wait_key,"data-wait-kind":String(t.kind),"aria-labelledby":n,children:[l("The run is waiting."),r.jsxs("p",{className:"af-auto__hint",children:["This kind of wait (",String(t.kind),") cannot be answered here; open the run."]})]})}function yj(e){const{row:t,tone:n,badge:i,statusText:a}=e.view,l=`af-auto-occ-${t.run_id}`,u=e.renderText??ih,d=e.discuss.enabled&&e.view.canDiscuss&&!e.busy,m=e.discuss.enabled?e.view.canDiscuss?null:"Available once this occurrence finishes.":e.discuss.reason??"Not available.",p=n==="failed"?t.failure?"No answer.":"No answer: the run failed.":n==="waiting"?"Waiting for your answer.":n==="running"?"Running…":"No answer.";return r.jsxs("li",{className:`af-auto-occ af-auto-occ--${n}`,"data-index":t.index,"data-tone":n,"aria-labelledby":`${l}-h`,children:[r.jsxs("div",{className:"af-auto-turn af-auto-turn--trigger","data-turn":"trigger",children:[r.jsxs("div",{className:"af-auto-turn__meta",id:`${l}-h`,children:[r.jsxs("span",{className:"af-auto-turn__index",children:["#",t.index]})," · ",t.trigger.summary," · fired ",tl(t.fired_at)]}),r.jsx("div",{className:"af-auto-turn__text",children:u(t.user_turn)})]}),r.jsxs("div",{className:"af-auto-turn af-auto-turn--answer","data-turn":"answer",children:[r.jsxs("div",{className:"af-auto-turn__meta",children:[i?r.jsx("span",{className:`af-auto-badge af-auto-badge--${n}`,children:i}):null,r.jsx("span",{className:"af-auto-turn__status",children:a}),t.finished_at?r.jsxs("span",{children:[" · ",tl(t.finished_at)]}):null]}),t.notify?r.jsxs("div",{className:"af-auto-notify","data-notify":"true",children:[r.jsx("strong",{children:t.notify.title}),t.notify.body?r.jsx("div",{className:"af-auto-notify__body",children:u(t.notify.body)}):null]}):null,t.failure?r.jsxs("div",{className:"af-auto-failure","data-failure":t.failure.reason_code,children:[r.jsx("strong",{children:t.failure.reason_code}),": ",t.failure.message," ",r.jsxs("span",{className:"af-auto-turn__muted",children:["(after ",t.failure.attempts," ",t.failure.attempts===1?"attempt":"attempts",")"]})]}):null,t.answer?r.jsx("div",{className:"af-auto-turn__text",children:u(t.answer)}):r.jsx("div",{className:"af-auto-turn__empty",children:p}),t.artifacts.length?r.jsx("ul",{className:"af-auto-artifacts","aria-label":"Artifacts",children:t.artifacts.map(g=>r.jsxs("li",{children:[r.jsx("a",{href:g.url,target:"_blank",rel:"noopener noreferrer",children:g.name})," ",r.jsx("span",{className:"af-auto-turn__muted",children:g.mime_type})]},g.artifact_id))}):null,t.waits.map(g=>r.jsx(pj,{wait:g,busy:e.busy,idBase:l,onAnswerWait:e.onAnswerWait,onWaitError:e.onWaitError,renderText:e.renderText},`${g.run_id}:${g.wait_key}`))]}),r.jsxs("div",{className:"af-auto-occ__foot",children:[r.jsxs("details",{className:"af-auto-occ__details",children:[r.jsx("summary",{children:"Run details"}),r.jsxs("dl",{className:"af-auto__facts",children:[r.jsx("dt",{children:"Run"}),r.jsx("dd",{children:r.jsx("code",{children:t.run_id})}),r.jsx("dt",{children:"Attempts"}),r.jsx("dd",{children:t.attempts})]}),r.jsxs("div",{className:"af-auto__row",children:[r.jsx("button",{type:"button",className:"af-auto__btn","data-action":"open-run",onClick:()=>e.onOpenRun(t.run_id),children:"Open run ledger"}),r.jsx("a",{className:"af-auto__link",href:t.ledger_url,target:"_blank",rel:"noopener noreferrer",children:"Ledger (JSON)"}),t.workspace_url?r.jsx("a",{className:"af-auto__link",href:t.workspace_url,target:"_blank",rel:"noopener noreferrer",children:"Workspace"}):null]})]}),e.discussOpen?r.jsxs("form",{className:"af-auto-discuss","aria-label":`${I_}, from occurrence ${t.index}`,onSubmit:g=>{g.preventDefault();const v=D_(g.currentTarget,"prompt");v&&e.onDiscussSubmit(t.index,v)},children:[r.jsxs("p",{className:"af-auto__hint",children:["Starts a new session that forks this automation at #",t.index," with its full history (runs 1–",t.index,"). It works in its own writable workspace; the automation's files are mounted read-only for the file tools (shell commands are not sandboxed), and nothing is written back into the automation's session."]}),r.jsx("textarea",{name:"prompt",rows:3,"aria-label":"Your message",placeholder:"Ask about this result…",required:!0}),r.jsxs("div",{className:"af-auto__row",children:[r.jsx("button",{type:"submit",className:"af-auto__btn af-auto__btn--primary","data-action":"discuss-submit",disabled:e.busy,children:"Start discussion"}),r.jsx("button",{type:"button",className:"af-auto__btn","data-action":"discuss-cancel",onClick:e.onDiscussCancel,children:"Cancel"})]})]}):r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"af-auto__btn af-auto__btn--quiet","data-action":"discuss",disabled:!d,"aria-describedby":m?`${l}-discuss-why`:void 0,onClick:()=>e.onDiscussOpen(t.index),children:I_}),m?r.jsx("span",{className:"af-auto__reasons",id:`${l}-discuss-why`,children:m}):null]})]})]})}function vj(e){const{summary:t,busy:n}=e,i=e.renderText??ih,a=_.useId(),l=_.useRef(null),[u,d]=_.useState(!1),[m,p]=_.useState([]),[g,v]=_.useState(!1),[w,x]=_.useState(null),[N,S]=_.useState(null),[R,T]=_.useState(null),[z,H]=_.useState(null);_.useEffect(()=>{var K;z&&((K=aj(l.current,[...z,".af-auto__notice",".af-auto__title"]))==null||K.focus(),H(null))},[z]);const D=_.useRef(null);D.current||(D.current=new rj(e.newId??ij));const G=D.current,Q=K=>S(lj(K)),Y=(K,L,O)=>{S(null),T(null),L(G.idFor(K)).then(q=>{G.settle(K,{ok:!0}),O(q)},q=>{G.settle(K,{ok:!1,error:q}),Q(q)})},ee=K0(t),ae=_.useRef(e.onSeen);ae.current=e.onSeen;const le=_.useRef(null);le.current||(le.current=new oj),_.useEffect(()=>{const K=le.current,L=ee?`${t.automation_id}|${ee}`:null;if(!ee||!K.next(L,t))return;const O=t;ae.current(ee).then(()=>K.succeeded(L),q=>{K.failed(L,O),Q(q)})});const ge=pg(t,e.occurrences,n),F=G0(e.occurrences),C=t.occurrence_count-e.occurrences.length,k=N??e.error??null,I=k?Dm(k):null,P=t.attention;return r.jsxs("section",{ref:l,className:`af-auto${e.className?` ${e.className}`:""}`,"aria-labelledby":a,"aria-busy":n,"data-text-rendering":e.renderText?"rich":"unformatted",children:[r.jsx(uj,{summary:t,triggerSources:e.triggerSources,titleId:a,nowMs:e.nowMs}),e.definition?r.jsx(dj,{definition:e.definition,renderText:i}):null,r.jsx(hj,{summary:t,occurrences:e.occurrences,busy:n,confirmingArchive:g,reviseOpen:u,idBase:`${a}-ctl`,onCommand:K=>Y(`command:${K}`,L=>e.onCommand(K,void 0,{command_id:L}),()=>{K===Qc.archive?(v(!1),T("Archive requested."),H(['[data-action="archive"]'])):T("Command sent.")}),onToggleRevise:()=>{p([]),d(!u)},onAskArchive:()=>v(!0),onCancelArchive:()=>{v(!1),H(['[data-action="archive"]'])}}),u?r.jsx(gj,{summary:t,busy:n,errors:m,onCancel:()=>{d(!1),H(['[data-action="revise"]'])},onSubmit:K=>{const L=X0(t,K);if(L===null){p(["Nothing changed."]);return}if("errors"in L){p(L.errors);return}p([]),Y(`revise:${t.revision}:${JSON.stringify(L)}`,O=>e.onRevise(L,t.revision,{command_id:O}),()=>{T("Revision sent; it applies from the next run."),d(!1),H(['[data-action="revise"]'])})}}):null,I?r.jsxs("div",{className:"af-auto__error",role:"alert","data-code":k==null?void 0:k.code,children:[r.jsx("strong",{children:I.title})," ",r.jsx("span",{children:I.detail})]}):null,R?r.jsx("div",{className:"af-auto__notice",role:"status",tabIndex:-1,children:R}):null,P.items.length||P.waits.length?r.jsx("section",{className:"af-auto__attention","aria-label":"Needs attention",children:r.jsxs("ul",{children:[P.items.map(K=>r.jsxs("li",{className:`af-auto__attention-item af-auto__attention-item--${K.kind}`,"data-cursor":K.cursor,children:[r.jsx("span",{className:`af-auto-badge af-auto-badge--${K.kind==="failure"?"failed":"notified"}`,children:K.kind==="failure"?"Failed":"Notified"})," ",r.jsx("strong",{children:K.title})," ",r.jsxs("span",{className:"af-auto-turn__muted",children:["#",K.index," · ",tl(K.at)]}),K.body?r.jsx("div",{className:"af-auto__attention-body",children:i(K.body)}):null]},K.cursor)),P.waits.map(K=>r.jsxs("li",{className:"af-auto__attention-item af-auto__attention-item--wait",children:[r.jsx("span",{className:"af-auto-badge af-auto-badge--waiting","data-wait-kind":K.kind,children:Ov[K.kind]??"Waiting for you"})," ",r.jsxs("span",{className:"af-auto-turn__muted",children:["#",K.index]}),K.prompt?r.jsx("div",{className:"af-auto__attention-body",children:i(K.prompt)}):null]},`${K.run_id}:${K.wait_key}`))]})}):null,C>0?r.jsxs("button",{type:"button",className:"af-auto__btn af-auto__more","data-action":"load-more",disabled:n,onClick:e.onLoadMore,children:["Load earlier occurrences (",C," more)"]}):null,F.length?r.jsx("ol",{className:"af-auto__timeline","aria-label":"Occurrences",children:F.map(K=>{const L=`[data-index="${K.row.index}"]`;return r.jsx(yj,{view:K,busy:n,discuss:ge.discuss,renderText:i,discussOpen:w===K.row.index,onOpenRun:e.onOpenRun,onAnswerWait:(O,q,E)=>{S(null),e.onAnswerWait(O,q,E).then(()=>T("Answer sent."),Q)},onWaitError:O=>S({status:0,code:"invalid_payload",message:O}),onDiscussOpen:x,onDiscussCancel:()=>{x(null),H([`${L} [data-action="discuss"]`])},onDiscussSubmit:(O,q)=>Y(`discuss:${O}:${q}`,E=>e.onDiscuss(O,q,{request_id:E}),E=>{x(null),T(`Discussion started (session ${E.session_id}).`),H([`${L} [data-action="discuss"]`])})},K.row.run_id)})}):r.jsx("p",{className:"af-auto__empty",children:"No occurrences yet."})]})}function Pv(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function wj(e){const t=Pv(e);if(!t||typeof t!="object"||Array.isArray(t))return{label:"input",value:t==null?"":String(t)};const n=Object.entries(t),a=["command","query","url","file_path","path","pattern","name"].map(l=>n.find(([u])=>u===l)).find(Boolean)||n[0];return a?{label:a[0].replace(/_/g," "),value:typeof a[1]=="string"?a[1]:JSON.stringify(a[1])??""}:{label:"",value:""}}function Iv({tool:e,showCopy:t=!0}){const[n,i]=_.useState(!1),a=Pv(e.arguments),l=wj(e.arguments),u=["file path","path"].includes(l.label)&&l.value.length>60?`${l.value.split(/[\\/]/).pop()} · ${l.value.slice(0,24)}…`:l.value,d=e.error&&/^File ['"].+['"] does not exist\.?$/.test(e.error)?"File not found. Expand for the exact path.":e.error&&e.error.length>180?`${e.error.slice(0,100)}…${e.error.slice(-70)}`:e.error,m={running:"Running",waiting:"Approval needed",completed:"Done",failed:"Failed"},p=e.startedAt&&e.endedAt?Date.parse(e.endedAt)-Date.parse(e.startedAt):NaN,g=a&&typeof a=="object"&&!Array.isArray(a)?Object.entries(a):null;return r.jsxs("details",{className:`pc-tool-activity pc-tool-activity--${e.status}`,children:[r.jsxs("summary",{className:"pc-tool-activity__summary",children:[r.jsx("span",{className:"pc-tool-activity__state-icon","aria-hidden":"true",children:r.jsx(Nn,{name:e.status==="completed"?"check":e.status==="failed"?"x":e.status==="waiting"?"warning":"loader",size:15})}),r.jsx("strong",{children:e.name}),r.jsx("span",{className:"pc-tool-activity__preview",title:l.value,children:l.value?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"pc-tool-activity__key",children:l.label}),u]}):"No parameters"}),r.jsx("span",{className:"pc-tool-activity__status",children:m[e.status]}),Number.isFinite(p)&&p>=0?r.jsxs("span",{className:"pc-tool-activity__duration",children:[(p/1e3).toFixed(1),"s"]}):null,r.jsx("span",{className:"pc-tool-activity__chevron","aria-hidden":"true",children:r.jsx(Nn,{name:"chevronRight",size:13})}),e.error?r.jsx("span",{className:"pc-tool-activity__error",title:e.error,children:d}):null]}),r.jsxs("div",{className:"pc-tool-activity__detail",children:[e.error?r.jsxs(r.Fragment,{children:[r.jsx("h4",{children:"Error"}),r.jsx("pre",{className:"pc-tool-activity__output",children:e.error})]}):null,r.jsxs("div",{className:"pc-tool-activity__detail-heading",children:[r.jsx("h4",{children:"Parameters"}),t?r.jsxs("button",{type:"button",onClick:async()=>i(await nc(JSON.stringify(e,null,2))),children:[r.jsx(Nn,{name:"copy",size:13}),n?"Copied":"Copy details"]}):null]}),g?r.jsx("dl",{className:"pc-tool-activity__parameters",children:g.map(([v,w])=>r.jsxs(pe.Fragment,{children:[r.jsx("dt",{children:v}),r.jsx("dd",{children:w&&typeof w=="object"?r.jsx(ps,{value:w}):r.jsx("code",{children:typeof w=="string"?w:JSON.stringify(w)})})]},v))}):e.arguments===void 0?r.jsx("p",{children:"Arguments are unavailable in this ledger."}):r.jsx(ps,{value:a}),e.output!==void 0?r.jsxs(r.Fragment,{children:[r.jsx("h4",{children:"Result"}),typeof e.output=="string"?r.jsx("pre",{className:"pc-tool-activity__output",children:e.output}):r.jsx("div",{className:"pc-tool-activity__output",children:r.jsx(ps,{value:e.output})})]}):null]})]})}function xj({tools:e,showCopy:t}){const n=i=>e.filter(a=>a.status===i).length;return r.jsxs("section",{className:"pc-tool-group","aria-label":"Tool activity",children:[r.jsxs("div",{className:"pc-tool-group__heading",children:[r.jsx(Nn,{name:"terminal",size:14}),r.jsx("strong",{children:"Tools"}),r.jsxs("span",{children:[e.length," ",e.length===1?"call":"calls"]}),r.jsx("div",{}),n("running")?r.jsxs("span",{className:"pc-tool-group__running",children:[n("running")," running"]}):null,n("waiting")?r.jsxs("span",{className:"pc-tool-group__waiting",children:[n("waiting")," need approval"]}):null,n("failed")?r.jsxs("span",{className:"pc-tool-group__failed",children:[n("failed")," failed"]}):null,n("completed")?r.jsxs("span",{className:"pc-tool-group__completed",children:[n("completed")," done"]}):null]}),e.map(i=>r.jsx(Iv,{tool:i,showCopy:t},i.id))]})}const Fr="not reported",_s=e=>e===void 0?Fr:Math.round(e).toLocaleString(),As=e=>{if(e===void 0)return Fr;if(e<6e4)return`${(e/1e3).toFixed(1)}s`;const t=Math.round(e/1e3);return`${Math.floor(t/60)}m ${String(t%60).padStart(2,"0")}s`},Dv=e=>e===void 0?Fr:`${Math.round(e).toLocaleString()} tok/s`,bj=(e,t)=>t>0?`${Math.round(e/t*100)}%`:"",Zl=(e,t,n=`${t}s`)=>`${e.toLocaleString()} ${e===1?t:n}`,jj=e=>{const t=e.split("#")[0].replace(/\/+$/,"");return t.slice(t.lastIndexOf("/")+1)||e};function Sj(e){const t=new Map;for(const n of e)n&&t.set(n,(t.get(n)||0)+1);return[...t].map(([n,i])=>i>1?`${n} ×${i}`:n).join(" · ")}function zm(e){const t=[],n=(e.models||[]).map(jj),i=e.providers||[];return(n.length||i.length)&&t.push([n.join(", ")||"model not reported",i.join(", ")].filter(Boolean).join(" · ")),t.push("From the run ledger; summed across this turn and its child runs."),t}function kj(e){const t=e.modelCalls||[],n=[],i=[{label:"Input",value:_s(e.inputTokens)},{label:"Output",value:_s(e.outputTokens)}];if(e.reasoningTokens!==void 0&&i.push({label:"Reasoning",value:_s(e.reasoningTokens),hint:"part of output"}),i.push({label:"Total",value:_s(e.totalTokens)}),n.push({heading:`Usage · ${Zl(e.llmCalls,"model call")}`,rows:i}),e.measuredCacheCalls){const l=e.cachedTokens||0,u=e.fedTokens||0,d=[{label:"Reused from cache",value:`${_s(l)}${l+u?` (${bj(l,l+u)})`:""}`},{label:"Newly processed",value:_s(e.fedTokens)},{label:"Outcome",value:Sj(t.map(m=>m.cacheOutcome))||(e.cacheOutcomes||[]).join(" · ")||Fr},{label:"Backend",value:(e.cacheBackends||[]).join(", ")||Fr}];e.measuredCacheCalls!==e.llmCalls&&d.push({label:"Measured on",value:`${e.measuredCacheCalls} of ${e.llmCalls} calls`}),n.push({heading:"Prompt cache",rows:d})}else e.llmCalls&&n.push({heading:"Prompt cache",rows:[{label:"Cache reuse",value:Fr}]});const a=t.filter(l=>l.inputTokens!==void 0);return a.length===1&&t.length===1?n.push({heading:"Context",rows:[{label:"Prompt size",value:`${_s(a[0].inputTokens)} tokens`}]}):a.length>1&&n.push({heading:"Context",rows:[{label:"First → last call",value:`${_s(a[0].inputTokens)} → ${_s(a[a.length-1].inputTokens)} tokens`}],note:"Each call re-sends the conversation, so the input total counts the context once per call."}),t.length>1&&n.push({heading:"Per call",table:{columns:["#","Input","Cached","New","Output","Cache"],rows:t.map((l,u)=>[String(u+1),_s(l.inputTokens),l.cachedTokens===void 0?"—":_s(l.cachedTokens),l.fedTokens===void 0?"—":_s(l.fedTokens),_s(l.outputTokens),l.cacheOutcome||"—"])}}),{kind:"tokens",title:"Tokens",headline:e.totalTokens===void 0?Fr:`${e.totalTokens.toLocaleString()} total`,sections:n,footer:zm(e)}}function dm(e,t,n,i){if(e===void 0)return Fr;const a=[As(e)];return t!==void 0&&a.push(`${t.toLocaleString()} ${i}${n!==void 0?` at ${Dv(n)}`:""}`),a.join(" · ")}function Nj(e){var p,g,v;const t=e.modelCalls||[],n=[],i=e.durationMs,a=[{label:"Wall clock",value:As(i)}];if(a.push({label:"Model",value:e.genTimeMs===void 0?Fr:`${As(e.genTimeMs)} · ${Zl(e.timedCalls||0,"call")}${e.timedCalls!==e.llmCalls?` (of ${e.llmCalls})`:""}`}),a.push({label:"Tools",value:e.toolTimeMs!==void 0?`${As(e.toolTimeMs)} · ${Zl(e.toolBatches||0,"batch","batches")}`:e.toolCalls?Fr:"none",hint:e.toolTimeIncludesApproval?"includes approval wait":void 0}),i!==void 0&&e.genTimeMs!==void 0){const w=i-e.genTimeMs-(e.toolTimeMs||0);a.push({label:"Orchestration",value:w>=0?As(w):"overlaps (parallel runs)",hint:"wall − model − tools: routing, hand-offs, model load"})}n.push({heading:"Turn",rows:a});const l=[],u=e.ttftCalls||0,d=e.promptPhaseCalls||0;e.promptPhaseMs!==void 0?l.push({label:u&&u===d?"Prefill (TTFT)":"Prefill",value:dm(e.promptPhaseMs,e.promptPhaseNewTokens,e.promptPhaseTokensPerSecond,"new tok"),hint:u===d?"measured time to first token":u?`TTFT measured on ${u} of ${d}; rest from provider rate`:"derived: prompt ÷ provider rate"}):e.prefillMs!==void 0&&e.prefillNewTokensPerSecond!==void 0?l.push({label:"Prefill",value:dm(e.prefillMs,e.prefillNewTokens,e.prefillNewTokensPerSecond,"new tok"),hint:"derived: prompt ÷ provider rate"}):e.prefillMs!==void 0?l.push({label:"Prefill",value:`${As(e.prefillMs)}${e.promptTokensPerSecond!==void 0?` at ${Dv(e.promptTokensPerSecond)}`:""}`,hint:"provider rate over all prompt tokens, restored included"}):l.push({label:"Prefill",value:Fr}),e.cachedTokens&&(e.promptPhaseMs??e.prefillMs)!==void 0&&l.push({label:"Restored",value:`${e.cachedTokens.toLocaleString()} tok from cache`,hint:"not recomputed"}),l.push({label:"Generation",value:e.generationPhaseMs!==void 0?dm(e.generationPhaseMs,e.generationPhaseTokens,e.generationPhaseTokensPerSecond,"tok"):dm(e.decodeMs,e.outputTokens,e.generationTokensPerSecond,"tok")}),e.measuredSpeedCalls&&e.measuredSpeedCalls!==e.llmCalls&&l.push({label:"Speeds from",value:`${e.measuredSpeedCalls} of ${e.llmCalls} calls`}),n.push({heading:"Model",rows:l});const m=e.speculation;if(m){const w=(m.draftKinds||[]).map(N=>N.toUpperCase()).join(", "),x=[{label:"Mode",value:`${m.used?"on":"off"}${w?` · ${w}`:""}${(p=m.modes)!=null&&p.length?` (${m.modes.join(", ")})`:""}`,hint:m.calls!==e.llmCalls||m.used!==m.calls?`used on ${m.used} of ${e.llmCalls} calls`:void 0},{label:"Acceptance",value:m.acceptanceRate===void 0?Fr:`${Math.round(m.acceptanceRate*100)}% · ${_s(m.acceptedTokens)} of ${_s(m.draftedTokens)} drafted`}];((g=m.draftLengths)!=null&&g.length||m.rounds!==void 0)&&x.push({label:"Draft length",value:`${(v=m.draftLengths)!=null&&v.length?`${m.draftLengths.join("/")} tok/round`:Fr}${m.rounds!==void 0?` · ${m.rounds.toLocaleString()} rounds`:""}`}),n.push({heading:"Speculation",rows:x})}return e.slowestToolBatch&&n.push({heading:"Tools",rows:[{label:"Total",value:`${As(e.toolTimeMs)} · ${Zl(e.toolBatches||0,"batch","batches")}`},{label:"Slowest",value:`${As(e.slowestToolBatch.ms)} · ${zv(e.slowestToolBatch)}`}],note:e.toolTimeIncludesApproval?"Gated calls are timed from request to result, so this includes waiting for your approval.":void 0}),t.length>1&&n.push({heading:"Per call",table:{columns:["#","Prefill","New tok/s","Gen","Gen tok/s","Cache"],rows:t.map((w,x)=>[String(x+1),w.promptMs===void 0?"—":`${As(w.promptMs)}${w.promptSource==="rate"?"*":""}`,w.promptNewTokensPerSecond===void 0?"—":Math.round(w.promptNewTokensPerSecond).toLocaleString(),w.generationMs===void 0?"—":As(w.generationMs),w.generationTokensPerSecond===void 0?"—":Math.round(w.generationTokensPerSecond).toLocaleString(),w.cacheOutcome||"—"])},note:t.some(w=>w.promptSource==="rate")?"* derived from the provider's prompt rate (no TTFT event).":void 0}),{kind:"time",title:"Time",headline:i===void 0?Fr:`${As(i)} wall clock`,sections:n,footer:zm(e)}}function zv(e){return e.tools.length===1?`${e.tools[0]} ×${e.calls}`:`${Zl(e.calls,"call")} (${e.tools.join(", ")})`}function Cj(e){const t=[],n=(e.toolsWaiting||0)+(e.toolsRunning||0);if(!e.toolCalls&&!n)return t.push({heading:"Outcome",rows:[{label:"Tools called",value:"none"}]}),{kind:"tools",title:"Tools",headline:"none",sections:t,footer:zm(e)};const i=[{label:"Succeeded",value:(e.toolCalls-(e.toolsFailed||0)).toLocaleString()},{label:"Failed",value:(e.toolsFailed||0).toLocaleString()}];e.toolsRunning&&i.push({label:"Running",value:e.toolsRunning.toLocaleString()}),e.toolsWaiting&&i.push({label:"Awaiting approval",value:e.toolsWaiting.toLocaleString(),hint:"not run yet — not a failure"}),t.push({heading:"Outcome",rows:i});const a=Object.entries(e.toolBreakdown||{}).sort((d,m)=>m[1].calls-d[1].calls||d[0].localeCompare(m[0]));a.length&&t.push({heading:"By tool",table:{columns:["Tool","Calls","Failed","Time"],rows:a.map(([d,m])=>[d,m.calls.toLocaleString(),m.failed.toLocaleString(),m.ms!==void 0?`${As(m.ms)}${m.sharedBatches?" +shared":""}`:m.sharedBatches?"shared":Fr])},note:a.some(([,d])=>d.sharedBatches)?"A batch that mixed tools ran them together; its time is not split between them.":void 0});const l=a.filter(([,d])=>d.errors&&Object.keys(d.errors).length);l.length&&t.push({heading:"Failures",rows:l.map(([d,m])=>({label:d,value:Object.entries(m.errors).sort((p,g)=>g[1]-p[1]).map(([p,g])=>g>1?`${p} ×${g}`:p).join(" · ")}))});const u=[{label:"Tool time",value:e.toolTimeMs===void 0?Fr:`${As(e.toolTimeMs)} · ${Zl(e.toolBatches||0,"batch","batches")}`}];return e.slowestToolBatch&&u.push({label:"Slowest batch",value:`${As(e.slowestToolBatch.ms)} · ${zv(e.slowestToolBatch)}`}),t.push({heading:"Timing",rows:u,note:e.toolTimeIncludesApproval?"Gated calls are timed from request to result, so this includes waiting for your approval.":void 0}),{kind:"tools",title:"Tools",headline:`${Zl(e.toolCalls,"call")}${e.toolsFailed?` · ${e.toolsFailed} failed`:""}`,sections:t,footer:zm(e)}}function Jh(e,t){return e==="tokens"?kj(t):e==="time"?Nj(t):Cj(t)}function $j(e){const t=e.detail;return r.jsxs("div",{ref:e.panelRef,id:e.id,role:"tooltip",className:`pc-stat-detail pc-stat-detail--${t.kind}`,style:e.style,onMouseEnter:e.onMouseEnter,onMouseLeave:e.onMouseLeave,children:[r.jsxs("div",{className:"pc-stat-detail-head",children:[r.jsx("span",{className:"pc-stat-detail-title",children:t.title}),r.jsx("span",{className:"pc-stat-detail-headline",children:t.headline})]}),t.sections.map(n=>{var i;return r.jsxs("div",{className:"pc-stat-detail-section",children:[r.jsx("div",{className:"pc-stat-detail-heading",children:n.heading}),(i=n.rows)!=null&&i.length?r.jsx("dl",{className:"pc-stat-detail-rows",children:n.rows.map(a=>r.jsxs(pe.Fragment,{children:[r.jsx("dt",{children:a.label}),r.jsxs("dd",{children:[r.jsx("span",{className:a.value===Fr?"pc-stat-detail-value pc-stat-detail-value--absent":"pc-stat-detail-value",children:a.value}),a.hint?r.jsx("span",{className:"pc-stat-detail-hint",children:a.hint}):null]})]},a.label))}):null,n.table?r.jsxs("table",{className:"pc-stat-detail-table",children:[r.jsx("thead",{children:r.jsx("tr",{children:n.table.columns.map(a=>r.jsx("th",{scope:"col",children:a},a))})}),r.jsx("tbody",{children:n.table.rows.map((a,l)=>r.jsx("tr",{children:a.map((u,d)=>r.jsx("td",{children:u},d))},l))})]}):null,n.note?r.jsx("p",{className:"pc-stat-detail-note",children:n.note}):null]},n.heading)}),r.jsx("div",{className:"pc-stat-detail-foot",children:t.footer.map(n=>r.jsx("div",{children:n},n))})]})}const Ho=8;function Ej(e){const[t,n]=_.useState(!!e.defaultOpen),[i,a]=_.useState(null),l=_.useRef(null),u=_.useRef(null),d=_.useRef(null),m=`pc-stat-${_.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,p=_.useCallback(()=>{d.current!==null&&window.clearTimeout(d.current),d.current=null},[]),g=_.useCallback(()=>{p(),n(!0)},[p]),v=_.useCallback(()=>{p(),d.current=window.setTimeout(()=>n(!1),120)},[p]);_.useEffect(()=>p,[p]),_.useLayoutEffect(()=>{if(!t){a(null);return}const S=()=>{const R=l.current,T=u.current;if(!R||!T)return;const z=R.getBoundingClientRect(),H=T.offsetWidth,D=T.offsetHeight,G=window.innerWidth,Q=window.innerHeight,Y=z.top-Ho-D,ee=z.bottom+Ho,ae=Y>=Ho?Y:ee+D<=Q-Ho?ee:Math.max(Ho,Q-Ho-D),le=Math.min(Math.max(Ho,z.left),Math.max(Ho,G-Ho-H));a({top:ae,left:le})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[t]),_.useEffect(()=>{if(!t)return;const S=R=>{R.key==="Escape"&&n(!1)};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[t]);const w=typeof e.onClick=="function",x=w?"button":"span",N=t?r.jsx($j,{detail:e.detail,id:m,panelRef:u,onMouseEnter:p,onMouseLeave:v,style:{position:"fixed",top:(i==null?void 0:i.top)??0,left:(i==null?void 0:i.left)??0,visibility:i?"visible":"hidden"}}):null;return r.jsxs(r.Fragment,{children:[r.jsxs(x,{ref:l,...w?{type:"button"}:{tabIndex:0},className:["pc-chat-stat","pc-chat-stat--detail",w?"pc-chat-stat--clickable":"",e.className].filter(Boolean).join(" "),"aria-label":`${e.label} — ${e.detail.title.toLowerCase()} details`,"aria-describedby":t?m:void 0,"data-stat-kind":e.detail.kind,onMouseEnter:g,onMouseLeave:v,onFocus:g,onBlur:()=>n(!1),onKeyDown:S=>{S.key==="Escape"&&n(!1)},onClick:w?()=>{var S;return(S=e.onClick)==null?void 0:S.call(e)}:void 0,children:[e.icon?r.jsx("span",{className:"pc-chat-stat-icon","aria-hidden":"true",children:e.icon}):null,r.jsx("span",{className:"pc-chat-stat-label",children:e.label})]}),N&&typeof document<"u"?kv.createPortal(N,document.body):N]})}function Aj(e){const t=e.totalTokens!==void 0?Jh("tokens",e):null,n=Jh("tools",e),i=e.durationMs!==void 0?Jh("time",e):null;return[...t?[{label:`${e.totalTokens.toLocaleString()} tokens`,detail:t}]:[],{label:`${e.toolCalls} ${e.toolCalls===1?"tool":"tools"}`,detail:n},...e.changedFiles.length?[{label:`${e.changedFiles.length} ${e.changedFiles.length===1?"file":"files"} changed`,title:e.changedFiles.join(`
|
|
55
|
+
`)}]:[],...i?[{label:`${(e.durationMs/1e3).toFixed(e.durationMs<1e4?1:0)}s`,detail:i}]:[]]}function Mj(e){const t=String(e.role||"").trim().toLowerCase()||"system",n=String(e.kind||"").trim().toLowerCase(),i=String(e.level||"").trim().toLowerCase();return t==="system"&&n==="report_bug"?{label:String(e.title||"").trim()||"Bug report",icon:"warning",variant:"report_bug"}:t==="system"&&n==="report_feature"?{label:String(e.title||"").trim()||"Feature request",icon:"check",variant:"report_feature"}:t==="user"?{label:String(e.title||"").trim()||"You",icon:"user",variant:"user"}:t==="assistant"?{label:String(e.title||"").trim()||"Agent",icon:"bot",variant:"assistant"}:{label:String(e.title||"").trim()||(i==="error"?"Error":i==="warn"?"Warning":"System"),icon:i==="error"?"error":i==="warn"?"warning":"info",variant:i==="error"?"error":i==="warn"?"warn":"status"}}function Tj(e){var T;const t=e.message,n=_.useMemo(()=>Mj(t),[t.kind,t.level,t.role,t.title]),i=String(t.ts||"").trim(),a=_.useMemo(()=>{if(!i)return"";const z=new Date(i);return Number.isFinite(z.getTime())?z.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):""},[i]),[l,u]=_.useState("idle"),d=_.useRef(null);_.useEffect(()=>()=>{d.current!==null&&window.clearTimeout(d.current)},[]);const m=t.live,p=!m&&typeof e.onSpeakToggle=="function"&&n.variant==="assistant"&&!!String(t.content||"").trim(),g=p&&((T=e.getSpeakState)==null?void 0:T.call(e,t))||"idle",v=g==="loading"?"loader":g==="playing"?"pause":"speaker",w=g==="loading"?"Generating audio…":g==="playing"?"Pause":g==="paused"?"Resume":"Speak (TTS)",x=e.showCopy!==!1,N=Array.isArray(e.attachments)?e.attachments:[],S=t.statistics,R=_.useMemo(()=>Array.isArray(e.stats)?e.stats:S?Aj(S):[],[e.stats,S]);return t.toolActivity?r.jsx(Iv,{tool:t.toolActivity,showCopy:e.showCopy}):r.jsxs("div",{className:["pc-chat-item",`pc-chat-item--${n.variant}`,m?"pc-chat-item--live":"",e.className].filter(Boolean).join(" "),...m?{"aria-busy":!0}:{},children:[r.jsxs("div",{className:"pc-chat-header",children:[r.jsx("div",{className:"pc-chat-avatar","aria-hidden":"true",children:r.jsx(Nn,{name:n.icon,size:14})}),r.jsx("span",{className:"pc-chat-role",children:n.label}),m?r.jsxs("span",{className:"pc-chat-live-indicator",title:"The reply is still being written",children:[r.jsx("span",{className:"pc-chat-live-dot","aria-hidden":"true"}),"streaming"]}):null,m!=null&&m.caption?r.jsx("span",{className:"pc-chat-live-caption",children:m.caption}):null,r.jsx("span",{className:"pc-chat-header-spacer"}),a?r.jsx("span",{className:"pc-chat-time",children:a}):null,r.jsxs("div",{className:"pc-chat-header-actions",children:[p?r.jsx("button",{className:"pc-chat-icon-btn",type:"button","aria-label":w,title:w,onClick:()=>{var z;return(z=e.onSpeakToggle)==null?void 0:z.call(e,t)},children:r.jsx(Nn,{name:v,size:22})}):null,x?r.jsx("button",{className:`pc-chat-icon-btn ${l!=="idle"?`pc-chat-icon-btn--${l}`:""}`.trim(),type:"button","aria-label":"Copy message",title:l==="idle"?"Copy":l==="copied"?"Copied":"Copy failed",onClick:async()=>{const z=await nc(String(t.content||""));u(z?"copied":"failed"),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>u("idle"),900)},children:r.jsx(Nn,{name:"copy",size:22})}):null]})]}),m!=null&&m.reasoning?r.jsxs("details",{className:"pc-chat-thinking",children:[r.jsx("summary",{children:"Thinking"}),r.jsx("div",{className:"pc-chat-thinking-body",children:m.reasoning})]}):null,!m||String(t.content||"").trim()?r.jsx("div",{className:"pc-chat-body",children:r.jsx(jv,{text:String(t.content||""),renderMarkdown:e.renderMarkdown,jsonCollapseAfterDepth:e.jsonCollapseAfterDepth,images:e.images||(n.variant==="user"?"inline":"link"),inlineImage:e.inlineImage})}):null,N.length?r.jsx("div",{className:"pc-chat-attachments","aria-label":"Attachments",children:N.slice(0,24).map((z,H)=>{const D=String(z.label||"").trim()||"attachment",G=String(z.target||"").trim(),Q=String(z.title||"").trim(),Y=!!z.disabled||typeof z.onClick!="function";return r.jsxs("button",{type:"button",className:"pc-chat-attachment-chip",title:Q||D,onClick:Y?void 0:z.onClick,disabled:Y,children:[r.jsx(Nn,{name:"paperclip",size:14}),G?r.jsx("span",{className:`pc-chat-attachment-target pc-chat-attachment-target--${G}`,children:G}):null,r.jsx("span",{className:"pc-chat-attachment-name",children:D})]},z.id||`${D}:${H}`)})}):null,R.length?r.jsx("div",{className:"pc-chat-stats","aria-label":"Stats",children:R.slice(0,12).map((z,H)=>{const D=String(z.label||"").trim();if(!D)return null;if(z.detail)return r.jsx(Ej,{label:D,detail:z.detail,icon:z.icon,onClick:z.onClick},z.id||`${D}:${H}`);const G=String(z.title||"").trim(),Q=typeof z.onClick=="function",Y=Q?"button":"span";return r.jsxs(Y,{...Q?{type:"button"}:{},className:["pc-chat-stat",Q?"pc-chat-stat--clickable":""].filter(Boolean).join(" "),title:G||void 0,onClick:Q?()=>{var ee;return(ee=z.onClick)==null?void 0:ee.call(z)}:void 0,children:[z.icon?r.jsx("span",{className:"pc-chat-stat-icon","aria-hidden":"true",children:z.icon}):null,r.jsx("span",{className:"pc-chat-stat-label",children:D})]},z.id||`${D}:${H}`)})}):null]})}function Rj(e,t){const n=Math.max(0,Math.trunc(t));return e.scrollHeight-e.scrollTop-e.clientHeight<=n}function Fv(e){const t=typeof e.autoScrollThresholdPx=="number"&&Number.isFinite(e.autoScrollThresholdPx)?e.autoScrollThresholdPx:120,n=e.autoScroll!==!1,i=_.useRef(null),a=_.useRef(null),[l,u]=_.useState(!0),d=_.useMemo(()=>Array.isArray(e.messages)?e.messages:[],[e.messages]),m=_.useMemo(()=>{var v;const g=[];for(const w of d){const x=g[g.length-1];w.toolActivity&&((v=x==null?void 0:x[0])!=null&&v.toolActivity)&&x[0].runId===w.runId?x.push(w):g.push([w])}return g},[d]);_.useEffect(()=>{if(!n)return;const g=i.current;if(!g)return;const v=()=>{u(Rj(g,t))};return g.addEventListener("scroll",v,{passive:!0}),v(),()=>g.removeEventListener("scroll",v)},[n,t]);const p=_.useMemo(()=>{let g=0;for(const v of d)g+=String(v.content??"").length;return`${d.length}:${g}:${String(e.afterKey??"")}`},[d,e.afterKey]);return _.useEffect(()=>{if(!n||!l)return;const g=i.current;g&&(g.scrollTop=g.scrollHeight)},[n,l,p]),r.jsxs("div",{ref:i,className:["pc-chat-thread",e.className].filter(Boolean).join(" "),children:[d.length?null:e.empty||null,m.map((g,v)=>{var N;const w=g[0],x=String(w.id||"")||String(w.ts||"")+":"+String(w.role||"")+":"+v;return w.toolActivity?r.jsx(xj,{tools:g.map(S=>S.toolActivity),showCopy:(N=e.messageProps)==null?void 0:N.showCopy},x):r.jsx(Tj,{message:w,...e.messageProps||{}},x)}),e.after,r.jsx("div",{ref:a})]})}const Bv=pe.forwardRef(function(t,n){const i=typeof t.rows=="number"&&Number.isFinite(t.rows)?Math.max(1,Math.trunc(t.rows)):3,a=!!t.disabled,l=!!t.busy,u=!a&&!l&&!!String(t.value||"").trim();return r.jsxs("div",{className:["pc-composer",t.className].filter(Boolean).join(" "),children:[t.leading,r.jsx("textarea",{ref:n,className:["pc-composer__textarea",t.textareaClassName].filter(Boolean).join(" "),value:t.value,onChange:d=>t.onChange(d.target.value),rows:i,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off",placeholder:t.placeholder||"","aria-label":t.ariaLabel||t.placeholder||"Message",disabled:a,autoFocus:!!t.autoFocus,onPaste:t.onPaste,onKeyDown:d=>{d.key!=="Enter"||d.shiftKey||d.nativeEvent.isComposing||d.keyCode===229||(d.preventDefault(),u&&t.onSubmit())}}),r.jsxs("div",{className:"pc-composer__row",children:[r.jsx("div",{className:"pc-composer__actions",children:t.actions}),r.jsx("button",{type:"button",className:t.sendButtonClassName||"pc-btn",disabled:!u,onClick:()=>t.onSubmit(),children:l?t.busyLabel||"Thinking…":t.sendLabel||"Send"})]}),t.overlay]})});function Lj(e){return!!(e&&typeof e[Symbol.asyncIterator]=="function")}function Oj(e){const[t,n]=_.useState([]),i=e.messages??t,a=S=>{e.onMessagesChange&&e.onMessagesChange(S),e.messages===void 0&&n(S)},l=_.useRef(i);l.current=i;const[u,d]=_.useState(""),[m,p]=_.useState(!1),g=_.useRef(null),v=e.assistantName||"Assistant",w=!!e.blockedNotice,x=async S=>{const R=String(S||"").trim();if(!R||m||w)return;d("");const T=l.current,z=[...T,{role:"user",content:R,ts:new Date().toISOString()}];a(z),p(!0);const H=new AbortController;g.current=H;try{const D=e.ask(R,{signal:H.signal,history:T});if(Lj(D)){let G="";const Q=[...z,{role:"assistant",title:v,content:"",ts:new Date().toISOString()}];a(Q);for await(const Y of D){if(H.signal.aborted)break;G+=String(Y??""),a([...z,{role:"assistant",title:v,content:G,ts:new Date().toISOString()}])}!G.trim()&&!H.signal.aborted&&a([...z,{role:"assistant",title:v,content:"#FALLBACK the assistant returned no answer.",level:"warn",ts:new Date().toISOString()}])}else{const G=String(await D??"").trim();a([...z,G?{role:"assistant",title:v,content:G,ts:new Date().toISOString()}:{role:"assistant",title:v,content:"#FALLBACK the assistant returned no answer.",level:"warn",ts:new Date().toISOString()}])}}catch(D){H.signal.aborted||a([...l.current,{role:"assistant",title:v,content:`#FALLBACK assistant request failed: ${String((D==null?void 0:D.message)||D||"unknown error")}`,level:"error",ts:new Date().toISOString()}])}finally{g.current===H&&(g.current=null),p(!1)}},N=_.useMemo(()=>i.length>0?null:r.jsxs("div",{className:"pc-assistant__empty",children:[r.jsx("div",{className:"pc-assistant__empty-text",children:e.emptyState||"Ask about this app — answers are grounded in its documentation."}),e.suggestions&&e.suggestions.length>0?r.jsx("div",{className:"pc-assistant__suggestions",children:e.suggestions.map(S=>r.jsx("button",{type:"button",className:"pc-assistant__suggestion",onClick:()=>void x(S),disabled:m||w,children:S},S))}):null]}),[i.length,e.emptyState,e.suggestions,m,w]);return r.jsxs("div",{className:`pc-assistant${e.className?` ${e.className}`:""}`,children:[r.jsxs("div",{className:"pc-assistant__thread",children:[N,r.jsx(Fv,{messages:i,autoScroll:!0}),w?r.jsx("div",{className:"pc-assistant__blocked",children:e.blockedNotice}):null]}),r.jsx("div",{className:"pc-assistant__composer",children:r.jsx(Bv,{value:u,onChange:d,onSubmit:()=>void x(u),placeholder:e.placeholder||"Ask about this app…",disabled:w,busy:m,rows:2,actions:m?r.jsx("button",{type:"button",className:"pc-btn",onClick:()=>{var S;(S=g.current)==null||S.abort()},children:"Stop"}):null})})]})}function Uv(e){return r.jsx(jv,{text:e,images:"link"})}function Pj(e){return r.jsx(vj,{...e,renderText:Uv})}const Ij="# AbstractObserver\n\n> Gateway-only observability UI (Web/PWA) for AbstractFramework runs: a browser SPA + tiny Node.js CLI that connects to an AbstractGateway HTTP API (HTTP fetch + SSE ledger streaming) and submits durable commands.\n\nThis repository is UI-only:\n- The packaged CLI (`bin/cli.js`) serves static assets from `dist/` (SPA fallback) and proxies `/api` to Gateway after hosted browser-session sign-in, using the shared session proxy from the `@abstractframework/app-server` runtime dependency.\n- The browser talks to same-origin `/api` in hosted mode; direct Gateway URLs remain available for local development via `src/lib/gateway_client.ts` (treat this file as the source of truth for HTTP endpoints and request shapes).\n- Hosted sign-in uses Gateway URL + user + token only to create an app-scoped browser session. Settings persistence strips Gateway bearer tokens. With `@abstractframework/app-server` 0.1.10 or newer the proxy sends the browser's connection address as `X-Forwarded-For` and `X-AbstractFramework-App-Proxy: abstractobserver` to the Gateway.\n- On non-local hosted UI hostnames, the server-configured Gateway URL is authoritative; browser-supplied Gateway URL changes are rejected unless `ABSTRACTOBSERVER_ALLOW_REMOTE_BROWSER_GATEWAY_CONFIG=1` is enabled behind access control. Forwarded host headers are trusted only when `ABSTRACTOBSERVER_TRUST_PROXY_HEADERS=1` or `ABSTRACTGATEWAY_TRUST_PROXY_HEADERS=1`.\n\n## Quickstart\n- Run packaged UI server (no build step): `npx --yes --package @abstractframework/observer -- abstractobserver`\n- Dev server (Vite; proxies `/api` in dev): `npm install && npm run dev`\n- Unit tests (Vitest): `npm test`\n- Production build (writes `dist/`): `npm run build`\n- Regenerate `llms-full.txt`: `npm run llms:full`\n\nNotes:\n- Build output lives in `dist/` and is served by `bin/cli.js` (don’t edit `dist/` manually).\n- Dev/build uses Vite aliases to sibling workspace packages under `../abstractuic/*/src` (see `vite.config.ts` and `docs/development.md`).\n- `llms.txt` format reference: https://llmstxt.org/\n\n## Documentation (start here)\n- [README](README.md): Install and quickstart\n- [Getting started](docs/getting-started.md): Run the UI and connect to a gateway\n- [FAQ](docs/faq.md): Common questions (grounded in code), including the CLI `/api` session proxy and the About dialog\n- [Docs index](docs/README.md): What to read next\n- [Architecture](docs/architecture.md): Components, data flow, diagrams\n- [Configuration](docs/configuration.md): CLI env vars, UI settings, deployment patterns\n- [API](docs/api.md): Gateway endpoints used by the UI, including Runtime Activity run pages and canonical artifact envelope search/stats for Runtime Artifact Explorer\n- [Automations](docs/automations.md): Launch → Automate (what, when in UTC intervals, independent/growing context, tool approval), the Automations page (controls, 409 conflicts), runs as a conversation, answering waits by kind, Discuss, automation tags on Board/Observe/System, legacy schedules and Recreate, the stub gateway\n- [Development](docs/development.md): Local dev, workspace deps, tests, build\n- [Security](docs/security.md): Trust boundaries and operational guidance\n- [Troubleshooting](docs/troubleshooting.md): Common issues and fixes (CORS, mixed content, 401 under `/api`, About shows the gateway unavailable, stale service worker, automations)\n\n## Key entrypoints (code)\n- [CLI server](bin/cli.js): static server (`PORT`, `HOST`, `ABSTRACTOBSERVER_GATEWAY_URL`), SPA fallback, `@abstractframework/app-server` session proxy, optional GPU widget config injection\n- [App shell + pages](src/ui/app.tsx): settings, page routing, observe/launch flows, durable commands\n- [Gateway client](src/lib/gateway_client.ts): HTTP client + SSE ledger streaming (API source of truth)\n- [Automations rules + controller](src/ui/automations.ts): workflow choice (`@default`), create body, run tags, capability gate, legacy prefill, typed wait answers, page controller\n- [Automations page](src/ui/automations_page.tsx) and [Automate fields](src/ui/automate_form.tsx): the page, rows and the ui-kit `AutomationPanel` wiring; the When/Context/Tools fields\n- [Automations stub gateway](scripts/automations_stub_server.mjs): dev/test stub serving the ui-kit fixtures\n- [Vite config](vite.config.ts): workspace aliases + dev session proxy and `/api` fallback proxy\n- [Package metadata](package.json): npm name/version, scripts, Node engine\n- [llms-full generator](scripts/generate-llms-full.mjs): defines which files are embedded into `llms-full.txt`\n\n## Ecosystem context\n- [AbstractFramework](https://github.com/lpalbou/AbstractFramework): ecosystem entrypoint and component map\n- [AbstractRuntime](https://github.com/lpalbou/abstractruntime): durable workflow runtime behind the gateway ledger\n- [AbstractCore](https://github.com/lpalbou/abstractcore): unified LLM + tools layer commonly used by workflows\n\n## Common tasks\n- Add/change a gateway capability: update `src/lib/gateway_client.ts` (source of truth) → update `docs/api.md` → run `npm test` + `npm run build`.\n- Change CLI behavior/config: update `bin/cli.js` → update `docs/configuration.md` → run `npm run build`.\n- Update docs for agents: edit docs → regenerate `llms-full.txt` with `npm run llms:full`.\n\n## Optional (project meta)\n- [Changelog](CHANGELOG.md): Release notes\n- [Contributing](CONTRIBUTING.md): How to develop and submit changes\n- [Security policy](SECURITY.md): Responsible vulnerability reporting\n- [Acknowledgments](ACKNOWLEDGMENTS.md): Credits\n- [Code of conduct](CODE_OF_CONDUCT.md): Conduct expectations and reporting\n- [License](LICENSE): MIT license\n",Dj="observer-docs-assistant",zj=1500,Fj=12e4;function Bj(e,t){return new Promise((n,i)=>{const a=setTimeout(n,e);t.addEventListener("abort",()=>{clearTimeout(a),i(new DOMException("aborted","AbortError"))},{once:!0})})}const Zh=1200;function Uj(e,t){const n=t.slice(-6),i=t.length-n.length,a=n.map(u=>{const d=u.role==="assistant"?"Assistant":"User",m=String(u.content||""),p=m.length>Zh?`${m.slice(0,Zh)}… [#TRUNCATION: ${Zh} of ${m.length} chars of this turn]`:m;return`${d}: ${p}`}).join(`
|
|
56
|
+
`),l=i>0?`[#TRUNCATION: showing the last ${n.length} turns; ${i} earlier turn(s) omitted]
|
|
57
|
+
`:"";return["You are the AbstractObserver in-app assistant. Answer questions about","using and understanding the AbstractObserver web app (pages: Board,","Observe/run page with Story/Ledger/Flow/Ask tabs, System with","Activity/Artifacts/Memory/Logs, Launch, Settings). Ground every answer","in the documentation index below; when the docs don't cover something,","say so plainly instead of guessing. Be concise and concrete.","","=== DOCUMENTATION INDEX (llms.txt) ===",Ij,"=== END DOCUMENTATION ===",a?`
|
|
58
|
+
Conversation so far:
|
|
59
|
+
`+l+a:"",`
|
|
60
|
+
User question: ${e}`].join(`
|
|
61
|
+
`)}function Wj(e){var t,n;for(let i=e.length-1;i>=0;i--){const a=e[i],l=a!=null&&a.result&&typeof a.result=="object"?a.result:null,u=[(t=l==null?void 0:l.response)==null?void 0:t.content,(n=l==null?void 0:l.response)==null?void 0:n.text,l==null?void 0:l.output,l==null?void 0:l.content,l==null?void 0:l.text];for(const d of u){const m=typeof d=="string"?d.trim():"";if(m)return m}}return""}function Hj(e){return async(t,n)=>{var d;const i=e(),a=n.history.map(m=>({role:m.role,content:String(m.content??"")})),l=await i.start_run(null,{prompt:Uj(t,a)},{bundle_id:"basic-agent",session_id:Dj}),u=Date.now();for(;;){if(await Bj(zj,n.signal),Date.now()-u>Fj)throw new Error("The assistant run timed out (120s). The run is still visible on the Observe page.");const m=await i.get_run(l),p=String((m==null?void 0:m.status)||"").trim().toLowerCase();if(p==="failed"||p==="cancelled"){const g=String(((d=m==null?void 0:m.error)==null?void 0:d.message)||(m==null?void 0:m.error)||"run "+p).slice(0,400);throw new Error(`The assistant run ${p}: ${g}`)}if(p==="completed"){const g=await i.get_ledger(l,{after:0,limit:500,signal:n.signal});return Wj(g.items)||"(the run completed but produced no readable answer — inspect it on the Observe page)"}}}}function qj(e){const t=_.useRef(e.gateway);t.current=e.gateway;const n=_.useMemo(()=>Hj(()=>t.current),[]),[i]=_.useState(void 0);return r.jsx(p0,{open:e.open,onClose:e.onClose,label:"Observer assistant",title:"Assistant",width:420,topOffset:e.topOffset,children:r.jsx(Oj,{ask:n,assistantName:"Observer",placeholder:"Ask about the observer…",blockedNotice:e.connected?i:"Connect to the gateway to use the assistant.",suggestions:["How do I see why a run failed?","Where do I find the artifacts a run produced?","What does the Board's Review column mean?","How do I launch a workflow on a schedule?"],emptyState:r.jsx("div",{children:"Answers are grounded in this app's documentation. Each question runs once through the connected gateway's basic agent."})})})}const Fm="@default:",z_="abstractcode.agent.v1";function Vj(e){const t=String(e||"").trim();if(t.startsWith(Fm)){const i=t.slice(Fm.length).trim();return i?{kind:"default",interface:i}:null}const n=t.indexOf(":");return n<=0||n>=t.length-1?null:{kind:"bundle",bundle_id:t.slice(0,n),flow_id:t.slice(n+1)}}function Gj(e){return e?e.kind==="default"?`${Fm}${e.interface}`:`${e.bundle_id}:${e.flow_id}`:""}function Kj(e){const t={};for(const i of e)for(const a of i.agent_default_interfaces||[])a&&!t[a]&&(t[a]=i.label);return[z_,...Object.keys(t).filter(i=>i!==z_).sort()].map(i=>({interface:i,value:`${Fm}${i}`,label:`Gateway default agent · ${i}${t[i]?` (now: ${t[i]})`:""}`}))}function Yj(e,t,n){if(!e)return null;if(e.kind==="default")return{flow_id:"@default",interface:e.interface,input_data:n};const i=String(t(e.bundle_id)||"").trim();if(!i)throw new Error(`The gateway listed no bundle_ref for bundle "${e.bundle_id}". Reload bundles, then try again.`);return{bundle_ref:i,flow_id:e.flow_id,input_data:n}}function Xj(e){const t={};for(const[n,i]of Object.entries(e||{}))if(typeof i=="string"){const a=i.trim();a&&(t[n]=a)}else i!==void 0&&(t[n]=i);return t}const Jj={once:"Run once: start this workflow now, a single run you can watch in Observe.",automate:"Automate: create an automation that runs this workflow on a schedule (every N minutes, hours or days) or when you ask; manage it on the Automations page."},Zj="#launch/automate";function Qj(e){const t=String(e||"").replace(/^#\/?/,"");if(t==="automations")return{page:"automations"};const n=/^launch(?:\/(once|automate))?$/.exec(t);return n?{page:"launch",mode:n[1]||"once"}:null}const F_={when:"every",amount:"24",unit:"h",once_at:"",context:"independent",tool_approval:"auto",title:"",start_at:"",count:"",until:""},xp={independent:"Each run starts fresh in its own session. Runs never see each other.",growing:"Each run is a new turn of one conversation and sees the previous runs. The history is bounded: the most recent 40 messages (at most 24,000 characters) are replayed; older runs drop out."};function Wv(e,t){const n=e.when==="every";return{prompt:t,when:n?{kind:"every",amount:Number(e.amount),unit:e.unit}:{kind:"once",at:e.once_at},context:e.context,toolApproval:e.tool_approval,title:e.title,...n&&e.start_at?{startAt:e.start_at}:{},...n&&e.count.trim()?{count:Number(e.count)}:{},...n&&e.until?{until:e.until}:{}}}function eS(e,t){if(t.input_data===null)return{ok:!1,errors:["The inputs are not valid JSON."]};const n=Xj(t.input_data),i=typeof n.prompt=="string"?n.prompt:"";delete n.prompt;let a;try{a=Yj(t.choice,t.bundle_ref_for,n)}catch(l){return{ok:!1,errors:[String((l==null?void 0:l.message)||l)]}}return Lv(Wv(e,i),{target:a,requestId:t.request_id})}function tS(e){const t=Lv(Wv(e,"preview"),{target:{flow_id:"@default",interface:z_},requestId:"preview"});if(!t.ok)return"";const n=t.body.trigger.config,i=$v(n);return e.when==="once"?`Runs ${i}.`:`Runs ${i}, first run ${n.start_at?`at ${tl(n.start_at)}`:"now"}.`}class nS{constructor(t){hs(this,"key","");hs(this,"id","");this.mint=t}id_for(t){return(!this.id||t!==this.key)&&(this.key=t,this.id=this.mint()),this.id}reset(){this.key="",this.id=""}}function rS(e,t,n){const i=eS(e,{...t,request_id:""});if(!i.ok)return i;const{request_id:a,...l}=i.body,u=n.id_for(JSON.stringify(l));return{ok:!0,body:{...i.body,request_id:u}}}function qo(e){return typeof e=="string"?e:e??null}function sS(e){var t,n,i,a,l,u;return{run_id:String((e==null?void 0:e.run_id)||"").trim(),workflow_id:qo(e==null?void 0:e.workflow_id),status:typeof(e==null?void 0:e.status)=="string"?String(e.status):"",created_at:qo(e==null?void 0:e.created_at),updated_at:qo(e==null?void 0:e.updated_at),ledger_len:typeof(e==null?void 0:e.ledger_len)=="number"?Number(e.ledger_len):(e==null?void 0:e.ledger_len)??null,parent_run_id:qo(e==null?void 0:e.parent_run_id),session_id:qo(e==null?void 0:e.session_id),actor_id:qo(e==null?void 0:e.actor_id),session_kind:qo(e==null?void 0:e.session_kind),automation_id:qo(e==null?void 0:e.automation_id),role:qo(e==null?void 0:e.role),occurrence_index:typeof(e==null?void 0:e.occurrence_index)=="number"?Number(e.occurrence_index):null,is_scheduled:typeof(e==null?void 0:e.is_scheduled)=="boolean"?!!e.is_scheduled:(e==null?void 0:e.is_scheduled)??null,paused:typeof(e==null?void 0:e.paused)=="boolean"?!!e.paused:(e==null?void 0:e.paused)??null,waiting_reason:typeof((t=e==null?void 0:e.waiting)==null?void 0:t.reason)=="string"?String(e.waiting.reason):((n=e==null?void 0:e.waiting)==null?void 0:n.reason)??null,schedule_interval:typeof((i=e==null?void 0:e.schedule)==null?void 0:i.interval)=="string"?String(e.schedule.interval).trim():((a=e==null?void 0:e.schedule)==null?void 0:a.interval)??null,schedule_target_workflow_id:typeof((l=e==null?void 0:e.schedule)==null?void 0:l.target_workflow_id)=="string"?String(e.schedule.target_workflow_id).trim():((u=e==null?void 0:e.schedule)==null?void 0:u.target_workflow_id)??null,current_node:typeof(e==null?void 0:e.current_node)=="string"?String(e.current_node).trim():(e==null?void 0:e.current_node)??null,llm_calls:typeof(e==null?void 0:e.llm_calls)=="number"?Number(e.llm_calls):(e==null?void 0:e.llm_calls)??null,tool_calls:typeof(e==null?void 0:e.tool_calls)=="number"?Number(e.tool_calls):(e==null?void 0:e.tool_calls)??null,tokens_total:typeof(e==null?void 0:e.tokens_total)=="number"?Number(e.tokens_total):(e==null?void 0:e.tokens_total)??null,error:(e==null?void 0:e.error)??null,waiting:(e==null?void 0:e.waiting)??null}}function Fd(e){const t=String((e==null?void 0:e.role)||"").trim(),n=String((e==null?void 0:e.session_kind)||"").trim();return t==="controller"?"automation":t==="occurrence"||t==="descendant"||n==="occurrence"?"occurrence":t==="discussion"||n==="discussion"?"discussion":t==="legacy_schedule"||(e==null?void 0:e.is_scheduled)===!0?"legacy":null}function Hv(e){const t=Fd(e);return t==="occurrence"?typeof e.occurrence_index=="number"?`occurrence #${e.occurrence_index}`:"occurrence":t==="legacy"?"legacy schedule":t||""}function bp(e){return String((e==null?void 0:e.role)||"").trim()==="controller"}function iS(e){var n,i,a;const t=(a=(i=(n=e==null?void 0:e.capabilities)==null?void 0:n.contracts)==null?void 0:i.common)==null?void 0:a.automations;return t&&typeof t=="object"&&t.available===!0?{available:!0,reason:""}:t&&typeof t=="object"&&t.available===!1?{available:!1,reason:"This gateway has the Automations API turned off."}:{available:!1,reason:"This gateway does not advertise the Automations API (capabilities.contracts.common.automations). Update AbstractGateway to use automations; legacy schedules stay manageable from their run view."}}function Ql(e){return e.legacy===!0||e.capabilities.includes("legacy")}function qv(e,t=Date.now()){const n=Ql(e),i=e.last_occurrence,a=i&&i.attempts>1?` after ${i.attempts} attempts`:"",l=e.attention.unread||e.attention.pending_waits>0;return{id:e.automation_id,title:e.title,cadence:gg(e.trigger),next_run:e.next_fire_at?`${tl(e.next_fire_at)} (${Mv(e.next_fire_at,t)})`:e.status==="paused"?"none while paused":"none scheduled",current:Av(e),state:e.status,last:i?i.excerpt:"",last_status:i?`#${i.index} ${i.status}${a}`:"no runs yet",attention:l?Tv(e):null,legacy:n}}function oS(e,t){const n=pg(e,[],t),i=e.last_occurrence,a=t?{enabled:!1,reason:"Working…"}:Ql(e)?{enabled:!1,reason:"Legacy schedule: managed with its existing controls."}:e.capabilities.includes("discuss")?i?{enabled:!0}:{enabled:!1,reason:"No occurrence to discuss yet."}:{enabled:!1,reason:"Not permitted for this automation."};return{pause:n.pause,resume:n.resume,run_now:n.run_now,edit:n.revise,archive:n.archive,discuss:a}}function aS(e,t){const n=l=>({enabled:!1,reason:l});if(t)return{legacy_pause:n("Working…"),legacy_resume:n("Working…"),legacy_run_now:n("Working…"),open_run:{enabled:!0},recreate:n("Working…")};const i=e.status==="paused",a=e.status==="active"||e.status==="paused";return{legacy_pause:i?n("Already suspended."):a?{enabled:!0}:n("The schedule has ended."),legacy_resume:i?{enabled:!0}:n(a?"Already running on schedule.":"The schedule has ended."),legacy_run_now:e.status==="active"?{enabled:!0}:n(i?"Resume the schedule first.":"The schedule has ended."),open_run:{enabled:!0},recreate:{enabled:!0}}}function lS(e,t){return e==="legacy_pause"?{type:"pause",payload:{reason:"Suspended from the Observer's Automations page"}}:e==="legacy_resume"?{type:"resume",payload:{}}:{type:"resume",payload:{payload:{mode:"run_now",requested_at:t}}}}const cS=/^([1-9][0-9]*)([smhd])$/;function uS(e){if(typeof e!="string"||!e.trim())return"";const t=Date.parse(e);return Number.isNaN(t)?"":new Date(t).toISOString().slice(0,16)}function dS(e,t){const n=e!=null&&e.schedule&&typeof e.schedule=="object"?e.schedule:null;if(!n)throw new Error("This run carries no legacy schedule metadata; nothing to recreate.");const i=String(n.target_bundle_ref||"").trim(),a=String(n.target_host_bundle_id||n.target_bundle_id||(i.includes("@")?i.slice(0,i.lastIndexOf("@")):"")||(t==null?void 0:t.bundle_id)||"").trim(),l=String(n.target_flow_id||(t==null?void 0:t.flow_id)||"").trim();if(!a||!l)throw new Error("The legacy schedule does not name its target workflow.");const u=[],d={...F_},m=typeof n.interval=="string"?n.interval.trim():"";if(!m)d.when="once",u.push("The legacy schedule ran once; pick the date and time (UTC) to run.");else{const w=cS.exec(m);let x=w?Number(w[1]):0,N=w?w[2]:"";N==="s"&&x%60===0&&(x=x/60,N="m"),N==="m"||N==="h"||N==="d"?(d.amount=String(x),d.unit=N):u.push(`The legacy interval "${m}" is not a whole number of minutes, hours or days; choose an interval.`)}typeof n.repeat_count=="number"&&n.repeat_count>=1&&(d.count=String(n.repeat_count));const p=uS(n.repeat_until);p&&(d.until=p),d.context=n.share_context===!1?"independent":"growing";const g=t&&typeof t.input_data=="object"&&t.input_data&&!Array.isArray(t.input_data)?t.input_data:{},v={};for(const[w,x]of Object.entries(g))w==="workflow_selection"||w.startsWith("_")||(v[w]=x);return{choice:{kind:"bundle",bundle_id:a,flow_id:l},input_data:v,form:d,notes:u}}const fS={items:[],loaded:!1,loading:!1,list_error:null,error:null,refreshed_at:null,status_filter:"",show_archived:!1,selected_id:"",detail:null,trigger_sources:[],busy:!1,notice:"",confirm_archive_id:""};function mS(e,t,n){return{answer_wait:async(i,a,l)=>{await e.submit_command({command_id:t(),run_id:i,type:"resume",payload:{wait_key:a,payload:l},client_id:"web_pwa"})},legacy_command:async(i,a,l)=>{await e.submit_command({command_id:t(),run_id:i,type:a,payload:l,client_id:"web_pwa"})},now_iso:n}}function hS(e,t){if(e==="ask_user"){if(typeof t.response!="string")throw new Error("An ask_user wait is answered with {response: string}.");return{response:t.response}}if(e==="tool_approval"){if(typeof t.approved!="boolean")throw new Error("A tool_approval wait is answered with {approved: true|false}.");const n=t.tool_ids;if(n!==void 0&&!(Array.isArray(n)&&n.every(i=>typeof i=="string")))throw new Error("tool_ids must be a list of strings.");return{approved:t.approved,...n!==void 0?{tool_ids:n}:{}}}if(e==="event"){if(!("payload"in t))throw new Error("An event wait is answered with {payload}.");return{payload:t.payload}}throw new Error(`This wait has no known kind (${JSON.stringify(e)}); the gateway must type its waits (ask_user, tool_approval, event).`)}function jp(e){return e.show_archived||e.status_filter==="archived"?e.items:e.items.filter(t=>t.status!=="archived")}function Sp(e){return e.items.filter(t=>t.status==="archived").length}function Vv(e,t){return`Discussion started from #${e} (session ${t.session_id}). It works in its own workspace ${t.workspace_root}; the automation's files are mounted read-only at ${t.mounted_workspace} for the file tools (shell commands are not sandboxed), and nothing is written back into the automation's session.`}const _S=3e4,fm=50;function Fi(e){return yg(e)?e:{status:0,code:"client_error",message:e&&typeof e=="object"&&"message"in e?String(e.message):String(e)}}function Qh(e,t){const n=new Map;for(const i of e)n.set(i.run_id,i);for(const i of t)n.set(i.run_id,i);return Array.from(n.values()).sort((i,a)=>a.index-i.index)}class gS{constructor(t,n,i=[1500,4e3]){hs(this,"state",{...fS});hs(this,"listeners",new Set);hs(this,"list_seq",0);hs(this,"detail_seq",0);hs(this,"sources_loaded",!1);this.client=t,this.host=n,this.followups_ms=i}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t)}}set(t){this.state={...this.state,...t};for(const n of this.listeners)n()}async list_all(){const t=[];let n;for(let i=0;i<200;i+=1){const a=await this.client.listAutomations({...this.state.status_filter?{status:this.state.status_filter}:{},...n?{cursor:n}:{},limit:fm});if(t.push(...a.items),!a.next_cursor)return t;n=a.next_cursor}throw new Error("GET /api/gateway/automations kept returning next_cursor after 200 pages.")}async refresh(){const t=++this.list_seq;this.set({loading:!0});try{const n=await this.list_all();if(t!==this.list_seq)return;const i=this.state.detail,a=i?n.find(l=>l.automation_id===i.automation_id):void 0;this.set({items:n,loaded:!0,loading:!1,list_error:null,refreshed_at:Date.now(),...i&&a?{detail:{...i,summary:a}}:{}}),i&&await this.reload_occurrences(i.automation_id)}catch(n){if(t!==this.list_seq)return;this.set({loading:!1,loaded:!0,list_error:Fi(n)})}}async set_status_filter(t){this.set({status_filter:t}),await this.refresh()}async load_trigger_sources(){if(this.sources_loaded)return;const t=await this.client.listTriggerSources();this.sources_loaded=!0,this.set({trigger_sources:t.items})}async select(t){var a;const n=String(t||"").trim(),i=++this.detail_seq;if(!n){this.set({selected_id:"",detail:null});return}this.set({selected_id:n,notice:"",...((a=this.state.detail)==null?void 0:a.automation_id)!==n?{detail:null}:{}});try{const l=this.state.items.find(m=>m.automation_id===n);if(l&&Ql(l)){this.set({detail:{automation_id:n,summary:l,definition:null,occurrences:[],next_cursor:null,error:null}});return}const[u,d]=await Promise.all([this.client.getAutomation(n),this.client.listOccurrences(n,{limit:fm})]);if(i!==this.detail_seq)return;this.set({detail:{automation_id:n,summary:l??u.summary,definition:u.definition,occurrences:Qh([],d.items),next_cursor:d.next_cursor,error:null}}),await this.load_trigger_sources()}catch(l){if(i!==this.detail_seq)return;this.set({error:Fi(l)})}}async reload_occurrences(t){const n=this.state.detail;if(!n||n.automation_id!==t||Ql(n.summary))return;const[i,a]=await Promise.all([this.client.getAutomation(t),this.client.listOccurrences(t,{limit:fm})]),l=this.state.detail;if(!l||l.automation_id!==t)return;const u=this.state.items.find(d=>d.automation_id===t);this.set({detail:{...l,summary:u??i.summary,definition:i.definition,occurrences:Qh(l.occurrences,a.items),next_cursor:l.occurrences.length>a.items.length?l.next_cursor:a.next_cursor}})}async load_more(){const t=this.state.detail;if(!(!t||!t.next_cursor))try{const n=await this.client.listOccurrences(t.automation_id,{cursor:t.next_cursor,limit:fm}),i=this.state.detail;if(!i||i.automation_id!==t.automation_id)return;this.set({detail:{...i,occurrences:Qh(i.occurrences,n.items),next_cursor:n.next_cursor}})}catch(n){this.set({error:Fi(n)})}}async after_change(t){await this.refresh();for(const n of this.followups_ms)setTimeout(()=>void this.refresh(),n)}async command(t,n,i,a){this.set({busy:!0});try{const l=await this.client.sendAutomationCommand(t,{type:n,...i?{payload:i}:{},...a?{command_id:a}:{}});return await this.after_change(t),l}catch(l){throw Fi(l)}finally{this.set({busy:!1})}}async revise(t,n,i,a){this.set({busy:!0});try{const l=await this.client.reviseAutomation(t,{changes:n,...i!==null?{expected_revision:i}:{},...a?{command_id:a}:{}});return await this.after_change(t),l}catch(l){throw Fi(l)}finally{this.set({busy:!1})}}async discuss(t,n,i,a){this.set({busy:!0});try{const l=await this.client.discuss(t,{occurrence_index:n,prompt:i,...a?{request_id:a}:{}});return this.set({notice:Vv(n,l)}),l}catch(l){throw Fi(l)}finally{this.set({busy:!1})}}async seen(t,n){try{await this.client.markSeen(t,n)}catch(i){throw Fi(i)}}async answer_wait(t,n,i,a){var l;this.set({busy:!0});try{const u=(((l=this.state.detail)==null?void 0:l.occurrences)||[]).flatMap(d=>d.waits).find(d=>d.run_id===n&&d.wait_key===i);if(!u)throw new Error(`No loaded wait ${i} on run ${n}; reload the automation.`);await this.host.answer_wait(n,i,hS(u.kind,a)),await this.after_change(t)}catch(u){throw Fi(u)}finally{this.set({busy:!1})}}async row_action(t,n){const i=`automation.${n}`;this.set({error:null,notice:""});try{await this.command(t.automation_id,i),this.set({notice:n==="run_now"&&t.status==="paused"?`Run now sent to “${t.title}”; it stays paused.`:`${n.replace("_"," ")} sent to “${t.title}”.`,confirm_archive_id:""})}catch(a){this.set({error:Fi(a)})}}set_show_archived(t){this.set({show_archived:t})}ask_archive(t){this.set({confirm_archive_id:t})}async legacy_action(t,n){if(!Ql(t))throw new Error("legacy_action on a non-legacy automation");const i=lS(n,this.host.now_iso());this.set({busy:!0,error:null,notice:""});try{await this.host.legacy_command(t.automation_id,i.type,i.payload),this.set({notice:`${i.type==="pause"?"Suspend":n==="legacy_run_now"?"Run now":"Resume"} sent to “${t.title}”.`}),await this.refresh()}catch(a){this.set({error:Fi(a)})}finally{this.set({busy:!1})}}report_error(t){this.set({error:Fi(t)})}clear_notice(){this.set({notice:"",error:null})}}function pS(e){const t=(n,i,a)=>r.jsx("button",{type:"button",role:"radio","aria-checked":e.mode===n,className:`seg_btn ${e.mode===n?"active":""}`,"data-mode":n,title:a,onClick:()=>e.on_change(n),children:i});return r.jsxs("div",{className:"launch_mode",children:[r.jsxs("div",{className:"seg_toggle launch_mode_switch",role:"radiogroup","aria-label":"Launch mode","aria-describedby":"launch_mode_help",children:[t("once","Run once"),t("automate","Automate",e.automate_available?void 0:e.automate_reason)]}),r.jsx("p",{className:"launch_mode_help",id:"launch_mode_help","data-mode-help":e.mode,"aria-live":"polite",children:Jj[e.mode]})]})}function yS(e){const t=e.form,n=tS(t);return r.jsxs("div",{className:"automate_fields",children:[r.jsxs("fieldset",{"data-section":"when",children:[r.jsx("legend",{children:"When (UTC)"}),r.jsxs("div",{className:"automate_row",role:"radiogroup","aria-label":"Schedule kind",children:[r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"automate_when",value:"every",checked:t.when==="every",disabled:e.disabled,onChange:()=>e.on_change({when:"every"})})," Repeat"]}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"automate_when",value:"once",checked:t.when==="once",disabled:e.disabled,onChange:()=>e.on_change({when:"once"})})," Once at…"]})]}),t.when==="every"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"automate_row",role:"group","aria-label":"Presets",children:J0.map(i=>i.when.kind==="every"?r.jsx("button",{type:"button",className:"btn btn_sm","data-preset":i.label,"aria-pressed":Number(t.amount)===i.when.amount&&t.unit===i.when.unit,disabled:e.disabled,onClick:()=>{i.when.kind==="every"&&e.on_change({amount:String(i.when.amount),unit:i.when.unit})},children:i.label},i.label):null)}),r.jsxs("div",{className:"automate_row",children:[r.jsx("span",{children:"Every"}),r.jsx("input",{type:"number",min:1,step:1,value:t.amount,disabled:e.disabled,"aria-label":"Interval amount",onChange:i=>e.on_change({amount:i.target.value})}),r.jsxs("select",{value:t.unit,disabled:e.disabled,"aria-label":"Interval unit",onChange:i=>e.on_change({unit:i.target.value}),children:[r.jsx("option",{value:"m",children:"minutes"}),r.jsx("option",{value:"h",children:"hours"}),r.jsx("option",{value:"d",children:"days"})]})]})]}):r.jsxs("label",{className:"automate_row",children:[r.jsx("span",{children:"Run once at (UTC)"}),r.jsx("input",{type:"datetime-local",value:t.once_at,disabled:e.disabled,onChange:i=>e.on_change({once_at:i.target.value})})]}),r.jsx("div",{className:"automate_preview","aria-live":"polite","data-preview":"true",children:n||"Incomplete schedule."})]}),r.jsxs("fieldset",{"data-section":"context",children:[r.jsx("legend",{children:"Context"}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"automate_context",value:"independent",checked:t.context==="independent",disabled:e.disabled,onChange:()=>e.on_change({context:"independent"})})," ",r.jsx("strong",{children:"Independent"})," (default) — ",xp.independent]}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"automate_context",value:"growing",checked:t.context==="growing",disabled:e.disabled,onChange:()=>e.on_change({context:"growing"})})," ",r.jsx("strong",{children:"Growing"})," — ",xp.growing]})]}),r.jsxs("fieldset",{"data-section":"tools",children:[r.jsx("legend",{children:"Tools"}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"automate_tools",value:"auto",checked:t.tool_approval==="auto",disabled:e.disabled,onChange:()=>e.on_change({tool_approval:"auto"})})," ",ej,e.tools&&e.tools.length?r.jsxs("span",{className:"automate_preview",children:[" — ",e.tools.join(", ")]}):null]}),r.jsxs("label",{children:[r.jsx("input",{type:"radio",name:"automate_tools",value:"ask",checked:t.tool_approval==="ask",disabled:e.disabled,onChange:()=>e.on_change({tool_approval:"ask"})})," Ask each time — every tool call waits for your approval on the Automations page"]})]})]})}function vS(e){const t=e.form;return r.jsxs("div",{className:"automate_fields launch_grid","data-section":"advanced-schedule",children:[r.jsxs("label",{className:"launch_grid_cell",style:{gridColumn:"1 / -1"},children:[r.jsx("span",{className:"launch_label",children:"Title"}),r.jsx("input",{value:t.title,maxLength:120,disabled:e.disabled,placeholder:"Defaults to the prompt's first line",onChange:n=>e.on_change({title:n.target.value})})]}),t.when==="every"?r.jsxs(r.Fragment,{children:[r.jsxs("label",{className:"launch_grid_cell",children:[r.jsx("span",{className:"launch_label",children:"First run at (UTC; empty = now)"}),r.jsx("input",{type:"datetime-local",value:t.start_at,disabled:e.disabled,onChange:n=>e.on_change({start_at:n.target.value})})]}),r.jsxs("label",{className:"launch_grid_cell",children:[r.jsx("span",{className:"launch_label",children:"Stop after this many runs"}),r.jsx("input",{type:"number",min:1,step:1,value:t.count,disabled:e.disabled,onChange:n=>e.on_change({count:n.target.value})})]}),r.jsxs("label",{className:"launch_grid_cell",children:[r.jsx("span",{className:"launch_label",children:"Stop at (UTC)"}),r.jsx("input",{type:"datetime-local",value:t.until,disabled:e.disabled,onChange:n=>e.on_change({until:n.target.value})})]})]}):null]})}const wS=[["","All"],["active","Active"],["paused","Paused"],["completed","Completed"],["failed","Failed"],["archived","Archived"]],xS={pause:"Pause",resume:"Resume",run_now:"Run now",edit:"Edit",archive:"Archive…",discuss:"Discuss"},bS={legacy_pause:"Suspend",legacy_resume:"Resume",legacy_run_now:"Run now",open_run:"Open run",recreate:"Recreate as automation"};function jS(e){const t=e.summary,n=qv(t),i=e.state.selected_id===t.automation_id,a=e.state.busy,l=(m,p,g,v,w)=>r.jsx("button",{type:"button",className:`btn btn_sm${w?` ${w}`:""}`,"data-action":m,disabled:!g.enabled,title:g.reason,onClick:v,children:p},m);let u;if(n.legacy){const m=aS(t,a);u=[t.status==="paused"?"legacy_resume":"legacy_pause","legacy_run_now","open_run","recreate"].map(g=>l(g,bS[g],m[g],()=>e.h.on_legacy_action(t,g)))}else{const m=oS(t,a);u=[t.status==="paused"?"resume":"pause","run_now","edit","archive","discuss"].map(g=>l(g,xS[g],m[g],()=>e.h.on_row_action(t,g),g==="archive"?"danger":void 0))}const d=e.state.confirm_archive_id===t.automation_id;return r.jsxs("li",{className:`auto_row${i?" selected":""}`,"data-automation-id":t.automation_id,"data-legacy":n.legacy?"true":void 0,children:[r.jsxs("button",{type:"button",className:"auto_row_main",onClick:()=>e.h.on_select(t.automation_id),"aria-current":i?"true":void 0,children:[r.jsxs("span",{className:"auto_row_title",children:[n.title,n.legacy?r.jsx("span",{className:"chip scheduled",children:"legacy"}):null,r.jsx("span",{className:`chip ${n.state==="failed"?"danger":n.state==="paused"?"warn":n.state==="active"?"info":"muted"}`,"data-field":"state",children:n.state}),n.attention?r.jsx("span",{className:"chip warn auto_row_attention","data-field":"attention",children:n.attention}):null]}),r.jsxs("span",{className:"auto_row_facts",children:[r.jsx("span",{"data-field":"cadence",children:n.cadence}),n.current?r.jsx("span",{className:"auto_row_current","data-field":"current",children:n.current}):null,r.jsxs("span",{"data-field":"next",children:["next: ",n.next_run]}),r.jsx("span",{"data-field":"last-status",children:n.last_status})]}),n.last?r.jsx("span",{className:"auto_row_excerpt","data-field":"excerpt",children:Uv(n.last)}):null]}),r.jsx("div",{className:"auto_row_actions",role:"toolbar","aria-label":`Controls for ${n.title}`,children:u}),d?r.jsxs("div",{className:"auto_row_confirm",role:"group","aria-label":"Confirm archive",children:[r.jsxs("span",{children:["Archive “",n.title,"”? Its history stays readable; it will not run again."]}),r.jsx("button",{type:"button",className:"btn btn_sm danger","data-action":"archive-confirm",disabled:a,onClick:()=>e.h.on_confirm_archive(t),children:"Archive"}),r.jsx("button",{type:"button",className:"btn btn_sm","data-action":"archive-cancel",onClick:e.h.on_cancel_archive,children:"Keep it"})]}):null]})}function SS(e){const t=e.state,n=t.error??t.list_error,i=n?Dm(n):null;return r.jsxs("section",{className:"pane auto_list","aria-label":"Automations",children:[r.jsxs("div",{className:"pane_header",children:[r.jsx("span",{className:"pane_title",children:"Automations"}),r.jsx("span",{className:"pane_count",children:jp(t).length}),r.jsx("span",{className:"pane_spacer"}),r.jsx("select",{className:"seg_select",value:t.status_filter,onChange:a=>e.h.on_status_filter(a.target.value),"aria-label":"Filter by status",children:wS.map(([a,l])=>r.jsx("option",{value:a,children:l},a||"all"))}),r.jsx("button",{type:"button",className:"btn btn_sm",onClick:e.h.on_refresh,disabled:t.loading||!e.available.available,children:t.loading?"…":"Refresh"})]}),r.jsxs("div",{className:"pane_body scroll",children:[r.jsx("a",{className:`btn primary auto_new${e.available.available?"":" disabled"}`,"data-action":"new",href:Zj,"aria-disabled":!e.available.available,title:"Open Launch in Automate mode",onClick:a=>{a.preventDefault(),e.available.available&&e.h.on_new()},children:"+ New automation"}),e.available.available?null:r.jsx("div",{className:"warn_callout",role:"note","data-unavailable":"true",children:e.available.reason}),i?r.jsxs("div",{className:"observe_context_card error",role:"alert","data-code":n==null?void 0:n.code,children:[r.jsx("strong",{children:i.title})," ",r.jsx("span",{children:i.detail})]}):null,t.notice?r.jsx("div",{className:"help_text muted",role:"status",children:t.notice}):null,e.available.available&&t.loaded&&!t.items.length?r.jsx("div",{className:"help_text muted",children:"No automations yet. Create one from Launch → Automate."}):null,Sp(t)>0&&t.status_filter!=="archived"?r.jsxs("label",{className:"auto_show_archived help_text muted",children:[r.jsx("input",{type:"checkbox","data-action":"show-archived",checked:t.show_archived,onChange:a=>e.h.on_show_archived(a.target.checked)})," Show archived (",Sp(t),")"]}):null,r.jsx("ul",{className:"auto_rows",children:jp(t).map(a=>r.jsx(jS,{summary:a,state:t,h:e.h},a.automation_id))})]})]})}function kS(e,t){const n=e.state,i=n.detail;if(!i||Ql(i.summary))return null;const a=i.automation_id;return{summary:i.summary,...i.definition?{definition:i.definition}:{},occurrences:i.occurrences,triggerSources:n.trigger_sources,busy:n.busy,...i.error?{error:i.error}:{},onRevise:(l,u,d)=>e.revise(a,l,u,d==null?void 0:d.command_id),onCommand:(l,u,d)=>e.command(a,l,u,d==null?void 0:d.command_id),onDiscuss:async(l,u,d)=>{const m=await e.discuss(a,l,u,d==null?void 0:d.request_id);return t.on_open_session(m,Vv(l,m)),m},onSeen:l=>e.seen(a,l),onLoadMore:()=>void e.load_more(),onOpenRun:l=>t.on_open_run(l),onAnswerWait:(l,u,d)=>e.answer_wait(a,l,u,d)}}function NS(e){const t=e.ctl.state.detail;if(!t&&e.ctl.state.selected_id)return r.jsx("section",{className:"pane auto_detail auto_detail_empty","aria-busy":"true",children:r.jsx("div",{className:"help_text muted",children:"Loading…"})});if(!t)return r.jsx("section",{className:"pane auto_detail auto_detail_empty",children:r.jsxs("div",{className:"help_text muted",children:["Select an automation to read its runs as a conversation, change it, or discuss a result (",I_.toLowerCase(),")."]})});if(Ql(t.summary)){const i=qv(t.summary);return r.jsxs("section",{className:"pane auto_detail","data-legacy":"true",children:[r.jsxs("div",{className:"pane_header",children:[r.jsx("span",{className:"pane_title",children:i.title}),r.jsx("span",{className:"chip scheduled",children:"legacy"})]}),r.jsxs("div",{className:"pane_body",children:[r.jsxs("p",{className:"help_text",children:["A schedule created before automations (",i.cadence,"). It keeps working with its existing controls: suspend, resume, run now and edit the interval from its run view. “Recreate as automation” opens Launch → Automate prefilled with its workflow, inputs and interval; the legacy schedule is not changed."]}),r.jsxs("div",{className:"auto_row_actions",children:[r.jsx("button",{type:"button",className:"btn btn_sm","data-action":"open_run",onClick:()=>e.h.on_legacy_action(t.summary,"open_run"),children:"Open run"}),r.jsx("button",{type:"button",className:"btn btn_sm primary","data-action":"recreate",onClick:()=>e.h.on_legacy_action(t.summary,"recreate"),children:"Recreate as automation"})]})]})]})}const n=kS(e.ctl,e.host);return r.jsx("section",{className:"pane auto_detail",children:n?r.jsx(Pj,{...n}):null})}function CS(e){const t=e.ctl;_.useSyncExternalStore(a=>t.subscribe(a),()=>t.state);const[n,i]=_.useState(()=>typeof document>"u"||document.visibilityState!=="hidden");return _.useEffect(()=>{const a=()=>i(document.visibilityState!=="hidden");return document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[]),_.useEffect(()=>{if(!e.active||!n||!e.available.available)return;t.refresh();const a=window.setInterval(()=>void t.refresh(),_S);return()=>window.clearInterval(a)},[t,e.active,n,e.available.available]),r.jsxs("div",{className:"page auto_page",children:[r.jsx(SS,{state:t.state,available:e.available,h:e.h}),r.jsx(NS,{ctl:t,host:e.host,h:e.h})]})}function $S(){const e="0.1.14".trim();if(!e)throw new Error("AbstractObserver: __APP_VERSION__ is not defined; the vite/vitest config must inject it from package.json");return e}function ES(){return b0("abstractobserver",$S())}async function AS(e){let t;try{t=await e.gateway_about()}catch(n){return pp(null,n instanceof Error?n.message||n.name:String(n))}return pp(t)}class Bm{constructor(t){this._maxSize=Bm._normalizeMaxSize(t),this._values=[]}get maxSize(){return this._maxSize}get size(){return this._values.length}static _normalizeMaxSize(t){const n=Number(t);return!Number.isFinite(n)||n<=0?1:Math.min(1e3,Math.floor(n))}setMaxSize(t){const n=Bm._normalizeMaxSize(t);this._maxSize=n,this._values.length>n&&(this._values=this._values.slice(this._values.length-n))}clear(){this._values=[]}push(t){const n=Number(t),i=Number.isFinite(n)?n:null;this._values.push(i),this._values.length>this._maxSize&&this._values.splice(0,this._values.length-this._maxSize)}values(){return this._values.slice()}last(){return this._values.length?this._values[this._values.length-1]:null}}function MS(e){try{return new URL(String(e)),!0}catch{return!1}}function TS({baseUrl:e,endpoint:t}){const n=String(t||"/api/gateway/host/metrics/gpu");return MS(n)?n:e&&String(e).trim()?new URL(n,String(e)).toString():n}async function RS({token:e,getToken:t}){if(typeof t=="function"){const n=await t();return n==null?"":String(n)}return e==null?"":String(e)}function LS({token:e}){const t=String(e||"").trim();return t?{Authorization:`Bearer ${t}`}:{}}function OS(e){if(!e||typeof e!="object")return null;const t=Number(e.utilization_gpu_pct);if(Number.isFinite(t))return t;const n=e.gpus;if(Array.isArray(n)&&n.length){const i=n.map(l=>Number(l&&l.utilization_gpu_pct)).filter(l=>Number.isFinite(l));return i.length?i.reduce((l,u)=>l+u,0)/i.length:null}return null}async function PS({baseUrl:e,endpoint:t,token:n,getToken:i,signal:a,fetchImpl:l}={}){const u=TS({baseUrl:e,endpoint:t}),d=await RS({token:n,getToken:i}),m=l||globalThis.fetch;if(typeof m!="function")return{ok:!1,status:0,error:"fetch_unavailable",payload:null};let p;try{p=await m(u,{method:"GET",headers:{Accept:"application/json",...LS({token:d})},signal:a})}catch(v){return{ok:!1,status:0,error:"network_error",detail:v instanceof Error?v.message:String(v),payload:null}}let g=null;try{g=await p.json()}catch{g=null}return{ok:p.ok,status:p.status,error:p.ok?null:"http_error",payload:g}}const jd=Object.freeze({tickMs:1500,historySize:20,endpoint:"/api/gateway/host/metrics/gpu",baseUrl:"",mode:"full"});function IS(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function kp(e,t,n){return Number.isFinite(e)?Math.min(n,Math.max(t,e)):t}function Np(e,t){const n=Number(e);return Number.isFinite(n)?Math.floor(n):t}function e_(e,t=1){const n=kp(Number(e)/100,0,1),i=Math.round(140-140*n),a=kp(Number(t),0,1);return a>=1?`hsl(${i} 85% 55%)`:`hsl(${i} 85% 55% / ${a})`}function Cp(e){const t={...jd,...e||{}};return t.tickMs=Math.max(250,Np(t.tickMs,jd.tickMs)),t.historySize=Math.max(1,Math.min(200,Np(t.historySize,jd.historySize))),t.endpoint=String(t.endpoint||jd.endpoint),t.baseUrl=String(t.baseUrl||""),t.mode=String(t.mode||jd.mode).trim().toLowerCase(),t.mode!=="icon"&&(t.mode="full"),t}function DS(){return`
|
|
62
|
+
:host{display:inline-block;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,"Apple Color Emoji","Segoe UI Emoji";line-height:1}
|
|
63
|
+
.wrap{box-sizing:border-box;display:flex;flex-direction:column;gap:6px;padding:var(--monitor-gpu-padding,8px 10px);border:1px solid var(--monitor-gpu-border,#2a2f3a);border-radius:var(--monitor-gpu-radius,10px);background:var(--monitor-gpu-bg,#0b1020);color:var(--monitor-gpu-fg,#e7eaf0);width:var(--monitor-gpu-width,180px)}
|
|
64
|
+
.wrap.icon{gap:var(--monitor-gpu-gap,4px);padding:var(--monitor-gpu-padding,4px);border-radius:var(--monitor-gpu-radius,999px);width:var(--monitor-gpu-width,30px);background:linear-gradient(180deg,rgba(255,255,255,0.08),rgba(255,255,255,0.02)),var(--monitor-gpu-bg,#0b1020);box-shadow:0 0 14px var(--monitor-gpu-accent-glow, rgba(76,195,255,0.18))}
|
|
65
|
+
.wrap.icon .top{display:none}
|
|
66
|
+
.wrap.icon .bars{height:var(--monitor-gpu-bars-height,18px)}
|
|
67
|
+
.top{display:flex;align-items:baseline;justify-content:space-between;gap:10px}
|
|
68
|
+
.label{font-size:var(--monitor-gpu-font-size,var(--font-size-sm,12px));opacity:.9}
|
|
69
|
+
.value{font-variant-numeric:tabular-nums;font-size:var(--monitor-gpu-font-size,var(--font-size-sm,12px));opacity:.95}
|
|
70
|
+
.bars{display:flex;align-items:flex-end;gap:2px;height:var(--monitor-gpu-bars-height,34px);overflow:hidden}
|
|
71
|
+
.bar{flex:1;min-width:0;border-radius:2px;background:var(--monitor-gpu-bar,#4cc3ff);height:2px;opacity:.9;transition:height .25s ease, background .25s ease, opacity .25s ease}
|
|
72
|
+
.bar.missing{background:var(--monitor-gpu-bar-missing,#62708a);opacity:.35}
|
|
73
|
+
.bar.error{background:var(--monitor-gpu-bar-error,#ff6b6b);opacity:.7}
|
|
74
|
+
.muted{opacity:.6}
|
|
75
|
+
`}class zS{constructor(t,n={}){if(!t||typeof t!="object")throw new TypeError("target element is required");this._target=t,this._opts=Cp(n),this._buffer=new Bm(this._opts.historySize),this._timer=null,this._timer_gen=0,this._running=!1,this._abort=null,this._resumeTimer=null,this._mounted=!1,this._els=null,this._token=n.token,this._getToken=n.getToken,this._stoppedForAuth=!1}get options(){return{...this._opts}}set token(t){this._token=t,String(this._token||"").trim()&&this._stoppedForAuth&&(this._stoppedForAuth=!1,this.start())}get token(){return this._token}set getToken(t){this._getToken=t}get getToken(){return this._getToken}mount(){if(this._mounted)return;if(typeof document>"u")throw new Error("MonitorGpuWidget requires a browser DOM");const t=this._target;t.textContent="";const n=document.createElement("style");n.textContent=DS();const i=document.createElement("div");i.className=this._opts.mode==="icon"?"wrap icon":"wrap";const a=document.createElement("div");a.className="top";const l=document.createElement("div");l.className="label",l.textContent="GPU";const u=document.createElement("div");u.className="value muted",u.textContent="—",a.appendChild(l),a.appendChild(u);const d=document.createElement("div");d.className="bars",i.appendChild(a),i.appendChild(d),t.appendChild(n),t.appendChild(i),this._els={wrap:i,value:u,bars:d},this._mounted=!0,this._rebuildBars(),this._render()}start(){this.mount(),!this._running&&(this._running=!0,this._timer_gen+=1,this._poll_loop(this._timer_gen))}stop(){this._running=!1,this._timer_gen+=1,this._timer&&(clearTimeout(this._timer),this._timer=null),this._resumeTimer&&(clearTimeout(this._resumeTimer),this._resumeTimer=null),this._abort&&(this._abort.abort(),this._abort=null)}destroy(){this.stop(),this._target&&this._mounted&&(this._target.textContent=""),this._mounted=!1,this._els=null}setOptions(t){const n=Cp({...this._opts,...t||{}}),i=n.historySize!==this._opts.historySize,a=n.tickMs!==this._opts.tickMs,l=n.mode!==this._opts.mode;this._opts=n,l&&this._mounted&&this._els&&this._els.wrap&&(this._els.wrap.className=n.mode==="icon"?"wrap icon":"wrap"),i&&(this._buffer.setMaxSize(n.historySize),this._mounted&&this._rebuildBars()),a&&this._running?(this.stop(),this.start()):this._mounted&&this._render()}push(t){this._buffer.push(t),this._render()}_rebuildBars(){if(!this._els)return;const{bars:t}=this._els;t.textContent="";for(let n=0;n<this._opts.historySize;n+=1){const i=document.createElement("div");i.className="bar missing",i.style.height="2px",t.appendChild(i)}}_render({error:t=!1}={}){if(!this._els)return;const{wrap:n,value:i,bars:a}=this._els,l=this._buffer.values(),u=this._buffer.last(),d=Number.isFinite(u)?Math.max(0,Math.min(100,u)):null;d==null?(i.textContent=t?"N/A":"—",i.classList.add("muted")):(i.textContent=`${d.toFixed(0)}%`,i.classList.remove("muted")),n&&(n.title=d==null?"GPU —":`GPU ${d.toFixed(0)}%`,d==null?(n.style.removeProperty("--monitor-gpu-accent"),n.style.removeProperty("--monitor-gpu-accent-glow")):(n.style.setProperty("--monitor-gpu-accent",e_(d,.95)),n.style.setProperty("--monitor-gpu-accent-glow",e_(d,.35))));const m=Array.from(a.children),p=Math.max(0,m.length-l.length),g=Math.max(2,a&&typeof a.clientHeight=="number"&&a.clientHeight>0?a.clientHeight:34);for(let v=0;v<m.length;v+=1){const w=m[v],x=v-p,N=x>=0?l[x]:null,S=Number.isFinite(N)?N:null,R=S==null?0:IS(S/100),T=Math.max(2,Math.min(g,Math.round(R*g)));w.style.height=`${T}px`,w.style.background=S==null?"":e_(S),w.className="bar",S==null&&w.classList.add("missing"),t&&w.classList.add("error")}}async _tick(){const t=String(this._token||"").trim(),n=this._getToken,i=!!t||typeof n=="function";this._abort&&this._abort.abort(),this._abort=new AbortController;const a=await PS({baseUrl:this._opts.baseUrl,endpoint:this._opts.endpoint,token:t,getToken:n,signal:this._abort.signal}),l=a&&a.payload,u=l&&typeof l=="object"?l.supported!==!1:!0,d=OS(l);if(!a.ok){if(this._buffer.push(null),this._render({error:!0}),a.status===401||a.status===403){const m=String(this._token||"").trim(),p=typeof this._getToken=="function";if(!i&&(!!m||p))return;this._stoppedForAuth=!0,this.stop()}else a.status===429&&(this.stop(),this._resumeTimer=setTimeout(()=>{this._resumeTimer=null,this._mounted&&this.start()},3e4));return}if(!u||d==null){this._buffer.push(null),this._render();return}this._buffer.push(d),this._render()}async _poll_loop(t){!this._running||t!==this._timer_gen||(await this._tick(),!(!this._running||t!==this._timer_gen)&&(this._timer=setTimeout(()=>{this._timer=null,this._poll_loop(t)},this._opts.tickMs)))}}function FS(e="monitor-gpu"){if(typeof globalThis>"u"||typeof globalThis.customElements>"u"||globalThis.customElements.get(e))return;const t=globalThis.HTMLElement||class{};class n extends t{static get observedAttributes(){return["tick-ms","history-size","endpoint","base-url","mode"]}constructor(){super(),this._shadow=this.attachShadow?this.attachShadow({mode:"open"}):null;const a=this._shadow||this;this._controller=new zS(a,{}),this._upgradeProperty("token"),this._upgradeProperty("getToken"),this._upgradeProperty("mode")}_upgradeProperty(a){if(!Object.prototype.hasOwnProperty.call(this,a))return;const l=this[a];try{delete this[a]}catch{}this[a]=l}connectedCallback(){this._controller.setOptions(this._readAttrs());const a=()=>{this.isConnected&&this._controller.start()};typeof queueMicrotask=="function"?queueMicrotask(a):Promise.resolve().then(a)}disconnectedCallback(){this._controller.destroy()}attributeChangedCallback(){this._controller.setOptions(this._readAttrs())}_readAttrs(){const a=this.getAttribute("tick-ms"),l=this.getAttribute("history-size"),u=this.getAttribute("endpoint"),d=this.getAttribute("base-url"),m=this.getAttribute("mode");return{...a!=null?{tickMs:a}:{},...l!=null?{historySize:l}:{},...u!=null?{endpoint:u}:{},...d!=null?{baseUrl:d}:{},...m!=null?{mode:m}:{}}}set token(a){this._controller.token=a}get token(){return this._controller.token}set getToken(a){this._controller.getToken=a}get getToken(){return this._controller.getToken}set tickMs(a){this._controller.setOptions({tickMs:a})}get tickMs(){return this._controller.options.tickMs}set historySize(a){this._controller.setOptions({historySize:a})}get historySize(){return this._controller.options.historySize}set endpoint(a){this._controller.setOptions({endpoint:a})}get endpoint(){return this._controller.options.endpoint}set baseUrl(a){this._controller.setOptions({baseUrl:a})}get baseUrl(){return this._controller.options.baseUrl}set mode(a){this._controller.setOptions({mode:a})}get mode(){return this._controller.options.mode}}globalThis.customElements.define(e,n)}function wt(){return new Date().toISOString()}function BS(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Tr(e,t){try{const n=JSON.stringify(e);return typeof n!="string"?String(e):n.length<=t?n:`${n.slice(0,Math.max(0,t-1))}…`}catch{const n=String(e);return n.length<=t?n:`${n.slice(0,Math.max(0,t-1))}…`}}function ut(e,t){const n=typeof(t==null?void 0:t.max_chars)=="number"?t.max_chars:360,i=typeof(t==null?void 0:t.max_lines)=="number"?t.max_lines:2,l=String(e||"").replace(/\r\n/g,`
|
|
76
|
+
`).replace(/\r/g,`
|
|
77
|
+
`).split(`
|
|
78
|
+
`),u=l.slice(0,Math.max(1,i)).join(`
|
|
79
|
+
`),d=l.length>i,m=u.length>n?`${u.slice(0,Math.max(0,n-1))}…`:u;return d&&m===u?`${u}…`:m}function Et(e,t){const n=String(e||"");return n.length<=t?n:`${n.slice(0,Math.max(0,t-1))}…`}function t_(e){const t=String(e||"").trim();return t&&t.replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"untitled"}function xn(e){const t=typeof e=="string"?e.trim():"";if(!t)return null;const n=t.replace(/(\.\d{3})\d+/,"$1"),i=Date.parse(n);return Number.isFinite(i)?i:null}function US(e){const t=Date.now()-e,n=Math.floor(t/1e3),i=Math.floor(n/60),a=Math.floor(i/60),l=Math.floor(a/24);return n<60?"just now":i<60?`${i}m ago`:a<24?`${a}h ago`:l<=3?`${l}d ago`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Ko(e){const t=xn(e);return t===null?"—":US(t)}function $p(e){if(!Number.isFinite(e))return"";const t=Math.floor(e/1e3);if(t<=0)return"now";const n=Math.floor(t/60),i=Math.floor(n/60),a=Math.floor(i/24),l=t%60,u=n%60,d=i%24;return a>0?`${a}d ${d}h`:i>0?`${i}h ${u}m`:n>0?`${n}m ${l}s`:`${t}s`}function vg(e){if(typeof e!="number"||!Number.isFinite(e)||e<0)return"—";const t=Math.floor(e/1e3),n=t%60,i=Math.floor(t/60),a=i%60,l=Math.floor(i/60),u=l%24,d=Math.floor(l/24);return d>0?`${d}d ${u}h`:l>0?`${l}h ${a}m`:i>0?`${i}m ${n}s`:`${Math.max(0,t)}s`}function Xo(e){const t=xn(e);return t===null?"—":new Date(t).toLocaleString()}function ln(...e){for(const t of e){const n=String(t??"").trim();if(n)return n}return""}function WS(...e){for(const t of e){const n=Number(t);if(Number.isFinite(n))return n}return null}function yi(e){const t=String(e||"").trim().toLowerCase();return t==="completed"||t==="failed"||t==="cancelled"}function du(e){const t=String(e||"").trim().toLowerCase();return t==="running"||t==="waiting"}function Gl(e){return String((e==null?void 0:e.started_at)||(e==null?void 0:e.created_at)||"").trim()}function Gv(e){const t=String((e==null?void 0:e.status)||"").trim();return yi(t)?String((e==null?void 0:e.finished_at)||(e==null?void 0:e.updated_at)||"").trim():""}function wg(e,t=Date.now()){const n=xn(Gl(e));if(n===null)return-1;const i=xn(Gv(e));return Math.max(0,(i!==null?i:t)-n)}function rc(e,t=Date.now()){return vg(wg(e,t))}function fu(e){return String(e||"").trim().toLowerCase()}function oh(e){return`${(e==null?void 0:e.filename)||""} ${(e==null?void 0:e.source_path)||""}`.trim().toLowerCase()}function Id(e,t){return t.some(n=>e.endsWith(n))}function HS(e){const t=(e==null?void 0:e.tags)||{};return[e==null?void 0:e.content_type,e==null?void 0:e.filename,e==null?void 0:e.source_path,e==null?void 0:e.modality,t.kind,t.type,t.source,t.format,t.content_format,t.name].map(n=>String(n||"").trim()).filter(Boolean).join(" ").toLowerCase()}function qS(e){const t=(e==null?void 0:e.tags)||{};return[e==null?void 0:e.content_type,e==null?void 0:e.filename,e==null?void 0:e.source_path,e==null?void 0:e.modality,e==null?void 0:e.semantic_kind,e==null?void 0:e.render_kind,e==null?void 0:e.task,t.semantic_kind,t.render_kind,t.kind,t.type,t.task,t.provider_task,t.source,t.format,t.content_format,t.name].map(n=>String(n||"").trim()).filter(Boolean).join(" ").toLowerCase()}function VS(e){const t=String(e||"").trimStart().slice(0,4096).toLowerCase();return t?!!(/^<!doctype\s+html\b/.test(t)||/^<html[\s>]/.test(t)||/<head[\s>][\s\S]*<\/head>/.test(t)||/<body[\s>][\s\S]*<\/body>/.test(t)||/<(?:article|main|section|div|p|h[1-6]|meta|title|script|style)\b[\s\S]*>/.test(t)&&/<\/(?:article|main|section|div|p|h[1-6]|title|script|style)>/.test(t)):!1}function Kv(e,t){var u,d,m,p,g;const n=fu(e==null?void 0:e.content_type),i=oh(e),a=[e==null?void 0:e.semantic_kind,e==null?void 0:e.render_kind,e==null?void 0:e.task,(u=e==null?void 0:e.tags)==null?void 0:u.semantic_kind,(d=e==null?void 0:e.tags)==null?void 0:d.render_kind,(m=e==null?void 0:e.tags)==null?void 0:m.task,(p=e==null?void 0:e.tags)==null?void 0:p.kind,(g=e==null?void 0:e.tags)==null?void 0:g.type].map(v=>String(v||"").trim().toLowerCase()).filter(Boolean).join(" ");if(/(^|[^a-z0-9])(code|source_code|script|program|executable)([^a-z0-9]|$)/i.test(a)||n.includes("javascript")||n.includes("typescript")||n.includes("x-python")||n.includes("x-shellscript")||n.includes("x-rust")||n.includes("x-go")||n.includes("x-java")||n.includes("x-csrc")||n.includes("x-c++src")||Id(i,[".py",".js",".jsx",".ts",".tsx",".mjs",".cjs",".sh",".bash",".zsh",".go",".rs",".java",".c",".cc",".cpp",".h",".hpp",".cs",".php",".rb",".swift",".kt",".sql"]))return!0;const l=String(t||"").replace(/\r\n/g,`
|
|
80
|
+
`).replace(/\r/g,`
|
|
81
|
+
`).split(`
|
|
82
|
+
`);return Yv(l)}function GS(e){const n=String(e||"").replace(/\r\n/g,`
|
|
83
|
+
`).replace(/\r/g,`
|
|
84
|
+
`).split(`
|
|
85
|
+
`),i=n.findIndex(u=>/^Markdown Content:\s*$/i.test(u.trim()));if(i===-1)return null;const a=[];for(const u of n.slice(0,i)){const d=u.match(/^\s*([A-Za-z][A-Za-z0-9 /_-]{1,40}):\s*(.+?)\s*$/);d&&a.push({label:d[1].trim(),value:d[2].trim()})}const l=n.slice(i+1).join(`
|
|
86
|
+
`).trim();return!a.length&&!l?null:{metadata:a,body:l}}function KS(e){const t=e.map(n=>n.trim()).filter(Boolean).slice(0,8);if(t.length<2)return!1;for(const n of[","," ",";"]){const i=t.map(a=>a.split(n).length);if(i[0]>=3&&i.every(a=>Math.abs(a-i[0])<=1))return!0}return!1}function YS(e){const t=e.map(i=>i.trimEnd()).filter(Boolean).slice(0,20);if(!t.length)return!1;const n=t.filter(i=>/^(\[[^\]]+\]|\d{4}-\d{2}-\d{2}[t\s]|\w+:\s|traceback\b|error\b|warn\b|info\b)/i.test(i.trim())).length;return t.length>=4&&n/t.length>=.55?!0:Yv(e)}function Yv(e){const t=e.map(i=>i.trimEnd()).filter(Boolean).slice(0,20);if(!t.length)return!1;const n=t.filter(i=>/[{};]\s*$/.test(i)||/^\s*(import|export|const|let|var|function|class|def|if|for|while|return)\b/.test(i)).length;return t.length>=4&&n/t.length>=.55}function XS(e){const t=String(e||"");if(!t.trim())return!1;const n=t.match(/\\[A-Za-z]{2,}\b/g)||[];if(n.length>=1&&/\\(?:setcctype|sectctype|documentclass|begin|end|maketitle|geq|leq|cite|ref|label)\b/.test(t)||n.length>=4)return!0;const a=t.replace(/\r\n/g,`
|
|
87
|
+
`).replace(/\r/g,`
|
|
88
|
+
`).split(`
|
|
89
|
+
`).map(m=>m.trim()).filter(Boolean).slice(0,80);if(a.length<12)return!1;const l=a.filter(m=>m.length<=28).length,u=a.filter(m=>/^[,.;:()†]+$/.test(m)).length;return a.filter(m=>/^(abstract\.?|introduction|references|appendix|figure\s+\d+|table\s+\d+)\b/i.test(m)).length>=2&&(l/a.length>=.45||u>=2)}function JS(e,t){var p;const n=String(t||""),i=HS(e);if(/(^|[^a-z0-9])(markdown|mdown)([^a-z0-9]|$)/i.test(i))return!0;if(!n.trim())return!1;if(/(^|\n)\s*Markdown Content:\s*(\n|$)/i.test(n)||n.includes("```")||/(^|\n)\s*#{1,6}\s+\S/.test(n)||/(^|\n)[ \t]*[-*][ \t]+\S/.test(n)||/(^|\n)[ \t]*\d+[\.)][ \t]+\S/.test(n)||/\*\*[^*\n][\s\S]*?\*\*/.test(n)||/\[[^\]\n]+\]\([^)]+\)/.test(n)||/(^|\n)\s*\|.+\|\s*(\n|$)/.test(n)&&/(^|\n)\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)+\|?\s*(\n|$)/.test(n))return!0;const a=n.replace(/\r\n/g,`
|
|
90
|
+
`).replace(/\r/g,`
|
|
91
|
+
`).split(`
|
|
92
|
+
`),l=a.map(g=>g.trim()).filter(Boolean);if(l.length<2||XS(n)||KS(a)||YS(a))return!1;const u=((p=n.match(/[A-Za-z][A-Za-z'-]+/g))==null?void 0:p.length)||0,d=a.filter(g=>!g.trim()).length,m=l.filter(g=>/[A-Za-z]{3,}/.test(g)&&g.length>=12).length;return u>=24&&m>=2&&(d>=1||l[0].length<=140)}function Dd(e){const t=fu(e==null?void 0:e.modality),n=fu(e==null?void 0:e.content_type),i=oh(e),a=qS(e);return t==="image"||n.startsWith("image/")||Id(i,[".png",".jpg",".jpeg",".gif",".webp",".bmp",".svg",".tif",".tiff",".heic"])?"image":t==="audio"||t==="voice"||t==="music"||t==="sound"||n.startsWith("audio/")||/(tts|stt|voice|music|sound|speech|audio)/i.test(a)||Id(i,[".wav",".mp3",".m4a",".aac",".flac",".ogg",".opus",".aiff",".mid",".midi"])?"audio":t==="video"||n.startsWith("video/")||Id(i,[".mp4",".mov",".webm",".mkv",".avi",".m4v"])?"video":!n||t==="text"||n.startsWith("text/")||n.includes("json")||n.includes("yaml")||n.includes("toml")||n.includes("xml")||n.includes("html")||n.includes("markdown")||n.includes("csv")||Kv(e,"")?"text":"binary"}function zd(e,t){const n=fu(e==null?void 0:e.content_type),i=oh(e),a=String(t||"").trim();return n.includes("html")||i.endsWith(".html")||i.endsWith(".htm")||VS(t)?"html":Kv(e,t)?"code":n.includes("markdown")||i.endsWith(".md")||i.endsWith(".markdown")?"markdown":n.includes("json")||i.endsWith(".json")||i.endsWith(".jsonl")||(a.startsWith("{")||a.startsWith("["))&&sh(a)!==null?"json":JS(e,t)?"markdown":"text"}function xg(e,t=""){const n=Dd(e);if(n==="image"||n==="video")return n;if(n==="audio"){const i=(e==null?void 0:e.tags)||{},a=[e==null?void 0:e.semantic_kind,e==null?void 0:e.modality,e==null?void 0:e.task,i.semantic_kind,i.modality,i.kind,i.task,i.source,e==null?void 0:e.filename,e==null?void 0:e.source_path].map(l=>String(l||"").trim().toLowerCase()).filter(Boolean).join(" ");return/(^|[^a-z0-9])(voice|tts|speech)([^a-z0-9]|$)/i.test(a)?"voice":/(^|[^a-z0-9])(music|song|instrumental|t2m)([^a-z0-9]|$)/i.test(a)?"music":/(^|[^a-z0-9])(sound|sfx|recording)([^a-z0-9]|$)/i.test(a)?"sound":"audio"}if(n==="binary"){const i=fu(e==null?void 0:e.modality),a=fu(e==null?void 0:e.content_type),l=oh(e);return i==="document"||a.includes("pdf")||Id(l,[".pdf",".doc",".docx",".ppt",".pptx",".xls",".xlsx"])?"document":"other"}return zd(e,t)}function n_(e){var p,g;const t=String(e||"").replace(/\r\n/g,`
|
|
93
|
+
`).replace(/\r/g,`
|
|
94
|
+
`).trim();if(!t)return"";const n=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),i=t.match(/<!--[\s\S]*?-->|<!doctype\b[^>]*>|<!\[CDATA\[[\s\S]*?\]\]>|<\/?[A-Za-z][^>]*>|[^<]+/gi)||[t],a=[];let l=0,u="";const d=v=>" ".repeat(Math.max(0,v)),m=(v,w)=>{const x=v.match(/^(<\/?|<!)([^\s/>]+)([\s\S]*?)(\/?>)$/);if(!x||v.length<=120||v.startsWith("</")||v.startsWith("<!"))return[`${d(w)}${v.trim()}`];const N=(x[3]||"").trim();if(!N)return[`${d(w)}${v.trim()}`];const S=N.match(/[^\s="'<>`]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'<>`]+))?/g)||[N];return[`${d(w)}${x[1]}${x[2]}`,...S.map(R=>`${d(w+1)}${R.trim()}`),`${d(w)}${x[4]}`]};for(const v of i){const w=String(v||"");if(!w.trim())continue;const x=w.trim().toLowerCase();if(x.startsWith("</")){const S=((p=x.match(/^<\/\s*([a-z0-9:-]+)/))==null?void 0:p[1])||"";u&&S===u&&(u=""),l=Math.max(0,l-1),a.push(`${d(l)}${w.trim()}`);continue}if(w.trimStart().startsWith("<")){a.push(...m(w,l));const S=((g=x.match(/^<\s*([a-z0-9:-]+)/))==null?void 0:g[1])||"";/\/>\s*$/.test(w)||x.startsWith("<!")||n.has(S)||(l+=1,(S==="script"||S==="style")&&(u=S));continue}if(u){const S=w.trim();S&&a.push(...S.split(`
|
|
95
|
+
`).map(R=>`${d(l)}${R.trimEnd()}`));continue}const N=w.replace(/\s+/g," ").trim();N&&a.push(`${d(l)}${N}`)}return a.join(`
|
|
96
|
+
`)}function ZS(e){var n;const t=((n=e==null?void 0:e.output)==null?void 0:n.stop_reason)??(e==null?void 0:e.stop_reason)??null;return t&&typeof t=="object"?t:null}function Um(e){const t=String((e==null?void 0:e.status)??"").trim().toLowerCase(),n=t==="completed"||t==="failed"||t==="cancelled";return e!=null&&e.paused&&!n?"paused":t==="completed"&&(e!=null&&e.stop_reason)&&e.stop_reason.finished===!1?"stopped":t||"unknown"}function nl(e,t){const n=String(e??"").trim().toLowerCase();return n==="stopped"?"warn":n==="completed"?t&&t.finished===!1?"warn":"ok":n==="failed"||n==="cancelled"?"danger":n==="waiting"||n==="paused"||n==="suspended"?"warn":n==="running"||n==="scheduled"?"info":"muted"}const QS=/^\s*<runtime_metadata>\s*([\s\S]*?)\s*<\/runtime_metadata>\s*/i;function bg(e){const t=typeof e=="string"?e:String(e??""),n=QS.exec(t);if(!n)return{text:t.trim(),metadata:null,stripped:!1};let i=null;try{const a=JSON.parse(String(n[1]||"").trim());a&&typeof a=="object"&&!Array.isArray(a)&&(i=a)}catch{i=null}return{text:t.slice(n[0].length).trim(),metadata:i,stripped:!0}}function Xv(...e){const t={};for(const n of e)if(!(!n||typeof n!="object"||Array.isArray(n)))for(const[i,a]of Object.entries(n))a==null||String(a).trim()===""||(t[i]=a);return Object.keys(t).length?t:null}function B_(e){if(e==null)return"";if(typeof e=="string")return e.trim();if(Array.isArray(e))return e.map(t=>B_(t)).filter(Boolean).join(`
|
|
97
|
+
`).trim();if(typeof e=="object"){const t=e.text??e.content??e.message??e.value;if(t!==e){const n=B_(t);if(n)return n}}return""}function Jv(e){const t=bg(B_(e));return{text:t.text,runtime_metadata:t.metadata}}function ek(e){var i,a;if(!e)return{text:"",runtime_metadata:null};const t=typeof e.prompt=="string"?String(e.prompt).trim():"";if(t){const l=bg(t);return{text:l.text,runtime_metadata:l.metadata}}const n=[(i=e.context)==null?void 0:i.messages,e.messages,e.conversation,e.history].filter(Array.isArray);for(const l of n)for(let u=l.length-1;u>=0;u-=1){const d=l[u],m=String((d==null?void 0:d.role)||(d==null?void 0:d.speaker)||"").trim().toLowerCase();if(m&&m!=="user"&&m!=="human")continue;const p=Jv((d==null?void 0:d.content)??(d==null?void 0:d.text)??d);if(p.text)return{text:p.text,runtime_metadata:Xv(p.runtime_metadata,d!=null&&d.runtime_metadata&&typeof d.runtime_metadata=="object"?d.runtime_metadata:null,(a=d==null?void 0:d.metadata)!=null&&a.runtime_metadata&&typeof d.metadata.runtime_metadata=="object"?d.metadata.runtime_metadata:null)}}return{text:"",runtime_metadata:null}}function tk(e,t=6){var l,u;if(!e)return[];const i=[(l=e.context)==null?void 0:l.messages,e.messages,e.conversation,e.history].filter(Array.isArray).find(d=>d.length)||[],a=[];for(const d of i){const m=String((d==null?void 0:d.role)||(d==null?void 0:d.speaker)||(d==null?void 0:d.author)||"").trim().toLowerCase()||"message",p=Jv((d==null?void 0:d.content)??(d==null?void 0:d.text)??(d==null?void 0:d.message)??d),g=p.text;if(!g)continue;const v=String((d==null?void 0:d.ts)||(d==null?void 0:d.timestamp)||(d==null?void 0:d.created_at)||(d==null?void 0:d.time)||"").trim(),w=Xv(p.runtime_metadata,d!=null&&d.runtime_metadata&&typeof d.runtime_metadata=="object"?d.runtime_metadata:null,(u=d==null?void 0:d.metadata)!=null&&u.runtime_metadata&&typeof d.metadata.runtime_metadata=="object"?d.metadata.runtime_metadata:null);a.push({role:m,text:g,ts:v,runtime_metadata:w})}return a.slice(Math.max(0,a.length-Math.max(1,t)))}function Zv(e){const t=String(e||"").trim().toLowerCase().replace(/\s+/g," ");return t==="please respond:"||t==="please respond"||t==="type response..."||t==="type response"}function nk(e){const t=e.map(n=>String((n==null?void 0:n.name)||"tool").trim()).filter(Boolean);return t.length?`${t.slice(0,3).join(", ")}${t.length>3?` +${t.length-3}`:""}`:""}const Qv="inferred from the call's arguments (regex heuristic) — not a declared risk tier; declared tiers replace this when the grant API ships";function ew(e){const t=String((e==null?void 0:e.name)||"").trim().toLowerCase(),n=e!=null&&e.arguments&&typeof e.arguments=="object"?e.arguments:{},i=String((n==null?void 0:n.command)||(n==null?void 0:n.cmd)||(n==null?void 0:n.shell)||"").trim().toLowerCase(),a=[];return(t.includes("execute_command")||t.includes("terminal")||i)&&a.push("Shell"),/[;&|]?\s*(rm|rmdir|mv|chmod|chown|sudo)\b/.test(i)&&a.push("Destructive risk"),/(^|\s)(curl|wget|scp|ssh|nc|ncat|ftp)\b/.test(i)&&a.push("Network"),/(^|\s)(cat|sed|rg|grep|ls|find|pwd)\b/.test(i)&&!/[>|]\s*\S/.test(i)&&a.push("Read path"),/[>|]\s*\S|(^|\s)(tee|touch|mkdir|cp)\b/.test(i)&&a.push("Filesystem write"),a.length||a.push("Tool call"),Array.from(new Set(a)).slice(0,4)}function jg(e,t){const n=String((e==null?void 0:e.reason)||"").trim().toLowerCase(),i=nk(t);return t.length?`Approval required: ${i||"tool call"}`:n==="user"?"Waiting for your answer":n==="event"?"Waiting for a user response event":n==="subworkflow"?"Waiting for a subworkflow":n==="until"?"Scheduled wait":n?`Waiting: ${n}`:"Waiting for input"}function tw(e,t){return t.length?"Review the requested tool call, then approve and execute it, approve without local execution, reject it, or cancel the whole run.":(Array.isArray(e==null?void 0:e.choices)?(e==null?void 0:e.choices)||[]:[]).length?"Select one of the allowed responses, then submit it to resume this run.":(e==null?void 0:e.allow_free_text)===!1?"This wait does not allow free text. Use the available response control or inspect the ledger.":String((e==null?void 0:e.prompt)||"").trim()?"Answer the workflow question below. Submitting resumes only this wait.":"No explicit question was emitted. Inspect the original request and recent ledger context before responding."}function nw(e,t){const n=String((e==null?void 0:e.prompt)||"").trim(),i=bg(n),a=ek(t);return i.text&&!Zv(i.text)?{text:i.text,runtime_metadata:i.metadata}:a.text?a:{text:i.text||n,runtime_metadata:i.metadata}}function rk(e,t){return nw(e,t).text}function sk(e,t){return e||String(t||"").trim()||{}}function hi(e,t){const n=String((e==null?void 0:e.schedule_target_workflow_id)||(e==null?void 0:e.workflow_id)||"").trim();return n?t[n]||n:"(workflow unknown)"}function rl(e){const t=String(e.status||"unknown").trim()||"unknown";return r.jsx("span",{className:`run_status_pill ${nl(t)}`,children:t})}function ik(e){var l;const t=String((e==null?void 0:e.status)||"").trim().toLowerCase();if(yi(t))return"";const n=e!=null&&e.waiting&&typeof e.waiting=="object"?e.waiting:null,i=String((n==null?void 0:n.reason)||(e==null?void 0:e.waiting_reason)||"").trim().toLowerCase(),a=Array.isArray((l=n==null?void 0:n.details)==null?void 0:l.tool_calls)?n.details.tool_calls:[];return a.length?jg(n,a):i==="user"?"Waiting for your answer":i==="event"?"Waiting for a response event":i==="subworkflow"?"Waiting for subworkflow":i==="until"?"Scheduled wait":i?`Waiting: ${i}`:t==="waiting"?"Waiting, reason unknown":""}function Wm(e){const t=e==null?void 0:e.error;return t?typeof t=="string"?ut(t,{max_chars:220,max_lines:2}):ut(Tr(t,400),{max_chars:220,max_lines:2}):""}function ok(e){const t=ik(e);if(t)return t;const n=Wm(e);if(n)return n;const i=String((e==null?void 0:e.current_node)||"").trim();if(i)return`Current node: ${i}`;const a=String((e==null?void 0:e.status)||"").trim().toLowerCase();return a==="running"?"Running":yi(a)?"Terminal":"No current activity reported"}function rw(e){return e!=null&&e.ref&&typeof e.ref=="object"?e.ref:e!=null&&e.artifact_ref&&typeof e.artifact_ref=="object"?e.artifact_ref:e!=null&&e.artifact&&typeof e.artifact=="object"?e.artifact:{}}function Ep(e){const t=rw(e),n=e!=null&&e.metadata&&typeof e.metadata=="object"?e.metadata:e!=null&&e.meta&&typeof e.meta=="object"?e.meta:{},i=e!=null&&e.tags&&typeof e.tags=="object"?e.tags:{},a=ln(e==null?void 0:e.modality,t==null?void 0:t.modality,n==null?void 0:n.modality,i.modality).toLowerCase();if(a)return a;const l=ln(e==null?void 0:e.content_type,e==null?void 0:e.mime_type,e==null?void 0:e.mime,t==null?void 0:t.content_type,t==null?void 0:t.mime_type,t==null?void 0:t.mime,n==null?void 0:n.content_type,i.content_type).toLowerCase();return l.startsWith("image/")?"image":l.startsWith("audio/")?"audio":l.startsWith("video/")?"video":l.includes("pdf")?"document":l.startsWith("text/")||l.includes("json")||l.includes("markdown")||l.includes("csv")?"text":"artifact"}function ak(e){return!e||typeof e!="object"?{}:e.artifact_envelope_v1&&typeof e.artifact_envelope_v1=="object"?e.artifact_envelope_v1:e.envelope&&typeof e.envelope=="object"?e.envelope:e}function lk(e,t){if(!e||typeof e!="object")return null;const n=ak(e),i=rw(e),a=e!=null&&e.metadata&&typeof e.metadata=="object"?e.metadata:e!=null&&e.meta&&typeof e.meta=="object"?e.meta:{},l=n!=null&&n.descriptor&&typeof n.descriptor=="object"?n.descriptor:e!=null&&e.descriptor&&typeof e.descriptor=="object"?e.descriptor:{},u=ln(n.artifact_id,e.artifact_id,e.$artifact,e.id,i.artifact_id,i.$artifact,i.id,a.artifact_id,a.$artifact);if(!u)return null;const d={...i.tags&&typeof i.tags=="object"?i.tags:{},...a.tags&&typeof a.tags=="object"?a.tags:{},...n.tags&&typeof n.tags=="object"?n.tags:{},...e.tags&&typeof e.tags=="object"?e.tags:{}},m={};for(const[D,G]of Object.entries(d)){const Q=String(D||"").trim();Q&&(m[Q]=String(G??""))}const p=ln(n.filename,e.filename,i.filename,a.filename,m.filename,m.name,e.name,i.name),g=ln(n.source_path,e.source_path,i.source_path,a.source_path,e.path,i.path,m.path,m.source_path,m.file_path),v=ln(n.content_type,e.content_type,e.mime_type,e.mime,i.content_type,i.mime_type,i.mime,a.content_type,m.content_type),w=ln(n.render_kind,l.render_kind,e.render_kind,m.render_kind),x=ln(n.semantic_kind,l.semantic_kind,e.semantic_kind,m.semantic_kind,m.artifact_type),N=n.access&&typeof n.access=="object"?n.access:e.access&&typeof e.access=="object"?e.access:{},S=n.producer&&typeof n.producer=="object"?n.producer:e.producer&&typeof e.producer=="object"?e.producer:l.producer&&typeof l.producer=="object"?l.producer:{},R=n.provenance&&typeof n.provenance=="object"?n.provenance:e.provenance&&typeof e.provenance=="object"?e.provenance:l.provenance&&typeof l.provenance=="object"?l.provenance:{},T=n.generation&&typeof n.generation=="object"?n.generation:e.generation&&typeof e.generation=="object"?e.generation:l.generation&&typeof l.generation=="object"?l.generation:{},z=n.media&&typeof n.media=="object"?n.media:e.media&&typeof e.media=="object"?e.media:l.media&&typeof l.media=="object"?l.media:{},H=n.links&&typeof n.links=="object"?n.links:e.links&&typeof e.links=="object"?e.links:l.links&&typeof l.links=="object"?l.links:{};return{artifact_id:u,run_id:ln(n.run_id,e.run_id,i.run_id,a.run_id,m.run_id,R.run_id),content_type:v,modality:ln(n.modality,e.modality,l.modality,m.modality)||Ep({...e,ref:i,metadata:a,tags:m}),semantic_kind:x||Ep({...e,ref:i,metadata:a,tags:m}),render_kind:w||xg({content_type:v,filename:p,source_path:g,modality:ln(n.modality,e.modality,m.modality),tags:m}),task:ln(n.task,l.task,e.task,m.task,m.provider_task),classification_source:ln(n.classification_source,l.classification_source,e.classification_source),session_id:ln(n.session_id,l.session_id,e.session_id,m.session_id),workflow_id:ln(n.workflow_id,l.workflow_id,e.workflow_id,m.workflow_id,m.workflow),node_id:ln(n.node_id,l.node_id,e.node_id,m.node_id,m.node),step_id:ln(n.step_id,l.step_id,e.step_id,m.step_id),effect_id:ln(n.effect_id,l.effect_id,e.effect_id,m.effect_id,m.effect_idempotency_key),turn_id:ln(n.turn_id,l.turn_id,e.turn_id,m.turn_id,m.turn),ledger_cursor:ln(n.ledger_cursor,l.ledger_cursor,e.ledger_cursor,m.ledger_cursor,m.step_cursor),parent_run_id:ln(n.parent_run_id,l.parent_run_id,e.parent_run_id,m.parent_run_id),actor_id:ln(n.actor_id,l.actor_id,e.actor_id,m.actor_id),title:ln(n.title,e.title,m.title,m.label,m.name),created_at:ln(n.created_at,e.created_at,i.created_at,a.created_at,m.created_at),size_bytes:WS(n.size_bytes,e.size_bytes,i.size_bytes,a.size_bytes,m.size_bytes),filename:p,source_path:g,sha256:ln(n.sha256,e.sha256,i.sha256,a.sha256,m.sha256),tags:m,producer:S,provenance:R,generation:T,media:z,source_refs:Array.isArray(n.source_refs)?n.source_refs:Array.isArray(e.source_refs)?e.source_refs:[],access:N,links:H,available_actions:Array.isArray(n.available_actions)?n.available_actions.map(String):Array.isArray(e.available_actions)?e.available_actions.map(String):[],provider_trace_available:!!(n.provider_trace_available??e.provider_trace_available),audit_available:!!(n.audit_available??e.audit_available),legacy_inferred:!!((n.legacy_inferred??e.legacy_inferred)||/(?:legacy|inferred|runtime_tags|runtime_mime)/i.test(ln(n.classification_source,l.classification_source,e.classification_source))),descriptor:l,source:t,raw:e}}function U_(e){return e.filename||e.title||(e.source_path?e.source_path.split("/").filter(Boolean).slice(-1)[0]:"")||Et(e.artifact_id,16)}function ck(e,t){if(t==="type")return ou(e);if(t==="run")return e.run_id||"(no run)";if(t==="turn")return W_(e);if(t==="node")return iu(e)||"(node unknown)";if(t==="workflow")return Sg(e)||"(workflow unknown)";if(t==="location"){const a=(e.source_path||e.filename||"").split("/").filter(Boolean);return a.length>1?a.slice(0,-1).join("/"):"(root)"}if(t==="source")return Bd(e)||e.source||"artifact";const n=xn(e.created_at);return n===null?"(unknown time)":new Date(n).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Sg(e){const t=(e==null?void 0:e.tags)||{};return String((e==null?void 0:e.workflow_id)||t.workflow_id||t.workflow||"").trim()}function iu(e){const t=(e==null?void 0:e.tags)||{},n=String((e==null?void 0:e.node_id)||t.node_id||t.node||(e==null?void 0:e.step_id)||t.step_id||"").trim();if(n)return n;const a=String((e==null?void 0:e.source_path)||t.path||"").trim().match(/(?:^|[._:/-])(node-[A-Za-z0-9_-]+)/);return a!=null&&a[1]?String(a[1]):""}function W_(e){const t=(e==null?void 0:e.tags)||{},n=String((e==null?void 0:e.turn_id)||t.turn_id||t.turn||t.cycle||(e==null?void 0:e.ledger_cursor)||t.ledger_cursor||t.step_cursor||"").trim();if(n)return`turn ${n}`;const i=iu(e),a=xn(e==null?void 0:e.created_at),l=a===null?"unknown time":new Date(a).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),u=e!=null&&e.run_id?Et(String(e.run_id),10):"unknown run";return i?`${u} · ${i} · ${l}`:`${u} · ${l}`}function Ap(e){if(!e)return"provenance unavailable";const t=[],n=Sg(e),i=iu(e),a=Bd(e),l=sw(e);return n&&t.push(n),i&&t.push(i),a&&t.push(a),l&&t.push(l),t.length?t.join(" · "):"provenance unavailable"}function Kl(e){if(typeof e!="number"||!Number.isFinite(e)||e<0)return"—";const t=["B","KB","MB","GB","TB"];let n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i+=1;const a=i===0?0:n>=10?1:2;return`${n.toFixed(a)} ${t[i]}`}function ou(e){const t=String((e==null?void 0:e.semantic_kind)||(e==null?void 0:e.modality)||"").trim().toLowerCase(),n=String((e==null?void 0:e.render_kind)||"").trim().toLowerCase(),i=t||n||"artifact";return{voice:"Voice",music:"Music",sound:"Sound",recording:"Recording",audio:"Unclassified audio",image:"Image",video:"Video",markdown:"Markdown",html:"HTML",json:"JSON",document:"Document",code:"Code",text:"Text",binary:"Other",artifact:"Other"}[i]||i.replace(/[_-]+/g," ").replace(/\b\w/g,l=>l.toUpperCase())}function uk(e){return e==="html"?"HTML":e==="json"?"JSON":e==="audio"?"Unclassified audio":e==="code"?"Code":e.slice(0,1).toUpperCase()+e.slice(1)}function dk(e){const t=Date.now();if(e==="hour")return new Date(t-3600*1e3).toISOString();if(e==="week")return new Date(t-10080*60*1e3).toISOString();if(e==="month")return new Date(t-720*60*60*1e3).toISOString();if(e==="today"){const n=new Date(t);return new Date(n.getFullYear(),n.getMonth(),n.getDate()).toISOString()}return""}function fk(e){return e==="oldest"?{order_by:"created_at",order:"asc"}:e==="size_desc"?{order_by:"size_bytes",order:"desc"}:e==="size_asc"?{order_by:"size_bytes",order:"asc"}:e==="last_access"?{order_by:"last_accessed_at",order:"desc"}:e==="turn"?{order_by:"turn",order:"asc"}:e==="type"?{order_by:"semantic_kind",order:"asc"}:{order_by:"created_at",order:"desc"}}function Mp(e){const t=e!=null&&e.stats&&typeof e.stats=="object"?e.stats:{},n=t!=null&&t.facets&&typeof t.facets=="object"?t.facets:e!=null&&e.facets&&typeof e.facets=="object"?e.facets:{};return n&&typeof n=="object"?n:{}}function mk(e){const t=Xo(e.created_at),n=Ko(e.created_at);return t==="—"?"Created —":`${t}${n&&n!=="—"?` (${n})`:""}`}function Tp(e){var a;const t=e.tags||{},n=String(((a=e.access)==null?void 0:a.last_accessed_at)||t.last_accessed_at||t.accessed_at||t.updated_at||e.created_at||"").trim(),i=Xo(n);return i==="—"?"—":i}function Rp(e){const t=e.tags||{},n=String(e.title||t.title||t.name||t.label||e.filename||"").trim();if(n)return n;const i=String(e.source_path||t.path||"").trim();if(i)return i.split("/").filter(Boolean).slice(-1)[0]||i;const a=Bd(e),l=ou(e);return a?`${l} ${a}`:`${l} artifact`}function Bd(e){var n;const t=e.tags||{};return String(e.task||((n=e.provenance)==null?void 0:n.source)||t.task||t.kind||t.source||e.source||"").trim()}function sw(e){var i,a,l,u,d,m,p,g;if(!e)return"";const t=ln((i=e.producer)==null?void 0:i.provider,(a=e.producer)==null?void 0:a.provider_id,(l=e.provenance)==null?void 0:l.provider,(u=e.generation)==null?void 0:u.provider),n=ln((d=e.producer)==null?void 0:d.model,(m=e.producer)==null?void 0:m.model_id,(p=e.provenance)==null?void 0:p.model,(g=e.generation)==null?void 0:g.model);return t&&n?`${t} / ${n}`:t||n}function hk(e){var t,n,i,a;return e?ln((t=e.generation)==null?void 0:t.prompt,(n=e.generation)==null?void 0:n.input,(i=e.generation)==null?void 0:i.text,(a=e.provenance)==null?void 0:a.prompt):""}function Lp(e){if(!e)return"";const t=e.media||{},n=Number(t.duration_s??t.duration_seconds??t.duration),i=Number(t.width??t.image_width??t.video_width),a=Number(t.height??t.image_height??t.video_height),l=Number(t.sample_rate??t.sample_rate_hz),u=Number(t.channels);if(Number.isFinite(n)&&n>0){const m=[`${n>=60?`${Math.floor(n/60)}m ${Math.round(n%60)}s`:`${n.toFixed(n>=10?1:2)}s`}`];return Number.isFinite(l)&&l>0&&m.push(`${Math.round(l/1e3)} kHz`),Number.isFinite(u)&&u>0&&m.push(`${u} ch`),m.join(" · ")}if(Number.isFinite(i)&&Number.isFinite(a)&&i>0&&a>0)return`${Math.round(i)} x ${Math.round(a)}`;const d=Number(t.page_count??t.pages);return Number.isFinite(d)&&d>0?`${Math.round(d)} pages`:""}function Op(e){return e.source_path||e.filename||""}function Hm(e,t,n){const i=e.run_id&&t[e.run_id]||null;if(!i)return e;const a=hi(i,n),l={...e.tags||{}};return a&&!l.workflow&&(l.workflow=a),a&&!l.workflow_id&&(l.workflow_id=a),{...e,workflow_id:e.workflow_id||a,tags:l}}function H_(e,t,n,i=""){const a=Hm(e,t,n),l=xg(a,i);return{json:"JSON",html:"HTML",markdown:"Markdown",code:"Code",voice:"Voice",music:"Music",sound:"Sound",audio:"Unclassified audio",image:"Image",video:"Video",document:"Document",text:"Text",other:"Other"}[l]||ou(a)}function Bi(e){var i;const t=e,n=(i=t==null?void 0:t.result)==null?void 0:i.wait;return!n||typeof n!="object"?null:n}function mm(e){var l,u,d;const t=e,n=t==null?void 0:t.effect;if(!n||typeof n!="object"||String(n.type||"")!=="emit_event")return null;const i=String(((l=n==null?void 0:n.payload)==null?void 0:l.name)||((u=n==null?void 0:n.payload)==null?void 0:u.event_name)||"").trim();if(!i)return null;const a=(d=n==null?void 0:n.payload)==null?void 0:d.payload;return{name:i,payload:a}}function gu(e){const t=e,n=t==null?void 0:t.details;if(!n||typeof n!="object")return[];if(Array.isArray(n))return n.filter(a=>a&&typeof a=="object"&&typeof a.name=="string");const i=n==null?void 0:n.tool_calls;return Array.isArray(i)?i:[]}function _k(e){var a,l;const t=String((e==null?void 0:e.status)||"").trim(),n=String(((a=e==null?void 0:e.effect)==null?void 0:a.type)||"").trim(),i=(l=e==null?void 0:e.effect)!=null&&l.payload&&typeof e.effect.payload=="object"?String(e.effect.payload.name||"").trim():"";return n==="emit_event"&&i?i:n||t||"record"}function iw(e){if(!e||typeof e!="object")return"Ledger record";const t=String(e.node_id||"").trim(),n=String(e.status||"").trim(),i=_k(e),a=Bi(e);if(a){const l=String(a.reason||"").trim();if(String(a.prompt||"").trim())return`${t||"node"} is waiting for a response`;if(l)return`${t||"node"} is waiting (${l})`}return e.error?`${t||"node"} failed`:n==="completed"?`${t||"node"} completed ${i}`:n==="running"?`${t||"node"} started ${i}`:n==="waiting"?`${t||"node"} is waiting`:[t,n,i].filter(Boolean).join(" · ")||"Ledger record"}function Kc(e){if(typeof e=="string")return{text:e,duration:-1};if(e&&typeof e=="object"){const t=typeof e.text=="string"?String(e.text):typeof e.value=="string"?String(e.value):typeof e.message=="string"?String(e.message):Tr(e,320),n=typeof e.duration=="number"?Number(e.duration):-1;return{text:t,duration:n}}return{text:Tr(e,320),duration:-1}}function ef(e){var u,d,m,p,g,v,w,x,N;if(!e||typeof e!="object")return"";const t=String(((u=e==null?void 0:e.effect)==null?void 0:u.type)||"").trim(),n=e==null?void 0:e.result,i=S=>typeof S=="string"?S.trim():S==null?"":typeof S=="number"||typeof S=="boolean"?String(S):"",a=S=>{if(!S||typeof S!="object")return"";const R=S,T=[R.response,R.answer,R.message,R.text,R.content];for(const z of T){const H=i(z);if(H)return H}return""};if(t==="answer_user"){const S=i(n==null?void 0:n.message)||i((d=n==null?void 0:n.output)==null?void 0:d.message)||i((m=n==null?void 0:n.output)==null?void 0:m.response)||i((g=(p=e==null?void 0:e.effect)==null?void 0:p.payload)==null?void 0:g.message)||i((w=(v=e==null?void 0:e.effect)==null?void 0:v.payload)==null?void 0:w.text)||i((N=(x=e==null?void 0:e.effect)==null?void 0:x.payload)==null?void 0:N.content);if(S)return S}if(t==="llm_call"){const S=a(n)||i(n==null?void 0:n.output)||a(n==null?void 0:n.output)||i(n==null?void 0:n.response);if(S)return S}return i(n==null?void 0:n.output)||a(n==null?void 0:n.output)||a(n)||i(n==null?void 0:n.response)}function Am(e){var a;const t=String((e==null?void 0:e.node_id)||""),n=String((e==null?void 0:e.status)||""),i=String(((a=e==null?void 0:e.effect)==null?void 0:a.type)||"");return`${t||"(node?)"} • ${n||"(status?)"} • ${i||"(effect?)"}`}function gk(e){return!!(e&&String(e.status||"")==="waiting")}function ow(e){var n,i;const t=[];for(const a of e||[]){const l=a.record;if(String(((n=l==null?void 0:l.effect)==null?void 0:n.type)||"").trim()!=="llm_call")continue;const d=(i=l==null?void 0:l.effect)!=null&&i.payload&&typeof l.effect.payload=="object"?l.effect.payload:{},m=l!=null&&l.result&&typeof l.result=="object"?l.result:{},p=(m==null?void 0:m.usage)||(m==null?void 0:m.token_usage)||{},g=typeof d.prompt=="string"?d.prompt:Array.isArray(d.messages)?Tr(d.messages,1800):"",v=typeof m.content=="string"?m.content:typeof m.response=="string"?m.response:typeof l.result=="string"?String(l.result):"",w=xn(l.started_at),x=xn(l.ended_at),N=Number(p.prompt_tokens??p.input_tokens??0)||0,S=Number(p.completion_tokens??p.output_tokens??0)||0;t.push({id:`${String(a.run_id||l.run_id||"")}:${a.cursor}`,cursor:Number(a.cursor||0),ts:String(l.ended_at||l.started_at||""),run_id:String(a.run_id||l.run_id||"").trim(),node_id:String(l.node_id||"").trim(),provider:String(d.provider||m.provider||m.runtime_provider||"").trim(),model:String(d.model||m.model||m.runtime_model||"").trim(),prompt_preview:ut(g,{max_chars:1200,max_lines:10}),response_preview:ut(v,{max_chars:1200,max_lines:10}),missing_response:!String(v||"").trim(),tokens:{prompt:N,completion:S,total:Number(p.total_tokens??N+S)||0},duration_ms:w!==null&&x!==null?Math.max(0,x-w):typeof m.gen_time=="number"?Number(m.gen_time)*1e3:null,status:String(l.status||"").trim(),error:l.error?Tr(l.error,500):"",raw:l})}return t.sort((a,l)=>(xn(l.ts)??0)-(xn(a.ts)??0))}function Pp(e){const t=e.size||18,n=Dd(e.artifact),i=xg(e.artifact,""),a=`artifact_glyph ${i==="code"?"code":n}`,l={width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round"};return n==="image"?r.jsx("span",{className:a,children:r.jsxs("svg",{...l,children:[r.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),r.jsx("path",{d:"M7 15l3-3 3 3 2-2 4 4"}),r.jsx("circle",{cx:"8",cy:"9",r:"1.4"})]})}):n==="audio"?r.jsx("span",{className:a,children:r.jsxs("svg",{...l,children:[r.jsx("path",{d:"M4 12h2"}),r.jsx("path",{d:"M8 8v8"}),r.jsx("path",{d:"M12 5v14"}),r.jsx("path",{d:"M16 8v8"}),r.jsx("path",{d:"M20 12h-2"})]})}):n==="video"?r.jsx("span",{className:a,children:r.jsxs("svg",{...l,children:[r.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),r.jsx("path",{d:"M9 9l6 3-6 3V9z",fill:"currentColor",stroke:"none"})]})}):i==="code"?r.jsx("span",{className:a,children:r.jsxs("svg",{...l,children:[r.jsx("path",{d:"M8 8l-4 4 4 4"}),r.jsx("path",{d:"M16 8l4 4-4 4"}),r.jsx("path",{d:"M14 4l-4 16"})]})}):n==="text"?r.jsx("span",{className:a,children:r.jsxs("svg",{...l,children:[r.jsx("path",{d:"M7 3h7l5 5v13H7z"}),r.jsx("path",{d:"M14 3v6h6"}),r.jsx("path",{d:"M10 13h7"}),r.jsx("path",{d:"M10 17h5"})]})}):r.jsx("span",{className:a,children:r.jsxs("svg",{...l,children:[r.jsx("path",{d:"M7 3h7l5 5v13H7z"}),r.jsx("path",{d:"M14 3v6h6"}),r.jsx("path",{d:"M9 14h8"})]})})}const pk=2,yk=Number.MAX_SAFE_INTEGER;function vk(e,t=120){const n=String(e||"").replace(/\s+/g," ").trim();return n.length<=t?n:`${n.slice(0,Math.max(0,t-1)).trimEnd()}…`}function wk(e){const t=String(e||"");if(typeof DOMParser>"u")return[{kind:"text",text:n_(t)||t}];try{const n=new DOMParser().parseFromString(t,"text/html"),i=[];n.doctype&&i.push({kind:"doctype",name:n.doctype.name||"html"});const a=l=>{if(l.nodeType===Node.TEXT_NODE){const u=String(l.textContent||"").trim();return u?{kind:"text",text:u}:null}if(l.nodeType===Node.COMMENT_NODE)return{kind:"comment",text:String(l.textContent||"")};if(l.nodeType===Node.ELEMENT_NODE){const u=l,d=Array.from(u.attributes||[]).map(p=>({name:p.name,value:p.value})),m=Array.from(u.childNodes||[]).map(a).filter(Boolean);return{kind:"element",tag:u.tagName.toLowerCase(),attrs:d,children:m}}return null};if(n.documentElement){const l=a(n.documentElement);l&&i.push(l)}return i.length?i:[{kind:"text",text:n_(t)||t}]}catch{return[{kind:"text",text:n_(t)||t}]}}function r_(e){return e.closing?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"runtime_html_punct",children:"</"}),r.jsx("span",{className:"runtime_html_tag",children:e.tag}),r.jsx("span",{className:"runtime_html_punct",children:">"})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"runtime_html_punct",children:"<"}),r.jsx("span",{className:"runtime_html_tag",children:e.tag}),e.attrs.map(t=>r.jsxs(pe.Fragment,{children:[" ",r.jsx("span",{className:"runtime_html_attr",children:t.name}),r.jsx("span",{className:"runtime_html_punct",children:"="}),r.jsxs("span",{className:"runtime_html_value",children:['"',t.value,'"']})]},`${e.tag}:${t.name}:${t.value}`)),r.jsx("span",{className:"runtime_html_punct",children:e.selfClosing?" />":">"})]})}function aw(e){const t=e.node,n=e.depth*14,i=e.depth<e.collapseAfterDepth,[a,l]=_.useState(i);if(_.useEffect(()=>{l(i)},[i,e.expansionVersion]),t.kind==="doctype")return r.jsxs("div",{className:"html-tree__line",style:{paddingLeft:n},children:[r.jsx("span",{className:"runtime_html_punct",children:"<!DOCTYPE "}),r.jsx("span",{className:"runtime_html_tag",children:t.name}),r.jsx("span",{className:"runtime_html_punct",children:">"})]});if(t.kind==="comment")return r.jsx("div",{className:"html-tree__line",style:{paddingLeft:n},children:r.jsx("span",{className:"runtime_html_comment",children:`<!-- ${t.text.trim()} -->`})});if(t.kind==="text")return r.jsx("div",{className:"html-tree__line html-tree__text",style:{paddingLeft:n},children:t.text});if(!t.children.length)return r.jsx("div",{className:"html-tree__line",style:{paddingLeft:n},children:r.jsx(r_,{tag:t.tag,attrs:t.attrs,selfClosing:!0})});const u=t.children.find(d=>d.kind==="text");return r.jsxs("details",{className:"html-tree__details",open:a,onToggle:d=>l(d.currentTarget.open),children:[r.jsxs("summary",{className:"html-tree__summary",style:{paddingLeft:n},children:[r.jsx("span",{className:"html-tree__caret","aria-hidden":"true",children:a?"▾":"▸"}),r.jsx(r_,{tag:t.tag,attrs:t.attrs}),!a&&u?r.jsxs("span",{className:"html-tree__summary_text",children:[" ",vk(u.text)]}):null]}),a?r.jsxs("div",{className:"html-tree__children",children:[t.children.map((d,m)=>r.jsx(aw,{node:d,depth:e.depth+1,collapseAfterDepth:e.collapseAfterDepth,expansionMode:e.expansionMode,expansionVersion:e.expansionVersion},`${e.depth}:${t.kind}:${t.tag}:${m}`)),r.jsx("div",{className:"html-tree__line",style:{paddingLeft:n},children:r.jsx(r_,{tag:t.tag,attrs:[],closing:!0})})]}):null]})}function xk(e){const t=_.useMemo(()=>wk(e.text),[e.text]),[n,i]=_.useState({mode:"folded",version:0}),a=n.mode==="unfolded"?yk:pk;_.useEffect(()=>{i(u=>({mode:"folded",version:u.version+1}))},[e.text]);const l=()=>{i(u=>({mode:u.mode==="unfolded"?"folded":"unfolded",version:u.version+1}))};return r.jsxs("div",{className:`${e.className} structured html_source_preview`,children:[r.jsx("div",{className:"html-tree__toolbar",children:r.jsx("button",{type:"button",className:"btn html-tree__toggle",onClick:l,"aria-expanded":n.mode==="unfolded",children:n.mode==="unfolded"?"Fold all":"Unfold all"})}),r.jsx("div",{className:"html-tree__tree",role:"tree","aria-label":"HTML source tree",children:t.map((u,d)=>r.jsx(aw,{node:u,depth:0,collapseAfterDepth:a,expansionMode:n.mode,expansionVersion:n.version},`root:${d}`))})]})}function bk(e){var i;const t=GS(e.text);if(!t)return r.jsx("div",{className:`${e.className} structured markdown_preview`,children:r.jsx(pi,{text:e.text})});const n=((i=t.metadata.find(a=>a.label.toLowerCase()==="title"))==null?void 0:i.value)||"";return r.jsxs("div",{className:`${e.className} structured markdown_preview artifact_markdown_report`,children:[n?r.jsx("h1",{className:"artifact_markdown_title",children:n}):null,t.metadata.length?r.jsx("dl",{className:"artifact_markdown_meta",children:t.metadata.map(a=>{const l=/^https?:\/\//i.test(a.value);return r.jsxs("div",{children:[r.jsx("dt",{children:a.label}),r.jsx("dd",{children:l?r.jsx("a",{href:a.value,target:"_blank",rel:"noreferrer",children:a.value}):a.value})]},`${a.label}:${a.value}`)})}):null,r.jsx(pi,{text:t.body||e.text})]})}function lw(e){const t=String(e.text||""),n=zd(e.artifact,t);if(n==="json"){const i=sh(t);if(i!==null)return r.jsx("div",{className:`${e.className} structured`,children:r.jsx(ps,{value:i,collapseAfterDepth:4,showCopy:!1})})}return n==="markdown"?r.jsx(bk,{text:t,className:e.className}):n==="html"?r.jsx(xk,{text:t,className:e.className}):r.jsx("pre",{className:`mono ${e.className}`,children:t})}function jk(e){const t=e.preview,n=e.artifact;return n?t.loading?r.jsx("div",{className:"runtime_inline_preview empty",children:"Loading preview…"}):t.error?r.jsx("div",{className:"runtime_inline_preview empty danger",children:t.error}):t.kind==="image"&&t.url?r.jsx("img",{className:"runtime_inline_preview media",src:t.url,alt:U_(n)}):t.kind==="audio"&&t.url?r.jsx("audio",{className:"runtime_inline_preview audio",src:t.url,controls:!0}):t.kind==="video"&&t.url?r.jsx("video",{className:"runtime_inline_preview media",src:t.url,controls:!0}):r.jsx(lw,{artifact:n,text:t.text||"Preview unavailable. Use Preview or Download.",className:"runtime_inline_preview text"}):r.jsx("div",{className:"runtime_inline_preview empty",children:"Select an artifact to preview it here."})}function kg(e){const t=e==null?void 0:e.waiting;return t&&typeof t=="object"?t:null}function cw(e){const t=kg(e);return String((t==null?void 0:t.reason)||(e==null?void 0:e.waiting_reason)||"").trim().toLowerCase()}function Ip(e){return e?String(e.prompt||"").trim()||Array.isArray(e.choices)&&e.choices.length>0?!0:e.allow_free_text!==!1&&String(e.reason||"").trim().toLowerCase()==="user":!1}function Sk(e){const t=e.map(n=>String((n==null?void 0:n.name)||"tool").trim()).filter(Boolean);return t.length?`${t.slice(0,3).join(", ")}${t.length>3?` +${t.length-3}`:""}`:""}function pu(e){const t=String((e==null?void 0:e.status)||"").trim().toLowerCase();if(yi(t)||t!=="waiting")return"none";const n=kg(e),i=cw(e);return gu(n).length?"tool_approval":i==="until"||String((e==null?void 0:e.role)||"").trim()==="controller"?"scheduled":i==="subworkflow"?"subworkflow":i==="event"?Ip(n)?"user_response":"external_event":i==="user"||Ip(n)?"user_response":"unknown_wait"}function uw(e){const t=kg(e),n=gu(t),i=pu(e);return i==="tool_approval"?`Tool approval: ${Sk(n)||"tool call"}`:i==="user_response"?Array.isArray(t==null?void 0:t.choices)&&t.choices.length>0?"Choice required":"User response needed":i==="scheduled"?String((e==null?void 0:e.role)||"").trim()==="controller"?"Automation waiting for its next run":"Scheduled wait":i==="subworkflow"?"Waiting for subworkflow":i==="external_event"?"Waiting for external event":i==="unknown_wait"?"Waiting, context unclear":""}function kk(e){const t=pu(e);if(t==="tool_approval")return"Review the tool request, then approve, reject, or cancel the whole run.";if(t==="user_response")return"Answer the workflow request. Submit resumes only this wait.";if(t==="scheduled")return"No response is needed. The run resumes when the scheduled time arrives or it is manually resumed.";if(t==="subworkflow")return"No direct response is needed. Inspect the child workflow or cancel the parent run.";if(t==="external_event")return"No direct response is available here. Inspect the ledger or the event source.";if(t==="unknown_wait")return"No clear prompt was provided. Review the input and recent ledger before taking action.";const n=String((e==null?void 0:e.status)||"").trim().toLowerCase();return n==="failed"?"Open the ledger, artifacts, or logs to inspect the failure.":n==="running"?"Watch the ledger/provider traces or cancel the workflow if it should stop.":yi(n)?"Open the ledger and artifacts for the final outcome.":"Open the run to inspect current activity."}function Dp(e){const t=e==null?void 0:e.error;if(!t)return"";if(typeof t=="string")return t;try{return JSON.stringify(t)}catch{return String(t)}}function Nk(e,t={}){const n=t.now_ms??Date.now(),i=t.workflow_label??"",a=String(e.status||"unknown").trim().toLowerCase()||"unknown",l=pu(e),u=yi(a),d=wg(e,n),m=xn(e.updated_at||e.created_at)??0,p=a==="running"&&d>=14400*1e3,g=uw(e)||Dp(e)||(e.current_node?`Current node: ${e.current_node}`:a==="running"?"Running":u?"Terminal":"No current activity reported");let v="all";l==="tool_approval"?v="tool_approval":l==="user_response"?v="user_wait":l==="scheduled"?v="scheduled":l==="subworkflow"||l==="external_event"?v="subflows":a==="failed"?v="failed":a==="running"?v="running":u&&(v="finished");const w=l==="tool_approval"?0:l==="user_response"?1:l==="unknown_wait"?2:a==="failed"?3:p?4:a==="running"?5:l!=="none"?6:u?8:7,x=l==="tool_approval"||l==="user_response",N=l==="tool_approval"?"Open approval":l==="user_response"?"Open wait":"Open Observe",S=[e.run_id,e.workflow_id,i,e.session_id,e.parent_run_id,e.status,e.current_node,cw(e),g,Dp(e)].join(" ").toLowerCase();return{run:e,run_id:String(e.run_id||"").trim(),status:a,wait_kind:l,queue:v,attention_rank:w,reason:g,expected_action:kk(e),action_label:N,search_text:S,is_terminal:u,needs_user_action:x,is_stale:p,duration_ms:d,updated_ms:m}}function Ck(e,t={}){const n=t.now_ms??Date.now(),i=t.workflow_label_by_id??{};return e.map(a=>Nk(a,{now_ms:n,workflow_label:i[String(a.workflow_id||"")]||String(a.workflow_id||"")}))}function $k(e){const t={attention:0,user_wait:0,tool_approval:0,running:0,failed:0,scheduled:0,subflows:0,finished:0,all:e.length};for(const n of e)t[n.queue]+=1,n.queue!=="finished"&&(n.needs_user_action||n.status==="failed"||n.is_stale||n.wait_kind==="unknown_wait")&&(t.attention+=1);return t}function Ek(e,t){const n=t.queue,a=(t.query??"").trim().toLowerCase();return e.filter(l=>{if(n==="attention"){if(!(l.needs_user_action||l.status==="failed"||l.is_stale||l.wait_kind==="unknown_wait"))return!1}else if(n!=="all"&&l.queue!==n)return!1;return!a||l.search_text.includes(a)})}function Ak(e,t){const n=[...e];return n.sort((i,a)=>{if(t==="recent")return a.updated_ms-i.updated_ms;if(t==="oldest")return i.updated_ms-a.updated_ms;if(t==="duration")return a.duration_ms-i.duration_ms;if(t==="tokens")return(Number(a.run.tokens_total||0)||0)-(Number(i.run.tokens_total||0)||0);if(t==="workflow")return String(i.run.workflow_id||"").localeCompare(String(a.run.workflow_id||""));const l=i.attention_rank-a.attention_rank;return l!==0?l:a.updated_ms-i.updated_ms}),n}function Mk(e){const[t,n]=_.useState("attention"),[i,a]=_.useState(""),[l,u]=_.useState("attention"),[d,m]=_.useState(""),p=_.useMemo(()=>{const F={};for(const C of e.artifacts){const k=String(C.run_id||"").trim();k&&(F[k]=(F[k]||0)+1)}return F},[e.artifacts]),g=_.useMemo(()=>Ck(e.runs,{workflow_label_by_id:e.workflow_label_by_id}),[e.runs,e.workflow_label_by_id]),v=_.useMemo(()=>$k(g),[g]),w=_.useMemo(()=>{const F=Ek(g,{queue:t,query:i});return Ak(F,l)},[g,t,i,l]),x=w.find(F=>String(F.run_id||"")===d)||w.find(F=>String(F.run_id||"")===e.selected_run_id)||w[0]||null,N=(x==null?void 0:x.run)||null,S=String((N==null?void 0:N.run_id)||"").trim(),R=String((N==null?void 0:N.session_id)||"").trim(),T=_.useMemo(()=>R?new Set(e.runs.filter(F=>String(F.session_id||"").trim()===R).map(F=>String(F.run_id||"").trim()).filter(Boolean)):new Set,[e.runs,R]),z=R?T.size:0,H=_.useMemo(()=>R?e.artifacts.filter(F=>String(F.session_id||"").trim()===R||T.has(String(F.run_id||"").trim())).length:0,[e.artifacts,R,T]),D=N!=null&&N.waiting&&typeof N.waiting=="object"?N.waiting:null,G=D?gu(D):[],Q=(x==null?void 0:x.reason)||(D?jg(D,G):""),Y=(x==null?void 0:x.expected_action)||(D?tw(D,G):""),ee=D?rk(D,null):"",ae=S&&p[S]||0,le=yi(N==null?void 0:N.status),ge=[{key:"attention",label:"Needs attention",count:v.attention},{key:"user_wait",label:"Needs my response",count:v.user_wait},{key:"tool_approval",label:"Tool approvals",count:v.tool_approval},{key:"running",label:"Running",count:v.running},{key:"failed",label:"Failed",count:v.failed},{key:"scheduled",label:"Scheduled",count:v.scheduled},{key:"subflows",label:"Subflows / external events",count:v.subflows},{key:"finished",label:"Finished",count:v.finished},{key:"all",label:"All loaded",count:v.all}];return r.jsxs("div",{className:"runtime_ops_layout",children:[r.jsxs("aside",{className:"pane runtime_ops_filters",children:[r.jsxs("div",{className:"pane_header runtime_ops_filter_header",children:[r.jsx("span",{className:"pane_title",children:"Queues"}),r.jsx("div",{className:"pane_spacer"}),r.jsxs("button",{className:"btn btn_icon",onClick:e.gateway_connected?e.on_refresh_runs:e.on_reconnect,children:[r.jsx(Nn,{name:"refresh",size:14}),e.gateway_connected?"Refresh":"Reconnect"]})]}),r.jsxs("div",{className:"pane_body scroll runtime_ops_queue_list",children:[ge.map(F=>r.jsxs("button",{className:`runtime_ops_filter ${t===F.key?"selected":""}`,"aria-pressed":t===F.key,onClick:()=>n(F.key),children:[r.jsx("span",{children:F.label}),r.jsx("strong",{children:F.count.toLocaleString()})]},F.key)),r.jsx("div",{className:"runtime_ops_hint",children:"Counts are for the loaded runtime page. Refine search or refresh when supervising large runtimes."})]})]}),r.jsxs("section",{className:"pane runtime_ops_table_panel",children:[r.jsxs("div",{className:"pane_header runtime_ops_list_header",children:[r.jsx("span",{className:"pane_title",children:"Runs"}),r.jsx("span",{className:"pane_count",children:w.length.toLocaleString()}),r.jsx("div",{className:"pane_spacer"}),r.jsx("input",{value:i,onChange:F=>a(F.target.value),placeholder:"Search workflow, run, node, status, error"}),r.jsxs("select",{className:"seg_select",value:l,onChange:F=>u(F.target.value),children:[r.jsx("option",{value:"attention",children:"Attention order"}),r.jsx("option",{value:"recent",children:"Latest event"}),r.jsx("option",{value:"oldest",children:"Oldest event"}),r.jsx("option",{value:"duration",children:"Longest duration"}),r.jsx("option",{value:"tokens",children:"Most tokens"}),r.jsx("option",{value:"workflow",children:"Workflow"})]})]}),r.jsxs("div",{className:"pane_body scroll runtime_ops_rows",children:[w.length?null:r.jsx("div",{className:"runtime_ops_empty",children:e.gateway_connected?"No runs match this queue.":"Gateway offline. Runtime activity cannot be loaded until the connection is restored."}),w.map(F=>{const C=F.run,k=String(C.run_id||"").trim(),I=p[k]||0;return r.jsxs("div",{className:`raised runtime_ops_row ${k===S?"selected":""}`,"aria-current":k===S?"true":void 0,tabIndex:0,onClick:()=>{m(k),e.on_select_run(k)},onKeyDown:P=>{(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),m(k),e.on_select_run(k))},children:[r.jsxs("div",{className:"runtime_ops_row_top",children:[r.jsx("strong",{className:"runtime_ops_row_name",children:hi(C,e.workflow_label_by_id)}),F.is_stale?r.jsx("span",{className:"chip warn",children:"stale"}):null,r.jsx(rl,{status:C.status})]}),r.jsxs("div",{className:"runtime_ops_row_sub",children:[r.jsx("span",{className:"mono",children:Et(k,18)}),r.jsx("span",{children:Ko(C.updated_at||C.created_at)}),r.jsx("span",{children:rc(C)}),r.jsx("span",{className:"runtime_ops_row_reason",title:F.reason,children:F.reason})]}),r.jsxs("div",{className:"runtime_ops_row_foot",children:[r.jsxs("span",{className:"runtime_ops_row_facts",children:[r.jsxs("span",{children:[Number(C.llm_calls||0).toLocaleString()," llm"]}),r.jsxs("span",{children:[Number(C.tool_calls||0).toLocaleString()," tools"]}),r.jsxs("span",{children:[Number(C.tokens_total||0).toLocaleString()," tok"]}),r.jsxs("span",{children:[I.toLocaleString()," artifacts"]})]}),r.jsxs("div",{className:"runtime_ops_actions",children:[F.needs_user_action?r.jsx("button",{className:"btn primary",onClick:P=>{P.stopPropagation(),e.on_open_run(k)},children:F.action_label}):r.jsx("button",{className:"btn",onClick:P=>{P.stopPropagation(),e.on_open_run(k)},children:"Open"}),r.jsx("button",{className:"btn",onClick:P=>{P.stopPropagation(),e.on_open_ledger(k)},children:"Ledger"}),r.jsx("button",{className:"btn",onClick:P=>{P.stopPropagation(),e.on_select_run(k),e.on_open_logs()},children:"Logs"}),r.jsx("button",{className:"btn",onClick:P=>{P.stopPropagation(),e.on_filter_artifacts(k)},children:"Artifacts"})]})]})]},k)})]})]}),r.jsxs("aside",{className:"pane runtime_ops_inspector",children:[r.jsxs("div",{className:"pane_header",children:[r.jsx("span",{className:"pane_title",children:"Run inspector"}),N?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"pane_spacer"}),r.jsx(rl,{status:N.status})]}):null]}),r.jsx("div",{className:"pane_body scroll runtime_ops_inspector_body",children:N?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"runtime_ops_inspector_head",children:[r.jsx("h3",{children:hi(N,e.workflow_label_by_id)}),r.jsx("span",{className:"mono",children:Et(S,28)})]}),r.jsxs("div",{className:"runtime_ops_decision",children:[r.jsx("strong",{children:(x==null?void 0:x.reason)||ok(N)}),r.jsx("span",{children:(x==null?void 0:x.expected_action)||(String(N.status||"").toLowerCase()==="waiting"?"This run is paused until the pending wait is resolved or the run is cancelled.":le?"This run is terminal. Open the ledger for the narrative and final error/output.":"This run is active or recently updated. Use ledger/provider logs to inspect live work.")})]}),r.jsxs("div",{className:"artifact_detail_grid",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Started"}),r.jsx("strong",{children:Xo(Gl(N))})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Elapsed"}),r.jsx("strong",{children:rc(N)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Last event"}),r.jsx("strong",{children:Xo(N.updated_at||N.created_at)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Session"}),r.jsx("strong",{className:"mono",children:N.session_id?Et(String(N.session_id),18):"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Node"}),r.jsx("strong",{className:"mono",children:N.current_node||"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Visible artifacts"}),r.jsx("strong",{children:ae.toLocaleString()})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Provider calls"}),r.jsx("strong",{children:Number(N.llm_calls||0).toLocaleString()})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Tokens"}),r.jsx("strong",{children:Number(N.tokens_total||0).toLocaleString()})]})]}),R?r.jsxs("section",{className:"runtime_ops_session_context",children:[r.jsxs("div",{children:[r.jsx("span",{className:"run_hero_eyebrow",children:"Session context"}),r.jsx("strong",{className:"mono",children:Et(R,30)})]}),r.jsxs("div",{className:"runtime_ops_session_facts",children:[r.jsxs("span",{children:[z.toLocaleString()," loaded run",z===1?"":"s"]}),r.jsxs("span",{children:[H.toLocaleString()," visible artifact",H===1?"":"s"]})]}),r.jsxs("div",{className:"runtime_detail_actions compact",children:[r.jsx("button",{className:"btn",onClick:()=>e.on_filter_session_artifacts(R),children:"Open session artifacts"}),r.jsx("button",{className:"btn",onClick:()=>void nc(R),children:"Copy session id"})]})]}):null,D?r.jsxs("div",{className:"runtime_ops_wait_summary",children:[r.jsxs("div",{className:"runtime_ops_wait_header",children:[r.jsx("span",{className:"run_hero_eyebrow",children:"Blocked on"}),r.jsx("strong",{children:Q})]}),r.jsx("p",{children:Y}),ee?r.jsxs("div",{className:"runtime_ops_wait_request",children:[r.jsx("span",{children:"Request"}),r.jsx(pi,{text:ee})]}):r.jsx("div",{className:"runtime_ops_wait_request muted",children:"No explicit prompt is attached to this wait. Open Observe or the ledger for full run context before responding."}),G.length?r.jsx("div",{className:"runtime_ops_wait_tools",children:G.map((F,C)=>r.jsxs(pe.Fragment,{children:[r.jsx("span",{className:"chip mono warn",children:String((F==null?void 0:F.name)||"tool")}),ew(F).map(k=>r.jsxs("span",{className:"chip muted",title:Qv,children:[k,"~"]},`${C}:${k}`))]},`${String((F==null?void 0:F.name)||"tool")}:${C}`))}):null,r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"muted",children:"Raw wait payload"}),r.jsx(ps,{value:D,collapseAfterDepth:3,showCopy:!0})]})]}):null,Wm(N)?r.jsx("div",{className:"warn_callout",children:Wm(N)}):null,r.jsxs("div",{className:"runtime_detail_actions",children:[r.jsx("button",{className:"btn primary",onClick:()=>e.on_open_run(S),children:"Open Observe"}),r.jsx("button",{className:"btn",onClick:()=>e.on_open_ledger(S),children:"Open ledger"}),r.jsx("button",{className:"btn",onClick:()=>e.on_filter_artifacts(S),children:"Open artifacts"}),r.jsx("button",{className:"btn",onClick:e.on_open_logs,children:"Open logs"}),r.jsx("button",{className:"btn",onClick:()=>void nc(S),children:"Copy run id"})]})]}):r.jsx("div",{className:"empty_state_inline",children:"Select a run to inspect why it is active or blocked."})})]})]})}function Tk(e){const t=e.selected_artifact,n=["voice","music","sound","recording","audio","image","video","markdown","html","json","document","code","text","other"],i=[{value:"all",label:"Any time"},{value:"hour",label:"Last hour"},{value:"today",label:"Today"},{value:"week",label:"7 days"},{value:"month",label:"30 days"}],a=_.useMemo(()=>new Set(e.type_filters),[e.type_filters]),l=Math.max(0,Number(e.artifact_total_count||0)),u=!!e.query.trim()||e.type_filters.length>0||e.date_filter!=="all"||e.scope!=="all"||!!e.artifact_run_filter.trim(),d=Math.max(1,Number(e.artifact_page_size||500)),m=Math.max(1,Math.ceil(l/d)),p=Math.min(Math.max(0,Number(e.artifact_page||0)),m-1),g=l?p*d+1:0,v=Math.min(l,p*d+e.artifacts.length),w=_.useMemo(()=>{const C={},k=e.artifact_type_facets&&Object.keys(e.artifact_type_facets).length?e.artifact_type_facets:e.artifact_facets,I=(k==null?void 0:k.semantic_kind)||{},P=(k==null?void 0:k.render_kind)||{};for(const K of n)C[K]=Number(I[K]||P[K]||0);return C.audio=Number(I.audio||0),C.other=Number(I.other||0)+Number(I.artifact||0)+Number(I.binary||0)+Number(I["(none)"]||0),C},[e.artifact_facets,e.artifact_type_facets]),x=C=>{const k=new Set(a);k.has(C)?k.delete(C):k.add(C),e.on_type_filters_change(Array.from(k.values()))},N=_.useMemo(()=>{const C={waiting:[],running:[],failed:[],cancelled:[],completed:[],other:[]};for(const k of e.runs){const I=String(k.status||"").trim().toLowerCase();I==="waiting"?C.waiting.push(k):I==="running"?C.running.push(k):I==="failed"?C.failed.push(k):I==="cancelled"?C.cancelled.push(k):I==="completed"?C.completed.push(k):C.other.push(k)}return C},[e.runs]),S=t!=null&&t.run_id&&e.run_by_id[t.run_id]||null,R=e.artifact_run_filter?hi(e.run_by_id[e.artifact_run_filter],e.workflow_label_by_id):"",T=_.useMemo(()=>{var I;const C=new Set,k=((I=e.artifact_facets)==null?void 0:I.run_id)||{};for(const P of Object.keys(k))P&&P!=="(none)"&&C.add(P);for(const P of e.artifacts)P.run_id&&C.add(P.run_id);for(const P of e.active_runs)P.run_id&&C.add(String(P.run_id));return Array.from(C).map(P=>e.run_by_id[P]||{run_id:P,workflow_id:null,status:"",created_at:null,updated_at:null}).sort((P,K)=>{const L=du(P.status)?0:1,O=du(K.status)?0:1;if(L!==O)return L-O;const q=xn(P.updated_at||P.created_at)??0;return(xn(K.updated_at||K.created_at)??0)-q}).slice(0,160)},[e.artifacts,e.active_runs,e.run_by_id,e.artifact_facets]),z=C=>{e.on_artifact_run_filter_change(C),e.on_session_filter_change(""),e.on_scope_change(C?"run":"all")},H=C=>e.gateway_connected?Math.max(0,Number(C||0)).toLocaleString():"—",D=e.selected_run_id&&e.run_by_id[e.selected_run_id]||null,G=_.useMemo(()=>{const C=e.runtime_log_query.trim().toLowerCase(),k=e.runtime_ledger_log_items||[];return C?k.filter(I=>{var L,O;const P=I.record||{};return[I.cursor,P.run_id,P.node_id,P.status,(L=P.effect)==null?void 0:L.type,P.started_at,P.ended_at,Tr(((O=P.effect)==null?void 0:O.payload)??{},900),Tr(P.result??{},900)].join(" ").toLowerCase().includes(C)}):k},[e.runtime_ledger_log_items,e.runtime_log_query]),Q=_.useMemo(()=>{const C=e.runtime_log_query.trim().toLowerCase(),k=ow(e.runtime_ledger_log_items);return C?k.filter(I=>[I.provider,I.model,I.run_id,I.node_id,I.status,I.error,I.prompt_preview,I.response_preview,I.tokens.prompt,I.tokens.completion,I.tokens.total].join(" ").toLowerCase().includes(C)):k},[e.runtime_ledger_log_items,e.runtime_log_query]),Y=Q.reduce((C,k)=>C+(Number(k.tokens.total)||0),0),ee=Q.filter(C=>C.missing_response||C.error).length,ae=_.useMemo(()=>{const C=e.runtime_log_query.trim().toLowerCase(),k=String(e.audit_log_text||"").replace(/\r\n/g,`
|
|
98
|
+
`).replace(/\r/g,`
|
|
99
|
+
`).split(`
|
|
100
|
+
`).filter(Boolean);return C?k.filter(I=>I.toLowerCase().includes(C)):k},[e.audit_log_text,e.runtime_log_query]),le=e.runtime_log_source==="run_ledger"||e.runtime_log_source==="provider_calls",ge=e.runtime_log_source==="run_ledger"?"Selected Run Ledger":e.runtime_log_source==="provider_calls"?"Provider Calls":"Gateway HTTP Audit",F=e.runtime_log_source==="run_ledger"?"Runtime execution records for the selected workflow run.":e.runtime_log_source==="provider_calls"?"Model/provider call records extracted from the selected run ledger.":"Global Gateway HTTP/audit tail. This is system activity, not artifact provenance.";return r.jsxs("div",{className:"page runtime_page",children:[r.jsxs("section",{className:"runtime_header",children:[r.jsxs("div",{children:[r.jsx("div",{className:"run_hero_eyebrow",children:"System"}),r.jsx("h2",{children:e.tab==="activity"?"Activity monitor":e.tab==="artifacts"?"Artifact explorer":e.tab==="memory"?"Active memory":"Logs"}),r.jsxs("div",{className:"run_hero_meta",children:[r.jsx("span",{className:`status_pill ${e.gateway_connected?"ok":"warn"}`,children:e.gateway_connected?"gateway connected":"gateway offline"}),e.tab==="artifacts"&&e.artifact_run_filter?r.jsxs("span",{className:"chip muted",children:["filtered run ",r.jsx("span",{className:"mono",children:Et(e.artifact_run_filter,18)})]}):null,e.session_id?r.jsxs("span",{className:"chip muted",children:["session ",r.jsx("span",{className:"mono",children:Et(e.session_id,18)})]}):null]})]}),r.jsxs("div",{className:"metric_grid compact runtime_header_metrics",children:[r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Waiting"}),r.jsx("strong",{children:H(N.waiting.length)})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Running"}),r.jsx("strong",{children:H(N.running.length)})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Failed"}),r.jsx("strong",{children:H(N.failed.length)})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsxs("span",{children:["Artifacts",u?" (filtered)":""]}),r.jsx("strong",{children:H(l)})]})]})]}),r.jsx("nav",{className:"runtime_mode_tabs",role:"tablist","aria-label":"System sections",children:["activity","artifacts","memory","logs"].map(C=>r.jsxs("button",{role:"tab","aria-selected":e.tab===C,className:`runtime_mode_tab ${e.tab===C?"active":""}`,onClick:()=>e.on_tab_change(C),children:[r.jsx(Nn,{name:C==="activity"?"history":C==="artifacts"?"download":C==="memory"?"agent":"terminal",size:14}),r.jsx("span",{children:C==="activity"?"Activity":C==="artifacts"?"Artifacts":C==="memory"?"Memory":"Logs"})]},C))}),e.gateway_connected?null:r.jsxs("div",{className:"runtime_offline_banner",role:"status",children:[r.jsxs("div",{children:[r.jsx("strong",{children:"Gateway offline"}),r.jsx("span",{children:"Activity, artifacts, memory, and logs are unavailable until the gateway reconnects."})]}),r.jsxs("div",{children:[r.jsx("button",{className:"btn primary",onClick:e.on_reconnect,children:"Reconnect"}),r.jsx("button",{className:"btn",onClick:e.on_open_settings,children:"Settings"})]})]}),e.error?r.jsx("div",{className:"warn_callout",children:e.error}):null,e.tab==="activity"?r.jsx(Mk,{gateway_connected:e.gateway_connected,runs:e.runs,artifacts:e.artifacts,selected_run_id:e.selected_run_id,workflow_label_by_id:e.workflow_label_by_id,on_select_run:e.on_select_run,on_open_run:e.on_open_run,on_open_ledger:e.on_open_ledger,on_refresh_runs:e.on_refresh_runs,on_reconnect:e.on_reconnect,on_open_logs:()=>e.on_tab_change("logs"),on_filter_artifacts:C=>{z(C),e.on_select_run(C),e.on_tab_change("artifacts")},on_filter_session_artifacts:C=>{C&&(e.on_artifact_run_filter_change(""),e.on_session_filter_change(C),e.on_scope_change("session"),e.on_tab_change("artifacts"))}}):null,e.tab==="memory"?e.memory_panel?r.jsx("div",{className:"runtime_memory_panel",children:e.memory_panel}):r.jsx("div",{className:"empty_state_inline",children:"The memory explorer needs a gateway connection — sign in to browse knowledge-graph assertions."}):null,e.tab==="artifacts"?r.jsxs(r.Fragment,{children:[r.jsxs("section",{className:"pane runtime_artifact_toolbar","aria-label":"Find artifacts",children:[r.jsxs("div",{className:"runtime_artifact_toolbar_top",children:[r.jsxs("label",{className:"artifact_filter_field artifact_filter_search",children:[r.jsx("span",{children:"Search"}),r.jsx("input",{value:e.query,onChange:C=>e.on_query_change(C.target.value),placeholder:"title, path, hash, run, workflow, tag"})]}),r.jsxs("label",{className:"artifact_filter_field",children:[r.jsx("span",{children:"Scope"}),r.jsxs("select",{className:"seg_select",value:e.scope,onChange:C=>{const k=C.target.value;k!=="run"&&e.on_artifact_run_filter_change(""),k==="session"?e.on_session_filter_change(e.session_id):e.on_session_filter_change(""),e.on_scope_change(k)},children:[r.jsx("option",{value:"all",children:"All runtime"}),r.jsx("option",{value:"session",children:"This session"}),r.jsx("option",{value:"run",children:"Selected run"})]})]}),r.jsxs("label",{className:"artifact_filter_field",children:[r.jsx("span",{children:"Group"}),r.jsxs("select",{className:"seg_select",value:e.group_by,onChange:C=>e.on_group_by_change(C.target.value),children:[r.jsx("option",{value:"type",children:"Type"}),r.jsx("option",{value:"time",children:"Date"}),r.jsx("option",{value:"turn",children:"Turn"}),r.jsx("option",{value:"node",children:"Node"}),r.jsx("option",{value:"workflow",children:"Workflow"}),r.jsx("option",{value:"run",children:"Run"}),r.jsx("option",{value:"location",children:"Location"}),r.jsx("option",{value:"source",children:"Source"})]})]}),r.jsxs("label",{className:"artifact_filter_field",children:[r.jsx("span",{children:"Sort"}),r.jsxs("select",{className:"seg_select",value:e.sort_by,onChange:C=>e.on_sort_by_change(C.target.value),children:[r.jsx("option",{value:"newest",children:"Newest"}),r.jsx("option",{value:"oldest",children:"Oldest"}),r.jsx("option",{value:"last_access",children:"Last accessed"}),r.jsx("option",{value:"turn",children:"Turn order"}),r.jsx("option",{value:"type",children:"Type"}),r.jsx("option",{value:"size_desc",children:"Largest"}),r.jsx("option",{value:"size_asc",children:"Smallest"})]})]}),r.jsxs("button",{className:"btn btn_icon",onClick:e.on_refresh_artifacts,disabled:!e.gateway_connected||e.loading,children:[r.jsx(Nn,{name:"refresh",size:14}),e.loading?"Loading…":"Refresh"]})]}),r.jsxs("div",{className:"artifact_filter_section",children:[r.jsxs("div",{className:"artifact_filter_label",children:["Type ",r.jsx("span",{className:"muted",children:"OR"})]}),r.jsxs("div",{className:"artifact_filter_chips",role:"group","aria-label":"Artifact type filters combine with OR",children:[n.map(C=>{const k=a.has(C),I=w[C]||0,P=uk(C);return r.jsxs("button",{type:"button","aria-pressed":k,"aria-label":`${k?"Remove":"Add"} ${P} artifact type filter. Type filters combine with OR.`,title:`${k?"Remove":"Add"} ${P}. Type filters combine with OR.`,className:`artifact_filter_chip ${k?"active":""}`,onClick:()=>x(C),children:[r.jsx("span",{children:P}),r.jsx("span",{className:"artifact_chip_count",children:e.gateway_connected?I.toLocaleString():"—"})]},C)}),e.type_filters.length?r.jsx("button",{type:"button",className:"artifact_filter_chip clear",onClick:()=>e.on_type_filters_change([]),children:"Clear types"}):null]})]}),r.jsxs("div",{className:"artifact_filter_section",children:[r.jsx("div",{className:"artifact_filter_label",children:"Date"}),r.jsx("div",{className:"artifact_filter_chips",role:"group","aria-label":"Artifact date filters",children:i.map(C=>r.jsx("button",{type:"button","aria-pressed":e.date_filter===C.value,className:`artifact_filter_chip ${e.date_filter===C.value?"active":""}`,onClick:()=>e.on_date_filter_change(C.value),children:C.label},C.value))})]})]}),r.jsx("div",{className:"artifact_scope_banner",children:e.artifact_run_filter?r.jsxs(r.Fragment,{children:["Showing artifacts for ",r.jsx("strong",{children:R||Et(e.artifact_run_filter,18)}),".",r.jsx("button",{className:"btn",onClick:()=>z(""),children:"Show all"})]}):r.jsxs(r.Fragment,{children:["Showing artifacts across the selected runtime scope. Select a run to filter the inventory. ",e.artifact_total_bytes?r.jsxs("span",{className:"mono muted",children:["Total size ",Kl(e.artifact_total_bytes)]}):null]})}),r.jsxs("div",{className:"runtime_artifacts_layout",children:[r.jsxs("aside",{className:"pane artifact_filter_rail",children:[r.jsxs("div",{className:"pane_header",children:[r.jsx("span",{className:"pane_title",children:"Runs"}),r.jsx("span",{className:"pane_count",children:T.length.toLocaleString()})]}),r.jsxs("div",{className:"pane_body scroll artifact_filter_rail_list",children:[r.jsxs("button",{className:`artifact_filter_run ${e.artifact_run_filter?"":"selected"}`,onClick:()=>z(""),children:[r.jsx("strong",{children:"All artifacts"}),r.jsx("span",{children:e.gateway_connected?`${l.toLocaleString()} match${l===1?"":"es"}`:"counts unavailable"})]}),T.map(C=>{const k=String(C.run_id||"").trim(),I=k===e.artifact_run_filter||k===(t==null?void 0:t.run_id);return r.jsxs("button",{className:`artifact_filter_run ${I?"selected":""}`,onClick:()=>z(k),title:k,children:[r.jsx("strong",{children:hi(C,e.workflow_label_by_id)}),r.jsx("span",{className:"mono",children:Et(k,15)}),r.jsx("span",{children:rc(C)})]},k)})]})]}),r.jsxs("section",{className:"pane runtime_artifact_browser",children:[r.jsxs("div",{className:"pane_header artifact_browser_header",children:[r.jsx("span",{className:"pane_title",children:"Artifacts"}),r.jsx("span",{className:"pane_count",children:l?`${g.toLocaleString()}-${v.toLocaleString()} of ${l.toLocaleString()}`:"0 items"}),r.jsx("div",{className:"pane_spacer"}),m>1?r.jsxs("div",{className:"artifact_pagination","aria-label":"Artifact pages",children:[r.jsx("button",{className:"btn",onClick:()=>e.on_artifact_page_change(0),disabled:p<=0,children:"First"}),r.jsx("button",{className:"btn",onClick:()=>e.on_artifact_page_change(p-1),disabled:p<=0,children:"Prev"}),r.jsxs("span",{className:"muted artifact_page_label",children:["Page ",(p+1).toLocaleString()," / ",m.toLocaleString()]}),r.jsx("button",{className:"btn",onClick:()=>e.on_artifact_page_change(p+1),disabled:p>=m-1,children:"Next"}),r.jsx("button",{className:"btn",onClick:()=>e.on_artifact_page_change(m-1),disabled:p>=m-1,children:"Last"})]}):null]}),r.jsxs("div",{className:"pane_body scroll artifact_browser_body",children:[e.artifact_groups.length?null:r.jsx("div",{className:"empty_state_inline",children:e.gateway_connected?"No artifacts match the current filters.":"Gateway offline. Artifact inventory cannot be loaded until the connection is restored."}),r.jsx("div",{className:"artifact_group_list",children:e.artifact_groups.map(C=>r.jsxs("section",{className:"artifact_group",children:[r.jsxs("div",{className:"artifact_group_header",children:[r.jsx("span",{children:C.key}),r.jsx("span",{className:"artifact_group_count",children:C.items.length})]}),C.items.map(k=>{var O;const I=k.run_id&&e.run_by_id[k.run_id]||null,P=I?hi(I,e.workflow_label_by_id):Sg(k),K=Lp(k),L=Number(((O=k.access)==null?void 0:O.access_count)||0)||0;return r.jsxs("button",{className:`artifact_row ${(t==null?void 0:t.artifact_id)===k.artifact_id?"selected":""}`,onClick:()=>{e.on_select_artifact(k.artifact_id),k.run_id&&e.on_select_run(k.run_id)},title:k.artifact_id,children:[r.jsx(Pp,{artifact:k,size:18}),r.jsxs("div",{className:"artifact_row_main",children:[r.jsxs("div",{className:"artifact_row_title",children:[r.jsx("strong",{children:Rp(Hm(k,e.run_by_id,e.workflow_label_by_id))}),r.jsx("span",{className:"artifact_type_badge",children:ou(k)}),k.render_kind&&k.render_kind!==k.semantic_kind?r.jsx("span",{className:"artifact_type_badge muted",children:k.render_kind}):null,k.legacy_inferred?r.jsx("span",{className:"artifact_type_badge inferred",children:"legacy inferred"}):null]}),r.jsxs("div",{className:"artifact_row_facts",children:[r.jsxs("span",{children:[r.jsx("b",{children:"Created"})," ",mk(k)]}),r.jsxs("span",{children:[r.jsx("b",{children:"Size"})," ",Kl(k.size_bytes)]}),r.jsxs("span",{children:[r.jsx("b",{children:"Last seen"})," ",Tp(k)]}),L?r.jsxs("span",{children:[r.jsx("b",{children:"Accesses"})," ",L.toLocaleString()]}):null,K?r.jsxs("span",{children:[r.jsx("b",{children:"Media"})," ",K]}):null,k.content_type?r.jsxs("span",{children:[r.jsx("b",{children:"MIME"})," ",k.content_type]}):null]}),r.jsxs("div",{className:"artifact_row_facts secondary",children:[P?r.jsxs("span",{children:[r.jsx("b",{children:"Workflow"})," ",P]}):null,k.run_id?r.jsxs("span",{className:"mono",children:[r.jsx("b",{children:"Run"})," ",Et(k.run_id,13)]}):null,r.jsxs("span",{children:[r.jsx("b",{children:"Turn"})," ",W_(k)]}),iu(k)?r.jsxs("span",{className:"mono",children:[r.jsx("b",{children:"Node"})," ",iu(k)]}):null,Bd(k)?r.jsxs("span",{children:[r.jsx("b",{children:"Source"})," ",Bd(k)]}):null]}),r.jsxs("div",{className:"artifact_row_facts tertiary",children:[r.jsxs("span",{className:"mono",children:[r.jsx("b",{children:"ID"})," ",Et(k.artifact_id,22)]}),r.jsxs("span",{children:[r.jsx("b",{children:"Provenance"})," ",Ap(k)]})]}),Op(k)?r.jsx("div",{className:"artifact_row_path mono",children:Op(k)}):null]})]},k.artifact_id)})]},C.key))})]})]}),r.jsx("aside",{className:"runtime_detail",children:r.jsxs("section",{className:"overview_panel runtime_artifact_detail",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Artifact Detail"}),t?r.jsx("span",{className:"chip mono muted",children:e.embedded_preview.render_kind?H_(t,e.run_by_id,e.workflow_label_by_id,e.embedded_preview.text):H_(t,e.run_by_id,e.workflow_label_by_id)}):null]}),t?r.jsxs(r.Fragment,{children:[(()=>{var O,q,E,X,ne,ie,de;const C=hk(t),k=sw(t),I=Lp(t),P=Number(((O=t.access)==null?void 0:O.access_count)||0)||0,K=ln((q=t.links)==null?void 0:q.provider_trace,(E=t.links)==null?void 0:E.provider_trace_url,(X=t.links)==null?void 0:X.provider_trace_id),L=ln((ne=t.links)==null?void 0:ne.audit,(ie=t.links)==null?void 0:ie.audit_tail,(de=t.links)==null?void 0:de.audit_url);return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"artifact_detail_header",children:[r.jsx(Pp,{artifact:t,size:22}),r.jsxs("div",{children:[r.jsx("div",{className:"artifact_detail_title",children:Rp(Hm(t,e.run_by_id,e.workflow_label_by_id))}),r.jsxs("div",{className:"artifact_detail_subtitle",children:[ou(t)," • ",t.render_kind||e.embedded_preview.render_kind||t.modality||"artifact"," • ",t.content_type||"unknown MIME"," • ",Kl(t.size_bytes),t.legacy_inferred?" • legacy inferred":""]})]})]}),r.jsx(jk,{artifact:t,preview:e.embedded_preview}),r.jsxs("div",{className:"artifact_detail_grid",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Semantic type"}),r.jsx("strong",{children:ou(t)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Render kind"}),r.jsx("strong",{children:t.render_kind||e.embedded_preview.render_kind||"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Created"}),r.jsx("strong",{children:Xo(t.created_at)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Size"}),r.jsx("strong",{children:Kl(t.size_bytes)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Last seen"}),r.jsx("strong",{children:Tp(t)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Accesses"}),r.jsx("strong",{children:P?P.toLocaleString():"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Run"}),r.jsx("strong",{className:"mono",children:t.run_id?Et(t.run_id,24):"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Workflow"}),r.jsx("strong",{children:S?hi(S,e.workflow_label_by_id):"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Turn"}),r.jsx("strong",{children:W_(t)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Node"}),r.jsx("strong",{className:"mono",children:iu(t)||"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Provider/model"}),r.jsx("strong",{children:k||"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Media facts"}),r.jsx("strong",{children:I||"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Trace"}),r.jsx("strong",{children:t.provider_trace_available?"available":"not recorded"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Provenance"}),r.jsx("strong",{children:Ap(t)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Artifact id"}),r.jsx("strong",{className:"mono",children:Et(t.artifact_id,30)})]}),t.sha256?r.jsxs("div",{children:[r.jsx("span",{children:"sha256"}),r.jsx("strong",{className:"mono",children:Et(t.sha256,30)})]}):null]}),C?r.jsxs("div",{className:"artifact_provenance_panel",children:[r.jsx("div",{className:"artifact_filter_label",children:"Generation prompt / input"}),r.jsx("div",{className:"artifact_prompt_text",children:C})]}):r.jsxs("div",{className:"artifact_provenance_panel muted",children:[r.jsx("div",{className:"artifact_filter_label",children:"Generation prompt / input"}),r.jsx("div",{className:"artifact_prompt_text",children:"Generation prompt not recorded by the runtime artifact descriptor."})]}),Object.keys(t.generation||{}).length||Object.keys(t.producer||{}).length?r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"mono muted",children:"Generation and producer metadata"}),r.jsx(ps,{value:{generation:t.generation,producer:t.producer,source_refs:t.source_refs},collapseAfterDepth:3,showCopy:!0})]}):null,t.source_path?r.jsx("div",{className:"artifact_detail_path mono",children:t.source_path}):null,r.jsxs("div",{className:"runtime_detail_actions",children:[r.jsx("button",{className:"btn primary",onClick:()=>e.on_preview_artifact(t),disabled:!t.run_id,children:e.embedded_preview.render_kind==="html"?"Open as web page":"Open full preview"}),r.jsx("button",{className:"btn",onClick:()=>e.on_download_artifact(t),disabled:!t.run_id,children:"Download"}),r.jsx("button",{className:"btn",onClick:()=>z(t.run_id),disabled:!t.run_id,children:"Show run artifacts"}),r.jsx("button",{className:"btn",onClick:()=>e.on_open_run(t.run_id),disabled:!t.run_id,children:"Open in Observe"}),r.jsx("button",{className:"btn",onClick:()=>e.on_open_ledger(t.run_id),disabled:!t.run_id,children:"Open run ledger"}),r.jsx("button",{className:"btn",onClick:()=>{K&&window.open(K,"_blank","noopener,noreferrer")},disabled:!K,children:"Open provider trace"}),r.jsx("button",{className:"btn",onClick:()=>{L?window.open(L,"_blank","noopener,noreferrer"):e.on_tab_change("logs")},disabled:!L&&!t.audit_available,children:"Open audit trail"}),r.jsx("button",{className:"btn",onClick:()=>void nc(t.artifact_id),disabled:!t.artifact_id,children:"Copy artifact id"})]})]})})(),r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"mono muted",children:"Raw metadata"}),r.jsx(ps,{value:t.raw,collapseAfterDepth:3,showCopy:!0})]})]}):r.jsx("div",{className:"empty_state_inline",children:"Select an artifact to inspect metadata, preview, or download content."})]})})]})]}):null,e.tab==="logs"?r.jsxs("section",{className:"overview_panel runtime_logs_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsxs("div",{children:[r.jsx("h3",{children:ge}),r.jsx("div",{className:"mono muted",children:F})]}),r.jsxs("div",{className:"actions",style:{marginTop:0},children:[le&&e.runtime_ledger_log_meta?r.jsx("span",{className:"mono muted",children:e.runtime_ledger_log_meta}):null,e.runtime_log_source==="gateway_audit"&&e.audit_log_meta?r.jsx("span",{className:"mono muted",children:e.audit_log_meta}):null,r.jsxs("button",{className:"btn btn_icon",onClick:()=>{le?e.on_refresh_runtime_ledger(e.selected_run_id):e.on_refresh_audit()},disabled:le?e.runtime_ledger_log_loading:e.audit_log_loading,children:[r.jsx(Nn,{name:"refresh",size:14}),le?e.runtime_ledger_log_loading?"Loading…":"Refresh":e.audit_log_loading?"Loading…":"Refresh"]})]})]}),r.jsxs("div",{className:"runtime_log_toolbar",children:[r.jsxs("div",{className:"seg_toggle mono",children:[r.jsx("button",{className:`seg_btn ${e.runtime_log_source==="run_ledger"?"active":""}`,onClick:()=>e.on_runtime_log_source_change("run_ledger"),children:"Run ledger"}),r.jsx("button",{className:`seg_btn ${e.runtime_log_source==="provider_calls"?"active":""}`,onClick:()=>e.on_runtime_log_source_change("provider_calls"),children:"Provider calls"}),r.jsx("button",{className:`seg_btn ${e.runtime_log_source==="gateway_audit"?"active":""}`,onClick:()=>e.on_runtime_log_source_change("gateway_audit"),children:"Gateway audit"})]}),r.jsx("input",{className:"mono",value:e.runtime_log_query,onChange:C=>e.on_runtime_log_query_change(C.target.value),placeholder:"Search node, status, effect, payload, error"})]}),e.runtime_log_source==="run_ledger"?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"runtime_log_context",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Selected run"}),r.jsx("strong",{children:D?hi(D,e.workflow_label_by_id):e.selected_run_id?Et(e.selected_run_id,24):"No run selected"}),e.selected_run_id?r.jsx("em",{className:"mono",children:Et(e.selected_run_id,34)}):null]}),r.jsxs("div",{children:[r.jsx("span",{children:"Session"}),r.jsx("strong",{className:"mono",children:D!=null&&D.session_id?Et(String(D.session_id),28):e.session_id?Et(e.session_id,28):"—"})]}),r.jsxs("div",{className:"runtime_log_context_actions",children:[r.jsx("button",{className:"btn",onClick:()=>e.on_open_run(e.selected_run_id),disabled:!e.selected_run_id,children:"Open Observe"}),r.jsx("button",{className:"btn",onClick:()=>z(e.selected_run_id),disabled:!e.selected_run_id,children:"Run artifacts"})]})]}),e.runtime_ledger_log_error?r.jsx("div",{className:"warn_callout",children:e.runtime_ledger_log_error}):null,e.selected_run_id?null:r.jsx("div",{className:"empty_state_inline",children:"Select a run in Activity or Artifact Explorer to inspect its runtime ledger."}),e.selected_run_id&&!G.length&&!e.runtime_ledger_log_loading?r.jsx("div",{className:"empty_state_inline",children:"No ledger records match the current search."}):null,r.jsx("div",{className:"runtime_log_event_list","aria-label":"Selected run ledger records",children:G.map(C=>{var ne,ie;const k=C.record||{},I=String(((ne=k==null?void 0:k.effect)==null?void 0:ne.type)||"").trim(),P=String((k==null?void 0:k.status)||"").trim(),K=String((k==null?void 0:k.node_id)||"").trim(),L=ln(k==null?void 0:k.ended_at,k==null?void 0:k.started_at,k==null?void 0:k.ts),O=Bi(k),q=iw(k),E=I?ut(Tr(((ie=k==null?void 0:k.effect)==null?void 0:ie.payload)??{},1200),{max_chars:1200,max_lines:6}):"",X=ef(k)||(O?`Waiting for ${String(O.reason||"input")}`:"")||((k==null?void 0:k.result)!==void 0?Tr(k.result,700):"");return r.jsxs("article",{className:`runtime_log_event ${nl(P)}`,children:[r.jsxs("div",{className:"runtime_log_event_header",children:[r.jsxs("span",{className:"mono",children:["#",C.cursor]}),r.jsx(rl,{status:P||"record"}),I?r.jsx("span",{className:"chip mono muted",children:I}):null,K?r.jsx("strong",{className:"mono",children:K}):null,L?r.jsx("span",{className:"mono muted",children:Xo(L)}):null]}),r.jsxs("div",{className:"runtime_log_event_body",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Request / activity"}),r.jsx("p",{children:[q||Am(k),E&&E!=="{}"?E:""].filter(Boolean).join(`
|
|
101
|
+
`)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Outcome"}),r.jsx("p",{children:ut(X||"—",{max_chars:1200,max_lines:6})})]})]}),r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"mono muted",children:"Raw ledger record"}),r.jsx(ps,{value:k,collapseAfterDepth:3,showCopy:!0})]})]},`${e.selected_run_id}:${C.cursor}`)})})]}):e.runtime_log_source==="provider_calls"?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"runtime_log_context",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Selected run"}),r.jsx("strong",{children:D?hi(D,e.workflow_label_by_id):e.selected_run_id?Et(e.selected_run_id,24):"No run selected"}),e.selected_run_id?r.jsx("em",{className:"mono",children:Et(e.selected_run_id,34)}):null]}),r.jsxs("div",{children:[r.jsx("span",{children:"Provider calls"}),r.jsx("strong",{children:Q.length.toLocaleString()}),r.jsx("em",{className:"mono",children:Y?`${Y.toLocaleString()} tokens`:"tokens not recorded"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Issues"}),r.jsx("strong",{children:ee.toLocaleString()})]}),r.jsxs("div",{className:"runtime_log_context_actions",children:[r.jsx("button",{className:"btn",onClick:()=>e.on_open_run(e.selected_run_id),disabled:!e.selected_run_id,children:"Open Observe"}),r.jsx("button",{className:"btn",onClick:()=>e.on_runtime_log_source_change("run_ledger"),disabled:!e.selected_run_id,children:"Run ledger"})]})]}),e.runtime_ledger_log_error?r.jsx("div",{className:"warn_callout",children:e.runtime_ledger_log_error}):null,e.selected_run_id?null:r.jsx("div",{className:"empty_state_inline",children:"Select a run in Activity or Artifact Explorer to inspect provider calls."}),e.selected_run_id&&!Q.length&&!e.runtime_ledger_log_loading?r.jsx("div",{className:"empty_state_inline",children:"No provider calls are present in the selected run ledger, or none match the current search."}):null,r.jsx("div",{className:"provider_activity_list runtime_provider_log_list",children:Q.map(C=>r.jsxs("article",{className:`provider_activity ${C.error||C.missing_response?"danger":""}`,children:[r.jsxs("div",{className:"provider_activity_header",children:[r.jsxs("div",{children:[r.jsx("h4",{children:[C.provider||"provider unknown",C.model||"model unknown"].join(" / ")}),r.jsxs("div",{className:"timeline_subtitle",children:[C.node_id?r.jsx("span",{className:"mono",children:C.node_id}):null,C.run_id?r.jsx("span",{className:"mono",children:Et(C.run_id,16)}):null,r.jsx("span",{children:vg(C.duration_ms)}),C.status?r.jsx(rl,{status:C.status}):null]})]}),r.jsxs("div",{className:"provider_tokens mono",children:[C.tokens.total?C.tokens.total.toLocaleString():"—"," tokens"]})]}),r.jsxs("div",{className:"provider_preview_grid",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Prompt / messages"}),r.jsx("p",{children:C.prompt_preview||"No prompt payload captured"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Response / error"}),r.jsx("p",{children:C.response_preview||C.error||"No response captured"})]})]}),r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"mono muted",children:"Raw provider ledger record"}),r.jsx(ps,{value:C.raw,collapseAfterDepth:3,showCopy:!0})]})]},C.id))})]}):r.jsxs(r.Fragment,{children:[e.audit_log_error?r.jsx("div",{className:"warn_callout",children:e.audit_log_error}):null,r.jsx("pre",{className:"mono audit_log_tail",children:ae.length?ae.join(`
|
|
102
|
+
`):"(audit tail not loaded or no lines match search)"})]})]}):null]})}const hm=30;function Rk(e){const[t,n]=_.useState(""),i=Array.isArray(e.wait.choices)?e.wait.choices:[],a=e.wait.allow_free_text!==!1,l=e.disabled===!0,u=String(e.wait.prompt||"").trim();return r.jsxs(r.Fragment,{children:[i.length?r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Expected response"}),r.jsxs("select",{className:"mono",value:t,onChange:d=>n(d.target.value),children:[r.jsx("option",{value:"",children:"(select)"}),i.map((d,m)=>r.jsx("option",{value:String(d),children:String(d)},m))]})]}):null,a?r.jsxs("div",{className:"field",children:[r.jsx("label",{children:i.length?"Or type a response":u?"Your answer":"Response to resume this wait"}),r.jsx("textarea",{className:"mono wait_response_input",value:t,onChange:d=>n(d.target.value),placeholder:u?"Type your answer to the request above…":"Type the response the workflow is waiting for…",rows:4})]}):null,r.jsx("div",{className:"actions",children:r.jsx("button",{className:"btn primary",disabled:l||!t.trim(),onClick:()=>e.on_submit(t.trim()),children:"Submit response"})})]})}function zp(e,t,n){if(Fd(e)==="automation"){const i=String(e.automation_id||e.run_id||"").trim();return n[i]||"Automation"}return hi(e,t)}function Fp(e){const t=Fd(e.run);return t?r.jsx("span",{className:"chip scheduled run_tree_tag","data-tag":t,children:Hv(e.run)}):null}function Lk(e){const t=e.selected_run_id.trim(),n=e.root_run_id.trim()||t,i=e.sections.reduce((a,l)=>a+l.rows.reduce((u,d)=>{const m=[d.run,...d.children];return u+m.filter(p=>du(p.status)).length},0),0);return r.jsxs("aside",{className:"observatory_sidebar pane",children:[r.jsxs("div",{className:"run_nav_header pane_header",children:[r.jsx("span",{className:"pane_title",children:"Runs"}),r.jsxs("span",{className:"pane_count",children:[e.total_runs.toLocaleString()," runs • ",i.toLocaleString()," active"]}),r.jsx("span",{className:"pane_spacer"}),r.jsxs("button",{className:"btn btn_icon",onClick:e.on_refresh,disabled:e.loading,title:"Refresh workflow runs",children:[r.jsx(Nn,{name:"refresh",size:14}),e.loading?"…":""]})]}),r.jsxs("div",{className:"run_nav_controls",children:[r.jsx("input",{value:e.search,onChange:a=>e.on_search(a.target.value),placeholder:"Search runs, sessions, workflows"}),r.jsxs("div",{className:"run_nav_filter_row",children:[r.jsx("div",{className:"seg_toggle run_nav_segments",children:["active","waiting","terminal","failed","all"].map(a=>r.jsx("button",{className:`seg_btn ${e.filter===a?"active":""}`,onClick:()=>e.on_filter(a),children:a},a))}),r.jsxs("select",{className:"seg_select",value:e.group_by,onChange:a=>e.on_group_by(a.target.value),title:"Group workflow runs",children:[r.jsx("option",{value:"status",children:"Group by status"}),r.jsx("option",{value:"workflow",children:"Group by workflow"}),r.jsx("option",{value:"session",children:"Group by session"})]})]})]}),r.jsxs("div",{className:"run_tree",children:[e.sections.length?null:e.connected?r.jsx("div",{className:"run_tree_empty",children:"No runs match the current filters."}):r.jsxs("div",{className:"run_tree_empty",children:["Gateway offline — runs are unavailable."," ",r.jsx("button",{className:"btn btn_sm",onClick:e.on_sign_in,children:"Sign in"})]}),e.sections.map(a=>r.jsxs("section",{className:"run_tree_section",children:[r.jsxs("div",{className:"run_tree_section_header",children:[r.jsx("span",{children:a.label}),r.jsx("span",{className:"mono",children:a.rows.length})]}),a.rows.map(l=>{const u=l.run,d=String(u.run_id||"").trim(),m=d===t;return r.jsxs("div",{className:"run_tree_group",children:[r.jsxs("button",{className:`run_tree_item ${m?"selected":""} ${d===n?"root_context":""}`,onClick:()=>e.on_select(d,d),title:d,children:[r.jsxs("div",{className:"run_tree_item_top",children:[r.jsx("span",{className:"run_tree_label",children:zp(u,e.workflow_label_by_id,e.automation_titles)}),r.jsx(Fp,{run:u}),u.status?r.jsx(rl,{status:Um(u)}):null]}),r.jsxs("div",{className:"run_tree_meta",children:[r.jsx("span",{className:"mono",children:Et(d,13)}),r.jsx("span",{children:Gl(u)?Ko(Gl(u)):"no start"}),r.jsx("span",{children:rc(u)})]})]}),l.children.length?r.jsx("div",{className:"run_tree_children",children:l.children.map(p=>{const g=String(p.run_id||"").trim();return r.jsxs("button",{className:`run_tree_item run_tree_child ${g===t?"selected":""}`,onClick:()=>e.on_select(g,d),title:g,children:[r.jsxs("div",{className:"run_tree_item_top",children:[r.jsx("span",{className:"run_tree_label",children:zp(p,e.workflow_label_by_id,e.automation_titles)}),r.jsx(Fp,{run:p}),r.jsx(rl,{status:Um(p)})]}),r.jsxs("div",{className:"run_tree_meta",children:[r.jsx("span",{className:"mono",children:Et(g,13)}),r.jsx("span",{children:Gl(p)?Ko(Gl(p)):"child"}),r.jsx("span",{children:rc(p)})]})]},g)})}):null]},d)})]},a.key))]})]})}function Bp(){return r.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:r.jsx("path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9L9.2 3.9A2 2 0 0 0 7.5 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"})})}function Ok(e){var R,T,z,H,D,G,Q;const t=e.run_id.trim(),[n,i]=_.useState(!1);if(!t)return r.jsx("div",{className:"run_overview",children:r.jsx("div",{className:"empty_state_inline",style:{padding:"48px 24px",textAlign:"center"},children:"Select a run on the left to inspect it — or start one from Launch."})});const a=hi(e.run,e.workflow_label_by_id),l=Gl(e.run)||String(((R=e.run_state)==null?void 0:R.started_at)||((T=e.run_state)==null?void 0:T.created_at)||"").trim(),u=Gv(e.run)||(yi(e.status_label)?String(((z=e.run_state)==null?void 0:z.updated_at)||"").trim():""),d=e.run?rc(e.run):l?vg((xn(u)??Date.now())-(xn(l)??Date.now())):"—",m=e.provider_activities.length,p=e.provider_activities.reduce((Y,ee)=>Y+(Number(ee.tokens.total)||0),0),g=e.provider_activities.filter(Y=>Y.missing_response||Y.error).length,v=String(((H=e.latest_summary)==null?void 0:H.text)||"").trim(),w=e.wait_state,x=yi(e.status_label),N=Wm(e.run)||String(((D=e.run_state)==null?void 0:D.error)||"").trim();let S="";for(let Y=e.records.length-1;Y>=0;Y--){const ee=ef((G=e.records[Y])==null?void 0:G.record);if(ee){S=ee;break}}return r.jsxs("div",{className:"run_overview",children:[r.jsxs("section",{className:"run_hero run_hero_line",children:[r.jsx("h2",{className:"run_hero_title",title:a,children:a}),r.jsx(rl,{status:e.status_label}),t?r.jsx("span",{className:"chip mono muted",title:t,children:Et(t,18)}):null,e.root_run_id&&e.root_run_id!==t?r.jsxs("span",{className:"chip mono muted",title:e.root_run_id,children:["root ",Et(e.root_run_id,12)]}):null,r.jsx("span",{className:"run_hero_spacer"}),e.workspace_root?r.jsxs("button",{className:"btn btn_icon",onClick:e.on_reveal_workspace,title:`Open the run's workspace folder
|
|
103
|
+
${e.workspace_root}`,children:[r.jsx(Bp,{}),"Folder"]}):null,r.jsx("button",{className:"btn",onClick:e.on_generate_summary,disabled:!t||e.summary_generating,children:e.summary_generating?"Summarizing…":v?"Refresh summary":"Summarize"}),r.jsx("button",{className:"btn",onClick:e.on_open_runtime,title:"Open this run's artifacts in the System explorer",children:"Run artifacts"})]}),x?r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Outcome"}),r.jsx("span",{className:`chip mono ${nl(e.status_label)}`,children:e.status_label||(N?"failed":"completed")})]}),N?r.jsx("div",{className:"error_callout",children:N}):null,S?r.jsx(pi,{text:ut(S,{max_chars:4e3,max_lines:60})}):null,!N&&!S?r.jsx("div",{className:"empty_state_inline",children:"No final text output was recorded for this run — produced files, if any, live under Run artifacts (above)."}):null]}):null,(()=>{const Y=Array.isArray(e.run_artifacts)?e.run_artifacts:[],ee=C=>{const k=String((C!=null&&C.tags&&typeof C.tags=="object"?C.tags.source:"")||"").trim();return k==="run_store_offload"||k==="node_trace_offload"},ae=C=>{const k=C!=null&&C.tags&&typeof C.tags=="object"?C.tags:{},I=String((C==null?void 0:C.filename)||k.filename||"").trim();if(I)return I;const P=String(k.path||(C==null?void 0:C.source_path)||"").trim();return P?P.split("/").pop()||P:String((C==null?void 0:C.title)||"").trim()||String((C==null?void 0:C.artifact_id)||"").slice(0,14)},le=C=>{var k;return r.jsxs("div",{className:"run_artifact_row",children:[r.jsx("span",{className:"run_artifact_name",title:String(((k=C==null?void 0:C.tags)==null?void 0:k.path)||(C==null?void 0:C.source_path)||(C==null?void 0:C.artifact_id)||""),children:ae(C)}),r.jsx("span",{className:"chip mono muted",children:String((C==null?void 0:C.content_type)||"?").replace(/^application\//,"").replace(/^text\//,"")}),r.jsx("span",{className:"run_artifact_size",children:typeof(C==null?void 0:C.size_bytes)=="number"?`${(C.size_bytes/1024).toFixed(C.size_bytes>1e5?0:1)} kB`:""}),r.jsxs("span",{className:"run_artifact_actions",children:[r.jsx("button",{className:"btn",onClick:()=>e.on_preview_run_artifact(C),children:"Preview"}),r.jsx("button",{className:"btn",onClick:()=>e.on_download_run_artifact(C),children:"Download"})]})]},String((C==null?void 0:C.artifact_id)||Math.random()))},ge=Y.filter(C=>!ee(C)),F=Y.filter(ee);return r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Artifacts"}),r.jsx("span",{className:"mono muted",children:Y.length?Y.length.toLocaleString():""}),e.workspace_root?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"pane_spacer"}),r.jsxs("button",{className:"btn btn_icon",onClick:e.on_reveal_workspace,title:`Open the run's workspace folder
|
|
104
|
+
${e.workspace_root}`,children:[r.jsx(Bp,{}),"Workspace"]})]}):null]}),e.run_artifacts_error?r.jsx("div",{className:"warn_callout",children:e.run_artifacts_error}):null,e.run_artifacts_loading&&!Y.length?r.jsx("div",{className:"empty_state_inline",children:"Loading artifacts…"}):null,!e.run_artifacts_loading&&!Y.length&&!e.run_artifacts_error?r.jsxs("div",{className:"empty_state_inline",children:["The runtime recorded no durable artifacts for this run.",e.workspace_root?" Files written to the workspace folder (if any) are reachable via the Folder button.":""]}):null,ge.length?r.jsx("div",{className:"run_artifact_list",children:ge.map(le)}):null,!ge.length&&Y.length?r.jsxs("div",{className:"empty_state_inline",children:["No file products — this run's durable artifacts are internal state offloads (below).",e.workspace_root?" Report files written to the workspace are reachable via the Folder button.":""]}):null,F.length?r.jsxs("details",{className:"runtime_raw_details",children:[r.jsxs("summary",{className:"muted",children:["Internal state offloads (",F.length,")"]}),r.jsx("div",{className:"run_artifact_list",children:F.map(le)})]}):null]})})(),r.jsxs("div",{className:"metric_grid",children:[r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Started"}),r.jsx("strong",{children:Xo(l)})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:u?"Finished":"Running for"}),r.jsx("strong",{children:u?Xo(u):d})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Total duration"}),r.jsx("strong",{children:d})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Ledger"}),r.jsx("strong",{children:(e.records_count+e.child_records_count).toLocaleString()})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Subworkflows"}),r.jsx("strong",{children:e.subrun_ids.length.toLocaleString()})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Provider calls"}),r.jsx("strong",{children:m.toLocaleString()})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Tokens"}),r.jsx("strong",{children:p?p.toLocaleString():"—"})]}),r.jsxs("div",{className:"metric_tile",children:[r.jsx("span",{children:"Assets"}),r.jsx("strong",{children:e.attachments_count.toLocaleString()})]})]}),r.jsxs("div",{className:"overview_columns",children:[r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:x?"What happened":"What is happening"}),w?r.jsx("span",{className:"chip mono info",children:"waiting"}):null]}),w?r.jsxs("div",{className:"overview_fact_list",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Reason"}),r.jsx("strong",{children:String(w.reason||"unknown")})]}),w.wait_key?r.jsxs("div",{children:[r.jsx("span",{children:"Wait key"}),r.jsx("strong",{className:"mono",children:Et(String(w.wait_key),34)})]}):null,(Q=w==null?void 0:w.details)!=null&&Q.sub_run_id?r.jsxs("div",{children:[r.jsx("span",{children:"Subworkflow"}),r.jsx("strong",{className:"mono",children:Et(String(w.details.sub_run_id),24)})]}):null,w.prompt?r.jsxs("div",{children:[r.jsx("span",{children:"Prompt"}),r.jsx("strong",{children:ut(String(w.prompt),{max_chars:260,max_lines:3})})]}):null,e.on_answer_wait&&w.wait_key&&String(w.reason||"")==="user"?r.jsx("div",{className:"overview_fact_actions",children:r.jsx("button",{className:"btn primary",onClick:e.on_answer_wait,children:"Review & answer…"})}):null]}):(()=>{var C;const Y=e.timeline_items.length?e.timeline_items[e.timeline_items.length-1]:null,ee=(Y==null?void 0:Y.record)||null,ae=String((ee==null?void 0:ee.node_id)||"").trim(),le=ae&&e.node_index?e.node_index[ae]:null,ge=String((le==null?void 0:le.label)||ae||"").trim(),F=String(((C=ee==null?void 0:ee.effect)==null?void 0:C.type)||"").trim();return ge||F?r.jsxs("div",{className:"overview_fact_list",children:[ge?r.jsxs("div",{children:[r.jsx("span",{children:x?"Ended at":"Last step"}),r.jsx("strong",{children:ge})]}):null,F?r.jsxs("div",{children:[r.jsx("span",{children:"Effect"}),r.jsx("strong",{className:"mono",children:F})]}):null]}):r.jsx("div",{className:"empty_state_inline",children:x?"Nothing in flight — the run is finished.":"No active wait is reported for this run."})})(),g?r.jsxs("div",{className:"warn_callout",children:[g," provider call(s) have missing responses or errors."]}):null]}),r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Summary"}),e.latest_summary?r.jsx("span",{className:"chip mono ok",children:"saved"}):r.jsx("span",{className:"chip mono muted",children:"none"})]}),e.summary_error?r.jsx("div",{className:"warn_callout",children:e.summary_error}):null,v?r.jsx(pi,{text:v}):r.jsx("div",{className:"empty_state_inline",children:"Generate a grounded summary from the root run and its subflows."})]})]}),e.subrun_ids.length?r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Subworkflows"}),r.jsx("span",{className:"mono muted",children:e.subrun_ids.length})]}),r.jsx("div",{className:"subrun_chip_list",children:e.subrun_ids.map(Y=>r.jsx("button",{className:"subrun_chip mono",onClick:()=>e.on_open_subrun(Y),title:Y,children:Et(Y,22)},Y))})]}):null,e.attachments.length||e.session_id?r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Session files"}),r.jsx("span",{className:"mono muted",children:e.attachments.length?`${e.attachments.length} file${e.attachments.length===1?"":"s"}`:""}),r.jsx("button",{className:"btn btn_sm",onClick:e.on_refresh_attachments,disabled:e.attachments_loading||!e.session_id,children:e.attachments_loading?"Refreshing…":"Refresh"})]}),e.attachments_error?r.jsx("div",{className:"warn_callout",children:e.attachments_error}):null,e.attachments.length?r.jsx("div",{className:"produced_list",children:e.attachments.map(Y=>{const ee=String((Y==null?void 0:Y.artifact_id)||"").trim();if(!ee)return null;const ae=Y!=null&&Y.tags&&typeof Y.tags=="object"?Y.tags:{},le=String((ae==null?void 0:ae.path)||"").trim()?`@${String(ae.path).trim()}`:String((ae==null?void 0:ae.filename)||"").trim()||ee,ge=typeof(Y==null?void 0:Y.size_bytes)=="number"?Number(Y.size_bytes):null,F=e.attachments_loading||!e.attachments_ready;return r.jsxs("div",{className:"produced_row",children:[r.jsx("span",{className:"produced_name mono",title:ee,children:le}),r.jsx("span",{className:"mono muted",children:ge!==null?`${ge.toLocaleString()} B`:""}),r.jsxs("span",{className:"produced_actions",children:[r.jsx("button",{className:"btn btn_sm",onClick:()=>e.on_preview_attachment(Y),disabled:F,children:"Preview"}),r.jsx("button",{className:"btn btn_sm",onClick:()=>e.on_download_attachment(Y),disabled:F,children:"Download"})]})]},ee)})}):r.jsx("div",{className:"empty_state_inline",children:x?"No files were attached to this run's session.":"No files in this run's session yet."})]}):null,e.timeline_items.length?r.jsxs("section",{className:"overview_panel",children:[r.jsxs("div",{className:"overview_panel_header",children:[r.jsx("h3",{children:"Chronology"}),r.jsx("span",{className:"mono muted",children:n||e.timeline_items.length<=hm?`${e.timeline_items.length} steps`:`last ${hm} of ${e.timeline_items.length} steps`}),e.timeline_items.length>hm?r.jsx("button",{className:"btn btn_sm",onClick:()=>i(Y=>!Y),children:n?"Show fewer":"Show all"}):null]}),r.jsx(Pk,{items:n?e.timeline_items:e.timeline_items.slice(-hm),node_index:e.node_index,workflow_label_by_id:e.workflow_label_by_id,on_copy:e.on_copy})]}):null]})}function Pk(e){const t=n=>{var T,z;const i=n,a=n.record||{},l=String(((T=a==null?void 0:a.effect)==null?void 0:T.type)||i.effect_type||"").trim(),u=String((a==null?void 0:a.status)||i.status||"").trim(),d=String((a==null?void 0:a.node_id)||i.node_id||"").trim(),m=d&&e.node_index?e.node_index[d]:null,p=String((m==null?void 0:m.label)||d||i.title||"Step").trim(),g=Bi(a),v=(z=a==null?void 0:a.effect)==null?void 0:z.payload,w=a==null?void 0:a.result,x=ef(a),N=l?Tr(v??{},900):ut(String(i.preview||""),{max_chars:900,max_lines:8}),S=x||(g?`Waiting for ${String(g.reason||"input")}${g.wait_key?` (${Et(String(g.wait_key),18)})`:""}`:"")||(w!==void 0?Tr(w,900):"");return{title:l==="llm_call"?"Model call":l==="tool_calls"?"Tool execution":l==="answer_user"?"User-facing response":l==="start_subworkflow"?"Subworkflow launched":l==="ask_user"?"User input requested":l||i.title||"Ledger event",subtitle:p,request:ut(N,{max_chars:900,max_lines:7}),outcome:ut(S,{max_chars:1100,max_lines:9}),cls:nl(u)}};return r.jsxs("div",{className:"human_timeline",children:[e.items.length?null:r.jsx("div",{className:"empty_state_inline",children:"No ledger records yet."}),e.items.map(n=>{const i=n.record||{},a=t(n),l=String(i.ended_at||i.started_at||n.ts||"").trim();return r.jsxs("article",{className:`timeline_event ${a.cls}`,children:[r.jsx("div",{className:"timeline_marker"}),r.jsxs("div",{className:"timeline_event_body",children:[r.jsxs("div",{className:"timeline_event_header",children:[r.jsxs("div",{children:[r.jsx("h3",{children:a.title}),r.jsxs("div",{className:"timeline_subtitle",children:[r.jsx("span",{children:a.subtitle}),n.run_id?r.jsx("span",{className:"mono",children:Et(String(n.run_id),13)}):null]})]}),r.jsxs("div",{className:"timeline_time",children:[r.jsx("span",{children:Ko(l)}),r.jsx("span",{className:"mono",title:l,children:Xo(l)})]})]}),r.jsxs("div",{className:"timeline_payload_grid",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Requested"}),r.jsx("p",{className:"mono",children:a.request||"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Outcome"}),r.jsx("p",{children:a.outcome||"—"})]})]}),r.jsx("div",{className:"timeline_actions",children:r.jsxs("button",{className:"btn btn_icon",onClick:()=>e.on_copy(JSON.stringify(i,null,2)),children:[r.jsx(Nn,{name:"copy",size:14}),"JSON"]})})]})]},`${String(n.run_id||i.run_id||"")}:${n.cursor}`)})]})}function Ik(e){const t=e.item,n=String(t.node_id||"").trim(),i=n&&e.node_index&&typeof e.node_index=="object"?e.node_index[n]:null,a=typeof(i==null?void 0:i.label)=="string"&&i.label.trim()?i.label.trim():n||t.title,l=typeof(i==null?void 0:i.type)=="string"&&i.type.trim()?i.type.trim():"",u=typeof(i==null?void 0:i.headerColor)=="string"&&i.headerColor.trim()?i.headerColor.trim():"",d=t.kind==="step"?a:t.title,m=u||(t.kind==="error"?"rgba(239, 68, 68, 0.85)":t.kind==="message"?"rgba(167, 139, 250, 0.85)":t.kind==="event"?"rgba(96, 165, 250, 0.85)":t.status==="waiting"?"rgba(96, 165, 250, 0.65)":t.status==="completed"?"rgba(34, 197, 94, 0.65)":"rgba(255, 255, 255, 0.14)"),p=String(t.status||"").trim(),g=p.toLowerCase(),v=nl(g),w=ef(t.data),x=!!(w&&w.trim()),N=Ko(t.ts);return r.jsxs("div",{className:`lc ${v}`,style:{"--lc-accent":m},children:[r.jsxs("div",{className:"lc_header",children:[r.jsx("span",{className:"lc_title",children:d}),r.jsxs("div",{className:"lc_header_right",children:[p?r.jsx("span",{className:`lc_status ${v}`,children:p}):null,r.jsx("span",{className:"lc_time",title:t.ts,children:N})]})]}),r.jsxs("div",{className:"lc_meta",children:[l?r.jsx("span",{className:"lc_chip",children:l}):null,t.effect_type?r.jsx("span",{className:"lc_chip",children:String(t.effect_type)}):null,t.cursor?r.jsxs("span",{className:"lc_chip",children:["#",t.cursor]}):null,t.run_id?r.jsx("span",{className:"lc_chip",children:Et(String(t.run_id),10)}):null,t.kind!=="step"&&n?r.jsx("span",{className:"lc_chip",children:n}):null]}),t.preview?r.jsx("div",{className:"lc_preview",children:t.preview}):null,t.data?r.jsxs("div",{className:"lc_actions",children:[x?r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"lc_btn",onClick:e.on_toggle_response,children:e.response_open?"Fold Response":"Unfold Response"}),r.jsx("button",{className:"lc_btn",onClick:()=>e.on_copy(String(w||"")),children:"Copy Response"})]}):null,r.jsx("button",{className:"lc_btn",onClick:e.on_toggle,children:e.open?"Fold JSON":"Unfold JSON"}),r.jsx("button",{className:"lc_btn",onClick:()=>{try{e.on_copy(JSON.stringify(t.data,null,2))}catch{e.on_copy(String(t.data))}},children:"Copy JSON"})]}):null,e.response_open&&x?r.jsx("div",{className:"lc_body",children:r.jsx(pi,{text:String(w||"")})}):null,e.open&&t.data?r.jsx("div",{className:"lc_body lc_body_json mono",children:r.jsx(ps,{value:t.data,collapseAfterDepth:3,showCopy:!1})}):null]})}class Dk{constructor(){hs(this,"_buffer","");hs(this,"_current",{data_lines:[]})}push(t,n){for(this._buffer+=t;;){const i=this._buffer.indexOf(`
|
|
105
|
+
`);if(i===-1)return;const a=this._buffer.slice(0,i);this._buffer=this._buffer.slice(i+1);const l=a.endsWith("\r")?a.slice(0,-1):a;if(l.startsWith(":"))continue;if(l===""){if(this._current.data_lines.length>0||this._current.event||this._current.id){const p={id:this._current.id,event:this._current.event,data:this._current.data_lines.join(`
|
|
106
|
+
`)};n(p)}this._current={data_lines:[]};continue}const u=l.indexOf(":"),d=u===-1?l:l.slice(0,u),m=u===-1?"":l.slice(u+1).trimStart();if(d==="id"){this._current.id=m;continue}if(d==="event"){this._current.event=m;continue}if(d==="data"){this._current.data_lines.push(m);continue}}}}function zt(e,t){const n=(e||"").trim().replace(/\/+$/,"");return n?`${n}${t}`:t}function mi(e,t=3e4){const n=AbortSignal.timeout(t);if(!e)return n;const i=AbortSignal.any;return typeof i=="function"?i([e,n]):e}function Pt(e){var i;const t=(e||"").trim(),n={};t&&(n.Authorization=`Bearer ${t}`);try{const a=(i=document.cookie.split(";").map(l=>l.trim()).find(l=>l.startsWith("abstractobserver_gateway_csrf=")))==null?void 0:i.slice(30);a&&(n["X-AbstractObserver-CSRF"]=decodeURIComponent(a))}catch{}return n}async function Wn(e){try{const t=await e.text();return t!=null&&t.trim()?t.trim():`${e.status}`}catch{return`${e.status}`}}class s_{constructor(t){hs(this,"_cfg");this._cfg={...t,base_url:(t.base_url||"").trim()}}async start_run(t,n,i){const a=String((i==null?void 0:i.bundle_id)||"").trim(),l=(i==null?void 0:i.session_id)===null||(i==null?void 0:i.session_id)===void 0?"":String(i.session_id||"").trim(),u=String(t||"").trim(),d=String((i==null?void 0:i.interface)||"").trim();if(u==="@default"&&(!d||a))throw new Error("start_run: flow_id '@default' needs `interface` and no bundle_id");const m={input_data:n||{}};a&&(m.bundle_id=a),u&&(m.flow_id=u),u==="@default"&&(m.interface=d),l&&(m.session_id=l);const p=await fetch(zt(this._cfg.base_url,"/api/gateway/runs/start"),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(m)});if(!p.ok)throw new Error(`start_run failed: ${p.status}`);const g=await p.json(),v=g==null?void 0:g.run_id;if(typeof v!="string"||!v)throw new Error("start_run: missing run_id");return v}async list_mcp_servers(){for(const t of["/api/gateway/mcp/servers","/api/gateway/mcp","/api/gateway/discovery/mcp"])try{const n=await fetch(zt(this._cfg.base_url,t),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(n.status===404||!n.ok)continue;const i=await n.json(),a=Array.isArray(i)?i:Array.isArray(i==null?void 0:i.servers)?i.servers:Array.isArray(i==null?void 0:i.items)?i.items:null;if(!a)continue;return a.map(l=>({name:String((l==null?void 0:l.name)||(l==null?void 0:l.id)||"").trim(),url:typeof(l==null?void 0:l.url)=="string"?l.url:void 0,description:typeof(l==null?void 0:l.description)=="string"?l.description:void 0,auth_required:typeof(l==null?void 0:l.auth_required)=="boolean"?l.auth_required:void 0})).filter(l=>l.name)}catch{return null}return null}async list_skills(){for(const t of["/api/gateway/skills","/api/gateway/skills/registry"])try{const n=await fetch(zt(this._cfg.base_url,t),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(n.status===404||!n.ok)continue;const i=await n.json(),a=Array.isArray(i)?i:Array.isArray(i==null?void 0:i.skills)?i.skills:Array.isArray(i==null?void 0:i.items)?i.items:null;if(!a)continue;return a.map(l=>({name:String((l==null?void 0:l.name)||(l==null?void 0:l.id)||"").trim(),description:typeof(l==null?void 0:l.description)=="string"?l.description:void 0,version:typeof(l==null?void 0:l.version)=="string"?l.version:void 0,trust_level:typeof(l==null?void 0:l.trust_level)=="string"?l.trust_level:void 0,blocked:typeof(l==null?void 0:l.blocked)=="boolean"?l.blocked:void 0,requires_review:typeof(l==null?void 0:l.requires_review)=="boolean"?l.requires_review:void 0,tree_hash:typeof(l==null?void 0:l.tree_hash)=="string"?l.tree_hash:void 0,reasons:Array.isArray(l==null?void 0:l.reasons)?l.reasons.map(u=>String(u||"")).filter(Boolean):void 0})).filter(l=>l.name)}catch{return null}return null}async get_run(t){const n=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(t)}`),{headers:{...Pt(this._cfg.auth_token)}});if(!n.ok)throw new Error(`get_run failed: ${await Wn(n)}`);return await n.json()}async get_run_history_bundle(t,n){const i=String(t||"").trim();if(!i)throw new Error("get_run_history_bundle: run_id is required");const a=new URLSearchParams;(n==null?void 0:n.include_subruns)===!1&&a.set("include_subruns","false"),(n==null?void 0:n.include_session)===!0&&a.set("include_session","true"),typeof(n==null?void 0:n.session_turn_limit)=="number"&&Number.isFinite(n.session_turn_limit)&&a.set("session_turn_limit",String(Math.max(1,Math.trunc(n.session_turn_limit)))),n!=null&&n.ledger_mode&&a.set("ledger_mode",String(n.ledger_mode)),typeof(n==null?void 0:n.ledger_max_items)=="number"&&Number.isFinite(n.ledger_max_items)&&a.set("ledger_max_items",String(Math.max(0,Math.trunc(n.ledger_max_items))));const l=zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/history_bundle?${a.toString()}`),u=await fetch(l,{headers:{...Pt(this._cfg.auth_token)}});if(!u.ok)throw new Error(`get_run_history_bundle failed: ${await Wn(u)}`);return await u.json()}async list_runs(t){const n=typeof(t==null?void 0:t.limit)=="number"?t.limit:50,i=String((t==null?void 0:t.status)||"").trim(),a=String((t==null?void 0:t.workflow_id)||"").trim(),l=String((t==null?void 0:t.session_id)||"").trim(),u=(t==null?void 0:t.root_only)===!0,d=new URLSearchParams;d.set("limit",String(n)),i&&d.set("status",i),a&&d.set("workflow_id",a),l&&d.set("session_id",l),u&&d.set("root_only","true"),typeof(t==null?void 0:t.include_ledger_len)=="boolean"&&d.set("include_ledger_len",String(t.include_ledger_len)),typeof(t==null?void 0:t.include_metrics)=="boolean"&&d.set("include_metrics",String(t.include_metrics)),typeof(t==null?void 0:t.include_drafts)=="boolean"&&d.set("include_drafts",String(t.include_drafts));const m=zt(this._cfg.base_url,`/api/gateway/runs?${d.toString()}`),p=await fetch(m,{headers:{...Pt(this._cfg.auth_token)},signal:AbortSignal.timeout(3e4)});if(!p.ok)throw new Error(`list_runs failed: ${await Wn(p)}`);return await p.json()}async audit_log_tail(t){const n=typeof(t==null?void 0:t.max_bytes)=="number"?Math.max(1024,Math.min(4e5,Math.floor(t.max_bytes))):8e4,i=zt(this._cfg.base_url,`/api/gateway/audit/tail?max_bytes=${encodeURIComponent(String(n))}`),a=await fetch(i,{headers:{...Pt(this._cfg.auth_token)}});if(!a.ok)throw new Error(`audit_log_tail failed: ${await Wn(a)}`);return await a.json()}async gateway_about(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/about"),{headers:{...Pt(this._cfg.auth_token)},signal:mi(void 0,1e4)});if(!t.ok)throw new Error(`HTTP ${t.status}`);return await t.json()}async get_run_input_data(t){const n=String(t||"").trim();if(!n)throw new Error("get_run_input_data: run_id is required");const i=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(n)}/input_data`),{headers:{...Pt(this._cfg.auth_token)}});if(!i.ok)throw new Error(`get_run_input_data failed: ${await Wn(i)}`);return await i.json()}async list_run_artifacts(t,n){const i=String(t||"").trim();if(!i)throw new Error("list_run_artifacts: run_id is required");const a=typeof(n==null?void 0:n.limit)=="number"?n.limit:200,l=typeof(n==null?void 0:n.offset)=="number"?Math.max(0,Math.floor(n.offset)):0,u=zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/artifacts?limit=${encodeURIComponent(String(a))}&offset=${encodeURIComponent(String(l))}`),d=await fetch(u,{headers:{...Pt(this._cfg.auth_token)}});if(!d.ok)throw new Error(`list_run_artifacts failed: ${await Wn(d)}`);return await d.json()}async list_session_artifacts(t,n){const i=String(t||"").trim();if(!i)throw new Error("list_session_artifacts: session_id is required");const a=typeof(n==null?void 0:n.limit)=="number"?n.limit:200,l=typeof(n==null?void 0:n.offset)=="number"?Math.max(0,Math.floor(n.offset)):0,u=zt(this._cfg.base_url,`/api/gateway/sessions/${encodeURIComponent(i)}/artifacts?limit=${encodeURIComponent(String(a))}&offset=${encodeURIComponent(String(l))}`),d=await fetch(u,{headers:{...Pt(this._cfg.auth_token)}});if(!d.ok)throw new Error(`list_session_artifacts failed: ${await Wn(d)}`);return await d.json()}async search_artifacts(t){const n=new URLSearchParams;n.set("scope",String((t==null?void 0:t.scope)||"all").trim()||"all");const i=String((t==null?void 0:t.session_id)||"").trim(),a=String((t==null?void 0:t.run_id)||"").trim(),l=String((t==null?void 0:t.modality)||"").trim(),u=String((t==null?void 0:t.artifact_kind)||"").trim(),d=String((t==null?void 0:t.semantic_kind)||"").trim(),m=String((t==null?void 0:t.render_kind)||"").trim(),p=String((t==null?void 0:t.workflow_id)||"").trim(),g=String((t==null?void 0:t.node_id)||"").trim(),v=String((t==null?void 0:t.content_type)||"").trim(),w=String((t==null?void 0:t.query)||"").trim(),x=String((t==null?void 0:t.tags)||"").trim(),N=String((t==null?void 0:t.cursor)||"").trim(),S=String((t==null?void 0:t.order_by)||"").trim(),R=String((t==null?void 0:t.order)||"").trim(),T=String((t==null?void 0:t.created_after)||"").trim(),z=String((t==null?void 0:t.created_before)||"").trim(),H=typeof(t==null?void 0:t.limit)=="number"?t.limit:500,D=typeof(t==null?void 0:t.offset)=="number"?Math.max(0,Math.floor(t.offset)):0;i&&n.set("session_id",i),a&&n.set("run_id",a),l&&n.set("modality",l),u&&n.set("artifact_kind",u),d&&n.set("semantic_kind",d),m&&n.set("render_kind",m),p&&n.set("workflow_id",p),g&&n.set("node_id",g),v&&n.set("content_type",v),w&&n.set("query",w),x&&n.set("tags",x),N&&n.set("cursor",N),S&&n.set("order_by",S),R&&n.set("order",R),T&&n.set("created_after",T),z&&n.set("created_before",z),t!=null&&t.include_stats&&n.set("include_stats","true"),n.set("limit",String(H)),n.set("offset",String(D));const G=await fetch(zt(this._cfg.base_url,`/api/gateway/artifacts/search?${n.toString()}`),{headers:{...Pt(this._cfg.auth_token)}});if(!G.ok)throw new Error(`search_artifacts failed: ${await Wn(G)}`);return await G.json()}async artifact_stats(t){const n=new URLSearchParams;n.set("scope",String((t==null?void 0:t.scope)||"all").trim()||"all");for(const a of["session_id","run_id","modality","semantic_kind","render_kind","workflow_id","node_id","content_type","query","tags","created_after","created_before"]){const l=String((t==null?void 0:t[a])||"").trim();l&&n.set(a,l)}const i=await fetch(zt(this._cfg.base_url,`/api/gateway/artifacts/stats?${n.toString()}`),{headers:{...Pt(this._cfg.auth_token)}});if(!i.ok)throw new Error(`artifact_stats failed: ${await Wn(i)}`);return await i.json()}async download_run_artifact_content(t,n,i){const a=String(t||"").trim(),l=String(n||"").trim();if(!a)throw new Error("download_run_artifact_content: run_id is required");if(!l)throw new Error("download_run_artifact_content: artifact_id is required");const u=String((i==null?void 0:i.access)||"").trim(),d=u?`?access=${encodeURIComponent(u)}`:"",m=zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(a)}/artifacts/${encodeURIComponent(l)}/content${d}`),p=await fetch(m,{headers:{...Pt(this._cfg.auth_token)}});if(!p.ok)throw new Error(`download_run_artifact_content failed: ${await Wn(p)}`);return await p.blob()}async list_entities(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/entities"),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!t.ok)throw new Error(`list_entities failed: ${await Wn(t)}`);const n=await t.json();return{entities:Array.isArray(n==null?void 0:n.entities)?n.entities:[]}}async get_entity_phases_spec(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/entities/spec/phases"),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!t.ok)throw new Error(`get_entity_phases_spec failed: ${await Wn(t)}`);return await t.json()}async get_entity_cognition(t){const n=await fetch(zt(this._cfg.base_url,`/api/gateway/entities/${encodeURIComponent(t)}/cognition`),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!n.ok)throw new Error(`get_entity_cognition failed: ${await Wn(n)}`);return await n.json()}async get_entity_card(t){const n=String(t||"").trim();if(!n)throw new Error("get_entity_card: name is required");const i=await fetch(zt(this._cfg.base_url,`/api/gateway/entities/${encodeURIComponent(n)}/card`),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!i.ok)throw new Error(`get_entity_card failed: ${await Wn(i)}`);return await i.json()}async read_entity_diary_entry(t,n){const i=String(t||"").trim(),a=String(n||"").trim();if(!i||!a)throw new Error("read_entity_diary_entry: name and entry_id are required");const l=zt(this._cfg.base_url,`/api/gateway/entities/${encodeURIComponent(i)}/diary/${encodeURIComponent(a)}?reason=${encodeURIComponent("observer board hint chip")}`),u=await fetch(l,{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!u.ok)throw new Error(`read_entity_diary_entry failed: ${await Wn(u)}`);return await u.json()}async get_ledger(t,n){const i=Number((n==null?void 0:n.after)||0),a=Number((n==null?void 0:n.limit)||0),l=zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(t)}/ledger?after=${encodeURIComponent(String(i))}&limit=${encodeURIComponent(String(a))}`),u=await fetch(l,{headers:{...Pt(this._cfg.auth_token)},signal:mi(n==null?void 0:n.signal)});if(!u.ok)throw new Error(`get_ledger failed: ${u.status}`);const d=await u.json(),m=Array.isArray(d==null?void 0:d.items)?d.items:[],p=typeof(d==null?void 0:d.next_after)=="number"?d.next_after:i;return{items:m,next_after:p}}async get_ledger_batch(t){const n=Array.isArray(t==null?void 0:t.runs)?t.runs:[],i=Number((t==null?void 0:t.limit)||0),a=await fetch(zt(this._cfg.base_url,"/api/gateway/runs/ledger/batch"),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify({runs:n,limit:i}),signal:mi()});if(!a.ok)throw new Error(`get_ledger_batch failed: ${a.status}`);const l=await a.json(),d=(l&&typeof l=="object"?l:{}).runs;return{runs:d&&typeof d=="object"?d:{}}}async generate_run_summary(t,n){const i=String(t||"").trim();if(!i)throw new Error("generate_run_summary: run_id is required");const a={include_subruns:(n==null?void 0:n.include_subruns)!==!1},l=typeof(n==null?void 0:n.provider)=="string"?String(n.provider).trim():"";l&&(a.provider=l);const u=typeof(n==null?void 0:n.model)=="string"?String(n.model).trim():"";u&&(a.model=u);const d=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/summary`),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(a)});if(!d.ok)throw new Error(`generate_run_summary failed: ${d.status}`);return await d.json()}async run_chat(t,n){const i=String(t||"").trim();if(!i)throw new Error("run_chat: run_id is required");const a={include_subruns:(n==null?void 0:n.include_subruns)!==!1,messages:Array.isArray(n==null?void 0:n.messages)?n.messages:[],persist:!!(n!=null&&n.persist)},l=typeof(n==null?void 0:n.provider)=="string"?String(n.provider).trim():"";l&&(a.provider=l);const u=typeof(n==null?void 0:n.model)=="string"?String(n.model).trim():"";u&&(a.model=u);const d=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/chat`),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(a)});if(!d.ok)throw new Error(`run_chat failed: ${d.status}`);return await d.json()}async audio_transcribe(t,n){const i=String(t||"").trim();if(!i)throw new Error("audio_transcribe: run_id is required");const a=n==null?void 0:n.audio_artifact;if(!a||typeof a!="object")throw new Error("audio_transcribe: audio_artifact is required");if(!String(a.$artifact||"").trim())throw new Error("audio_transcribe: audio_artifact.$artifact is required");const u={audio_artifact:a},d=String((n==null?void 0:n.language)||"").trim();d&&(u.language=d);const m=String((n==null?void 0:n.request_id)||"").trim();m&&(u.request_id=m);const p=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/audio/transcribe`),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(u)});if(!p.ok)throw new Error(`audio_transcribe failed: ${await Wn(p)}`);const g=await p.json(),v=String((g==null?void 0:g.text)||"");return{ok:!!(g!=null&&g.ok),run_id:String((g==null?void 0:g.run_id)||""),request_id:String((g==null?void 0:g.request_id)||""),text:v,transcript_artifact:g==null?void 0:g.transcript_artifact}}async voice_tts(t,n){const i=String(t||"").trim();if(!i)throw new Error("voice_tts: run_id is required");const a=String((n==null?void 0:n.text)||"").trim();if(!a)throw new Error("voice_tts: text is required");const l={text:a},u=String((n==null?void 0:n.voice)||"").trim();u&&(l.voice=u);const d=String((n==null?void 0:n.format)||"").trim();d&&(l.format=d);const m=String((n==null?void 0:n.request_id)||"").trim();m&&(l.request_id=m);const p=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/voice/tts`),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(l)});if(!p.ok)throw new Error(`voice_tts failed: ${await Wn(p)}`);const g=await p.json();return{ok:!!(g!=null&&g.ok),run_id:String((g==null?void 0:g.run_id)||""),request_id:String((g==null?void 0:g.request_id)||""),audio_artifact:g==null?void 0:g.audio_artifact}}async save_chat_thread(t,n){const i=String(t||"").trim();if(!i)throw new Error("save_chat_thread: run_id is required");const a={include_subruns:(n==null?void 0:n.include_subruns)!==!1,messages:Array.isArray(n==null?void 0:n.messages)?n.messages:[]},l=typeof(n==null?void 0:n.provider)=="string"?String(n.provider).trim():"";l&&(a.provider=l);const u=typeof(n==null?void 0:n.model)=="string"?String(n.model).trim():"";u&&(a.model=u);const d=typeof(n==null?void 0:n.title)=="string"?String(n.title).trim():"";d&&(a.title=d);const m=await fetch(zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(i)}/chat_threads`),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(a)});if(!m.ok)throw new Error(`save_chat_thread failed: ${await Wn(m)}`);return await m.json()}async list_bundles(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/bundles"),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!t.ok)throw new Error(`list_bundles failed: ${t.status}`);return await t.json()}async reload_bundles(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/bundles/reload"),{method:"POST",headers:{...Pt(this._cfg.auth_token)}});if(!t.ok)throw new Error(`reload_bundles failed: ${t.status}`);return await t.json()}async upload_bundle(t,n){const i=(n==null?void 0:n.overwrite)===!0,a=(n==null?void 0:n.reload)!==!1,l=new FormData;l.set("overwrite",i?"true":"false"),l.set("reload",a?"true":"false"),l.set("file",t,t.name||"upload.flow");const u=await fetch(zt(this._cfg.base_url,"/api/gateway/bundles/upload"),{method:"POST",headers:{...Pt(this._cfg.auth_token)},body:l});if(!u.ok)throw new Error(`upload_bundle failed: ${await Wn(u)}`);return await u.json()}async attachments_upload(t,n,i){const a=String(t||"").trim();if(!a)throw new Error("attachments_upload: session_id is required");if(!n)throw new Error("attachments_upload: file is required");const l=String((i==null?void 0:i.filename)||"").trim()||String((n==null?void 0:n.name)||"").trim()||"upload.bin",u=String((i==null?void 0:i.content_type)||"").trim()||String((n==null?void 0:n.type)||"").trim(),d=new FormData;d.append("session_id",a),d.append("file",n,l),d.append("filename",l),u&&d.append("content_type",u);const m=await fetch(zt(this._cfg.base_url,"/api/gateway/attachments/upload"),{method:"POST",headers:{...Pt(this._cfg.auth_token)},body:d});if(!m.ok)throw new Error(`attachments_upload failed: ${await Wn(m)}`);const p=await m.json(),g=p==null?void 0:p.attachment;if(!g||typeof g!="object")throw new Error("attachments_upload: missing attachment");if(!String(g.$artifact||"").trim())throw new Error("attachments_upload: missing attachment.$artifact");return g}async remove_bundle(t,n){const i=String(t||"").trim();if(!i)throw new Error("remove_bundle: bundle_id is required");const a=new URLSearchParams,l=String((n==null?void 0:n.bundle_version)||"").trim();l&&a.set("bundle_version",l),a.set("reload",(n==null?void 0:n.reload)===!1?"false":"true");const u=zt(this._cfg.base_url,`/api/gateway/bundles/${encodeURIComponent(i)}?${a.toString()}`),d=await fetch(u,{method:"DELETE",headers:{...Pt(this._cfg.auth_token)}});if(!d.ok)throw new Error(`remove_bundle failed: ${await Wn(d)}`);return await d.json()}async discovery_tools(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/discovery/tools"),{headers:{...Pt(this._cfg.auth_token)}});if(!t.ok)throw new Error(`discovery_tools failed: ${t.status}`);return await t.json()}async discovery_providers(t){const n=(t==null?void 0:t.include_models)===!0,i=zt(this._cfg.base_url,`/api/gateway/discovery/providers?include_models=${encodeURIComponent(String(n))}`),a=await fetch(i,{headers:{...Pt(this._cfg.auth_token)}});if(!a.ok)throw new Error(`discovery_providers failed: ${a.status}`);return await a.json()}async discovery_provider_models(t){const n=String(t||"").trim();if(!n)throw new Error("discovery_provider_models: provider_name is required");const i=await fetch(zt(this._cfg.base_url,`/api/gateway/discovery/providers/${encodeURIComponent(n)}/models`),{headers:{...Pt(this._cfg.auth_token)}});if(!i.ok)throw new Error(`discovery_provider_models failed: ${i.status}`);return await i.json()}async get_bundle(t){const n=String(t||"").trim();if(!n)throw new Error("get_bundle: bundle_id is required");const i=await fetch(zt(this._cfg.base_url,`/api/gateway/bundles/${encodeURIComponent(n)}`),{headers:{...Pt(this._cfg.auth_token)}});if(!i.ok)throw new Error(`get_bundle failed: ${i.status}`);return await i.json()}async get_bundle_flow(t,n){const i=String(t||"").trim(),a=String(n||"").trim();if(!i)throw new Error("get_bundle_flow: bundle_id is required");if(!a)throw new Error("get_bundle_flow: flow_id is required");const l=await fetch(zt(this._cfg.base_url,`/api/gateway/bundles/${encodeURIComponent(i)}/flows/${encodeURIComponent(a)}`),{headers:{...Pt(this._cfg.auth_token)}});if(!l.ok)throw new Error(`get_bundle_flow failed: ${l.status}`);return await l.json()}async get_workflow_flow(t){const n=String(t||"").trim();if(!n)throw new Error("get_workflow_flow: workflow_id is required");const i=await fetch(zt(this._cfg.base_url,`/api/gateway/workflows/${encodeURIComponent(n)}/flow`),{headers:{...Pt(this._cfg.auth_token)}});if(!i.ok)throw new Error(`get_workflow_flow failed: ${i.status}`);return await i.json()}async discovery_capabilities(){const t=await fetch(zt(this._cfg.base_url,"/api/gateway/discovery/capabilities"),{headers:{...Pt(this._cfg.auth_token)},signal:mi()});if(!t.ok)throw new Error(`discovery_capabilities failed: ${await Wn(t)}`);return await t.json()}automations_client(){const t=this._cfg.auth_token;return z0({fetch:(n,i)=>fetch(n,i),baseUrl:this._cfg.base_url,headers:()=>Pt(t)})}async submit_command(t){const n=await fetch(zt(this._cfg.base_url,"/api/gateway/commands"),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(t)});if(!n.ok)throw new Error(`submit_command failed: ${n.status}`);return await n.json()}async kg_query(t){const n=String((t==null?void 0:t.scope)||"session").trim().toLowerCase(),i=String((t==null?void 0:t.order)||"desc").trim().toLowerCase(),a=typeof(t==null?void 0:t.limit)=="number"&&Number.isFinite(t.limit)?Number(t.limit):500,l={scope:n,order:i,limit:a},u=String((t==null?void 0:t.run_id)||"").trim();u&&(l.run_id=u);const d=String((t==null?void 0:t.session_id)||"").trim();d&&(l.session_id=d);const m=String((t==null?void 0:t.owner_id)||"").trim();m&&(l.owner_id=m),t!=null&&t.all_owners&&(l.all_owners=!0);const p=String((t==null?void 0:t.subject)||"").trim();p&&(l.subject=p);const g=String((t==null?void 0:t.predicate)||"").trim();g&&(l.predicate=g);const v=String((t==null?void 0:t.object)||"").trim();v&&(l.object=v);const w=String((t==null?void 0:t.since)||"").trim();w&&(l.since=w);const x=String((t==null?void 0:t.until)||"").trim();x&&(l.until=x);const N=String((t==null?void 0:t.active_at)||"").trim();N&&(l.active_at=N);const S=String((t==null?void 0:t.query_text)||"").trim();S&&(l.query_text=S),typeof(t==null?void 0:t.min_score)=="number"&&Number.isFinite(t.min_score)&&(l.min_score=Number(t.min_score));const R=await fetch(zt(this._cfg.base_url,"/api/gateway/kg/query"),{method:"POST",headers:{"Content-Type":"application/json",...Pt(this._cfg.auth_token)},body:JSON.stringify(l)});if(!R.ok)throw new Error(`kg_query failed: ${await Wn(R)}`);return await R.json()}async stream_ledger(t,n){const i=Number((n==null?void 0:n.after)||0),a=n.on_step,l=n.signal,u=zt(this._cfg.base_url,`/api/gateway/runs/${encodeURIComponent(t)}/ledger/stream?after=${encodeURIComponent(String(i))}`),d=await fetch(u,{headers:{Accept:"text/event-stream",...Pt(this._cfg.auth_token)},signal:l});if(!d.ok)throw new Error(`stream_ledger failed: ${d.status}`);if(!d.body)throw new Error("stream_ledger: response body is missing");const m=d.body.getReader(),p=new TextDecoder("utf-8"),g=new Dk;for(;;){const{value:v,done:w}=await m.read();if(w)return;const x=p.decode(v,{stream:!0});g.push(x,N=>{if(!(N.event!=="step"||!N.data))try{const S=JSON.parse(N.data);S&&typeof S.cursor=="number"&&S.record&&a(S)}catch{}})}}}function zr(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`id_${Date.now()}_${Math.random().toString(16).slice(2)}`}function zk(e){const t=(e||"").trim();return t?{Authorization:`Bearer ${t}`}:{}}class Fk{constructor(t){hs(this,"_cfg");this._cfg={...t,url:(t.url||"").trim()}}async call_tool(t){const n=String((t==null?void 0:t.name)||"").trim(),i=String((t==null?void 0:t.call_id)||(t==null?void 0:t.id)||zr()),a=t!=null&&t.arguments&&typeof t.arguments=="object"?t.arguments:{};if(!n)return{call_id:i,name:"",success:!1,output:null,error:"Missing tool name"};const l={jsonrpc:"2.0",id:zr(),method:"tools/call",params:{name:n,arguments:a}},u=await fetch(this._cfg.url,{method:"POST",headers:{"Content-Type":"application/json",...zk(this._cfg.auth_token)},body:JSON.stringify(l)});if(!u.ok)return{call_id:i,name:n,success:!1,output:null,error:`Worker HTTP ${u.status}`};const d=await u.json().catch(()=>null),m=d==null?void 0:d.result,p=!!(m!=null&&m.isError),v=(Array.isArray(m==null?void 0:m.content)?m.content:[]).find(x=>x&&x.type==="text"&&typeof x.text=="string"),w=(v==null?void 0:v.text)??"";return p?{call_id:i,name:n,success:!1,output:null,error:w||"Tool failed"}:{call_id:i,name:n,success:!0,output:w,error:null}}}class Up{constructor(t,n){hs(this,"pending",[]);hs(this,"scheduled",!1);hs(this,"generation",0);this.schedule=t,this.on_flush=n}push(t){if(this.pending.push(t),this.scheduled)return;this.scheduled=!0;const n=this.generation;this.schedule(()=>{if(n!==this.generation)return;this.scheduled=!1;const i=this.pending;this.pending=[],i.length&&this.on_flush(i)})}reset(){this.generation+=1,this.pending=[],this.scheduled=!1}pending_count(){return this.pending.length}}function Wp(e,t=""){const n=String(e.role||"").trim(),i=String(e.automation_id||"").trim();return n==="occurrence"&&i&&i!==e.run_id?i:String(e.parent_run_id||t||"").trim()}function Bk(e,t){const n=xn(e.updated_at||e.created_at)??0;return(xn(t.updated_at||t.created_at)??0)-n}function Uk(e,t){const n=t.query.trim().toLowerCase(),i=[...e],a={};for(const w of i){const x=String(w.run_id||"").trim();x&&(a[x]=w)}for(const w of e){const x=Wp(w);if(String(w.role||"")==="occurrence"&&x&&!a[x]){const N={run_id:x,workflow_id:null,status:"",role:"controller",session_kind:"automation",automation_id:x,updated_at:w.updated_at??null,created_at:w.created_at??null};a[x]=N,i.push(N)}}const l={},u={};for(const w of i){const x=String(w.run_id||"").trim();if(!x)continue;const N=Wp(w,t.parent_hint?t.parent_hint(x):"");u[x]=N,N&&(l[N]||(l[N]=[])).push(w)}const d=w=>{const x=String(w.status||"").trim().toLowerCase();return t.filter==="all"?!0:t.filter==="active"?du(x):t.filter==="waiting"?x==="waiting":t.filter==="terminal"?yi(x):t.filter==="failed"?x==="failed":!0},m=w=>{if(!n)return!0;const x=String(w.workflow_id||w.schedule_target_workflow_id||"").trim(),N=x?t.workflow_label_by_id[x]||x:"";return[w.run_id,x,N,w.session_id,w.status,w.session_kind,w.automation_id].join(" ").toLowerCase().includes(n)},p=[];for(const w of i){const x=String(w.run_id||"").trim();if(!x)continue;const N=u[x];(!N||!a[N])&&p.push(x)}const g={},v=w=>{if(t.group_by==="workflow"){const N=String(w.schedule_target_workflow_id||w.workflow_id||"").trim()||"(unknown workflow)";return{key:N,label:t.workflow_label_by_id[N]||N}}if(t.group_by==="session"){const N=String(w.session_id||"").trim()||"(no session)";return{key:N,label:N}}const x=String(w.status||"").trim().toLowerCase()||"unknown";return du(x)?{key:"active",label:"Active"}:x==="failed"?{key:"failed",label:"Failed"}:yi(x)?{key:"finished",label:"Finished"}:{key:x,label:x}};for(const w of p){const x=a[w];if(!x)continue;const N=[...l[w]||[]].sort(Bk),S=N.some(T=>d(T)&&m(T));if(!(d(x)&&m(x))&&!S)continue;const R=v(x);g[R.key]||(g[R.key]={key:R.key,label:R.label,rows:[]}),g[R.key].rows.push({run:x,children:N})}return Object.values(g).sort((w,x)=>{const N={active:0,waiting:1,failed:2,finished:3},S=N[w.key]??10,R=N[x.key]??10;return S!==R?S-R:w.label.localeCompare(x.label)})}const Wk={execution:"#FFFFFF",string:"#FF00FF",number:"#00FF00",boolean:"#FF0000",object:"#00FFFF",array:"#FF8800",tools:"#FF8800",provider:"#00D2FF",model:"#9D4EDD",provider_text:"#00D2FF",model_text:"#9D4EDD",provider_image:"#19D3B8",model_image:"#8B5CF6",provider_voice:"#22D3EE",model_voice:"#A855F7",agent:"#4488FF",any:"#888888"},Hk=[{type:"execution",label:"Execution",shape:"▷",description:"Controls flow order"},{type:"string",label:"String",shape:"●",description:"Text data"},{type:"number",label:"Number",shape:"●",description:"Integer or float"},{type:"boolean",label:"Boolean",shape:"◇",description:"True/False"},{type:"object",label:"Object",shape:"●",description:"JSON objects"},{type:"array",label:"Array",shape:"■",description:"Collections"},{type:"tools",label:"Tools",shape:"■",description:"Tool allowlist (string[])"},{type:"provider_text",label:"Text Provider",shape:"●",description:"Text/LLM provider id/name"},{type:"provider_image",label:"Image Provider",shape:"●",description:"Image-generation provider id"},{type:"provider_voice",label:"Voice Provider",shape:"●",description:"Voice/TTS/STT provider id"},{type:"provider",label:"Provider (legacy)",shape:"●",description:"Legacy unscoped provider id/name"},{type:"model",label:"Model",shape:"●",description:"Model id/name scoped by the selected provider"},{type:"agent",label:"Agent",shape:"⬢",description:"Agent reference"},{type:"any",label:"Any",shape:"●",description:"Accepts any type"}];function qk(){const[e,t]=_.useState(!0);return r.jsxs("div",{className:"pin-legend",children:[r.jsxs("button",{className:"pin-legend-toggle mono",type:"button",onClick:()=>t(n=>!n),title:"Pin Type Legend",children:[e?"?":"×"," Pin Types"]}),e?null:r.jsxs("div",{className:"pin-legend-content",children:[Hk.map(n=>r.jsxs("div",{className:"pin-legend-row",children:[r.jsx("span",{className:"pin-legend-shape",style:{color:Wk[n.type]},children:n.shape}),r.jsx("span",{className:"pin-legend-label mono",children:n.label}),r.jsx("span",{className:"pin-legend-desc mono",children:n.description})]},n.type)),r.jsxs("div",{className:"pin-legend-rules mono",children:[r.jsx("strong",{children:"Connection Rules:"}),r.jsxs("ul",{children:[r.jsx("li",{children:"Execution connects to Execution only"}),r.jsx("li",{children:'"Any" type accepts all data types'}),r.jsx("li",{children:"Same types always compatible"}),r.jsx("li",{children:"Array and Object are interchangeable"}),r.jsx("li",{children:'"Tools" is compatible with Array (specialized string[])'})]})]})]})]})}function rn(e){return typeof e=="string"?e:e==null?"":String(e)}function Hp(e,t){const n=rn(e).trim();return n.length<=t?n:`${n.slice(0,Math.max(0,t-1))}…`}function dw(e){const t=rn(e==null?void 0:e.targetHandle),n=rn(e==null?void 0:e.sourceHandle);return!!(t==="exec-in"||n==="exec-out"||t.includes("exec")||n.includes("exec"))}function fw(e){if(!e||typeof e!="object")return"";const t=e!=null&&e.data&&typeof e.data=="object"?e.data:{};return rn((t==null?void 0:t.nodeType)||(e==null?void 0:e.type)||"").trim()}function mw(e){if(!e||typeof e!="object")return"";const t=e!=null&&e.data&&typeof e.data=="object"?e.data:{},n=(t==null?void 0:t.subflowId)||(t==null?void 0:t.flowId),i=rn(n).trim();if(!i)return"";if(i.includes(":")){const a=i.split(":",2);if(a.length===2&&a[1])return a[1].trim()}return i}function Vk(e){const t=rn(e==null?void 0:e.entryNode).trim();if(t)return t;const n=Array.isArray(e==null?void 0:e.nodes)?e.nodes:[];for(const i of n)if(fw(i)==="on_flow_start"){const a=rn(i==null?void 0:i.id).trim();if(a)return a}return""}function i_(e){const t=e!=null&&e.position&&typeof e.position=="object"?e.position:{},n=typeof t.x=="number"?t.x:0,i=typeof t.y=="number"?t.y:0;return{x:n,y:i}}function Sd(e,t){const n=rn(e).trim(),i=rn(t).trim();return i?n?`${n}::${i}`:i:""}function Gk(e){const t=e.root&&typeof e.root=="object"?e.root:{};if(!e.expand_subflows)return t;const n=[],i=[],a=new Set,l=(u,d,m,p)=>{if(!u||typeof u!="object"||n.length>=e.max_nodes||i.length>=e.max_edges)return;const g=Array.isArray(u.nodes)?u.nodes:[],v=Array.isArray(u.edges)?u.edges:[];for(const w of g){const x=rn(w==null?void 0:w.id).trim();if(!x)continue;const N=Sd(d,x);if(!N||a.has(N))continue;const S=i_(w),R={...w,id:N,position:{x:S.x+m.x,y:S.y+m.y}};if(n.push(R),a.add(N),n.length>=e.max_nodes)break}for(const w of v){if(!dw(w))continue;const x=rn(w==null?void 0:w.source).trim(),N=rn(w==null?void 0:w.target).trim();if(!x||!N)continue;const S=Sd(d,x),R=Sd(d,N);if(!S||!R)continue;const T=rn(w==null?void 0:w.id).trim(),z=T?`${S}->${R}::${T}`:`${S}->${R}`;if(i.push({...w,id:z,source:S,target:R}),i.length>=e.max_edges)break}if(!(p>=e.max_depth))for(const w of g){if(n.length>=e.max_nodes||i.length>=e.max_edges)return;if(fw(w)!=="subflow")continue;const x=mw(w);if(!x)continue;const N=e.flow_by_id[x];if(!N||typeof N!="object")continue;const S=Sd(d,rn(w==null?void 0:w.id));if(!S)continue;const R=Vk(N);if(!R)continue;const z=(Array.isArray(N.nodes)?N.nodes:[]).find(ae=>rn(ae==null?void 0:ae.id).trim()===R)||null;if(!z)continue;const H=i_(w),D=i_(z),Y={x:H.x+m.x+240-D.x,y:H.y+m.y+0-D.y},ee=Sd(S,R);i.push({id:`${S}=>${ee}`,source:S,target:ee,sourceHandle:"exec-out",targetHandle:"exec-in"}),l(N,S,Y,p+1)}};return l(t,"",{x:0,y:0},0),{...t,id:rn(t.id),nodes:n,edges:i}}function Kk(e){const t=rn(e).trim().toLowerCase();return t?!!(t.startsWith("literal")||t.includes("literal")||t==="concat"||t==="join"||t==="cast"||t==="parse_json"||t==="stringify_json"||t==="break_object"||t==="get_property"||t==="set_property"||t.includes("get_property")||t.includes("set_property")||t==="get_variable"||t==="set_variable"||t.includes("get_variable")||t.includes("set_variable")||t==="json_schema"):!1}function Yk(e){const t=e.nodes.filter(l=>e.keep_id(l.id)),n=new Set(t.map(l=>l.id)),i={};for(const l of e.edges)i[l.source]||(i[l.source]=[]),i[l.source].push(l.target);const a=new Map;for(const l of t){const u=new Set,d=(i[l.id]||[]).slice();for(;d.length;){const m=d.pop();if(!m||u.has(m))continue;if(u.add(m),n.has(m)){const g=`${l.id}->${m}`;a.has(g)||a.set(g,{id:g,source:l.id,target:m});continue}const p=i[m]||[];for(const g of p)u.has(g)||d.push(g);if(a.size>=e.max_edges)break}if(a.size>=e.max_edges)break}return{nodes:t,edges:Array.from(a.values())}}function qp(e,t){const a=Math.max(t.w*8,160),l=Math.max(t.h*8,120),u=Math.max(160,Math.min(a,e.w)),d=Math.max(120,Math.min(l,e.h));return{x:e.x,y:e.y,w:u,h:d}}function Xk(e){const t=typeof e.now_ms=="number"?e.now_ms:Date.now(),n=e.flow,i=rn(e.active_node_id),a=e.recent_nodes||{},l=e.visited_nodes||{},u=e.highlight_path===!0,d=typeof e.vertical_compact=="number"?Math.max(.4,Math.min(1,e.vertical_compact)):.78,{nodes:m,edges:p,bounds:g}=_.useMemo(()=>{const L=Gk({root:n||{},flow_by_id:e.flow_by_id||{},expand_subflows:e.expand_subflows===!0,max_depth:3,max_nodes:700,max_edges:900}),O=Array.isArray(L.nodes)?L.nodes:[],q=Array.isArray(L.edges)?L.edges:[];let E=[];for(const $e of O){const Re=rn($e==null?void 0:$e.id).trim();if(!Re)continue;const ot=$e!=null&&$e.position&&typeof $e.position=="object"?$e.position:{},he=typeof ot.x=="number"?ot.x:0,Pe=typeof ot.y=="number"?ot.y:0,Ve=$e!=null&&$e.data&&typeof $e.data=="object"?$e.data:{},Rt=rn((Ve==null?void 0:Ve.label)||($e==null?void 0:$e.label)||Re)||Re,Xt=rn((Ve==null?void 0:Ve.nodeType)||($e==null?void 0:$e.type)||"unknown")||"unknown",fn=rn((Ve==null?void 0:Ve.headerColor)||($e==null?void 0:$e.headerColor)||"")||"",Ft=Ve!=null&&Ve.eventConfig&&typeof Ve.eventConfig=="object"?Ve.eventConfig:null,At=Ft&&typeof Ft.schedule=="string"?rn(Ft.schedule).trim():"",sn=Ft&&typeof Ft.recurrent=="boolean"?!!Ft.recurrent:void 0,zn=Xt==="subflow"?mw($e):"",$t=At||sn!==void 0||zn?{schedule:At||void 0,recurrent:sn,subflow_id:zn||void 0}:void 0;E.push({id:Re,x:he,y:Pe,label:Rt,type:Xt,color:fn,meta:$t})}const X={};for(const $e of E)X[$e.id]=$e;let ne=[];for(const $e of q){if(!dw($e))continue;const Re=rn($e==null?void 0:$e.source).trim(),ot=rn($e==null?void 0:$e.target).trim();!Re||!ot||ne.push({id:rn(($e==null?void 0:$e.id)||`${Re}->${ot}`),source:Re,target:ot})}const ie=new Set(E.map($e=>$e.id));if(ne=ne.filter($e=>ie.has($e.source)&&ie.has($e.target)),e.simplify===!0){const Re=Yk({nodes:E,edges:ne,keep_id:ot=>{if(i&&ot===i)return!0;const he=X[ot];if(!he)return!1;const Pe=rn(he.type).trim().toLowerCase();return Pe==="on_flow_start"||Pe==="on_flow_end"||Pe==="subflow"?!0:!Kk(Pe)},max_edges:900});E=Re.nodes,ne=Re.edges}if(e.prefer_vertical===!0&&E.length>=2){const $e=E.map(Ve=>Ve.x),Re=E.map(Ve=>Ve.y),ot=Math.max(...$e)-Math.min(...$e),he=Math.max(...Re)-Math.min(...Re);ot>=he&&(E=E.map(Ve=>({...Ve,x:Ve.y,y:Ve.x})));const Pe=Math.min(...E.map(Ve=>Ve.y));E=E.map(Ve=>({...Ve,y:Pe+(Ve.y-Pe)*d}))}const de={};for(const $e of E)de[$e.id]=$e;const xe=160,be=56,Ee=xe/2,Oe=be/2;let He=0,Ke=0,Ct=0,pt=0;E.length&&(He=Math.min(...E.map($e=>$e.x)),Ke=Math.min(...E.map($e=>$e.y)),Ct=Math.max(...E.map($e=>$e.x+xe)),pt=Math.max(...E.map($e=>$e.y+be)));let gt=0;if(ne.length){const $e=new Set(ne.map(Re=>`${Re.source}->${Re.target}`));for(const Re of ne){if(!$e.has(`${Re.target}->${Re.source}`))continue;const ot=de[Re.source],he=de[Re.target];if(!ot||!he)continue;const Pe=ot.x+Ee,Ve=ot.y+Oe,Rt=he.x+Ee,Xt=he.y+Oe,fn=Math.max(1,Math.hypot(Rt-Pe,Xt-Ve)),Ft=Math.max(28,Math.min(72,fn*.14)),At=Math.min(200,Ft*3.5);At>gt&&(gt=At)}}const yt=60+gt,nt={x:He-yt,y:Ke-yt,w:Ct-He+yt*2,h:pt-Ke+yt*2,node_w:xe,node_h:be};return{nodes:E,edges:ne,bounds:nt}},[n,e.flow_by_id,e.expand_subflows,e.simplify,e.prefer_vertical,i,d]);if(!n)return r.jsx("div",{className:"graph_empty mono",children:"(no graph loaded)"});const v=_.useRef(null),[w,x]=_.useState(()=>({x:g.x,y:g.y,w:g.w,h:g.h})),N=_.useRef(w);N.current=w,_.useEffect(()=>{x({x:g.x,y:g.y,w:g.w,h:g.h})},[g.x,g.y,g.w,g.h]);const S=_.useRef(new Map),R=_.useRef(null),T=`${w.x} ${w.y} ${w.w} ${w.h}`,z={};for(const L of m)z[L.id]=L;const H=L=>{let O=rn(L).trim();if(!O)return"";if(z[O])return O;for(;O.includes("::");)if(O=O.slice(0,Math.max(0,O.lastIndexOf("::"))),z[O])return O;return""},D=H(i),G={};for(const[L,O]of Object.entries(a)){if(typeof O!="number")continue;const q=H(L);q&&(G[q]=Math.max(G[q]||0,O))}const Q={};if(u)for(const[L,O]of Object.entries(l)){if(typeof O!="number")continue;const q=H(L);q&&(Q[q]=typeof Q[q]=="number"?Math.min(Q[q],O):O)}const Y=rn(e.schedule_next_in).trim(),ee=rn(e.schedule_interval).trim(),ae=e.node_last_ms&&typeof e.node_last_ms=="object"?e.node_last_ms:{},le=L=>{try{const O=new Date(L),q=String(O.getHours()).padStart(2,"0"),E=String(O.getMinutes()).padStart(2,"0");return`${q}:${E}`}catch{return""}},ge=(L,O)=>{var ne,ie;const q=rn((ne=L.meta)==null?void 0:ne.schedule).trim();if(!(((ie=L.meta)==null?void 0:ie.recurrent)===!0))return O&&Y?`next ${Y}`:q&&q.length<=12&&!q.includes("T")?`in ${q}`:"scheduled";const X=q||ee;return X?O&&Y?`${X} • next ${Y}`:`every ${X}`:O&&Y?`next ${Y}`:"scheduled"},F=L=>{var xe;const O=rn((xe=L.meta)==null?void 0:xe.subflow_id).trim(),q=O&&e.flow_by_id?e.flow_by_id[O]:null,X=rn(q==null?void 0:q.name).trim()||O||L.label||L.id,ne=typeof ae[L.id]=="number"?Number(ae[L.id]):null,ie=ne!==null?le(ne):"",de=ie?`last ${ie}`:"subflow";return{label:X,sub:de}},C=(L,O,q)=>{const E=q||N.current,X=v.current;if(!X)return{x:L,y:O};const ne=X.getBoundingClientRect(),ie=ne.width>0?(L-ne.left)/ne.width:0,de=ne.height>0?(O-ne.top)/ne.height:0;return{x:E.x+ie*E.w,y:E.y+de*E.h}},k=(L,O,q)=>{const E=q||N.current,X=Math.max(.12,Math.min(8,O)),ne=E.w*X,ie=E.h*X,de=E.w>0?(L.x-E.x)/E.w:.5,xe=E.h>0?(L.y-E.y)/E.h:.5,be=L.x-de*ne,Ee=L.y-xe*ie;x(qp({x:be,y:Ee,w:ne,h:ie},g))},I=(L,O,q)=>{const E=q||N.current,X=v.current;if(!X)return;const ne=X.getBoundingClientRect(),ie=.88,de=ne.width>0?L/ne.width*E.w*ie:0,xe=ne.height>0?O/ne.height*E.h*ie:0;x(be=>qp({x:(q||be).x-de,y:(q||be).y-xe,w:(q||be).w,h:(q||be).h},g))},P=_.useMemo(()=>{const L=new Set;for(const O of p)L.add(`${O.source}->${O.target}`);return L},[p]),K=(L,O,q,E)=>{const X=g.node_w,ne=g.node_h,ie=Math.abs(q),de=Math.abs(E);if(ie<1e-6&&de<1e-6)return{x:L,y:O};const xe=ie>1e-6?X/2/ie:Number.POSITIVE_INFINITY,be=de>1e-6?ne/2/de:Number.POSITIVE_INFINITY,Ee=Math.min(xe,be);return{x:L+q*Ee,y:O+E*Ee}};return r.jsxs("div",{className:"graph_wrap",children:[r.jsxs("div",{className:"graph_corner",children:[r.jsxs("div",{className:"graph_corner_buttons",children:[r.jsx("button",{className:"btn graph_corner_btn",type:"button",onClick:()=>x({x:g.x,y:g.y,w:g.w,h:g.h}),title:"Recenter",children:"⤢"}),r.jsx("button",{className:"btn graph_corner_btn",type:"button",onClick:()=>{const L=v.current;if(!L)return;const O=L.getBoundingClientRect(),q=C(O.left+O.width/2,O.top+O.height/2);k(q,.84)},title:"Zoom in",children:"+"}),r.jsx("button",{className:"btn graph_corner_btn",type:"button",onClick:()=>{const L=v.current;if(!L)return;const O=L.getBoundingClientRect(),q=C(O.left+O.width/2,O.top+O.height/2);k(q,1.18)},title:"Zoom out",children:"−"})]}),r.jsx(qk,{})]}),r.jsxs("svg",{ref:v,className:"graph_svg",viewBox:T,role:"img","aria-label":"Workflow execution graph",onWheel:L=>{L.preventDefault();const O=C(L.clientX,L.clientY),q=typeof L.deltaY=="number"?L.deltaY:0,E=typeof L.deltaMode=="number"?Number(L.deltaMode):0,X=E===1?q*24:E===2?q*800:q,ne=45e-5*1.15*1.1;let ie=Math.exp(X*ne);ie=Math.max(.86,Math.min(1.16,ie)),k(O,ie)},onPointerDown:L=>{var q,E;(E=(q=L.currentTarget).setPointerCapture)==null||E.call(q,L.pointerId),S.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const O=Array.from(S.current.values());if(O.length===1)R.current={mode:"pan",start_view:N.current,start_client:{x:L.clientX,y:L.clientY},start_dist:0,anchor_svg:{x:0,y:0}};else if(O.length>=2){const X=O[0],ne=O[1],ie=X.x-ne.x,de=X.y-ne.y,xe=Math.max(1,Math.hypot(ie,de)),be={x:(X.x+ne.x)/2,y:(X.y+ne.y)/2},Ee=N.current;R.current={mode:"pinch",start_view:Ee,start_client:be,start_dist:xe,anchor_svg:C(be.x,be.y,Ee)}}},onPointerMove:L=>{if(!S.current.has(L.pointerId))return;S.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const O=R.current;if(!O)return;const q=Array.from(S.current.values());if(O.mode==="pan"&&q.length===1){const E=L.clientX-O.start_client.x,X=L.clientY-O.start_client.y;I(E,X,O.start_view)}else if(O.mode==="pinch"&&q.length>=2){const E=q[0],X=q[1],ne=E.x-X.x,ie=E.y-X.y,de=Math.max(1,Math.hypot(ne,ie)),xe=O.start_dist/de;k(O.anchor_svg,xe,O.start_view)}},onPointerUp:L=>{S.current.delete(L.pointerId),S.current.size===0&&(R.current=null)},onPointerCancel:L=>{S.current.delete(L.pointerId),S.current.size===0&&(R.current=null)},children:[r.jsxs("defs",{children:[r.jsx("marker",{id:"arrow",viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"8",markerHeight:"8",orient:"auto-start-reverse",children:r.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"rgba(148,163,184,0.55)"})}),r.jsxs("filter",{id:"glow",children:[r.jsx("feGaussianBlur",{stdDeviation:"3",result:"coloredBlur"}),r.jsxs("feMerge",{children:[r.jsx("feMergeNode",{in:"coloredBlur"}),r.jsx("feMergeNode",{in:"SourceGraphic"})]})]})]}),p.map(L=>{const O=z[L.source],q=z[L.target];if(!O||!q)return null;const E=O.x+g.node_w/2,X=O.y+g.node_h/2,ne=q.x+g.node_w/2,ie=q.y+g.node_h/2,de=ne-E,xe=ie-X,be=K(E,X,de,xe),Ee=K(ne,ie,-de,-xe),Oe=L.source!==L.target&&P.has(`${L.target}->${L.source}`),He=Math.max(1,Math.hypot(de,xe)),Ke=-xe/He,Ct=de/He,pt=String(L.source)<String(L.target)?1:-1,yt=Math.abs(de)>=Math.abs(xe)?de>=0:xe>=0,nt=!Oe||yt,$e=Math.max(28,Math.min(72,He*.14)),Re=Math.min(200,$e*3.5),ot=Oe&&!nt?Re*pt:0,he=(be.x+Ee.x)/2+Ke*ot,Pe=(be.y+Ee.y)/2+Ct*ot,Ve=Oe&&!nt?`M ${be.x} ${be.y} Q ${he} ${Pe} ${Ee.x} ${Ee.y}`:`M ${be.x} ${be.y} L ${Ee.x} ${Ee.y}`,Rt=u&&Q&&Q[L.source]!==void 0&&Q[L.target]!==void 0;return r.jsx("path",{d:Ve,className:`graph_edge ${Rt?"visited":""}`,markerEnd:"url(#arrow)",fill:"none"},L.id)}),m.map(L=>{const q=(typeof G[L.id]=="number"?G[L.id]:0)>t,E=D&&L.id===D,X=u&&Q&&Q[L.id]!==void 0,ne=`graph_node ${E?"active":q?"recent":""} ${X?"visited":""}`,ie=L.color||"rgba(255,255,255,0.16)";let de=L.label||L.id,xe=L.type;if(L.type==="on_schedule")xe=ge(L,!!E);else if(L.type==="subflow"){const Oe=F(L);de=Oe.label,xe=Oe.sub}const be=Hp(de,22),Ee=Hp(xe,22);return r.jsxs("g",{className:ne,transform:`translate(${L.x}, ${L.y})`,children:[r.jsx("rect",{className:"graph_node_bg",width:g.node_w,height:g.node_h,rx:12,ry:12}),r.jsx("rect",{className:"graph_node_bar",width:g.node_w,height:6,rx:12,ry:12,fill:ie}),r.jsx("text",{className:"graph_node_label",x:12,y:28,children:be}),r.jsx("text",{className:"graph_node_type",x:12,y:46,children:Ee}),L.type==="on_schedule"?r.jsx("text",{className:"graph_node_icon",x:g.node_w-18,y:18,children:"⏰"}):null]},L.id)})]})]})}function Br(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,i;n<e.length;n++)(i=Br(e[n]))!==""&&(t+=(t&&" ")+i);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var o_={exports:{}},a_={},l_={exports:{}},c_={};/**
|
|
107
|
+
* @license React
|
|
108
|
+
* use-sync-external-store-shim.production.js
|
|
109
|
+
*
|
|
110
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
111
|
+
*
|
|
112
|
+
* This source code is licensed under the MIT license found in the
|
|
113
|
+
* LICENSE file in the root directory of this source tree.
|
|
114
|
+
*/var Vp;function Jk(){if(Vp)return c_;Vp=1;var e=Qd();function t(v,w){return v===w&&(v!==0||1/v===1/w)||v!==v&&w!==w}var n=typeof Object.is=="function"?Object.is:t,i=e.useState,a=e.useEffect,l=e.useLayoutEffect,u=e.useDebugValue;function d(v,w){var x=w(),N=i({inst:{value:x,getSnapshot:w}}),S=N[0].inst,R=N[1];return l(function(){S.value=x,S.getSnapshot=w,m(S)&&R({inst:S})},[v,x,w]),a(function(){return m(S)&&R({inst:S}),v(function(){m(S)&&R({inst:S})})},[v]),u(x),x}function m(v){var w=v.getSnapshot;v=v.value;try{var x=w();return!n(v,x)}catch{return!0}}function p(v,w){return w()}var g=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?p:d;return c_.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:g,c_}var Gp;function Zk(){return Gp||(Gp=1,l_.exports=Jk()),l_.exports}/**
|
|
115
|
+
* @license React
|
|
116
|
+
* use-sync-external-store-shim/with-selector.production.js
|
|
117
|
+
*
|
|
118
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
119
|
+
*
|
|
120
|
+
* This source code is licensed under the MIT license found in the
|
|
121
|
+
* LICENSE file in the root directory of this source tree.
|
|
122
|
+
*/var Kp;function Qk(){if(Kp)return a_;Kp=1;var e=Qd(),t=Zk();function n(p,g){return p===g&&(p!==0||1/p===1/g)||p!==p&&g!==g}var i=typeof Object.is=="function"?Object.is:n,a=t.useSyncExternalStore,l=e.useRef,u=e.useEffect,d=e.useMemo,m=e.useDebugValue;return a_.useSyncExternalStoreWithSelector=function(p,g,v,w,x){var N=l(null);if(N.current===null){var S={hasValue:!1,value:null};N.current=S}else S=N.current;N=d(function(){function T(Q){if(!z){if(z=!0,H=Q,Q=w(Q),x!==void 0&&S.hasValue){var Y=S.value;if(x(Y,Q))return D=Y}return D=Q}if(Y=D,i(H,Q))return Y;var ee=w(Q);return x!==void 0&&x(Y,ee)?(H=Q,Y):(H=Q,D=ee)}var z=!1,H,D,G=v===void 0?null:v;return[function(){return T(g())},G===null?void 0:function(){return T(G())}]},[g,v,w,x]);var R=a(p,N[0],N[1]);return u(function(){S.hasValue=!0,S.value=R},[R]),m(R),R},a_}var Yp;function eN(){return Yp||(Yp=1,o_.exports=Qk()),o_.exports}var tN=eN();const nN=mg(tN),rN={},Xp=e=>{let t;const n=new Set,i=(g,v)=>{const w=typeof g=="function"?g(t):g;if(!Object.is(w,t)){const x=t;t=v??(typeof w!="object"||w===null)?w:Object.assign({},t,w),n.forEach(N=>N(t,x))}},a=()=>t,m={setState:i,getState:a,getInitialState:()=>p,subscribe:g=>(n.add(g),()=>n.delete(g)),destroy:()=>{(rN?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},p=t=e(i,a,m);return m},sN=e=>e?Xp(e):Xp,{useDebugValue:iN}=pe,{useSyncExternalStoreWithSelector:oN}=nN,aN=e=>e;function hw(e,t=aN,n){const i=oN(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return iN(i),i}const Jp=(e,t)=>{const n=sN(e),i=(a,l=t)=>hw(n,a,l);return Object.assign(i,n),i},lN=(e,t)=>e?Jp(e,t):Jp;function Rr(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[i,a]of e)if(!Object.is(a,t.get(i)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const i of e)if(!t.has(i))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const i of n)if(!Object.prototype.hasOwnProperty.call(t,i)||!Object.is(e[i],t[i]))return!1;return!0}var cN={value:()=>{}};function ah(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new Mm(n)}function Mm(e){this._=e}function uN(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",a=n.indexOf(".");if(a>=0&&(i=n.slice(a+1),n=n.slice(0,a)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Mm.prototype=ah.prototype={constructor:Mm,on:function(e,t){var n=this._,i=uN(e+"",n),a,l=-1,u=i.length;if(arguments.length<2){for(;++l<u;)if((a=(e=i[l]).type)&&(a=dN(n[a],e.name)))return a;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++l<u;)if(a=(e=i[l]).type)n[a]=Zp(n[a],e.name,t);else if(t==null)for(a in n)n[a]=Zp(n[a],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Mm(e)},call:function(e,t){if((a=arguments.length-2)>0)for(var n=new Array(a),i=0,a,l;i<a;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(l=this._[e],i=0,a=l.length;i<a;++i)l[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],a=0,l=i.length;a<l;++a)i[a].value.apply(t,n)}};function dN(e,t){for(var n=0,i=e.length,a;n<i;++n)if((a=e[n]).name===t)return a.value}function Zp(e,t,n){for(var i=0,a=e.length;i<a;++i)if(e[i].name===t){e[i]=cN,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var q_="http://www.w3.org/1999/xhtml";const Qp={svg:"http://www.w3.org/2000/svg",xhtml:q_,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function lh(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Qp.hasOwnProperty(t)?{space:Qp[t],local:e}:e}function fN(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===q_&&t.documentElement.namespaceURI===q_?t.createElement(e):t.createElementNS(n,e)}}function mN(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function _w(e){var t=lh(e);return(t.local?mN:fN)(t)}function hN(){}function Ng(e){return e==null?hN:function(){return this.querySelector(e)}}function _N(e){typeof e!="function"&&(e=Ng(e));for(var t=this._groups,n=t.length,i=new Array(n),a=0;a<n;++a)for(var l=t[a],u=l.length,d=i[a]=new Array(u),m,p,g=0;g<u;++g)(m=l[g])&&(p=e.call(m,m.__data__,g,l))&&("__data__"in m&&(p.__data__=m.__data__),d[g]=p);return new Xs(i,this._parents)}function gN(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function pN(){return[]}function gw(e){return e==null?pN:function(){return this.querySelectorAll(e)}}function yN(e){return function(){return gN(e.apply(this,arguments))}}function vN(e){typeof e=="function"?e=yN(e):e=gw(e);for(var t=this._groups,n=t.length,i=[],a=[],l=0;l<n;++l)for(var u=t[l],d=u.length,m,p=0;p<d;++p)(m=u[p])&&(i.push(e.call(m,m.__data__,p,u)),a.push(m));return new Xs(i,a)}function pw(e){return function(){return this.matches(e)}}function yw(e){return function(t){return t.matches(e)}}var wN=Array.prototype.find;function xN(e){return function(){return wN.call(this.children,e)}}function bN(){return this.firstElementChild}function jN(e){return this.select(e==null?bN:xN(typeof e=="function"?e:yw(e)))}var SN=Array.prototype.filter;function kN(){return Array.from(this.children)}function NN(e){return function(){return SN.call(this.children,e)}}function CN(e){return this.selectAll(e==null?kN:NN(typeof e=="function"?e:yw(e)))}function $N(e){typeof e!="function"&&(e=pw(e));for(var t=this._groups,n=t.length,i=new Array(n),a=0;a<n;++a)for(var l=t[a],u=l.length,d=i[a]=[],m,p=0;p<u;++p)(m=l[p])&&e.call(m,m.__data__,p,l)&&d.push(m);return new Xs(i,this._parents)}function vw(e){return new Array(e.length)}function EN(){return new Xs(this._enter||this._groups.map(vw),this._parents)}function qm(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}qm.prototype={constructor:qm,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function AN(e){return function(){return e}}function MN(e,t,n,i,a,l){for(var u=0,d,m=t.length,p=l.length;u<p;++u)(d=t[u])?(d.__data__=l[u],i[u]=d):n[u]=new qm(e,l[u]);for(;u<m;++u)(d=t[u])&&(a[u]=d)}function TN(e,t,n,i,a,l,u){var d,m,p=new Map,g=t.length,v=l.length,w=new Array(g),x;for(d=0;d<g;++d)(m=t[d])&&(w[d]=x=u.call(m,m.__data__,d,t)+"",p.has(x)?a[d]=m:p.set(x,m));for(d=0;d<v;++d)x=u.call(e,l[d],d,l)+"",(m=p.get(x))?(i[d]=m,m.__data__=l[d],p.delete(x)):n[d]=new qm(e,l[d]);for(d=0;d<g;++d)(m=t[d])&&p.get(w[d])===m&&(a[d]=m)}function RN(e){return e.__data__}function LN(e,t){if(!arguments.length)return Array.from(this,RN);var n=t?TN:MN,i=this._parents,a=this._groups;typeof e!="function"&&(e=AN(e));for(var l=a.length,u=new Array(l),d=new Array(l),m=new Array(l),p=0;p<l;++p){var g=i[p],v=a[p],w=v.length,x=ON(e.call(g,g&&g.__data__,p,i)),N=x.length,S=d[p]=new Array(N),R=u[p]=new Array(N),T=m[p]=new Array(w);n(g,v,S,R,T,x,t);for(var z=0,H=0,D,G;z<N;++z)if(D=S[z]){for(z>=H&&(H=z+1);!(G=R[H])&&++H<N;);D._next=G||null}}return u=new Xs(u,i),u._enter=d,u._exit=m,u}function ON(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function PN(){return new Xs(this._exit||this._groups.map(vw),this._parents)}function IN(e,t,n){var i=this.enter(),a=this,l=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(a=t(a),a&&(a=a.selection())),n==null?l.remove():n(l),i&&a?i.merge(a).order():a}function DN(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,a=n.length,l=i.length,u=Math.min(a,l),d=new Array(a),m=0;m<u;++m)for(var p=n[m],g=i[m],v=p.length,w=d[m]=new Array(v),x,N=0;N<v;++N)(x=p[N]||g[N])&&(w[N]=x);for(;m<a;++m)d[m]=n[m];return new Xs(d,this._parents)}function zN(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],a=i.length-1,l=i[a],u;--a>=0;)(u=i[a])&&(l&&u.compareDocumentPosition(l)^4&&l.parentNode.insertBefore(u,l),l=u);return this}function FN(e){e||(e=BN);function t(v,w){return v&&w?e(v.__data__,w.__data__):!v-!w}for(var n=this._groups,i=n.length,a=new Array(i),l=0;l<i;++l){for(var u=n[l],d=u.length,m=a[l]=new Array(d),p,g=0;g<d;++g)(p=u[g])&&(m[g]=p);m.sort(t)}return new Xs(a,this._parents).order()}function BN(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function UN(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function WN(){return Array.from(this)}function HN(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],a=0,l=i.length;a<l;++a){var u=i[a];if(u)return u}return null}function qN(){let e=0;for(const t of this)++e;return e}function VN(){return!this.node()}function GN(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var a=t[n],l=0,u=a.length,d;l<u;++l)(d=a[l])&&e.call(d,d.__data__,l,a);return this}function KN(e){return function(){this.removeAttribute(e)}}function YN(e){return function(){this.removeAttributeNS(e.space,e.local)}}function XN(e,t){return function(){this.setAttribute(e,t)}}function JN(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function ZN(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function QN(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function e1(e,t){var n=lh(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?YN:KN:typeof t=="function"?n.local?QN:ZN:n.local?JN:XN)(n,t))}function ww(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function t1(e){return function(){this.style.removeProperty(e)}}function n1(e,t,n){return function(){this.style.setProperty(e,t,n)}}function r1(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function s1(e,t,n){return arguments.length>1?this.each((t==null?t1:typeof t=="function"?r1:n1)(e,t,n??"")):mu(this.node(),e)}function mu(e,t){return e.style.getPropertyValue(t)||ww(e).getComputedStyle(e,null).getPropertyValue(t)}function i1(e){return function(){delete this[e]}}function o1(e,t){return function(){this[e]=t}}function a1(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function l1(e,t){return arguments.length>1?this.each((t==null?i1:typeof t=="function"?a1:o1)(e,t)):this.node()[e]}function xw(e){return e.trim().split(/^|\s+/)}function Cg(e){return e.classList||new bw(e)}function bw(e){this._node=e,this._names=xw(e.getAttribute("class")||"")}bw.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function jw(e,t){for(var n=Cg(e),i=-1,a=t.length;++i<a;)n.add(t[i])}function Sw(e,t){for(var n=Cg(e),i=-1,a=t.length;++i<a;)n.remove(t[i])}function c1(e){return function(){jw(this,e)}}function u1(e){return function(){Sw(this,e)}}function d1(e,t){return function(){(t.apply(this,arguments)?jw:Sw)(this,e)}}function f1(e,t){var n=xw(e+"");if(arguments.length<2){for(var i=Cg(this.node()),a=-1,l=n.length;++a<l;)if(!i.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?d1:t?c1:u1)(n,t))}function m1(){this.textContent=""}function h1(e){return function(){this.textContent=e}}function _1(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function g1(e){return arguments.length?this.each(e==null?m1:(typeof e=="function"?_1:h1)(e)):this.node().textContent}function p1(){this.innerHTML=""}function y1(e){return function(){this.innerHTML=e}}function v1(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function w1(e){return arguments.length?this.each(e==null?p1:(typeof e=="function"?v1:y1)(e)):this.node().innerHTML}function x1(){this.nextSibling&&this.parentNode.appendChild(this)}function b1(){return this.each(x1)}function j1(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function S1(){return this.each(j1)}function k1(e){var t=typeof e=="function"?e:_w(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function N1(){return null}function C1(e,t){var n=typeof e=="function"?e:_w(e),i=t==null?N1:typeof t=="function"?t:Ng(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function $1(){var e=this.parentNode;e&&e.removeChild(this)}function E1(){return this.each($1)}function A1(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function M1(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function T1(e){return this.select(e?M1:A1)}function R1(e){return arguments.length?this.property("__data__",e):this.node().__data__}function L1(e){return function(t){e.call(this,t,this.__data__)}}function O1(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function P1(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,a=t.length,l;n<a;++n)l=t[n],(!e.type||l.type===e.type)&&l.name===e.name?this.removeEventListener(l.type,l.listener,l.options):t[++i]=l;++i?t.length=i:delete this.__on}}}function I1(e,t,n){return function(){var i=this.__on,a,l=L1(t);if(i){for(var u=0,d=i.length;u<d;++u)if((a=i[u]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=l,a.options=n),a.value=t;return}}this.addEventListener(e.type,l,n),a={type:e.type,name:e.name,value:t,listener:l,options:n},i?i.push(a):this.__on=[a]}}function D1(e,t,n){var i=O1(e+""),a,l=i.length,u;if(arguments.length<2){var d=this.node().__on;if(d){for(var m=0,p=d.length,g;m<p;++m)for(a=0,g=d[m];a<l;++a)if((u=i[a]).type===g.type&&u.name===g.name)return g.value}return}for(d=t?I1:P1,a=0;a<l;++a)this.each(d(i[a],t,n));return this}function kw(e,t,n){var i=ww(e),a=i.CustomEvent;typeof a=="function"?a=new a(t,n):(a=i.document.createEvent("Event"),n?(a.initEvent(t,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(t,!1,!1)),e.dispatchEvent(a)}function z1(e,t){return function(){return kw(this,e,t)}}function F1(e,t){return function(){return kw(this,e,t.apply(this,arguments))}}function B1(e,t){return this.each((typeof t=="function"?F1:z1)(e,t))}function*U1(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],a=0,l=i.length,u;a<l;++a)(u=i[a])&&(yield u)}var Nw=[null];function Xs(e,t){this._groups=e,this._parents=t}function tf(){return new Xs([[document.documentElement]],Nw)}function W1(){return this}Xs.prototype=tf.prototype={constructor:Xs,select:_N,selectAll:vN,selectChild:jN,selectChildren:CN,filter:$N,data:LN,enter:EN,exit:PN,join:IN,merge:DN,selection:W1,order:zN,sort:FN,call:UN,nodes:WN,node:HN,size:qN,empty:VN,each:GN,attr:e1,style:s1,property:l1,classed:f1,text:g1,html:w1,raise:b1,lower:S1,append:k1,insert:C1,remove:E1,clone:T1,datum:R1,on:D1,dispatch:B1,[Symbol.iterator]:U1};function _i(e){return typeof e=="string"?new Xs([[document.querySelector(e)]],[document.documentElement]):new Xs([[e]],Nw)}function H1(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Ui(e,t){if(e=H1(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(t.getScreenCTM().inverse()),[i.x,i.y]}if(t.getBoundingClientRect){var a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}}return[e.pageX,e.pageY]}const q1={passive:!1},Ud={capture:!0,passive:!1};function u_(e){e.stopImmediatePropagation()}function au(e){e.preventDefault(),e.stopImmediatePropagation()}function Cw(e){var t=e.document.documentElement,n=_i(e).on("dragstart.drag",au,Ud);"onselectstart"in t?n.on("selectstart.drag",au,Ud):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function $w(e,t){var n=e.document.documentElement,i=_i(e).on("dragstart.drag",null);t&&(i.on("click.drag",au,Ud),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const _m=e=>()=>e;function V_(e,{sourceEvent:t,subject:n,target:i,identifier:a,active:l,x:u,y:d,dx:m,dy:p,dispatch:g}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:l,enumerable:!0,configurable:!0},x:{value:u,enumerable:!0,configurable:!0},y:{value:d,enumerable:!0,configurable:!0},dx:{value:m,enumerable:!0,configurable:!0},dy:{value:p,enumerable:!0,configurable:!0},_:{value:g}})}V_.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function V1(e){return!e.ctrlKey&&!e.button}function G1(){return this.parentNode}function K1(e,t){return t??{x:e.x,y:e.y}}function Y1(){return navigator.maxTouchPoints||"ontouchstart"in this}function X1(){var e=V1,t=G1,n=K1,i=Y1,a={},l=ah("start","drag","end"),u=0,d,m,p,g,v=0;function w(D){D.on("mousedown.drag",x).filter(i).on("touchstart.drag",R).on("touchmove.drag",T,q1).on("touchend.drag touchcancel.drag",z).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function x(D,G){if(!(g||!e.call(this,D,G))){var Q=H(this,t.call(this,D,G),D,G,"mouse");Q&&(_i(D.view).on("mousemove.drag",N,Ud).on("mouseup.drag",S,Ud),Cw(D.view),u_(D),p=!1,d=D.clientX,m=D.clientY,Q("start",D))}}function N(D){if(au(D),!p){var G=D.clientX-d,Q=D.clientY-m;p=G*G+Q*Q>v}a.mouse("drag",D)}function S(D){_i(D.view).on("mousemove.drag mouseup.drag",null),$w(D.view,p),au(D),a.mouse("end",D)}function R(D,G){if(e.call(this,D,G)){var Q=D.changedTouches,Y=t.call(this,D,G),ee=Q.length,ae,le;for(ae=0;ae<ee;++ae)(le=H(this,Y,D,G,Q[ae].identifier,Q[ae]))&&(u_(D),le("start",D,Q[ae]))}}function T(D){var G=D.changedTouches,Q=G.length,Y,ee;for(Y=0;Y<Q;++Y)(ee=a[G[Y].identifier])&&(au(D),ee("drag",D,G[Y]))}function z(D){var G=D.changedTouches,Q=G.length,Y,ee;for(g&&clearTimeout(g),g=setTimeout(function(){g=null},500),Y=0;Y<Q;++Y)(ee=a[G[Y].identifier])&&(u_(D),ee("end",D,G[Y]))}function H(D,G,Q,Y,ee,ae){var le=l.copy(),ge=Ui(ae||Q,G),F,C,k;if((k=n.call(D,new V_("beforestart",{sourceEvent:Q,target:w,identifier:ee,active:u,x:ge[0],y:ge[1],dx:0,dy:0,dispatch:le}),Y))!=null)return F=k.x-ge[0]||0,C=k.y-ge[1]||0,function I(P,K,L){var O=ge,q;switch(P){case"start":a[ee]=I,q=u++;break;case"end":delete a[ee],--u;case"drag":ge=Ui(L||K,G),q=u;break}le.call(P,D,new V_(P,{sourceEvent:K,subject:k,target:w,identifier:ee,active:q,x:ge[0]+F,y:ge[1]+C,dx:ge[0]-O[0],dy:ge[1]-O[1],dispatch:le}),Y)}}return w.filter=function(D){return arguments.length?(e=typeof D=="function"?D:_m(!!D),w):e},w.container=function(D){return arguments.length?(t=typeof D=="function"?D:_m(D),w):t},w.subject=function(D){return arguments.length?(n=typeof D=="function"?D:_m(D),w):n},w.touchable=function(D){return arguments.length?(i=typeof D=="function"?D:_m(!!D),w):i},w.on=function(){var D=l.on.apply(l,arguments);return D===l?w:D},w.clickDistance=function(D){return arguments.length?(v=(D=+D)*D,w):Math.sqrt(v)},w}function $g(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Ew(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function nf(){}var Wd=.7,Vm=1/Wd,lu="\\s*([+-]?\\d+)\\s*",Hd="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",co="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",J1=/^#([0-9a-f]{3,8})$/,Z1=new RegExp(`^rgb\\(${lu},${lu},${lu}\\)$`),Q1=new RegExp(`^rgb\\(${co},${co},${co}\\)$`),e2=new RegExp(`^rgba\\(${lu},${lu},${lu},${Hd}\\)$`),t2=new RegExp(`^rgba\\(${co},${co},${co},${Hd}\\)$`),n2=new RegExp(`^hsl\\(${Hd},${co},${co}\\)$`),r2=new RegExp(`^hsla\\(${Hd},${co},${co},${Hd}\\)$`),ey={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};$g(nf,qd,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:ty,formatHex:ty,formatHex8:s2,formatHsl:i2,formatRgb:ny,toString:ny});function ty(){return this.rgb().formatHex()}function s2(){return this.rgb().formatHex8()}function i2(){return Aw(this).formatHsl()}function ny(){return this.rgb().formatRgb()}function qd(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=J1.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?ry(t):n===3?new Ms(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?gm(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?gm(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Z1.exec(e))?new Ms(t[1],t[2],t[3],1):(t=Q1.exec(e))?new Ms(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=e2.exec(e))?gm(t[1],t[2],t[3],t[4]):(t=t2.exec(e))?gm(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=n2.exec(e))?oy(t[1],t[2]/100,t[3]/100,1):(t=r2.exec(e))?oy(t[1],t[2]/100,t[3]/100,t[4]):ey.hasOwnProperty(e)?ry(ey[e]):e==="transparent"?new Ms(NaN,NaN,NaN,0):null}function ry(e){return new Ms(e>>16&255,e>>8&255,e&255,1)}function gm(e,t,n,i){return i<=0&&(e=t=n=NaN),new Ms(e,t,n,i)}function o2(e){return e instanceof nf||(e=qd(e)),e?(e=e.rgb(),new Ms(e.r,e.g,e.b,e.opacity)):new Ms}function G_(e,t,n,i){return arguments.length===1?o2(e):new Ms(e,t,n,i??1)}function Ms(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}$g(Ms,G_,Ew(nf,{brighter(e){return e=e==null?Vm:Math.pow(Vm,e),new Ms(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Wd:Math.pow(Wd,e),new Ms(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ms(ec(this.r),ec(this.g),ec(this.b),Gm(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:sy,formatHex:sy,formatHex8:a2,formatRgb:iy,toString:iy}));function sy(){return`#${Yl(this.r)}${Yl(this.g)}${Yl(this.b)}`}function a2(){return`#${Yl(this.r)}${Yl(this.g)}${Yl(this.b)}${Yl((isNaN(this.opacity)?1:this.opacity)*255)}`}function iy(){const e=Gm(this.opacity);return`${e===1?"rgb(":"rgba("}${ec(this.r)}, ${ec(this.g)}, ${ec(this.b)}${e===1?")":`, ${e})`}`}function Gm(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function ec(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Yl(e){return e=ec(e),(e<16?"0":"")+e.toString(16)}function oy(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Wi(e,t,n,i)}function Aw(e){if(e instanceof Wi)return new Wi(e.h,e.s,e.l,e.opacity);if(e instanceof nf||(e=qd(e)),!e)return new Wi;if(e instanceof Wi)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,a=Math.min(t,n,i),l=Math.max(t,n,i),u=NaN,d=l-a,m=(l+a)/2;return d?(t===l?u=(n-i)/d+(n<i)*6:n===l?u=(i-t)/d+2:u=(t-n)/d+4,d/=m<.5?l+a:2-l-a,u*=60):d=m>0&&m<1?0:u,new Wi(u,d,m,e.opacity)}function l2(e,t,n,i){return arguments.length===1?Aw(e):new Wi(e,t,n,i??1)}function Wi(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}$g(Wi,l2,Ew(nf,{brighter(e){return e=e==null?Vm:Math.pow(Vm,e),new Wi(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Wd:Math.pow(Wd,e),new Wi(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*t,a=2*n-i;return new Ms(d_(e>=240?e-240:e+120,a,i),d_(e,a,i),d_(e<120?e+240:e-120,a,i),this.opacity)},clamp(){return new Wi(ay(this.h),pm(this.s),pm(this.l),Gm(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Gm(this.opacity);return`${e===1?"hsl(":"hsla("}${ay(this.h)}, ${pm(this.s)*100}%, ${pm(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ay(e){return e=(e||0)%360,e<0?e+360:e}function pm(e){return Math.max(0,Math.min(1,e||0))}function d_(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Mw=e=>()=>e;function c2(e,t){return function(n){return e+n*t}}function u2(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function d2(e){return(e=+e)==1?Tw:function(t,n){return n-t?u2(t,n,e):Mw(isNaN(t)?n:t)}}function Tw(e,t){var n=t-e;return n?c2(e,n):Mw(isNaN(e)?t:e)}const ly=(function e(t){var n=d2(t);function i(a,l){var u=n((a=G_(a)).r,(l=G_(l)).r),d=n(a.g,l.g),m=n(a.b,l.b),p=Tw(a.opacity,l.opacity);return function(g){return a.r=u(g),a.g=d(g),a.b=m(g),a.opacity=p(g),a+""}}return i.gamma=e,i})(1);function Ya(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var K_=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,f_=new RegExp(K_.source,"g");function f2(e){return function(){return e}}function m2(e){return function(t){return e(t)+""}}function h2(e,t){var n=K_.lastIndex=f_.lastIndex=0,i,a,l,u=-1,d=[],m=[];for(e=e+"",t=t+"";(i=K_.exec(e))&&(a=f_.exec(t));)(l=a.index)>n&&(l=t.slice(n,l),d[u]?d[u]+=l:d[++u]=l),(i=i[0])===(a=a[0])?d[u]?d[u]+=a:d[++u]=a:(d[++u]=null,m.push({i:u,x:Ya(i,a)})),n=f_.lastIndex;return n<t.length&&(l=t.slice(n),d[u]?d[u]+=l:d[++u]=l),d.length<2?m[0]?m2(m[0].x):f2(t):(t=m.length,function(p){for(var g=0,v;g<t;++g)d[(v=m[g]).i]=v.x(p);return d.join("")})}var cy=180/Math.PI,Y_={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Rw(e,t,n,i,a,l){var u,d,m;return(u=Math.sqrt(e*e+t*t))&&(e/=u,t/=u),(m=e*n+t*i)&&(n-=e*m,i-=t*m),(d=Math.sqrt(n*n+i*i))&&(n/=d,i/=d,m/=d),e*i<t*n&&(e=-e,t=-t,m=-m,u=-u),{translateX:a,translateY:l,rotate:Math.atan2(t,e)*cy,skewX:Math.atan(m)*cy,scaleX:u,scaleY:d}}var ym;function _2(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Y_:Rw(t.a,t.b,t.c,t.d,t.e,t.f)}function g2(e){return e==null||(ym||(ym=document.createElementNS("http://www.w3.org/2000/svg","g")),ym.setAttribute("transform",e),!(e=ym.transform.baseVal.consolidate()))?Y_:(e=e.matrix,Rw(e.a,e.b,e.c,e.d,e.e,e.f))}function Lw(e,t,n,i){function a(p){return p.length?p.pop()+" ":""}function l(p,g,v,w,x,N){if(p!==v||g!==w){var S=x.push("translate(",null,t,null,n);N.push({i:S-4,x:Ya(p,v)},{i:S-2,x:Ya(g,w)})}else(v||w)&&x.push("translate("+v+t+w+n)}function u(p,g,v,w){p!==g?(p-g>180?g+=360:g-p>180&&(p+=360),w.push({i:v.push(a(v)+"rotate(",null,i)-2,x:Ya(p,g)})):g&&v.push(a(v)+"rotate("+g+i)}function d(p,g,v,w){p!==g?w.push({i:v.push(a(v)+"skewX(",null,i)-2,x:Ya(p,g)}):g&&v.push(a(v)+"skewX("+g+i)}function m(p,g,v,w,x,N){if(p!==v||g!==w){var S=x.push(a(x)+"scale(",null,",",null,")");N.push({i:S-4,x:Ya(p,v)},{i:S-2,x:Ya(g,w)})}else(v!==1||w!==1)&&x.push(a(x)+"scale("+v+","+w+")")}return function(p,g){var v=[],w=[];return p=e(p),g=e(g),l(p.translateX,p.translateY,g.translateX,g.translateY,v,w),u(p.rotate,g.rotate,v,w),d(p.skewX,g.skewX,v,w),m(p.scaleX,p.scaleY,g.scaleX,g.scaleY,v,w),p=g=null,function(x){for(var N=-1,S=w.length,R;++N<S;)v[(R=w[N]).i]=R.x(x);return v.join("")}}}var p2=Lw(_2,"px, ","px)","deg)"),y2=Lw(g2,", ",")",")"),v2=1e-12;function uy(e){return((e=Math.exp(e))+1/e)/2}function w2(e){return((e=Math.exp(e))-1/e)/2}function x2(e){return((e=Math.exp(2*e))-1)/(e+1)}const b2=(function e(t,n,i){function a(l,u){var d=l[0],m=l[1],p=l[2],g=u[0],v=u[1],w=u[2],x=g-d,N=v-m,S=x*x+N*N,R,T;if(S<v2)T=Math.log(w/p)/t,R=function(Y){return[d+Y*x,m+Y*N,p*Math.exp(t*Y*T)]};else{var z=Math.sqrt(S),H=(w*w-p*p+i*S)/(2*p*n*z),D=(w*w-p*p-i*S)/(2*w*n*z),G=Math.log(Math.sqrt(H*H+1)-H),Q=Math.log(Math.sqrt(D*D+1)-D);T=(Q-G)/t,R=function(Y){var ee=Y*T,ae=uy(G),le=p/(n*z)*(ae*x2(t*ee+G)-w2(G));return[d+le*x,m+le*N,p*ae/uy(t*ee+G)]}}return R.duration=T*1e3*t/Math.SQRT2,R}return a.rho=function(l){var u=Math.max(.001,+l),d=u*u,m=d*d;return e(u,d,m)},a})(Math.SQRT2,2,4);var hu=0,Od=0,kd=0,Ow=1e3,Km,Pd,Ym=0,sc=0,ch=0,Vd=typeof performance=="object"&&performance.now?performance:Date,Pw=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Eg(){return sc||(Pw(j2),sc=Vd.now()+ch)}function j2(){sc=0}function Xm(){this._call=this._time=this._next=null}Xm.prototype=Iw.prototype={constructor:Xm,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Eg():+n)+(t==null?0:+t),!this._next&&Pd!==this&&(Pd?Pd._next=this:Km=this,Pd=this),this._call=e,this._time=n,X_()},stop:function(){this._call&&(this._call=null,this._time=1/0,X_())}};function Iw(e,t,n){var i=new Xm;return i.restart(e,t,n),i}function S2(){Eg(),++hu;for(var e=Km,t;e;)(t=sc-e._time)>=0&&e._call.call(void 0,t),e=e._next;--hu}function dy(){sc=(Ym=Vd.now())+ch,hu=Od=0;try{S2()}finally{hu=0,N2(),sc=0}}function k2(){var e=Vd.now(),t=e-Ym;t>Ow&&(ch-=t,Ym=e)}function N2(){for(var e,t=Km,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Km=n);Pd=e,X_(i)}function X_(e){if(!hu){Od&&(Od=clearTimeout(Od));var t=e-sc;t>24?(e<1/0&&(Od=setTimeout(dy,e-Vd.now()-ch)),kd&&(kd=clearInterval(kd))):(kd||(Ym=Vd.now(),kd=setInterval(k2,Ow)),hu=1,Pw(dy))}}function fy(e,t,n){var i=new Xm;return t=t==null?0:+t,i.restart(a=>{i.stop(),e(a+t)},t,n),i}var C2=ah("start","end","cancel","interrupt"),$2=[],Dw=0,my=1,J_=2,Tm=3,hy=4,Z_=5,Rm=6;function uh(e,t,n,i,a,l){var u=e.__transition;if(!u)e.__transition={};else if(n in u)return;E2(e,n,{name:t,index:i,group:a,on:C2,tween:$2,time:l.time,delay:l.delay,duration:l.duration,ease:l.ease,timer:null,state:Dw})}function Ag(e,t){var n=Vi(e,t);if(n.state>Dw)throw new Error("too late; already scheduled");return n}function uo(e,t){var n=Vi(e,t);if(n.state>Tm)throw new Error("too late; already running");return n}function Vi(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function E2(e,t,n){var i=e.__transition,a;i[t]=n,n.timer=Iw(l,0,n.time);function l(p){n.state=my,n.timer.restart(u,n.delay,n.time),n.delay<=p&&u(p-n.delay)}function u(p){var g,v,w,x;if(n.state!==my)return m();for(g in i)if(x=i[g],x.name===n.name){if(x.state===Tm)return fy(u);x.state===hy?(x.state=Rm,x.timer.stop(),x.on.call("interrupt",e,e.__data__,x.index,x.group),delete i[g]):+g<t&&(x.state=Rm,x.timer.stop(),x.on.call("cancel",e,e.__data__,x.index,x.group),delete i[g])}if(fy(function(){n.state===Tm&&(n.state=hy,n.timer.restart(d,n.delay,n.time),d(p))}),n.state=J_,n.on.call("start",e,e.__data__,n.index,n.group),n.state===J_){for(n.state=Tm,a=new Array(w=n.tween.length),g=0,v=-1;g<w;++g)(x=n.tween[g].value.call(e,e.__data__,n.index,n.group))&&(a[++v]=x);a.length=v+1}}function d(p){for(var g=p<n.duration?n.ease.call(null,p/n.duration):(n.timer.restart(m),n.state=Z_,1),v=-1,w=a.length;++v<w;)a[v].call(e,g);n.state===Z_&&(n.on.call("end",e,e.__data__,n.index,n.group),m())}function m(){n.state=Rm,n.timer.stop(),delete i[t];for(var p in i)return;delete e.__transition}}function Lm(e,t){var n=e.__transition,i,a,l=!0,u;if(n){t=t==null?null:t+"";for(u in n){if((i=n[u]).name!==t){l=!1;continue}a=i.state>J_&&i.state<Z_,i.state=Rm,i.timer.stop(),i.on.call(a?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[u]}l&&delete e.__transition}}function A2(e){return this.each(function(){Lm(this,e)})}function M2(e,t){var n,i;return function(){var a=uo(this,e),l=a.tween;if(l!==n){i=n=l;for(var u=0,d=i.length;u<d;++u)if(i[u].name===t){i=i.slice(),i.splice(u,1);break}}a.tween=i}}function T2(e,t,n){var i,a;if(typeof n!="function")throw new Error;return function(){var l=uo(this,e),u=l.tween;if(u!==i){a=(i=u).slice();for(var d={name:t,value:n},m=0,p=a.length;m<p;++m)if(a[m].name===t){a[m]=d;break}m===p&&a.push(d)}l.tween=a}}function R2(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=Vi(this.node(),n).tween,a=0,l=i.length,u;a<l;++a)if((u=i[a]).name===e)return u.value;return null}return this.each((t==null?M2:T2)(n,e,t))}function Mg(e,t,n){var i=e._id;return e.each(function(){var a=uo(this,i);(a.value||(a.value={}))[t]=n.apply(this,arguments)}),function(a){return Vi(a,i).value[t]}}function zw(e,t){var n;return(typeof t=="number"?Ya:t instanceof qd?ly:(n=qd(t))?(t=n,ly):h2)(e,t)}function L2(e){return function(){this.removeAttribute(e)}}function O2(e){return function(){this.removeAttributeNS(e.space,e.local)}}function P2(e,t,n){var i,a=n+"",l;return function(){var u=this.getAttribute(e);return u===a?null:u===i?l:l=t(i=u,n)}}function I2(e,t,n){var i,a=n+"",l;return function(){var u=this.getAttributeNS(e.space,e.local);return u===a?null:u===i?l:l=t(i=u,n)}}function D2(e,t,n){var i,a,l;return function(){var u,d=n(this),m;return d==null?void this.removeAttribute(e):(u=this.getAttribute(e),m=d+"",u===m?null:u===i&&m===a?l:(a=m,l=t(i=u,d)))}}function z2(e,t,n){var i,a,l;return function(){var u,d=n(this),m;return d==null?void this.removeAttributeNS(e.space,e.local):(u=this.getAttributeNS(e.space,e.local),m=d+"",u===m?null:u===i&&m===a?l:(a=m,l=t(i=u,d)))}}function F2(e,t){var n=lh(e),i=n==="transform"?y2:zw;return this.attrTween(e,typeof t=="function"?(n.local?z2:D2)(n,i,Mg(this,"attr."+e,t)):t==null?(n.local?O2:L2)(n):(n.local?I2:P2)(n,i,t))}function B2(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function U2(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function W2(e,t){var n,i;function a(){var l=t.apply(this,arguments);return l!==i&&(n=(i=l)&&U2(e,l)),n}return a._value=t,a}function H2(e,t){var n,i;function a(){var l=t.apply(this,arguments);return l!==i&&(n=(i=l)&&B2(e,l)),n}return a._value=t,a}function q2(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var i=lh(e);return this.tween(n,(i.local?W2:H2)(i,t))}function V2(e,t){return function(){Ag(this,e).delay=+t.apply(this,arguments)}}function G2(e,t){return t=+t,function(){Ag(this,e).delay=t}}function K2(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?V2:G2)(t,e)):Vi(this.node(),t).delay}function Y2(e,t){return function(){uo(this,e).duration=+t.apply(this,arguments)}}function X2(e,t){return t=+t,function(){uo(this,e).duration=t}}function J2(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Y2:X2)(t,e)):Vi(this.node(),t).duration}function Z2(e,t){if(typeof t!="function")throw new Error;return function(){uo(this,e).ease=t}}function Q2(e){var t=this._id;return arguments.length?this.each(Z2(t,e)):Vi(this.node(),t).ease}function eC(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;uo(this,e).ease=n}}function tC(e){if(typeof e!="function")throw new Error;return this.each(eC(this._id,e))}function nC(e){typeof e!="function"&&(e=pw(e));for(var t=this._groups,n=t.length,i=new Array(n),a=0;a<n;++a)for(var l=t[a],u=l.length,d=i[a]=[],m,p=0;p<u;++p)(m=l[p])&&e.call(m,m.__data__,p,l)&&d.push(m);return new Jo(i,this._parents,this._name,this._id)}function rC(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,a=n.length,l=Math.min(i,a),u=new Array(i),d=0;d<l;++d)for(var m=t[d],p=n[d],g=m.length,v=u[d]=new Array(g),w,x=0;x<g;++x)(w=m[x]||p[x])&&(v[x]=w);for(;d<i;++d)u[d]=t[d];return new Jo(u,this._parents,this._name,this._id)}function sC(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function iC(e,t,n){var i,a,l=sC(t)?Ag:uo;return function(){var u=l(this,e),d=u.on;d!==i&&(a=(i=d).copy()).on(t,n),u.on=a}}function oC(e,t){var n=this._id;return arguments.length<2?Vi(this.node(),n).on.on(e):this.each(iC(n,e,t))}function aC(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function lC(){return this.on("end.remove",aC(this._id))}function cC(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ng(e));for(var i=this._groups,a=i.length,l=new Array(a),u=0;u<a;++u)for(var d=i[u],m=d.length,p=l[u]=new Array(m),g,v,w=0;w<m;++w)(g=d[w])&&(v=e.call(g,g.__data__,w,d))&&("__data__"in g&&(v.__data__=g.__data__),p[w]=v,uh(p[w],t,n,w,p,Vi(g,n)));return new Jo(l,this._parents,t,n)}function uC(e){var t=this._name,n=this._id;typeof e!="function"&&(e=gw(e));for(var i=this._groups,a=i.length,l=[],u=[],d=0;d<a;++d)for(var m=i[d],p=m.length,g,v=0;v<p;++v)if(g=m[v]){for(var w=e.call(g,g.__data__,v,m),x,N=Vi(g,n),S=0,R=w.length;S<R;++S)(x=w[S])&&uh(x,t,n,S,w,N);l.push(w),u.push(g)}return new Jo(l,u,t,n)}var dC=tf.prototype.constructor;function fC(){return new dC(this._groups,this._parents)}function mC(e,t){var n,i,a;return function(){var l=mu(this,e),u=(this.style.removeProperty(e),mu(this,e));return l===u?null:l===n&&u===i?a:a=t(n=l,i=u)}}function Fw(e){return function(){this.style.removeProperty(e)}}function hC(e,t,n){var i,a=n+"",l;return function(){var u=mu(this,e);return u===a?null:u===i?l:l=t(i=u,n)}}function _C(e,t,n){var i,a,l;return function(){var u=mu(this,e),d=n(this),m=d+"";return d==null&&(m=d=(this.style.removeProperty(e),mu(this,e))),u===m?null:u===i&&m===a?l:(a=m,l=t(i=u,d))}}function gC(e,t){var n,i,a,l="style."+t,u="end."+l,d;return function(){var m=uo(this,e),p=m.on,g=m.value[l]==null?d||(d=Fw(t)):void 0;(p!==n||a!==g)&&(i=(n=p).copy()).on(u,a=g),m.on=i}}function pC(e,t,n){var i=(e+="")=="transform"?p2:zw;return t==null?this.styleTween(e,mC(e,i)).on("end.style."+e,Fw(e)):typeof t=="function"?this.styleTween(e,_C(e,i,Mg(this,"style."+e,t))).each(gC(this._id,e)):this.styleTween(e,hC(e,i,t),n).on("end.style."+e,null)}function yC(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function vC(e,t,n){var i,a;function l(){var u=t.apply(this,arguments);return u!==a&&(i=(a=u)&&yC(e,u,n)),i}return l._value=t,l}function wC(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,vC(e,t,n??""))}function xC(e){return function(){this.textContent=e}}function bC(e){return function(){var t=e(this);this.textContent=t??""}}function jC(e){return this.tween("text",typeof e=="function"?bC(Mg(this,"text",e)):xC(e==null?"":e+""))}function SC(e){return function(t){this.textContent=e.call(this,t)}}function kC(e){var t,n;function i(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&SC(a)),t}return i._value=e,i}function NC(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,kC(e))}function CC(){for(var e=this._name,t=this._id,n=Bw(),i=this._groups,a=i.length,l=0;l<a;++l)for(var u=i[l],d=u.length,m,p=0;p<d;++p)if(m=u[p]){var g=Vi(m,t);uh(m,e,n,p,u,{time:g.time+g.delay+g.duration,delay:0,duration:g.duration,ease:g.ease})}return new Jo(i,this._parents,e,n)}function $C(){var e,t,n=this,i=n._id,a=n.size();return new Promise(function(l,u){var d={value:u},m={value:function(){--a===0&&l()}};n.each(function(){var p=uo(this,i),g=p.on;g!==e&&(t=(e=g).copy(),t._.cancel.push(d),t._.interrupt.push(d),t._.end.push(m)),p.on=t}),a===0&&l()})}var EC=0;function Jo(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function Bw(){return++EC}var Vo=tf.prototype;Jo.prototype={constructor:Jo,select:cC,selectAll:uC,selectChild:Vo.selectChild,selectChildren:Vo.selectChildren,filter:nC,merge:rC,selection:fC,transition:CC,call:Vo.call,nodes:Vo.nodes,node:Vo.node,size:Vo.size,empty:Vo.empty,each:Vo.each,on:oC,attr:F2,attrTween:q2,style:pC,styleTween:wC,text:jC,textTween:NC,remove:lC,tween:R2,delay:K2,duration:J2,ease:Q2,easeVarying:tC,end:$C,[Symbol.iterator]:Vo[Symbol.iterator]};function AC(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var MC={time:null,delay:0,duration:250,ease:AC};function TC(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function RC(e){var t,n;e instanceof Jo?(t=e._id,e=e._name):(t=Bw(),(n=MC).time=Eg(),e=e==null?null:e+"");for(var i=this._groups,a=i.length,l=0;l<a;++l)for(var u=i[l],d=u.length,m,p=0;p<d;++p)(m=u[p])&&uh(m,e,t,p,u,n||TC(m,t));return new Jo(i,this._parents,e,t)}tf.prototype.interrupt=A2;tf.prototype.transition=RC;const vm=e=>()=>e;function LC(e,{sourceEvent:t,target:n,transform:i,dispatch:a}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:a}})}function Go(e,t,n){this.k=e,this.x=t,this.y=n}Go.prototype={constructor:Go,scale:function(e){return e===1?this:new Go(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Go(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Yo=new Go(1,0,0);Go.prototype;function m_(e){e.stopImmediatePropagation()}function Nd(e){e.preventDefault(),e.stopImmediatePropagation()}function OC(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function PC(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function _y(){return this.__zoom||Yo}function IC(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function DC(){return navigator.maxTouchPoints||"ontouchstart"in this}function zC(e,t,n){var i=e.invertX(t[0][0])-n[0][0],a=e.invertX(t[1][0])-n[1][0],l=e.invertY(t[0][1])-n[0][1],u=e.invertY(t[1][1])-n[1][1];return e.translate(a>i?(i+a)/2:Math.min(0,i)||Math.max(0,a),u>l?(l+u)/2:Math.min(0,l)||Math.max(0,u))}function Uw(){var e=OC,t=PC,n=zC,i=IC,a=DC,l=[0,1/0],u=[[-1/0,-1/0],[1/0,1/0]],d=250,m=b2,p=ah("start","zoom","end"),g,v,w,x=500,N=150,S=0,R=10;function T(k){k.property("__zoom",_y).on("wheel.zoom",ee,{passive:!1}).on("mousedown.zoom",ae).on("dblclick.zoom",le).filter(a).on("touchstart.zoom",ge).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",C).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}T.transform=function(k,I,P,K){var L=k.selection?k.selection():k;L.property("__zoom",_y),k!==L?G(k,I,P,K):L.interrupt().each(function(){Q(this,arguments).event(K).start().zoom(null,typeof I=="function"?I.apply(this,arguments):I).end()})},T.scaleBy=function(k,I,P,K){T.scaleTo(k,function(){var L=this.__zoom.k,O=typeof I=="function"?I.apply(this,arguments):I;return L*O},P,K)},T.scaleTo=function(k,I,P,K){T.transform(k,function(){var L=t.apply(this,arguments),O=this.__zoom,q=P==null?D(L):typeof P=="function"?P.apply(this,arguments):P,E=O.invert(q),X=typeof I=="function"?I.apply(this,arguments):I;return n(H(z(O,X),q,E),L,u)},P,K)},T.translateBy=function(k,I,P,K){T.transform(k,function(){return n(this.__zoom.translate(typeof I=="function"?I.apply(this,arguments):I,typeof P=="function"?P.apply(this,arguments):P),t.apply(this,arguments),u)},null,K)},T.translateTo=function(k,I,P,K,L){T.transform(k,function(){var O=t.apply(this,arguments),q=this.__zoom,E=K==null?D(O):typeof K=="function"?K.apply(this,arguments):K;return n(Yo.translate(E[0],E[1]).scale(q.k).translate(typeof I=="function"?-I.apply(this,arguments):-I,typeof P=="function"?-P.apply(this,arguments):-P),O,u)},K,L)};function z(k,I){return I=Math.max(l[0],Math.min(l[1],I)),I===k.k?k:new Go(I,k.x,k.y)}function H(k,I,P){var K=I[0]-P[0]*k.k,L=I[1]-P[1]*k.k;return K===k.x&&L===k.y?k:new Go(k.k,K,L)}function D(k){return[(+k[0][0]+ +k[1][0])/2,(+k[0][1]+ +k[1][1])/2]}function G(k,I,P,K){k.on("start.zoom",function(){Q(this,arguments).event(K).start()}).on("interrupt.zoom end.zoom",function(){Q(this,arguments).event(K).end()}).tween("zoom",function(){var L=this,O=arguments,q=Q(L,O).event(K),E=t.apply(L,O),X=P==null?D(E):typeof P=="function"?P.apply(L,O):P,ne=Math.max(E[1][0]-E[0][0],E[1][1]-E[0][1]),ie=L.__zoom,de=typeof I=="function"?I.apply(L,O):I,xe=m(ie.invert(X).concat(ne/ie.k),de.invert(X).concat(ne/de.k));return function(be){if(be===1)be=de;else{var Ee=xe(be),Oe=ne/Ee[2];be=new Go(Oe,X[0]-Ee[0]*Oe,X[1]-Ee[1]*Oe)}q.zoom(null,be)}})}function Q(k,I,P){return!P&&k.__zooming||new Y(k,I)}function Y(k,I){this.that=k,this.args=I,this.active=0,this.sourceEvent=null,this.extent=t.apply(k,I),this.taps=0}Y.prototype={event:function(k){return k&&(this.sourceEvent=k),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(k,I){return this.mouse&&k!=="mouse"&&(this.mouse[1]=I.invert(this.mouse[0])),this.touch0&&k!=="touch"&&(this.touch0[1]=I.invert(this.touch0[0])),this.touch1&&k!=="touch"&&(this.touch1[1]=I.invert(this.touch1[0])),this.that.__zoom=I,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(k){var I=_i(this.that).datum();p.call(k,this.that,new LC(k,{sourceEvent:this.sourceEvent,target:T,transform:this.that.__zoom,dispatch:p}),I)}};function ee(k,...I){if(!e.apply(this,arguments))return;var P=Q(this,I).event(k),K=this.__zoom,L=Math.max(l[0],Math.min(l[1],K.k*Math.pow(2,i.apply(this,arguments)))),O=Ui(k);if(P.wheel)(P.mouse[0][0]!==O[0]||P.mouse[0][1]!==O[1])&&(P.mouse[1]=K.invert(P.mouse[0]=O)),clearTimeout(P.wheel);else{if(K.k===L)return;P.mouse=[O,K.invert(O)],Lm(this),P.start()}Nd(k),P.wheel=setTimeout(q,N),P.zoom("mouse",n(H(z(K,L),P.mouse[0],P.mouse[1]),P.extent,u));function q(){P.wheel=null,P.end()}}function ae(k,...I){if(w||!e.apply(this,arguments))return;var P=k.currentTarget,K=Q(this,I,!0).event(k),L=_i(k.view).on("mousemove.zoom",X,!0).on("mouseup.zoom",ne,!0),O=Ui(k,P),q=k.clientX,E=k.clientY;Cw(k.view),m_(k),K.mouse=[O,this.__zoom.invert(O)],Lm(this),K.start();function X(ie){if(Nd(ie),!K.moved){var de=ie.clientX-q,xe=ie.clientY-E;K.moved=de*de+xe*xe>S}K.event(ie).zoom("mouse",n(H(K.that.__zoom,K.mouse[0]=Ui(ie,P),K.mouse[1]),K.extent,u))}function ne(ie){L.on("mousemove.zoom mouseup.zoom",null),$w(ie.view,K.moved),Nd(ie),K.event(ie).end()}}function le(k,...I){if(e.apply(this,arguments)){var P=this.__zoom,K=Ui(k.changedTouches?k.changedTouches[0]:k,this),L=P.invert(K),O=P.k*(k.shiftKey?.5:2),q=n(H(z(P,O),K,L),t.apply(this,I),u);Nd(k),d>0?_i(this).transition().duration(d).call(G,q,K,k):_i(this).call(T.transform,q,K,k)}}function ge(k,...I){if(e.apply(this,arguments)){var P=k.touches,K=P.length,L=Q(this,I,k.changedTouches.length===K).event(k),O,q,E,X;for(m_(k),q=0;q<K;++q)E=P[q],X=Ui(E,this),X=[X,this.__zoom.invert(X),E.identifier],L.touch0?!L.touch1&&L.touch0[2]!==X[2]&&(L.touch1=X,L.taps=0):(L.touch0=X,O=!0,L.taps=1+!!g);g&&(g=clearTimeout(g)),O&&(L.taps<2&&(v=X[0],g=setTimeout(function(){g=null},x)),Lm(this),L.start())}}function F(k,...I){if(this.__zooming){var P=Q(this,I).event(k),K=k.changedTouches,L=K.length,O,q,E,X;for(Nd(k),O=0;O<L;++O)q=K[O],E=Ui(q,this),P.touch0&&P.touch0[2]===q.identifier?P.touch0[0]=E:P.touch1&&P.touch1[2]===q.identifier&&(P.touch1[0]=E);if(q=P.that.__zoom,P.touch1){var ne=P.touch0[0],ie=P.touch0[1],de=P.touch1[0],xe=P.touch1[1],be=(be=de[0]-ne[0])*be+(be=de[1]-ne[1])*be,Ee=(Ee=xe[0]-ie[0])*Ee+(Ee=xe[1]-ie[1])*Ee;q=z(q,Math.sqrt(be/Ee)),E=[(ne[0]+de[0])/2,(ne[1]+de[1])/2],X=[(ie[0]+xe[0])/2,(ie[1]+xe[1])/2]}else if(P.touch0)E=P.touch0[0],X=P.touch0[1];else return;P.zoom("touch",n(H(q,E,X),P.extent,u))}}function C(k,...I){if(this.__zooming){var P=Q(this,I).event(k),K=k.changedTouches,L=K.length,O,q;for(m_(k),w&&clearTimeout(w),w=setTimeout(function(){w=null},x),O=0;O<L;++O)q=K[O],P.touch0&&P.touch0[2]===q.identifier?delete P.touch0:P.touch1&&P.touch1[2]===q.identifier&&delete P.touch1;if(P.touch1&&!P.touch0&&(P.touch0=P.touch1,delete P.touch1),P.touch0)P.touch0[1]=this.__zoom.invert(P.touch0[0]);else if(P.end(),P.taps===2&&(q=Ui(q,this),Math.hypot(v[0]-q[0],v[1]-q[1])<R)){var E=_i(this).on("dblclick.zoom");E&&E.apply(this,arguments)}}}return T.wheelDelta=function(k){return arguments.length?(i=typeof k=="function"?k:vm(+k),T):i},T.filter=function(k){return arguments.length?(e=typeof k=="function"?k:vm(!!k),T):e},T.touchable=function(k){return arguments.length?(a=typeof k=="function"?k:vm(!!k),T):a},T.extent=function(k){return arguments.length?(t=typeof k=="function"?k:vm([[+k[0][0],+k[0][1]],[+k[1][0],+k[1][1]]]),T):t},T.scaleExtent=function(k){return arguments.length?(l[0]=+k[0],l[1]=+k[1],T):[l[0],l[1]]},T.translateExtent=function(k){return arguments.length?(u[0][0]=+k[0][0],u[1][0]=+k[1][0],u[0][1]=+k[0][1],u[1][1]=+k[1][1],T):[[u[0][0],u[0][1]],[u[1][0],u[1][1]]]},T.constrain=function(k){return arguments.length?(n=k,T):n},T.duration=function(k){return arguments.length?(d=+k,T):d},T.interpolate=function(k){return arguments.length?(m=k,T):m},T.on=function(){var k=p.on.apply(p,arguments);return k===p?T:k},T.clickDistance=function(k){return arguments.length?(S=(k=+k)*k,T):Math.sqrt(S)},T.tapDistance=function(k){return arguments.length?(R=+k,T):R},T}const dh=_.createContext(null),FC=dh.Provider,Zo={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`},Ww=Zo.error001();function An(e,t){const n=_.useContext(dh);if(n===null)throw new Error(Ww);return hw(n,e,t)}const xr=()=>{const e=_.useContext(dh);if(e===null)throw new Error(Ww);return _.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},BC=e=>e.userSelectionActive?"none":"all";function Gd({position:e,children:t,className:n,style:i,...a}){const l=An(BC),u=`${e}`.split("-");return pe.createElement("div",{className:Br(["react-flow__panel",n,...u]),style:{...i,pointerEvents:l},...a},t)}function UC({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:pe.createElement(Gd,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},pe.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const WC=({x:e,y:t,label:n,labelStyle:i={},labelShowBg:a=!0,labelBgStyle:l={},labelBgPadding:u=[2,4],labelBgBorderRadius:d=2,children:m,className:p,...g})=>{const v=_.useRef(null),[w,x]=_.useState({x:0,y:0,width:0,height:0}),N=Br(["react-flow__edge-textwrapper",p]);return _.useEffect(()=>{if(v.current){const S=v.current.getBBox();x({x:S.x,y:S.y,width:S.width,height:S.height})}},[n]),typeof n>"u"||!n?null:pe.createElement("g",{transform:`translate(${e-w.width/2} ${t-w.height/2})`,className:N,visibility:w.width?"visible":"hidden",...g},a&&pe.createElement("rect",{width:w.width+2*u[0],x:-u[0],y:-u[1],height:w.height+2*u[1],className:"react-flow__edge-textbg",style:l,rx:d,ry:d}),pe.createElement("text",{className:"react-flow__edge-text",y:w.height/2,dy:"0.3em",ref:v,style:i},n),m)};var HC=_.memo(WC);const Tg=e=>({width:e.offsetWidth,height:e.offsetHeight}),_u=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Rg=(e={x:0,y:0},t)=>({x:_u(e.x,t[0][0],t[1][0]),y:_u(e.y,t[0][1],t[1][1])}),gy=(e,t,n)=>e<t?_u(Math.abs(e-t),1,50)/50:e>n?-_u(Math.abs(e-n),1,50)/50:0,Hw=(e,t)=>{const n=gy(e.x,35,t.width-35)*20,i=gy(e.y,35,t.height-35)*20;return[n,i]},qw=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},Vw=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Kd=({x:e,y:t,width:n,height:i})=>({x:e,y:t,x2:e+n,y2:t+i}),Gw=({x:e,y:t,x2:n,y2:i})=>({x:e,y:t,width:n-e,height:i-t}),py=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),qC=(e,t)=>Gw(Vw(Kd(e),Kd(t))),Q_=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),i=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*i)},VC=e=>gi(e.width)&&gi(e.height)&&gi(e.x)&&gi(e.y),gi=e=>!isNaN(e)&&isFinite(e),cr=Symbol.for("internals"),Kw=["Enter"," ","Escape"],GC=(e,t)=>{},KC=e=>"nativeEvent"in e;function eg(e){var a,l;const t=KC(e)?e.nativeEvent:e,n=((l=(a=t.composedPath)==null?void 0:a.call(t))==null?void 0:l[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const Yw=e=>"clientX"in e,Qa=(e,t)=>{var l,u;const n=Yw(e),i=n?e.clientX:(l=e.touches)==null?void 0:l[0].clientX,a=n?e.clientY:(u=e.touches)==null?void 0:u[0].clientY;return{x:i-((t==null?void 0:t.left)??0),y:a-((t==null?void 0:t.top)??0)}},Jm=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},rf=({id:e,path:t,labelX:n,labelY:i,label:a,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:m,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x=20})=>pe.createElement(pe.Fragment,null,pe.createElement("path",{id:e,style:g,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:v,markerStart:w}),x&&pe.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:x,className:"react-flow__edge-interaction"}),a&&gi(n)&&gi(i)?pe.createElement(HC,{x:n,y:i,label:a,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:m,labelBgBorderRadius:p}):null);rf.displayName="BaseEdge";function Cd(e,t,n){return n===void 0?n:i=>{const a=t().edges.find(l=>l.id===e);a&&n(i,{...a})}}function Xw({sourceX:e,sourceY:t,targetX:n,targetY:i}){const a=Math.abs(n-e)/2,l=n<e?n+a:n-a,u=Math.abs(i-t)/2,d=i<t?i+u:i-u;return[l,d,a,u]}function Jw({sourceX:e,sourceY:t,targetX:n,targetY:i,sourceControlX:a,sourceControlY:l,targetControlX:u,targetControlY:d}){const m=e*.125+a*.375+u*.375+n*.125,p=t*.125+l*.375+d*.375+i*.125,g=Math.abs(m-e),v=Math.abs(p-t);return[m,p,g,v]}var ic;(function(e){e.Strict="strict",e.Loose="loose"})(ic||(ic={}));var Xl;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Xl||(Xl={}));var Yd;(function(e){e.Partial="partial",e.Full="full"})(Yd||(Yd={}));var Za;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Za||(Za={}));var Xd;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Xd||(Xd={}));var dt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(dt||(dt={}));function yy({pos:e,x1:t,y1:n,x2:i,y2:a}){return e===dt.Left||e===dt.Right?[.5*(t+i),n]:[t,.5*(n+a)]}function Zw({sourceX:e,sourceY:t,sourcePosition:n=dt.Bottom,targetX:i,targetY:a,targetPosition:l=dt.Top}){const[u,d]=yy({pos:n,x1:e,y1:t,x2:i,y2:a}),[m,p]=yy({pos:l,x1:i,y1:a,x2:e,y2:t}),[g,v,w,x]=Jw({sourceX:e,sourceY:t,targetX:i,targetY:a,sourceControlX:u,sourceControlY:d,targetControlX:m,targetControlY:p});return[`M${e},${t} C${u},${d} ${m},${p} ${i},${a}`,g,v,w,x]}const Lg=_.memo(({sourceX:e,sourceY:t,targetX:n,targetY:i,sourcePosition:a=dt.Bottom,targetPosition:l=dt.Top,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:v,style:w,markerEnd:x,markerStart:N,interactionWidth:S})=>{const[R,T,z]=Zw({sourceX:e,sourceY:t,sourcePosition:a,targetX:n,targetY:i,targetPosition:l});return pe.createElement(rf,{path:R,labelX:T,labelY:z,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:v,style:w,markerEnd:x,markerStart:N,interactionWidth:S})});Lg.displayName="SimpleBezierEdge";const vy={[dt.Left]:{x:-1,y:0},[dt.Right]:{x:1,y:0},[dt.Top]:{x:0,y:-1},[dt.Bottom]:{x:0,y:1}},YC=({source:e,sourcePosition:t=dt.Bottom,target:n})=>t===dt.Left||t===dt.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},wy=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function XC({source:e,sourcePosition:t=dt.Bottom,target:n,targetPosition:i=dt.Top,center:a,offset:l}){const u=vy[t],d=vy[i],m={x:e.x+u.x*l,y:e.y+u.y*l},p={x:n.x+d.x*l,y:n.y+d.y*l},g=YC({source:m,sourcePosition:t,target:p}),v=g.x!==0?"x":"y",w=g[v];let x=[],N,S;const R={x:0,y:0},T={x:0,y:0},[z,H,D,G]=Xw({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(u[v]*d[v]===-1){N=a.x||z,S=a.y||H;const Y=[{x:N,y:m.y},{x:N,y:p.y}],ee=[{x:m.x,y:S},{x:p.x,y:S}];u[v]===w?x=v==="x"?Y:ee:x=v==="x"?ee:Y}else{const Y=[{x:m.x,y:p.y}],ee=[{x:p.x,y:m.y}];if(v==="x"?x=u.x===w?ee:Y:x=u.y===w?Y:ee,t===i){const C=Math.abs(e[v]-n[v]);if(C<=l){const k=Math.min(l-1,l-C);u[v]===w?R[v]=(m[v]>e[v]?-1:1)*k:T[v]=(p[v]>n[v]?-1:1)*k}}if(t!==i){const C=v==="x"?"y":"x",k=u[v]===d[C],I=m[C]>p[C],P=m[C]<p[C];(u[v]===1&&(!k&&I||k&&P)||u[v]!==1&&(!k&&P||k&&I))&&(x=v==="x"?Y:ee)}const ae={x:m.x+R.x,y:m.y+R.y},le={x:p.x+T.x,y:p.y+T.y},ge=Math.max(Math.abs(ae.x-x[0].x),Math.abs(le.x-x[0].x)),F=Math.max(Math.abs(ae.y-x[0].y),Math.abs(le.y-x[0].y));ge>=F?(N=(ae.x+le.x)/2,S=x[0].y):(N=x[0].x,S=(ae.y+le.y)/2)}return[[e,{x:m.x+R.x,y:m.y+R.y},...x,{x:p.x+T.x,y:p.y+T.y},n],N,S,D,G]}function JC(e,t,n,i){const a=Math.min(wy(e,t)/2,wy(t,n)/2,i),{x:l,y:u}=t;if(e.x===l&&l===n.x||e.y===u&&u===n.y)return`L${l} ${u}`;if(e.y===u){const p=e.x<n.x?-1:1,g=e.y<n.y?1:-1;return`L ${l+a*p},${u}Q ${l},${u} ${l},${u+a*g}`}const d=e.x<n.x?1:-1,m=e.y<n.y?-1:1;return`L ${l},${u+a*m}Q ${l},${u} ${l+a*d},${u}`}function tg({sourceX:e,sourceY:t,sourcePosition:n=dt.Bottom,targetX:i,targetY:a,targetPosition:l=dt.Top,borderRadius:u=5,centerX:d,centerY:m,offset:p=20}){const[g,v,w,x,N]=XC({source:{x:e,y:t},sourcePosition:n,target:{x:i,y:a},targetPosition:l,center:{x:d,y:m},offset:p});return[g.reduce((R,T,z)=>{let H="";return z>0&&z<g.length-1?H=JC(g[z-1],T,g[z+1],u):H=`${z===0?"M":"L"}${T.x} ${T.y}`,R+=H,R},""),v,w,x,N]}const fh=_.memo(({sourceX:e,sourceY:t,targetX:n,targetY:i,label:a,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:m,labelBgBorderRadius:p,style:g,sourcePosition:v=dt.Bottom,targetPosition:w=dt.Top,markerEnd:x,markerStart:N,pathOptions:S,interactionWidth:R})=>{const[T,z,H]=tg({sourceX:e,sourceY:t,sourcePosition:v,targetX:n,targetY:i,targetPosition:w,borderRadius:S==null?void 0:S.borderRadius,offset:S==null?void 0:S.offset});return pe.createElement(rf,{path:T,labelX:z,labelY:H,label:a,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:m,labelBgBorderRadius:p,style:g,markerEnd:x,markerStart:N,interactionWidth:R})});fh.displayName="SmoothStepEdge";const Og=_.memo(e=>{var t;return pe.createElement(fh,{...e,pathOptions:_.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});Og.displayName="StepEdge";function ZC({sourceX:e,sourceY:t,targetX:n,targetY:i}){const[a,l,u,d]=Xw({sourceX:e,sourceY:t,targetX:n,targetY:i});return[`M ${e},${t}L ${n},${i}`,a,l,u,d]}const Pg=_.memo(({sourceX:e,sourceY:t,targetX:n,targetY:i,label:a,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:m,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x})=>{const[N,S,R]=ZC({sourceX:e,sourceY:t,targetX:n,targetY:i});return pe.createElement(rf,{path:N,labelX:S,labelY:R,label:a,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:m,labelBgBorderRadius:p,style:g,markerEnd:v,markerStart:w,interactionWidth:x})});Pg.displayName="StraightEdge";function wm(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function xy({pos:e,x1:t,y1:n,x2:i,y2:a,c:l}){switch(e){case dt.Left:return[t-wm(t-i,l),n];case dt.Right:return[t+wm(i-t,l),n];case dt.Top:return[t,n-wm(n-a,l)];case dt.Bottom:return[t,n+wm(a-n,l)]}}function Qw({sourceX:e,sourceY:t,sourcePosition:n=dt.Bottom,targetX:i,targetY:a,targetPosition:l=dt.Top,curvature:u=.25}){const[d,m]=xy({pos:n,x1:e,y1:t,x2:i,y2:a,c:u}),[p,g]=xy({pos:l,x1:i,y1:a,x2:e,y2:t,c:u}),[v,w,x,N]=Jw({sourceX:e,sourceY:t,targetX:i,targetY:a,sourceControlX:d,sourceControlY:m,targetControlX:p,targetControlY:g});return[`M${e},${t} C${d},${m} ${p},${g} ${i},${a}`,v,w,x,N]}const Zm=_.memo(({sourceX:e,sourceY:t,targetX:n,targetY:i,sourcePosition:a=dt.Bottom,targetPosition:l=dt.Top,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:v,style:w,markerEnd:x,markerStart:N,pathOptions:S,interactionWidth:R})=>{const[T,z,H]=Qw({sourceX:e,sourceY:t,sourcePosition:a,targetX:n,targetY:i,targetPosition:l,curvature:S==null?void 0:S.curvature});return pe.createElement(rf,{path:T,labelX:z,labelY:H,label:u,labelStyle:d,labelShowBg:m,labelBgStyle:p,labelBgPadding:g,labelBgBorderRadius:v,style:w,markerEnd:x,markerStart:N,interactionWidth:R})});Zm.displayName="BezierEdge";const Ig=_.createContext(null),QC=Ig.Provider;Ig.Consumer;const e$=()=>_.useContext(Ig),t$=e=>"id"in e&&"source"in e&&"target"in e,n$=({source:e,sourceHandle:t,target:n,targetHandle:i})=>`reactflow__edge-${e}${t||""}-${n}${i||""}`,ng=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(i=>`${i}=${e[i]}`).join("&")}`,r$=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),s$=(e,t)=>{if(!e.source||!e.target)return t;let n;return t$(e)?n={...e}:n={...e,id:n$(e)},r$(n,t)?t:t.concat(n)},rg=({x:e,y:t},[n,i,a],l,[u,d])=>{const m={x:(e-n)/a,y:(t-i)/a};return l?{x:u*Math.round(m.x/u),y:d*Math.round(m.y/d)}:m},ex=({x:e,y:t},[n,i,a])=>({x:e*a+n,y:t*a+i}),tc=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],i=(e.height??0)*t[1],a={x:e.position.x-n,y:e.position.y-i};return{...a,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-i}:a}},mh=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((i,a)=>{const{x:l,y:u}=tc(a,t).positionAbsolute;return Vw(i,Kd({x:l,y:u,width:a.width||0,height:a.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Gw(n)},tx=(e,t,[n,i,a]=[0,0,1],l=!1,u=!1,d=[0,0])=>{const m={x:(t.x-n)/a,y:(t.y-i)/a,width:t.width/a,height:t.height/a},p=[];return e.forEach(g=>{const{width:v,height:w,selectable:x=!0,hidden:N=!1}=g;if(u&&!x||N)return!1;const{positionAbsolute:S}=tc(g,d),R={x:S.x,y:S.y,width:v||0,height:w||0},T=Q_(m,R),z=typeof v>"u"||typeof w>"u"||v===null||w===null,H=l&&T>0,D=(v||0)*(w||0);(z||H||T>=D||g.dragging)&&p.push(g)}),p},nx=(e,t)=>{const n=e.map(i=>i.id);return t.filter(i=>n.includes(i.source)||n.includes(i.target))},rx=(e,t,n,i,a,l=.1)=>{const u=t/(e.width*(1+l)),d=n/(e.height*(1+l)),m=Math.min(u,d),p=_u(m,i,a),g=e.x+e.width/2,v=e.y+e.height/2,w=t/2-g*p,x=n/2-v*p;return{x:w,y:x,zoom:p}},ql=(e,t=0)=>e.transition().duration(t);function by(e,t,n,i){return(t[n]||[]).reduce((a,l)=>{var u,d;return`${e.id}-${l.id}-${n}`!==i&&a.push({id:l.id||null,type:n,nodeId:e.id,x:(((u=e.positionAbsolute)==null?void 0:u.x)??0)+l.x+l.width/2,y:(((d=e.positionAbsolute)==null?void 0:d.y)??0)+l.y+l.height/2}),a},[])}function i$(e,t,n,i,a,l){const{x:u,y:d}=Qa(e),p=t.elementsFromPoint(u,d).find(N=>N.classList.contains("react-flow__handle"));if(p){const N=p.getAttribute("data-nodeid");if(N){const S=Dg(void 0,p),R=p.getAttribute("data-handleid"),T=l({nodeId:N,id:R,type:S});if(T){const z=a.find(H=>H.nodeId===N&&H.type===S&&H.id===R);return{handle:{id:R,type:S,nodeId:N,x:(z==null?void 0:z.x)||n.x,y:(z==null?void 0:z.y)||n.y},validHandleResult:T}}}}let g=[],v=1/0;if(a.forEach(N=>{const S=Math.sqrt((N.x-n.x)**2+(N.y-n.y)**2);if(S<=i){const R=l(N);S<=v&&(S<v?g=[{handle:N,validHandleResult:R}]:S===v&&g.push({handle:N,validHandleResult:R}),v=S)}}),!g.length)return{handle:null,validHandleResult:sx()};if(g.length===1)return g[0];const w=g.some(({validHandleResult:N})=>N.isValid),x=g.some(({handle:N})=>N.type==="target");return g.find(({handle:N,validHandleResult:S})=>x?N.type==="target":w?S.isValid:!0)||g[0]}const o$={source:null,target:null,sourceHandle:null,targetHandle:null},sx=()=>({handleDomNode:null,isValid:!1,connection:o$,endHandle:null});function ix(e,t,n,i,a,l,u){const d=a==="target",m=u.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),p={...sx(),handleDomNode:m};if(m){const g=Dg(void 0,m),v=m.getAttribute("data-nodeid"),w=m.getAttribute("data-handleid"),x=m.classList.contains("connectable"),N=m.classList.contains("connectableend"),S={source:d?v:n,sourceHandle:d?w:i,target:d?n:v,targetHandle:d?i:w};p.connection=S,x&&N&&(t===ic.Strict?d&&g==="source"||!d&&g==="target":v!==n||w!==i)&&(p.endHandle={nodeId:v,handleId:w,type:g},p.isValid=l(S))}return p}function a$({nodes:e,nodeId:t,handleId:n,handleType:i}){return e.reduce((a,l)=>{if(l[cr]){const{handleBounds:u}=l[cr];let d=[],m=[];u&&(d=by(l,u,"source",`${t}-${n}-${i}`),m=by(l,u,"target",`${t}-${n}-${i}`)),a.push(...d,...m)}return a},[])}function Dg(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function h_(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function l$(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function ox({event:e,handleId:t,nodeId:n,onConnect:i,isTarget:a,getState:l,setState:u,isValidConnection:d,edgeUpdaterType:m,onEdgeUpdateEnd:p}){const g=qw(e.target),{connectionMode:v,domNode:w,autoPanOnConnect:x,connectionRadius:N,onConnectStart:S,panBy:R,getNodes:T,cancelConnection:z}=l();let H=0,D;const{x:G,y:Q}=Qa(e),Y=g==null?void 0:g.elementFromPoint(G,Q),ee=Dg(m,Y),ae=w==null?void 0:w.getBoundingClientRect();if(!ae||!ee)return;let le,ge=Qa(e,ae),F=!1,C=null,k=!1,I=null;const P=a$({nodes:T(),nodeId:n,handleId:t,handleType:ee}),K=()=>{if(!x)return;const[q,E]=Hw(ge,ae);R({x:q,y:E}),H=requestAnimationFrame(K)};u({connectionPosition:ge,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:ee,connectionStartHandle:{nodeId:n,handleId:t,type:ee},connectionEndHandle:null}),S==null||S(e,{nodeId:n,handleId:t,handleType:ee});function L(q){const{transform:E}=l();ge=Qa(q,ae);const{handle:X,validHandleResult:ne}=i$(q,g,rg(ge,E,!1,[1,1]),N,P,ie=>ix(ie,v,n,t,a?"target":"source",d,g));if(D=X,F||(K(),F=!0),I=ne.handleDomNode,C=ne.connection,k=ne.isValid,u({connectionPosition:D&&k?ex({x:D.x,y:D.y},E):ge,connectionStatus:l$(!!D,k),connectionEndHandle:ne.endHandle}),!D&&!k&&!I)return h_(le);C.source!==C.target&&I&&(h_(le),le=I,I.classList.add("connecting","react-flow__handle-connecting"),I.classList.toggle("valid",k),I.classList.toggle("react-flow__handle-valid",k))}function O(q){var E,X;(D||I)&&C&&k&&(i==null||i(C)),(X=(E=l()).onConnectEnd)==null||X.call(E,q),m&&(p==null||p(q)),h_(le),z(),cancelAnimationFrame(H),F=!1,k=!1,C=null,I=null,g.removeEventListener("mousemove",L),g.removeEventListener("mouseup",O),g.removeEventListener("touchmove",L),g.removeEventListener("touchend",O)}g.addEventListener("mousemove",L),g.addEventListener("mouseup",O),g.addEventListener("touchmove",L),g.addEventListener("touchend",O)}const jy=()=>!0,c$=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),u$=(e,t,n)=>i=>{const{connectionStartHandle:a,connectionEndHandle:l,connectionClickStartHandle:u}=i;return{connecting:(a==null?void 0:a.nodeId)===e&&(a==null?void 0:a.handleId)===t&&(a==null?void 0:a.type)===n||(l==null?void 0:l.nodeId)===e&&(l==null?void 0:l.handleId)===t&&(l==null?void 0:l.type)===n,clickConnecting:(u==null?void 0:u.nodeId)===e&&(u==null?void 0:u.handleId)===t&&(u==null?void 0:u.type)===n}},ax=_.forwardRef(({type:e="source",position:t=dt.Top,isValidConnection:n,isConnectable:i=!0,isConnectableStart:a=!0,isConnectableEnd:l=!0,id:u,onConnect:d,children:m,className:p,onMouseDown:g,onTouchStart:v,...w},x)=>{var ae,le;const N=u||null,S=e==="target",R=xr(),T=e$(),{connectOnClick:z,noPanClassName:H}=An(c$,Rr),{connecting:D,clickConnecting:G}=An(u$(T,N,e),Rr);T||(le=(ae=R.getState()).onError)==null||le.call(ae,"010",Zo.error010());const Q=ge=>{const{defaultEdgeOptions:F,onConnect:C,hasDefaultEdges:k}=R.getState(),I={...F,...ge};if(k){const{edges:P,setEdges:K}=R.getState();K(s$(I,P))}C==null||C(I),d==null||d(I)},Y=ge=>{if(!T)return;const F=Yw(ge);a&&(F&&ge.button===0||!F)&&ox({event:ge,handleId:N,nodeId:T,onConnect:Q,isTarget:S,getState:R.getState,setState:R.setState,isValidConnection:n||R.getState().isValidConnection||jy}),F?g==null||g(ge):v==null||v(ge)},ee=ge=>{const{onClickConnectStart:F,onClickConnectEnd:C,connectionClickStartHandle:k,connectionMode:I,isValidConnection:P}=R.getState();if(!T||!k&&!a)return;if(!k){F==null||F(ge,{nodeId:T,handleId:N,handleType:e}),R.setState({connectionClickStartHandle:{nodeId:T,type:e,handleId:N}});return}const K=qw(ge.target),L=n||P||jy,{connection:O,isValid:q}=ix({nodeId:T,id:N,type:e},I,k.nodeId,k.handleId||null,k.type,L,K);q&&Q(O),C==null||C(ge),R.setState({connectionClickStartHandle:null})};return pe.createElement("div",{"data-handleid":N,"data-nodeid":T,"data-handlepos":t,"data-id":`${T}-${N}-${e}`,className:Br(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",H,p,{source:!S,target:S,connectable:i,connectablestart:a,connectableend:l,connecting:G,connectionindicator:i&&(a&&!D||l&&D)}]),onMouseDown:Y,onTouchStart:Y,onClick:z?ee:void 0,ref:x,...w},m)});ax.displayName="Handle";var Qm=_.memo(ax);const lx=({data:e,isConnectable:t,targetPosition:n=dt.Top,sourcePosition:i=dt.Bottom})=>pe.createElement(pe.Fragment,null,pe.createElement(Qm,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,pe.createElement(Qm,{type:"source",position:i,isConnectable:t}));lx.displayName="DefaultNode";var sg=_.memo(lx);const cx=({data:e,isConnectable:t,sourcePosition:n=dt.Bottom})=>pe.createElement(pe.Fragment,null,e==null?void 0:e.label,pe.createElement(Qm,{type:"source",position:n,isConnectable:t}));cx.displayName="InputNode";var ux=_.memo(cx);const dx=({data:e,isConnectable:t,targetPosition:n=dt.Top})=>pe.createElement(pe.Fragment,null,pe.createElement(Qm,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);dx.displayName="OutputNode";var fx=_.memo(dx);const zg=()=>null;zg.displayName="GroupNode";const d$=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected)}),xm=e=>e.id;function f$(e,t){return Rr(e.selectedNodes.map(xm),t.selectedNodes.map(xm))&&Rr(e.selectedEdges.map(xm),t.selectedEdges.map(xm))}const mx=_.memo(({onSelectionChange:e})=>{const t=xr(),{selectedNodes:n,selectedEdges:i}=An(d$,f$);return _.useEffect(()=>{const a={nodes:n,edges:i};e==null||e(a),t.getState().onSelectionChange.forEach(l=>l(a))},[n,i,e]),null});mx.displayName="SelectionListener";const m$=e=>!!e.onSelectionChange;function h$({onSelectionChange:e}){const t=An(m$);return e||t?pe.createElement(mx,{onSelectionChange:e}):null}const _$=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function Yc(e,t){_.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function qt(e,t,n){_.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const g$=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,onConnect:a,onConnectStart:l,onConnectEnd:u,onClickConnectStart:d,onClickConnectEnd:m,nodesDraggable:p,nodesConnectable:g,nodesFocusable:v,edgesFocusable:w,edgesUpdatable:x,elevateNodesOnSelect:N,minZoom:S,maxZoom:R,nodeExtent:T,onNodesChange:z,onEdgesChange:H,elementsSelectable:D,connectionMode:G,snapGrid:Q,snapToGrid:Y,translateExtent:ee,connectOnClick:ae,defaultEdgeOptions:le,fitView:ge,fitViewOptions:F,onNodesDelete:C,onEdgesDelete:k,onNodeDrag:I,onNodeDragStart:P,onNodeDragStop:K,onSelectionDrag:L,onSelectionDragStart:O,onSelectionDragStop:q,noPanClassName:E,nodeOrigin:X,rfId:ne,autoPanOnConnect:ie,autoPanOnNodeDrag:de,onError:xe,connectionRadius:be,isValidConnection:Ee,nodeDragThreshold:Oe})=>{const{setNodes:He,setEdges:Ke,setDefaultNodesAndEdges:Ct,setMinZoom:pt,setMaxZoom:gt,setTranslateExtent:yt,setNodeExtent:nt,reset:$e}=An(_$,Rr),Re=xr();return _.useEffect(()=>{const ot=i==null?void 0:i.map(he=>({...he,...le}));return Ct(n,ot),()=>{$e()}},[]),qt("defaultEdgeOptions",le,Re.setState),qt("connectionMode",G,Re.setState),qt("onConnect",a,Re.setState),qt("onConnectStart",l,Re.setState),qt("onConnectEnd",u,Re.setState),qt("onClickConnectStart",d,Re.setState),qt("onClickConnectEnd",m,Re.setState),qt("nodesDraggable",p,Re.setState),qt("nodesConnectable",g,Re.setState),qt("nodesFocusable",v,Re.setState),qt("edgesFocusable",w,Re.setState),qt("edgesUpdatable",x,Re.setState),qt("elementsSelectable",D,Re.setState),qt("elevateNodesOnSelect",N,Re.setState),qt("snapToGrid",Y,Re.setState),qt("snapGrid",Q,Re.setState),qt("onNodesChange",z,Re.setState),qt("onEdgesChange",H,Re.setState),qt("connectOnClick",ae,Re.setState),qt("fitViewOnInit",ge,Re.setState),qt("fitViewOnInitOptions",F,Re.setState),qt("onNodesDelete",C,Re.setState),qt("onEdgesDelete",k,Re.setState),qt("onNodeDrag",I,Re.setState),qt("onNodeDragStart",P,Re.setState),qt("onNodeDragStop",K,Re.setState),qt("onSelectionDrag",L,Re.setState),qt("onSelectionDragStart",O,Re.setState),qt("onSelectionDragStop",q,Re.setState),qt("noPanClassName",E,Re.setState),qt("nodeOrigin",X,Re.setState),qt("rfId",ne,Re.setState),qt("autoPanOnConnect",ie,Re.setState),qt("autoPanOnNodeDrag",de,Re.setState),qt("onError",xe,Re.setState),qt("connectionRadius",be,Re.setState),qt("isValidConnection",Ee,Re.setState),qt("nodeDragThreshold",Oe,Re.setState),Yc(e,He),Yc(t,Ke),Yc(S,pt),Yc(R,gt),Yc(ee,yt),Yc(T,nt),null},Sy={display:"none"},p$={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},hx="react-flow__node-desc",_x="react-flow__edge-desc",y$="react-flow__aria-live",v$=e=>e.ariaLiveMessage;function w$({rfId:e}){const t=An(v$);return pe.createElement("div",{id:`${y$}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:p$},t)}function x$({rfId:e,disableKeyboardA11y:t}){return pe.createElement(pe.Fragment,null,pe.createElement("div",{id:`${hx}-${e}`,style:Sy},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),pe.createElement("div",{id:`${_x}-${e}`,style:Sy},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&pe.createElement(w$,{rfId:e}))}var Jd=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,i]=_.useState(!1),a=_.useRef(!1),l=_.useRef(new Set([])),[u,d]=_.useMemo(()=>{if(e!==null){const p=(Array.isArray(e)?e:[e]).filter(v=>typeof v=="string").map(v=>v.split("+")),g=p.reduce((v,w)=>v.concat(...w),[]);return[p,g]}return[[],[]]},[e]);return _.useEffect(()=>{const m=typeof document<"u"?document:null,p=(t==null?void 0:t.target)||m;if(e!==null){const g=x=>{if(a.current=x.ctrlKey||x.metaKey||x.shiftKey,(!a.current||a.current&&!t.actInsideInputWithModifier)&&eg(x))return!1;const S=Ny(x.code,d);l.current.add(x[S]),ky(u,l.current,!1)&&(x.preventDefault(),i(!0))},v=x=>{if((!a.current||a.current&&!t.actInsideInputWithModifier)&&eg(x))return!1;const S=Ny(x.code,d);ky(u,l.current,!0)?(i(!1),l.current.clear()):l.current.delete(x[S]),x.key==="Meta"&&l.current.clear(),a.current=!1},w=()=>{l.current.clear(),i(!1)};return p==null||p.addEventListener("keydown",g),p==null||p.addEventListener("keyup",v),window.addEventListener("blur",w),()=>{p==null||p.removeEventListener("keydown",g),p==null||p.removeEventListener("keyup",v),window.removeEventListener("blur",w)}}},[e,i]),n};function ky(e,t,n){return e.filter(i=>n||i.length===t.size).some(i=>i.every(a=>t.has(a)))}function Ny(e,t){return t.includes(e)?"code":"key"}function gx(e,t,n,i){var u,d;if(!e.parentNode)return n;const a=t.get(e.parentNode),l=tc(a,i);return gx(a,t,{x:(n.x??0)+l.x,y:(n.y??0)+l.y,z:(((u=a[cr])==null?void 0:u.z)??0)>(n.z??0)?((d=a[cr])==null?void 0:d.z)??0:n.z??0},i)}function px(e,t,n){e.forEach(i=>{var a;if(i.parentNode&&!e.has(i.parentNode))throw new Error(`Parent node ${i.parentNode} not found`);if(i.parentNode||n!=null&&n[i.id]){const{x:l,y:u,z:d}=gx(i,e,{...i.position,z:((a=i[cr])==null?void 0:a.z)??0},t);i.positionAbsolute={x:l,y:u},i[cr].z=d,n!=null&&n[i.id]&&(i[cr].isParent=!0)}})}function __(e,t,n,i){const a=new Map,l={},u=i?1e3:0;return e.forEach(d=>{var w;const m=(gi(d.zIndex)?d.zIndex:0)+(d.selected?u:0),p=t.get(d.id),g={...d,positionAbsolute:{x:d.position.x,y:d.position.y}};d.parentNode&&(l[d.parentNode]=!0);const v=(p==null?void 0:p.type)&&(p==null?void 0:p.type)!==d.type;Object.defineProperty(g,cr,{enumerable:!1,value:{handleBounds:v||(w=p==null?void 0:p[cr])==null?void 0:w.handleBounds,z:m}}),a.set(d.id,g)}),px(a,n,l),a}function yx(e,t={}){const{getNodes:n,width:i,height:a,minZoom:l,maxZoom:u,d3Zoom:d,d3Selection:m,fitViewOnInitDone:p,fitViewOnInit:g,nodeOrigin:v}=e(),w=t.initial&&!p&&g;if(d&&m&&(w||!t.initial)){const N=n().filter(R=>{var z;const T=t.includeHiddenNodes?R.width&&R.height:!R.hidden;return(z=t.nodes)!=null&&z.length?T&&t.nodes.some(H=>H.id===R.id):T}),S=N.every(R=>R.width&&R.height);if(N.length>0&&S){const R=mh(N,v),{x:T,y:z,zoom:H}=rx(R,i,a,t.minZoom??l,t.maxZoom??u,t.padding??.1),D=Yo.translate(T,z).scale(H);return typeof t.duration=="number"&&t.duration>0?d.transform(ql(m,t.duration),D):d.transform(m,D),!0}}return!1}function b$(e,t){return e.forEach(n=>{const i=t.get(n.id);i&&t.set(i.id,{...i,[cr]:i[cr],selected:n.selected})}),new Map(t)}function j$(e,t){return t.map(n=>{const i=e.find(a=>a.id===n.id);return i&&(n.selected=i.selected),n})}function bm({changedNodes:e,changedEdges:t,get:n,set:i}){const{nodeInternals:a,edges:l,onNodesChange:u,onEdgesChange:d,hasDefaultNodes:m,hasDefaultEdges:p}=n();e!=null&&e.length&&(m&&i({nodeInternals:b$(e,a)}),u==null||u(e)),t!=null&&t.length&&(p&&i({edges:j$(t,l)}),d==null||d(t))}const Xc=()=>{},S$={zoomIn:Xc,zoomOut:Xc,zoomTo:Xc,getZoom:()=>1,setViewport:Xc,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:Xc,fitBounds:Xc,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},k$=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),N$=()=>{const e=xr(),{d3Zoom:t,d3Selection:n}=An(k$,Rr);return _.useMemo(()=>n&&t?{zoomIn:a=>t.scaleBy(ql(n,a==null?void 0:a.duration),1.2),zoomOut:a=>t.scaleBy(ql(n,a==null?void 0:a.duration),1/1.2),zoomTo:(a,l)=>t.scaleTo(ql(n,l==null?void 0:l.duration),a),getZoom:()=>e.getState().transform[2],setViewport:(a,l)=>{const[u,d,m]=e.getState().transform,p=Yo.translate(a.x??u,a.y??d).scale(a.zoom??m);t.transform(ql(n,l==null?void 0:l.duration),p)},getViewport:()=>{const[a,l,u]=e.getState().transform;return{x:a,y:l,zoom:u}},fitView:a=>yx(e.getState,a),setCenter:(a,l,u)=>{const{width:d,height:m,maxZoom:p}=e.getState(),g=typeof(u==null?void 0:u.zoom)<"u"?u.zoom:p,v=d/2-a*g,w=m/2-l*g,x=Yo.translate(v,w).scale(g);t.transform(ql(n,u==null?void 0:u.duration),x)},fitBounds:(a,l)=>{const{width:u,height:d,minZoom:m,maxZoom:p}=e.getState(),{x:g,y:v,zoom:w}=rx(a,u,d,m,p,(l==null?void 0:l.padding)??.1),x=Yo.translate(g,v).scale(w);t.transform(ql(n,l==null?void 0:l.duration),x)},project:a=>{const{transform:l,snapToGrid:u,snapGrid:d}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),rg(a,l,u,d)},screenToFlowPosition:a=>{const{transform:l,snapToGrid:u,snapGrid:d,domNode:m}=e.getState();if(!m)return a;const{x:p,y:g}=m.getBoundingClientRect(),v={x:a.x-p,y:a.y-g};return rg(v,l,u,d)},flowToScreenPosition:a=>{const{transform:l,domNode:u}=e.getState();if(!u)return a;const{x:d,y:m}=u.getBoundingClientRect(),p=ex(a,l);return{x:p.x+d,y:p.y+m}},viewportInitialized:!0}:S$,[t,n])};function Fg(){const e=N$(),t=xr(),n=_.useCallback(()=>t.getState().getNodes().map(S=>({...S})),[]),i=_.useCallback(S=>t.getState().nodeInternals.get(S),[]),a=_.useCallback(()=>{const{edges:S=[]}=t.getState();return S.map(R=>({...R}))},[]),l=_.useCallback(S=>{const{edges:R=[]}=t.getState();return R.find(T=>T.id===S)},[]),u=_.useCallback(S=>{const{getNodes:R,setNodes:T,hasDefaultNodes:z,onNodesChange:H}=t.getState(),D=R(),G=typeof S=="function"?S(D):S;if(z)T(G);else if(H){const Q=G.length===0?D.map(Y=>({type:"remove",id:Y.id})):G.map(Y=>({item:Y,type:"reset"}));H(Q)}},[]),d=_.useCallback(S=>{const{edges:R=[],setEdges:T,hasDefaultEdges:z,onEdgesChange:H}=t.getState(),D=typeof S=="function"?S(R):S;if(z)T(D);else if(H){const G=D.length===0?R.map(Q=>({type:"remove",id:Q.id})):D.map(Q=>({item:Q,type:"reset"}));H(G)}},[]),m=_.useCallback(S=>{const R=Array.isArray(S)?S:[S],{getNodes:T,setNodes:z,hasDefaultNodes:H,onNodesChange:D}=t.getState();if(H){const Q=[...T(),...R];z(Q)}else if(D){const G=R.map(Q=>({item:Q,type:"add"}));D(G)}},[]),p=_.useCallback(S=>{const R=Array.isArray(S)?S:[S],{edges:T=[],setEdges:z,hasDefaultEdges:H,onEdgesChange:D}=t.getState();if(H)z([...T,...R]);else if(D){const G=R.map(Q=>({item:Q,type:"add"}));D(G)}},[]),g=_.useCallback(()=>{const{getNodes:S,edges:R=[],transform:T}=t.getState(),[z,H,D]=T;return{nodes:S().map(G=>({...G})),edges:R.map(G=>({...G})),viewport:{x:z,y:H,zoom:D}}},[]),v=_.useCallback(({nodes:S,edges:R})=>{const{nodeInternals:T,getNodes:z,edges:H,hasDefaultNodes:D,hasDefaultEdges:G,onNodesDelete:Q,onEdgesDelete:Y,onNodesChange:ee,onEdgesChange:ae}=t.getState(),le=(S||[]).map(I=>I.id),ge=(R||[]).map(I=>I.id),F=z().reduce((I,P)=>{const K=!le.includes(P.id)&&P.parentNode&&I.find(O=>O.id===P.parentNode);return(typeof P.deletable=="boolean"?P.deletable:!0)&&(le.includes(P.id)||K)&&I.push(P),I},[]),C=H.filter(I=>typeof I.deletable=="boolean"?I.deletable:!0),k=C.filter(I=>ge.includes(I.id));if(F||k){const I=nx(F,C),P=[...k,...I],K=P.reduce((L,O)=>(L.includes(O.id)||L.push(O.id),L),[]);if((G||D)&&(G&&t.setState({edges:H.filter(L=>!K.includes(L.id))}),D&&(F.forEach(L=>{T.delete(L.id)}),t.setState({nodeInternals:new Map(T)}))),K.length>0&&(Y==null||Y(P),ae&&ae(K.map(L=>({id:L,type:"remove"})))),F.length>0&&(Q==null||Q(F),ee)){const L=F.map(O=>({id:O.id,type:"remove"}));ee(L)}}},[]),w=_.useCallback(S=>{const R=VC(S),T=R?null:t.getState().nodeInternals.get(S.id);return!R&&!T?[null,null,R]:[R?S:py(T),T,R]},[]),x=_.useCallback((S,R=!0,T)=>{const[z,H,D]=w(S);return z?(T||t.getState().getNodes()).filter(G=>{if(!D&&(G.id===H.id||!G.positionAbsolute))return!1;const Q=py(G),Y=Q_(Q,z);return R&&Y>0||Y>=z.width*z.height}):[]},[]),N=_.useCallback((S,R,T=!0)=>{const[z]=w(S);if(!z)return!1;const H=Q_(z,R);return T&&H>0||H>=z.width*z.height},[]);return _.useMemo(()=>({...e,getNodes:n,getNode:i,getEdges:a,getEdge:l,setNodes:u,setEdges:d,addNodes:m,addEdges:p,toObject:g,deleteElements:v,getIntersectingNodes:x,isNodeIntersecting:N}),[e,n,i,a,l,u,d,m,p,g,v,x,N])}const C$={actInsideInputWithModifier:!1};var $$=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=xr(),{deleteElements:i}=Fg(),a=Jd(e,C$),l=Jd(t);_.useEffect(()=>{if(a){const{edges:u,getNodes:d}=n.getState(),m=d().filter(g=>g.selected),p=u.filter(g=>g.selected);i({nodes:m,edges:p}),n.setState({nodesSelectionActive:!1})}},[a]),_.useEffect(()=>{n.setState({multiSelectionActive:l})},[l])};function E$(e){const t=xr();_.useEffect(()=>{let n;const i=()=>{var l,u;if(!e.current)return;const a=Tg(e.current);(a.height===0||a.width===0)&&((u=(l=t.getState()).onError)==null||u.call(l,"004",Zo.error004())),t.setState({width:a.width||500,height:a.height||500})};return i(),window.addEventListener("resize",i),e.current&&(n=new ResizeObserver(()=>i()),n.observe(e.current)),()=>{window.removeEventListener("resize",i),n&&e.current&&n.unobserve(e.current)}},[])}const Bg={position:"absolute",width:"100%",height:"100%",top:0,left:0},A$=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,jm=e=>({x:e.x,y:e.y,zoom:e.k}),Jc=(e,t)=>e.target.closest(`.${t}`),Cy=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),$y=e=>{const t=e.ctrlKey&&Jm()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},M$=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),T$=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:i,zoomOnScroll:a=!0,zoomOnPinch:l=!0,panOnScroll:u=!1,panOnScrollSpeed:d=.5,panOnScrollMode:m=Xl.Free,zoomOnDoubleClick:p=!0,elementsSelectable:g,panOnDrag:v=!0,defaultViewport:w,translateExtent:x,minZoom:N,maxZoom:S,zoomActivationKeyCode:R,preventScrolling:T=!0,children:z,noWheelClassName:H,noPanClassName:D})=>{const G=_.useRef(),Q=xr(),Y=_.useRef(!1),ee=_.useRef(!1),ae=_.useRef(null),le=_.useRef({x:0,y:0,zoom:0}),{d3Zoom:ge,d3Selection:F,d3ZoomHandler:C,userSelectionActive:k}=An(M$,Rr),I=Jd(R),P=_.useRef(0),K=_.useRef(!1),L=_.useRef();return E$(ae),_.useEffect(()=>{if(ae.current){const O=ae.current.getBoundingClientRect(),q=Uw().scaleExtent([N,S]).translateExtent(x),E=_i(ae.current).call(q),X=Yo.translate(w.x,w.y).scale(_u(w.zoom,N,S)),ne=[[0,0],[O.width,O.height]],ie=q.constrain()(X,ne,x);q.transform(E,ie),q.wheelDelta($y),Q.setState({d3Zoom:q,d3Selection:E,d3ZoomHandler:E.on("wheel.zoom"),transform:[ie.x,ie.y,ie.k],domNode:ae.current.closest(".react-flow")})}},[]),_.useEffect(()=>{F&&ge&&(u&&!I&&!k?F.on("wheel.zoom",O=>{if(Jc(O,H))return!1;O.preventDefault(),O.stopImmediatePropagation();const q=F.property("__zoom").k||1,E=Jm();if(O.ctrlKey&&l&&E){const Oe=Ui(O),He=$y(O),Ke=q*Math.pow(2,He);ge.scaleTo(F,Ke,Oe,O);return}const X=O.deltaMode===1?20:1;let ne=m===Xl.Vertical?0:O.deltaX*X,ie=m===Xl.Horizontal?0:O.deltaY*X;!E&&O.shiftKey&&m!==Xl.Vertical&&(ne=O.deltaY*X,ie=0),ge.translateBy(F,-(ne/q)*d,-(ie/q)*d,{internal:!0});const de=jm(F.property("__zoom")),{onViewportChangeStart:xe,onViewportChange:be,onViewportChangeEnd:Ee}=Q.getState();clearTimeout(L.current),K.current||(K.current=!0,t==null||t(O,de),xe==null||xe(de)),K.current&&(e==null||e(O,de),be==null||be(de),L.current=setTimeout(()=>{n==null||n(O,de),Ee==null||Ee(de),K.current=!1},150))},{passive:!1}):typeof C<"u"&&F.on("wheel.zoom",function(O,q){if(!T||Jc(O,H))return null;O.preventDefault(),C.call(this,O,q)},{passive:!1}))},[k,u,m,F,ge,C,I,l,T,H,t,e,n]),_.useEffect(()=>{ge&&ge.on("start",O=>{var X,ne;if(!O.sourceEvent||O.sourceEvent.internal)return null;P.current=(X=O.sourceEvent)==null?void 0:X.button;const{onViewportChangeStart:q}=Q.getState(),E=jm(O.transform);Y.current=!0,le.current=E,((ne=O.sourceEvent)==null?void 0:ne.type)==="mousedown"&&Q.setState({paneDragging:!0}),q==null||q(E),t==null||t(O.sourceEvent,E)})},[ge,t]),_.useEffect(()=>{ge&&(k&&!Y.current?ge.on("zoom",null):k||ge.on("zoom",O=>{var E;const{onViewportChange:q}=Q.getState();if(Q.setState({transform:[O.transform.x,O.transform.y,O.transform.k]}),ee.current=!!(i&&Cy(v,P.current??0)),(e||q)&&!((E=O.sourceEvent)!=null&&E.internal)){const X=jm(O.transform);q==null||q(X),e==null||e(O.sourceEvent,X)}}))},[k,ge,e,v,i]),_.useEffect(()=>{ge&&ge.on("end",O=>{if(!O.sourceEvent||O.sourceEvent.internal)return null;const{onViewportChangeEnd:q}=Q.getState();if(Y.current=!1,Q.setState({paneDragging:!1}),i&&Cy(v,P.current??0)&&!ee.current&&i(O.sourceEvent),ee.current=!1,(n||q)&&A$(le.current,O.transform)){const E=jm(O.transform);le.current=E,clearTimeout(G.current),G.current=setTimeout(()=>{q==null||q(E),n==null||n(O.sourceEvent,E)},u?150:0)}})},[ge,u,v,n,i]),_.useEffect(()=>{ge&&ge.filter(O=>{const q=I||a,E=l&&O.ctrlKey;if((v===!0||Array.isArray(v)&&v.includes(1))&&O.button===1&&O.type==="mousedown"&&(Jc(O,"react-flow__node")||Jc(O,"react-flow__edge")))return!0;if(!v&&!q&&!u&&!p&&!l||k||!p&&O.type==="dblclick"||Jc(O,H)&&O.type==="wheel"||Jc(O,D)&&(O.type!=="wheel"||u&&O.type==="wheel"&&!I)||!l&&O.ctrlKey&&O.type==="wheel"||!q&&!u&&!E&&O.type==="wheel"||!v&&(O.type==="mousedown"||O.type==="touchstart")||Array.isArray(v)&&!v.includes(O.button)&&(O.type==="mousedown"||O.type==="touchstart"))return!1;const X=Array.isArray(v)&&v.includes(O.button)||!O.button||O.button<=1;return(!O.ctrlKey||O.type==="wheel")&&X})},[k,ge,a,l,u,p,v,g,I]),pe.createElement("div",{className:"react-flow__renderer",ref:ae,style:Bg},z)},R$=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function L$(){const{userSelectionActive:e,userSelectionRect:t}=An(R$,Rr);return e&&t?pe.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function Ey(e,t){const n=e.find(i=>i.id===t.parentNode);if(n){const i=t.position.x+t.width-n.width,a=t.position.y+t.height-n.height;if(i>0||a>0||t.position.x<0||t.position.y<0){if(n.style={...n.style},n.style.width=n.style.width??n.width,n.style.height=n.style.height??n.height,i>0&&(n.style.width+=i),a>0&&(n.style.height+=a),t.position.x<0){const l=Math.abs(t.position.x);n.position.x=n.position.x-l,n.style.width+=l,t.position.x=0}if(t.position.y<0){const l=Math.abs(t.position.y);n.position.y=n.position.y-l,n.style.height+=l,t.position.y=0}n.width=n.style.width,n.height=n.style.height}}}function O$(e,t){if(e.some(i=>i.type==="reset"))return e.filter(i=>i.type==="reset").map(i=>i.item);const n=e.filter(i=>i.type==="add").map(i=>i.item);return t.reduce((i,a)=>{const l=e.filter(d=>d.id===a.id);if(l.length===0)return i.push(a),i;const u={...a};for(const d of l)if(d)switch(d.type){case"select":{u.selected=d.selected;break}case"position":{typeof d.position<"u"&&(u.position=d.position),typeof d.positionAbsolute<"u"&&(u.positionAbsolute=d.positionAbsolute),typeof d.dragging<"u"&&(u.dragging=d.dragging),u.expandParent&&Ey(i,u);break}case"dimensions":{typeof d.dimensions<"u"&&(u.width=d.dimensions.width,u.height=d.dimensions.height),typeof d.updateStyle<"u"&&(u.style={...u.style||{},...d.dimensions}),typeof d.resizing=="boolean"&&(u.resizing=d.resizing),u.expandParent&&Ey(i,u);break}case"remove":return i}return i.push(u),i},n)}function P$(e,t){return O$(e,t)}const Xa=(e,t)=>({id:e,type:"select",selected:t});function ru(e,t){return e.reduce((n,i)=>{const a=t.includes(i.id);return!i.selected&&a?(i.selected=!0,n.push(Xa(i.id,!0))):i.selected&&!a&&(i.selected=!1,n.push(Xa(i.id,!1))),n},[])}const g_=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},I$=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),vx=_.memo(({isSelecting:e,selectionMode:t=Yd.Full,panOnDrag:n,onSelectionStart:i,onSelectionEnd:a,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:m,onPaneMouseMove:p,onPaneMouseLeave:g,children:v})=>{const w=_.useRef(null),x=xr(),N=_.useRef(0),S=_.useRef(0),R=_.useRef(),{userSelectionActive:T,elementsSelectable:z,dragging:H}=An(I$,Rr),D=()=>{x.setState({userSelectionActive:!1,userSelectionRect:null}),N.current=0,S.current=0},G=C=>{l==null||l(C),x.getState().resetSelectedElements(),x.setState({nodesSelectionActive:!1})},Q=C=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){C.preventDefault();return}u==null||u(C)},Y=d?C=>d(C):void 0,ee=C=>{const{resetSelectedElements:k,domNode:I}=x.getState();if(R.current=I==null?void 0:I.getBoundingClientRect(),!z||!e||C.button!==0||C.target!==w.current||!R.current)return;const{x:P,y:K}=Qa(C,R.current);k(),x.setState({userSelectionRect:{width:0,height:0,startX:P,startY:K,x:P,y:K}}),i==null||i(C)},ae=C=>{const{userSelectionRect:k,nodeInternals:I,edges:P,transform:K,onNodesChange:L,onEdgesChange:O,nodeOrigin:q,getNodes:E}=x.getState();if(!e||!R.current||!k)return;x.setState({userSelectionActive:!0,nodesSelectionActive:!1});const X=Qa(C,R.current),ne=k.startX??0,ie=k.startY??0,de={...k,x:X.x<ne?X.x:ne,y:X.y<ie?X.y:ie,width:Math.abs(X.x-ne),height:Math.abs(X.y-ie)},xe=E(),be=tx(I,de,K,t===Yd.Partial,!0,q),Ee=nx(be,P).map(He=>He.id),Oe=be.map(He=>He.id);if(N.current!==Oe.length){N.current=Oe.length;const He=ru(xe,Oe);He.length&&(L==null||L(He))}if(S.current!==Ee.length){S.current=Ee.length;const He=ru(P,Ee);He.length&&(O==null||O(He))}x.setState({userSelectionRect:de})},le=C=>{if(C.button!==0)return;const{userSelectionRect:k}=x.getState();!T&&k&&C.target===w.current&&(G==null||G(C)),x.setState({nodesSelectionActive:N.current>0}),D(),a==null||a(C)},ge=C=>{T&&(x.setState({nodesSelectionActive:N.current>0}),a==null||a(C)),D()},F=z&&(e||T);return pe.createElement("div",{className:Br(["react-flow__pane",{dragging:H,selection:e}]),onClick:F?void 0:g_(G,w),onContextMenu:g_(Q,w),onWheel:g_(Y,w),onMouseEnter:F?void 0:m,onMouseDown:F?ee:void 0,onMouseMove:F?ae:p,onMouseUp:F?le:void 0,onMouseLeave:F?ge:g,ref:w,style:Bg},v,pe.createElement(L$,null))});vx.displayName="Pane";function wx(e,t){if(!e.parentNode)return!1;const n=t.get(e.parentNode);return n?n.selected?!0:wx(n,t):!1}function Ay(e,t,n){let i=e;do{if(i!=null&&i.matches(t))return!0;if(i===n.current)return!1;i=i.parentElement}while(i);return!1}function D$(e,t,n,i){return Array.from(e.values()).filter(a=>(a.selected||a.id===i)&&(!a.parentNode||!wx(a,e))&&(a.draggable||t&&typeof a.draggable>"u")).map(a=>{var l,u;return{id:a.id,position:a.position||{x:0,y:0},positionAbsolute:a.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((l=a.positionAbsolute)==null?void 0:l.x)??0),y:n.y-(((u=a.positionAbsolute)==null?void 0:u.y)??0)},delta:{x:0,y:0},extent:a.extent,parentNode:a.parentNode,width:a.width,height:a.height,expandParent:a.expandParent}})}function z$(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function xx(e,t,n,i,a=[0,0],l){const u=z$(e,e.extent||i);let d=u;if(e.extent==="parent"&&!e.expandParent)if(e.parentNode&&e.width&&e.height){const g=n.get(e.parentNode),{x:v,y:w}=tc(g,a).positionAbsolute;d=g&&gi(v)&&gi(w)&&gi(g.width)&&gi(g.height)?[[v+e.width*a[0],w+e.height*a[1]],[v+g.width-e.width+e.width*a[0],w+g.height-e.height+e.height*a[1]]]:d}else l==null||l("005",Zo.error005()),d=u;else if(e.extent&&e.parentNode&&e.extent!=="parent"){const g=n.get(e.parentNode),{x:v,y:w}=tc(g,a).positionAbsolute;d=[[e.extent[0][0]+v,e.extent[0][1]+w],[e.extent[1][0]+v,e.extent[1][1]+w]]}let m={x:0,y:0};if(e.parentNode){const g=n.get(e.parentNode);m=tc(g,a).positionAbsolute}const p=d&&d!=="parent"?Rg(t,d):t;return{position:{x:p.x-m.x,y:p.y-m.y},positionAbsolute:p}}function p_({nodeId:e,dragItems:t,nodeInternals:n}){const i=t.map(a=>({...n.get(a.id),position:a.position,positionAbsolute:a.positionAbsolute}));return[e?i.find(a=>a.id===e):i[0],i]}const My=(e,t,n,i)=>{const a=t.querySelectorAll(e);if(!a||!a.length)return null;const l=Array.from(a),u=t.getBoundingClientRect(),d={x:u.width*i[0],y:u.height*i[1]};return l.map(m=>{const p=m.getBoundingClientRect();return{id:m.getAttribute("data-handleid"),position:m.getAttribute("data-handlepos"),x:(p.left-u.left-d.x)/n,y:(p.top-u.top-d.y)/n,...Tg(m)}})};function $d(e,t,n){return n===void 0?n:i=>{const a=t().nodeInternals.get(e);a&&n(i,{...a})}}function ig({id:e,store:t,unselect:n=!1,nodeRef:i}){const{addSelectedNodes:a,unselectNodesAndEdges:l,multiSelectionActive:u,nodeInternals:d,onError:m}=t.getState(),p=d.get(e);if(!p){m==null||m("012",Zo.error012(e));return}t.setState({nodesSelectionActive:!1}),p.selected?(n||p.selected&&u)&&(l({nodes:[p],edges:[]}),requestAnimationFrame(()=>{var g;return(g=i==null?void 0:i.current)==null?void 0:g.blur()})):a([e])}function F$(){const e=xr();return _.useCallback(({sourceEvent:n})=>{const{transform:i,snapGrid:a,snapToGrid:l}=e.getState(),u=n.touches?n.touches[0].clientX:n.clientX,d=n.touches?n.touches[0].clientY:n.clientY,m={x:(u-i[0])/i[2],y:(d-i[1])/i[2]};return{xSnapped:l?a[0]*Math.round(m.x/a[0]):m.x,ySnapped:l?a[1]*Math.round(m.y/a[1]):m.y,...m}},[])}function y_(e){return(t,n,i)=>e==null?void 0:e(t,i)}function bx({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:i,nodeId:a,isSelectable:l,selectNodesOnDrag:u}){const d=xr(),[m,p]=_.useState(!1),g=_.useRef([]),v=_.useRef({x:null,y:null}),w=_.useRef(0),x=_.useRef(null),N=_.useRef({x:0,y:0}),S=_.useRef(null),R=_.useRef(!1),T=_.useRef(!1),z=F$();return _.useEffect(()=>{if(e!=null&&e.current){const H=_i(e.current),D=({x:Y,y:ee})=>{const{nodeInternals:ae,onNodeDrag:le,onSelectionDrag:ge,updateNodePositions:F,nodeExtent:C,snapGrid:k,snapToGrid:I,nodeOrigin:P,onError:K}=d.getState();v.current={x:Y,y:ee};let L=!1,O={x:0,y:0,x2:0,y2:0};if(g.current.length>1&&C){const E=mh(g.current,P);O=Kd(E)}if(g.current=g.current.map(E=>{const X={x:Y-E.distance.x,y:ee-E.distance.y};I&&(X.x=k[0]*Math.round(X.x/k[0]),X.y=k[1]*Math.round(X.y/k[1]));const ne=[[C[0][0],C[0][1]],[C[1][0],C[1][1]]];g.current.length>1&&C&&!E.extent&&(ne[0][0]=E.positionAbsolute.x-O.x+C[0][0],ne[1][0]=E.positionAbsolute.x+(E.width??0)-O.x2+C[1][0],ne[0][1]=E.positionAbsolute.y-O.y+C[0][1],ne[1][1]=E.positionAbsolute.y+(E.height??0)-O.y2+C[1][1]);const ie=xx(E,X,ae,ne,P,K);return L=L||E.position.x!==ie.position.x||E.position.y!==ie.position.y,E.position=ie.position,E.positionAbsolute=ie.positionAbsolute,E}),!L)return;F(g.current,!0,!0),p(!0);const q=a?le:y_(ge);if(q&&S.current){const[E,X]=p_({nodeId:a,dragItems:g.current,nodeInternals:ae});q(S.current,E,X)}},G=()=>{if(!x.current)return;const[Y,ee]=Hw(N.current,x.current);if(Y!==0||ee!==0){const{transform:ae,panBy:le}=d.getState();v.current.x=(v.current.x??0)-Y/ae[2],v.current.y=(v.current.y??0)-ee/ae[2],le({x:Y,y:ee})&&D(v.current)}w.current=requestAnimationFrame(G)},Q=Y=>{var P;const{nodeInternals:ee,multiSelectionActive:ae,nodesDraggable:le,unselectNodesAndEdges:ge,onNodeDragStart:F,onSelectionDragStart:C}=d.getState();T.current=!0;const k=a?F:y_(C);(!u||!l)&&!ae&&a&&((P=ee.get(a))!=null&&P.selected||ge()),a&&l&&u&&ig({id:a,store:d,nodeRef:e});const I=z(Y);if(v.current=I,g.current=D$(ee,le,I,a),k&&g.current){const[K,L]=p_({nodeId:a,dragItems:g.current,nodeInternals:ee});k(Y.sourceEvent,K,L)}};if(t)H.on(".drag",null);else{const Y=X1().on("start",ee=>{const{domNode:ae,nodeDragThreshold:le}=d.getState();le===0&&Q(ee);const ge=z(ee);v.current=ge,x.current=(ae==null?void 0:ae.getBoundingClientRect())||null,N.current=Qa(ee.sourceEvent,x.current)}).on("drag",ee=>{var F,C;const ae=z(ee),{autoPanOnNodeDrag:le,nodeDragThreshold:ge}=d.getState();if(!R.current&&T.current&&le&&(R.current=!0,G()),!T.current){const k=ae.xSnapped-(((F=v==null?void 0:v.current)==null?void 0:F.x)??0),I=ae.ySnapped-(((C=v==null?void 0:v.current)==null?void 0:C.y)??0);Math.sqrt(k*k+I*I)>ge&&Q(ee)}(v.current.x!==ae.xSnapped||v.current.y!==ae.ySnapped)&&g.current&&T.current&&(S.current=ee.sourceEvent,N.current=Qa(ee.sourceEvent,x.current),D(ae))}).on("end",ee=>{if(T.current&&(p(!1),R.current=!1,T.current=!1,cancelAnimationFrame(w.current),g.current)){const{updateNodePositions:ae,nodeInternals:le,onNodeDragStop:ge,onSelectionDragStop:F}=d.getState(),C=a?ge:y_(F);if(ae(g.current,!1,!1),C){const[k,I]=p_({nodeId:a,dragItems:g.current,nodeInternals:le});C(ee.sourceEvent,k,I)}}}).filter(ee=>{const ae=ee.target;return!ee.button&&(!n||!Ay(ae,`.${n}`,e))&&(!i||Ay(ae,i,e))});return H.call(Y),()=>{H.on(".drag",null)}}}},[e,t,n,i,l,d,a,u,z]),m}function jx(){const e=xr();return _.useCallback(n=>{const{nodeInternals:i,nodeExtent:a,updateNodePositions:l,getNodes:u,snapToGrid:d,snapGrid:m,onError:p,nodesDraggable:g}=e.getState(),v=u().filter(z=>z.selected&&(z.draggable||g&&typeof z.draggable>"u")),w=d?m[0]:5,x=d?m[1]:5,N=n.isShiftPressed?4:1,S=n.x*w*N,R=n.y*x*N,T=v.map(z=>{if(z.positionAbsolute){const H={x:z.positionAbsolute.x+S,y:z.positionAbsolute.y+R};d&&(H.x=m[0]*Math.round(H.x/m[0]),H.y=m[1]*Math.round(H.y/m[1]));const{positionAbsolute:D,position:G}=xx(z,H,i,a,void 0,p);z.position=G,z.positionAbsolute=D}return z});l(T,!0,!1)},[])}const cu={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var Ed=e=>{const t=({id:n,type:i,data:a,xPos:l,yPos:u,xPosOrigin:d,yPosOrigin:m,selected:p,onClick:g,onMouseEnter:v,onMouseMove:w,onMouseLeave:x,onContextMenu:N,onDoubleClick:S,style:R,className:T,isDraggable:z,isSelectable:H,isConnectable:D,isFocusable:G,selectNodesOnDrag:Q,sourcePosition:Y,targetPosition:ee,hidden:ae,resizeObserver:le,dragHandle:ge,zIndex:F,isParent:C,noDragClassName:k,noPanClassName:I,initialized:P,disableKeyboardA11y:K,ariaLabel:L,rfId:O,hasHandleBounds:q})=>{const E=xr(),X=_.useRef(null),ne=_.useRef(Y),ie=_.useRef(ee),de=_.useRef(i),xe=H||z||g||v||w||x,be=jx(),Ee=$d(n,E.getState,v),Oe=$d(n,E.getState,w),He=$d(n,E.getState,x),Ke=$d(n,E.getState,N),Ct=$d(n,E.getState,S),pt=nt=>{const{nodeDragThreshold:$e}=E.getState();if(H&&(!Q||!z||$e>0)&&ig({id:n,store:E,nodeRef:X}),g){const Re=E.getState().nodeInternals.get(n);Re&&g(nt,{...Re})}},gt=nt=>{if(!eg(nt))if(Kw.includes(nt.key)&&H){const $e=nt.key==="Escape";ig({id:n,store:E,unselect:$e,nodeRef:X})}else!K&&z&&p&&Object.prototype.hasOwnProperty.call(cu,nt.key)&&(E.setState({ariaLiveMessage:`Moved selected node ${nt.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~l}, y: ${~~u}`}),be({x:cu[nt.key].x,y:cu[nt.key].y,isShiftPressed:nt.shiftKey}))};_.useEffect(()=>()=>{X.current&&(le==null||le.unobserve(X.current))},[]),_.useEffect(()=>{if(X.current&&!ae){const nt=X.current;(!P||!q)&&(le==null||le.unobserve(nt),le==null||le.observe(nt))}},[ae,P,q]),_.useEffect(()=>{const nt=de.current!==i,$e=ne.current!==Y,Re=ie.current!==ee;X.current&&(nt||$e||Re)&&(nt&&(de.current=i),$e&&(ne.current=Y),Re&&(ie.current=ee),E.getState().updateNodeDimensions([{id:n,nodeElement:X.current,forceUpdate:!0}]))},[n,i,Y,ee]);const yt=bx({nodeRef:X,disabled:ae||!z,noDragClassName:k,handleSelector:ge,nodeId:n,isSelectable:H,selectNodesOnDrag:Q});return ae?null:pe.createElement("div",{className:Br(["react-flow__node",`react-flow__node-${i}`,{[I]:z},T,{selected:p,selectable:H,parent:C,dragging:yt}]),ref:X,style:{zIndex:F,transform:`translate(${d}px,${m}px)`,pointerEvents:xe?"all":"none",visibility:P?"visible":"hidden",...R},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:Ee,onMouseMove:Oe,onMouseLeave:He,onContextMenu:Ke,onClick:pt,onDoubleClick:Ct,onKeyDown:G?gt:void 0,tabIndex:G?0:void 0,role:G?"button":void 0,"aria-describedby":K?void 0:`${hx}-${O}`,"aria-label":L},pe.createElement(QC,{value:n},pe.createElement(e,{id:n,data:a,type:i,xPos:l,yPos:u,selected:p,isConnectable:D,sourcePosition:Y,targetPosition:ee,dragging:yt,dragHandle:ge,zIndex:F})))};return t.displayName="NodeWrapper",_.memo(t)};const B$=e=>{const t=e.getNodes().filter(n=>n.selected);return{...mh(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function U$({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const i=xr(),{width:a,height:l,x:u,y:d,transformString:m,userSelectionActive:p}=An(B$,Rr),g=jx(),v=_.useRef(null);if(_.useEffect(()=>{var N;n||(N=v.current)==null||N.focus({preventScroll:!0})},[n]),bx({nodeRef:v}),p||!a||!l)return null;const w=e?N=>{const S=i.getState().getNodes().filter(R=>R.selected);e(N,S)}:void 0,x=N=>{Object.prototype.hasOwnProperty.call(cu,N.key)&&g({x:cu[N.key].x,y:cu[N.key].y,isShiftPressed:N.shiftKey})};return pe.createElement("div",{className:Br(["react-flow__nodesselection","react-flow__container",t]),style:{transform:m}},pe.createElement("div",{ref:v,className:"react-flow__nodesselection-rect",onContextMenu:w,tabIndex:n?void 0:-1,onKeyDown:n?void 0:x,style:{width:a,height:l,top:d,left:u}}))}var W$=_.memo(U$);const H$=e=>e.nodesSelectionActive,Sx=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:a,onPaneContextMenu:l,onPaneScroll:u,deleteKeyCode:d,onMove:m,onMoveStart:p,onMoveEnd:g,selectionKeyCode:v,selectionOnDrag:w,selectionMode:x,onSelectionStart:N,onSelectionEnd:S,multiSelectionKeyCode:R,panActivationKeyCode:T,zoomActivationKeyCode:z,elementsSelectable:H,zoomOnScroll:D,zoomOnPinch:G,panOnScroll:Q,panOnScrollSpeed:Y,panOnScrollMode:ee,zoomOnDoubleClick:ae,panOnDrag:le,defaultViewport:ge,translateExtent:F,minZoom:C,maxZoom:k,preventScrolling:I,onSelectionContextMenu:P,noWheelClassName:K,noPanClassName:L,disableKeyboardA11y:O})=>{const q=An(H$),E=Jd(v),X=Jd(T),ne=X||le,ie=X||Q,de=E||w&&ne!==!0;return $$({deleteKeyCode:d,multiSelectionKeyCode:R}),pe.createElement(T$,{onMove:m,onMoveStart:p,onMoveEnd:g,onPaneContextMenu:l,elementsSelectable:H,zoomOnScroll:D,zoomOnPinch:G,panOnScroll:ie,panOnScrollSpeed:Y,panOnScrollMode:ee,zoomOnDoubleClick:ae,panOnDrag:!E&&ne,defaultViewport:ge,translateExtent:F,minZoom:C,maxZoom:k,zoomActivationKeyCode:z,preventScrolling:I,noWheelClassName:K,noPanClassName:L},pe.createElement(vx,{onSelectionStart:N,onSelectionEnd:S,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:a,onPaneContextMenu:l,onPaneScroll:u,panOnDrag:ne,isSelecting:!!de,selectionMode:x},e,q&&pe.createElement(W$,{onSelectionContextMenu:P,noPanClassName:L,disableKeyboardA11y:O})))};Sx.displayName="FlowRenderer";var q$=_.memo(Sx);function V$(e){return An(_.useCallback(n=>e?tx(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function G$(e){const t={input:Ed(e.input||ux),default:Ed(e.default||sg),output:Ed(e.output||fx),group:Ed(e.group||zg)},n={},i=Object.keys(e).filter(a=>!["input","default","output","group"].includes(a)).reduce((a,l)=>(a[l]=Ed(e[l]||sg),a),n);return{...t,...i}}const K$=({x:e,y:t,width:n,height:i,origin:a})=>!n||!i?{x:e,y:t}:a[0]<0||a[1]<0||a[0]>1||a[1]>1?{x:e,y:t}:{x:e-n*a[0],y:t-i*a[1]},Y$=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),kx=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:a,updateNodeDimensions:l,onError:u}=An(Y$,Rr),d=V$(e.onlyRenderVisibleElements),m=_.useRef(),p=_.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const g=new ResizeObserver(v=>{const w=v.map(x=>({id:x.target.getAttribute("data-id"),nodeElement:x.target,forceUpdate:!0}));l(w)});return m.current=g,g},[]);return _.useEffect(()=>()=>{var g;(g=m==null?void 0:m.current)==null||g.disconnect()},[]),pe.createElement("div",{className:"react-flow__nodes",style:Bg},d.map(g=>{var G,Q,Y;let v=g.type||"default";e.nodeTypes[v]||(u==null||u("003",Zo.error003(v)),v="default");const w=e.nodeTypes[v]||e.nodeTypes.default,x=!!(g.draggable||t&&typeof g.draggable>"u"),N=!!(g.selectable||a&&typeof g.selectable>"u"),S=!!(g.connectable||n&&typeof g.connectable>"u"),R=!!(g.focusable||i&&typeof g.focusable>"u"),T=e.nodeExtent?Rg(g.positionAbsolute,e.nodeExtent):g.positionAbsolute,z=(T==null?void 0:T.x)??0,H=(T==null?void 0:T.y)??0,D=K$({x:z,y:H,width:g.width??0,height:g.height??0,origin:e.nodeOrigin});return pe.createElement(w,{key:g.id,id:g.id,className:g.className,style:g.style,type:v,data:g.data,sourcePosition:g.sourcePosition||dt.Bottom,targetPosition:g.targetPosition||dt.Top,hidden:g.hidden,xPos:z,yPos:H,xPosOrigin:D.x,yPosOrigin:D.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!g.selected,isDraggable:x,isSelectable:N,isConnectable:S,isFocusable:R,resizeObserver:p,dragHandle:g.dragHandle,zIndex:((G=g[cr])==null?void 0:G.z)??0,isParent:!!((Q=g[cr])!=null&&Q.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!g.width&&!!g.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:g.ariaLabel,hasHandleBounds:!!((Y=g[cr])!=null&&Y.handleBounds)})}))};kx.displayName="NodeRenderer";var X$=_.memo(kx);const J$=(e,t,n)=>n===dt.Left?e-t:n===dt.Right?e+t:e,Z$=(e,t,n)=>n===dt.Top?e-t:n===dt.Bottom?e+t:e,Ty="react-flow__edgeupdater",Ry=({position:e,centerX:t,centerY:n,radius:i=10,onMouseDown:a,onMouseEnter:l,onMouseOut:u,type:d})=>pe.createElement("circle",{onMouseDown:a,onMouseEnter:l,onMouseOut:u,className:Br([Ty,`${Ty}-${d}`]),cx:J$(t,i,e),cy:Z$(n,i,e),r:i,stroke:"transparent",fill:"transparent"}),Q$=()=>!0;var Zc=e=>{const t=({id:n,className:i,type:a,data:l,onClick:u,onEdgeDoubleClick:d,selected:m,animated:p,label:g,labelStyle:v,labelShowBg:w,labelBgStyle:x,labelBgPadding:N,labelBgBorderRadius:S,style:R,source:T,target:z,sourceX:H,sourceY:D,targetX:G,targetY:Q,sourcePosition:Y,targetPosition:ee,elementsSelectable:ae,hidden:le,sourceHandleId:ge,targetHandleId:F,onContextMenu:C,onMouseEnter:k,onMouseMove:I,onMouseLeave:P,edgeUpdaterRadius:K,onEdgeUpdate:L,onEdgeUpdateStart:O,onEdgeUpdateEnd:q,markerEnd:E,markerStart:X,rfId:ne,ariaLabel:ie,isFocusable:de,isUpdatable:xe,pathOptions:be,interactionWidth:Ee})=>{const Oe=_.useRef(null),[He,Ke]=_.useState(!1),[Ct,pt]=_.useState(!1),gt=xr(),yt=_.useMemo(()=>`url('#${ng(X,ne)}')`,[X,ne]),nt=_.useMemo(()=>`url('#${ng(E,ne)}')`,[E,ne]);if(le)return null;const $e=$t=>{var mn;const{edges:pn,addSelectedEdges:Pn,unselectNodesAndEdges:Cn,multiSelectionActive:yn}=gt.getState(),Mn=pn.find(br=>br.id===n);Mn&&(ae&&(gt.setState({nodesSelectionActive:!1}),Mn.selected&&yn?(Cn({nodes:[],edges:[Mn]}),(mn=Oe.current)==null||mn.blur()):Pn([n])),u&&u($t,Mn))},Re=Cd(n,gt.getState,d),ot=Cd(n,gt.getState,C),he=Cd(n,gt.getState,k),Pe=Cd(n,gt.getState,I),Ve=Cd(n,gt.getState,P),Rt=($t,pn)=>{if($t.button!==0)return;const{edges:Pn,isValidConnection:Cn}=gt.getState(),yn=pn?z:T,Mn=(pn?F:ge)||null,mn=pn?"target":"source",br=Cn||Q$,Hn=pn,Qn=Pn.find(oe=>oe.id===n);pt(!0),O==null||O($t,Qn,mn);const ys=oe=>{pt(!1),q==null||q(oe,Qn,mn)};ox({event:$t,handleId:Mn,nodeId:yn,onConnect:oe=>L==null?void 0:L(Qn,oe),isTarget:Hn,getState:gt.getState,setState:gt.setState,isValidConnection:br,edgeUpdaterType:mn,onEdgeUpdateEnd:ys})},Xt=$t=>Rt($t,!0),fn=$t=>Rt($t,!1),Ft=()=>Ke(!0),At=()=>Ke(!1),sn=!ae&&!u,zn=$t=>{var pn;if(Kw.includes($t.key)&&ae){const{unselectNodesAndEdges:Pn,addSelectedEdges:Cn,edges:yn}=gt.getState();$t.key==="Escape"?((pn=Oe.current)==null||pn.blur(),Pn({edges:[yn.find(mn=>mn.id===n)]})):Cn([n])}};return pe.createElement("g",{className:Br(["react-flow__edge",`react-flow__edge-${a}`,i,{selected:m,animated:p,inactive:sn,updating:He}]),onClick:$e,onDoubleClick:Re,onContextMenu:ot,onMouseEnter:he,onMouseMove:Pe,onMouseLeave:Ve,onKeyDown:de?zn:void 0,tabIndex:de?0:void 0,role:de?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":ie===null?void 0:ie||`Edge from ${T} to ${z}`,"aria-describedby":de?`${_x}-${ne}`:void 0,ref:Oe},!Ct&&pe.createElement(e,{id:n,source:T,target:z,selected:m,animated:p,label:g,labelStyle:v,labelShowBg:w,labelBgStyle:x,labelBgPadding:N,labelBgBorderRadius:S,data:l,style:R,sourceX:H,sourceY:D,targetX:G,targetY:Q,sourcePosition:Y,targetPosition:ee,sourceHandleId:ge,targetHandleId:F,markerStart:yt,markerEnd:nt,pathOptions:be,interactionWidth:Ee}),xe&&pe.createElement(pe.Fragment,null,(xe==="source"||xe===!0)&&pe.createElement(Ry,{position:Y,centerX:H,centerY:D,radius:K,onMouseDown:Xt,onMouseEnter:Ft,onMouseOut:At,type:"source"}),(xe==="target"||xe===!0)&&pe.createElement(Ry,{position:ee,centerX:G,centerY:Q,radius:K,onMouseDown:fn,onMouseEnter:Ft,onMouseOut:At,type:"target"})))};return t.displayName="EdgeWrapper",_.memo(t)};function eE(e){const t={default:Zc(e.default||Zm),straight:Zc(e.bezier||Pg),step:Zc(e.step||Og),smoothstep:Zc(e.step||fh),simplebezier:Zc(e.simplebezier||Lg)},n={},i=Object.keys(e).filter(a=>!["default","bezier"].includes(a)).reduce((a,l)=>(a[l]=Zc(e[l]||Zm),a),n);return{...t,...i}}function Ly(e,t,n=null){const i=((n==null?void 0:n.x)||0)+t.x,a=((n==null?void 0:n.y)||0)+t.y,l=(n==null?void 0:n.width)||t.width,u=(n==null?void 0:n.height)||t.height;switch(e){case dt.Top:return{x:i+l/2,y:a};case dt.Right:return{x:i+l,y:a+u/2};case dt.Bottom:return{x:i+l/2,y:a+u};case dt.Left:return{x:i,y:a+u/2}}}function Oy(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const tE=(e,t,n,i,a,l)=>{const u=Ly(n,e,t),d=Ly(l,i,a);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y}};function nE({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:i,targetWidth:a,targetHeight:l,width:u,height:d,transform:m}){const p={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+a),y2:Math.max(e.y+i,t.y+l)};p.x===p.x2&&(p.x2+=1),p.y===p.y2&&(p.y2+=1);const g=Kd({x:(0-m[0])/m[2],y:(0-m[1])/m[2],width:u/m[2],height:d/m[2]}),v=Math.max(0,Math.min(g.x2,p.x2)-Math.max(g.x,p.x)),w=Math.max(0,Math.min(g.y2,p.y2)-Math.max(g.y,p.y));return Math.ceil(v*w)>0}function Py(e){var i,a,l,u,d;const t=((i=e==null?void 0:e[cr])==null?void 0:i.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((a=e==null?void 0:e.positionAbsolute)==null?void 0:a.x)<"u"&&typeof((l=e==null?void 0:e.positionAbsolute)==null?void 0:l.y)<"u";return[{x:((u=e==null?void 0:e.positionAbsolute)==null?void 0:u.x)||0,y:((d=e==null?void 0:e.positionAbsolute)==null?void 0:d.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const rE=[{level:0,isMaxLevel:!0,edges:[]}];function sE(e,t,n=!1){let i=-1;const a=e.reduce((u,d)=>{var g,v;const m=gi(d.zIndex);let p=m?d.zIndex:0;if(n){const w=t.get(d.target),x=t.get(d.source),N=d.selected||(w==null?void 0:w.selected)||(x==null?void 0:x.selected),S=Math.max(((g=x==null?void 0:x[cr])==null?void 0:g.z)||0,((v=w==null?void 0:w[cr])==null?void 0:v.z)||0,1e3);p=(m?d.zIndex:0)+(N?S:0)}return u[p]?u[p].push(d):u[p]=[d],i=p>i?p:i,u},{}),l=Object.entries(a).map(([u,d])=>{const m=+u;return{edges:d,level:m,isMaxLevel:m===i}});return l.length===0?rE:l}function iE(e,t,n){const i=An(_.useCallback(a=>e?a.edges.filter(l=>{const u=t.get(l.source),d=t.get(l.target);return(u==null?void 0:u.width)&&(u==null?void 0:u.height)&&(d==null?void 0:d.width)&&(d==null?void 0:d.height)&&nE({sourcePos:u.positionAbsolute||{x:0,y:0},targetPos:d.positionAbsolute||{x:0,y:0},sourceWidth:u.width,sourceHeight:u.height,targetWidth:d.width,targetHeight:d.height,width:a.width,height:a.height,transform:a.transform})}):a.edges,[e,t]));return sE(i,t,n)}const oE=({color:e="none",strokeWidth:t=1})=>pe.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),aE=({color:e="none",strokeWidth:t=1})=>pe.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),Iy={[Xd.Arrow]:oE,[Xd.ArrowClosed]:aE};function lE(e){const t=xr();return _.useMemo(()=>{var a,l;return Object.prototype.hasOwnProperty.call(Iy,e)?Iy[e]:((l=(a=t.getState()).onError)==null||l.call(a,"009",Zo.error009(e)),null)},[e])}const cE=({id:e,type:t,color:n,width:i=12.5,height:a=12.5,markerUnits:l="strokeWidth",strokeWidth:u,orient:d="auto-start-reverse"})=>{const m=lE(t);return m?pe.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:l,orient:d,refX:"0",refY:"0"},pe.createElement(m,{color:n,strokeWidth:u})):null},uE=({defaultColor:e,rfId:t})=>n=>{const i=[];return n.edges.reduce((a,l)=>([l.markerStart,l.markerEnd].forEach(u=>{if(u&&typeof u=="object"){const d=ng(u,t);i.includes(d)||(a.push({id:d,color:u.color||e,...u}),i.push(d))}}),a),[]).sort((a,l)=>a.id.localeCompare(l.id))},Nx=({defaultColor:e,rfId:t})=>{const n=An(_.useCallback(uE({defaultColor:e,rfId:t}),[e,t]),(i,a)=>!(i.length!==a.length||i.some((l,u)=>l.id!==a[u].id)));return pe.createElement("defs",null,n.map(i=>pe.createElement(cE,{id:i.id,key:i.id,type:i.type,color:i.color,width:i.width,height:i.height,markerUnits:i.markerUnits,strokeWidth:i.strokeWidth,orient:i.orient})))};Nx.displayName="MarkerDefinitions";var dE=_.memo(Nx);const fE=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),Cx=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:i,edgeTypes:a,noPanClassName:l,onEdgeUpdate:u,onEdgeContextMenu:d,onEdgeMouseEnter:m,onEdgeMouseMove:p,onEdgeMouseLeave:g,onEdgeClick:v,edgeUpdaterRadius:w,onEdgeDoubleClick:x,onEdgeUpdateStart:N,onEdgeUpdateEnd:S,children:R})=>{const{edgesFocusable:T,edgesUpdatable:z,elementsSelectable:H,width:D,height:G,connectionMode:Q,nodeInternals:Y,onError:ee}=An(fE,Rr),ae=iE(t,Y,n);return D?pe.createElement(pe.Fragment,null,ae.map(({level:le,edges:ge,isMaxLevel:F})=>pe.createElement("svg",{key:le,style:{zIndex:le},width:D,height:G,className:"react-flow__edges react-flow__container"},F&&pe.createElement(dE,{defaultColor:e,rfId:i}),pe.createElement("g",null,ge.map(C=>{const[k,I,P]=Py(Y.get(C.source)),[K,L,O]=Py(Y.get(C.target));if(!P||!O)return null;let q=C.type||"default";a[q]||(ee==null||ee("011",Zo.error011(q)),q="default");const E=a[q]||a.default,X=Q===ic.Strict?L.target:(L.target??[]).concat(L.source??[]),ne=Oy(I.source,C.sourceHandle),ie=Oy(X,C.targetHandle),de=(ne==null?void 0:ne.position)||dt.Bottom,xe=(ie==null?void 0:ie.position)||dt.Top,be=!!(C.focusable||T&&typeof C.focusable>"u"),Ee=typeof u<"u"&&(C.updatable||z&&typeof C.updatable>"u");if(!ne||!ie)return ee==null||ee("008",Zo.error008(ne,C)),null;const{sourceX:Oe,sourceY:He,targetX:Ke,targetY:Ct}=tE(k,ne,de,K,ie,xe);return pe.createElement(E,{key:C.id,id:C.id,className:Br([C.className,l]),type:q,data:C.data,selected:!!C.selected,animated:!!C.animated,hidden:!!C.hidden,label:C.label,labelStyle:C.labelStyle,labelShowBg:C.labelShowBg,labelBgStyle:C.labelBgStyle,labelBgPadding:C.labelBgPadding,labelBgBorderRadius:C.labelBgBorderRadius,style:C.style,source:C.source,target:C.target,sourceHandleId:C.sourceHandle,targetHandleId:C.targetHandle,markerEnd:C.markerEnd,markerStart:C.markerStart,sourceX:Oe,sourceY:He,targetX:Ke,targetY:Ct,sourcePosition:de,targetPosition:xe,elementsSelectable:H,onEdgeUpdate:u,onContextMenu:d,onMouseEnter:m,onMouseMove:p,onMouseLeave:g,onClick:v,edgeUpdaterRadius:w,onEdgeDoubleClick:x,onEdgeUpdateStart:N,onEdgeUpdateEnd:S,rfId:i,ariaLabel:C.ariaLabel,isFocusable:be,isUpdatable:Ee,pathOptions:"pathOptions"in C?C.pathOptions:void 0,interactionWidth:C.interactionWidth})})))),R):null};Cx.displayName="EdgeRenderer";var mE=_.memo(Cx);const hE=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function _E({children:e}){const t=An(hE);return pe.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function gE(e){const t=Fg(),n=_.useRef(!1);_.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const pE={[dt.Left]:dt.Right,[dt.Right]:dt.Left,[dt.Top]:dt.Bottom,[dt.Bottom]:dt.Top},$x=({nodeId:e,handleType:t,style:n,type:i=Za.Bezier,CustomComponent:a,connectionStatus:l})=>{var Q,Y,ee;const{fromNode:u,handleId:d,toX:m,toY:p,connectionMode:g}=An(_.useCallback(ae=>({fromNode:ae.nodeInternals.get(e),handleId:ae.connectionHandleId,toX:(ae.connectionPosition.x-ae.transform[0])/ae.transform[2],toY:(ae.connectionPosition.y-ae.transform[1])/ae.transform[2],connectionMode:ae.connectionMode}),[e]),Rr),v=(Q=u==null?void 0:u[cr])==null?void 0:Q.handleBounds;let w=v==null?void 0:v[t];if(g===ic.Loose&&(w=w||(v==null?void 0:v[t==="source"?"target":"source"])),!u||!w)return null;const x=d?w.find(ae=>ae.id===d):w[0],N=x?x.x+x.width/2:(u.width??0)/2,S=x?x.y+x.height/2:u.height??0,R=(((Y=u.positionAbsolute)==null?void 0:Y.x)??0)+N,T=(((ee=u.positionAbsolute)==null?void 0:ee.y)??0)+S,z=x==null?void 0:x.position,H=z?pE[z]:null;if(!z||!H)return null;if(a)return pe.createElement(a,{connectionLineType:i,connectionLineStyle:n,fromNode:u,fromHandle:x,fromX:R,fromY:T,toX:m,toY:p,fromPosition:z,toPosition:H,connectionStatus:l});let D="";const G={sourceX:R,sourceY:T,sourcePosition:z,targetX:m,targetY:p,targetPosition:H};return i===Za.Bezier?[D]=Qw(G):i===Za.Step?[D]=tg({...G,borderRadius:0}):i===Za.SmoothStep?[D]=tg(G):i===Za.SimpleBezier?[D]=Zw(G):D=`M${R},${T} ${m},${p}`,pe.createElement("path",{d:D,fill:"none",className:"react-flow__connection-path",style:n})};$x.displayName="ConnectionLine";const yE=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function vE({containerStyle:e,style:t,type:n,component:i}){const{nodeId:a,handleType:l,nodesConnectable:u,width:d,height:m,connectionStatus:p}=An(yE,Rr);return!(a&&l&&d&&u)?null:pe.createElement("svg",{style:e,width:d,height:m,className:"react-flow__edges react-flow__connectionline react-flow__container"},pe.createElement("g",{className:Br(["react-flow__connection",p])},pe.createElement($x,{nodeId:a,handleType:l,style:t,type:n,CustomComponent:i,connectionStatus:p})))}function Dy(e,t){return _.useRef(null),xr(),_.useMemo(()=>t(e),[e])}const Ex=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:i,onMoveEnd:a,onInit:l,onNodeClick:u,onEdgeClick:d,onNodeDoubleClick:m,onEdgeDoubleClick:p,onNodeMouseEnter:g,onNodeMouseMove:v,onNodeMouseLeave:w,onNodeContextMenu:x,onSelectionContextMenu:N,onSelectionStart:S,onSelectionEnd:R,connectionLineType:T,connectionLineStyle:z,connectionLineComponent:H,connectionLineContainerStyle:D,selectionKeyCode:G,selectionOnDrag:Q,selectionMode:Y,multiSelectionKeyCode:ee,panActivationKeyCode:ae,zoomActivationKeyCode:le,deleteKeyCode:ge,onlyRenderVisibleElements:F,elementsSelectable:C,selectNodesOnDrag:k,defaultViewport:I,translateExtent:P,minZoom:K,maxZoom:L,preventScrolling:O,defaultMarkerColor:q,zoomOnScroll:E,zoomOnPinch:X,panOnScroll:ne,panOnScrollSpeed:ie,panOnScrollMode:de,zoomOnDoubleClick:xe,panOnDrag:be,onPaneClick:Ee,onPaneMouseEnter:Oe,onPaneMouseMove:He,onPaneMouseLeave:Ke,onPaneScroll:Ct,onPaneContextMenu:pt,onEdgeUpdate:gt,onEdgeContextMenu:yt,onEdgeMouseEnter:nt,onEdgeMouseMove:$e,onEdgeMouseLeave:Re,edgeUpdaterRadius:ot,onEdgeUpdateStart:he,onEdgeUpdateEnd:Pe,noDragClassName:Ve,noWheelClassName:Rt,noPanClassName:Xt,elevateEdgesOnSelect:fn,disableKeyboardA11y:Ft,nodeOrigin:At,nodeExtent:sn,rfId:zn})=>{const $t=Dy(e,G$),pn=Dy(t,eE);return gE(l),pe.createElement(q$,{onPaneClick:Ee,onPaneMouseEnter:Oe,onPaneMouseMove:He,onPaneMouseLeave:Ke,onPaneContextMenu:pt,onPaneScroll:Ct,deleteKeyCode:ge,selectionKeyCode:G,selectionOnDrag:Q,selectionMode:Y,onSelectionStart:S,onSelectionEnd:R,multiSelectionKeyCode:ee,panActivationKeyCode:ae,zoomActivationKeyCode:le,elementsSelectable:C,onMove:n,onMoveStart:i,onMoveEnd:a,zoomOnScroll:E,zoomOnPinch:X,zoomOnDoubleClick:xe,panOnScroll:ne,panOnScrollSpeed:ie,panOnScrollMode:de,panOnDrag:be,defaultViewport:I,translateExtent:P,minZoom:K,maxZoom:L,onSelectionContextMenu:N,preventScrolling:O,noDragClassName:Ve,noWheelClassName:Rt,noPanClassName:Xt,disableKeyboardA11y:Ft},pe.createElement(_E,null,pe.createElement(mE,{edgeTypes:pn,onEdgeClick:d,onEdgeDoubleClick:p,onEdgeUpdate:gt,onlyRenderVisibleElements:F,onEdgeContextMenu:yt,onEdgeMouseEnter:nt,onEdgeMouseMove:$e,onEdgeMouseLeave:Re,onEdgeUpdateStart:he,onEdgeUpdateEnd:Pe,edgeUpdaterRadius:ot,defaultMarkerColor:q,noPanClassName:Xt,elevateEdgesOnSelect:!!fn,disableKeyboardA11y:Ft,rfId:zn},pe.createElement(vE,{style:z,type:T,component:H,containerStyle:D})),pe.createElement("div",{className:"react-flow__edgelabel-renderer"}),pe.createElement(X$,{nodeTypes:$t,onNodeClick:u,onNodeDoubleClick:m,onNodeMouseEnter:g,onNodeMouseMove:v,onNodeMouseLeave:w,onNodeContextMenu:x,selectNodesOnDrag:k,onlyRenderVisibleElements:F,noPanClassName:Xt,noDragClassName:Ve,disableKeyboardA11y:Ft,nodeOrigin:At,nodeExtent:sn,rfId:zn})))};Ex.displayName="GraphView";var wE=_.memo(Ex);const og=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Va={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:og,nodeExtent:og,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:ic.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:GC,isValidConnection:void 0},xE=()=>lN((e,t)=>({...Va,setNodes:n=>{const{nodeInternals:i,nodeOrigin:a,elevateNodesOnSelect:l}=t();e({nodeInternals:__(n,i,a,l)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:i={}}=t();e({edges:n.map(a=>({...i,...a}))})},setDefaultNodesAndEdges:(n,i)=>{const a=typeof n<"u",l=typeof i<"u",u=a?__(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:u,edges:l?i:[],hasDefaultNodes:a,hasDefaultEdges:l})},updateNodeDimensions:n=>{const{onNodesChange:i,nodeInternals:a,fitViewOnInit:l,fitViewOnInitDone:u,fitViewOnInitOptions:d,domNode:m,nodeOrigin:p}=t(),g=m==null?void 0:m.querySelector(".react-flow__viewport");if(!g)return;const v=window.getComputedStyle(g),{m22:w}=new window.DOMMatrixReadOnly(v.transform),x=n.reduce((S,R)=>{const T=a.get(R.id);if(T){const z=Tg(R.nodeElement);!!(z.width&&z.height&&(T.width!==z.width||T.height!==z.height||R.forceUpdate))&&(a.set(T.id,{...T,[cr]:{...T[cr],handleBounds:{source:My(".source",R.nodeElement,w,p),target:My(".target",R.nodeElement,w,p)}},...z}),S.push({id:T.id,type:"dimensions",dimensions:z}))}return S},[]);px(a,p);const N=u||l&&!u&&yx(t,{initial:!0,...d});e({nodeInternals:new Map(a),fitViewOnInitDone:N}),(x==null?void 0:x.length)>0&&(i==null||i(x))},updateNodePositions:(n,i=!0,a=!1)=>{const{triggerNodeChanges:l}=t(),u=n.map(d=>{const m={id:d.id,type:"position",dragging:a};return i&&(m.positionAbsolute=d.positionAbsolute,m.position=d.position),m});l(u)},triggerNodeChanges:n=>{const{onNodesChange:i,nodeInternals:a,hasDefaultNodes:l,nodeOrigin:u,getNodes:d,elevateNodesOnSelect:m}=t();if(n!=null&&n.length){if(l){const p=P$(n,d()),g=__(p,a,u,m);e({nodeInternals:g})}i==null||i(n)}},addSelectedNodes:n=>{const{multiSelectionActive:i,edges:a,getNodes:l}=t();let u,d=null;i?u=n.map(m=>Xa(m,!0)):(u=ru(l(),n),d=ru(a,[])),bm({changedNodes:u,changedEdges:d,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:i,edges:a,getNodes:l}=t();let u,d=null;i?u=n.map(m=>Xa(m,!0)):(u=ru(a,n),d=ru(l(),[])),bm({changedNodes:d,changedEdges:u,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:i}={})=>{const{edges:a,getNodes:l}=t(),u=n||l(),d=i||a,m=u.map(g=>(g.selected=!1,Xa(g.id,!1))),p=d.map(g=>Xa(g.id,!1));bm({changedNodes:m,changedEdges:p,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:i,maxZoom:a}=t();i==null||i.scaleExtent([n,a]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:i,minZoom:a}=t();i==null||i.scaleExtent([a,n]),e({maxZoom:n})},setTranslateExtent:n=>{var i;(i=t().d3Zoom)==null||i.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:i}=t(),l=i().filter(d=>d.selected).map(d=>Xa(d.id,!1)),u=n.filter(d=>d.selected).map(d=>Xa(d.id,!1));bm({changedNodes:l,changedEdges:u,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:i}=t();i.forEach(a=>{a.positionAbsolute=Rg(a.position,n)}),e({nodeExtent:n,nodeInternals:new Map(i)})},panBy:n=>{const{transform:i,width:a,height:l,d3Zoom:u,d3Selection:d,translateExtent:m}=t();if(!u||!d||!n.x&&!n.y)return!1;const p=Yo.translate(i[0]+n.x,i[1]+n.y).scale(i[2]),g=[[0,0],[a,l]],v=u==null?void 0:u.constrain()(p,g,m);return u.transform(d,v),i[0]!==v.x||i[1]!==v.y||i[2]!==v.k},cancelConnection:()=>e({connectionNodeId:Va.connectionNodeId,connectionHandleId:Va.connectionHandleId,connectionHandleType:Va.connectionHandleType,connectionStatus:Va.connectionStatus,connectionStartHandle:Va.connectionStartHandle,connectionEndHandle:Va.connectionEndHandle}),reset:()=>e({...Va})}),Object.is),Ug=({children:e})=>{const t=_.useRef(null);return t.current||(t.current=xE()),pe.createElement(FC,{value:t.current},e)};Ug.displayName="ReactFlowProvider";const Ax=({children:e})=>_.useContext(dh)?pe.createElement(pe.Fragment,null,e):pe.createElement(Ug,null,e);Ax.displayName="ReactFlowWrapper";const bE={input:ux,default:sg,output:fx,group:zg},jE={default:Zm,straight:Pg,step:Og,smoothstep:fh,simplebezier:Lg},SE=[0,0],kE=[15,15],NE={x:0,y:0,zoom:1},CE={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},Mx=_.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,className:a,nodeTypes:l=bE,edgeTypes:u=jE,onNodeClick:d,onEdgeClick:m,onInit:p,onMove:g,onMoveStart:v,onMoveEnd:w,onConnect:x,onConnectStart:N,onConnectEnd:S,onClickConnectStart:R,onClickConnectEnd:T,onNodeMouseEnter:z,onNodeMouseMove:H,onNodeMouseLeave:D,onNodeContextMenu:G,onNodeDoubleClick:Q,onNodeDragStart:Y,onNodeDrag:ee,onNodeDragStop:ae,onNodesDelete:le,onEdgesDelete:ge,onSelectionChange:F,onSelectionDragStart:C,onSelectionDrag:k,onSelectionDragStop:I,onSelectionContextMenu:P,onSelectionStart:K,onSelectionEnd:L,connectionMode:O=ic.Strict,connectionLineType:q=Za.Bezier,connectionLineStyle:E,connectionLineComponent:X,connectionLineContainerStyle:ne,deleteKeyCode:ie="Backspace",selectionKeyCode:de="Shift",selectionOnDrag:xe=!1,selectionMode:be=Yd.Full,panActivationKeyCode:Ee="Space",multiSelectionKeyCode:Oe=Jm()?"Meta":"Control",zoomActivationKeyCode:He=Jm()?"Meta":"Control",snapToGrid:Ke=!1,snapGrid:Ct=kE,onlyRenderVisibleElements:pt=!1,selectNodesOnDrag:gt=!0,nodesDraggable:yt,nodesConnectable:nt,nodesFocusable:$e,nodeOrigin:Re=SE,edgesFocusable:ot,edgesUpdatable:he,elementsSelectable:Pe,defaultViewport:Ve=NE,minZoom:Rt=.5,maxZoom:Xt=2,translateExtent:fn=og,preventScrolling:Ft=!0,nodeExtent:At,defaultMarkerColor:sn="#b1b1b7",zoomOnScroll:zn=!0,zoomOnPinch:$t=!0,panOnScroll:pn=!1,panOnScrollSpeed:Pn=.5,panOnScrollMode:Cn=Xl.Free,zoomOnDoubleClick:yn=!0,panOnDrag:Mn=!0,onPaneClick:mn,onPaneMouseEnter:br,onPaneMouseMove:Hn,onPaneMouseLeave:Qn,onPaneScroll:ys,onPaneContextMenu:qn,children:oe,onEdgeUpdate:ve,onEdgeContextMenu:qe,onEdgeDoubleClick:We,onEdgeMouseEnter:et,onEdgeMouseMove:at,onEdgeMouseLeave:Nt,onEdgeUpdateStart:xt,onEdgeUpdateEnd:Wt,edgeUpdaterRadius:lt=10,onNodesChange:Vt,onEdgesChange:It,noDragClassName:jt="nodrag",noWheelClassName:ft="nowheel",noPanClassName:Mt="nopan",fitView:Ce=!1,fitViewOptions:Ut,connectOnClick:St=!0,attributionPosition:nn,proOptions:kt,defaultEdgeOptions:er,elevateNodesOnSelect:tr=!0,elevateEdgesOnSelect:Ur=!1,disableKeyboardA11y:jr=!1,autoPanOnConnect:Zr=!0,autoPanOnNodeDrag:Wr=!0,connectionRadius:Gi=20,isValidConnection:ye,onError:Vn,style:cn,id:Ki,nodeDragThreshold:vi,...vs},Qr)=>{const Ts=Ki||"1";return pe.createElement("div",{...vs,style:{...cn,...CE},ref:Qr,className:Br(["react-flow",a]),"data-testid":"rf__wrapper",id:Ki},pe.createElement(Ax,null,pe.createElement(wE,{onInit:p,onMove:g,onMoveStart:v,onMoveEnd:w,onNodeClick:d,onEdgeClick:m,onNodeMouseEnter:z,onNodeMouseMove:H,onNodeMouseLeave:D,onNodeContextMenu:G,onNodeDoubleClick:Q,nodeTypes:l,edgeTypes:u,connectionLineType:q,connectionLineStyle:E,connectionLineComponent:X,connectionLineContainerStyle:ne,selectionKeyCode:de,selectionOnDrag:xe,selectionMode:be,deleteKeyCode:ie,multiSelectionKeyCode:Oe,panActivationKeyCode:Ee,zoomActivationKeyCode:He,onlyRenderVisibleElements:pt,selectNodesOnDrag:gt,defaultViewport:Ve,translateExtent:fn,minZoom:Rt,maxZoom:Xt,preventScrolling:Ft,zoomOnScroll:zn,zoomOnPinch:$t,zoomOnDoubleClick:yn,panOnScroll:pn,panOnScrollSpeed:Pn,panOnScrollMode:Cn,panOnDrag:Mn,onPaneClick:mn,onPaneMouseEnter:br,onPaneMouseMove:Hn,onPaneMouseLeave:Qn,onPaneScroll:ys,onPaneContextMenu:qn,onSelectionContextMenu:P,onSelectionStart:K,onSelectionEnd:L,onEdgeUpdate:ve,onEdgeContextMenu:qe,onEdgeDoubleClick:We,onEdgeMouseEnter:et,onEdgeMouseMove:at,onEdgeMouseLeave:Nt,onEdgeUpdateStart:xt,onEdgeUpdateEnd:Wt,edgeUpdaterRadius:lt,defaultMarkerColor:sn,noDragClassName:jt,noWheelClassName:ft,noPanClassName:Mt,elevateEdgesOnSelect:Ur,rfId:Ts,disableKeyboardA11y:jr,nodeOrigin:Re,nodeExtent:At}),pe.createElement(g$,{nodes:e,edges:t,defaultNodes:n,defaultEdges:i,onConnect:x,onConnectStart:N,onConnectEnd:S,onClickConnectStart:R,onClickConnectEnd:T,nodesDraggable:yt,nodesConnectable:nt,nodesFocusable:$e,edgesFocusable:ot,edgesUpdatable:he,elementsSelectable:Pe,elevateNodesOnSelect:tr,minZoom:Rt,maxZoom:Xt,nodeExtent:At,onNodesChange:Vt,onEdgesChange:It,snapToGrid:Ke,snapGrid:Ct,connectionMode:O,translateExtent:fn,connectOnClick:St,defaultEdgeOptions:er,fitView:Ce,fitViewOptions:Ut,onNodesDelete:le,onEdgesDelete:ge,onNodeDragStart:Y,onNodeDrag:ee,onNodeDragStop:ae,onSelectionDrag:k,onSelectionDragStart:C,onSelectionDragStop:I,noPanClassName:Mt,nodeOrigin:Re,rfId:Ts,autoPanOnConnect:Zr,autoPanOnNodeDrag:Wr,onError:Vn,connectionRadius:Gi,isValidConnection:ye,nodeDragThreshold:vi}),pe.createElement(h$,{onSelectionChange:F}),oe,pe.createElement(UC,{proOptions:kt,position:nn}),pe.createElement(x$,{rfId:Ts,disableKeyboardA11y:jr})))});Mx.displayName="ReactFlow";const Tx=({id:e,x:t,y:n,width:i,height:a,style:l,color:u,strokeColor:d,strokeWidth:m,className:p,borderRadius:g,shapeRendering:v,onClick:w,selected:x})=>{const{background:N,backgroundColor:S}=l||{},R=u||N||S;return pe.createElement("rect",{className:Br(["react-flow__minimap-node",{selected:x},p]),x:t,y:n,rx:g,ry:g,width:i,height:a,fill:R,stroke:d,strokeWidth:m,shapeRendering:v,onClick:w?T=>w(T,e):void 0})};Tx.displayName="MiniMapNode";var $E=_.memo(Tx);const EE=e=>e.nodeOrigin,AE=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),v_=e=>e instanceof Function?e:()=>e;function ME({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:i=5,nodeStrokeWidth:a=2,nodeComponent:l=$E,onClick:u}){const d=An(AE,Rr),m=An(EE),p=v_(t),g=v_(e),v=v_(n),w=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return pe.createElement(pe.Fragment,null,d.map(x=>{const{x:N,y:S}=tc(x,m).positionAbsolute;return pe.createElement(l,{key:x.id,x:N,y:S,width:x.width,height:x.height,style:x.style,selected:x.selected,className:v(x),color:p(x),borderRadius:i,strokeColor:g(x),strokeWidth:a,shapeRendering:w,onClick:u,id:x.id})}))}var TE=_.memo(ME);const RE=200,LE=150,OE=e=>{const t=e.getNodes(),n={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:n,boundingRect:t.length>0?qC(mh(t,e.nodeOrigin),n):n,rfId:e.rfId}},PE="react-flow__minimap-desc";function Rx({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:i="#e2e2e2",nodeClassName:a="",nodeBorderRadius:l=5,nodeStrokeWidth:u=2,nodeComponent:d,maskColor:m="rgb(240, 240, 240, 0.6)",maskStrokeColor:p="none",maskStrokeWidth:g=1,position:v="bottom-right",onClick:w,onNodeClick:x,pannable:N=!1,zoomable:S=!1,ariaLabel:R="React Flow mini map",inversePan:T=!1,zoomStep:z=10,offsetScale:H=5}){const D=xr(),G=_.useRef(null),{boundingRect:Q,viewBB:Y,rfId:ee}=An(OE,Rr),ae=(e==null?void 0:e.width)??RE,le=(e==null?void 0:e.height)??LE,ge=Q.width/ae,F=Q.height/le,C=Math.max(ge,F),k=C*ae,I=C*le,P=H*C,K=Q.x-(k-Q.width)/2-P,L=Q.y-(I-Q.height)/2-P,O=k+P*2,q=I+P*2,E=`${PE}-${ee}`,X=_.useRef(0);X.current=C,_.useEffect(()=>{if(G.current){const de=_i(G.current),xe=Oe=>{const{transform:He,d3Selection:Ke,d3Zoom:Ct}=D.getState();if(Oe.sourceEvent.type!=="wheel"||!Ke||!Ct)return;const pt=-Oe.sourceEvent.deltaY*(Oe.sourceEvent.deltaMode===1?.05:Oe.sourceEvent.deltaMode?1:.002)*z,gt=He[2]*Math.pow(2,pt);Ct.scaleTo(Ke,gt)},be=Oe=>{const{transform:He,d3Selection:Ke,d3Zoom:Ct,translateExtent:pt,width:gt,height:yt}=D.getState();if(Oe.sourceEvent.type!=="mousemove"||!Ke||!Ct)return;const nt=X.current*Math.max(1,He[2])*(T?-1:1),$e={x:He[0]-Oe.sourceEvent.movementX*nt,y:He[1]-Oe.sourceEvent.movementY*nt},Re=[[0,0],[gt,yt]],ot=Yo.translate($e.x,$e.y).scale(He[2]),he=Ct.constrain()(ot,Re,pt);Ct.transform(Ke,he)},Ee=Uw().on("zoom",N?be:null).on("zoom.wheel",S?xe:null);return de.call(Ee),()=>{de.on("zoom",null)}}},[N,S,T,z]);const ne=w?de=>{const xe=Ui(de);w(de,{x:xe[0],y:xe[1]})}:void 0,ie=x?(de,xe)=>{const be=D.getState().nodeInternals.get(xe);x(de,be)}:void 0;return pe.createElement(Gd,{position:v,style:e,className:Br(["react-flow__minimap",t]),"data-testid":"rf__minimap"},pe.createElement("svg",{width:ae,height:le,viewBox:`${K} ${L} ${O} ${q}`,role:"img","aria-labelledby":E,ref:G,onClick:ne},R&&pe.createElement("title",{id:E},R),pe.createElement(TE,{onClick:ie,nodeColor:i,nodeStrokeColor:n,nodeBorderRadius:l,nodeClassName:a,nodeStrokeWidth:u,nodeComponent:d}),pe.createElement("path",{className:"react-flow__minimap-mask",d:`M${K-P},${L-P}h${O+P*2}v${q+P*2}h${-O-P*2}z
|
|
123
|
+
M${Y.x},${Y.y}h${Y.width}v${Y.height}h${-Y.width}z`,fill:m,fillRule:"evenodd",stroke:p,strokeWidth:g,pointerEvents:"none"})))}Rx.displayName="MiniMap";var IE=_.memo(Rx);function DE(){return pe.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},pe.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function zE(){return pe.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},pe.createElement("path",{d:"M0 0h32v4.2H0z"}))}function FE(){return pe.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},pe.createElement("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"}))}function BE(){return pe.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},pe.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"}))}function UE(){return pe.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},pe.createElement("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"}))}const su=({children:e,className:t,...n})=>pe.createElement("button",{type:"button",className:Br(["react-flow__controls-button",t]),...n},e);su.displayName="ControlButton";const WE=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),Lx=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:i=!0,fitViewOptions:a,onZoomIn:l,onZoomOut:u,onFitView:d,onInteractiveChange:m,className:p,children:g,position:v="bottom-left"})=>{const w=xr(),[x,N]=_.useState(!1),{isInteractive:S,minZoomReached:R,maxZoomReached:T}=An(WE,Rr),{zoomIn:z,zoomOut:H,fitView:D}=Fg();if(_.useEffect(()=>{N(!0)},[]),!x)return null;const G=()=>{z(),l==null||l()},Q=()=>{H(),u==null||u()},Y=()=>{D(a),d==null||d()},ee=()=>{w.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),m==null||m(!S)};return pe.createElement(Gd,{className:Br(["react-flow__controls",p]),position:v,style:e,"data-testid":"rf__controls"},t&&pe.createElement(pe.Fragment,null,pe.createElement(su,{onClick:G,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:T},pe.createElement(DE,null)),pe.createElement(su,{onClick:Q,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:R},pe.createElement(zE,null))),n&&pe.createElement(su,{className:"react-flow__controls-fitview",onClick:Y,title:"fit view","aria-label":"fit view"},pe.createElement(FE,null)),i&&pe.createElement(su,{className:"react-flow__controls-interactive",onClick:ee,title:"toggle interactivity","aria-label":"toggle interactivity"},S?pe.createElement(UE,null):pe.createElement(BE,null)),g)};Lx.displayName="Controls";var HE=_.memo(Lx),Hi;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Hi||(Hi={}));function qE({color:e,dimensions:t,lineWidth:n}){return pe.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function VE({color:e,radius:t}){return pe.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const GE={[Hi.Dots]:"#91919a",[Hi.Lines]:"#eee",[Hi.Cross]:"#e2e2e2"},KE={[Hi.Dots]:1,[Hi.Lines]:1,[Hi.Cross]:6},YE=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Ox({id:e,variant:t=Hi.Dots,gap:n=20,size:i,lineWidth:a=1,offset:l=2,color:u,style:d,className:m}){const p=_.useRef(null),{transform:g,patternId:v}=An(YE,Rr),w=u||GE[t],x=i||KE[t],N=t===Hi.Dots,S=t===Hi.Cross,R=Array.isArray(n)?n:[n,n],T=[R[0]*g[2]||1,R[1]*g[2]||1],z=x*g[2],H=S?[z,z]:T,D=N?[z/l,z/l]:[H[0]/l,H[1]/l];return pe.createElement("svg",{className:Br(["react-flow__background",m]),style:{...d,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:p,"data-testid":"rf__background"},pe.createElement("pattern",{id:v+e,x:g[0]%T[0],y:g[1]%T[1],width:T[0],height:T[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${D[0]},-${D[1]})`},N?pe.createElement(VE,{color:w,radius:z/l}):pe.createElement(qE,{dimensions:H,color:w,lineWidth:a})),pe.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${v+e})`}))}Ox.displayName="Background";var XE=_.memo(Ox);function Px(e,t={}){const n=e&&typeof e=="object"&&!Array.isArray(e)?e:null;if(!n)return null;const i=typeof n.x=="number"&&Number.isFinite(n.x)?n.x:null,a=typeof n.y=="number"&&Number.isFinite(n.y)?n.y:null,l=typeof n.zoom=="number"&&Number.isFinite(n.zoom)?n.zoom:null;if(i===null||a===null||l===null)return null;const u=typeof t.maxAbsTranslate=="number"&&Number.isFinite(t.maxAbsTranslate)?Math.abs(t.maxAbsTranslate):1e6;if(Math.abs(i)>u||Math.abs(a)>u)return null;const d=typeof t.minZoom=="number"&&Number.isFinite(t.minZoom)?t.minZoom:.025,m=typeof t.maxZoom=="number"&&Number.isFinite(t.maxZoom)?t.maxZoom:6,p=Math.min(d,m),g=Math.max(d,m);return{x:i,y:a,zoom:Math.min(g,Math.max(p,l))}}function eh(e){const t=String(e||"").trim();if(!t)return"";const n=t.indexOf(":");return n!==-1&&n<t.length-1?t.slice(n+1):t}function JE(e){const t=String(e||"").trim();if(!t)return"entity";const n=t.indexOf(":");if(n<=0||n>=t.length-1)return"entity";const i=t.slice(0,n).toLowerCase(),a=t.slice(n+1).toLowerCase();if(i==="ex"){const l=a.indexOf("-"),u=l>0?a.slice(0,l):a;return u==="person"?"person":u==="org"?"org":u==="concept"?"concept":u==="claim"?"claim":u==="event"?"event":u==="doc"?"doc":u==="thing"?"thing":"entity"}return i==="schema"||i==="skos"||i==="dcterms"||i==="rdf"||i==="cito"?"vocab":"entity"}function ZE(e){const t=String(e||"").trim();if(!t)return"";const n=t.indexOf(":");if(n<=0||n>=t.length-1)return eh(t);const i=t.slice(0,n).toLowerCase(),a=t.slice(n+1);if(i==="ex"){const l=a.indexOf("-");if(l>0&&l<a.length-1)return a.slice(l+1)}return eh(t)}function ag(e){const i=Math.max(1,Math.ceil(Math.sqrt(e.length))),a={};for(let l=0;l<e.length;l++){const u=Math.floor(l/i),d=l%i;a[e[l]]={x:d*240,y:u*120}}return a}function lg(e){const t=String(e??"");let n=2166136261;for(let i=0;i<t.length;i++)n^=t.charCodeAt(i),n=Math.imul(n,16777619);return n>>>0}function Ix(e){let t=e>>>0;return()=>{t+=1831565813;let n=Math.imul(t^t>>>15,1|t);return n^=n+Math.imul(n^n>>>7,61|n),((n^n>>>14)>>>0)/4294967296}}function QE(e,t){const n={},i=e.length;if(!i)return n;const a=Math.max(260,Math.sqrt(i)*150),l=t%360*Math.PI/180;for(let u=0;u<i;u++){const d=l+2*Math.PI*u/i;n[e[u]]={x:a*Math.cos(d),y:a*Math.sin(d)}}return n}function zy(e,t,n){var N;const i={};if(!e.length)return i;const a=new Map;for(const S of e)a.set(S,new Set);for(const S of t){const R=String((S==null?void 0:S.source)||"").trim(),T=String((S==null?void 0:S.target)||"").trim();if(!R||!T||R===T)continue;const z=a.get(R),H=a.get(T);z&&z.add(T),H&&H.add(R)}let l=e[0],u=-1;for(const S of e){const R=((N=a.get(S))==null?void 0:N.size)??0;(R>u||R===u&&S.localeCompare(l)<0)&&(l=S,u=R)}const d=new Map,m=[];for(d.set(l,0),m.push(l);m.length;){const S=m.shift(),R=d.get(S)??0,T=Array.from(a.get(S)??[]);T.sort((z,H)=>z.localeCompare(H));for(const z of T)d.has(z)||(d.set(z,R+1),m.push(z))}let p=0;for(const S of d.values())p=Math.max(p,S);for(const S of e)d.has(S)||d.set(S,p+1);const g=new Map;for(const S of e){const R=d.get(S)??0,T=g.get(R);T?T.push(S):g.set(R,[S])}const v=Array.from(g.keys()).sort((S,R)=>S-R),w=260,x=n%360*Math.PI/180;for(const S of v){const R=g.get(S)||[];if(R.sort((D,G)=>D.localeCompare(G)),S===0){if(R.length===1)i[R[0]]={x:0,y:0};else for(let G=0;G<R.length;G++){const Q=x+2*Math.PI*G/R.length;i[R[G]]={x:80*Math.cos(Q),y:80*Math.sin(Q)}}continue}const T=w*S,z=R.length;if(z===1){i[R[0]]={x:T,y:0};continue}const H=x+S*.35;for(let D=0;D<z;D++){const G=H+2*Math.PI*D/z;i[R[D]]={x:T*Math.cos(G),y:T*Math.sin(G)}}}return i}function eu(e,t={}){const n=t.kind??"grid",i=typeof t.seed=="number"&&Number.isFinite(t.seed)?Math.trunc(t.seed):0,a=e.nodes.map(l=>l.id);if(n==="grid")return ag(a);if(n==="circle")return QE(a,i);if(n==="radial")return zy(a,e.edges,i);if(n==="force"){const l=zy(a,e.edges,i),u=Ix(i||1),d=Math.max(10,Math.min(42,Math.sqrt(a.length)*2.75)),m={};for(const p of a){const g=l[p]||{x:0,y:0};m[p]={x:g.x+(u()-.5)*d,y:g.y+(u()-.5)*d}}return m}return ag(a)}function eA(e){return Array.isArray(e)?e.filter(t=>t&&typeof t=="object"&&typeof t.subject=="string"&&typeof t.predicate=="string"&&typeof t.object=="string"):[]}function tA(e,t={}){const n=!!(t.groupEdges??!0),i=Math.max(1,t.maxEdgeLabelPredicates??3),a=eA(e),l=new Set;for(const w of a){const x=String(w.subject||"").trim(),N=String(w.object||"").trim();x&&l.add(x),N&&l.add(N)}const u=Array.from(l);u.sort((w,x)=>w.localeCompare(x));const d=ag(u),m=u.map(w=>({id:w,type:"default",data:{label:ZE(w),kind:JE(w)},position:d[w]||{x:0,y:0}})),p=new Map,g=(w,x)=>{const N=String(w.subject||"").trim(),S=String(w.object||"").trim(),R=String(w.predicate||"").trim();return n?`edge:${N}:${S}`:`edge:${x}:${N}:${R}:${S}`};for(let w=0;w<a.length;w++){const x=a[w],N=g(x,w),S=p.get(N);S?S.push(x):p.set(N,[x])}const v=[];for(const[w,x]of p.entries()){const N=x[0],S=String(N.subject||"").trim(),R=String(N.object||"").trim();if(!S||!R)continue;const T=new Map;for(const Y of x){const ee=String(Y.predicate||"").trim();ee&&T.set(ee,(T.get(ee)||0)+1)}const z=Array.from(T.entries());z.sort((Y,ee)=>ee[1]-Y[1]||Y[0].localeCompare(ee[0]));const D=z.slice(0,i).map(([Y,ee])=>ee>1?`${eh(Y)}×${ee}`:eh(Y)).join(" | "),G=z.length>i?` +${z.length-i}`:"",Q=`${D}${G}`.trim();v.push({id:w,source:S,target:R,label:Q,animated:!1,data:{assertions:x,predicateSummary:Q}})}return{nodes:m,edges:v}}function nA(e,t,n,i={}){const a=i.directed!==!1,l=String(t||"").trim(),u=String(n||"").trim();if(!l||!u)return null;if(l===u)return{nodeIds:[l],edgeIds:[]};const d=new Map,m=(S,R,T)=>{const z=d.get(S);z?z.push({to:R,edgeId:T}):d.set(S,[{to:R,edgeId:T}])};for(const S of e.edges)m(S.source,S.target,S.id),a||m(S.target,S.source,S.id);const p=[l],g=new Map,v=new Map;for(g.set(l,null),v.set(l,null);p.length;){const S=p.shift(),R=d.get(S)||[];for(const T of R)if(!g.has(T.to)){if(g.set(T.to,S),v.set(T.to,T.edgeId),T.to===u){p.length=0;break}p.push(T.to)}}if(!g.has(u))return null;const w=[],x=[];let N=u;for(;N;){w.push(N);const S=v.get(N);S&&x.push(S),N=g.get(N)||null}return w.reverse(),x.reverse(),{nodeIds:w,edgeIds:x}}const Fy={seed:1,dt:1,springLength:240,springStrength:.03,repulsionStrength:9e3,centeringStrength:.003,damping:.85,maxSpeed:90,maxRepulsionNodes:320};function Sm(e,t={}){const n={...Fy,...t,seed:typeof t.seed=="number"&&Number.isFinite(t.seed)?Math.trunc(t.seed):Fy.seed},i=e.nodes.map(x=>x.id),a=i.length,l=new Float64Array(2*a),u=new Float64Array(2*a),d=new Float64Array(2*a),m=new Map;for(let x=0;x<a;x++)m.set(i[x],x);const p=t.positions??eu(e,{kind:"force",seed:n.seed}),g=Ix(n.seed||1),v=Math.max(8,Math.min(38,Math.sqrt(a)*2.25));for(let x=0;x<a;x++){const N=i[x],S=p[N],R=typeof(S==null?void 0:S.x)=="number"&&Number.isFinite(S.x)?S.x:(g()-.5)*500,T=typeof(S==null?void 0:S.y)=="number"&&Number.isFinite(S.y)?S.y:(g()-.5)*500;l[2*x]=R+(g()-.5)*v,l[2*x+1]=T+(g()-.5)*v,u[2*x]=0,u[2*x+1]=0}const w=[];for(const x of e.edges){const N=m.get(String((x==null?void 0:x.source)||"").trim()),S=m.get(String((x==null?void 0:x.target)||"").trim());typeof N!="number"||typeof S!="number"||N===S||w.push(N,S)}return{nodeIds:i,pos:l,vel:u,acc:d,edges:new Uint32Array(w),options:n,tick:0}}function rA(e,t=1){const n=e.nodeIds.length;if(!n)return;const i=e.options,a=i.dt;for(let l=0;l<Math.max(1,Math.trunc(t));l++){if(e.acc.fill(0),n<=i.maxRepulsionNodes){const x=i.repulsionStrength;for(let N=0;N<n;N++){const S=e.pos[2*N],R=e.pos[2*N+1];for(let T=N+1;T<n;T++){const z=e.pos[2*T]-S,H=e.pos[2*T+1]-R,D=z*z+H*H+1e-6,G=1/Math.sqrt(D),Q=x/D,Y=Q*z*G,ee=Q*H*G;e.acc[2*N]-=Y,e.acc[2*N+1]-=ee,e.acc[2*T]+=Y,e.acc[2*T+1]+=ee}}}const d=i.springLength,m=i.springStrength,p=e.edges;for(let x=0;x<p.length;x+=2){const N=p[x],S=p[x+1],R=e.pos[2*N],T=e.pos[2*N+1],z=e.pos[2*S],H=e.pos[2*S+1],D=z-R,G=H-T,Q=D*D+G*G+1e-6,Y=Math.sqrt(Q),ee=m*(Y-d),ae=ee*D/Y,le=ee*G/Y;e.acc[2*N]+=ae,e.acc[2*N+1]+=le,e.acc[2*S]-=ae,e.acc[2*S+1]-=le}const g=i.centeringStrength;for(let x=0;x<n;x++)e.acc[2*x]+=-g*e.pos[2*x],e.acc[2*x+1]+=-g*e.pos[2*x+1];const v=i.damping,w=i.maxSpeed;for(let x=0;x<n;x++){let N=(e.vel[2*x]+e.acc[2*x]*a)*v,S=(e.vel[2*x+1]+e.acc[2*x+1]*a)*v;const R=Math.sqrt(N*N+S*S);if(R>w){const T=w/R;N*=T,S*=T}e.vel[2*x]=N,e.vel[2*x+1]=S,e.pos[2*x]+=N*a,e.pos[2*x+1]+=S*a}e.tick+=1}}function sA(e){const t=e.nodeIds.length;if(!t)return 0;let n=0;for(let i=0;i<t;i++){const a=e.vel[2*i],l=e.vel[2*i+1];n+=Math.sqrt(a*a+l*l)}return n/t}function iA(e){const t={},n=e.nodeIds.length;for(let i=0;i<n;i++)t[e.nodeIds[i]]={x:e.pos[2*i],y:e.pos[2*i+1]};return t}function By(e,t="session"){const n=String(e??"").trim().toLowerCase();return n==="run"||n==="session"||n==="global"||n==="all"?n:t}function oA(){if(typeof window>"u"||typeof window.matchMedia!="function")return!1;try{return window.matchMedia("(pointer: coarse)").matches||window.matchMedia("(max-width: 720px)").matches}catch{return!1}}function aA(){return r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",children:[r.jsx("rect",{x:"3",y:"3",width:"3",height:"3",rx:"1"}),r.jsx("rect",{x:"3",y:"7",width:"3",height:"3",rx:"1"}),r.jsx("rect",{x:"3",y:"11",width:"3",height:"3",rx:"1"}),r.jsx("rect",{x:"8",y:"3.5",width:"6",height:"2",rx:"1",fill:"none",strokeWidth:"1.4"}),r.jsx("rect",{x:"8",y:"7.5",width:"6",height:"2",rx:"1",fill:"none",strokeWidth:"1.4"}),r.jsx("rect",{x:"8",y:"11.5",width:"6",height:"2",rx:"1",fill:"none",strokeWidth:"1.4"})]})}function Dx(e,t,n,i){const a=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.min(n,Math.max(t,a))}function Ad(e){const t=Dx(e,.6,2.4,1),n=240*t,i=9e3*t*t;return{springLength:n,repulsionStrength:i}}const Zd="abstractuic_amx_saved_layouts_v1",cg=.025,ug=6,zx=1e6;function Wg(){if(typeof window>"u")return null;try{return window.localStorage}catch{return null}}function dg(e,t="grid"){const n=String(e??"").trim().toLowerCase();return n==="grid"||n==="circle"||n==="radial"||n==="force"?n:t}function lA(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:null;if(!t)return null;const n=typeof t.x=="number"&&Number.isFinite(t.x)?t.x:null,i=typeof t.y=="number"&&Number.isFinite(t.y)?t.y:null;return n===null||i===null?null:{x:n,y:i}}function Uy(e){const t=Wg();if(!t)return null;const n=String(e??"").trim();if(!n)return null;try{const i=t.getItem(Zd);if(!i)return null;const a=JSON.parse(i),l=a&&typeof a=="object"&&!Array.isArray(a)?a:null;if(!l)return null;const u=l[n],d=u&&typeof u=="object"&&!Array.isArray(u)?u:null;if(!d)return null;const m=d.version===1?1:null;if(m===null)return null;const p=dg(d.kind,"grid"),g=typeof d.seed=="number"&&Number.isFinite(d.seed)?Math.trunc(d.seed):lg(n),v=d.positions&&typeof d.positions=="object"&&!Array.isArray(d.positions)?d.positions:null,w={};if(v)for(const[S,R]of Object.entries(v)){const T=lA(R);T&&(w[String(S)]=T)}const x=Px(d.viewport,{minZoom:cg,maxZoom:ug,maxAbsTranslate:zx})??void 0,N=typeof d.saved_at=="string"&&d.saved_at.trim()?d.saved_at.trim():"";return{version:m,kind:p,seed:g,positions:w,viewport:x,saved_at:N}}catch{return null}}function cA(e,t){const n=Wg();if(!n)return;const i=String(e??"").trim();if(i)try{const a=n.getItem(Zd),l=a?JSON.parse(a):null,u=l&&typeof l=="object"&&!Array.isArray(l)?{...l}:{};u[i]=t,n.setItem(Zd,JSON.stringify(u))}catch{}}function uA(e){const t=Wg();if(!t)return;const n=String(e??"").trim();if(n)try{const i=t.getItem(Zd);if(!i)return;const a=JSON.parse(i),l=a&&typeof a=="object"&&!Array.isArray(a)?{...a}:null;if(!l||!(n in l))return;delete l[n],t.setItem(Zd,JSON.stringify(l))}catch{}}function dA(e){const t=String(e??"").trim();if(!t)return;const n=Number(t);if(Number.isFinite(n))return n}function w_(e,t){const n=!!(t!=null&&t.allowZero),i=!!(t!=null&&t.allowNegativeOne),a=String(e??"").trim();if(!a)return;const l=Number(a);if(!Number.isFinite(l))return;const u=Math.trunc(l);if(i&&u===-1)return-1;if(!(!n&&u<=0)&&!(n&&u<0))return u}function fA(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e,n=typeof t.recall_level=="string"?t.recall_level:"",i=t.applied&&typeof t.applied=="object"&&!Array.isArray(t.applied)?t.applied:null,a=[];return n&&a.push(`recall_level=${n}`),i&&(typeof i.limit=="number"&&a.push(`limit=${i.limit}`),typeof i.min_score=="number"&&a.push(`min_score=${i.min_score}`),typeof i.max_input_tokens=="number"&&a.push(`max_input_tokens=${i.max_input_tokens}`)),a.length?a.join(" · "):null}function mA(e){if(!e||typeof e!="object")return null;const t=[],n=typeof e.scope=="string"?e.scope.trim():"",i=typeof e.owner_id=="string"?e.owner_id.trim():"";n&&t.push(`scope=${n}`),i&&t.push(`owner_id=${i}`);const a=typeof e.confidence=="number"&&Number.isFinite(e.confidence)?e.confidence:null;a!==null&&t.push(`confidence=${a.toFixed(3)}`);const l=e.provenance&&typeof e.provenance=="object"&&!Array.isArray(e.provenance)?e.provenance:null;if(l){const p=typeof l.writer_run_id=="string"?l.writer_run_id.trim():"",g=typeof l.writer_workflow_id=="string"?l.writer_workflow_id.trim():"";p&&t.push(`writer_run_id=${p}`),g&&t.push(`writer_workflow_id=${g}`)}const u=e.attributes&&typeof e.attributes=="object"&&!Array.isArray(e.attributes)?e.attributes:null,d=u&&u._retrieval&&typeof u._retrieval=="object"&&!Array.isArray(u._retrieval)?u._retrieval:null,m=d&&typeof d.score=="number"&&Number.isFinite(d.score)?d.score:null;return m!==null&&t.push(`score=${m.toFixed(3)}`),t.length?t.join(" · "):null}function hA(e,t){const n=String(e??""),i=String(t??"").trim();if(!i)return n;const a=n.toLowerCase().indexOf(i.toLowerCase());if(a<0)return n;const l=n.slice(0,a),u=n.slice(a,a+i.length),d=n.slice(a+i.length);return r.jsxs(r.Fragment,{children:[l,r.jsx("span",{className:"amx-hl",children:u}),d]})}function Md(e){const t=String(e??"").trim().toLowerCase();return t==="person"?{stroke:"rgba(96, 165, 250, 0.82)",bg:"rgba(96, 165, 250, 0.10)",minimap:"rgba(96, 165, 250, 0.85)"}:t==="org"?{stroke:"rgba(34, 197, 94, 0.78)",bg:"rgba(34, 197, 94, 0.10)",minimap:"rgba(34, 197, 94, 0.82)"}:t==="concept"?{stroke:"rgba(168, 85, 247, 0.78)",bg:"rgba(168, 85, 247, 0.10)",minimap:"rgba(168, 85, 247, 0.82)"}:t==="claim"?{stroke:"rgba(251, 191, 36, 0.78)",bg:"rgba(251, 191, 36, 0.10)",minimap:"rgba(251, 191, 36, 0.82)"}:t==="event"?{stroke:"rgba(239, 68, 68, 0.74)",bg:"rgba(239, 68, 68, 0.10)",minimap:"rgba(239, 68, 68, 0.80)"}:t==="doc"?{stroke:"rgba(14, 165, 233, 0.74)",bg:"rgba(14, 165, 233, 0.10)",minimap:"rgba(14, 165, 233, 0.80)"}:t==="vocab"?{stroke:"rgba(148, 163, 184, 0.55)",bg:"rgba(148, 163, 184, 0.06)",minimap:"rgba(148, 163, 184, 0.70)"}:t==="thing"?{stroke:"rgba(255, 255, 255, 0.20)",bg:"rgba(255, 255, 255, 0.04)",minimap:"rgba(255, 255, 255, 0.30)"}:{stroke:"rgba(255, 255, 255, 0.14)",bg:"rgba(0, 0, 0, 0.18)",minimap:"rgba(255, 255, 255, 0.24)"}}function _A(e){const t=typeof e=="string"?e.trim():"";if(!t)return null;const n=t.replace(/(\.\d{3})\d+/,"$1"),i=Date.parse(n);return Number.isFinite(i)?i:null}function Td(e){const t=_A(e);if(t===null)return"";const n=new Date(t),i=n.getUTCFullYear(),a=String(n.getUTCMonth()+1).padStart(2,"0"),l=String(n.getUTCDate()).padStart(2,"0"),u=String(n.getUTCHours()).padStart(2,"0"),d=String(n.getUTCMinutes()).padStart(2,"0");return`${i}/${a}/${l} ${u}:${d}`}function Fx(e){const t=String(e??"").trim();if(!t)return"";const n=t.indexOf(":");return n!==-1&&n<t.length-1?t.slice(n+1):t}function x_(e,t){const n=String(e??"").trim().toLowerCase();return!!(n&&t.has(n))}function gA(e,t={}){const n=Math.max(1,t.maxPredicates??3),i=new Map;for(const m of e){const p=String((m==null?void 0:m.predicate)||"").trim();p&&i.set(p,(i.get(p)||0)+1)}const a=Array.from(i.entries());a.sort((m,p)=>p[1]-m[1]||m[0].localeCompare(p[0]));const u=a.slice(0,n).map(([m,p])=>{const g=Fx(m);return p>1?`${g}×${p}`:g}).join(" | "),d=a.length>n?` +${a.length-n}`:"";return`${u}${d}`.trim()}function pA({resetKey:e,queryMode:t,items:n,activeMemoryText:i,packets:a,packetsVersion:l,packedCount:u,dropped:d,estimatedTokens:m,effort:p,warnings:g,onQuery:v,onItemsReplace:w,onOpenSpan:x,onOpenTranscript:N}){var eo;const S=_.useRef(null),R=_.useMemo(()=>{const B=n==null?void 0:n[0],re=n==null?void 0:n[n.length-1],we=B?`${B.subject}|${B.predicate}|${B.object}`:"",Se=re?`${re.subject}|${re.predicate}|${re.object}`:"";return`${(n==null?void 0:n.length)||0}:${we}:${Se}`},[n]),T=String(e??R),z=t==="replace"?"replace":"override",[H,D]=_.useState(null),[G,Q]=_.useState(null),[Y,ee]=_.useState(!1),[ae,le]=_.useState(""),[ge,F]=_.useState(!1),[C,k]=_.useState("");_.useEffect(()=>{D(null),Q(null),le(""),ee(!1),k(""),F(!1)},[T]);const[I,P]=_.useState(""),[K,L]=_.useState(!0),[O,q]=_.useState(!1),[E,X]=_.useState(!0),[ne]=_.useState(()=>({compact:oA(),show:!1})),ie=ne.compact,[de,xe]=_.useState(ne.show),[be,Ee]=_.useState(!1),Oe=T,He=_.useMemo(()=>lg(Oe),[Oe]),[Ke,Ct]=_.useState("grid"),[pt,gt]=_.useState(He),[yt,nt]=_.useState(!1),[$e,Re]=_.useState(1),ot=_.useRef(null),he=_.useRef(null),Pe=_.useRef(!1),[Ve,Rt]=_.useState(0),Xt=_.useRef(null),fn=_.useRef(0),Ft=_.useRef(0),At=_.useRef(0),sn=_.useRef(0),[zn,$t]=_.useState(!1),[pn,Pn]=_.useState(""),[Cn,yn]=_.useState({}),Mn=_.useRef({});_.useEffect(()=>{Mn.current=Cn},[Cn]);const[mn,br]=_.useState(""),[Hn,Qn]=_.useState(""),ys=_.useMemo(()=>{var re;const B=(re=n==null?void 0:n[0])==null?void 0:re.scope;return By(B,"session")},[n]),[qn,oe]=_.useState(ys),[ve,qe]=_.useState("standard"),[We,et]=_.useState(""),[at,Nt]=_.useState(""),[xt,Wt]=_.useState(""),[lt,Vt]=_.useState(""),[It,jt]=_.useState(""),[ft,Mt]=_.useState(""),[Ce,Ut]=_.useState(""),[St,nn]=_.useState("qwen/qwen3-next-80b");_.useEffect(()=>{oe(ys)},[T]);const kt=Array.isArray(n)?n:[],er=typeof i=="string"?i:"",tr=Array.isArray(a)?a:[],Ur=typeof l=="number"?l:void 0,jr=typeof u=="number"?u:void 0,Zr=typeof d=="number"?d:void 0,Wr=typeof m=="number"?m:void 0,Gi=p,ye=g,Vn=z==="override"&&(H!=null&&H.items)&&Array.isArray(H.items)?H.items:kt,cn=typeof(H==null?void 0:H.active_memory_text)=="string"&&H.active_memory_text.trim()?H.active_memory_text:er,Ki=(H==null?void 0:H.effort)??Gi,vi=(H==null?void 0:H.warnings)??ye,vs=_.useMemo(()=>new Set(["rdf:type","schema:name","skos:preflabel","skos:altlabel","dcterms:title","dcterms:identifier"]),[]),Qr=_.useMemo(()=>E?Vn:(Vn||[]).filter(B=>!x_(B==null?void 0:B.predicate,vs)),[Vn,E,vs]),Ts=_.useMemo(()=>tA(Vn,{groupEdges:K}),[Vn,K]),rt=_.useMemo(()=>{if(E)return Ts;const B=[];for(const re of Ts.edges){const Se=(re&&re.data&&Array.isArray(re.data.assertions)?re.data.assertions:[]).filter(Fe=>!x_(Fe==null?void 0:Fe.predicate,vs));if(!Se.length)continue;const je=gA(Se);B.push({...re,label:je,data:{...re.data,assertions:Se,predicateSummary:je}})}return{nodes:Ts.nodes,edges:B}},[Ts,E,vs]),Qt=_.useMemo(()=>rt.nodes.map(B=>B.id),[rt.nodes]),ur=_.useMemo(()=>{const B=Qt[0]||"",re=Qt[Qt.length-1]||"";return`${Qt.length}:${B}:${re}`},[Qt]),Js=_.useMemo(()=>{var re;const B=new Map;for(const we of rt.nodes)B.set(we.id,String(((re=we.data)==null?void 0:re.label)||we.id));return B},[rt.nodes]),nr=_.useMemo(()=>{var re;const B=new Map;for(const we of rt.nodes)B.set(we.id,String(((re=we.data)==null?void 0:re.kind)||""));return B},[rt.nodes]),Yi=I.trim().toLowerCase(),Xi=_.useMemo(()=>{var re;if(!Yi)return new Set;const B=new Set;for(const we of rt.nodes){const Se=String(we.id||"").toLowerCase(),je=String(((re=we.data)==null?void 0:re.label)||"").toLowerCase();(Se.includes(Yi)||je.includes(Yi))&&B.add(we.id)}return B},[rt.nodes,Yi]),Qo=_.useCallback((B,re)=>{const we={};for(const Se of Qt){const je=B[Se]||re[Se];we[Se]=je?{x:je.x,y:je.y}:{x:0,y:0}}return we},[Qt]);_.useEffect(()=>{yn(B=>{const re=eu(rt,{kind:Ke,seed:pt}),we={};for(const Se of Qt){const je=B[Se]||re[Se];we[Se]=je?{x:je.x,y:je.y}:{x:0,y:0}}return we})},[rt,Ke,pt,Qt,ur]),_.useEffect(()=>{if(!Pe.current)return;const B=S.current;if(!(!B||typeof B.fitView!="function")&&Qt.length){Pe.current=!1;try{B.fitView({padding:.2,duration:0})}catch{try{B.fitView({padding:.2})}catch{}}}},[Qt.length,ur,Cn]),_.useEffect(()=>{nt(!1),ot.current=null,he.current=null,Pe.current=!1,fn.current=0,Ft.current=0,At.current=0;const B=Uy(Oe);if(B&&Object.keys(B.positions||{}).length){if(Ct(B.kind),gt(B.seed),$t(!0),Pn(B.saved_at||""),B.viewport){he.current=B.viewport;const je=S.current;if(je&&typeof je.setViewport=="function"){try{je.setViewport(B.viewport,{duration:0})}catch{try{je.setViewport(B.viewport)}catch{}}he.current=null}}else Pe.current=!0;const Se=eu(rt,{kind:B.kind,seed:B.seed});yn(Qo(B.positions,Se));return}$t(!1),Pn("");const re=lg(Oe);gt(re);const we=eu(rt,{kind:Ke,seed:re});yn(we),Ke==="force"&&rt.nodes.length>0&&rt.nodes.length<=320&&(ot.current=Sm(rt,{seed:re,positions:we,...Ad($e)}),nt(!0))},[Oe]);const In=_.useMemo(()=>{const B=String(mn||"").trim(),re=String(Hn||"").trim();return!B||!re?null:nA(rt,B,re,{directed:O})},[rt,mn,Hn,O]),es=!!(In&&String(mn||"").trim()&&String(Hn||"").trim()),$n=_.useMemo(()=>{const B=String(mn||"").trim(),re=String(Hn||"").trim();if(!B||!re)return null;const we=O,Se=new Map,je=(it,ct)=>{const Bt=Se.get(it);Bt?Bt.push(ct):Se.set(it,[ct])};for(const it of rt.edges)je(it.source,it.target),we||je(it.target,it.source);const Fe=new Set,mt=[];for(Fe.add(B),mt.push(B);mt.length;){const it=mt.shift(),ct=Se.get(it)||[];for(const Bt of ct)Fe.has(Bt)||(Fe.add(Bt),mt.push(Bt))}return{reachableFromStart:Fe.size,endReachable:Fe.has(re),nodes:rt.nodes.length,edges:rt.edges.length,assertions:Qr.length}},[O,rt.edges,rt.nodes.length,Hn,mn,Qr.length]),ts=_.useMemo(()=>new Set((In==null?void 0:In.nodeIds)||[]),[In]),Ji=_.useMemo(()=>new Set((In==null?void 0:In.edgeIds)||[]),[In]),[Kn,Hr]=_.useState(""),[rr,Rs]=_.useState(""),dr=!!(String(Kn||"").trim()||String(rr||"").trim()),ea=_.useMemo(()=>{const B=new Set,re=new Set,we=String(Kn||"").trim(),Se=String(rr||"").trim();if(we){B.add(we);for(const je of rt.edges)(je.source===we||je.target===we)&&(re.add(je.id),B.add(je.source),B.add(je.target));return{nodes:B,edges:re}}if(Se){const je=rt.edges.find(Fe=>Fe.id===Se);je&&(re.add(je.id),B.add(je.source),B.add(je.target))}return{nodes:B,edges:re}},[rt.edges,rr,Kn]);_.useEffect(()=>{Hr(""),Rs(""),br(""),Qn("")},[T]);const[Zi,en]=_.useState(!1);_.useEffect(()=>{en(!1)},[T]),_.useEffect(()=>{yt||(ot.current=null)},[yt]),_.useEffect(()=>{if(Ke!=="force")return;const B=ot.current;if(!B)return;const re=Ad($e);B.options.springLength=re.springLength,B.options.repulsionStrength=re.repulsionStrength},[Ke,$e]),_.useEffect(()=>{Ke!=="force"&&yt&&nt(!1)},[Ke,yt]),_.useEffect(()=>{if(!yt||Ke!=="force"||rt.nodes.length===0||typeof window>"u"||typeof window.requestAnimationFrame!="function")return;ot.current||(ot.current=Sm(rt,{seed:pt,positions:Mn.current,...Ad($e)}));let B=0,re=0,we=0;const Se=rt.nodes.length<=140?2:1,je=1600,Fe=.08,mt=it=>{if(B=window.requestAnimationFrame(mt),it-re<33)return;re=it;const ct=ot.current;if(!ct){nt(!1);return}rA(ct,Se),we+=Se,yn(iA(ct)),(sA(ct)<=Fe||we>=je)&&nt(!1)};return B=window.requestAnimationFrame(mt),()=>{window.cancelAnimationFrame(B)}},[rt,Ke,yt,pt]);const sl=_.useMemo(()=>rt.nodes.map(B=>{var Kt;const re=ts.has(B.id),we=Xi.has(B.id),Se=Kn===B.id,je=dr&&ea.nodes.has(B.id),Fe=Md((Kt=B.data)==null?void 0:Kt.kind),mt="rgba(34, 211, 238, 0.88)",it=we?"0 0 0 1px rgba(34, 211, 238, 0.34), 0 0 16px rgba(34, 211, 238, 0.26), 0 0 44px rgba(34, 211, 238, 0.14)":"",ct=re?"rgba(168, 85, 247, 0.9)":we?mt:Fe.stroke,Bt=Se?"0 0 0 2px rgba(255,255,255,0.20), 0 18px 46px rgba(0,0,0,0.55)":je?"0 0 0 1px rgba(96, 165, 250, 0.28), 0 12px 34px rgba(0,0,0,0.45)":void 0,Lt=it&&Bt?`${it}, ${Bt}`:Bt||it||void 0,sr=re?"rgba(168, 85, 247, 0.10)":we?"rgba(34, 211, 238, 0.08)":Fe.bg,Dt=es?re||Se?1:.16:dr?je||Se?1:.1:1;return{...B,position:Cn[B.id]?{x:Cn[B.id].x,y:Cn[B.id].y}:B.position,style:{...B.style||{},border:`1px solid ${ct}`,borderRadius:10,background:sr,color:"rgba(255,255,255,0.92)",opacity:Dt,padding:8,fontSize:12,boxShadow:Lt,width:180,cursor:"pointer"}}}),[rt.nodes,es,Xi,Cn,Kn,ts,dr,ea.nodes]),wi=_.useMemo(()=>rt.edges.map(B=>{const re=Ji.has(B.id),we=rr===B.id,Se=dr&&ea.edges.has(B.id),je=re?"rgba(168, 85, 247, 0.9)":dr?Se||we?"rgba(96, 165, 250, 0.55)":"rgba(255,255,255,0.14)":"rgba(255,255,255,0.18)",Fe=re?2.75:dr?Se||we?2.25:1.25:1.5,mt=we?"drop-shadow(0 0 10px rgba(168, 85, 247, 0.25))":void 0,it=re?"rgba(168, 85, 247, 0.9)":es?"rgba(255,255,255,0.10)":"rgba(255,255,255,0.28)",ct=es?re||we?1:.1:dr?Se||we?1:.08:1,Bt=es?re||we?1:0:dr?Se||we?1:0:1,Lt=es?re||we?String(B.label||""):"":String(B.label||"");return{...B,label:Lt,style:{...B.style||{},stroke:je,strokeWidth:Fe,filter:mt,opacity:ct},animated:!1,markerEnd:{type:Xd.ArrowClosed,color:it,width:20,height:20},labelShowBg:!0,labelBgPadding:[6,3],labelBgBorderRadius:10,labelBgStyle:{fill:`rgba(0, 0, 0, ${.38*Bt})`,stroke:`rgba(255, 255, 255, ${.14*Bt})`,strokeWidth:1},labelStyle:{fill:`rgba(255, 255, 255, ${.92*Bt})`,fontSize:10,fontWeight:600,letterSpacing:.2,textTransform:"lowercase"}}}),[rt.edges,es,rr,Ji,dr,ea.edges]),ns=_.useMemo(()=>{if(!rr)return[];const B=rt.edges.find(we=>we.id===rr),re=B&&B.data&&Array.isArray(B.data.assertions)?B.data.assertions:[];return Array.isArray(re)?re:[]},[rt.edges,rr]),Sr=_.useMemo(()=>rr&&rt.edges.find(B=>B.id===rr)||null,[rt.edges,rr]),ta=_.useMemo(()=>{const B=String(Kn||"").trim();return B?Vn.filter(re=>!re||typeof re!="object"||!(re.subject===B||re.object===B)?!1:E?!0:!x_(re.predicate,vs)):[]},[Vn,Kn,E,vs]),ws=_.useMemo(()=>rr?ns:ta,[ns,rr,ta]),Zs=_.useMemo(()=>{const B=new Map;for(const re of ws){if(!re||typeof re!="object")continue;const we=re.provenance&&typeof re.provenance=="object"&&!Array.isArray(re.provenance)?re.provenance:null,Se=we&&typeof we.span_id=="string"?we.span_id.trim():"",je=we&&typeof we.writer_run_id=="string"?we.writer_run_id.trim():"",Fe=typeof re.owner_id=="string"?re.owner_id.trim():"",mt=je||Fe;if(!mt||!Se)continue;const it=`${mt}|${Se}`,ct=B.get(it),Bt=typeof re.observed_at=="string"?re.observed_at.trim():"";ct?(ct.count+=1,Bt&&(!ct.last_observed_at||Bt>ct.last_observed_at)&&(ct.last_observed_at=Bt,ct.last_observed_at_fmt=Td(Bt),ct.assertion=re)):B.set(it,{span_run_id:mt,span_id:Se,writer_run_id:je,count:1,last_observed_at:Bt,last_observed_at_fmt:Td(Bt),assertion:re})}return Array.from(B.values()).sort((re,we)=>String(we.last_observed_at||"").localeCompare(String(re.last_observed_at||"")))},[ws]),xi=_.useMemo(()=>{const B=new Map;for(const re of ws){if(!re||typeof re!="object")continue;const we=re.provenance&&typeof re.provenance=="object"&&!Array.isArray(re.provenance)?re.provenance:null,Se=we&&typeof we.span_id=="string"?we.span_id.trim():"",je=we&&typeof we.writer_run_id=="string"?we.writer_run_id.trim():"";if(!je||Se)continue;const Fe=B.get(je),mt=typeof re.observed_at=="string"?re.observed_at.trim():"";Fe?(Fe.count+=1,mt&&(!Fe.last_observed_at||mt>Fe.last_observed_at)&&(Fe.last_observed_at=mt,Fe.last_observed_at_fmt=Td(mt),Fe.assertion=re)):B.set(je,{run_id:je,count:1,last_observed_at:mt,last_observed_at_fmt:Td(mt),assertion:re})}return Array.from(B.values()).sort((re,we)=>String(we.last_observed_at||"").localeCompare(String(re.last_observed_at||"")))},[ws]),qr=_.useCallback(B=>{const re=String(B.run_id||"").trim(),we=typeof B.span_id=="string"?String(B.span_id).trim():"";if(re){if(N){try{N({run_id:re,span_id:we||void 0,assertion:B.assertion})}catch{}return}if(x&&we)try{x({run_id:re,span_id:we,assertion:B.assertion})}catch{}}},[x,N]),kr=_.useCallback(async B=>{const re=String(B??"");if(re)try{await navigator.clipboard.writeText(re)}catch{}},[]),xs=_.useCallback(()=>{const B=S.current;if(!(!B||typeof B.fitView!="function")){if(Kn&&typeof B.getNode=="function"){const re=B.getNode(Kn);if(re){B.fitView({nodes:[re],padding:.55,duration:350});return}}B.fitView({padding:.2,duration:350})}},[Kn]),Vr=_.useCallback(B=>{const re=B.kind,we=Math.trunc(B.seed);nt(!1),ot.current=null,he.current=null,Ct(re),gt(we);const Se=eu(rt,{kind:re,seed:we});yn(Se),re==="force"&&(B.autoPlay??!0)&&rt.nodes.length>0&&rt.nodes.length<=320&&(ot.current=Sm(rt,{seed:we,positions:Se,...Ad($e)}),nt(!0))},[rt,$e]),bi=_.useCallback(()=>{if(Ke==="force"){if(yt){nt(!1);return}ot.current=Sm(rt,{seed:pt,positions:Mn.current,...Ad($e)}),nt(!0)}},[rt,Ke,yt,pt,$e]);_.useEffect(()=>()=>{typeof window>"u"||typeof window.cancelAnimationFrame=="function"&&sn.current&&window.cancelAnimationFrame(sn.current)},[]);const rs=_.useCallback(()=>{const B=S.current;if(!B||typeof B.getViewport!="function"||!Qt.length)return null;const re=Xt.current;if(!re)return null;const we=re.getBoundingClientRect();if(!Number.isFinite(we.width)||!Number.isFinite(we.height)||we.width<64||we.height<64)return null;const Se=B.getViewport(),je=typeof(Se==null?void 0:Se.zoom)=="number"&&Number.isFinite(Se.zoom)?Se.zoom:null,Fe=typeof(Se==null?void 0:Se.x)=="number"&&Number.isFinite(Se.x)?Se.x:null,mt=typeof(Se==null?void 0:Se.y)=="number"&&Number.isFinite(Se.y)?Se.y:null;if(je===null||Fe===null||mt===null||je<=0)return null;const it=140,ct=Math.min(Qt.length,180),Bt=Mn.current;let Lt=0,sr=0;for(const Dt of Qt){const Kt=Bt[Dt];if(!Kt||!Number.isFinite(Kt.x)||!Number.isFinite(Kt.y))continue;sr+=1;const hn=[{x:Kt.x,y:Kt.y},{x:Kt.x+90,y:Kt.y+24}];for(const _n of hn){const mr=_n.x*je+Fe,Nr=_n.y*je+mt;if(mr>-it&&mr<we.width+it&&Nr>-it&&Nr<we.height+it)return!1}if(Lt++,Lt>=ct)break}return sr?!0:null},[Qt]),fr=_.useCallback(B=>{typeof window>"u"||typeof window.requestAnimationFrame!="function"||sn.current||(sn.current=window.requestAnimationFrame(()=>{sn.current=0;const re=rs();if(re===null){if(At.current>=12)return;At.current+=1,window.setTimeout(()=>fr(`${B}:probe`),120);return}if(re!==!0){At.current=0,Ft.current=0;return}At.current=0;const we=S.current;if(we&&typeof we.fitView=="function")try{we.fitView({padding:.2,duration:0})}catch{try{we.fitView({padding:.2})}catch{}}if(Ft.current+=1,Ft.current>=4&&fn.current<1){Ft.current=0,fn.current+=1,Rt(Se=>Se+1);return}Ft.current<8&&window.setTimeout(()=>fr(`${B}:retry`),220)}))},[rs]);_.useEffect(()=>{Ft.current=0,fn.current=0,At.current=0,fr("mount")},[T,fr]),_.useEffect(()=>{fr("graph change")},[ur,fr]),_.useEffect(()=>{const B=Xt.current;if(!B||typeof window>"u"||typeof ResizeObserver!="function")return;const re=new ResizeObserver(()=>fr("resize"));return re.observe(B),()=>re.disconnect()},[fr]);const ji=_.useCallback(()=>{const B=new Date().toISOString(),re={};for(const mt of Qt){const it=Mn.current[mt];it&&typeof it.x=="number"&&typeof it.y=="number"&&(re[mt]={x:it.x,y:it.y})}const we=S.current,Se=we&&typeof we.toObject=="function"?we.toObject():null,je=Se&&Se.viewport?Se.viewport:we&&typeof we.getViewport=="function"?we.getViewport():null,Fe=Px(je,{minZoom:cg,maxZoom:ug,maxAbsTranslate:zx})??void 0;cA(Oe,{version:1,kind:Ke,seed:pt,positions:re,viewport:Fe,saved_at:B}),$t(!0),Pn(B),nt(!1)},[Oe,Ke,pt,Qt]),fo=_.useCallback(()=>{const B=Uy(Oe);if(!B)return;nt(!1),ot.current=null,Ct(B.kind),gt(B.seed),$t(!0),Pn(B.saved_at||""),he.current=B.viewport||null,Pe.current=!B.viewport;const re=eu(rt,{kind:B.kind,seed:B.seed});if(yn(Qo(B.positions,re)),B.viewport){const we=S.current;if(we&&typeof we.setViewport=="function"){try{we.setViewport(B.viewport,{duration:0})}catch{try{we.setViewport(B.viewport)}catch{}}he.current=null}}},[Qo,rt,Oe]),il=_.useCallback(()=>{uA(Oe),$t(!1),Pn("")},[Oe]),Gr=_.useCallback(B=>{if(!Array.isArray(B)||B.length===0)return;let re=!1;yn(we=>{let Se=we,je=!1;for(const Fe of B){const mt=Fe&&typeof Fe=="object"&&"id"in Fe&&typeof Fe.id=="string"?String(Fe.id):"",it=(Fe==null?void 0:Fe.type)==="position"?Fe==null?void 0:Fe.position:null;mt&&it&&typeof it.x=="number"&&typeof it.y=="number"&&(je||(Se={...we},je=!0),Se[mt]={x:it.x,y:it.y},Fe!=null&&Fe.dragging&&(re=!0))}return je?Se:we}),re&&yt&&nt(!1)},[yt]),mo=_.useMemo(()=>{const B=new Map;for(const re of rt.edges)B.set(re.id,re);return B},[rt.edges]),Ls=_.useMemo(()=>{var Se;if(!In)return[];const B=In.nodeIds||[],re=In.edgeIds||[],we=[];for(let je=0;je<Math.min(B.length-1,re.length);je++){const Fe=B[je],mt=B[je+1],it=re[je],ct=mo.get(it),Bt=String(((Se=ct==null?void 0:ct.data)==null?void 0:Se.predicateSummary)||(ct==null?void 0:ct.label)||"").trim(),Lt=ct&&ct.source===Fe&&ct.target===mt?"forward":ct&&ct.source===mt&&ct.target===Fe?"reverse":"unknown";we.push({from:Fe,to:mt,edgeId:it,predicate:Bt,dir:Lt})}return we},[mo,In]),oc=_.useCallback(async()=>{if(v){le(""),k(""),ee(!0);try{const B=dA(It),re=w_(ft,{allowZero:!0,allowNegativeOne:!0}),we=w_(Ce,{allowZero:!0}),Se=await v({scope:qn,owner_id:void 0,recall_level:ve,query_text:We||void 0,subject:at||void 0,predicate:xt||void 0,object:lt||void 0,min_score:B,limit:re,max_input_tokens:we,model:St||void 0});D(Se),Q("live query"),z==="replace"&&w&&Se&&Array.isArray(Se.items)&&w(Se.items,{kind:"live query",result:Se})}catch(B){const re=B instanceof Error?B.message:String(B);le(re||"Query failed")}finally{ee(!1)}}},[ft,Ce,It,St,lt,w,v,xt,z,We,ve,qn,at]),ss=_.useCallback(async()=>{if(!v)return;const B=String(mn||"").trim(),re=String(Hn||"").trim();if(!B||!re)return;const we=Math.max(200,w_(ft)??80),Se=60;k(""),le(""),F(!0);try{const je=[],Fe=new Set,mt=Dt=>{if(!Dt||typeof Dt!="object"||typeof Dt.subject!="string"||typeof Dt.predicate!="string"||typeof Dt.object!="string")return;const Kt=`${Dt.subject}|${Dt.predicate}|${Dt.object}|${String(Dt.observed_at||"")}|${String(Dt.scope||"")}|${String(Dt.owner_id||"")}`;Fe.has(Kt)||(Fe.add(Kt),je.push(Dt))};for(const Dt of Vn)mt(Dt);const it=O,ct=new Set,Bt=[B],Lt=new Set([B]),sr=async Dt=>{const Kt=await v({scope:qn,recall_level:ve,min_score:0,limit:we,subject:Dt,query_text:void 0,max_input_tokens:0,model:void 0});if(Kt&&Array.isArray(Kt.items)){for(const hn of Kt.items)if(mt(hn),typeof hn.subject=="string"&&hn.subject.trim()===Dt&&typeof hn.object=="string"){const _n=hn.object.trim();_n&&!Lt.has(_n)&&(Lt.add(_n),Bt.push(_n))}}if(!it){const hn=await v({scope:qn,recall_level:ve,min_score:0,limit:we,object:Dt,query_text:void 0,max_input_tokens:0,model:void 0});if(hn&&Array.isArray(hn.items)){for(const _n of hn.items)if(mt(_n),typeof _n.object=="string"&&_n.object.trim()===Dt&&typeof _n.subject=="string"){const mr=_n.subject.trim();mr&&!Lt.has(mr)&&(Lt.add(mr),Bt.push(mr))}}}};for(;Bt.length&&ct.size<Se&&!Lt.has(re);){const Dt=Bt.shift();!Dt||ct.has(Dt)||(ct.add(Dt),await sr(Dt))}D({ok:!0,count:je.length,items:je,active_memory_text:cn,raw:{expanded_for_path:!0,expanded_nodes:ct.size,discovered_nodes:Lt.size,merged:je.length,directed:it}}),Q("expanded neighborhood"),z==="replace"&&w&&w(je,{kind:"expanded neighborhood",result:{ok:!0,count:je.length,items:je,active_memory_text:cn,raw:{expanded_for_path:!0,expanded_nodes:ct.size,discovered_nodes:Lt.size,merged:je.length,directed:it}}})}catch(je){const Fe=je instanceof Error?je.message:String(je);k(Fe||"Expand neighborhood failed")}finally{F(!1)}},[O,cn,Vn,ft,w,v,Hn,mn,z,ve,qn]),Qi=_.useCallback(()=>{D(null),Q(null),le(""),ee(!1),k(""),F(!1),br(""),Qn(""),Hr(""),Rs("")},[]),Lr="Search KG",ho=rt.nodes.length,_o=rt.edges.length,go=Qr.length;return r.jsxs("div",{className:"amx-root",children:[r.jsxs("div",{className:"amx-left",children:[r.jsx("div",{className:"amx-graphbar",role:"toolbar","aria-label":"Graph layout controls",children:r.jsxs("div",{className:"amx-graphbar-row",children:[r.jsx("span",{className:"amx-graphbar-title",children:"layout"}),r.jsxs("select",{value:Ke,onChange:B=>Ct(dg(B.target.value,Ke)),disabled:!Qt.length,children:[r.jsx("option",{value:"grid",children:"grid (deterministic)"}),r.jsx("option",{value:"radial",children:"radial (bfs)"}),r.jsx("option",{value:"circle",children:"circle"}),r.jsx("option",{value:"force",children:"force (simulation)"})]}),Ke==="force"?r.jsxs("label",{className:"amx-graphbar-spread",children:[r.jsx("span",{className:"amx-graphbar-title",children:"spread"}),r.jsx("input",{type:"range",min:"0.7",max:"2.2",step:"0.1",value:$e,onChange:B=>Re(Dx(Number(B.target.value),.7,2.2,1))}),r.jsxs("span",{className:"amx-small",children:[$e.toFixed(1),"×"]})]}):null,r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>Vr({kind:Ke,seed:pt}),disabled:!Qt.length,children:"Apply"}),r.jsx("button",{type:"button",className:"amx-btn",onClick:bi,disabled:!Qt.length||Ke!=="force",children:yt?"Pause simulation":"Play simulation"})]})}),r.jsxs("div",{className:"amx-graph","aria-label":"Knowledge graph",ref:Xt,children:[r.jsx(Ug,{children:r.jsxs(Mx,{nodes:sl,edges:wi,defaultViewport:{x:0,y:0,zoom:1},minZoom:cg,maxZoom:ug,onInit:B=>{S.current=B;const re=he.current;if(re&&typeof B.setViewport=="function")try{B.setViewport(re,{duration:0})}catch{try{B.setViewport(re)}catch{}}if(Pe.current&&typeof B.fitView=="function")try{B.fitView({padding:.2,duration:0})}catch{try{B.fitView({padding:.2})}catch{}}he.current=null,Pe.current=!1,fr("init")},nodesDraggable:!0,nodesConnectable:!1,elementsSelectable:!0,onNodesChange:Gr,onNodeClick:(B,re)=>{Rs(""),Hr(re.id)},onEdgeClick:(B,re)=>{Hr(""),Rs(re.id)},onPaneClick:()=>{Hr(""),Rs("")},children:[r.jsx(HE,{className:"amx-flow-controls",children:r.jsx(su,{type:"button",className:`amx-control-legend ${be?"amx-control-legend-active":""}`,onClick:()=>Ee(B=>!B),title:be?"Hide node color legend":"Show node color legend","aria-label":be?"Hide node color legend":"Show node color legend",children:r.jsx(aA,{})})}),r.jsx(Gd,{position:"bottom-right",className:"amx-panel-bottom-right",children:r.jsx("div",{className:"amx-panel-toggles",children:r.jsx("button",{type:"button",className:"amx-minimap-toggle",onClick:()=>xe(B=>!B),title:de?"Hide minimap preview":"Show minimap preview","aria-label":de?"Hide minimap preview":"Show minimap preview",children:de?"minimap on":"minimap off"})})}),de?r.jsx(IE,{position:"bottom-right",pannable:!0,zoomable:!0,maskColor:"rgba(0,0,0,0.45)",style:{background:"rgba(12, 18, 34, 0.88)",border:"1px solid rgba(255,255,255,0.12)",borderRadius:10,width:ie?120:160,height:ie?80:110,marginBottom:56},nodeColor:B=>{var re;return Md((re=B.data)==null?void 0:re.kind).minimap}}):null,be?r.jsxs(Gd,{position:"bottom-left",className:"amx-legend-panel",children:[r.jsx("div",{className:"amx-legend-title",children:"node colors"}),r.jsx("div",{className:"amx-legend",children:[{k:"person",label:"person"},{k:"org",label:"org"},{k:"concept",label:"concept"},{k:"claim",label:"claim"},{k:"event",label:"event"},{k:"doc",label:"doc"},{k:"vocab",label:"vocab"}].map(({k:B,label:re})=>r.jsx("span",{className:"amx-legend-item",style:{borderColor:Md(B).stroke},children:re},B))})]}):null,r.jsx(XE,{gap:20,size:1,color:"rgba(255,255,255,0.06)"})]})},Ve),r.jsxs("details",{className:"amx-panel amx-controls",children:[r.jsxs("summary",{children:[r.jsx("span",{className:"amx-controls-title",children:Lr}),r.jsxs("span",{className:"amx-small",children:[go," assertions · ",ho," nodes · ",_o," edges"]})]}),r.jsxs("div",{className:"amx-toolbar",style:{marginTop:10},children:[r.jsxs("div",{className:"amx-toolbar-grid",children:[r.jsxs("label",{children:["search / highlight",r.jsx("input",{value:I,onChange:B=>P(B.target.value),placeholder:"filter nodes by id/label"})]}),r.jsxs("label",{children:["group edges",r.jsxs("select",{value:String(K),onChange:B=>L(B.target.value==="true"),children:[r.jsx("option",{value:"true",children:"group (subject→object)"}),r.jsx("option",{value:"false",children:"no grouping"})]})]}),r.jsxs("label",{children:["view",r.jsxs("select",{value:String(E),onChange:B=>X(B.target.value==="true"),children:[r.jsx("option",{value:"true",children:"all assertions"}),r.jsx("option",{value:"false",children:"hide rdf:type / labels"})]})]}),r.jsxs("label",{children:["path mode",r.jsxs("select",{value:String(O),onChange:B=>q(B.target.value==="true"),children:[r.jsx("option",{value:"false",children:"undirected"}),r.jsx("option",{value:"true",children:"directed"})]})]})]}),r.jsxs("details",{className:"amx-details",children:[r.jsx("summary",{children:"layout"}),r.jsxs("div",{className:"amx-toolbar-grid",style:{marginTop:10},children:[r.jsxs("label",{children:["layout",r.jsxs("select",{value:Ke,onChange:B=>Ct(dg(B.target.value,Ke)),children:[r.jsx("option",{value:"grid",children:"grid (deterministic)"}),r.jsx("option",{value:"radial",children:"radial (bfs)"}),r.jsx("option",{value:"circle",children:"circle"}),r.jsx("option",{value:"force",children:"force (simulation)"})]})]}),r.jsxs("label",{children:["seed",r.jsx("input",{type:"number",step:"1",value:pt,onChange:B=>gt(Math.trunc(Number(B.target.value||0)||0))})]})]}),r.jsxs("div",{className:"amx-actions",style:{marginTop:10},children:[r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>Vr({kind:Ke,seed:pt}),disabled:!Qt.length,children:"Apply layout"}),Ke==="force"?r.jsx("button",{type:"button",className:"amx-btn",onClick:bi,disabled:!Qt.length,children:yt?"Pause simulation":"Play simulation"}):null,r.jsx("button",{type:"button",className:"amx-btn",onClick:ji,disabled:!Qt.length,children:"Save layout"}),zn?r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"amx-btn",onClick:fo,children:"Load saved"}),r.jsx("button",{type:"button",className:"amx-btn",onClick:il,children:"Clear saved"})]}):null]}),r.jsxs("div",{className:"amx-small",style:{marginTop:10,opacity:.9},children:["Drag nodes to adjust manually; use ",r.jsx("span",{className:"amx-mono",children:"Save layout"})," for a stable, replayable view.",zn?r.jsxs("span",{children:[" ","(saved",pn?`: ${pn}`:"",")"]}):r.jsx("span",{children:" (no saved layout)"})]})]}),r.jsxs("details",{className:"amx-details",children:[r.jsx("summary",{children:"path"}),r.jsxs("div",{className:"amx-toolbar-grid",style:{marginTop:10},children:[r.jsxs("label",{children:["path start",r.jsxs("select",{value:mn,onChange:B=>br(B.target.value),children:[r.jsx("option",{value:"",children:"(none)"}),Qt.map(B=>r.jsx("option",{value:B,children:(()=>{const re=Js.get(B)||B;return re===B?re:`${re} (${B})`})()},B))]})]}),r.jsxs("label",{children:["path end",r.jsxs("select",{value:Hn,onChange:B=>Qn(B.target.value),children:[r.jsx("option",{value:"",children:"(none)"}),Qt.map(B=>r.jsx("option",{value:B,children:(()=>{const re=Js.get(B)||B;return re===B?re:`${re} (${B})`})()},B))]})]})]}),In?r.jsx("div",{className:"amx-small",style:{marginTop:10},children:Ls.map((B,re)=>{const we=Js.get(B.from)||B.from,Se=Js.get(B.to)||B.to,je=B.dir==="reverse"?" ← ":" → ",Fe=B.predicate?` (${B.predicate})`:"";return r.jsxs("div",{children:[re===0?r.jsx("span",{children:we}):null,je,r.jsxs("span",{children:[Se,Fe]})]},`${B.edgeId}:${re}`)})}):mn&&Hn?r.jsxs("div",{className:"amx-small",style:{marginTop:10,opacity:.9},children:["No path found in the current subgraph (",($n==null?void 0:$n.assertions)??go," assertions · ",($n==null?void 0:$n.nodes)??rt.nodes.length," nodes ·"," ",($n==null?void 0:$n.edges)??rt.edges.length," edges). Start reaches ",($n==null?void 0:$n.reachableFromStart)??0," nodes.",v?r.jsx("div",{style:{marginTop:10},children:r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>void ss(),disabled:ge,children:ge?"Expanding…":"Expand neighborhood"})}):null]}):r.jsx("div",{className:"amx-small",style:{marginTop:10},children:"(no path)"})]}),r.jsxs("details",{className:"amx-details",children:[r.jsx("summary",{children:"query"}),r.jsxs("div",{className:"amx-toolbar-grid",style:{marginTop:10},children:[r.jsxs("label",{children:["query_text (semantic)",r.jsx("input",{value:We,onChange:B=>et(B.target.value),placeholder:"e.g. emotion chip"})]}),r.jsxs("label",{children:["subject (exact)",r.jsx("input",{value:at,onChange:B=>Nt(B.target.value),placeholder:"e.g. ex:person-data"})]}),r.jsxs("label",{children:["predicate (exact)",r.jsx("input",{value:xt,onChange:B=>Wt(B.target.value),placeholder:"e.g. schema:about"})]}),r.jsxs("label",{children:["object (exact)",r.jsx("input",{value:lt,onChange:B=>Vt(B.target.value),placeholder:"e.g. ex:concept-emotion-chip"})]}),r.jsxs("label",{children:["min_score",r.jsx("input",{type:"number",step:"any",value:It,onChange:B=>jt(B.target.value),placeholder:"(auto)"})]}),r.jsxs("label",{children:["limit",r.jsx("input",{type:"number",min:"-1",step:"1",value:ft,onChange:B=>Mt(B.target.value),placeholder:"0/-1 = unlimited (if supported)"})]})]})]}),r.jsxs("details",{className:"amx-details",children:[r.jsx("summary",{children:"advanced"}),r.jsxs("div",{className:"amx-toolbar-grid",style:{marginTop:10},children:[r.jsxs("label",{children:["scope",r.jsxs("select",{value:qn,onChange:B=>oe(By(B.target.value,qn)),children:[r.jsx("option",{value:"run",children:"run"}),r.jsx("option",{value:"session",children:"session"}),r.jsx("option",{value:"global",children:"global"}),r.jsx("option",{value:"all",children:"all"})]})]}),r.jsxs("label",{children:["recall level",r.jsxs("select",{value:ve,onChange:B=>qe(B.target.value||"standard"),children:[r.jsx("option",{value:"urgent",children:"urgent"}),r.jsx("option",{value:"standard",children:"standard"}),r.jsx("option",{value:"deep",children:"deep"})]})]}),r.jsxs("label",{children:["max_input_tokens",r.jsx("input",{type:"number",min:"0",step:"1",value:Ce,onChange:B=>Ut(B.target.value),placeholder:"(auto)"})]}),r.jsxs("label",{children:["model (budgeting)",r.jsx("input",{value:St,onChange:B=>nn(B.target.value),placeholder:"qwen/qwen3-next-80b"})]})]})]}),r.jsxs("div",{className:"amx-actions",children:[r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>void oc(),disabled:!v||Y,children:Y?"Querying…":"Query store"}),r.jsx("button",{type:"button",className:"amx-btn",onClick:Qi,disabled:!H&&!ae&&!Y,children:"Reset to step output"}),H?r.jsxs("span",{className:"amx-small",children:["showing: ",G||"live query"]}):r.jsx("span",{className:"amx-small",children:"showing: step output"}),ae?r.jsx("span",{className:"amx-small",style:{color:"var(--error, rgba(255, 80, 80, 0.95))"},children:ae}):null,C?r.jsx("span",{className:"amx-small",style:{color:"var(--error, rgba(255, 80, 80, 0.95))"},children:C}):null]})]})]})]})]}),r.jsxs("div",{className:"amx-right",children:[r.jsxs("div",{className:"amx-panel",children:[r.jsx("h3",{children:"Details"}),r.jsx("div",{className:"amx-small",style:{marginBottom:8},children:"Derived from `memory_kg_query` packetization (max_input_tokens); safe to inject into an LLM system prompt."}),(()=>{const B=fA(Ki);return B?r.jsx("div",{className:"amx-small",style:{marginBottom:8,opacity:.9},children:B}):null})(),(()=>{const B=vi;if(!B)return null;const re=typeof B=="string"?B:Array.isArray(B)?B.map(we=>String(we)).join(" · "):JSON.stringify(B);return!re||!re.trim()?null:r.jsx("div",{className:"amx-small",style:{marginBottom:8,color:"var(--warning, rgba(255, 180, 90, 0.95))"},children:re})})(),r.jsx("div",{className:"amx-small",style:{marginBottom:8,opacity:.9},children:(()=>{const B=(H==null?void 0:H.packets_version)??Ur,re=(H==null?void 0:H.packed_count)??jr,we=(H==null?void 0:H.dropped)??Zr,Se=(H==null?void 0:H.estimated_tokens)??Wr,je=[];return typeof B=="number"&&je.push(`packets_v${B}`),typeof re=="number"&&je.push(`packed=${re}`),typeof we=="number"&&je.push(`dropped=${we}`),typeof Se=="number"&&je.push(`est_tokens=${Se}`),je.length?je.join(" · "):"No packetization stats (set max_input_tokens > 0)."})()}),r.jsx("div",{className:"amx-active-memory",children:hA(cn||"(empty)",I)}),(()=>{const B=H!=null&&H.packets&&Array.isArray(H.packets)?H.packets:tr;return!Array.isArray(B)||B.length===0?null:r.jsxs("div",{style:{marginTop:10},children:[r.jsxs("button",{type:"button",className:"amx-btn",onClick:()=>en(re=>!re),children:[Zi?"Hide":"Show"," packets (",B.length,")"]}),Zi?r.jsx("div",{className:"amx-list",style:{marginTop:10},children:B.slice(0,120).map((re,we)=>{const Se=re&&typeof re=="object"&&!Array.isArray(re)?re:null,je=Se&&typeof Se.statement=="string"?Se.statement:typeof re=="string"?re:"",Fe=Se&&(typeof Se.retrieval_score=="number"||typeof Se.retrieval_score=="string")?Se.retrieval_score:null,mt=Se&&typeof Se.observed_at=="string"?Se.observed_at:null;return r.jsxs("div",{className:"amx-item",children:[r.jsx("div",{className:"amx-mono",children:je||"(packet)"}),mt||Fe!==null?r.jsxs("div",{className:"amx-small",children:[mt?`[${mt}]`:null,mt&&Fe!==null?" ":null,Fe!==null?`score:${Fe}`:null]}):null]},we)})}):null]})})(),r.jsx("div",{style:{marginTop:14,marginBottom:12,borderTop:"1px solid var(--ui-border-1, rgba(255,255,255,0.08))"}}),r.jsx("div",{className:"amx-small",style:{marginBottom:8,fontWeight:700,opacity:.9},children:"Inspect"}),r.jsx("div",{className:"amx-small",style:{marginBottom:8},children:"Click a node or edge to inspect its assertions."}),Kn?r.jsxs("div",{className:"amx-item",style:{marginBottom:10,display:"flex",justifyContent:"space-between",gap:10,alignItems:"center"},children:[r.jsxs("div",{style:{minWidth:0},children:[r.jsx("div",{className:"amx-mono",style:{fontSize:11,opacity:.95},children:Js.get(Kn)||Kn}),r.jsxs("div",{className:"amx-small",children:["kind=",nr.get(Kn)||"entity"," · id=",Kn]})]}),r.jsxs("div",{className:"amx-actions",children:[r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>void kr(Kn),children:"Copy id"}),r.jsx("button",{type:"button",className:"amx-btn",onClick:xs,children:"Focus"})]})]}):Sr&&Sr.source&&Sr.target?r.jsxs("div",{className:"amx-item",style:{marginBottom:10,display:"flex",justifyContent:"space-between",gap:10,alignItems:"center"},children:[r.jsxs("div",{style:{minWidth:0},children:[r.jsxs("div",{className:"amx-mono",style:{fontSize:11,opacity:.95},children:[Sr.source," —",String(Sr.label||((eo=Sr.data)==null?void 0:eo.predicateSummary)||"").trim()||"?","→ ",Sr.target]}),r.jsxs("div",{className:"amx-small",children:["edge_id=",Sr.id]})]}),r.jsxs("div",{className:"amx-actions",children:[r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>void kr(Sr.id),children:"Copy id"}),r.jsx("button",{type:"button",className:"amx-btn",onClick:xs,children:"Fit"})]})]}):r.jsx("div",{className:"amx-small",style:{marginBottom:10,opacity:.9},children:"(no selection)"}),r.jsx("div",{className:"amx-list",children:ws.slice(0,80).map((B,re)=>{const we=String(B.subject||"").trim(),Se=String(B.predicate||"").trim(),je=String(B.object||"").trim(),Fe=Js.get(we)||we,mt=Js.get(je)||je,it=nr.get(we)||"entity",ct=nr.get(je)||"entity",Bt=Md(it),Lt=Md(ct),sr=Td(B.observed_at),Dt=mA(B),Kt=B.provenance&&typeof B.provenance=="object"&&!Array.isArray(B.provenance)?B.provenance:null,hn=Kt&&typeof Kt.span_id=="string"?Kt.span_id.trim():"",_n=Kt&&typeof Kt.writer_run_id=="string"?Kt.writer_run_id.trim():"",mr=typeof B.owner_id=="string"?B.owner_id.trim():"",Nr=_n||mr,Qs=!!((N||x)&&hn&&Nr),na=!!(N&&_n&&!hn),ra=Qs||na;return r.jsxs("div",{className:"amx-item amx-triple-card",children:[r.jsxs("div",{className:"amx-triple-row",children:[r.jsx("button",{type:"button",className:"amx-term",style:{borderColor:Bt.stroke,background:Bt.bg},title:we,onClick:()=>{we&&(Rs(""),Hr(we))},children:Fe||we||"(subject)"}),r.jsx("span",{className:"amx-arrow",children:"—"}),r.jsx("span",{className:"amx-predicate",title:Se,children:Fx(Se)||"(predicate)"}),r.jsx("span",{className:"amx-arrow",children:"→"}),r.jsx("button",{type:"button",className:"amx-term",style:{borderColor:Lt.stroke,background:Lt.bg},title:je,onClick:()=>{je&&(Rs(""),Hr(je))},children:mt||je||"(object)"})]}),r.jsxs("div",{className:"amx-triple-meta",children:[sr?r.jsxs("span",{className:"amx-small",title:String(B.observed_at||""),children:["[",sr,"]"]}):null,Dt?r.jsx("span",{className:"amx-small",children:Dt}):null]}),hn||_n?r.jsxs("div",{className:"amx-triple-actions",children:[hn?r.jsxs("span",{className:"amx-small",children:["span:",hn]}):null,_n?r.jsxs("span",{className:"amx-small",children:["run:",_n]}):null,ra?r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>{if(Qs&&hn&&Nr){qr({run_id:Nr,span_id:hn,assertion:B});return}na&&_n&&qr({run_id:_n,assertion:B})},children:"Open transcript"}):null]}):null]},re)})})]}),r.jsxs("div",{className:"amx-panel",children:[r.jsx("h3",{children:"Transcript"}),r.jsx("div",{className:"amx-small",style:{marginBottom:8},children:"Pivot from a triple to its provenance transcript (span/note artifact, or run input fallback)."}),Zs.length?r.jsxs("div",{style:{marginBottom:12},children:[r.jsx("div",{className:"amx-small",style:{marginBottom:6,opacity:.85},children:"spans"}),r.jsx("div",{className:"amx-list",style:{maxHeight:320},children:Zs.slice(0,60).map(B=>r.jsxs("div",{className:"amx-item",style:{display:"flex",justifyContent:"space-between",gap:10,alignItems:"center"},children:[r.jsxs("div",{style:{minWidth:0},children:[r.jsxs("div",{className:"amx-mono",style:{fontSize:11,opacity:.95},children:["span:",B.span_id]}),r.jsxs("div",{className:"amx-small",children:["run_id=",B.span_run_id," · assertions=",B.count,B.last_observed_at_fmt?` · last=[${B.last_observed_at_fmt}]`:""]})]}),x||N?r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>qr({run_id:B.span_run_id,span_id:B.span_id,assertion:B.assertion}),children:"Open transcript"}):null]},`${B.span_run_id}|${B.span_id}`))})]}):null,N&&xi.length?r.jsxs("div",{style:{marginBottom:12},children:[r.jsx("div",{className:"amx-small",style:{marginBottom:6,opacity:.85},children:"runs (fallback)"}),r.jsx("div",{className:"amx-list",style:{maxHeight:240},children:xi.slice(0,40).map(B=>r.jsxs("div",{className:"amx-item",style:{display:"flex",justifyContent:"space-between",gap:10,alignItems:"center"},children:[r.jsxs("div",{style:{minWidth:0},children:[r.jsxs("div",{className:"amx-mono",style:{fontSize:11,opacity:.95},children:["run:",B.run_id]}),r.jsxs("div",{className:"amx-small",children:["assertions=",B.count,B.last_observed_at_fmt?` · last=[${B.last_observed_at_fmt}]`:""]})]}),r.jsx("button",{type:"button",className:"amx-btn",onClick:()=>qr({run_id:B.run_id,assertion:B.assertion}),children:"Open transcript"})]},B.run_id))})]}):null,!Zs.length&&!(N&&xi.length)?r.jsx("div",{className:"amx-small",children:"(no provenance)"}):null]})]})]})}function Ja({open:e,title:t,children:n,actions:i,variant:a="default",onClose:l}){if(_.useEffect(()=>{if(!e)return;const d=m=>{m.key==="Escape"&&l()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[e,l]),!e)return null;const u=a==="fullscreen";return r.jsx("div",{className:`modal_backdrop${u?" fullscreen":""}`,onMouseDown:d=>{d.target===d.currentTarget&&l()},children:r.jsxs("div",{className:`modal_panel${u?" fullscreen":""}`,children:[r.jsxs("div",{className:"modal_header",children:[r.jsx("div",{className:"modal_title",children:t}),r.jsx("button",{className:"btn",onClick:l,children:"Close"})]}),r.jsx("div",{className:"modal_body",children:n}),i?r.jsx("div",{className:"modal_footer",children:i}):null]})})}function b_(e,t="session"){const n=String(e||"").trim().toLowerCase();return n==="run"||n==="session"||n==="global"||n==="all"?n:t}function Ga(e){const t=typeof e=="string"?e.trim():"";if(!t)return null;const n=t.replace(/(\.\d{3})\d+/,"$1"),i=Date.parse(n);return Number.isFinite(i)?i:null}function Vl(e){if(typeof e!="number"||!Number.isFinite(e))return"—";const t=new Date(e),n=t.getUTCFullYear(),i=String(t.getUTCMonth()+1).padStart(2,"0"),a=String(t.getUTCDate()).padStart(2,"0"),l=String(t.getUTCHours()).padStart(2,"0"),u=String(t.getUTCMinutes()).padStart(2,"0");return`${n}/${i}/${a} ${l}:${u}`}function yA(e){const t=String(e??"").trim();if(!t)return"";if(/^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}$/.test(t))return t;const n=Ga(t);return n!==null?Vl(n):t}function Hg(e){const t=typeof e=="string"?e:String(e??"");return t?!t.includes("\\n")&&!t.includes("\\r")&&!t.includes("\\t")?t:t.replace(/\\r\\n/g,`
|
|
124
|
+
`).replace(/\\n/g,`
|
|
125
|
+
`).replace(/\\t/g," "):""}function Bx(e){return String(e??"").replace(/[*_`~]/g,"")}function km(e,t){const n=!!(t!=null&&t.strip_punct),i=Hg(e);let a=Bx(i).replace(/\s+/g," ").trim().toLowerCase();return n&&(a=a.replace(/[^\p{L}\p{N}\s]+/gu,"").replace(/\s+/g," ").trim()),a}function Nm(e,t){const n=String(t??"").trim();if(!n)return!1;const i=km(n,{strip_punct:!1});if(!i)return!1;if(km(String(e??""),{strip_punct:!1}).includes(i))return!0;const l=km(n,{strip_punct:!0});return l?km(String(e??""),{strip_punct:!0}).includes(l):!1}function Wy(e){const t=Hg(e).trim();if(!t)return[];const n=[],i=u=>{const d=String(u??"").replace(/\s+/g," ").trim();d&&(d.length<6||n.includes(d)||n.push(d))},a=t.search(/[`*_~]/);if(a>0){const u=t.slice(0,a);u.replace(/\s+/g," ").trim().length>=10&&i(u)}const l=[/`([^`]+)`/g,/\*\*([^*]+)\*\*/g,/__([^_]+)__/g,/\*([^*]+)\*/g,/_([^_]+)_/g];for(const u of l){let d;for(;(d=u.exec(t))!==null;){const m=String(d[1]??"").trim();m&&i(m)}}return i(Bx(t)),n}function vA(e){const t=String(e??"").replace(/\r\n/g,`
|
|
126
|
+
`).replace(/\r/g,`
|
|
127
|
+
`);if(!t)return null;const n=t.split(`
|
|
128
|
+
`);let i;const a=[],l=[];let u=null,d=[],m=!1;const p=()=>{if(!u)return;const w=d.join(`
|
|
129
|
+
`).trim();w&&l.push({role:u,lines:[w]}),u=null,d=[]};for(const w of n){const x=i?null:w.match(/^\s*created_at\s*=\s*(.+)\s*$/i);if(x&&x[1]){i=x[1].trim();continue}const N=w.match(/^\s*(USER|ASSISTANT|SYSTEM)\s*:\s*(.*)$/i);if(N){m=!0,p();const S=String(N[1]||"").trim().toLowerCase();u=S==="user"?"user":S==="assistant"?"assistant":"system";const R=String(N[2]??"");d=R?[R]:[];continue}u?d.push(w):a.push(w)}if(p(),!m||!l.length)return null;const g=a.join(`
|
|
130
|
+
`).trim(),v={messages:[]};i&&(v.created_at=i),g&&v.messages.push({role:"system",content:g});for(const w of l)v.messages.push({role:w.role,content:w.lines.join(`
|
|
131
|
+
`)});return v.messages.length?v:null}function Hy(e,t){const n=String(e||""),i=String(t||"");return i>n?i:n}function qy(e){const t=String((e==null?void 0:e.subject)||"").trim(),n=String((e==null?void 0:e.predicate)||"").trim(),i=String((e==null?void 0:e.object)||"").trim(),a=String((e==null?void 0:e.observed_at)||"").trim(),l=String((e==null?void 0:e.scope)||"").trim(),u=String((e==null?void 0:e.owner_id)||"").trim();return`${t}|${n}|${i}|${a}|${l}|${u}`}function wA(e){const t=String((e==null?void 0:e.observed_at)||"").trim(),n=String((e==null?void 0:e.subject)||"").trim(),i=String((e==null?void 0:e.predicate)||"").trim(),a=String((e==null?void 0:e.object)||"").trim(),l=String((e==null?void 0:e.scope)||"").trim(),u=String((e==null?void 0:e.owner_id)||"").trim(),d=[];l&&d.push(`scope=${l}`),u&&d.push(`owner=${u}`);const m=d.length?` (${d.join(", ")})`:"";return`${t?`[${t}] `:""}${n} --${i}--> ${a}${m}`}function xA({gateway:e,selected_run_id:t,selected_session_id:n}){const[i,a]=_.useState(String(t||"").trim()),[l,u]=_.useState(String(n||"").trim()),[d,m]=_.useState("all"),p=d==="all",[g,v]=_.useState(!0),[w,x]=_.useState(750),[N,S]=_.useState(5e3),[R,T]=_.useState([]),[z,H]=_.useState(void 0),[D,G]=_.useState(""),[Q,Y]=_.useState(!1),[ee,ae]=_.useState([]),[le,ge]=_.useState(!1),[F,C]=_.useState(!1),[k,I]=_.useState(""),[P,K]=_.useState(""),[L,O]=_.useState(""),[q,E]=_.useState(""),[X,ne]=_.useState("artifact"),[ie,de]=_.useState(null),[xe,be]=_.useState(""),[Ee,Oe]=_.useState(null),He=_.useRef(!1),Ke=_.useMemo(()=>{const oe=Ee,ve=oe!=null&&oe.attributes&&typeof oe.attributes=="object"&&!Array.isArray(oe.attributes)?oe.attributes:null;return(ve&&typeof ve.evidence_quote=="string"?String(ve.evidence_quote):"").trim()},[Ee]),Ct=_.useMemo(()=>{const oe=ie,ve=oe&&typeof oe=="object"&&!Array.isArray(oe)?oe:null,qe=ve&&typeof ve.note=="string"?String(ve.note):"";return Hg(qe).trim()},[ie]),pt=_.useMemo(()=>{const oe=ie&&typeof ie=="object"&&!Array.isArray(ie)?ie:null,ve=oe&&Array.isArray(oe.messages)?oe.messages:null;return Array.isArray(ve)?ve:null},[ie]),gt=_.useMemo(()=>{const oe=Ct,ve=Ke;return!oe||!ve?!1:Nm(oe,ve)},[Ke,Ct]),yt=_.useMemo(()=>{const oe=pt,ve=Ke;if(!oe||!ve)return[];const qe=[];for(let We=0;We<Math.min(oe.length,500);We++){const et=oe[We],at=(et==null?void 0:et.content)==null?"":String(et.content);Nm(at,ve)&&qe.push(We)}return qe},[Ke,pt]),nt=_.useMemo(()=>new Set(yt),[yt]),$e=yt.length?yt[0]:null,Re=_.useCallback(oe=>{const ve=document.getElementById(`source_msg_${oe}`);ve&&typeof ve.scrollIntoView=="function"&&ve.scrollIntoView({block:"center",behavior:"smooth"})},[]),ot=_.useCallback(()=>{const oe=document.getElementById("source_note_hit_0")||document.getElementById("source_note_msg_hit_0");oe&&typeof oe.scrollIntoView=="function"&&oe.scrollIntoView({block:"center",behavior:"smooth"})},[]);_.useEffect(()=>{if(le&&!(F||k)&&!He.current){if($e!==null){He.current=!0,window.setTimeout(()=>Re($e),0);return}if(gt){He.current=!0,window.setTimeout(()=>ot(),0);return}}},[Re,ot,k,$e,F,gt,le]);const he=_.useRef(new Set),Pe=_.useRef(""),Ve=_.useRef(null),Rt=_.useRef(null);_.useEffect(()=>{a(String(t||"").trim())},[t]),_.useEffect(()=>{u(String(n||"").trim())},[n]);const Xt=_.useMemo(()=>{const oe=String(i||"").trim(),ve=String(l||"").trim();return`mindmap:${d}:${oe}:${ve}`},[i,l,d]),fn=_.useMemo(()=>{let oe=null,ve=null;for(const qe of R){const We=Ga(qe==null?void 0:qe.observed_at);We!==null&&(oe=oe===null?We:Math.min(oe,We),ve=ve===null?We:Math.max(ve,We))}return{min_ms:oe,max_ms:ve}},[R]),Ft=1e3,At=_.useMemo(()=>{const oe=fn.min_ms,ve=fn.max_ms;if(typeof oe!="number"||typeof ve!="number"||!Number.isFinite(oe)||!Number.isFinite(ve))return null;if(ve<=oe)return{min_ms:oe,max_ms:oe,real_max_ms:ve};const qe=oe+Math.ceil((ve-oe)/Ft)*Ft;return{min_ms:oe,max_ms:qe,real_max_ms:ve}},[fn.max_ms,fn.min_ms]),[sn,zn]=_.useState(!0),[$t,pn]=_.useState(null);_.useEffect(()=>{sn&&At&&pn(At.max_ms)},[sn,At]);const Pn=_.useMemo(()=>{const oe=typeof $t=="number"?$t:null;return oe===null?R:R.filter(ve=>{const qe=Ga(ve==null?void 0:ve.observed_at);return qe===null?!0:qe<=oe})},[R,$t]),Cn=_.useCallback((oe,ve)=>{const qe=Array.isArray(oe)?oe:[],We=String(Pe.current||"").trim(),et=new Set,at=[];let Nt="";for(const xt of qe){if(!xt||typeof xt!="object"||typeof xt.subject!="string"||typeof xt.predicate!="string"||typeof xt.object!="string")continue;const Wt=qy(xt);if(et.has(Wt))continue;et.add(Wt),at.push(xt);const lt=String(xt.observed_at||"").trim();lt&&(Nt=Hy(Nt,lt))}T(at),H(ve==null?void 0:ve.warnings),he.current=et,Pe.current=Nt||We},[]),yn=_.useCallback(async oe=>{const ve=b_(oe.scope,"session"),qe=String(oe.subject||"").trim(),We=String(oe.predicate||"").trim(),et=String(oe.object||"").trim(),at=String(oe.since||"").trim(),Nt=String(oe.until||"").trim(),xt=String(oe.active_at||"").trim(),Wt=String(oe.query_text||"").trim(),lt=typeof oe.min_score=="number"&&Number.isFinite(oe.min_score)?Number(oe.min_score):void 0,Vt=oe.order==="asc"?"asc":"desc",It=typeof oe.limit=="number"&&Number.isFinite(oe.limit)?Number(oe.limit):0,jt=String(i||"").trim(),ft=String(l||"").trim(),Mt={scope:ve,all_owners:p,limit:It,order:Vt};qe&&(Mt.subject=qe),We&&(Mt.predicate=We),et&&(Mt.object=et),at&&(Mt.since=at),Nt&&(Mt.until=Nt),xt&&(Mt.active_at=xt),Wt&&(Mt.query_text=Wt),typeof lt=="number"&&(Mt.min_score=lt),p||(ve==="run"?jt&&(Mt.run_id=jt):ve==="session"?ft?Mt.session_id=ft:jt&&(Mt.run_id=jt):ve==="all"&&(jt?Mt.run_id=jt:ft&&(Mt.session_id=ft)));try{const Ce=await e.kg_query(Mt),Ut=Array.isArray(Ce==null?void 0:Ce.items)?Ce.items:[],St=Ce==null?void 0:Ce.warnings;return{ok:(Ce==null?void 0:Ce.ok)!==!1,count:Number((Ce==null?void 0:Ce.count)||Ut.length),items:Ut,warnings:St,raw:Ce}}catch(Ce){const Ut=Ce instanceof Error?Ce.message:String(Ce);if(Ut.includes("Run '")&&Ut.includes("not found")&&!ft&&(ve==="session"||ve==="all")&&jt){const nn=await e.kg_query({...Mt,run_id:void 0,session_id:jt}),kt=Array.isArray(nn==null?void 0:nn.items)?nn.items:[],er=nn==null?void 0:nn.warnings;return{ok:(nn==null?void 0:nn.ok)!==!1,count:Number((nn==null?void 0:nn.count)||kt.length),items:kt,warnings:er,raw:nn}}throw new Error(Ut||"KG query failed")}},[p,e,i,l]),Mn=_.useCallback(async oe=>{var We;const ve=String(oe.run_id||"").trim(),qe=String(oe.span_id||"").trim();if(!(!ve||!qe)){ge(!0),C(!0),I(""),O(ve),E(qe),ne("artifact"),K(`source span:${qe}`),de(null),be(""),Oe(oe.assertion&&typeof oe.assertion=="object"?oe.assertion:null),He.current=!1;try{const et=[ve],at=typeof((We=oe.assertion)==null?void 0:We.owner_id)=="string"?String(oe.assertion.owner_id).trim():"";at&&at!==ve&&et.push(at);let Nt=null,xt=null;for(const Wt of et)try{xt=await(await e.download_run_artifact_content(Wt,qe)).text(),Wt!==ve&&O(Wt);break}catch(lt){Nt=lt instanceof Error?lt.message:String(lt)}if(xt==null)throw new Error(Nt||"Failed to load source span");be(xt);try{const Wt=JSON.parse(xt);de(Wt)}catch{de(null)}}catch(et){const at=et instanceof Error?et.message:String(et);I(at||"Failed to load source span")}finally{C(!1)}}},[e]),mn=_.useCallback(async oe=>{const ve=String(oe.run_id||"").trim();if(!ve)return null;try{const qe=await e.list_run_artifacts(ve,{limit:200}),et=(Array.isArray(qe==null?void 0:qe.items)?qe.items:[]).map(lt=>{const Vt=typeof(lt==null?void 0:lt.artifact_id)=="string"?String(lt.artifact_id).trim():"",It=lt!=null&<.tags&&typeof lt.tags=="object"&&!Array.isArray(lt.tags)?lt.tags:null,jt=It&&typeof It.kind=="string"?String(It.kind).trim():"";return{artifact_id:Vt,kind:jt}}).filter(lt=>!!(lt.artifact_id&&(lt.kind==="conversation_span"||lt.kind==="memory_note")));if(!et.length)return null;if(et.length===1)return et[0].artifact_id;const at=oe.assertion,Nt=at!=null&&at.attributes&&typeof at.attributes=="object"&&!Array.isArray(at.attributes)?at.attributes:null,Wt=(Nt&&typeof Nt.evidence_quote=="string"?String(Nt.evidence_quote):"").trim();if(!Wt)return null;for(const lt of et.slice(0,10))try{const It=await(await e.download_run_artifact_content(ve,lt.artifact_id)).text(),jt=JSON.parse(It);if(jt&&typeof jt=="object"){const ft=typeof jt.note=="string"?String(jt.note):"";if(ft&&ft.includes(Wt))return lt.artifact_id;const Mt=Array.isArray(jt.messages)?jt.messages:null;if(Mt){for(const Ce of Mt.slice(0,200))if(((Ce==null?void 0:Ce.content)==null?"":String(Ce.content)).includes(Wt))return lt.artifact_id}}}catch{}}catch{}return null},[e]),br=_.useCallback(async oe=>{const ve=String(oe.run_id||"").trim();if(ve){ge(!0),C(!0),I(""),O(ve),E(""),ne("run_input"),K(`transcript run:${ve}`),de(null),be(""),Oe(oe.assertion&&typeof oe.assertion=="object"?oe.assertion:null),He.current=!1;try{const qe=await mn({run_id:ve,assertion:oe.assertion});if(qe){await Mn({run_id:ve,span_id:qe,assertion:oe.assertion});return}const We=await e.get_run_input_data(ve),et=We&&typeof We=="object"&&!Array.isArray(We)?We.input_data:null,at={kind:"run_input_data",run_id:ve};if(We&&typeof(We==null?void 0:We.workflow_id)=="string"&&(at.workflow_id=String(We.workflow_id)),et&&typeof et=="object"&&!Array.isArray(et)){const Nt=et.context,Wt=(Nt&&typeof Nt=="object"&&Array.isArray(Nt.messages)?Nt.messages:null)||(Array.isArray(et.messages)?et.messages:null);Array.isArray(Wt)&&(at.messages=Wt);const lt=["text","prompt","task","message"];for(const Vt of lt){const It=et[Vt];if(typeof It=="string"&&It.trim()){at.note=It.trim();break}}at.input_data=et}!at.messages&&!at.note&&(at.note=JSON.stringify(et??We??{},null,2));try{const Nt=await e.get_run(ve),xt=Nt&&typeof(Nt==null?void 0:Nt.created_at)=="string"?String(Nt.created_at):"";xt&&(at.created_at=xt)}catch{}de(at),be(JSON.stringify(We,null,2))}catch(qe){const We=qe instanceof Error?qe.message:String(qe);I(We||"Failed to load run input transcript")}finally{C(!1)}}},[e,Mn,mn]),Hn=_.useCallback(async()=>{G(""),Y(!0);try{const oe=d==="all"?"all":d,ve=await yn({scope:oe,limit:0,order:"desc"});Cn(ve.items||[],{warnings:ve.warnings}),Ve.current={scope:oe}}catch(oe){const ve=oe instanceof Error?oe.message:String(oe);G(ve||"Load failed")}finally{Y(!1)}},[yn,Cn,d]);_.useEffect(()=>{R.length||Hn()},[]);const Qn=_.useCallback(async oe=>{const ve=b_(oe.scope,"session");return Rt.current=oe,await yn({scope:ve,subject:oe.subject,predicate:oe.predicate,object:oe.object,query_text:oe.query_text,min_score:oe.min_score,since:oe.since,until:oe.until,active_at:oe.active_at,limit:typeof oe.limit=="number"?oe.limit:0,order:"desc"})},[yn]),ys=_.useCallback((oe,ve)=>{var qe;if((ve==null?void 0:ve.kind)==="live query"){const We=Rt.current;We&&(Ve.current={scope:b_(We.scope,"session"),subject:typeof We.subject=="string"?We.subject:void 0,predicate:typeof We.predicate=="string"?We.predicate:void 0,object:typeof We.object=="string"?We.object:void 0})}Cn(oe,{warnings:(qe=ve==null?void 0:ve.result)==null?void 0:qe.warnings})},[Cn]),qn=_.useCallback(async()=>{const oe=Ve.current;if(!oe)return;const ve=String(Pe.current||"").trim(),qe=await yn({scope:oe.scope,subject:oe.subject,predicate:oe.predicate,object:oe.object,since:ve||void 0,order:"asc",limit:0}),We=Array.isArray(qe.items)?qe.items:[];if(!We.length)return;const at=Date.now()+Math.max(250,Math.min(2e4,N)),Nt=he.current,xt=[],Wt=[];let lt=String(Pe.current||"").trim();for(const Vt of We){if(!Vt||typeof Vt!="object"||typeof Vt.subject!="string"||typeof Vt.predicate!="string"||typeof Vt.object!="string")continue;const It=qy(Vt);if(Nt.has(It))continue;Nt.add(It),xt.push(Vt),Wt.push({id:It,assertion:Vt,expires_at_ms:at});const jt=String(Vt.observed_at||"").trim();jt&&(lt=Hy(lt,jt))}xt.length&&(Pe.current=lt,T(Vt=>{const It=Vt.concat(xt);return It.sort((jt,ft)=>String((ft==null?void 0:ft.observed_at)||"").localeCompare(String((jt==null?void 0:jt.observed_at)||""))),It}),ae(Vt=>{const It=Vt.concat(Wt);return It.sort((jt,ft)=>ft.expires_at_ms-jt.expires_at_ms),It.slice(0,30)}))},[N,yn]);return _.useEffect(()=>{if(!g)return;let oe=!1,ve=null;const qe=async()=>{if(!oe){try{await qn()}catch{}oe||(ve=window.setTimeout(()=>void qe(),Math.max(250,Math.min(6e4,w))))}};return qe(),()=>{oe=!0,ve!==null&&window.clearTimeout(ve)}},[g,w,qn]),_.useEffect(()=>{if(!ee.length)return;const oe=window.setInterval(()=>{const ve=Date.now();ae(qe=>qe.filter(We=>We.expires_at_ms>ve))},250);return()=>window.clearInterval(oe)},[ee.length]),r.jsxs("div",{className:"mindmap_root",children:[r.jsxs("div",{className:"mindmap_bar",children:[r.jsx("button",{className:"btn",onClick:()=>void Hn(),disabled:Q,children:Q?"Loading…":"Load snapshot"}),r.jsxs("label",{className:"field_inline",children:[r.jsx("span",{className:"mono muted",children:"source"}),r.jsxs("select",{value:d,onChange:oe=>{const ve=String(oe.target.value||"").trim();(ve==="all"||ve==="global"||ve==="session"||ve==="run")&&m(ve)},children:[r.jsx("option",{value:"all",children:"all memory"}),r.jsx("option",{value:"global",children:"global"}),r.jsx("option",{value:"session",children:"session"}),r.jsx("option",{value:"run",children:"run"})]})]}),r.jsxs("label",{className:"field_inline",children:[r.jsx("span",{className:"mono muted",children:"live"}),r.jsx("input",{type:"checkbox",checked:g,onChange:oe=>v(!!oe.target.checked)})]}),d==="session"?r.jsxs("label",{className:"field_inline",children:[r.jsx("span",{className:"mono muted",children:"session_id"}),r.jsx("input",{className:"mono",value:l,onChange:oe=>u(String(oe.target.value||"")),placeholder:"(required)"})]}):null,d==="run"?r.jsxs("label",{className:"field_inline",children:[r.jsx("span",{className:"mono muted",children:"run_id"}),r.jsx("input",{className:"mono",value:i,onChange:oe=>a(String(oe.target.value||"")),placeholder:"(required)"})]}):null,r.jsxs("details",{className:"mindmap_details",children:[r.jsx("summary",{className:"mono muted",children:"advanced"}),r.jsx("div",{className:"mindmap_advanced",children:r.jsxs("div",{className:"field_inline",children:[r.jsx("span",{className:"mono muted",style:{width:84},children:"poll_ms"}),r.jsx("input",{type:"number",min:250,max:6e4,step:50,value:w,onChange:oe=>x(Math.max(250,Number(oe.target.value||0)||750))}),r.jsx("span",{className:"mono muted",children:"highlight_ms"}),r.jsx("input",{type:"number",min:250,max:2e4,step:250,value:N,onChange:oe=>S(Math.max(250,Number(oe.target.value||0)||5e3))})]})})]})]}),D?r.jsx("div",{className:"mindmap_error mono",children:D}):null,r.jsxs("div",{className:"mindmap_explorer",children:[r.jsx(pA,{title:"mindmap",resetKey:Xt,queryMode:"replace",items:Pn,warnings:z,onQuery:Qn,onItemsReplace:ys,onOpenSpan:({run_id:oe,span_id:ve,assertion:qe})=>{Mn({run_id:oe,span_id:ve,assertion:qe})},onOpenTranscript:({run_id:oe,span_id:ve,assertion:qe})=>{const We=String(oe||"").trim(),et=typeof ve=="string"?String(ve).trim():"";We&&(et?Mn({run_id:We,span_id:et,assertion:qe}):br({run_id:We,assertion:qe}))}},Xt),ee.length?r.jsxs("div",{className:"mindmap_recent mindmap_overlay mindmap_overlay_recent",children:[r.jsx("div",{className:"mindmap_recent_title mono muted",children:"new assertions"}),r.jsx("div",{className:"mindmap_recent_list",children:ee.slice().sort((oe,ve)=>ve.expires_at_ms-oe.expires_at_ms).slice(0,12).map(oe=>r.jsx("div",{className:"mindmap_recent_item mono",children:wA(oe.assertion)},oe.id))})]}):null,At?r.jsx("div",{className:"mindmap_timeline mindmap_overlay mindmap_overlay_timeline",children:r.jsxs("div",{className:"mindmap_timeline_row",children:[r.jsx("div",{className:"mindmap_timeline_label mono muted",children:Vl(Math.min(typeof $t=="number"?$t:At.max_ms,At.real_max_ms))}),r.jsx("input",{className:"mindmap_slider",type:"range",min:At.min_ms,max:At.max_ms,step:Ft,value:typeof $t=="number"?$t:At.max_ms,onChange:oe=>{const ve=Number(oe.target.value||0);pn(ve),zn(ve>=At.max_ms)}}),r.jsxs("div",{className:"mindmap_timeline_counts mono muted",children:[Pn.length.toLocaleString(),"/",R.length.toLocaleString()]})]})}):null]}),r.jsxs(Ja,{open:le,title:P||"source",onClose:()=>{ge(!1)},children:[F?r.jsx("div",{className:"mono muted",children:"Loading…"}):null,k?r.jsx("div",{className:"mindmap_error mono",children:k}):null,!F&&!k?r.jsxs("div",{className:"source_span",children:[(()=>{const oe=Ee;if(!oe)return null;const ve=String(oe.subject||"").trim(),qe=String(oe.predicate||"").trim(),We=String(oe.object||"").trim(),et=Vl(Ga(oe.observed_at)),at=oe.attributes&&typeof oe.attributes=="object"&&!Array.isArray(oe.attributes)?oe.attributes:null,Nt=at&&typeof at.evidence_quote=="string"?String(at.evidence_quote):"",xt=at&&typeof at.original_context=="string"?String(at.original_context):"";return r.jsxs("div",{className:"source_header",children:[r.jsxs("div",{className:"mono source_triple",title:`${ve} --${qe}--> ${We}`,children:[ve," ",r.jsxs("span",{className:"muted",children:["—",qe,"→"]})," ",We," ",et?r.jsxs("span",{className:"muted",children:["[",et,"]"]}):null]}),Nt?r.jsxs("div",{className:"source_evidence",children:[r.jsx("div",{className:"mono muted",style:{fontSize:11,marginBottom:6},children:"evidence_quote"}),r.jsx("pre",{className:"mono source_evidence_quote",children:Nt}),xt?r.jsxs("details",{className:"source_evidence_more",children:[r.jsx("summary",{className:"mono muted",children:"original_context"}),r.jsx("pre",{className:"mono source_evidence_quote",children:xt})]}):null]}):null]})})(),r.jsxs("div",{className:"mono muted",style:{marginBottom:10},children:["run_id=",L," · ",X==="artifact"?`span_id=${q}`:"source=input_data"]}),r.jsxs("div",{className:"source_actions",children:[$e!==null?r.jsx("button",{className:"btn",onClick:()=>Re($e),children:"Jump to evidence"}):null,$e===null&>?r.jsx("button",{className:"btn",onClick:()=>ot(),children:"Jump to evidence"}):null]}),(()=>{const oe=ie,ve=oe&&typeof oe=="object"&&!Array.isArray(oe)?oe:null,qe=pt,We=Ct,et=ve&&typeof ve.created_at=="string"?String(ve.created_at):"",at=et?Ga(et):null,Nt=at!==null?Vl(at):et,xt=ve&&ve.span&&typeof ve.span=="object"&&!Array.isArray(ve.span)?ve.span:null,Wt=xt&&typeof xt.from_timestamp=="string"?String(xt.from_timestamp):"",lt=xt&&typeof xt.to_timestamp=="string"?String(xt.to_timestamp):"",Vt=Wt?Ga(Wt):null,It=lt?Ga(lt):null,jt=Vt!==null&&It!==null?`${Vl(Vt)} → ${Vl(It)}`:"";if(We){const ft=vA(We);if(ft){const Mt=Ke,Ce=Mt?ft.messages.findIndex(kt=>Nm(kt.content,Mt)):-1,Ut=Mt?Wy(Mt):[],St=ft.created_at||et,nn=St?yA(St):et?Nt:"";return r.jsx("div",{className:"source_chat",children:ft.messages.map((kt,er)=>{const tr=kt.role,Ur=!!(Mt&&Nm(kt.content,Mt)),jr=tr==="user"?"USER":tr==="assistant"?"ASSISTANT":"SYSTEM";return r.jsxs("div",{id:er===Ce?"source_note_msg_hit_0":void 0,className:`source_msg source_${tr} ${Ur?"source_match":""}`,children:[r.jsxs("div",{className:"source_msg_meta mono muted",children:[r.jsxs("span",{children:["#",er+1," · ",jr,Ur?r.jsx("span",{className:"source_match_badge",children:"evidence"}):null]}),nn?r.jsx("span",{title:St||"",children:nn}):null]}),r.jsx("div",{className:"source_msg_body",children:r.jsx(pi,{text:kt.content,highlights:Ur&&Ut.length?Ut:void 0,highlightClassName:"source_note_hit",highlightId:er===Ce?"source_note_hit_0":void 0})})]},`note_msg:${er}`)})})}return r.jsxs("div",{className:"source_note",children:[et?r.jsx("div",{className:"mono muted",style:{marginBottom:10},children:r.jsxs("span",{title:et,children:["created_at=",Nt]})}):null,r.jsx(pi,{text:We,highlights:Ke?Wy(Ke):void 0,highlightClassName:"source_note_hit",highlightId:"source_note_hit_0"})]})}if(qe){const ft=new Map;for(const Ce of qe){const Ut=typeof(Ce==null?void 0:Ce.role)=="string"?String(Ce.role):"unknown";ft.set(Ut,(ft.get(Ut)||0)+1)}const Mt=Array.from(ft.entries()).sort((Ce,Ut)=>Ut[1]-Ce[1]||Ce[0].localeCompare(Ut[0])).map(([Ce,Ut])=>`${Ce}×${Ut}`).join(" · ");return r.jsxs("div",{className:"source_chat",children:[et?r.jsxs("div",{className:"mono muted",style:{marginBottom:10},children:[r.jsxs("span",{title:et,children:["created_at=",Nt]})," · messages=",qe.length]}):null,jt?r.jsxs("div",{className:"mono muted",style:{marginBottom:10},children:["span=",jt]}):null,Mt?r.jsxs("div",{className:"mono muted",style:{marginBottom:10},children:["participants: ",Mt]}):null,qe.slice(0,200).map((Ce,Ut)=>{var Zr,Wr;const St=typeof(Ce==null?void 0:Ce.role)=="string"?String(Ce.role):"unknown",nn=(Ce==null?void 0:Ce.content)==null?"":String(Ce.content),kt=typeof(Ce==null?void 0:Ce.timestamp)=="string"?String(Ce.timestamp):"",er=kt?Ga(kt):null,tr=er!==null?Vl(er):kt,Ur=typeof(Ce==null?void 0:Ce.message_id)=="string"?String(Ce.message_id):typeof((Zr=Ce==null?void 0:Ce.metadata)==null?void 0:Zr.message_id)=="string"?String(Ce.metadata.message_id):typeof((Wr=Ce==null?void 0:Ce.metadata)==null?void 0:Wr.id)=="string"?String(Ce.metadata.id):"",jr=nt.has(Ut);return r.jsxs("div",{id:`source_msg_${Ut}`,className:`source_msg source_${St} ${jr?"source_match":""}`,children:[r.jsxs("div",{className:"source_msg_meta mono muted",children:[r.jsxs("span",{children:["#",Ut+1," · ",St,jr?r.jsx("span",{className:"source_match_badge",children:"evidence"}):null,Ur?r.jsx("span",{className:"source_msg_id",children:Ur}):null]}),kt?r.jsx("span",{title:kt,children:tr}):null]}),r.jsx("div",{className:"source_msg_body",children:r.jsx(pi,{text:nn})})]},Ut)})]})}return r.jsx("pre",{className:"mono source_raw",style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:(typeof oe=="string"?oe:xe)||"(empty)"})})()]}):null]})]})}const j_=4;function bA(e){var l;const t=(l=e==null?void 0:e.discoveries)==null?void 0:l.dreams_signals_brief;if(!t||typeof t!="object"||Array.isArray(t))return null;const n=typeof t.count=="number"&&Number.isInteger(t.count)&&t.count>0?t.count:0;if(!n)return null;const i=u=>Array.isArray(u)?u.filter(d=>typeof d=="string").map(d=>d.trim()).filter(Boolean):[],a=typeof t.dreams=="number"&&Number.isInteger(t.dreams)&&t.dreams>0?t.dreams:null;return{count:n,kinds:i(t.kinds),felt_tones:i(t.felt_tones),dreams:a}}function Vy(e){if(!e||typeof e!="object")return null;const t=String(e.title||"").trim(),n=String(e.statement||"").trim();if(!t&&!n)return null;const i=typeof e.entry_id=="string"&&e.entry_id.trim()?e.entry_id.trim():null;return{record_id:String(e.record_id||"").trim(),title:t,statement:n,entry_id:i}}function jA(e){var d,m;const t=p=>{var v;const g=(v=e==null?void 0:e[p])==null?void 0:v.open;return Array.isArray(g)?g.map(Vy).filter(w=>w!==null):[]},n=t("questions"),i=t("problems"),a=(d=e==null?void 0:e.lessons)==null?void 0:d.lessons,l=Array.isArray(a)?a.map(Vy).filter(p=>p!==null):[],u=typeof((m=e==null?void 0:e.lessons)==null?void 0:m.total)=="number"?e.lessons.total:l.length;return{questions:n.slice(0,j_),questions_total:n.length,problems:i.slice(0,j_),problems_total:i.length,lessons:l.slice(0,j_),lessons_total:u}}function S_(e){return e===null||!Number.isFinite(e)||e<0?"":e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(e<1e4?1:0)}k`:`${(e/1e6).toFixed(1)}M`}const Gy={review:"Review",working:"Working",pending:"Pending",done:"Done"},SA={review:"nothing needs you",working:"idle",pending:"nothing scheduled",done:"no recent runs"},kA={pending:"scheduled or queued — will run without you",working:"running or parked listening — no action needed",review:"needs a human decision — act here",done:"terminal — read the outcome"};function NA(e){const t=String((e==null?void 0:e.status)||"").trim().toLowerCase();if(yi(t))return"done";const n=pu(e);return n==="tool_approval"||n==="user_response"?"review":n==="scheduled"||t==="pending"||t==="queued"||t==="created"?"pending":"working"}function CA(e){const t=pu(e);return t==="tool_approval"||t==="user_response"}function Ky(e,t=Date.now()){const n=NA(e),i=e!=null&&e.waiting&&typeof e.waiting=="object"?e.waiting:null,a=gu(i),l=xn((i==null?void 0:i.since)||(e==null?void 0:e.updated_at)||(e==null?void 0:e.created_at)||"");return{run_id:String((e==null?void 0:e.run_id)||""),column:n,workflow:String((e==null?void 0:e.workflow_id)||"").trim()||"(workflow?)",status:String((e==null?void 0:e.status)||"").trim().toLowerCase(),wait_kind:pu(e),reason:uw(e),tool_names:a.map(u=>String((u==null?void 0:u.name)||"tool")).filter(Boolean),wait_key:String((i==null?void 0:i.wait_key)||"").trim(),allow_free_text:(i==null?void 0:i.allow_free_text)!==!1,prompt:String((i==null?void 0:i.prompt)||"").trim(),since_ms:l,duration_ms:wg(e,t),tokens_total:typeof(e==null?void 0:e.tokens_total)=="number"?e.tokens_total:null,llm_calls:typeof(e==null?void 0:e.llm_calls)=="number"?e.llm_calls:null,tool_calls:typeof(e==null?void 0:e.tool_calls)=="number"?e.tool_calls:null,is_scheduled:!!(e!=null&&e.is_scheduled),schedule_interval:String((e==null?void 0:e.schedule_interval)||"").trim(),failed:String((e==null?void 0:e.status)||"").trim().toLowerCase()==="failed",error:String((e==null?void 0:e.error)||"").trim(),paused:!!(e!=null&&e.paused),is_subrun:!!String((e==null?void 0:e.parent_run_id)||"").trim(),tag:Fd(e),tag_label:Hv(e),automation_id:Fd(e)==="occurrence"?String((e==null?void 0:e.automation_id)||"").trim():""}}function $A(e,t,n=Date.now()){const i={pending:[],working:[],review:[],done:[]},a=t&&t.length?t:e,l=new Set;for(const u of a||[]){const d=String((u==null?void 0:u.run_id)||"").trim();!u||!d||l.has(d)||bp(u)||CA(u)&&(l.add(d),i.review.push(Ky(u,n)))}for(const u of e||[]){const d=String((u==null?void 0:u.run_id)||"").trim();if(!u||!d||l.has(d)||bp(u))continue;const m=Ky(u,n);i[m.column].push(m)}return i.review.sort((u,d)=>(u.since_ms??0)-(d.since_ms??0)),i.working.sort((u,d)=>(d.since_ms??0)-(u.since_ms??0)),i.pending.sort((u,d)=>(d.since_ms??0)-(u.since_ms??0)),i.done.sort((u,d)=>Number(d.failed)-Number(u.failed)||(d.since_ms??0)-(u.since_ms??0)),i}const fg={"12h":12*36e5,"24h":24*36e5,"48h":48*36e5,"72h":72*36e5,"7d":7*864e5,"14d":14*864e5,"1m":30*864e5,all:null},k_={"12h":"last 12h","24h":"last 24h","48h":"last 48h","72h":"last 72h","7d":"last 7 days","14d":"last 14 days","1m":"last month",all:"all loaded"},Yy="48h";function EA(e,t,n=Date.now()){const i=fg[t]??null;if(i===null)return{visible:e,hidden_count:0};const a=n-i,l=[];let u=0;for(const d of e)d.since_ms===null||d.since_ms>=a?l.push(d):u+=1;return{visible:l,hidden_count:u}}function AA(e,t=Date.now()){const n=String(e||"").trim();if(!n)return null;const i=Date.parse(n);return Number.isFinite(i)?Math.max(0,t-i):null}const MA=6e4;function Rd(e,t=Date.now()){if(e===null||!Number.isFinite(e))return"";const n=Math.max(0,t-e);return n<6e4?`${Math.round(n/1e3)}s`:n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${(n/36e5).toFixed(1)}h`:`${(n/864e5).toFixed(1)}d`}function TA(e){return!Number.isFinite(e)||e<0?"":e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.floor(e/6e4)}m${Math.round(e%6e4/1e3)}s`:`${(e/36e5).toFixed(1)}h`}function RA(e){const t=String(e||"");return t.length>14?`${t.slice(0,6)}…${t.slice(-6)}`:t}function N_(e){const t=String(e||"").trim();return t.length>72?`${t.slice(0,70)}…`:t}function LA(e){const t=String(e||"");let n=t.includes(":")?t.slice(t.lastIndexOf(":")+1):t;if(t.includes(":")&&/^[0-9a-f]{6,}$/i.test(n.trim())){const i=t.slice(0,t.lastIndexOf(":"));/[a-z]/i.test(i)&&!/^[0-9a-f]+$/i.test(i.replace(/[@.\-_]/g,""))&&(n=i)}return n.length>34?`${n.slice(0,32)}…`:n}function Om(e){return e.toLowerCase().replace(/[_-]+/g," ")}function OA(e){var p,g;const t=e!=null&&e.spec&&typeof e.spec=="object"?e.spec:null,n=t!=null&&t.phases&&typeof t.phases=="object"&&!Array.isArray(t.phases)?t.phases:null;if(!n)return null;const i=Object.keys(n).filter(v=>v&&typeof v=="string");if(!i.length)return null;const a=[];for(const v of i){a.push({needle:Om(v),phase:v});const w=(p=n[v])==null?void 0:p.spoken_synonyms;if(Array.isArray(w))for(const x of w){const N=Om(String(x||"").trim());N&&a.push({needle:N,phase:v})}}const u=(typeof t.initial_phase=="string"&&i.includes(t.initial_phase)?t.initial_phase:null)??(i.includes("sleep")?"sleep":null);if(!u)return null;const d=[],m=(g=t==null?void 0:t.state_mode_axis)==null?void 0:g.words;if(m&&typeof m=="object"&&!Array.isArray(m))for(const[v,w]of Object.entries(m)){const x=String((w==null?void 0:w.phase)||"").trim(),N=Om(String(v||"").trim());N&&i.includes(x)&&d.push({needle:N,phase:x})}return{phases:i,synonyms:a,modes:d,initial:u,version:typeof t.version=="number"?t.version:null,sha256:String((e==null?void 0:e.sha256)||"").trim()}}const PA=["asleep","sleep","dream"],IA=["rest"],DA=["awake","idle"];function zA(e,t){const n=String(e||"").trim().toLowerCase();if(!n)return"unknown";if(t){const i=Om(n),a=t.synonyms.filter(u=>i.includes(u.needle)).sort((u,d)=>d.needle.length-u.needle.length);if(a.length)return a[0].phase;const l=t.modes.filter(u=>i.includes(u.needle)).sort((u,d)=>d.needle.length-u.needle.length);return l.length?l[0].phase:n.includes("task")&&!n.includes("no_task")&&t.phases.includes("work")?"work":PA.some(u=>n.includes(u))?t.initial:IA.some(u=>n.includes(u))&&t.phases.includes("personal")?"personal":DA.some(u=>n.includes(u))?t.initial:n.includes("stop")?"stopped":n.includes("pause")?"paused":n}return n.includes("visit")?"visit":n.includes("sleep")||n.includes("dream")?"sleep":n.includes("personal")||n.includes("own_time")||n.includes("own time")?"personal":n.includes("task")&&!n.includes("no_task")||n.includes("work")?"work":n.includes("awake")||n.includes("idle")?"sleep":n.includes("stop")?"stopped":n.includes("pause")?"paused":n.includes("rest")?"resting":n}const FA=new Set(["visit","work","personal","sleep","paused","resting","stopped","unknown"]),BA=new Set(["visit","work","personal","sleep","paused","resting","stopped","unknown"]);function UA(e){if(!e)return FA;const t=e.phases.filter(n=>BA.has(n));return new Set([...t,"paused","stopped","unknown"])}function WA(e){var Q,Y,ee,ae,le,ge;const t=Date.now(),n=_.useMemo(()=>$A(e.runs,e.all_runs,Date.now()),[e.runs,e.all_runs]),[i,a]=_.useState(""),[l,u]=_.useState(""),[d,m]=_.useState(!1),[p,g]=_.useState(()=>{try{const F=localStorage.getItem("abstractobserver_done_window_v1");return F&&F in fg?F:Yy}catch{return Yy}}),v=_.useMemo(()=>EA(n.done,p,t),[n.done,p]),w=Rd(e.runs_refreshed_at,t),x=n.review.length,N=v.visible.filter(F=>F.failed).length,[S,R]=_.useState(""),[T,z]=_.useState(null),H=F=>`${F.run_id}:${F.wait_key}:${F.since_ms??""}`;_.useEffect(()=>{i&&(n.review.some(F=>H(F)===i)||a(""))},[n,i]);async function D(F,C){a(H(F)),u("");try{await e.on_resume_wait(F.run_id,F.wait_key,C)}catch(k){u(`${F.run_id}: ${String((k==null?void 0:k.message)||k||"resume failed")}`),a("")}}function G(F){const C=i===H(F),k=F.column==="review",I=k&&!F.wait_key;return r.jsxs("div",{className:`mc_card ${k?"mc_card_review":""} ${F.failed?"mc_card_failed":""}`,onClick:()=>e.on_open_run(F.run_id),role:"button",tabIndex:0,onKeyDown:P=>{P.key==="Enter"&&P.target===P.currentTarget&&e.on_open_run(F.run_id)},children:[r.jsxs("div",{className:"mc_card_head",children:[r.jsx("span",{className:"mc_card_title",title:F.workflow,children:LA(F.workflow)}),(()=>{const P=F.failed?"failed":Um({status:F.status,paused:F.paused});return r.jsx("span",{className:`mc_status ${nl(P)}`,children:P==="unknown"?"?":P})})()]}),r.jsxs("div",{className:"mc_card_meta",children:[r.jsx("span",{className:"mono",title:F.run_id,children:RA(F.run_id)}),F.is_subrun?r.jsx("span",{title:"This wait lives in a child run of an agent workflow",children:"subrun"}):null,F.tag?r.jsx("span",{className:"mc_pill","data-tag":F.tag,children:F.tag_label}):null,F.automation_id?r.jsx("button",{type:"button",className:"btn btn_sm",title:"Open this occurrence's automation",onClick:P=>{P.stopPropagation(),e.on_open_automation(F.automation_id)},onKeyDown:P=>P.stopPropagation(),children:"Automation"}):null,F.duration_ms>=0?r.jsx("span",{children:TA(F.duration_ms)}):null,F.tokens_total!==null?r.jsxs("span",{children:[F.tokens_total.toLocaleString()," tk"]}):null,F.tool_calls!==null&&F.tool_calls>0?r.jsxs("span",{children:[F.tool_calls," tools"]}):null]}),F.is_scheduled&&F.schedule_interval?r.jsxs("div",{className:"mc_card_line",children:["every ",F.schedule_interval]}):null,F.failed&&F.error?r.jsx("div",{className:"mc_card_error",title:F.error,children:F.error.length>120?`${F.error.slice(0,118)}…`:F.error}):null,k?r.jsxs("div",{className:"mc_card_review_body",onClick:P=>P.stopPropagation(),onKeyDown:P=>P.stopPropagation(),children:[r.jsx("div",{className:"mc_card_reason",children:F.reason||"Needs a decision"}),F.prompt?r.jsx("div",{className:"mc_card_prompt",title:F.prompt,children:F.prompt.length>240?`${F.prompt.slice(0,238)}…`:F.prompt}):null,F.tool_names.length?r.jsxs("div",{className:"mc_card_tools",title:"Tool calls awaiting your approval",children:[F.tool_names.slice(0,4).map((P,K)=>r.jsx("span",{className:"mc_tool_chip mono",children:P},`${P}_${K}`)),F.tool_names.length>4?r.jsxs("span",{className:"mc_tool_chip",children:["+",F.tool_names.length-4," more"]}):null]}):null,F.since_ms!==null?r.jsxs("div",{className:"mc_card_waiting",children:["waiting ",Rd(F.since_ms,t)]}):null,I?r.jsx("div",{className:"mc_card_line",title:"The wait has not registered a wait_key yet — open the run to inspect.",children:"wait key not published yet — open the run"}):null,I?r.jsx("div",{className:"mc_card_actions",children:r.jsx("button",{className:"btn",onClick:()=>e.on_open_run(F.run_id),children:"Open the run →"})}):F.wait_kind==="tool_approval"?r.jsxs("div",{className:"mc_card_actions",children:[r.jsx("button",{className:"btn success",disabled:C,onClick:()=>void D(F,{approved:!0}),children:C?"Resuming…":"Approve"}),r.jsx("button",{className:"btn danger",disabled:C,onClick:()=>void D(F,{approved:!1}),children:"Reject"})]}):r.jsx("div",{className:"mc_card_actions",children:r.jsx("button",{className:"btn primary",onClick:()=>e.on_open_run(F.run_id),children:"Review & answer →"})})]}):null]},F.run_id)}return r.jsxs("div",{className:"page page_scroll mc_page",children:[r.jsxs("div",{className:"mc_health",children:[r.jsx("span",{className:`mc_led ${e.gateway_connected?"ok":"bad"}`,title:e.gateway_connected?"Gateway connected":"Gateway unreachable"}),e.gateway_connected?null:r.jsx("span",{className:"mc_health_text",children:"gateway unreachable"}),e.runs_refreshed_at===null?r.jsx("span",{className:"mc_health_text muted mc_loading",children:"loading runs…"}):r.jsxs("div",{className:"mc_stats",children:[r.jsxs("div",{className:`mc_stat ${x?"is_hot":""}`,title:"runs blocked on a human decision (Review column)",children:[r.jsx("span",{className:"mc_stat_value",children:x}),r.jsx("span",{className:"mc_stat_label",children:"need you"})]}),r.jsxs("div",{className:`mc_stat ${N?"is_bad":""}`,title:"failed runs in the Done column",children:[r.jsx("span",{className:"mc_stat_value",children:N}),r.jsx("span",{className:"mc_stat_label",children:"failed"})]}),r.jsxs("div",{className:"mc_stat",title:"runs executing or parked listening",children:[r.jsx("span",{className:"mc_stat_value",children:n.working.length}),r.jsx("span",{className:"mc_stat_label",children:"working"})]})]}),r.jsx("span",{className:"mc_spacer"}),r.jsxs("div",{className:"mc_health_side",children:[w?r.jsxs("span",{className:"mc_health_text muted",title:"age of the last runs poll — the board is only as live as this",children:["data ",w," old"]}):null,r.jsx("button",{className:"btn",onClick:e.on_refresh,disabled:e.refreshing,children:e.refreshing?"Refreshing…":"Refresh"})]})]}),l?r.jsx("div",{className:"mc_error",children:l}):null,e.entities.length||e.entities_error?r.jsxs("div",{className:"mc_entities",children:[r.jsxs("div",{className:"mc_entities_head",children:[r.jsxs("span",{children:["Entities",e.entities_total>e.entities.length?` (${e.entities.length} of ${e.entities_total} — open the entity app for all)`:""]}),r.jsx("a",{className:"mc_entity_link",href:e.entity_app_href,target:"_blank",rel:"noreferrer",children:"open the entity app →"})]}),e.entities_error?r.jsx("div",{className:"muted",children:e.entities_error}):null,r.jsx("div",{className:"mc_entities_row",children:e.entities.map(F=>r.jsxs("div",{className:"mc_entity_cell",children:[r.jsxs("a",{className:"mc_entity",href:`${e.entity_app_href}${e.entity_app_href.includes("?")?"&":"?"}entity=${encodeURIComponent(F.name)}&live=1`,target:"_blank",rel:"noreferrer",title:[F.error,F.age_days!==null?`${F.age_days.toFixed(0)} days old`:"",F.last_moment].filter(Boolean).join(" — ")||F.name,children:[r.jsx("span",{className:"mc_entity_name",children:F.name}),(()=>{var O;const C=String(F.live_phase||F.state||"").trim(),k=zA(C,e.phase_graph),I=UA(e.phase_graph).has(k)?k:"other",P=((O=e.phase_graph)==null?void 0:O.initial)??"sleep",K=/awake|idle/i.test(C)&&k===P,L=C&&C.toLowerCase()!==k?` — wire word: ${C}${K?" (settling)":""}`:"";return r.jsx("span",{className:`mc_entity_phase mc_phase_${I}`,title:(F.live_phase?"phase (cognition wire)":"phase from card state — cognition wire unavailable")+L,children:k})})(),F.last_moment?r.jsx("span",{className:"mc_entity_moment",title:F.last_moment,children:F.last_moment.replace(/_/g," ")}):null,(()=>{if(F.working===!0)return r.jsx("span",{className:"mc_entity_live",title:"busy now (loop mid-day or live visit — store-read, never fabricated)",children:"● busy"});const C=AA(F.last_moment_at,t);return F.working===!1?r.jsxs("span",{className:"mc_entity_live muted",title:"idle (cognition wire)",children:["idle",C!==null?` · ${Rd(t-C,t)} ago`:""]}):C===null?null:C<=MA?r.jsx("span",{className:"mc_entity_live",title:`last moment ${Rd(t-C,t)} ago`,children:"● active"}):r.jsxs("span",{className:"mc_entity_live muted",title:"time since the last recorded moment",children:[Rd(t-C,t)," ago"]})})(),F.tokens_total!==null?r.jsxs("span",{className:"muted mc_entity_spend",title:`lifetime billed tokens (home run ledger)${F.live_visit_tokens!==null?`; open visit: ${S_(F.live_visit_tokens)} tk`:""}${F.spend_warning?`; ${F.spend_warning}`:""}`,children:[S_(F.tokens_total)," tk",F.live_visit_tokens!==null?` (+${S_(F.live_visit_tokens)})`:"",F.spend_warning?"*":""]}):null]}),F.open_questions_total||F.open_problems_total||F.lessons_total||F.dreams_brief?r.jsx("button",{type:"button",className:"mc_entity_hints_btn","aria-expanded":S===F.name,title:"open questions / problems + distilled lessons + night signals from the entity card — click to expand",onClick:()=>R(S===F.name?"":F.name),children:[F.open_questions_total?`${F.open_questions_total} question${F.open_questions_total>1?"s":""}`:"",F.open_problems_total?`${F.open_problems_total} problem${F.open_problems_total>1?"s":""}`:"",F.lessons_total?`${F.lessons_total} lesson${F.lessons_total>1?"s":""}`:"",F.dreams_brief?`night: ${F.dreams_brief.count} signal${F.dreams_brief.count>1?"s":""}`:""].filter(Boolean).join(" · ")}):null]},F.name))}),(()=>{if(!S)return null;const F=e.entities.find(I=>I.name===S);if(!F||!F.open_questions.length&&!F.open_problems.length&&!F.lessons.length&&!F.dreams_brief)return null;const C=e.on_read_diary?async I=>{const P=await e.on_read_diary(F.name,I);z({entity:F.name,entry:(P==null?void 0:P.entry)??P,seq:typeof(P==null?void 0:P.read_recorded_at_seq)=="number"?P.read_recorded_at_seq:null})}:void 0,k=F.open_questions_total-F.open_questions.length+(F.open_problems_total-F.open_problems.length)+(F.lessons_total-F.lessons.length);return r.jsxs("div",{className:"mc_entity_hints_panel",children:[F.open_questions.map((I,P)=>r.jsx(Gh,{kind:"question",label:I.title||N_(I.statement),entryId:I.entry_id,onOpen:C,title:I.statement||I.title},`q_${I.record_id||P}`)),F.open_problems.map((I,P)=>r.jsx(Gh,{kind:"problem",label:I.title||N_(I.statement),entryId:I.entry_id,onOpen:C,title:I.statement||I.title},`p_${I.record_id||P}`)),F.lessons.map((I,P)=>r.jsx(Gh,{kind:"lesson",label:I.title||N_(I.statement),entryId:I.entry_id,onOpen:C,title:I.statement||I.title},`l_${I.record_id||P}`)),F.dreams_brief?r.jsxs("span",{className:"mc_entity_dreams muted",title:"night signals carried by STANDING dreams (the sleep pass's maintenance stream; count = signals, not dreams); felt tones color the content, they never rank it — the entity app renders the full stream",children:["night signals: ",F.dreams_brief.count,F.dreams_brief.dreams?` across ${F.dreams_brief.dreams} dream${F.dreams_brief.dreams>1?"s":""}`:"",F.dreams_brief.kinds.length?` — ${F.dreams_brief.kinds.slice(0,6).join(", ")}${F.dreams_brief.kinds.length>6?` +${F.dreams_brief.kinds.length-6} more`:""}`:"",F.dreams_brief.felt_tones.length?` · felt: ${F.dreams_brief.felt_tones.slice(0,6).join(", ")}`:""]}):null,k>0?r.jsxs("span",{className:"muted mc_entity_hints_more",children:["+",k," more — open the entity app"]}):null]})})()]}):null,T?r.jsx(Ja,{open:!0,title:`${T.entity} — diary entry`,onClose:()=>z(null),children:r.jsxs("div",{className:"mc_diary_entry",children:[r.jsx("div",{className:"mc_diary_meta muted",children:[(Q=T.entry)!=null&&Q.kind?`kind: ${T.entry.kind}`:"",(Y=T.entry)!=null&&Y.visibility?`visibility: ${T.entry.visibility}`:"",(ee=T.entry)!=null&&ee.written_at?`written: ${T.entry.written_at}`:"",(ae=T.entry)!=null&&ae.entry_id?`id: ${T.entry.entry_id}`:""].filter(Boolean).join(" · ")}),r.jsxs("div",{className:"mc_diary_recorded muted",children:["this read was recorded in ",T.entity,"’s stream",T.seq!==null?` (seq ${T.seq})`:""]}),(le=T.entry)!=null&&le.gist?r.jsx("div",{className:"mc_diary_gist",children:String(T.entry.gist)}):null,r.jsx("pre",{className:"mc_diary_text",children:String(((ge=T.entry)==null?void 0:ge.text)||"(entry carries no text)")})]})}):null,r.jsx("div",{className:"mc_board",children:Object.keys(Gy).map(F=>{const C=F==="done"?v.visible:n[F],k=F==="done"&&!d?C.slice(0,8):C;return r.jsxs("div",{className:`mc_column mc_column_${F}`,children:[r.jsxs("div",{className:"mc_column_head",children:[r.jsx("span",{className:"mc_column_title",children:Gy[F]}),F==="done"?r.jsx("select",{className:"mc_window_select",value:p,title:"Show terminal runs from this time window",onClick:I=>I.stopPropagation(),onChange:I=>{const P=I.target.value;g(P),m(!1);try{localStorage.setItem("abstractobserver_done_window_v1",P)}catch{}},children:Object.keys(fg).map(I=>r.jsx("option",{value:I,children:k_[I]},I))}):null,r.jsx("span",{className:"mc_column_count",title:F==="done"&&v.hidden_count?`${v.hidden_count} older run(s) outside this window`:void 0,children:C.length})]}),r.jsx("div",{className:"mc_column_hint muted",children:kA[F]}),r.jsxs("div",{className:"mc_column_cards",children:[k.map(I=>G(I)),C.length?null:r.jsx("div",{className:"mc_empty muted",children:e.runs_refreshed_at===null?"loading…":F==="done"&&v.hidden_count?`none in the ${k_[p]} — ${v.hidden_count} older`:SA[F]}),F==="done"&&C.length>8&&!d?r.jsxs("button",{className:"btn mc_more",onClick:()=>m(!0),children:["show all ",C.length]}):null,F==="done"&&v.hidden_count&&C.length?r.jsxs("div",{className:"mc_window_note muted",title:"Widen the window above to see older terminal runs",children:["+",v.hidden_count," older outside ",k_[p]]}):null]})]},F)})})]})}function Xy(e){const t=Array.from(new Set(e.map(n=>String(n||"").trim()).filter(Boolean)));return t.sort((n,i)=>n.localeCompare(i)),t}function Jy(e){const t=e.disabled===!0,n=_.useMemo(()=>Xy(e.options||[]),[e.options]),i=_.useMemo(()=>Xy(e.value||[]),[e.value]),[a,l]=_.useState(!1),[u,d]=_.useState(""),m=_.useMemo(()=>{const v=u.trim().toLowerCase();return v?n.filter(w=>w.toLowerCase().includes(v)):n},[n,u]),p=_.useMemo(()=>new Set(i),[i]),g=typeof e.max_list_height_px=="number"?e.max_list_height_px:220;return r.jsxs("div",{className:"multi_select",children:[r.jsxs("div",{className:"multi_select_row",children:[r.jsxs("button",{className:"btn",type:"button",onClick:()=>l(v=>!v),disabled:t||!n.length,"aria-expanded":a,children:[a?"Hide":"Select"," • ",i.length>0?`${i.length} of ${n.length}`:e.placeholder||"(none)"]}),r.jsx("button",{className:"btn",type:"button",onClick:()=>e.onChange(n.slice()),disabled:t||!n.length||i.length===n.length,title:"Select all",children:"All"}),r.jsx("button",{className:"btn",type:"button",onClick:()=>e.onChange([]),disabled:t||i.length===0,title:"Clear selection",children:"Clear"})]}),i.length>0?r.jsx("div",{className:"multi_select_chips",children:i.map(v=>r.jsxs("span",{className:"multi_select_chip",title:v,onClick:()=>{if(t)return;const w=new Set(p);w.delete(v),e.onChange(Array.from(w.values()))},children:[v,t?null:r.jsx("span",{className:"multi_select_chip_x",children:"×"})]},v))}):null,a?r.jsxs("div",{className:"multi_select_panel",children:[r.jsx("input",{className:"mono",value:u,onChange:v=>d(String(v.target.value||"")),placeholder:"filter…",disabled:t}),r.jsxs("div",{className:"multi_select_list",style:{maxHeight:`${g}px`},children:[m.map(v=>{const w=p.has(v);return r.jsxs("label",{className:`multi_select_item mono ${w?"checked":""}`,children:[r.jsx("input",{type:"checkbox",checked:w,disabled:t,onChange:x=>{const N=new Set(p);x.target.checked?N.add(v):N.delete(v),e.onChange(Array.from(N.values()))}}),r.jsx("span",{children:v})]},v)}),m.length?null:r.jsx("div",{className:"mono muted",children:"(no matches)"})]})]}):null]})}function HA(){var t;if(typeof window>"u")return!1;const e=navigator;return!!((t=e==null?void 0:e.mediaDevices)!=null&&t.getUserMedia)&&typeof window.MediaRecorder=="function"}function qA(){if(typeof window>"u")return!1;const e=window;return!!(e!=null&&e.AudioContext||e!=null&&e.webkitAudioContext)}function VA(){const e=window.MediaRecorder,t=i=>{var a;try{return!!((a=e==null?void 0:e.isTypeSupported)!=null&&a.call(e,i))}catch{return!1}},n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus","audio/ogg"];for(const i of n)if(t(i))return i;return""}async function GA(e,t){var a;const n=t.slice(0),i=(a=e.decodeAudioData)==null?void 0:a.bind(e);if(typeof i!="function")throw new Error("decodeAudioData not available");try{const l=i(n);if(l&&typeof l.then=="function")return await l}catch{}return await new Promise((l,u)=>{try{i(n,l,u)}catch(d){u(d)}})}function KA(e){const t=I=>{var P;return(P=e.on_error)==null?void 0:P.call(e,I)},n=_.useMemo(()=>qA(),[]),i=_.useMemo(()=>HA(),[]),[a,l]=_.useState({key:"",status:"idle"}),u=_.useRef(""),d=_.useRef(""),m=_.useRef(null),p=_.useRef(null),g=_.useRef(null),v=_.useRef(null),w=_.useRef(0),x=_.useRef(0),N=()=>{try{const I=globalThis,P=(I==null?void 0:I.AudioContext)||(I==null?void 0:I.webkitAudioContext);if(!P)return null;if(!m.current){const O=new P,q=O.createGain();q.gain.value=1,q.connect(O.destination),m.current=O,p.current=q}const K=m.current,L=p.current;if(!K||!L)return null;try{K.state==="suspended"&&K.resume()}catch{}return{ctx:K,gain:L}}catch{return null}},S=()=>{const I=g.current;if(g.current=null,!!I){try{I.onended=null}catch{}try{I.stop()}catch{}try{I.disconnect()}catch{}}},R=()=>{S(),d.current="",u.current="",v.current=null,w.current=0,x.current=0,l({key:"",status:"idle"})};_.useEffect(()=>()=>{var I,P;R();try{(I=p.current)==null||I.disconnect()}catch{}try{(P=m.current)==null||P.close()}catch{}m.current=null,p.current=null,v.current=null},[]);const T=async(I,P,K)=>{const L=N();if(!L)throw new Error("TTS playback is not supported in this browser");const{ctx:O,gain:q}=L;try{O.state==="suspended"&&await O.resume()}catch{}S();const E=O.createBufferSource();E.buffer=P,E.connect(q);const X=Number.isFinite(Number(P.duration))?Number(P.duration):0,ne=Math.max(0,Math.min(Number(K||0),X>0?Math.max(0,X-.01):0));x.current=O.currentTime-ne,w.current=ne,g.current=E,u.current=I,E.onended=()=>{g.current===E&&(g.current=null,w.current=0,x.current=0,u.current="",l({key:"",status:"idle"}))},E.start(0,ne),l({key:I,status:"playing"})},z=async(I,P)=>{const K=String(I||"").trim(),L=String(P||"").trim();if(!K||!L)return;const O=e.gateway,q=String(e.run_id||"").trim();if(!O){t==null||t("Connect to the gateway first.");return}if(!q){t==null||t("Voice store not available (missing run_id).");return}const E=N();if(!E){t==null||t("TTS playback is not supported in this browser.");return}const X=a.key===K;if(X&&a.status==="playing"){const ne=Math.max(0,E.ctx.currentTime-Number(x.current||0));w.current=ne,S(),l({key:K,status:"paused"});return}if(X&&a.status==="paused"){const ne=v.current;if(ne){t==null||t("");try{await T(K,ne,w.current)}catch(ie){t==null||t(String((ie==null?void 0:ie.message)||ie||"TTS play failed")),l({key:"",status:"idle"})}return}}if(!(X&&a.status==="loading")){S(),v.current=null,w.current=0,x.current=0,u.current=K,d.current=K,l({key:K,status:"loading"}),t==null||t("");try{const ne=await O.voice_tts(q,{text:L,request_id:zr()}),ie=ne==null?void 0:ne.audio_artifact,de=ie&&typeof ie=="object"&&!Array.isArray(ie)?String(ie.$artifact||"").trim():"";if(!de)throw new Error("TTS failed: missing audio artifact");const be=await(await O.download_run_artifact_content(q,de)).arrayBuffer();if(d.current!==K)return;const Ee=await GA(E.ctx,be);if(d.current!==K)return;v.current=Ee,w.current=0,await T(K,Ee,0)}catch(ne){d.current===K&&(d.current="",u.current="",l({key:"",status:"idle"})),t==null||t(String((ne==null?void 0:ne.message)||ne||"TTS failed"))}}},[H,D]=_.useState(!1),[G,Q]=_.useState(!1),Y=_.useRef(null),ee=_.useRef(null),ae=_.useRef([]),le=_.useRef("");function ge(){var I,P;try{(P=(I=Y.current)==null?void 0:I.getTracks)==null||P.call(I).forEach(K=>{try{K.stop()}catch{}})}catch{}Y.current=null}_.useEffect(()=>()=>{var I,P;try{(P=(I=ee.current)==null?void 0:I.stop)==null||P.call(I)}catch{}ee.current=null,ge()},[]);async function F(I,P){var q;if(t==null||t(""),!I||!I.size||G)return;const K=e.gateway,L=String(e.session_id||"").trim(),O=String(e.run_id||"").trim();if(!K){t==null||t("Connect to the gateway first.");return}if(!L){t==null||t("Voice input unavailable (missing session_id).");return}if(!O){t==null||t("Voice input unavailable (missing run_id).");return}Q(!0);try{const E=String(P||I.type||"").toLowerCase(),X=E.includes("mp4")?"m4a":E.includes("ogg")?"ogg":E.includes("wav")?"wav":"webm",ne=new File([I],`recording.${X}`,{type:E||"audio/webm"}),ie=await K.attachments_upload(L,ne,{filename:ne.name,content_type:ne.type}),de=await K.audio_transcribe(O,{audio_artifact:ie,request_id:zr()}),xe=String((de==null?void 0:de.text)||"").trim();xe&&((q=e.on_transcript)==null||q.call(e,xe))}catch(E){t==null||t(String((E==null?void 0:E.message)||E||"Transcription failed"))}finally{Q(!1)}}async function C(){if(t==null||t(""),!i){t==null||t("Voice recording is not supported in this browser (MediaRecorder/getUserMedia unavailable).");return}if(!G&&!(H||ee.current)){ae.current=[];try{const I=await navigator.mediaDevices.getUserMedia({audio:!0});Y.current=I;const P=VA();le.current=P;const K=P?new MediaRecorder(I,{mimeType:P}):new MediaRecorder(I);ee.current=K,K.ondataavailable=L=>{try{L!=null&&L.data&&ae.current.push(L.data)}catch{}},K.onerror=()=>{t==null||t("Recording failed.")},K.onstop=()=>{D(!1),ge(),ee.current=null;try{const L=new Blob(ae.current,{type:le.current||""});F(L,le.current)}catch(L){t==null||t(String((L==null?void 0:L.message)||L||"Failed to build recording"))}},K.start(),D(!0)}catch(I){ge(),ee.current=null,D(!1);const P=String((I==null?void 0:I.message)||I||"Failed to access microphone");t==null||t(P.toLowerCase().includes("permission")?`Microphone permission denied: ${P}`:P)}}}function k(){const I=ee.current;if(!(!H||!I)){ee.current=null,D(!1);try{I.stop()}catch(P){t==null||t(String((P==null?void 0:P.message)||P||"Failed to stop recording"))}}}return _.useEffect(()=>{if(!H)return;const I=()=>k();return window.addEventListener("pointerup",I),window.addEventListener("pointercancel",I),()=>{window.removeEventListener("pointerup",I),window.removeEventListener("pointercancel",I)}},[H]),{tts_supported:n,tts_playback:a,toggle_tts:z,stop_tts:R,voice_ptt_supported:i,voice_ptt_recording:H,voice_ptt_busy:G,start_voice_ptt_recording:C,stop_voice_ptt_recording:k}}const Cm=500,th="http://127.0.0.1:8080";function Zy(e){const t=String(e||"").trim(),n=t.indexOf(":");return n<=0||n>=t.length-1?null:{bundle_id:t.slice(0,n),flow_id:t.slice(n+1)}}function Ld(e){const t=String(e||"").trim();return t.startsWith("abstractcode.")?`abstract.${t.slice(13)}`:t}function C_(e){const t=e&&typeof e=="object"?e:{},n=typeof(t==null?void 0:t.count)=="number"&&Number.isFinite(t.count)?Number(t.count):null,i=typeof(t==null?void 0:t.node_id)=="string"&&t.node_id.trim()?` before ${t.node_id.trim()}`:"";return`${n===null?"steering":`${n} steer message${n===1?"":"s"}`} folded into the run${i} — the loop sees it at this boundary`}function $_(e){const t=String(e||"").trim();return t.startsWith("abstract.")||t.startsWith("abstractcode.")}function YA(e){const t=String(e||"").trim();if(t.startsWith("evt:")){const n=t.split(":",4);if(n.length===4&&n[3])return String(n[3]).trim()}return t}function XA(e){if(!e||typeof e!="object")return[];const t=Array.isArray(e.nodes)?e.nodes:[];if(!t.length)return[];let n=null;for(const d of t){if(!d||typeof d!="object")continue;const m=d.data&&typeof d.data=="object"?d.data:{};if(String(m.nodeType||d.type||"").trim()==="on_flow_start"){n=d;break}}if(!n)return[];const i=n.data&&typeof n.data=="object"?n.data:{},a=Array.isArray(i.outputs)?i.outputs:[],l=i.pinDefaults&&typeof i.pinDefaults=="object"?i.pinDefaults:{},u=[];for(const d of a){if(!d||typeof d!="object")continue;const m=String(d.id||"").trim();if(!m)continue;const p=String(d.type||"").trim();if(p==="execution"||m==="exec-out"||m==="exec")continue;const g=String(d.label||m).trim()||m,v={id:m,label:g,type:p||"unknown"};l&&Object.prototype.hasOwnProperty.call(l,m)&&(v.default=l[m]),u.push(v)}return u}function E_(e,t){const n=String((e==null?void 0:e.message)||e||"Discovery failed");if(/\b401\b/.test(n)){const i=String(t.gateway_user||"").trim();return i?`Gateway authentication failed for user '${i}'. Sign in again through the connection dialog. (${n})`:`Gateway authentication failed. Sign in through the connection dialog (or check the dev bearer token under Settings → Advanced). (${n})`}return n}const JA=/^[a-zA-Z0-9_-]+$/;function Qy(e){return JA.test(String(e||"").trim())}async function ZA(e){const t=String(e||""),n=new TextEncoder().encode(t),i=globalThis.crypto;if(!i||!i.subtle||typeof i.subtle.digest!="function")throw new Error("crypto.subtle.digest not available");const a=await i.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(a)).map(l=>l.toString(16).padStart(2,"0")).join("")}async function ev(e){const t=String(e||"").trim();if(!t)throw new Error("session_id is required");if(Qy(t)){const i=`session_memory_${t}`;if(Qy(i))return i}return`session_memory_sha_${(await ZA(t)).slice(0,32)}`}const tv=new Set(["abstract.status","abstract.summary","abstract.chat"]);function QA(e){if(!e)return!1;if(e.kind==="error")return!0;if(e.kind==="info")return!1;const t=String(e.emit_name||"").trim();if((e.kind==="event"||e.kind==="message")&&t)return!tv.has(t);const n=String(e.effect_type||"").trim();if(n){if(n==="tool_calls"||n==="llm_call"||n==="ask_user"||n==="answer_user"||n==="memory_compact"||n==="start_subworkflow")return!0;if(n==="emit_event")return!(t&&tv.has(t))}if(String(e.status||"").trim()==="waiting"){const l=Bi(e.data),u=String((l==null?void 0:l.reason)||"").trim();return!!(u==="user"||u==="event"||gu(l).length)}return!!ef(e.data)}function eM(){try{const e=localStorage.getItem("abstractobserver_settings");if(!e)throw new Error("missing");const t=JSON.parse(e);return{gateway_url:String((t==null?void 0:t.gateway_url)||th),auth_token:"",gateway_user:String((t==null?void 0:t.gateway_user)||""),gateway_auth_mode:(t==null?void 0:t.gateway_auth_mode)==="direct"?"direct":"session",worker_url:String((t==null?void 0:t.worker_url)||""),worker_token:String((t==null?void 0:t.worker_token)||""),theme:String((t==null?void 0:t.theme)||"dark"),font_scale:String((t==null?void 0:t.font_scale)||(t==null?void 0:t.fontScale)||"md").trim()||"md",header_density:String((t==null?void 0:t.header_density)||(t==null?void 0:t.headerDensity)||"standard").trim()||"standard",auto_connect_gateway:(t==null?void 0:t.auto_connect_gateway)!==!1,maintenance_ai_provider:String((t==null?void 0:t.maintenance_ai_provider)||""),assistant_skill_names:Array.isArray(t==null?void 0:t.assistant_skill_names)?t.assistant_skill_names.map(n=>String(n||"").trim()).filter(Boolean):[],maintenance_ai_model:String((t==null?void 0:t.maintenance_ai_model)||"")}}catch{return{gateway_url:th,auth_token:"",gateway_user:"",gateway_auth_mode:"session",worker_url:"",worker_token:"",theme:"dark",font_scale:"md",header_density:"standard",auto_connect_gateway:!0,maintenance_ai_provider:"",assistant_skill_names:[],maintenance_ai_model:""}}}function tM(e){localStorage.setItem("abstractobserver_settings",JSON.stringify({...e,auth_token:""}))}function nM(e){if(!e||typeof e!="object"||Array.isArray(e))return[];const t=[],n=(a,l)=>{const u=String(l??"").trim();u&&(t.some(d=>d.label===a&&d.value===u)||t.push({label:a,value:u}))},i=String(e.display??"").trim().replace(/^\[/,"").replace(/\]$/,"");return n("time",i||e.local_datetime),n("tz",e.timezone),n("country",e.country),n("user",e.user),t}function nv(e){const t=nM(e.metadata);return t.length?r.jsx("div",{className:"runtime_metadata_chips","aria-label":"Runtime metadata",children:t.map(n=>r.jsxs("span",{className:"chip mono muted",children:[n.label,": ",n.value]},`${n.label}:${n.value}`))}):null}function rv(e){const t=String(e||"").trim();return t?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t):!1}function rM(){try{const t=String(window.location.hash||"").replace(/^#/,"").split("/").filter(Boolean),n=t.length?String(t[t.length-1]||"").trim():"";if(rv(n))return n;const a=String(window.location.pathname||"").split("/").filter(Boolean),l=a.length?String(a[a.length-1]||"").trim():"";if(rv(l))return l}catch{}return""}function sM(){try{const e="abstractobserver_session_id_v1",t=window.sessionStorage.getItem(e);if(t&&t.trim())return t.trim();const n=globalThis.crypto,a=`obs_${n&&typeof n.randomUUID=="function"?n.randomUUID():`${Math.random().toString(16).slice(2)}_${Date.now().toString(16)}`}`;return window.sessionStorage.setItem(e,a),a}catch{return""}}function iM(){var Wa,Hc,Ul,Wl,Er,Di,$s,Ir,vd,qc,Vc,tm,zi;const[e,t]=_.useState("board"),[n,i]=_.useState(()=>eM()),a=typeof window<"u"&&((Wa=window.__ABSTRACT_UI_CONFIG__)==null?void 0:Wa.monitor_gpu)===!0,l=typeof window<"u"&&(((Hc=window.__ABSTRACT_UI_CONFIG__)==null?void 0:Hc.entity_app_url)||"").trim().replace(/\/+$/,"")||"http://127.0.0.1:3007",u=_.useRef(null),[d,m]=_.useState(""),[p,g]=_.useState(""),[v,w]=_.useState(()=>rM()),[x,N]=_.useState(""),[S,R]=_.useState(""),[T,z]=_.useState("{}"),[H]=_.useState(()=>sM()),[D,G]=_.useState(null),[Q,Y]=_.useState(!1),[ee,ae]=_.useState(""),[le,ge]=_.useState(!1),[F,C]=_.useState(""),[k,I]=_.useState(!1),P=f0({appName:"AbstractObserver",variant:"dismissable",defaultGatewayUrl:typeof window<"u"&&((Ul=window.__ABSTRACT_UI_CONFIG__)==null?void 0:Ul.gateway_url)||th,onStatusChange:h=>Ku(h)}),[K,L]=_.useState(null),[O,q]=_.useState(null),[E,X]=_.useState(!1),[ne,ie]=_.useState(null),[de,xe]=_.useState("once"),[be,Ee]=_.useState(""),[Oe,He]=_.useState(F_),[Ke,Ct]=_.useState([]),[pt,gt]=_.useState(null),[yt,nt]=_.useState(!1),[$e,Re]=_.useState([]),ot=_.useRef(new nS(zr)),[he,Pe]=_.useState({available:!1,reason:"Sign in to a gateway to use automations."}),[Ve,Rt]=R0("abstractobserver",{legacyKey:"abstractobserver_settings"}),[Xt,fn]=_.useState(!1),[Ft,At]=_.useState(!1),[sn,zn]=_.useState([]),[$t,pn]=_.useState([]),[Pn,Cn]=_.useState([]),[yn,Mn]=_.useState(!1),[mn,br]=_.useState(null),[Hn,Qn]=_.useState([]),[ys,qn]=_.useState(0),[oe,ve]=_.useState(""),qe=_.useRef(!1),We=_.useRef(0),et=_.useRef(0),[at,Nt]=_.useState(!1),[xt,Wt]=_.useState([]),[lt,Vt]=_.useState([]),[It,jt]=_.useState({}),[ft,Mt]=_.useState(!1),[Ce,Ut]=_.useState(!1),[St,nn]=_.useState(!1),[kt,er]=_.useState([]),[tr,Ur]=_.useState([]),jr=_.useRef(0),Zr=_.useRef(null);Zr.current||(Zr.current=new Up(h=>window.setTimeout(h,40),h=>er(j=>j.concat(h))));const Wr=_.useRef(null);Wr.current||(Wr.current=new Up(h=>window.setTimeout(h,40),h=>Ur(j=>j.concat(h))));const Gi=_.useRef({scanned:0,found:null}),[ye,Vn]=_.useState(null),[cn,Ki]=_.useState(""),[vi,vs]=_.useState(!1),Qr=_.useRef(null),[Ts,rt]=_.useState({}),[Qt,ur]=_.useState({}),[Js,nr]=_.useState(!1),[Yi,Xi]=_.useState(""),[Qo,In]=_.useState(!0),[es,$n]=_.useState(""),[ts,Ji]=_.useState(!1),[Kn,Hr]=_.useState(!1),[rr,Rs]=_.useState(6),[dr,ea]=_.useState("standard"),[Zi,en]=_.useState(""),[sl,wi]=_.useState(""),[ns,Sr]=_.useState(!1),[ta,ws]=_.useState(!1),[Zs,xi]=_.useState("pause"),[qr,kr]=_.useState(""),[xs,Vr]=_.useState(""),[bi,rs]=_.useState(""),fr=_.useRef(null),ji=_.useRef(null),[fo,il]=_.useState(!1),Gr=_.useRef(null),[mo,Ls]=_.useState(""),[oc,ss]=_.useState(""),[Qi,Lr]=_.useState(""),[ho,_o]=_.useState(""),[go,eo]=_.useState(""),[B,re]=_.useState(!1),[we,Se]=_.useState("idle"),[je,Fe]=_.useState([]),mt=_.useRef(null),[it,ct]=_.useState(!1),[Bt,Lt]=_.useState(""),[sr,Dt]=_.useState(""),[Kt,hn]=_.useState(""),[_n,mr]=_.useState([]),[Nr,Qs]=_.useState(!1),[na,ra]=_.useState(""),[yu,ac]=_.useState(""),[sa,lc]=_.useState(!1),[sf,po]=_.useState(""),of=_.useMemo(()=>{if(!je.length)return"";try{return JSON.stringify(je.map(h=>({role:h.role,content:h.content,ts:h.ts})))}catch{return"1"}},[je]),vu=_.useMemo(()=>je.length?Kt?of!==Kt:!0:!1,[of,je.length,Kt]),cc=_.useMemo(()=>_n.map(h=>{const j=String(h.title||"").trim()||`Chat ${String(h.thread_id||"").slice(0,8)}`,$=String(h.created_at||"").trim(),M=$?$.replace("T"," ").slice(0,19):"",U=String(h.run_id||"").trim()?String(h.run_id).slice(0,8):"",W=[j,M&&`(${M})`,U&&`run ${U}`].filter(Boolean).join(" • ");return{value:String(h.thread_id||""),label:W}}),[_n]);_.useEffect(()=>{a&&FS()},[a]),_.useEffect(()=>{if(!a)return;const h=u.current;h&&(h.token=n.gateway_auth_mode==="direct"&&n.auth_token||"")},[a,n.auth_token,n.gateway_auth_mode]);const[wu,xu]=_.useState([]),[hh,bu]=_.useState({}),[ju,af]=_.useState({}),[Su,Jt]=_.useState(""),[uc,_h]=_.useState(""),[ku,gh]=_.useState("all"),[Nu,ph]=_.useState("status"),[hr,Os]=_.useState("overview"),[yo,ol]=_.useState(!0),[al,dc]=_.useState("steps"),[lf,Cu]=_.useState(""),[fc,mc]=_.useState(""),[vo,hc]=_.useState([]),[cf,uf]=_.useState(!1),[df,ll]=_.useState(""),[ia,wo]=_.useState(""),[yh,oa]=_.useState([]),[vh,$u]=_.useState(!1),[Eu,cl]=_.useState(""),[ff,_c]=_.useState(!1),[mf,wh]=_.useState(""),[xh,aa]=_.useState(""),[hf,gc]=_.useState(""),[Ps,to]=_.useState(!1),[xo,la]=_.useState(""),[bo,ca]=_.useState(null),[ua,Au]=_.useState({}),[_f,ei]=_.useState(!1),[pc,Si]=_.useState(""),[da,gf]=_.useState(!1),[ul,fa]=_.useState(!1),[Mu,dl]=_.useState(()=>Date.now()),[bs,jo]=_.useState(""),[pf,fl]=_.useState({}),[yf,yc]=_.useState({}),ma=_.useRef([]),Yn=_.useRef(null),ti=_.useRef(""),ha=_.useRef({}),_a=_.useRef({}),Tu=_.useRef({}),ki=_.useRef(new Set),[Ni,ml]=_.useState([]),ga=_.useRef(""),on=_.useRef({}),ni=_.useRef(null),_r=_.useRef(null),Is=_.useRef(0),So=_.useRef({}),pa=_.useRef(!1),Ds=_.useRef(new Set),[ya,Ci]=_.useState(""),[zs,no]=_.useState(""),ri=_.useRef(""),[Ru,va]=_.useState(!1),[vc,wa]=_.useState(""),wc=()=>({artifact_id:"",kind:"binary",render_kind:"",text:"",url:"",loading:!1,error:""}),[ko,xc]=_.useState("activity"),[Lu,Ou]=_.useState([]),[vf,wf]=_.useState(0),[Pu,$i]=_.useState(0),[xf,No]=_.useState({}),[si,xa]=_.useState({}),[Ei,bc]=_.useState(!1),[bh,bf]=_.useState(""),[Fs,hl]=_.useState(""),[ii,ba]=_.useState("all"),[ja,Co]=_.useState(""),[is,bn]=_.useState([]),[un,ro]=_.useState("all"),[Fn,Kr]=_.useState("type"),[oi,Sa]=_.useState("newest"),[Bn,_l]=_.useState(""),[ka,Na]=_.useState(""),[gl,jc]=_.useState(""),[os,Ca]=_.useState(0),[so,Sc]=_.useState(()=>wc()),[jh,Bs]=_.useState(!1),[$o,$a]=_.useState(""),[kc,ai]=_.useState(""),[vn,Or]=_.useState(""),[Ai,Mi]=_.useState("text"),[Ti,li]=_.useState(null),[jf,Eo]=_.useState(!1),[Nc,gr]=_.useState(""),[Yr,jn]=_.useState(""),[Us,Iu]=_.useState(""),[Du,Cc]=_.useState(!1),[zu,Fu]=_.useState(""),[Ao,Sf]=_.useState("run_ledger"),[Ea,Bu]=_.useState(""),[Sh,Mo]=_.useState([]),[$c,Ec]=_.useState(""),[kf,To]=_.useState(!1),[Nf,Aa]=_.useState(""),Le=_.useMemo(()=>new s_({base_url:n.gateway_auth_mode==="session"?"":n.gateway_url,auth_token:n.gateway_auth_mode==="session"?"":n.auth_token}),[n.gateway_auth_mode,n.gateway_url,n.auth_token]),Tn=_.useMemo(()=>new gS(Le.automations_client(),mS(Le,zr,wt)),[Le]),Ac=_.useSyncExternalStore(h=>Tn.subscribe(h),()=>Tn.state);_.useEffect(()=>{const h=()=>{const j=Qj(window.location.hash);j&&(j.page==="launch"&&xe(j.mode),t(j.page))};return h(),window.addEventListener("hashchange",h),()=>window.removeEventListener("hashchange",h)},[]);const Uu=_.useMemo(()=>{const h={};for(const j of Ac.items)h[j.automation_id]=j.title;return h},[Ac.items]),Wu=_.useMemo(()=>ES(),[]),[Hu,Ro]=_.useState([]),as=_.useRef(0);function Lo(){const h=++as.current;Ro([["Gateway","checking…"]]),AS(Le).then(j=>{h===as.current&&Ro(j)})}const Ma=_.useMemo(()=>n.worker_url.trim()?new Fk({url:n.worker_url.trim(),auth_token:n.worker_token}):null,[n.worker_url,n.worker_token]),Cr=kt.length?kt[kt.length-1].record:null,Ot=_.useMemo(()=>Bi(Cr),[Cr]),Rn=_.useMemo(()=>{const h=S.trim();if(!D||!h||String(D.bundle_id||"").trim()&&String(D.bundle_id||"").trim()!==h)return null;const j=Array.isArray(D.entrypoints)?D.entrypoints:[];if(!j.length)return null;const $=x.trim();if($)return j.find(U=>String(U.flow_id||"").trim()===$)||null;if(j.length===1)return j[0];const M=String(D.default_entrypoint||"").trim();return M&&j.find(U=>String(U.flow_id||"").trim()===M)||null},[D,S,x]),pl=_.useMemo(()=>{const h=Rn==null?void 0:Rn.inputs;return Array.isArray(h)?h:[]},[Rn]),qu=_.useMemo(()=>XA(bo),[bo]),ls=_.useMemo(()=>pl.length?pl:qu,[pl,qu]),Ri=_.useMemo(()=>{const h=typeof(ye==null?void 0:ye.workflow_id)=="string"?String(ye.workflow_id):"",j=Zy(h);if(j&&D&&String(D.bundle_id||"").trim()===j.bundle_id){const U=(Array.isArray(D.entrypoints)?D.entrypoints:[]).find(W=>String((W==null?void 0:W.flow_id)||"").trim()===j.flow_id);if(U&&U.node_index&&typeof U.node_index=="object")return U.node_index}const $=Rn==null?void 0:Rn.node_index;return $&&typeof $=="object"?$:{}},[ye,D,Rn]);_.useEffect(()=>{tM(n)},[n]),_.useEffect(()=>()=>{ni.current&&ni.current.abort(),_r.current&&_r.current.abort(),fr.current&&window.clearTimeout(fr.current),ji.current&&window.clearTimeout(ji.current),Yn.current&&window.clearTimeout(Yn.current),Gr.current&&window.clearTimeout(Gr.current)},[]);const st=_.useMemo(()=>{const h=T.trim();if(!h)return{};try{const j=JSON.parse(h);return typeof j!="object"||j===null||Array.isArray(j)?null:j}catch{return null}},[T]),Cf=typeof(st==null?void 0:st.prompt)=="string"?String(st.prompt):"",Ta=typeof(st==null?void 0:st.provider)=="string"?String(st.provider):"",$f=typeof(st==null?void 0:st.model)=="string"?String(st.model):"",yl=typeof(st==null?void 0:st.workspace_root)=="string"?String(st.workspace_root):"",Ws=typeof(st==null?void 0:st.workspace_access_mode)=="string"?String(st.workspace_access_mode):"",vl=_.useMemo(()=>{const h=st==null?void 0:st.workspace_allowed_paths;return Array.isArray(h)?h.map(j=>String(j||"").trim()).filter(Boolean).join(`
|
|
132
|
+
`):typeof h=="string"?String(h):""},[st]),wl=_.useMemo(()=>{const h=st==null?void 0:st.workspace_ignored_paths;return Array.isArray(h)?h.map(j=>String(j||"").trim()).filter(Boolean).join(`
|
|
133
|
+
`):typeof h=="string"?String(h):""},[st]),Oo=ls.length>0&&!!S.trim(),xl=h=>{const j=String(h||"").trim().toLowerCase();return j==="object"||j==="memory"||j==="assertion"||j==="assertions"||j==="any"};_.useEffect(()=>{ur({})},[S,x]),_.useEffect(()=>{st!==null&&rt(h=>{const j={};for(const $ of ls){if(!$||typeof $!="object")continue;const M=String($.id||"").trim();if(!M)continue;const U=String($.type||"").trim();if(!xl(U))continue;if(String(Qt[M]||"").trim()){j[M]=typeof h[M]=="string"?h[M]:"";continue}const V=st==null?void 0:st[M];V===void 0?j[M]="":j[M]=BS(V)}return j})},[ls,st,Qt]);const Hs=be?{kind:"default",interface:be}:S.trim()&&x.trim()?{kind:"bundle",bundle_id:S.trim(),flow_id:x.trim()}:null,Ef=Gj(Hs),js=Array.isArray(st==null?void 0:st.skills)?st.skills.map(h=>String(h||"").trim()).filter(Boolean):[],Zt=_.useMemo(()=>{const h={};for(const j of sn){const $=String(j.workflow_id||"").trim(),M=String(j.label||"").trim();$&&M&&(h[$]=M)}return h},[sn]),bl=_.useMemo(()=>sn.filter(h=>h.has_interface),[sn]),Vu=_.useMemo(()=>{const h=new Set;for(const j of Array.isArray(lt)?lt:[]){const $=String((j==null?void 0:j.name)||"").trim();$&&h.add($)}return Array.from(h).sort()},[lt]),Gu=_.useMemo(()=>{const h=[];for(const j of Array.isArray(lt)?lt:[]){const $=String((j==null?void 0:j.name)||"").trim();if(!$)continue;const M=String((j==null?void 0:j.display_name)||"").trim();h.push({name:$,display_name:M||void 0})}return h},[lt]),Mc=_.useMemo(()=>{const h=new Set;for(const j of xt||[]){if(!j||typeof j!="object")continue;const $=String(j.name||"").trim();$&&h.add($)}return Array.from(h).sort()},[xt]),Tc=_.useMemo(()=>{const h=n.maintenance_ai_provider.trim();if(!h)return{models:[],error:""};const j=It[h];return j?{models:(Array.isArray(j.models)?j.models:[]).map(M=>String(M||"").trim()).filter(Boolean),error:String(j.error||"")}:{models:[],error:""}},[It,n.maintenance_ai_provider]),Li=n.maintenance_ai_provider.trim(),Ln=!!(Li&&k&&!Object.prototype.hasOwnProperty.call(It,Li));_.useEffect(()=>{const h=Ta.trim();if(!h||It[h]||on.current[h])return;on.current[h]=!0;let j=!1;return(async()=>{try{const M=await Le.discovery_provider_models(h);if(j)return;const U=Array.isArray(M==null?void 0:M.models)?M.models:[],W=typeof(M==null?void 0:M.error)=="string"?String(M.error):"";jt(V=>({...V,[h]:{models:U,error:W||void 0}}))}catch(M){if(j)return;jt(U=>({...U,[h]:{models:[],error:String((M==null?void 0:M.message)||M||"Failed to load models")}}))}finally{delete on.current[h]}})(),()=>{j=!0}},[Ta,It,Le]),_.useEffect(()=>{const h=n.maintenance_ai_provider.trim();if(!h||!k||It[h]||on.current[h])return;on.current[h]=!0;let j=!1;return(async()=>{try{const M=await Le.discovery_provider_models(h);if(j)return;const U=Array.isArray(M==null?void 0:M.models)?M.models:[],W=typeof(M==null?void 0:M.error)=="string"?String(M.error):"";jt(V=>({...V,[h]:{models:U,error:W||void 0}}))}catch(M){if(j)return;jt(U=>({...U,[h]:{models:[],error:String((M==null?void 0:M.message)||M||"Failed to load models")}}))}finally{delete on.current[h]}})(),()=>{j=!0}},[n.maintenance_ai_provider,It,Le,k]);function Tt(h,j){const $=String(h||"").trim();if(!$)return;let M={};try{const U=JSON.parse(T||"{}");typeof U=="object"&&U!==null&&!Array.isArray(U)&&(M=U)}catch{M={}}if(j==null){delete M[$],z(JSON.stringify(M,null,2));return}if(typeof j=="string")j?M[$]=j:delete M[$];else if(Array.isArray(j)){const U=j.map(W=>W).filter(W=>W!=null);U.length?M[$]=U:delete M[$]}else M[$]=j;z(JSON.stringify(M,null,2))}async function Xn(h){const j=String(h||"").trim();if(!j)return ae("Missing bundle_id"),null;ae(""),Y(!0);try{const $=await Le.get_bundle(j);return G($),Gt({ts:wt(),kind:"info",title:`Loaded bundle ${j}`}),$}catch($){return G(null),ae(String(($==null?void 0:$.message)||$||"Failed to load bundle")),null}finally{Y(!1)}}function Ra(h){const j=[],$=Array.isArray(h==null?void 0:h.items)?h.items:[];for(const M of $){const U=String((M==null?void 0:M.bundle_id)||"").trim();if(!U)continue;const W=Array.isArray(M==null?void 0:M.entrypoints)?M.entrypoints:[];if(W.length)for(const V of W){const Z=String((V==null?void 0:V.flow_id)||"").trim();if(!Z||(V==null?void 0:V.deprecated)===!0)continue;const ke=`${U}:${Z}`,me=String((V==null?void 0:V.name)||"").trim(),ue=me?`${U} · ${me}`:`${U} · ${Z}`,Ne=String((V==null?void 0:V.description)||"").trim(),ze=(Array.isArray(V==null?void 0:V.interfaces)?V.interfaces:[]).some(Be=>String(Be||"").trim().length>0),Ge=Array.isArray(V==null?void 0:V.agent_default_interfaces)?V.agent_default_interfaces.map(Be=>String(Be||"").trim()).filter(Boolean):[];j.push({workflow_id:ke,bundle_id:U,bundle_ref:String((M==null?void 0:M.bundle_ref)||"").trim(),flow_id:Z,label:ue,description:Ne||void 0,has_interface:ze,agent_default_interfaces:Ge})}}return j.sort((M,U)=>M.label.localeCompare(U.label)),j}async function ir(h=Le,j){if(qe.current&&!(j!=null&&j.force))return;qe.current=!0;const $=Po.current;Mn(!0);try{const M=me=>me.map(sS).filter(ue=>!!ue.run_id),[U,W]=await Promise.all([h.list_runs({limit:200,root_only:!0,include_metrics:!0}),h.list_runs({limit:500,root_only:!1,include_metrics:!0})]);if($!==Po.current)return;const V=Array.isArray(U==null?void 0:U.items)?U.items:[],Z=Array.isArray(W==null?void 0:W.items)?W.items:[],ke=M(V).filter(me=>!String(me.parent_run_id||"").trim()||me.role==="occurrence");pn(ke),Cn(M(Z).filter(me=>!!me.run_id)),br(Date.now()),et.current=0,We.current=0}catch(M){const U=String((M==null?void 0:M.message)||M||"");if(Gt({ts:wt(),kind:"error",title:"Refresh runs failed",preview:ut(U)}),(/\b40[13]\b/.test(U)||/unauthorized|forbidden/i.test(U))&&P.refresh().catch(()=>{}),/\b429\b/.test(U)||/too many requests/i.test(U)){const W=Math.min(12e4,Math.max(15e3,et.current*2||15e3));et.current=W,We.current=Date.now()+W,Gt({ts:wt(),kind:"info",title:`Gateway rate-limited — pausing polls ${Math.round(W/1e3)}s`})}}finally{qe.current=!1,Mn(!1)}}async function La(h){var Z,ke,me;const j=Po.current;I(!0),jt({});const[$,,M,U,W]=await Promise.allSettled([h.list_bundles(),ir(h),h.discovery_tools(),h.discovery_providers({include_models:!1}),h.discovery_capabilities()]);if(j!==Po.current)return;if($.status==="rejected"&&M.status==="rejected"&&U.status==="rejected"){I(!1),C(E_($.reason,n)),Gt({ts:wt(),kind:"error",title:"Discovery failed",preview:ut(String($.reason||""))});return}Pe(W.status==="fulfilled"?iS(W.value):{available:!1,reason:`Could not read the gateway capabilities: ${String(((Z=W.reason)==null?void 0:Z.message)||W.reason)}`});let V=0;if($.status==="fulfilled"){const ue=Ra($.value);V=ue.length,zn(ue)}else zn([]),Gt({ts:wt(),kind:"error",title:"Discovery bundles failed",preview:ut(String($.reason||""))});if(M.status==="fulfilled"){const ue=Array.isArray((ke=M.value)==null?void 0:ke.items)?M.value.items:[];Wt(ue)}else Wt([]),Gt({ts:wt(),kind:"error",title:"Discovery tools failed",preview:ut(String(M.reason||""))});if(U.status==="fulfilled"){const ue=Array.isArray((me=U.value)==null?void 0:me.items)?U.value.items:[];Vt(ue)}else Vt([]),Gt({ts:wt(),kind:"error",title:"Discovery providers failed",preview:ut(String(U.reason||""))});Gt({ts:wt(),kind:"info",title:"Gateway discovery loaded",preview:ut(`workflows: ${V}`)})}async function jl(h){var j,$;C(""),I(!1),ge(!0);try{if(!(h!=null&&h.prefer_direct)&&(await P.refresh(),or.current))return;const M=String(n.auth_token||"").trim();if(!M){h!=null&&h.open_modal_if_needed&&P.openModal();return}const U=String(n.gateway_url||"").trim();if(U){const V=U.toLowerCase();if(!V.startsWith("http://")&&!V.startsWith("https://"))throw new Error("Gateway URL must start with http:// or https:// (or leave it blank to use same origin / dev proxy).");try{if(String(((j=window==null?void 0:window.location)==null?void 0:j.protocol)||"")==="https:"&&V.startsWith("http://"))throw new Error("Gateway URL is http:// but this page is https:// (mixed content is blocked). Use https:// or leave Gateway URL blank to use same origin /api proxy.");const ke=new URL(U),me=String((($=window==null?void 0:window.location)==null?void 0:$.hostname)||"").trim().toLowerCase(),ue=String(ke.hostname||"").trim().toLowerCase(),Ne=Ie=>Ie==="localhost"||Ie==="127.0.0.1"||Ie==="::1";if(Ne(ue)&&me&&!Ne(me))throw new Error("Gateway URL points to localhost, which from this device is not your machine. Use the gateway's public URL (e.g. an ngrok https URL) or leave Gateway URL blank to use same origin /api proxy.")}catch(Z){throw new Error(String((Z==null?void 0:Z.message)||Z||"Invalid Gateway URL"))}}const W=new s_({base_url:U,auth_token:M});await W.list_bundles(),i(V=>({...V,gateway_auth_mode:"direct"})),await La(W)}catch(M){C(E_(M,n))}finally{ge(!1)}}const or=_.useRef(!1),Po=_.useRef(0),Sl=_.useRef(!1);function Ku(h){var $,M,U;L(h);const j=!!(h&&h.has_session&&(($=h.gateway)!=null&&$.ok));if(or.current=j,j){if(Sl.current=!1,k&&n.gateway_auth_mode==="direct")return;const W=String(((U=(M=h==null?void 0:h.gateway)==null?void 0:M.principal)==null?void 0:U.user_id)||"").trim();if(i(V=>({...V,gateway_auth_mode:"session",auth_token:"",gateway_user:W||V.gateway_user})),k&&n.gateway_auth_mode==="session")return;C(""),ge(!0),La(new s_({base_url:"",auth_token:""})).catch(V=>C(E_(V,n))).finally(()=>ge(!1));return}h&&!h.has_session&&(n.gateway_auth_mode==="session"&&Io({keep_session:!0}),String(n.auth_token||"").trim()&&!k&&!Sl.current&&(Sl.current=!0,jl({prefer_direct:!0})))}async function ci(){if(!(at||le)){Nt(!0);try{await Le.reload_bundles();const h=await Le.list_bundles(),j=Ra(h);zn(j),Gt({ts:wt(),kind:"info",title:"Bundles reloaded",preview:ut(`workflows: ${j.length}`)})}catch(h){const j=String((h==null?void 0:h.message)||h||"Bundle reload failed");Gt({ts:wt(),kind:"error",title:"Bundle reload failed",preview:ut(j),data:{error:j}})}finally{Nt(!1)}}}async function Ss(h){if(vi||le||!k)return;const j=h;if(j){vs(!0),Jt("");try{const $=await Le.upload_bundle(j,{overwrite:!1,reload:!0});Gt({ts:wt(),kind:"info",title:"Bundle uploaded",preview:ut(String(($==null?void 0:$.bundle_ref)||""))});const M=await Le.list_bundles(),U=Ra(M);zn(U)}catch($){const M=String(($==null?void 0:$.message)||$||"Upload failed");Jt(M),Gt({ts:wt(),kind:"error",title:"Upload .flow failed",preview:ut(M),data:{error:M}})}finally{vs(!1);try{Qr.current&&(Qr.current.value="")}catch{}}}}function Io(h){Po.current+=1,h!=null&&h.keep_session||(P.signOut().catch(()=>{}),or.current=!1),Df(),R(""),N(""),la(""),G(null),ae(""),Y(!1),zn([]),pn([]),Cn([]),br(null),Qn([]),Wt([]),Vt([]),jt({}),C(""),I(!1),L(null),i(j=>({...j,auth_token:""})),Gt({ts:wt(),kind:"info",title:"Gateway disconnected"})}async function kl(h){const j=String(h??"");if(j){try{await navigator.clipboard.writeText(j),Sn("Copied to clipboard",2);return}catch{}try{const $=document.createElement("textarea");$.value=j,$.style.position="fixed",$.style.left="-9999px",$.style.top="0",$.style.opacity="0",document.body.appendChild($),$.focus(),$.select(),document.execCommand("copy"),document.body.removeChild($),Sn("Copied to clipboard",2)}catch{Sn("Copy failed",2)}}}_.useEffect(()=>{const h=d.trim();if(!ft||!h)return;let j=!1;const $=async()=>{if(!(We.current>Date.now()))try{const U=await Le.get_run(h);j||Vn(U)}catch{}};$();const M=window.setInterval($,2e3);return()=>{j=!0,window.clearInterval(M)}},[ft,d,Le]),_.useEffect(()=>{if(!k)return;let h=null,j=!1,$=!1;const M=V=>{j||(h!==null&&window.clearTimeout(h),h=window.setTimeout(()=>void U(),V))},U=async()=>{if($)return;const V=We.current-Date.now();if(V>0){M(V+500);return}$=!0;const Z=Date.now();try{await ir(Le)}finally{$=!1;const ke=Date.now()-Z,me=document.visibilityState==="hidden"?3e4:5e3;M(Math.max(me,ke*3))}},W=()=>{document.visibilityState==="visible"&&U()};return U(),document.addEventListener("visibilitychange",W),()=>{j=!0,h!==null&&window.clearTimeout(h),document.removeEventListener("visibilitychange",W)}},[k,Le]);const[Yu,Rc]=_.useState(null);_.useEffect(()=>{if(!k){Rc(null);return}let h=!1;return(async()=>{try{const j=await Le.get_entity_phases_spec();if(h)return;const $=OA(j);if(Rc($),$)try{const M=localStorage.getItem("abstractobserver_phase_graph_id_v1"),U=M?JSON.parse(M):null;U&&U.sha256&&$.sha256&&U.sha256!==$.sha256&&U.version===$.version&&Gt({ts:wt(),kind:"error",title:"Phase-graph drift: served bytes changed without a version bump",preview:ut(`v${$.version}: ${String(U.sha256).slice(0,12)}… -> ${String($.sha256).slice(0,12)}…`),data:{prev:U,now:{sha256:$.sha256,version:$.version}}}),localStorage.setItem("abstractobserver_phase_graph_id_v1",JSON.stringify({sha256:$.sha256,version:$.version}))}catch{}}catch(j){if(!h){Rc(null);const $=String((j==null?void 0:j.message)||j||"");/404|not found/i.test($)||Gt({ts:wt(),kind:"info",title:"Phase-graph fetch failed — pre-wire fallback vocabulary in use (#FALLBACK)",preview:ut($),data:{error:$}})}}})(),()=>{h=!0}},[k]),_.useEffect(()=>{if(!k){Qn([]),ve("");return}let h=!1,j=null;const $=async()=>{if(!(We.current>Date.now())){try{const M=await Le.list_entities(),U=M.entities.map(V=>String((V==null?void 0:V.name)||(V==null?void 0:V.slug)||"").trim()).filter(Boolean).slice(0,12),W=await Promise.all(U.map(async V=>{var Z,ke;try{const[me,ue]=await Promise.all([Le.get_entity_card(V),Le.get_entity_cognition(V).catch(()=>null)]),Ne=me!=null&&me.state&&typeof me.state=="object"?me.state:null,Ie=Array.isArray(me==null?void 0:me.moments)?me.moments:[],ze=Ie.length?Ie[Ie.length-1]:null,Ge=(Z=ue==null?void 0:ue.spend)==null?void 0:Z.lifetime,Be=(ke=ue==null?void 0:ue.spend)==null?void 0:ke.live_visit,tn=Array.isArray(ue==null?void 0:ue.warnings)?ue.warnings.map(Ue=>String(Ue||"")).filter(Boolean):[],Je=jA(me);return{name:V,state:String((Ne==null?void 0:Ne.state)??(typeof(me==null?void 0:me.state)=="string"?me.state:"")).trim(),age_days:typeof(me==null?void 0:me.age_days)=="number"?me.age_days:null,last_moment:String((ze==null?void 0:ze.kind)||"").trim(),last_moment_at:String((ze==null?void 0:ze.at)||"").trim(),working:typeof(ue==null?void 0:ue.working)=="boolean"?ue.working:null,tokens_total:typeof(Ge==null?void 0:Ge.tokens_total)=="number"?Ge.tokens_total:null,live_visit_tokens:typeof(Be==null?void 0:Be.tokens_total)=="number"?Be.tokens_total:null,spend_warning:tn.join(" | "),live_phase:typeof(ue==null?void 0:ue.phase)=="string"?ue.phase:"",open_questions:Je.questions,open_questions_total:Je.questions_total,open_problems:Je.problems,open_problems_total:Je.problems_total,lessons:Je.lessons,lessons_total:Je.lessons_total,dreams_brief:bA(me),error:""}}catch(me){return{name:V,state:"",age_days:null,last_moment:"",last_moment_at:"",working:null,tokens_total:null,live_visit_tokens:null,spend_warning:"",live_phase:"",open_questions:[],open_questions_total:0,open_problems:[],open_problems_total:0,lessons:[],lessons_total:0,dreams_brief:null,error:String((me==null?void 0:me.message)||me||"card failed")}}}));h||(Qn(W),qn(M.entities.length),ve(""))}catch(M){if(!h){Qn([]);const U=String((M==null?void 0:M.message)||M||"");ve(/404|not found/i.test(U)?"":U)}}h||(j=window.setTimeout(()=>void $(),3e4))}};return $(),()=>{h=!0,j!==null&&window.clearTimeout(j)}},[k,Le]);async function Af(h,j,$){const M=String(j||"").trim();if(!h||!M)throw new Error("This wait has no wait_key yet — open the run to inspect.");await Le.submit_command({command_id:zr(),run_id:h,type:"resume",payload:{wait_key:M,payload:$||{}},client_id:"web_pwa"}),Gt({ts:wt(),kind:"info",title:"Board resume submitted",preview:ut(`run ${h} · wait ${M}`),data:{run_id:h,wait_key:M}}),ir(Le,{force:!0}),window.setTimeout(()=>void ir(Le,{force:!0}),1200)}const ks=_.useMemo(()=>{const h=ye==null?void 0:ye.session_id;return typeof h=="string"?h.trim():h==null?"":String(h||"").trim()},[ye]),Do=_.useMemo(()=>{const h=String(ks||"").trim();return h||String(H||"").trim()},[ks,H]);_.useEffect(()=>{if(!k||!Do){eo(""),_o("");return}(async()=>{try{const h=await ev(Do);eo(h)}catch{eo("")}})()},[k,Do]);const Un=KA({gateway:k?Le:null,session_id:Do,run_id:go,on_error:_o,on_transcript:h=>{const j=String(h||"").trim();j&&(ss($=>{const M=String($||"");return M.trim()?`${M.trimEnd()}
|
|
134
|
+
${j}`:j}),window.setTimeout(()=>{var $;return($=mt.current)==null?void 0:$.focus()},0))}});function Xu(h,j){try{const $=URL.createObjectURL(h),M=document.createElement("a");M.href=$,M.download=j||"download",M.rel="noreferrer",document.body.appendChild(M),M.click(),document.body.removeChild(M),window.setTimeout(()=>URL.revokeObjectURL($),5e3)}catch{}}async function Ju(){if(!cf){if(!k||!ks){mc(""),hc([]),ll("");return}uf(!0),ll("");try{const h=await ev(ks);mc(h);const j=await Le.list_run_artifacts(h,{limit:800}),M=(Array.isArray(j==null?void 0:j.items)?j.items:[]).filter(U=>{const W=U==null?void 0:U.tags;return W&&typeof W=="object"&&String(W.kind||"").trim()==="attachment"});hc(M)}catch(h){const j=String((h==null?void 0:h.message)||h||"Failed to load session attachments"),$=j.toLowerCase();j.includes("404")||$.includes("session_memory_")&&$.includes("not found")||$.includes('"detail"')&&$.includes("not found")&&$.includes("session_memory_")?(hc([]),ll("")):(hc([]),ll(j)),mc("")}finally{uf(!1)}}}async function Mf(){const h=ia.trim();if(!h){Sn("This run recorded no workspace folder",2);return}try{const j=await fetch("/api/local/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:h})}),$=await j.json().catch(()=>({}));j.ok&&($!=null&&$.ok)?Sn(`Opened ${String($.path||h)}`,2):Sn(String(($==null?void 0:$.error)||`Folder reveal failed (${j.status})`),3)}catch(j){Sn(String((j==null?void 0:j.message)||j||"Folder reveal failed"),3)}}async function Nl(h){const j=String(fc||"").trim();if(!j){Sn("No session attachment store yet",2);return}const $=String((h==null?void 0:h.artifact_id)||"").trim();if(!$)return;const M=h!=null&&h.tags&&typeof h.tags=="object"?h.tags:{},U=String(M.filename||"").trim(),W=String(M.path||"").trim(),V=U||(W?W.split("/").pop():"")||$,Z=t_(V);try{const ke=await Le.download_run_artifact_content(j,$,{access:"download"});Xu(ke,Z),Sn("Downloaded attachment",2)}catch(ke){Sn(String((ke==null?void 0:ke.message)||ke||"Download failed"),3)}}async function Tf(h){const j=String(fc||"").trim(),$=String((h==null?void 0:h.artifact_id)||"").trim();if(!j||!$)return;const M=h!=null&&h.tags&&typeof h.tags=="object"?h.tags:{},U=String(M.filename||"").trim(),W=String(M.path||"").trim(),V=W?`@${W}`:U||$,Z=typeof(h==null?void 0:h.size_bytes)=="number"?Number(h.size_bytes):null,ke=String((h==null?void 0:h.content_type)||M.content_type||"").trim().toLowerCase();if(wh(V),aa(""),gc(""),_c(!0),typeof Z=="number"&&Z>1e6){aa(`(Attachment is ${Z.toLocaleString()} bytes; download to view.)`);return}if(!(!ke||ke.startsWith("text/")||ke.includes("json")||ke.includes("yaml")||ke.includes("toml")||ke.includes("xml"))){aa(`(Binary attachment: ${ke||"unknown"}; download to view.)`);return}to(!0);try{const Ne=await(await Le.download_run_artifact_content(j,$,{access:"download"})).text(),Ie=14e3,ze=Ne.length>Ie?`${Ne.slice(0,Math.max(0,Ie-1))}…`:Ne;aa(ze)}catch(ue){gc(String((ue==null?void 0:ue.message)||ue||"Preview failed"))}finally{to(!1)}}async function Cl(h){const j=String((h==null?void 0:h.run_id)||"").trim(),$=String((h==null?void 0:h.artifact_id)||"").trim();if(!j||!$){Sn("Artifact download needs a run id",3);return}const M=U_(h)||$;try{const U=await Le.download_run_artifact_content(j,$,{access:"preview"});Xu(U,t_(M)),Sn("Downloaded artifact",2)}catch(U){Sn(String((U==null?void 0:U.message)||U||"Download failed"),3)}}async function $l(h){const j=String((h==null?void 0:h.run_id)||"").trim(),$=String((h==null?void 0:h.artifact_id)||"").trim();if(!j||!$){Sn("Artifact preview needs a run id",3);return}const M=U_(h),U=String((h==null?void 0:h.content_type)||"").trim().toLowerCase(),W=Dd(h),Z=W==="text"&&zd(h,"")==="html"?window.open("about:blank","_blank"):null;if(Z&&(Z.document.write('<!doctype html><title>Loading artifact preview...</title><body style="font:14px system-ui;padding:24px">Loading artifact preview...</body>'),Z.document.close()),$a(M||$),ai(""),gr(""),Mi(W),li(h),Bs(!0),vn&&(URL.revokeObjectURL(vn),Or("")),W==="binary"){ai(`(Binary artifact: ${U||"unknown"}; download to view.)`);return}if(W==="text"&&typeof h.size_bytes=="number"&&h.size_bytes>15e5){ai(`(Text artifact is ${h.size_bytes.toLocaleString()} bytes; download to view.)`);return}Eo(!0);try{const ke=await Le.download_run_artifact_content(j,$,{access:"preview"});if(W==="text"){const me=await ke.text(),ue=zd(h,me);if(ue==="html"){const Ie=new Blob([me],{type:U.includes("html")?String(h.content_type||"text/html"):"text/html;charset=utf-8"}),ze=URL.createObjectURL(Ie),Ge=Z||window.open("about:blank","_blank");if(Ge){Ge.location.href=ze,Bs(!1),li(null),ai(""),Eo(!1),setTimeout(()=>URL.revokeObjectURL(ze),300*1e3),Sn("Opened HTML preview",2);return}URL.revokeObjectURL(ze),gr("Browser blocked opening the HTML page. Showing highlighted source instead.")}else Z&&Z.close();const Ne=ue==="json"?15e5:ue==="markdown"?25e4:ue==="html"?3e5:22e3;ai(me.length>Ne&&ue!=="text"?`${Kl(h.size_bytes??me.length)} ${ue.toUpperCase()} artifact. Download to inspect it.`:me.length>Ne?`${me.slice(0,Math.max(0,Ne-1))}…`:me)}else Z&&Z.close(),Or(URL.createObjectURL(ke))}catch(ke){Z&&Z.close(),gr(String((ke==null?void 0:ke.message)||ke||"Preview failed"))}finally{Eo(!1)}}_.useEffect(()=>()=>{vn&&URL.revokeObjectURL(vn)},[vn]);async function Rf(h){const j=String(h.artifact_id||"").trim(),$=String(h.run_id||"").trim(),M=Dd(h);if(!$||!j)return{artifact_id:j,kind:M,render_kind:"",text:"Preview needs artifact run metadata.",url:"",loading:!1,error:""};if(M==="binary")return{artifact_id:j,kind:M,render_kind:"",text:`Preview unavailable for ${h.content_type||h.modality||"this artifact"}. Download to inspect it.`,url:"",loading:!1,error:""};if(M==="text"&&typeof h.size_bytes=="number"&&h.size_bytes>5e5)return{artifact_id:j,kind:M,render_kind:"",text:`${Kl(h.size_bytes)} text artifact. Use Preview for a larger view or Download to inspect locally.`,url:"",loading:!1,error:""};try{const U=await Le.download_run_artifact_content($,j,{access:"preview"});if(M==="text"){const W=await U.text(),V=zd(h,W),Z=V==="json"?5e5:V==="markdown"?12e4:V==="html"?3e5:8e3;return{artifact_id:j,kind:M,render_kind:V,text:W.length>Z&&V!=="text"?`${Kl(h.size_bytes??W.length)} ${V.toUpperCase()} artifact. Use Larger preview or Download to inspect it.`:W.length>Z?`${W.slice(0,Math.max(0,Z-1))}…`:W,url:"",loading:!1,error:""}}return{artifact_id:j,kind:M,render_kind:"",text:"",url:URL.createObjectURL(U),loading:!1,error:""}}catch(U){return{artifact_id:j,kind:M,render_kind:"",text:"",url:"",loading:!1,error:String((U==null?void 0:U.message)||U||"Preview failed")}}}async function Zu(h){if(so.url&&URL.revokeObjectURL(so.url),!h){Sc(wc());return}const j=String(h.artifact_id||"").trim(),$=Dd(h);Sc({artifact_id:j,kind:$,render_kind:"",text:"",url:"",loading:!0,error:""}),Sc(await Rf(h))}_.useEffect(()=>{Ju()},[Le,k,ks]);function Gt(h){const j=String(h.id||"").trim()||zr();xu($=>[{...h,id:j},...$].slice(0,800))}function Sn(h,j){rs(h),ji.current&&window.clearTimeout(ji.current),il(!1),window.requestAnimationFrame(()=>il(!0)),ji.current=window.setTimeout(()=>{il(!1),ji.current=null},1500),fr.current&&(window.clearTimeout(fr.current),fr.current=null),j>0&&(fr.current=window.setTimeout(()=>{rs(""),fr.current=null},Math.max(1,j)*1e3))}function Xr(h,j){const $=String(h||"").trim(),M=String(j||"").trim();if(!M)return"";const U=$?String(ha.current[$]||"").trim():"";return U?`${U}::${M}`:M}function Lc(h,j,$){const M=String(h||"").trim(),U=String(j||"").trim(),W=String($||"").trim();if(!M||!U||!W)return;const V=Xr(M,U);V&&(ha.current[W]=V,_a.current[W]=M,Tu.current[W]={parent_run_id:M,parent_node_id:U},ki.current.has(W)||(ki.current.add(W),ml(Z=>Z.includes(W)?Z:[...Z,W])))}function Oa(h){const j=String(h||"").trim();if(!j)return;const $=Date.now(),M=ti.current;ti.current=j,dl($),fl(U=>{const W={};for(const[me,ue]of Object.entries(U))typeof ue=="number"&&ue>$&&(W[me]=ue);W[j]=Math.max(W[j]||0,$+2e3),M&&M!==j&&(W[M]=Math.max(W[M]||0,$+2e3));const V=Object.keys(W);if(V.length<=200)return W;const Z=V.sort((me,ue)=>(W[ue]||0)-(W[me]||0)).slice(0,200),ke={};for(const me of Z)ke[me]=W[me]||0;return ke}),yc(U=>{if(typeof U[j]=="number")return U;const W={...U,[j]:$};if(ma.current.push(j),ma.current.length>8e3){const V=ma.current.splice(0,1500);for(const Z of V)delete W[Z]}return W}),Yn.current&&window.clearTimeout(Yn.current),Yn.current=window.setTimeout(()=>{const U=Date.now();fl(W=>{const V={};for(const[Z,ke]of Object.entries(W))typeof ke=="number"&&ke>U&&(V[Z]=ke);return V}),dl(U),Yn.current=null},2200)}function Qu(h,j){var Be,tn,Je;const $=String(j||"").trim()||d.trim();jr.current=h.cursor,(Be=Zr.current)==null||Be.push({cursor:h.cursor,record:h.record}),$&&Ds.current.add(`${$}:${h.cursor}`);const M=mm(h.record),U=M&&M.name?Ld(M.name):"",W=h.record,V=typeof(W==null?void 0:W.node_id)=="string"?W.node_id:"",Z=typeof(W==null?void 0:W.status)=="string"?W.status:"",ke=typeof((tn=W==null?void 0:W.effect)==null?void 0:tn.type)=="string"?W.effect.type:"",me=typeof(W==null?void 0:W.run_id)=="string"?W.run_id:"",ue=me||$;if(U==="abstract.status"&&ue===$){const{text:Ue,duration:vt}=Kc(M==null?void 0:M.payload);Sn(Ue,vt)}const Ne=V?Xr(ue,V):"";if(Z==="waiting"){const Ue=Bi(W);if(String((Ue==null?void 0:Ue.reason)||"").trim()==="subworkflow"){const wn=typeof((Je=Ue==null?void 0:Ue.details)==null?void 0:Je.sub_run_id)=="string"?String(Ue.details.sub_run_id):"";wn&&V&&Lc(ue,V,wn)}}if(V&&(Oa(Xr(ue,V)),Z==="waiting"||Z==="running")){const Ue=Xr(ue,V);Ue&&(ti.current=Ue,jo(Ue))}let Ie="step",ze=Ne||V||"(node?)",Ge="";if(M&&M.name&&$_(M.name))Ie=U==="abstract.message"?"message":"event",ze=U||M.name,Ge=ut(U==="abstract.steer_seen"?C_(M==null?void 0:M.payload):Kc(M==null?void 0:M.payload).text);else if(W!=null&&W.error)Ie="error",ze="error",Ge=ut(Tr(W.error,360));else if(Z==="waiting"){const Ue=Bi(W),vt=String((Ue==null?void 0:Ue.reason)||"").trim();Ge=ut(vt?`waiting • ${vt}`:"waiting")}else W!=null&&W.result?Ge=ut(Tr(W.result,360)):ke?Ge=ut(ke):Ge=ut(Am(W));Gt({id:`step:${me||$||"?"}:${h.cursor}`,ts:String((W==null?void 0:W.ended_at)||(W==null?void 0:W.started_at)||wt()),kind:Ie,title:ze,preview:Ge,data:W,cursor:h.cursor,run_id:me||$||void 0,node_id:Ne||V,status:Z,effect_type:ke,emit_name:U||(M==null?void 0:M.name)||void 0})}function Lf(h,j){var Ge,Be,tn;Is.current=Math.max(Is.current,j.cursor);const $=`${h}:${j.cursor}`;if(!!Ds.current.has($))return;Ds.current.add($),(Ge=Wr.current)==null||Ge.push({run_id:h,cursor:j.cursor,record:j.record});const U=mm(j.record),W=U&&U.name?Ld(U.name):"",V=j.record,Z=typeof(V==null?void 0:V.node_id)=="string"?V.node_id:"",ke=Z?Xr(h,Z):"",me=typeof(V==null?void 0:V.status)=="string"?V.status:"",ue=typeof((Be=V==null?void 0:V.effect)==null?void 0:Be.type)=="string"?V.effect.type:"";if(me==="waiting"){const Je=Bi(V);if(String((Je==null?void 0:Je.reason)||"").trim()==="subworkflow"){const vt=typeof((tn=Je==null?void 0:Je.details)==null?void 0:tn.sub_run_id)=="string"?String(Je.details.sub_run_id):"";vt&&Z&&Lc(h,Z,vt),vt&&ri.current.trim()===String(h||"").trim()&&(ri.current=vt,no(vt))}}if(Z&&(Oa(Xr(h,Z)),me==="waiting"||me==="running")){const Je=Xr(h,Z);Je&&(ti.current=Je,jo(Je))}if((me==="completed"||me==="failed")&&ri.current.trim()===String(h||"").trim()){const Je=String(_a.current[String(h||"").trim()]||"").trim();Je&&Je!==d.trim()?(ri.current=Je,no(Je)):(ri.current="",no(""))}if(W==="abstract.status"&&h===d.trim()){const{text:Je,duration:Ue}=Kc(U==null?void 0:U.payload);Sn(Je,Ue)}let Ne="step",Ie=ke||Z||"(node?)",ze="";if(U&&U.name&&$_(U.name))Ne=W==="abstract.message"?"message":"event",Ie=`subrun • ${W||U.name}`,ze=ut(W==="abstract.steer_seen"?C_(U==null?void 0:U.payload):Kc(U==null?void 0:U.payload).text);else if(V!=null&&V.error)Ne="error",Ie="error",ze=ut(Tr(V.error,360));else if(me==="waiting"){const Je=Bi(V),Ue=String((Je==null?void 0:Je.reason)||"").trim();ze=ut(Ue?`waiting • ${Ue}`:"waiting")}else V!=null&&V.result?ze=ut(Tr(V.result,360)):ue?ze=ut(ue):ze=ut(Am(V));Gt({id:`step:${h}:${j.cursor}`,ts:String((V==null?void 0:V.ended_at)||(V==null?void 0:V.started_at)||wt()),kind:Ne,title:Ie,preview:ze,data:V,cursor:j.cursor,run_id:h,node_id:ke||Z,status:me,effect_type:ue,emit_name:W||(U==null?void 0:U.name)||""})}function Of(h,j){var Be,tn,Je;const $=String(h||"").trim();if(!$)return;const M=`${$}:${j.cursor}`;if(!!Ds.current.has(M))return;Ds.current.add(M),(Be=Wr.current)==null||Be.push({run_id:$,cursor:j.cursor,record:j.record});const W=mm(j.record),V=W&&W.name?Ld(W.name):"",Z=j.record,ke=typeof(Z==null?void 0:Z.node_id)=="string"?Z.node_id:"",me=ke?Xr($,ke):"",ue=typeof(Z==null?void 0:Z.status)=="string"?Z.status:"",Ne=typeof((tn=Z==null?void 0:Z.effect)==null?void 0:tn.type)=="string"?Z.effect.type:"";if(ue==="waiting"){const Ue=Bi(Z);if(String((Ue==null?void 0:Ue.reason)||"").trim()==="subworkflow"){const wn=typeof((Je=Ue==null?void 0:Ue.details)==null?void 0:Je.sub_run_id)=="string"?String(Ue.details.sub_run_id):"";wn&&ke&&Lc($,ke,wn)}}if(ke&&(Oa(Xr($,ke)),ue==="waiting"||ue==="running")){const Ue=Xr($,ke);Ue&&(ti.current=Ue,jo(Ue))}if(V==="abstract.status"&&$===d.trim()){const{text:Ue,duration:vt}=Kc(W==null?void 0:W.payload);Sn(Ue,vt)}let Ie="step",ze=me||ke||"(node?)",Ge="";if(W&&W.name&&$_(W.name))Ie=V==="abstract.message"?"message":"event",ze=`subrun • ${V||W.name}`,Ge=ut(V==="abstract.steer_seen"?C_(W==null?void 0:W.payload):Kc(W==null?void 0:W.payload).text);else if(Z!=null&&Z.error)Ie="error",ze="error",Ge=ut(Tr(Z.error,360));else if(ue==="waiting"){const Ue=Bi(Z),vt=String((Ue==null?void 0:Ue.reason)||"").trim();Ge=ut(vt?`waiting • ${vt}`:"waiting")}else Z!=null&&Z.result?Ge=ut(Tr(Z.result,360)):Ne?Ge=ut(Ne):Ge=ut(Am(Z));Gt({id:`step:${$}:${j.cursor}`,ts:String((Z==null?void 0:Z.ended_at)||(Z==null?void 0:Z.started_at)||wt()),kind:Ie,title:ze,preview:Ge,data:Z,cursor:j.cursor,run_id:$,node_id:me||ke,status:ue,effect_type:Ne,emit_name:V||(W==null?void 0:W.name)||""})}async function Pf(h,j){var M,U;let $=j.after;for(;;){if((M=j.signal)!=null&&M.aborted)return $;const W=await Le.get_ledger(h,{after:$,limit:200,signal:j.signal});if((U=j.signal)!=null&&U.aborted)return $;const V=Array.isArray(W.items)?W.items:[];if(!V.length)return jr.current=$,$;const Z=$;for(let ke=0;ke<V.length;ke++){const me=V[ke];Qu({cursor:Z+ke+1,record:me},h)}$=typeof W.next_after=="number"?W.next_after:$}}async function Pa(h){var W,V,Z,ke;const j=String(h||"").trim();Jt(""),Ut(!0),Mt(!1),(W=Zr.current)==null||W.reset(),(V=Wr.current)==null||V.reset(),Gi.current={scanned:0,found:null},er([]),jr.current=0,Ur([]),Ds.current=new Set,xu([]),bu({}),af({}),dc("steps"),Cu(""),rs(""),Vn(null),Ls(""),wo(""),oa([]),cl(""),jo(""),ti.current="",fl({}),yc({}),ma.current=[],dl(Date.now()),ha.current=j?{[j]:""}:{},_a.current={},Tu.current={},ki.current=new Set,ml([]),ga.current="",ri.current="",no(""),So.current={},Yn.current&&window.clearTimeout(Yn.current),Yn.current=null,Gr.current&&window.clearTimeout(Gr.current),Gr.current=null,ni.current&&ni.current.abort(),_r.current&&_r.current.abort(),_r.current=null,Is.current=0,Ci("");const $=new AbortController;ni.current=$;let M=!1;try{let me="",ue="";try{const Ne=await Le.get_run(j);Vn(Ne);const Ie=typeof(Ne==null?void 0:Ne.workflow_id)=="string"?String(Ne.workflow_id):"",ze=Zy(Ie);ze&&(me=ze.bundle_id,ue=ze.flow_id)}catch{}try{const Ne=await Le.get_run_input_data(j);typeof(Ne==null?void 0:Ne.bundle_id)=="string"&&(me=String(Ne.bundle_id||"").trim()||me),typeof(Ne==null?void 0:Ne.flow_id)=="string"&&(ue=String(Ne.flow_id||"").trim()||ue);const Ie=Ne&&typeof Ne.input_data=="object"&&Ne.input_data&&!Array.isArray(Ne.input_data)?Ne.input_data:null;Ie&&z(JSON.stringify(Ie,null,2));const ze=Ne==null?void 0:Ne.workspace,Ge=typeof(ze==null?void 0:ze.workspace_root)=="string"?String(ze.workspace_root).trim():"";wo(Ge)}catch{wo("")}(async()=>{$u(!0),cl("");try{const Ne=await Le.list_run_artifacts(j,{limit:200}),Ie=Array.isArray(Ne==null?void 0:Ne.items)?Ne.items:[];$.signal.aborted||oa(Ie)}catch(Ne){$.signal.aborted||(oa([]),cl(String((Ne==null?void 0:Ne.message)||Ne||"artifact listing failed")))}finally{$.signal.aborted||$u(!1)}})(),me&&ue&&(R(me),N(ue),la(ue),await Xn(me)),await Pf(j,{after:0,signal:$.signal});try{const Ne=await Le.get_run_history_bundle(j,{include_subruns:!0,include_session:!1,ledger_mode:"tail",ledger_max_items:1}),Ie=Ne&&typeof Ne=="object"?Ne.ledgers:null,Ge=(Ie&&typeof Ie=="object"?Object.keys(Ie):[]).map(Be=>String(Be||"").trim()).filter(Boolean).filter(Be=>Be!==j);if(Ge.length){for(const Be of Ge)ki.current.add(Be);ml(Be=>Array.from(new Set([...Be,...Ge])));try{const Be=typeof((Z=Ie==null?void 0:Ie[j])==null?void 0:Z.total)=="number"?Number(Ie[j].total):0;let tn="",Je=-1;for(const Ue of Ge){const vt=typeof((ke=Ie==null?void 0:Ie[Ue])==null?void 0:ke.total)=="number"?Number(Ie[Ue].total):0;vt>Je&&(tn=Ue,Je=vt)}tn&&Je>Math.max(Be*3,Be+20)&&(ri.current=tn,no(tn))}catch{}}}catch{}Mt(!0),Gt({ts:wt(),kind:"info",title:`Attached to run ${j}`,data:{run_id:j}}),M=!0}catch(me){const ue=String((me==null?void 0:me.message)||me||"unknown error");Jt(ue),Gt({ts:wt(),kind:"error",title:"Connection error",preview:ut(ue),data:{error:ue}}),Mt(!1)}finally{Ut(!1)}if(!M||$.signal.aborted)return;(async()=>{let me=250;for(;!$.signal.aborted;){try{const ue=await Pf(j,{after:jr.current,signal:$.signal});await Le.stream_ledger(j,{after:ue,on_step:Ne=>Qu(Ne,j),signal:$.signal})}catch(ue){if($.signal.aborted)break;const Ne=String((ue==null?void 0:ue.message)||ue||"stream error");Gt({ts:wt(),kind:"error",title:"Ledger stream error (will retry)",preview:ut(Ne),data:{error:Ne}})}if($.signal.aborted)break;await new Promise(ue=>setTimeout(ue,me)),me=Math.min(5e3,Math.floor(me*1.6))}})()}async function kh(){const h=Hs,j=(h==null?void 0:h.kind)==="bundle"?h.flow_id:(h==null?void 0:h.kind)==="default"?"@default":"",$=(h==null?void 0:h.kind)==="bundle"?h.bundle_id:"";if(!h){const M="Select a workflow first (Launch → pick a workflow).";return Jt(M),M}Jt(""),Ut(!0);try{let M={};const U=T.trim();if(U)try{if(M=JSON.parse(U),typeof M!="object"||M===null||Array.isArray(M))throw new Error("input_data must be a JSON object")}catch(ue){const Ne=`Invalid input_data JSON: ${String((ue==null?void 0:ue.message)||ue)}`;return Jt(Ne),Ne}for(const[ue,Ne]of Object.entries(M)){if(typeof Ne!="string")continue;const Ie=Ne.trim();Ie?M[ue]=Ie:delete M[ue]}const W=(ls||[]).find(ue=>ue&&typeof ue=="object"&&ue.id==="prompt"),V=W&&typeof W=="object"&&Object.prototype.hasOwnProperty.call(W,"default"),Z=M==null?void 0:M.prompt,ke=typeof Z=="string"?Z.trim():"";if(W&&!V&&!ke){const ue="Missing required input_data.prompt";return Jt(ue),ue}const me=await Le.start_run(j,M,{...$?{bundle_id:$}:{},...h.kind==="default"?{interface:h.interface}:{},session_id:String(H||"").trim()||null});return g(me),m(me),Ki(""),await Pa(me),ir(),null}catch(M){const U=String((M==null?void 0:M.message)||M||"start failed");return Jt(U),U}finally{Ut(!1)}}async function Nh(){if(Ct([]),gt(null),!he.available){Ct([he.reason]);return}const h=rS(Oe,{choice:Hs,bundle_ref_for:j=>{var $;return(($=sn.find(M=>M.bundle_id===j))==null?void 0:$.bundle_ref)||""},input_data:st},ot.current);if(!h.ok){Ct(h.errors);return}nt(!0);try{const j=await Le.automations_client().createAutomation(h.body);ot.current.reset(),Re([]),He(F_),Gt({ts:wt(),kind:"info",title:"Automation created",preview:ut(`${h.body.title} · ${j.automation_id}`)}),t("automations"),await Tn.refresh(),await Tn.select(j.automation_id)}catch(j){const $=(j&&typeof j=="object"&&typeof j.code=="string"?j:null)||{status:0,code:"client_error",message:String((j==null?void 0:j.message)||j||"Create failed")};gt($)}finally{nt(!1)}}async function If(){if(Ki(""),de==="automate"){await Nh();return}const h=await kh();if(h){Ki(h);return}Os("overview"),t("observe")}async function ed(h){if(Tt("skills",void 0),!!h){if(h.kind==="default"){Ee(h.interface),R(""),N(""),G(null);return}Ee(""),R(h.bundle_id),N(h.flow_id),la(h.flow_id),await Xn(h.bundle_id)}}async function td(h){const[j,$]=await Promise.all([Le.get_run(h),Le.get_run_input_data(h)]),M=dS(j,$);await ed(M.choice),z(JSON.stringify(M.input_data,null,2)),He(M.form),Re([`Recreating the legacy schedule ${Et(h,14)} as an automation. The legacy schedule keeps running until you suspend it.`,...M.notes]),ot.current.reset(),xe("automate"),t("launch")}async function ui(h,j){const $=String(h||"").trim();if(!$)return;if(Ce){Sn(`Still attaching — retry in a moment (${Et($,14)})`,2500);return}Jt("");const M=String((j==null?void 0:j.root_run_id)||$).trim()||$;g(M),m($),await Pa($)}_.useEffect(()=>{const h=String(v||"").trim();if(!h)return;let j=!1;return(async()=>{try{if(k||await jl({open_modal_if_needed:!0}),j)return;Os("overview"),t("observe"),await ui(h)}catch($){j||Jt(String(($==null?void 0:$.message)||$||"Failed to attach run from URL"))}finally{j||w("")}})(),()=>{j=!0}},[v]);function Df(){var h,j;ni.current&&ni.current.abort(),ni.current=null,_r.current&&_r.current.abort(),_r.current=null,Is.current=0,Ci(""),m(""),g(""),ha.current={},_a.current={},Tu.current={},ki.current=new Set,ml([]),ga.current="",ri.current="",no(""),So.current={},Ls(""),Yn.current&&window.clearTimeout(Yn.current),Yn.current=null,Gr.current&&window.clearTimeout(Gr.current),Gr.current=null,Mt(!1),Ut(!1),nn(!1),jr.current=0,(h=Zr.current)==null||h.reset(),(j=Wr.current)==null||j.reset(),Gi.current={scanned:0,found:null},er([]),Ur([]),Ds.current=new Set,Vn(null),xu([]),bu({}),jo(""),ti.current="",fl({}),yc({}),ma.current=[],dl(Date.now()),Sn("",-1),Jt(""),va(!1),wa(""),Fe([]),ss(""),Lr(""),re(!1),ct(!1),Lt(""),Dt(""),hn(""),mr([]),Qs(!1),ra(""),ac(""),lc(!1),po("")}_.useEffect(()=>{Fe([]),ss(""),Lr(""),re(!1),ct(!1),Lt(""),Dt(""),hn(""),mr([]),Qs(!1),ra(""),ac(""),lc(!1),po("")},[d]),_.useEffect(()=>{hr==="chat"&&d.trim()&&k&&El()},[hr,d,k,ye==null?void 0:ye.workflow_id]);async function zf(h,j,$){const M=String(h||"").trim();if(!M)return Jt("Missing run_id"),"Missing run_id";Jt("");try{const U={},W=String(($==null?void 0:$.reason)||"").trim();W&&(U.reason=W),await Le.submit_command({command_id:zr(),run_id:M,type:j,payload:U,client_id:"web_pwa"}),Gt({ts:wt(),kind:"info",title:`${j} submitted`,preview:W?`reason: ${W}`:"",data:{run_id:M,type:j,reason:W}});try{if(M===d.trim()){const V=await Le.get_run(M);Vn(V)}}catch{}return ir(Le,{force:!0}),window.setTimeout(()=>void ir(Le,{force:!0}),900),window.setTimeout(()=>void ir(Le,{force:!0}),2400),null}catch(U){const W=String((U==null?void 0:U.message)||U||`${j} failed`);return Jt(W),W}}async function Ff(h,j){return zf(d.trim(),h,j)}async function Ns(h,j="Stopped from AbstractObserver"){const $=String(h||"").trim();if(!$||!window.confirm(`Cancel run ${Et($,24)}?`))return;await zf($,"cancel",{reason:j})||Sn("Cancel submitted",2)}async function nd(){var $;const h=d.trim();if(!h){Jt("Select a run first.");return}if(!k){Jt("Connect to the gateway first.");return}if(St)return;const j=String((($=ye==null?void 0:ye.waiting)==null?void 0:$.reason)||"").trim().toLowerCase()||String(pr||"").trim().toLowerCase();if(!cs||qs||Oi||Dn.toLowerCase()!=="waiting"||j!=="until"){Jt("This run is not a scheduled wait that can be triggered now.");return}Jt(""),nn(!0);try{const M={payload:{mode:"run_now",requested_at:wt()}},U=String($r||"").trim();U&&(M.wait_key=U),await Le.submit_command({command_id:zr(),run_id:h,type:"resume",payload:M,client_id:"web_pwa"}),Gt({ts:wt(),kind:"info",title:"Scheduled run triggered",preview:ut(`run ${h}`),data:{run_id:h,until:On||null}});try{const W=await Le.get_run(h);Vn(W)}catch{}}catch(M){Jt(String((M==null?void 0:M.message)||M||"Failed to trigger scheduled run"))}finally{nn(!1)}}async function Oc(h){const j=d.trim();if(!j)return Jt("Missing run_id"),"Missing run_id";if(ts)return"Schedule update already in progress";const $=String(h.interval||"").trim();if(!/^\s*(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)\s*$/i.test($)){const U="Invalid interval (expected like '20m', '1h', '0.5s', '250ms')";return $n(U),U}$n(""),Jt(""),Ji(!0),Ut(!0);try{await Le.submit_command({command_id:zr(),run_id:j,type:"update_schedule",payload:{interval:$,apply_immediately:h.apply_immediately!==!1},client_id:"web_pwa"}),Gt({ts:wt(),kind:"info",title:"Schedule updated",preview:ut(`interval: ${$}`),data:{interval:$},run_id:j});try{const U=await Le.get_run(j);Vn(U)}catch{}return null}catch(U){const W=String((U==null?void 0:U.message)||U||"update_schedule failed");return $n(W),Jt(W),W}finally{Ut(!1),Ji(!1)}}async function Bf(h){const j=d.trim();if(!j)return Jt("Missing run_id"),"Missing run_id";if(ns)return"Compaction already in progress";const $=typeof(h==null?void 0:h.preserve_recent)=="number"?h.preserve_recent:rr,M=Math.max(0,Math.min(500,Math.floor(Number.isFinite($)?$:6))),U=(h==null?void 0:h.compression_mode)||dr,W=String((h==null?void 0:h.focus)??Zi??"").trim();wi(""),Jt(""),Sr(!0),Ut(!0);try{const V={preserve_recent:M,compression_mode:U};return W&&(V.focus=W),await Le.submit_command({command_id:zr(),run_id:j,type:"compact_memory",payload:V,client_id:"web_pwa"}),Gt({ts:wt(),kind:"info",title:"Compaction requested",preview:ut(`mode: ${U} • preserve_recent: ${M}`),data:V,run_id:j}),null}catch(V){const Z=String((V==null?void 0:V.message)||V||"compact_memory failed");return wi(Z),Jt(Z),Z}finally{Ut(!1),Sr(!1)}}async function Uf(){const h=d.trim();if(!h){wa("Missing run_id");return}if(!Ru){wa(""),va(!0);try{const j=n.maintenance_ai_provider.trim(),$=n.maintenance_ai_model.trim();await Le.generate_run_summary(h,{provider:j||void 0,model:$||void 0,include_subruns:!0}),Gt({ts:wt(),kind:"info",title:"Summary generation requested",preview:ut(`run ${h}`)})}catch(j){wa(String((j==null?void 0:j.message)||j||"Failed to generate summary"))}finally{va(!1)}}}async function Wf(){const h=d.trim();if(!h){Lr("Select a run first.");return}if(!k){Lr("Connect to the gateway first.");return}const j=oc.trim();if(!j||B)return;if(Un.voice_ptt_busy){_o("Wait for transcription to finish.");return}Lr(""),_o(""),re(!0);const M={id:`local:${zr()}`,role:"user",content:j,ts:wt()};Fe(U=>[...U,M]),ss("");try{const U=[...je,M].slice(-20).map(ue=>({role:ue.role,content:ue.content})),W=n.maintenance_ai_provider.trim(),V=n.maintenance_ai_model.trim(),Z=await Le.run_chat(h,{provider:W||void 0,model:V||void 0,include_subruns:!0,messages:U}),ke=String((Z==null?void 0:Z.answer)||"").trim()||"(empty response)",me=String((Z==null?void 0:Z.generated_at)||"").trim()||wt();Fe(ue=>[...ue,{id:`local:${zr()}`,role:"assistant",content:ke,ts:me}])}catch(U){Lr(String((U==null?void 0:U.message)||U||"Chat failed")),Fe(W=>[...W,{id:`local:${zr()}`,role:"assistant",content:"(error: failed to generate answer)",ts:wt()}])}finally{re(!1)}}function rd(h){const j=String(h.id||h.ts||"").trim(),$=String(h.content||"").trim();!j||!$||(_o(""),Un.toggle_tts(j,$))}function Ia(h){const j=String(h.id||h.ts||"").trim(),$=Un.tts_playback;return!j||!$.key||$.key!==j?"idle":$.status}function Pc(h){if(!je.length)return;const j=d.trim(),$=j?`Run ${j}`:"Chat",M=Pb(je.map(U=>({role:U.role,content:U.content,ts:U.ts})),{heading:$});if(h==="download"){const U=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-"),W=`abstractobserver-chat-${t_(j||"run")}-${U}.md`;Ib({filename:W,text:M,mime:"text/markdown;charset=utf-8"});return}(async()=>{const U=await nc(M);Se(U?"copied":"failed"),window.setTimeout(()=>Se("idle"),900)})()}async function El(){const h=typeof(ye==null?void 0:ye.workflow_id)=="string"?String(ye.workflow_id).trim():"";if(!h){mr([]);return}if(k&&!Nr){ra(""),Qs(!0);try{const j=await Le.list_runs({limit:200,workflow_id:h,root_only:!0}),$=Array.isArray(j==null?void 0:j.items)?j.items:[],M=[];for(const me of $){const ue=typeof(me==null?void 0:me.run_id)=="string"?String(me.run_id).trim():"";if(!ue)continue;const Ne=typeof(me==null?void 0:me.ledger_len)=="number"?Number(me.ledger_len):0;M.push({run_id:ue,ledger_len:Number.isFinite(Ne)?Ne:0})}if(!M.length){mr([]);return}const U=400,W=M.map(me=>({run_id:me.run_id,after:Math.max(0,(me.ledger_len||0)-U)})),V=await Le.get_ledger_batch({runs:W,limit:U}),Z=[],ke=new Set;for(const me of M){const ue=V!=null&&V.runs&&typeof V.runs=="object"?V.runs[me.run_id]:null,Ne=Array.isArray(ue==null?void 0:ue.items)?ue.items:[];for(const Ie of Ne){const ze=Ie==null?void 0:Ie.effect;if(!ze||typeof ze!="object"||String(ze.type||"")!=="emit_event")continue;const Ge=ze.payload;if(!Ge||typeof Ge!="object"||String(Ge.name||"")!=="abstract.chat.thread")continue;const Be=Ge.payload;if(!Be||typeof Be!="object")continue;const tn=typeof Be.thread_id=="string"?String(Be.thread_id).trim():"";if(!tn||ke.has(tn))continue;ke.add(tn);const Je=typeof Be.created_at=="string"?String(Be.created_at):"",Ue=typeof Be.title=="string"?String(Be.title):"",vt=typeof Be.workflow_id=="string"?String(Be.workflow_id):h,wn=typeof Be.run_id=="string"?String(Be.run_id):me.run_id,En=typeof Be.provider=="string"?String(Be.provider):"",Dr=typeof Be.model=="string"?String(Be.model):"",ms=typeof Be.message_count=="number"?Number(Be.message_count):null,Ys=Be.chat_artifact,Ar=Ys&&typeof Ys=="object"&&typeof Ys.$artifact=="string"?String(Ys.$artifact):"";Ar&&Z.push({thread_id:tn,created_at:Je,title:Ue||`Chat ${tn.slice(0,8)}`,run_id:wn,workflow_id:vt,message_count:ms,provider:En,model:Dr,artifact_id:Ar})}}Z.sort((me,ue)=>String(ue.created_at||"").localeCompare(String(me.created_at||""))),mr(Z)}catch(j){ra(String((j==null?void 0:j.message)||j||"Failed to load saved discussions"))}finally{Qs(!1)}}}async function Ch(){const h=d.trim();if(!h){Lt("Select a run first.");return}if(!k){Lt("Connect to the gateway first.");return}if(je.length&&!it){Lt(""),ct(!0);try{const j=n.maintenance_ai_provider.trim(),$=n.maintenance_ai_model.trim(),M=await Le.save_chat_thread(h,{provider:j||void 0,model:$||void 0,include_subruns:!0,messages:je.map(V=>({role:V.role,content:V.content,ts:V.ts}))}),U=typeof(M==null?void 0:M.created_at)=="string"?String(M.created_at):wt();Dt(U);try{const V=JSON.stringify(je.map(Z=>({role:Z.role,content:Z.content,ts:Z.ts})));hn(V)}catch{hn("1")}typeof(M==null?void 0:M.thread_id)=="string"&&String(M.thread_id).trim()&&ac(String(M.thread_id).trim());const W=!!(M!=null&&M.duplicate);Sn(W?"Already saved":"Saved discussion",2),await El()}catch(j){Lt(String((j==null?void 0:j.message)||j||"Failed to save discussion"))}finally{ct(!1)}}}async function Hf(){const h=String(yu||"").trim();if(!h)return;const j=_n.find(U=>String(U.thread_id||"").trim()===h)||null;if(!j){po("Saved discussion not found (refresh list).");return}if(!k){po("Connect to the gateway first.");return}if(sa)return;const $=je.length>0,M=(()=>{if(!$)return!1;if(!Kt)return!0;try{return JSON.stringify(je.map(W=>({role:W.role,content:W.content,ts:W.ts})))!==Kt}catch{return!0}})();if(!($&&M&&!window.confirm("Replace the current chat with the selected saved discussion? Unsaved changes will be lost."))){po(""),lc(!0);try{const W=await(await Le.download_run_artifact_content(j.run_id,j.artifact_id)).text(),V=JSON.parse(W),Z=Array.isArray(V==null?void 0:V.messages)?V.messages:[],ke=typeof(V==null?void 0:V.created_at)=="string"?String(V.created_at):String(j.created_at||""),me=[];for(let ue=0;ue<Z.length;ue++){const Ne=Z[ue];if(!Ne||typeof Ne!="object")continue;const Ie=String(Ne.role||"").trim()==="assistant"?"assistant":"user",ze=typeof Ne.content=="string"?String(Ne.content):"";if(!ze.trim())continue;const Ge=typeof Ne.ts=="string"?String(Ne.ts):ke||wt();me.push({id:`thread:${h}:${ue}`,role:Ie,content:ze.trim(),ts:Ge})}Fe(me),ss(""),Lr(""),Lt(""),Dt(ke||"");try{const ue=JSON.stringify(me.map(Ne=>({role:Ne.role,content:Ne.content,ts:Ne.ts})));hn(ue)}catch{hn("1")}Sn("Loaded discussion",2)}catch(U){po(String((U==null?void 0:U.message)||U||"Failed to load saved discussion"))}finally{lc(!1)}}}async function Al(h){const j=d.trim(),$=String((Ot==null?void 0:Ot.wait_key)||"").trim();if(!j||!$){Jt("No active wait to resume");return}if(String((Ot==null?void 0:Ot.reason)||"").trim()==="subworkflow"){Jt("This run is waiting on a subworkflow; attach to the child run instead of resuming manually.");return}Jt(""),nn(!0);try{await Le.submit_command({command_id:zr(),run_id:j,type:"resume",payload:{wait_key:$,payload:h||{}},client_id:"web_pwa"}),Gt({ts:wt(),kind:"info",title:"Resume submitted",preview:ut(`wait_key: ${$}`),data:{wait_key:$,payload:h||{}}}),Ls($);try{const M=await Le.get_run(j);Vn(M)}catch{}ir(Le,{force:!0}),window.setTimeout(()=>void ir(Le,{force:!0}),900),window.setTimeout(()=>void ir(Le,{force:!0}),2400),Gr.current&&window.clearTimeout(Gr.current),Gr.current=window.setTimeout(()=>{Ls(M=>M===$?"":M)},2e3)}catch(M){Jt(String((M==null?void 0:M.message)||M||"resume failed"))}finally{nn(!1)}}async function qf(h){if(!Ma){Jt("No worker configured");return}if(!St){Jt(""),nn(!0);try{const j=[];for(const $ of h){const M=await Ma.call_tool($);j.push(M)}await Al({mode:"executed",results:j})}finally{nn(!1)}}}const io=_.useMemo(()=>gu(Ot),[Ot]),$r=String((Ot==null?void 0:Ot.wait_key)||"").trim(),pr=String((Ot==null?void 0:Ot.reason)||"").trim(),On=typeof(Ot==null?void 0:Ot.until)=="string"?String(Ot.until):"",Dn=typeof(ye==null?void 0:ye.status)=="string"?String(ye.status):"",Oi=!!(ye!=null&&ye.paused),qs=Dn==="completed"||Dn==="failed"||Dn==="cancelled",Vf=pr==="until"&&!!On,Ml=!qs&&gk(Cr)&&(!!$r||Vf),Gf=pr==="user",Tl=pr==="event"?Ld(YA($r)):"",Kf=pr==="event"&&Tl==="abstract.ask",sd=io.length>0,id=Ml&&$r&&(Gf||Kf||sd)&&mo!==$r&&e!=="board",oo=typeof((Wl=Ot==null?void 0:Ot.details)==null?void 0:Wl.sub_run_id)=="string"?String(Ot.details.sub_run_id):"",zo={run_id:d.trim(),workflow_id:typeof(ye==null?void 0:ye.workflow_id)=="string"?String(ye.workflow_id):null,status:Dn,created_at:typeof(ye==null?void 0:ye.created_at)=="string"?String(ye.created_at):null,updated_at:typeof(ye==null?void 0:ye.updated_at)=="string"?String(ye.updated_at):null,session_id:typeof(ye==null?void 0:ye.session_id)=="string"?String(ye.session_id):null,current_node:typeof(ye==null?void 0:ye.current_node)=="string"?String(ye.current_node):null},Ic=kt.slice(-10).map(h=>{var j,$,M,U,W,V;return{cursor:h.cursor,node_id:String(((j=h.record)==null?void 0:j.node_id)||"").trim(),status:String((($=h.record)==null?void 0:$.status)||"").trim(),effect_type:String(((U=(M=h.record)==null?void 0:M.effect)==null?void 0:U.type)||"").trim(),ts:String(((W=h.record)==null?void 0:W.ended_at)||((V=h.record)==null?void 0:V.started_at)||"").trim(),summary:iw(h.record)}}),od=jg(Ot,io),ad=tw(Ot,io),Rl=nw(Ot,st),Da=Rl.text,Yf=Rl.runtime_metadata,za=String((Ot==null?void 0:Ot.prompt)||"").trim(),ld=tk(st,6),Dc=!!(za&&Zv(za)),Vs=!!(za&&!Dc),$h=Vs?"Question from workflow":Da&&Da!==za?"Closest prior user request":"Request context",Xf=sk(st,T),cd=!!T.trim(),Jr=ye!=null&&ye.schedule&&typeof ye.schedule=="object"?ye.schedule:null,Fo=typeof(Jr==null?void 0:Jr.interval)=="string"?String(Jr.interval).trim():"",Ll=typeof(Jr==null?void 0:Jr.share_context)=="boolean"?!!Jr.share_context:null,yr=typeof(Jr==null?void 0:Jr.repeat_count)=="number"?Number(Jr.repeat_count):null,cs=!!(ye!=null&&ye.is_scheduled)||!!Jr,ud=cs&&!!Fo,Ol=cs?Oi?"Resume schedule":"Suspend schedule":Dn==="running"&&!Oi?"Pause":"Resume",vr=cs?Oi?"resume":"pause":Ol==="Pause"?"pause":"resume",Eh=cs?!d.trim()||Ce||St||qs:!d.trim()||Ce||St||qs||vr==="resume"&&!Oi,Xe=cs&&!Oi&&!qs&&!Ce&&!St&&Dn.toLowerCase()==="waiting"&&(String(((Er=ye==null?void 0:ye.waiting)==null?void 0:Er.reason)||"").trim().toLowerCase()==="until"||pr==="until")&&!!String(On||"").trim(),ar=(Di=ye==null?void 0:ye.limits)==null?void 0:Di.tokens,Bo=typeof(ar==null?void 0:ar.pct)=="number"?Number(ar.pct):null,dd=ar==null?void 0:ar.estimated_used,Jf=(ar==null?void 0:ar.max_input_tokens)??(ar==null?void 0:ar.max_tokens),Pl=_.useMemo(()=>{const h=Gi.current;kt.length<h.scanned&&(h.scanned=0,h.found=null);for(let j=h.scanned;j<kt.length;j++){const $=kt[j],M=$==null?void 0:$.record;if(!M)continue;const U=mm(M);if((U&&U.name?Ld(U.name):"")!=="abstract.summary")continue;const V=U!=null&&U.payload&&typeof U.payload=="object"?U.payload:{},Z=typeof(V==null?void 0:V.text)=="string"?String(V.text):"";Z.trim()&&(h.found={cursor:$.cursor,ts:String((M==null?void 0:M.ended_at)||(M==null?void 0:M.started_at)||""),text:Z,provider:typeof(V==null?void 0:V.provider)=="string"?String(V.provider):void 0,model:typeof(V==null?void 0:V.model)=="string"?String(V.model):void 0,generated_at:typeof(V==null?void 0:V.generated_at)=="string"?String(V.generated_at):void 0,source:V==null?void 0:V.source})}return h.scanned=kt.length,h.found},[kt]);_.useEffect(()=>{ri.current=zs.trim()},[zs]),_.useEffect(()=>{const h=d.trim(),j=oo.trim();if(!(ft&&pr==="subworkflow"&&!!j&&j!==h)){ga.current="",zs.trim()&&no("");return}ga.current!==j&&(ga.current=j,ri.current=j,no(j))},[ft,d,pr,oo,zs]),_.useEffect(()=>{Au({})},[S]);const Il=_.useMemo(()=>((Array.isArray(D==null?void 0:D.entrypoints)?D==null?void 0:D.entrypoints:[])||[]).map(j=>String((j==null?void 0:j.flow_id)||"").trim()).filter(Boolean),[D]),Gs=_.useMemo(()=>{const h=String((ye==null?void 0:ye.workflow_id)||"").trim();return ft&&cs?h:""},[ft,cs,ye==null?void 0:ye.workflow_id]),Zf=_.useMemo(()=>{var V;if(!ft||!d.trim()||!Gs.trim())return bs;const h=String((ye==null?void 0:ye.status)||"").trim().toLowerCase(),j=String((ye==null?void 0:ye.current_node)||"").trim();if(h!=="waiting"&&h!=="running"||!j)return bs;const $=Xr(d.trim(),j);if(!$)return bs;const M=String(pr||((V=ye==null?void 0:ye.waiting)==null?void 0:V.reason)||"").trim().toLowerCase(),U=typeof(Cr==null?void 0:Cr.node_id)=="string"?String(Cr.node_id).trim():"",W=typeof(Cr==null?void 0:Cr.status)=="string"?String(Cr.status).trim().toLowerCase():"";return h==="waiting"&&M==="until"||!bs.trim()||(W==="waiting"||W==="running")&&!U?$:bs},[ft,d,Gs,ye==null?void 0:ye.status,ye==null?void 0:ye.current_node,($s=ye==null?void 0:ye.waiting)==null?void 0:$s.reason,pr,bs,Cr]),Qf=_.useMemo(()=>{const h={},j=d.trim(),$=(M,U)=>{if(!U)return;const W=typeof(U==null?void 0:U.node_id)=="string"?String(U.node_id).trim():"";if(!W)return;const V=Xr(M,W);if(!V)return;const Z=String((U==null?void 0:U.ended_at)||(U==null?void 0:U.started_at)||"").trim(),ke=xn(Z);ke!==null&&(h[V]=Math.max(h[V]||0,ke))};for(const M of kt)M&&M.record&&$(j,M.record);for(const M of tr)M&&M.record&&$(String(M.run_id||"").trim(),M.record);return h},[kt,tr,d,Ni]);_.useEffect(()=>{var $;if(!ft||!d.trim()||!Gs.trim())return;const h=String((ye==null?void 0:ye.current_node)||"").trim();!h||String((($=ye==null?void 0:ye.waiting)==null?void 0:$.reason)||"").trim()==="subworkflow"||Oa(Xr(d.trim(),h))},[ft,d,Gs,ye==null?void 0:ye.current_node,(Ir=ye==null?void 0:ye.waiting)==null?void 0:Ir.reason]),_.useEffect(()=>{const h=String((Rn==null?void 0:Rn.flow_id)||"").trim();h&&(xo.trim()||la(h))},[Rn,xo]),_.useEffect(()=>{const h=Gs.trim(),j=S.trim(),$=xo.trim();if(h){let U=!1;return ei(!0),Si(""),Le.get_workflow_flow(h).then(W=>{if(U)return;const V=W==null?void 0:W.flow;ca(V&&typeof V=="object"?V:null)}).catch(W=>{U||(ca(null),Si(String((W==null?void 0:W.message)||W||"Failed to load workflow flow")))}).finally(()=>{U||ei(!1)}),()=>{U=!0}}if(!j||!$){ca(null),Si(""),ei(!1);return}let M=!1;return ei(!0),Si(""),Le.get_bundle_flow(j,$).then(U=>{if(M)return;const W=U==null?void 0:U.flow,V=W&&typeof W=="object"?W:null;ca(V),V&&Au(Z=>({...Z,[$]:V}))}).catch(U=>{M||(ca(null),Si(String((U==null?void 0:U.message)||U||"Failed to load flow")))}).finally(()=>{M||ei(!1)}),()=>{M=!0}},[Gs,S,xo,Le]),_.useEffect(()=>{const h=S.trim();if(!da||!h||!bo)return;let j=!1;const $=3,M=me=>{const ue=Array.isArray(me==null?void 0:me.nodes)?me.nodes:[],Ne=[];for(const Ie of ue){const ze=Ie!=null&&Ie.data&&typeof Ie.data=="object"?Ie.data:{};if(String((ze==null?void 0:ze.nodeType)||(Ie==null?void 0:Ie.type)||"").trim()!=="subflow")continue;const Be=(ze==null?void 0:ze.subflowId)||(ze==null?void 0:ze.flowId),tn=typeof Be=="string"?Be.trim():"";tn&&Ne.push(tn.includes(":")?tn.split(":",2)[1]:tn)}return Ne},U=new Set,W=new Set,V=(me,ue)=>{if(!(!me||ue>=$))for(const Ne of M(me)){const Ie=String(Ne||"").trim();if(!Ie||U.has(Ie))continue;U.add(Ie),W.add(Ie);const ze=ua[Ie];ze&&V(ze,ue+1)}};V(bo,0);const Z=Array.from(W).filter(me=>!ua[me]).slice(0,20);return Z.length?((async()=>{for(const me of Z){if(j)return;try{const ue=await Le.get_bundle_flow(h,me),Ne=ue==null?void 0:ue.flow,Ie=Ne&&typeof Ne=="object"?Ne:null;if(!Ie)continue;Au(ze=>ze[me]?ze:{...ze,[me]:Ie})}catch{}}})(),()=>{j=!0}):void 0},[da,S,bo,ua,Le]);const fd=_.useMemo(()=>{const j=(Array.isArray(D==null?void 0:D.flows)?D==null?void 0:D.flows:[]).map($=>String($||"").trim()).filter(Boolean);return j.length?Array.from(new Set(j)).sort():Array.from(new Set(Il)).sort()},[D,Il]);_.useEffect(()=>{qs&&bs.trim()&&(jo(""),ti.current="")},[qs,d,bs]),_.useEffect(()=>{const h=zs.trim(),j=d.trim();if(!(ft&&!!h&&h!==j)){_r.current&&_r.current.abort(),_r.current=null,Is.current=0,ya&&Ci("");return}if(ya===h)return;_r.current&&_r.current.abort();const M=new AbortController;_r.current=M,Is.current=0,Ci(h),Gt({ts:wt(),kind:"info",title:`Following run ${h} (status/events)`});let U=250;return(async()=>{for(;!M.signal.aborted;){try{await Le.stream_ledger(h,{after:Is.current,on_step:V=>Lf(h,V),signal:M.signal});return}catch(V){if(M.signal.aborted)break;const Z=String((V==null?void 0:V.message)||V||"stream error");Gt({ts:wt(),kind:"error",title:"Child ledger stream error (will retry)",preview:ut(Z),data:{child_run_id:h,error:Z}})}if(M.signal.aborted)break;await new Promise(V=>setTimeout(V,U)),U=Math.min(5e3,Math.floor(U*1.6))}})(),()=>{M.abort()}},[ft,zs,d,Le,ya]),_.useEffect(()=>{if(!ft||!d.trim())return;let h=!1;const j=async()=>{if(!h&&!pa.current&&Ni.length&&!(We.current>Date.now())){pa.current=!0;try{const M=Ni.map(Z=>String(Z||"").trim()).filter(Boolean);if(!M.length)return;const U=M.map(Z=>({run_id:Z,after:Number(So.current[Z]||0)})),W=await Le.get_ledger_batch({runs:U,limit:200}),V=W&&typeof W=="object"?W.runs:{};for(const Z of M){if(h)return;const ke=V&&typeof V=="object"?V[Z]:null,me=Array.isArray(ke==null?void 0:ke.items)?ke.items:[],ue=typeof(ke==null?void 0:ke.next_after)=="number"?ke.next_after:Number(So.current[Z]||0),Ne=Number(So.current[Z]||0);for(let Ie=0;Ie<me.length;Ie++){const ze=me[Ie];Of(Z,{cursor:Ne+Ie+1,record:ze})}So.current[Z]=ue}}catch(M){if(h)return;Gt({ts:wt(),kind:"error",title:"Subrun digest poll failed",preview:ut(String((M==null?void 0:M.message)||M||""))})}finally{pa.current=!1}}};j();const $=window.setInterval(()=>void j(),2e3);return()=>{h=!0,window.clearInterval($),pa.current=!1}},[ft,d,Ni,Le]);const Dl=_.useMemo(()=>yo?wu.filter(QA):wu,[yo,wu]),Cs=_.useMemo(()=>{const h=d.trim(),j=[];for(const $ of kt)!$||!$.record||j.push({run_id:h,cursor:$.cursor,record:$.record});for(const $ of tr)!$||!$.record||j.push({run_id:String($.run_id||"").trim(),cursor:$.cursor,record:$.record});return j},[kt,tr,d]),Gn=_.useMemo(()=>{var j,$,M;const h={};for(const U of Cs){const W=String(U.run_id||((j=U.record)==null?void 0:j.run_id)||"").trim();!W||String(((M=($=U.record)==null?void 0:$.effect)==null?void 0:M.type)||"").trim()!=="llm_call"||(h[W]=(h[W]||0)+1)}return h},[Cs]),Ks=_.useMemo(()=>{const h=zs.trim();if(h)return h;let j="",$=-1;for(const[M,U]of Object.entries(Gn))U>$&&(j=M,$=U);return j||d.trim()},[Gn,zs,d]),Pr=(lf.trim()||Ks).trim(),zc=_.useMemo(()=>{var U;const h=new Set,j=d.trim(),$=zs.trim();j&&h.add(j),$&&h.add($);for(const W of Ni){const V=String(W||"").trim();V&&h.add(V)}for(const W of Cs){const V=String(W.run_id||((U=W.record)==null?void 0:U.run_id)||"").trim();V&&h.add(V)}const M=Array.from(h);return M.sort((W,V)=>j&&W===j&&V!==j?-1:j&&V===j&&W!==j?1:$&&W===$&&V!==$?-1:$&&V===$&&W!==$?1:W<V?-1:W>V?1:0),M},[d,zs,Ni,Cs]),Fc=_.useMemo(()=>Mb(Cs,{run_id:Pr}),[Cs,Pr]),dn=_.useMemo(()=>{const h=d.trim();return h&&(Pn.find(j=>String(j.run_id||"").trim()===h)||$t.find(j=>String(j.run_id||"").trim()===h))||null},[Pn,$t,d]),Uo=String((ye==null?void 0:ye.status)||(dn==null?void 0:dn.status)||"").trim(),di=String(pr||((vd=ye==null?void 0:ye.waiting)==null?void 0:vd.reason)||(dn==null?void 0:dn.waiting_reason)||"").trim().toLowerCase(),em=!!(ye!=null&&ye.is_scheduled||dn!=null&&dn.is_scheduled),md=!!(ye!=null&&ye.paused||dn!=null&&dn.paused),hd=em&&Uo.toLowerCase()==="waiting",_d=hd&&di==="until",gd=xn(On),pd=_d&&gd!==null?$p(gd-Date.now()):"",ao=ZS(ye),Fa=em&&md?"Suspended":hd?"Scheduled":Um({status:Uo,paused:md,stop_reason:ao});async function us(){if(k){bc(!0),bf("");try{const h=ii,j=h==="session"?String(ja||ks||H||"").trim():"",$=h==="run"?String(Bn||d||"").trim():"",M=dk(un),U=is.length?is.join(","):"",W=fk(oi),V=Math.max(0,os)*Cm,Z=await Le.search_artifacts({scope:h,session_id:j||void 0,run_id:$||void 0,query:Fs||void 0,artifact_kind:U||void 0,created_after:M||void 0,include_stats:!0,limit:Cm,offset:V,order_by:W.order_by,order:W.order}),ke=[],me=new Set;for(const Ge of Array.isArray(Z==null?void 0:Z.items)?Z.items:[]){const Be=lk(Ge,"search");!Be||me.has(Be.artifact_id)||(me.add(Be.artifact_id),ke.push(Be))}const ue=Z!=null&&Z.stats&&typeof Z.stats=="object"?Z.stats:{},Ne=Number((ue==null?void 0:ue.total)??(Z==null?void 0:Z.total)??ke.length),Ie=Mp(Z);let ze=Ie;if(is.length)try{const Ge=await Le.search_artifacts({scope:h,session_id:j||void 0,run_id:$||void 0,query:Fs||void 0,created_after:M||void 0,include_stats:!0,limit:1,offset:0,order_by:W.order_by,order:W.order});ze=Mp(Ge)}catch{ze=Ie}wf(Number.isFinite(Ne)?Math.max(0,Ne):ke.length),$i(Number((ue==null?void 0:ue.total_bytes)??(ue==null?void 0:ue.byte_total)??0)||0),No(Ie),xa(ze),Ou(ke),jc(Ge=>{var Be;return Ge&&ke.some(tn=>tn.artifact_id===Ge)?Ge:((Be=ke[0])==null?void 0:Be.artifact_id)||""})}catch(h){bf(String((h==null?void 0:h.message)||h||"Failed to load artifacts")),Ou([]),wf(0),$i(0),No({}),xa({}),jc("")}finally{bc(!1)}}}async function Yt(){if(k){Cc(!0),Fu("");try{const h=await Le.audit_log_tail({max_bytes:16e4}),j=typeof(h==null?void 0:h.bytes)=="number"?Number(h.bytes):0,$=!!(h!=null&&h.truncated);jn(String((h==null?void 0:h.content)||"")),Iu(`${j.toLocaleString()} bytes${$?" (tail)":""}`)}catch(h){Fu(String((h==null?void 0:h.message)||h||"Failed to load audit log")),jn(""),Iu("")}finally{Cc(!1)}}}async function Jn(h){if(!k)return;const j=String(h||ka||Bn||d||"").trim();if(!j){Mo([]),Ec(""),Aa("Select a run in Activity or Artifacts to load its runtime ledger.");return}To(!0),Aa("");try{const $=await Le.get_ledger(j,{after:0,limit:2e3}),M=Array.isArray($.items)?$.items:[];Mo(M.map((W,V)=>({cursor:V+1,record:W})));const U=typeof $.next_after=="number"?Number($.next_after):M.length;Ec(`${M.length.toLocaleString()} record${M.length===1?"":"s"}${U>=2e3?" (first 2,000)":""}`)}catch($){Aa(String(($==null?void 0:$.message)||$||"Failed to load run ledger")),Mo([]),Ec("")}finally{To(!1)}}_.useEffect(()=>{k&&e==="runtime"&&us()},[k,e,ii,ja,Bn,Fs,is,un,oi,os]),_.useEffect(()=>{k&&(Du||Yr||e==="runtime"&&Yt())},[k,e,hr]),_.useEffect(()=>{if(!k||e!=="runtime"||ko!=="logs"||Ao!=="run_ledger"&&Ao!=="provider_calls")return;const h=String(ka||Bn||d||"").trim();h&&Jn(h)},[k,e,ko,Ao,ka,Bn,d]);const gn=_.useMemo(()=>{const h=new Map;for(const j of[...$t,...Pn]){const $=String(j.run_id||"").trim();$&&h.set($,j)}for(const j of Ni){const $=String(j||"").trim();!$||h.has($)||h.set($,{run_id:$,workflow_id:null,status:"",created_at:null,updated_at:null,ledger_len:null,parent_run_id:_a.current[$]||null,session_id:ks||null})}return d.trim()&&!h.has(d.trim())&&h.set(d.trim(),{run_id:d.trim(),workflow_id:typeof(ye==null?void 0:ye.workflow_id)=="string"?String(ye.workflow_id):null,status:typeof(ye==null?void 0:ye.status)=="string"?String(ye.status):"",created_at:typeof(ye==null?void 0:ye.created_at)=="string"?String(ye.created_at):null,updated_at:typeof(ye==null?void 0:ye.updated_at)=="string"?String(ye.updated_at):null,ledger_len:kt.length||null,parent_run_id:typeof(ye==null?void 0:ye.parent_run_id)=="string"?String(ye.parent_run_id):null,session_id:typeof(ye==null?void 0:ye.session_id)=="string"?String(ye.session_id):ks||null}),Array.from(h.values()).sort((j,$)=>{const M=xn(j.updated_at||j.created_at)??0;return(xn($.updated_at||$.created_at)??0)-M})},[Pn,$t,d,ye,kt.length,Ni,ks]),wr=_.useMemo(()=>Uk(gn,{query:uc,filter:ku,group_by:Nu,workflow_label_by_id:Zt,parent_hint:h=>_a.current[h]||""}),[gn,uc,ku,Nu,Zt]),ds=_.useMemo(()=>ow(Cs),[Cs]),Ba=_.useMemo(()=>{const h=[...Cs];return h.sort((j,$)=>{var W,V,Z,ke;const M=xn(((W=j.record)==null?void 0:W.ended_at)||((V=j.record)==null?void 0:V.started_at))??0,U=xn(((Z=$.record)==null?void 0:Z.ended_at)||((ke=$.record)==null?void 0:ke.started_at))??0;return M-U}),h.slice(-240)},[Cs]),kn=_.useMemo(()=>{const h={};for(const j of gn){const $=String(j.run_id||"").trim();$&&(h[$]=j)}return h},[gn]),Wo=String(ka||Bn||d||"").trim(),Pi=Wo&&kn[Wo]||null,zl=String(ja||(Pi==null?void 0:Pi.session_id)||ks||H||"").trim(),Bc=_.useMemo(()=>Lu.map(h=>Hm(h,kn,Zt)),[Lu,kn,Zt]);_.useEffect(()=>{Ca(0)},[Fs,is,un,Bn,oi,Fn,ii,ja]);const Fl=Math.max(1,Math.ceil(vf/Cm)),lr=Math.min(Math.max(0,os),Fl-1);_.useEffect(()=>{os!==lr&&Ca(lr)},[os,lr]);const Ii=_.useMemo(()=>Bc,[Bc,lr]),Ua=_.useMemo(()=>{const h={};for(const j of Ii){const $=Fn==="type"?H_(j,kn,Zt):ck(j,Fn);h[$]||(h[$]=[]),h[$].push(j)}return Object.entries(h).map(([j,$])=>({key:j,items:$})).sort((j,$)=>{var M,U;if(Fn==="time"){const W=xn((M=j.items[0])==null?void 0:M.created_at)??0,V=xn((U=$.items[0])==null?void 0:U.created_at)??0;if(W!==V)return V-W}return j.key.localeCompare($.key)})},[Ii,Fn,kn,Zt]),fs=_.useMemo(()=>{const h=gl.trim();return h?Ii.find(j=>j.artifact_id===h)||Ii[0]||null:Ii[0]||null},[Ii,gl]);_.useEffect(()=>{e!=="runtime"||ko!=="artifacts"||Zu(fs)},[e,ko,fs==null?void 0:fs.artifact_id]),_.useEffect(()=>()=>{so.url&&URL.revokeObjectURL(so.url)},[so.url]);const Uc=_.useMemo(()=>gn.filter(h=>du(h.status)),[gn]);_.useEffect(()=>{if(e!=="settings"&&e!=="launch"||!k||E)return;let h=!1;return(async()=>{const[j,$]=await Promise.all([Le.list_skills(),Le.list_mcp_servers()]);h||(q(j),ie($),X(!0))})(),()=>{h=!0}},[e,k,E]);const yd=[{id:"board",label:"Board",icon:r.jsx(Nn,{name:"board",size:16})},{id:"observe",label:"Observe",icon:r.jsx(Nn,{name:"history",size:16})},{id:"runtime",label:"System",icon:r.jsx(Nn,{name:"server",size:16})},{id:"launch",label:"Launch",icon:r.jsx(Nn,{name:"send",size:16})},{id:"automations",label:"Automations",icon:r.jsx(Nn,{name:"refresh",size:16})}],lo={board:"Board",observe:"Observe",runtime:"System",launch:"Launch",automations:"Automations",settings:"Settings"},Bl=r.jsxs(r.Fragment,{children:[Hs?r.jsxs("details",{className:"launch_capabilities",style:{marginTop:"10px"},children:[r.jsxs("summary",{className:"help_text muted",style:{cursor:"pointer"},children:["Capabilities",js.length?` · ${js.length} skill${js.length===1?"":"s"}`:""]}),r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-sm)",marginTop:"8px"},children:"Skills attach knowledge procedures to this run. The gateway resolves selections through the trust gate at start: validated skills activate, unverified ones are held for review, blocked ones never ride."}),O===null?r.jsx("div",{className:"help_text muted",style:{marginTop:"8px"},children:"This gateway does not serve a skills inventory yet — the shelf lights up here when it ships."}):O.length?r.jsx("div",{className:"launch_skill_list",children:O.map(h=>{var U;const j=js.includes(h.name),$=h.blocked===!0,M=h.requires_review===!0&&!$;return r.jsxs("label",{className:`launch_skill_row ${$?"is_blocked":""} ${j?"is_on":""}`,title:[h.description||"",h.tree_hash?`tree ${h.tree_hash.slice(0,16)}…`:"",$&&((U=h.reasons)!=null&&U.length)?`blocked: ${h.reasons.join("; ")}`:""].filter(Boolean).join(`
|
|
135
|
+
`),children:[r.jsx("input",{type:"checkbox",checked:j,disabled:$||Ce||St||yt,onChange:W=>{const V=W.target.checked?Array.from(new Set([...js,h.name])):js.filter(Z=>Z!==h.name);Tt("skills",V.length?V:void 0)}}),r.jsx("span",{className:"launch_skill_name",children:h.name}),h.trust_level?r.jsx("span",{className:`chip ${$?"danger":M?"warn":"muted"}`,children:$?"blocked":M?"review":h.trust_level}):null,h.description?r.jsx("span",{className:"launch_skill_desc",children:h.description}):null]},h.name)})}):r.jsx("div",{className:"help_text muted",style:{marginTop:"8px"},children:"The gateway's skills shelf is empty."}),js.length?r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-xxs)",marginTop:"6px"},children:"Selected skills ride the run as input_data.skills; the resolved verdicts land in the run's record."}):null]}):null,r.jsxs("details",{style:{marginTop:"10px"},children:[r.jsx("summary",{className:"help_text muted",style:{cursor:"pointer"},children:"Workspace"}),r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-sm)",marginTop:"8px"},children:"Controls what the agent can access via filesystem tools."}),r.jsxs("div",{className:"launch_grid",style:{marginTop:"8px"},children:[r.jsxs("div",{className:"launch_grid_cell",style:{gridColumn:"1 / -1"},children:[r.jsx("label",{className:"launch_label",children:"Workspace Root"}),r.jsx("input",{className:"mono",value:yl,onChange:h=>Tt("workspace_root",h.target.value),placeholder:"/path/to/workspace",disabled:Ce||St}),r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-xxs)"},children:"Empty = gateway default (isolated per-run workspace)"})]}),r.jsxs("div",{className:"launch_grid_cell",children:[r.jsx("label",{className:"launch_label",children:"Access Mode"}),r.jsxs("select",{className:"mono",value:(Ws||"workspace_only").trim()||"workspace_only",onChange:h=>Tt("workspace_access_mode",h.target.value),disabled:Ce||St,children:[r.jsx("option",{value:"workspace_only",children:"workspace_only"}),r.jsx("option",{value:"workspace_or_allowed",children:"workspace_or_allowed"}),r.jsx("option",{value:"all_except_ignored",children:"all_except_ignored"})]}),r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-xxs)"},children:"workspace_only: absolute paths must stay under root. workspace_or_allowed: allow additional roots."})]})]}),(Ws||"").trim()==="workspace_or_allowed"?r.jsxs("div",{className:"field",style:{marginTop:"8px"},children:[r.jsx("label",{className:"launch_label",children:"Allowed Paths"}),r.jsx("textarea",{className:"mono",rows:3,value:vl,onChange:h=>Tt("workspace_allowed_paths",h.target.value),placeholder:`/path/to/project
|
|
136
|
+
/path/to/workspace`,disabled:Ce||St,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off"}),r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-xxs)"},children:"Newline-separated directories (absolute or relative to workspace_root)"})]}):null,r.jsxs("div",{className:"field",style:{marginTop:"8px"},children:[r.jsx("label",{className:"launch_label",children:"Ignored Paths"}),r.jsx("textarea",{className:"mono",rows:3,value:wl,onChange:h=>Tt("workspace_ignored_paths",h.target.value),placeholder:`node_modules
|
|
137
|
+
runtime
|
|
138
|
+
secret`,disabled:Ce||St,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off"}),r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-xxs)"},children:"Newline-separated paths to block (absolute or relative to workspace_root)"})]})]}),r.jsxs("details",{className:"launch_bundles",style:{marginTop:"10px"},children:[r.jsx("summary",{className:"help_text muted",style:{cursor:"pointer"},children:"Workflow bundles"}),r.jsxs("div",{className:"launch_workflow_bar",style:{marginTop:"8px"},children:[r.jsx("input",{ref:Qr,type:"file",accept:".flow",style:{display:"none"},onChange:h=>{const j=h.target.files&&h.target.files.length?h.target.files[0]:null;j&&Ss(j)}}),r.jsx("button",{type:"button",className:"btn launch_btn_upload",onClick:()=>{var h;return(h=Qr.current)==null?void 0:h.click()},disabled:!k||le||vi||Ce||St,title:"Upload a .flow bundle",children:vi?"…":"Upload .flow"}),r.jsxs("button",{type:"button",className:"btn launch_btn_reload",onClick:()=>void ci(),disabled:!k||le||at||Ce||St,title:"Reload picks up server-side edits",children:[r.jsx(Nn,{name:"refresh",size:14}),at?"…":"Reload bundles"]})]})]})]});function fi(h){t("observe"),Os("overview"),ui(h)}const Wc={on_select:h=>void Tn.select(h),on_row_action:(h,j)=>{if(j==="edit"||j==="discuss"){Tn.select(h.automation_id);return}if(j==="archive"){Tn.ask_archive(h.automation_id);return}Tn.row_action(h,j)},on_legacy_action:(h,j)=>{if(j==="open_run"){fi(h.automation_id);return}if(j==="recreate"){td(h.automation_id).catch($=>Tn.report_error($));return}Tn.legacy_action(h,j)},on_confirm_archive:h=>void Tn.row_action(h,"archive"),on_cancel_archive:()=>Tn.ask_archive(""),on_status_filter:h=>void Tn.set_status_filter(h),on_refresh:()=>void Tn.refresh(),on_new:()=>{xe("automate"),t("launch")},on_show_archived:h=>Tn.set_show_archived(h)};return r.jsxs("div",{className:"app-shell shell",children:[r.jsxs("aside",{className:"shell_sidebar",children:[r.jsxs("div",{className:"shell_brand",title:"AbstractObserver (Web/PWA)",children:[r.jsx("span",{className:"logo-icon shell_brand_mark","aria-hidden":"true",children:r.jsxs("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("ellipse",{cx:"12",cy:"12",rx:"9",ry:"4.2",transform:"rotate(-18 12 12)",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",opacity:"0.75"}),r.jsx("circle",{cx:"12",cy:"12",r:"4.7",fill:"currentColor",opacity:"0.95"}),r.jsx("circle",{cx:"10.3",cy:"10.7",r:"1.6",fill:"#ffffff",opacity:"0.18"}),r.jsx("circle",{cx:"19",cy:"13.6",r:"1.2",fill:"currentColor"})]})}),r.jsx("span",{className:"shell_brand_name",children:"Observer"})]}),r.jsxs("nav",{className:"shell_nav",children:[yd.map(h=>r.jsxs("button",{className:`shell_nav_item ${e===h.id?"active":""}`,onClick:()=>t(h.id),type:"button",children:[r.jsx("span",{className:"shell_nav_icon",children:h.icon}),r.jsx("span",{className:"shell_nav_label",children:h.label})]},h.id)),r.jsxs("a",{className:"shell_nav_item",href:l,target:"_blank",rel:"noreferrer",title:"Open the entity app (memory graph + visits)",children:[r.jsx("span",{className:"shell_nav_icon",children:r.jsx(Nn,{name:"bot",size:16})}),r.jsx("span",{className:"shell_nav_label",children:"Entities ↗"})]}),r.jsxs("button",{className:`shell_nav_item ${e==="settings"?"active":""}`,onClick:()=>t("settings"),type:"button",children:[r.jsx("span",{className:"shell_nav_icon",children:r.jsx(Nn,{name:"settings",size:16})}),r.jsx("span",{className:"shell_nav_label",children:"Settings"})]})]}),r.jsx("div",{className:"shell_sidebar_footer",children:r.jsxs("div",{className:"shell_connection shell_connection_passive",title:k?"Gateway connected":le?"Gateway: connecting…":"Gateway: signed out",children:[r.jsx("span",{className:`gateway_led ${k?"ok":le?"warn":"err"}`,"aria-hidden":"true"}),r.jsx("span",{className:`shell_connection_label ${k&&((Vc=(qc=K==null?void 0:K.gateway)==null?void 0:qc.principal)!=null&&Vc.user_id)?"mono":""}`,children:k?((zi=(tm=K==null?void 0:K.gateway)==null?void 0:tm.principal)==null?void 0:zi.user_id)||(n.gateway_auth_mode==="direct"?"direct dev":"connected"):le?"connecting…":"signed out"})]})})]}),r.jsxs("div",{className:"shell_main",children:[r.jsxs("header",{className:"shell_header",children:[r.jsx("div",{className:"shell_header_title",children:lo[e]||"Observer"}),r.jsxs("div",{className:"shell_header_actions",children:[a?r.jsx("monitor-gpu",{ref:u,mode:"icon","history-size":"5","tick-ms":"1500","base-url":n.gateway_auth_mode==="session"?"":n.gateway_url,title:"GPU usage (host)",style:{"--monitor-gpu-width":"34px","--monitor-gpu-bars-height":"22px","--monitor-gpu-padding":"2px 4px","--monitor-gpu-radius":"999px","--monitor-gpu-bg":"rgba(0,0,0,0.22)","--monitor-gpu-border":"rgba(255,255,255,0.16)",flexShrink:0}}):null,r.jsx(A0,{assistant:{open:Ft,onToggle:()=>At(h=>!h),label:"Observer assistant (docs-grounded)"},appearance:{onOpen:()=>fn(!0)},about:{identity:Wu,extraRows:Hu,onOpen:Lo},connection:{phase:P.phase,signingOut:P.signingOut,onConnect:()=>P.openModal(),onDisconnect:()=>Io()}})]})]}),r.jsx(u0,{...P.modalProps}),r.jsx(L0,{open:Xt,onClose:()=>fn(!1),value:Ve,onChange:Rt}),r.jsx(qj,{open:Ft,onClose:()=>At(!1),connected:k,topOffset:44,gateway:Le}),r.jsxs("div",{className:"app-body shell_content",children:[e==="board"?k?r.jsx(WA,{gateway_connected:k,runs:$t,all_runs:Pn,runs_refreshed_at:mn,entities:Hn,entities_total:ys,entities_error:oe,refreshing:yn,on_refresh:()=>void ir(Le,{force:!0}),on_open_run:h=>{t("observe"),Os("overview"),ui(h)},on_resume_wait:Af,on_open_automation:h=>{t("automations"),Tn.refresh().then(()=>Tn.select(h))},entity_app_href:l,on_read_diary:(h,j)=>Le.read_entity_diary_entry(h,j),phase_graph:Yu}):r.jsx("div",{className:"page page_scroll",children:r.jsx("div",{className:"page_inner constrained",children:r.jsxs("div",{className:"card mc_hero",children:[r.jsx("div",{className:"title",children:r.jsx("h1",{children:"Connect to your gateway"})}),r.jsxs("p",{className:"muted",children:["Mission Control shows every run and entity on one board — but nothing is connected yet.",F?` Last attempt: ${F}`:""]}),r.jsxs("div",{className:"row",style:{gap:"8px",alignItems:"center"},children:[r.jsx("button",{className:"btn primary",onClick:()=>P.openModal(),disabled:le,children:le?"Connecting…":"Sign in"}),r.jsx("button",{className:"btn",onClick:()=>void jl({open_modal_if_needed:!0}),disabled:le,title:"Retry with an existing browser session or a direct dev token",children:"Retry connection"})]})]})})}):null,e==="settings"?r.jsx("div",{className:"page page_scroll",children:r.jsxs("div",{className:"page_inner settings_col",children:[r.jsxs("section",{className:"pane",children:[r.jsxs("div",{className:"pane_header",children:[r.jsx("span",{className:"pane_title",children:"Gateway"}),r.jsx("span",{className:"pane_spacer"}),r.jsx("span",{className:`chip ${k?"ok":"warn"}`,children:Cv(K).label})]}),r.jsxs("div",{className:"pane_body settings_body",children:[r.jsxs("div",{className:"settings_row",children:[r.jsxs("div",{className:"settings_row_main",children:[r.jsx("div",{className:"settings_row_title",children:"Connection"}),r.jsx("div",{className:"settings_row_help",children:"The shared AbstractFramework sign-in: a gateway user token exchanges for an HTTP-only browser session. Raw tokens are never stored."})]}),r.jsxs("div",{className:"settings_row_actions",children:[r.jsx("button",{className:"btn",onClick:()=>P.openModal(),children:"Manage connection…"}),k?r.jsx("button",{className:"btn",onClick:()=>Io(),title:"Sign this browser out of the gateway (this app's session only)",children:"Sign out"}):null]})]}),F?r.jsx("div",{className:"warn_callout",children:F}):null,r.jsxs("div",{className:"settings_row",children:[r.jsxs("div",{className:"settings_row_main",children:[r.jsx("div",{className:"settings_row_title",children:"Auto-connect on load"}),r.jsx("div",{className:"settings_row_help",children:"Reuse the browser session automatically when the app opens."})]}),r.jsx("div",{className:"settings_row_actions",children:r.jsxs("select",{value:n.auto_connect_gateway?"on":"off",onChange:h=>i(j=>({...j,auto_connect_gateway:h.target.value==="on"})),children:[r.jsx("option",{value:"on",children:"On"}),r.jsx("option",{value:"off",children:"Off"})]})})]}),r.jsxs("details",{className:"settings_advanced",children:[r.jsx("summary",{children:"Advanced: direct dev connection (bearer token, cross-origin)"}),r.jsxs("div",{className:"field",style:{marginTop:"8px"},children:[r.jsx("label",{children:"Gateway URL"}),r.jsx("input",{value:n.gateway_url,onChange:h=>i(j=>({...j,gateway_url:h.target.value})),placeholder:th})]}),r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Dev bearer token"}),r.jsx("input",{type:"password",value:n.auth_token,onChange:h=>i(j=>({...j,auth_token:h.target.value,gateway_auth_mode:"direct"})),placeholder:"development only — prefer the sign-in dialog"})]}),r.jsx("button",{className:"btn",onClick:()=>void jl({prefer_direct:!0}),disabled:le,children:le?"Connecting…":"Connect directly"})]})]})]}),r.jsxs("section",{className:"pane",children:[r.jsxs("div",{className:"pane_header",children:[r.jsx("span",{className:"pane_title",children:"Assistant"}),r.jsx("span",{className:"pane_spacer"}),r.jsx("span",{className:"chip muted",children:"docs Q&A + run Ask"})]}),r.jsxs("div",{className:"pane_body settings_body",children:[r.jsx("div",{className:"settings_row_help",style:{marginTop:0},children:"The model answering the header assistant and the run page's Ask tab. Blank fields follow the gateway defaults."}),r.jsx(t0,{className:"field",providerLabel:"Provider",modelLabel:"Model",providerPlaceholder:"(gateway default)",modelPlaceholder:"(gateway default)",provider:n.maintenance_ai_provider,model:n.maintenance_ai_model,providers:Gu,models:Tc.models,loadingProviders:le,loadingModels:Ln,modelError:Li?Tc.error:"",allowCustomProvider:!0,allowCustomModel:!0,allowGatewayDefault:!0,gatewayDefaultLabel:"(gateway default)",onChange:h=>i(j=>({...j,maintenance_ai_provider:h.provider,maintenance_ai_model:h.model}))}),r.jsx("div",{className:"settings_subhead",children:"Skills"}),O===null?r.jsx("div",{className:"settings_row_help",children:k?E?"The gateway does not serve a skills inventory yet — the abstractskill shelf list lights up here the day it ships.":"Probing the gateway for the skills inventory…":"Connect to the gateway to list installable skills (abstractskill shelf)."}):O.length?r.jsx("div",{className:"settings_choice_list",children:O.map(h=>{const j=n.assistant_skill_names.includes(h.name);return r.jsxs("label",{className:`settings_choice ${j?"on":""}`,title:h.description||h.name,children:[r.jsx("input",{type:"checkbox",checked:j,onChange:$=>i(M=>({...M,assistant_skill_names:$.target.checked?Array.from(new Set([...M.assistant_skill_names,h.name])):M.assistant_skill_names.filter(U=>U!==h.name)}))}),r.jsxs("span",{className:"settings_choice_name",children:[h.name,h.version?r.jsxs("em",{children:[" v",h.version]}):null]}),h.description?r.jsx("span",{className:"settings_choice_desc",children:h.description}):null]},h.name)})}):r.jsx("div",{className:"settings_row_help",children:"The gateway serves an empty skills inventory."}),r.jsx("div",{className:"settings_row_help",children:"Selected skills ride the assistant's runs once the gateway's skills-attachment lane serves them; the selection persists here meanwhile."}),r.jsx("div",{className:"settings_subhead",children:"MCP servers"}),r.jsx("div",{className:"settings_row_help",style:{marginTop:0},children:"Remote tool endpoints the assistant may call. The gateway does not serve an MCP inventory yet — one manual endpoint is supported (advanced / potentially dangerous: it executes tool waits from this browser)."}),r.jsxs("div",{className:"settings_mcp_row",children:[r.jsx("input",{className:"mono",value:n.worker_url,onChange:h=>i(j=>({...j,worker_url:h.target.value})),placeholder:"https://your-mcp-worker-endpoint"}),r.jsx("input",{className:"mono",type:"password",value:n.worker_token,onChange:h=>i(j=>({...j,worker_token:h.target.value})),placeholder:"Bearer token (optional)"}),r.jsx("span",{className:`chip ${n.worker_url.trim()?"ok":"muted"}`,children:n.worker_url.trim()?"configured":"none"})]})]})]})]})}):null,e==="launch"?r.jsx("div",{className:"page page_scroll",children:r.jsx("div",{className:"page_inner constrained",children:r.jsxs("div",{className:"card",children:[r.jsx(pS,{mode:de,automate_available:he.available,automate_reason:he.reason,on_change:xe}),de==="automate"&&!he.available&&k?r.jsx("div",{className:"warn_callout",role:"note",children:he.reason}):null,de==="automate"&&$e.length?r.jsx("div",{className:"help_text",role:"note",children:$e.map(h=>r.jsx("div",{children:h},h))}):null,k?null:r.jsxs("div",{className:"warn_callout",children:["Not connected."," ",r.jsx("button",{className:"btn primary",onClick:()=>P.openModal(),children:"Sign in"})," ","to launch workflows on this gateway."]}),de==="automate"?r.jsx("div",{className:"section_title",children:"What"}):null,r.jsx("div",{className:"launch_workflow_bar",children:r.jsxs("select",{className:"launch_workflow_select","aria-label":"Workflow",value:Ef,onChange:async h=>{const j=Vj(String(h.target.value||""));j&&await ed(j)},disabled:le||!k,children:[r.jsx("option",{value:"",children:bl.length?"(select workflow)":ft?le?"(loading workflows…)":"(no executable workflows published on this gateway)":"(sign in to load workflows)"}),r.jsx("optgroup",{label:"Gateway default",children:Kj(sn).map(h=>r.jsx("option",{value:h.value,children:h.label},h.value))}),r.jsx("optgroup",{label:"Workflows",children:bl.map(h=>r.jsx("option",{value:h.workflow_id,children:h.label},h.workflow_id))})]})}),r.jsxs("div",{className:"field",children:[Rn!=null&&Rn.description?r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-sm)",marginTop:"6px"},children:String(Rn.description)}):null,Q?r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-sm)"},children:"Loading workflow…"}):null,ee?r.jsx("div",{className:"mono",style:{color:"rgba(239, 68, 68, 0.9)",fontSize:"var(--font-size-sm)"},children:ee}):null]}),r.jsx("div",{className:"section_divider"}),r.jsx("div",{className:"section_title",children:"Inputs"}),Hs?st===null?r.jsxs("div",{className:"log_item",style:{borderColor:"rgba(239, 68, 68, 0.35)",marginTop:"10px"},children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{className:"mono",children:"input error"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:"Invalid input JSON — reselect the workflow to reset its inputs."})]}):Oo?r.jsx("div",{className:"launch_inputs",children:(()=>{const h=Ce||St,j=[],$=[];for(const W of ls){if(!W||typeof W!="object")continue;const V=String(W.id||"").trim();if(!V)continue;const Z=String(W.type||"").trim().toLowerCase();Z==="tools"||Z==="skills"||Z==="mcp"||Z==="mcp_servers"||V==="skills"||V==="mcp"||V==="mcp_servers"||Z==="array"||xl(Z)||V==="prompt"||V==="system"?j.push(W):$.push(W)}const M=W=>String(W||"").trim().replace(/_/g," ").replace(/\b\w/g,V=>V.toUpperCase()),U=(W,V)=>{const Z=String(W.id||"").trim();if(!Z)return null;const ke=String(W.label||Z).trim()||Z,me=ke===Z?M(Z):ke,ue=String(W.type||"").trim().toLowerCase(),Ne=Object.prototype.hasOwnProperty.call(W,"default"),Ie=Ne?W.default:void 0,ze=Ne?typeof Ie=="string"?Ie:Tr(Ie,80):"",Ge=st==null?void 0:st[Z],Be=Ne?`${ze}`:"";if(ue==="tools"){const Ue=Array.isArray(Ge)?Ge.map(En=>String(En||"").trim()).filter(Boolean):[],vt=Array.isArray(Ie)?Ie.map(En=>String(En||"").trim()).filter(Boolean):[],wn=Array.from(new Set([...Mc,...Ue,...vt])).sort();return r.jsxs("div",{className:"launch_field_wide",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx(Jy,{options:wn,value:Ue,disabled:h,placeholder:"(no tools selected)",onChange:En=>Tt(Z,En)})]},Z)}if(ue==="skills"||Z==="skills")return null;if(ue==="mcp"||ue==="mcp_servers"||Z==="mcp"||Z==="mcp_servers"){const Ue=Array.isArray(Ge)?Ge.map(En=>String(En||"").trim()).filter(Boolean):[];if(ne===null&&!Ue.length)return r.jsxs("div",{className:"launch_field_wide",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx("div",{className:"help_text muted",children:"This gateway does not serve an MCP server inventory yet — MCP selection lights up here when it ships."})]},Z);const vt=(ne||[]).map(En=>En.name),wn=Array.from(new Set([...vt,...Ue])).sort();return r.jsxs("div",{className:"launch_field_wide",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx(Jy,{options:wn,value:Ue,disabled:h,placeholder:"(no MCP servers selected)",onChange:En=>Tt(Z,En)})]},Z)}if(ue==="provider"||ue==="provider_text"){const Ue=typeof Ge=="string"?String(Ge):"";return r.jsxs("div",{className:V||"launch_field",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsxs("select",{value:Ue,onChange:vt=>Tt(Z,vt.target.value),disabled:h,children:[r.jsx("option",{value:"",children:Be||"(select)"}),Vu.map(vt=>r.jsx("option",{value:vt,children:vt},vt))]})]},Z)}if(ue==="model"||ue==="model_text"){const Ue=typeof Ge=="string"?String(Ge):"",vt=String((st==null?void 0:st.provider)||"").trim(),wn=vt?It[vt]:void 0,En=wn&&Array.isArray(wn.models)?wn.models.map(Dr=>String(Dr||"").trim()).filter(Boolean):[];return r.jsxs("div",{className:V||"launch_field",children:[r.jsx("label",{className:"launch_label",children:me}),En.length?r.jsxs("select",{value:Ue,onChange:Dr=>Tt(Z,Dr.target.value),disabled:h,children:[r.jsx("option",{value:"",children:Be||"(select)"}),En.map(Dr=>r.jsx("option",{value:Dr,children:Dr},Dr))]}):r.jsx("input",{value:Ue,onChange:Dr=>Tt(Z,Dr.target.value),placeholder:Be||"model id",disabled:h})]},Z)}if(ue==="boolean"){const Ue=typeof Ge=="boolean"?Ge?"true":"false":"";return r.jsxs("div",{className:V||"launch_field",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsxs("select",{value:Ue,onChange:vt=>{const wn=String(vt.target.value||"").trim();wn?Tt(Z,wn==="true"):Tt(Z,void 0)},disabled:h,children:[r.jsx("option",{value:"",children:Be||"(default)"}),r.jsx("option",{value:"true",children:"Yes"}),r.jsx("option",{value:"false",children:"No"})]})]},Z)}if(ue==="number"){const Ue=typeof Ge=="number"&&Number.isFinite(Ge)?String(Ge):"";return r.jsxs("div",{className:V||"launch_field",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx("input",{type:"number",value:Ue,onChange:vt=>{const wn=String(vt.target.value||"").trim();if(!wn){Tt(Z,void 0);return}const En=Number(wn);Number.isFinite(En)&&Tt(Z,En)},placeholder:Be,disabled:h})]},Z)}if(ue==="array"){const Ue=Array.isArray(Ge)?Ge.map(vt=>String(vt||"").trim()).filter(Boolean).join(`
|
|
139
|
+
`):"";return r.jsxs("div",{className:"launch_field_wide",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx("textarea",{className:"mono",value:Ue,onChange:vt=>{const wn=String(vt.target.value||"").split(/\r?\n/g).map(En=>String(En||"").trim()).filter(Boolean);Tt(Z,wn.length?wn:void 0)},placeholder:Be||"(one item per line)",rows:2,disabled:h})]},Z)}if(xl(ue)){const Ue=typeof Ts[Z]=="string"?Ts[Z]:"",vt=String(Qt[Z]||"").trim();return r.jsxs("div",{className:"launch_field_wide",children:[r.jsxs("label",{className:"launch_label",children:[me," ",r.jsx("span",{className:"launch_label_type",children:ue})]}),r.jsx("textarea",{className:"mono",value:Ue,onChange:wn=>{const En=String(wn.target.value??"");rt(ms=>({...ms,[Z]:En}));const Dr=En.trim();if(!Dr){ur(ms=>{const Ys={...ms};return delete Ys[Z],Ys}),Tt(Z,void 0);return}try{const ms=JSON.parse(Dr);ur(Ys=>{const Ar={...Ys};return delete Ar[Z],Ar}),Tt(Z,ms)}catch(ms){ur(Ys=>({...Ys,[Z]:String((ms==null?void 0:ms.message)||ms||"Invalid JSON")}))}},placeholder:Be||"{...}",rows:3,disabled:h}),vt?r.jsx("div",{className:"launch_field_error",children:vt}):null]},Z)}const tn=typeof Ge=="string"?String(Ge):"";return Z==="prompt"||Z==="system"?r.jsxs("div",{className:"launch_field_wide",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx("textarea",{value:tn,onChange:Ue=>Tt(Z,Ue.target.value),placeholder:Be||(Z==="prompt"?"What should the agent do?":"System instructions (optional)"),rows:3,disabled:h})]},Z):r.jsxs("div",{className:V||"launch_field",children:[r.jsx("label",{className:"launch_label",children:me}),r.jsx("input",{value:tn,onChange:Ue=>Tt(Z,Ue.target.value),placeholder:Be,disabled:h})]},Z)};return j.sort((W,V)=>{const Z={system:0,prompt:1,tools:2};return(Z[String(W.id||"")]??10)-(Z[String(V.id||"")]??10)}),r.jsxs(r.Fragment,{children:[j.map(W=>U(W)),$.length>0?r.jsx("div",{className:"launch_grid",children:$.map(W=>U(W,"launch_grid_cell"))}):null]})})()}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"field",style:{marginTop:"10px"},children:[r.jsx("label",{children:"Prompt (common)"}),r.jsx("textarea",{value:Cf,onChange:h=>Tt("prompt",h.target.value),placeholder:"What do you want the workflow/agent to do?",rows:3,disabled:Ce||St})]}),r.jsxs("div",{className:"row",children:[r.jsx("div",{className:"col",children:r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Provider (common)"}),r.jsx("input",{value:Ta,onChange:h=>Tt("provider",h.target.value),placeholder:"lmstudio / ollama / openai / ...",disabled:Ce||St})]})}),r.jsx("div",{className:"col",children:r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Model (common)"}),r.jsx("input",{value:$f,onChange:h=>Tt("model",h.target.value),placeholder:"qwen/qwen3-next-80b / gpt-4.1 / ...",disabled:Ce||St})]})})]})]}):r.jsx("div",{className:"help_text muted",style:{fontSize:"var(--font-size-sm)",marginTop:"8px"},children:"Select a workflow above to configure inputs."}),de==="automate"?r.jsxs(r.Fragment,{children:[r.jsx(yS,{form:Oe,tools:Array.isArray(st==null?void 0:st.tools)?st.tools.map(h=>String(h)):void 0,disabled:yt,on_change:h=>He(j=>({...j,...h}))}),r.jsxs("details",{className:"launch_advanced",style:{marginTop:"10px"},children:[r.jsxs("summary",{className:"help_text muted",style:{cursor:"pointer"},children:["Advanced",js.length?` · ${js.length} skill${js.length===1?"":"s"}`:""]}),r.jsx(vS,{form:Oe,disabled:yt,on_change:h=>He(j=>({...j,...h}))}),Bl]})]}):Bl,r.jsx("div",{className:"section_divider"}),cn?r.jsxs("div",{className:"observe_context_card error",style:{marginBottom:"10px"},children:[r.jsx("span",{className:"chip mono danger",children:"error"}),r.jsx("span",{className:"mono",children:cn})]}):null,de==="automate"&&Ke.length?r.jsx("ul",{className:"automate_errors",role:"alert",children:Ke.map(h=>r.jsx("li",{children:h},h))}):null,de==="automate"&&pt?r.jsxs("div",{className:"observe_context_card error",role:"alert","data-code":pt.code,style:{marginBottom:"10px"},children:[r.jsx("span",{className:"chip mono danger",children:pt.code}),r.jsxs("span",{children:[r.jsx("strong",{children:Dm(pt).title})," ",Dm(pt).detail,pt.field?r.jsxs("span",{className:"mono",children:[" (",pt.field,")"]}):null]})]}):null,r.jsx("div",{className:"launch_actions_bar launch_actions_stack",children:(()=>{const h=de==="automate",j=k?Hs?st===null?"Inputs contain invalid JSON":h&&!he.available?"Automations unavailable on this gateway":Ce||St?"Attaching to a run…":le||Q?"Loading…":yt?"Submitting…":"":"Select a workflow":"Sign in first";return r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"launch_submit_btn",onClick:()=>void If(),disabled:!!j,title:j,children:h?yt?"Creating…":"Create automation":Ce?"Launching…":"Launch now"}),j&&!yt&&!Ce?r.jsx("span",{className:"mono muted launch_disabled_reason",children:j}):null]})})()})]})})}):null,e==="automations"?r.jsx(CS,{ctl:Tn,active:e==="automations"&&k,available:he,h:Wc,host:{on_open_run:h=>fi(h),on_open_session:(h,j)=>{Gt({ts:wt(),kind:"info",title:"Discussion started",preview:ut(j),data:h}),Sn(j,12),fi(h.run_id)}}}):null,e==="runtime"?r.jsx(Tk,{gateway_connected:k,tab:ko,runs:gn,active_runs:Uc,all_artifacts:Lu,artifacts:Ii,artifact_total_count:vf,artifact_total_bytes:Pu,artifact_facets:xf,artifact_type_facets:si,artifact_page:lr,artifact_page_size:Cm,artifact_groups:Ua,selected_artifact:fs,embedded_preview:so,loading:Ei,error:bh,query:Fs,scope:ii,type_filters:is,date_filter:un,group_by:Fn,sort_by:oi,artifact_run_filter:Bn,audit_log_text:Yr,audit_log_meta:Us,audit_log_loading:Du,audit_log_error:zu,workflow_label_by_id:Zt,run_by_id:kn,selected_run_id:Wo,session_id:zl,runtime_log_source:Ao,runtime_log_query:Ea,runtime_ledger_log_items:Sh,runtime_ledger_log_meta:$c,runtime_ledger_log_loading:kf,runtime_ledger_log_error:Nf,on_tab_change:xc,on_query_change:hl,on_scope_change:ba,on_session_filter_change:Co,on_type_filters_change:bn,on_date_filter_change:ro,on_group_by_change:Kr,on_sort_by_change:Sa,on_artifact_page_change:Ca,on_artifact_run_filter_change:h=>{const j=String(h||"").trim();_l(j),j&&Na(j),j&&ii!=="run"&&ba("run")},on_refresh_artifacts:()=>void us(),on_refresh_audit:()=>void Yt(),on_refresh_runtime_ledger:h=>void Jn(h),on_runtime_log_source_change:Sf,on_runtime_log_query_change:Bu,on_select_run:h=>{const j=String(h||"").trim();Na(j);const $=j&&kn[j]||null,M=String(($==null?void 0:$.session_id)||"").trim();M&&Co(M)},on_select_artifact:jc,on_preview_artifact:h=>void $l(h),on_download_artifact:h=>void Cl(h),on_open_run:h=>{Na(String(h||"").trim()),t("observe"),Os("overview"),ui(h)},on_open_ledger:h=>{Na(String(h||"").trim()),t("observe"),Os("ledger"),ui(h)},on_refresh_runs:()=>void ir(Le,{force:!0}),on_reconnect:()=>void jl({open_modal_if_needed:!0}),on_open_settings:()=>t("settings"),memory_panel:k?r.jsx(xA,{gateway:Le,selected_run_id:ka,selected_session_id:zl}):null}):null,e==="observe"?r.jsx("div",{className:"page observe_page",children:r.jsxs("div",{className:"observatory_layout",children:[r.jsx(Lk,{sections:wr,selected_run_id:d,root_run_id:p,search:uc,filter:ku,group_by:Nu,loading:yn,connected:k,on_sign_in:()=>P.openModal(),total_runs:gn.length,workflow_label_by_id:Zt,automation_titles:Uu,on_search:_h,on_filter:gh,on_group_by:ph,on_refresh:()=>void ir(),on_select:(h,j)=>void ui(h,{root_run_id:j||h})}),r.jsxs("div",{className:"observatory_main",children:[r.jsxs("div",{className:"observe_toolbar",children:[r.jsxs("div",{className:"observe_toolbar_row",children:[d.trim()?r.jsxs("div",{className:"observe_run_identity",title:d.trim(),children:[r.jsx("span",{className:"observe_run_name",children:Zt[String((dn==null?void 0:dn.workflow_id)||"")]||String((dn==null?void 0:dn.workflow_id)||"").trim()||Et(d.trim(),22)}),r.jsx("span",{className:"chip mono muted",children:Et(d.trim(),14)}),r.jsx("span",{className:`chip ${nl(Fa||Uo,ao)}`,title:String((ao==null?void 0:ao.headline)||""),children:Fa||Uo||"unknown"})]}):r.jsx("span",{className:"observe_run_identity_empty",children:"No run selected"}),r.jsx("span",{className:"observe_toolbar_spacer"}),d.trim()?r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn",onClick:()=>{if(vr==="pause"){xi("pause"),kr(""),Vr(""),ws(!0);return}Ff("resume")},disabled:Eh,children:Ol}),Xe?r.jsx("button",{className:"btn primary",onClick:()=>void nd(),disabled:Ce||St||qs||Oi,children:"Run now"}):null,r.jsx("button",{className:"btn danger",onClick:()=>{xi("cancel"),kr(""),Vr(""),ws(!0)},disabled:Ce||St||qs,children:"Cancel"}),r.jsx("button",{className:"btn btn_icon",onClick:Df,title:"Clear the run view",children:r.jsx(Nn,{name:"x",size:14})})]}):null]}),d.trim()&&!qs?r.jsx("div",{className:"observe_steer_row",children:r.jsx(g0,{runId:d.trim(),parked:Ml,submit:(h,j)=>Le.submit_command({command_id:`steer-${zr()}`,run_id:h,type:"inject_guidance",payload:{guidance:j},client_id:"web_pwa"}).then($=>({accepted:!!($!=null&&$.accepted),duplicate:!!($!=null&&$.duplicate),seq:Number(($==null?void 0:$.seq)??0)})),onSent:()=>Gt({ts:wt(),kind:"info",title:"Steer queued",preview:"inject_guidance submitted — delivery shows as abstract.steer_seen in the ledger"})})}):null,Ml||cs||Su?r.jsxs("div",{className:"observe_toolbar_context",children:[Ml?r.jsxs("div",{className:"observe_context_card info",children:[r.jsxs("div",{className:"observe_context_label",children:[(()=>{const h=cs?Oi?"suspended":"scheduled":"waiting";return r.jsx("span",{className:`chip ${nl(h)}`,children:h})})(),r.jsx("span",{className:"muted",children:pr||"unknown"})]}),r.jsxs("div",{className:"observe_context_body",children:[$r?r.jsxs("span",{className:"mono",title:$r,children:[r.jsx("span",{className:"muted",children:"wait_key"}),": ",Et($r,46)]}):null,pr==="event"&&Tl?r.jsxs("span",{className:"mono",children:[r.jsx("span",{className:"muted",children:"event"}),": ",Tl]}):null,pr==="subworkflow"&&oo?r.jsxs("span",{className:"mono",children:[r.jsx("span",{className:"muted",children:"child"}),": ",Et(oo,18)]}):null,pr==="until"&&On?r.jsxs("span",{className:"mono",title:On,children:[r.jsx("span",{className:"muted",children:"until"}),": ",Et(On,46)]}):null,pr==="until"&&On?r.jsx("span",{className:"mono muted",children:(()=>{const h=xn(On),j=h!==null?new Date(h).toLocaleString():On,$=h!==null?$p(h-Date.now()):"";return`Next at ${j}${$?` (in ${$})`:""}`})()}):null]}),pr==="subworkflow"&&oo?r.jsxs("div",{className:"observe_context_actions",children:[r.jsx("button",{className:"btn primary",onClick:async()=>{m(oo),await Pa(oo)},disabled:Ce,children:"Attach to child"}),p.trim()&&p.trim()!==d.trim()?r.jsx("button",{className:"btn",onClick:async()=>{m(p.trim()),await Pa(p.trim())},disabled:Ce,children:"Back to root"}):null]}):null]}):null,cs?r.jsxs("div",{className:"observe_context_card muted",children:[r.jsxs("div",{className:"observe_context_label",children:[r.jsx("span",{className:"chip muted",children:"schedule"}),r.jsx("span",{className:"muted",children:ud?`every ${Fo}`:"once"})]}),r.jsxs("div",{className:"observe_context_body",children:[Fo?r.jsxs("span",{className:"mono",children:[r.jsx("span",{className:"muted",children:"interval"}),": ",Fo]}):null,r.jsxs("span",{className:"mono",children:[r.jsx("span",{className:"muted",children:"share ctx"}),": ",Ll?"yes":"no"]}),typeof yr=="number"?r.jsxs("span",{className:"mono",children:[r.jsx("span",{className:"muted",children:"repeats"}),": ",yr]}):null]}),Bo!==null?r.jsxs("div",{className:"observe_context_budget",children:[r.jsxs("span",{className:"mono muted",children:[typeof dd=="number"&&typeof Jf=="number"?`${dd.toLocaleString()} / ${Jf.toLocaleString()}`:"",` • ${Math.round(Math.max(0,Math.min(1,Bo))*100)}%`]}),r.jsx("div",{className:"observe_budget_bar",children:r.jsx("div",{className:`observe_budget_fill ${Bo>=.9?"danger":Bo>=.75?"warn":"ok"}`,style:{width:`${Math.round(Math.max(0,Math.min(1,Bo))*100)}%`}})})]}):null,r.jsxs("div",{className:"observe_context_actions",children:[ud?r.jsx("button",{className:"btn",onClick:()=>{Xi(Fo||""),In(!0),$n(""),nr(!0)},disabled:Ce||ts,children:"Edit schedule"}):null,ud?r.jsx("button",{className:"btn",onClick:()=>{wi(""),Hr(!0)},disabled:Ce||ns,children:"Compact context"}):null,r.jsx("button",{className:"btn",onClick:()=>void td(d.trim()).catch(h=>Jt(String((h==null?void 0:h.message)||h))),disabled:Ce||!d.trim(),title:"Open Launch → Automate prefilled from this schedule (this schedule is not changed)",children:"Recreate as automation"})]})]}):null,Su?r.jsxs("div",{className:"observe_context_card error",children:[r.jsx("span",{className:"chip danger",children:"error"}),r.jsx("span",{className:"mono",children:Su})]}):null]}):null]}),r.jsxs("div",{className:"card panel_card card_scroll observe_viewer observe_viewer_full",children:[r.jsxs("div",{className:"tab_bar",children:[r.jsxs("div",{role:"tablist","aria-label":"Run views",className:"observe_tablist",children:[r.jsx("button",{role:"tab","aria-selected":hr==="overview",className:`tab ${hr==="overview"?"active":""}`,onClick:()=>Os("overview"),children:"Story"}),r.jsx("button",{role:"tab","aria-selected":hr==="ledger",className:`tab ${hr==="ledger"?"active":""}`,onClick:()=>Os("ledger"),children:"Ledger"}),r.jsx("button",{role:"tab","aria-selected":hr==="graph",className:`tab ${hr==="graph"?"active":""}`,onClick:()=>Os("graph"),children:"Flow"}),r.jsx("button",{role:"tab","aria-selected":hr==="chat",className:`tab ${hr==="chat"?"active":""}`,onClick:()=>Os("chat"),children:"Ask"})]}),hr==="ledger"&&(Dl.length>0||al==="cycles")?r.jsxs("div",{className:"tab_bar_controls",children:[r.jsxs("div",{className:"seg_toggle",children:[r.jsx("button",{className:`seg_btn ${al==="steps"?"active":""}`,onClick:()=>dc("steps"),children:"Steps"}),r.jsx("button",{className:`seg_btn ${al==="cycles"?"active":""}`,onClick:()=>dc("cycles"),children:"Cycles"})]}),al==="steps"?r.jsx("button",{className:`seg_action ${yo?"active":""}`,onClick:()=>ol(h=>!h),title:yo?"Showing condensed view":"Showing all steps",children:yo?"Condensed":"All"}):r.jsxs("select",{className:"mono seg_select",value:Pr,onChange:h=>Cu(String(h.target.value||"")),disabled:!zc.length,title:"Select run for cycles view",children:[zc.length?null:r.jsx("option",{value:"",children:"(no runs)"}),zc.map(h=>{const j=typeof Gn[h]=="number"?Number(Gn[h]):0,$=`${Et(h,18)}${j?` • ${j} llm`:""}`;return r.jsx("option",{value:h,children:$},h)})]}),r.jsx("button",{className:"seg_action",disabled:!kt.length&&!tr.length,title:"Copy full ledger as JSONL",onClick:()=>{const $=[...kt.map(W=>({run_id:d.trim()||W.record.run_id||"",cursor:W.cursor,record:W.record})),...tr.map(W=>({run_id:W.run_id,cursor:W.cursor,record:W.record}))].map(W=>{var ke,me;const V=String(((ke=W.record)==null?void 0:ke.ended_at)||((me=W.record)==null?void 0:me.started_at)||"").trim(),Z=xn(V);return{...W,_ms:Z??0}});$.sort((W,V)=>(W._ms||0)-(V._ms||0));const U=($.length>5e3?$.slice($.length-5e3):$).map(({_ms:W,...V})=>JSON.stringify(V)).join(`
|
|
140
|
+
`);kl(U)},children:"Copy JSONL"})]}):null,hr==="graph"?r.jsxs("div",{className:"tab_bar_controls",children:[r.jsx("button",{className:`seg_action ${da?"active":""}`,onClick:()=>gf(h=>!h),children:"Subflows"}),r.jsx("button",{className:`seg_action ${ul?"active":""}`,onClick:()=>fa(h=>!h),children:"Path"}),fd.length?r.jsx("select",{className:"mono seg_select",value:xo,onChange:h=>la(String(h.target.value||"")),disabled:!!Gs.trim()||!S.trim()||_f,children:fd.map(h=>r.jsx("option",{value:h,children:h},h))}):null]}):null]}),hr==="overview"?r.jsx(Ok,{run_id:d,run:dn,run_state:ye,status_label:Fa||Uo||"unknown",workflow_label_by_id:Zt,root_run_id:p,subrun_ids:Ni,session_id:ks,records_count:kt.length,records:kt,child_records_count:tr.length,provider_activities:ds,attachments_count:vo.length,latest_summary:Pl,wait_state:Ot,summary_generating:Ru,summary_error:vc,on_generate_summary:()=>void Uf(),on_open_runtime:()=>{const h=String(d||"").trim();h&&(Na(h),_l(h),ba("run")),xc("artifacts"),t("runtime")},on_open_subrun:h=>void ui(h,{root_run_id:p||d||h}),on_answer_wait:()=>Ls(""),workspace_root:ia,on_reveal_workspace:()=>void Mf(),run_artifacts:yh,run_artifacts_loading:vh,run_artifacts_error:Eu,on_preview_run_artifact:h=>void $l(h),on_download_run_artifact:h=>void Cl(h),timeline_items:Ba,node_index:Ri,attachments:vo,attachments_loading:cf,attachments_error:df,attachments_ready:!!fc.trim(),on_refresh_attachments:()=>void Ju(),on_preview_attachment:h=>void Tf(h),on_download_attachment:h=>void Nl(h),on_copy:h=>void kl(h)}):null,hr==="ledger"?r.jsx(r.Fragment,{children:al==="steps"?r.jsxs("div",{className:"log log_scroll",children:[Dl.map(h=>r.jsx(Ik,{item:h,open:hh[h.id]===!0,on_toggle:()=>bu(j=>({...j,[h.id]:!j[h.id]})),response_open:ju[h.id]===!0,on_toggle_response:()=>af(j=>({...j,[h.id]:!j[h.id]})),node_index:Ri,on_copy:j=>void kl(j)},h.id)),Dl.length?null:r.jsx("div",{className:"empty_state_inline",children:"(no ledger items)"})]}):r.jsx("div",{className:"log log_scroll",children:r.jsx(kb,{items:Fc.items,title:"Agent",subtitle:Fc.node_id?`node_id: ${Fc.node_id}`:"Live per-effect trace (LLM/tool calls).",subRunId:Pr,onOpenSubRun:Pr&&Pr!==d.trim()?()=>{m(Pr),Pa(Pr)}:void 0})})}):null,hr==="graph"?r.jsxs(r.Fragment,{children:[pc?r.jsxs("div",{className:"log_item log_item_danger",children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{children:"graph error"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:pc})]}):null,_f?r.jsxs("div",{className:"log_item log_item_info",children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{children:"loading"}),r.jsx("span",{className:"mono",children:Gs.trim()?Gs.trim():xo})]}),r.jsx("div",{className:"body mono",children:"Loading graph…"})]}):null,r.jsx("div",{className:"graph_panel",children:r.jsx(Xk,{flow:bo,flow_by_id:ua,expand_subflows:da,simplify:!0,prefer_vertical:!0,vertical_compact:.78,schedule_next_in:pd,schedule_interval:Fo,node_last_ms:Qf,active_node_id:Zf,recent_nodes:pf,visited_nodes:yf,highlight_path:ul,now_ms:Mu})})]}):null,r.jsxs(Ja,{open:ff,title:mf||"Attachment",onClose:()=>{_c(!1),aa(""),gc(""),to(!1)},actions:r.jsx(r.Fragment,{children:r.jsx("button",{className:"btn",onClick:()=>{_c(!1),aa(""),gc(""),to(!1)},children:"Close"})}),children:[Ps?r.jsx("div",{className:"mono muted",style:{fontSize:"var(--font-size-sm)",marginBottom:"8px"},children:"Loading…"}):null,hf?r.jsx("div",{className:"mono",style:{color:"rgba(239, 68, 68, 0.9)",fontSize:"var(--font-size-sm)",marginBottom:"8px"},children:hf}):null,r.jsx("pre",{className:"mono",style:{whiteSpace:"pre-wrap",maxHeight:"62vh",overflow:"auto",margin:0},children:xh||"(empty)"})]}),hr==="chat"?r.jsxs("div",{className:"ask_tab log_scroll",style:{marginTop:"6px"},children:[r.jsxs("div",{className:"ask_header",children:[r.jsx("span",{className:"ask_title",children:"Ask about this run"}),r.jsx("span",{className:"chip muted",title:"Model comes from Settings → Assistant (blank = gateway default)",children:(n.maintenance_ai_provider.trim()||"gateway")+" / "+(n.maintenance_ai_model.trim()||"default")}),r.jsx("span",{className:"pane_spacer"}),r.jsx("span",{className:"ask_hint",children:"Read-only · grounded in this run + subflows"})]}),r.jsxs("details",{className:"ask_manage",children:[r.jsx("summary",{children:"History & export"}),r.jsxs("div",{className:"field",style:{marginTop:"10px"},children:[r.jsxs("div",{className:"actions",style:{justifyContent:"space-between",alignItems:"center",gap:"10px",flexWrap:"wrap",marginTop:0},children:[r.jsx("div",{style:{flex:1,minWidth:260},children:r.jsx(uu,{value:yu,options:cc,placeholder:Nr?"Loading…":cc.length?"Select a saved discussion…":"(none saved)",disabled:!d.trim()||!k||!cc.length,loading:Nr,searchable:!0,clearable:!0,onChange:h=>{ac(h),po("")}})}),r.jsxs("div",{className:"actions",style:{justifyContent:"flex-end",marginTop:0},children:[r.jsx("button",{className:"btn",type:"button",disabled:!yu.trim()||!k||sa,onClick:()=>void Hf(),children:sa?"Loading…":"Load"}),r.jsx("button",{className:"btn",type:"button",disabled:!je.length||B||it||sa,onClick:()=>{Fe([]),ss(""),Lr(""),Lt(""),Dt(""),hn("")},children:"Clear"}),r.jsx("button",{className:"btn",type:"button",onClick:()=>void El(),disabled:!d.trim()||!k||Nr,children:Nr?"Refreshing…":"Refresh"})]})]}),r.jsxs("div",{className:"actions",style:{justifyContent:"flex-end",marginTop:"8px",flexWrap:"wrap"},children:[r.jsx("button",{className:"btn",type:"button",disabled:!je.length||!d.trim()||!k||it||!vu,onClick:()=>void Ch(),title:vu?"":"No changes since last save",children:it?"Saving…":!vu&&sr?"Saved":"Save discussion"}),r.jsx("button",{className:"btn",type:"button",disabled:!je.length,onClick:()=>Pc("download"),children:"Export Markdown"}),r.jsx("button",{className:"btn",type:"button",disabled:!je.length,onClick:()=>Pc("copy"),children:we==="copied"?"Copied":we==="failed"?"Copy failed":"Copy Markdown"})]}),sr?r.jsxs("div",{className:"chat_hint",children:["Last saved: ",Ko(sr)]}):null,Bt?r.jsx("div",{className:"chat_hint chat_hint_danger",children:Bt}):null,sf?r.jsx("div",{className:"chat_hint chat_hint_danger",children:sf}):null,na?r.jsx("div",{className:"chat_hint chat_hint_danger",children:na}):null]})]}),Qi?r.jsxs("div",{className:"log_item log_item_danger",children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{children:"error"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:Qi})]}):null,ho?r.jsxs("div",{className:"log_item log_item_danger",children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{children:"voice"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:ho})]}):null,r.jsx("div",{className:"chat_messages",style:{marginTop:"10px"},children:r.jsx(Fv,{messages:je,className:"log_scroll",messageProps:Un.tts_supported&&k&&go.trim()?{onSpeakToggle:rd,getSpeakState:Ia,jsonCollapseAfterDepth:4}:{jsonCollapseAfterDepth:4},empty:r.jsx("div",{className:"chat_empty_hint",children:"Ask about this run (why failed, which tools, what happened in subflows)."})})}),r.jsx("div",{className:"chat_composer",style:{marginTop:"10px"},children:r.jsx(Bv,{ref:mt,value:oc,onChange:ss,onSubmit:()=>void Wf(),placeholder:"Ask about this run…",disabled:!d.trim()||!k||B,busy:B||Un.voice_ptt_busy,busyLabel:Un.voice_ptt_busy?"Transcribing…":"Thinking…",rows:3,sendButtonClassName:"btn primary",actions:r.jsxs("button",{className:`btn btn_icon voice_btn${Un.voice_ptt_recording?" danger":""}`,type:"button",disabled:!k||!Do.trim()||!go.trim()||B||Un.voice_ptt_busy||!Un.voice_ptt_supported,title:Un.voice_ptt_supported?Un.voice_ptt_busy?"Transcribing…":Un.voice_ptt_recording?"Recording… release to transcribe":"Hold to talk (record + transcribe)":"Voice recording is not supported in this browser","aria-label":"Voice input",onPointerDown:h=>{var j,$;if(!(!k||!Do.trim()||!go.trim()||B||Un.voice_ptt_busy||!Un.voice_ptt_supported)){h.preventDefault();try{($=(j=h.currentTarget)==null?void 0:j.setPointerCapture)==null||$.call(j,h.pointerId)}catch{}Un.start_voice_ptt_recording()}},onPointerUp:h=>{h.preventDefault(),Un.stop_voice_ptt_recording()},onPointerCancel:h=>{h.preventDefault(),Un.stop_voice_ptt_recording()},children:[r.jsx(Nn,{name:Un.voice_ptt_recording?"x":"mic",size:16}),Un.voice_ptt_busy?"Transcribing…":Un.voice_ptt_recording?"Recording…":"Voice"]})})})]}):null,d.trim()?r.jsxs("div",{className:`status_bar ${fo?"pulse":""}`,children:[r.jsx("strong",{children:"Run"}),":"," ",r.jsx("span",{className:"mono",children:Fa||Uo||"unknown"}),_d&&pd?r.jsxs("span",{className:"mono muted",children:[" • next in ",pd]}):null,bi?r.jsxs("span",{className:"mono muted",children:[" • ",bi]}):null]}):null]})]})]})}):null,r.jsxs(Ja,{open:jh,title:$o||"Artifact",onClose:()=>{Bs(!1),ai(""),gr(""),Eo(!1),li(null),vn&&(URL.revokeObjectURL(vn),Or(""))},actions:r.jsx("button",{className:"btn",onClick:()=>{Bs(!1),ai(""),gr(""),Eo(!1),li(null),vn&&(URL.revokeObjectURL(vn),Or(""))},children:"Close"}),children:[jf?r.jsx("div",{className:"mono muted",style:{fontSize:"var(--font-size-sm)",marginBottom:"8px"},children:"Loading…"}):null,Nc?r.jsx("div",{className:"mono",style:{color:"rgba(239, 68, 68, 0.9)",fontSize:"var(--font-size-sm)",marginBottom:"8px"},children:Nc}):null,Ai==="image"&&vn?r.jsx("img",{className:"runtime_preview_media",src:vn,alt:$o||"Artifact preview"}):Ai==="audio"&&vn?r.jsx("audio",{className:"runtime_preview_media",controls:!0,src:vn}):Ai==="video"&&vn?r.jsx("video",{className:"runtime_preview_media",controls:!0,src:vn}):r.jsx(lw,{artifact:Ti,text:kc||"(empty)",className:"runtime_preview_text"})]}),Js?r.jsxs(Ja,{open:Js,title:"Edit schedule",onClose:()=>{nr(!1),Xi(""),In(!0),$n(""),Ji(!1)},actions:r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn",onClick:()=>{nr(!1),Xi(""),In(!0),$n(""),Ji(!1)},disabled:Ce||ts,children:"Back"}),r.jsx("button",{className:"btn primary",onClick:async()=>{await Oc({interval:Yi,apply_immediately:Qo})||(nr(!1),$n(""),Ji(!1))},disabled:Ce||ts||!Yi.trim(),children:"Save"})]}),children:[es?r.jsxs("div",{className:"log_item",style:{borderColor:"rgba(239, 68, 68, 0.35)",marginBottom:"10px"},children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{className:"mono",children:"error"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:es})]}):null,r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Interval"}),r.jsx("input",{className:"mono",value:Yi,onChange:h=>Xi(String(h.target.value||"")),placeholder:"20m / 1h / 0.5s / 250ms",disabled:Ce||ts}),r.jsxs("div",{className:"mono muted",style:{fontSize:"var(--font-size-sm)"},children:["Accepted units: ",r.jsx("span",{className:"mono",children:"ms"}),", ",r.jsx("span",{className:"mono",children:"s"}),", ",r.jsx("span",{className:"mono",children:"m"}),","," ",r.jsx("span",{className:"mono",children:"h"}),", ",r.jsx("span",{className:"mono",children:"d"}),". This updates the existing scheduled run in place (no context loss)."]})]}),r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Quick picks"}),r.jsx("div",{className:"actions",style:{gap:"8px",flexWrap:"wrap"},children:["15m","30m","1h","2h","6h","1d"].map(h=>r.jsx("button",{className:"btn",onClick:()=>Xi(h),disabled:Ce||ts,children:h},h))})]}),r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Apply"}),r.jsxs("label",{style:{display:"flex",gap:"10px",alignItems:"center"},children:[r.jsx("input",{type:"checkbox",checked:Qo,onChange:h=>In(!!h.target.checked),disabled:Ce||ts}),"Apply immediately (recompute next run from now if waiting)"]})]})]}):null,Kn?r.jsxs(Ja,{open:Kn,title:"Compact scheduled context",onClose:()=>{Hr(!1),wi(""),Sr(!1)},actions:r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn",onClick:()=>{Hr(!1),wi(""),Sr(!1)},disabled:Ce||ns,children:"Cancel"}),r.jsx("button",{className:"btn primary",onClick:async()=>{await Bf({preserve_recent:rr,compression_mode:dr,focus:Zi})||(Hr(!1),wi(""),Sr(!1))},disabled:Ce||ns,children:ns?"Compacting…":"Compact"})]}),children:[sl?r.jsxs("div",{className:"log_item",style:{borderColor:"rgba(239, 68, 68, 0.35)",marginBottom:"10px"},children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{className:"mono",children:"error"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:sl})]}):null,r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Preserve recent turns"}),r.jsx("input",{type:"number",min:1,value:String(rr),onChange:h=>Rs(Math.max(1,parseInt(h.target.value||"6",10)||6)),disabled:Ce||ns})]}),r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Mode"}),r.jsxs("select",{value:dr,onChange:h=>ea(h.target.value),disabled:Ce||ns,children:[r.jsx("option",{value:"light",children:"light"}),r.jsx("option",{value:"standard",children:"standard"}),r.jsx("option",{value:"heavy",children:"heavy"})]})]}),r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Focus (optional)"}),r.jsx("input",{className:"mono",value:Zi,onChange:h=>en(String(h.target.value||"")),placeholder:"e.g. important decisions, next steps…",disabled:Ce||ns})]})]}):null,ta?r.jsxs(Ja,{open:ta,title:Zs==="cancel"?"Cancel run":cs?"Suspend schedule":"Pause run",onClose:()=>{ws(!1),kr(""),Vr("")},actions:r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn",onClick:()=>{ws(!1),kr(""),Vr("")},disabled:Ce||St,children:"Back"}),r.jsx("button",{className:`btn ${Zs==="cancel"?"danger":"primary"}`,onClick:async()=>{Vr("");const h=await Ff(Zs,{reason:qr});if(h){Vr(h);return}ws(!1),kr(""),Vr("")},disabled:Ce||St,children:Zs==="pause"?cs?"Suspend":"Pause":"Cancel"})]}),children:[xs?r.jsxs("div",{className:"log_item",style:{borderColor:"rgba(239, 68, 68, 0.35)",marginBottom:"10px"},children:[r.jsxs("div",{className:"meta",children:[r.jsx("span",{className:"mono",children:"error"}),r.jsx("span",{className:"mono",children:wt()})]}),r.jsx("div",{className:"body mono",children:xs})]}):null,r.jsxs("div",{className:"field",children:[r.jsx("label",{children:"Reason (optional)"}),r.jsx("input",{className:"mono",value:qr,onChange:h=>kr(h.target.value),placeholder:"reason…"})]})]}):null,id?r.jsxs(Ja,{open:id,title:od,onClose:()=>{$r&&Ls($r)},actions:r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn",onClick:()=>{Os("ledger"),t("observe"),$r&&Ls($r)},disabled:!d.trim(),children:"Open ledger"}),r.jsx("button",{className:"btn",onClick:()=>$r&&Ls($r),disabled:St,children:"Dismiss"}),io.length?r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn danger",disabled:St,onClick:()=>Al({approved:!1}),children:"Reject"}),r.jsx("button",{className:"btn",disabled:St,onClick:()=>Al({approved:!0}),children:"Approve only"}),r.jsx("button",{className:"btn primary",disabled:!Ma||St,onClick:()=>qf(io),children:"Approve and execute"})]}):null]}),children:[r.jsxs("div",{className:"wait_context_panel",children:[r.jsxs("div",{className:"wait_context_header",children:[r.jsxs("div",{children:[r.jsx("div",{className:"run_hero_eyebrow",children:"What you need to do"}),r.jsx("strong",{children:od}),r.jsx("p",{children:ad})]}),r.jsx(rl,{status:Dn||"waiting"})]}),Da?r.jsxs("div",{className:`wait_request_card ${Vs?"":"inferred"}`,children:[r.jsx("span",{children:$h}),r.jsx(nv,{metadata:Yf}),r.jsx(pi,{text:Da}),Vs?null:r.jsx("p",{className:"wait_context_note",children:"The runtime did not attach a specific question to this wait. This is inferred from the run input; verify the session turns and workflow steps before answering."})]}):r.jsx("div",{className:"warn_callout",children:"This wait did not provide a clear prompt or recoverable prior user request. Review the full run input and recent workflow steps before submitting a response."}),ld.length?r.jsxs("section",{className:"wait_context_block wait_conversation_context",children:[r.jsx("span",{children:"Recent session turns"}),r.jsx("div",{className:"wait_turn_list",children:ld.map((h,j)=>r.jsxs("div",{className:`wait_turn_row role_${h.role.replace(/[^a-z0-9_-]+/g,"_")}`,children:[r.jsxs("div",{className:"wait_turn_meta",children:[r.jsx("strong",{children:h.role==="assistant"?"Assistant":h.role==="user"||h.role==="human"?"User":h.role}),h.ts?r.jsx("span",{className:"mono muted",children:Ko(h.ts)}):null]}),r.jsx(nv,{metadata:h.runtime_metadata}),r.jsx(pi,{text:ut(h.text,{max_chars:1200,max_lines:10})})]},`${h.role}:${j}`))})]}):null,r.jsxs("div",{className:"artifact_detail_grid",children:[r.jsxs("div",{children:[r.jsx("span",{children:"Workflow"}),r.jsx("strong",{children:hi(zo,Zt)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Run"}),r.jsx("strong",{className:"mono",children:Et(d.trim(),24)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Node"}),r.jsx("strong",{className:"mono",children:zo.current_node||String((Cr==null?void 0:Cr.node_id)||"—")})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Elapsed"}),r.jsx("strong",{children:rc(zo)})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Session"}),r.jsx("strong",{className:"mono",children:zo.session_id?Et(String(zo.session_id),18):"—"})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Wait key"}),r.jsx("strong",{className:"mono",children:Et($r,28)})]})]}),cd?r.jsxs("details",{className:"runtime_raw_details wait_full_input_details",open:!Da,children:[r.jsx("summary",{className:"mono muted",children:"Full run input JSON"}),r.jsx("div",{className:"wait_shared_json",children:r.jsx(ps,{value:Xf,collapseAfterDepth:4,showCopy:!0})})]}):null,r.jsxs("section",{className:"wait_context_block",children:[r.jsx("span",{children:"Recent workflow steps leading to this wait"}),r.jsxs("div",{className:"wait_event_list",children:[Ic.map(h=>r.jsxs("div",{className:"wait_event_row",children:[r.jsxs("span",{className:"mono",children:["#",h.cursor]}),r.jsx("strong",{children:h.summary||h.effect_type||h.status||"event"}),r.jsx("span",{className:"mono muted",children:[h.node_id,h.status,Ko(h.ts)].filter(Boolean).join(" · ")})]},`${h.cursor}:${h.node_id}:${h.status}`)),Ic.length?null:r.jsx("div",{className:"empty_state_inline",children:"No ledger context is loaded. Open the ledger before deciding."})]})]})]}),io.length?r.jsxs("div",{className:"wait_action_panel",children:[r.jsx("div",{className:"wait_action_intro",children:"Approve and execute runs the listed tool request through your configured worker. Approve only sends approval without local execution. Reject returns a denial. Cancel run stops the whole workflow run."}),r.jsx("div",{className:"wait_tool_list",children:io.map((h,j)=>r.jsxs("div",{className:"wait_tool_card",children:[r.jsxs("div",{className:"wait_tool_header",children:[r.jsx("strong",{children:String((h==null?void 0:h.name)||"tool")}),r.jsxs("div",{className:"wait_tool_badges",children:[r.jsx("span",{className:"chip mono warn",children:"approval"}),ew(h).map($=>r.jsxs("span",{className:"chip mono muted",title:Qv,children:[$,"~"]},$))]})]}),r.jsx("div",{className:"wait_tool_args",children:r.jsx(ps,{value:(h==null?void 0:h.arguments)||{},collapseAfterDepth:3,showCopy:!0})})]},`${String((h==null?void 0:h.name)||"tool")}:${j}`))}),Ma?null:r.jsx("div",{className:"warn_callout",children:"No tool worker is configured, so Observer cannot execute these calls directly."}),r.jsx("div",{className:"actions",children:r.jsx("button",{className:"btn danger",onClick:()=>void Ns(d.trim(),"Cancelled from wait prompt"),disabled:!d.trim()||St,children:"Cancel whole run"})}),r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"mono muted",children:"Diagnostics"}),r.jsx("div",{className:"wait_shared_json",children:r.jsx(ps,{value:Ot||{},collapseAfterDepth:3,showCopy:!0})})]})]}):r.jsxs("div",{className:"wait_action_panel",children:[r.jsx("div",{className:"wait_action_intro",children:"Submit only when the request above is clear. The response resumes this wait only; Cancel run attempts to stop the whole workflow and prevent further work."}),r.jsx("div",{className:"wait_prompt_text",children:Da||"No explicit prompt was provided. Open the ledger for context before responding."}),r.jsx(Rk,{wait:Ot,disabled:St,on_submit:h=>Al({response:h})}),r.jsx("div",{className:"actions",children:r.jsx("button",{className:"btn danger",onClick:()=>void Ns(d.trim(),"Cancelled from wait prompt"),disabled:!d.trim()||St,children:"Cancel whole run"})}),r.jsxs("details",{className:"runtime_raw_details",children:[r.jsx("summary",{className:"mono muted",children:"Diagnostics"}),r.jsx("div",{className:"wait_shared_json",children:r.jsx(ps,{value:Ot||{},collapseAfterDepth:3,showCopy:!0})})]})]})]}):null]})]})]})}if("serviceWorker"in navigator){window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js").then(t=>t.update()).catch(()=>{})});let e=!1;navigator.serviceWorker.addEventListener("controllerchange",()=>{e||(e=!0,window.location.reload())})}ob.createRoot(document.getElementById("root")).render(r.jsx(pe.StrictMode,{children:r.jsx(iM,{})}));
|
|
141
|
+
//# sourceMappingURL=index-1Y-bFEjo.js.map
|