(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 q of z.addedNodes)q.tagName==="LINK"&&q.rel==="modulepreload"&&O(q)}).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 Oc(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Di={exports:{}},Xs={},Oi={exports:{}},he={};var dc;function vf(){if(dc)return he;dc=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"),q=Symbol.for("react.context"),te=Symbol.for("react.forward_ref"),U=Symbol.for("react.suspense"),I=Symbol.for("react.memo"),G=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 ae={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Me=Object.assign,Z={};function re(m,k,J){this.props=m,this.context=k,this.refs=Z,this.updater=J||ae}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 K(){}K.prototype=re.prototype;function le(m,k,J){this.props=m,this.context=k,this.refs=Z,this.updater=J||ae}var we=le.prototype=new K;we.constructor=le,Me(we,re.prototype),we.isPureReactComponent=!0;var $e=Array.isArray,Te=Object.prototype.hasOwnProperty,Le={current:null},Fe={key:!0,ref:!0,__self:!0,__source:!0};function se(m,k,J){var ue,de={},fe=null,ye=null;if(k!=null)for(ue in k.ref!==void 0&&(ye=k.ref),k.key!==void 0&&(fe=""+k.key),k)Te.call(k,ue)&&!Fe.hasOwnProperty(ue)&&(de[ue]=k[ue]);var ge=arguments.length-2;if(ge===1)de.children=J;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[ue]=D,m=ue);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 q=Date,te=q.now();i.unstable_now=function(){return q.now()-te}}var U=[],I=[],G=1,L=null,H=3,ae=!1,Me=!1,Z=!1,re=typeof setTimeout=="function"?setTimeout:null,K=typeof clearTimeout=="function"?clearTimeout:null,le=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function we(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 $e(A){if(Z=!1,we(A),!Me)if(h(U)!==null)Me=!0,Pe(Te);else{var V=h(I);V!==null&&pe($e,V.startTime-A)}}function Te(A,V){Me=!1,Z&&(Z=!1,K(se),se=-1),ae=!0;var D=H;try{for(we(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),we(V)}else O(U);L=h(U)}if(L!==null)var J=!0;else{var ue=h(I);ue!==null&&pe($e,ue.startTime-V),J=!1}return J}finally{L=null,H=D,ae=!1}}var Le=!1,Fe=null,se=-1,De=5,Ke=-1;function tt(){return!(i.unstable_now()-KeA||125m?(A.sortIndex=D,g(I,A),h(U)===null&&A===h(I)&&(Z?(K(se),se=-1):Z=!0,pe($e,D-m))):(A.sortIndex=k,g(U,A),Me||ae||(Me=!0,Pe(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}}}})(Fi)),Fi}var gc;function wf(){return gc||(gc=1,$i.exports=Sf()),$i.exports}var vc;function jf(){if(vc)return It;vc=1;var i=qi(),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]*$/,G={},L={};function H(e){return U.call(L,e)?!0:U.call(G,e)?!1:I.test(e)?L[e]=!0:(G[e]=!0,!1)}function ae(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 Me(e,t,n,r){if(t===null||typeof t>"u"||ae(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 K=/[\-:]([a-z])/g;function le(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(K,le);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(K,le);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(K,le);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 we(e,t,n,r){var s=re.hasOwnProperty(t)?re[t]:null;(s!==null?s.type!==0:r||!(2c||s[u]!==l[c]){var p=` `+s[u].replace(" at new "," at ");return e.displayName&&p.includes("")&&(p=p.replace("",e.displayName)),p}while(1<=u&&0<=c);break}}}finally{J=!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=ue(e.type,!1),e;case 11:return e=ue(e.type.render,!1),e;case 1:return e=ue(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 Fe:return"Fragment";case Le:return"Portal";case De:return"Profiler";case se:return"StrictMode";case Ye:return"Suspense";case nt:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case tt:return(e.displayName||"Context")+".Consumer";case Ke:return(e._context.displayName||"Context")+".Provider";case wt: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 Pe: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 ke(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 Lt(e){e._valueTracker||(e._valueTracker=ke(e))}function Un(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 Nn(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 En(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 Vt(e,t){t=t.checked,t!=null&&we(e,"checked",t,!1)}function Qt(e,t){Vt(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")?an(e,t.type,n):t.hasOwnProperty("defaultValue")&&an(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 an(e,t,n){(t!=="number"||Nn(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var Dt=Array.isArray;function Wt(e,t,n,r){if(e=e.options,t){t={};for(var s=0;s"+t.valueOf().toString()+"",t=qt.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Ot(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var cn={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},Be=["Webkit","ms","Moz","O"];Object.keys(cn).forEach(function(e){Be.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),cn[t]=cn[e]})});function lt(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||cn.hasOwnProperty(e)&&cn[e]?(""+t).trim():t+"px"}function dn(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 fn=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 Gt(e,t){if(t){if(fn[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 Hn(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 jt=null;function Rn(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Jt=null,zt=null,$t=null;function Rr(e){if(e=zs(e)){if(typeof Jt!="function")throw Error(h(280));var t=e.stateNode;t&&(t=go(t),Jt(e.stateNode,e.type,t))}}function Ve(e){zt?$t?$t.push(e):$t=[e]:zt=e}function ir(){if(zt){var e=zt,t=$t;if($t=zt=null,Rr(e),t)for(e=0;e>>=0,e===0?32:31-(Jr(e)/Yr|0)|0}var xt=64,Dn=4194304;function Xe(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 hn(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 c=u&~s;c!==0?r=Xe(c):(l&=u,l!==0&&(r=Xe(l)))}else u=n&~s,u!==0?r=Xe(u):l!==0&&(r=Xe(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 Qn(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),sa=" ",oa=!1;function la(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 ia(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ts=!1;function md(e,t){switch(e){case"compositionend":return ia(t);case"keypress":return t.which!==32?null:(oa=!0,sa);case"textInput":return e=t.data,e===sa&&oa?null:e;default:return null}}function pd(e,t){if(ts)return e==="compositionend"||!hl&&la(e,t)?(e=Xi(),so=ul=pr=null,ts=!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=pa(n)}}function ga(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ga(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function va(){for(var e=window,t=Nn();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=Nn(e.document)}return t}function yl(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=va(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ga(n.ownerDocument.documentElement,n)){if(r!==null&&yl(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=ha(n,l);var u=ha(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,ns=null,xl=null,As=null,_l=!1;function ya(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;_l||ns==null||ns!==Nn(r)||(r=ns,"selectionStart"in r&&yl(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=mo(xl,"onSelect"),0is||(e.current=Al[is],Al[is]=null,is--)}function Ie(e,t){is++,Al[is]=e.current,e.current=t}var yr={},ct=vr(yr),Pt=vr(!1),zr=yr;function as(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 Mt(e){return e=e.childContextTypes,e!=null}function vo(){ze(Pt),ze(ct)}function Ia(e,t,n){if(ct.current!==yr)throw Error(h(168));Ie(ct,t),Ie(Pt,n)}function La(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 yo(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||yr,zr=ct.current,Ie(ct,e),Ie(Pt,Pt.current),!0}function Da(e,t,n){var r=e.stateNode;if(!r)throw Error(h(169));n?(e=La(e,t,zr),r.__reactInternalMemoizedMergedChildContext=e,ze(Pt),ze(ct),Ie(ct,e)):ze(Pt),Ie(Pt,n)}var Gn=null,xo=!1,Il=!1;function Oa(e){Gn===null?Gn=[e]:Gn.push(e)}function Dd(e){xo=!0,Oa(e)}function xr(){if(!Il&&Gn!==null){Il=!0;var e=0,t=j;try{var n=Gn;for(j=1;e>=u,s-=u,Jn=1<<32-ut(t)+s|n<ne?(ot=X,X=null):ot=X.sibling;var Se=C(x,X,S[ne],T);if(Se===null){X===null&&(X=ot);break}e&&X&&Se.alternate===null&&t(x,X),v=l(Se,v,ne),Y===null?W=Se:Y.sibling=Se,Y=Se,X=ot}if(ne===S.length)return n(x,X),Ue&&Fr(x,ne),W;if(X===null){for(;nene?(ot=X,X=null):ot=X.sibling;var Pr=C(x,X,Se.value,T);if(Pr===null){X===null&&(X=ot);break}e&&X&&Pr.alternate===null&&t(x,X),v=l(Pr,v,ne),Y===null?W=Pr:Y.sibling=Pr,Y=Pr,X=ot}if(Se.done)return n(x,X),Ue&&Fr(x,ne),W;if(X===null){for(;!Se.done;ne++,Se=S.next())Se=M(x,Se.value,T),Se!==null&&(v=l(Se,v,ne),Y===null?W=Se:Y.sibling=Se,Y=Se);return Ue&&Fr(x,ne),W}for(X=r(x,X);!Se.done;ne++,Se=S.next())Se=$(X,x,ne,Se.value,T),Se!==null&&(e&&Se.alternate!==null&&X.delete(Se.key===null?ne:Se.key),v=l(Se,v,ne),Y===null?W=Se:Y.sibling=Se,Y=Se);return e&&X.forEach(function(gf){return t(x,gf)}),Ue&&Fr(x,ne),W}function qe(x,v,S,T){if(typeof S=="object"&&S!==null&&S.type===Fe&&S.key===null&&(S=S.props.children),typeof S=="object"&&S!==null){switch(S.$$typeof){case Te:e:{for(var W=S.key,Y=v;Y!==null;){if(Y.key===W){if(W=S.type,W===Fe){if(Y.tag===7){n(x,Y.sibling),v=s(Y,S.props.children),v.return=x,x=v;break e}}else if(Y.elementType===W||typeof W=="object"&&W!==null&&W.$$typeof===Pe&&Ha(W)===Y.type){n(x,Y.sibling),v=s(Y,S.props),v.ref=$s(x,Y,S),v.return=x,x=v;break e}n(x,Y);break}else t(x,Y);Y=Y.sibling}S.type===Fe?(v=Kr(S.props.children,x.mode,T,S.key),v.return=x,x=v):(T=Ko(S.type,S.key,S.props,null,x.mode,T),T.ref=$s(x,v,S),T.return=x,x=T)}return u(x);case Le: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(x,v.sibling),v=s(v,S.children||[]),v.return=x,x=v;break e}else{n(x,v);break}else t(x,v);v=v.sibling}v=Ri(S,x.mode,T),v.return=x,x=v}return u(x);case Pe:return Y=S._init,qe(x,v,Y(S._payload),T)}if(Dt(S))return B(x,v,S,T);if(V(S))return b(x,v,S,T);jo(x,S)}return typeof S=="string"&&S!==""||typeof S=="number"?(S=""+S,v!==null&&v.tag===6?(n(x,v.sibling),v=s(v,S),v.return=x,x=v):(n(x,v),v=Mi(S,x.mode,T),v.return=x,x=v),u(x)):n(x,v)}return qe}var fs=ba(!0),Va=ba(!1),ko=vr(null),Co=null,ms=null,Fl=null;function Ul(){Fl=ms=Co=null}function Bl(e){var t=ko.current;ze(ko),e._currentValue=t}function Hl(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 ps(e,t){Co=e,Fl=ms=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&t)!==0&&(Rt=!0),e.firstContext=null)}function rn(e){var t=e._currentValue;if(Fl!==e)if(e={context:e,memoizedValue:t,next:null},ms===null){if(Co===null)throw Error(h(308));ms=e,Co.dependencies={lanes:0,firstContext:e}}else ms=ms.next=e;return t}var Ur=null;function bl(e){Ur===null?Ur=[e]:Ur.push(e)}function Qa(e,t,n,r){var s=t.interleaved;return s===null?(n.next=n,bl(t)):(n.next=s.next,s.next=n),t.interleaved=n,Xn(e,r)}function Xn(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 Vl(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function Wa(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 Zn(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,(_e&2)!==0){var s=r.pending;return s===null?t.next=t:(t.next=s.next,s.next=t),r.pending=t,Xn(e,n)}return s=r.interleaved,s===null?(t.next=t,bl(r)):(t.next=s.next,s.next=t),r.interleaved=t,Xn(e,n)}function No(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,E(e,n)}}function Ka(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 Eo(e,t,n,r){var s=e.updateQueue;_r=!1;var l=s.firstBaseUpdate,u=s.lastBaseUpdate,c=s.shared.pending;if(c!==null){s.shared.pending=null;var p=c,w=p.next;p.next=null,u===null?l=w:u.next=w,u=p;var N=e.alternate;N!==null&&(N=N.updateQueue,c=N.lastBaseUpdate,c!==u&&(c===null?N.firstBaseUpdate=w:c.next=w,N.lastBaseUpdate=p))}if(l!==null){var M=s.baseState;u=0,N=w=p=null,c=l;do{var C=c.lane,$=c.eventTime;if((r&C)===C){N!==null&&(N=N.next={eventTime:$,lane:0,tag:c.tag,payload:c.payload,callback:c.callback,next:null});e:{var B=e,b=c;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}}c.callback!==null&&c.lane!==0&&(e.flags|=64,C=s.effects,C===null?s.effects=[c]:C.push(c))}else $={eventTime:$,lane:C,tag:c.tag,payload:c.payload,callback:c.callback,next:null},N===null?(w=N=$,p=M):N=N.next=$,u|=C;if(c=c.next,c===null){if(c=s.shared.pending,c===null)break;C=c,c=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);br|=u,e.lanes=u,e.memoizedState=M}}function qa(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;tn?n:4,e(!0);var r=Gl.transition;Gl.transition={};try{e(!1),t()}finally{j=n,Gl.transition=r}}function mu(){return sn().memoizedState}function Fd(e,t,n){var r=Cr(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},pu(e))hu(t,n);else if(n=Qa(e,t,n,r),n!==null){var s=St();kn(n,e,r,s),gu(n,t,r)}}function Ud(e,t,n){var r=Cr(e),s={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(pu(e))hu(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,c=l(u,n);if(s.hasEagerState=!0,s.eagerState=c,xn(c,u)){var p=t.interleaved;p===null?(s.next=s,bl(t)):(s.next=p.next,p.next=s),t.interleaved=s;return}}catch{}n=Qa(e,t,s,r),n!==null&&(s=St(),kn(n,e,r,s),gu(n,t,r))}}function pu(e){var t=e.alternate;return e===be||t!==null&&t===be}function hu(e,t){Hs=Ro=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function gu(e,t,n){if((n&4194240)!==0){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,E(e,n)}}var Io={readContext:rn,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:rn,useCallback:function(e,t){return $n().memoizedState=[e,t===void 0?null:t],e},useContext:rn,useEffect:ou,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,To(4194308,4,au.bind(null,t,e),n)},useLayoutEffect:function(e,t){return To(4194308,4,e,t)},useInsertionEffect:function(e,t){return To(4,2,e,t)},useMemo:function(e,t){var n=$n();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=$n();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,be,e),[r.memoizedState,e]},useRef:function(e){var t=$n();return e={current:e},t.memoizedState=e},useState:ru,useDebugValue:ni,useDeferredValue:function(e){return $n().memoizedState=e},useTransition:function(){var e=ru(!1),t=e[0];return e=$d.bind(null,e[1]),$n().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=be,s=$n();if(Ue){if(n===void 0)throw Error(h(407));n=n()}else{if(n=t(),st===null)throw Error(h(349));(Hr&30)!==0||Xa(r,t,n)}s.memoizedState=n;var l={value:n,getSnapshot:t};return s.queue=l,ou(eu.bind(null,r,l,e),[e]),r.flags|=2048,Qs(9,Za.bind(null,r,l,n,t),void 0,null),n},useId:function(){var e=$n(),t=st.identifierPrefix;if(Ue){var n=Yn,r=Jn;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[On]=t,e[Os]=r,Ou(e,t,!1,!1),t.stateNode=e;e:{switch(u=Hn(n,r),n){case"dialog":Oe("cancel",e),Oe("close",e),s=r;break;case"iframe":case"object":case"embed":Oe("load",e),s=r;break;case"video":case"audio":for(s=0;sxs&&(t.flags|=128,r=!0,Ws(l,!1),t.lanes=4194304)}else{if(!r)if(e=Po(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&&!Ue)return ft(t),null}else 2*Re()-l.renderingStartTime>xs&&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=Re(),t.sibling=null,n=He.current,Ie(He,r?n&1|2:n&1),t):(ft(t),null);case 22:case 23:return Ni(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&(t.mode&1)!==0?(Ht&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(Dl(t),t.tag){case 1:return Mt(t.type)&&vo(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return hs(),ze(Pt),ze(ct),ql(),e=t.flags,(e&65536)!==0&&(e&128)===0?(t.flags=e&-65537|128,t):null;case 5:return Wl(t),null;case 13:if(ze(He),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(h(340));ds()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ze(He),null;case 4:return hs(),null;case 10:return Bl(t.type._context),null;case 22:case 23:return Ni(),null;case 24:return null;default:return null}}var zo=!1,mt=!1,Jd=typeof WeakSet=="function"?WeakSet:Set,F=null;function vs(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){We(e,t,r)}else n.current=null}function pi(e,t,n){try{n()}catch(r){We(e,t,r)}}var Fu=!1;function Yd(e,t){if(Nl=no,e=va(),yl(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,c=-1,p=-1,w=0,N=0,M=e,C=null;t:for(;;){for(var $;M!==n||s!==0&&M.nodeType!==3||(c=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&&(c=u),C===l&&++N===r&&(p=u),($=M.nextSibling)!==null)break;M=C,C=M.parentNode}M=$}n=c===-1||p===-1?null:{start:c,end:p}}else n=null}n=n||{start:0,end:0}}else n=null;for(El={focusedElem:e,selectionRange:n},no=!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,qe=B.memoizedState,x=t.stateNode,v=x.getSnapshotBeforeUpdate(t.elementType===t.type?b:Sn(t.type,b),qe);x.__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){We(t,t.return,T)}if(e=t.sibling,e!==null){e.return=t.return,F=e;break}F=t.return}return B=Fu,Fu=!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&&pi(t,n,l)}s=s.next}while(s!==r)}}function $o(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 hi(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 Uu(e){var t=e.alternate;t!==null&&(e.alternate=null,Uu(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[On],delete t[Os],delete t[Tl],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 Hu(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 gi(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=ho));else if(r!==4&&(e=e.child,e!==null))for(gi(e,t,n),e=e.sibling;e!==null;)gi(e,t,n),e=e.sibling}function vi(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(vi(e,t,n),e=e.sibling;e!==null;)vi(e,t,n),e=e.sibling}var it=null,wn=!1;function wr(e,t,n){for(n=n.child;n!==null;)bu(e,t,n),n=n.sibling}function bu(e,t,n){if(Nt&&typeof Nt.onCommitFiberUnmount=="function")try{Nt.onCommitFiberUnmount(mr,n)}catch{}switch(n.tag){case 5:mt||vs(n,t);case 6:var r=it,s=wn;it=null,wr(e,t,n),it=r,wn=s,it!==null&&(wn?(e=it,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):it.removeChild(n.stateNode));break;case 18:it!==null&&(wn?(e=it,n=n.stateNode,e.nodeType===8?Rl(e.parentNode,n):e.nodeType===1&&Rl(e,n),Cs(e)):Rl(it,n.stateNode));break;case 4:r=it,s=wn,it=n.stateNode.containerInfo,wn=!0,wr(e,t,n),it=r,wn=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)&&pi(n,t,u),s=s.next}while(s!==r)}wr(e,t,n);break;case 1:if(!mt&&(vs(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(c){We(n,t,c)}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 Vu(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 jn(e,t){var n=t.deletions;if(n!==null)for(var r=0;rs&&(s=u),r&=~l}if(r=s,r=Re()-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,bo=0,(_e&6)!==0)throw Error(h(331));var s=_e;for(_e|=4,F=e.current;F!==null;){var l=F,u=l.child;if((F.flags&16)!==0){var c=l.deletions;if(c!==null){for(var p=0;pRe()-_i?Qr(e,0):xi|=n),At(e,t)}function rc(e,t){t===0&&((e.mode&1)===0?t=1:(t=Dn,Dn<<=1,(Dn&130023424)===0&&(Dn=4194304)));var n=St();e=Xn(e,t),e!==null&&(Qn(e,t,n),At(e,n))}function of(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),rc(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),rc(e,n)}var sc;sc=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Pt.current)Rt=!0;else{if((e.lanes&n)===0&&(t.flags&128)===0)return Rt=!1,Kd(e,t,n);Rt=(e.flags&131072)!==0}else Rt=!1,Ue&&(t.flags&1048576)!==0&&za(t,So,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;Oo(e,t),e=t.pendingProps;var s=as(t,ct.current);ps(t,n),s=Yl(null,t,r,e,s,n);var l=Xl();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,Mt(r)?(l=!0,yo(t)):l=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,Vl(t),s.updater=Lo,t.stateNode=s,s._reactInternals=t,si(t,r,e,n),t=ai(null,t,r,!0,l,n)):(t.tag=0,Ue&&l&&Ll(t),_t(null,t,s,n),t=t.child),t;case 16:r=t.elementType;e:{switch(Oo(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=uf(r),e=Sn(r,e),s){case 0:t=ii(null,t,r,e,n);break e;case 1:t=Ru(null,t,r,e,n);break e;case 11:t=Cu(null,t,r,e,n);break e;case 14:t=Nu(null,t,r,Sn(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:Sn(r,s),ii(e,t,r,s,n);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Sn(r,s),Ru(e,t,r,s,n);case 3:e:{if(Tu(t),e===null)throw Error(h(387));r=t.pendingProps,l=t.memoizedState,s=l.element,Wa(e,t),Eo(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=gs(Error(h(423)),t),t=Au(e,t,r,n,s);break e}else if(r!==s){s=gs(Error(h(424)),t),t=Au(e,t,r,n,s);break e}else for(Bt=gr(t.stateNode.containerInfo.firstChild),Ut=t,Ue=!0,_n=null,n=Va(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(ds(),r===s){t=er(e,t,n);break e}_t(e,t,r,n)}t=t.child}return t;case 5:return Ga(t),e===null&&zl(t),r=t.type,s=t.pendingProps,l=e!==null?e.memoizedProps:null,u=s.children,Pl(r,s)?u=null:l!==null&&Pl(r,l)&&(t.flags|=32),Mu(e,t),_t(e,t,u,n),t.child;case 6:return e===null&&zl(t),null;case 13:return Iu(e,t,n);case 4:return Ql(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=fs(t,null,r,n):_t(e,t,r,n),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Sn(r,s),Cu(e,t,r,s,n);case 7:return _t(e,t,t.pendingProps,n),t.child;case 8:return _t(e,t,t.pendingProps.children,n),t.child;case 12:return _t(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,Ie(ko,r._currentValue),r._currentValue=u,l!==null)if(xn(l.value,u)){if(l.children===s.children&&!Pt.current){t=er(e,t,n);break e}}else for(l=t.child,l!==null&&(l.return=t);l!==null;){var c=l.dependencies;if(c!==null){u=l.child;for(var p=c.firstContext;p!==null;){if(p.context===r){if(l.tag===1){p=Zn(-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),Hl(l.return,n,t),c.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,c=u.alternate,c!==null&&(c.lanes|=n),Hl(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}_t(e,t,s.children,n),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,ps(t,n),s=rn(s),r=r(s),t.flags|=1,_t(e,t,r,n),t.child;case 14:return r=t.type,s=Sn(r,t.pendingProps),s=Sn(r.type,s),Nu(e,t,r,s,n);case 15:return Eu(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Sn(r,s),Oo(e,t),t.tag=1,Mt(r)?(e=!0,yo(t)):e=!1,ps(t,n),yu(t,r,s),si(t,r,s,n),ai(null,t,r,!0,e,n);case 19:return Du(e,t,n);case 22:return Pu(e,t,n)}throw Error(h(156,t.tag))};function oc(e,t){return Tr(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 ln(e,t,n,r){return new af(e,t,n,r)}function Pi(e){return e=e.prototype,!(!e||!e.isReactComponent)}function uf(e){if(typeof e=="function")return Pi(e)?1:0;if(e!=null){if(e=e.$$typeof,e===wt)return 11;if(e===ve)return 14}return 2}function Er(e,t){var n=e.alternate;return n===null?(n=ln(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 Ko(e,t,n,r,s,l){var u=2;if(r=e,typeof e=="function")Pi(e)&&(u=1);else if(typeof e=="string")u=5;else e:switch(e){case Fe:return Kr(n.children,s,l,t);case se:u=8,s|=8;break;case De:return e=ln(12,n,t,s|2),e.elementType=De,e.lanes=l,e;case Ye:return e=ln(13,n,t,s),e.elementType=Ye,e.lanes=l,e;case nt:return e=ln(19,n,t,s),e.elementType=nt,e.lanes=l,e;case pe:return qo(n,s,l,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ke:u=10;break e;case tt:u=9;break e;case wt:u=11;break e;case ve:u=14;break e;case Pe:u=16,r=null;break e}throw Error(h(130,e==null?e:typeof e,""))}return t=ln(u,n,t,s),t.elementType=e,t.type=r,t.lanes=l,t}function Kr(e,t,n,r){return e=ln(7,e,r,t),e.lanes=n,e}function qo(e,t,n,r){return e=ln(22,e,r,t),e.elementType=pe,e.lanes=n,e.stateNode={isHidden:!1},e}function Mi(e,t,n){return e=ln(6,e,null,t),e.lanes=n,e}function Ri(e,t,n){return t=ln(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=Vn(0),this.expirationTimes=Vn(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Vn(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function Ti(e,t,n,r,s,l,u,c,p){return e=new cf(e,t,n,c,p),t===1?(t=1,l===!0&&(t|=8)):t=0,l=ln(3,null,null,t),e.current=l,l.stateNode=e,l.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Vl(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(),zi.exports=jf(),zi.exports}var xc;function Cf(){if(xc)return tl;xc=1;var i=kf();return tl.createRoot=i.createRoot,tl.hydrateRoot=i.hydrateRoot,tl}var Nf=Cf();const Ef=Oc(Nf),Pf="/api";async function Ee(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 Ce={async listModels(i){return Ee("/llm/models",{method:"POST",body:JSON.stringify({llmProvider:i.llmProvider,apiKey:i.apiKey,model:i.model,baseUrl:i.baseUrl})})},async testConnection(i){return Ee("/llm/test-connection",{method:"POST",body:JSON.stringify({llmProvider:i.llmProvider,apiKey:i.apiKey,model:i.model,baseUrl:i.baseUrl})})},async normalize(i){return Ee("/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 Ee("/history")},async loadTrace(i){return Ee(`/history/${i}`)},async loadPresets(){return Ee("/presets")},async savePreset(i){return Ee("/presets/save",{method:"POST",body:JSON.stringify(i)})},async runEval(i){return Ee("/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 Ee("/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 Ee(`/eval/run-async/${encodeURIComponent(i)}`)},async startRun(){return Ee("/accounting-agent/v1/runs/start",{method:"POST",body:JSON.stringify({initiator:"ndc_operator",source:"gui"})})},async finishRun(i){return Ee("/accounting-agent/v1/runs/finish",{method:"POST",body:JSON.stringify({runId:i,status:"DONE",source:"gui",reason:"Остановлено оператором из GUI"})})},async listRuns(){return Ee("/accounting-agent/v1/runs")},async listResults(){return Ee("/accounting-agent/v1/results")},async runTrace(i){return Ee(`/accounting-agent/v1/trace/run/${i}`)},async sendAssistantMessage(i){return Ee("/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 Ee(`/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 Ee(`/assistant/annotations${h?`?${h}`:""}`)},async saveAssistantAnnotation(i){return Ee("/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 Ee(`/autoruns/history${h?`?${h}`:""}`)},async loadAutoRunDetail(i){return Ee(`/autoruns/history/${encodeURIComponent(i)}`)},async loadAutoRunCaseDialog(i,g){return Ee(`/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 Ee(`/autoruns/annotations${h?`?${h}`:""}`)},async saveAutoRunAnnotation(i){return Ee("/autoruns/annotations",{method:"POST",body:JSON.stringify(i)})},async updateAutoRunAnnotation(i){return Ee(`/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 Ee(`/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 Ee(`/autoruns/autogen/history${h?`?${h}`:""}`)},async loadAutoRunAutogenPersonalityCatalog(){return Ee("/autoruns/autogen/personality-catalog")},async generateAutoRunQuestions(i){return Ee("/autoruns/autogen/generate",{method:"POST",body:JSON.stringify(i)})}};function bt({value:i}){return o.jsx("pre",{className:"json-view",children:JSON.stringify(i??{},null,2)})}function Cn({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 q=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(Cn,{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:q})]}),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(bt,{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(q=>q.trimEnd()).filter(q=>q.trim().length>0).filter(q=>!Af.some(te=>te.test(q))).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]),y.useEffect(()=>()=>{K.current!==null&&window.clearTimeout(K.current)},[]);async function Le(se){if(g.length===0)return;const De=Df(i,g,se),Ke=await $f(De);Te(se==="technical"?"тех":"чат"),we(Ke?"success":"error"),K.current!==null&&window.clearTimeout(K.current),K.current=window.setTimeout(()=>{we("idle")},2200)}function Fe(){if(!Z.current)return;const se=Z.current,De=se.scrollHeight-se.scrollTop-se.clientHeight;re.current=De<16}return o.jsx(Cn,{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:()=>{Le("default")},disabled:g.length===0,title:"Экспорт только user-facing чата",children:"Скопировать чат"}),o.jsx("button",{type:"button",className:"assistant-copy-btn",onClick:()=>{Le("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,le==="success"?o.jsxs("span",{className:"assistant-copy-feedback success",children:["Скопировано (",$e,")"]}):null,le==="error"?o.jsx("span",{className:"assistant-copy-feedback error",children:"Ошибка копирования"}):null]})]}),G?o.jsx("p",{className:"error-text assistant-toolbar-error",children:G}):null]}),o.jsx("div",{ref:Z,className:"assistant-chat-list",onScroll:Fe,children:g.map((se,De)=>{const Ke=se.role==="assistant"&&L&&typeof H=="function"&&(typeof Me=="function"?Me(se,De):!0),tt=se.role==="assistant"&&typeof ae=="function"?ae(se,De):!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,De),disabled:!Ke,title:Ke?"Комментировать ответ ассистента":"Комментарий недоступен для этого сообщения","aria-label":Ke?"Комментировать ответ ассистента":"Комментарий недоступен для этого сообщения",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(bt,{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:()=>q(),disabled:U||!h.trim(),children:U?"Выполняю...":"Отправить"})]})]})]})})}const Ui={fromLocal:"",toLocal:"",target:"all",mode:"all",useMock:"any",promptContains:"",limit:120},nl="needs_dialog_policy_fix",pt="__all__",ll="__live__:",_c="ndc_autoruns_ui_config_v1",Sc="ndc-autoruns-save",Bi=["Анализ запроса","Получение данных","Подготовка ответа"],Ki=[{id:"general",label:"Общий контур",domain:"",defaultPrompt:"Генерируй реалистичные живые вопросы бухгалтера по 1С. Добавляй разговорные формулировки и опечатки, но сохраняй бизнес-смысл."}];function Uf(i=Ki){return i.reduce((g,h)=>(g[h.id]=h.defaultPrompt,g),{})}const wc={mode:"codex_creative",count:24,personalityId:"general",personalityPrompts:Uf(),persistToEvalCases:!0,generatedBy:"manual_reviewer"};function Hi(i){const g=String(i??"").trim();return/^\d{4}-\d{2}-\d{2}$/.test(g)?g:""}function jc(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 kc(){const i=new Date;return i.setDate(i.getDate()-14),Bf(i)}function rl(i){if(!i.trim())return;const g=Date.parse(i);if(Number.isFinite(g))return new Date(g).toISOString()}function Mr(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 sl(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 Cc(i){return i==="up"?"Рост":i==="down"?"Регресс":"Без изменений"}function Vf(i,g){return i.find(h=>h.case_id===g)??null}function Nc(i){const g=Math.max(1,Math.min(5,Math.round(i)));return`${"●".repeat(g)}${"○".repeat(5-g)}`}function Ec(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 ol(i){return`${ll}${i}`}function Ss(i){return i.startsWith(ll)}function Pc(i){return i.startsWith(ll)?i.slice(ll.length):""}function $c(i){const g=i.report_summary?.run_timestamp??i.created_at,h=Math.max(0,i.total_cases-i.completed_cases);return{run_id:ol(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=$c(i),O=i.cases.map(G=>({case_id:G.case_id,domain:null,query_class:null,status:G.status==="completed"?"closed":G.status==="failed"?"open":"unknown",score_index:null,trace_id:null,reply_type:null,session_id:`${i.run_id}-${G.case_id}`,dialog_available:G.messages.length>0,commented_count:0,latest_annotation_at:null,avg_rating:null,checks:null,metric_subscores:null})),z=g!==pt&&O.some(G=>G.case_id===g)?g:O.length>0?pt:"",q={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 G of i.cases)for(let L=0;LL.case_id===z)??null;for(let L=0;L<(G?.messages.length??0);L+=1){const H=G?.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:q,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 Mc({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:q,showCommentsMode:te,onLog:U}){const[I,G]=y.useState({...Ui,fromLocal:kc()}),[L,H]=y.useState(""),[ae,Me]=y.useState(null),[Z,re]=y.useState(null),[K,le]=y.useState(null),[we,$e]=y.useState([]),[Te,Le]=y.useState("all"),[Fe,se]=y.useState(!1),[De,Ke]=y.useState(null),[tt,wt]=y.useState([]),[Ye,nt]=y.useState(""),[ve,Pe]=y.useState(""),[pe,A]=y.useState(""),[V,D]=y.useState(Ki),[m,k]=y.useState(wc),[J,ue]=y.useState([]),[de,fe]=y.useState(""),[ye,ge]=y.useState([]),[ee,ke]=y.useState(null),[Lt,Un]=y.useState(null),[Nn,En]=y.useState(!1),[rr,Vt]=y.useState(!1),[Qt,Bn]=y.useState(!1),[an,Dt]=y.useState(!1),[Wt,un]=y.useState(!1),[sr,Pn]=y.useState(!1),[or,Mn]=y.useState(!1),[Kt,qt]=y.useState(!1),[lr,Ot]=y.useState(""),[cn,Be]=y.useState(""),[lt,dn]=y.useState(""),[fn,Gt]=y.useState([]),[Hn,jt]=y.useState([]),[Rn,Jt]=y.useState(""),[zt,$t]=y.useState(!1),[Rr,Ve]=y.useState(!1),[ir,kt]=y.useState(""),[ar,Yt]=y.useState(""),[ur,ht]=y.useState(String(Ui.limit)),[cr,gt]=y.useState(String(wc.count)),[mn,pn]=y.useState(160),[ie,Ge]=y.useState({open:!1,caseId:"",caseMessageIndex:-1,messageIndex:-1,rating:3,comment:"",manualCaseDecision:nl,annotationAuthor:"manual_reviewer",saving:!1,error:""}),[me,vt]=y.useState({open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:"manual_reviewer",saving:!1,error:""}),dr=y.useRef(!1),je=y.useRef(null),Qe=y.useMemo(()=>V.find(a=>a.id===m.personalityId)??V[0]??Ki[0],[m.personalityId,V]),yt=y.useMemo(()=>J.find(a=>a.generation_id===de)??J[0]??null,[J,de]),Tn=Z?Vf(Z.cases,pe):null,Q=y.useMemo(()=>Fe?we.filter(a=>!a.resolved):we,[we,Fe]),Ne=Q.find(a=>a.annotation_id===Ye)??null,An=K?.messages.find(a=>a.message_index===ie.messageIndex)??null,Tr=y.useMemo(()=>{if(!K||ie.messageIndex<0)return null;for(let a=ie.messageIndex-1;a>=0;a-=1){const d=K.messages[a];if(d?.role==="user")return d}return null},[ie.messageIndex,K]),Xt=y.useMemo(()=>{const a=new Map;for(const d of Hn)d.message_id&&a.set(d.message_id,d);return a},[Hn]),Ar=me.messageIndex>=0?fn[me.messageIndex]??null:null,qr=y.useMemo(()=>{if(me.messageIndex<0)return null;for(let a=me.messageIndex-1;a>=0;a-=1){const d=fn[a];if(d?.role==="user")return d}return null},[me.messageIndex,fn]),Re=y.useMemo(()=>{if(Q.length===0)return null;const a=Q.reduce((d,_)=>d+_.rating,0)/Q.length;return Number(a.toFixed(2))},[Q]),fr=y.useMemo(()=>{const a=[...ae?.items??[]];return ee&&a.unshift($c(ee)),ve&&!a.some(d=>d.run_id===ve)&&Z?.run&&a.unshift(Z.run),a},[ee,ae?.items,Z?.run,ve]),oe=y.useCallback(a=>{U?.(`[autoruns] ${a}`)},[U]),In=y.useCallback(async a=>{const d=String(a??"").trim();if(!d){jt([]);return}try{const _=await Ce.loadAssistantAnnotations({session_id:d,limit:400});jt(_.items??[])}catch(_){const P=_ instanceof Error?_.message:String(_);oe(`Assistant live annotations load error: ${P}`)}},[oe]),Ct=y.useCallback(a=>{vt(d=>d.saving&&!a?.force?d:{open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:"manual_reviewer",saving:!1,error:""})},[]),Ir=y.useCallback(async(a,d)=>{a.stopPropagation(),a.preventDefault();const _=String(d??"").trim();if(_)try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(_);else{const P=document.createElement("textarea");P.value=_,P.setAttribute("readonly","true"),P.style.position="fixed",P.style.opacity="0",document.body.appendChild(P),P.select(),document.execCommand("copy"),document.body.removeChild(P)}oe(`run id copied: ${_}`)}catch(P){const ce=P instanceof Error?P.message:String(P);Be(`Копирование run id: ${ce}`),oe(`copy run id error: ${ce}`)}},[oe]);function Lr(){let a=0;kt(Bi[0]);const d=window.setInterval(()=>{a=Math.min(a+1,Bi.length-1),kt(Bi[a])},650);return()=>window.clearInterval(d)}const mr=y.useCallback(()=>{dn(""),Gt([]),jt([]),Jt(""),kt(""),Yt(""),Ct({force:!0}),oe("Live-чат ассистента в истории автопрогонов сброшен.")},[Ct,oe]),Nt=y.useCallback(async()=>{const a=Rn.trim();if(!a)return;Ve(!0),Yt(""),Jt(""),Gt(_=>[..._,{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 d=Lr();try{const _=await Ce.sendAssistantMessage({connection:i,prompts:g,userMessage:a,sessionId:lt||void 0,promptVersion:h,useMock:zt});dn(_.session_id),Gt(_.conversation),await In(_.session_id),kt("Ответ готов"),oe(`Live-ответ ассистента получен: trace=${_.debug.trace_id}`)}catch(_){const P=_ instanceof Error?_.message:String(_);Yt(P),kt("Ошибка ассистента"),oe(`Live-чат ассистента: ошибка отправки сообщения: ${P}`)}finally{d(),Ve(!1)}},[Rn,lt,zt,h,i,In,oe,g]),Gr=y.useCallback(a=>{const d=a.trim();if(!d){ht(String(I.limit));return}if(!/^\d+$/.test(d)){ht(String(I.limit));return}const _=Number.parseInt(d,10);if(!Number.isFinite(_)){ht(String(I.limit));return}const P=Math.max(1,Math.min(500,_));P!==I.limit&&G(ce=>({...ce,limit:P})),ht(String(P))},[I.limit]),ut=y.useCallback(a=>{const d=a.trim();if(!d){gt(String(m.count));return}if(!/^\d+$/.test(d)){gt(String(m.count));return}const _=Number.parseInt(d,10);if(!Number.isFinite(_)){gt(String(m.count));return}const P=Math.max(1,Math.min(200,_));P!==m.count&&k(ce=>({...ce,count:P})),gt(String(P))},[m.count]),Jr=y.useCallback(a=>{pn(jc(a))},[]),Yr=y.useCallback(a=>{const d=a.currentTarget.offsetHeight;Number.isFinite(d)&&d>0&&Jr(d)},[Jr]),Ln=y.useCallback(async()=>{qt(!0);try{const a=await Ce.loadAutoRunAnnotations({limit:800,manual_case_decision:Te});$e(a.items),Ke(a.manual_case_decision_schema??null),wt(a.available_manual_case_decisions??[]),nt(d=>a.items.length===0?"":a.items.some(_=>_.annotation_id===d)?d:a.items[0].annotation_id)}catch(a){oe(`Annotations load error: ${a instanceof Error?a.message:String(a)}`)}finally{qt(!1)}},[Te,oe]),xt=y.useCallback(async()=>{Dt(!0);try{const a=await Ce.loadAutoRunAutogenHistory({limit:180});ue(a.items)}catch(a){oe(`Autogen history load error: ${a instanceof Error?a.message:String(a)}`)}finally{Dt(!1)}},[oe]),Dn=y.useCallback(async()=>{try{const d=(await Ce.loadAutoRunAutogenPersonalityCatalog()).items.map(_=>({id:String(_.id??"").trim(),label:String(_.label??"").trim(),domain:typeof _.domain=="string"?_.domain.trim():"",defaultPrompt:String(_.default_prompt??"").trim()})).filter(_=>_.id.length>0&&_.label.length>0);if(d.length===0)return;D(d.map(_=>({id:_.id,label:_.label,domain:_.domain||"",defaultPrompt:_.defaultPrompt||"Генерируй реалистичные вопросы бухгалтера по выбранному профилю. Не выдумывай непокрытые возможности."})))}catch(a){oe(`Autogen personality catalog load error: ${a instanceof Error?a.message:String(a)}`)}},[oe]),Xe=y.useCallback(async()=>{Bn(!0);try{const a=await Ce.loadAutoRunPostAnalysis({run_id:ve&&!Ss(ve)?ve:void 0,limit_per_queue:30,annotation_limit:1500,from:rl(I.fromLocal),to:rl(I.toLocal),target:I.target,mode:I.mode,use_mock:I.useMock,prompt_contains:I.promptContains.trim()||void 0});Un(a)}catch(a){oe(`Post-analysis load error: ${a instanceof Error?a.message:String(a)}`),Un(null)}finally{Bn(!1)}},[I.fromLocal,I.mode,I.promptContains,I.target,I.toLocal,I.useMock,oe,ve]),hn=y.useCallback(async()=>{En(!0),Be("");try{const a=m.personalityPrompts[m.personalityId]??"",d=[g.systemPrompt,g.developerPrompt,g.domainPrompt,g.schemaNotes,g.fewShotExamples].join(` `).slice(0,900),_=await Ce.generateAutoRunQuestions({mode:m.mode,count:m.count,domain:Qe.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:d,autogen_personality_id:Qe.id,autogen_personality_prompt:a.trim()||void 0}});oe(`Generated ${_.generation.count} questions (${_.generation.mode}) id=${_.generation.generation_id}`+(_.generation.saved_case_set_file?` saved=${_.generation.saved_case_set_file}`:"")),fe(_.generation.generation_id),ge([..._.generation.questions??[]]),await xt()}catch(a){const d=a instanceof Error?a.message:String(a);Be(`Автогенерация: ${d}`),oe(`Autogen generate error: ${d}`)}finally{En(!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,Qe.domain,Qe.id]),bn=y.useCallback(async(a,d)=>{if(Ss(a)){const _=Pc(a);if(ee&&ee.job_id===_){const P=Zs(ee,d);Pe(a),A(P.caseId),le(P.dialog);return}le(null);return}Mn(!0);try{const _=await Ce.loadAutoRunCaseDialog(a,d);le(_)}catch(_){const P=_ instanceof Error?_.message:String(_);Be(`Диалог кейса: ${P}`),le(null),oe(`Dialog load error for ${a}/${d}: ${P}`)}finally{Mn(!1)}},[ee,oe]),Zt=y.useCallback(async(a,d)=>{if(Ss(a)){const _=Pc(a);if(ee&&ee.job_id===_){const P=Zs(ee,d??pt);Pe(a),A(P.caseId),re(P.detail),le(P.dialog);return}Pe(a),A(""),re(null),le(null);return}Pn(!0);try{const _=await Ce.loadAutoRunDetail(a);re(_);const P=(d&&(d===pt||_.cases.some(ce=>ce.case_id===d))?d:"")||(_.cases.length>0?pt:"")||"";Pe(a),A(P),P?await bn(a,P):le(null)}catch(_){const P=_ instanceof Error?_.message:String(_);Be(`Детализация прогона: ${P}`),re(null),le(null),oe(`Run detail load error for ${a}: ${P}`)}finally{Pn(!1)}},[ee,bn,oe]),gn=y.useCallback(async a=>{un(!0),Be("");try{const d=await Ce.loadAutoRunsHistory({from:rl(I.fromLocal),to:rl(I.toLocal),target:I.target,mode:I.mode,use_mock:I.useMock,prompt_contains:I.promptContains.trim()||void 0,limit:I.limit});if(Me(d),d.items.length===0){Pe(""),A(""),re(null),le(null);return}const _=a?.keepSelection??!0,P=a?.preferredRunId??"",ce=a?.preferredCaseId??"",Ae=_&&P&&d.items.some(en=>en.run_id===P)?P:d.items[0].run_id;await Zt(Ae,_?ce:void 0),Xe()}catch(d){const _=d instanceof Error?d.message:String(d);Be(`История прогонов: ${_}`),oe(`History load error: ${_}`)}finally{un(!1)}},[I.fromLocal,I.limit,I.mode,I.promptContains,I.target,I.toLocal,I.useMock,Xe,Zt,oe]),Et=y.useCallback(()=>{je.current!==null&&(window.clearTimeout(je.current),je.current=null)},[]),Vn=y.useCallback(async a=>{try{const d=await Ce.loadEvalRunAsyncStatus(a);ke(d.job);const _=ol(a);if(ve===_){const P=Zs(d.job,pe||pt);re(P.detail),le(P.dialog),A(P.caseId)}if(d.job.status==="completed"){Et(),Vt(!1);const P=d.job.report_summary?.run_id??d.job.run_id;await gn({keepSelection:!0,preferredRunId:P||ve,preferredCaseId:pt}),await xt(),ke(null);return}if(d.job.status==="failed"){Et(),Vt(!1),Be(`Запуск прогонов: ${d.job.error??"неизвестная ошибка"}`),oe(`Autogen async run failed: ${d.job.error??"unknown error"}`);return}Et(),je.current=window.setTimeout(()=>{Vn(a)},500)}catch(d){Et(),Vt(!1);const _=d instanceof Error?d.message:String(d);Be(`Запуск прогонов: ${_}`),oe(`Autogen async status error: ${_}`)}},[xt,gn,oe,pe,ve,Et]),Qn=y.useCallback(async()=>{Et(),Vt(!0),Be("");try{const a=yt;if(!a)throw new Error("История автогенерации пуста. Сначала сгенерируйте пачку вопросов.");const d=ye.map(Kn=>Kn.trim()).filter(Kn=>Kn.length>0);if(d.length===0)throw new Error("Нет вопросов для запуска: список пустой после ручного редактирования.");const _=I.useMock==="true",P=Hi(L),Ae=(await Ce.startEvalRunAsync({connection:i,prompts:g,promptVersion:h,mode:"single-pass-strict",caseSetFile:a.saved_case_set_file??void 0,useMock:_,evalTarget:"assistant_stage1",questions:d,analysisDate:P||void 0})).job;ke(Ae);const en=ol(Ae.job_id),yn=Zs(Ae,pt);Pe(en),A(yn.caseId),re(yn.detail),le(yn.dialog),oe(`Запущен async-прогон job=${Ae.job_id}, run_id=${Ae.run_id}, вопросов=${d.length}`+(a.saved_case_set_file?`, base_case_set=${a.saved_case_set_file}`:"")+(P?`, analysis_date=${P}`:", analysis_date=current_state")),Vn(Ae.job_id)}catch(a){const d=a instanceof Error?a.message:String(a);Be(`Запуск прогонов: ${d}`),oe(`Autogen run error: ${d}`),Vt(!1)}},[L,h,i,ye,I.useMock,oe,Vn,g,yt,Et]),f=y.useCallback(a=>{if(a.role!=="assistant")return;const d=a.case_id??pe,_=a.case_message_index??a.message_index;Ge({open:!0,caseId:d,caseMessageIndex:_,messageIndex:a.message_index,rating:a.annotation?.rating??3,comment:a.annotation?.comment??"",manualCaseDecision:a.annotation?.manual_case_decision??nl,annotationAuthor:a.annotation?.annotation_author??m.generatedBy,saving:!1,error:""})},[m.generatedBy,pe]),E=y.useCallback(a=>{Ge(d=>d.saving&&!a?.force?d:{open:!1,caseId:"",caseMessageIndex:-1,messageIndex:-1,rating:3,comment:"",manualCaseDecision:nl,annotationAuthor:m.generatedBy,saving:!1,error:""})},[m.generatedBy]),j=y.useCallback(async()=>{const a=ve,d=ie.caseId,_=ie.caseMessageIndex;if(!(!a||!d||_<0)){if(Ss(a)){Ge(P=>({...P,error:"Комментарий можно сохранить после завершения прогона."}));return}if(!ie.comment.trim()){Ge(P=>({...P,error:"Добавьте комментарий."}));return}Ge(P=>({...P,saving:!0,error:""}));try{await Ce.saveAutoRunAnnotation({run_id:a,case_id:d,message_index:_,rating:ie.rating,comment:ie.comment.trim(),manual_case_decision:ie.manualCaseDecision,annotation_author:ie.annotationAuthor.trim()||void 0}),E({force:!0}),Promise.all([Zt(a,pe),Ln(),Xe()]).catch(P=>{const ce=P instanceof Error?P.message:String(P);Be(`Обновление после комментария: ${ce}`),oe(`Comment refresh error: ${ce}`)})}catch(P){Ge(ce=>({...ce,saving:!1,error:P instanceof Error?P.message:String(P)}))}}},[E,ie.annotationAuthor,ie.caseId,ie.caseMessageIndex,ie.comment,ie.manualCaseDecision,ie.rating,Ln,Xe,Zt,oe,pe,ve]),xe=y.useCallback(a=>a.role==="assistant",[]),Wn=y.useCallback(a=>a.role==="assistant"&&Xt.has(a.message_id),[Xt]),vn=y.useCallback((a,d)=>{if(a.role!=="assistant")return;const _=lt.trim(),P=String(a.session_id??"").trim();if(!(_||P)){Yt("Сначала получите ответ ассистента в активной сессии.");return}!_&&P&&dn(P);const Ae=Xt.get(a.message_id)??null;Yt(""),vt({open:!0,messageIndex:d,rating:Ae?.rating??3,comment:Ae?.comment??"",annotationAuthor:Ae?.annotation_author??"manual_reviewer",saving:!1,error:""})},[Xt,lt]),eo=y.useCallback(async()=>{if(me.messageIndex<0)return;if(!me.comment.trim()){vt(_=>({..._,error:"Добавьте комментарий."}));return}const a=fn[me.messageIndex]??null,d=lt.trim()||(a?.role==="assistant"?String(a.session_id??"").trim():"");if(!d){vt(_=>({..._,error:"Сессия ассистента не найдена."}));return}vt(_=>({..._,saving:!0,error:""}));try{const _=await Ce.saveAssistantAnnotation({session_id:d,message_index:me.messageIndex,rating:me.rating,comment:me.comment.trim(),annotation_author:me.annotationAuthor.trim()||void 0});jt(P=>{const ce=[...P],Ae=ce.findIndex(en=>en.annotation_id===_.annotation.annotation_id);return Ae>=0?ce[Ae]=_.annotation:ce.unshift(_.annotation),ce.sort((en,yn)=>Date.parse(yn.updated_at)-Date.parse(en.updated_at))}),Ct({force:!0})}catch(_){const P=_ instanceof Error?_.message:String(_);vt(ce=>({...ce,saving:!1,error:P}))}},[me.annotationAuthor,me.comment,me.messageIndex,me.rating,fn,lt,Ct]),ws=y.useCallback(a=>{$e(d=>d.map(_=>_.annotation_id===a.annotation_id?{..._,...a}:_)),le(d=>d&&{...d,annotations:d.annotations.map(_=>_.annotation_id===a.annotation_id?a:_),messages:d.messages.map(_=>!_.annotation||_.annotation.annotation_id!==a.annotation_id?_:{..._,commented:!0,annotation:a})})},[]),js=y.useCallback(async(a,d)=>{if(a.annotation_id){if(Ss(a.run_id)){Be("Статус выполнения можно менять только для завершённых прогонов.");return}Ot(a.annotation_id);try{const _=await Ce.updateAutoRunAnnotation({annotation_id:a.annotation_id,resolved:d,resolved_by:m.generatedBy||void 0});ws(_.annotation),Xe()}catch(_){const P=_ instanceof Error?_.message:String(_);Be(`Смена статуса кейса: ${P}`),oe(`Annotation resolve toggle error: ${P}`)}finally{Ot("")}}},[ws,m.generatedBy,Xe,oe]),Xr=y.useCallback(async a=>{nt(a.annotation_id),await Zt(a.run_id,a.case_id),ae?.items.some(d=>d.run_id===a.run_id)||Be("Комментарий относится к прогону вне текущего фильтра. Детали загружены напрямую.")},[ae?.items,Zt]);y.useEffect(()=>{dr.current||(dr.current=!0,gn({keepSelection:!1}),xt(),Dn(),Xe())},[xt,Dn,gn,Xe]),y.useEffect(()=>{dr.current&&Ln()},[Te,Ln]),y.useEffect(()=>{nt(a=>Q.length===0?"":Q.some(d=>d.annotation_id===a)?a:Q[0].annotation_id)},[Q]),y.useEffect(()=>{fe(a=>J.length===0?"":a&&J.some(d=>d.generation_id===a)?a:J[0].generation_id)},[J]),y.useEffect(()=>{if(!yt){ge([]);return}ge([...yt.questions])},[yt?.generation_id]),y.useEffect(()=>{ht(String(I.limit))},[I.limit]),y.useEffect(()=>{gt(String(m.count))},[m.count]),y.useEffect(()=>{if(!lt.trim()){jt([]);return}In(lt)},[lt,In]),y.useEffect(()=>{if(!ee)return;const a=ol(ee.job_id);if(ve!==a)return;const d=Zs(ee,pe||pt);re(d.detail),le(d.dialog),A(d.caseId)},[ee,pe,ve]),y.useEffect(()=>()=>{Et()},[Et]),y.useEffect(()=>{V.length!==0&&k(a=>{let d=!1;const _={...a.personalityPrompts};for(const ce of V)(typeof _[ce.id]!="string"||_[ce.id].trim().length===0)&&(_[ce.id]=ce.defaultPrompt,d=!0);let P=a.personalityId;return V.some(ce=>ce.id===a.personalityId)||(P=V[0].id,d=!0),d?{...a,personalityId:P,personalityPrompts:_}:a})},[V]),y.useEffect(()=>{const a=localStorage.getItem(_c);if(a)try{const d=JSON.parse(a);if(d.filters){const _=d.filters;G(P=>({...P,..._,limit:typeof _.limit=="number"?Math.max(1,Math.min(500,_.limit)):P.limit}))}typeof d.analysisDate=="string"&&H(Hi(d.analysisDate)),typeof d.autogenPersonalityPromptHeight=="number"&&pn(jc(d.autogenPersonalityPromptHeight)),d.autoGenSettings&&k(_=>{const P={..._.personalityPrompts},ce=d.autoGenSettings?.personalityPrompts??{};for(const[en,yn]of Object.entries(ce))typeof yn=="string"&&en.trim().length>0&&(P[en.trim()]=yn);const Ae=typeof d.autoGenSettings?.personalityId=="string"&&d.autoGenSettings.personalityId.trim().length>0?d.autoGenSettings.personalityId.trim():_.personalityId;return{..._,mode:d.autoGenSettings?.mode==="codex_creative"||d.autoGenSettings?.mode==="qwen_seed"?d.autoGenSettings.mode:_.mode,count:typeof d.autoGenSettings?.count=="number"?Math.max(1,Math.min(200,d.autoGenSettings.count)):_.count,personalityId:Ae,personalityPrompts:P,persistToEvalCases:typeof d.autoGenSettings?.persistToEvalCases=="boolean"?d.autoGenSettings.persistToEvalCases:_.persistToEvalCases,generatedBy:typeof d.autoGenSettings?.generatedBy=="string"?d.autoGenSettings.generatedBy:_.generatedBy}}),(d.annotationDecisionFilter==="all"||typeof d.annotationDecisionFilter=="string"&&d.annotationDecisionFilter.length>0)&&Le(d.annotationDecisionFilter),typeof d.hideResolvedAnnotations=="boolean"&&se(d.hideResolvedAnnotations)}catch{}},[]);const Dr=y.useCallback(()=>{const a={filters:I,analysisDate:L,autogenPersonalityPromptHeight:mn,autoGenSettings:{mode:m.mode,count:m.count,personalityId:m.personalityId,personalityPrompts:m.personalityPrompts,persistToEvalCases:m.persistToEvalCases,generatedBy:m.generatedBy},annotationDecisionFilter:Te,hideResolvedAnnotations:Fe};localStorage.setItem(_c,JSON.stringify(a))},[L,Te,m,mn,I,Fe]);return y.useEffect(()=>{const a=()=>{Dr(),oe("Сохранены настройки панели автопрогонов.")};return window.addEventListener(Sc,a),()=>{window.removeEventListener(Sc,a)}},[oe,Dr]),o.jsxs(Cn,{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=>G(d=>({...d,fromLocal:a.target.value}))})]}),o.jsxs("label",{children:["Дата по",o.jsx("input",{type:"datetime-local",value:I.toLocal,onChange:a=>G(d=>({...d,toLocal:a.target.value}))})]}),o.jsxs("label",{children:["Целевой контур",o.jsxs("select",{value:I.target,onChange:a=>G(d=>({...d,target:a.target.value})),children:[o.jsx("option",{value:"all",children:"все"}),(ae?.available.targets??[]).map(a=>o.jsx("option",{value:a,children:a},a))]})]}),o.jsxs("label",{children:["Режим",o.jsxs("select",{value:I.mode,onChange:a=>G(d=>({...d,mode:a.target.value})),children:[o.jsx("option",{value:"all",children:"все"}),(ae?.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=>G(d=>({...d,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 d=a.target.value;(d===""||/^\d+$/.test(d))&&ht(d)},onBlur:a=>Gr(a.target.value),onKeyDown:a=>{a.key==="Enter"&&Gr(a.target.value)}})]}),o.jsxs("label",{className:"full-width",children:["Версия промпта содержит",o.jsx("input",{value:I.promptContains,onChange:a=>G(d=>({...d,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:(ae?.available.prompt_versions??[]).map(a=>o.jsx("option",{value:a},a))}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",disabled:Wt,onClick:()=>{gn({keepSelection:!1})},children:Wt?"Обновляю...":"Применить"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>{G({...Ui,fromLocal:kc()}),Be("")},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(d=>({...d,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 d=a.target.value;(d===""||/^\d+$/.test(d))&>(d)},onBlur:a=>ut(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ut(a.target.value)}})]}),o.jsxs("label",{children:["Личность автогенерации",o.jsx("select",{value:m.personalityId,onChange:a=>k(d=>({...d,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(d=>({...d,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(d=>({...d,personalityPrompts:{...d.personalityPrompts,[d.personalityId]:a.target.value}})),placeholder:"Текст промпта для выбранной личности автогенерации",style:{height:`${mn}px`},onMouseUp:Yr,onTouchEnd:Yr})]}),o.jsxs("label",{className:"checkbox-row",children:[o.jsx("input",{type:"checkbox",checked:m.persistToEvalCases,onChange:a=>k(d=>({...d,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(Hi(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:Nn,onClick:()=>{hn()},children:Nn?"Генерирую...":"Сгенерировать пачку"}),o.jsx("button",{type:"button",className:"tab",disabled:an,onClick:()=>{xt()},children:an?"Обновляю...":"Обновить историю"}),o.jsx("button",{type:"button",className:"autoruns-run-launch-btn",disabled:rr||ye.length===0,onClick:()=>{Qn()},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:J.length===0,children:[J.length===0?o.jsx("option",{value:"",children:"нет генераций"}):null,J.map(a=>o.jsxs("option",{value:a.generation_id,children:[Mr(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,d)=>o.jsxs("div",{className:"autoruns-generated-question-item",children:[o.jsxs("span",{children:[d+1,". ",a]}),o.jsx("button",{type:"button",className:"autoruns-remove-question-btn",onClick:()=>ge(_=>_.filter((P,ce)=>ce!==d)),title:"Удалить вопрос из запуска","aria-label":"Удалить вопрос из запуска",children:"+"})]},`${d}-${a.slice(0,24)}`))})]}),o.jsx("p",{className:"muted",children:"Запуск выполняет `assistant_stage1` eval по выбранному кейс-сету."}),o.jsxs("div",{className:"autoruns-autogen-list",children:[an?o.jsx("p",{className:"muted",children:"Загружаю историю автогенераций..."}):null,!an&&J.length===0?o.jsx("p",{className:"muted",children:"История автогенераций пока пустая."}):null,J.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:Mr(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})]})]}),cn?o.jsx("p",{className:"error-text",children:cn}):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:(ae?.stats.runs_total??0)+(ee?1:0)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Средний score"}),o.jsx("strong",{children:sl(ae?.stats.avg_score_index??null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Тренд"}),o.jsx("strong",{children:ae?Cc(ae.stats.trend):"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Блокеры"}),o.jsx("strong",{children:ae?.stats.blocking_runs??0})]})]}),o.jsxs("div",{className:"autoruns-run-list",children:[fr.map(a=>o.jsxs("button",{type:"button",className:ve===a.run_id?"autoruns-run-item selected":"autoruns-run-item",onClick:()=>{Zt(a.run_id)},children:[o.jsxs("div",{className:"autoruns-run-head",children:[o.jsx("strong",{children:Mr(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:d=>{Ir(d,a.run_id)},onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),Ir(d,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:["оценка: ",sl(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)),fr.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 d=a.target.value;Zt(d)},children:fr.map(a=>o.jsxs("option",{value:a.run_id,children:[Mr(a.run_timestamp)," | ",a.run_id]},a.run_id))})]}),o.jsxs("label",{children:["Кейс",o.jsxs("select",{value:pe,onChange:a=>{const d=a.target.value;A(d),ve&&d&&bn(ve,d)},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&&bn(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&&bn(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&&(K?.messages.length??0)===0?o.jsx("p",{className:"muted",children:"Диалог для этого прогона не найден."}):null,(K?.messages??[]).map((a,d)=>{const _=a.role==="assistant"?"assistant":"user";return o.jsxs("article",{className:`autoruns-msg ${_}`,children:[o.jsxs("header",{children:[o.jsx("strong",{children:_==="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?Mr(a.created_at):"нет данных"}),_==="assistant"&&!Ss(ve)?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:a.commented?"autoruns-comment-icon commented":"autoruns-comment-icon",onClick:()=>f(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:()=>{js(a.annotation,!a.annotation.resolved)},disabled:lr===a.annotation.annotation_id,title:a.annotation.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный","aria-label":a.annotation.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный",children:o.jsx(Mc,{resolved:a.annotation.resolved})}):null]}):null]})]}),o.jsx("p",{children:a.text}),_==="assistant"&&a.annotation?o.jsxs("div",{className:"autoruns-msg-annotation",children:[o.jsx("strong",{children:Nc(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??`${_}-${d}`)})]})]}),R?o.jsx("div",{className:"autoruns-col autoruns-assistant-live-col",children:o.jsx(zc,{sessionId:lt,conversation:fn,inputValue:Rn,onInputChange:Jt,useMock:zt,onUseMockChange:$t,onSend:Nt,onClear:mr,busy:Rr,statusText:ir,errorMessage:ar,showCommentAction:!0,onCommentAssistantMessage:vn,isAssistantMessageCommented:Wn,canCommentAssistantMessage:xe})}):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:Tn?.case_id??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"домен:"}),o.jsx("strong",{children:Tn?.domain??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"класс запроса:"}),o.jsx("strong",{children:Tn?.query_class??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"trace:"}),o.jsx("strong",{children:Tn?.trace_id??"нет данных"})]})]}),o.jsx("h4",{children:"Шаги декомпозиции"}),(K?.decomposition.length??0)>0?o.jsx("ol",{className:"autoruns-decomposition-list",children:(K?.decomposition??[]).map((a,d)=>o.jsx("li",{children:a},`${d}-${a.slice(0,24)}`))}):o.jsx("p",{className:"muted",children:"В логах кейса нет явной декомпозиции."})]}):null,q?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:sl(ae?.stats.latest_score_index??null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Предыдущий"}),o.jsx("strong",{children:sl(ae?.stats.previous_score_index??null)})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Тренд"}),o.jsx("strong",{children:ae?Cc(ae.stats.trend):"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Пробелы качества"}),o.jsx("strong",{children:ae?.stats.quality_gap_runs??0})]})]}),o.jsx("h4",{children:"Покрытие доменов (история)"}),Ec(ae?.stats.domain_coverage??[]),o.jsx("h4",{style:{marginTop:14},children:"Покрытие доменов (выбранный прогон)"}),Ec(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(Lt?.post_analysis.stats.by_queue??{}).map(([a,d])=>o.jsxs("div",{children:[o.jsx("span",{children:a}),o.jsx("strong",{children:d})]},a))}),o.jsxs("div",{className:"autoruns-autogen-list",children:[(Lt?.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&&(Lt?.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=>Le(a.target.value),children:[o.jsx("option",{value:"all",children:"все"}),(tt.length>0?tt:De?.enum??[]).map(a=>o.jsx("option",{value:a,children:String(De?.labels?.[a]??a)},a))]})]}),o.jsx("button",{type:"button",className:"tab autoruns-resolved-filter-toggle",onClick:()=>se(a=>!a),children:Fe?"Показать выполненные":"Скрыть выполненные"})]}),o.jsxs("div",{className:"autoruns-stats-grid",children:[o.jsxs("div",{children:[o.jsx("span",{children:"Комментариев"}),o.jsx("strong",{children:Q.length})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Средний рейтинг"}),o.jsx("strong",{children:Re===null?"нет данных":`${Re.toFixed(2)} / 5`})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Последний"}),o.jsx("strong",{children:Q.length>0?Mr(Q[0].updated_at):"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"Статус"}),o.jsx("strong",{children:Kt?"обновляю":"готово"})]})]}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",disabled:Kt,onClick:()=>{Ln()},children:Kt?"Обновляю...":"Обновить список"}),o.jsx("button",{type:"button",className:"tab",disabled:Qt,onClick:()=>{Xe()},children:Qt?"Идет пост-анализ...":"Обновить пост-анализ"})]}),o.jsxs("div",{className:"autoruns-comments-list",children:[Kt?o.jsx("p",{className:"muted",children:"Загружаю комментарии..."}):null,!Kt&&Q.length===0?o.jsx("p",{className:"muted",children:we.length===0?"Пока нет откомментированных ответов.":"Нет открытых кейсов по текущему фильтру."}):null,Q.map(a=>o.jsxs("article",{className:Ye===a.annotation_id?"autoruns-comment-item selected":"autoruns-comment-item",onClick:()=>{Xr(a)},role:"button",tabIndex:0,onKeyDown:d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),Xr(a))},children:[o.jsxs("div",{className:"autoruns-comment-head",children:[o.jsx("strong",{children:Nc(a.rating)}),o.jsxs("div",{className:"autoruns-comment-head-actions",children:[o.jsx("span",{children:Mr(a.updated_at)}),o.jsx("button",{type:"button",className:a.resolved?"autoruns-resolve-toggle resolved":"autoruns-resolve-toggle",onClick:d=>{d.preventDefault(),d.stopPropagation(),js(a,!a.resolved)},disabled:lr===a.annotation_id,title:a.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный","aria-label":a.resolved?"Отметить кейс как невыполненный":"Отметить кейс как выполненный",children:o.jsx(Mc,{resolved:a.resolved})})]})]}),o.jsx("div",{className:"autoruns-run-meta",children:a.run_id}),o.jsxs("div",{className:"autoruns-run-meta",children:["case=",a.case_id," | msg=",a.message_index]}),o.jsxs("div",{className:"autoruns-run-meta",children:["decision=",a.manual_case_decision,a.annotation_author?` | author=${a.annotation_author}`:""]}),a.resolved_at?o.jsxs("div",{className:"autoruns-run-meta",children:["выполнено",": ",Mr(a.resolved_at),a.resolved_by?` | by=${a.resolved_by}`:""]}):null,a.context.question_text?o.jsxs("p",{children:["Q: ",a.context.question_text]}):null,a.context.answer_text?o.jsxs("p",{children:["A: ",a.context.answer_text]}):null,o.jsx("p",{children:a.comment})]},a.annotation_id))]}),Ne?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:Ne.technical_context.trace_id??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"reply_type:"}),o.jsx("strong",{children:Ne.technical_context.reply_type??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"domain:"}),o.jsx("strong",{children:Ne.technical_context.domain??"нет данных"})]}),o.jsxs("div",{children:[o.jsx("span",{children:"query_class:"}),o.jsx("strong",{children:Ne.technical_context.query_class??"нет данных"})]})]}),o.jsx("h4",{children:"JSON разбор"}),o.jsx(bt,{value:{annotation_id:Ne.annotation_id,run_id:Ne.run_id,case_id:Ne.case_id,message_index:Ne.message_index,rating:Ne.rating,comment:Ne.comment,manual_case_decision:Ne.manual_case_decision,annotation_author:Ne.annotation_author,resolved:Ne.resolved,resolved_at:Ne.resolved_at,resolved_by:Ne.resolved_by,context:Ne.context,technical_context:Ne.technical_context,case_summary:Ne.case_summary?{case_id:Ne.case_summary.case_id,domain:Ne.case_summary.domain,query_class:Ne.case_summary.query_class,checks:Ne.case_summary.checks,metric_subscores:Ne.case_summary.metric_subscores}:null}})]}):null]}):null]}),me.open?o.jsx("div",{className:"autoruns-comment-modal-backdrop",onClick:a=>{a.target===a.currentTarget&&Ct()},children:o.jsxs("div",{className:"autoruns-comment-modal",children:[o.jsx("h3",{children:"Комментарий к ответу ассистента"}),o.jsx("p",{className:"muted",children:"Комментарий сохраняется отдельно от комментариев автопрогонов."}),qr?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Вопрос пользователя"}),o.jsx("p",{className:"autoruns-comment-quote",children:qr.text})]}):null,Ar?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Ответ ассистента"}),o.jsx("p",{className:"autoruns-comment-quote",children:Ar.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(d=>({...d,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(d=>({...d,annotationAuthor:a.target.value})),placeholder:"manual_reviewer",disabled:me.saving})]})}),o.jsxs("label",{children:["Комментарий",o.jsx("textarea",{value:me.comment,onChange:a=>vt(d=>({...d,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:()=>{eo()},disabled:me.saving,children:me.saving?"Сохраняю...":"Готово"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>Ct(),disabled:me.saving,children:"Отмена"})]})]})}):null,ie.open?o.jsx("div",{className:"autoruns-comment-modal-backdrop",onClick:a=>{a.target===a.currentTarget&&E()},children:o.jsxs("div",{className:"autoruns-comment-modal",children:[o.jsx("h3",{children:"Комментарий к ответу системы"}),o.jsx("p",{className:"muted",children:"Оцените ответ по 5-балльной шкале и добавьте комментарий по браку."}),An?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:Tr?.text??"Вопрос в диалоге не найден."})]}),o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Ответ системы"}),o.jsx("p",{className:"autoruns-comment-quote",children:An.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:ie.rating>=a?"autoruns-rating-dot active":"autoruns-rating-dot",onClick:()=>Ge(d=>({...d,rating:a})),disabled:ie.saving,"aria-label":`Оценка ${a}`,children:ie.rating>=a?"●":"○"},a))}),o.jsxs("div",{className:"autoruns-form-grid",children:[o.jsxs("label",{children:["Решение по кейсу",o.jsx("select",{value:ie.manualCaseDecision,onChange:a=>Ge(d=>({...d,manualCaseDecision:a.target.value})),disabled:ie.saving,children:(tt.length>0?tt:De?.enum??[nl]).map(a=>o.jsx("option",{value:a,children:String(De?.labels?.[a]??a)},a))})]}),o.jsxs("label",{children:["Автор комментария",o.jsx("input",{value:ie.annotationAuthor,onChange:a=>Ge(d=>({...d,annotationAuthor:a.target.value})),placeholder:"manual_reviewer",disabled:ie.saving})]})]}),o.jsxs("label",{children:["Комментарий",o.jsx("textarea",{value:ie.comment,onChange:a=>Ge(d=>({...d,comment:a.target.value})),placeholder:"Почему ответ бракованный, что именно пошло не так, какие технические детали проверить.",rows:4,disabled:ie.saving})]}),ie.error?o.jsx("p",{className:"error-text",children:ie.error}):null,o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>{j()},disabled:ie.saving,children:ie.saving?"Сохраняю...":"Готово"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>E(),disabled:ie.saving,children:"Отмена"})]})]})}):null]})}function Rc({value:i,modelOptions:g,modelsBusy:h,onChange:O,onReloadModels:R,onTestConnection:z,onSaveLocalConfig:q,lastStatus:te,busy:U}){const I=i.llmProvider==="local",G=g.includes(i.model),[L,H]=y.useState(String(i.temperature)),[ae,Me]=y.useState(String(i.maxOutputTokens));y.useEffect(()=>{H(String(i.temperature))},[i.temperature]),y.useEffect(()=>{Me(String(i.maxOutputTokens))},[i.maxOutputTokens]);const Z=K=>{const le=K.replace(",",".").trim();if(!le){H(String(i.temperature));return}const we=Number(le);if(!Number.isFinite(we)){H(String(i.temperature));return}O({...i,temperature:we}),H(String(we))},re=K=>{const le=K.trim();if(!le){Me(String(i.maxOutputTokens));return}const we=Number.parseInt(le,10);if(!Number.isFinite(we)||we<=0){Me(String(i.maxOutputTokens));return}O({...i,maxOutputTokens:we}),Me(String(we))};return o.jsxs(Cn,{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:K=>{const le=K.target.value==="local"?"local":"openai";O({...i,llmProvider:le,baseUrl:le==="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:G?i.model:"__manual__",onChange:K=>{const le=K.target.value;le!=="__manual__"&&O({...i,model:le})},children:[o.jsx("option",{value:"__manual__",children:"Manual input"}),g.map(K=>o.jsx("option",{value:K,children:K},K))]})]}),o.jsxs("label",{children:["Model ID (manual)",o.jsx("input",{value:i.model,onChange:K=>O({...i,model:K.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:K=>O({...i,apiKey:K.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:K=>O({...i,baseUrl:K.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:K=>H(K.target.value),onBlur:K=>Z(K.target.value),onKeyDown:K=>{K.key==="Enter"&&Z(K.target.value)}})]}),o.jsxs("label",{children:["Max output tokens",o.jsx("input",{type:"number",value:ae,onChange:K=>Me(K.target.value),onBlur:K=>re(K.target.value),onKeyDown:K=>{K.key==="Enter"&&re(K.target.value)}})]})]}),o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>q(),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(Cn,{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(Cn,{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),q=String(z?.schema_version??""),te=q==="normalized_query_v2"||q==="normalized_query_v2_0_1"||q==="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."},G=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(Cn,{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(bt,{value:h?.normalized??{note:"Нет данных."}}):null,i==="fragments"?o.jsx(bt,{value:U}):null,i==="scope"?o.jsx(bt,{value:I}):null,i==="flags"?o.jsx(bt,{value:G}):null,i==="route"?o.jsx(bt,{value:h?.route_hint_summary??{note:"Нет данных."}}):null,i==="raw"?o.jsx(bt,{value:h?.raw_model_output??{note:"Нет данных."}}):null,i==="validation"?o.jsx(bt,{value:h?.validation??{note:"Нет данных."}}):null,i==="logs"?o.jsx(bt,{value:O}):null]})}function Tc({value:i,onChange:g,presets:h,selectedPresetId:O,onSelectPreset:R,onLoadPreset:z,onSavePreset:q,onResetDefaults:te,onDiffPrevious:U,presetName:I,onPresetNameChange:G,diffSummary:L}){return o.jsxs(Cn,{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=>G(H.target.value),placeholder:"Имя для сохранения"}),o.jsx("button",{type:"button",onClick:()=>q(),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:q,errorMessage:te}){return o.jsxs(Cn,{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=>q(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:q,onCopyEvalReport:te,evalBusy:U,traceItems:I,evalReport:G}){return o.jsxs(Cn,{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:()=>q(),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(bt,{value:I}),o.jsxs("div",{className:"eval-report-wrap",children:[o.jsx("h3",{style:{marginTop:12},children:"Отчет eval"}),o.jsx(bt,{value:G??{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},Ac={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:""},bi={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}},Ic="ndc_normalizer_session_config_v1",Lc="ndc_autoruns_layout_config_v1",rm="ndc-autoruns-save",Vi=["Анализ запроса","Получение данных","Подготовка ответа"],sm="assistant",Qi="normalizer_v2_0_2",Dc="address_query_runtime_v1",om=["normalized","fragments","scope","flags","route","raw","validation","logs"],Wi="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]=y.useState(tm),[h,O]=y.useState(Ac),[R,z]=y.useState(nm),[q,te]=y.useState(null),[U,I]=y.useState([]),[G,L]=y.useState([]),[H,ae]=y.useState("normalized"),[Me,Z]=y.useState(!1),[re,K]=y.useState(!1),[le,we]=y.useState([]),[$e,Te]=y.useState(""),[Le,Fe]=y.useState([]),[se,De]=y.useState(""),[Ke,tt]=y.useState("NDC custom preset"),[wt,Ye]=y.useState(null),[nt,ve]=y.useState(""),[Pe,pe]=y.useState(!1),[A,V]=y.useState([]),[D,m]=y.useState(""),[k,J]=y.useState([]),[ue,de]=y.useState(!1),[fe,ye]=y.useState(null),[ge,ee]=y.useState(""),[ke,Lt]=y.useState(sm),[Un,Nn]=y.useState(!0),[En,rr]=y.useState(!0),[Vt,Qt]=y.useState(!0),[Bn,an]=y.useState(!0),[Dt,Wt]=y.useState(!0),[un,sr]=y.useState(!0),[Pn,or]=y.useState(!0),[Mn,Kt]=y.useState(!0),[qt,lr]=y.useState(!0),[Ot,cn]=y.useState(!0),[Be,lt]=y.useState(!0),[dn,fn]=y.useState(!0),[Gt,Hn]=y.useState(!0),[jt,Rn]=y.useState(!0),[Jt,zt]=y.useState(!0),[$t,Rr]=y.useState(!0),[Ve,ir]=y.useState(""),[kt,ar]=y.useState([]),[Yt,ur]=y.useState(""),[ht,cr]=y.useState(!1),[gt,mn]=y.useState(""),[pn,ie]=y.useState(""),[Ge,me]=y.useState([]),[vt,dr]=y.useState(!1),[je,Qe]=y.useState({open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:Wi,saving:!1,error:""}),yt=y.useRef(!1),Tn=y.useRef(!1);y.useEffect(()=>{const f=document.documentElement,{colors:E}=bi;f.style.setProperty("--rgb-background",E.backgroundRgb),f.style.setProperty("--rgb-surface-main",E.mainSurfaceRgb),f.style.setProperty("--rgb-surface-horizontal",E.horizontalSurfaceRgb),f.style.setProperty("--rgb-surface-focus",E.focusSurfaceRgb),f.style.setProperty("--rgb-active",E.activeRgb),f.style.setProperty("--rgb-active-text",E.activeTextRgb),f.style.setProperty("--rgb-text-main",E.textMainRgb),f.style.setProperty("--rgb-text-muted",E.textMutedRgb),f.style.setProperty("--rgb-danger",E.dangerRgb),f.style.setProperty("--rgb-scrollbar-track",E.scrollbarTrackRgb),f.style.setProperty("--rgb-scrollbar-thumb",E.scrollbarThumbRgb),f.style.setProperty("--rgb-scrollbar-thumb-hover",E.scrollbarThumbHoverRgb),f.style.setProperty("--mode-column-width",`${bi.layout.modeColumnWidthPx}px`),f.style.setProperty("--mode-toggle-width",`${bi.layout.modeToggleWidthPx}px`)},[]);const Q=f=>{L(E=>[lm(f),...E].slice(0,300))};function Ne(){let f=0;mn(Vi[0]);const E=window.setInterval(()=>{f=Math.min(f+1,Vi.length-1),mn(Vi[f])},650);return()=>window.clearInterval(E)}y.useEffect(()=>{const f=localStorage.getItem(Ic);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 E=localStorage.getItem(Lc);if(E)try{const j=JSON.parse(E);(j.uiMode==="assistant"||j.uiMode==="decomposition"||j.uiMode==="autoruns")&&Lt(j.uiMode),j.activeTab&&om.includes(j.activeTab)&&ae(j.activeTab),typeof j.showAutorunsAssistantMode=="boolean"&&Nn(j.showAutorunsAssistantMode),typeof j.showAutorunsDecompositionMode=="boolean"&&rr(j.showAutorunsDecompositionMode),typeof j.showAutorunsProgressMode=="boolean"&&Qt(j.showAutorunsProgressMode),typeof j.showAutorunsCommentsMode=="boolean"&&an(j.showAutorunsCommentsMode),typeof j.showAssistantConnectionMode=="boolean"&&Wt(j.showAssistantConnectionMode),typeof j.showAssistantPromptMode=="boolean"&&sr(j.showAssistantPromptMode),typeof j.showAssistantChatMode=="boolean"&&or(j.showAssistantChatMode),typeof j.showAssistantCommentsMode=="boolean"&&Kt(j.showAssistantCommentsMode),typeof j.showAssistantSamMode=="boolean"&&lr(j.showAssistantSamMode),typeof j.showDecompositionConnectionMode=="boolean"&&cn(j.showDecompositionConnectionMode),typeof j.showDecompositionPromptMode=="boolean"&<(j.showDecompositionPromptMode),typeof j.showDecompositionQueryMode=="boolean"&&fn(j.showDecompositionQueryMode),typeof j.showDecompositionOutputMode=="boolean"&&Hn(j.showDecompositionOutputMode),typeof j.showDecompositionMetricsMode=="boolean"&&Rn(j.showDecompositionMetricsMode),typeof j.showDecompositionHistoryMode=="boolean"&&zt(j.showDecompositionHistoryMode),typeof j.showDecompositionRuntimeMode=="boolean"&&Rr(j.showDecompositionRuntimeMode),j.prompts&&(O(xe=>({...xe,...j.prompts})),Tn.current=!0)}catch{}An(),Tr(),Xt()},[]);async function An(){try{const f=await Ce.loadHistory();I(f.items??[])}catch(f){Q(`History load error: ${f instanceof Error?f.message:String(f)}`)}}async function Tr(){try{const E=(await Ce.loadPresets()).presets??[];if(Fe(E),Tn.current){yt.current=!0;return}if(yt.current)return;const j=E.find(xe=>xe.prompt_version===Qi)??E.find(xe=>xe.id==="default-normalizer-v2_0_2");if(!j){yt.current=!0,Q(`Preset autoload skipped: ${Qi} not found.`);return}De(j.id),Ye(h),O({systemPrompt:j.systemPrompt,developerPrompt:j.developerPrompt,domainPrompt:j.domainPrompt,schemaNotes:j.schemaNotes??"",fewShotExamples:j.fewShotExamples??""}),yt.current=!0,Q(`Preset autoloaded: ${j.name} (${j.prompt_version}).`)}catch(f){Q(`Presets load error: ${f instanceof Error?f.message:String(f)}`)}}async function Xt(){try{const f=await Ce.listRuns();V(f.items??[])}catch(f){Q(`Runs load error: ${f instanceof Error?f.message:String(f)}`)}}function Ar(){localStorage.setItem(Ic,JSON.stringify({model:i.model,llmProvider:i.llmProvider,baseUrl:i.baseUrl,temperature:i.temperature,maxOutputTokens:i.maxOutputTokens})),Q("Local config saved (without API key).")}function qr(){localStorage.setItem(Lc,JSON.stringify({uiMode:ke,activeTab:H,showAutorunsAssistantMode:Un,showAutorunsDecompositionMode:En,showAutorunsProgressMode:Vt,showAutorunsCommentsMode:Bn,showAssistantConnectionMode:Dt,showAssistantPromptMode:un,showAssistantChatMode:Pn,showAssistantCommentsMode:Mn,showAssistantSamMode:qt,showDecompositionConnectionMode:Ot,showDecompositionPromptMode:Be,showDecompositionQueryMode:dn,showDecompositionOutputMode:Gt,showDecompositionMetricsMode:jt,showDecompositionHistoryMode:Jt,showDecompositionRuntimeMode:$t,prompts:h})),window.dispatchEvent(new CustomEvent(rm)),Q("UI layout and prompts saved.")}async function Re(){Z(!0),ee("");try{const f=await Ce.testConnection(i);f.provider==="local"?f.model_found===!0?(Te(`LOCAL OK - ${f.model}`),Q(`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}`),Q(`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}`),Q("Local server is reachable, but model catalog could not be verified.")):(Te(`OPENAI OK - ${f.model}`),Q(`OpenAI connection ok: ${f.model}`))}catch(f){const E=f instanceof Error?f.message:String(f);Te("Connection error"),ee(`Test connection: ${E}`),Q(`Test connection error: ${E}`)}finally{Z(!1)}}async function fr(){K(!0);try{const E=(await Ce.listModels(i)).models??[];we(E),E.length>0&&g(j=>j.model&&E.includes(j.model)?j:{...j,model:E[0]}),Q(`Model catalog loaded (${i.llmProvider}): ${E.length} items.`)}catch(f){const E=f instanceof Error?f.message:String(f);Q(`Load model list error: ${E}`)}finally{K(!1)}}y.useEffect(()=>{we([])},[i.llmProvider,i.baseUrl]);async function oe(f){Z(!0),ee("");try{const E=await Ce.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:Pe});te(E),ae("normalized"),Q(`Normalize done: trace=${E.trace_id}, validation=${E.validation.passed?"passed":"failed"}`),An()}catch(E){const j=E instanceof Error?E.message:String(E);ee(`Normalize: ${j}`),Q(`Normalize error: ${j}`)}finally{Z(!1)}}function In(){const f=Le.find(E=>E.id===se);if(!f){Q("Preset is not selected.");return}Ye(h),O({systemPrompt:f.systemPrompt,developerPrompt:f.developerPrompt,domainPrompt:f.domainPrompt,schemaNotes:f.schemaNotes??"",fewShotExamples:f.fewShotExamples??""}),Q(`Preset loaded: ${f.name}`)}async function Ct(){try{await Ce.savePreset({name:Ke||"NDC preset",prompt_version:"normalizer_v2_0_2",systemPrompt:h.systemPrompt,developerPrompt:h.developerPrompt,domainPrompt:h.domainPrompt,schemaNotes:h.schemaNotes,fewShotExamples:h.fewShotExamples}),Q("Preset saved."),await Tr()}catch(f){Q(`Preset save error: ${f instanceof Error?f.message:String(f)}`)}}function Ir(){O(Ac),Q("Prompt panel reset to defaults.")}function Lr(){const f=im(h,wt);ve(f),Q(f)}function mr(){const f=R.batchQuestionsRaw.split(";").map(E=>E.trim()).filter(Boolean).join(` `);f&&(z(E=>({...E,batchQuestionsRaw:f})),Q("Batch field formatted: `;` converted to blank-line separators."))}async function Nt(f){try{const j=(await Ce.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")}),ae("raw"),ee(""),Q(`Trace opened: ${f}`)}catch(E){const j=E instanceof Error?E.message:String(E);ee(`Trace: ${j}`),Q(`Trace open error ${f}: ${j}`)}}async function Gr(){try{const f=await Ce.startRun();m(f.run.runId),Q(`Run started: ${f.run.runId}`),Q("Tip: start run does not execute normalize by itself. Use 'Run eval v2.0.2' button."),await Xt()}catch(f){Q(`Run start error: ${f instanceof Error?f.message:String(f)}`)}}async function ut(){if(D)try{await Ce.finishRun(D),Q(`Run finished: ${D}`),await Xt()}catch(f){Q(`Run finish error: ${f instanceof Error?f.message:String(f)}`)}}async function Jr(){de(!0),ee("");try{Q("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 E=await Ce.runEval({connection:i,prompts:h,promptVersion:"normalizer_v2_0_2",mode:"single-pass-strict",rawQuestions:f,useMock:Pe});ye(E.report),Q("Eval v2.0.2 run finished.");const j=E.report;if(j.run_id&&Q(`Eval run id: ${j.run_id}`),j.metrics){const xe=j.metrics;Q(`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 An()}catch(f){const E=f instanceof Error?f.message:String(f);E.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"]}),Q("Backend is legacy-only for eval right now. Showing v2 pilot plan.")):(ee(`Eval: ${E}`),Q(`Eval run error: ${E}`))}finally{de(!1)}}async function Yr(){try{const f=JSON.stringify(fe??{},null,2);await navigator.clipboard.writeText(f),Q("Eval report copied to clipboard.")}catch(f){Q(`Eval report copy error: ${f instanceof Error?f.message:String(f)}`)}}const Ln=y.useMemo(()=>{const f=new Map;for(const E of Ge)E.message_id&&f.set(E.message_id,E);return f},[Ge]),xt=je.messageIndex>=0?kt[je.messageIndex]??null:null,Dn=y.useMemo(()=>{if(je.messageIndex<0)return null;for(let f=je.messageIndex-1;f>=0;f-=1){const E=kt[f];if(E?.role==="user")return E}return null},[je.messageIndex,kt]);async function Xe(f){if(!f.trim()){me([]);return}dr(!0);try{const E=await Ce.loadAssistantAnnotations({session_id:f,limit:400});me(E.items??[])}catch(E){const j=E instanceof Error?E.message:String(E);Q(`Assistant annotations load error: ${j}`)}finally{dr(!1)}}function hn(f){Qe(E=>E.saving&&!f?.force?E:{open:!1,messageIndex:-1,rating:3,comment:"",annotationAuthor:Wi,saving:!1,error:""})}function bn(f,E){if(f.role!=="assistant")return;const j=Ve.trim(),xe=String(f.session_id??"").trim();if(!(j||xe)){ie("Сначала получите ответ ассистента в активной сессии.");return}!j&&xe&&ir(xe);const vn=Ln.get(f.message_id)??null;Qe({open:!0,messageIndex:E,rating:vn?.rating??3,comment:vn?.comment??"",annotationAuthor:vn?.annotation_author??Wi,saving:!1,error:""})}function Zt(f){return f.role==="assistant"}function gn(f){return f.role==="assistant"&&Ln.has(f.message_id)}async function Et(){if(!Ve.trim()){Qe(f=>({...f,error:"Сессия ассистента не найдена."}));return}if(!(je.messageIndex<0)){if(!je.comment.trim()){Qe(f=>({...f,error:"Добавьте комментарий."}));return}Qe(f=>({...f,saving:!0,error:""}));try{const f=await Ce.saveAssistantAnnotation({session_id:Ve,message_index:je.messageIndex,rating:je.rating,comment:je.comment.trim(),annotation_author:je.annotationAuthor.trim()||void 0});me(E=>{const j=[...E],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,vn)=>Date.parse(vn.updated_at)-Date.parse(Wn.updated_at))}),hn({force:!0})}catch(f){const E=f instanceof Error?f.message:String(f);Qe(j=>({...j,saving:!1,error:E}))}}}function Vn(){ir(""),ar([]),ur(""),mn(""),ie(""),me([]),hn({force:!0}),Q("Assistant session reset.")}async function Qn(){const f=Yt.trim();if(!f)return;cr(!0),ie(""),ur(""),ar(j=>[...j,{message_id:`local-${Date.now()}`,session_id:Ve||"pending",role:"user",text:f,reply_type:null,created_at:new Date().toISOString(),trace_id:null,debug:null}]);const E=Ne();try{const j=await Ce.sendAssistantMessage({connection:i,prompts:h,userMessage:f,sessionId:Ve||void 0,promptVersion:Dc,useMock:Pe});ir(j.session_id),ar(j.conversation),mn("Ответ готов"),await Xe(j.session_id),Q(`Assistant reply received: trace=${j.debug.trace_id}`)}catch(j){const xe=j instanceof Error?j.message:String(j);ie(xe),mn("Ошибка ассистента"),Q(`Assistant error: ${xe}`)}finally{E(),cr(!1)}}return y.useEffect(()=>{if(!Ve.trim()){me([]);return}Xe(Ve)},[Ve]),y.useEffect(()=>{if(!D){J([]);return}Ce.runTrace(D).then(f=>J(f.items)).catch(f=>Q(`Run trace error: ${f instanceof Error?f.message:String(f)}`))},[D]),o.jsxs("main",{className:`app-root ${ke==="assistant"||ke==="decomposition"||ke==="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:ke==="assistant"?"tab active":"tab",onClick:()=>Lt("assistant"),children:"Ассистент"}),o.jsx("button",{type:"button",className:ke==="decomposition"?"tab active":"tab",onClick:()=>Lt("decomposition"),children:"Декомпозиция"}),o.jsx("button",{type:"button",className:ke==="autoruns"?"tab active":"tab",onClick:()=>Lt("autoruns"),children:"История автопрогонов"}),o.jsx("button",{type:"button",className:"tab",onClick:qr,children:"Сохранить"})]}),ke==="assistant"?o.jsxs("div",{className:"mode-switch-row mode-switch-row-right",children:[o.jsx("button",{type:"button",className:Dt?"tab active":"tab",onClick:()=>Wt(f=>!f),children:"LLM Connector"}),o.jsx("button",{type:"button",className:un?"tab active":"tab",onClick:()=>sr(f=>!f),children:"Prompt Manager"}),o.jsx("button",{type:"button",className:Pn?"tab active":"tab",onClick:()=>or(f=>!f),children:"Режим ассистента"}),o.jsx("button",{type:"button",className:Mn?"tab active":"tab",onClick:()=>Kt(f=>!f),children:"Комментарии ассистента"}),o.jsx("button",{type:"button",className:qt?"tab active":"tab",onClick:()=>lr(f=>!f),children:"SAM"})]}):ke==="decomposition"?o.jsxs("div",{className:"mode-switch-row mode-switch-row-right",children:[o.jsx("button",{type:"button",className:Ot?"tab active":"tab",onClick:()=>cn(f=>!f),children:"LLM"}),o.jsx("button",{type:"button",className:Be?"tab active":"tab",onClick:()=>lt(f=>!f),children:"Prompt"}),o.jsx("button",{type:"button",className:dn?"tab active":"tab",onClick:()=>fn(f=>!f),children:"Запрос"}),o.jsx("button",{type:"button",className:Gt?"tab active":"tab",onClick:()=>Hn(f=>!f),children:"Выход"}),o.jsx("button",{type:"button",className:jt?"tab active":"tab",onClick:()=>Rn(f=>!f),children:"Метрики"}),o.jsx("button",{type:"button",className:Jt?"tab active":"tab",onClick:()=>zt(f=>!f),children:"История"}),o.jsx("button",{type:"button",className:$t?"tab active":"tab",onClick:()=>Rr(f=>!f),children:"NDC Run Monitor"})]}):ke==="autoruns"?o.jsxs("div",{className:"mode-switch-row mode-switch-row-right",children:[o.jsx("button",{type:"button",className:Un?"tab active":"tab",onClick:()=>Nn(f=>!f),children:"Режим ассистента"}),o.jsx("button",{type:"button",className:En?"tab active":"tab",onClick:()=>rr(f=>!f),children:"Режим декомпозиции"}),o.jsx("button",{type:"button",className:Vt?"tab active":"tab",onClick:()=>Qt(f=>!f),children:"Прогресс/регресс"}),o.jsx("button",{type:"button",className:Bn?"tab active":"tab",onClick:()=>an(f=>!f),children:"Комментарии"})]}):null]}),ke==="assistant"?o.jsx("div",{className:"layout-grid layout-grid-mode-columns",children:o.jsxs("div",{className:"mode-columns",children:[Dt?o.jsx("div",{className:"mode-col",children:o.jsx(Rc,{value:i,modelOptions:le,modelsBusy:re,onChange:g,onReloadModels:fr,onSaveLocalConfig:Ar,onTestConnection:Re,lastStatus:$e,busy:Me||ht})}):null,un?o.jsx("div",{className:"mode-col mode-col-wide",children:o.jsx(Tc,{value:h,onChange:O,presets:Le,selectedPresetId:se,onSelectPreset:De,onLoadPreset:In,onSavePreset:Ct,onResetDefaults:Ir,onDiffPrevious:Lr,presetName:Ke,onPresetNameChange:tt,diffSummary:nt})}):null,Pn?o.jsx("div",{className:"mode-col mode-col-xwide",children:o.jsx(zc,{sessionId:Ve,conversation:kt,inputValue:Yt,onInputChange:ur,useMock:Pe,onUseMockChange:pe,onSend:Qn,onClear:Vn,busy:ht,statusText:gt,errorMessage:pn,showCommentAction:!0,onCommentAssistantMessage:bn,isAssistantMessageCommented:gn,canCommentAssistantMessage:Zt})}):null,Mn?o.jsx("div",{className:"mode-col",children:o.jsx(Cn,{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:Ve?`session: ${Ve}`:"Сессия не запущена"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>{Xe(Ve)},disabled:!Ve||vt,children:vt?"Обновляю...":"Обновить"})]}),o.jsxs("div",{className:"assistant-comments-list",children:[Ve?null:o.jsx("p",{className:"muted",children:"Появится после первого ответа ассистента."}),Ve&&Ge.length===0&&!vt?o.jsx("p",{className:"muted",children:"Комментариев по этой сессии пока нет."}):null,Ge.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,qt?o.jsx("div",{className:"mode-col",children:o.jsx(Rf,{sessionId:Ve,conversation:kt,statusText:gt,errorMessage:pn,useMock:Pe,appLogs:G})}):null,!Dt&&!un&&!Pn&&!Mn&&!qt?o.jsx("div",{className:"mode-columns-empty",children:"Все панели режима ассистента скрыты. Включите нужные блоки справа в шапке."}):null]})}):ke==="decomposition"?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(Rc,{value:i,modelOptions:le,modelsBusy:re,onChange:g,onReloadModels:fr,onSaveLocalConfig:Ar,onTestConnection:Re,lastStatus:$e,busy:Me})}):null,Be?o.jsx("div",{className:"mode-col mode-col-wide",children:o.jsx(Tc,{value:h,onChange:O,presets:Le,selectedPresetId:se,onSelectPreset:De,onLoadPreset:In,onSavePreset:Ct,onResetDefaults:Ir,onDiffPrevious:Lr,presetName:Ke,onPresetNameChange:tt,diffSummary:nt})}):null,dn?o.jsx("div",{className:"mode-col",children:o.jsx(Zf,{value:R,onChange:z,onApplyBatchFormat:mr,onNormalize:oe,busy:Me,useMock:Pe,onUseMockChange:pe,errorMessage:ge})}):null,Gt?o.jsx("div",{className:"mode-col mode-col-xwide",children:o.jsx(Xf,{tab:H,onTabChange:ae,result:q,appLogs:G})}):null,jt?o.jsx("div",{className:"mode-col",children:o.jsx(Gf,{result:q})}):null,Jt?o.jsx("div",{className:"mode-col",children:o.jsx(qf,{items:U,onRefresh:An,onOpenTrace:Nt})}):null,$t?o.jsx("div",{className:"mode-col mode-col-xwide",children:o.jsx(em,{runs:A,selectedRunId:D,onSelectRun:m,onStartRun:Gr,onFinishRun:ut,onRefreshRuns:Xt,onRunEval:Jr,onCopyEvalReport:Yr,evalBusy:ue,traceItems:k,evalReport:fe})}):null,!Ot&&!Be&&!dn&&!Gt&&!jt&&!Jt&&!$t?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:Dc,decompositionPromptVersion:Qi,showAssistantMode:Un,showDecompositionMode:En,showProgressMode:Vt,showCommentsMode:Bn,onLog:Q})}),je.open?o.jsx("div",{className:"autoruns-comment-modal-backdrop",onClick:f=>{f.target===f.currentTarget&&hn()},children:o.jsxs("div",{className:"autoruns-comment-modal",children:[o.jsx("h3",{children:"Комментарий к ответу ассистента"}),o.jsx("p",{className:"muted",children:"Эта разметка хранится отдельно от комментариев автопрогонов."}),Dn?o.jsxs("details",{className:"autoruns-prompt-details",open:!0,children:[o.jsx("summary",{children:"Вопрос пользователя"}),o.jsx("p",{className:"autoruns-comment-quote",children:Dn.text})]}):null,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,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:je.rating>=f?"autoruns-rating-dot active":"autoruns-rating-dot",onClick:()=>Qe(E=>({...E,rating:f})),disabled:je.saving,"aria-label":`Оценка ${f}`,children:je.rating>=f?"●":"○"},f))}),o.jsx("div",{className:"autoruns-form-grid",children:o.jsxs("label",{children:["Автор комментария",o.jsx("input",{value:je.annotationAuthor,onChange:f=>Qe(E=>({...E,annotationAuthor:f.target.value})),placeholder:"manual_reviewer",disabled:je.saving})]})}),o.jsxs("label",{children:["Комментарий",o.jsx("textarea",{value:je.comment,onChange:f=>Qe(E=>({...E,comment:f.target.value})),placeholder:"Что именно не так в ответе и что проверить.",rows:4,disabled:je.saving})]}),je.error?o.jsx("p",{className:"error-text",children:je.error}):null,o.jsxs("div",{className:"button-row",children:[o.jsx("button",{type:"button",onClick:()=>{Et()},disabled:je.saving,children:je.saving?"Сохраняю...":"Готово"}),o.jsx("button",{type:"button",className:"tab",onClick:()=>hn(),disabled:je.saving,children:"Отмена"})]})]})}):null]})}Ef.createRoot(document.getElementById("root")).render(o.jsx(_f.StrictMode,{children:o.jsx(am,{})}));