(function(){const g=document.createElement("link").relList;if(g&&g.supports&&g.supports("modulepreload"))return;for(const R of document.querySelectorAll('link[rel="modulepreload"]'))O(R);new MutationObserver(R=>{for(const z of R)if(z.type==="childList")for(const K of z.addedNodes)K.tagName==="LINK"&&K.rel==="modulepreload"&&O(K)}).observe(document,{childList:!0,subtree:!0});function h(R){const z={};return R.integrity&&(z.integrity=R.integrity),R.referrerPolicy&&(z.referrerPolicy=R.referrerPolicy),R.crossOrigin==="use-credentials"?z.credentials="include":R.crossOrigin==="anonymous"?z.credentials="omit":z.credentials="same-origin",z}function O(R){if(R.ep)return;R.ep=!0;const z=h(R);fetch(R.href,z)}})();function zc(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Oi={exports:{}},Xs={},zi={exports:{}},he={};var mc;function vf(){if(mc)return he;mc=1;var i=Symbol.for("react.element"),g=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),O=Symbol.for("react.strict_mode"),R=Symbol.for("react.profiler"),z=Symbol.for("react.provider"),K=Symbol.for("react.context"),te=Symbol.for("react.forward_ref"),U=Symbol.for("react.suspense"),I=Symbol.for("react.memo"),q=Symbol.for("react.lazy"),L=Symbol.iterator;function H(m){return m===null||typeof m!="object"?null:(m=L&&m[L]||m["@@iterator"],typeof m=="function"?m:null)}var ue={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Re=Object.assign,Z={};function re(m,k,G){this.props=m,this.context=k,this.refs=Z,this.updater=G||ue}re.prototype.isReactComponent={},re.prototype.setState=function(m,k){if(typeof m!="object"&&typeof m!="function"&&m!=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,m,k,"setState")},re.prototype.forceUpdate=function(m){this.updater.enqueueForceUpdate(this,m,"forceUpdate")};function W(){}W.prototype=re.prototype;function ie(m,k,G){this.props=m,this.context=k,this.refs=Z,this.updater=G||ue}var je=ie.prototype=new W;je.constructor=ie,Re(je,re.prototype),je.isPureReactComponent=!0;var ze=Array.isArray,Te=Object.prototype.hasOwnProperty,Ie={current:null},$e={key:!0,ref:!0,__self:!0,__source:!0};function se(m,k,G){var ce,de={},fe=null,ye=null;if(k!=null)for(ce in k.ref!==void 0&&(ye=k.ref),k.key!==void 0&&(fe=""+k.key),k)Te.call(k,ce)&&!$e.hasOwnProperty(ce)&&(de[ce]=k[ce]);var ge=arguments.length-2;if(ge===1)de.children=G;else if(1>>1,k=A[m];if(0>>1;mR(de,D))feR(ye,de)?(A[m]=ye,A[fe]=D,m=fe):(A[m]=de,A[ce]=D,m=ce);else if(feR(ye,D))A[m]=ye,A[fe]=D,m=fe;else break e}}return V}function R(A,V){var D=A.sortIndex-V.sortIndex;return D!==0?D:A.id-V.id}if(typeof performance=="object"&&typeof performance.now=="function"){var z=performance;i.unstable_now=function(){return z.now()}}else{var K=Date,te=K.now();i.unstable_now=function(){return K.now()-te}}var U=[],I=[],q=1,L=null,H=3,ue=!1,Re=!1,Z=!1,re=typeof setTimeout=="function"?setTimeout:null,W=typeof clearTimeout=="function"?clearTimeout:null,ie=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function je(A){for(var V=h(I);V!==null;){if(V.callback===null)O(I);else if(V.startTime<=A)O(I),V.sortIndex=V.expirationTime,g(U,V);else break;V=h(I)}}function ze(A){if(Z=!1,je(A),!Re)if(h(U)!==null)Re=!0,Me(Te);else{var V=h(I);V!==null&&pe(ze,V.startTime-A)}}function Te(A,V){Re=!1,Z&&(Z=!1,W(se),se=-1),ue=!0;var D=H;try{for(je(V),L=h(U);L!==null&&(!(L.expirationTime>V)||A&&!tt());){var m=L.callback;if(typeof m=="function"){L.callback=null,H=L.priorityLevel;var k=m(L.expirationTime<=V);V=i.unstable_now(),typeof k=="function"?L.callback=k:L===h(U)&&O(U),je(V)}else O(U);L=h(U)}if(L!==null)var G=!0;else{var ce=h(I);ce!==null&&pe(ze,ce.startTime-V),G=!1}return G}finally{L=null,H=D,ue=!1}}var Ie=!1,$e=null,se=-1,Le=5,We=-1;function tt(){return!(i.unstable_now()-WeA||125m?(A.sortIndex=D,g(I,A),h(U)===null&&A===h(I)&&(Z?(W(se),se=-1):Z=!0,pe(ze,D-m))):(A.sortIndex=k,g(U,A),Re||ue||(Re=!0,Me(Te))),A},i.unstable_shouldYield=tt,i.unstable_wrapCallback=function(A){var V=H;return function(){var D=H;H=V;try{return A.apply(this,arguments)}finally{H=D}}}})(Ui)),Ui}var yc;function wf(){return yc||(yc=1,Fi.exports=Sf()),Fi.exports}var xc;function jf(){if(xc)return Lt;xc=1;var i=Ji(),g=wf();function h(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),U=Object.prototype.hasOwnProperty,I=/^[: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]*$/,q={},L={};function H(e){return U.call(L,e)?!0:U.call(q,e)?!1:I.test(e)?L[e]=!0:(q[e]=!0,!1)}function ue(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function Re(e,t,n,r){if(t===null||typeof t>"u"||ue(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function Z(e,t,n,r,s,l,u){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=s,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=l,this.removeEmptyString=u}var re={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){re[e]=new Z(e,0,!1,e,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];re[t]=new Z(t,1,!1,e[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(e){re[e]=new Z(e,2,!1,e.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){re[e]=new Z(e,2,!1,e,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){re[e]=new Z(e,3,!1,e.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(e){re[e]=new Z(e,3,!0,e,null,!1,!1)}),["capture","download"].forEach(function(e){re[e]=new Z(e,4,!1,e,null,!1,!1)}),["cols","rows","size","span"].forEach(function(e){re[e]=new Z(e,6,!1,e,null,!1,!1)}),["rowSpan","start"].forEach(function(e){re[e]=new Z(e,5,!1,e.toLowerCase(),null,!1,!1)});var W=/[\-:]([a-z])/g;function ie(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(W,ie);re[t]=new Z(t,1,!1,e,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(W,ie);re[t]=new Z(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(W,ie);re[t]=new Z(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(e){re[e]=new Z(e,1,!1,e.toLowerCase(),null,!1,!1)}),re.xlinkHref=new Z("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(e){re[e]=new Z(e,1,!1,e.toLowerCase(),null,!0,!0)});function je(e,t,n,r){var s=re.hasOwnProperty(t)?re[t]:null;(s!==null?s.type!==0:r||!(2d||s[u]!==l[d]){var p=` `+s[u].replace(" at new "," at ");return e.displayName&&p.includes("")&&(p=p.replace("",e.displayName)),p}while(1<=u&&0<=d);break}}}finally{G=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?k(e):""}function de(e){switch(e.tag){case 5:return k(e.type);case 16:return k("Lazy");case 13:return k("Suspense");case 19:return k("SuspenseList");case 0:case 2:case 15:return e=ce(e.type,!1),e;case 11:return e=ce(e.type.render,!1),e;case 1:return e=ce(e.type,!0),e;default:return""}}function fe(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case $e:return"Fragment";case Ie:return"Portal";case Le:return"Profiler";case se:return"StrictMode";case Je:return"Suspense";case nt:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case tt:return(e.displayName||"Context")+".Consumer";case We:return(e._context.displayName||"Context")+".Provider";case jt:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ve:return t=e.displayName||null,t!==null?t:fe(e.type)||"Memo";case Me:t=e._payload,e=e._init;try{return fe(e(t))}catch{}}return null}function ye(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return fe(t);case 8:return t===se?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function ge(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function ee(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function Ce(e){var t=ee(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var s=n.get,l=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return s.call(this)},set:function(u){r=""+u,l.call(this,u)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(u){r=""+u},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Dt(e){e._valueTracker||(e._valueTracker=Ce(e))}function Hn(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=ee(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function Rn(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Tn(e,t){var n=t.checked;return D({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function rr(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=ge(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Kt(e,t){t=t.checked,t!=null&&je(e,"checked",t,!1)}function qt(e,t){Kt(e,t);var n=ge(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?fn(e,t.type,n):t.hasOwnProperty("defaultValue")&&fn(e,t.type,ge(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function bn(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function fn(e,t,n){(t!=="number"||Rn(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Ot=Array.isArray;function Gt(e,t,n,r){if(e=e.options,t){t={};for(var s=0;s"+t.valueOf().toString()+"",t=Yt.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function zt(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}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},Ue=["Webkit","ms","Moz","O"];Object.keys(pn).forEach(function(e){Ue.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),pn[t]=pn[e]})});function lt(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||pn.hasOwnProperty(e)&&pn[e]?(""+t).trim():t+"px"}function hn(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,s=lt(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,s):e[n]=s}}var gn=D({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 Xt(e,t){if(t){if(gn[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(h(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(h(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(h(61))}if(t.style!=null&&typeof t.style!="object")throw Error(h(62))}}function Zt(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var kt=null;function Ln(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var en=null,$t=null,Ft=null;function Mr(e){if(e=zs(e)){if(typeof en!="function")throw Error(h(280));var t=e.stateNode;t&&(t=vo(t),en(e.stateNode,e.type,t))}}function be(e){$t?Ft?Ft.push(e):Ft=[e]:$t=e}function ir(){if($t){var e=$t,t=Ft;if(Ft=$t=null,Mr(e),t)for(e=0;e>>=0,e===0?32:31-(qr(e)/Gr|0)|0}var Ut=64,xt=4194304;function sn(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Ye(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,s=e.suspendedLanes,l=e.pingedLanes,u=n&268435455;if(u!==0){var d=u&~s;d!==0?r=sn(d):(l&=u,l!==0&&(r=sn(l)))}else u=n&~s,u!==0?r=sn(u):l!==0&&(r=sn(l));if(r===0)return 0;if(t!==0&&t!==r&&(t&s)===0&&(s=r&-r,l=t&-t,s>=l||s===16&&(l&4194240)!==0))return t;if((r&4)!==0&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0n;n++)t.push(e);return t}function _n(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-ut(t),e[t]=n}function f(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0=Ps),la=" ",ia=!1;function aa(e,t){switch(e){case"keyup":return dd.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function ua(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Zr=!1;function md(e,t){switch(e){case"compositionend":return ua(t);case"keypress":return t.which!==32?null:(ia=!0,la);case"textInput":return e=t.data,e===la&&ia?null:e;default:return null}}function pd(e,t){if(Zr)return e==="compositionend"||!gl&&aa(e,t)?(e=ea(),oo=cl=pr=null,Zr=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=ga(n)}}function ya(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ya(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function xa(){for(var e=window,t=Rn();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Rn(e.document)}return t}function xl(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function jd(e){var t=xa(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ya(n.ownerDocument.documentElement,n)){if(r!==null&&xl(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var s=n.textContent.length,l=Math.min(r.start,s);r=r.end===void 0?l:Math.min(r.end,s),!e.extend&&l>r&&(s=r,r=l,l=s),s=va(n,l);var u=va(n,r);s&&u&&(e.rangeCount!==1||e.anchorNode!==s.node||e.anchorOffset!==s.offset||e.focusNode!==u.node||e.focusOffset!==u.offset)&&(t=t.createRange(),t.setStart(s.node,s.offset),e.removeAllRanges(),l>r?(e.addRange(t),e.extend(u.node,u.offset)):(t.setEnd(u.node,u.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n=document.documentMode,es=null,_l=null,As=null,Sl=!1;function _a(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Sl||es==null||es!==Rn(r)||(r=es,"selectionStart"in r&&xl(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),As&&Ts(As,r)||(As=r,r=po(_l,"onSelect"),0os||(e.current=Il[os],Il[os]=null,os--)}function Ae(e,t){os++,Il[os]=e.current,e.current=t}var yr={},ct=vr(yr),Mt=vr(!1),Or=yr;function ls(e,t){var n=e.type.contextTypes;if(!n)return yr;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var s={},l;for(l in n)s[l]=t[l];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=s),s}function Rt(e){return e=e.childContextTypes,e!=null}function yo(){Oe(Mt),Oe(ct)}function Da(e,t,n){if(ct.current!==yr)throw Error(h(168));Ae(ct,t),Ae(Mt,n)}function Oa(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var s in r)if(!(s in t))throw Error(h(108,ye(e)||"Unknown",s));return D({},n,r)}function xo(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||yr,Or=ct.current,Ae(ct,e),Ae(Mt,Mt.current),!0}function za(e,t,n){var r=e.stateNode;if(!r)throw Error(h(169));n?(e=Oa(e,t,Or),r.__reactInternalMemoizedMergedChildContext=e,Oe(Mt),Oe(ct),Ae(ct,e)):Oe(Mt),Ae(Mt,n)}var qn=null,_o=!1,Ll=!1;function $a(e){qn===null?qn=[e]:qn.push(e)}function Dd(e){_o=!0,$a(e)}function xr(){if(!Ll&&qn!==null){Ll=!0;var e=0,t=j;try{var n=qn;for(j=1;e>=u,s-=u,Gn=1<<32-ut(t)+s|n<ne?(ot=X,X=null):ot=X.sibling;var we=C(_,X,S[ne],T);if(we===null){X===null&&(X=ot);break}e&&X&&we.alternate===null&&t(_,X),v=l(we,v,ne),Y===null?Q=we:Y.sibling=we,Y=we,X=ot}if(ne===S.length)return n(_,X),Fe&&$r(_,ne),Q;if(X===null){for(;nene?(ot=X,X=null):ot=X.sibling;var Pr=C(_,X,we.value,T);if(Pr===null){X===null&&(X=ot);break}e&&X&&Pr.alternate===null&&t(_,X),v=l(Pr,v,ne),Y===null?Q=Pr:Y.sibling=Pr,Y=Pr,X=ot}if(we.done)return n(_,X),Fe&&$r(_,ne),Q;if(X===null){for(;!we.done;ne++,we=S.next())we=M(_,we.value,T),we!==null&&(v=l(we,v,ne),Y===null?Q=we:Y.sibling=we,Y=we);return Fe&&$r(_,ne),Q}for(X=r(_,X);!we.done;ne++,we=S.next())we=$(X,_,ne,we.value,T),we!==null&&(e&&we.alternate!==null&&X.delete(we.key===null?ne:we.key),v=l(we,v,ne),Y===null?Q=we:Y.sibling=we,Y=we);return e&&X.forEach(function(gf){return t(_,gf)}),Fe&&$r(_,ne),Q}function Ke(_,v,S,T){if(typeof S=="object"&&S!==null&&S.type===$e&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case Te:e:{for(var Q=S.key,Y=v;Y!==null;){if(Y.key===Q){if(Q=S.type,Q===$e){if(Y.tag===7){n(_,Y.sibling),v=s(Y,S.props.children),v.return=_,_=v;break e}}else if(Y.elementType===Q||typeof Q=="object"&&Q!==null&&Q.$$typeof===Me&&Va(Q)===Y.type){n(_,Y.sibling),v=s(Y,S.props),v.ref=$s(_,Y,S),v.return=_,_=v;break e}n(_,Y);break}else t(_,Y);Y=Y.sibling}S.type===$e?(v=Wr(S.props.children,_.mode,T,S.key),v.return=_,_=v):(T=qo(S.type,S.key,S.props,null,_.mode,T),T.ref=$s(_,v,S),T.return=_,_=T)}return u(_);case Ie:e:{for(Y=S.key;v!==null;){if(v.key===Y)if(v.tag===4&&v.stateNode.containerInfo===S.containerInfo&&v.stateNode.implementation===S.implementation){n(_,v.sibling),v=s(v,S.children||[]),v.return=_,_=v;break e}else{n(_,v);break}else t(_,v);v=v.sibling}v=Ti(S,_.mode,T),v.return=_,_=v}return u(_);case Me:return Y=S._init,Ke(_,v,Y(S._payload),T)}if(Ot(S))return B(_,v,S,T);if(V(S))return b(_,v,S,T);ko(_,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,v!==null&&v.tag===6?(n(_,v.sibling),v=s(v,S),v.return=_,_=v):(n(_,v),v=Ri(S,_.mode,T),v.return=_,_=v),u(_)):n(_,v)}return Ke}var cs=Qa(!0),Wa=Qa(!1),Co=vr(null),No=null,ds=null,Ul=null;function Bl(){Ul=ds=No=null}function Hl(e){var t=Co.current;Oe(Co),e._currentValue=t}function bl(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function fs(e,t){No=e,Ul=ds=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&t)!==0&&(Tt=!0),e.firstContext=null)}function an(e){var t=e._currentValue;if(Ul!==e)if(e={context:e,memoizedValue:t,next:null},ds===null){if(No===null)throw Error(h(308));ds=e,No.dependencies={lanes:0,firstContext:e}}else ds=ds.next=e;return t}var Fr=null;function Vl(e){Fr===null?Fr=[e]:Fr.push(e)}function Ka(e,t,n,r){var s=t.interleaved;return s===null?(n.next=n,Vl(t)):(n.next=s.next,s.next=n),t.interleaved=n,Yn(e,r)}function Yn(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var _r=!1;function Ql(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function qa(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function Xn(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Sr(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,(Se&2)!==0){var s=r.pending;return s===null?t.next=t:(t.next=s.next,s.next=t),r.pending=t,Yn(e,n)}return s=r.interleaved,s===null?(t.next=t,Vl(r)):(t.next=s.next,s.next=t),r.interleaved=t,Yn(e,n)}function Eo(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,P(e,n)}}function Ga(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var s=null,l=null;if(n=n.firstBaseUpdate,n!==null){do{var u={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};l===null?s=l=u:l=l.next=u,n=n.next}while(n!==null);l===null?s=l=t:l=l.next=t}else s=l=t;n={baseState:r.baseState,firstBaseUpdate:s,lastBaseUpdate:l,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function Po(e,t,n,r){var s=e.updateQueue;_r=!1;var l=s.firstBaseUpdate,u=s.lastBaseUpdate,d=s.shared.pending;if(d!==null){s.shared.pending=null;var p=d,w=p.next;p.next=null,u===null?l=w:u.next=w,u=p;var N=e.alternate;N!==null&&(N=N.updateQueue,d=N.lastBaseUpdate,d!==u&&(d===null?N.firstBaseUpdate=w:d.next=w,N.lastBaseUpdate=p))}if(l!==null){var M=s.baseState;u=0,N=w=p=null,d=l;do{var C=d.lane,$=d.eventTime;if((r&C)===C){N!==null&&(N=N.next={eventTime:$,lane:0,tag:d.tag,payload:d.payload,callback:d.callback,next:null});e:{var B=e,b=d;switch(C=t,$=n,b.tag){case 1:if(B=b.payload,typeof B=="function"){M=B.call($,M,C);break e}M=B;break e;case 3:B.flags=B.flags&-65537|128;case 0:if(B=b.payload,C=typeof B=="function"?B.call($,M,C):B,C==null)break e;M=D({},M,C);break e;case 2:_r=!0}}d.callback!==null&&d.lane!==0&&(e.flags|=64,C=s.effects,C===null?s.effects=[d]:C.push(d))}else $={eventTime:$,lane:C,tag:d.tag,payload:d.payload,callback:d.callback,next:null},N===null?(w=N=$,p=M):N=N.next=$,u|=C;if(d=d.next,d===null){if(d=s.shared.pending,d===null)break;C=d,d=C.next,C.next=null,s.lastBaseUpdate=C,s.shared.pending=null}}while(!0);if(N===null&&(p=M),s.baseState=p,s.firstBaseUpdate=w,s.lastBaseUpdate=N,t=s.shared.interleaved,t!==null){s=t;do u|=s.lane,s=s.next;while(s!==t)}else l===null&&(s.shared.lanes=0);Hr|=u,e.lanes=u,e.memoizedState=M}}function Ja(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Jl.transition;Jl.transition={};try{e(!1),t()}finally{j=n,Jl.transition=r}}function hu(){return un().memoizedState}function Fd(e,t,n){var r=Cr(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},gu(e))vu(t,n);else if(n=Ka(e,t,n,r),n!==null){var s=wt();Pn(n,e,r,s),yu(n,t,r)}}function Ud(e,t,n){var r=Cr(e),s={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(gu(e))vu(t,s);else{var l=e.alternate;if(e.lanes===0&&(l===null||l.lanes===0)&&(l=t.lastRenderedReducer,l!==null))try{var u=t.lastRenderedState,d=l(u,n);if(s.hasEagerState=!0,s.eagerState=d,jn(d,u)){var p=t.interleaved;p===null?(s.next=s,Vl(t)):(s.next=p.next,p.next=s),t.interleaved=s;return}}catch{}n=Ka(e,t,s,r),n!==null&&(s=wt(),Pn(n,e,r,s),yu(n,t,r))}}function gu(e){var t=e.alternate;return e===He||t!==null&&t===He}function vu(e,t){Hs=To=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function yu(e,t,n){if((n&4194240)!==0){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,P(e,n)}}var Lo={readContext:an,useCallback:dt,useContext:dt,useEffect:dt,useImperativeHandle:dt,useInsertionEffect:dt,useLayoutEffect:dt,useMemo:dt,useReducer:dt,useRef:dt,useState:dt,useDebugValue:dt,useDeferredValue:dt,useTransition:dt,useMutableSource:dt,useSyncExternalStore:dt,useId:dt,unstable_isNewReconciler:!1},Bd={readContext:an,useCallback:function(e,t){return Un().memoizedState=[e,t===void 0?null:t],e},useContext:an,useEffect:iu,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,Ao(4194308,4,cu.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Ao(4194308,4,e,t)},useInsertionEffect:function(e,t){return Ao(4,2,e,t)},useMemo:function(e,t){var n=Un();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Un();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=Fd.bind(null,He,e),[r.memoizedState,e]},useRef:function(e){var t=Un();return e={current:e},t.memoizedState=e},useState:ou,useDebugValue:ri,useDeferredValue:function(e){return Un().memoizedState=e},useTransition:function(){var e=ou(!1),t=e[0];return e=$d.bind(null,e[1]),Un().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=He,s=Un();if(Fe){if(n===void 0)throw Error(h(407));n=n()}else{if(n=t(),st===null)throw Error(h(349));(Br&30)!==0||eu(r,t,n)}s.memoizedState=n;var l={value:n,getSnapshot:t};return s.queue=l,iu(nu.bind(null,r,l,e),[e]),r.flags|=2048,Qs(9,tu.bind(null,r,l,n,t),void 0,null),n},useId:function(){var e=Un(),t=st.identifierPrefix;if(Fe){var n=Jn,r=Gn;n=(r&~(1<<32-ut(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=bs++,0<\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=u.createElement(n,{is:r.is}):(e=u.createElement(n),n==="select"&&(u=e,r.multiple?u.multiple=!0:r.size&&(u.size=r.size))):e=u.createElementNS(e,n),e[$n]=t,e[Os]=r,$u(e,t,!1,!1),t.stateNode=e;e:{switch(u=Zt(n,r),n){case"dialog":De("cancel",e),De("close",e),s=r;break;case"iframe":case"object":case"embed":De("load",e),s=r;break;case"video":case"audio":for(s=0;svs&&(t.flags|=128,r=!0,Ws(l,!1),t.lanes=4194304)}else{if(!r)if(e=Mo(u),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Ws(l,!0),l.tail===null&&l.tailMode==="hidden"&&!u.alternate&&!Fe)return ft(t),null}else 2*_e()-l.renderingStartTime>vs&&n!==1073741824&&(t.flags|=128,r=!0,Ws(l,!1),t.lanes=4194304);l.isBackwards?(u.sibling=t.child,t.child=u):(n=l.last,n!==null?n.sibling=u:t.child=u,l.last=u)}return l.tail!==null?(t=l.tail,l.rendering=t,l.tail=t.sibling,l.renderingStartTime=_e(),t.sibling=null,n=Be.current,Ae(Be,r?n&1|2:n&1),t):(ft(t),null);case 22:case 23:return Ei(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&(t.mode&1)!==0?(Qt&1073741824)!==0&&(ft(t),t.subtreeFlags&6&&(t.flags|=8192)):ft(t),null;case 24:return null;case 25:return null}throw Error(h(156,t.tag))}function Gd(e,t){switch(Ol(t),t.tag){case 1:return Rt(t.type)&&yo(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return ms(),Oe(Mt),Oe(ct),Gl(),e=t.flags,(e&65536)!==0&&(e&128)===0?(t.flags=e&-65537|128,t):null;case 5:return Kl(t),null;case 13:if(Oe(Be),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(h(340));us()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Oe(Be),null;case 4:return ms(),null;case 10:return Hl(t.type._context),null;case 22:case 23:return Ei(),null;case 24:return null;default:return null}}var $o=!1,mt=!1,Jd=typeof WeakSet=="function"?WeakSet:Set,F=null;function hs(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Qe(e,t,r)}else n.current=null}function hi(e,t,n){try{n()}catch(r){Qe(e,t,r)}}var Bu=!1;function Yd(e,t){if(El=ro,e=xa(),xl(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var s=r.anchorOffset,l=r.focusNode;r=r.focusOffset;try{n.nodeType,l.nodeType}catch{n=null;break e}var u=0,d=-1,p=-1,w=0,N=0,M=e,C=null;t:for(;;){for(var $;M!==n||s!==0&&M.nodeType!==3||(d=u+s),M!==l||r!==0&&M.nodeType!==3||(p=u+r),M.nodeType===3&&(u+=M.nodeValue.length),($=M.firstChild)!==null;)C=M,M=$;for(;;){if(M===e)break t;if(C===n&&++w===s&&(d=u),C===l&&++N===r&&(p=u),($=M.nextSibling)!==null)break;M=C,C=M.parentNode}M=$}n=d===-1||p===-1?null:{start:d,end:p}}else n=null}n=n||{start:0,end:0}}else n=null;for(Pl={focusedElem:e,selectionRange:n},ro=!1,F=t;F!==null;)if(t=F,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,F=e;else for(;F!==null;){t=F;try{var B=t.alternate;if((t.flags&1024)!==0)switch(t.tag){case 0:case 11:case 15:break;case 1:if(B!==null){var b=B.memoizedProps,Ke=B.memoizedState,_=t.stateNode,v=_.getSnapshotBeforeUpdate(t.elementType===t.type?b:Cn(t.type,b),Ke);_.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var S=t.stateNode.containerInfo;S.nodeType===1?S.textContent="":S.nodeType===9&&S.documentElement&&S.removeChild(S.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(h(163))}}catch(T){Qe(t,t.return,T)}if(e=t.sibling,e!==null){e.return=t.return,F=e;break}F=t.return}return B=Bu,Bu=!1,B}function Ks(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var s=r=r.next;do{if((s.tag&e)===e){var l=s.destroy;s.destroy=void 0,l!==void 0&&hi(t,n,l)}s=s.next}while(s!==r)}}function Fo(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function gi(e){var t=e.ref;if(t!==null){var n=e.stateNode;e.tag,e=n,typeof t=="function"?t(e):t.current=e}}function Hu(e){var t=e.alternate;t!==null&&(e.alternate=null,Hu(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[$n],delete t[Os],delete t[Al],delete t[Id],delete t[Ld])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function bu(e){return e.tag===5||e.tag===3||e.tag===4}function Vu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||bu(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function vi(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=go));else if(r!==4&&(e=e.child,e!==null))for(vi(e,t,n),e=e.sibling;e!==null;)vi(e,t,n),e=e.sibling}function yi(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(yi(e,t,n),e=e.sibling;e!==null;)yi(e,t,n),e=e.sibling}var it=null,Nn=!1;function wr(e,t,n){for(n=n.child;n!==null;)Qu(e,t,n),n=n.sibling}function Qu(e,t,n){if(Nt&&typeof Nt.onCommitFiberUnmount=="function")try{Nt.onCommitFiberUnmount(mr,n)}catch{}switch(n.tag){case 5:mt||hs(n,t);case 6:var r=it,s=Nn;it=null,wr(e,t,n),it=r,Nn=s,it!==null&&(Nn?(e=it,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):it.removeChild(n.stateNode));break;case 18:it!==null&&(Nn?(e=it,n=n.stateNode,e.nodeType===8?Tl(e.parentNode,n):e.nodeType===1&&Tl(e,n),Cs(e)):Tl(it,n.stateNode));break;case 4:r=it,s=Nn,it=n.stateNode.containerInfo,Nn=!0,wr(e,t,n),it=r,Nn=s;break;case 0:case 11:case 14:case 15:if(!mt&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var l=s,u=l.destroy;l=l.tag,u!==void 0&&((l&2)!==0||(l&4)!==0)&&hi(n,t,u),s=s.next}while(s!==r)}wr(e,t,n);break;case 1:if(!mt&&(hs(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(d){Qe(n,t,d)}wr(e,t,n);break;case 21:wr(e,t,n);break;case 22:n.mode&1?(mt=(r=mt)||n.memoizedState!==null,wr(e,t,n),mt=r):wr(e,t,n);break;default:wr(e,t,n)}}function Wu(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new Jd),t.forEach(function(r){var s=lf.bind(null,e,r);n.has(r)||(n.add(r),r.then(s,s))})}}function En(e,t){var n=t.deletions;if(n!==null)for(var r=0;rs&&(s=u),r&=~l}if(r=s,r=_e()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*Zd(r/1960))-r,10e?16:e,kr===null)var r=!1;else{if(e=kr,kr=null,Vo=0,(Se&6)!==0)throw Error(h(331));var s=Se;for(Se|=4,F=e.current;F!==null;){var l=F,u=l.child;if((F.flags&16)!==0){var d=l.deletions;if(d!==null){for(var p=0;p_e()-Si?Vr(e,0):_i|=n),It(e,t)}function oc(e,t){t===0&&((e.mode&1)===0?t=1:(t=xt,xt<<=1,(xt&130023424)===0&&(xt=4194304)));var n=wt();e=Yn(e,t),e!==null&&(_n(e,t,n),It(e,n))}function of(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),oc(e,n)}function lf(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,s=e.memoizedState;s!==null&&(n=s.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(h(314))}r!==null&&r.delete(t),oc(e,n)}var lc;lc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Mt.current)Tt=!0;else{if((e.lanes&n)===0&&(t.flags&128)===0)return Tt=!1,Kd(e,t,n);Tt=(e.flags&131072)!==0}else Tt=!1,Fe&&(t.flags&1048576)!==0&&Fa(t,wo,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;zo(e,t),e=t.pendingProps;var s=ls(t,ct.current);fs(t,n),s=Xl(null,t,r,e,s,n);var l=Zl();return t.flags|=1,typeof s=="object"&&s!==null&&typeof s.render=="function"&&s.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Rt(r)?(l=!0,xo(t)):l=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,Ql(t),s.updater=Do,t.stateNode=s,s._reactInternals=t,oi(t,r,e,n),t=ui(null,t,r,!0,l,n)):(t.tag=0,Fe&&l&&Dl(t),St(null,t,s,n),t=t.child),t;case 16:r=t.elementType;e:{switch(zo(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=uf(r),e=Cn(r,e),s){case 0:t=ai(null,t,r,e,n);break e;case 1:t=Au(null,t,r,e,n);break e;case 11:t=Eu(null,t,r,e,n);break e;case 14:t=Pu(null,t,r,Cn(r.type,e),n);break e}throw Error(h(306,r,""))}return t;case 0:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Cn(r,s),ai(e,t,r,s,n);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Cn(r,s),Au(e,t,r,s,n);case 3:e:{if(Iu(t),e===null)throw Error(h(387));r=t.pendingProps,l=t.memoizedState,s=l.element,qa(e,t),Po(t,r,null,n);var u=t.memoizedState;if(r=u.element,l.isDehydrated)if(l={element:r,isDehydrated:!1,cache:u.cache,pendingSuspenseBoundaries:u.pendingSuspenseBoundaries,transitions:u.transitions},t.updateQueue.baseState=l,t.memoizedState=l,t.flags&256){s=ps(Error(h(423)),t),t=Lu(e,t,r,n,s);break e}else if(r!==s){s=ps(Error(h(424)),t),t=Lu(e,t,r,n,s);break e}else for(Vt=gr(t.stateNode.containerInfo.firstChild),bt=t,Fe=!0,kn=null,n=Wa(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(us(),r===s){t=Zn(e,t,n);break e}St(e,t,r,n)}t=t.child}return t;case 5:return Ya(t),e===null&&$l(t),r=t.type,s=t.pendingProps,l=e!==null?e.memoizedProps:null,u=s.children,Ml(r,s)?u=null:l!==null&&Ml(r,l)&&(t.flags|=32),Tu(e,t),St(e,t,u,n),t.child;case 6:return e===null&&$l(t),null;case 13:return Du(e,t,n);case 4:return Wl(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=cs(t,null,r,n):St(e,t,r,n),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Cn(r,s),Eu(e,t,r,s,n);case 7:return St(e,t,t.pendingProps,n),t.child;case 8:return St(e,t,t.pendingProps.children,n),t.child;case 12:return St(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,s=t.pendingProps,l=t.memoizedProps,u=s.value,Ae(Co,r._currentValue),r._currentValue=u,l!==null)if(jn(l.value,u)){if(l.children===s.children&&!Mt.current){t=Zn(e,t,n);break e}}else for(l=t.child,l!==null&&(l.return=t);l!==null;){var d=l.dependencies;if(d!==null){u=l.child;for(var p=d.firstContext;p!==null;){if(p.context===r){if(l.tag===1){p=Xn(-1,n&-n),p.tag=2;var w=l.updateQueue;if(w!==null){w=w.shared;var N=w.pending;N===null?p.next=p:(p.next=N.next,N.next=p),w.pending=p}}l.lanes|=n,p=l.alternate,p!==null&&(p.lanes|=n),bl(l.return,n,t),d.lanes|=n;break}p=p.next}}else if(l.tag===10)u=l.type===t.type?null:l.child;else if(l.tag===18){if(u=l.return,u===null)throw Error(h(341));u.lanes|=n,d=u.alternate,d!==null&&(d.lanes|=n),bl(u,n,t),u=l.sibling}else u=l.child;if(u!==null)u.return=l;else for(u=l;u!==null;){if(u===t){u=null;break}if(l=u.sibling,l!==null){l.return=u.return,u=l;break}u=u.return}l=u}St(e,t,s.children,n),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,fs(t,n),s=an(s),r=r(s),t.flags|=1,St(e,t,r,n),t.child;case 14:return r=t.type,s=Cn(r,t.pendingProps),s=Cn(r.type,s),Pu(e,t,r,s,n);case 15:return Mu(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Cn(r,s),zo(e,t),t.tag=1,Rt(r)?(e=!0,xo(t)):e=!1,fs(t,n),_u(t,r,s),oi(t,r,s,n),ui(null,t,r,!0,e,n);case 19:return zu(e,t,n);case 22:return Ru(e,t,n)}throw Error(h(156,t.tag))};function ic(e,t){return Rr(e,t)}function af(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function dn(e,t,n,r){return new af(e,t,n,r)}function Mi(e){return e=e.prototype,!(!e||!e.isReactComponent)}function uf(e){if(typeof e=="function")return Mi(e)?1:0;if(e!=null){if(e=e.$$typeof,e===jt)return 11;if(e===ve)return 14}return 2}function Er(e,t){var n=e.alternate;return n===null?(n=dn(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function qo(e,t,n,r,s,l){var u=2;if(r=e,typeof e=="function")Mi(e)&&(u=1);else if(typeof e=="string")u=5;else e:switch(e){case $e:return Wr(n.children,s,l,t);case se:u=8,s|=8;break;case Le:return e=dn(12,n,t,s|2),e.elementType=Le,e.lanes=l,e;case Je:return e=dn(13,n,t,s),e.elementType=Je,e.lanes=l,e;case nt:return e=dn(19,n,t,s),e.elementType=nt,e.lanes=l,e;case pe:return Go(n,s,l,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case We:u=10;break e;case tt:u=9;break e;case jt:u=11;break e;case ve:u=14;break e;case Me:u=16,r=null;break e}throw Error(h(130,e==null?e:typeof e,""))}return t=dn(u,n,t,s),t.elementType=e,t.type=r,t.lanes=l,t}function Wr(e,t,n,r){return e=dn(7,e,r,t),e.lanes=n,e}function Go(e,t,n,r){return e=dn(22,e,r,t),e.elementType=pe,e.lanes=n,e.stateNode={isHidden:!1},e}function Ri(e,t,n){return e=dn(6,e,null,t),e.lanes=n,e}function Ti(e,t,n){return t=dn(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function cf(e,t,n,r,s){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=_t(0),this.expirationTimes=_t(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=_t(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function Ai(e,t,n,r,s,l,u,d,p){return e=new cf(e,t,n,d,p),t===1?(t=1,l===!0&&(t|=8)):t=0,l=dn(3,null,null,t),e.current=l,l.stateNode=e,l.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Ql(l),e}function df(e,t,n){var r=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(i)}catch(g){console.error(g)}}return i(),$i.exports=jf(),$i.exports}var Sc;function Cf(){if(Sc)return nl;Sc=1;var i=kf();return nl.createRoot=i.createRoot,nl.hydrateRoot=i.hydrateRoot,nl}var Nf=Cf();const Ef=zc(Nf),Pf="/api";async function Pe(i,g){const h=await fetch(`${Pf}${i}`,{...g,headers:{"Content-Type":"application/json",...g?.headers??{}}}),O=await h.json();if(!h.ok){const R=O.error?.message??"Ошибка запроса";throw new Error(R)}return O}const Ne={async listModels(i){return Pe("/llm/models",{method:"POST",body:JSON.stringify({llmProvider:i.llmProvider,apiKey:i.apiKey,model:i.model,baseUrl:i.baseUrl})})},async testConnection(i){return Pe("/llm/test-connection",{method:"POST",body:JSON.stringify({llmProvider:i.llmProvider,apiKey:i.apiKey,model:i.model,baseUrl:i.baseUrl})})},async normalize(i){return Pe("/normalize",{method:"POST",body:JSON.stringify({llmProvider:i.connection.llmProvider,apiKey:i.connection.apiKey,model:i.connection.model,baseUrl:i.connection.baseUrl,temperature:i.connection.temperature,maxOutputTokens:i.connection.maxOutputTokens,promptVersion:i.promptVersion,systemPrompt:i.prompts.systemPrompt,developerPrompt:i.prompts.developerPrompt,domainPrompt:i.prompts.domainPrompt,fewShotExamples:i.prompts.fewShotExamples,userQuestion:i.query.userQuestion,context:{period_hint:i.query.periodHint??"",business_context:i.query.businessContext??"",expected_route:i.query.expectedRoute??""},saveAsTestCase:!!i.saveAsTestCase,useMock:!!i.useMock})})},async loadHistory(){return Pe("/history")},async loadTrace(i){return Pe(`/history/${i}`)},async loadPresets(){return Pe("/presets")},async savePreset(i){return Pe("/presets/save",{method:"POST",body:JSON.stringify(i)})},async runEval(i){return Pe("/eval/run",{method:"POST",body:JSON.stringify({normalizeConfig:{llmProvider:i.connection.llmProvider,apiKey:i.connection.apiKey,model:i.connection.model,baseUrl:i.connection.baseUrl,temperature:i.connection.temperature,maxOutputTokens:i.connection.maxOutputTokens,promptVersion:i.promptVersion,systemPrompt:i.prompts.systemPrompt,developerPrompt:i.prompts.developerPrompt,domainPrompt:i.prompts.domainPrompt,fewShotExamples:i.prompts.fewShotExamples},caseIds:i.caseIds,useMock:!!i.useMock,mode:i.mode??"standard",caseSetFile:i.caseSetFile,rawQuestions:i.rawQuestions,eval_target:i.evalTarget,compare_with_report_file:i.compareWithReportFile,analysis_date:i.analysisDate})})},async startEvalRunAsync(i){return Pe("/eval/run-async/start",{method:"POST",body:JSON.stringify({normalizeConfig:{llmProvider:i.connection.llmProvider,apiKey:i.connection.apiKey,model:i.connection.model,baseUrl:i.connection.baseUrl,temperature:i.connection.temperature,maxOutputTokens:i.connection.maxOutputTokens,promptVersion:i.promptVersion,systemPrompt:i.prompts.systemPrompt,developerPrompt:i.prompts.developerPrompt,domainPrompt:i.prompts.domainPrompt,fewShotExamples:i.prompts.fewShotExamples},caseIds:i.caseIds,useMock:!!i.useMock,mode:i.mode??"standard",caseSetFile:i.caseSetFile,rawQuestions:i.rawQuestions,eval_target:i.evalTarget,compare_with_report_file:i.compareWithReportFile,questions:i.questions,analysis_date:i.analysisDate})})},async loadEvalRunAsyncStatus(i){return Pe(`/eval/run-async/${encodeURIComponent(i)}`)},async startRun(){return Pe("/accounting-agent/v1/runs/start",{method:"POST",body:JSON.stringify({initiator:"ndc_operator",source:"gui"})})},async finishRun(i){return Pe("/accounting-agent/v1/runs/finish",{method:"POST",body:JSON.stringify({runId:i,status:"DONE",source:"gui",reason:"Остановлено оператором из GUI"})})},async listRuns(){return Pe("/accounting-agent/v1/runs")},async listResults(){return Pe("/accounting-agent/v1/results")},async runTrace(i){return Pe(`/accounting-agent/v1/trace/run/${i}`)},async sendAssistantMessage(i){return Pe("/assistant/message",{method:"POST",body:JSON.stringify({session_id:i.sessionId??"",mode:"assistant",message:i.userMessage,user_message:i.userMessage,llmProvider:i.connection.llmProvider,apiKey:i.connection.apiKey,model:i.connection.model,baseUrl:i.connection.baseUrl,temperature:i.connection.temperature,maxOutputTokens:i.connection.maxOutputTokens,promptVersion:i.promptVersion??"address_query_runtime_v1",systemPrompt:i.prompts.systemPrompt,developerPrompt:i.prompts.developerPrompt,domainPrompt:i.prompts.domainPrompt,fewShotExamples:i.prompts.fewShotExamples,context:{period_hint:i.context?.periodHint??"",business_context:i.context?.businessContext??""},useMock:!!i.useMock})})},async loadAssistantSession(i){return Pe(`/assistant/session/${i}`)},async loadAssistantAnnotations(i){const g=new URLSearchParams;i?.session_id&&g.set("session_id",i.session_id),typeof i?.limit=="number"&&g.set("limit",String(i.limit));const h=g.toString();return Pe(`/assistant/annotations${h?`?${h}`:""}`)},async saveAssistantAnnotation(i){return Pe("/assistant/annotations",{method:"POST",body:JSON.stringify(i)})},async loadAutoRunsHistory(i){const g=new URLSearchParams;i?.from&&g.set("from",i.from),i?.to&&g.set("to",i.to),i?.target&&g.set("target",i.target),i?.mode&&g.set("mode",i.mode),i?.use_mock&&g.set("use_mock",i.use_mock),i?.prompt_contains&&g.set("prompt_contains",i.prompt_contains),typeof i?.limit=="number"&&g.set("limit",String(i.limit)),typeof i?.scan_limit=="number"&&g.set("scan_limit",String(i.scan_limit));const h=g.toString();return Pe(`/autoruns/history${h?`?${h}`:""}`)},async loadAutoRunDetail(i){return Pe(`/autoruns/history/${encodeURIComponent(i)}`)},async loadAutoRunCaseDialog(i,g){return Pe(`/autoruns/history/${encodeURIComponent(i)}/case/${encodeURIComponent(g)}/dialog`)},async loadAutoRunAnnotations(i){const g=new URLSearchParams;i?.run_id&&g.set("run_id",i.run_id),i?.case_id&&g.set("case_id",i.case_id),typeof i?.min_rating=="number"&&g.set("min_rating",String(i.min_rating)),i?.manual_case_decision&&g.set("manual_case_decision",i.manual_case_decision),typeof i?.limit=="number"&&g.set("limit",String(i.limit));const h=g.toString();return Pe(`/autoruns/annotations${h?`?${h}`:""}`)},async saveAutoRunAnnotation(i){return Pe("/autoruns/annotations",{method:"POST",body:JSON.stringify(i)})},async updateAutoRunAnnotation(i){return Pe(`/autoruns/annotations/${encodeURIComponent(i.annotation_id)}`,{method:"PATCH",body:JSON.stringify({resolved:i.resolved,resolved_by:i.resolved_by})})},async loadAutoRunPostAnalysis(i){const g=new URLSearchParams;i?.run_id&&g.set("run_id",i.run_id),typeof i?.limit_per_queue=="number"&&g.set("limit_per_queue",String(i.limit_per_queue)),typeof i?.annotation_limit=="number"&&g.set("annotation_limit",String(i.annotation_limit)),typeof i?.scan_limit=="number"&&g.set("scan_limit",String(i.scan_limit)),i?.from&&g.set("from",i.from),i?.to&&g.set("to",i.to),i?.target&&g.set("target",i.target),i?.mode&&g.set("mode",i.mode),i?.use_mock&&g.set("use_mock",i.use_mock),i?.prompt_contains&&g.set("prompt_contains",i.prompt_contains);const h=g.toString();return Pe(`/autoruns/post-analysis${h?`?${h}`:""}`)},async loadAutoRunAutogenHistory(i){const g=new URLSearchParams;i?.mode&&g.set("mode",i.mode),typeof i?.limit=="number"&&g.set("limit",String(i.limit));const h=g.toString();return Pe(`/autoruns/autogen/history${h?`?${h}`:""}`)},async loadAutoRunAutogenPersonalityCatalog(){return Pe("/autoruns/autogen/personality-catalog")},async generateAutoRunQuestions(i){return Pe("/autoruns/autogen/generate",{method:"POST",body:JSON.stringify(i)})}};function Wt({value:i}){return o.jsx("pre",{className:"json-view",children:JSON.stringify(i??{},null,2)})}function Mn({title:i,subtitle:g,actions:h,className:O,hideHeader:R,children:z}){return o.jsxs("section",{className:O?`panel-frame ${O}`:"panel-frame",children:[R?null:o.jsxs("header",{className:"panel-header",children:[o.jsxs("div",{children:[o.jsx("h2",{children:i}),g?o.jsx("p",{children:g}):null]}),h?o.jsx("div",{className:"panel-actions",children:h}):null]}),o.jsx("div",{className:"panel-body",children:z})]})}function Mf(i){const g=new Date(i);return Number.isNaN(g.getTime())?i:g.toLocaleString("ru-RU")}function Rf({sessionId:i,conversation:g,statusText:h,errorMessage:O,useMock:R,appLogs:z}){const K=g.filter(I=>I.role==="assistant").length,te=g.filter(I=>I.role==="user").length,U=g.length>0?g[g.length-1]:null;return o.jsxs(Mn,{title:"SAM",subtitle:"System Assistant Monitor: срез по текущей сессии и логам.",children:[o.jsxs("div",{className:"metrics-grid",children:[o.jsxs("div",{children:[o.jsx("span",{children:"session_id"}),o.jsx("strong",{children:i||"новая сессия"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"mock_mode"}),o.jsx("strong",{children:R?"on":"off"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"сообщений пользователя"}),o.jsx("strong",{children:te})]}),o.jsxs("div",{children:[o.jsx("span",{children:"ответов ассистента"}),o.jsx("strong",{children:K})]}),o.jsxs("div",{children:[o.jsx("span",{children:"статус"}),o.jsx("strong",{children:h||"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"ошибка"}),o.jsx("strong",{children:O||"нет"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"последнее сообщение"}),o.jsx("strong",{children:U?.created_at?Mf(U.created_at):"нет данных"})]})]}),o.jsx("h3",{style:{marginTop:12},children:"Последние системные логи"}),o.jsx(Wt,{value:z.slice(0,120)})]})}const Tf=/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json|route_summary_json|debug_payload|technical_breakdown)\b/i,Af=[/\b(?:debug_payload_json|technical_breakdown_json)\b/i,/\b(?:route_summary|semantic_profile|domain_scope|relation_patterns|account_scope)\b/i,/\b(?:coverage_report|retrieval_status|problem_unit_state|candidate_evidence)\b/i,/\b(?:graph_domain_scope|graph_runtime|selection_reason|why_included)\b/i];function If(i){try{return JSON.stringify(i,null,2)}catch{return String(i)}}function Lf(i){const g=String(i??""),h=g.match(Tf);return(h?g.slice(0,h.index):g).replace(/###\s*(?:debug_payload_json|technical_breakdown_json|route_summary_json)[\s\S]*?(?:```[\s\S]*?```|$)/gi,"").replace(/(?:^|\n)\s*#{0,6}\s*(?:debug_payload_json|technical_breakdown_json|route_summary_json)\b[\s\S]*$/gi,"").split(/\r?\n/g).map(K=>K.trimEnd()).filter(K=>K.trim().length>0).filter(K=>!Af.some(te=>te.test(K))).join(` `).trim()}function Df(i,g,h="default"){const O=h==="technical",R=[];R.push("# Assistant conversation export"),R.push(`session_id: ${i||"n/a"}`),R.push(`export_mode: ${h}`),R.push(`exported_at: ${new Date().toISOString()}`),R.push("");for(let z=0;z{Z.current&&re.current&&(Z.current.scrollTop=Z.current.scrollHeight)},[g]),x.useEffect(()=>()=>{W.current!==null&&window.clearTimeout(W.current)},[]);async function Ie(se){if(g.length===0)return;const Le=Df(i,g,se),We=await $f(Le);Te(se==="technical"?"тех":"чат"),je(We?"success":"error"),W.current!==null&&window.clearTimeout(W.current),W.current=window.setTimeout(()=>{je("idle")},2200)}function $e(){if(!Z.current)return;const se=Z.current,Le=se.scrollHeight-se.scrollTop-se.clientHeight;re.current=Le<16}return o.jsx(Mn,{className:"assistant-panel-frame",title:"Режим ассистента",children:o.jsxs("div",{className:"assistant-live-shell",children:[o.jsxs("div",{className:"assistant-toolbar",children:[o.jsxs("div",{className:"assistant-toolbar-actions",children:[o.jsx("button",{type:"button",className:"assistant-copy-btn",onClick:()=>{Ie("default")},disabled:g.length===0,title:"Экспорт только user-facing чата",children:"Скопировать чат"}),o.jsx("button",{type:"button",className:"assistant-copy-btn",onClick:()=>{Ie("technical")},disabled:g.length===0,title:"Технический экспорт с debug payload",children:"Скопировать техчат"}),o.jsx("button",{type:"button",className:"assistant-copy-btn",onClick:()=>te(),disabled:U&&g.length===0,children:"Сбросить сессию"})]}),o.jsxs("div",{className:"assistant-toolbar-meta",children:[i?o.jsx("span",{className:"status-chip",children:`session: ${i}`}):null,o.jsxs("div",{className:"assistant-toolbar-meta-right",children:[I?o.jsx("span",{className:"assistant-live-status",children:I}):null,ie==="success"?o.jsxs("span",{className:"assistant-copy-feedback success",children:["Скопировано (",ze,")"]}):null,ie==="error"?o.jsx("span",{className:"assistant-copy-feedback error",children:"Ошибка копирования"}):null]})]}),q?o.jsx("p",{className:"error-text assistant-toolbar-error",children:q}):null]}),o.jsx("div",{ref:Z,className:"assistant-chat-list",onScroll:$e,children:g.map((se,Le)=>{const We=se.role==="assistant"&&L&&typeof H=="function"&&(typeof Re=="function"?Re(se,Le):!0),tt=se.role==="assistant"&&typeof ue=="function"?ue(se,Le):!1;return o.jsxs("article",{className:`assistant-msg ${se.role}`,children:[o.jsxs("header",{className:"assistant-msg-head",children:[o.jsxs("div",{className:"assistant-msg-head-main",children:[o.jsx("strong",{children:Of(se.role)}),o.jsx("span",{children:zf(se.created_at)})]}),se.role==="assistant"&&L?o.jsx("div",{className:"assistant-msg-head-actions",children:o.jsx("button",{type:"button",className:tt?"autoruns-comment-icon assistant-comment-btn commented":"autoruns-comment-icon assistant-comment-btn",onClick:()=>H?.(se,Le),disabled:!We,title:We?"Комментировать ответ ассистента":"Комментарий недоступен для этого сообщения","aria-label":We?"Комментировать ответ ассистента":"Комментарий недоступен для этого сообщения",children:o.jsx(Ff,{commented:tt})})}):null]}),o.jsx("div",{className:"assistant-msg-body",children:se.text}),se.role==="assistant"&&se.debug?o.jsxs("details",{className:"assistant-debug",children:[o.jsx("summary",{children:"Показать технический разбор"}),o.jsx(Wt,{value:se.debug})]}):null]},se.message_id)})}),o.jsxs("div",{className:"assistant-compose",children:[o.jsxs("label",{className:"full-width",children:["Сообщение",o.jsx("textarea",{className:"assistant-input-textarea",value:h,onChange:se=>O(se.target.value),rows:4,placeholder:"Введите вопрос к данным компании..."})]}),o.jsxs("div",{className:"button-row assistant-send-row",children:[o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:R,onChange:se=>z(se.target.checked)}),"Mock-режим"]}),o.jsx("button",{type:"button",className:"assistant-send-btn",onClick:()=>K(),disabled:U||!h.trim(),children:U?"Выполняю...":"Отправить"})]})]})]})})}const Bi={fromLocal:"",toLocal:"",target:"all",mode:"all",useMock:"any",promptContains:"",limit:120},rl="needs_dialog_policy_fix",pt="__all__",il="__live__:",wc="ndc_autoruns_ui_config_v1",jc="ndc-autoruns-save",Hi=["Анализ запроса","Получение данных","Подготовка ответа"],Gi=[{id:"general",label:"Общий контур",domain:"",defaultPrompt:"Генерируй реалистичные живые вопросы бухгалтера по 1С. Добавляй разговорные формулировки и опечатки, но сохраняй бизнес-смысл."}];function Uf(i=Gi){return i.reduce((g,h)=>(g[h.id]=h.defaultPrompt,g),{})}const kc={mode:"codex_creative",count:24,personalityId:"general",personalityPrompts:Uf(),persistToEvalCases:!0,generatedBy:"manual_reviewer"};function bi(i){const g=String(i??"").trim();return/^\d{4}-\d{2}-\d{2}$/.test(g)?g:""}function Cc(i){const g=typeof i=="number"&&Number.isFinite(i)?Math.trunc(i):160;return Math.max(110,Math.min(520,g))}function Bf(i){const g=i.getFullYear(),h=String(i.getMonth()+1).padStart(2,"0"),O=String(i.getDate()).padStart(2,"0"),R=String(i.getHours()).padStart(2,"0"),z=String(i.getMinutes()).padStart(2,"0");return`${g}-${h}-${O}T${R}:${z}`}function Nc(){const i=new Date;return i.setDate(i.getDate()-14),Bf(i)}function sl(i){if(!i.trim())return;const g=Date.parse(i);if(Number.isFinite(g))return new Date(g).toISOString()}function tr(i){if(!i)return"нет данных";const g=Date.parse(i);return Number.isFinite(g)?new Date(g).toLocaleString("ru-RU"):i}function Hf(i,g){return g<=0?0:Math.max(0,Math.min(100,Number((i/g*100).toFixed(1))))}function ol(i){return typeof i!="number"?"нет данных":`${i.toFixed(1)}%`}function bf(i){return i==="assistant_stage1"?"assistant/s1":i==="assistant_stage2"?"assistant/s2":i==="assistant_p0"?"assistant/p0":i}function Ec(i){return i==="up"?"Рост":i==="down"?"Регресс":"Без изменений"}function Vf(i,g){return i.find(h=>h.case_id===g)??null}function Vi(i){const g=Math.max(1,Math.min(5,Math.round(i)));return`${"●".repeat(g)}${"○".repeat(5-g)}`}function Pc(i){return i.length===0?o.jsx("p",{className:"muted",children:"Покрытие доменов пока не сформировано."}):o.jsx("div",{className:"autoruns-coverage-list",children:i.map(g=>{const h=Hf(g.closed_cases,g.total_cases);return o.jsxs("div",{className:"autoruns-coverage-item",children:[o.jsxs("div",{className:"autoruns-coverage-head",children:[o.jsx("strong",{children:g.domain}),o.jsxs("span",{children:[g.closed_cases,"/",g.total_cases," (",h,"%)"]})]}),o.jsx("div",{className:"autoruns-coverage-bar",children:o.jsx("div",{style:{width:`${h}%`}})})]},g.domain)})})}function ll(i){return`${il}${i}`}function xs(i){return i.startsWith(il)}function Mc(i){return i.startsWith(il)?i.slice(il.length):""}function Fc(i){const g=i.report_summary?.run_timestamp??i.created_at,h=Math.max(0,i.total_cases-i.completed_cases);return{run_id:ll(i.job_id),eval_target:i.eval_target,run_timestamp:g,mode:"single-pass-strict",llm_provider:null,model:null,use_mock:null,analysis_date:i.report_summary?.analysis_date??i.analysis_date??null,prompt_version:null,schema_version:null,suite_id:i.case_set_file,cases_total:i.total_cases,requests_total:null,report_path:`async_job:${i.job_id}`,score_index:i.report_summary?.score_index??null,blocking_failures:0,quality_failures:0,closed_cases:i.completed_cases,open_cases:h,domain_coverage:[{domain:"runtime",total_cases:i.total_cases,closed_cases:i.completed_cases}]}}function Zs(i,g){const h=Fc(i),O=i.cases.map(q=>({case_id:q.case_id,domain:null,query_class:null,status:q.status==="completed"?"closed":q.status==="failed"?"open":"unknown",score_index:null,trace_id:null,reply_type:null,session_id:`${i.run_id}-${q.case_id}`,dialog_available:q.messages.length>0,commented_count:0,latest_annotation_at:null,avg_rating:null,checks:null,metric_subscores:null})),z=g!==pt&&O.some(q=>q.case_id===g)?g:O.length>0?pt:"",K={ok:!0,run:h,coverage:{closed_cases:i.completed_cases,open_cases:Math.max(0,i.total_cases-i.completed_cases),domain_coverage:[{domain:"runtime",total_cases:i.total_cases,closed_cases:i.completed_cases}]},cases:O,annotations_summary:{total:0},report:i.report_summary?{run_id:i.report_summary.run_id,run_timestamp:i.report_summary.run_timestamp,score_index:i.report_summary.score_index,cases_total:i.report_summary.cases_total,analysis_date:i.report_summary.analysis_date??i.analysis_date??null}:{}},te=[];let U=0;if(z===pt)for(const q of i.cases)for(let L=0;LL.case_id===z)??null;for(let L=0;L<(q?.messages.length??0);L+=1){const H=q?.messages[L];H&&te.push({...H,message_index:L,case_id:z,case_message_index:L,commented:!1,annotation:null})}}const I={ok:!0,run_id:h.run_id,case_id:z,source:"assistant_session",session_id:z===pt?`${i.run_id}::__all__`:`${i.run_id}-${z}`,messages:te,decomposition:[],assistant_mode:{status:i.status,completed_cases:i.completed_cases,total_cases:i.total_cases},annotations:[]};return{detail:K,dialog:I,caseId:z}}function Qf({commented:i}){const g=i?"comment-icon-svg commented":"comment-icon-svg";return o.jsx("svg",{className:g,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:o.jsx("path",{d:"M5 6.5h14v9H11.5l-4.5 3v-3H5z"})})}function Rc({resolved:i}){return o.jsxs("svg",{className:i?"resolve-icon-svg resolved":"resolve-icon-svg",viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",children:[o.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),i?o.jsx("path",{d:"M5.1 8.2 7.2 10.3 11 6.5"}):null]})}function Wf(){return o.jsxs("svg",{className:"autoruns-copy-icon-svg",viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:[o.jsx("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2.2"}),o.jsx("path",{d:"M15 7V5.8a1.8 1.8 0 0 0-1.8-1.8H5.8A1.8 1.8 0 0 0 4 5.8v7.4A1.8 1.8 0 0 0 5.8 15H7"})]})}function Kf({connection:i,prompts:g,assistantPromptVersion:h,decompositionPromptVersion:O,showAssistantMode:R,showDecompositionMode:z,showProgressMode:K,showCommentsMode:te,onLog:U}){const[I,q]=x.useState({...Bi,fromLocal:Nc()}),[L,H]=x.useState(""),[ue,Re]=x.useState(null),[Z,re]=x.useState(null),[W,ie]=x.useState(null),[je,ze]=x.useState([]),[Te,Ie]=x.useState("all"),[$e,se]=x.useState(!1),[Le,We]=x.useState(null),[tt,jt]=x.useState([]),[Je,nt]=x.useState(""),[ve,Me]=x.useState(""),[pe,A]=x.useState(""),[V,D]=x.useState(Gi),[m,k]=x.useState(kc),[G,ce]=x.useState([]),[de,fe]=x.useState(""),[ye,ge]=x.useState([]),[ee,Ce]=x.useState(null),[Dt,Hn]=x.useState(null),[Rn,Tn]=x.useState(!1),[rr,Kt]=x.useState(!1),[qt,bn]=x.useState(!1),[fn,Ot]=x.useState(!1),[Gt,mn]=x.useState(!1),[sr,An]=x.useState(!1),[or,In]=x.useState(!1),[Jt,Yt]=x.useState(!1),[lr,zt]=x.useState(""),[pn,Ue]=x.useState(""),[lt,hn]=x.useState(""),[gn,Xt]=x.useState([]),[Zt,kt]=x.useState([]),[Ln,en]=x.useState(""),[$t,Ft]=x.useState(!1),[Mr,be]=x.useState(!1),[ir,Ct]=x.useState(""),[ar,tn]=x.useState(""),[ur,ht]=x.useState(String(Bi.limit)),[cr,gt]=x.useState(String(kc.count)),[vn,yn]=x.useState(160),[ae,qe]=x.useState({open:!1,caseId:"",caseMessageIndex:-1,messageIndex:-1,rating:3,comment:"",manualCaseDecision:rl,annotationAuthor:"manual_reviewer",saving:!1,error:""}),[me,vt]=x.useState({open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:"manual_reviewer",saving:!1,error:""}),dr=x.useRef(!1),ke=x.useRef(null),Ve=x.useMemo(()=>V.find(a=>a.id===m.personalityId)??V[0]??Gi[0],[m.personalityId,V]),yt=x.useMemo(()=>G.find(a=>a.generation_id===de)??G[0]??null,[G,de]),Dn=Z?Vf(Z.cases,pe):null,J=x.useMemo(()=>$e?je.filter(a=>!a.resolved):je,[je,$e]),Ee=J.find(a=>a.annotation_id===Je)??null,On=W?.messages.find(a=>a.message_index===ae.messageIndex)??null,Rr=x.useMemo(()=>{if(!W||ae.messageIndex<0)return null;for(let a=ae.messageIndex-1;a>=0;a-=1){const c=W.messages[a];if(c?.role==="user")return c}return null},[ae.messageIndex,W]),nn=x.useMemo(()=>{const a=new Map;for(const c of Zt)c.message_id&&a.set(c.message_id,c);return a},[Zt]),Tr=me.messageIndex>=0?gn[me.messageIndex]??null:null,Kr=x.useMemo(()=>{if(me.messageIndex<0)return null;for(let a=me.messageIndex-1;a>=0;a-=1){const c=gn[a];if(c?.role==="user")return c}return null},[me.messageIndex,gn]),_e=x.useMemo(()=>{const a=J.map(y=>({source:"autorun",key:`autorun:${y.annotation_id}`,updated_at:y.updated_at,rating:y.rating,autorun:y,assistant:null})),c=Zt.map(y=>({source:"assistant_live",key:`assistant:${y.annotation_id}`,updated_at:y.updated_at,rating:y.rating,autorun:null,assistant:y}));return[...a,...c].sort((y,E)=>Date.parse(E.updated_at)-Date.parse(y.updated_at))},[Zt,J]),Ar=x.useMemo(()=>{if(_e.length===0)return null;const a=_e.reduce((c,y)=>c+y.rating,0)/_e.length;return Number(a.toFixed(2))},[_e]),Vn=x.useMemo(()=>{const a=[...ue?.items??[]];return ee&&a.unshift(Fc(ee)),ve&&!a.some(c=>c.run_id===ve)&&Z?.run&&a.unshift(Z.run),a},[ee,ue?.items,Z?.run,ve]),oe=x.useCallback(a=>{U?.(`[autoruns] ${a}`)},[U]),rn=x.useCallback(async a=>{const c=String(a??"").trim();if(!c){kt([]);return}try{const y=await Ne.loadAssistantAnnotations({session_id:c,limit:400});kt(y.items??[])}catch(y){const E=y instanceof Error?y.message:String(y);oe(`Assistant live annotations load error: ${E}`)}},[oe]),xn=x.useCallback(a=>{vt(c=>c.saving&&!a?.force?c:{open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:"manual_reviewer",saving:!1,error:""})},[]),fr=x.useCallback(async(a,c)=>{a.stopPropagation(),a.preventDefault();const y=String(c??"").trim();if(y)try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(y);else{const E=document.createElement("textarea");E.value=y,E.setAttribute("readonly","true"),E.style.position="fixed",E.style.opacity="0",document.body.appendChild(E),E.select(),document.execCommand("copy"),document.body.removeChild(E)}oe(`run id copied: ${y}`)}catch(E){const le=E instanceof Error?E.message:String(E);Ue(`Копирование run id: ${le}`),oe(`copy run id error: ${le}`)}},[oe]);function mr(){let a=0;Ct(Hi[0]);const c=window.setInterval(()=>{a=Math.min(a+1,Hi.length-1),Ct(Hi[a])},650);return()=>window.clearInterval(c)}const Nt=x.useCallback(()=>{hn(""),Xt([]),kt([]),en(""),Ct(""),tn(""),xn({force:!0}),oe("Live-чат ассистента в истории автопрогонов сброшен.")},[xn,oe]),_s=x.useCallback(async()=>{const a=Ln.trim();if(!a)return;be(!0),tn(""),en(""),Xt(y=>[...y,{message_id:`autoruns-live-${Date.now()}`,session_id:lt||"pending",role:"user",text:a,reply_type:null,created_at:new Date().toISOString(),trace_id:null,debug:null}]);const c=mr();try{const y=await Ne.sendAssistantMessage({connection:i,prompts:g,userMessage:a,sessionId:lt||void 0,promptVersion:h,useMock:$t});hn(y.session_id),Xt(y.conversation),await rn(y.session_id),Ct("Ответ готов"),oe(`Live-ответ ассистента получен: trace=${y.debug.trace_id}`)}catch(y){const E=y instanceof Error?y.message:String(y);tn(E),Ct("Ошибка ассистента"),oe(`Live-чат ассистента: ошибка отправки сообщения: ${E}`)}finally{c(),be(!1)}},[Ln,lt,$t,h,i,rn,oe,g]),ut=x.useCallback(a=>{const c=a.trim();if(!c){ht(String(I.limit));return}if(!/^\d+$/.test(c)){ht(String(I.limit));return}const y=Number.parseInt(c,10);if(!Number.isFinite(y)){ht(String(I.limit));return}const E=Math.max(1,Math.min(500,y));E!==I.limit&&q(le=>({...le,limit:E})),ht(String(E))},[I.limit]),qr=x.useCallback(a=>{const c=a.trim();if(!c){gt(String(m.count));return}if(!/^\d+$/.test(c)){gt(String(m.count));return}const y=Number.parseInt(c,10);if(!Number.isFinite(y)){gt(String(m.count));return}const E=Math.max(1,Math.min(200,y));E!==m.count&&k(le=>({...le,count:E})),gt(String(E))},[m.count]),Gr=x.useCallback(a=>{yn(Cc(a))},[]),Ir=x.useCallback(a=>{const c=a.currentTarget.offsetHeight;Number.isFinite(c)&&c>0&&Gr(c)},[Gr]),Ut=x.useCallback(async()=>{Yt(!0);try{const a=await Ne.loadAutoRunAnnotations({limit:800,manual_case_decision:Te});ze(a.items),We(a.manual_case_decision_schema??null),jt(a.available_manual_case_decisions??[]),nt(c=>a.items.length===0?"":a.items.some(y=>y.annotation_id===c)?c:a.items[0].annotation_id)}catch(a){oe(`Annotations load error: ${a instanceof Error?a.message:String(a)}`)}finally{Yt(!1)}},[Te,oe]),xt=x.useCallback(async()=>{Ot(!0);try{const a=await Ne.loadAutoRunAutogenHistory({limit:180});ce(a.items)}catch(a){oe(`Autogen history load error: ${a instanceof Error?a.message:String(a)}`)}finally{Ot(!1)}},[oe]),sn=x.useCallback(async()=>{try{const c=(await Ne.loadAutoRunAutogenPersonalityCatalog()).items.map(y=>({id:String(y.id??"").trim(),label:String(y.label??"").trim(),domain:typeof y.domain=="string"?y.domain.trim():"",defaultPrompt:String(y.default_prompt??"").trim()})).filter(y=>y.id.length>0&&y.label.length>0);if(c.length===0)return;D(c.map(y=>({id:y.id,label:y.label,domain:y.domain||"",defaultPrompt:y.defaultPrompt||"Генерируй реалистичные вопросы бухгалтера по выбранному профилю. Не выдумывай непокрытые возможности."})))}catch(a){oe(`Autogen personality catalog load error: ${a instanceof Error?a.message:String(a)}`)}},[oe]),Ye=x.useCallback(async()=>{bn(!0);try{const a=await Ne.loadAutoRunPostAnalysis({run_id:ve&&!xs(ve)?ve:void 0,limit_per_queue:30,annotation_limit:1500,from:sl(I.fromLocal),to:sl(I.toLocal),target:I.target,mode:I.mode,use_mock:I.useMock,prompt_contains:I.promptContains.trim()||void 0});Hn(a)}catch(a){oe(`Post-analysis load error: ${a instanceof Error?a.message:String(a)}`),Hn(null)}finally{bn(!1)}},[I.fromLocal,I.mode,I.promptContains,I.target,I.toLocal,I.useMock,oe,ve]),Ss=x.useCallback(async()=>{Tn(!0),Ue("");try{const a=m.personalityPrompts[m.personalityId]??"",c=[g.systemPrompt,g.developerPrompt,g.domainPrompt,g.schemaNotes,g.fewShotExamples].join(` `).slice(0,900),y=await Ne.generateAutoRunQuestions({mode:m.mode,count:m.count,domain:Ve.domain||void 0,persist_to_eval_cases:m.persistToEvalCases,generated_by:m.generatedBy.trim()||void 0,llm:{llm_provider:i.llmProvider,api_key:i.apiKey,model:i.model,base_url:i.baseUrl,temperature:i.temperature,max_output_tokens:i.maxOutputTokens},context:{llm_provider:i.llmProvider,model:i.model,assistant_prompt_version:h,decomposition_prompt_version:O,prompt_fingerprint:c,autogen_personality_id:Ve.id,autogen_personality_prompt:a.trim()||void 0}});oe(`Generated ${y.generation.count} questions (${y.generation.mode}) id=${y.generation.generation_id}`+(y.generation.saved_case_set_file?` saved=${y.generation.saved_case_set_file}`:"")),fe(y.generation.generation_id),ge([...y.generation.questions??[]]),await xt()}catch(a){const c=a instanceof Error?a.message:String(a);Ue(`Автогенерация: ${c}`),oe(`Autogen generate error: ${c}`)}finally{Tn(!1)}},[h,m.count,m.generatedBy,m.mode,m.personalityId,m.personalityPrompts,m.persistToEvalCases,i.apiKey,i.baseUrl,i.llmProvider,i.maxOutputTokens,i.model,i.temperature,O,xt,oe,g.developerPrompt,g.domainPrompt,g.fewShotExamples,g.schemaNotes,g.systemPrompt,Ve.domain,Ve.id]),Qn=x.useCallback(async(a,c)=>{if(xs(a)){const y=Mc(a);if(ee&&ee.job_id===y){const E=Zs(ee,c);Me(a),A(E.caseId),ie(E.dialog);return}ie(null);return}In(!0);try{const y=await Ne.loadAutoRunCaseDialog(a,c);ie(y)}catch(y){const E=y instanceof Error?y.message:String(y);Ue(`Диалог кейса: ${E}`),ie(null),oe(`Dialog load error for ${a}/${c}: ${E}`)}finally{In(!1)}},[ee,oe]),Et=x.useCallback(async(a,c)=>{if(xs(a)){const y=Mc(a);if(ee&&ee.job_id===y){const E=Zs(ee,c??pt);Me(a),A(E.caseId),re(E.detail),ie(E.dialog);return}Me(a),A(""),re(null),ie(null);return}An(!0);try{const y=await Ne.loadAutoRunDetail(a);re(y);const E=(c&&(c===pt||y.cases.some(le=>le.case_id===c))?c:"")||(y.cases.length>0?pt:"")||"";Me(a),A(E),E?await Qn(a,E):ie(null)}catch(y){const E=y instanceof Error?y.message:String(y);Ue(`Детализация прогона: ${E}`),re(null),ie(null),oe(`Run detail load error for ${a}: ${E}`)}finally{An(!1)}},[ee,Qn,oe]),zn=x.useCallback(async a=>{mn(!0),Ue("");try{const c=await Ne.loadAutoRunsHistory({from:sl(I.fromLocal),to:sl(I.toLocal),target:I.target,mode:I.mode,use_mock:I.useMock,prompt_contains:I.promptContains.trim()||void 0,limit:I.limit});if(Re(c),c.items.length===0){Me(""),A(""),re(null),ie(null);return}const y=a?.keepSelection??!0,E=a?.preferredRunId??"",le=a?.preferredCaseId??"",Xe=y&&E&&c.items.some(Bt=>Bt.run_id===E)?E:c.items[0].run_id;await Et(Xe,y?le:void 0),Ye()}catch(c){const y=c instanceof Error?c.message:String(c);Ue(`История прогонов: ${y}`),oe(`History load error: ${y}`)}finally{mn(!1)}},[I.fromLocal,I.limit,I.mode,I.promptContains,I.target,I.toLocal,I.useMock,Ye,Et,oe]),_t=x.useCallback(()=>{ke.current!==null&&(window.clearTimeout(ke.current),ke.current=null)},[]),_n=x.useCallback(async a=>{try{const c=await Ne.loadEvalRunAsyncStatus(a);Ce(c.job);const y=ll(a);if(ve===y){const E=Zs(c.job,pe||pt);re(E.detail),ie(E.dialog),A(E.caseId)}if(c.job.status==="completed"){_t(),Kt(!1);const E=c.job.report_summary?.run_id??c.job.run_id;await zn({keepSelection:!0,preferredRunId:E||ve,preferredCaseId:pt}),await xt(),Ce(null);return}if(c.job.status==="failed"){_t(),Kt(!1),Ue(`Запуск прогонов: ${c.job.error??"неизвестная ошибка"}`),oe(`Autogen async run failed: ${c.job.error??"unknown error"}`);return}_t(),ke.current=window.setTimeout(()=>{_n(a)},500)}catch(c){_t(),Kt(!1);const y=c instanceof Error?c.message:String(c);Ue(`Запуск прогонов: ${y}`),oe(`Autogen async status error: ${y}`)}},[xt,zn,oe,pe,ve,_t]),f=x.useCallback(async()=>{_t(),Kt(!0),Ue("");try{const a=yt;if(!a)throw new Error("История автогенерации пуста. Сначала сгенерируйте пачку вопросов.");const c=ye.map(js=>js.trim()).filter(js=>js.length>0);if(c.length===0)throw new Error("Нет вопросов для запуска: список пустой после ручного редактирования.");const y=I.useMock==="true",E=bi(L),Xe=(await Ne.startEvalRunAsync({connection:i,prompts:g,promptVersion:h,mode:"single-pass-strict",caseSetFile:a.saved_case_set_file??void 0,useMock:y,evalTarget:"assistant_stage1",questions:c,analysisDate:E||void 0})).job;Ce(Xe);const Bt=ll(Xe.job_id),Pt=Zs(Xe,pt);Me(Bt),A(Pt.caseId),re(Pt.detail),ie(Pt.dialog),oe(`Запущен async-прогон job=${Xe.job_id}, run_id=${Xe.run_id}, вопросов=${c.length}`+(a.saved_case_set_file?`, base_case_set=${a.saved_case_set_file}`:"")+(E?`, analysis_date=${E}`:", analysis_date=current_state")),_n(Xe.job_id)}catch(a){const c=a instanceof Error?a.message:String(a);Ue(`Запуск прогонов: ${c}`),oe(`Autogen run error: ${c}`),Kt(!1)}},[L,h,i,ye,I.useMock,oe,_n,g,yt,_t]),P=x.useCallback(a=>{if(a.role!=="assistant")return;const c=a.case_id??pe,y=a.case_message_index??a.message_index;qe({open:!0,caseId:c,caseMessageIndex:y,messageIndex:a.message_index,rating:a.annotation?.rating??3,comment:a.annotation?.comment??"",manualCaseDecision:a.annotation?.manual_case_decision??rl,annotationAuthor:a.annotation?.annotation_author??m.generatedBy,saving:!1,error:""})},[m.generatedBy,pe]),j=x.useCallback(a=>{qe(c=>c.saving&&!a?.force?c:{open:!1,caseId:"",caseMessageIndex:-1,messageIndex:-1,rating:3,comment:"",manualCaseDecision:rl,annotationAuthor:m.generatedBy,saving:!1,error:""})},[m.generatedBy]),xe=x.useCallback(async()=>{const a=ve,c=ae.caseId,y=ae.caseMessageIndex;if(!(!a||!c||y<0)){if(xs(a)){qe(E=>({...E,error:"Комментарий можно сохранить после завершения прогона."}));return}if(!ae.comment.trim()){qe(E=>({...E,error:"Добавьте комментарий."}));return}qe(E=>({...E,saving:!0,error:""}));try{await Ne.saveAutoRunAnnotation({run_id:a,case_id:c,message_index:y,rating:ae.rating,comment:ae.comment.trim(),manual_case_decision:ae.manualCaseDecision,annotation_author:ae.annotationAuthor.trim()||void 0}),j({force:!0}),Promise.all([Et(a,pe),Ut(),Ye()]).catch(E=>{const le=E instanceof Error?E.message:String(E);Ue(`Обновление после комментария: ${le}`),oe(`Comment refresh error: ${le}`)})}catch(E){qe(le=>({...le,saving:!1,error:E instanceof Error?E.message:String(E)}))}}},[j,ae.annotationAuthor,ae.caseId,ae.caseMessageIndex,ae.comment,ae.manualCaseDecision,ae.rating,Ut,Ye,Et,oe,pe,ve]),Wn=x.useCallback(a=>a.role==="assistant",[]),Sn=x.useCallback(a=>a.role==="assistant"&&nn.has(a.message_id),[nn]),eo=x.useCallback((a,c)=>{if(a.role!=="assistant")return;const y=lt.trim(),E=String(a.session_id??"").trim();if(!(y||E)){tn("Сначала получите ответ ассистента в активной сессии.");return}!y&&E&&hn(E);const Xe=nn.get(a.message_id)??null;tn(""),vt({open:!0,messageIndex:c,rating:Xe?.rating??3,comment:Xe?.comment??"",annotationAuthor:Xe?.annotation_author??"manual_reviewer",saving:!1,error:""})},[nn,lt]),to=x.useCallback(async()=>{if(me.messageIndex<0)return;if(!me.comment.trim()){vt(y=>({...y,error:"Добавьте комментарий."}));return}const a=gn[me.messageIndex]??null,c=lt.trim()||(a?.role==="assistant"?String(a.session_id??"").trim():"");if(!c){vt(y=>({...y,error:"Сессия ассистента не найдена."}));return}vt(y=>({...y,saving:!0,error:""}));try{const y=await Ne.saveAssistantAnnotation({session_id:c,message_index:me.messageIndex,rating:me.rating,comment:me.comment.trim(),annotation_author:me.annotationAuthor.trim()||void 0});kt(E=>{const le=[...E],Xe=le.findIndex(Bt=>Bt.annotation_id===y.annotation.annotation_id);return Xe>=0?le[Xe]=y.annotation:le.unshift(y.annotation),le.sort((Bt,Pt)=>Date.parse(Pt.updated_at)-Date.parse(Bt.updated_at))}),xn({force:!0})}catch(y){const E=y instanceof Error?y.message:String(y);vt(le=>({...le,saving:!1,error:E}))}},[me.annotationAuthor,me.comment,me.messageIndex,me.rating,gn,lt,xn]),ws=x.useCallback(a=>{ze(c=>c.map(y=>y.annotation_id===a.annotation_id?{...y,...a}:y)),ie(c=>c&&{...c,annotations:c.annotations.map(y=>y.annotation_id===a.annotation_id?a:y),messages:c.messages.map(y=>!y.annotation||y.annotation.annotation_id!==a.annotation_id?y:{...y,commented:!0,annotation:a})})},[]),Jr=x.useCallback(async(a,c)=>{if(a.annotation_id){if(xs(a.run_id)){Ue("Статус выполнения можно менять только для завершённых прогонов.");return}zt(a.annotation_id);try{const y=await Ne.updateAutoRunAnnotation({annotation_id:a.annotation_id,resolved:c,resolved_by:m.generatedBy||void 0});ws(y.annotation),Ye()}catch(y){const E=y instanceof Error?y.message:String(y);Ue(`Смена статуса кейса: ${E}`),oe(`Annotation resolve toggle error: ${E}`)}finally{zt("")}}},[ws,m.generatedBy,Ye,oe]),Lr=x.useCallback(async a=>{nt(a.annotation_id),await Et(a.run_id,a.case_id),ue?.items.some(c=>c.run_id===a.run_id)||Ue("Комментарий относится к прогону вне текущего фильтра. Детали загружены напрямую.")},[ue?.items,Et]);x.useEffect(()=>{dr.current||(dr.current=!0,zn({keepSelection:!1}),xt(),sn(),Ye())},[xt,sn,zn,Ye]),x.useEffect(()=>{dr.current&&Ut()},[Te,Ut]),x.useEffect(()=>{nt(a=>J.length===0?"":J.some(c=>c.annotation_id===a)?a:J[0].annotation_id)},[J]),x.useEffect(()=>{fe(a=>G.length===0?"":a&&G.some(c=>c.generation_id===a)?a:G[0].generation_id)},[G]),x.useEffect(()=>{if(!yt){ge([]);return}ge([...yt.questions])},[yt?.generation_id]),x.useEffect(()=>{ht(String(I.limit))},[I.limit]),x.useEffect(()=>{gt(String(m.count))},[m.count]),x.useEffect(()=>{if(!lt.trim()){kt([]);return}rn(lt)},[lt,rn]),x.useEffect(()=>{if(!ee)return;const a=ll(ee.job_id);if(ve!==a)return;const c=Zs(ee,pe||pt);re(c.detail),ie(c.dialog),A(c.caseId)},[ee,pe,ve]),x.useEffect(()=>()=>{_t()},[_t]),x.useEffect(()=>{V.length!==0&&k(a=>{let c=!1;const y={...a.personalityPrompts};for(const le of V)(typeof y[le.id]!="string"||y[le.id].trim().length===0)&&(y[le.id]=le.defaultPrompt,c=!0);let E=a.personalityId;return V.some(le=>le.id===a.personalityId)||(E=V[0].id,c=!0),c?{...a,personalityId:E,personalityPrompts:y}:a})},[V]),x.useEffect(()=>{const a=localStorage.getItem(wc);if(a)try{const c=JSON.parse(a);if(c.filters){const y=c.filters;q(E=>({...E,...y,limit:typeof y.limit=="number"?Math.max(1,Math.min(500,y.limit)):E.limit}))}typeof c.analysisDate=="string"&&H(bi(c.analysisDate)),typeof c.autogenPersonalityPromptHeight=="number"&&yn(Cc(c.autogenPersonalityPromptHeight)),c.autoGenSettings&&k(y=>{const E={...y.personalityPrompts},le=c.autoGenSettings?.personalityPrompts??{};for(const[Bt,Pt]of Object.entries(le))typeof Pt=="string"&&Bt.trim().length>0&&(E[Bt.trim()]=Pt);const Xe=typeof c.autoGenSettings?.personalityId=="string"&&c.autoGenSettings.personalityId.trim().length>0?c.autoGenSettings.personalityId.trim():y.personalityId;return{...y,mode:c.autoGenSettings?.mode==="codex_creative"||c.autoGenSettings?.mode==="qwen_seed"?c.autoGenSettings.mode:y.mode,count:typeof c.autoGenSettings?.count=="number"?Math.max(1,Math.min(200,c.autoGenSettings.count)):y.count,personalityId:Xe,personalityPrompts:E,persistToEvalCases:typeof c.autoGenSettings?.persistToEvalCases=="boolean"?c.autoGenSettings.persistToEvalCases:y.persistToEvalCases,generatedBy:typeof c.autoGenSettings?.generatedBy=="string"?c.autoGenSettings.generatedBy:y.generatedBy}}),(c.annotationDecisionFilter==="all"||typeof c.annotationDecisionFilter=="string"&&c.annotationDecisionFilter.length>0)&&Ie(c.annotationDecisionFilter),typeof c.hideResolvedAnnotations=="boolean"&&se(c.hideResolvedAnnotations)}catch{}},[]);const wn=x.useCallback(()=>{const a={filters:I,analysisDate:L,autogenPersonalityPromptHeight:vn,autoGenSettings:{mode:m.mode,count:m.count,personalityId:m.personalityId,personalityPrompts:m.personalityPrompts,persistToEvalCases:m.persistToEvalCases,generatedBy:m.generatedBy},annotationDecisionFilter:Te,hideResolvedAnnotations:$e};localStorage.setItem(wc,JSON.stringify(a))},[L,Te,m,vn,I,$e]);return x.useEffect(()=>{const a=()=>{wn(),oe("Сохранены настройки панели автопрогонов.")};return window.addEventListener(jc,a),()=>{window.removeEventListener(jc,a)}},[oe,wn]),o.jsxs(Mn,{className:"autoruns-frame",title:"",hideHeader:!0,children:[o.jsxs("div",{className:"autoruns-columns",children:[o.jsxs("section",{className:"autoruns-col",children:[o.jsx("div",{className:"autoruns-col-header",children:o.jsx("h3",{children:"Настройки"})}),o.jsx("h4",{children:"Настройки выборки"}),o.jsxs("div",{className:"autoruns-form-grid",children:[o.jsxs("label",{children:["Дата с",o.jsx("input",{type:"datetime-local",value:I.fromLocal,onChange:a=>q(c=>({...c,fromLocal:a.target.value}))})]}),o.jsxs("label",{children:["Дата по",o.jsx("input",{type:"datetime-local",value:I.toLocal,onChange:a=>q(c=>({...c,toLocal:a.target.value}))})]}),o.jsxs("label",{children:["Целевой контур",o.jsxs("select",{value:I.target,onChange:a=>q(c=>({...c,target:a.target.value})),children:[o.jsx("option",{value:"all",children:"все"}),(ue?.available.targets??[]).map(a=>o.jsx("option",{value:a,children:a},a))]})]}),o.jsxs("label",{children:["Режим",o.jsxs("select",{value:I.mode,onChange:a=>q(c=>({...c,mode:a.target.value})),children:[o.jsx("option",{value:"all",children:"все"}),(ue?.available.modes??[]).map(a=>o.jsx("option",{value:a,children:a},a))]})]}),o.jsxs("label",{children:["Использовать mock",o.jsxs("select",{value:I.useMock,onChange:a=>q(c=>({...c,useMock:a.target.value})),children:[o.jsx("option",{value:"any",children:"любой"}),o.jsx("option",{value:"true",children:"да"}),o.jsx("option",{value:"false",children:"нет"})]})]}),o.jsxs("label",{children:["Лимит",o.jsx("input",{type:"number",min:1,max:500,value:ur,onChange:a=>{const c=a.target.value;(c===""||/^\d+$/.test(c))&&ht(c)},onBlur:a=>ut(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ut(a.target.value)}})]}),o.jsxs("label",{className:"full-width",children:["Версия промпта содержит",o.jsx("input",{value:I.promptContains,onChange:a=>q(c=>({...c,promptContains:a.target.value})),placeholder:"normalizer_v2_0_2 / address_query_runtime_v1",list:"autoruns-prompt-versions"})]})]}),o.jsx("datalist",{id:"autoruns-prompt-versions",children:(ue?.available.prompt_versions??[]).map(a=>o.jsx("option",{value:a},a))}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",disabled:Gt,onClick:()=>{zn({keepSelection:!1})},children:Gt?"Обновляю...":"Применить"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>{q({...Bi,fromLocal:Nc()}),Ue("")},children:"Сбросить фильтры"})]}),o.jsx("h4",{children:"Контур генерации"}),o.jsxs("div",{className:"autoruns-meta-list",children:[o.jsxs("div",{children:[o.jsx("span",{children:"Провайдер:"}),o.jsx("strong",{children:i.llmProvider})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Модель:"}),o.jsx("strong",{children:i.model||"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Промпт ассистента:"}),o.jsx("strong",{children:h})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Промпт декомпозиции:"}),o.jsx("strong",{children:O})]})]}),o.jsx("h4",{children:"Автогенерация вопросов"}),o.jsxs("div",{className:"autoruns-form-grid",children:[o.jsxs("label",{children:["Режим генерации",o.jsxs("select",{value:m.mode,onChange:a=>k(c=>({...c,mode:a.target.value})),children:[o.jsx("option",{value:"codex_creative",children:"codex_creative"}),o.jsx("option",{value:"qwen_seed",children:"qwen_seed"})]})]}),o.jsxs("label",{children:["Кол-во",o.jsx("input",{type:"number",min:1,max:200,value:cr,onChange:a=>{const c=a.target.value;(c===""||/^\d+$/.test(c))&>(c)},onBlur:a=>qr(a.target.value),onKeyDown:a=>{a.key==="Enter"&&qr(a.target.value)}})]}),o.jsxs("label",{children:["Личность автогенерации",o.jsx("select",{value:m.personalityId,onChange:a=>k(c=>({...c,personalityId:a.target.value})),children:V.map(a=>o.jsx("option",{value:a.id,children:a.label},a.id))})]}),o.jsxs("label",{children:["Кто генерирует",o.jsx("input",{value:m.generatedBy,onChange:a=>k(c=>({...c,generatedBy:a.target.value})),placeholder:"manual_reviewer"})]}),o.jsxs("label",{className:"full-width",children:["Промпт личности",o.jsx("textarea",{className:"autoruns-personality-prompt",value:m.personalityPrompts[m.personalityId]??"",onChange:a=>k(c=>({...c,personalityPrompts:{...c.personalityPrompts,[c.personalityId]:a.target.value}})),placeholder:"Текст промпта для выбранной личности автогенерации",style:{height:`${vn}px`},onMouseUp:Ir,onTouchEnd:Ir})]}),o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:m.persistToEvalCases,onChange:a=>k(c=>({...c,persistToEvalCases:a.target.checked}))}),"Сохранять кейс-сет в `eval_cases`"]})]}),o.jsxs("div",{className:"autoruns-form-grid",children:[o.jsxs("label",{children:["Дата анализа (срез)",o.jsx("input",{type:"date",value:L,onChange:a=>H(bi(a.target.value))})]}),o.jsx("div",{className:"button-row",children:o.jsx("button",{type:"button",className:"tab",disabled:!L,onClick:()=>H(""),children:"Сбросить дату среза"})})]}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",disabled:Rn,onClick:()=>{Ss()},children:Rn?"Генерирую...":"Сгенерировать пачку"}),o.jsx("button",{type:"button",className:"tab",disabled:fn,onClick:()=>{xt()},children:fn?"Обновляю...":"Обновить историю"}),o.jsx("button",{type:"button",className:"autoruns-run-launch-btn",disabled:rr||ye.length===0,onClick:()=>{f()},children:rr?"Запускаю...":"Запустить прогоны"})]}),o.jsx("div",{className:"autoruns-form-grid",children:o.jsxs("label",{className:"full-width",children:["Кейс-сет для запуска",o.jsxs("select",{value:de,onChange:a=>fe(a.target.value),disabled:G.length===0,children:[G.length===0?o.jsx("option",{value:"",children:"нет генераций"}):null,G.map(a=>o.jsxs("option",{value:a.generation_id,children:[tr(a.created_at)," | ",a.mode," | ",a.count," | ",a.saved_case_set_file??"без файла"]},a.generation_id))]})]})}),o.jsxs("div",{className:"autoruns-generated-questions",children:[o.jsxs("div",{className:"autoruns-generated-questions-head",children:[o.jsxs("strong",{children:["Вопросы к запуску: ",ye.length]}),o.jsx("button",{type:"button",className:"tab",onClick:()=>ge([...yt?.questions??[]]),disabled:!yt,children:"Восстановить"})]}),ye.length===0?o.jsx("p",{className:"muted",children:"Список вопросов пуст. Сгенерируйте пачку или восстановите из выбранной генерации."}):o.jsx("div",{className:"autoruns-generated-questions-list",children:ye.map((a,c)=>o.jsxs("div",{className:"autoruns-generated-question-item",children:[o.jsxs("span",{children:[c+1,". ",a]}),o.jsx("button",{type:"button",className:"autoruns-remove-question-btn",onClick:()=>ge(y=>y.filter((E,le)=>le!==c)),title:"Удалить вопрос из запуска","aria-label":"Удалить вопрос из запуска",children:"+"})]},`${c}-${a.slice(0,24)}`))})]}),o.jsx("p",{className:"muted",children:"Запуск выполняет `assistant_stage1` eval по выбранному кейс-сету."}),o.jsxs("div",{className:"autoruns-autogen-list",children:[fn?o.jsx("p",{className:"muted",children:"Загружаю историю автогенераций..."}):null,!fn&&G.length===0?o.jsx("p",{className:"muted",children:"История автогенераций пока пустая."}):null,G.slice(0,30).map(a=>o.jsxs("article",{className:de===a.generation_id?"autoruns-autogen-item selected":"autoruns-autogen-item",onClick:()=>fe(a.generation_id),children:[o.jsxs("header",{children:[o.jsx("strong",{children:tr(a.created_at)}),o.jsx("span",{children:a.mode})]}),o.jsxs("div",{className:"autoruns-run-meta",children:["id=",a.generation_id," | count=",a.count]}),o.jsxs("div",{className:"autoruns-run-meta",children:["домен=",a.domain??"общий",a.generated_by?` | автор=${a.generated_by}`:""]}),a.saved_case_set_file?o.jsxs("div",{className:"autoruns-run-meta",children:["кейс-сет=",a.saved_case_set_file]}):null,(a.questions??[]).length>0?o.jsx("p",{children:a.questions[0]}):null]},a.generation_id))]}),o.jsxs("details",{className:"autoruns-prompt-details",children:[o.jsx("summary",{children:"Копия активного промпта (только чтение)"}),o.jsxs("label",{children:["Системный",o.jsx("textarea",{readOnly:!0,value:g.systemPrompt})]}),o.jsxs("label",{children:["Разработчика",o.jsx("textarea",{readOnly:!0,value:g.developerPrompt})]}),o.jsxs("label",{children:["Доменный",o.jsx("textarea",{readOnly:!0,value:g.domainPrompt})]}),o.jsxs("label",{children:["Заметки по схеме",o.jsx("textarea",{readOnly:!0,value:g.schemaNotes})]}),o.jsxs("label",{children:["Примеры few-shot",o.jsx("textarea",{readOnly:!0,value:g.fewShotExamples})]})]}),pn?o.jsx("p",{className:"error-text",children:pn}):null]}),o.jsxs("section",{className:"autoruns-col",children:[o.jsx("div",{className:"autoruns-col-header",children:o.jsx("h3",{children:"Выдача прогонов"})}),o.jsxs("div",{className:"autoruns-stats-grid",children:[o.jsxs("div",{children:[o.jsx("span",{children:"Всего"}),o.jsx("strong",{children:(ue?.stats.runs_total??0)+(ee?1:0)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Средний score"}),o.jsx("strong",{children:ol(ue?.stats.avg_score_index??null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Тренд"}),o.jsx("strong",{children:ue?Ec(ue.stats.trend):"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Блокеры"}),o.jsx("strong",{children:ue?.stats.blocking_runs??0})]})]}),o.jsxs("div",{className:"autoruns-run-list",children:[Vn.map(a=>o.jsxs("button",{type:"button",className:ve===a.run_id?"autoruns-run-item selected":"autoruns-run-item",onClick:()=>{Et(a.run_id)},children:[o.jsxs("div",{className:"autoruns-run-head",children:[o.jsx("strong",{children:tr(a.run_timestamp)}),o.jsx("span",{children:bf(a.eval_target)})]}),o.jsxs("div",{className:"autoruns-run-meta autoruns-run-id-row",children:[o.jsx("span",{children:a.run_id}),o.jsx("span",{role:"button",tabIndex:0,className:"autoruns-copy-run-id-btn",onClick:c=>{fr(c,a.run_id)},onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),fr(c,a.run_id))},title:"Скопировать run id","aria-label":`Скопировать run id ${a.run_id}`,children:o.jsx(Wf,{})})]}),o.jsxs("div",{className:"autoruns-run-meta",children:["режим=",a.mode??"нет данных"," | mock=",String(a.use_mock)]}),o.jsxs("div",{className:"autoruns-run-meta",children:["analysis_date=",a.analysis_date??"current_state"]}),a.llm_provider||a.model?o.jsxs("div",{className:"autoruns-run-meta",children:["llm=",a.llm_provider??"нет данных"," | модель=",a.model??"нет данных"]}):null,o.jsxs("div",{className:"autoruns-run-meta",children:["промпт=",a.prompt_version??"нет данных"]}),o.jsxs("div",{className:"autoruns-run-foot",children:[o.jsxs("span",{children:["оценка: ",ol(a.score_index)]}),o.jsxs("span",{children:["закрыто/открыто: ",a.closed_cases,"/",a.open_cases]})]}),o.jsxs("div",{className:"autoruns-run-foot",children:[o.jsxs("span",{children:["блокеры: ",a.blocking_failures]}),o.jsxs("span",{children:["качество: ",a.quality_failures]})]})]},a.run_id)),Vn.length===0?o.jsx("p",{className:"muted",children:"За выбранный диапазон прогонов нет."}):null]})]}),o.jsxs("section",{className:"autoruns-col",children:[o.jsxs("div",{className:"autoruns-col-header",children:[o.jsx("h3",{children:"Диалог прогона"}),o.jsxs("div",{className:"autoruns-dialog-toolbar",children:[o.jsxs("label",{children:["Прогон",o.jsx("select",{value:ve,onChange:a=>{const c=a.target.value;Et(c)},children:Vn.map(a=>o.jsxs("option",{value:a.run_id,children:[tr(a.run_timestamp)," | ",a.run_id]},a.run_id))})]}),o.jsxs("label",{children:["Кейс",o.jsxs("select",{value:pe,onChange:a=>{const c=a.target.value;A(c),ve&&c&&Qn(ve,c)},children:[(Z?.cases.length??0)>0?o.jsx("option",{value:pt,children:"ВСЕ кейсы подряд"}):null,(Z?.cases??[]).map(a=>o.jsxs("option",{value:a.case_id,children:[a.case_id," | ",a.status]},a.case_id))]})]})]})]}),o.jsxs("div",{className:"autoruns-case-list",children:[(Z?.cases.length??0)>0?o.jsxs("button",{type:"button",className:pe===pt?"autoruns-case-item selected":"autoruns-case-item",onClick:()=>{A(pt),ve&&Qn(ve,pt)},children:[o.jsx("span",{children:"ВСЕ кейсы подряд"}),o.jsx("span",{children:Z?.cases.length})]},pt):null,(Z?.cases??[]).map(a=>o.jsxs("button",{type:"button",className:pe===a.case_id?"autoruns-case-item selected":"autoruns-case-item",onClick:()=>{A(a.case_id),ve&&Qn(ve,a.case_id)},children:[o.jsx("span",{children:a.case_id}),o.jsxs("span",{children:[a.status,a.commented_count>0?` | комм=${a.commented_count}`:""]})]},a.case_id))]}),o.jsxs("div",{className:"autoruns-dialog-view",children:[or||sr?o.jsx("p",{className:"muted",children:"Загружаю диалог..."}):null,!or&&!sr&&(W?.messages.length??0)===0?o.jsx("p",{className:"muted",children:"Диалог для этого прогона не найден."}):null,(W?.messages??[]).map((a,c)=>{const y=a.role==="assistant"?"assistant":"user";return o.jsxs("article",{className:`autoruns-msg ${y}`,children:[o.jsxs("header",{children:[o.jsx("strong",{children:y==="assistant"?"Система":"Модель/вопрос"}),o.jsxs("div",{className:"autoruns-msg-head-actions",children:[a.case_id?o.jsx("span",{className:"autoruns-msg-case-tag",children:a.case_id}):null,o.jsx("span",{children:a.created_at?tr(a.created_at):"нет данных"}),y==="assistant"&&!xs(ve)?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:a.commented?"autoruns-comment-icon commented":"autoruns-comment-icon",onClick:()=>P(a),title:"\\u041a\\u043e\\u043c\\u043c\\u0435\\u043d\\u0442\\u0438\\u0440\\u043e\\u0432\\u0430\\u0442\\u044c \\u043e\\u0442\\u0432\\u0435\\u0442 \\u0441\\u0438\\u0441\\u0442\\u0435\\u043c\\u044b","aria-label":"\\u041a\\u043e\\u043c\\u043c\\u0435\\u043d\\u0442\\u0438\\u0440\\u043e\\u0432\\u0430\\u0442\\u044c \\u043e\\u0442\\u0432\\u0435\\u0442 \\u0441\\u0438\\u0441\\u0442\\u0435\\u043c\\u044b",children:o.jsx(Qf,{commented:a.commented})}),a.annotation?o.jsx("button",{type:"button",className:a.annotation.resolved?"autoruns-resolve-toggle resolved":"autoruns-resolve-toggle",onClick:()=>{Jr(a.annotation,!a.annotation.resolved)},disabled:lr===a.annotation.annotation_id,title:a.annotation.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный","aria-label":a.annotation.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный",children:o.jsx(Rc,{resolved:a.annotation.resolved})}):null]}):null]})]}),o.jsx("p",{children:a.text}),y==="assistant"&&a.annotation?o.jsxs("div",{className:"autoruns-msg-annotation",children:[o.jsx("strong",{children:Vi(a.annotation.rating)}),o.jsx("span",{children:a.annotation.comment}),o.jsxs("span",{className:"muted",children:[a.annotation.manual_case_decision,a.annotation.annotation_author?` | ${a.annotation.annotation_author}`:""]})]}):null,(a.trace_id||a.reply_type)&&o.jsxs("footer",{children:[a.trace_id?o.jsxs("span",{children:["trace=",a.trace_id]}):null,a.reply_type?o.jsxs("span",{children:["reply_type=",a.reply_type]}):null]})]},a.message_id??`${y}-${c}`)})]})]}),R?o.jsx("div",{className:"autoruns-col autoruns-assistant-live-col",children:o.jsx($c,{sessionId:lt,conversation:gn,inputValue:Ln,onInputChange:en,useMock:$t,onUseMockChange:Ft,onSend:_s,onClear:Nt,busy:Mr,statusText:ir,errorMessage:ar,showCommentAction:!0,onCommentAssistantMessage:eo,isAssistantMessageCommented:Sn,canCommentAssistantMessage:Wn})}):null,z?o.jsxs("section",{className:"autoruns-col",children:[o.jsx("div",{className:"autoruns-col-header",children:o.jsx("h3",{children:"Режим декомпозиции"})}),o.jsxs("div",{className:"autoruns-meta-list",children:[o.jsxs("div",{children:[o.jsx("span",{children:"кейс:"}),o.jsx("strong",{children:Dn?.case_id??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"домен:"}),o.jsx("strong",{children:Dn?.domain??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"класс запроса:"}),o.jsx("strong",{children:Dn?.query_class??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"trace:"}),o.jsx("strong",{children:Dn?.trace_id??"нет данных"})]})]}),o.jsx("h4",{children:"Шаги декомпозиции"}),(W?.decomposition.length??0)>0?o.jsx("ol",{className:"autoruns-decomposition-list",children:(W?.decomposition??[]).map((a,c)=>o.jsx("li",{children:a},`${c}-${a.slice(0,24)}`))}):o.jsx("p",{className:"muted",children:"В логах кейса нет явной декомпозиции."})]}):null,K?o.jsxs("section",{className:"autoruns-col",children:[o.jsx("div",{className:"autoruns-col-header",children:o.jsx("h3",{children:"Прогресс / регресс"})}),o.jsxs("div",{className:"autoruns-stats-grid",children:[o.jsxs("div",{children:[o.jsx("span",{children:"Последний score"}),o.jsx("strong",{children:ol(ue?.stats.latest_score_index??null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Предыдущий"}),o.jsx("strong",{children:ol(ue?.stats.previous_score_index??null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Тренд"}),o.jsx("strong",{children:ue?Ec(ue.stats.trend):"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Пробелы качества"}),o.jsx("strong",{children:ue?.stats.quality_gap_runs??0})]})]}),o.jsx("h4",{children:"Покрытие доменов (история)"}),Pc(ue?.stats.domain_coverage??[]),o.jsx("h4",{style:{marginTop:14},children:"Покрытие доменов (выбранный прогон)"}),Pc(Z?.coverage.domain_coverage??[]),o.jsx("h4",{style:{marginTop:14},children:"Очереди фиксов пост-анализа"}),qt?o.jsx("p",{className:"muted",children:"Собираю пост-анализ..."}):null,qt?null:o.jsx("div",{className:"autoruns-stats-grid",children:Object.entries(Dt?.post_analysis.stats.by_queue??{}).map(([a,c])=>o.jsxs("div",{children:[o.jsx("span",{children:a}),o.jsx("strong",{children:c})]},a))}),o.jsxs("div",{className:"autoruns-autogen-list",children:[(Dt?.post_analysis.recommended_regression_candidates??[]).slice(0,12).map(a=>o.jsxs("article",{className:"autoruns-autogen-item",children:[o.jsxs("header",{children:[o.jsx("strong",{children:a.manual_case_decision}),o.jsxs("span",{children:[a.rating,"/5"]})]}),o.jsxs("div",{className:"autoruns-run-meta",children:[a.domain??"неизвестно"," / ",a.query_class??"неизвестно"]}),o.jsx("p",{children:a.comment})]},a.annotation_id)),!qt&&(Dt?.post_analysis.recommended_regression_candidates.length??0)===0?o.jsx("p",{className:"muted",children:"Рекомендованных кандидатов пока нет."}):null]})]}):null,te?o.jsxs("section",{className:"autoruns-col",children:[o.jsx("div",{className:"autoruns-col-header",children:o.jsx("h3",{children:"Комментарии"})}),o.jsx("h4",{children:"Размеченные ответы"}),o.jsxs("div",{className:"autoruns-comment-filter-row",children:[o.jsxs("label",{children:["Фильтр решений",o.jsxs("select",{value:Te,onChange:a=>Ie(a.target.value),children:[o.jsx("option",{value:"all",children:"все"}),(tt.length>0?tt:Le?.enum??[]).map(a=>o.jsx("option",{value:a,children:String(Le?.labels?.[a]??a)},a))]})]}),o.jsx("button",{type:"button",className:"tab autoruns-resolved-filter-toggle",onClick:()=>se(a=>!a),children:$e?"Показать выполненные":"Скрыть выполненные"})]}),o.jsxs("div",{className:"autoruns-stats-grid",children:[o.jsxs("div",{children:[o.jsx("span",{children:"Комментариев"}),o.jsx("strong",{children:_e.length})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Средний рейтинг"}),o.jsx("strong",{children:Ar===null?"нет данных":`${Ar.toFixed(2)} / 5`})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Последний"}),o.jsx("strong",{children:_e.length>0?tr(_e[0].updated_at):"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Статус"}),o.jsx("strong",{children:Jt?"обновляю":"готово"})]})]}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",disabled:Jt,onClick:()=>{Ut()},children:Jt?"Обновляю...":"Обновить список"}),o.jsx("button",{type:"button",className:"tab",disabled:qt,onClick:()=>{Ye()},children:qt?"Идет пост-анализ...":"Обновить пост-анализ"})]}),o.jsxs("div",{className:"autoruns-comments-list",children:[Jt?o.jsx("p",{className:"muted",children:"Загружаю комментарии..."}):null,!Jt&&_e.length===0?o.jsx("p",{className:"muted",children:je.length===0&&Zt.length===0?"Пока нет откомментированных ответов.":"Нет открытых кейсов по текущему фильтру."}):null,_e.map(a=>{if(a.source==="assistant_live"){const y=a.assistant;return o.jsxs("article",{className:"autoruns-comment-item",children:[o.jsxs("div",{className:"autoruns-comment-head",children:[o.jsx("strong",{children:Vi(y.rating)}),o.jsx("div",{className:"autoruns-comment-head-actions",children:o.jsx("span",{children:tr(y.updated_at)})})]}),o.jsxs("div",{className:"autoruns-run-meta",children:["live-session: ",y.session_id]}),o.jsxs("div",{className:"autoruns-run-meta",children:["msg=",y.message_index]}),o.jsxs("div",{className:"autoruns-run-meta",children:["source=assistant_live",y.annotation_author?` | author=${y.annotation_author}`:""]}),y.context.question_text?o.jsxs("p",{children:["Q: ",y.context.question_text]}):null,y.context.answer_text?o.jsxs("p",{children:["A: ",y.context.answer_text]}):null,o.jsx("p",{children:y.comment})]},a.key)}const c=a.autorun;return o.jsxs("article",{className:Je===c.annotation_id?"autoruns-comment-item selected":"autoruns-comment-item",onClick:()=>{Lr(c)},role:"button",tabIndex:0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),Lr(c))},children:[o.jsxs("div",{className:"autoruns-comment-head",children:[o.jsx("strong",{children:Vi(c.rating)}),o.jsxs("div",{className:"autoruns-comment-head-actions",children:[o.jsx("span",{children:tr(c.updated_at)}),o.jsx("button",{type:"button",className:c.resolved?"autoruns-resolve-toggle resolved":"autoruns-resolve-toggle",onClick:y=>{y.preventDefault(),y.stopPropagation(),Jr(c,!c.resolved)},disabled:lr===c.annotation_id,title:c.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный","aria-label":c.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный",children:o.jsx(Rc,{resolved:c.resolved})})]})]}),o.jsx("div",{className:"autoruns-run-meta",children:c.run_id}),o.jsxs("div",{className:"autoruns-run-meta",children:["case=",c.case_id," | msg=",c.message_index]}),o.jsxs("div",{className:"autoruns-run-meta",children:["decision=",c.manual_case_decision,c.annotation_author?` | author=${c.annotation_author}`:""]}),c.resolved_at?o.jsxs("div",{className:"autoruns-run-meta",children:["выполнено",": ",tr(c.resolved_at),c.resolved_by?` | by=${c.resolved_by}`:""]}):null,c.context.question_text?o.jsxs("p",{children:["Q: ",c.context.question_text]}):null,c.context.answer_text?o.jsxs("p",{children:["A: ",c.context.answer_text]}):null,o.jsx("p",{children:c.comment})]},a.key)})]}),Ee?o.jsxs(o.Fragment,{children:[o.jsx("h4",{children:"Тех-контекст брака"}),o.jsxs("div",{className:"autoruns-meta-list",children:[o.jsxs("div",{children:[o.jsx("span",{children:"trace:"}),o.jsx("strong",{children:Ee.technical_context.trace_id??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"reply_type:"}),o.jsx("strong",{children:Ee.technical_context.reply_type??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"domain:"}),o.jsx("strong",{children:Ee.technical_context.domain??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"query_class:"}),o.jsx("strong",{children:Ee.technical_context.query_class??"нет данных"})]})]}),o.jsx("h4",{children:"JSON разбор"}),o.jsx(Wt,{value:{annotation_id:Ee.annotation_id,run_id:Ee.run_id,case_id:Ee.case_id,message_index:Ee.message_index,rating:Ee.rating,comment:Ee.comment,manual_case_decision:Ee.manual_case_decision,annotation_author:Ee.annotation_author,resolved:Ee.resolved,resolved_at:Ee.resolved_at,resolved_by:Ee.resolved_by,context:Ee.context,technical_context:Ee.technical_context,case_summary:Ee.case_summary?{case_id:Ee.case_summary.case_id,domain:Ee.case_summary.domain,query_class:Ee.case_summary.query_class,checks:Ee.case_summary.checks,metric_subscores:Ee.case_summary.metric_subscores}:null}})]}):null]}):null]}),me.open?o.jsx("div",{className:"autoruns-comment-modal-backdrop",onClick:a=>{a.target===a.currentTarget&&xn()},children:o.jsxs("div",{className:"autoruns-comment-modal",children:[o.jsx("h3",{children:"Комментарий к ответу ассистента"}),o.jsx("p",{className:"muted",children:"Комментарий будет добавлен в общий список комментариев справа с меткой `assistant_live`."}),Kr?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Вопрос пользователя"}),o.jsx("p",{className:"autoruns-comment-quote",children:Kr.text})]}):null,Tr?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Ответ ассистента"}),o.jsx("p",{className:"autoruns-comment-quote",children:Tr.text})]}):null,o.jsx("div",{className:"autoruns-rating-row",role:"group","aria-label":"Рейтинг ответа ассистента",children:[1,2,3,4,5].map(a=>o.jsx("button",{type:"button",className:me.rating>=a?"autoruns-rating-dot active":"autoruns-rating-dot",onClick:()=>vt(c=>({...c,rating:a})),disabled:me.saving,"aria-label":`Оценка ${a}`,children:me.rating>=a?"●":"○"},a))}),o.jsx("div",{className:"autoruns-form-grid",children:o.jsxs("label",{children:["Автор комментария",o.jsx("input",{value:me.annotationAuthor,onChange:a=>vt(c=>({...c,annotationAuthor:a.target.value})),placeholder:"manual_reviewer",disabled:me.saving})]})}),o.jsxs("label",{children:["Комментарий",o.jsx("textarea",{value:me.comment,onChange:a=>vt(c=>({...c,comment:a.target.value})),placeholder:"Что именно не так в ответе и что нужно исправить.",rows:4,disabled:me.saving})]}),me.error?o.jsx("p",{className:"error-text",children:me.error}):null,o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>{to()},disabled:me.saving,children:me.saving?"Сохраняю...":"Готово"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>xn(),disabled:me.saving,children:"Отмена"})]})]})}):null,ae.open?o.jsx("div",{className:"autoruns-comment-modal-backdrop",onClick:a=>{a.target===a.currentTarget&&j()},children:o.jsxs("div",{className:"autoruns-comment-modal",children:[o.jsx("h3",{children:"Комментарий к ответу системы"}),o.jsx("p",{className:"muted",children:"Оцените ответ по 5-балльной шкале и добавьте комментарий по браку."}),On?o.jsxs(o.Fragment,{children:[o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Вопрос пользователя"}),o.jsx("p",{className:"autoruns-comment-quote",children:Rr?.text??"Вопрос в диалоге не найден."})]}),o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Ответ системы"}),o.jsx("p",{className:"autoruns-comment-quote",children:On.text})]})]}):null,o.jsx("div",{className:"autoruns-rating-row",role:"group","aria-label":"Рейтинг ответа",children:[1,2,3,4,5].map(a=>o.jsx("button",{type:"button",className:ae.rating>=a?"autoruns-rating-dot active":"autoruns-rating-dot",onClick:()=>qe(c=>({...c,rating:a})),disabled:ae.saving,"aria-label":`Оценка ${a}`,children:ae.rating>=a?"●":"○"},a))}),o.jsxs("div",{className:"autoruns-form-grid",children:[o.jsxs("label",{children:["Решение по кейсу",o.jsx("select",{value:ae.manualCaseDecision,onChange:a=>qe(c=>({...c,manualCaseDecision:a.target.value})),disabled:ae.saving,children:(tt.length>0?tt:Le?.enum??[rl]).map(a=>o.jsx("option",{value:a,children:String(Le?.labels?.[a]??a)},a))})]}),o.jsxs("label",{children:["Автор комментария",o.jsx("input",{value:ae.annotationAuthor,onChange:a=>qe(c=>({...c,annotationAuthor:a.target.value})),placeholder:"manual_reviewer",disabled:ae.saving})]})]}),o.jsxs("label",{children:["Комментарий",o.jsx("textarea",{value:ae.comment,onChange:a=>qe(c=>({...c,comment:a.target.value})),placeholder:"Почему ответ бракованный, что именно пошло не так, какие технические детали проверить.",rows:4,disabled:ae.saving})]}),ae.error?o.jsx("p",{className:"error-text",children:ae.error}):null,o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>{xe()},disabled:ae.saving,children:ae.saving?"Сохраняю...":"Готово"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>j(),disabled:ae.saving,children:"Отмена"})]})]})}):null]})}function Tc({value:i,modelOptions:g,modelsBusy:h,onChange:O,onReloadModels:R,onTestConnection:z,onSaveLocalConfig:K,lastStatus:te,busy:U}){const I=i.llmProvider==="local",q=g.includes(i.model),[L,H]=x.useState(String(i.temperature)),[ue,Re]=x.useState(String(i.maxOutputTokens));x.useEffect(()=>{H(String(i.temperature))},[i.temperature]),x.useEffect(()=>{Re(String(i.maxOutputTokens))},[i.maxOutputTokens]);const Z=W=>{const ie=W.replace(",",".").trim();if(!ie){H(String(i.temperature));return}const je=Number(ie);if(!Number.isFinite(je)){H(String(i.temperature));return}O({...i,temperature:je}),H(String(je))},re=W=>{const ie=W.trim();if(!ie){Re(String(i.maxOutputTokens));return}const je=Number.parseInt(ie,10);if(!Number.isFinite(je)||je<=0){Re(String(i.maxOutputTokens));return}O({...i,maxOutputTokens:je}),Re(String(je))};return o.jsxs(Mn,{title:"LLM Connection",subtitle:"Switch between OpenAI cloud and local OpenAI-compatible server.",actions:o.jsx("span",{className:"status-chip",children:te||"Status: not checked"}),children:[o.jsxs("div",{className:"grid-two",children:[o.jsxs("label",{children:["Provider",o.jsxs("select",{value:i.llmProvider,onChange:W=>{const ie=W.target.value==="local"?"local":"openai";O({...i,llmProvider:ie,baseUrl:ie==="local"?"http://127.0.0.1:1234/v1":"https://api.openai.com/v1"})},children:[o.jsx("option",{value:"openai",children:"OpenAI (token)"}),o.jsx("option",{value:"local",children:"Local (LM Studio / OpenAI-compatible)"})]})]}),o.jsxs("label",{children:["Model",o.jsxs("select",{value:q?i.model:"__manual__",onChange:W=>{const ie=W.target.value;ie!=="__manual__"&&O({...i,model:ie})},children:[o.jsx("option",{value:"__manual__",children:"Manual input"}),g.map(W=>o.jsx("option",{value:W,children:W},W))]})]}),o.jsxs("label",{children:["Model ID (manual)",o.jsx("input",{value:i.model,onChange:W=>O({...i,model:W.target.value}),placeholder:"qwen2.5-14b-instruct or lmstudio loaded model id"})]}),I?null:o.jsxs("label",{className:"full-width",children:["OpenAI API Key",o.jsx("input",{type:"password",value:i.apiKey,onChange:W=>O({...i,apiKey:W.target.value}),placeholder:"sk-..."})]}),o.jsxs("label",{className:I?"full-width":void 0,children:[I?"Local server base URL":"Base URL",o.jsx("input",{value:i.baseUrl,onChange:W=>O({...i,baseUrl:W.target.value}),placeholder:I?"http://127.0.0.1:1234/v1":"https://api.openai.com/v1"})]}),o.jsxs("label",{children:["Temperature",o.jsx("input",{type:"number",step:"0.1",value:L,onChange:W=>H(W.target.value),onBlur:W=>Z(W.target.value),onKeyDown:W=>{W.key==="Enter"&&Z(W.target.value)}})]}),o.jsxs("label",{children:["Max output tokens",o.jsx("input",{type:"number",value:ue,onChange:W=>Re(W.target.value),onBlur:W=>re(W.target.value),onKeyDown:W=>{W.key==="Enter"&&re(W.target.value)}})]})]}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>K(),children:"Save local config"}),o.jsx("button",{type:"button",onClick:()=>R(),disabled:U||h,children:h?"Loading models...":"Load model list"}),o.jsx("button",{type:"button",onClick:()=>z(),disabled:U,children:U?"Checking...":"Test connection"})]})]})}function qf({items:i,onRefresh:g,onOpenTrace:h}){return o.jsx(Mn,{title:"История нормализаций",subtitle:"Короткий вопрос, confidence, route hint и статус валидации.",actions:o.jsx("button",{type:"button",onClick:()=>g(),children:"Обновить"}),children:o.jsxs("div",{className:"history-list",children:[i.length===0?o.jsx("p",{className:"muted",children:"История пока пустая."}):null,i.map(O=>o.jsxs("button",{type:"button",className:"history-item",onClick:()=>h(O.trace_id),children:[o.jsxs("div",{className:"history-row",children:[o.jsx("strong",{children:O.route_hint??"route: n/a"}),o.jsx("span",{children:O.validation_passed?"schema: ok":"schema: fail"})]}),o.jsx("p",{children:O.question_short}),o.jsxs("div",{className:"history-row",children:[o.jsx("span",{children:O.model}),o.jsx("span",{children:new Date(O.timestamp).toLocaleString("ru-RU")})]})]},O.trace_id))]})})}function nr(i){return i==null||i===""?"—":String(i)}function Gf({result:i}){return o.jsx(Mn,{title:"Runtime метрики",subtitle:"trace_id, токены, latency и статус валидации.",children:o.jsxs("div",{className:"metrics-grid",children:[o.jsxs("div",{children:[o.jsx("span",{children:"trace_id"}),o.jsx("strong",{children:nr(i?.trace_id)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"request_started_at"}),o.jsx("strong",{children:nr(i?new Date(Date.now()-i.latency_ms).toISOString():null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"request_finished_at"}),o.jsx("strong",{children:nr(i?new Date().toISOString():null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"latency_ms"}),o.jsx("strong",{children:nr(i?.latency_ms)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"input_tokens"}),o.jsx("strong",{children:nr(i?.usage?.input_tokens)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"output_tokens"}),o.jsx("strong",{children:nr(i?.usage?.output_tokens)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"total_tokens"}),o.jsx("strong",{children:nr(i?.usage?.total_tokens)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"validation_status"}),o.jsx("strong",{children:i?.validation?.passed?"passed":"failed"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"prompt_version"}),o.jsx("strong",{children:nr(i?.prompt_version)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"schema_version"}),o.jsx("strong",{children:nr(i?.schema_version)})]})]})})}const Jf={normalized:"Normalized JSON",fragments:"Fragment View",scope:"Scope View",flags:"Flags View",route:"Route Simulation",raw:"Raw model output",validation:"Validation",logs:"Logs"};function Yf(i){return i&&typeof i=="object"?i:null}function Xf({tab:i,onTabChange:g,result:h,appLogs:O}){const R=["normalized","fragments","scope","flags","route","raw","validation","logs"],z=Yf(h?.normalized),K=String(z?.schema_version??""),te=K==="normalized_query_v2"||K==="normalized_query_v2_0_1"||K==="normalized_query_v2_0_2",U=te?{fragments:z?.fragments??[],discarded_fragments:z?.discarded_fragments??[]}:{note:"Fragment View доступен для normalized_query_v2."},I=te?{message_in_scope:z?.message_in_scope??null,scope_confidence:z?.scope_confidence??null,contains_multiple_tasks:z?.contains_multiple_tasks??null,global_notes:z?.global_notes??null}:{note:"Scope View доступен для normalized_query_v2."},q=te?Array.isArray(z?.fragments)?(z?.fragments).map(L=>({fragment_id:L.fragment_id??null,domain_relevance:L.domain_relevance??null,candidate_labels:L.candidate_labels??[],execution_readiness:L.execution_readiness??null,clarification_reason:L.clarification_reason??null,soft_assumption_used:L.soft_assumption_used??[],route_status:L.route_status??null,no_route_reason:L.no_route_reason??null,flags:L.flags??{}})):[]:{note:"Flags View доступен для normalized_query_v2."};return o.jsxs(Mn,{title:"Выходные данные",subtitle:"Structured output и диагностические вкладки.",children:[o.jsx("div",{className:"tab-row",children:R.map(L=>o.jsx("button",{type:"button",className:i===L?"tab active":"tab",onClick:()=>g(L),children:Jf[L]},L))}),i==="normalized"?o.jsx(Wt,{value:h?.normalized??{note:"Нет данных."}}):null,i==="fragments"?o.jsx(Wt,{value:U}):null,i==="scope"?o.jsx(Wt,{value:I}):null,i==="flags"?o.jsx(Wt,{value:q}):null,i==="route"?o.jsx(Wt,{value:h?.route_hint_summary??{note:"Нет данных."}}):null,i==="raw"?o.jsx(Wt,{value:h?.raw_model_output??{note:"Нет данных."}}):null,i==="validation"?o.jsx(Wt,{value:h?.validation??{note:"Нет данных."}}):null,i==="logs"?o.jsx(Wt,{value:O}):null]})}function Ac({value:i,onChange:g,presets:h,selectedPresetId:O,onSelectPreset:R,onLoadPreset:z,onSavePreset:K,onResetDefaults:te,onDiffPrevious:U,presetName:I,onPresetNameChange:q,diffSummary:L}){return o.jsxs(Mn,{title:"Prompt Manager",subtitle:"Системный, developer и domain уровни управляются отдельно.",children:[o.jsxs("div",{className:"prompt-manager-grid",children:[o.jsxs("label",{children:["Системный prompt",o.jsx("textarea",{value:i.systemPrompt,onChange:H=>g({...i,systemPrompt:H.target.value}),rows:6})]}),o.jsxs("label",{children:["Developer / Instruction prompt",o.jsx("textarea",{value:i.developerPrompt,onChange:H=>g({...i,developerPrompt:H.target.value}),rows:6})]}),o.jsxs("label",{children:["Domain prompt",o.jsx("textarea",{value:i.domainPrompt,onChange:H=>g({...i,domainPrompt:H.target.value}),rows:6})]}),o.jsxs("label",{children:["Schema notes",o.jsx("textarea",{value:i.schemaNotes,onChange:H=>g({...i,schemaNotes:H.target.value}),rows:6})]}),o.jsxs("label",{className:"full-width",children:["Few-shot examples",o.jsx("textarea",{value:i.fewShotExamples,onChange:H=>g({...i,fewShotExamples:H.target.value}),rows:8})]})]}),o.jsxs("div",{className:"button-row",children:[o.jsxs("select",{value:O,onChange:H=>R(H.target.value),children:[o.jsx("option",{value:"",children:"Выберите preset..."}),h.map(H=>o.jsx("option",{value:H.id,children:H.name},H.id))]}),o.jsx("button",{type:"button",onClick:()=>z(),children:"Загрузить preset"}),o.jsx("input",{value:I,onChange:H=>q(H.target.value),placeholder:"Имя для сохранения"}),o.jsx("button",{type:"button",onClick:()=>K(),children:"Сохранить preset"}),o.jsx("button",{type:"button",onClick:()=>U(),children:"Diff с предыдущим"}),o.jsx("button",{type:"button",onClick:()=>te(),children:"Сбросить к default"})]}),L?o.jsx("p",{className:"diff-summary",children:L}):null]})}function Zf({value:i,onChange:g,onApplyBatchFormat:h,onNormalize:O,busy:R,useMock:z,onUseMockChange:K,errorMessage:te}){return o.jsxs(Mn,{title:"Запрос пользователя",subtitle:"NDC semantic front-end: нормализуем, но не отвечаем за бухгалтерскую суть.",children:[o.jsxs("div",{className:"grid-two",children:[o.jsxs("label",{className:"full-width",children:["Raw user question",o.jsx("textarea",{value:i.userQuestion,onChange:U=>g({...i,userQuestion:U.target.value}),rows:6,placeholder:"Например: По каким покупателям у нас на конец июня висят отгрузки без оплаты..."})]}),o.jsxs("label",{className:"full-width",children:["Batch queries (`;` separator)",o.jsx("textarea",{value:i.batchQuestionsRaw,onChange:U=>g({...i,batchQuestionsRaw:U.target.value}),onBlur:()=>h(),rows:8,placeholder:"Вопрос 1; Вопрос 2; Вопрос 3"})]}),o.jsxs("label",{children:["Optional period context",o.jsx("input",{value:i.periodHint,onChange:U=>g({...i,periodHint:U.target.value})})]}),o.jsxs("label",{children:["Optional business context",o.jsx("input",{value:i.businessContext,onChange:U=>g({...i,businessContext:U.target.value})})]}),o.jsxs("label",{children:["Optional expected route (eval)",o.jsx("input",{value:i.expectedRoute,onChange:U=>g({...i,expectedRoute:U.target.value})})]})]}),o.jsxs("div",{className:"button-row",children:[o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:z,onChange:U=>K(U.target.checked)}),"Mock-режим (без вызова OpenAI)"]}),o.jsx("button",{type:"button",onClick:()=>h(),disabled:R||!i.batchQuestionsRaw.trim(),children:"Применить `;` в переносы"}),o.jsx("button",{type:"button",onClick:()=>O(!1),disabled:R||!i.userQuestion.trim(),children:R?"Нормализуем...":"Normalize"}),o.jsx("button",{type:"button",onClick:()=>O(!0),disabled:R||!i.userQuestion.trim(),children:R?"Сохраняем...":"Normalize + Save as test case"})]}),te?o.jsx("p",{className:"error-text",children:te}):null]})}function em({runs:i,selectedRunId:g,onSelectRun:h,onStartRun:O,onFinishRun:R,onRefreshRuns:z,onRunEval:K,onCopyEvalReport:te,evalBusy:U,traceItems:I,evalReport:q}){return o.jsxs(Mn,{title:"NDC Run Monitor",subtitle:"Важно: кнопка Запустить run создает только run-сущность. Кнопка eval запускает batch-проверку normalizer v2.0.2.",children:[o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>O(),children:"Запустить run"}),o.jsx("button",{type:"button",onClick:()=>R(),disabled:!g,children:"Завершить выбранный run"}),o.jsx("button",{type:"button",onClick:()=>z(),children:"Обновить runs"}),o.jsx("button",{type:"button",onClick:()=>K(),disabled:U,children:U?"Идет eval v2.0.2...":"Запустить eval v2.0.2"})]}),o.jsxs("div",{className:"runtime-stack",children:[o.jsxs("div",{className:"runtime-runs",children:[i.map(L=>o.jsxs("button",{type:"button",className:g===L.runId?"history-item selected":"history-item",onClick:()=>h(L.runId),children:[o.jsxs("div",{className:"history-row",children:[o.jsx("strong",{children:L.status}),o.jsx("span",{children:L.runId})]}),o.jsxs("div",{className:"history-row",children:[o.jsx("span",{children:L.sessionId}),o.jsx("span",{children:new Date(L.updatedAt).toLocaleString("ru-RU")})]})]},L.runId)),i.length===0?o.jsx("p",{className:"muted",children:"Нет активных запусков."}):null]}),o.jsxs("div",{className:"runtime-details",children:[o.jsx("h3",{children:"Trace выбранного run"}),o.jsx(Wt,{value:I}),o.jsxs("div",{className:"eval-report-wrap",children:[o.jsx("h3",{style:{marginTop:12},children:"Отчет eval"}),o.jsx(Wt,{value:q??{note:"Eval пока не запускался"}}),o.jsx("button",{type:"button",className:"copy-cube-button",title:"Скопировать отчет eval",onClick:()=>te(),children:"⧉"})]})]})]})]})}const tm={llmProvider:"openai",apiKey:"",model:"gpt-4o-mini",baseUrl:"https://api.openai.com/v1",temperature:0,maxOutputTokens:700},Ic={systemPrompt:"Ты semantic-normalizer для бухгалтерского ассистента NDC. Возвращай только JSON по схеме normalized_query_v2_0_2.",developerPrompt:"Сначала делай decomposition сообщения на task fragments, затем определяй domain scope и route-critical flags. Для каждого fragment заполняй execution_readiness + route_status + no_route_reason. Если fragment routable, не оставляй его в no_route.",domainPrompt:"Контур: данные текущего предприятия в 1С/NDC. In-scope: документы, проводки, взаиморасчеты, остатки, периодное закрытие, аномалии и контрольные проверки. Out-of-scope: общая теория, законы и оффтоп.",schemaNotes:"schema_version: normalized_query_v2_0_2. Строгий JSON без дополнительных полей.",fewShotExamples:"Q: Проверь по поставщикам хвосты и разложи цепочку документов/оплат. => fragment in_scope, flags: multi_entity + chain_explanation. Q: Как вообще по ФСБУ? => out_of_scope/generic_accounting."},nm={userQuestion:"",batchQuestionsRaw:"",periodHint:"",businessContext:"",expectedRoute:""},Qi={colors:{backgroundRgb:"18, 18, 18",mainSurfaceRgb:"25, 25, 25",horizontalSurfaceRgb:"30, 30, 30",focusSurfaceRgb:"35, 35, 35",activeRgb:"167, 59, 255",activeTextRgb:"240, 240, 240",textMainRgb:"240, 240, 240",textMutedRgb:"166, 166, 166",dangerRgb:"126, 126, 126",scrollbarTrackRgb:"20, 20, 20",scrollbarThumbRgb:"30, 30, 30",scrollbarThumbHoverRgb:"30, 50, 30"},layout:{modeColumnWidthPx:406,modeToggleWidthPx:188}},Lc="ndc_normalizer_session_config_v1",Dc="ndc_autoruns_layout_config_v1",rm="ndc-autoruns-save",Wi=["Анализ запроса","Получение данных","Подготовка ответа"],sm="assistant",Ki="normalizer_v2_0_2",Oc="address_query_runtime_v1",om=["normalized","fragments","scope","flags","route","raw","validation","logs"],qi="manual_reviewer";function lm(i){return`[${new Date().toLocaleTimeString("ru-RU")}] ${i}`}function im(i,g){if(!g)return"Previous preset is not selected.";const O=["systemPrompt","developerPrompt","domainPrompt","schemaNotes","fewShotExamples"].filter(R=>i[R]!==g[R]).map(R=>`${R}: ${Math.abs(i[R].length-g[R].length)} chars delta`);return O.length===0?"No changes against previous preset.":`Changed fields: ${O.length}. ${O.join(" | ")}`}function am(){const[i,g]=x.useState(tm),[h,O]=x.useState(Ic),[R,z]=x.useState(nm),[K,te]=x.useState(null),[U,I]=x.useState([]),[q,L]=x.useState([]),[H,ue]=x.useState("normalized"),[Re,Z]=x.useState(!1),[re,W]=x.useState(!1),[ie,je]=x.useState([]),[ze,Te]=x.useState(""),[Ie,$e]=x.useState([]),[se,Le]=x.useState(""),[We,tt]=x.useState("NDC custom preset"),[jt,Je]=x.useState(null),[nt,ve]=x.useState(""),[Me,pe]=x.useState(!1),[A,V]=x.useState([]),[D,m]=x.useState(""),[k,G]=x.useState([]),[ce,de]=x.useState(!1),[fe,ye]=x.useState(null),[ge,ee]=x.useState(""),[Ce,Dt]=x.useState(sm),[Hn,Rn]=x.useState(!0),[Tn,rr]=x.useState(!0),[Kt,qt]=x.useState(!0),[bn,fn]=x.useState(!0),[Ot,Gt]=x.useState(!0),[mn,sr]=x.useState(!0),[An,or]=x.useState(!0),[In,Jt]=x.useState(!0),[Yt,lr]=x.useState(!0),[zt,pn]=x.useState(!0),[Ue,lt]=x.useState(!0),[hn,gn]=x.useState(!0),[Xt,Zt]=x.useState(!0),[kt,Ln]=x.useState(!0),[en,$t]=x.useState(!0),[Ft,Mr]=x.useState(!0),[be,ir]=x.useState(""),[Ct,ar]=x.useState([]),[tn,ur]=x.useState(""),[ht,cr]=x.useState(!1),[gt,vn]=x.useState(""),[yn,ae]=x.useState(""),[qe,me]=x.useState([]),[vt,dr]=x.useState(!1),[ke,Ve]=x.useState({open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:qi,saving:!1,error:""}),yt=x.useRef(!1),Dn=x.useRef(!1);x.useEffect(()=>{const f=document.documentElement,{colors:P}=Qi;f.style.setProperty("--rgb-background",P.backgroundRgb),f.style.setProperty("--rgb-surface-main",P.mainSurfaceRgb),f.style.setProperty("--rgb-surface-horizontal",P.horizontalSurfaceRgb),f.style.setProperty("--rgb-surface-focus",P.focusSurfaceRgb),f.style.setProperty("--rgb-active",P.activeRgb),f.style.setProperty("--rgb-active-text",P.activeTextRgb),f.style.setProperty("--rgb-text-main",P.textMainRgb),f.style.setProperty("--rgb-text-muted",P.textMutedRgb),f.style.setProperty("--rgb-danger",P.dangerRgb),f.style.setProperty("--rgb-scrollbar-track",P.scrollbarTrackRgb),f.style.setProperty("--rgb-scrollbar-thumb",P.scrollbarThumbRgb),f.style.setProperty("--rgb-scrollbar-thumb-hover",P.scrollbarThumbHoverRgb),f.style.setProperty("--mode-column-width",`${Qi.layout.modeColumnWidthPx}px`),f.style.setProperty("--mode-toggle-width",`${Qi.layout.modeToggleWidthPx}px`)},[]);const J=f=>{L(P=>[lm(f),...P].slice(0,300))};function Ee(){let f=0;vn(Wi[0]);const P=window.setInterval(()=>{f=Math.min(f+1,Wi.length-1),vn(Wi[f])},650);return()=>window.clearInterval(P)}x.useEffect(()=>{const f=localStorage.getItem(Lc);if(f)try{const j=JSON.parse(f);g(xe=>({...xe,llmProvider:j.llmProvider==="local"?"local":"openai",model:j.model??xe.model,baseUrl:j.baseUrl??xe.baseUrl,temperature:j.temperature??xe.temperature,maxOutputTokens:j.maxOutputTokens??xe.maxOutputTokens}))}catch{}const P=localStorage.getItem(Dc);if(P)try{const j=JSON.parse(P);(j.uiMode==="assistant"||j.uiMode==="decomposition"||j.uiMode==="autoruns")&&Dt(j.uiMode),j.activeTab&&om.includes(j.activeTab)&&ue(j.activeTab),typeof j.showAutorunsAssistantMode=="boolean"&&Rn(j.showAutorunsAssistantMode),typeof j.showAutorunsDecompositionMode=="boolean"&&rr(j.showAutorunsDecompositionMode),typeof j.showAutorunsProgressMode=="boolean"&&qt(j.showAutorunsProgressMode),typeof j.showAutorunsCommentsMode=="boolean"&&fn(j.showAutorunsCommentsMode),typeof j.showAssistantConnectionMode=="boolean"&&Gt(j.showAssistantConnectionMode),typeof j.showAssistantPromptMode=="boolean"&&sr(j.showAssistantPromptMode),typeof j.showAssistantChatMode=="boolean"&&or(j.showAssistantChatMode),typeof j.showAssistantCommentsMode=="boolean"&&Jt(j.showAssistantCommentsMode),typeof j.showAssistantSamMode=="boolean"&&lr(j.showAssistantSamMode),typeof j.showDecompositionConnectionMode=="boolean"&&pn(j.showDecompositionConnectionMode),typeof j.showDecompositionPromptMode=="boolean"&<(j.showDecompositionPromptMode),typeof j.showDecompositionQueryMode=="boolean"&&gn(j.showDecompositionQueryMode),typeof j.showDecompositionOutputMode=="boolean"&&Zt(j.showDecompositionOutputMode),typeof j.showDecompositionMetricsMode=="boolean"&&Ln(j.showDecompositionMetricsMode),typeof j.showDecompositionHistoryMode=="boolean"&&$t(j.showDecompositionHistoryMode),typeof j.showDecompositionRuntimeMode=="boolean"&&Mr(j.showDecompositionRuntimeMode),j.prompts&&(O(xe=>({...xe,...j.prompts})),Dn.current=!0)}catch{}On(),Rr(),nn()},[]);async function On(){try{const f=await Ne.loadHistory();I(f.items??[])}catch(f){J(`History load error: ${f instanceof Error?f.message:String(f)}`)}}async function Rr(){try{const P=(await Ne.loadPresets()).presets??[];if($e(P),Dn.current){yt.current=!0;return}if(yt.current)return;const j=P.find(xe=>xe.prompt_version===Ki)??P.find(xe=>xe.id==="default-normalizer-v2_0_2");if(!j){yt.current=!0,J(`Preset autoload skipped: ${Ki} not found.`);return}Le(j.id),Je(h),O({systemPrompt:j.systemPrompt,developerPrompt:j.developerPrompt,domainPrompt:j.domainPrompt,schemaNotes:j.schemaNotes??"",fewShotExamples:j.fewShotExamples??""}),yt.current=!0,J(`Preset autoloaded: ${j.name} (${j.prompt_version}).`)}catch(f){J(`Presets load error: ${f instanceof Error?f.message:String(f)}`)}}async function nn(){try{const f=await Ne.listRuns();V(f.items??[])}catch(f){J(`Runs load error: ${f instanceof Error?f.message:String(f)}`)}}function Tr(){localStorage.setItem(Lc,JSON.stringify({model:i.model,llmProvider:i.llmProvider,baseUrl:i.baseUrl,temperature:i.temperature,maxOutputTokens:i.maxOutputTokens})),J("Local config saved (without API key).")}function Kr(){localStorage.setItem(Dc,JSON.stringify({uiMode:Ce,activeTab:H,showAutorunsAssistantMode:Hn,showAutorunsDecompositionMode:Tn,showAutorunsProgressMode:Kt,showAutorunsCommentsMode:bn,showAssistantConnectionMode:Ot,showAssistantPromptMode:mn,showAssistantChatMode:An,showAssistantCommentsMode:In,showAssistantSamMode:Yt,showDecompositionConnectionMode:zt,showDecompositionPromptMode:Ue,showDecompositionQueryMode:hn,showDecompositionOutputMode:Xt,showDecompositionMetricsMode:kt,showDecompositionHistoryMode:en,showDecompositionRuntimeMode:Ft,prompts:h})),window.dispatchEvent(new CustomEvent(rm)),J("UI layout and prompts saved.")}async function _e(){Z(!0),ee("");try{const f=await Ne.testConnection(i);f.provider==="local"?f.model_found===!0?(Te(`LOCAL OK - ${f.model}`),J(`Local model is available: ${f.model} (catalog size=${f.models_count??"n/a"}).`)):f.model_found===!1?(Te(`LOCAL OK, model not loaded - ${f.model}`),J(`Local server is reachable, but model '${f.model}' is not in loaded catalog. Use 'Load model list' and select one of loaded models.`)):(Te(`LOCAL OK (model list unavailable) - ${f.model}`),J("Local server is reachable, but model catalog could not be verified.")):(Te(`OPENAI OK - ${f.model}`),J(`OpenAI connection ok: ${f.model}`))}catch(f){const P=f instanceof Error?f.message:String(f);Te("Connection error"),ee(`Test connection: ${P}`),J(`Test connection error: ${P}`)}finally{Z(!1)}}async function Ar(){W(!0);try{const P=(await Ne.listModels(i)).models??[];je(P),P.length>0&&g(j=>j.model&&P.includes(j.model)?j:{...j,model:P[0]}),J(`Model catalog loaded (${i.llmProvider}): ${P.length} items.`)}catch(f){const P=f instanceof Error?f.message:String(f);J(`Load model list error: ${P}`)}finally{W(!1)}}x.useEffect(()=>{je([])},[i.llmProvider,i.baseUrl]);async function Vn(f){Z(!0),ee("");try{const P=await Ne.normalize({connection:i,prompts:h,promptVersion:"normalizer_v2_0_2",query:{userQuestion:R.userQuestion,periodHint:R.periodHint,businessContext:R.businessContext,expectedRoute:R.expectedRoute},saveAsTestCase:f,useMock:Me});te(P),ue("normalized"),J(`Normalize done: trace=${P.trace_id}, validation=${P.validation.passed?"passed":"failed"}`),On()}catch(P){const j=P instanceof Error?P.message:String(P);ee(`Normalize: ${j}`),J(`Normalize error: ${j}`)}finally{Z(!1)}}function oe(){const f=Ie.find(P=>P.id===se);if(!f){J("Preset is not selected.");return}Je(h),O({systemPrompt:f.systemPrompt,developerPrompt:f.developerPrompt,domainPrompt:f.domainPrompt,schemaNotes:f.schemaNotes??"",fewShotExamples:f.fewShotExamples??""}),J(`Preset loaded: ${f.name}`)}async function rn(){try{await Ne.savePreset({name:We||"NDC preset",prompt_version:"normalizer_v2_0_2",systemPrompt:h.systemPrompt,developerPrompt:h.developerPrompt,domainPrompt:h.domainPrompt,schemaNotes:h.schemaNotes,fewShotExamples:h.fewShotExamples}),J("Preset saved."),await Rr()}catch(f){J(`Preset save error: ${f instanceof Error?f.message:String(f)}`)}}function xn(){O(Ic),J("Prompt panel reset to defaults.")}function fr(){const f=im(h,jt);ve(f),J(f)}function mr(){const f=R.batchQuestionsRaw.split(";").map(P=>P.trim()).filter(Boolean).join(` `);f&&(z(P=>({...P,batchQuestionsRaw:f})),J("Batch field formatted: `;` converted to blank-line separators."))}async function Nt(f){try{const j=(await Ne.loadTrace(f)).trace,xe=j.parsed_normalized_json??null;te({trace_id:String(j.trace_id??f),ok:!!j.validation_result?.passed,normalized:xe,route_hint_summary:j.route_hint_summary??(xe?{route_hint:xe.route_hint??null,confidence:xe.confidence?.route_hint??null}:null),raw_model_output:j.raw_model_response??{},validation:j.validation_result??{passed:!1,errors:["validation not found"]},usage:j.usage??{input_tokens:0,output_tokens:0,total_tokens:0},latency_ms:Number(j.latency_ms??0),prompt_version:String(j.prompt_version??"unknown"),schema_version:String(j.schema_version??"unknown")}),ue("raw"),ee(""),J(`Trace opened: ${f}`)}catch(P){const j=P instanceof Error?P.message:String(P);ee(`Trace: ${j}`),J(`Trace open error ${f}: ${j}`)}}async function _s(){try{const f=await Ne.startRun();m(f.run.runId),J(`Run started: ${f.run.runId}`),J("Tip: start run does not execute normalize by itself. Use 'Run eval v2.0.2' button."),await nn()}catch(f){J(`Run start error: ${f instanceof Error?f.message:String(f)}`)}}async function ut(){if(D)try{await Ne.finishRun(D),J(`Run finished: ${D}`),await nn()}catch(f){J(`Run finish error: ${f instanceof Error?f.message:String(f)}`)}}async function qr(){de(!0),ee("");try{J("Starting eval in v2 contour.");const f=R.batchQuestionsRaw.trim()||R.userQuestion.trim();if(!f)throw new Error("Fill batch field or Raw user question first.");const P=await Ne.runEval({connection:i,prompts:h,promptVersion:"normalizer_v2_0_2",mode:"single-pass-strict",rawQuestions:f,useMock:Me});ye(P.report),J("Eval v2.0.2 run finished.");const j=P.report;if(j.run_id&&J(`Eval run id: ${j.run_id}`),j.metrics){const xe=j.metrics;J(`Eval metrics v2.0.2: schema=${xe.schema_validation_pass_rate??"n/a"}%, route_accuracy=${xe.route_resolution_accuracy??"n/a"}%, no_route_precision=${xe.no_route_precision??"n/a"}%, state_consistency=${xe.execution_state_consistency_rate??"n/a"}%`)}await On()}catch(f){const P=f instanceof Error?f.message:String(f);P.includes("Legacy eval runner supports normalized_query_v1 only")?(ye({status:"plan_only",prompt_version:"normalizer_v2",reason:"backend eval runner is still legacy-v1 only",plan_file:"reports/v2_pilot_eval_plan.md",next_steps:["run cheap mock sanity for schema/fragment/scope","run small real batch (10-15 messages, temperature=0)","run challenge-30 replay with v2 metrics"]}),J("Backend is legacy-only for eval right now. Showing v2 pilot plan.")):(ee(`Eval: ${P}`),J(`Eval run error: ${P}`))}finally{de(!1)}}async function Gr(){try{const f=JSON.stringify(fe??{},null,2);await navigator.clipboard.writeText(f),J("Eval report copied to clipboard.")}catch(f){J(`Eval report copy error: ${f instanceof Error?f.message:String(f)}`)}}const Ir=x.useMemo(()=>{const f=new Map;for(const P of qe)P.message_id&&f.set(P.message_id,P);return f},[qe]),Ut=ke.messageIndex>=0?Ct[ke.messageIndex]??null:null,xt=x.useMemo(()=>{if(ke.messageIndex<0)return null;for(let f=ke.messageIndex-1;f>=0;f-=1){const P=Ct[f];if(P?.role==="user")return P}return null},[ke.messageIndex,Ct]);async function sn(f){if(!f.trim()){me([]);return}dr(!0);try{const P=await Ne.loadAssistantAnnotations({session_id:f,limit:400});me(P.items??[])}catch(P){const j=P instanceof Error?P.message:String(P);J(`Assistant annotations load error: ${j}`)}finally{dr(!1)}}function Ye(f){Ve(P=>P.saving&&!f?.force?P:{open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:qi,saving:!1,error:""})}function Ss(f,P){if(f.role!=="assistant")return;const j=be.trim(),xe=String(f.session_id??"").trim();if(!(j||xe)){ae("Сначала получите ответ ассистента в активной сессии.");return}!j&&xe&&ir(xe);const Sn=Ir.get(f.message_id)??null;Ve({open:!0,messageIndex:P,rating:Sn?.rating??3,comment:Sn?.comment??"",annotationAuthor:Sn?.annotation_author??qi,saving:!1,error:""})}function Qn(f){return f.role==="assistant"}function Et(f){return f.role==="assistant"&&Ir.has(f.message_id)}async function zn(){if(!be.trim()){Ve(f=>({...f,error:"Сессия ассистента не найдена."}));return}if(!(ke.messageIndex<0)){if(!ke.comment.trim()){Ve(f=>({...f,error:"Добавьте комментарий."}));return}Ve(f=>({...f,saving:!0,error:""}));try{const f=await Ne.saveAssistantAnnotation({session_id:be,message_index:ke.messageIndex,rating:ke.rating,comment:ke.comment.trim(),annotation_author:ke.annotationAuthor.trim()||void 0});me(P=>{const j=[...P],xe=j.findIndex(Wn=>Wn.annotation_id===f.annotation.annotation_id);return xe>=0?j[xe]=f.annotation:j.unshift(f.annotation),j.sort((Wn,Sn)=>Date.parse(Sn.updated_at)-Date.parse(Wn.updated_at))}),Ye({force:!0})}catch(f){const P=f instanceof Error?f.message:String(f);Ve(j=>({...j,saving:!1,error:P}))}}}function _t(){ir(""),ar([]),ur(""),vn(""),ae(""),me([]),Ye({force:!0}),J("Assistant session reset.")}async function _n(){const f=tn.trim();if(!f)return;cr(!0),ae(""),ur(""),ar(j=>[...j,{message_id:`local-${Date.now()}`,session_id:be||"pending",role:"user",text:f,reply_type:null,created_at:new Date().toISOString(),trace_id:null,debug:null}]);const P=Ee();try{const j=await Ne.sendAssistantMessage({connection:i,prompts:h,userMessage:f,sessionId:be||void 0,promptVersion:Oc,useMock:Me});ir(j.session_id),ar(j.conversation),vn("Ответ готов"),await sn(j.session_id),J(`Assistant reply received: trace=${j.debug.trace_id}`)}catch(j){const xe=j instanceof Error?j.message:String(j);ae(xe),vn("Ошибка ассистента"),J(`Assistant error: ${xe}`)}finally{P(),cr(!1)}}return x.useEffect(()=>{if(!be.trim()){me([]);return}sn(be)},[be]),x.useEffect(()=>{if(!D){G([]);return}Ne.runTrace(D).then(f=>G(f.items)).catch(f=>J(`Run trace error: ${f instanceof Error?f.message:String(f)}`))},[D]),o.jsxs("main",{className:`app-root ${Ce==="assistant"||Ce==="decomposition"||Ce==="autoruns"?"app-root-autoruns":""}`,children:[o.jsxs("header",{className:"app-topbar",children:[o.jsxs("div",{className:"mode-switch-row",children:[o.jsx("button",{type:"button",className:Ce==="assistant"?"tab active":"tab",onClick:()=>Dt("assistant"),children:"Ассистент"}),o.jsx("button",{type:"button",className:Ce==="decomposition"?"tab active":"tab",onClick:()=>Dt("decomposition"),children:"Декомпозиция"}),o.jsx("button",{type:"button",className:Ce==="autoruns"?"tab active":"tab",onClick:()=>Dt("autoruns"),children:"История автопрогонов"}),o.jsx("button",{type:"button",className:"tab",onClick:Kr,children:"Сохранить"})]}),Ce==="assistant"?o.jsxs("div",{className:"mode-switch-row mode-switch-row-right",children:[o.jsx("button",{type:"button",className:Ot?"tab active":"tab",onClick:()=>Gt(f=>!f),children:"LLM Connector"}),o.jsx("button",{type:"button",className:mn?"tab active":"tab",onClick:()=>sr(f=>!f),children:"Prompt Manager"}),o.jsx("button",{type:"button",className:An?"tab active":"tab",onClick:()=>or(f=>!f),children:"Режим ассистента"}),o.jsx("button",{type:"button",className:In?"tab active":"tab",onClick:()=>Jt(f=>!f),children:"Комментарии ассистента"}),o.jsx("button",{type:"button",className:Yt?"tab active":"tab",onClick:()=>lr(f=>!f),children:"SAM"})]}):Ce==="decomposition"?o.jsxs("div",{className:"mode-switch-row mode-switch-row-right",children:[o.jsx("button",{type:"button",className:zt?"tab active":"tab",onClick:()=>pn(f=>!f),children:"LLM"}),o.jsx("button",{type:"button",className:Ue?"tab active":"tab",onClick:()=>lt(f=>!f),children:"Prompt"}),o.jsx("button",{type:"button",className:hn?"tab active":"tab",onClick:()=>gn(f=>!f),children:"Запрос"}),o.jsx("button",{type:"button",className:Xt?"tab active":"tab",onClick:()=>Zt(f=>!f),children:"Выход"}),o.jsx("button",{type:"button",className:kt?"tab active":"tab",onClick:()=>Ln(f=>!f),children:"Метрики"}),o.jsx("button",{type:"button",className:en?"tab active":"tab",onClick:()=>$t(f=>!f),children:"История"}),o.jsx("button",{type:"button",className:Ft?"tab active":"tab",onClick:()=>Mr(f=>!f),children:"NDC Run Monitor"})]}):Ce==="autoruns"?o.jsxs("div",{className:"mode-switch-row mode-switch-row-right",children:[o.jsx("button",{type:"button",className:Hn?"tab active":"tab",onClick:()=>Rn(f=>!f),children:"Режим ассистента"}),o.jsx("button",{type:"button",className:Tn?"tab active":"tab",onClick:()=>rr(f=>!f),children:"Режим декомпозиции"}),o.jsx("button",{type:"button",className:Kt?"tab active":"tab",onClick:()=>qt(f=>!f),children:"Прогресс/регресс"}),o.jsx("button",{type:"button",className:bn?"tab active":"tab",onClick:()=>fn(f=>!f),children:"Комментарии"})]}):null]}),Ce==="assistant"?o.jsx("div",{className:"layout-grid layout-grid-mode-columns",children:o.jsxs("div",{className:"mode-columns",children:[Ot?o.jsx("div",{className:"mode-col",children:o.jsx(Tc,{value:i,modelOptions:ie,modelsBusy:re,onChange:g,onReloadModels:Ar,onSaveLocalConfig:Tr,onTestConnection:_e,lastStatus:ze,busy:Re||ht})}):null,mn?o.jsx("div",{className:"mode-col mode-col-wide",children:o.jsx(Ac,{value:h,onChange:O,presets:Ie,selectedPresetId:se,onSelectPreset:Le,onLoadPreset:oe,onSavePreset:rn,onResetDefaults:xn,onDiffPrevious:fr,presetName:We,onPresetNameChange:tt,diffSummary:nt})}):null,An?o.jsx("div",{className:"mode-col mode-col-xwide",children:o.jsx($c,{sessionId:be,conversation:Ct,inputValue:tn,onInputChange:ur,useMock:Me,onUseMockChange:pe,onSend:_n,onClear:_t,busy:ht,statusText:gt,errorMessage:yn,showCommentAction:!0,onCommentAssistantMessage:Ss,isAssistantMessageCommented:Et,canCommentAssistantMessage:Qn})}):null,In?o.jsx("div",{className:"mode-col",children:o.jsx(Mn,{className:"assistant-comments-frame",title:"Комментарии ассистента",children:o.jsxs("div",{className:"assistant-comments-shell",children:[o.jsxs("div",{className:"assistant-comments-toolbar",children:[o.jsx("span",{className:"muted",children:be?`session: ${be}`:"Сессия не запущена"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>{sn(be)},disabled:!be||vt,children:vt?"Обновляю...":"Обновить"})]}),o.jsxs("div",{className:"assistant-comments-list",children:[be?null:o.jsx("p",{className:"muted",children:"Появится после первого ответа ассистента."}),be&&qe.length===0&&!vt?o.jsx("p",{className:"muted",children:"Комментариев по этой сессии пока нет."}):null,qe.map(f=>o.jsxs("article",{className:"assistant-comment-item",children:[o.jsxs("div",{className:"assistant-comment-head",children:[o.jsx("strong",{children:`${"●".repeat(Math.max(1,Math.min(5,Math.round(f.rating))))}${"○".repeat(Math.max(0,5-Math.round(f.rating)))}`}),o.jsx("span",{children:new Date(f.updated_at).toLocaleString("ru-RU")})]}),f.context.question_text?o.jsxs("p",{children:["Q: ",f.context.question_text]}):null,f.context.answer_text?o.jsxs("p",{children:["A: ",f.context.answer_text]}):null,o.jsx("p",{children:f.comment}),o.jsxs("div",{className:"assistant-comment-meta",children:[f.context.trace_id?o.jsx("span",{children:`trace=${f.context.trace_id}`}):null,f.context.reply_type?o.jsx("span",{children:`reply_type=${f.context.reply_type}`}):null]})]},f.annotation_id))]})]})})}):null,Yt?o.jsx("div",{className:"mode-col",children:o.jsx(Rf,{sessionId:be,conversation:Ct,statusText:gt,errorMessage:yn,useMock:Me,appLogs:q})}):null,!Ot&&!mn&&!An&&!In&&!Yt?o.jsx("div",{className:"mode-columns-empty",children:"Все панели режима ассистента скрыты. Включите нужные блоки справа в шапке."}):null]})}):Ce==="decomposition"?o.jsx("div",{className:"layout-grid layout-grid-mode-columns",children:o.jsxs("div",{className:"mode-columns",children:[zt?o.jsx("div",{className:"mode-col",children:o.jsx(Tc,{value:i,modelOptions:ie,modelsBusy:re,onChange:g,onReloadModels:Ar,onSaveLocalConfig:Tr,onTestConnection:_e,lastStatus:ze,busy:Re})}):null,Ue?o.jsx("div",{className:"mode-col mode-col-wide",children:o.jsx(Ac,{value:h,onChange:O,presets:Ie,selectedPresetId:se,onSelectPreset:Le,onLoadPreset:oe,onSavePreset:rn,onResetDefaults:xn,onDiffPrevious:fr,presetName:We,onPresetNameChange:tt,diffSummary:nt})}):null,hn?o.jsx("div",{className:"mode-col",children:o.jsx(Zf,{value:R,onChange:z,onApplyBatchFormat:mr,onNormalize:Vn,busy:Re,useMock:Me,onUseMockChange:pe,errorMessage:ge})}):null,Xt?o.jsx("div",{className:"mode-col mode-col-xwide",children:o.jsx(Xf,{tab:H,onTabChange:ue,result:K,appLogs:q})}):null,kt?o.jsx("div",{className:"mode-col",children:o.jsx(Gf,{result:K})}):null,en?o.jsx("div",{className:"mode-col",children:o.jsx(qf,{items:U,onRefresh:On,onOpenTrace:Nt})}):null,Ft?o.jsx("div",{className:"mode-col mode-col-xwide",children:o.jsx(em,{runs:A,selectedRunId:D,onSelectRun:m,onStartRun:_s,onFinishRun:ut,onRefreshRuns:nn,onRunEval:qr,onCopyEvalReport:Gr,evalBusy:ce,traceItems:k,evalReport:fe})}):null,!zt&&!Ue&&!hn&&!Xt&&!kt&&!en&&!Ft?o.jsx("div",{className:"mode-columns-empty",children:"Все панели режима декомпозиции скрыты. Включите нужные блоки справа в шапке."}):null]})}):o.jsx("div",{className:"layout-grid layout-grid-autoruns",children:o.jsx(Kf,{connection:i,prompts:h,assistantPromptVersion:Oc,decompositionPromptVersion:Ki,showAssistantMode:Hn,showDecompositionMode:Tn,showProgressMode:Kt,showCommentsMode:bn,onLog:J})}),ke.open?o.jsx("div",{className:"autoruns-comment-modal-backdrop",onClick:f=>{f.target===f.currentTarget&&Ye()},children:o.jsxs("div",{className:"autoruns-comment-modal",children:[o.jsx("h3",{children:"Комментарий к ответу ассистента"}),o.jsx("p",{className:"muted",children:"Эта разметка хранится отдельно от комментариев автопрогонов."}),xt?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Вопрос пользователя"}),o.jsx("p",{className:"autoruns-comment-quote",children:xt.text})]}):null,Ut?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Ответ ассистента"}),o.jsx("p",{className:"autoruns-comment-quote",children:Ut.text})]}):null,o.jsx("div",{className:"autoruns-rating-row",role:"group","aria-label":"Рейтинг ответа",children:[1,2,3,4,5].map(f=>o.jsx("button",{type:"button",className:ke.rating>=f?"autoruns-rating-dot active":"autoruns-rating-dot",onClick:()=>Ve(P=>({...P,rating:f})),disabled:ke.saving,"aria-label":`Оценка ${f}`,children:ke.rating>=f?"●":"○"},f))}),o.jsx("div",{className:"autoruns-form-grid",children:o.jsxs("label",{children:["Автор комментария",o.jsx("input",{value:ke.annotationAuthor,onChange:f=>Ve(P=>({...P,annotationAuthor:f.target.value})),placeholder:"manual_reviewer",disabled:ke.saving})]})}),o.jsxs("label",{children:["Комментарий",o.jsx("textarea",{value:ke.comment,onChange:f=>Ve(P=>({...P,comment:f.target.value})),placeholder:"Что именно не так в ответе и что проверить.",rows:4,disabled:ke.saving})]}),ke.error?o.jsx("p",{className:"error-text",children:ke.error}):null,o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>{zn()},disabled:ke.saving,children:ke.saving?"Сохраняю...":"Готово"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>Ye(),disabled:ke.saving,children:"Отмена"})]})]})}):null]})}Ef.createRoot(document.getElementById("root")).render(o.jsx(_f.StrictMode,{children:o.jsx(am,{})}));