@khanglvm/llm-router 2.3.6 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,7 @@ Error generating stack: `+r.message+`
48
48
  `)},BR=function(){var e=parseInt(document.body.getAttribute(Ns)||"0",10);return isFinite(e)?e:0},KL=function(){Os.useEffect(function(){return document.body.setAttribute(Ns,(BR()+1).toString()),function(){var e=BR()-1;e<=0?document.body.removeAttribute(Ns):document.body.setAttribute(Ns,e.toString())}},[])},Py=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;KL();var a=Os.useMemo(function(){return Uy(o)},[o]);return Os.createElement(HL,{styles:FL(a,!t,o,n?"":"!important")})};var jy=!1;if(typeof window<"u")try{hu=Object.defineProperty({},"passive",{get:function(){return jy=!0,!0}}),window.addEventListener("test",hu,hu),window.removeEventListener("test",hu,hu)}catch{jy=!1}var hu,ll=jy?{passive:!1}:!1;var $L=function(e){return e.tagName==="TEXTAREA"},UR=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!$L(e)&&n[t]==="visible")},GL=function(e){return UR(e,"overflowY")},qL=function(e){return UR(e,"overflowX")},Vy=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=PR(e,r);if(o){var a=jR(e,r),i=a[1],l=a[2];if(i>l)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},WL=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},YL=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},PR=function(e,t){return e==="v"?GL(t):qL(t)},jR=function(e,t){return e==="v"?WL(t):YL(t)},QL=function(e,t){return e==="h"&&t==="rtl"?-1:1},VR=function(e,t,n,r,o){var a=QL(e,window.getComputedStyle(t).direction),i=a*r,l=n.target,s=t.contains(l),c=!1,d=i>0,u=0,f=0;do{if(!l)break;var p=jR(e,l),v=p[0],m=p[1],b=p[2],h=m-b-a*v;(v||h)&&PR(e,l)&&(u+=h,f+=v);var g=l.parentNode;l=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!s&&l!==document.body||s&&(t.contains(l)||t===l));return(d&&(o&&Math.abs(u)<1||!o&&i>u)||!d&&(o&&Math.abs(f)<1||!o&&-i>f))&&(c=!0),c};var dm=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},HR=function(e){return[e.deltaX,e.deltaY]},FR=function(e){return e&&"current"in e?e.current:e},XL=function(e,t){return e[0]===t[0]&&e[1]===t[1]},ZL=function(e){return`
49
49
  .block-interactivity-`.concat(e,` {pointer-events: none;}
50
50
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
51
- `)},JL=0,_s=[];function KR(e){var t=Vt.useRef([]),n=Vt.useRef([0,0]),r=Vt.useRef(),o=Vt.useState(JL++)[0],a=Vt.useState(gu)[0],i=Vt.useRef(e);Vt.useEffect(function(){i.current=e},[e]),Vt.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=MR([e.lockRef.current],(e.shards||[]).map(FR),!0).filter(Boolean);return m.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var l=Vt.useCallback(function(m,b){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var h=dm(m),g=n.current,y="deltaX"in m?m.deltaX:g[0]-h[0],x="deltaY"in m?m.deltaY:g[1]-h[1],w,C=m.target,E=Math.abs(y)>Math.abs(x)?"h":"v";if("touches"in m&&E==="h"&&C.type==="range")return!1;var A=window.getSelection(),M=A&&A.anchorNode,L=M?M===C||M.contains(C):!1;if(L)return!1;var P=Vy(E,C);if(!P)return!0;if(P?w=E:(w=E==="v"?"h":"v",P=Vy(E,C)),!P)return!1;if(!r.current&&"changedTouches"in m&&(y||x)&&(r.current=w),!w)return!0;var D=r.current||w;return VR(D,b,m,D==="h"?y:x,!0)},[]),s=Vt.useCallback(function(m){var b=m;if(!(!_s.length||_s[_s.length-1]!==a)){var h="deltaY"in b?HR(b):dm(b),g=t.current.filter(function(w){return w.name===b.type&&(w.target===b.target||b.target===w.shadowParent)&&XL(w.delta,h)})[0];if(g&&g.should){b.cancelable&&b.preventDefault();return}if(!g){var y=(i.current.shards||[]).map(FR).filter(Boolean).filter(function(w){return w.contains(b.target)}),x=y.length>0?l(b,y[0]):!i.current.noIsolation;x&&b.cancelable&&b.preventDefault()}}},[]),c=Vt.useCallback(function(m,b,h,g){var y={name:m,delta:b,target:h,should:g,shadowParent:eD(h)};t.current.push(y),setTimeout(function(){t.current=t.current.filter(function(x){return x!==y})},1)},[]),d=Vt.useCallback(function(m){n.current=dm(m),r.current=void 0},[]),u=Vt.useCallback(function(m){c(m.type,HR(m),m.target,l(m,e.lockRef.current))},[]),f=Vt.useCallback(function(m){c(m.type,dm(m),m.target,l(m,e.lockRef.current))},[]);Vt.useEffect(function(){return _s.push(a),e.setCallbacks({onScrollCapture:u,onWheelCapture:u,onTouchMoveCapture:f}),document.addEventListener("wheel",s,ll),document.addEventListener("touchmove",s,ll),document.addEventListener("touchstart",d,ll),function(){_s=_s.filter(function(m){return m!==a}),document.removeEventListener("wheel",s,ll),document.removeEventListener("touchmove",s,ll),document.removeEventListener("touchstart",d,ll)}},[]);var p=e.removeScrollBar,v=e.inert;return Vt.createElement(Vt.Fragment,null,v?Vt.createElement(a,{styles:ZL(o)}):null,p?Vt.createElement(Py,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function eD(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var $R=Ly(um,KR);var GR=fm.forwardRef(function(e,t){return fm.createElement(pu,vr({},e,{ref:t,sideCar:$R}))});GR.classNames=pu.classNames;var Hy=GR;var Oe=_(Z(),1),tD=[" ","Enter","ArrowUp","ArrowDown"],nD=[" ","Enter"],sl="Select",[pm,gm,rD]=hf(sl),[ks,ZU]=Xr(sl,[rD,Cy]),hm=Cy(),[oD,vi]=ks(sl),[aD,iD]=ks(sl),qR=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:a,value:i,defaultValue:l,onValueChange:s,dir:c,name:d,autoComplete:u,disabled:f,required:p,form:v}=e,m=hm(t),[b,h]=ee.useState(null),[g,y]=ee.useState(null),[x,w]=ee.useState(!1),C=ds(c),[E,A]=pa({prop:r,defaultProp:o??!1,onChange:a,caller:sl}),[M,L]=pa({prop:i,defaultProp:l,onChange:s,caller:sl}),P=ee.useRef(null),D=b?v||!!b.closest("form"):!0,[G,ae]=ee.useState(new Set),ge=Array.from(G).map(j=>j.props.value).join(";");return(0,Oe.jsx)(vR,{...m,children:(0,Oe.jsxs)(oD,{required:p,scope:t,trigger:b,onTriggerChange:h,valueNode:g,onValueNodeChange:y,valueNodeHasChildren:x,onValueNodeHasChildrenChange:w,contentId:ci(),value:M,onValueChange:L,open:E,onOpenChange:A,dir:C,triggerPointerDownPosRef:P,disabled:f,children:[(0,Oe.jsx)(pm.Provider,{scope:t,children:(0,Oe.jsx)(aD,{scope:e.__scopeSelect,onNativeOptionAdd:ee.useCallback(j=>{ae(J=>new Set(J).add(j))},[]),onNativeOptionRemove:ee.useCallback(j=>{ae(J=>{let Q=new Set(J);return Q.delete(j),Q})},[]),children:n})}),D?(0,Oe.jsxs)(gE,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:u,value:M,onChange:j=>L(j.target.value),disabled:f,form:v,children:[M===void 0?(0,Oe.jsx)("option",{value:""}):null,Array.from(G)]},ge):null]})})};qR.displayName=sl;var WR="SelectTrigger",YR=ee.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...o}=e,a=hm(n),i=vi(WR,n),l=i.disabled||r,s=xt(t,i.onTriggerChange),c=gm(n),d=ee.useRef("touch"),[u,f,p]=yE(m=>{let b=c().filter(y=>!y.disabled),h=b.find(y=>y.value===i.value),g=vE(b,m,h);g!==void 0&&i.onValueChange(g.value)}),v=m=>{l||(i.onOpenChange(!0),p()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return(0,Oe.jsx)(bR,{asChild:!0,...a,children:(0,Oe.jsx)(Xe.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":hE(i.value)?"":void 0,...o,ref:s,onClick:dt(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&v(m)}),onPointerDown:dt(o.onPointerDown,m=>{d.current=m.pointerType;let b=m.target;b.hasPointerCapture(m.pointerId)&&b.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(v(m),m.preventDefault())}),onKeyDown:dt(o.onKeyDown,m=>{let b=u.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&f(m.key),!(b&&m.key===" ")&&tD.includes(m.key)&&(v(),m.preventDefault())})})})});YR.displayName=WR;var QR="SelectValue",XR=ee.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:o,children:a,placeholder:i="",...l}=e,s=vi(QR,n),{onValueNodeHasChildrenChange:c}=s,d=a!==void 0,u=xt(t,s.onValueNodeChange);return Xt(()=>{c(d)},[c,d]),(0,Oe.jsx)(Xe.span,{...l,ref:u,style:{pointerEvents:"none"},children:hE(s.value)?(0,Oe.jsx)(Oe.Fragment,{children:i}):a})});XR.displayName=QR;var lD="SelectIcon",ZR=ee.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...o}=e;return(0,Oe.jsx)(Xe.span,{"aria-hidden":!0,...o,ref:t,children:r||"\u25BC"})});ZR.displayName=lD;var sD="SelectPortal",JR=e=>(0,Oe.jsx)(Ey,{asChild:!0,...e});JR.displayName=sD;var cl="SelectContent",eE=ee.forwardRef((e,t)=>{let n=vi(cl,e.__scopeSelect),[r,o]=ee.useState();if(Xt(()=>{o(new DocumentFragment)},[]),!n.open){let a=r;return a?Wy.createPortal((0,Oe.jsx)(tE,{scope:e.__scopeSelect,children:(0,Oe.jsx)(pm.Slot,{scope:e.__scopeSelect,children:(0,Oe.jsx)("div",{children:e.children})})}),a):null}return(0,Oe.jsx)(nE,{...e,ref:t})});eE.displayName=cl;var xo=10,[tE,bi]=ks(cl),cD="SelectContentImpl",uD=Wi("SelectContent.RemoveScroll"),nE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:a,onPointerDownOutside:i,side:l,sideOffset:s,align:c,alignOffset:d,arrowPadding:u,collisionBoundary:f,collisionPadding:p,sticky:v,hideWhenDetached:m,avoidCollisions:b,...h}=e,g=vi(cl,n),[y,x]=ee.useState(null),[w,C]=ee.useState(null),E=xt(t,I=>x(I)),[A,M]=ee.useState(null),[L,P]=ee.useState(null),D=gm(n),[G,ae]=ee.useState(!1),ge=ee.useRef(!1);ee.useEffect(()=>{if(y)return TR(y)},[y]),t1();let j=ee.useCallback(I=>{let[ue,...he]=D().map(ve=>ve.ref.current),[_e]=he.slice(-1),Ee=document.activeElement;for(let ve of I)if(ve===Ee||(ve?.scrollIntoView({block:"nearest"}),ve===ue&&w&&(w.scrollTop=0),ve===_e&&w&&(w.scrollTop=w.scrollHeight),ve?.focus(),document.activeElement!==Ee))return},[D,w]),J=ee.useCallback(()=>j([A,y]),[j,A,y]);ee.useEffect(()=>{G&&J()},[G,J]);let{onOpenChange:Q,triggerPointerDownPosRef:H}=g;ee.useEffect(()=>{if(y){let I={x:0,y:0},ue=_e=>{I={x:Math.abs(Math.round(_e.pageX)-(H.current?.x??0)),y:Math.abs(Math.round(_e.pageY)-(H.current?.y??0))}},he=_e=>{I.x<=10&&I.y<=10?_e.preventDefault():y.contains(_e.target)||Q(!1),document.removeEventListener("pointermove",ue),H.current=null};return H.current!==null&&(document.addEventListener("pointermove",ue),document.addEventListener("pointerup",he,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ue),document.removeEventListener("pointerup",he,{capture:!0})}}},[y,Q,H]),ee.useEffect(()=>{let I=()=>Q(!1);return window.addEventListener("blur",I),window.addEventListener("resize",I),()=>{window.removeEventListener("blur",I),window.removeEventListener("resize",I)}},[Q]);let[B,ft]=yE(I=>{let ue=D().filter(Ee=>!Ee.disabled),he=ue.find(Ee=>Ee.ref.current===document.activeElement),_e=vE(ue,I,he);_e&&setTimeout(()=>_e.ref.current.focus())}),X=ee.useCallback((I,ue,he)=>{let _e=!ge.current&&!he;(g.value!==void 0&&g.value===ue||_e)&&(M(I),_e&&(ge.current=!0))},[g.value]),je=ee.useCallback(()=>y?.focus(),[y]),ie=ee.useCallback((I,ue,he)=>{let _e=!ge.current&&!he;(g.value!==void 0&&g.value===ue||_e)&&P(I)},[g.value]),xe=r==="popper"?Fy:rE,Ie=xe===Fy?{side:l,sideOffset:s,align:c,alignOffset:d,arrowPadding:u,collisionBoundary:f,collisionPadding:p,sticky:v,hideWhenDetached:m,avoidCollisions:b}:{};return(0,Oe.jsx)(tE,{scope:n,content:y,viewport:w,onViewportChange:C,itemRefCallback:X,selectedItem:A,onItemLeave:je,itemTextRefCallback:ie,focusSelectedItem:J,selectedItemText:L,position:r,isPositioned:G,searchRef:B,children:(0,Oe.jsx)(Hy,{as:uD,allowPinchZoom:!0,children:(0,Oe.jsx)(my,{asChild:!0,trapped:g.open,onMountAutoFocus:I=>{I.preventDefault()},onUnmountAutoFocus:dt(o,I=>{g.trigger?.focus({preventScroll:!0}),I.preventDefault()}),children:(0,Oe.jsx)(cy,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:i,onFocusOutside:I=>I.preventDefault(),onDismiss:()=>g.onOpenChange(!1),children:(0,Oe.jsx)(xe,{role:"listbox",id:g.contentId,"data-state":g.open?"open":"closed",dir:g.dir,onContextMenu:I=>I.preventDefault(),...h,...Ie,onPlaced:()=>ae(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...h.style},onKeyDown:dt(h.onKeyDown,I=>{let ue=I.ctrlKey||I.altKey||I.metaKey;if(I.key==="Tab"&&I.preventDefault(),!ue&&I.key.length===1&&ft(I.key),["ArrowUp","ArrowDown","Home","End"].includes(I.key)){let _e=D().filter(Ee=>!Ee.disabled).map(Ee=>Ee.ref.current);if(["ArrowUp","End"].includes(I.key)&&(_e=_e.slice().reverse()),["ArrowUp","ArrowDown"].includes(I.key)){let Ee=I.target,ve=_e.indexOf(Ee);_e=_e.slice(ve+1)}setTimeout(()=>j(_e)),I.preventDefault()}})})})})})})});nE.displayName=cD;var dD="SelectItemAlignedPosition",rE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...o}=e,a=vi(cl,n),i=bi(cl,n),[l,s]=ee.useState(null),[c,d]=ee.useState(null),u=xt(t,E=>d(E)),f=gm(n),p=ee.useRef(!1),v=ee.useRef(!0),{viewport:m,selectedItem:b,selectedItemText:h,focusSelectedItem:g}=i,y=ee.useCallback(()=>{if(a.trigger&&a.valueNode&&l&&c&&m&&b&&h){let E=a.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),M=a.valueNode.getBoundingClientRect(),L=h.getBoundingClientRect();if(a.dir!=="rtl"){let Ee=L.left-A.left,ve=M.left-Ee,Fe=E.left-ve,Je=E.width+Fe,Ht=Math.max(Je,A.width),wn=window.innerWidth-xo,fn=iy(ve,[xo,Math.max(xo,wn-Ht)]);l.style.minWidth=Je+"px",l.style.left=fn+"px"}else{let Ee=A.right-L.right,ve=window.innerWidth-M.right-Ee,Fe=window.innerWidth-E.right-ve,Je=E.width+Fe,Ht=Math.max(Je,A.width),wn=window.innerWidth-xo,fn=iy(ve,[xo,Math.max(xo,wn-Ht)]);l.style.minWidth=Je+"px",l.style.right=fn+"px"}let P=f(),D=window.innerHeight-xo*2,G=m.scrollHeight,ae=window.getComputedStyle(c),ge=parseInt(ae.borderTopWidth,10),j=parseInt(ae.paddingTop,10),J=parseInt(ae.borderBottomWidth,10),Q=parseInt(ae.paddingBottom,10),H=ge+j+G+Q+J,B=Math.min(b.offsetHeight*5,H),ft=window.getComputedStyle(m),X=parseInt(ft.paddingTop,10),je=parseInt(ft.paddingBottom,10),ie=E.top+E.height/2-xo,xe=D-ie,Ie=b.offsetHeight/2,I=b.offsetTop+Ie,ue=ge+j+I,he=H-ue;if(ue<=ie){let Ee=P.length>0&&b===P[P.length-1].ref.current;l.style.bottom="0px";let ve=c.clientHeight-m.offsetTop-m.offsetHeight,Fe=Math.max(xe,Ie+(Ee?je:0)+ve+J),Je=ue+Fe;l.style.height=Je+"px"}else{let Ee=P.length>0&&b===P[0].ref.current;l.style.top="0px";let Fe=Math.max(ie,ge+m.offsetTop+(Ee?X:0)+Ie)+he;l.style.height=Fe+"px",m.scrollTop=ue-ie+m.offsetTop}l.style.margin=`${xo}px 0`,l.style.minHeight=B+"px",l.style.maxHeight=D+"px",r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,l,c,m,b,h,a.dir,r]);Xt(()=>y(),[y]);let[x,w]=ee.useState();Xt(()=>{c&&w(window.getComputedStyle(c).zIndex)},[c]);let C=ee.useCallback(E=>{E&&v.current===!0&&(y(),g?.(),v.current=!1)},[y,g]);return(0,Oe.jsx)(mD,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:(0,Oe.jsx)("div",{ref:s,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:x},children:(0,Oe.jsx)(Xe.div,{...o,ref:u,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});rE.displayName=dD;var fD="SelectPopperPosition",Fy=ee.forwardRef((e,t)=>{let{__scopeSelect:n,align:r="start",collisionPadding:o=xo,...a}=e,i=hm(n);return(0,Oe.jsx)(xR,{...i,...a,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...a.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Fy.displayName=fD;var[mD,Yy]=ks(cl,{}),Ky="SelectViewport",oE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...o}=e,a=bi(Ky,n),i=Yy(Ky,n),l=xt(t,a.onViewportChange),s=ee.useRef(0);return(0,Oe.jsxs)(Oe.Fragment,{children:[(0,Oe.jsx)("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),(0,Oe.jsx)(pm.Slot,{scope:n,children:(0,Oe.jsx)(Xe.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:dt(o.onScroll,c=>{let d=c.currentTarget,{contentWrapper:u,shouldExpandOnScrollRef:f}=i;if(f?.current&&u){let p=Math.abs(s.current-d.scrollTop);if(p>0){let v=window.innerHeight-xo*2,m=parseFloat(u.style.minHeight),b=parseFloat(u.style.height),h=Math.max(m,b);if(h<v){let g=h+p,y=Math.min(v,g),x=g-y;u.style.height=y+"px",u.style.bottom==="0px"&&(d.scrollTop=x>0?x:0,u.style.justifyContent="flex-end")}}}s.current=d.scrollTop})})})]})});oE.displayName=Ky;var aE="SelectGroup",[pD,gD]=ks(aE),iE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,o=ci();return(0,Oe.jsx)(pD,{scope:n,id:o,children:(0,Oe.jsx)(Xe.div,{role:"group","aria-labelledby":o,...r,ref:t})})});iE.displayName=aE;var lE="SelectLabel",sE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,o=gD(lE,n);return(0,Oe.jsx)(Xe.div,{id:o.id,...r,ref:t})});sE.displayName=lE;var mm="SelectItem",[hD,cE]=ks(mm),uE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:o=!1,textValue:a,...i}=e,l=vi(mm,n),s=bi(mm,n),c=l.value===r,[d,u]=ee.useState(a??""),[f,p]=ee.useState(!1),v=xt(t,g=>s.itemRefCallback?.(g,r,o)),m=ci(),b=ee.useRef("touch"),h=()=>{o||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return(0,Oe.jsx)(hD,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:ee.useCallback(g=>{u(y=>y||(g?.textContent??"").trim())},[]),children:(0,Oe.jsx)(pm.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:(0,Oe.jsx)(Xe.div,{role:"option","aria-labelledby":m,"data-highlighted":f?"":void 0,"aria-selected":c&&f,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:dt(i.onFocus,()=>p(!0)),onBlur:dt(i.onBlur,()=>p(!1)),onClick:dt(i.onClick,()=>{b.current!=="mouse"&&h()}),onPointerUp:dt(i.onPointerUp,()=>{b.current==="mouse"&&h()}),onPointerDown:dt(i.onPointerDown,g=>{b.current=g.pointerType}),onPointerMove:dt(i.onPointerMove,g=>{b.current=g.pointerType,o?s.onItemLeave?.():b.current==="mouse"&&g.currentTarget.focus({preventScroll:!0})}),onPointerLeave:dt(i.onPointerLeave,g=>{g.currentTarget===document.activeElement&&s.onItemLeave?.()}),onKeyDown:dt(i.onKeyDown,g=>{s.searchRef?.current!==""&&g.key===" "||(nD.includes(g.key)&&h(),g.key===" "&&g.preventDefault())})})})})});uE.displayName=mm;var yu="SelectItemText",dE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:o,...a}=e,i=vi(yu,n),l=bi(yu,n),s=cE(yu,n),c=iD(yu,n),[d,u]=ee.useState(null),f=xt(t,h=>u(h),s.onItemTextChange,h=>l.itemTextRefCallback?.(h,s.value,s.disabled)),p=d?.textContent,v=ee.useMemo(()=>(0,Oe.jsx)("option",{value:s.value,disabled:s.disabled,children:p},s.value),[s.disabled,s.value,p]),{onNativeOptionAdd:m,onNativeOptionRemove:b}=c;return Xt(()=>(m(v),()=>b(v)),[m,b,v]),(0,Oe.jsxs)(Oe.Fragment,{children:[(0,Oe.jsx)(Xe.span,{id:s.textId,...a,ref:f}),s.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Wy.createPortal(a.children,i.valueNode):null]})});dE.displayName=yu;var fE="SelectItemIndicator",mE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return cE(fE,n).isSelected?(0,Oe.jsx)(Xe.span,{"aria-hidden":!0,...r,ref:t}):null});mE.displayName=fE;var $y="SelectScrollUpButton",yD=ee.forwardRef((e,t)=>{let n=bi($y,e.__scopeSelect),r=Yy($y,e.__scopeSelect),[o,a]=ee.useState(!1),i=xt(t,r.onScrollButtonChange);return Xt(()=>{if(n.viewport&&n.isPositioned){let s=function(){let d=c.scrollTop>0;a(d)};var l=s;let c=n.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),o?(0,Oe.jsx)(pE,{...e,ref:i,onAutoScroll:()=>{let{viewport:l,selectedItem:s}=n;l&&s&&(l.scrollTop=l.scrollTop-s.offsetHeight)}}):null});yD.displayName=$y;var Gy="SelectScrollDownButton",vD=ee.forwardRef((e,t)=>{let n=bi(Gy,e.__scopeSelect),r=Yy(Gy,e.__scopeSelect),[o,a]=ee.useState(!1),i=xt(t,r.onScrollButtonChange);return Xt(()=>{if(n.viewport&&n.isPositioned){let s=function(){let d=c.scrollHeight-c.clientHeight,u=Math.ceil(c.scrollTop)<d;a(u)};var l=s;let c=n.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),o?(0,Oe.jsx)(pE,{...e,ref:i,onAutoScroll:()=>{let{viewport:l,selectedItem:s}=n;l&&s&&(l.scrollTop=l.scrollTop+s.offsetHeight)}}):null});vD.displayName=Gy;var pE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...o}=e,a=bi("SelectScrollButton",n),i=ee.useRef(null),l=gm(n),s=ee.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return ee.useEffect(()=>()=>s(),[s]),Xt(()=>{l().find(d=>d.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[l]),(0,Oe.jsx)(Xe.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:dt(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:dt(o.onPointerMove,()=>{a.onItemLeave?.(),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:dt(o.onPointerLeave,()=>{s()})})}),bD="SelectSeparator",xD=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,Oe.jsx)(Xe.div,{"aria-hidden":!0,...r,ref:t})});xD.displayName=bD;var qy="SelectArrow",SD=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,o=hm(n),a=vi(qy,n),i=bi(qy,n);return a.open&&i.position==="popper"?(0,Oe.jsx)(SR,{...o,...r,ref:t}):null});SD.displayName=qy;var wD="SelectBubbleInput",gE=ee.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let o=ee.useRef(null),a=xt(r,o),i=df(t);return ee.useEffect(()=>{let l=o.current;if(!l)return;let s=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(s,"value").set;if(i!==t&&d){let u=new Event("change",{bubbles:!0});d.call(l,t),l.dispatchEvent(u)}},[i,t]),(0,Oe.jsx)(Xe.select,{...n,style:{...Ty,...n.style},ref:a,defaultValue:t})});gE.displayName=wD;function hE(e){return e===""||e===void 0}function yE(e){let t=cr(e),n=ee.useRef(""),r=ee.useRef(0),o=ee.useCallback(i=>{let l=n.current+i;t(l),(function s(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>s(""),1e3))})(l)},[t]),a=ee.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return ee.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,a]}function vE(e,t,n){let o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,a=n?e.indexOf(n):-1,i=AD(e,Math.max(a,0));o.length===1&&(i=i.filter(c=>c!==n));let s=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return s!==n?s:void 0}function AD(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var bE=qR,xE=YR,SE=XR,wE=ZR,AE=JR,CE=eE,RE=oE,EE=iE,TE=sE,ME=uE,NE=dE,OE=mE;var _E=_(me(),1);var kE=_(Z(),1),wt=(0,_E.forwardRef)(function({className:t,...n},r){return(0,kE.jsx)("input",{ref:r,className:F("flex h-9 w-full rounded-lg border border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40",t),...n})});function LE(e){return String(e||"").trim().toLowerCase()}function ym(e){return LE(e).length>0}function DE({searchEnabled:e=!0}={}){return!!e}function Qy(e){let t=String(e?.key||"");return!t||t.length!==1||e?.ctrlKey||e?.metaKey||e?.altKey?"":t.trim()?t:""}function IE(e={},t=""){let n=LE(t);return n?[e?.label,e?.value,e?.hint,e?.textValue,e?.searchText].map(o=>String(o||"").toLowerCase()).join(" ").includes(n):!0}var vm=_(me(),1),RD=12;function Xy(e){return/auto|scroll|hidden|clip|overlay/.test(String(e||"").toLowerCase())}function ED(e,t){return{top:Math.max(e.top,t.top),right:Math.min(e.right,t.right),bottom:Math.min(e.bottom,t.bottom),left:Math.max(e.left,t.left)}}function bm(e){if(typeof window>"u")return[];let t=[],n=e?.parentElement||null;for(;n&&n!==document.body&&n!==document.documentElement;){let r=window.getComputedStyle(n);(Xy(r.overflow)||Xy(r.overflowY)||Xy(r.overflowX))&&t.push(n),n=n.parentElement}return t}function TD(e,{viewportPadding:t=RD}={}){if(typeof window>"u")return null;let n={top:t,right:window.innerWidth-t,bottom:window.innerHeight-t,left:t};for(let r of bm(e))n=ED(n,r.getBoundingClientRect());return n}function MD({anchorRect:e,boundaryRect:t,preferredSide:n="bottom",offset:r=4,desiredHeight:o=288}={}){if(!e||!t)return{side:n==="top"?"top":"bottom",maxHeight:o};let a=Math.max(0,e.top-t.top-r),i=Math.max(0,t.bottom-e.bottom-r),s=a===i?n==="top"?"top":"bottom":a>i?"top":"bottom",c=Math.max(0,Math.min(o,s==="top"?a:i));return{side:s,maxHeight:c}}function xm({open:e=!1,anchorRef:t,preferredSide:n="bottom",offset:r=4,desiredHeight:o=288}={}){let[a,i]=(0,vm.useState)(()=>({side:n==="top"?"top":"bottom",maxHeight:o}));return(0,vm.useLayoutEffect)(()=>{if(!e||typeof window>"u")return;let l=t?.current||null;if(!l){i({side:n==="top"?"top":"bottom",maxHeight:o});return}let s=()=>{i(MD({anchorRect:l.getBoundingClientRect(),boundaryRect:TD(l),preferredSide:n,offset:r,desiredHeight:o}))};s();let c=bm(l);window.addEventListener("resize",s);for(let u of c)u.addEventListener("scroll",s,{passive:!0});let d=null;if(typeof ResizeObserver=="function"){d=new ResizeObserver(s),d.observe(l);for(let u of c)d.observe(u)}return()=>{window.removeEventListener("resize",s);for(let u of c)u.removeEventListener("scroll",s);d?.disconnect?.()}},[e,t,n,r,o]),a}var Sn=_(Z(),1),wm=(0,it.createContext)(null),ND="Enter character to filter",OD=41,_D="data-llm-router-select-search-input";function Sm(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Sm(t)).filter(Boolean).join(" "):(0,it.isValidElement)(e)?Sm(e.props?.children):""}function Zy(e,t="first"){let n=Array.from(e?.querySelectorAll?.("[role='option']")||[]).filter(a=>a.getAttribute("aria-disabled")!=="true");if(n.length===0)return;let r=n.find(a=>a.getAttribute("data-state")==="checked");(t==="last"?n[n.length-1]:r||n[0])?.focus?.()}function kD(e={}){let t=String(e.textValue||Sm(e.children)||"").trim();return{value:String(e.value||""),textValue:t,searchText:String(e.searchText||"")}}function zE(e,t=""){let n=0,r=0;return{children:it.Children.map(e,a=>{if(!(0,it.isValidElement)(a))return a;if(a.type?.__LLM_ROUTER_SELECT_ITEM===!0){n+=1;let l=IE(kD(a.props),t);return l&&(r+=1),l?a:null}if(!a.props?.children)return a;let i=zE(a.props.children,t);return n+=i.totalItems,r+=i.matchedItems,a.type?.__LLM_ROUTER_SELECT_GROUP===!0&&i.matchedItems===0?null:(0,it.cloneElement)(a,void 0,i.children)}),totalItems:n,matchedItems:r}}function rn({open:e,defaultOpen:t=!1,onOpenChange:n,searchEnabled:r=!0,openSearchRequest:o=0,children:a,...i}){let[l,s]=(0,it.useState)(!!t),[c,d]=(0,it.useState)(""),[u,f]=(0,it.useState)(!1),p=(0,it.useRef)(null),v=(0,it.useRef)(0),m=e!==void 0?e:l;(0,it.useEffect)(()=>{m||(d(""),f(!1))},[m]);function b(g){e===void 0&&s(g),n?.(g),g||(d(""),f(!1))}(0,it.useEffect)(()=>{!o||o===v.current||(v.current=o,d(""),r&&f(!0),!m&&(e===void 0&&s(!0),n?.(!0)))},[o,r,m,e,n]);let h={open:m,searchEnabled:r,filterValue:c,setFilterValue:d,searchSessionActive:u,setSearchSessionActive:f,setOpen:b,triggerRef:p,openSearchRequest:o};return(0,Sn.jsx)(wm.Provider,{value:h,children:(0,Sn.jsx)(bE,{...i,open:m,onOpenChange:b,children:a})})}var on=(0,it.forwardRef)(function({className:t,children:n,onKeyDown:r,...o},a){let i=(0,it.useContext)(wm),l=i?.triggerRef||null,s=(0,it.useCallback)(d=>{if(l&&(l.current=d),typeof a=="function"){a(d);return}a&&(a.current=d)},[l,a]);function c(d){if(r?.(d),d.defaultPrevented||!i?.searchEnabled||o.disabled)return;let u=Qy(d);u&&(d.preventDefault(),i.setSearchSessionActive?.(!0),i.setOpen(!0),i.setFilterValue(f=>`${f}${u}`))}return(0,Sn.jsxs)(xE,{ref:s,className:F("relative inline-flex h-9 w-full items-center gap-2 rounded-lg border border-input bg-background/80 pl-3 pr-9 text-sm text-foreground shadow-sm outline-none transition focus:border-ring focus:ring-2 focus:ring-ring/40 disabled:cursor-not-allowed disabled:opacity-50",t),onKeyDown:c,...o,children:[(0,Sn.jsx)("span",{className:"min-w-0 flex-1 truncate text-left",children:n}),(0,Sn.jsx)(wE,{className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground",children:"\u25BE"})]})});function an(e){return(0,Sn.jsx)(SE,{...e})}var ln=(0,it.forwardRef)(function({className:t,children:n,position:r="popper",onKeyDownCapture:o,searchPlaceholder:a=ND,emptySearchMessage:i="No matching options.",...l},s){let c=(0,it.useContext)(wm),d=(0,it.useRef)(null),u=(0,it.useRef)(null),f=xm({open:!!c?.open,anchorRef:c?.triggerRef,preferredSide:"bottom",desiredHeight:288,offset:4}),p=DE({searchEnabled:c?.searchEnabled,filterValue:c?.filterValue,sessionActive:c?.searchSessionActive}),v=(0,it.useMemo)(()=>ym(c?.filterValue)?zE(n,c?.filterValue):{children:n,totalItems:0,matchedItems:0},[n,c?.filterValue]),m=ym(c?.filterValue)&&v.totalItems>0&&v.matchedItems===0,b=Math.max(0,Math.floor((f.maxHeight||288)-(p?OD:0)));(0,it.useEffect)(()=>{if(!c?.open||!p||typeof window>"u")return;let x=window.requestAnimationFrame(()=>{let w=u.current;if(!w)return;w.focus();let C=w.value.length;w.setSelectionRange(C,C)});return()=>window.cancelAnimationFrame(x)},[c?.open,p,c?.openSearchRequest]);let h=(0,it.useCallback)(x=>{if(d.current=x,typeof s=="function"){s(x);return}s&&(s.current=x)},[s]);function g(x){if(o?.(x),x.defaultPrevented||x.target===u.current||!c?.searchEnabled)return;let w=Qy(x);w&&(x.preventDefault(),x.stopPropagation(),c.setSearchSessionActive?.(!0),c.setFilterValue(C=>`${C}${w}`))}function y(x){let w=x.target.value;c?.setSearchSessionActive?.(!0),c?.setFilterValue(w)}return(0,Sn.jsx)(AE,{children:(0,Sn.jsxs)(CE,{ref:h,position:r,side:r==="popper"?f.side:void 0,className:F("z-50 min-w-[8rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-lg",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=top]:-translate-y-1",t),onKeyDownCapture:g,...l,children:[p?(0,Sn.jsx)("div",{className:"border-b border-border/70 p-1",children:(0,Sn.jsx)(wt,{ref:u,"data-llm-router-select-search-input":"true",value:c?.filterValue||"",autoComplete:"off",autoCorrect:"off",autoCapitalize:"none",spellCheck:!1,placeholder:a,className:"h-8 border-border/70 bg-background/90",onChange:y,onPointerDown:x=>x.stopPropagation(),onClick:x=>x.stopPropagation(),onKeyDown:x=>{if(x.stopPropagation(),x.key==="ArrowDown"){x.preventDefault(),Zy(d.current,"first");return}if(x.key==="ArrowUp"){x.preventDefault(),Zy(d.current,"last");return}x.key==="Escape"&&(x.preventDefault(),c?.setSearchSessionActive?.(!1),c?.setFilterValue(""),typeof window<"u"&&window.requestAnimationFrame(()=>Zy(d.current)))}})}):null,(0,Sn.jsxs)(RE,{className:"px-1 pb-1",style:{maxHeight:`${b}px`},children:[ym(c?.filterValue)?v.children:n,m?(0,Sn.jsx)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:i}):null]})]})})}),Dt=(0,it.forwardRef)(function({className:t,children:n,searchText:r="",textValue:o,onPointerMove:a,...i},l){let s=(0,it.useContext)(wm),c=String(o||Sm(n)||"").trim();function d(u){if(a?.(u),u.defaultPrevented||!s?.searchEnabled||typeof document>"u")return;let f=document.activeElement;f instanceof HTMLElement&&f.getAttribute(_D)==="true"&&u.preventDefault()}return(0,Sn.jsxs)(ME,{ref:l,className:F("relative flex w-full cursor-default select-none items-center rounded-lg py-2 pl-3 pr-8 text-sm text-foreground outline-none transition-colors hover:bg-accent/60 focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),textValue:c,onPointerMove:d,...i,children:[(0,Sn.jsx)(NE,{children:n}),(0,Sn.jsx)("span",{className:"absolute right-2 inline-flex h-4 w-4 items-center justify-center text-xs text-muted-foreground",children:(0,Sn.jsx)(OE,{children:"\u2713"})})]})});Dt.__LLM_ROUTER_SELECT_ITEM=!0;function ul(e){return(0,Sn.jsx)(EE,{...e})}ul.__LLM_ROUTER_SELECT_GROUP=!0;var Ls=(0,it.forwardRef)(function({className:t,children:n,...r},o){return(0,Sn.jsx)(TE,{ref:o,className:F("-mt-1 sticky top-0 z-10 -mx-1 mb-1 block border-b border-border/55 bg-background/96 px-4 py-2 text-xs font-semibold uppercase tracking-[0.18em] text-foreground/80 backdrop-blur-sm",t),...r,children:n})});var vu=_(Z(),1);function Jy(e={}){let t=[],n=e?.modelAliases&&typeof e.modelAliases=="object"&&!Array.isArray(e.modelAliases)?e.modelAliases:{};for(let o of Object.keys(n))t.push({value:o,label:o,hint:`Alias \xB7 ${(n[o]?.targets||[]).length||0} target(s)`,kind:"alias",groupKey:"aliases",groupLabel:"Aliases"});for(let o of Array.isArray(e?.providers)?e.providers:[]){let a=String(o?.id||"").trim(),i=String(o?.name||a||"provider").trim()||"provider";for(let l of Array.isArray(o?.models)?o.models:[]){let s=String(l?.id||"").trim();if(!a||!s)continue;let c=Number.isFinite(l?.contextWindow)?Number(l.contextWindow):null;t.push({value:`${a}/${s}`,label:`${a}/${s}`,hint:c?`${i} \xB7 ${gi(c)}`:i,kind:"model",providerId:a,groupKey:`provider:${a}`,groupLabel:i})}}let r=new Set;return t.filter(o=>!o?.value||r.has(o.value)?!1:(r.add(o.value),!0))}function LD(e=""){let t=String(e||"").trim();if(!t)return{};let n=Cf(t);if(n?.kind==="alias")return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};if(n?.kind==="model"&&n.providerId)return{kind:"model",providerId:n.providerId,groupKey:`provider:${n.providerId}`,groupLabel:n.providerId};if(n?.kind==="model")return{kind:"model",groupKey:"llm-router",groupLabel:"LLM Router"};let r=t.startsWith("alias:")?t.slice(6).trim():t;if(!r.includes("/"))return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};let o=r.indexOf("/"),a=r.slice(0,o).trim();return a?{kind:"model",providerId:a,groupKey:`provider:${a}`,groupLabel:a}:{}}function xi(e=[],t=[]){let n=[...Array.isArray(e)?e:[]],r=new Set(n.map(o=>String(o?.value||"").trim()).filter(Boolean));for(let o of(Array.isArray(t)?t:[]).map(a=>String(a||"").trim()).filter(Boolean))r.has(o)||(r.add(o),n.push({value:o,label:o,hint:"Current config",...LD(o)}));return n}function DD(e=[]){let t=[],n=new Map,r=null;for(let o of(Array.isArray(e)?e:[]).filter(Boolean)){let a=String(o?.groupKey||o?.groupLabel||"").trim(),i=String(o?.groupLabel||"").trim();if(!a){r||(r={key:"__ungrouped__",label:"",options:[]},t.push(r)),r.options.push(o);continue}let l=n.get(a);l||(l={key:a,label:i||a,options:[]},n.set(a,l),t.push(l)),l.options.push(o)}return t}function ID(e={},{includeHint:t=!1}={}){let n=String(e?.label||e?.value||"").trim()||String(e?.value||"").trim(),r=String(e?.hint||"").trim();return t&&r?`${n} \xB7 ${r}`:n}function BE(e=[],{keyPrefix:t="select-option",includeHint:n=!1}={}){return DD(e).map((r,o)=>{let a=r.options.map(i=>(0,vu.jsx)(Dt,{value:i.value,searchText:`${i.label||""} ${i.value||""} ${i.hint||""} ${r.label||""}`,children:ID(i,{includeHint:n})},`${t}-${i.value}`));return r.label?(0,vu.jsxs)(ul,{children:[(0,vu.jsx)(Ls,{children:r.label}),a]},`${t}-group-${r.key||o}`):a})}var Ds=_(me(),1),PE=_(Ri(),1);var oo=_(me(),1);var zD="flex h-9 w-full rounded-lg border border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40";function BD({committedValue:e="",draftValue:t="",isFocused:n=!1,hasLocalDraft:r=!1,previousCommittedValue:o=""}={}){let a=String(e??""),i=String(t??""),l=String(o??"");return n?{draftValue:i,hasLocalDraft:r,previousCommittedValue:a}:!r||a===i?{draftValue:a,hasLocalDraft:!1,previousCommittedValue:a}:a!==l?{draftValue:a,hasLocalDraft:!1,previousCommittedValue:a}:{draftValue:i,hasLocalDraft:!0,previousCommittedValue:a}}function UD({committedValue:e="",draftValue:t="",isFocused:n=!1,hasLocalDraft:r=!1}={}){return String(n||r?t??"":e??"")}function PD({commitOnBlur:e=!1,draftValue:t="",hasLocalDraft:n=!1}={}){return!e||!n?null:String(t??"")}var Am=(0,oo.forwardRef)(function({className:t,commitOnBlur:n=!1,value:r,onValueCommit:o,onValueChange:a,onChange:i,onFocus:l,onBlur:s,...c},d){let u=String(r??""),[f,p]=(0,oo.useState)(u),[v,m]=(0,oo.useState)(!1),[b,h]=(0,oo.useState)(!1),g=(0,oo.useRef)(u);return(0,oo.useEffect)(()=>{let y=BD({committedValue:u,draftValue:f,isFocused:v,hasLocalDraft:b,previousCommittedValue:g.current});g.current=y.previousCommittedValue,p(y.draftValue),h(y.hasLocalDraft)},[u,f,b,v]),(0,oo.createElement)("input",{...c,ref:d,className:F(zD,t),value:UD({committedValue:u,draftValue:f,isFocused:v,hasLocalDraft:b}),onFocus:y=>{m(!0),l?.(y)},onChange:y=>{let x=y.target.value;p(x),h(!0),a?.(x,y),i?.(y)},onBlur:y=>{m(!1);let x=PD({commitOnBlur:n,draftValue:f,hasLocalDraft:b});x!==null&&o?.(x,y),s?.(y)}})});var jD=/^\d*$/;function UE(e){let t=String(e??""),n=jD.test(t);return{accepted:n,draftValue:n?t:"",shouldCommit:n&&t!=="",commitValue:n&&t!==""?t:""}}var de=_(Z(),1);function VD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:e,children:[(0,de.jsx)("path",{d:"M8 12V4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),(0,de.jsx)("path",{d:"M4.75 7.25 8 4l3.25 3.25",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function HD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:e,children:[(0,de.jsx)("path",{d:"M8 4v8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),(0,de.jsx)("path",{d:"M4.75 8.75 8 12l3.25-3.25",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function FD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,de.jsx)("path",{d:"M2.5 10s3-5.5 7.5-5.5S17.5 10 17.5 10s-3 5.5-7.5 5.5S2.5 10 2.5 10Z"}),(0,de.jsx)("circle",{cx:"10",cy:"10",r:"2.5"})]})}function KD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,de.jsx)("path",{d:"M8.15 4.85A8.5 8.5 0 0 1 10 4.5c4.5 0 7.5 5.5 7.5 5.5a12.4 12.4 0 0 1-1.67 2.28"}),(0,de.jsx)("path",{d:"M5.6 5.6A12.2 12.2 0 0 0 2.5 10s3 5.5 7.5 5.5a8.3 8.3 0 0 0 4.4-1.6"}),(0,de.jsx)("path",{d:"M8.23 8.23a2.5 2.5 0 0 0 3.54 3.54"}),(0,de.jsx)("path",{d:"M3 3l14 14"})]})}function Is({value:e,onChange:t,onValueChange:n,placeholder:r,disabled:o,isEnvVar:a,buffered:i,commitOnBlur:l,onValueCommit:s,className:c,inputProps:d={},maskMode:u="password"}){let[f,p]=(0,Ds.useState)(!1),v=!a&&!f,m=v&&u!=="obscured-text"?"password":"text",b=v&&u==="obscured-text"?{...d?.style&&typeof d.style=="object"?d.style:{},WebkitTextSecurity:"disc"}:d?.style,h=i?{value:e||"",onValueChange:n,onValueCommit:s,commitOnBlur:l,type:m,autoComplete:"off",spellCheck:!1,placeholder:r,disabled:o,className:F("flex h-9 w-full rounded-lg rounded-r-none border border-r-0 border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40",c),style:b,...d}:{value:e||"",onChange:t,type:m,autoComplete:"off",spellCheck:!1,placeholder:r,disabled:o,className:F("flex h-9 w-full rounded-lg rounded-r-none border border-r-0 border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40",c),style:b,...d};return(0,de.jsxs)("div",{className:"flex",children:[i?(0,de.jsx)(Am,{...h}):(0,de.jsx)("input",{...h}),(0,de.jsx)("button",{type:"button",tabIndex:-1,onClick:()=>p(g=>!g),disabled:o,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg rounded-l-none border border-l-0 border-input bg-background/80 text-muted-foreground transition hover:text-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50","aria-label":f?"Hide credential":"Show credential",children:f?(0,de.jsx)(KD,{className:"h-4 w-4"}):(0,de.jsx)(FD,{className:"h-4 w-4"})})]})}function Sa({disabled:e=!1,label:t="Move up",onClick:n}){return(0,de.jsx)($,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 rounded-full p-0",onMouseDown:r=>r.preventDefault(),onClick:n,disabled:e,"aria-label":t,title:t,children:(0,de.jsx)(VD,{className:"h-3.5 w-3.5"})})}function dl({disabled:e=!1,label:t="Move down",onClick:n}){return(0,de.jsx)($,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 rounded-full p-0",onMouseDown:r=>r.preventDefault(),onClick:n,disabled:e,"aria-label":t,title:t,children:(0,de.jsx)(HD,{className:"h-3.5 w-3.5"})})}function ev({active:e=!1}){return e?(0,de.jsx)("span",{"aria-hidden":"true",className:"inline-flex h-2.5 w-2.5 rounded-full bg-emerald-500"}):null}function pt({label:e,hint:t,className:n,children:r,stacked:o=!1,headerClassName:a,hintClassName:i,headerAction:l=null}){return(0,de.jsxs)("div",{className:F("flex flex-col gap-2 text-sm",n),children:[(0,de.jsxs)("div",{className:F("text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",o?"flex min-h-10 items-start justify-between gap-3":"flex items-center justify-between gap-2",a),children:[(0,de.jsxs)("div",{className:F("min-w-0",o?"flex-1 space-y-1":"flex min-w-0 items-center gap-2"),children:[(0,de.jsx)("span",{children:e}),t?(0,de.jsx)("span",{className:F("block normal-case tracking-normal text-[11px] text-muted-foreground/80",o?"leading-4":null,i),children:t}):null]}),l?(0,de.jsx)("div",{className:"shrink-0",children:l}):null]}),r]})}function Cm({value:e,onValueChange:t,disabled:n=!1,allowEmptyCommit:r=!1,...o}){let a=String(e??""),[i,l]=(0,Ds.useState)(a);return(0,Ds.useEffect)(()=>{l(a)},[a]),(0,de.jsx)(wt,{...o,value:i,inputMode:"numeric",disabled:n,onChange:s=>{let c=UE(s.target.value);c.accepted&&(l(c.draftValue),c.shouldCommit?t(c.commitValue):r&&c.draftValue===""&&t(""))},onBlur:()=>{l(s=>s!==""?s:r?(t(""),""):a)}})}function jE({label:e,hint:t,checked:n=!1,onCheckedChange:r,disabled:o=!1,className:a}){return(0,de.jsxs)("div",{className:F("flex items-center justify-between gap-4 rounded-2xl border border-border/70 bg-background/80 px-4 py-3",a),children:[(0,de.jsxs)("div",{className:"min-w-0",children:[(0,de.jsx)("div",{className:"text-sm font-medium text-foreground",children:e}),t?(0,de.jsx)("div",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:t}):null]}),(0,de.jsx)(Pc,{checked:n,onCheckedChange:r,disabled:o,className:"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-60"})]})}function Zn({open:e=!1,title:t="",description:n="",onClose:r=()=>{},children:o,variant:a="dialog",headerActions:i=null,showCloseButton:l=!0,closeDisabled:s=!1,closeOnEscape:c=!0,closeOnBackdrop:d=!0,footer:u=null,contentClassName:f="",bodyClassName:p="",footerClassName:v=""}){if((0,Ds.useEffect)(()=>{if(!e||typeof window>"u")return;function h(g){g.key==="Escape"&&c&&r()}return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[c,e,r]),!e)return null;let m=a==="page",b=(0,de.jsx)("div",{className:F("fixed inset-0 z-50 bg-slate-950/55 backdrop-blur-sm",m?"p-0":"flex items-center justify-center p-4"),onMouseDown:h=>{h.target===h.currentTarget&&d&&r()},children:(0,de.jsxs)("div",{className:F("overflow-hidden border border-border/70 bg-card/95 shadow-2xl",m?"flex h-full w-full flex-col rounded-none border-x-0 border-y-0 bg-background/98":"flex max-h-[85vh] w-full max-w-3xl flex-col rounded-3xl",f),children:[(0,de.jsxs)("div",{className:F("flex items-start justify-between gap-3 border-b border-border/70",m?"px-5 py-4 sm:px-6":"px-5 py-4"),children:[(0,de.jsxs)("div",{className:"min-w-0",children:[(0,de.jsx)("div",{className:"text-base font-semibold text-foreground",children:t}),n?(0,de.jsx)("div",{className:"mt-1 text-sm leading-6 text-muted-foreground",children:n}):null]}),(0,de.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[i,l?(0,de.jsx)($,{type:"button",variant:"ghost",size:"sm",onClick:r,disabled:s,children:"Close"}):null]})]}),(0,de.jsx)("div",{className:F("overflow-y-auto",m?"min-h-0 flex-1 px-5 py-4 sm:px-6 sm:py-5":"min-h-0 flex-1 px-5 py-4",p),children:o}),u?(0,de.jsx)("div",{className:F("border-t border-border/70 bg-background/96",m?"px-5 py-4 sm:px-6":"px-5 py-4",v),children:u}):null]})});return typeof document>"u"||!document.body?b:(0,PE.createPortal)(b,document.body)}function Rm({open:e=!1,anchorRef:t,preferredSide:n="bottom",desiredHeight:r=288,offset:o=4,className:a="",children:i,...l}){let s=xm({open:e,anchorRef:t,preferredSide:n,desiredHeight:r,offset:o});return e?(0,de.jsx)("div",{className:F("absolute left-0 right-0 z-30 overflow-y-auto rounded-xl border border-border/70 bg-popover shadow-lg",s.side==="top"?"bottom-full mb-1":"top-full mt-1",a),style:{maxHeight:`${Math.max(0,Math.floor(s.maxHeight||r))}px`},...l,children:i}):null}function VE({open:e=!1,onKeepEditing:t=()=>{},onDiscardAndClose:n=()=>{},onSaveAndClose:r=()=>{},saveDisabled:o=!1,dirtyLabels:a=[],details:i=""}){let l=a.length>1?`${a.slice(0,-1).join(", ")} and ${a[a.length-1]}`:a[0]||"this form";return(0,de.jsx)(Zn,{open:e,onClose:t,title:"Unsaved changes",description:`You have unsaved edits in ${l}.`,contentClassName:"max-w-lg rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",showCloseButton:!1,footer:(0,de.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,de.jsx)($,{type:"button",variant:"ghost",onClick:t,children:"Keep editing"}),(0,de.jsx)($,{type:"button",variant:"outline",onClick:n,children:"Cancel + Close"}),(0,de.jsx)($,{type:"button",onClick:()=>{r()},disabled:o,children:"Save + Close"})]}),children:(0,de.jsxs)("div",{className:"space-y-3 text-sm leading-6 text-muted-foreground",children:[(0,de.jsx)("div",{children:"Choose whether to save these edits before closing the modal."}),i?(0,de.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-amber-900",children:i}):null]})})}function HE({open:e=!1,failedModelIds:t=[],onKeepEditing:n=()=>{},onRemoveFailedAndClose:r=()=>{},removeDisabled:o=!1}){let a=t.length>1?`${t.length} failed models`:t[0]||"the failed model";return(0,de.jsx)(Zn,{open:e,onClose:n,title:"Failed model tests",description:`Some new models did not pass validation: ${a}.`,contentClassName:"max-w-lg rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",showCloseButton:!1,footer:(0,de.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,de.jsx)($,{type:"button",variant:"ghost",onClick:n,children:"Keep editing"}),(0,de.jsx)($,{type:"button",variant:"outline",onClick:()=>{r()},disabled:o,children:"Remove failed + close"})]}),children:(0,de.jsxs)("div",{className:"space-y-3 text-sm leading-6 text-muted-foreground",children:[(0,de.jsx)("div",{children:"Successful new models are still kept in the draft. You can continue editing, or remove only the failed rows and close the modal."}),t.length>0?(0,de.jsx)("div",{className:"rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-rose-900",children:t.join(", ")}):null]})})}function Dr(){return(0,de.jsx)("span",{className:"mr-2 inline-flex h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-r-transparent align-[-0.125em]"})}function FE({children:e,onClick:t,disabled:n=!1,title:r="",className:o=""}){return(0,de.jsx)("button",{type:"button",className:F("inline-flex items-center rounded-full border border-border bg-background/70 px-2.5 py-1 text-[11px] font-medium tracking-wide text-muted-foreground transition hover:border-primary/35 hover:bg-primary/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",o),onClick:t,disabled:n,title:r,"aria-label":r||void 0,children:e})}var Me=_(Z(),1);function $D({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("circle",{cx:"6.75",cy:"10",r:"3.25"}),(0,Me.jsx)("path",{d:"M10 10h6.5"}),(0,Me.jsx)("path",{d:"M13.5 10v2.25"}),(0,Me.jsx)("path",{d:"M15.75 10v1.5"})]})}function GD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M16.25 10a6.25 6.25 0 1 1-1.83-4.42"}),(0,Me.jsx)("path",{d:"M13.5 3.75h3v3"}),(0,Me.jsx)("path",{d:"M16.5 3.75 12.75 7.5"})]})}function qD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M7.25 5.75h-1.5A2.75 2.75 0 0 0 3 8.5v5.75A2.75 2.75 0 0 0 5.75 17h5.75a2.75 2.75 0 0 0 2.75-2.75v-1.5"}),(0,Me.jsx)("path",{d:"M10.5 9.5 17 3"}),(0,Me.jsx)("path",{d:"M12 3h5v5"})]})}function WD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M6 3.5h5.25L15 7.25V16A1.5 1.5 0 0 1 13.5 17.5h-7A1.5 1.5 0 0 1 5 16V5A1.5 1.5 0 0 1 6.5 3.5H6Z"}),(0,Me.jsx)("path",{d:"M11 3.5V7.5H15"})]})}function YD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M6 3.5h5.25L15 7.25V16A1.5 1.5 0 0 1 13.5 17.5h-7A1.5 1.5 0 0 1 5 16V5A1.5 1.5 0 0 1 6.5 3.5H6Z"}),(0,Me.jsx)("path",{d:"M11 3.5V7.5H15"}),(0,Me.jsx)("path",{d:"M7 12.25a3 3 0 1 1 2.85 2.99"}),(0,Me.jsx)("path",{d:"M8.5 10.25h1.5v1.5"})]})}function QD({label:e,value:t,icon:n,disabled:r=!1,onClick:o,actionLabel:a}){return(0,Me.jsxs)("button",{type:"button",className:"inline-flex h-9 min-w-0 max-w-full items-center gap-2 rounded-full border border-border/70 bg-background/90 px-3 text-left transition hover:border-accent hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70 sm:max-w-[18rem]",onClick:o,disabled:r,"aria-label":a,title:r?a:t,children:[(0,Me.jsx)("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-secondary text-muted-foreground",children:n}),(0,Me.jsx)("span",{className:"shrink-0 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:e}),(0,Me.jsx)("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:t})]})}function XD({value:e,pending:t=!1,disabled:n=!1,rotateDisabled:r=!1,onCopy:o,onRotate:a}){return(0,Me.jsxs)("div",{className:"flex h-9 min-w-0 max-w-full items-stretch overflow-hidden rounded-full border border-border/70 bg-background/90 sm:max-w-[18rem]",children:[(0,Me.jsxs)("button",{type:"button",className:"inline-flex min-w-0 flex-1 items-center gap-2 rounded-l-full px-3 text-left transition hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70",onClick:o,disabled:n,"aria-label":t?"Gateway key is still generating":"Copy gateway key",title:t?"Gateway key is still generating":"Copy gateway key",children:[(0,Me.jsx)("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-secondary text-muted-foreground",children:(0,Me.jsx)($D,{className:"h-3.5 w-3.5"})}),(0,Me.jsx)("span",{className:"shrink-0 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"Gateway key"}),(0,Me.jsx)("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e})]}),(0,Me.jsx)("button",{type:"button",className:"inline-flex w-9 shrink-0 items-center justify-center rounded-r-full border-l border-border/70 text-muted-foreground transition hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-70",onClick:a,disabled:r,"aria-label":"Rotate gateway key",title:"Rotate gateway key",children:(0,Me.jsx)(GD,{className:"h-3.5 w-3.5"})})]})}function $E({endpointValue:e,endpointDisabled:t=!1,gatewayValue:n,gatewayPending:r=!1,gatewayDisabled:o=!1,rotateDisabled:a=!1,onCopyEndpoint:i,onCopyGatewayKey:l,onRotateKey:s}){return(0,Me.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,Me.jsx)(QD,{label:"Endpoint",value:e,icon:(0,Me.jsx)(qD,{className:"h-3.5 w-3.5"}),disabled:t,onClick:i,actionLabel:t?"API endpoint not ready yet":"Copy API endpoint"}),(0,Me.jsx)(XD,{value:n,pending:r,disabled:o,rotateDisabled:a,onCopy:l,onRotate:s})]})}function KE({label:e,value:t,icon:n,disabled:r=!1,onClick:o,actionLabel:a="",emptyLabel:i="Not resolved"}){let l=String(t||"").trim()||i;return(0,Me.jsxs)("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-start gap-2 rounded-2xl border border-border/70 bg-background/90 px-3 py-2 text-left transition hover:border-accent hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70",onClick:o,disabled:r,"aria-label":a,title:r?a:l,children:[(0,Me.jsx)("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-secondary text-muted-foreground",children:n}),(0,Me.jsxs)("span",{className:"min-w-0",children:[(0,Me.jsx)("span",{className:"block text-[9px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:e}),(0,Me.jsx)("span",{className:"mt-1 block break-all text-[11px] font-medium leading-4 text-foreground",children:l})]})]})}function fl({connected:e=!1,className:t,srLabel:n="Connected",size:r="sm"}){if(!e)return null;let o=r==="md"?"h-3.5 w-3.5":"h-2.5 w-2.5",a=r==="md"?"h-2 w-2":"h-1.5 w-1.5";return(0,Me.jsxs)("span",{className:F("relative inline-flex shrink-0 items-center justify-center",o,t),children:[(0,Me.jsx)("span",{"aria-hidden":"true",className:"absolute inset-0 rounded-full bg-emerald-400/45 animate-ping motion-reduce:animate-none"}),(0,Me.jsx)("span",{"aria-hidden":"true",className:F("relative rounded-full bg-emerald-500 ring-2 ring-emerald-500/15",a)}),(0,Me.jsx)("span",{className:"sr-only",children:n})]})}function Em({primaryLabel:e="Config file",primaryValue:t="",primaryIcon:n=(0,Me.jsx)(WD,{className:"h-3 w-3"}),onOpenPrimary:r,secondaryLabel:o="Backup file",secondaryValue:a="",secondaryIcon:i=(0,Me.jsx)(YD,{className:"h-3 w-3"}),onOpenSecondary:l}){let s=String(t||"").trim(),c=String(a||"").trim();return(0,Me.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,Me.jsx)(KE,{label:e,value:s,icon:n,disabled:!s||typeof r!="function",onClick:r,actionLabel:s?`Open ${e.toLowerCase()}`:`${e} path is not resolved yet`}),(0,Me.jsx)(KE,{label:o,value:c,icon:i,disabled:!c||typeof l!="function",onClick:l,actionLabel:c?`Open ${o.toLowerCase()}`:`${o} path is not resolved yet`})]})}var Fo=_(me(),1);var Jt=_(Z(),1);function ZD(e){return e==="error"?"Error":e==="success"?"Success":"Notice"}function JD({notice:e,onDismiss:t}){let[n,r]=(0,Fo.useState)(Rf),[o,a]=(0,Fo.useState)(Rf),[i,l]=(0,Fo.useState)(!1),s=(0,Fo.useRef)(null),c=(0,Fo.useRef)(0);(0,Fo.useEffect)(()=>{if(n<=0){t();return}if(i){s.current&&(clearTimeout(s.current),s.current=null);return}return c.current=Date.now(),s.current=setTimeout(()=>{s.current=null,t()},n),()=>{s.current&&(clearTimeout(s.current),s.current=null)}},[t,i,n]),(0,Fo.useEffect)(()=>{if(i||n<=0){a(n);return}let g=()=>{let x=c.current?Date.now()-c.current:0;a(Math.max(0,n-x))};g();let y=setInterval(g,zA);return()=>clearInterval(y)},[i,n]);function d(){if(i)return;s.current&&(clearTimeout(s.current),s.current=null);let g=c.current?Date.now()-c.current:0,y=Math.max(0,n-g);r(y),a(y),l(!0)}function u(){l(!1)}let f=e.tone==="error"?"border-rose-200 bg-rose-50 text-rose-800":e.tone==="success"?"border-emerald-200 bg-emerald-50 text-emerald-800":"border-amber-200 bg-amber-50 text-amber-800",p=9,v=2*Math.PI*p,m=Math.max(0,Math.min(1,o/Rf)),b=v*(1-m),h=i?`Auto-dismiss paused with ${Math.max(0,o/1e3).toFixed(1)} seconds remaining`:`Auto-dismiss in ${Math.max(0,o/1e3).toFixed(1)} seconds`;return(0,Jt.jsx)("div",{className:F("pointer-events-auto rounded-2xl border px-4 py-3 text-sm shadow-lg backdrop-blur",f),onMouseEnter:d,onMouseLeave:u,onFocusCapture:d,onBlurCapture:g=>{g.currentTarget.contains(g.relatedTarget)||u()},role:e.tone==="error"?"alert":"status",children:(0,Jt.jsxs)("div",{className:"min-w-0",children:[(0,Jt.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,Jt.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-[0.16em] opacity-75",children:ZD(e.tone)}),(0,Jt.jsxs)("div",{className:"relative mt-0.5 h-6 w-6 shrink-0 opacity-85","aria-label":h,title:h,children:[(0,Jt.jsxs)("svg",{viewBox:"0 0 24 24",className:F("h-6 w-6 -rotate-90",i?"opacity-70":"opacity-100"),"aria-hidden":"true",children:[(0,Jt.jsx)("circle",{cx:"12",cy:"12",r:p,fill:"none",stroke:"currentColor",strokeOpacity:"0.18",strokeWidth:"2"}),(0,Jt.jsx)("circle",{cx:"12",cy:"12",r:p,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeDasharray:v,strokeDashoffset:b,className:"transition-[stroke-dashoffset,opacity] duration-100 ease-linear"})]}),(0,Jt.jsx)("span",{className:F("pointer-events-none absolute inset-0 flex items-center justify-center",i?"gap-[2px]":""),"aria-hidden":"true",children:i?(0,Jt.jsxs)(Jt.Fragment,{children:[(0,Jt.jsx)("span",{className:"h-2.5 w-[2px] rounded-full bg-current/75"}),(0,Jt.jsx)("span",{className:"h-2.5 w-[2px] rounded-full bg-current/75"})]}):(0,Jt.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-current/75"})})]})]}),(0,Jt.jsx)("div",{className:"mt-1 leading-6",children:e.message}),(0,Jt.jsx)("div",{className:"mt-2 flex justify-end",children:(0,Jt.jsx)("button",{className:"rounded-full border border-current/15 px-2.5 py-1 text-[11px] font-medium uppercase tracking-[0.16em] opacity-85 transition hover:border-current/30 hover:opacity-100",onClick:t,type:"button",children:"Dismiss"})})]})})}function tv({notices:e,onDismiss:t}){return!Array.isArray(e)||e.length===0?null:(0,Jt.jsx)("div",{className:"pointer-events-none fixed inset-x-4 top-4 z-50 flex flex-col items-end gap-3","aria-live":"polite","aria-relevant":"additions text",children:e.map(n=>(0,Jt.jsx)("div",{className:"w-full max-w-md",children:(0,Jt.jsx)(JD,{notice:n,onDismiss:()=>t(n.id)})},n.id))})}var Aa=_(me(),1);var Tn=_(me(),1);var $n=_(me(),1);var wa=_(me(),1);function zs(e=[]){let t=(0,wa.useRef)(new Map),n=(0,wa.useRef)(new Map),r=(0,wa.useRef)(new Map),o=(0,wa.useRef)(""),a=JSON.stringify(e);return(0,wa.useLayoutEffect)(()=>{let i=new Map;for(let d of e){let u=t.current.get(d);u&&i.set(d,u.getBoundingClientRect())}let l=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(o.current!==""&&o.current!==a&&!l)for(let d of e){let u=r.current.get(d),f=i.get(d),p=t.current.get(d);if(!u||!f||!p)continue;let v=u.top-f.top;Math.abs(v)<1||typeof p.animate!="function"||p.animate([{transform:`translateY(${v}px)`},{transform:"translateY(0)"}],{duration:220,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})}let c=new Set(e);for(let d of n.current.keys())c.has(d)||n.current.delete(d);r.current=i,o.current=a},[a]),(0,wa.useMemo)(()=>i=>(n.current.has(i)||n.current.set(i,l=>{if(l){t.current.set(i,l);return}t.current.delete(i)}),n.current.get(i)),[])}var yt=_(Z(),1);function nv({title:e,rows:t,onChange:n,options:r,disabled:o=!1,addLabel:a="Add target",emptyLabel:i="No targets configured.",helperText:l="Drag rows or use the arrow to change routing order.",helperAction:s=null,placeholder:c="provider/model or alias",draftPlaceholder:d="Add a new route",showDraftRow:u=!1,showDraftFocusButton:f=!1,showWeightInput:p=!1,filterOtherSelectedValues:v=!1,excludedValues:m=[]}){let b=(0,$n.useRef)(0),h=(0,$n.useRef)(""),g=(0,$n.useRef)(null),y=(0,$n.useRef)(new Map),x=(0,$n.useRef)(0),w=(0,$n.useRef)(0),[C,E]=(0,$n.useState)(0),A=(0,$n.useMemo)(()=>String(e||"targets").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"targets",[e]),M=`${A}-draft-row`,L=(0,$n.useMemo)(()=>{let X=(t||[]).filter(je=>String(je?.ref||"").trim());return u?[{key:M,ref:"",sourceRef:""},...X]:X},[t,u,M]),P=zs(L.map(X=>X.key)),D=(0,$n.useMemo)(()=>pr(m),[m]),G=(0,$n.useMemo)(()=>xi(r,[...L.map(X=>X?.ref),...D]),[r,L,D]);(0,$n.useEffect)(()=>()=>{typeof window<"u"&&x.current&&window.cancelAnimationFrame(x.current)},[]);function ae(X,je){if(u&&X===M){if(!String(je||"").trim())return;b.current+=1,n([{key:`${A}-draft-${b.current}`,ref:je,sourceRef:"",...p?{weight:"1"}:{}},...(t||[]).filter(ie=>String(ie?.ref||"").trim())]);return}n((t||[]).map(ie=>ie.key===X?{...ie,ref:je}:ie))}function ge(X,je){n((t||[]).map(ie=>ie.key===X?{...ie,weight:je}:ie))}function j(X){n((t||[]).filter(je=>je.key!==X))}function J(X){n(xs(t||[],X,je=>je?.key))}function Q(X){n(kf(t||[],X,je=>je?.key))}function H(){h.current="",va(g.current,!1),g.current=null}function B(){b.current+=1;let X=new Set([...(t||[]).map(ie=>String(ie?.ref||"").trim()).filter(Boolean),...D]),je=G.find(ie=>!X.has(ie.value))?.value||"";n([...t||[],{key:`${A}-draft-${b.current}`,ref:je,sourceRef:""}])}function ft(){if(!u||o)return;let X=y.current.get(M);if(!X||typeof window>"u"){E(Fe=>Fe+1);return}w.current+=1;let je=w.current;x.current&&(window.cancelAnimationFrame(x.current),x.current=0),X.scrollIntoView({block:"start",behavior:"smooth"});let ie=bm(X),xe=qh(X,ie),Ie=0,I=0,ue=90,he=8,_e=6,Ee=.5,ve=()=>{if(w.current!==je)return;let Fe=y.current.get(M)||X,Je=qh(Fe,ie);if(!Number.isFinite(Je.top)||!Number.isFinite(Je.left)){x.current=0,E(Ht=>Ht+1);return}if(nC(xe,Je,Ee)?Ie+=1:Ie=0,xe=Je,I+=1,I>=he&&Ie>=_e||I>=ue){x.current=0,E(Ht=>Ht+1);return}x.current=window.requestAnimationFrame(ve)};x.current=window.requestAnimationFrame(ve)}return(0,yt.jsxs)("div",{className:"space-y-2 rounded-2xl border border-border/70 bg-background/55 p-4",children:[(0,yt.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,yt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,yt.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:e}),f&&u?(0,yt.jsx)($,{type:"button",variant:"ghost",size:"sm",className:"h-6 w-6 rounded-md p-0 text-muted-foreground hover:text-foreground",onMouseDown:X=>X.preventDefault(),onClick:ft,disabled:o,"aria-label":a,title:a,children:(0,yt.jsx)(KA,{className:"h-3.5 w-3.5"})}):null]}),(0,yt.jsxs)("div",{className:"ml-auto flex max-w-full flex-wrap items-start justify-end gap-x-3 gap-y-2",children:[l?(0,yt.jsx)("div",{className:"max-w-[34rem] text-right text-[11px] leading-4 text-muted-foreground",children:l}):null,u?null:(0,yt.jsx)($,{type:"button",variant:"ghost",onClick:B,disabled:o,children:a})]})]}),L.length>0?(0,yt.jsx)("div",{className:"space-y-2",children:L.map((X,je)=>{let ie=u&&X.key===M,xe=ie?-1:(t||[]).findIndex(I=>I?.key===X.key),Ie=v?G.filter(I=>{let ue=String(I?.value||"").trim();return ue?ue===String(X?.ref||"").trim()?!0:D.includes(ue)?!1:!(L||[]).some(he=>he?.key!==X.key&&String(he?.ref||"").trim()===ue):!1}):G;return(0,yt.jsxs)("div",{ref:I=>{if(P(X.key)(I),I){y.current.set(X.key,I);return}y.current.delete(X.key)},"data-reorder-row":"true",onDragOver:I=>{!o&&h.current&&h.current!==X.key&&(I.preventDefault(),I.dataTransfer.dropEffect="move")},onDrop:I=>{if(o)return;I.preventDefault();let ue=I.dataTransfer.getData("text/plain")||h.current;H(),n(_f(t||[],ue,X.key))},className:F(p?"grid grid-cols-[auto_auto_auto_minmax(0,1fr)_10rem_5.5rem] items-center gap-2 rounded-xl border border-border/70 bg-card/90 p-3":"grid grid-cols-[auto_auto_auto_minmax(0,1fr)_5.5rem] items-center gap-2 rounded-xl border border-border/70 bg-card/90 p-3",ie?"border-dashed bg-background/85":null),children:[(0,yt.jsx)("span",{className:F("flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground",ie||o?"opacity-45":"cursor-grab"),draggable:!o&&!ie,onDragStart:I=>{if(o||ie)return;let ue=Ss(I.currentTarget);I.dataTransfer.effectAllowed="move",I.dataTransfer.setData("text/plain",X.key),ue&&typeof I.dataTransfer?.setDragImage=="function"&&I.dataTransfer.setDragImage(ue,20,20),H(),h.current=X.key,g.current=ue,va(ue,!0)},onDragEnd:H,title:ie?"New route draft row":"Drag to reorder",children:(0,yt.jsx)(vs,{className:"h-4 w-4"})}),(0,yt.jsx)(Sa,{disabled:o||ie||xe<=0,label:ie||xe<=0?"Already first":`Move ${X.ref||`target ${xe+1}`} up`,onClick:()=>J(X.key)}),(0,yt.jsx)(dl,{disabled:o||ie||xe===-1||xe>=(t||[]).length-1,label:ie||xe===-1||xe>=(t||[]).length-1?"Already last":`Move ${X.ref||`target ${xe+1}`} down`,onClick:()=>Q(X.key)}),(0,yt.jsxs)("div",{className:"flex h-9 min-w-0 overflow-hidden rounded-lg border border-input bg-background/80 shadow-sm transition focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/40",children:[(0,yt.jsx)("div",{className:"flex shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Model"}),(0,yt.jsxs)(rn,{value:X.ref||void 0,onValueChange:I=>ae(X.key,I),disabled:o,openSearchRequest:ie?C:0,children:[(0,yt.jsx)(on,{className:"h-full min-w-0 flex-1 rounded-none border-0 bg-transparent px-3 shadow-none focus:border-transparent focus:ring-0",children:(0,yt.jsx)(an,{placeholder:ie?d:c})}),(0,yt.jsx)(ln,{children:Ie.length>0?BE(Ie,{keyPrefix:`${e}-row-${X.key}`}):(0,yt.jsx)(Dt,{value:"__no-route-options",disabled:!0,children:"No routes available"})})]})]}),p?(0,yt.jsxs)("div",{className:F("flex h-9 overflow-hidden rounded-lg border border-input bg-background/80 shadow-sm transition focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/40",ie?"opacity-45":null),children:[(0,yt.jsx)("div",{className:"flex shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Weight"}),(0,yt.jsx)(wt,{value:ie?"":String(X?.weight||"1"),onChange:I=>ge(X.key,I.target.value),inputMode:"numeric",placeholder:"1",disabled:o||ie,className:"h-full min-w-0 rounded-none border-0 bg-transparent px-3 text-center shadow-none focus:border-transparent focus:ring-0","aria-label":ie?"Weight for new target":`Weight for ${X.ref||`target ${je+1}`}`})]}):null,ie?(0,yt.jsx)($,{type:"button",variant:"ghost",className:F(ys,"pointer-events-none invisible"),tabIndex:-1,disabled:!0,"aria-hidden":"true",children:"Remove"}):(0,yt.jsx)($,{type:"button",variant:"ghost",className:ys,onMouseDown:I=>I.preventDefault(),onClick:()=>j(X.key),disabled:o,children:"Remove"})]},X.key)})}):(0,yt.jsx)("div",{className:"rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:i}),s?(0,yt.jsx)("div",{className:"flex min-h-8 items-center justify-end",children:s}):null]})}var ml=_(me(),1);var te=_(Z(),1);function e5(e,t){let n=Math.abs(Number(e)||0),r=Math.abs(Number(t)||0);for(;r!==0;){let o=n%r;n=r,r=o}return n||1}function t5(e=[]){return!Array.isArray(e)||e.length===0?1:e.reduce((t,n)=>e5(t,n),0)||1}function n5(e,t){let n=String(e||"").trim();if(!n)return"Unconfigured route";let r=t.get(n);if(!r)return n;let o=String(r.label||n).trim()||n,a=String(r.hint||"").trim();return a&&a!==o?`${o} \xB7 ${a}`:o}function GE(e,t,n=[]){let r=new Map((n||[]).map(l=>[String(l?.value||"").trim(),l]).filter(([l])=>!!l)),o=new Map((Array.isArray(t?.targets)?t.targets:[]).map(l=>[String(l?.ref||"").trim(),l]).filter(([l])=>!!l)),a=new Map((Array.isArray(t?.fallbackTargets)?t.fallbackTargets:[]).map(l=>[String(l?.ref||"").trim(),l]).filter(([l])=>!!l));function i(l,s,c){return(l||[]).map((d,u)=>{let f=String(d?.ref||"").trim(),p=String(d?.sourceRef||d?.ref||"").trim(),v=c.get(p)||c.get(f)||{},m=Number(d?.weight??v?.weight),b=Number.isFinite(m)&&m>0?Math.floor(m):1;return{key:`${s}-${f||"empty"}-${u}`,ref:f,label:n5(f,r),bucket:s,weight:b}}).filter(d=>!!d.ref)}return[...i(e?.targets,"primary",o),...i(e?.fallbackTargets,"fallback",a)]}function r5(e=[],t=8){if(!Array.isArray(e)||e.length===0)return[];let n=e.map(l=>Math.max(1,Number(l?.weight)||1)),r=t5(n),o=n.map(l=>Math.max(1,Math.floor(l/r))),a=o.reduce((l,s)=>l+s,0);if(a>24){let l=a/24;o=o.map(s=>Math.max(1,Math.round(s/l))),a=o.reduce((s,c)=>s+c,0)}let i=[];for(let l=0;l<e.length;l+=1)for(let s=0;s<o[l];s+=1)i.push(e[l]);return Array.from({length:Math.max(e.length,t)},(l,s)=>i[s%i.length])}function o5(e,t=[]){let n=Lf(e),r=Df(n),o=Array.isArray(t)?t.filter(Boolean):[],i=o.some(l=>l.bucket==="fallback")?"Runtime builds the candidate pool as all primary targets first, then all fallback targets.":"Runtime builds the candidate pool from the primary target list only.";if(n==="round-robin"){let l=o.length>0?Array.from({length:Math.max(o.length,8)},(s,c)=>o[c%o.length]):[];return{strategyLabel:r,summary:"Each new request starts from the next candidate in the current pool, then wraps around.",poolNote:`${i} Round-robin rotates across that combined eligible list.`,sequenceLabel:"Example starting candidate by request",sequenceEntries:l,footnote:"If a candidate is unhealthy or quota-blocked, it is skipped and the next eligible candidate is chosen."}}if(n==="weighted-rr"||n==="quota-aware-weighted-rr"||n==="auto"){let l=n==="auto",s=r5(o,8);return{strategyLabel:r,summary:l?"`auto` normalizes to quota-aware weighted round-robin in the runtime balancer.":n==="quota-aware-weighted-rr"?"Candidates rotate like weighted round-robin, but low remaining quota or poor health lowers their share.":"Candidates repeat in proportion to their configured weights.",poolNote:`${i} This strategy ranks across the full eligible pool after it is built.`,sequenceLabel:"Example starting candidate by request",sequenceEntries:s,footnote:l||n==="quota-aware-weighted-rr"?"When all quotas and health scores are equal, the rotation looks like the weighted example below. Low remaining capacity or retryable failures push a target later.":"Weights come from the existing alias target metadata when present. Targets without a stored weight behave as weight 1."}}return{strategyLabel:r,summary:"Requests try candidates in the configured list order and only move to later candidates when earlier ones are unavailable or fail.",poolNote:`${i} Ordered keeps that exact sequence.`,sequenceLabel:"Attempt order",sequenceEntries:o,footnote:"This is the most predictable option when you want a strict preference order."}}function qE({open:e=!1,onClose:t=()=>{},onSave:n=()=>{},aliasLabel:r="",initialStrategy:o="auto",entries:a=[],disabled:i=!1}){let l=Lf(o),[s,c]=(0,ml.useState)(l),[d,u]=(0,ml.useState)(!1);(0,ml.useEffect)(()=>{e&&(c(l),u(!1))},[e,l,r]);async function f(){if(!(i||d)){u(!0);try{await n(s)!==!1&&t()}finally{u(!1)}}}return(0,te.jsx)(Zn,{open:e,onClose:t,title:r?`Choose strategy \xB7 ${r}`:"Choose strategy",description:"Review each routing strategy in its own tab. Save applies the currently selected tab to this alias.",showCloseButton:!1,footer:(0,te.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,te.jsx)($,{type:"button",variant:"ghost",onClick:t,disabled:d,children:"Cancel"}),(0,te.jsx)($,{type:"button",onClick:()=>{f()},disabled:i||d,children:d?"Saving\u2026":"Save strategy"})]}),children:(0,te.jsxs)(fs,{value:s,onValueChange:c,children:[(0,te.jsx)("div",{className:"overflow-x-auto pb-1",children:(0,te.jsx)(ms,{className:"h-auto min-w-max flex-wrap justify-start gap-2 rounded-2xl bg-secondary/80 p-2",children:Ef.map(p=>(0,te.jsx)(dr,{value:p.value,className:"h-auto min-h-10 rounded-xl px-4 py-2",children:p.label},p.value))})}),Ef.map(p=>{let v=o5(p.value,a),m=(v.sequenceEntries||[]).filter(Boolean);return(0,te.jsx)(fr,{value:p.value,className:"mt-4",children:(0,te.jsxs)("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)]",children:[(0,te.jsxs)("div",{className:"space-y-4",children:[(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-5",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)(ut,{variant:"outline",children:v.strategyLabel}),(0,te.jsxs)(ut,{variant:"info",children:[a.length," candidate",a.length===1?"":"s"]})]}),(0,te.jsxs)("div",{className:"mt-4 space-y-3 text-sm leading-6 text-foreground",children:[(0,te.jsx)("p",{children:v.summary}),(0,te.jsx)("p",{className:"text-muted-foreground",children:v.poolNote})]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-5",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:v.sequenceLabel}),m.length>0?(0,te.jsx)("div",{className:"mt-4 flex flex-wrap gap-2",children:m.map((b,h)=>(0,te.jsxs)("div",{className:"rounded-full border border-border/70 bg-card/90 px-3 py-1.5 text-sm text-foreground",children:[(0,te.jsx)("span",{className:"mr-2 text-xs text-muted-foreground",children:h+1}),(0,te.jsx)("span",{children:b.label})]},`${b.key}-sequence-${h}`))}):(0,te.jsx)("div",{className:"mt-4 rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:"Add at least one target to preview how this strategy would route requests."}),(0,te.jsx)("div",{className:"mt-4 text-sm leading-6 text-muted-foreground",children:v.footnote})]})]}),(0,te.jsx)("div",{className:"space-y-4",children:(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-5",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Current setup"}),r?(0,te.jsx)(ut,{variant:"outline",children:r}):null]}),a.length>0?(0,te.jsx)("div",{className:"mt-4 space-y-2",children:a.map(b=>(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2 rounded-xl border border-border/70 bg-card/90 px-3 py-2 text-sm",children:[(0,te.jsx)(ut,{variant:b.bucket==="primary"?"info":"outline",children:b.bucket}),(0,te.jsx)("span",{className:"font-medium text-foreground",children:b.label}),(0,te.jsxs)("span",{className:"text-xs text-muted-foreground",children:["weight ",b.weight]})]},b.key))}):(0,te.jsx)("div",{className:"mt-4 rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:"This alias does not have any targets yet."})]})})]})},p.value)})]})})}function WE({open:e=!1,onClose:t=()=>{},config:n={}}){let r=(0,ml.useMemo)(()=>FC(n),[n]);return(0,te.jsx)(Zn,{open:e,onClose:t,title:"Alias guide",description:"Aliases give clients one stable route while letting LLM Router swap, balance, and fail over across provider/model targets behind that route.",contentClassName:"max-h-[92vh] max-w-4xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)]",children:(0,te.jsxs)("div",{className:"space-y-4",children:[(0,te.jsxs)("div",{className:"grid gap-4 md:grid-cols-3",children:[(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Stable route"}),(0,te.jsxs)("div",{className:"mt-2 text-sm leading-6 text-foreground",children:["Expose one alias like ",(0,te.jsx)("code",{children:"coding"})," or ",(0,te.jsx)("code",{children:"gpt-5.4"})," to clients, then retarget the alias later without touching client config."]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Selection strategy"}),(0,te.jsx)("div",{className:"mt-2 text-sm leading-6 text-foreground",children:"The alias strategy controls how LLM Router picks from the configured targets. Ordered is strict preference; the other strategies distribute traffic when multiple targets are healthy."})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Fallback behavior"}),(0,te.jsx)("div",{className:"mt-2 text-sm leading-6 text-foreground",children:"If one target is unavailable or rate limited, LLM Router can continue to later candidates in the same alias instead of failing the whole request immediately."})]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-4",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)(ut,{variant:"warning",children:"Important"}),(0,te.jsx)("div",{className:"text-sm font-medium text-amber-950",children:"Mixed context windows inside one alias can change behavior."})]}),(0,te.jsxs)("div",{className:"mt-3 text-sm leading-6 text-amber-900",children:["If an alias mixes models with different context windows, requests that fit the larger model may still fail on the smaller model. For example, an alias that includes both a ",(0,te.jsx)("code",{children:"258K"})," model and a ",(0,te.jsx)("code",{children:"128K"})," model can still fail when routing lands on the smaller target. Keep aliases aligned by context size when you expect long histories or large prompts."]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Current config check"}),(0,te.jsx)("div",{className:"mt-1 text-sm text-muted-foreground",children:"Aliases below currently mix different configured model context windows."})]}),(0,te.jsx)(ut,{variant:r.length>0?"warning":"success",children:r.length>0?`${r.length} alias${r.length===1?"":"es"} need review`:"No mixed context windows detected"})]}),r.length>0?(0,te.jsx)("div",{className:"mt-4 space-y-3",children:r.map(o=>(0,te.jsxs)("div",{className:"rounded-2xl border border-amber-200 bg-amber-50/70 p-4",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)(ut,{variant:"outline",children:o.aliasId}),(0,te.jsxs)("div",{className:"text-sm font-medium text-amber-950",children:["Smallest target: ",gi(o.smallestContextWindow),". Largest target: ",gi(o.largestContextWindow),"."]})]}),(0,te.jsxs)("div",{className:"mt-3 flex flex-wrap gap-2",children:[o.models.map(a=>(0,te.jsxs)("div",{className:"rounded-full border border-amber-200 bg-background/90 px-3 py-1.5 text-sm text-foreground",children:[a.ref," \xB7 ",gi(a.contextWindow)]},a.ref)),o.unknownRefs.map(a=>(0,te.jsxs)("div",{className:"rounded-full border border-dashed border-amber-300 bg-background/70 px-3 py-1.5 text-sm text-muted-foreground",children:[a," \xB7 context unknown"]},a))]})]},o.aliasId))}):(0,te.jsx)("div",{className:"mt-4 rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:"No alias currently mixes known context-window sizes across its configured targets."})]})]})})}var Ae=_(Z(),1),a5=500;function Si(e=[]){return(e||[]).map(t=>({ref:String(t?.ref||"").trim(),weight:String(t?.weight||"1").trim()}))}function rv({aliasId:e,alias:t,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabled:i=!1,disabledReason:l="",busy:s=!1,onApply:c,onRemove:d,onCopyAliasId:u=()=>{},isNew:f=!1,alwaysShowAliasIdInput:p=!1,showIssueOnSubmitOnly:v=!1,onDiscard:m=()=>{},onOpenStrategyModal:b=()=>{},titleAccessory:h=null,aliasSwitcher:g=null,framed:y=!0}){let x=aC(e,t,{isNew:f}),w=(0,Tn.useMemo)(()=>MA(f?"":e,t),[x]),[C,E]=(0,Tn.useState)(w),[A,M]=(0,Tn.useState)(f),[L,P]=(0,Tn.useState)(!1),D=(0,Tn.useRef)(null),G=(0,Tn.useRef)(0),ae=(0,Tn.useRef)(""),[ge,j]=(0,Tn.useState)("idle");(0,Tn.useEffect)(()=>{E(w),M(f),P(!1),j("idle"),ae.current=""},[w,f]);let J=!f&&Array.isArray(g?.entries)&&g.entries.length>1,Q=p||A;(0,Tn.useEffect)(()=>{if(!Q)return;let q=typeof window<"u"?window.requestAnimationFrame(()=>{D.current?.focus(),D.current?.select?.()}):0;return()=>{typeof window<"u"&&window.cancelAnimationFrame(q)}},[Q]);let H=String(C?.id||"").trim(),B=e===St||H===St,ft=(0,Tn.useMemo)(()=>xi((r||[]).filter(q=>q.kind!=="alias"&&q.value!==H&&q.value!==`alias:${H}`),[...(C?.targets||[]).map(q=>q?.ref),...(C?.fallbackTargets||[]).map(q=>q?.ref)]),[r,H,C?.targets,C?.fallbackTargets]),X=(C?.targets||[]).map(q=>String(q?.ref||"").trim()),je=(C?.fallbackTargets||[]).map(q=>String(q?.ref||"").trim()),ie=[...X,...je],xe=[...C?.targets||[],...C?.fallbackTargets||[]],Ie=xe.some(q=>!String(q?.ref||"").trim()),I=ws(ie),ue=xe.some(q=>{if(!String(q?.ref||"").trim())return!1;let be=Math.floor(Number(q?.weight));return!Number.isFinite(be)||be<=0}),he=H&&n.some(q=>q!==e&&q===H),_e=H&&ie.some(q=>q===H||q===`alias:${H}`),Ee=ie.filter(Boolean).length>0,ve=JSON.stringify({id:w.id,strategy:w.strategy,targets:Si(w.targets),fallbackTargets:Si(w.fallbackTargets)}),Fe=JSON.stringify({id:H,strategy:C?.strategy,targets:Si(C?.targets),fallbackTargets:Si(C?.fallbackTargets)}),Je=JSON.stringify({targets:Si(w.targets),fallbackTargets:Si(w.fallbackTargets)}),Ht=JSON.stringify({targets:Si(C?.targets),fallbackTargets:Si(C?.fallbackTargets)}),wn=ve!==Fe,fn=H?UA.test(H)?he?"Alias id already exists. Choose another id.":Ie?"Fill or remove blank target rows before applying.":I?"Duplicate targets are not allowed anywhere in this alias.":ue?"Target weights must be positive integers.":_e?"An alias cannot target itself.":"":"Alias id must start with a letter or number and use letters, numbers, dots, underscores, colons, or hyphens.":"Alias id is required.",Ft=i?l:fn,Yt=i?l:v&&fn&&!L?"":fn,st=i||s,Ve=String(H||e||"").trim(),Vn=Ve||"Select alias",mn=st||B||f,er=B?"Default alias cannot be removed":`Remove alias ${Ve||e}`,Ra=(0,Tn.useMemo)(()=>Ff(Vn),[Vn]),Te=B||o===e||o===H,Ze=a===e||a===H,Ce=f?"Enter alias name. Example: claude-opus":void 0,Ge=(0,Tn.useMemo)(()=>GE(C,t,r),[C,t,r]);async function ao(){if(P(!0),Ft)return!1;let q=await c(e,C);return q&&f&&m(e),q}async function pn(q){let be={...C,strategy:q};return await c(e,be)?f?(m(e),!0):(E(be),!0):!1}async function It(){if(P(!0),Ft)return!1;let q=await c(e,C);return q&&(M(!1),P(!1)),q}function N(){if(p)return;if(!J){M(!1);return}let q=String(e||"").trim(),be=String(C?.id||"").trim();if(!be||be===q){E(Be=>({...Be,id:q})),M(!1),P(!1);return}It()}function se(q){if(q.key==="Escape"){q.preventDefault(),E(be=>({...be,id:w.id})),M(!1),P(!1);return}!p&&q.key==="Enter"&&(q.preventDefault(),q.currentTarget.blur())}async function W(){if(Q){let q=String(e||"").trim(),be=String(C?.id||"").trim();if(!be||be===q){E(Be=>({...Be,id:q})),M(!1),P(!1);return}await It();return}M(!0)}(0,Tn.useEffect)(()=>()=>{typeof window<"u"&&G.current&&window.clearTimeout(G.current)},[]),(0,Tn.useEffect)(()=>{if(f||st||Ft||Ht===Je){typeof window<"u"&&G.current&&(window.clearTimeout(G.current),G.current=0),!f&&Ht===Je&&ge!=="saving"&&j("idle");return}if(!(ae.current===Ht&&ge==="error")&&(j("pending"),!(typeof window>"u")))return G.current=window.setTimeout(()=>{G.current=0,ae.current=Ht,j("saving"),c(e,C,{showSuccessNotice:!1,successMessage:""}).then(q=>{j(q?"saved":"error")})},a5),()=>{G.current&&(window.clearTimeout(G.current),G.current=0)}},[e,Ht,C,Je,f,Ft,st,c]);let Re=f?"":ge==="saving"?"Saving alias changes\u2026":ge==="pending"?"Changes save automatically.":ge==="saved"?"Alias changes saved.":ge==="error"?"Autosave failed. Keep editing to retry.":"Changes save automatically.",ce=(0,Ae.jsxs)("div",{className:"space-y-4",children:[(0,Ae.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,Ae.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,Ae.jsx)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:J?(0,Ae.jsxs)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-2",children:[(0,Ae.jsxs)("div",{className:F("flex h-9 min-w-0 max-w-full overflow-hidden rounded-lg border border-input bg-background/80 shadow-sm transition focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/40",Q?"flex-1":"w-fit"),children:[(0,Ae.jsx)("div",{className:"flex shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Select an alias"}),Q?(0,Ae.jsx)(wt,{ref:D,value:C.id,placeholder:Ce,onChange:q=>E(be=>({...be,id:q.target.value})),onBlur:N,onKeyDown:se,disabled:st||B,className:"h-full min-w-[12rem] flex-1 rounded-none border-0 bg-transparent px-3 text-sm font-medium shadow-none focus:border-transparent focus:ring-0"}):(0,Ae.jsxs)(rn,{value:g.value||void 0,onValueChange:g.onValueChange,children:[(0,Ae.jsx)(on,{className:"h-full min-w-[10rem] flex-none rounded-none border-0 bg-transparent px-3 pr-[50px] text-left text-sm font-medium shadow-none focus:border-transparent focus:ring-0",style:{width:`${Ra}px`,maxWidth:"100%"},children:(0,Ae.jsx)(an,{placeholder:"Select alias"})}),(0,Ae.jsx)(ln,{children:g.entries.map(([q,be])=>(0,Ae.jsx)(Dt,{value:q,searchText:`${q} ${(be?.targets||[]).length} ${(be?.fallbackTargets||[]).length}`,children:q},q))})]}),Q?null:(0,Ae.jsx)("button",{type:"button",className:"flex h-full w-10 shrink-0 items-center justify-center border-l border-border/70 text-muted-foreground transition hover:bg-accent/60 hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/60 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{u(Ve)},disabled:st||!Ve,"aria-label":`Copy alias id ${Ve}`,title:Ve?`Copy alias id ${Ve}`:"Alias id is not ready yet",children:(0,Ae.jsx)(ZA,{className:"h-4 w-4 shrink-0"})})]}),(0,Ae.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-9 w-9 rounded-lg border-border/70 bg-background/70 p-0 text-muted-foreground shadow-none hover:bg-background/90 hover:text-foreground",onMouseDown:q=>{Q&&q.preventDefault()},onClick:()=>{W()},disabled:st||B,"aria-label":Q?"Save alias id":B?"Default alias id cannot be edited":"Edit alias id",title:Q?"Save alias id":B?"Default alias id cannot be edited":"Edit alias id",children:Q?(0,Ae.jsx)(XA,{className:"h-4 w-4 shrink-0"}):(0,Ae.jsx)(bs,{className:"h-4 w-4 shrink-0"})}),f?null:(0,Ae.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-9 w-9 rounded-lg border-border/70 bg-background/70 p-0 text-muted-foreground shadow-none hover:border-destructive hover:bg-background/90 hover:text-destructive",onClick:()=>d(e),disabled:mn,"aria-label":er,title:er,children:(0,Ae.jsx)(Qc,{className:"h-4 w-4 shrink-0"})})]}):(0,Ae.jsxs)(Ae.Fragment,{children:[Q?(0,Ae.jsx)(wt,{ref:D,autoFocus:f,value:C.id,placeholder:Ce,onChange:q=>E(be=>({...be,id:q.target.value})),onBlur:N,onKeyDown:se,disabled:st||B&&!f,className:"max-w-[22rem] font-semibold"}):B&&!f?(0,Ae.jsx)("div",{className:"truncate text-base font-semibold text-foreground",children:e}):(0,Ae.jsxs)("button",{type:"button",className:"group inline-flex max-w-full items-center gap-2 rounded-lg text-left text-base font-semibold text-foreground transition hover:bg-primary/5 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-2 focus-visible:ring-offset-background",onClick:()=>M(!0),disabled:st,"aria-label":"Edit alias id",title:"Edit alias id",children:[(0,Ae.jsx)("span",{className:"truncate",children:f?H||"New alias":H||e}),(0,Ae.jsx)(bs,{className:"h-4 w-4 shrink-0"})]}),h?(0,Ae.jsx)("div",{className:"min-w-[11rem] max-w-full",children:h}):null]})}),B?null:(0,Ae.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Te?(0,Ae.jsx)(ut,{variant:"success",children:"Default route"}):null,Ze?(0,Ae.jsx)(ut,{variant:"info",children:"AMP default"}):null]})]}),(0,Ae.jsxs)("div",{className:"flex items-start gap-2 self-start",children:[(0,Ae.jsxs)($,{type:"button",variant:"outline",size:"default",className:"group h-9 gap-0 overflow-hidden rounded-lg border-border/70 bg-background/70 px-0 text-sm font-medium normal-case tracking-normal shadow-none hover:bg-background/90",onClick:()=>b({aliasLabel:H||(f?"New alias":e),strategy:C?.strategy||"auto",entries:Ge,disabled:st||!!Ft,onSave:pn}),disabled:st,children:[(0,Ae.jsx)("span",{className:"flex h-full shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Routing stratergy"}),(0,Ae.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-2 px-3 text-left",children:[(0,Ae.jsx)("span",{className:"truncate",children:Df(C.strategy||"auto")}),(0,Ae.jsx)(bs,{className:"h-4 w-4 shrink-0"})]})]}),!J&&!f?(0,Ae.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-9 w-9 rounded-lg border-border/70 bg-background/70 p-0 text-muted-foreground shadow-none hover:border-destructive hover:bg-background/90 hover:text-destructive",onClick:()=>d(e),disabled:mn,"aria-label":er,title:er,children:(0,Ae.jsx)(Qc,{className:"h-4 w-4 shrink-0"})}):null]})]}),(0,Ae.jsx)(nv,{title:"Primary targets",rows:C.targets,onChange:q=>E(be=>({...be,targets:q})),options:ft,disabled:st,addLabel:"Add target",emptyLabel:"No targets yet. This alias can stay empty until you wire routes back in.",helperText:"Primary targets are tried first. Drag to reorder targets. Weights and metadata stay with the same ref.",draftPlaceholder:"Add a new target",showDraftRow:!0,showDraftFocusButton:!0,showWeightInput:!0,filterOtherSelectedValues:!0,excludedValues:je}),(0,Ae.jsx)(nv,{title:"Fallback targets",rows:C.fallbackTargets,onChange:q=>E(be=>({...be,fallbackTargets:q})),options:ft,disabled:st,addLabel:"Add fallback",emptyLabel:"No fallback targets configured.",helperText:"Fallback targets only enter the candidate pool after the full primary list. Weights still apply within the chosen routing strategy.",draftPlaceholder:"Add a fallback target",showDraftRow:!0,showDraftFocusButton:!0,showWeightInput:!0,filterOtherSelectedValues:!0,excludedValues:X}),Yt?null:(0,Ae.jsx)("div",{className:"text-xs text-muted-foreground",children:Re}),Yt?(0,Ae.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:Yt}):null,!Yt&&B&&!Ee?(0,Ae.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:["The fixed ",(0,Ae.jsx)("code",{children:"default"})," route is empty. Requests routed to ",(0,Ae.jsx)("code",{children:"default"})," or ",(0,Ae.jsx)("code",{children:"smart"})," will return 500 until you add a working target."]}):null,f?(0,Ae.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,Ae.jsx)("div",{children:(0,Ae.jsx)($,{type:"button",variant:"ghost",onClick:()=>m(e),disabled:st,children:"Discard"})}),(0,Ae.jsx)("div",{className:"flex flex-wrap justify-end gap-2",children:(0,Ae.jsx)($,{type:"button",onClick:()=>{ao()},disabled:st||!!Ft,children:s?"Saving\u2026":"Create alias"})})]}):null]});return y?(0,Ae.jsx)(Gt,{children:(0,Ae.jsx)(qt,{className:"space-y-4 p-5",children:ce})}):ce}var en=_(Z(),1);function YE({aliases:e,config:t,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabledReason:i="",busy:l=!1,onApplyAlias:s,onRemoveAlias:c,onCopyAliasId:d}){let u=Object.entries(e||{}),f=!!i,[p,v]=(0,Aa.useState)(""),[m,b]=(0,Aa.useState)(!1),[h,g]=(0,Aa.useState)(""),y=(0,Aa.useMemo)(()=>oC(),[]),[x,w]=(0,Aa.useState)({open:!1,aliasLabel:"",strategy:"auto",entries:[],disabled:!1,onSave:null});function C(){f||l||v(`draft-${Date.now()}`)}function E(j){(!j||j===p)&&v("")}function A(){v("")}function M({aliasLabel:j="",strategy:J="auto",entries:Q=[],disabled:H=!1,onSave:B=null}){w({open:!0,aliasLabel:j,strategy:J,entries:Q,disabled:H,onSave:B})}function L(){w(j=>({...j,open:!1}))}async function P(j,J,Q={}){let H=await s(j,J,Q);if(H){let B=String(J?.id||j||"").trim()||j;g(B)}return H}(0,Aa.useEffect)(()=>{let j=u.map(([J])=>J);if(j.length===0){h&&g("");return}(!h||!j.includes(h))&&g(j[0])},[u,h]);let D=u.find(([j])=>j===h)||u[0]||null,G=D?.[0]||"",ae=D?.[1]||null,ge=u.length>1?{value:G,onValueChange:g,entries:u}:null;return(0,en.jsxs)(en.Fragment,{children:[(0,en.jsxs)(Gt,{children:[(0,en.jsx)(Qr,{children:(0,en.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,en.jsx)("div",{className:"space-y-1",children:(0,en.jsx)(li,{children:"Model aliases give clients one stable route across multiple provider/models, so you can swap, balance, and fail over without changing client config."})}),(0,en.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,en.jsx)($,{type:"button",variant:"outline",size:"sm",onClick:()=>b(!0),children:"Help"}),(0,en.jsx)($,{type:"button",size:"sm",onClick:C,disabled:f||l,children:l?"Saving\u2026":"Add alias"})]})]})}),(0,en.jsxs)(qt,{className:"space-y-4",children:[f?(0,en.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:i}):null,u.length>0?G&&ae?(0,en.jsx)(rv,{aliasId:G,alias:ae,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabled:f,disabledReason:i,busy:l,onApply:P,onRemove:c,onCopyAliasId:d,onOpenStrategyModal:M,aliasSwitcher:ge,framed:!1},G):null:(0,en.jsxs)("div",{className:"rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground",children:["No model aliases yet. Add one to expose stable routes like ",(0,en.jsx)("code",{children:"coding"})," or ",(0,en.jsx)("code",{children:"chat.fast"})," in the Web UI."]})]})]}),(0,en.jsx)(Zn,{open:!!p,onClose:A,title:"Add alias",description:"Set a stable client-facing route, choose its strategy, and order the targets it should use.",showCloseButton:!1,contentClassName:"max-h-[92vh] max-w-5xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)]",children:p?(0,en.jsx)(rv,{aliasId:p,alias:y,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabled:f,disabledReason:i,busy:l,onApply:P,onRemove:c,onCopyAliasId:d,isNew:!0,alwaysShowAliasIdInput:!0,showIssueOnSubmitOnly:!0,onDiscard:E,onOpenStrategyModal:M,framed:!1},p):null}),(0,en.jsx)(qE,{open:x.open,onClose:L,onSave:j=>x.onSave?.(j),aliasLabel:x.aliasLabel,initialStrategy:x.strategy,entries:x.entries,disabled:x.disabled}),(0,en.jsx)(WE,{open:m,onClose:()=>b(!1),config:t})]})}var Wt=_(me(),1);var pl=_(me(),1);var Ir=_(Z(),1);function bu({values:e,onChange:t,placeholder:n,helperText:r,inputRef:o=null,inputClassName:a="",suggestedValues:i=[],valueStates:l={},draftValue:s="",onDraftValueChange:c=()=>{},commitOnBlur:d=!1,disabled:u=!1,isValueValid:f=v=>!!String(v||"").trim(),inputProps:p={}}){let v=(0,pl.useMemo)(()=>pr(e),[e]),[m,b]=(0,pl.useState)(""),[h,g]=(0,pl.useState)("");function y(A=s,{clearDraft:M=!0}={}){if(u)return!1;let L=Of(A).filter(D=>f(D));if(L.length===0)return M&&c(""),!1;let P=Array.from(new Set([...v||[],...L]));return JSON.stringify(P)!==JSON.stringify(v||[])&&t(P),M&&c(""),!0}function x(A){u||(t(v.filter(M=>M!==A)),m===A&&(b(""),g("")))}function w(){u||i.length&&(t(Array.from(new Set([...v||[],...i]))),c(""))}function C(A){u||(b(A),g(A))}function E(A=h){if(u)return b(""),g(""),!1;if(!m)return!1;let M=Of(A).filter(G=>f(G)),L=[],P=!1;for(let G of v||[]){if(G!==m){L.push(G);continue}P||(L.push(...M),P=!0)}let D=Array.from(new Set(L.map(G=>String(G||"").trim()).filter(Boolean)));return JSON.stringify(D)!==JSON.stringify(v||[])&&t(D),b(""),g(""),M.length>0}return(0,pl.useEffect)(()=>{!u||!m||(b(""),g(""))},[u,m]),(0,Ir.jsxs)("div",{className:"space-y-2",children:[(0,Ir.jsxs)("div",{className:F("flex min-h-11 flex-wrap items-center gap-2 rounded-xl border border-input bg-background/80 px-3 py-2",u?"opacity-80":null),children:[v.map(A=>{let M=l?.[A]||"default",L=M==="success"?"border-emerald-200 bg-emerald-50 text-emerald-900":M==="error"?"border-rose-200 bg-rose-50 text-rose-900":M==="pending"?"border-sky-200 bg-sky-50 text-sky-900":"border-border bg-secondary text-foreground",P=!u&&m===A;return(0,Ir.jsxs)("span",{className:F("inline-flex max-w-full items-center gap-1 rounded-full border px-2.5 py-1 text-xs",L),children:[P?(0,Ir.jsx)("input",{autoFocus:!0,className:"min-w-[7rem] bg-transparent text-xs text-foreground outline-none",value:h,onChange:D=>g(D.target.value),onKeyDown:D=>{if(D.key==="Enter"||D.key==="Tab"){D.preventDefault(),E();return}D.key==="Escape"&&(D.preventDefault(),b(""),g(""))},onBlur:()=>{E()}}):(0,Ir.jsx)("button",{className:"max-w-[16rem] truncate text-left transition hover:text-foreground disabled:cursor-not-allowed disabled:opacity-70",type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>C(A),disabled:u,title:"Click to edit",children:A}),(0,Ir.jsx)("button",{className:"text-muted-foreground transition hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60",type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>x(A),disabled:u,children:"\xD7"})]},A)}),(0,Ir.jsx)("input",{...p,ref:o,className:F("min-w-[10rem] flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-70",a),value:s,disabled:u,onChange:A=>{let M=A.target.value;if(/[\s,]/.test(M)){let L=M.split(/[\s,]+/),P=L.pop()||"";L.length>0&&y(L.join(","),{clearDraft:!1}),c(P);return}c(M)},onKeyDown:A=>{if((A.key===","||A.key===" "||A.key==="Enter"||A.key==="Tab")&&s.trim()){A.preventDefault(),y();return}A.key==="Backspace"&&!s&&v.length>0&&(A.preventDefault(),x(v[v.length-1]))},onPaste:A=>{let M=A.clipboardData?.getData("text")||"";if(/[\s,]/.test(M)){A.preventDefault();let L=M.split(/[\s,]+/).filter(Boolean).filter(P=>f(P));L.length>0&&(t(Array.from(new Set([...v||[],...L]))),c(""));return}A.preventDefault(),c(`${s}${M}`)},onBlur:()=>{if(d&&f(s)){y(s);return}c(s)},placeholder:n}),v.length>0||s?(0,Ir.jsx)("button",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground transition hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60",type:"button",onMouseDown:A=>A.preventDefault(),onClick:()=>{t([]),c("")},disabled:u,children:"Clear all"}):null]}),(0,Ir.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[r?(0,Ir.jsx)("span",{children:r}):null,v.length===0&&i.length>0?(0,Ir.jsx)("button",{className:"font-medium uppercase tracking-[0.16em] text-foreground transition hover:text-primary disabled:cursor-not-allowed disabled:opacity-60",type:"button",onClick:w,disabled:u,children:"Use suggested values"}):null]})]})}var Jn=_(me(),1);var Ye=_(Z(),1);function QE(e="rate-limit-draft-row"){return nu({key:e,models:[],requests:"",windowValue:"",windowUnit:po.custom.rateLimitDefaults.windowUnit},{keyPrefix:"rate-limit-draft",defaults:po.custom.rateLimitDefaults,useDefaults:!1})}function Tm(e=[],{keyPrefix:t="rate-limit-draft"}={}){let n=`${t}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;return[...Array.isArray(e)?e:[],QE(n)]}function i5({value:e=[],onChange:t,availableModelIds:n=[],disabled:r=!1}){let o=(0,Jn.useRef)(null),[a,i]=(0,Jn.useState)(!1),l=(0,Jn.useMemo)(()=>mo(e),[e]),s=l.includes("all"),c=s?[]:l.filter(Boolean),d=s||c.length===0,u=(0,Jn.useMemo)(()=>pr(n),[n]);(0,Jn.useEffect)(()=>{if(!a||typeof document>"u")return;function h(g){o.current?.contains(g.target)||i(!1)}return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[a]);function f(h){t(mo(h))}function p(h){f(h?["all"]:[])}function v(h,g){let y=g?[...c,h]:c.filter(x=>x!==h);f(y)}function m(h){if(h==="all"){f([]);return}f(c.filter(g=>g!==h))}let b=s?[{key:"all",label:"All model",removable:!0}]:c.length>0?c.map(h=>({key:h,label:h,removable:!0})):[{key:"__implicit-all__",label:"All model",removable:!1,muted:!0}];return(0,Ye.jsxs)("div",{ref:o,className:"relative space-y-1.5",children:[(0,Ye.jsxs)("div",{role:"button",tabIndex:r?-1:0,className:F("flex min-h-9 w-full items-center justify-between gap-2 rounded-lg border border-input bg-background/80 px-3 py-1.5 text-left text-sm text-foreground shadow-sm outline-none transition focus:border-ring focus:ring-2 focus:ring-ring/40",r?"cursor-not-allowed opacity-50":"cursor-pointer",a?"border-ring ring-2 ring-ring/40":null),onClick:()=>{r||i(h=>!h)},"aria-expanded":a,"aria-haspopup":"menu",onKeyDown:h=>{if(!r){if(h.key==="Enter"||h.key===" "){h.preventDefault(),i(g=>!g);return}if(h.key==="ArrowDown"){h.preventDefault(),i(!0);return}h.key==="Escape"&&(h.preventDefault(),i(!1))}},children:[(0,Ye.jsx)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5",children:b.map(h=>h.removable?(0,Ye.jsxs)("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-full border border-border/70 bg-background px-2 py-0.5 text-xs font-medium text-foreground transition hover:border-accent hover:bg-accent",onClick:g=>{g.preventDefault(),g.stopPropagation(),m(h.key)},disabled:r,title:`Remove ${h.label}`,children:[(0,Ye.jsx)("span",{className:"truncate",children:h.label}),(0,Ye.jsx)("span",{className:"text-muted-foreground",children:"x"})]},h.key):(0,Ye.jsx)("span",{className:F("inline-flex max-w-full items-center rounded-full border px-2 py-0.5 text-xs font-medium",h.muted?"border-border/70 bg-secondary/45 text-muted-foreground":"border-border/70 bg-background text-foreground"),children:(0,Ye.jsx)("span",{className:"truncate",children:h.label})},h.key))}),(0,Ye.jsx)("span",{className:"text-muted-foreground",children:"\u25BE"})]}),a?(0,Ye.jsxs)(Rm,{open:a,anchorRef:o,preferredSide:"top",desiredHeight:192,className:"p-2",onMouseDown:h=>h.stopPropagation(),onClick:h=>h.stopPropagation(),onKeyDown:h=>{h.key==="Escape"&&(h.preventDefault(),i(!1))},children:[(0,Ye.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-sm text-foreground transition hover:bg-secondary/60",children:[(0,Ye.jsx)("input",{type:"checkbox",className:"h-4 w-4 rounded border-input",checked:s,onChange:h=>p(h.target.checked)}),(0,Ye.jsx)("span",{children:"All model"})]}),(0,Ye.jsx)("div",{className:"my-1 border-t border-border/70"}),u.length>0?(0,Ye.jsx)("div",{children:u.map(h=>(0,Ye.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-sm text-foreground transition hover:bg-secondary/60",children:[(0,Ye.jsx)("input",{type:"checkbox",className:"h-4 w-4 rounded border-input",checked:c.includes(h),onChange:g=>v(h,g.target.checked)}),(0,Ye.jsx)("span",{className:"truncate",children:h})]},h))}):(0,Ye.jsx)("div",{className:"px-2 py-2 text-sm text-muted-foreground",children:"No models available yet."})]}):null]})}function Mm({rows:e,onChange:t,availableModelIds:n=[],disabled:r=!1,inputRef:o=null,helperText:a="",onValidBlur:i=null}){let l=Array.isArray(e)?e:[],s=(0,Jn.useRef)(null),c=(0,Jn.useRef)(l),d=(0,Jn.useMemo)(()=>pr(n),[n]),u=(0,Jn.useMemo)(()=>{let g=new Set,y=new Set;for(let x of gr(l)){let w=Fc(x);if(w){if(g.has(w)){y.add(w);continue}g.add(w)}}return y},[l]),f=(0,Jn.useMemo)(()=>l.map(g=>({...QE(g.key),...g,models:mo(g?.models||[])})),[l]);(0,Jn.useEffect)(()=>{c.current=l},[l]);function p(g){let y=Array.isArray(g)?g:[];c.current=y,t(y)}function v(g,y){p(l.map(x=>x.key===g?{...x,...y}:x))}function m(g){p(l.filter(y=>y.key!==g))}function b(g){if(If(g))return"";let y=mo(g?.models||[]);if(d.length>0&&y.some(w=>w!=="all"&&!d.includes(w)))return"Use exact provider model ids only.";if(Yh(g?.requests,0)<=0)return"Requests must be a positive integer.";if(Yh(g?.windowValue,0)<=0)return"Window size must be a positive integer.";if(!Fh.includes(String(g?.windowUnit||"").trim()))return"Window unit is invalid.";let x=Fc({requests:g?.requests,windowValue:g?.windowValue,windowUnit:g?.windowUnit});return x&&u.has(x)?"Another row already uses this cap.":""}function h(g){if(!(!i||r)&&!g.currentTarget.contains(g.relatedTarget)){if(typeof window>"u"){let y=gr(c.current);Lo(y,{knownModelIds:d,requireAtLeastOne:!0})||i(y);return}window.setTimeout(()=>{if(!s.current||s.current.contains(document.activeElement))return;let y=gr(c.current);Lo(y,{knownModelIds:d,requireAtLeastOne:!0})||i(y)},0)}}return(0,Ye.jsxs)("div",{ref:s,className:"space-y-2.5",onBlurCapture:h,children:[(0,Ye.jsx)("div",{className:"space-y-2.5",children:f.map((g,y)=>{let x=If(g),w=b(g);return(0,Ye.jsxs)("div",{className:F("rounded-2xl border border-border/70 bg-background/70 p-3",w?"border-amber-200 bg-amber-50/70":null,x?"border-dashed bg-background/80":null),children:[(0,Ye.jsxs)("div",{className:"grid gap-2.5 xl:grid-cols-[minmax(0,1.5fr)_minmax(0,0.72fr)_minmax(0,0.72fr)_minmax(0,0.86fr)_auto] xl:items-end",children:[(0,Ye.jsx)(pt,{label:"Models",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Ye.jsx)(i5,{value:g.models,onChange:C=>v(g.key,{models:C}),availableModelIds:d,disabled:r})}),(0,Ye.jsx)(pt,{label:"Request",stacked:!0,className:"gap-1",headerClassName:"min-h-0",children:(0,Ye.jsx)(wt,{ref:y===0?o:null,value:g.requests,onChange:C=>v(g.key,{requests:C.target.value}),disabled:r,inputMode:"numeric",placeholder:"60"})}),(0,Ye.jsx)(pt,{label:"Window",stacked:!0,className:"gap-1",headerClassName:"min-h-0",children:(0,Ye.jsx)(wt,{value:g.windowValue,onChange:C=>v(g.key,{windowValue:C.target.value}),disabled:r,inputMode:"numeric",placeholder:"1"})}),(0,Ye.jsx)(pt,{label:"Unit",stacked:!0,className:"gap-1",headerClassName:"min-h-0",children:(0,Ye.jsxs)(rn,{value:String(g.windowUnit||"minute"),onValueChange:C=>v(g.key,{windowUnit:C}),disabled:r,children:[(0,Ye.jsx)(on,{children:(0,Ye.jsx)(an,{placeholder:"Window unit"})}),(0,Ye.jsx)(ln,{children:Fh.map(C=>(0,Ye.jsx)(Dt,{value:C,children:C},`${g.key}-${C}`))})]})}),(0,Ye.jsx)($,{type:"button",variant:"ghost",onClick:()=>m(g.key),disabled:r,className:"xl:self-end",children:"Remove"})]}),w?(0,Ye.jsx)("div",{className:"mt-2.5 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:w}):null]},g.key)})}),a?(0,Ye.jsx)("div",{className:"text-xs leading-5 text-muted-foreground",children:a}):null]})}var lt=_(me(),1);var XE=[{key:"supportsReasoning",label:"Reasoning",field:"reasoning_effort"},{key:"supportsThinking",label:"Thinking",field:"thinking"},{key:"supportsResponseFormat",label:"Response Format",field:"response_format"},{key:"supportsLogprobs",label:"Logprobs",field:"logprobs"},{key:"supportsServiceTier",label:"Service Tier",field:"service_tier"},{key:"supportsPrediction",label:"Prediction",field:"prediction"},{key:"supportsStreamOptions",label:"Stream Options",field:"stream_options"}];function ZE(e={},t={}){if(!t||typeof t!="object")return e;let n={...e};for(let r of Object.keys(t))typeof t[r]=="boolean"&&n[r]===void 0&&(n[r]=t[r]);return n}function JE(e){if(e===void 0)return!0;if(e===!0)return!1}function eT(e){return!e||typeof e!="object"?!1:Object.values(e).some(t=>typeof t=="boolean")}var wi=_(Z(),1);function l5({label:e,value:t,disabled:n,onCycle:r}){let o=typeof t=="boolean";return(0,wi.jsxs)("button",{type:"button",disabled:n,onClick:r,className:F("flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs transition-colors",t===!0&&"border-emerald-200 bg-emerald-50/80",t===!1&&"border-rose-200 bg-rose-50/60",!o&&"border-border/60 bg-secondary/40",!n&&"hover:bg-accent"),children:[(0,wi.jsx)("span",{className:F("inline-flex h-3 w-3 shrink-0 items-center justify-center rounded-full text-[8px] font-bold leading-none",t===!0&&"bg-emerald-500 text-white",t===!1&&"bg-rose-400 text-white",!o&&"bg-muted-foreground/25"),children:t===!0?"\u2713":t===!1?"\u2715":""}),(0,wi.jsx)("span",{className:F("select-none whitespace-nowrap font-medium",t===!0&&"text-emerald-800",t===!1&&"text-rose-700 line-through",!o&&"text-muted-foreground"),children:e})]})}function tT({capabilities:e={},disabled:t=!1,onChange:n}){return(0,wi.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[(0,wi.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground/80",children:"Capabilities"}),XE.map(({key:r,label:o})=>{let a=e[r];return(0,wi.jsx)(l5,{label:o,value:a,disabled:t,onCycle:()=>n(r,JE(a))},r)})]})}var Ne=_(Z(),1);function nT({provider:e,disabled:t=!1,disabledReason:n="",busy:r=!1,onApply:o,framed:a=!0,focusRequest:i=0,onStateChange:l=null,testStateByModel:s={},savePhase:c="",saveMessage:d=""}){let u=(0,lt.useMemo)(()=>NA(e),[e]),[f,p]=(0,lt.useState)([]),[v,m]=(0,lt.useState)(""),[b,h]=(0,lt.useState)(!1),[g,y]=(0,lt.useState)({}),[x,w]=(0,lt.useState)({}),[C,E]=(0,lt.useState)(null),[A,M]=(0,lt.useState)(""),[L,P]=(0,lt.useState)(""),[D,G]=(0,lt.useState)({}),ae=(0,lt.useRef)(0),ge=(0,lt.useRef)([]),j=(0,lt.useRef)(new Map),J=(0,lt.useRef)(new Map),Q=(0,lt.useRef)(""),H=(0,lt.useRef)(""),B=(0,lt.useRef)(null),ft=(0,lt.useRef)(new Map),X=(0,lt.useRef)(new Map);function je(N={}){return ae.current+=1,{key:`model-${e.id}-draft-${ae.current}`,id:"",sourceId:"",contextWindow:"",capabilities:{},...N}}function ie(N){Q.current=N}function xe(N=[],{preserveFocus:se=!1}={}){let W=[],Re=null;for(let ce of Array.isArray(N)?N:[]){let q=String(ce?.id||""),be=ce?.contextWindow===void 0||ce?.contextWindow===null?"":String(ce.contextWindow);if(String(q).trim()){W.push({...ce,id:q,contextWindow:be});continue}Re||(Re={...ce,id:"",contextWindow:be})}return Re||(Re=je(),se&&ie(Re.key)),[Re,...W]}function Ie(N){w(se=>{if(!se[N])return se;let W={...se};return delete W[N],W})}function I(N,se){y(W=>{if(se)return W[N]?W:{...W,[N]:!0};if(!W[N])return W;let Re={...W};return delete Re[N],Re})}function ue(N,se={},{clearLookupState:W=!1,clearStatus:Re=!0,closeLookupMenu:ce=!1}={}){W&&Ie(N),Re&&E(null),ce&&A===N&&M(""),p(q=>xe(q.map(be=>be.key===N?{...be,...se}:be),{preserveFocus:!1}))}(0,lt.useEffect)(()=>{ge.current=f},[f]),(0,lt.useEffect)(()=>{let N=xe(u,{preserveFocus:!0});p(N),ge.current=N,ft.current.clear(),X.current.clear(),y({}),w({}),E(null),M(""),P(""),G({})},[u]),(0,lt.useEffect)(()=>{let N=Q.current;if(!N)return;let se=j.current.get(N);if(!se)return;se.scrollIntoView?.({block:"nearest"}),se.focus();let W=se.value?.length||0;se.setSelectionRange?.(W,W),Q.current=""},[f]),(0,lt.useEffect)(()=>{i&&p(N=>{let se=xe(N,{preserveFocus:!1}),W=se.find(Re=>!String(Re?.id||"").trim())||se[se.length-1];return W&&ie(W.key),se})},[i]),(0,lt.useEffect)(()=>{A&&(f.some(N=>N.key===A)||M(""))},[f,A]),(0,lt.useEffect)(()=>{L&&(f.some(N=>N.key===L)||P(""))},[f,L]),(0,lt.useEffect)(()=>{G(N=>{let se=new Set(f.map(ce=>ce.key)),W=!1,Re={};for(let[ce,q]of Object.entries(N)){if(!se.has(ce)){W=!0;continue}Re[ce]=q}return W?Re:N})},[f]),(0,lt.useEffect)(()=>{if(!A||typeof document>"u")return;function N(se){J.current.get(A)?.contains(se.target)||M("")}return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[A]);let he=(0,lt.useMemo)(()=>f.filter(N=>String(N?.id||"").trim()),[f]),_e=(0,lt.useMemo)(()=>u.map(N=>({id:String(N?.id||"").trim(),contextWindow:Uo(N?.contextWindow||""),capabilities:N?.capabilities||{}})).filter(N=>N.id),[u]),Ee=(0,lt.useMemo)(()=>he.map(N=>({...N,id:String(N?.id||"").trim(),contextWindow:Uo(N?.contextWindow||"")})),[he]),ve=Ee.map(N=>N.id),Fe=_e.map(N=>N.id),Je=ve.filter(N=>!Fe.includes(N)),Ht=ws(ve),wn=ve.length>0,fn=new Set(Ee.filter(N=>{let se=String(N?.contextWindow||"").trim();if(!se)return!1;let W=Number.parseInt(se,10);return!Number.isFinite(W)||W<=0||String(W)!==se}).map(N=>N.key)),Ft=Ee.filter(N=>!String(N?.contextWindow||"").trim()),Yt=JSON.stringify(_e)!==JSON.stringify(Ee.map(N=>({id:N.id,contextWindow:N.contextWindow,capabilities:N.capabilities||{}}))),Ve=t||r||(v!==""||c==="testing"||c==="saving")||b,Vn=(0,lt.useMemo)(()=>{let N=-1;return f.forEach((se,W)=>{String(se?.id||"").trim()&&(N=W)}),N},[f]),mn=t?n:wn?Ht?"Model ids must be unique for each provider.":fn.size>0?"Context windows must be positive integers when set.":"":"Keep at least one model id on the provider.",er=zs(f.map(N=>N.key));(0,lt.useEffect)(()=>{l?.({isDirty:Yt,issue:mn,locked:Ve,rows:Ee.map(N=>({...N,contextWindow:Uo(N.contextWindow)}))})},[l,Yt,mn,Ve,Ee]);function Ra(N){Ie(N),I(N,!1),E(null),A===N&&M(""),L===N&&P(""),G(se=>{if(!Object.prototype.hasOwnProperty.call(se,N))return se;let W={...se};return delete W[N],W}),p(se=>xe(se.filter(W=>W.key!==N)))}function Te(N){p(se=>xe(xs(se,N,W=>W?.key)))}function Ze(N){p(se=>xe(kf(se,N,W=>W?.key)))}function Ce(){H.current="",va(B.current,!1),B.current=null}async function Ge(N,{force:se=!1}={}){let W=String(N||"").trim();if(!W)return Rs({query:W});if(!se&&ft.current.has(W))return ft.current.get(W);if(!se&&X.current.has(W))return X.current.get(W);let Re=(async()=>{let ce=await su([W]),q=(Array.isArray(ce)?ce:[]).find(Be=>String(Be?.query||"").trim()===W)||{query:W},be=Rs(q,{fallbackQuery:W});return ft.current.set(W,be),be})();X.current.set(W,Re);try{return await Re}finally{X.current.delete(W)}}async function ao(N,{openMenu:se=!1,prefill:W=!1,modelId:Re=""}={}){let ce=ge.current.find(be=>be.key===N),q=String(Re||ce?.id||"").trim();if(!q)return null;se&&M(N),I(N,!0);try{let be=await Ge(q);if(w(Be=>({...Be,[N]:be})),W){let Be=Kf(be),Se=be?.exactMatch?.capabilities;(Be||Se)&&p(Le=>xe(Le.map(et=>{if(et.key!==N)return et;let we=String(et?.id||"").trim();if(!we||we!==q)return et;let ot={};return Be&&!String(et?.contextWindow||"").trim()&&(ot.contextWindow=Be),Se&&!eT(et.capabilities)&&(ot.capabilities=ZE(et.capabilities,Se)),Object.keys(ot).length>0?{...et,...ot}:et}),{preserveFocus:!1}))}return be}catch(be){let Be=be instanceof Error?be.message:String(be),Se={query:q,status:"error",error:Be,options:[]};return w(Le=>({...Le,[N]:Se})),Se}finally{I(N,!1)}}async function pn(N=[]){let se=new Set(Array.isArray(N)?N:[]),W=Ee.filter(Re=>!Re.id||String(Re?.contextWindow||"").trim()?!1:se.size===0?!0:se.has(Re.key)).map(Re=>({key:Re.key,id:Re.id}));if(W.length!==0){h(!0),E(null);try{let Re=await su(W.map(et=>et.id)),ce=KC(Re),q=new Map(W.map(et=>[et.key,et]));for(let et of ce.values())et?.query&&ft.current.set(et.query,et);let be=Array.isArray(ge.current)?ge.current:[],Be=0,Se=0,Le=be.map(et=>{let we=q.get(et.key);if(!we)return et;let ot=String(et?.id||"").trim(),Ln=String(et?.contextWindow||"").trim();if(!ot||ot!==we.id||Ln)return et;let Ea=ce.get(ot)||Rs({query:ot}),So=Kf(Ea);return So?(Be+=1,{...et,contextWindow:So}):(Se+=1,et)});p(xe(Le,{preserveFocus:!1})),E({tone:Be>0?"success":"warning",message:Be>0?`Filled ${Be} context size${Be===1?"":"s"}${Se>0?`; ${Se} still need a manual value`:""}.`:`Could not fill ${Se} model${Se===1?"":"s"}.`})}catch(Re){E({tone:"error",message:Re instanceof Error?Re.message:String(Re)})}finally{h(!1)}}}async function It(){if(Ve||mn||!Yt)return!1;let N=ho(e)==="api"&&Je.length>0;m(N?"testing":"saving");try{return await o(Ee.map(se=>({...se,contextWindow:Uo(se.contextWindow)})))}finally{m("")}}return(0,Ne.jsxs)("div",{className:F(a?"space-y-3 rounded-2xl border border-border/70 bg-background/60 p-4":"space-y-3"),children:[(0,Ne.jsx)("div",{className:"rounded-2xl border border-border/70 bg-secondary/35 px-4 py-3 text-sm leading-6 text-muted-foreground",children:"Direct routes follow this top-to-bottom order. Focus a context field to load suggested sizes, or use Fill missing context size to fill each empty row with a median size."}),(0,Ne.jsx)("div",{className:"space-y-2",children:f.map((N,se)=>{let W=String(N?.id||"").trim(),Re=String(N?.contextWindow||"").trim(),ce=!!W,q=ce?he.findIndex(we=>we.key===N.key):-1,be=x[N.key]||null,Be=!!g[N.key],Se=A===N.key&&!!W,Le=fn.has(N.key),et=W&&s?.[W]||"default";return(0,Ne.jsxs)("div",{ref:er(N.key),"data-reorder-row":"true",onDragOver:we=>{!Ve&&H.current&&H.current!==N.key&&(we.preventDefault(),we.dataTransfer.dropEffect="move")},onDrop:we=>{if(Ve)return;we.preventDefault();let ot=we.dataTransfer.getData("text/plain")||H.current;Ce(),p(Ln=>xe(_f(Ln,ot,N.key)))},className:F("space-y-2 rounded-xl border border-border/70 bg-card/90 p-3",ce?null:"border-dashed bg-background/85",Le?"border-amber-200 bg-amber-50/70":null,!Le&&et==="success"?"border-emerald-200 bg-emerald-50/70":null,!Le&&et==="error"?"border-rose-200 bg-rose-50/70":null,!Le&&et==="pending"?"border-sky-200 bg-sky-50/70":null),children:[(0,Ne.jsxs)("div",{className:"grid grid-cols-[auto_auto_auto_minmax(0,1fr)_minmax(12rem,14rem)_5.5rem] items-center gap-2",children:[(0,Ne.jsx)("span",{className:F("flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground",ce&&!Ve?"cursor-grab":"opacity-45"),draggable:!Ve&&ce,onDragStart:we=>{if(Ve||!ce)return;let ot=Ss(we.currentTarget);we.dataTransfer.effectAllowed="move",we.dataTransfer.setData("text/plain",N.key),ot&&typeof we.dataTransfer?.setDragImage=="function"&&we.dataTransfer.setDragImage(ot,20,20),Ce(),H.current=N.key,B.current=ot,va(ot,!0)},onDragEnd:Ce,title:ce?"Drag to reorder":"New model draft row",children:(0,Ne.jsx)(vs,{className:"h-4 w-4"})}),(0,Ne.jsx)(Sa,{disabled:Ve||!ce||q<=0,label:!ce||q<=0?"Already first":`Move ${N.id||`model ${q+1}`} up`,onClick:()=>Te(N.key)}),(0,Ne.jsx)(dl,{disabled:Ve||!ce||se>=Vn,label:!ce||se>=Vn?"Already last":`Move ${N.id||`model ${q+1}`} down`,onClick:()=>Ze(N.key)}),(0,Ne.jsx)(wt,{ref:we=>{we?j.current.set(N.key,we):j.current.delete(N.key)},value:N.id,onChange:we=>ue(N.key,{id:we.target.value},{clearLookupState:!0,closeLookupMenu:!0}),placeholder:ce?"Model id":"Add a new model id",disabled:Ve}),(0,Ne.jsxs)("div",{ref:we=>{we?J.current.set(N.key,we):J.current.delete(N.key)},className:"relative min-w-0",children:[(0,Ne.jsx)(wt,{value:L===N.key?D[N.key]??lu(N.contextWindow):HC(N.contextWindow),onChange:we=>{let ot=we.target.value,Ln=Uo(ot);G(Ea=>({...Ea,[N.key]:lu(Ln)})),ue(N.key,{contextWindow:Ln},{clearStatus:!1})},onBlur:we=>{P(ot=>ot===N.key?"":ot),G(ot=>{if(!Object.prototype.hasOwnProperty.call(ot,N.key))return ot;let Ln={...ot};return delete Ln[N.key],Ln}),ue(N.key,{contextWindow:Uo(we.target.value)},{clearStatus:!1})},onFocus:()=>{W&&(P(N.key),G(we=>({...we,[N.key]:lu(N.contextWindow)})),ao(N.key,{openMenu:!0}))},onClick:()=>{W&&ao(N.key,{openMenu:!0})},onKeyDown:we=>{if(we.key==="ArrowDown"&&W){we.preventDefault(),ao(N.key,{openMenu:!0});return}we.key==="Escape"&&(we.preventDefault(),M(""))},placeholder:"Context window",inputMode:"numeric",disabled:Ve||!W,className:"font-medium tabular-nums","aria-label":W?`Context window for ${W}`:"Context window"}),Se?(0,Ne.jsx)(Rm,{open:Se,anchorRef:{current:J.current.get(N.key)||null},preferredSide:"top",desiredHeight:224,className:"z-20 rounded-lg bg-background/98 p-2",onMouseDown:we=>we.preventDefault(),children:Be?(0,Ne.jsxs)("div",{className:"inline-flex items-center gap-2 px-1 py-2 text-sm text-muted-foreground",children:[(0,Ne.jsx)(Dr,{}),"Fetching size options for ",(0,Ne.jsx)("code",{children:W}),"."]}):be?.status==="error"?(0,Ne.jsx)("div",{className:"rounded-lg border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-900",children:be.error||"Could not load suggested sizes."}):be?.options?.length>0?(0,Ne.jsx)("div",{className:"space-y-1",children:be.options.map(we=>(0,Ne.jsxs)("button",{type:"button",className:"flex w-full flex-col gap-2 rounded-lg border border-border/70 bg-background px-3 py-2 text-left text-sm text-foreground transition hover:border-accent hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70",disabled:Ve,onMouseDown:ot=>ot.preventDefault(),onClick:()=>{G(ot=>({...ot,[N.key]:lu(we.contextWindow)})),ue(N.key,{contextWindow:String(we.contextWindow)},{clearStatus:!1}),M("")},title:`Use ${we.label}`,children:[(0,Ne.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,Ne.jsx)("div",{className:"break-words font-medium leading-5",children:we.label}),(0,Ne.jsx)("div",{className:"break-words text-xs leading-4 text-muted-foreground",children:we.detail})]}),(0,Ne.jsxs)("div",{className:"w-full rounded-md border border-border/70 bg-secondary/70 px-3 py-2",children:[(0,Ne.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Context size"}),(0,Ne.jsx)("div",{className:"mt-1 text-lg font-semibold leading-none tabular-nums text-foreground",children:gi(we.contextWindow)})]})]},we.key))}):(0,Ne.jsxs)("div",{className:"rounded-lg border border-dashed border-border/70 bg-background/80 px-3 py-2 text-xs text-muted-foreground",children:["No suggested size was found for ",(0,Ne.jsx)("code",{children:be?.query||W}),"."]})}):null]}),ce?(0,Ne.jsx)($,{type:"button",variant:"ghost",className:ys,onMouseDown:we=>we.preventDefault(),onClick:()=>Ra(N.key),disabled:Ve,children:"Remove"}):(0,Ne.jsx)($,{type:"button",variant:"ghost",className:F(ys,"pointer-events-none invisible"),tabIndex:-1,disabled:!0,"aria-hidden":"true",children:"Remove"})]}),ce&&(0,Ne.jsx)(tT,{capabilities:N.capabilities||{},disabled:Ve,onChange:(we,ot)=>{let Ln={...N.capabilities||{}};ot===void 0?delete Ln[we]:Ln[we]=ot,ue(N.key,{capabilities:Ln})}}),Be?(0,Ne.jsx)("div",{className:"flex justify-end text-xs",children:(0,Ne.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-sky-700",children:[(0,Ne.jsx)(Dr,{}),"Looking up sizes"]})}):null,Le?(0,Ne.jsxs)("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900",children:["Enter a positive integer like ",(0,Ne.jsx)("code",{children:"128000"}),", or leave the field blank."]}):et==="pending"?(0,Ne.jsx)("div",{className:"rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-xs text-sky-900",children:"Testing this model against the provider endpoint now."}):et==="success"?(0,Ne.jsx)("div",{className:"rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-900",children:"Confirmed by the latest live provider test."}):et==="error"?(0,Ne.jsx)("div",{className:"rounded-lg border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-900",children:"This model failed the latest live provider test."}):null]},N.key)})}),mn?(0,Ne.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:mn}):null,C?(0,Ne.jsx)("div",{className:F("rounded-xl px-3 py-2 text-sm",C.tone==="error"?"border border-rose-200 bg-rose-50 text-rose-900":C.tone==="warning"?"border border-amber-200 bg-amber-50 text-amber-900":"border border-emerald-200 bg-emerald-50 text-emerald-900"),children:C.message}):null,(0,Ne.jsx)("div",{className:F("sticky z-10 border-t border-border/70 bg-background/95 pt-3 backdrop-blur",a?"bottom-0":"bottom-0 -mx-5 rounded-b-[1rem] px-5 pb-4"),children:(0,Ne.jsxs)("div",{className:"flex min-h-9 items-center justify-between gap-3",children:[(0,Ne.jsx)("div",{className:F("text-xs",c==="testing"?"text-sky-700":c==="saving"?"text-foreground":"text-muted-foreground"),children:c==="testing"?(0,Ne.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,Ne.jsx)(Dr,{}),d||"Testing new models before save."]}):c==="saving"?(0,Ne.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,Ne.jsx)(Dr,{}),d||"Saving provider models."]}):Je.length>0&&ho(e)==="api"?`${Je.length} new model${Je.length===1?"":"s"} will be tested before save.`:"Existing models keep their current configuration metadata."}),(0,Ne.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[!t&&!Ve&&Ft.length>0?(0,Ne.jsx)($,{type:"button",variant:"outline",onClick:()=>{pn()},children:b?"Filling\u2026":"Fill missing context size"}):null,!t&&!Ve&&Yt?(0,Ne.jsx)($,{type:"button",variant:"ghost",onClick:()=>{y({}),w({}),E(null),M(""),ft.current.clear(),X.current.clear(),p(xe(u,{preserveFocus:!0}))},children:"Reset"}):null,!t&&Yt&&!mn?(0,Ne.jsx)($,{type:"button",onClick:()=>{It()},disabled:Ve,children:c==="testing"||v==="testing"?"Testing\u2026":c==="saving"||v==="saving"||r?"Saving\u2026":"Save models"}):null]})]})})]})}var le=_(Z(),1);function s5({provider:e,onRemove:t,onCopyModelId:n,onApplyProviderDetails:r,onApplyProviderModels:o,onSaveAndCloseEditor:a,disabledReason:i="",busy:l=!1}){let s=(0,Wt.useMemo)(()=>mC(e),[e]),[c,d]=(0,Wt.useState)(s),[u,f]=(0,Wt.useState)(!1),[p,v]=(0,Wt.useState)(!1),[m,b]=(0,Wt.useState)(!1),[h,g]=(0,Wt.useState)("provider"),[y,x]=(0,Wt.useState)(""),[w,C]=(0,Wt.useState)(0),[E,A]=(0,Wt.useState)({isDirty:!1,issue:"",locked:!1,rows:[]}),[M,L]=(0,Wt.useState)({phase:"",modelStates:{},failedModelIds:[],message:""}),P=(0,Wt.useRef)(null),D=(0,Wt.useRef)(null),G=(0,Wt.useRef)(null),ae=(0,Wt.useRef)(null);(0,Wt.useEffect)(()=>{d(s)},[s]);let j=ho(e)!=="api",J=(Array.isArray(e?.models)?e.models:[]).map(Te=>String(Te?.id||"").trim()).filter(Boolean),Q=ba(e),H=j?"":iC(e?.rateLimits),B=j?[]:Yn(c?.endpoints,c?.endpointDraft),ft=j?[]:gr(c?.rateLimitRows),X=JSON.stringify({id:String(c?.id||"").trim(),name:String(c?.name||"").trim(),credentialInput:String(c?.credentialInput||"").trim(),endpoints:B,endpointDraft:String(c?.endpointDraft||"").trim(),rateLimitRows:Qh(c?.rateLimitRows)}),je=JSON.stringify({id:String(s?.id||"").trim(),name:String(s?.name||"").trim(),credentialInput:String(s?.credentialInput||"").trim(),endpoints:pr(s?.endpoints),endpointDraft:String(s?.endpointDraft||"").trim(),rateLimitRows:Qh(s?.rateLimitRows)}),ie=X!==je,xe=!!i||l,Ie=new Set((Array.isArray(E.rows)?E.rows:[]).map(Te=>String(Te?.id||"").trim()).filter(Boolean)),I=M.failedModelIds.filter(Te=>Ie.has(Te)),ue=xe||M.phase==="testing"||M.phase==="saving",he=j?"":Lo(ft,{knownModelIds:J,requireAtLeastOne:!0}),_e=i||(String(c?.id||"").trim()?Xi.test(String(c?.id||"").trim())?String(c?.name||"").trim()?!j&&B.length===0?"Add at least one endpoint for API Key providers.":!j&&B.some(Te=>!fi(Te))?"All endpoints must start with http:// or https://.":he:"Provider name is required.":"Provider id must start with a letter and use lowercase letters, digits, or dashes only.":"Provider id is required."),Ee=j?c:{...c,endpoints:B,endpointDraft:""},ve=!!E.isDirty,Fe=ie||ve,Je=[ie?"provider settings":"",ve?"model list":""].filter(Boolean),Ht=[ie&&_e?`Provider: ${_e}`:"",ve&&E.issue?`Models: ${E.issue}`:""].filter(Boolean).join(" "),wn=xe||M.phase==="testing"||M.phase==="saving"||ie&&!!_e||ve&&(!!E.issue||E.locked)||typeof a!="function";async function fn(){let Te=await r(e.id,Ee);return Te&&Ve(),Te}async function Ft(Te){let Ze=await o(e.id,Te,{providerDraft:ie?Ee:null,onModelTestStateChange:Ce=>{L({phase:String(Ce?.phase||""),modelStates:Ce?.modelStates&&typeof Ce.modelStates=="object"?Ce.modelStates:{},failedModelIds:Array.isArray(Ce?.failedModelIds)?Ce.failedModelIds:[],message:String(Ce?.message||"")})}});return Ze&&Ve(),Ze}function Yt(){d(s)}let st=(0,Wt.useCallback)(Te=>{A(Te)},[]);function Ve(){v(!1),b(!1),f(!1),g("provider"),x(""),d(s),A({isDirty:!1,issue:"",locked:!1,rows:[]}),L({phase:"",modelStates:{},failedModelIds:[],message:""})}async function Vn(){let Te=(Array.isArray(E.rows)?E.rows:[]).filter(Ce=>!I.includes(String(Ce?.id||"").trim()));return Te.length===0&&!ie||await a(e.id,{providerDraft:ie?Ee:null,modelRows:ve?Te:null,onModelTestStateChange:Ce=>{L({phase:String(Ce?.phase||""),modelStates:Ce?.modelStates&&typeof Ce.modelStates=="object"?Ce.modelStates:{},failedModelIds:Array.isArray(Ce?.failedModelIds)?Ce.failedModelIds:[],message:String(Ce?.message||"")})}})?(Ve(),!0):(g("models"),!1)}(0,Wt.useEffect)(()=>{L({phase:"",modelStates:{},failedModelIds:[],message:""})},[s]),(0,Wt.useEffect)(()=>{I.length>0||!m||b(!1)},[I,m]),(0,Wt.useEffect)(()=>{if(!u||h!=="provider"||y!=="endpoint"&&y!=="rate-limit"||typeof window>"u")return;let Te=window.requestAnimationFrame(()=>{let Ze=y==="endpoint"?P.current:G.current,Ce=y==="endpoint"?D.current:ae.current;Ze?.scrollIntoView?.({block:"nearest"}),Ce?.focus?.(),Ce?.select?.(),x("")});return()=>window.cancelAnimationFrame(Te)},[u,h,y]);function mn(Te="provider",Ze=""){v(!1),b(!1),g(Te),x(Ze),Te==="models"&&Ze==="models"&&C(Ce=>Ce+1),f(!0)}function er(){if(!ue){if(I.length>0){v(!1),b(!0);return}if(Fe){v(!0);return}Ve()}}async function Ra(){if(wn)return;if(!await a(e.id,{providerDraft:ie?Ee:null,modelRows:ve?E.rows:null,onModelTestStateChange:Ze=>{L({phase:String(Ze?.phase||""),modelStates:Ze?.modelStates&&typeof Ze.modelStates=="object"?Ze.modelStates:{},failedModelIds:Array.isArray(Ze?.failedModelIds)?Ze.failedModelIds:[],message:String(Ze?.message||"")})}})){ve&&(v(!1),g("models"));return}Ve()}return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Gt,{children:(0,le.jsxs)(qt,{className:"space-y-3 p-5",children:[(0,le.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,le.jsx)("div",{className:"min-w-0 flex-1 px-0.5 py-0.5",children:(0,le.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[(0,le.jsx)("span",{className:"text-base font-semibold text-foreground",children:e.name||e.id}),(0,le.jsxs)("span",{className:"text-sm text-muted-foreground",children:["(",e.id,")"]})]})}),(0,le.jsxs)("div",{className:"flex items-start gap-2 self-start",children:[(0,le.jsxs)($,{type:"button",variant:"outline",size:"sm",className:"gap-1.5 normal-case tracking-normal",onClick:()=>mn("provider"),disabled:xe,"aria-label":`Edit provider ${e.name||e.id}`,title:"Edit provider",children:[(0,le.jsx)(bs,{className:"h-4 w-4 shrink-0"}),"Edit"]}),(0,le.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-8 w-8 shrink-0 p-0 text-muted-foreground hover:border-destructive/35 hover:bg-destructive/5 hover:text-destructive",onClick:()=>t(e.id),disabled:l,"aria-label":"Remove provider",title:"Remove provider",children:(0,le.jsx)(Qc,{className:"h-4 w-4"})})]})]}),J.length>0?(0,le.jsx)("div",{className:"flex flex-wrap gap-2 pt-1",children:J.map(Te=>(0,le.jsx)(FE,{onClick:()=>n?.(Te),title:`Copy model id ${Te}`,className:"max-w-full",children:(0,le.jsx)("span",{className:"truncate",children:Te})},`${e.id}-${Te}`))}):null]})}),(0,le.jsx)(Zn,{open:u,onClose:er,title:`Edit \xB7 ${e.id}`,description:M.phase==="testing"?M.message||"Testing new models before save.":M.phase==="saving"?M.message||"Saving provider changes.":"Switch between provider settings and model list. Each tab saves independently.",closeDisabled:ue,closeOnBackdrop:!ue,closeOnEscape:!ue,contentClassName:"max-h-[92vh] max-w-5xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)] pb-0",children:(0,le.jsxs)(fs,{value:h,onValueChange:g,children:[(0,le.jsxs)(ms,{className:"w-full justify-start",children:[(0,le.jsx)(dr,{value:"provider",children:"Provider"}),(0,le.jsx)(dr,{value:"models",children:"Model list"})]}),(0,le.jsxs)(fr,{forceMount:!0,value:"provider",className:F("space-y-4 pb-4",h!=="provider"?"hidden":null),children:[(0,le.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/60 p-4",children:(0,le.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Provider"}),(0,le.jsx)("div",{className:"mt-1 text-sm text-muted-foreground",children:"Update provider identity and connection settings here."})]}),(0,le.jsx)(ut,{variant:"outline",children:j?"Subscription":"API Key"})]})}),(0,le.jsxs)("div",{className:F("grid gap-3",j?"md:grid-cols-2":"md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]"),children:[(0,le.jsx)(pt,{label:"Provider name",stacked:!0,children:(0,le.jsx)(wt,{value:c.name,onChange:Te=>d(Ze=>({...Ze,name:Te.target.value})),disabled:ue})}),(0,le.jsx)(pt,{label:"Provider id",hint:"Used in direct routes like provider/model",stacked:!0,children:(0,le.jsx)(wt,{value:c.id,onChange:Te=>d(Ze=>({...Ze,id:Lr(Te.target.value)})),disabled:ue})})]}),j?null:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(pt,{label:"API key or env",hint:"Use an env var like OPENAI_API_KEY or paste the direct key.",stacked:!0,children:(0,le.jsx)(Is,{value:c.credentialInput||"",onChange:Te=>d(Ze=>({...Ze,credentialInput:Te.target.value})),disabled:ue,placeholder:"Example: OPENAI_API_KEY or sk-...",isEnvVar:go(c.credentialInput)})}),(0,le.jsx)("div",{ref:P,children:(0,le.jsx)(pt,{label:"Endpoints",hint:Q.length>1?"Comma, space, or newline turns into chips. The first endpoint stays active until you re-test this provider.":"Comma, space, or newline turns into chips.",stacked:!0,children:(0,le.jsx)(bu,{values:c.endpoints,onChange:Te=>d(Ze=>({...Ze,endpoints:Te})),draftValue:c.endpointDraft,onDraftValueChange:Te=>d(Ze=>({...Ze,endpointDraft:Te})),commitOnBlur:!0,disabled:ue,isValueValid:fi,inputRef:D,inputClassName:"placeholder:text-muted-foreground/55",placeholder:"Click here to type new endpoint",helperText:"Paste one or more endpoints"})})}),(0,le.jsx)("div",{ref:G,className:"grid gap-3 md:grid-cols-2 xl:grid-cols-[minmax(0,1.35fr)_minmax(0,0.8fr)_minmax(0,0.8fr)_minmax(0,1fr)]",children:(0,le.jsx)("div",{className:"md:col-span-2 xl:col-span-4",children:(0,le.jsx)(pt,{label:"Rate limit",stacked:!0,headerAction:(0,le.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:()=>d(Te=>({...Te,rateLimitRows:Tm(Te.rateLimitRows)})),disabled:ue,children:"Add rate limit"}),children:(0,le.jsx)(Mm,{rows:c.rateLimitRows,onChange:Te=>d(Ze=>({...Ze,rateLimitRows:Te})),availableModelIds:J,disabled:ue,inputRef:ae})})})})]}),_e?(0,le.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:_e}):null,(0,le.jsxs)("div",{className:"flex min-h-9 items-center justify-end gap-2",children:[!ue&&ie?(0,le.jsx)($,{type:"button",variant:"ghost",onClick:Yt,children:"Reset"}):null,ie&&!_e?(0,le.jsx)($,{type:"button",onClick:()=>{fn()},disabled:ue,children:M.phase==="saving"||l?"Saving\u2026":"Save provider"}):null]})]}),(0,le.jsx)(fr,{forceMount:!0,value:"models",className:F(h!=="models"?"hidden":null),children:(0,le.jsx)(nT,{provider:e,disabled:!!i,disabledReason:i,busy:l,framed:!1,focusRequest:w,onStateChange:st,onApply:Ft,testStateByModel:M.modelStates,savePhase:M.phase,saveMessage:M.message})})]})}),(0,le.jsx)(VE,{open:p,onKeepEditing:()=>v(!1),onDiscardAndClose:Ve,onSaveAndClose:Ra,saveDisabled:wn,dirtyLabels:Je,details:Ht}),(0,le.jsx)(HE,{open:m,failedModelIds:I,onKeepEditing:()=>b(!1),onRemoveFailedAndClose:Vn,removeDisabled:ue||typeof a!="function"})]})}function c5({providers:e,onRemove:t,onCopyModelId:n,onApplyProviderDetails:r,onApplyProviderModels:o,onSaveAndCloseEditor:a,disabledReason:i="",busy:l=!1}){return e.length?(0,le.jsx)("div",{className:"grid gap-4 xl:grid-cols-2",children:e.map(s=>(0,le.jsx)(s5,{provider:s,onRemove:t,onCopyModelId:n,onApplyProviderDetails:r,onApplyProviderModels:o,onSaveAndCloseEditor:a,disabledReason:i,busy:l},s.id))}):(0,le.jsx)(Gt,{children:(0,le.jsx)(qt,{className:"flex flex-col gap-4 p-5 text-sm text-muted-foreground",children:(0,le.jsx)("div",{children:"No enabled providers are configured yet. Use Add provider to create your first provider, model list, and rate limits."})})})}function rT({providers:e,onAddProvider:t,onRemove:n,onCopyModelId:r,onApplyProviderDetails:o,onApplyProviderModels:a,onSaveAndCloseEditor:i,disabledReason:l="",busy:s=!1}){return(0,le.jsxs)("section",{className:"rounded-2xl border border-border/70 bg-card p-4","aria-label":"Provider models",children:[(0,le.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,le.jsxs)("div",{className:"min-w-0",children:[(0,le.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Provider & Models"}),(0,le.jsx)("div",{className:"mt-1 text-sm text-muted-foreground",children:"Manage providers, direct model routes, endpoints, and rate limits in one place."})]}),(0,le.jsx)($,{onClick:t,children:"Add provider"})]}),(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(c5,{providers:e,onRemove:n,onCopyModelId:r,onApplyProviderDetails:o,onApplyProviderModels:a,onSaveAndCloseEditor:i,disabledReason:l,busy:s})})]})}var xu=_(me(),1);var ne=_(Z(),1);function oT({connected:e,snapshot:t,models:n,busy:r,refreshing:o,config:a,onRefresh:i,onLoad:l,onUnload:s,onPin:c,onKeepAlive:d,onContextLength:u,onAddToRouter:f,onRemoveFromRouter:p,onAutoLoad:v,onSaveSettings:m,onInstall:b,onStartServer:h,onStopServer:g,onSyncRouter:y}){let x=a?.ollama||{},[w,C]=(0,xu.useState)(x.baseUrl||"http://localhost:11434"),[E,A]=(0,xu.useState)(x.autoConnect!==!1),[M,L]=(0,xu.useState)(x.defaultKeepAlive||"5m"),P=t?.installed===!0;return(0,ne.jsxs)("div",{className:"space-y-4",children:[(0,ne.jsx)(Gt,{children:(0,ne.jsxs)(qt,{className:"p-4 space-y-3",children:[(0,ne.jsxs)("div",{className:"flex items-center justify-between",children:[(0,ne.jsxs)("div",{className:"flex items-center gap-2",children:[(0,ne.jsx)("h3",{className:"font-medium",children:"Ollama Connection"}),e?(0,ne.jsx)(ut,{variant:"success",children:"Connected"}):(0,ne.jsx)(ut,{variant:"outline",children:"Disconnected"})]}),(0,ne.jsxs)("div",{className:"flex gap-2",children:[!P&&(0,ne.jsx)($,{size:"sm",onClick:b,disabled:r._install,children:r._install?"Installing\u2026":"Install Ollama"}),P&&!e&&(0,ne.jsx)($,{size:"sm",onClick:h,disabled:r._startServer,children:r._startServer?"Starting\u2026":"Start Server"}),e&&(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:g,children:"Stop Server"})]})]}),t?.version&&(0,ne.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Version: ",t.version]})]})}),e&&(0,ne.jsx)(Gt,{children:(0,ne.jsxs)(qt,{className:"p-4 space-y-3",children:[(0,ne.jsxs)("div",{className:"flex items-center justify-between",children:[(0,ne.jsx)("h3",{className:"font-medium",children:"Models"}),(0,ne.jsxs)("div",{className:"flex gap-2",children:[(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:y,disabled:r._syncRouter,children:r._syncRouter?"Syncing\u2026":"Sync All to Router"}),(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:i,disabled:o,children:o?"Refreshing\u2026":"Reload Models"})]})]}),n.length===0&&!o&&(0,ne.jsxs)("p",{className:"text-sm text-muted-foreground",children:["No models found. Pull models with ",(0,ne.jsx)("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:"ollama pull <model>"})]}),(0,ne.jsx)("div",{className:"space-y-2",children:n.map(D=>(0,ne.jsx)(u5,{model:D,busy:r[D.name]||{},onLoad:l,onUnload:s,onPin:c,onKeepAlive:d,onContextLength:u,onAddToRouter:f,onRemoveFromRouter:p,onAutoLoad:v},D.name))})]})}),(0,ne.jsx)(Gt,{children:(0,ne.jsxs)(qt,{className:"p-4 space-y-3",children:[(0,ne.jsx)("h3",{className:"font-medium",children:"Settings"}),(0,ne.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("label",{className:"mb-1 block text-xs font-medium text-muted-foreground",children:"Base URL"}),(0,ne.jsx)(wt,{value:w,onChange:D=>C(D.target.value),placeholder:"http://localhost:11434"})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("label",{className:"mb-1 block text-xs font-medium text-muted-foreground",children:"Default Keep Alive"}),(0,ne.jsxs)(rn,{value:M,onValueChange:L,children:[(0,ne.jsx)(on,{children:(0,ne.jsx)(an,{})}),(0,ne.jsx)(ln,{children:$h.map(D=>(0,ne.jsx)(Dt,{value:D.value,children:D.label},D.value))})]})]})]}),(0,ne.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,ne.jsx)("label",{className:"text-sm text-foreground",children:"Auto-connect on startup"}),(0,ne.jsx)(Pc,{checked:E,onCheckedChange:A})]}),(0,ne.jsx)($,{size:"sm",onClick:()=>m({baseUrl:w,autoConnect:E,defaultKeepAlive:M}),children:"Save Settings"})]})})]})}function u5({model:e,busy:t,onLoad:n,onUnload:r,onPin:o,onKeepAlive:a,onContextLength:i,onAddToRouter:l,onRemoveFromRouter:s,onAutoLoad:c}){let[d,u]=(0,xu.useState)(e.contextLength||0);return(0,ne.jsxs)("div",{className:"rounded-lg border border-border p-3 space-y-2",children:[(0,ne.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,ne.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,ne.jsx)("span",{className:"font-mono text-sm font-medium",children:e.name}),(0,ne.jsx)(ut,{variant:"outline",children:e.parameterSize||"?"}),(0,ne.jsx)(ut,{variant:"outline",children:e.quantizationLevel||"?"}),e.loaded?(0,ne.jsxs)(ut,{variant:"success",children:["Loaded",e.sizeVramFormatted?` (${e.sizeVramFormatted})`:""]}):(0,ne.jsx)(ut,{variant:"default",children:"Available"}),e.isPinned&&(0,ne.jsx)(ut,{variant:"warning",children:"Pinned"})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.loaded?(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:()=>r(e.name),disabled:t.unloading,children:t.unloading?"Unloading\u2026":"Unload"}):(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:()=>n(e.name),disabled:t.loading,children:t.loading?"Loading\u2026":"Load"}),(0,ne.jsx)($,{size:"sm",variant:e.isPinned?"default":"outline",onClick:()=>o(e.name,!e.isPinned),disabled:t.pinning,title:e.isPinned?"Unpin (allow auto-unload)":"Pin in memory (blocks eviction)",children:e.isPinned?"Unpin":"Pin"}),e.inRouter?(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:()=>s(e.name),className:"text-red-600 hover:text-red-700",children:"Remove from Router"}):(0,ne.jsx)($,{size:"sm",variant:"default",onClick:()=>l(e.name),children:"Add to Router"})]})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-4 flex-wrap text-xs",children:[(0,ne.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ne.jsx)("label",{className:"text-muted-foreground whitespace-nowrap",children:"Keep Alive:"}),(0,ne.jsxs)(rn,{value:e.keepAlive||"5m",onValueChange:f=>a(e.name,f),children:[(0,ne.jsx)(on,{className:"h-7 w-[160px] text-xs",children:(0,ne.jsx)(an,{})}),(0,ne.jsx)(ln,{children:$h.map(f=>(0,ne.jsx)(Dt,{value:f.value,children:f.label},f.value))})]})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ne.jsx)("label",{className:"text-muted-foreground whitespace-nowrap",children:"Context:"}),(0,ne.jsx)(wt,{type:"number",className:"h-7 w-24 text-xs",value:d,onChange:f=>u(Number(f.target.value)),onBlur:()=>{d!==e.contextLength&&i(e.name,d)},min:0,step:1024}),e.contextLength>0&&(0,ne.jsxs)("span",{className:"text-muted-foreground",children:["max: ",e.contextLength.toLocaleString()]})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-2",children:[(0,ne.jsx)(Pc,{checked:e.autoLoad,onCheckedChange:f=>c(e.name,f)}),(0,ne.jsx)("label",{className:"text-muted-foreground",children:"Auto-load on start"})]}),e.estimatedVram&&(0,ne.jsxs)("span",{className:"text-muted-foreground",children:["Est. VRAM: ",e.estimatedVram]})]})]})}var Nm=_(me(),1);var re=_(Z(),1);function d5(e=[]){let t=[],n=new Map,r=null;for(let o of(Array.isArray(e)?e:[]).filter(Boolean)){let a=String(o?.groupKey||o?.groupLabel||"").trim(),i=String(o?.groupLabel||"").trim();if(!a){r||(r={key:"__ungrouped__",label:"",options:[]},t.push(r)),r.options.push(o);continue}let l=n.get(a);l||(l={key:a,label:i||a,options:[]},n.set(a,l),t.push(l)),l.options.push(o)}return t}function f5(e={},{includeHint:t=!1}={}){let n=String(e?.label||e?.value||"").trim()||String(e?.value||"").trim(),r=String(e?.hint||"").trim();return t&&r?`${n} \xB7 ${r}`:n}function aT(e=[],{keyPrefix:t="select-option",includeHint:n=!1}={}){return d5(e).map((r,o)=>{let a=r.options.map(i=>(0,re.jsx)(Dt,{value:i.value,searchText:`${i.label||""} ${i.value||""} ${i.hint||""} ${r.label||""}`,children:f5(i,{includeHint:n})},`${t}-${i.value}`));return r.label?(0,re.jsxs)(ul,{children:[(0,re.jsx)(Ls,{children:r.label}),a]},`${t}-group-${r.key||o}`):a})}function m5({className:e=""}){return(0,re.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,re.jsx)("path",{d:"M10 2.75 4.75 5v4.12c0 3.42 2.1 6.58 5.25 7.88 3.15-1.3 5.25-4.46 5.25-7.88V5L10 2.75Z"}),(0,re.jsx)("circle",{cx:"10",cy:"9",r:"1.4"}),(0,re.jsx)("path",{d:"M10 10.4v2.1"})]})}function iT({rows:e,routeOptions:t,webSearchSnapshot:n,ampClientUrl:r,ampClientGlobal:o,routingBusy:a,onToggleGlobalRouting:i,onInboundChange:l,onOutboundChange:s,onCreateEntry:c,onRemoveEntry:d,onOpenWebSearchTab:u,onOpenConfigPath:f,onOpenSecretsPath:p,hasMasterKey:v,disabledReason:m,autosaveState:b}){let[h,g]=(0,Nm.useState)(!1),[y,x]=(0,Nm.useState)(""),[w,C]=(0,Nm.useState)(String(t[0]?.value||"").trim()),E=e.some(H=>String(H?.inbound||"").trim()===String(y||"").trim()&&String(y||"").trim()),A=String(y||"").trim()&&String(w||"").trim()&&!E,M=o?.routedViaRouter===!0,L=String(o?.error||"").trim(),P=!!(v&&r&&!m&&!L),D=Number(n?.configuredProviderCount)||0,G=M&&D===0,ae=m?"warning":b.status==="error"?"danger":b.status==="pending"?"outline":b.status==="saving"?"info":b.savedAt?"success":"outline",ge=m?"Needs review":b.status==="error"?"Save failed":b.status==="pending"?"Unsaved":b.status==="saving"?"saving...":b.savedAt?"Saved":"Ready",j=m||(b.status==="error"?b.message:b.status==="pending"?"Unsaved changes queued. Auto-save will run shortly.":b.status==="saving"?"Saving changes...":b.savedAt?`Last saved ${As(b.savedAt)}.`:"AMP route changes auto-save after valid edits.");async function J(){!A||await c?.({inbound:y,outbound:w})===!1||(g(!1),x(""),C(String(t[0]?.value||"").trim()))}function Q(){g(!0),x(""),C(String(t[0]?.value||"").trim())}return(0,re.jsx)("div",{className:"grid gap-4",children:(0,re.jsxs)(Gt,{children:[(0,re.jsxs)(Qr,{className:"flex flex-col gap-3 p-4 pb-0 sm:flex-row sm:items-start sm:justify-between",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(_o,{className:"flex items-center gap-2",children:(0,re.jsx)("span",{children:"Use AMP via LLM Router"})}),(0,re.jsx)(Em,{primaryLabel:"Config file",primaryValue:o?.settingsFilePath||"",onOpenPrimary:f,secondaryLabel:"Secrets file",secondaryValue:o?.secretsFilePath||"",secondaryIcon:(0,re.jsx)(m5,{className:"h-3 w-3"}),onOpenSecondary:p})]}),(0,re.jsx)("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:(0,re.jsx)($,{type:"button",size:"sm",variant:M?"outline":void 0,onClick:i,disabled:a!==""||!M&&!P,children:a==="enable"?"Connecting\u2026":a==="disable"?"Disconnecting\u2026":M?"Disconnect":"Connect"})})]}),(0,re.jsxs)(qt,{className:"space-y-4 p-4",children:[L?(0,re.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:L}):null,!M&&!v?(0,re.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:["Set ",(0,re.jsx)("code",{children:"masterKey"})," first to connect AMP."]}):null,G?(0,re.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:[(0,re.jsx)("div",{className:"max-w-3xl",children:"AMP is connected, but no alternative web search provider is configured. AMP web search is only available through the shared Web Search tab."}),(0,re.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:u,children:"Open Web Search"})]}):null,m?(0,re.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:m}):(0,re.jsxs)("div",{className:"space-y-3 rounded-2xl border border-border/70 bg-background/60 p-4",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Route mapping editor"}),(0,re.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:"Map built-in AMP route keys and wildcard model matches to managed routes."})]}),(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,re.jsx)(ut,{variant:ae,children:ge}),(0,re.jsxs)(ut,{variant:"outline",children:[e.length," routes"]}),(0,re.jsx)($,{type:"button",size:"sm",onClick:Q,children:"Add custom mapping"})]})]}),(0,re.jsx)("div",{className:"text-xs text-muted-foreground",children:j}),h?(0,re.jsx)("div",{className:"rounded-2xl border border-dashed border-border bg-background/80 p-3",children:(0,re.jsxs)("div",{className:"grid gap-3 xl:grid-cols-[160px_minmax(0,1fr)_minmax(0,1fr)] xl:items-start",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Add custom mapping"}),(0,re.jsx)(ut,{variant:"info",children:"Custom"})]}),(0,re.jsxs)("div",{className:"text-xs leading-5 text-muted-foreground",children:["Match a built-in AMP route key like ",(0,re.jsx)("code",{children:"smart"})," or a wildcard such as ",(0,re.jsx)("code",{children:"gpt-*-codex*"}),", then send it to any managed route."]}),(0,re.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,re.jsx)($,{type:"button",size:"sm",onClick:J,disabled:!A,children:"Create mapping"}),(0,re.jsx)($,{type:"button",size:"sm",variant:"ghost",onClick:()=>g(!1),children:"Close"})]})]}),(0,re.jsx)(pt,{label:"Inbound match",hint:"Built-in route key or AMP model pattern",children:(0,re.jsx)(wt,{value:y,onChange:H=>x(H.target.value),placeholder:"smart or gpt-*-codex*"})}),(0,re.jsx)(pt,{label:"Route target",hint:"Alias or provider/model route in LLM Router",children:(0,re.jsxs)(rn,{value:w||void 0,onValueChange:C,children:[(0,re.jsx)(on,{children:(0,re.jsx)(an,{placeholder:"Select local route"})}),(0,re.jsx)(ln,{children:aT(t,{keyPrefix:"amp-route-create",includeHint:!0})})]})})]})}):null,(0,re.jsx)("div",{className:"space-y-2",children:e.map(H=>(0,re.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/75 p-3",children:(0,re.jsxs)("div",{className:"grid gap-3 xl:grid-cols-[160px_minmax(0,1fr)_minmax(0,1fr)] xl:items-start",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-foreground",children:H.label}),H.isCustom?(0,re.jsx)(ut,{variant:"info",children:"Custom"}):null]}),(0,re.jsx)("div",{className:"text-xs leading-5 text-muted-foreground",children:H.description}),H.removable?(0,re.jsx)($,{type:"button",size:"sm",variant:"ghost",onClick:()=>d(H.id),children:"Remove"}):null]}),(0,re.jsx)(pt,{label:"Inbound wildcard",hint:H.defaultMatch?`Default: ${H.defaultMatch}`:"AMP model pattern",children:(0,re.jsx)(Am,{commitOnBlur:!0,value:H.inbound,onValueCommit:B=>l(H.id,B),placeholder:H.defaultMatch||"gpt-*-codex*",onKeyDown:B=>{B.key==="Enter"&&(B.preventDefault(),B.currentTarget.blur())}})}),(0,re.jsx)(pt,{label:"Target route",hint:"Alias or provider/model route",children:(0,re.jsxs)(rn,{value:H.outbound||"__default__",onValueChange:B=>s(H.id,B),children:[(0,re.jsx)(on,{children:(0,re.jsx)(an,{placeholder:H.removable?"Choose target route":"Use default route"})}),(0,re.jsxs)(ln,{children:[H.removable?null:(0,re.jsx)(Dt,{value:"__default__",children:"Use default route"}),aT(t,{keyPrefix:`amp-route-${H.id}`,includeHint:!0})]})]})})]})},H.id))})]})]})]})})}var Ca=_(me(),1);var Y=_(Z(),1);function p5({className:e=""}){return(0,Y.jsxs)("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:e,children:[(0,Y.jsx)("path",{d:"M8 3.5v9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),(0,Y.jsx)("path",{d:"M3.5 8h9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function g5({open:e=!1,onClose:t=()=>{},candidates:n=[],onTestAndAdd:r=async()=>{},disabledReason:o=""}){let[a,i]=(0,Ca.useState)(""),[l,s]=(0,Ca.useState)(""),[c,d]=(0,Ca.useState)(!1),[u,f]=(0,Ca.useState)(""),p=Array.isArray(n)?n:[],v=p.find(y=>y.providerId===a)||p[0]||null,m=Array.isArray(v?.models)?v.models:[];(0,Ca.useEffect)(()=>{if(!e){d(!1),f("");return}let y=p[0]?.providerId||"";i(x=>p.some(C=>C.providerId===x)?x:y)},[e,p]),(0,Ca.useEffect)(()=>{let y=m[0]?.value||"";s(x=>m.some(C=>C.value===x)?x:y)},[m]);let b=mi(a,l),h=e&&!c&&!o&&a&&l;async function g(){if(h){d(!0),f("");try{await r({providerId:a,modelId:l}),t()}catch(y){f(y instanceof Error?y.message:String(y))}finally{d(!1)}}}return(0,Y.jsx)(Zn,{open:e,onClose:()=>{c||t()},title:"Add ChatGPT Search Endpoint",description:"Choose a configured OpenAI-compatible GPT route. Test runs a live Responses API request with the native web search tool, then saves the route on success.",contentClassName:"max-h-[92vh] max-w-3xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",showCloseButton:!1,footer:(0,Y.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,Y.jsx)($,{type:"button",variant:"ghost",onClick:t,disabled:c,children:"Cancel"}),(0,Y.jsx)($,{type:"button",onClick:()=>{g()},disabled:!h,children:c?"Testing\u2026":"Test connection"})]}),children:(0,Y.jsxs)("div",{className:"space-y-4",children:[o?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:o}):null,!o&&p.length===0?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:"No configured OpenAI-compatible GPT providers are available yet. Add a provider with a GPT model first."}):null,p.length>0?(0,Y.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,Y.jsx)(pt,{label:"Provider",hint:"Configured provider or ChatGPT subscription",stacked:!0,children:(0,Y.jsxs)(rn,{value:a||void 0,onValueChange:i,disabled:c||!!o,children:[(0,Y.jsx)(on,{children:(0,Y.jsx)(an,{placeholder:"Choose provider"})}),(0,Y.jsx)(ln,{children:p.map(y=>(0,Y.jsx)(Dt,{value:y.providerId,children:y.providerLabel},y.providerId))})]})}),(0,Y.jsx)(pt,{label:"GPT model",hint:"Only GPT models on OpenAI-compatible routes are listed",stacked:!0,children:(0,Y.jsxs)(rn,{value:l||void 0,onValueChange:s,disabled:c||!!o||m.length===0,children:[(0,Y.jsx)(on,{children:(0,Y.jsx)(an,{placeholder:"Choose model"})}),(0,Y.jsx)(ln,{children:m.map(y=>(0,Y.jsx)(Dt,{value:y.value,children:y.label},y.routeId))})]})})]}):null,b?(0,Y.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-4 py-3",children:[(0,Y.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Saved route id"}),(0,Y.jsx)("div",{className:"mt-1 text-sm font-medium text-foreground",children:b}),(0,Y.jsx)("div",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:"This route stores only the provider/model reference. No separate API key or quota is saved here."})]}):null,u?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:u}):null]})})}function lT({webSearchConfig:e,webSearchProviders:t,hostedSearchCandidates:n,onWebSearchStrategyChange:r,onWebSearchProviderChange:o,onWebSearchProviderMove:a,onRemoveWebSearchProvider:i,onAddHostedSearchEndpoint:l,disabledReason:s,autosaveState:c}){let[d,u]=(0,Ca.useState)(!1),f=String(e?.strategy||"ordered").trim()==="quota-balance"?"quota-balance":"ordered",p=Array.isArray(n)&&n.some(m=>Array.isArray(m?.models)&&m.models.length>0),v=s||(c.status==="error"?c.message:c.status==="pending"?"Unsaved changes queued. Auto-save will run shortly.":c.status==="saving"?"Saving changes...":c.savedAt?`Last saved ${As(c.savedAt)}.`:"");return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(Gt,{children:[(0,Y.jsxs)(Qr,{className:"flex flex-col gap-4 p-4 pb-0 xl:flex-row xl:items-start xl:justify-between",children:[(0,Y.jsxs)("div",{className:"space-y-1",children:[(0,Y.jsx)(_o,{children:"Web Search"}),(0,Y.jsx)(li,{className:"text-xs leading-5",children:"Shared web search routing for AMP and other router-managed tools."}),v?(0,Y.jsx)("div",{className:"text-xs text-muted-foreground",children:v}):null]}),(0,Y.jsxs)("div",{className:"flex w-full shrink-0 flex-wrap items-end justify-end gap-3 xl:w-auto",children:[(0,Y.jsxs)("div",{className:"min-w-[12rem] space-y-1",children:[(0,Y.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Routing strategy"}),(0,Y.jsxs)(rn,{value:f,onValueChange:r,disabled:!!s,children:[(0,Y.jsx)(on,{children:(0,Y.jsx)(an,{placeholder:"Choose strategy"})}),(0,Y.jsx)(ln,{children:FA.map(m=>(0,Y.jsx)(Dt,{value:m.value,children:m.label},m.value))})]})]}),(0,Y.jsxs)($,{type:"button",variant:"outline",className:"gap-2",onClick:()=>u(!0),disabled:!!s||!p,children:[(0,Y.jsx)(p5,{className:"h-3.5 w-3.5"}),(0,Y.jsx)("span",{children:"Endpoint"})]})]})]}),(0,Y.jsx)(qt,{className:"space-y-4 p-4",children:(0,Y.jsx)("div",{className:"space-y-3",children:(t||[]).map(m=>{if(m.kind==="hosted"){let g=m.runtimeState&&m.runtimeState.ready===!1?"This provider/model route is no longer available or is not OpenAI-compatible.":"";return(0,Y.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-4",children:(0,Y.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,Y.jsxs)("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-start xl:justify-between",children:[(0,Y.jsxs)("div",{className:"min-w-0",children:[(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,Y.jsx)(ev,{active:m.active}),(0,Y.jsx)("div",{className:"text-sm font-medium text-foreground",children:m.label}),(0,Y.jsx)(ut,{variant:"outline",children:"GPT Search"})]}),(0,Y.jsx)("div",{className:"mt-1 text-xs break-all text-muted-foreground",children:m.routeId}),(0,Y.jsx)("div",{className:"mt-2 text-xs leading-5 text-muted-foreground",children:"Uses the provider's native OpenAI Responses web search tool. No local API key or quota is stored here."})]}),(0,Y.jsxs)("div",{className:"flex items-center gap-2 self-start",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2 rounded-xl border border-border/70 bg-background/70 p-1",children:[(0,Y.jsx)(Sa,{disabled:!!s||m.displayIndex<=0,label:`Move ${m.routeId} up`,onClick:()=>a(m.id,"up")}),(0,Y.jsx)(dl,{disabled:!!s||m.displayIndex>=m.displayCount-1,label:`Move ${m.routeId} down`,onClick:()=>a(m.id,"down")})]}),(0,Y.jsx)($,{type:"button",size:"sm",variant:"ghost",onClick:()=>i(m.id),disabled:!!s,children:"Remove"})]})]}),g?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:g}):null]})},m.key)}let b=m.credentialField,h=String(m?.credentialValue||"").trim();return(0,Y.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-4",children:(0,Y.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,Y.jsxs)("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-start xl:justify-between",children:[(0,Y.jsx)("div",{className:"min-w-0",children:(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,Y.jsx)(ev,{active:m.active}),(0,Y.jsx)("div",{className:"text-sm font-medium text-foreground",children:m.label})]})}),(0,Y.jsxs)("div",{className:"flex items-center gap-2 self-start rounded-xl border border-border/70 bg-background/70 p-1",children:[(0,Y.jsx)(Sa,{disabled:!!s||m.displayIndex<=0,label:`Move ${m.label} up`,onClick:()=>a(m.id,"up")}),(0,Y.jsx)(dl,{disabled:!!s||m.displayIndex>=m.displayCount-1,label:`Move ${m.label} down`,onClick:()=>a(m.id,"down")})]})]}),(0,Y.jsxs)("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,0.9fr)_minmax(0,1.35fr)]",children:[(0,Y.jsx)(pt,{label:m.credentialLabel,hint:m.credentialField==="url"?"Required to enable this backend.":"Required to enable this backend. Stored in router config.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Is,{buffered:!0,value:h,placeholder:m.credentialPlaceholder,onValueChange:g=>o(m.id,b,g),disabled:!!s,isEnvVar:m.credentialField==="url"})}),(0,Y.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,Y.jsx)(pt,{label:"Result per call",hint:"Empty keeps the default of 5.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Cm,{value:m.resultPerCallInput,placeholder:"Default: 5",allowEmptyCommit:!0,onValueChange:g=>o(m.id,"count",g),disabled:!!s})}),(0,Y.jsx)(pt,{label:"Monthly limit",hint:"0 keeps quotas self-managed.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Cm,{value:String(m.limit||0),onValueChange:g=>o(m.id,"limit",g),disabled:!!s})}),(0,Y.jsx)(pt,{label:"Synced remaining",hint:"Adjust after manual upstream sync.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Cm,{value:String(m.remaining||0),onValueChange:g=>o(m.id,"remaining",g),disabled:!!s})})]})]})]})},m.key)})})})]}),(0,Y.jsx)(g5,{open:d,onClose:()=>u(!1),candidates:n,onTestAndAdd:l,disabledReason:s})]})}var Su=_(me(),1);var S=_(Z(),1);function h5(e=""){let t=String(e||"").trim();if(!t)return{};let n=Cf(t);if(n?.kind==="alias")return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};if(n?.kind==="model"&&n.providerId)return{kind:"model",providerId:n.providerId,groupKey:`provider:${n.providerId}`,groupLabel:n.providerId};if(n?.kind==="model")return{kind:"model",groupKey:"llm-router",groupLabel:"LLM Router"};let r=t.startsWith("alias:")?t.slice(6).trim():t;if(!r.includes("/"))return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};let o=r.indexOf("/"),a=r.slice(0,o).trim();return a?{kind:"model",providerId:a,groupKey:`provider:${a}`,groupLabel:a}:{}}function y5(e=[],t=[]){let n=[...Array.isArray(e)?e:[]],r=new Set(n.map(o=>String(o?.value||"").trim()).filter(Boolean));for(let o of(Array.isArray(t)?t:[]).map(a=>String(a||"").trim()).filter(Boolean))r.has(o)||(r.add(o),n.push({value:o,label:o,hint:"Current config",...h5(o)}));return n}function v5(e=[]){let t=[],n=new Map,r=null;for(let o of(Array.isArray(e)?e:[]).filter(Boolean)){let a=String(o?.groupKey||o?.groupLabel||"").trim(),i=String(o?.groupLabel||"").trim();if(!a){r||(r={key:"__ungrouped__",label:"",options:[]},t.push(r)),r.options.push(o);continue}let l=n.get(a);l||(l={key:a,label:i||a,options:[]},n.set(a,l),t.push(l)),l.options.push(o)}return t}function b5(e={},{includeHint:t=!1}={}){let n=String(e?.label||e?.value||"").trim()||String(e?.value||"").trim(),r=String(e?.hint||"").trim();return t&&r?`${n} \xB7 ${r}`:n}function x5(e=[],{keyPrefix:t="select-option",includeHint:n=!1}={}){return v5(e).map((r,o)=>{let a=r.options.map(i=>(0,S.jsx)(Dt,{value:i.value,searchText:`${i.label||""} ${i.value||""} ${i.hint||""} ${r.label||""}`,children:b5(i,{includeHint:n})},`${t}-${i.value}`));return r.label?(0,S.jsxs)(ul,{children:[(0,S.jsx)(Ls,{children:r.label}),a]},`${t}-group-${r.key||o}`):a})}function S5({className:e=""}){return(0,S.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,S.jsx)("path",{d:"M6 3.5h5.25L15 7.25V16A1.5 1.5 0 0 1 13.5 17.5h-7A1.5 1.5 0 0 1 5 16V5A1.5 1.5 0 0 1 6.5 3.5H6Z"}),(0,S.jsx)("path",{d:"M11 3.5V7.5H15"}),(0,S.jsx)("path",{d:"M7 12.25a3 3 0 1 1 2.85 2.99"}),(0,S.jsx)("path",{d:"M8.5 10.25h1.5v1.5"})]})}function cT({bindingValue:e="",thinkingLevel:t="",configFilePath:n="",endpointUrl:r=""}={}){let o=String(e||"").trim(),a=String(t||"").trim(),i=String(n||"").trim(),l=String(r||"").trim(),s=Af(o),c=s?"Mode: Inherit Codex model":o?`Mode: Pinned to ${o}`:"Mode: Choose a route",d=s?{variant:"success",title:"Inherit mode keeps Codex-native model picks intact.",body:(0,S.jsxs)(S.Fragment,{children:["Codex CLI still chooses its own model name. Create a same-name alias in the ",(0,S.jsx)("span",{className:"font-medium",children:"Alias & Fallback"})," tab so LLM Router can resolve that name to the real upstream target you want."]})}:o?{variant:"info",title:"Pinned mode forces one router target.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router writes ",(0,S.jsxs)("code",{children:["model=",o]})," into Codex CLI config. That is the simplest setup when every Codex session should use one managed route or alias."]})}:{variant:"warning",title:"Choose your model strategy before you connect.",body:(0,S.jsxs)(S.Fragment,{children:["Pick ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"})," if Codex should keep using its built-in model names, or pick one managed route/alias if you want a single fixed target."]})};return{title:"Codex CLI guide",description:"Quick setup for routing Codex CLI through LLM Router while keeping model routing easy to inspect and change later.",badges:[{label:c,variant:s?"success":o?"info":"outline"},{label:a?`Thinking: ${a}`:"Thinking: Codex default",variant:"outline"},{label:i?"Config file detected":"User config: ~/.codex/config.toml",variant:"outline"}],callout:d,highlights:[{eyebrow:"1. Connect",title:"Point Codex CLI at LLM Router",body:l?(0,S.jsxs)(S.Fragment,{children:["When connected, Codex sends requests to ",(0,S.jsx)("code",{children:l}),". LLM Router then handles upstream auth, alias resolution, and failover."]}):(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch Codex CLI so it talks to LLM Router instead of a provider directly."]})},{eyebrow:"2. Route",title:"Choose between inherit and pinned mode",body:s?(0,S.jsxs)(S.Fragment,{children:["Keep Codex model names such as ",(0,S.jsx)("code",{children:"gpt-5.4"}),", then create matching aliases in LLM Router, for example ",(0,S.jsx)("code",{children:"gpt-5.4"})," -> ",(0,S.jsx)("code",{children:"demo/gpt-4o-mini"}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Select one managed route or alias in ",(0,S.jsx)("span",{className:"font-medium",children:"Default model"})," when you want every Codex request to land on the same router target."]})},{eyebrow:"3. Tune",title:"Optional reasoning control",body:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("span",{className:"font-medium",children:"Thinking level"})," writes Codex CLI ",(0,S.jsx)("code",{children:"model_reasoning_effort"})," with the official values ",(0,S.jsx)("code",{children:"minimal"}),", ",(0,S.jsx)("code",{children:"low"}),", ",(0,S.jsx)("code",{children:"medium"}),", ",(0,S.jsx)("code",{children:"high"}),", or ",(0,S.jsx)("code",{children:"xhigh"}),"."]})}],sections:[{title:"Quick start",items:[(0,S.jsxs)(S.Fragment,{children:["Set a ",(0,S.jsx)("code",{children:"masterKey"})," in LLM Router first. The ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," button stays disabled until gateway auth is ready."]}),(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch the Codex CLI config file and router base URL."]}),s?(0,S.jsxs)(S.Fragment,{children:["Leave ",(0,S.jsx)("span",{className:"font-medium",children:"Default model"})," on ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"}),", then create aliases that match the Codex model names you actually use."]}):o?(0,S.jsxs)(S.Fragment,{children:["Your current default is pinned to ",(0,S.jsx)("code",{children:o}),". Change it only when you want Codex to use a different managed route or alias."]}):(0,S.jsxs)(S.Fragment,{children:["Choose either ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"})," or one managed route/alias in ",(0,S.jsx)("span",{className:"font-medium",children:"Default model"})," before you start using Codex through the router."]}),(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Thinking level"})," only when you want LLM Router to write ",(0,S.jsx)("code",{children:"model_reasoning_effort"}),"; leave it unset to keep Codex CLI defaults."]})]},{title:"Choose the right model strategy",items:[(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"})," when you want Codex-native model names and model-specific UI/options to remain visible."]}),(0,S.jsx)(S.Fragment,{children:"Use a fixed route or alias when your team wants one centrally managed target regardless of what Codex would otherwise choose."}),(0,S.jsx)(S.Fragment,{children:"If Codex-specific options disappear after pinning a route, switch back to inherit mode and route those same model names through aliases instead."})]},{title:"Where these settings land",items:[i?(0,S.jsxs)(S.Fragment,{children:["This page is currently managing ",(0,S.jsx)("code",{children:i}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Codex CLI usually stores user settings in ",(0,S.jsx)("code",{children:"~/.codex/config.toml"}),". Trusted projects can also add overrides in ",(0,S.jsx)("code",{children:".codex/config.toml"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The router-managed bindings in this panel map to Codex CLI ",(0,S.jsx)("code",{children:"model"})," and ",(0,S.jsx)("code",{children:"model_reasoning_effort"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Open Codex CLI Config File"})," whenever you want to inspect the exact generated config."]})]},{title:"Quick verify",items:[(0,S.jsx)(S.Fragment,{children:"Open the config file from this page and confirm the values match the mode you intended."}),(0,S.jsx)(S.Fragment,{children:"Start Codex CLI and run a small prompt. If inherit mode is on, make sure the Codex model you selected has a same-name alias in LLM Router."}),(0,S.jsxs)(S.Fragment,{children:["If requests fail after switching models, check the ",(0,S.jsx)("span",{className:"font-medium",children:"Alias & Fallback"})," tab first because the alias behind that model name may be missing or pointed at the wrong target."]})]}]}}function uT({bindings:e={},settingsFilePath:t="",endpointUrl:n=""}={}){let r=String(e?.primaryModel||"").trim(),o=String(e?.defaultOpusModel||"").trim(),a=String(e?.defaultSonnetModel||"").trim(),i=String(e?.defaultHaikuModel||"").trim(),l=String(e?.subagentModel||"").trim(),s=OA(e?.thinkingLevel),c=String(t||"").trim(),d=String(n||"").trim(),u=[r,o,a,i,l,s].filter(Boolean).length,f=r?{variant:"info",title:"Primary model override is active.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router is currently writing ",(0,S.jsxs)("code",{children:["ANTHROPIC_MODEL=",r]}),". Leave that field blank if you want Claude Code to keep choosing its own primary model."]})}:u>0?{variant:"info",title:"Only filled fields are overridden.",body:(0,S.jsx)(S.Fragment,{children:"Claude Code continues to inherit its normal defaults for every blank field. This is useful when you only want to steer alias models, subagents, or effort level through LLM Router."})}:{variant:"success",title:"Blank fields are a valid setup.",body:(0,S.jsx)(S.Fragment,{children:"You do not need to fill every binding. Leave fields empty unless you want LLM Router to override that specific Claude Code setting."})};return{title:"Claude Code guide",description:"Quick setup for routing Claude Code through LLM Router while keeping only the model and effort level overrides you actually want.",badges:[{label:u>0?`${u} override${u===1?"":"s"} active`:"No router overrides",variant:u>0?"info":"outline"},{label:s?`Effort: ${s}`:"Effort: Claude adaptive default",variant:"outline"},{label:c?"Settings file detected":"Settings scope: local/project/user",variant:"outline"}],callout:f,highlights:[{eyebrow:"1. Connect",title:"Point Claude Code at the router",body:d?(0,S.jsxs)(S.Fragment,{children:["When connected, Claude Code sends requests to ",(0,S.jsx)("code",{children:d}),". LLM Router then handles upstream auth, route selection, and failover."]}):(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch Claude Code so it uses the router Anthropic endpoint instead of a provider directly."]})},{eyebrow:"2. Override",title:"Set only the bindings you need",body:(0,S.jsxs)(S.Fragment,{children:["Leave fields blank to inherit Claude Code defaults. Fill ",(0,S.jsx)("code",{children:"ANTHROPIC_MODEL"}),", the Opus/Sonnet/Haiku defaults, or ",(0,S.jsx)("code",{children:"CLAUDE_CODE_SUBAGENT_MODEL"})," only when you want LLM Router to manage those values."]})},{eyebrow:"3. Effort",title:"Set thinking effort level",body:(0,S.jsxs)(S.Fragment,{children:["The ",(0,S.jsx)("span",{className:"font-medium",children:"Effort level"})," dropdown writes ",(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"})," to your shell profile. If the shell profile cannot be updated, ",(0,S.jsx)("code",{children:"effortLevel"})," is set in ",(0,S.jsx)("code",{children:"settings.json"}),' as a fallback (only "high" is supported there).']})}],sections:[{title:"Quick start",items:[(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch Claude Code toward the router and keep provider credentials centralized inside LLM Router."]}),(0,S.jsxs)(S.Fragment,{children:["Leave ",(0,S.jsx)("span",{className:"font-medium",children:"Current model override"})," empty unless you explicitly want to replace Claude Code's own main model selection."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Default Opus"}),", ",(0,S.jsx)("span",{className:"font-medium",children:"Default Sonnet"}),", and ",(0,S.jsx)("span",{className:"font-medium",children:"Default Haiku"})," when you want Claude Code's built-in alias names to resolve to managed routes or aliases."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Sub-agent model"})," when background workers or helper agents should run on a different route than the main session."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Effort level"})," to set ",(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"})," in your shell profile; leave it unset to keep Claude Code's adaptive default. The ",(0,S.jsx)("code",{children:"effortLevel"})," key in ",(0,S.jsx)("code",{children:"settings.json"}),' (only "high") acts as a fallback when the shell profile cannot be updated.']})]},{title:"What each binding controls",items:[(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"ANTHROPIC_MODEL"}),": overrides the main model for the active Claude Code session."]}),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"ANTHROPIC_DEFAULT_OPUS_MODEL"}),", ",(0,S.jsx)("code",{children:"ANTHROPIC_DEFAULT_SONNET_MODEL"}),", and ",(0,S.jsx)("code",{children:"ANTHROPIC_DEFAULT_HAIKU_MODEL"}),": remap Claude Code's built-in alias names to managed routes or aliases."]}),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"CLAUDE_CODE_SUBAGENT_MODEL"}),": routes subagents and background workers to a specific managed model."]}),s?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"}),": currently set to ",(0,S.jsx)("span",{className:"font-medium",children:s})," in your shell profile."]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"}),": stays unset unless you choose an effort level."]})]},{title:"Settings scope and precedence",items:[(0,S.jsxs)(S.Fragment,{children:["Claude Code settings apply in this order: ",(0,S.jsx)("code",{children:"managed-settings.json"}),", CLI arguments, ",(0,S.jsx)("code",{children:".claude/settings.local.json"}),", ",(0,S.jsx)("code",{children:".claude/settings.json"}),", then ",(0,S.jsx)("code",{children:"~/.claude/settings.json"}),"."]}),c?(0,S.jsxs)(S.Fragment,{children:["This page is currently managing ",(0,S.jsx)("code",{children:c}),"."]}):(0,S.jsx)(S.Fragment,{children:"Claude Code can read from project-local, project-shared, or user settings files depending on what exists in your environment."}),(0,S.jsx)(S.Fragment,{children:"If a value seems ignored, check whether a higher-precedence file or command-line flag is overriding it."})]},{title:"Quick verify",items:[(0,S.jsxs)(S.Fragment,{children:["Open the settings file from this page and confirm the ",(0,S.jsx)("code",{children:"env"})," block contains only the overrides you meant to set."]}),(0,S.jsxs)(S.Fragment,{children:["Launch Claude Code and test both the main session and any subagents if you changed ",(0,S.jsx)("code",{children:"CLAUDE_CODE_SUBAGENT_MODEL"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["If thinking behavior is not what you expected, remember this UI writes ",(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"})," to your shell profile; clearing the field returns control to Claude Code's own default behavior."]})]}]}}function dT({bindings:e={},settingsFilePath:t="",endpointUrl:n=""}={}){let r=String(e?.defaultModel||"").trim(),o=String(e?.missionOrchestratorModel||"").trim(),a=String(e?.missionWorkerModel||"").trim(),i=String(e?.missionValidatorModel||"").trim(),l=_A(e?.reasoningEffort),s=String(t||"").trim(),c=String(n||"").trim(),d=r||o||a||i?{variant:"info",title:"Factory defaults are set.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router injects a managed ",(0,S.jsx)("code",{children:"customModels"})," entry, registers it as ",(0,S.jsx)("code",{children:"generic-chat-completion-api"}),", and writes separate defaults for normal sessions and Missions."]})}:{variant:"success",title:"Factory Droid connected via custom model entry.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router injects a managed ",(0,S.jsx)("code",{children:"customModels"})," entry pointing at the gateway. Set normal or Mission defaults below, or use Factory Droid's ",(0,S.jsx)("code",{children:"/model"})," command to pick the routed model at runtime."]})};return{title:"Factory Droid guide",description:"Quick setup for routing Factory Droid through LLM Router via a managed custom model entry.",badges:[{label:r?`Normal: ${r}`:"Normal: Factory default",variant:r?"info":"outline"},{label:o?`Orchestrator: ${o}`:"Orchestrator: Factory default",variant:o?"info":"outline"},{label:a?`Worker: ${a}`:"Worker: Factory default",variant:a?"info":"outline"},{label:i?`Validator: ${i}`:"Validator: Factory default",variant:i?"info":"outline"},{label:l?`Reasoning: ${l}`:"Reasoning: Droid default",variant:"outline"},{label:s?"Settings file detected":"User config: ~/.factory/settings.json",variant:"outline"}],callout:d,highlights:[{eyebrow:"1. Connect",title:"Point Factory Droid at LLM Router",body:c?(0,S.jsxs)(S.Fragment,{children:["When connected, Factory Droid sends requests to ",(0,S.jsx)("code",{children:c}),". LLM Router handles upstream auth, alias resolution, and failover."]}):(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to inject a managed custom model entry into Factory Droid settings."]})},{eyebrow:"2. Route",title:"Set normal and Mission defaults",body:(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Normal mode model"})," for regular sessions, then set separate Mission bindings for the orchestrator, worker, and validator roles."]})},{eyebrow:"3. Tune",title:"Optional reasoning control",body:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("span",{className:"font-medium",children:"Reasoning effort"})," writes Factory Droid ",(0,S.jsx)("code",{children:"reasoningEffort"}),". Values: ",(0,S.jsx)("code",{children:"off"}),", ",(0,S.jsx)("code",{children:"none"}),", ",(0,S.jsx)("code",{children:"low"}),", ",(0,S.jsx)("code",{children:"medium"}),", or ",(0,S.jsx)("code",{children:"high"}),"."]})}],sections:[{title:"Quick start",items:[(0,S.jsxs)(S.Fragment,{children:["Set a ",(0,S.jsx)("code",{children:"masterKey"})," in LLM Router first. The ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," button stays disabled until gateway auth is ready."]}),(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to inject a managed ",(0,S.jsx)("code",{children:"customModels"})," entry into ",(0,S.jsx)("code",{children:"~/.factory/settings.json"}),"."]}),r?(0,S.jsxs)(S.Fragment,{children:["Your normal-session default is ",(0,S.jsx)("code",{children:r}),". Change it any time from this panel."]}):(0,S.jsxs)(S.Fragment,{children:["Choose a managed route or alias in ",(0,S.jsx)("span",{className:"font-medium",children:"Normal mode model"})," to set the default Factory session route."]}),o?(0,S.jsxs)(S.Fragment,{children:["Your Mission orchestrator default is ",(0,S.jsx)("code",{children:o}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Mission orchestrator"})," when mission planning should use a specific route."]}),a?(0,S.jsxs)(S.Fragment,{children:["Your Mission worker default is ",(0,S.jsx)("code",{children:a}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Mission worker"})," when implementation workers should use a specific route."]}),i?(0,S.jsxs)(S.Fragment,{children:["Your Mission validator default is ",(0,S.jsx)("code",{children:i}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Mission validator"})," when validation workers should use a specific route."]}),(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Reasoning effort"})," only when you want LLM Router to write ",(0,S.jsx)("code",{children:"reasoningEffort"}),"; leave it unset to keep Factory Droid defaults."]})]},{title:"How it works",items:[(0,S.jsxs)(S.Fragment,{children:["LLM Router adds a ",(0,S.jsx)("code",{children:"customModels"})," entry with ",(0,S.jsx)("code",{children:'provider: "generic-chat-completion-api"'})," and the gateway base URL."]}),(0,S.jsxs)(S.Fragment,{children:["The injected entry has a ",(0,S.jsx)("code",{children:"_llmRouterManaged"})," marker so it can be cleanly updated or removed without touching your other custom models."]}),(0,S.jsxs)(S.Fragment,{children:["The router-managed bindings map to both the legacy root ",(0,S.jsx)("code",{children:"model"})," field and current Factory settings such as ",(0,S.jsx)("code",{children:"sessionDefaultSettings.model"}),", ",(0,S.jsx)("code",{children:"missionOrchestratorModel"}),", and ",(0,S.jsx)("code",{children:"missionModelSettings"}),"."]}),(0,S.jsx)(S.Fragment,{children:"Disconnecting removes only the managed entry and restores any backed-up session, Mission, or reasoning settings."})]},{title:"Where these settings land",items:[s?(0,S.jsxs)(S.Fragment,{children:["This page is managing ",(0,S.jsx)("code",{children:s}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Factory Droid stores user settings in ",(0,S.jsx)("code",{children:"~/.factory/settings.json"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The normal-session binding maps to ",(0,S.jsx)("code",{children:"sessionDefaultSettings.model"})," and the legacy root ",(0,S.jsx)("code",{children:"model"})," field."]}),(0,S.jsxs)(S.Fragment,{children:["The Mission orchestrator binding maps to ",(0,S.jsx)("code",{children:"missionOrchestratorModel"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The Mission worker binding maps to ",(0,S.jsx)("code",{children:"missionModelSettings.workerModel"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The Mission validator binding maps to ",(0,S.jsx)("code",{children:"missionModelSettings.validationWorkerModel"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Open Config File"})," to inspect the generated settings."]})]},{title:"Quick verify",items:[(0,S.jsxs)(S.Fragment,{children:["Open the settings file from this page and confirm the ",(0,S.jsx)("code",{children:"customModels"})," array contains the LLM Router entry."]}),(0,S.jsxs)(S.Fragment,{children:["Launch Factory Droid and run a small prompt. Use ",(0,S.jsx)("code",{children:"/model"})," to confirm the routed model is available."]}),(0,S.jsxs)(S.Fragment,{children:["If requests fail, check the ",(0,S.jsx)("span",{className:"font-medium",children:"Alias & Fallback"})," tab first to ensure the alias behind your model exists."]})]}]}}function w5(e="outline"){switch(e){case"success":return"border-emerald-200 bg-emerald-50";case"warning":return"border-amber-200 bg-amber-50";case"danger":return"border-rose-200 bg-rose-50";case"info":return"border-sky-200 bg-sky-50";default:return"border-border/70 bg-background/70"}}function sT(e="outline"){switch(e){case"success":return"text-emerald-950";case"warning":return"text-amber-950";case"danger":return"text-rose-950";case"info":return"text-sky-950";default:return"text-foreground"}}function A5({guideContent:e}){let[t,n]=(0,Su.useState)(!1),r=String(e?.title||"").trim()||"Guide",o=String(e?.description||"").trim(),a=Array.isArray(e?.badges)?e.badges.filter(Boolean):[],i=Array.isArray(e?.highlights)?e.highlights.filter(Boolean):[],l=Array.isArray(e?.sections)?e.sections.filter(Boolean):[],s=e?.callout&&e.callout.body?e.callout:null,c=s?.variant||"outline";return i.length===0&&l.length===0&&!s?null:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)($,{type:"button",size:"sm",variant:"outline","aria-label":r,onClick:()=>n(!0),children:"Guide"}),(0,S.jsx)(Zn,{open:t,onClose:()=>n(!1),title:r,description:o,contentClassName:"max-h-[92vh] max-w-4xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)]",children:(0,S.jsxs)("div",{className:"space-y-4",children:[a.length>0?(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:a.map((d,u)=>(0,S.jsx)(ut,{variant:d?.variant||"outline",children:d?.label},`${r}-badge-${u}`))}):null,s?(0,S.jsxs)("div",{className:F("rounded-2xl border p-4",w5(c)),children:[(0,S.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,S.jsx)(ut,{variant:["success","warning","danger","info"].includes(c)?c:"outline",children:c==="success"?"Current best fit":c==="warning"?"Needs attention":c==="info"?"Current behavior":"Guide note"}),(0,S.jsx)("div",{className:F("text-sm font-medium",sT(c)),children:s.title})]}),(0,S.jsx)("div",{className:F("mt-3 text-sm leading-6",sT(c)),children:s.body})]}):null,i.length>0?(0,S.jsx)("div",{className:F("grid gap-4",i.length>2?"md:grid-cols-3":"md:grid-cols-2"),children:i.map((d,u)=>(0,S.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[d?.eyebrow?(0,S.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:d.eyebrow}):null,(0,S.jsx)("div",{className:"mt-2 text-sm font-medium text-foreground",children:d?.title}),(0,S.jsx)("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:d?.body})]},`${r}-highlight-${u}`))}):null,l.map((d,u)=>{let f=Array.isArray(d?.items)?d.items.filter(Boolean):[];return(0,S.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,S.jsx)("div",{className:"text-sm font-medium text-foreground",children:d?.title}),d?.description?(0,S.jsx)("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:d.description}):null,f.length>0?(0,S.jsx)("div",{className:"mt-3 space-y-3",children:f.map((p,v)=>(0,S.jsxs)("div",{className:"flex gap-3 text-sm leading-6 text-foreground",children:[(0,S.jsx)("span",{className:"mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-foreground/50"}),(0,S.jsx)("div",{className:"min-w-0",children:p})]},`${r}-section-${u}-item-${v}`))}):null]},`${r}-section-${u}`)})]})})]})}function C5({field:e,routeOptions:t,disabled:n=!1,onValueChange:r}){let o=String(e?.value||"").trim()||(e?.allowUnset?"__unset__":""),a=(0,Su.useMemo)(()=>{let i=e?.usesRouteOptions===!1?[]:t,l=Array.isArray(e?.options)?e.options:[],s=Array.isArray(e?.extraOptions)?e.extraOptions:[];return e?.allowUnset?[{value:"__unset__",label:"Inherit tool default",hint:""},...s,...l,...i]:[...s,...l,...i]},[e?.allowUnset,e?.extraOptions,e?.options,e?.usesRouteOptions,t]);return(0,S.jsxs)(rn,{value:o,onValueChange:r,disabled:n||a.length===0,children:[(0,S.jsx)(on,{children:(0,S.jsx)(an,{placeholder:e.placeholder||"Select a route"})}),(0,S.jsx)(ln,{children:a.length>0?x5(a,{keyPrefix:e.id||"binding-option"}):(0,S.jsx)(Dt,{value:"__no-route-options",disabled:!0,children:"No routes available"})})]})}function Om({toolName:e,toolState:t,endpointUrl:n,routeOptions:r,connectionBusy:o,bindingBusy:a,onToggleRouting:i,onBindingChange:l,hasMasterKey:s,disabledReason:c,onOpenPrimaryPath:d,onOpenSecondaryPath:u,secondaryPathLabel:f="Backup file",secondaryPathIcon:p=(0,S.jsx)(S5,{className:"h-3 w-3"}),bindingFields:v=[],guideContent:m=null}){let b=t?.routedViaRouter===!0,h=String(t?.error||"").trim(),g=!!(s&&n&&!c&&!h),y=(0,Su.useMemo)(()=>{let w=new Set(["__unset__"]);for(let C of v){for(let E of Array.isArray(C?.extraOptions)?C.extraOptions:[]){let A=String(E?.value||"").trim();A&&w.add(A)}for(let E of Array.isArray(C?.options)?C.options:[]){let A=String(E?.value||"").trim();A&&w.add(A)}}return v.filter(C=>C?.usesRouteOptions!==!1).map(C=>String(C?.value||"").trim()).filter(C=>C&&!w.has(C))},[v]),x=y5(r,y);return(0,S.jsxs)(Gt,{children:[(0,S.jsxs)(Qr,{className:"flex flex-col gap-3 p-4 pb-0 sm:flex-row sm:items-start sm:justify-between",children:[(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsx)(_o,{className:"flex items-center gap-2",children:(0,S.jsx)("span",{children:`Use ${e} via LLM Router`})}),(0,S.jsx)(Em,{primaryLabel:"Config file",primaryValue:t?.configFilePath||t?.settingsFilePath||"",onOpenPrimary:d,secondaryLabel:f,secondaryValue:t?.backupFilePath||"",secondaryIcon:p,onOpenSecondary:u})]}),(0,S.jsxs)("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[m?(0,S.jsx)(A5,{guideContent:m}):null,(0,S.jsx)($,{type:"button",size:"sm",variant:b?"outline":void 0,onClick:i,disabled:o!==""||!b&&!g,children:o==="enable"?"Connecting\u2026":o==="disable"?"Disconnecting\u2026":b?"Disconnect":"Connect"})]})]}),(0,S.jsxs)(qt,{className:"space-y-4 p-4",children:[h?(0,S.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:h}):null,!b&&!s?(0,S.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:["Set ",(0,S.jsx)("code",{children:"masterKey"})," first to connect ",e,"."]}):null,c?(0,S.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:c}):null,(0,S.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/60 p-4",children:[(0,S.jsx)("div",{children:(0,S.jsxs)("div",{children:[(0,S.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Model bindings"}),(0,S.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:"Prefer LLM Router aliases here so you can retarget models later from the Alias & Fallback tab."})]})}),v.length===0?(0,S.jsx)("div",{className:"mt-4 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:"No tool bindings are available yet."}):(0,S.jsx)("div",{className:"mt-4 grid gap-3",children:v.map(w=>(0,S.jsxs)("div",{className:"rounded-xl border border-border/70 bg-background/80 p-3",children:[(0,S.jsxs)("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[(0,S.jsx)("div",{className:"text-sm font-medium text-foreground",children:w.label}),(0,S.jsx)(ut,{variant:"outline",children:w.envKey})]}),(0,S.jsx)("div",{className:"mb-3 text-xs leading-5 text-muted-foreground",children:w.description}),(0,S.jsx)(C5,{field:w,routeOptions:x,disabled:w.standaloneWhenDisconnected?a:!b||a,onValueChange:C=>l(w.id,C==="__unset__"?"":C)})]},w.id))})]})]})]})}var At=_(Z(),1);function fT({logs:e,activityLogEnabled:t=!0,activityFilter:n="usage",busyAction:r="",onActivityFilterChange:o,onToggleEnabled:a,onClear:i}){let l=Array.isArray(e)?e:[],s=l.filter(d=>n==="all"?!0:Wh(d)===n),c=qc[n]||qc.usage;return(0,At.jsxs)(Gt,{children:[(0,At.jsx)(Qr,{children:(0,At.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,At.jsxs)("div",{className:"space-y-1",children:[(0,At.jsx)(_o,{children:"Activity"}),(0,At.jsx)(li,{children:t?"Router actions, request fallbacks, and runtime issues stream here.":"Activity logging is paused. Re-enable it to capture router actions, request fallbacks, and runtime issues."})]}),(0,At.jsxs)("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[(0,At.jsx)("div",{className:"min-w-[13rem]",children:(0,At.jsxs)(rn,{value:n,onValueChange:o,searchEnabled:!1,children:[(0,At.jsx)(on,{children:(0,At.jsx)(an,{placeholder:"Filter category"})}),(0,At.jsx)(ln,{children:kA.map(d=>(0,At.jsx)(Dt,{value:d.value,children:d.label},d.value))})]})}),(0,At.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:i,disabled:r!==""||!e?.length,children:r==="clear"?"Clearing\u2026":"Clear log"}),(0,At.jsx)($,{type:"button",size:"sm",variant:t?"outline":"default",onClick:a,disabled:r!=="",children:r==="toggle"?"Updating\u2026":t?"Disable log":"Enable log"})]})]})}),(0,At.jsx)(qt,{children:(0,At.jsx)("div",{className:"max-h-[32rem] space-y-3 overflow-auto pr-1",children:s.length?s.map(d=>{let u=Wh(d),f=qc[u]||qc.usage;return(0,At.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,At.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,At.jsxs)("div",{className:"flex items-center gap-2",children:[(0,At.jsx)("span",{className:F("inline-flex h-2.5 w-2.5 rounded-full ring-4",Hh[d.level]||Hh.info)}),(0,At.jsx)(ut,{variant:f.badgeVariant,children:f.label}),(0,At.jsx)("span",{className:"text-sm font-medium text-foreground",children:d.message})]}),(0,At.jsx)("span",{className:"text-xs text-muted-foreground",children:As(d.time)})]}),d.detail?(0,At.jsx)("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:d.detail}):null]},d.id)}):l.length?(0,At.jsxs)("div",{className:"rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground",children:["No ",c.emptyLabel," activity matches the current filter. Switch the dropdown to inspect the hidden categories."]}):(0,At.jsx)("div",{className:"rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground",children:"Activity is quiet. Save config changes or start the router to populate this stream."})})})]})}var Et=_(me(),1);var ov=_(me(),1);var dn=_(Z(),1);function mT({rows:e,onChange:t}){let n=Bf(e),r=n.length>0?n:[{name:"",value:""}];function o(l,s,c){s==="name"&&rC(r,c,l)||t(r.map((d,u)=>u===l?{...d,[s]:c}:d))}function a(){t([...r,{name:"",value:""}])}function i(l){let s=r.filter((c,d)=>d!==l);t(s.length>0?s:[{name:"",value:""}])}return(0,dn.jsxs)("div",{className:"space-y-2",children:[r.map((l,s)=>(0,dn.jsxs)("div",{className:"grid gap-2 md:grid-cols-[minmax(0,0.9fr)_minmax(0,1.3fr)_auto]",children:[(0,dn.jsx)(wt,{value:l.name,onChange:c=>o(s,"name",c.target.value),placeholder:s===0?"User-Agent":"Header name"}),(0,dn.jsx)(wt,{value:l.value,onChange:c=>o(s,"value",c.target.value),placeholder:s===0?eo:"Header value"}),(0,dn.jsx)($,{type:"button",variant:"ghost",onClick:()=>i(s),children:"Remove"})]},`header-row-${s}`)),(0,dn.jsxs)("div",{className:"flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[(0,dn.jsx)("span",{children:"User-Agent is included by default. Add more only when a provider needs them."}),(0,dn.jsx)($,{type:"button",variant:"outline",onClick:a,children:"Add custom header"})]})]})}function pT({providerId:e,values:t,onChange:n}){let r=(t||[]).map(u=>String(u||"").trim()).filter(Boolean),o=zs(r),a=(0,ov.useRef)(""),i=(0,ov.useRef)(null);function l(u){n((t||[]).filter(f=>f!==u))}function s(u,f){if(!u||!f||u===f)return;let p=[...t||[]],v=p.indexOf(u),m=p.indexOf(f);if(v===-1||m===-1)return;let[b]=p.splice(v,1);p.splice(m,0,b),n(p)}function c(u){n(xs(t||[],u,f=>String(f||"").trim()))}function d(){a.current="",va(i.current,!1),i.current=null}return(0,dn.jsxs)("div",{className:"space-y-2",children:[(0,dn.jsx)("div",{className:"space-y-2 rounded-xl border border-input bg-background/80 px-3 py-3",children:r.length>0?r.map((u,f)=>(0,dn.jsxs)("div",{ref:o(u),"data-reorder-row":"true",onDragOver:p=>{a.current&&a.current!==u&&(p.preventDefault(),p.dataTransfer.dropEffect="move")},onDrop:p=>{p.preventDefault();let v=p.dataTransfer.getData("text/plain")||a.current;d(),s(v,u)},className:F("grid grid-cols-[auto_auto_minmax(0,1fr)_auto] items-center gap-2 rounded-xl border border-border/70 bg-card/90 p-3"),children:[(0,dn.jsx)("span",{className:"flex h-8 w-8 cursor-grab items-center justify-center rounded-full text-muted-foreground",draggable:!0,onDragStart:p=>{let v=Ss(p.currentTarget);p.dataTransfer.effectAllowed="move",p.dataTransfer.setData("text/plain",u),v&&typeof p.dataTransfer?.setDragImage=="function"&&p.dataTransfer.setDragImage(v,20,20),d(),a.current=u,i.current=v,va(v,!0)},onDragEnd:d,title:"Drag to reorder",children:(0,dn.jsx)(vs,{className:"h-4 w-4"})}),(0,dn.jsx)(Sa,{disabled:f===0,label:f===0?"Already first":`Move ${e}/${u} up`,onClick:()=>c(u)}),(0,dn.jsxs)("span",{className:"truncate text-sm font-medium text-foreground",children:[e,"/",u]}),(0,dn.jsx)("button",{className:"text-muted-foreground transition hover:text-foreground",type:"button",onMouseDown:p=>p.preventDefault(),onClick:()=>l(u),children:"\xD7"})]},u)):(0,dn.jsxs)("span",{className:"block px-1 text-xs text-muted-foreground",children:["Leave it empty for now, or add models to back the fixed ",(0,dn.jsx)("code",{children:"default"})," route. An empty default route returns 500 until you add a working model."]})}),(0,dn.jsx)("div",{className:"text-xs text-muted-foreground",children:"Drag rows to change the preferred order, use the arrow to move a model earlier, or remove any models you do not want in this route."})]})}var k=_(Z(),1);function av({baseConfig:e,onApplyDraft:t,onValidateDraft:n,onSaveDraft:r,onSaveAndStart:o,seedMode:a="blank",mode:i="add",targetProviderId:l="",defaultProviderUserAgent:s=eo,framed:c=!0,showHeader:d=!0}){let[u,f]=(0,Et.useState)(0),[p,v]=(0,Et.useState)(""),[m,b]=(0,Et.useState)(()=>vC(e,{seedMode:a,targetProviderId:l,defaultProviderUserAgent:s})),[h,g]=(0,Et.useState)(null),[y,x]=(0,Et.useState)(""),[w,C]=(0,Et.useState)({}),[E,A]=(0,Et.useState)(!1),[M,L]=(0,Et.useState)(null),[P,D]=(0,Et.useState)(""),[G,ae]=(0,Et.useState)(!1),[ge,j]=(0,Et.useState)(""),J=(0,Et.useRef)(!0),Q=(0,Et.useRef)(""),H=(0,Et.useRef)(Math.random().toString(36).slice(2,10)),B=i==="edit",ft=!B&&a==="blank"&&Vf(e),X=`llr-qs-endpoint-${H.current}`,je=`llr-qs-endpoint-input-${H.current}`,ie=`llr-qs-credential-${H.current}`,xe=`llr-qs-credential-input-${H.current}`,Ie=[{title:"Provider",detail:"Choose API Key or OAuth first, then enter the provider details needed for that connection type."},{title:"Models",detail:"Add model ids, then configure one or more rate limits for all models or selected models. API Key providers are tested before continue."},{title:"Default",detail:"Order the models behind the fixed `default` route before you finish."}],I=Yn(m.modelIds,m.modelDraft),ue=jf(m.aliasModelIds,I),he=m.connectionType==="api"?Yn(m.endpoints,m.endpointDraft):[],_e=(0,Et.useMemo)(()=>({...m,endpoints:he,modelIds:I,aliasModelIds:ue,rateLimitRows:gr(m.rateLimitRows)}),[m,he,I,ue]),Ee=(0,Et.useMemo)(()=>Uf(m.headerRows||[]),[m.headerRows]),ve=String(m.apiKeyEnv||"").trim(),Fe=(0,Et.useMemo)(()=>Jh(_e),[_e]),Je=M?.signature===Fe?M.result:null,Ht=Je?.models?.length>0?Je.models:ny(m.selectedConnection||"custom"),wn=Lr(m.providerId||m.providerName||"my-provider")||"my-provider",fn=ry(m),Ft=JSON.stringify({connectionType:m.connectionType,selectedConnection:m.selectedConnection,subscriptionProfile:fn}),Yt=I.filter(V=>w[V]==="error"),st=I.filter(V=>w[V]==="success"),Ve=I.some(V=>w[V]==="success"||w[V]==="error"),Vn=I.length>0&&I.every(V=>w[V]==="success"),mn=st.length>0,er=Yt.length>0,Ra=I.some(V=>!w[V]||w[V]==="default"),Te=h?.signature===Fe?h.result:null,Ze=m.connectionType!=="api"||mn,Ce=(0,Et.useMemo)(()=>bC(e,_e,Te,{targetProviderId:l}),[e,_e,Te,l]),Ge=(0,Et.useMemo)(()=>`${JSON.stringify(Ce,null,2)}
51
+ `)},JL=0,_s=[];function KR(e){var t=Vt.useRef([]),n=Vt.useRef([0,0]),r=Vt.useRef(),o=Vt.useState(JL++)[0],a=Vt.useState(gu)[0],i=Vt.useRef(e);Vt.useEffect(function(){i.current=e},[e]),Vt.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=MR([e.lockRef.current],(e.shards||[]).map(FR),!0).filter(Boolean);return m.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var l=Vt.useCallback(function(m,b){if("touches"in m&&m.touches.length===2||m.type==="wheel"&&m.ctrlKey)return!i.current.allowPinchZoom;var h=dm(m),g=n.current,y="deltaX"in m?m.deltaX:g[0]-h[0],x="deltaY"in m?m.deltaY:g[1]-h[1],w,C=m.target,E=Math.abs(y)>Math.abs(x)?"h":"v";if("touches"in m&&E==="h"&&C.type==="range")return!1;var A=window.getSelection(),M=A&&A.anchorNode,L=M?M===C||M.contains(C):!1;if(L)return!1;var P=Vy(E,C);if(!P)return!0;if(P?w=E:(w=E==="v"?"h":"v",P=Vy(E,C)),!P)return!1;if(!r.current&&"changedTouches"in m&&(y||x)&&(r.current=w),!w)return!0;var D=r.current||w;return VR(D,b,m,D==="h"?y:x,!0)},[]),s=Vt.useCallback(function(m){var b=m;if(!(!_s.length||_s[_s.length-1]!==a)){var h="deltaY"in b?HR(b):dm(b),g=t.current.filter(function(w){return w.name===b.type&&(w.target===b.target||b.target===w.shadowParent)&&XL(w.delta,h)})[0];if(g&&g.should){b.cancelable&&b.preventDefault();return}if(!g){var y=(i.current.shards||[]).map(FR).filter(Boolean).filter(function(w){return w.contains(b.target)}),x=y.length>0?l(b,y[0]):!i.current.noIsolation;x&&b.cancelable&&b.preventDefault()}}},[]),c=Vt.useCallback(function(m,b,h,g){var y={name:m,delta:b,target:h,should:g,shadowParent:eD(h)};t.current.push(y),setTimeout(function(){t.current=t.current.filter(function(x){return x!==y})},1)},[]),d=Vt.useCallback(function(m){n.current=dm(m),r.current=void 0},[]),u=Vt.useCallback(function(m){c(m.type,HR(m),m.target,l(m,e.lockRef.current))},[]),f=Vt.useCallback(function(m){c(m.type,dm(m),m.target,l(m,e.lockRef.current))},[]);Vt.useEffect(function(){return _s.push(a),e.setCallbacks({onScrollCapture:u,onWheelCapture:u,onTouchMoveCapture:f}),document.addEventListener("wheel",s,ll),document.addEventListener("touchmove",s,ll),document.addEventListener("touchstart",d,ll),function(){_s=_s.filter(function(m){return m!==a}),document.removeEventListener("wheel",s,ll),document.removeEventListener("touchmove",s,ll),document.removeEventListener("touchstart",d,ll)}},[]);var p=e.removeScrollBar,v=e.inert;return Vt.createElement(Vt.Fragment,null,v?Vt.createElement(a,{styles:ZL(o)}):null,p?Vt.createElement(Py,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function eD(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var $R=Ly(um,KR);var GR=fm.forwardRef(function(e,t){return fm.createElement(pu,vr({},e,{ref:t,sideCar:$R}))});GR.classNames=pu.classNames;var Hy=GR;var Oe=_(Z(),1),tD=[" ","Enter","ArrowUp","ArrowDown"],nD=[" ","Enter"],sl="Select",[pm,gm,rD]=hf(sl),[ks,ZU]=Xr(sl,[rD,Cy]),hm=Cy(),[oD,vi]=ks(sl),[aD,iD]=ks(sl),qR=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:a,value:i,defaultValue:l,onValueChange:s,dir:c,name:d,autoComplete:u,disabled:f,required:p,form:v}=e,m=hm(t),[b,h]=ee.useState(null),[g,y]=ee.useState(null),[x,w]=ee.useState(!1),C=ds(c),[E,A]=pa({prop:r,defaultProp:o??!1,onChange:a,caller:sl}),[M,L]=pa({prop:i,defaultProp:l,onChange:s,caller:sl}),P=ee.useRef(null),D=b?v||!!b.closest("form"):!0,[G,ae]=ee.useState(new Set),ge=Array.from(G).map(j=>j.props.value).join(";");return(0,Oe.jsx)(vR,{...m,children:(0,Oe.jsxs)(oD,{required:p,scope:t,trigger:b,onTriggerChange:h,valueNode:g,onValueNodeChange:y,valueNodeHasChildren:x,onValueNodeHasChildrenChange:w,contentId:ci(),value:M,onValueChange:L,open:E,onOpenChange:A,dir:C,triggerPointerDownPosRef:P,disabled:f,children:[(0,Oe.jsx)(pm.Provider,{scope:t,children:(0,Oe.jsx)(aD,{scope:e.__scopeSelect,onNativeOptionAdd:ee.useCallback(j=>{ae(J=>new Set(J).add(j))},[]),onNativeOptionRemove:ee.useCallback(j=>{ae(J=>{let Q=new Set(J);return Q.delete(j),Q})},[]),children:n})}),D?(0,Oe.jsxs)(gE,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:u,value:M,onChange:j=>L(j.target.value),disabled:f,form:v,children:[M===void 0?(0,Oe.jsx)("option",{value:""}):null,Array.from(G)]},ge):null]})})};qR.displayName=sl;var WR="SelectTrigger",YR=ee.forwardRef((e,t)=>{let{__scopeSelect:n,disabled:r=!1,...o}=e,a=hm(n),i=vi(WR,n),l=i.disabled||r,s=xt(t,i.onTriggerChange),c=gm(n),d=ee.useRef("touch"),[u,f,p]=yE(m=>{let b=c().filter(y=>!y.disabled),h=b.find(y=>y.value===i.value),g=vE(b,m,h);g!==void 0&&i.onValueChange(g.value)}),v=m=>{l||(i.onOpenChange(!0),p()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return(0,Oe.jsx)(bR,{asChild:!0,...a,children:(0,Oe.jsx)(Xe.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:l,"data-disabled":l?"":void 0,"data-placeholder":hE(i.value)?"":void 0,...o,ref:s,onClick:dt(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&v(m)}),onPointerDown:dt(o.onPointerDown,m=>{d.current=m.pointerType;let b=m.target;b.hasPointerCapture(m.pointerId)&&b.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(v(m),m.preventDefault())}),onKeyDown:dt(o.onKeyDown,m=>{let b=u.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&f(m.key),!(b&&m.key===" ")&&tD.includes(m.key)&&(v(),m.preventDefault())})})})});YR.displayName=WR;var QR="SelectValue",XR=ee.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:o,children:a,placeholder:i="",...l}=e,s=vi(QR,n),{onValueNodeHasChildrenChange:c}=s,d=a!==void 0,u=xt(t,s.onValueNodeChange);return Xt(()=>{c(d)},[c,d]),(0,Oe.jsx)(Xe.span,{...l,ref:u,style:{pointerEvents:"none"},children:hE(s.value)?(0,Oe.jsx)(Oe.Fragment,{children:i}):a})});XR.displayName=QR;var lD="SelectIcon",ZR=ee.forwardRef((e,t)=>{let{__scopeSelect:n,children:r,...o}=e;return(0,Oe.jsx)(Xe.span,{"aria-hidden":!0,...o,ref:t,children:r||"\u25BC"})});ZR.displayName=lD;var sD="SelectPortal",JR=e=>(0,Oe.jsx)(Ey,{asChild:!0,...e});JR.displayName=sD;var cl="SelectContent",eE=ee.forwardRef((e,t)=>{let n=vi(cl,e.__scopeSelect),[r,o]=ee.useState();if(Xt(()=>{o(new DocumentFragment)},[]),!n.open){let a=r;return a?Wy.createPortal((0,Oe.jsx)(tE,{scope:e.__scopeSelect,children:(0,Oe.jsx)(pm.Slot,{scope:e.__scopeSelect,children:(0,Oe.jsx)("div",{children:e.children})})}),a):null}return(0,Oe.jsx)(nE,{...e,ref:t})});eE.displayName=cl;var xo=10,[tE,bi]=ks(cl),cD="SelectContentImpl",uD=Wi("SelectContent.RemoveScroll"),nE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:a,onPointerDownOutside:i,side:l,sideOffset:s,align:c,alignOffset:d,arrowPadding:u,collisionBoundary:f,collisionPadding:p,sticky:v,hideWhenDetached:m,avoidCollisions:b,...h}=e,g=vi(cl,n),[y,x]=ee.useState(null),[w,C]=ee.useState(null),E=xt(t,I=>x(I)),[A,M]=ee.useState(null),[L,P]=ee.useState(null),D=gm(n),[G,ae]=ee.useState(!1),ge=ee.useRef(!1);ee.useEffect(()=>{if(y)return TR(y)},[y]),t1();let j=ee.useCallback(I=>{let[ue,...he]=D().map(ve=>ve.ref.current),[_e]=he.slice(-1),Ee=document.activeElement;for(let ve of I)if(ve===Ee||(ve?.scrollIntoView({block:"nearest"}),ve===ue&&w&&(w.scrollTop=0),ve===_e&&w&&(w.scrollTop=w.scrollHeight),ve?.focus(),document.activeElement!==Ee))return},[D,w]),J=ee.useCallback(()=>j([A,y]),[j,A,y]);ee.useEffect(()=>{G&&J()},[G,J]);let{onOpenChange:Q,triggerPointerDownPosRef:H}=g;ee.useEffect(()=>{if(y){let I={x:0,y:0},ue=_e=>{I={x:Math.abs(Math.round(_e.pageX)-(H.current?.x??0)),y:Math.abs(Math.round(_e.pageY)-(H.current?.y??0))}},he=_e=>{I.x<=10&&I.y<=10?_e.preventDefault():y.contains(_e.target)||Q(!1),document.removeEventListener("pointermove",ue),H.current=null};return H.current!==null&&(document.addEventListener("pointermove",ue),document.addEventListener("pointerup",he,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",ue),document.removeEventListener("pointerup",he,{capture:!0})}}},[y,Q,H]),ee.useEffect(()=>{let I=()=>Q(!1);return window.addEventListener("blur",I),window.addEventListener("resize",I),()=>{window.removeEventListener("blur",I),window.removeEventListener("resize",I)}},[Q]);let[B,ft]=yE(I=>{let ue=D().filter(Ee=>!Ee.disabled),he=ue.find(Ee=>Ee.ref.current===document.activeElement),_e=vE(ue,I,he);_e&&setTimeout(()=>_e.ref.current.focus())}),X=ee.useCallback((I,ue,he)=>{let _e=!ge.current&&!he;(g.value!==void 0&&g.value===ue||_e)&&(M(I),_e&&(ge.current=!0))},[g.value]),je=ee.useCallback(()=>y?.focus(),[y]),ie=ee.useCallback((I,ue,he)=>{let _e=!ge.current&&!he;(g.value!==void 0&&g.value===ue||_e)&&P(I)},[g.value]),xe=r==="popper"?Fy:rE,Ie=xe===Fy?{side:l,sideOffset:s,align:c,alignOffset:d,arrowPadding:u,collisionBoundary:f,collisionPadding:p,sticky:v,hideWhenDetached:m,avoidCollisions:b}:{};return(0,Oe.jsx)(tE,{scope:n,content:y,viewport:w,onViewportChange:C,itemRefCallback:X,selectedItem:A,onItemLeave:je,itemTextRefCallback:ie,focusSelectedItem:J,selectedItemText:L,position:r,isPositioned:G,searchRef:B,children:(0,Oe.jsx)(Hy,{as:uD,allowPinchZoom:!0,children:(0,Oe.jsx)(my,{asChild:!0,trapped:g.open,onMountAutoFocus:I=>{I.preventDefault()},onUnmountAutoFocus:dt(o,I=>{g.trigger?.focus({preventScroll:!0}),I.preventDefault()}),children:(0,Oe.jsx)(cy,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:i,onFocusOutside:I=>I.preventDefault(),onDismiss:()=>g.onOpenChange(!1),children:(0,Oe.jsx)(xe,{role:"listbox",id:g.contentId,"data-state":g.open?"open":"closed",dir:g.dir,onContextMenu:I=>I.preventDefault(),...h,...Ie,onPlaced:()=>ae(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...h.style},onKeyDown:dt(h.onKeyDown,I=>{let ue=I.ctrlKey||I.altKey||I.metaKey;if(I.key==="Tab"&&I.preventDefault(),!ue&&I.key.length===1&&ft(I.key),["ArrowUp","ArrowDown","Home","End"].includes(I.key)){let _e=D().filter(Ee=>!Ee.disabled).map(Ee=>Ee.ref.current);if(["ArrowUp","End"].includes(I.key)&&(_e=_e.slice().reverse()),["ArrowUp","ArrowDown"].includes(I.key)){let Ee=I.target,ve=_e.indexOf(Ee);_e=_e.slice(ve+1)}setTimeout(()=>j(_e)),I.preventDefault()}})})})})})})});nE.displayName=cD;var dD="SelectItemAlignedPosition",rE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,onPlaced:r,...o}=e,a=vi(cl,n),i=bi(cl,n),[l,s]=ee.useState(null),[c,d]=ee.useState(null),u=xt(t,E=>d(E)),f=gm(n),p=ee.useRef(!1),v=ee.useRef(!0),{viewport:m,selectedItem:b,selectedItemText:h,focusSelectedItem:g}=i,y=ee.useCallback(()=>{if(a.trigger&&a.valueNode&&l&&c&&m&&b&&h){let E=a.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),M=a.valueNode.getBoundingClientRect(),L=h.getBoundingClientRect();if(a.dir!=="rtl"){let Ee=L.left-A.left,ve=M.left-Ee,Fe=E.left-ve,Je=E.width+Fe,Ht=Math.max(Je,A.width),wn=window.innerWidth-xo,fn=iy(ve,[xo,Math.max(xo,wn-Ht)]);l.style.minWidth=Je+"px",l.style.left=fn+"px"}else{let Ee=A.right-L.right,ve=window.innerWidth-M.right-Ee,Fe=window.innerWidth-E.right-ve,Je=E.width+Fe,Ht=Math.max(Je,A.width),wn=window.innerWidth-xo,fn=iy(ve,[xo,Math.max(xo,wn-Ht)]);l.style.minWidth=Je+"px",l.style.right=fn+"px"}let P=f(),D=window.innerHeight-xo*2,G=m.scrollHeight,ae=window.getComputedStyle(c),ge=parseInt(ae.borderTopWidth,10),j=parseInt(ae.paddingTop,10),J=parseInt(ae.borderBottomWidth,10),Q=parseInt(ae.paddingBottom,10),H=ge+j+G+Q+J,B=Math.min(b.offsetHeight*5,H),ft=window.getComputedStyle(m),X=parseInt(ft.paddingTop,10),je=parseInt(ft.paddingBottom,10),ie=E.top+E.height/2-xo,xe=D-ie,Ie=b.offsetHeight/2,I=b.offsetTop+Ie,ue=ge+j+I,he=H-ue;if(ue<=ie){let Ee=P.length>0&&b===P[P.length-1].ref.current;l.style.bottom="0px";let ve=c.clientHeight-m.offsetTop-m.offsetHeight,Fe=Math.max(xe,Ie+(Ee?je:0)+ve+J),Je=ue+Fe;l.style.height=Je+"px"}else{let Ee=P.length>0&&b===P[0].ref.current;l.style.top="0px";let Fe=Math.max(ie,ge+m.offsetTop+(Ee?X:0)+Ie)+he;l.style.height=Fe+"px",m.scrollTop=ue-ie+m.offsetTop}l.style.margin=`${xo}px 0`,l.style.minHeight=B+"px",l.style.maxHeight=D+"px",r?.(),requestAnimationFrame(()=>p.current=!0)}},[f,a.trigger,a.valueNode,l,c,m,b,h,a.dir,r]);Xt(()=>y(),[y]);let[x,w]=ee.useState();Xt(()=>{c&&w(window.getComputedStyle(c).zIndex)},[c]);let C=ee.useCallback(E=>{E&&v.current===!0&&(y(),g?.(),v.current=!1)},[y,g]);return(0,Oe.jsx)(mD,{scope:n,contentWrapper:l,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:(0,Oe.jsx)("div",{ref:s,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:x},children:(0,Oe.jsx)(Xe.div,{...o,ref:u,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});rE.displayName=dD;var fD="SelectPopperPosition",Fy=ee.forwardRef((e,t)=>{let{__scopeSelect:n,align:r="start",collisionPadding:o=xo,...a}=e,i=hm(n);return(0,Oe.jsx)(xR,{...i,...a,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...a.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Fy.displayName=fD;var[mD,Yy]=ks(cl,{}),Ky="SelectViewport",oE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,nonce:r,...o}=e,a=bi(Ky,n),i=Yy(Ky,n),l=xt(t,a.onViewportChange),s=ee.useRef(0);return(0,Oe.jsxs)(Oe.Fragment,{children:[(0,Oe.jsx)("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),(0,Oe.jsx)(pm.Slot,{scope:n,children:(0,Oe.jsx)(Xe.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:l,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:dt(o.onScroll,c=>{let d=c.currentTarget,{contentWrapper:u,shouldExpandOnScrollRef:f}=i;if(f?.current&&u){let p=Math.abs(s.current-d.scrollTop);if(p>0){let v=window.innerHeight-xo*2,m=parseFloat(u.style.minHeight),b=parseFloat(u.style.height),h=Math.max(m,b);if(h<v){let g=h+p,y=Math.min(v,g),x=g-y;u.style.height=y+"px",u.style.bottom==="0px"&&(d.scrollTop=x>0?x:0,u.style.justifyContent="flex-end")}}}s.current=d.scrollTop})})})]})});oE.displayName=Ky;var aE="SelectGroup",[pD,gD]=ks(aE),iE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,o=ci();return(0,Oe.jsx)(pD,{scope:n,id:o,children:(0,Oe.jsx)(Xe.div,{role:"group","aria-labelledby":o,...r,ref:t})})});iE.displayName=aE;var lE="SelectLabel",sE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,o=gD(lE,n);return(0,Oe.jsx)(Xe.div,{id:o.id,...r,ref:t})});sE.displayName=lE;var mm="SelectItem",[hD,cE]=ks(mm),uE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,value:r,disabled:o=!1,textValue:a,...i}=e,l=vi(mm,n),s=bi(mm,n),c=l.value===r,[d,u]=ee.useState(a??""),[f,p]=ee.useState(!1),v=xt(t,g=>s.itemRefCallback?.(g,r,o)),m=ci(),b=ee.useRef("touch"),h=()=>{o||(l.onValueChange(r),l.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return(0,Oe.jsx)(hD,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:ee.useCallback(g=>{u(y=>y||(g?.textContent??"").trim())},[]),children:(0,Oe.jsx)(pm.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:(0,Oe.jsx)(Xe.div,{role:"option","aria-labelledby":m,"data-highlighted":f?"":void 0,"aria-selected":c&&f,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:dt(i.onFocus,()=>p(!0)),onBlur:dt(i.onBlur,()=>p(!1)),onClick:dt(i.onClick,()=>{b.current!=="mouse"&&h()}),onPointerUp:dt(i.onPointerUp,()=>{b.current==="mouse"&&h()}),onPointerDown:dt(i.onPointerDown,g=>{b.current=g.pointerType}),onPointerMove:dt(i.onPointerMove,g=>{b.current=g.pointerType,o?s.onItemLeave?.():b.current==="mouse"&&g.currentTarget.focus({preventScroll:!0})}),onPointerLeave:dt(i.onPointerLeave,g=>{g.currentTarget===document.activeElement&&s.onItemLeave?.()}),onKeyDown:dt(i.onKeyDown,g=>{s.searchRef?.current!==""&&g.key===" "||(nD.includes(g.key)&&h(),g.key===" "&&g.preventDefault())})})})})});uE.displayName=mm;var yu="SelectItemText",dE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,className:r,style:o,...a}=e,i=vi(yu,n),l=bi(yu,n),s=cE(yu,n),c=iD(yu,n),[d,u]=ee.useState(null),f=xt(t,h=>u(h),s.onItemTextChange,h=>l.itemTextRefCallback?.(h,s.value,s.disabled)),p=d?.textContent,v=ee.useMemo(()=>(0,Oe.jsx)("option",{value:s.value,disabled:s.disabled,children:p},s.value),[s.disabled,s.value,p]),{onNativeOptionAdd:m,onNativeOptionRemove:b}=c;return Xt(()=>(m(v),()=>b(v)),[m,b,v]),(0,Oe.jsxs)(Oe.Fragment,{children:[(0,Oe.jsx)(Xe.span,{id:s.textId,...a,ref:f}),s.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Wy.createPortal(a.children,i.valueNode):null]})});dE.displayName=yu;var fE="SelectItemIndicator",mE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return cE(fE,n).isSelected?(0,Oe.jsx)(Xe.span,{"aria-hidden":!0,...r,ref:t}):null});mE.displayName=fE;var $y="SelectScrollUpButton",yD=ee.forwardRef((e,t)=>{let n=bi($y,e.__scopeSelect),r=Yy($y,e.__scopeSelect),[o,a]=ee.useState(!1),i=xt(t,r.onScrollButtonChange);return Xt(()=>{if(n.viewport&&n.isPositioned){let s=function(){let d=c.scrollTop>0;a(d)};var l=s;let c=n.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),o?(0,Oe.jsx)(pE,{...e,ref:i,onAutoScroll:()=>{let{viewport:l,selectedItem:s}=n;l&&s&&(l.scrollTop=l.scrollTop-s.offsetHeight)}}):null});yD.displayName=$y;var Gy="SelectScrollDownButton",vD=ee.forwardRef((e,t)=>{let n=bi(Gy,e.__scopeSelect),r=Yy(Gy,e.__scopeSelect),[o,a]=ee.useState(!1),i=xt(t,r.onScrollButtonChange);return Xt(()=>{if(n.viewport&&n.isPositioned){let s=function(){let d=c.scrollHeight-c.clientHeight,u=Math.ceil(c.scrollTop)<d;a(u)};var l=s;let c=n.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[n.viewport,n.isPositioned]),o?(0,Oe.jsx)(pE,{...e,ref:i,onAutoScroll:()=>{let{viewport:l,selectedItem:s}=n;l&&s&&(l.scrollTop=l.scrollTop+s.offsetHeight)}}):null});vD.displayName=Gy;var pE=ee.forwardRef((e,t)=>{let{__scopeSelect:n,onAutoScroll:r,...o}=e,a=bi("SelectScrollButton",n),i=ee.useRef(null),l=gm(n),s=ee.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return ee.useEffect(()=>()=>s(),[s]),Xt(()=>{l().find(d=>d.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[l]),(0,Oe.jsx)(Xe.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:dt(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:dt(o.onPointerMove,()=>{a.onItemLeave?.(),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:dt(o.onPointerLeave,()=>{s()})})}),bD="SelectSeparator",xD=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e;return(0,Oe.jsx)(Xe.div,{"aria-hidden":!0,...r,ref:t})});xD.displayName=bD;var qy="SelectArrow",SD=ee.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,o=hm(n),a=vi(qy,n),i=bi(qy,n);return a.open&&i.position==="popper"?(0,Oe.jsx)(SR,{...o,...r,ref:t}):null});SD.displayName=qy;var wD="SelectBubbleInput",gE=ee.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{let o=ee.useRef(null),a=xt(r,o),i=df(t);return ee.useEffect(()=>{let l=o.current;if(!l)return;let s=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(s,"value").set;if(i!==t&&d){let u=new Event("change",{bubbles:!0});d.call(l,t),l.dispatchEvent(u)}},[i,t]),(0,Oe.jsx)(Xe.select,{...n,style:{...Ty,...n.style},ref:a,defaultValue:t})});gE.displayName=wD;function hE(e){return e===""||e===void 0}function yE(e){let t=cr(e),n=ee.useRef(""),r=ee.useRef(0),o=ee.useCallback(i=>{let l=n.current+i;t(l),(function s(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>s(""),1e3))})(l)},[t]),a=ee.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return ee.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,a]}function vE(e,t,n){let o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,a=n?e.indexOf(n):-1,i=AD(e,Math.max(a,0));o.length===1&&(i=i.filter(c=>c!==n));let s=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return s!==n?s:void 0}function AD(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var bE=qR,xE=YR,SE=XR,wE=ZR,AE=JR,CE=eE,RE=oE,EE=iE,TE=sE,ME=uE,NE=dE,OE=mE;var _E=_(me(),1);var kE=_(Z(),1),wt=(0,_E.forwardRef)(function({className:t,...n},r){return(0,kE.jsx)("input",{ref:r,className:F("flex h-9 w-full rounded-lg border border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40",t),...n})});function LE(e){return String(e||"").trim().toLowerCase()}function ym(e){return LE(e).length>0}function DE({searchEnabled:e=!0}={}){return!!e}function Qy(e){let t=String(e?.key||"");return!t||t.length!==1||e?.ctrlKey||e?.metaKey||e?.altKey?"":t.trim()?t:""}function IE(e={},t=""){let n=LE(t);return n?[e?.label,e?.value,e?.hint,e?.textValue,e?.searchText].map(o=>String(o||"").toLowerCase()).join(" ").includes(n):!0}var vm=_(me(),1),RD=12;function Xy(e){return/auto|scroll|hidden|clip|overlay/.test(String(e||"").toLowerCase())}function ED(e,t){return{top:Math.max(e.top,t.top),right:Math.min(e.right,t.right),bottom:Math.min(e.bottom,t.bottom),left:Math.max(e.left,t.left)}}function bm(e){if(typeof window>"u")return[];let t=[],n=e?.parentElement||null;for(;n&&n!==document.body&&n!==document.documentElement;){let r=window.getComputedStyle(n);(Xy(r.overflow)||Xy(r.overflowY)||Xy(r.overflowX))&&t.push(n),n=n.parentElement}return t}function TD(e,{viewportPadding:t=RD}={}){if(typeof window>"u")return null;let n={top:t,right:window.innerWidth-t,bottom:window.innerHeight-t,left:t};for(let r of bm(e))n=ED(n,r.getBoundingClientRect());return n}function MD({anchorRect:e,boundaryRect:t,preferredSide:n="bottom",offset:r=4,desiredHeight:o=288}={}){if(!e||!t)return{side:n==="top"?"top":"bottom",maxHeight:o};let a=Math.max(0,e.top-t.top-r),i=Math.max(0,t.bottom-e.bottom-r),s=a===i?n==="top"?"top":"bottom":a>i?"top":"bottom",c=Math.max(0,Math.min(o,s==="top"?a:i));return{side:s,maxHeight:c}}function xm({open:e=!1,anchorRef:t,preferredSide:n="bottom",offset:r=4,desiredHeight:o=288}={}){let[a,i]=(0,vm.useState)(()=>({side:n==="top"?"top":"bottom",maxHeight:o}));return(0,vm.useLayoutEffect)(()=>{if(!e||typeof window>"u")return;let l=t?.current||null;if(!l){i({side:n==="top"?"top":"bottom",maxHeight:o});return}let s=()=>{i(MD({anchorRect:l.getBoundingClientRect(),boundaryRect:TD(l),preferredSide:n,offset:r,desiredHeight:o}))};s();let c=bm(l);window.addEventListener("resize",s);for(let u of c)u.addEventListener("scroll",s,{passive:!0});let d=null;if(typeof ResizeObserver=="function"){d=new ResizeObserver(s),d.observe(l);for(let u of c)d.observe(u)}return()=>{window.removeEventListener("resize",s);for(let u of c)u.removeEventListener("scroll",s);d?.disconnect?.()}},[e,t,n,r,o]),a}var Sn=_(Z(),1),wm=(0,it.createContext)(null),ND="Enter character to filter",OD=41,_D="data-llm-router-select-search-input";function Sm(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Sm(t)).filter(Boolean).join(" "):(0,it.isValidElement)(e)?Sm(e.props?.children):""}function Zy(e,t="first"){let n=Array.from(e?.querySelectorAll?.("[role='option']")||[]).filter(a=>a.getAttribute("aria-disabled")!=="true");if(n.length===0)return;let r=n.find(a=>a.getAttribute("data-state")==="checked");(t==="last"?n[n.length-1]:r||n[0])?.focus?.()}function kD(e={}){let t=String(e.textValue||Sm(e.children)||"").trim();return{value:String(e.value||""),textValue:t,searchText:String(e.searchText||"")}}function zE(e,t=""){let n=0,r=0;return{children:it.Children.map(e,a=>{if(!(0,it.isValidElement)(a))return a;if(a.type?.__LLM_ROUTER_SELECT_ITEM===!0){n+=1;let l=IE(kD(a.props),t);return l&&(r+=1),l?a:null}if(!a.props?.children)return a;let i=zE(a.props.children,t);return n+=i.totalItems,r+=i.matchedItems,a.type?.__LLM_ROUTER_SELECT_GROUP===!0&&i.matchedItems===0?null:(0,it.cloneElement)(a,void 0,i.children)}),totalItems:n,matchedItems:r}}function rn({open:e,defaultOpen:t=!1,onOpenChange:n,searchEnabled:r=!0,openSearchRequest:o=0,children:a,...i}){let[l,s]=(0,it.useState)(!!t),[c,d]=(0,it.useState)(""),[u,f]=(0,it.useState)(!1),p=(0,it.useRef)(null),v=(0,it.useRef)(0),m=e!==void 0?e:l;(0,it.useEffect)(()=>{m||(d(""),f(!1))},[m]);function b(g){e===void 0&&s(g),n?.(g),g||(d(""),f(!1))}(0,it.useEffect)(()=>{!o||o===v.current||(v.current=o,d(""),r&&f(!0),!m&&(e===void 0&&s(!0),n?.(!0)))},[o,r,m,e,n]);let h={open:m,searchEnabled:r,filterValue:c,setFilterValue:d,searchSessionActive:u,setSearchSessionActive:f,setOpen:b,triggerRef:p,openSearchRequest:o};return(0,Sn.jsx)(wm.Provider,{value:h,children:(0,Sn.jsx)(bE,{...i,open:m,onOpenChange:b,children:a})})}var on=(0,it.forwardRef)(function({className:t,children:n,onKeyDown:r,...o},a){let i=(0,it.useContext)(wm),l=i?.triggerRef||null,s=(0,it.useCallback)(d=>{if(l&&(l.current=d),typeof a=="function"){a(d);return}a&&(a.current=d)},[l,a]);function c(d){if(r?.(d),d.defaultPrevented||!i?.searchEnabled||o.disabled)return;let u=Qy(d);u&&(d.preventDefault(),i.setSearchSessionActive?.(!0),i.setOpen(!0),i.setFilterValue(f=>`${f}${u}`))}return(0,Sn.jsxs)(xE,{ref:s,className:F("relative inline-flex h-9 w-full items-center gap-2 rounded-lg border border-input bg-background/80 pl-3 pr-9 text-sm text-foreground shadow-sm outline-none transition focus:border-ring focus:ring-2 focus:ring-ring/40 disabled:cursor-not-allowed disabled:opacity-50",t),onKeyDown:c,...o,children:[(0,Sn.jsx)("span",{className:"min-w-0 flex-1 truncate text-left",children:n}),(0,Sn.jsx)(wE,{className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground",children:"\u25BE"})]})});function an(e){return(0,Sn.jsx)(SE,{...e})}var ln=(0,it.forwardRef)(function({className:t,children:n,position:r="popper",onKeyDownCapture:o,searchPlaceholder:a=ND,emptySearchMessage:i="No matching options.",...l},s){let c=(0,it.useContext)(wm),d=(0,it.useRef)(null),u=(0,it.useRef)(null),f=xm({open:!!c?.open,anchorRef:c?.triggerRef,preferredSide:"bottom",desiredHeight:288,offset:4}),p=DE({searchEnabled:c?.searchEnabled,filterValue:c?.filterValue,sessionActive:c?.searchSessionActive}),v=(0,it.useMemo)(()=>ym(c?.filterValue)?zE(n,c?.filterValue):{children:n,totalItems:0,matchedItems:0},[n,c?.filterValue]),m=ym(c?.filterValue)&&v.totalItems>0&&v.matchedItems===0,b=Math.max(0,Math.floor((f.maxHeight||288)-(p?OD:0)));(0,it.useEffect)(()=>{if(!c?.open||!p||typeof window>"u")return;let x=window.requestAnimationFrame(()=>{let w=u.current;if(!w)return;w.focus();let C=w.value.length;w.setSelectionRange(C,C)});return()=>window.cancelAnimationFrame(x)},[c?.open,p,c?.openSearchRequest]);let h=(0,it.useCallback)(x=>{if(d.current=x,typeof s=="function"){s(x);return}s&&(s.current=x)},[s]);function g(x){if(o?.(x),x.defaultPrevented||x.target===u.current||!c?.searchEnabled)return;let w=Qy(x);w&&(x.preventDefault(),x.stopPropagation(),c.setSearchSessionActive?.(!0),c.setFilterValue(C=>`${C}${w}`))}function y(x){let w=x.target.value;c?.setSearchSessionActive?.(!0),c?.setFilterValue(w)}return(0,Sn.jsx)(AE,{children:(0,Sn.jsxs)(CE,{ref:h,position:r,side:r==="popper"?f.side:void 0,className:F("z-50 min-w-[8rem] overflow-hidden rounded-xl border border-border/70 bg-popover text-popover-foreground shadow-lg",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=top]:-translate-y-1",t),onKeyDownCapture:g,...l,children:[p?(0,Sn.jsx)("div",{className:"border-b border-border/70 p-1",children:(0,Sn.jsx)(wt,{ref:u,"data-llm-router-select-search-input":"true",value:c?.filterValue||"",autoComplete:"off",autoCorrect:"off",autoCapitalize:"none",spellCheck:!1,placeholder:a,className:"h-8 border-border/70 bg-background/90",onChange:y,onPointerDown:x=>x.stopPropagation(),onClick:x=>x.stopPropagation(),onKeyDown:x=>{if(x.stopPropagation(),x.key==="ArrowDown"){x.preventDefault(),Zy(d.current,"first");return}if(x.key==="ArrowUp"){x.preventDefault(),Zy(d.current,"last");return}x.key==="Escape"&&(x.preventDefault(),c?.setSearchSessionActive?.(!1),c?.setFilterValue(""),typeof window<"u"&&window.requestAnimationFrame(()=>Zy(d.current)))}})}):null,(0,Sn.jsxs)(RE,{className:"px-1 pb-1",style:{maxHeight:`${b}px`},children:[ym(c?.filterValue)?v.children:n,m?(0,Sn.jsx)("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:i}):null]})]})})}),Dt=(0,it.forwardRef)(function({className:t,children:n,searchText:r="",textValue:o,onPointerMove:a,...i},l){let s=(0,it.useContext)(wm),c=String(o||Sm(n)||"").trim();function d(u){if(a?.(u),u.defaultPrevented||!s?.searchEnabled||typeof document>"u")return;let f=document.activeElement;f instanceof HTMLElement&&f.getAttribute(_D)==="true"&&u.preventDefault()}return(0,Sn.jsxs)(ME,{ref:l,className:F("relative flex w-full cursor-default select-none items-center rounded-lg py-2 pl-3 pr-8 text-sm text-foreground outline-none transition-colors hover:bg-accent/60 focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),textValue:c,onPointerMove:d,...i,children:[(0,Sn.jsx)(NE,{children:n}),(0,Sn.jsx)("span",{className:"absolute right-2 inline-flex h-4 w-4 items-center justify-center text-xs text-muted-foreground",children:(0,Sn.jsx)(OE,{children:"\u2713"})})]})});Dt.__LLM_ROUTER_SELECT_ITEM=!0;function ul(e){return(0,Sn.jsx)(EE,{...e})}ul.__LLM_ROUTER_SELECT_GROUP=!0;var Ls=(0,it.forwardRef)(function({className:t,children:n,...r},o){return(0,Sn.jsx)(TE,{ref:o,className:F("-mt-1 sticky top-0 z-10 -mx-1 mb-1 block border-b border-border/55 bg-background/96 px-4 py-2 text-xs font-semibold uppercase tracking-[0.18em] text-foreground/80 backdrop-blur-sm",t),...r,children:n})});var vu=_(Z(),1);function Jy(e={}){let t=[],n=e?.modelAliases&&typeof e.modelAliases=="object"&&!Array.isArray(e.modelAliases)?e.modelAliases:{};for(let o of Object.keys(n))t.push({value:o,label:o,hint:`Alias \xB7 ${(n[o]?.targets||[]).length||0} target(s)`,kind:"alias",groupKey:"aliases",groupLabel:"Aliases"});for(let o of Array.isArray(e?.providers)?e.providers:[]){let a=String(o?.id||"").trim(),i=String(o?.name||a||"provider").trim()||"provider";for(let l of Array.isArray(o?.models)?o.models:[]){let s=String(l?.id||"").trim();if(!a||!s)continue;let c=Number.isFinite(l?.contextWindow)?Number(l.contextWindow):null;t.push({value:`${a}/${s}`,label:`${a}/${s}`,hint:c?`${i} \xB7 ${gi(c)}`:i,kind:"model",providerId:a,groupKey:`provider:${a}`,groupLabel:i})}}let r=new Set;return t.filter(o=>!o?.value||r.has(o.value)?!1:(r.add(o.value),!0))}function LD(e=""){let t=String(e||"").trim();if(!t)return{};let n=Cf(t);if(n?.kind==="alias")return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};if(n?.kind==="model"&&n.providerId)return{kind:"model",providerId:n.providerId,groupKey:`provider:${n.providerId}`,groupLabel:n.providerId};if(n?.kind==="model")return{kind:"model",groupKey:"llm-router",groupLabel:"LLM Router"};let r=t.startsWith("alias:")?t.slice(6).trim():t;if(!r.includes("/"))return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};let o=r.indexOf("/"),a=r.slice(0,o).trim();return a?{kind:"model",providerId:a,groupKey:`provider:${a}`,groupLabel:a}:{}}function xi(e=[],t=[]){let n=[...Array.isArray(e)?e:[]],r=new Set(n.map(o=>String(o?.value||"").trim()).filter(Boolean));for(let o of(Array.isArray(t)?t:[]).map(a=>String(a||"").trim()).filter(Boolean))r.has(o)||(r.add(o),n.push({value:o,label:o,hint:"Current config",...LD(o)}));return n}function DD(e=[]){let t=[],n=new Map,r=null;for(let o of(Array.isArray(e)?e:[]).filter(Boolean)){let a=String(o?.groupKey||o?.groupLabel||"").trim(),i=String(o?.groupLabel||"").trim();if(!a){r||(r={key:"__ungrouped__",label:"",options:[]},t.push(r)),r.options.push(o);continue}let l=n.get(a);l||(l={key:a,label:i||a,options:[]},n.set(a,l),t.push(l)),l.options.push(o)}return t}function ID(e={},{includeHint:t=!1}={}){let n=String(e?.label||e?.value||"").trim()||String(e?.value||"").trim(),r=String(e?.hint||"").trim();return t&&r?`${n} \xB7 ${r}`:n}function BE(e=[],{keyPrefix:t="select-option",includeHint:n=!1}={}){return DD(e).map((r,o)=>{let a=r.options.map(i=>(0,vu.jsx)(Dt,{value:i.value,searchText:`${i.label||""} ${i.value||""} ${i.hint||""} ${r.label||""}`,children:ID(i,{includeHint:n})},`${t}-${i.value}`));return r.label?(0,vu.jsxs)(ul,{children:[(0,vu.jsx)(Ls,{children:r.label}),a]},`${t}-group-${r.key||o}`):a})}var Ds=_(me(),1),PE=_(Ri(),1);var oo=_(me(),1);var zD="flex h-9 w-full rounded-lg border border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40";function BD({committedValue:e="",draftValue:t="",isFocused:n=!1,hasLocalDraft:r=!1,previousCommittedValue:o=""}={}){let a=String(e??""),i=String(t??""),l=String(o??"");return n?{draftValue:i,hasLocalDraft:r,previousCommittedValue:a}:!r||a===i?{draftValue:a,hasLocalDraft:!1,previousCommittedValue:a}:a!==l?{draftValue:a,hasLocalDraft:!1,previousCommittedValue:a}:{draftValue:i,hasLocalDraft:!0,previousCommittedValue:a}}function UD({committedValue:e="",draftValue:t="",isFocused:n=!1,hasLocalDraft:r=!1}={}){return String(n||r?t??"":e??"")}function PD({commitOnBlur:e=!1,draftValue:t="",hasLocalDraft:n=!1}={}){return!e||!n?null:String(t??"")}var Am=(0,oo.forwardRef)(function({className:t,commitOnBlur:n=!1,value:r,onValueCommit:o,onValueChange:a,onChange:i,onFocus:l,onBlur:s,...c},d){let u=String(r??""),[f,p]=(0,oo.useState)(u),[v,m]=(0,oo.useState)(!1),[b,h]=(0,oo.useState)(!1),g=(0,oo.useRef)(u);return(0,oo.useEffect)(()=>{let y=BD({committedValue:u,draftValue:f,isFocused:v,hasLocalDraft:b,previousCommittedValue:g.current});g.current=y.previousCommittedValue,p(y.draftValue),h(y.hasLocalDraft)},[u,f,b,v]),(0,oo.createElement)("input",{...c,ref:d,className:F(zD,t),value:UD({committedValue:u,draftValue:f,isFocused:v,hasLocalDraft:b}),onFocus:y=>{m(!0),l?.(y)},onChange:y=>{let x=y.target.value;p(x),h(!0),a?.(x,y),i?.(y)},onBlur:y=>{m(!1);let x=PD({commitOnBlur:n,draftValue:f,hasLocalDraft:b});x!==null&&o?.(x,y),s?.(y)}})});var jD=/^\d*$/;function UE(e){let t=String(e??""),n=jD.test(t);return{accepted:n,draftValue:n?t:"",shouldCommit:n&&t!=="",commitValue:n&&t!==""?t:""}}var de=_(Z(),1);function VD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:e,children:[(0,de.jsx)("path",{d:"M8 12V4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),(0,de.jsx)("path",{d:"M4.75 7.25 8 4l3.25 3.25",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function HD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:e,children:[(0,de.jsx)("path",{d:"M8 4v8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),(0,de.jsx)("path",{d:"M4.75 8.75 8 12l3.25-3.25",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}function FD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,de.jsx)("path",{d:"M2.5 10s3-5.5 7.5-5.5S17.5 10 17.5 10s-3 5.5-7.5 5.5S2.5 10 2.5 10Z"}),(0,de.jsx)("circle",{cx:"10",cy:"10",r:"2.5"})]})}function KD({className:e=""}){return(0,de.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,de.jsx)("path",{d:"M8.15 4.85A8.5 8.5 0 0 1 10 4.5c4.5 0 7.5 5.5 7.5 5.5a12.4 12.4 0 0 1-1.67 2.28"}),(0,de.jsx)("path",{d:"M5.6 5.6A12.2 12.2 0 0 0 2.5 10s3 5.5 7.5 5.5a8.3 8.3 0 0 0 4.4-1.6"}),(0,de.jsx)("path",{d:"M8.23 8.23a2.5 2.5 0 0 0 3.54 3.54"}),(0,de.jsx)("path",{d:"M3 3l14 14"})]})}function Is({value:e,onChange:t,onValueChange:n,placeholder:r,disabled:o,isEnvVar:a,buffered:i,commitOnBlur:l,onValueCommit:s,className:c,inputProps:d={},maskMode:u="password"}){let[f,p]=(0,Ds.useState)(!1),v=!a&&!f,m=v&&u!=="obscured-text"?"password":"text",b=v&&u==="obscured-text"?{...d?.style&&typeof d.style=="object"?d.style:{},WebkitTextSecurity:"disc"}:d?.style,h=i?{value:e||"",onValueChange:n,onValueCommit:s,commitOnBlur:l,type:m,autoComplete:"off",spellCheck:!1,placeholder:r,disabled:o,className:F("flex h-9 w-full rounded-lg rounded-r-none border border-r-0 border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40",c),style:b,...d}:{value:e||"",onChange:t,type:m,autoComplete:"off",spellCheck:!1,placeholder:r,disabled:o,className:F("flex h-9 w-full rounded-lg rounded-r-none border border-r-0 border-input bg-background/80 px-3 py-2 text-sm text-foreground shadow-sm outline-none transition placeholder:text-muted-foreground focus:border-ring focus:ring-2 focus:ring-ring/40",c),style:b,...d};return(0,de.jsxs)("div",{className:"flex",children:[i?(0,de.jsx)(Am,{...h}):(0,de.jsx)("input",{...h}),(0,de.jsx)("button",{type:"button",tabIndex:-1,onClick:()=>p(g=>!g),disabled:o,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg rounded-l-none border border-l-0 border-input bg-background/80 text-muted-foreground transition hover:text-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50","aria-label":f?"Hide credential":"Show credential",children:f?(0,de.jsx)(KD,{className:"h-4 w-4"}):(0,de.jsx)(FD,{className:"h-4 w-4"})})]})}function Sa({disabled:e=!1,label:t="Move up",onClick:n}){return(0,de.jsx)($,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 rounded-full p-0",onMouseDown:r=>r.preventDefault(),onClick:n,disabled:e,"aria-label":t,title:t,children:(0,de.jsx)(VD,{className:"h-3.5 w-3.5"})})}function dl({disabled:e=!1,label:t="Move down",onClick:n}){return(0,de.jsx)($,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 rounded-full p-0",onMouseDown:r=>r.preventDefault(),onClick:n,disabled:e,"aria-label":t,title:t,children:(0,de.jsx)(HD,{className:"h-3.5 w-3.5"})})}function ev({active:e=!1}){return e?(0,de.jsx)("span",{"aria-hidden":"true",className:"inline-flex h-2.5 w-2.5 rounded-full bg-emerald-500"}):null}function pt({label:e,hint:t,className:n,children:r,stacked:o=!1,headerClassName:a,hintClassName:i,headerAction:l=null}){return(0,de.jsxs)("div",{className:F("flex flex-col gap-2 text-sm",n),children:[(0,de.jsxs)("div",{className:F("text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",o?"flex min-h-10 items-start justify-between gap-3":"flex items-center justify-between gap-2",a),children:[(0,de.jsxs)("div",{className:F("min-w-0",o?"flex-1 space-y-1":"flex min-w-0 items-center gap-2"),children:[(0,de.jsx)("span",{children:e}),t?(0,de.jsx)("span",{className:F("block normal-case tracking-normal text-[11px] text-muted-foreground/80",o?"leading-4":null,i),children:t}):null]}),l?(0,de.jsx)("div",{className:"shrink-0",children:l}):null]}),r]})}function Cm({value:e,onValueChange:t,disabled:n=!1,allowEmptyCommit:r=!1,...o}){let a=String(e??""),[i,l]=(0,Ds.useState)(a);return(0,Ds.useEffect)(()=>{l(a)},[a]),(0,de.jsx)(wt,{...o,value:i,inputMode:"numeric",disabled:n,onChange:s=>{let c=UE(s.target.value);c.accepted&&(l(c.draftValue),c.shouldCommit?t(c.commitValue):r&&c.draftValue===""&&t(""))},onBlur:()=>{l(s=>s!==""?s:r?(t(""),""):a)}})}function jE({label:e,hint:t,checked:n=!1,onCheckedChange:r,disabled:o=!1,className:a}){return(0,de.jsxs)("div",{className:F("flex items-center justify-between gap-4 rounded-2xl border border-border/70 bg-background/80 px-4 py-3",a),children:[(0,de.jsxs)("div",{className:"min-w-0",children:[(0,de.jsx)("div",{className:"text-sm font-medium text-foreground",children:e}),t?(0,de.jsx)("div",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:t}):null]}),(0,de.jsx)(Pc,{checked:n,onCheckedChange:r,disabled:o,className:"data-[disabled]:cursor-not-allowed data-[disabled]:opacity-60"})]})}function Zn({open:e=!1,title:t="",description:n="",onClose:r=()=>{},children:o,variant:a="dialog",headerActions:i=null,showCloseButton:l=!0,closeDisabled:s=!1,closeOnEscape:c=!0,closeOnBackdrop:d=!0,footer:u=null,contentClassName:f="",bodyClassName:p="",footerClassName:v=""}){if((0,Ds.useEffect)(()=>{if(!e||typeof window>"u")return;function h(g){g.key==="Escape"&&c&&r()}return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[c,e,r]),!e)return null;let m=a==="page",b=(0,de.jsx)("div",{className:F("fixed inset-0 z-50 bg-slate-950/55 backdrop-blur-sm",m?"p-0":"flex items-center justify-center p-4"),onMouseDown:h=>{h.target===h.currentTarget&&d&&r()},children:(0,de.jsxs)("div",{className:F("overflow-hidden border border-border/70 bg-card/95 shadow-2xl",m?"flex h-full w-full flex-col rounded-none border-x-0 border-y-0 bg-background/98":"flex max-h-[85vh] w-full max-w-3xl flex-col rounded-3xl",f),children:[(0,de.jsxs)("div",{className:F("flex items-start justify-between gap-3 border-b border-border/70",m?"px-5 py-4 sm:px-6":"px-5 py-4"),children:[(0,de.jsxs)("div",{className:"min-w-0",children:[(0,de.jsx)("div",{className:"text-base font-semibold text-foreground",children:t}),n?(0,de.jsx)("div",{className:"mt-1 text-sm leading-6 text-muted-foreground",children:n}):null]}),(0,de.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[i,l?(0,de.jsx)($,{type:"button",variant:"ghost",size:"sm",onClick:r,disabled:s,children:"Close"}):null]})]}),(0,de.jsx)("div",{className:F("overflow-y-auto",m?"min-h-0 flex-1 px-5 py-4 sm:px-6 sm:py-5":"min-h-0 flex-1 px-5 py-4",p),children:o}),u?(0,de.jsx)("div",{className:F("border-t border-border/70 bg-background/96",m?"px-5 py-4 sm:px-6":"px-5 py-4",v),children:u}):null]})});return typeof document>"u"||!document.body?b:(0,PE.createPortal)(b,document.body)}function Rm({open:e=!1,anchorRef:t,preferredSide:n="bottom",desiredHeight:r=288,offset:o=4,className:a="",children:i,...l}){let s=xm({open:e,anchorRef:t,preferredSide:n,desiredHeight:r,offset:o});return e?(0,de.jsx)("div",{className:F("absolute left-0 right-0 z-30 overflow-y-auto rounded-xl border border-border/70 bg-popover shadow-lg",s.side==="top"?"bottom-full mb-1":"top-full mt-1",a),style:{maxHeight:`${Math.max(0,Math.floor(s.maxHeight||r))}px`},...l,children:i}):null}function VE({open:e=!1,onKeepEditing:t=()=>{},onDiscardAndClose:n=()=>{},onSaveAndClose:r=()=>{},saveDisabled:o=!1,dirtyLabels:a=[],details:i=""}){let l=a.length>1?`${a.slice(0,-1).join(", ")} and ${a[a.length-1]}`:a[0]||"this form";return(0,de.jsx)(Zn,{open:e,onClose:t,title:"Unsaved changes",description:`You have unsaved edits in ${l}.`,contentClassName:"max-w-lg rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",showCloseButton:!1,footer:(0,de.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,de.jsx)($,{type:"button",variant:"ghost",onClick:t,children:"Keep editing"}),(0,de.jsx)($,{type:"button",variant:"outline",onClick:n,children:"Cancel + Close"}),(0,de.jsx)($,{type:"button",onClick:()=>{r()},disabled:o,children:"Save + Close"})]}),children:(0,de.jsxs)("div",{className:"space-y-3 text-sm leading-6 text-muted-foreground",children:[(0,de.jsx)("div",{children:"Choose whether to save these edits before closing the modal."}),i?(0,de.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-amber-900",children:i}):null]})})}function HE({open:e=!1,failedModelIds:t=[],onKeepEditing:n=()=>{},onRemoveFailedAndClose:r=()=>{},removeDisabled:o=!1}){let a=t.length>1?`${t.length} failed models`:t[0]||"the failed model";return(0,de.jsx)(Zn,{open:e,onClose:n,title:"Failed model tests",description:`Some new models did not pass validation: ${a}.`,contentClassName:"max-w-lg rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",showCloseButton:!1,footer:(0,de.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,de.jsx)($,{type:"button",variant:"ghost",onClick:n,children:"Keep editing"}),(0,de.jsx)($,{type:"button",variant:"outline",onClick:()=>{r()},disabled:o,children:"Remove failed + close"})]}),children:(0,de.jsxs)("div",{className:"space-y-3 text-sm leading-6 text-muted-foreground",children:[(0,de.jsx)("div",{children:"Successful new models are still kept in the draft. You can continue editing, or remove only the failed rows and close the modal."}),t.length>0?(0,de.jsx)("div",{className:"rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-rose-900",children:t.join(", ")}):null]})})}function Dr(){return(0,de.jsx)("span",{className:"mr-2 inline-flex h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-r-transparent align-[-0.125em]"})}function FE({children:e,onClick:t,disabled:n=!1,title:r="",className:o=""}){return(0,de.jsx)("button",{type:"button",className:F("inline-flex items-center rounded-full border border-border bg-background/70 px-2.5 py-1 text-[11px] font-medium tracking-wide text-muted-foreground transition hover:border-primary/35 hover:bg-primary/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",o),onClick:t,disabled:n,title:r,"aria-label":r||void 0,children:e})}var Me=_(Z(),1);function $D({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("circle",{cx:"6.75",cy:"10",r:"3.25"}),(0,Me.jsx)("path",{d:"M10 10h6.5"}),(0,Me.jsx)("path",{d:"M13.5 10v2.25"}),(0,Me.jsx)("path",{d:"M15.75 10v1.5"})]})}function GD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M16.25 10a6.25 6.25 0 1 1-1.83-4.42"}),(0,Me.jsx)("path",{d:"M13.5 3.75h3v3"}),(0,Me.jsx)("path",{d:"M16.5 3.75 12.75 7.5"})]})}function qD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M7.25 5.75h-1.5A2.75 2.75 0 0 0 3 8.5v5.75A2.75 2.75 0 0 0 5.75 17h5.75a2.75 2.75 0 0 0 2.75-2.75v-1.5"}),(0,Me.jsx)("path",{d:"M10.5 9.5 17 3"}),(0,Me.jsx)("path",{d:"M12 3h5v5"})]})}function WD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M6 3.5h5.25L15 7.25V16A1.5 1.5 0 0 1 13.5 17.5h-7A1.5 1.5 0 0 1 5 16V5A1.5 1.5 0 0 1 6.5 3.5H6Z"}),(0,Me.jsx)("path",{d:"M11 3.5V7.5H15"})]})}function YD({className:e=""}){return(0,Me.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,Me.jsx)("path",{d:"M6 3.5h5.25L15 7.25V16A1.5 1.5 0 0 1 13.5 17.5h-7A1.5 1.5 0 0 1 5 16V5A1.5 1.5 0 0 1 6.5 3.5H6Z"}),(0,Me.jsx)("path",{d:"M11 3.5V7.5H15"}),(0,Me.jsx)("path",{d:"M7 12.25a3 3 0 1 1 2.85 2.99"}),(0,Me.jsx)("path",{d:"M8.5 10.25h1.5v1.5"})]})}function QD({label:e,value:t,icon:n,disabled:r=!1,onClick:o,actionLabel:a}){return(0,Me.jsxs)("button",{type:"button",className:"inline-flex h-9 min-w-0 max-w-full items-center gap-2 rounded-full border border-border/70 bg-background/90 px-3 text-left transition hover:border-accent hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70 sm:max-w-[18rem]",onClick:o,disabled:r,"aria-label":a,title:r?a:t,children:[(0,Me.jsx)("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-secondary text-muted-foreground",children:n}),(0,Me.jsx)("span",{className:"shrink-0 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:e}),(0,Me.jsx)("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:t})]})}function XD({value:e,pending:t=!1,disabled:n=!1,rotateDisabled:r=!1,onCopy:o,onRotate:a}){return(0,Me.jsxs)("div",{className:"flex h-9 min-w-0 max-w-full items-stretch overflow-hidden rounded-full border border-border/70 bg-background/90 sm:max-w-[18rem]",children:[(0,Me.jsxs)("button",{type:"button",className:"inline-flex min-w-0 flex-1 items-center gap-2 rounded-l-full px-3 text-left transition hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70",onClick:o,disabled:n,"aria-label":t?"Gateway key is still generating":"Copy gateway key",title:t?"Gateway key is still generating":"Copy gateway key",children:[(0,Me.jsx)("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-secondary text-muted-foreground",children:(0,Me.jsx)($D,{className:"h-3.5 w-3.5"})}),(0,Me.jsx)("span",{className:"shrink-0 text-[10px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"Gateway key"}),(0,Me.jsx)("span",{className:"min-w-0 truncate text-xs font-medium text-foreground",children:e})]}),(0,Me.jsx)("button",{type:"button",className:"inline-flex w-9 shrink-0 items-center justify-center rounded-r-full border-l border-border/70 text-muted-foreground transition hover:bg-accent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-70",onClick:a,disabled:r,"aria-label":"Rotate gateway key",title:"Rotate gateway key",children:(0,Me.jsx)(GD,{className:"h-3.5 w-3.5"})})]})}function $E({endpointValue:e,endpointDisabled:t=!1,gatewayValue:n,gatewayPending:r=!1,gatewayDisabled:o=!1,rotateDisabled:a=!1,onCopyEndpoint:i,onCopyGatewayKey:l,onRotateKey:s}){return(0,Me.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,Me.jsx)(QD,{label:"Endpoint",value:e,icon:(0,Me.jsx)(qD,{className:"h-3.5 w-3.5"}),disabled:t,onClick:i,actionLabel:t?"API endpoint not ready yet":"Copy API endpoint"}),(0,Me.jsx)(XD,{value:n,pending:r,disabled:o,rotateDisabled:a,onCopy:l,onRotate:s})]})}function KE({label:e,value:t,icon:n,disabled:r=!1,onClick:o,actionLabel:a="",emptyLabel:i="Not resolved"}){let l=String(t||"").trim()||i;return(0,Me.jsxs)("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-start gap-2 rounded-2xl border border-border/70 bg-background/90 px-3 py-2 text-left transition hover:border-accent hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70",onClick:o,disabled:r,"aria-label":a,title:r?a:l,children:[(0,Me.jsx)("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-secondary text-muted-foreground",children:n}),(0,Me.jsxs)("span",{className:"min-w-0",children:[(0,Me.jsx)("span",{className:"block text-[9px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:e}),(0,Me.jsx)("span",{className:"mt-1 block break-all text-[11px] font-medium leading-4 text-foreground",children:l})]})]})}function fl({connected:e=!1,className:t,srLabel:n="Connected",size:r="sm"}){if(!e)return null;let o=r==="md"?"h-3.5 w-3.5":"h-2.5 w-2.5",a=r==="md"?"h-2 w-2":"h-1.5 w-1.5";return(0,Me.jsxs)("span",{className:F("relative inline-flex shrink-0 items-center justify-center",o,t),children:[(0,Me.jsx)("span",{"aria-hidden":"true",className:"absolute inset-0 rounded-full bg-emerald-400/45 animate-ping motion-reduce:animate-none"}),(0,Me.jsx)("span",{"aria-hidden":"true",className:F("relative rounded-full bg-emerald-500 ring-2 ring-emerald-500/15",a)}),(0,Me.jsx)("span",{className:"sr-only",children:n})]})}function Em({primaryLabel:e="Config file",primaryValue:t="",primaryIcon:n=(0,Me.jsx)(WD,{className:"h-3 w-3"}),onOpenPrimary:r,secondaryLabel:o="Backup file",secondaryValue:a="",secondaryIcon:i=(0,Me.jsx)(YD,{className:"h-3 w-3"}),onOpenSecondary:l}){let s=String(t||"").trim(),c=String(a||"").trim();return(0,Me.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,Me.jsx)(KE,{label:e,value:s,icon:n,disabled:!s||typeof r!="function",onClick:r,actionLabel:s?`Open ${e.toLowerCase()}`:`${e} path is not resolved yet`}),(0,Me.jsx)(KE,{label:o,value:c,icon:i,disabled:!c||typeof l!="function",onClick:l,actionLabel:c?`Open ${o.toLowerCase()}`:`${o} path is not resolved yet`})]})}var Fo=_(me(),1);var Jt=_(Z(),1);function ZD(e){return e==="error"?"Error":e==="success"?"Success":"Notice"}function JD({notice:e,onDismiss:t}){let[n,r]=(0,Fo.useState)(Rf),[o,a]=(0,Fo.useState)(Rf),[i,l]=(0,Fo.useState)(!1),s=(0,Fo.useRef)(null),c=(0,Fo.useRef)(0);(0,Fo.useEffect)(()=>{if(n<=0){t();return}if(i){s.current&&(clearTimeout(s.current),s.current=null);return}return c.current=Date.now(),s.current=setTimeout(()=>{s.current=null,t()},n),()=>{s.current&&(clearTimeout(s.current),s.current=null)}},[t,i,n]),(0,Fo.useEffect)(()=>{if(i||n<=0){a(n);return}let g=()=>{let x=c.current?Date.now()-c.current:0;a(Math.max(0,n-x))};g();let y=setInterval(g,zA);return()=>clearInterval(y)},[i,n]);function d(){if(i)return;s.current&&(clearTimeout(s.current),s.current=null);let g=c.current?Date.now()-c.current:0,y=Math.max(0,n-g);r(y),a(y),l(!0)}function u(){l(!1)}let f=e.tone==="error"?"border-rose-200 bg-rose-50 text-rose-800":e.tone==="success"?"border-emerald-200 bg-emerald-50 text-emerald-800":"border-amber-200 bg-amber-50 text-amber-800",p=9,v=2*Math.PI*p,m=Math.max(0,Math.min(1,o/Rf)),b=v*(1-m),h=i?`Auto-dismiss paused with ${Math.max(0,o/1e3).toFixed(1)} seconds remaining`:`Auto-dismiss in ${Math.max(0,o/1e3).toFixed(1)} seconds`;return(0,Jt.jsx)("div",{className:F("pointer-events-auto rounded-2xl border px-4 py-3 text-sm shadow-lg backdrop-blur",f),onMouseEnter:d,onMouseLeave:u,onFocusCapture:d,onBlurCapture:g=>{g.currentTarget.contains(g.relatedTarget)||u()},role:e.tone==="error"?"alert":"status",children:(0,Jt.jsxs)("div",{className:"min-w-0",children:[(0,Jt.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,Jt.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-[0.16em] opacity-75",children:ZD(e.tone)}),(0,Jt.jsxs)("div",{className:"relative mt-0.5 h-6 w-6 shrink-0 opacity-85","aria-label":h,title:h,children:[(0,Jt.jsxs)("svg",{viewBox:"0 0 24 24",className:F("h-6 w-6 -rotate-90",i?"opacity-70":"opacity-100"),"aria-hidden":"true",children:[(0,Jt.jsx)("circle",{cx:"12",cy:"12",r:p,fill:"none",stroke:"currentColor",strokeOpacity:"0.18",strokeWidth:"2"}),(0,Jt.jsx)("circle",{cx:"12",cy:"12",r:p,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeDasharray:v,strokeDashoffset:b,className:"transition-[stroke-dashoffset,opacity] duration-100 ease-linear"})]}),(0,Jt.jsx)("span",{className:F("pointer-events-none absolute inset-0 flex items-center justify-center",i?"gap-[2px]":""),"aria-hidden":"true",children:i?(0,Jt.jsxs)(Jt.Fragment,{children:[(0,Jt.jsx)("span",{className:"h-2.5 w-[2px] rounded-full bg-current/75"}),(0,Jt.jsx)("span",{className:"h-2.5 w-[2px] rounded-full bg-current/75"})]}):(0,Jt.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-current/75"})})]})]}),(0,Jt.jsx)("div",{className:"mt-1 leading-6",children:e.message}),(0,Jt.jsx)("div",{className:"mt-2 flex justify-end",children:(0,Jt.jsx)("button",{className:"rounded-full border border-current/15 px-2.5 py-1 text-[11px] font-medium uppercase tracking-[0.16em] opacity-85 transition hover:border-current/30 hover:opacity-100",onClick:t,type:"button",children:"Dismiss"})})]})})}function tv({notices:e,onDismiss:t}){return!Array.isArray(e)||e.length===0?null:(0,Jt.jsx)("div",{className:"pointer-events-none fixed inset-x-4 top-4 z-50 flex flex-col items-end gap-3","aria-live":"polite","aria-relevant":"additions text",children:e.map(n=>(0,Jt.jsx)("div",{className:"w-full max-w-md",children:(0,Jt.jsx)(JD,{notice:n,onDismiss:()=>t(n.id)})},n.id))})}var Aa=_(me(),1);var Tn=_(me(),1);var $n=_(me(),1);var wa=_(me(),1);function zs(e=[]){let t=(0,wa.useRef)(new Map),n=(0,wa.useRef)(new Map),r=(0,wa.useRef)(new Map),o=(0,wa.useRef)(""),a=JSON.stringify(e);return(0,wa.useLayoutEffect)(()=>{let i=new Map;for(let d of e){let u=t.current.get(d);u&&i.set(d,u.getBoundingClientRect())}let l=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(o.current!==""&&o.current!==a&&!l)for(let d of e){let u=r.current.get(d),f=i.get(d),p=t.current.get(d);if(!u||!f||!p)continue;let v=u.top-f.top;Math.abs(v)<1||typeof p.animate!="function"||p.animate([{transform:`translateY(${v}px)`},{transform:"translateY(0)"}],{duration:220,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})}let c=new Set(e);for(let d of n.current.keys())c.has(d)||n.current.delete(d);r.current=i,o.current=a},[a]),(0,wa.useMemo)(()=>i=>(n.current.has(i)||n.current.set(i,l=>{if(l){t.current.set(i,l);return}t.current.delete(i)}),n.current.get(i)),[])}var yt=_(Z(),1);function nv({title:e,rows:t,onChange:n,options:r,disabled:o=!1,addLabel:a="Add target",emptyLabel:i="No targets configured.",helperText:l="Drag rows or use the arrow to change routing order.",helperAction:s=null,placeholder:c="provider/model or alias",draftPlaceholder:d="Add a new route",showDraftRow:u=!1,showDraftFocusButton:f=!1,showWeightInput:p=!1,filterOtherSelectedValues:v=!1,excludedValues:m=[]}){let b=(0,$n.useRef)(0),h=(0,$n.useRef)(""),g=(0,$n.useRef)(null),y=(0,$n.useRef)(new Map),x=(0,$n.useRef)(0),w=(0,$n.useRef)(0),[C,E]=(0,$n.useState)(0),A=(0,$n.useMemo)(()=>String(e||"targets").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"targets",[e]),M=`${A}-draft-row`,L=(0,$n.useMemo)(()=>{let X=(t||[]).filter(je=>String(je?.ref||"").trim());return u?[{key:M,ref:"",sourceRef:""},...X]:X},[t,u,M]),P=zs(L.map(X=>X.key)),D=(0,$n.useMemo)(()=>pr(m),[m]),G=(0,$n.useMemo)(()=>xi(r,[...L.map(X=>X?.ref),...D]),[r,L,D]);(0,$n.useEffect)(()=>()=>{typeof window<"u"&&x.current&&window.cancelAnimationFrame(x.current)},[]);function ae(X,je){if(u&&X===M){if(!String(je||"").trim())return;b.current+=1,n([{key:`${A}-draft-${b.current}`,ref:je,sourceRef:"",...p?{weight:"1"}:{}},...(t||[]).filter(ie=>String(ie?.ref||"").trim())]);return}n((t||[]).map(ie=>ie.key===X?{...ie,ref:je}:ie))}function ge(X,je){n((t||[]).map(ie=>ie.key===X?{...ie,weight:je}:ie))}function j(X){n((t||[]).filter(je=>je.key!==X))}function J(X){n(xs(t||[],X,je=>je?.key))}function Q(X){n(kf(t||[],X,je=>je?.key))}function H(){h.current="",va(g.current,!1),g.current=null}function B(){b.current+=1;let X=new Set([...(t||[]).map(ie=>String(ie?.ref||"").trim()).filter(Boolean),...D]),je=G.find(ie=>!X.has(ie.value))?.value||"";n([...t||[],{key:`${A}-draft-${b.current}`,ref:je,sourceRef:""}])}function ft(){if(!u||o)return;let X=y.current.get(M);if(!X||typeof window>"u"){E(Fe=>Fe+1);return}w.current+=1;let je=w.current;x.current&&(window.cancelAnimationFrame(x.current),x.current=0),X.scrollIntoView({block:"start",behavior:"smooth"});let ie=bm(X),xe=qh(X,ie),Ie=0,I=0,ue=90,he=8,_e=6,Ee=.5,ve=()=>{if(w.current!==je)return;let Fe=y.current.get(M)||X,Je=qh(Fe,ie);if(!Number.isFinite(Je.top)||!Number.isFinite(Je.left)){x.current=0,E(Ht=>Ht+1);return}if(nC(xe,Je,Ee)?Ie+=1:Ie=0,xe=Je,I+=1,I>=he&&Ie>=_e||I>=ue){x.current=0,E(Ht=>Ht+1);return}x.current=window.requestAnimationFrame(ve)};x.current=window.requestAnimationFrame(ve)}return(0,yt.jsxs)("div",{className:"space-y-2 rounded-2xl border border-border/70 bg-background/55 p-4",children:[(0,yt.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,yt.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,yt.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:e}),f&&u?(0,yt.jsx)($,{type:"button",variant:"ghost",size:"sm",className:"h-6 w-6 rounded-md p-0 text-muted-foreground hover:text-foreground",onMouseDown:X=>X.preventDefault(),onClick:ft,disabled:o,"aria-label":a,title:a,children:(0,yt.jsx)(KA,{className:"h-3.5 w-3.5"})}):null]}),(0,yt.jsxs)("div",{className:"ml-auto flex max-w-full flex-wrap items-start justify-end gap-x-3 gap-y-2",children:[l?(0,yt.jsx)("div",{className:"max-w-[34rem] text-right text-[11px] leading-4 text-muted-foreground",children:l}):null,u?null:(0,yt.jsx)($,{type:"button",variant:"ghost",onClick:B,disabled:o,children:a})]})]}),L.length>0?(0,yt.jsx)("div",{className:"space-y-2",children:L.map((X,je)=>{let ie=u&&X.key===M,xe=ie?-1:(t||[]).findIndex(I=>I?.key===X.key),Ie=v?G.filter(I=>{let ue=String(I?.value||"").trim();return ue?ue===String(X?.ref||"").trim()?!0:D.includes(ue)?!1:!(L||[]).some(he=>he?.key!==X.key&&String(he?.ref||"").trim()===ue):!1}):G;return(0,yt.jsxs)("div",{ref:I=>{if(P(X.key)(I),I){y.current.set(X.key,I);return}y.current.delete(X.key)},"data-reorder-row":"true",onDragOver:I=>{!o&&h.current&&h.current!==X.key&&(I.preventDefault(),I.dataTransfer.dropEffect="move")},onDrop:I=>{if(o)return;I.preventDefault();let ue=I.dataTransfer.getData("text/plain")||h.current;H(),n(_f(t||[],ue,X.key))},className:F(p?"grid grid-cols-[auto_auto_auto_minmax(0,1fr)_10rem_5.5rem] items-center gap-2 rounded-xl border border-border/70 bg-card/90 p-3":"grid grid-cols-[auto_auto_auto_minmax(0,1fr)_5.5rem] items-center gap-2 rounded-xl border border-border/70 bg-card/90 p-3",ie?"border-dashed bg-background/85":null),children:[(0,yt.jsx)("span",{className:F("flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground",ie||o?"opacity-45":"cursor-grab"),draggable:!o&&!ie,onDragStart:I=>{if(o||ie)return;let ue=Ss(I.currentTarget);I.dataTransfer.effectAllowed="move",I.dataTransfer.setData("text/plain",X.key),ue&&typeof I.dataTransfer?.setDragImage=="function"&&I.dataTransfer.setDragImage(ue,20,20),H(),h.current=X.key,g.current=ue,va(ue,!0)},onDragEnd:H,title:ie?"New route draft row":"Drag to reorder",children:(0,yt.jsx)(vs,{className:"h-4 w-4"})}),(0,yt.jsx)(Sa,{disabled:o||ie||xe<=0,label:ie||xe<=0?"Already first":`Move ${X.ref||`target ${xe+1}`} up`,onClick:()=>J(X.key)}),(0,yt.jsx)(dl,{disabled:o||ie||xe===-1||xe>=(t||[]).length-1,label:ie||xe===-1||xe>=(t||[]).length-1?"Already last":`Move ${X.ref||`target ${xe+1}`} down`,onClick:()=>Q(X.key)}),(0,yt.jsxs)("div",{className:"flex h-9 min-w-0 overflow-hidden rounded-lg border border-input bg-background/80 shadow-sm transition focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/40",children:[(0,yt.jsx)("div",{className:"flex shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Model"}),(0,yt.jsxs)(rn,{value:X.ref||void 0,onValueChange:I=>ae(X.key,I),disabled:o,openSearchRequest:ie?C:0,children:[(0,yt.jsx)(on,{className:"h-full min-w-0 flex-1 rounded-none border-0 bg-transparent px-3 shadow-none focus:border-transparent focus:ring-0",children:(0,yt.jsx)(an,{placeholder:ie?d:c})}),(0,yt.jsx)(ln,{children:Ie.length>0?BE(Ie,{keyPrefix:`${e}-row-${X.key}`}):(0,yt.jsx)(Dt,{value:"__no-route-options",disabled:!0,children:"No routes available"})})]})]}),p?(0,yt.jsxs)("div",{className:F("flex h-9 overflow-hidden rounded-lg border border-input bg-background/80 shadow-sm transition focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/40",ie?"opacity-45":null),children:[(0,yt.jsx)("div",{className:"flex shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Weight"}),(0,yt.jsx)(wt,{value:ie?"":String(X?.weight||"1"),onChange:I=>ge(X.key,I.target.value),inputMode:"numeric",placeholder:"1",disabled:o||ie,className:"h-full min-w-0 rounded-none border-0 bg-transparent px-3 text-center shadow-none focus:border-transparent focus:ring-0","aria-label":ie?"Weight for new target":`Weight for ${X.ref||`target ${je+1}`}`})]}):null,ie?(0,yt.jsx)($,{type:"button",variant:"ghost",className:F(ys,"pointer-events-none invisible"),tabIndex:-1,disabled:!0,"aria-hidden":"true",children:"Remove"}):(0,yt.jsx)($,{type:"button",variant:"ghost",className:ys,onMouseDown:I=>I.preventDefault(),onClick:()=>j(X.key),disabled:o,children:"Remove"})]},X.key)})}):(0,yt.jsx)("div",{className:"rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:i}),s?(0,yt.jsx)("div",{className:"flex min-h-8 items-center justify-end",children:s}):null]})}var ml=_(me(),1);var te=_(Z(),1);function e5(e,t){let n=Math.abs(Number(e)||0),r=Math.abs(Number(t)||0);for(;r!==0;){let o=n%r;n=r,r=o}return n||1}function t5(e=[]){return!Array.isArray(e)||e.length===0?1:e.reduce((t,n)=>e5(t,n),0)||1}function n5(e,t){let n=String(e||"").trim();if(!n)return"Unconfigured route";let r=t.get(n);if(!r)return n;let o=String(r.label||n).trim()||n,a=String(r.hint||"").trim();return a&&a!==o?`${o} \xB7 ${a}`:o}function GE(e,t,n=[]){let r=new Map((n||[]).map(l=>[String(l?.value||"").trim(),l]).filter(([l])=>!!l)),o=new Map((Array.isArray(t?.targets)?t.targets:[]).map(l=>[String(l?.ref||"").trim(),l]).filter(([l])=>!!l)),a=new Map((Array.isArray(t?.fallbackTargets)?t.fallbackTargets:[]).map(l=>[String(l?.ref||"").trim(),l]).filter(([l])=>!!l));function i(l,s,c){return(l||[]).map((d,u)=>{let f=String(d?.ref||"").trim(),p=String(d?.sourceRef||d?.ref||"").trim(),v=c.get(p)||c.get(f)||{},m=Number(d?.weight??v?.weight),b=Number.isFinite(m)&&m>0?Math.floor(m):1;return{key:`${s}-${f||"empty"}-${u}`,ref:f,label:n5(f,r),bucket:s,weight:b}}).filter(d=>!!d.ref)}return[...i(e?.targets,"primary",o),...i(e?.fallbackTargets,"fallback",a)]}function r5(e=[],t=8){if(!Array.isArray(e)||e.length===0)return[];let n=e.map(l=>Math.max(1,Number(l?.weight)||1)),r=t5(n),o=n.map(l=>Math.max(1,Math.floor(l/r))),a=o.reduce((l,s)=>l+s,0);if(a>24){let l=a/24;o=o.map(s=>Math.max(1,Math.round(s/l))),a=o.reduce((s,c)=>s+c,0)}let i=[];for(let l=0;l<e.length;l+=1)for(let s=0;s<o[l];s+=1)i.push(e[l]);return Array.from({length:Math.max(e.length,t)},(l,s)=>i[s%i.length])}function o5(e,t=[]){let n=Lf(e),r=Df(n),o=Array.isArray(t)?t.filter(Boolean):[],i=o.some(l=>l.bucket==="fallback")?"Runtime builds the candidate pool as all primary targets first, then all fallback targets.":"Runtime builds the candidate pool from the primary target list only.";if(n==="round-robin"){let l=o.length>0?Array.from({length:Math.max(o.length,8)},(s,c)=>o[c%o.length]):[];return{strategyLabel:r,summary:"Each new request starts from the next candidate in the current pool, then wraps around.",poolNote:`${i} Round-robin rotates across that combined eligible list.`,sequenceLabel:"Example starting candidate by request",sequenceEntries:l,footnote:"If a candidate is unhealthy or quota-blocked, it is skipped and the next eligible candidate is chosen."}}if(n==="weighted-rr"||n==="quota-aware-weighted-rr"||n==="auto"){let l=n==="auto",s=r5(o,8);return{strategyLabel:r,summary:l?"`auto` normalizes to quota-aware weighted round-robin in the runtime balancer.":n==="quota-aware-weighted-rr"?"Candidates rotate like weighted round-robin, but low remaining quota or poor health lowers their share.":"Candidates repeat in proportion to their configured weights.",poolNote:`${i} This strategy ranks across the full eligible pool after it is built.`,sequenceLabel:"Example starting candidate by request",sequenceEntries:s,footnote:l||n==="quota-aware-weighted-rr"?"When all quotas and health scores are equal, the rotation looks like the weighted example below. Low remaining capacity or retryable failures push a target later.":"Weights come from the existing alias target metadata when present. Targets without a stored weight behave as weight 1."}}return{strategyLabel:r,summary:"Requests try candidates in the configured list order and only move to later candidates when earlier ones are unavailable or fail.",poolNote:`${i} Ordered keeps that exact sequence.`,sequenceLabel:"Attempt order",sequenceEntries:o,footnote:"This is the most predictable option when you want a strict preference order."}}function qE({open:e=!1,onClose:t=()=>{},onSave:n=()=>{},aliasLabel:r="",initialStrategy:o="auto",entries:a=[],disabled:i=!1}){let l=Lf(o),[s,c]=(0,ml.useState)(l),[d,u]=(0,ml.useState)(!1);(0,ml.useEffect)(()=>{e&&(c(l),u(!1))},[e,l,r]);async function f(){if(!(i||d)){u(!0);try{await n(s)!==!1&&t()}finally{u(!1)}}}return(0,te.jsx)(Zn,{open:e,onClose:t,title:r?`Choose strategy \xB7 ${r}`:"Choose strategy",description:"Review each routing strategy in its own tab. Save applies the currently selected tab to this alias.",showCloseButton:!1,footer:(0,te.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,te.jsx)($,{type:"button",variant:"ghost",onClick:t,disabled:d,children:"Cancel"}),(0,te.jsx)($,{type:"button",onClick:()=>{f()},disabled:i||d,children:d?"Saving\u2026":"Save strategy"})]}),children:(0,te.jsxs)(fs,{value:s,onValueChange:c,children:[(0,te.jsx)("div",{className:"overflow-x-auto pb-1",children:(0,te.jsx)(ms,{className:"h-auto min-w-max flex-wrap justify-start gap-2 rounded-2xl bg-secondary/80 p-2",children:Ef.map(p=>(0,te.jsx)(dr,{value:p.value,className:"h-auto min-h-10 rounded-xl px-4 py-2",children:p.label},p.value))})}),Ef.map(p=>{let v=o5(p.value,a),m=(v.sequenceEntries||[]).filter(Boolean);return(0,te.jsx)(fr,{value:p.value,className:"mt-4",children:(0,te.jsxs)("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)]",children:[(0,te.jsxs)("div",{className:"space-y-4",children:[(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-5",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)(ut,{variant:"outline",children:v.strategyLabel}),(0,te.jsxs)(ut,{variant:"info",children:[a.length," candidate",a.length===1?"":"s"]})]}),(0,te.jsxs)("div",{className:"mt-4 space-y-3 text-sm leading-6 text-foreground",children:[(0,te.jsx)("p",{children:v.summary}),(0,te.jsx)("p",{className:"text-muted-foreground",children:v.poolNote})]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-5",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:v.sequenceLabel}),m.length>0?(0,te.jsx)("div",{className:"mt-4 flex flex-wrap gap-2",children:m.map((b,h)=>(0,te.jsxs)("div",{className:"rounded-full border border-border/70 bg-card/90 px-3 py-1.5 text-sm text-foreground",children:[(0,te.jsx)("span",{className:"mr-2 text-xs text-muted-foreground",children:h+1}),(0,te.jsx)("span",{children:b.label})]},`${b.key}-sequence-${h}`))}):(0,te.jsx)("div",{className:"mt-4 rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:"Add at least one target to preview how this strategy would route requests."}),(0,te.jsx)("div",{className:"mt-4 text-sm leading-6 text-muted-foreground",children:v.footnote})]})]}),(0,te.jsx)("div",{className:"space-y-4",children:(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-5",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Current setup"}),r?(0,te.jsx)(ut,{variant:"outline",children:r}):null]}),a.length>0?(0,te.jsx)("div",{className:"mt-4 space-y-2",children:a.map(b=>(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2 rounded-xl border border-border/70 bg-card/90 px-3 py-2 text-sm",children:[(0,te.jsx)(ut,{variant:b.bucket==="primary"?"info":"outline",children:b.bucket}),(0,te.jsx)("span",{className:"font-medium text-foreground",children:b.label}),(0,te.jsxs)("span",{className:"text-xs text-muted-foreground",children:["weight ",b.weight]})]},b.key))}):(0,te.jsx)("div",{className:"mt-4 rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:"This alias does not have any targets yet."})]})})]})},p.value)})]})})}function WE({open:e=!1,onClose:t=()=>{},config:n={}}){let r=(0,ml.useMemo)(()=>FC(n),[n]);return(0,te.jsx)(Zn,{open:e,onClose:t,title:"Alias guide",description:"Aliases give clients one stable route while letting LLM Router swap, balance, and fail over across provider/model targets behind that route.",contentClassName:"max-h-[92vh] max-w-4xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)]",children:(0,te.jsxs)("div",{className:"space-y-4",children:[(0,te.jsxs)("div",{className:"grid gap-4 md:grid-cols-3",children:[(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Stable route"}),(0,te.jsxs)("div",{className:"mt-2 text-sm leading-6 text-foreground",children:["Expose one alias like ",(0,te.jsx)("code",{children:"coding"})," or ",(0,te.jsx)("code",{children:"gpt-5.4"})," to clients, then retarget the alias later without touching client config."]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Selection strategy"}),(0,te.jsx)("div",{className:"mt-2 text-sm leading-6 text-foreground",children:"The alias strategy controls how LLM Router picks from the configured targets. Ordered is strict preference; the other strategies distribute traffic when multiple targets are healthy."})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Fallback behavior"}),(0,te.jsx)("div",{className:"mt-2 text-sm leading-6 text-foreground",children:"If one target is unavailable or rate limited, LLM Router can continue to later candidates in the same alias instead of failing the whole request immediately."})]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-4",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)(ut,{variant:"warning",children:"Important"}),(0,te.jsx)("div",{className:"text-sm font-medium text-amber-950",children:"Mixed context windows inside one alias can change behavior."})]}),(0,te.jsxs)("div",{className:"mt-3 text-sm leading-6 text-amber-900",children:["If an alias mixes models with different context windows, requests that fit the larger model may still fail on the smaller model. For example, an alias that includes both a ",(0,te.jsx)("code",{children:"258K"})," model and a ",(0,te.jsx)("code",{children:"128K"})," model can still fail when routing lands on the smaller target. Keep aliases aligned by context size when you expect long histories or large prompts."]})]}),(0,te.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Current config check"}),(0,te.jsx)("div",{className:"mt-1 text-sm text-muted-foreground",children:"Aliases below currently mix different configured model context windows."})]}),(0,te.jsx)(ut,{variant:r.length>0?"warning":"success",children:r.length>0?`${r.length} alias${r.length===1?"":"es"} need review`:"No mixed context windows detected"})]}),r.length>0?(0,te.jsx)("div",{className:"mt-4 space-y-3",children:r.map(o=>(0,te.jsxs)("div",{className:"rounded-2xl border border-amber-200 bg-amber-50/70 p-4",children:[(0,te.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,te.jsx)(ut,{variant:"outline",children:o.aliasId}),(0,te.jsxs)("div",{className:"text-sm font-medium text-amber-950",children:["Smallest target: ",gi(o.smallestContextWindow),". Largest target: ",gi(o.largestContextWindow),"."]})]}),(0,te.jsxs)("div",{className:"mt-3 flex flex-wrap gap-2",children:[o.models.map(a=>(0,te.jsxs)("div",{className:"rounded-full border border-amber-200 bg-background/90 px-3 py-1.5 text-sm text-foreground",children:[a.ref," \xB7 ",gi(a.contextWindow)]},a.ref)),o.unknownRefs.map(a=>(0,te.jsxs)("div",{className:"rounded-full border border-dashed border-amber-300 bg-background/70 px-3 py-1.5 text-sm text-muted-foreground",children:[a," \xB7 context unknown"]},a))]})]},o.aliasId))}):(0,te.jsx)("div",{className:"mt-4 rounded-xl border border-dashed border-border px-4 py-5 text-sm text-muted-foreground",children:"No alias currently mixes known context-window sizes across its configured targets."})]})]})})}var Ae=_(Z(),1),a5=500;function Si(e=[]){return(e||[]).map(t=>({ref:String(t?.ref||"").trim(),weight:String(t?.weight||"1").trim()}))}function rv({aliasId:e,alias:t,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabled:i=!1,disabledReason:l="",busy:s=!1,onApply:c,onRemove:d,onCopyAliasId:u=()=>{},isNew:f=!1,alwaysShowAliasIdInput:p=!1,showIssueOnSubmitOnly:v=!1,onDiscard:m=()=>{},onOpenStrategyModal:b=()=>{},titleAccessory:h=null,aliasSwitcher:g=null,framed:y=!0}){let x=aC(e,t,{isNew:f}),w=(0,Tn.useMemo)(()=>MA(f?"":e,t),[x]),[C,E]=(0,Tn.useState)(w),[A,M]=(0,Tn.useState)(f),[L,P]=(0,Tn.useState)(!1),D=(0,Tn.useRef)(null),G=(0,Tn.useRef)(0),ae=(0,Tn.useRef)(""),[ge,j]=(0,Tn.useState)("idle");(0,Tn.useEffect)(()=>{E(w),M(f),P(!1),j("idle"),ae.current=""},[w,f]);let J=!f&&Array.isArray(g?.entries)&&g.entries.length>1,Q=p||A;(0,Tn.useEffect)(()=>{if(!Q)return;let q=typeof window<"u"?window.requestAnimationFrame(()=>{D.current?.focus(),D.current?.select?.()}):0;return()=>{typeof window<"u"&&window.cancelAnimationFrame(q)}},[Q]);let H=String(C?.id||"").trim(),B=e===St||H===St,ft=(0,Tn.useMemo)(()=>xi((r||[]).filter(q=>q.kind!=="alias"&&q.value!==H&&q.value!==`alias:${H}`),[...(C?.targets||[]).map(q=>q?.ref),...(C?.fallbackTargets||[]).map(q=>q?.ref)]),[r,H,C?.targets,C?.fallbackTargets]),X=(C?.targets||[]).map(q=>String(q?.ref||"").trim()),je=(C?.fallbackTargets||[]).map(q=>String(q?.ref||"").trim()),ie=[...X,...je],xe=[...C?.targets||[],...C?.fallbackTargets||[]],Ie=xe.some(q=>!String(q?.ref||"").trim()),I=ws(ie),ue=xe.some(q=>{if(!String(q?.ref||"").trim())return!1;let be=Math.floor(Number(q?.weight));return!Number.isFinite(be)||be<=0}),he=H&&n.some(q=>q!==e&&q===H),_e=H&&ie.some(q=>q===H||q===`alias:${H}`),Ee=ie.filter(Boolean).length>0,ve=JSON.stringify({id:w.id,strategy:w.strategy,targets:Si(w.targets),fallbackTargets:Si(w.fallbackTargets)}),Fe=JSON.stringify({id:H,strategy:C?.strategy,targets:Si(C?.targets),fallbackTargets:Si(C?.fallbackTargets)}),Je=JSON.stringify({targets:Si(w.targets),fallbackTargets:Si(w.fallbackTargets)}),Ht=JSON.stringify({targets:Si(C?.targets),fallbackTargets:Si(C?.fallbackTargets)}),wn=ve!==Fe,fn=H?UA.test(H)?he?"Alias id already exists. Choose another id.":Ie?"Fill or remove blank target rows before applying.":I?"Duplicate targets are not allowed anywhere in this alias.":ue?"Target weights must be positive integers.":_e?"An alias cannot target itself.":"":"Alias id must start with a letter or number and use letters, numbers, dots, underscores, colons, or hyphens.":"Alias id is required.",Ft=i?l:fn,Yt=i?l:v&&fn&&!L?"":fn,st=i||s,Ve=String(H||e||"").trim(),Vn=Ve||"Select alias",mn=st||B||f,er=B?"Default alias cannot be removed":`Remove alias ${Ve||e}`,Ra=(0,Tn.useMemo)(()=>Ff(Vn),[Vn]),Te=B||o===e||o===H,Ze=a===e||a===H,Ce=f?"Enter alias name. Example: claude-opus":void 0,Ge=(0,Tn.useMemo)(()=>GE(C,t,r),[C,t,r]);async function ao(){if(P(!0),Ft)return!1;let q=await c(e,C);return q&&f&&m(e),q}async function pn(q){let be={...C,strategy:q};return await c(e,be)?f?(m(e),!0):(E(be),!0):!1}async function It(){if(P(!0),Ft)return!1;let q=await c(e,C);return q&&(M(!1),P(!1)),q}function N(){if(p)return;if(!J){M(!1);return}let q=String(e||"").trim(),be=String(C?.id||"").trim();if(!be||be===q){E(Be=>({...Be,id:q})),M(!1),P(!1);return}It()}function se(q){if(q.key==="Escape"){q.preventDefault(),E(be=>({...be,id:w.id})),M(!1),P(!1);return}!p&&q.key==="Enter"&&(q.preventDefault(),q.currentTarget.blur())}async function W(){if(Q){let q=String(e||"").trim(),be=String(C?.id||"").trim();if(!be||be===q){E(Be=>({...Be,id:q})),M(!1),P(!1);return}await It();return}M(!0)}(0,Tn.useEffect)(()=>()=>{typeof window<"u"&&G.current&&window.clearTimeout(G.current)},[]),(0,Tn.useEffect)(()=>{if(f||st||Ft||Ht===Je){typeof window<"u"&&G.current&&(window.clearTimeout(G.current),G.current=0),!f&&Ht===Je&&ge!=="saving"&&j("idle");return}if(!(ae.current===Ht&&ge==="error")&&(j("pending"),!(typeof window>"u")))return G.current=window.setTimeout(()=>{G.current=0,ae.current=Ht,j("saving"),c(e,C,{showSuccessNotice:!1,successMessage:""}).then(q=>{j(q?"saved":"error")})},a5),()=>{G.current&&(window.clearTimeout(G.current),G.current=0)}},[e,Ht,C,Je,f,Ft,st,c]);let Re=f?"":ge==="saving"?"Saving alias changes\u2026":ge==="pending"?"Changes save automatically.":ge==="saved"?"Alias changes saved.":ge==="error"?"Autosave failed. Keep editing to retry.":"Changes save automatically.",ce=(0,Ae.jsxs)("div",{className:"space-y-4",children:[(0,Ae.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,Ae.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,Ae.jsx)("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:J?(0,Ae.jsxs)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-2",children:[(0,Ae.jsxs)("div",{className:F("flex h-9 min-w-0 max-w-full overflow-hidden rounded-lg border border-input bg-background/80 shadow-sm transition focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/40",Q?"flex-1":"w-fit"),children:[(0,Ae.jsx)("div",{className:"flex shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Select an alias"}),Q?(0,Ae.jsx)(wt,{ref:D,value:C.id,placeholder:Ce,onChange:q=>E(be=>({...be,id:q.target.value})),onBlur:N,onKeyDown:se,disabled:st||B,className:"h-full min-w-[12rem] flex-1 rounded-none border-0 bg-transparent px-3 text-sm font-medium shadow-none focus:border-transparent focus:ring-0"}):(0,Ae.jsxs)(rn,{value:g.value||void 0,onValueChange:g.onValueChange,children:[(0,Ae.jsx)(on,{className:"h-full min-w-[10rem] flex-none rounded-none border-0 bg-transparent px-3 pr-[50px] text-left text-sm font-medium shadow-none focus:border-transparent focus:ring-0",style:{width:`${Ra}px`,maxWidth:"100%"},children:(0,Ae.jsx)(an,{placeholder:"Select alias"})}),(0,Ae.jsx)(ln,{children:g.entries.map(([q,be])=>(0,Ae.jsx)(Dt,{value:q,searchText:`${q} ${(be?.targets||[]).length} ${(be?.fallbackTargets||[]).length}`,children:q},q))})]}),Q?null:(0,Ae.jsx)("button",{type:"button",className:"flex h-full w-10 shrink-0 items-center justify-center border-l border-border/70 text-muted-foreground transition hover:bg-accent/60 hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/60 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{u(Ve)},disabled:st||!Ve,"aria-label":`Copy alias id ${Ve}`,title:Ve?`Copy alias id ${Ve}`:"Alias id is not ready yet",children:(0,Ae.jsx)(ZA,{className:"h-4 w-4 shrink-0"})})]}),(0,Ae.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-9 w-9 rounded-lg border-border/70 bg-background/70 p-0 text-muted-foreground shadow-none hover:bg-background/90 hover:text-foreground",onMouseDown:q=>{Q&&q.preventDefault()},onClick:()=>{W()},disabled:st||B,"aria-label":Q?"Save alias id":B?"Default alias id cannot be edited":"Edit alias id",title:Q?"Save alias id":B?"Default alias id cannot be edited":"Edit alias id",children:Q?(0,Ae.jsx)(XA,{className:"h-4 w-4 shrink-0"}):(0,Ae.jsx)(bs,{className:"h-4 w-4 shrink-0"})}),f?null:(0,Ae.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-9 w-9 rounded-lg border-border/70 bg-background/70 p-0 text-muted-foreground shadow-none hover:border-destructive hover:bg-background/90 hover:text-destructive",onClick:()=>d(e),disabled:mn,"aria-label":er,title:er,children:(0,Ae.jsx)(Qc,{className:"h-4 w-4 shrink-0"})})]}):(0,Ae.jsxs)(Ae.Fragment,{children:[Q?(0,Ae.jsx)(wt,{ref:D,autoFocus:f,value:C.id,placeholder:Ce,onChange:q=>E(be=>({...be,id:q.target.value})),onBlur:N,onKeyDown:se,disabled:st||B&&!f,className:"max-w-[22rem] font-semibold"}):B&&!f?(0,Ae.jsx)("div",{className:"truncate text-base font-semibold text-foreground",children:e}):(0,Ae.jsxs)("button",{type:"button",className:"group inline-flex max-w-full items-center gap-2 rounded-lg text-left text-base font-semibold text-foreground transition hover:bg-primary/5 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-2 focus-visible:ring-offset-background",onClick:()=>M(!0),disabled:st,"aria-label":"Edit alias id",title:"Edit alias id",children:[(0,Ae.jsx)("span",{className:"truncate",children:f?H||"New alias":H||e}),(0,Ae.jsx)(bs,{className:"h-4 w-4 shrink-0"})]}),h?(0,Ae.jsx)("div",{className:"min-w-[11rem] max-w-full",children:h}):null]})}),B?null:(0,Ae.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Te?(0,Ae.jsx)(ut,{variant:"success",children:"Default route"}):null,Ze?(0,Ae.jsx)(ut,{variant:"info",children:"AMP default"}):null]})]}),(0,Ae.jsxs)("div",{className:"flex items-start gap-2 self-start",children:[(0,Ae.jsxs)($,{type:"button",variant:"outline",size:"default",className:"group h-9 gap-0 overflow-hidden rounded-lg border-border/70 bg-background/70 px-0 text-sm font-medium normal-case tracking-normal shadow-none hover:bg-background/90",onClick:()=>b({aliasLabel:H||(f?"New alias":e),strategy:C?.strategy||"auto",entries:Ge,disabled:st||!!Ft,onSave:pn}),disabled:st,children:[(0,Ae.jsx)("span",{className:"flex h-full shrink-0 items-center border-r border-border/70 bg-secondary/55 px-2.5 text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Routing stratergy"}),(0,Ae.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-2 px-3 text-left",children:[(0,Ae.jsx)("span",{className:"truncate",children:Df(C.strategy||"auto")}),(0,Ae.jsx)(bs,{className:"h-4 w-4 shrink-0"})]})]}),!J&&!f?(0,Ae.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-9 w-9 rounded-lg border-border/70 bg-background/70 p-0 text-muted-foreground shadow-none hover:border-destructive hover:bg-background/90 hover:text-destructive",onClick:()=>d(e),disabled:mn,"aria-label":er,title:er,children:(0,Ae.jsx)(Qc,{className:"h-4 w-4 shrink-0"})}):null]})]}),(0,Ae.jsx)(nv,{title:"Primary targets",rows:C.targets,onChange:q=>E(be=>({...be,targets:q})),options:ft,disabled:st,addLabel:"Add target",emptyLabel:"No targets yet. This alias can stay empty until you wire routes back in.",helperText:"Primary targets are tried first. Drag to reorder targets. Weights and metadata stay with the same ref.",draftPlaceholder:"Add a new target",showDraftRow:!0,showDraftFocusButton:!0,showWeightInput:!0,filterOtherSelectedValues:!0,excludedValues:je}),(0,Ae.jsx)(nv,{title:"Fallback targets",rows:C.fallbackTargets,onChange:q=>E(be=>({...be,fallbackTargets:q})),options:ft,disabled:st,addLabel:"Add fallback",emptyLabel:"No fallback targets configured.",helperText:"Fallback targets only enter the candidate pool after the full primary list. Weights still apply within the chosen routing strategy.",draftPlaceholder:"Add a fallback target",showDraftRow:!0,showDraftFocusButton:!0,showWeightInput:!0,filterOtherSelectedValues:!0,excludedValues:X}),Yt?null:(0,Ae.jsx)("div",{className:"text-xs text-muted-foreground",children:Re}),Yt?(0,Ae.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:Yt}):null,!Yt&&B&&!Ee?(0,Ae.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:["The fixed ",(0,Ae.jsx)("code",{children:"default"})," route is empty. Requests routed to ",(0,Ae.jsx)("code",{children:"default"})," or ",(0,Ae.jsx)("code",{children:"smart"})," will return 500 until you add a working target."]}):null,f?(0,Ae.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,Ae.jsx)("div",{children:(0,Ae.jsx)($,{type:"button",variant:"ghost",onClick:()=>m(e),disabled:st,children:"Discard"})}),(0,Ae.jsx)("div",{className:"flex flex-wrap justify-end gap-2",children:(0,Ae.jsx)($,{type:"button",onClick:()=>{ao()},disabled:st||!!Ft,children:s?"Saving\u2026":"Create alias"})})]}):null]});return y?(0,Ae.jsx)(Gt,{children:(0,Ae.jsx)(qt,{className:"space-y-4 p-5",children:ce})}):ce}var en=_(Z(),1);function YE({aliases:e,config:t,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabledReason:i="",busy:l=!1,onApplyAlias:s,onRemoveAlias:c,onCopyAliasId:d}){let u=Object.entries(e||{}),f=!!i,[p,v]=(0,Aa.useState)(""),[m,b]=(0,Aa.useState)(!1),[h,g]=(0,Aa.useState)(""),y=(0,Aa.useMemo)(()=>oC(),[]),[x,w]=(0,Aa.useState)({open:!1,aliasLabel:"",strategy:"auto",entries:[],disabled:!1,onSave:null});function C(){f||l||v(`draft-${Date.now()}`)}function E(j){(!j||j===p)&&v("")}function A(){v("")}function M({aliasLabel:j="",strategy:J="auto",entries:Q=[],disabled:H=!1,onSave:B=null}){w({open:!0,aliasLabel:j,strategy:J,entries:Q,disabled:H,onSave:B})}function L(){w(j=>({...j,open:!1}))}async function P(j,J,Q={}){let H=await s(j,J,Q);if(H){let B=String(J?.id||j||"").trim()||j;g(B)}return H}(0,Aa.useEffect)(()=>{let j=u.map(([J])=>J);if(j.length===0){h&&g("");return}(!h||!j.includes(h))&&g(j[0])},[u,h]);let D=u.find(([j])=>j===h)||u[0]||null,G=D?.[0]||"",ae=D?.[1]||null,ge=u.length>1?{value:G,onValueChange:g,entries:u}:null;return(0,en.jsxs)(en.Fragment,{children:[(0,en.jsxs)(Gt,{children:[(0,en.jsx)(Qr,{children:(0,en.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,en.jsx)("div",{className:"space-y-1",children:(0,en.jsx)(li,{children:"Model aliases give clients one stable route across multiple provider/models, so you can swap, balance, and fail over without changing client config."})}),(0,en.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,en.jsx)($,{type:"button",variant:"outline",size:"sm",onClick:()=>b(!0),children:"Help"}),(0,en.jsx)($,{type:"button",size:"sm",onClick:C,disabled:f||l,children:l?"Saving\u2026":"Add alias"})]})]})}),(0,en.jsxs)(qt,{className:"space-y-4",children:[f?(0,en.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:i}):null,u.length>0?G&&ae?(0,en.jsx)(rv,{aliasId:G,alias:ae,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabled:f,disabledReason:i,busy:l,onApply:P,onRemove:c,onCopyAliasId:d,onOpenStrategyModal:M,aliasSwitcher:ge,framed:!1},G):null:(0,en.jsxs)("div",{className:"rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground",children:["No model aliases yet. Add one to expose stable routes like ",(0,en.jsx)("code",{children:"coding"})," or ",(0,en.jsx)("code",{children:"chat.fast"})," in the Web UI."]})]})]}),(0,en.jsx)(Zn,{open:!!p,onClose:A,title:"Add alias",description:"Set a stable client-facing route, choose its strategy, and order the targets it should use.",showCloseButton:!1,contentClassName:"max-h-[92vh] max-w-5xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)]",children:p?(0,en.jsx)(rv,{aliasId:p,alias:y,aliasIds:n,routeOptions:r,defaultModel:o,ampDefaultRoute:a,disabled:f,disabledReason:i,busy:l,onApply:P,onRemove:c,onCopyAliasId:d,isNew:!0,alwaysShowAliasIdInput:!0,showIssueOnSubmitOnly:!0,onDiscard:E,onOpenStrategyModal:M,framed:!1},p):null}),(0,en.jsx)(qE,{open:x.open,onClose:L,onSave:j=>x.onSave?.(j),aliasLabel:x.aliasLabel,initialStrategy:x.strategy,entries:x.entries,disabled:x.disabled}),(0,en.jsx)(WE,{open:m,onClose:()=>b(!1),config:t})]})}var Wt=_(me(),1);var pl=_(me(),1);var Ir=_(Z(),1);function bu({values:e,onChange:t,placeholder:n,helperText:r,inputRef:o=null,inputClassName:a="",suggestedValues:i=[],valueStates:l={},draftValue:s="",onDraftValueChange:c=()=>{},commitOnBlur:d=!1,disabled:u=!1,isValueValid:f=v=>!!String(v||"").trim(),inputProps:p={}}){let v=(0,pl.useMemo)(()=>pr(e),[e]),[m,b]=(0,pl.useState)(""),[h,g]=(0,pl.useState)("");function y(A=s,{clearDraft:M=!0}={}){if(u)return!1;let L=Of(A).filter(D=>f(D));if(L.length===0)return M&&c(""),!1;let P=Array.from(new Set([...v||[],...L]));return JSON.stringify(P)!==JSON.stringify(v||[])&&t(P),M&&c(""),!0}function x(A){u||(t(v.filter(M=>M!==A)),m===A&&(b(""),g("")))}function w(){u||i.length&&(t(Array.from(new Set([...v||[],...i]))),c(""))}function C(A){u||(b(A),g(A))}function E(A=h){if(u)return b(""),g(""),!1;if(!m)return!1;let M=Of(A).filter(G=>f(G)),L=[],P=!1;for(let G of v||[]){if(G!==m){L.push(G);continue}P||(L.push(...M),P=!0)}let D=Array.from(new Set(L.map(G=>String(G||"").trim()).filter(Boolean)));return JSON.stringify(D)!==JSON.stringify(v||[])&&t(D),b(""),g(""),M.length>0}return(0,pl.useEffect)(()=>{!u||!m||(b(""),g(""))},[u,m]),(0,Ir.jsxs)("div",{className:"space-y-2",children:[(0,Ir.jsxs)("div",{className:F("flex min-h-11 flex-wrap items-center gap-2 rounded-xl border border-input bg-background/80 px-3 py-2",u?"opacity-80":null),children:[v.map(A=>{let M=l?.[A]||"default",L=M==="success"?"border-emerald-200 bg-emerald-50 text-emerald-900":M==="error"?"border-rose-200 bg-rose-50 text-rose-900":M==="pending"?"border-sky-200 bg-sky-50 text-sky-900":"border-border bg-secondary text-foreground",P=!u&&m===A;return(0,Ir.jsxs)("span",{className:F("inline-flex max-w-full items-center gap-1 rounded-full border px-2.5 py-1 text-xs",L),children:[P?(0,Ir.jsx)("input",{autoFocus:!0,className:"min-w-[7rem] bg-transparent text-xs text-foreground outline-none",value:h,onChange:D=>g(D.target.value),onKeyDown:D=>{if(D.key==="Enter"||D.key==="Tab"){D.preventDefault(),E();return}D.key==="Escape"&&(D.preventDefault(),b(""),g(""))},onBlur:()=>{E()}}):(0,Ir.jsx)("button",{className:"max-w-[16rem] truncate text-left transition hover:text-foreground disabled:cursor-not-allowed disabled:opacity-70",type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>C(A),disabled:u,title:"Click to edit",children:A}),(0,Ir.jsx)("button",{className:"text-muted-foreground transition hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60",type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>x(A),disabled:u,children:"\xD7"})]},A)}),(0,Ir.jsx)("input",{...p,ref:o,className:F("min-w-[10rem] flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-70",a),value:s,disabled:u,onChange:A=>{let M=A.target.value;if(/[\s,]/.test(M)){let L=M.split(/[\s,]+/),P=L.pop()||"";L.length>0&&y(L.join(","),{clearDraft:!1}),c(P);return}c(M)},onKeyDown:A=>{if((A.key===","||A.key===" "||A.key==="Enter"||A.key==="Tab")&&s.trim()){A.preventDefault(),y();return}A.key==="Backspace"&&!s&&v.length>0&&(A.preventDefault(),x(v[v.length-1]))},onPaste:A=>{let M=A.clipboardData?.getData("text")||"";if(/[\s,]/.test(M)){A.preventDefault();let L=M.split(/[\s,]+/).filter(Boolean).filter(P=>f(P));L.length>0&&(t(Array.from(new Set([...v||[],...L]))),c(""));return}A.preventDefault(),c(`${s}${M}`)},onBlur:()=>{if(d&&f(s)){y(s);return}c(s)},placeholder:n}),v.length>0||s?(0,Ir.jsx)("button",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground transition hover:text-foreground disabled:cursor-not-allowed disabled:opacity-60",type:"button",onMouseDown:A=>A.preventDefault(),onClick:()=>{t([]),c("")},disabled:u,children:"Clear all"}):null]}),(0,Ir.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[r?(0,Ir.jsx)("span",{children:r}):null,v.length===0&&i.length>0?(0,Ir.jsx)("button",{className:"font-medium uppercase tracking-[0.16em] text-foreground transition hover:text-primary disabled:cursor-not-allowed disabled:opacity-60",type:"button",onClick:w,disabled:u,children:"Use suggested values"}):null]})]})}var Jn=_(me(),1);var Ye=_(Z(),1);function QE(e="rate-limit-draft-row"){return nu({key:e,models:[],requests:"",windowValue:"",windowUnit:po.custom.rateLimitDefaults.windowUnit},{keyPrefix:"rate-limit-draft",defaults:po.custom.rateLimitDefaults,useDefaults:!1})}function Tm(e=[],{keyPrefix:t="rate-limit-draft"}={}){let n=`${t}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;return[...Array.isArray(e)?e:[],QE(n)]}function i5({value:e=[],onChange:t,availableModelIds:n=[],disabled:r=!1}){let o=(0,Jn.useRef)(null),[a,i]=(0,Jn.useState)(!1),l=(0,Jn.useMemo)(()=>mo(e),[e]),s=l.includes("all"),c=s?[]:l.filter(Boolean),d=s||c.length===0,u=(0,Jn.useMemo)(()=>pr(n),[n]);(0,Jn.useEffect)(()=>{if(!a||typeof document>"u")return;function h(g){o.current?.contains(g.target)||i(!1)}return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[a]);function f(h){t(mo(h))}function p(h){f(h?["all"]:[])}function v(h,g){let y=g?[...c,h]:c.filter(x=>x!==h);f(y)}function m(h){if(h==="all"){f([]);return}f(c.filter(g=>g!==h))}let b=s?[{key:"all",label:"All model",removable:!0}]:c.length>0?c.map(h=>({key:h,label:h,removable:!0})):[{key:"__implicit-all__",label:"All model",removable:!1,muted:!0}];return(0,Ye.jsxs)("div",{ref:o,className:"relative space-y-1.5",children:[(0,Ye.jsxs)("div",{role:"button",tabIndex:r?-1:0,className:F("flex min-h-9 w-full items-center justify-between gap-2 rounded-lg border border-input bg-background/80 px-3 py-1.5 text-left text-sm text-foreground shadow-sm outline-none transition focus:border-ring focus:ring-2 focus:ring-ring/40",r?"cursor-not-allowed opacity-50":"cursor-pointer",a?"border-ring ring-2 ring-ring/40":null),onClick:()=>{r||i(h=>!h)},"aria-expanded":a,"aria-haspopup":"menu",onKeyDown:h=>{if(!r){if(h.key==="Enter"||h.key===" "){h.preventDefault(),i(g=>!g);return}if(h.key==="ArrowDown"){h.preventDefault(),i(!0);return}h.key==="Escape"&&(h.preventDefault(),i(!1))}},children:[(0,Ye.jsx)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5",children:b.map(h=>h.removable?(0,Ye.jsxs)("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-full border border-border/70 bg-background px-2 py-0.5 text-xs font-medium text-foreground transition hover:border-accent hover:bg-accent",onClick:g=>{g.preventDefault(),g.stopPropagation(),m(h.key)},disabled:r,title:`Remove ${h.label}`,children:[(0,Ye.jsx)("span",{className:"truncate",children:h.label}),(0,Ye.jsx)("span",{className:"text-muted-foreground",children:"x"})]},h.key):(0,Ye.jsx)("span",{className:F("inline-flex max-w-full items-center rounded-full border px-2 py-0.5 text-xs font-medium",h.muted?"border-border/70 bg-secondary/45 text-muted-foreground":"border-border/70 bg-background text-foreground"),children:(0,Ye.jsx)("span",{className:"truncate",children:h.label})},h.key))}),(0,Ye.jsx)("span",{className:"text-muted-foreground",children:"\u25BE"})]}),a?(0,Ye.jsxs)(Rm,{open:a,anchorRef:o,preferredSide:"top",desiredHeight:192,className:"p-2",onMouseDown:h=>h.stopPropagation(),onClick:h=>h.stopPropagation(),onKeyDown:h=>{h.key==="Escape"&&(h.preventDefault(),i(!1))},children:[(0,Ye.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-sm text-foreground transition hover:bg-secondary/60",children:[(0,Ye.jsx)("input",{type:"checkbox",className:"h-4 w-4 rounded border-input",checked:s,onChange:h=>p(h.target.checked)}),(0,Ye.jsx)("span",{children:"All model"})]}),(0,Ye.jsx)("div",{className:"my-1 border-t border-border/70"}),u.length>0?(0,Ye.jsx)("div",{children:u.map(h=>(0,Ye.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-sm text-foreground transition hover:bg-secondary/60",children:[(0,Ye.jsx)("input",{type:"checkbox",className:"h-4 w-4 rounded border-input",checked:c.includes(h),onChange:g=>v(h,g.target.checked)}),(0,Ye.jsx)("span",{className:"truncate",children:h})]},h))}):(0,Ye.jsx)("div",{className:"px-2 py-2 text-sm text-muted-foreground",children:"No models available yet."})]}):null]})}function Mm({rows:e,onChange:t,availableModelIds:n=[],disabled:r=!1,inputRef:o=null,helperText:a="",onValidBlur:i=null}){let l=Array.isArray(e)?e:[],s=(0,Jn.useRef)(null),c=(0,Jn.useRef)(l),d=(0,Jn.useMemo)(()=>pr(n),[n]),u=(0,Jn.useMemo)(()=>{let g=new Set,y=new Set;for(let x of gr(l)){let w=Fc(x);if(w){if(g.has(w)){y.add(w);continue}g.add(w)}}return y},[l]),f=(0,Jn.useMemo)(()=>l.map(g=>({...QE(g.key),...g,models:mo(g?.models||[])})),[l]);(0,Jn.useEffect)(()=>{c.current=l},[l]);function p(g){let y=Array.isArray(g)?g:[];c.current=y,t(y)}function v(g,y){p(l.map(x=>x.key===g?{...x,...y}:x))}function m(g){p(l.filter(y=>y.key!==g))}function b(g){if(If(g))return"";let y=mo(g?.models||[]);if(d.length>0&&y.some(w=>w!=="all"&&!d.includes(w)))return"Use exact provider model ids only.";if(Yh(g?.requests,0)<=0)return"Requests must be a positive integer.";if(Yh(g?.windowValue,0)<=0)return"Window size must be a positive integer.";if(!Fh.includes(String(g?.windowUnit||"").trim()))return"Window unit is invalid.";let x=Fc({requests:g?.requests,windowValue:g?.windowValue,windowUnit:g?.windowUnit});return x&&u.has(x)?"Another row already uses this cap.":""}function h(g){if(!(!i||r)&&!g.currentTarget.contains(g.relatedTarget)){if(typeof window>"u"){let y=gr(c.current);Lo(y,{knownModelIds:d,requireAtLeastOne:!0})||i(y);return}window.setTimeout(()=>{if(!s.current||s.current.contains(document.activeElement))return;let y=gr(c.current);Lo(y,{knownModelIds:d,requireAtLeastOne:!0})||i(y)},0)}}return(0,Ye.jsxs)("div",{ref:s,className:"space-y-2.5",onBlurCapture:h,children:[(0,Ye.jsx)("div",{className:"space-y-2.5",children:f.map((g,y)=>{let x=If(g),w=b(g);return(0,Ye.jsxs)("div",{className:F("rounded-2xl border border-border/70 bg-background/70 p-3",w?"border-amber-200 bg-amber-50/70":null,x?"border-dashed bg-background/80":null),children:[(0,Ye.jsxs)("div",{className:"grid gap-2.5 xl:grid-cols-[minmax(0,1.5fr)_minmax(0,0.72fr)_minmax(0,0.72fr)_minmax(0,0.86fr)_auto] xl:items-end",children:[(0,Ye.jsx)(pt,{label:"Models",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Ye.jsx)(i5,{value:g.models,onChange:C=>v(g.key,{models:C}),availableModelIds:d,disabled:r})}),(0,Ye.jsx)(pt,{label:"Request",stacked:!0,className:"gap-1",headerClassName:"min-h-0",children:(0,Ye.jsx)(wt,{ref:y===0?o:null,value:g.requests,onChange:C=>v(g.key,{requests:C.target.value}),disabled:r,inputMode:"numeric",placeholder:"60"})}),(0,Ye.jsx)(pt,{label:"Window",stacked:!0,className:"gap-1",headerClassName:"min-h-0",children:(0,Ye.jsx)(wt,{value:g.windowValue,onChange:C=>v(g.key,{windowValue:C.target.value}),disabled:r,inputMode:"numeric",placeholder:"1"})}),(0,Ye.jsx)(pt,{label:"Unit",stacked:!0,className:"gap-1",headerClassName:"min-h-0",children:(0,Ye.jsxs)(rn,{value:String(g.windowUnit||"minute"),onValueChange:C=>v(g.key,{windowUnit:C}),disabled:r,children:[(0,Ye.jsx)(on,{children:(0,Ye.jsx)(an,{placeholder:"Window unit"})}),(0,Ye.jsx)(ln,{children:Fh.map(C=>(0,Ye.jsx)(Dt,{value:C,children:C},`${g.key}-${C}`))})]})}),(0,Ye.jsx)($,{type:"button",variant:"ghost",onClick:()=>m(g.key),disabled:r,className:"xl:self-end",children:"Remove"})]}),w?(0,Ye.jsx)("div",{className:"mt-2.5 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:w}):null]},g.key)})}),a?(0,Ye.jsx)("div",{className:"text-xs leading-5 text-muted-foreground",children:a}):null]})}var lt=_(me(),1);var XE=[{key:"supportsReasoning",label:"Reasoning",field:"reasoning_effort"},{key:"supportsThinking",label:"Thinking",field:"thinking"},{key:"supportsResponseFormat",label:"Response Format",field:"response_format"},{key:"supportsLogprobs",label:"Logprobs",field:"logprobs"},{key:"supportsServiceTier",label:"Service Tier",field:"service_tier"},{key:"supportsPrediction",label:"Prediction",field:"prediction"},{key:"supportsStreamOptions",label:"Stream Options",field:"stream_options"}];function ZE(e={},t={}){if(!t||typeof t!="object")return e;let n={...e};for(let r of Object.keys(t))typeof t[r]=="boolean"&&n[r]===void 0&&(n[r]=t[r]);return n}function JE(e){if(e===void 0)return!0;if(e===!0)return!1}function eT(e){return!e||typeof e!="object"?!1:Object.values(e).some(t=>typeof t=="boolean")}var wi=_(Z(),1);function l5({label:e,value:t,disabled:n,onCycle:r}){let o=typeof t=="boolean";return(0,wi.jsxs)("button",{type:"button",disabled:n,onClick:r,className:F("flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs transition-colors",t===!0&&"border-emerald-200 bg-emerald-50/80",t===!1&&"border-rose-200 bg-rose-50/60",!o&&"border-border/60 bg-secondary/40",!n&&"hover:bg-accent"),children:[(0,wi.jsx)("span",{className:F("inline-flex h-3 w-3 shrink-0 items-center justify-center rounded-full text-[8px] font-bold leading-none",t===!0&&"bg-emerald-500 text-white",t===!1&&"bg-rose-400 text-white",!o&&"bg-muted-foreground/25"),children:t===!0?"\u2713":t===!1?"\u2715":""}),(0,wi.jsx)("span",{className:F("select-none whitespace-nowrap font-medium",t===!0&&"text-emerald-800",t===!1&&"text-rose-700 line-through",!o&&"text-muted-foreground"),children:e})]})}function tT({capabilities:e={},disabled:t=!1,onChange:n}){return(0,wi.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[(0,wi.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground/80",children:"Capabilities"}),XE.map(({key:r,label:o})=>{let a=e[r];return(0,wi.jsx)(l5,{label:o,value:a,disabled:t,onCycle:()=>n(r,JE(a))},r)})]})}var Ne=_(Z(),1);function nT({provider:e,disabled:t=!1,disabledReason:n="",busy:r=!1,onApply:o,framed:a=!0,focusRequest:i=0,onStateChange:l=null,testStateByModel:s={},savePhase:c="",saveMessage:d=""}){let u=(0,lt.useMemo)(()=>NA(e),[e]),[f,p]=(0,lt.useState)([]),[v,m]=(0,lt.useState)(""),[b,h]=(0,lt.useState)(!1),[g,y]=(0,lt.useState)({}),[x,w]=(0,lt.useState)({}),[C,E]=(0,lt.useState)(null),[A,M]=(0,lt.useState)(""),[L,P]=(0,lt.useState)(""),[D,G]=(0,lt.useState)({}),ae=(0,lt.useRef)(0),ge=(0,lt.useRef)([]),j=(0,lt.useRef)(new Map),J=(0,lt.useRef)(new Map),Q=(0,lt.useRef)(""),H=(0,lt.useRef)(""),B=(0,lt.useRef)(null),ft=(0,lt.useRef)(new Map),X=(0,lt.useRef)(new Map);function je(N={}){return ae.current+=1,{key:`model-${e.id}-draft-${ae.current}`,id:"",sourceId:"",contextWindow:"",capabilities:{},...N}}function ie(N){Q.current=N}function xe(N=[],{preserveFocus:se=!1}={}){let W=[],Re=null;for(let ce of Array.isArray(N)?N:[]){let q=String(ce?.id||""),be=ce?.contextWindow===void 0||ce?.contextWindow===null?"":String(ce.contextWindow);if(String(q).trim()){W.push({...ce,id:q,contextWindow:be});continue}Re||(Re={...ce,id:"",contextWindow:be})}return Re||(Re=je(),se&&ie(Re.key)),[Re,...W]}function Ie(N){w(se=>{if(!se[N])return se;let W={...se};return delete W[N],W})}function I(N,se){y(W=>{if(se)return W[N]?W:{...W,[N]:!0};if(!W[N])return W;let Re={...W};return delete Re[N],Re})}function ue(N,se={},{clearLookupState:W=!1,clearStatus:Re=!0,closeLookupMenu:ce=!1}={}){W&&Ie(N),Re&&E(null),ce&&A===N&&M(""),p(q=>xe(q.map(be=>be.key===N?{...be,...se}:be),{preserveFocus:!1}))}(0,lt.useEffect)(()=>{ge.current=f},[f]),(0,lt.useEffect)(()=>{let N=xe(u,{preserveFocus:!0});p(N),ge.current=N,ft.current.clear(),X.current.clear(),y({}),w({}),E(null),M(""),P(""),G({})},[u]),(0,lt.useEffect)(()=>{let N=Q.current;if(!N)return;let se=j.current.get(N);if(!se)return;se.scrollIntoView?.({block:"nearest"}),se.focus();let W=se.value?.length||0;se.setSelectionRange?.(W,W),Q.current=""},[f]),(0,lt.useEffect)(()=>{i&&p(N=>{let se=xe(N,{preserveFocus:!1}),W=se.find(Re=>!String(Re?.id||"").trim())||se[se.length-1];return W&&ie(W.key),se})},[i]),(0,lt.useEffect)(()=>{A&&(f.some(N=>N.key===A)||M(""))},[f,A]),(0,lt.useEffect)(()=>{L&&(f.some(N=>N.key===L)||P(""))},[f,L]),(0,lt.useEffect)(()=>{G(N=>{let se=new Set(f.map(ce=>ce.key)),W=!1,Re={};for(let[ce,q]of Object.entries(N)){if(!se.has(ce)){W=!0;continue}Re[ce]=q}return W?Re:N})},[f]),(0,lt.useEffect)(()=>{if(!A||typeof document>"u")return;function N(se){J.current.get(A)?.contains(se.target)||M("")}return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[A]);let he=(0,lt.useMemo)(()=>f.filter(N=>String(N?.id||"").trim()),[f]),_e=(0,lt.useMemo)(()=>u.map(N=>({id:String(N?.id||"").trim(),contextWindow:Uo(N?.contextWindow||""),capabilities:N?.capabilities||{}})).filter(N=>N.id),[u]),Ee=(0,lt.useMemo)(()=>he.map(N=>({...N,id:String(N?.id||"").trim(),contextWindow:Uo(N?.contextWindow||"")})),[he]),ve=Ee.map(N=>N.id),Fe=_e.map(N=>N.id),Je=ve.filter(N=>!Fe.includes(N)),Ht=ws(ve),wn=ve.length>0,fn=new Set(Ee.filter(N=>{let se=String(N?.contextWindow||"").trim();if(!se)return!1;let W=Number.parseInt(se,10);return!Number.isFinite(W)||W<=0||String(W)!==se}).map(N=>N.key)),Ft=Ee.filter(N=>!String(N?.contextWindow||"").trim()),Yt=JSON.stringify(_e)!==JSON.stringify(Ee.map(N=>({id:N.id,contextWindow:N.contextWindow,capabilities:N.capabilities||{}}))),Ve=t||r||(v!==""||c==="testing"||c==="saving")||b,Vn=(0,lt.useMemo)(()=>{let N=-1;return f.forEach((se,W)=>{String(se?.id||"").trim()&&(N=W)}),N},[f]),mn=t?n:wn?Ht?"Model ids must be unique for each provider.":fn.size>0?"Context windows must be positive integers when set.":"":"Keep at least one model id on the provider.",er=zs(f.map(N=>N.key));(0,lt.useEffect)(()=>{l?.({isDirty:Yt,issue:mn,locked:Ve,rows:Ee.map(N=>({...N,contextWindow:Uo(N.contextWindow)}))})},[l,Yt,mn,Ve,Ee]);function Ra(N){Ie(N),I(N,!1),E(null),A===N&&M(""),L===N&&P(""),G(se=>{if(!Object.prototype.hasOwnProperty.call(se,N))return se;let W={...se};return delete W[N],W}),p(se=>xe(se.filter(W=>W.key!==N)))}function Te(N){p(se=>xe(xs(se,N,W=>W?.key)))}function Ze(N){p(se=>xe(kf(se,N,W=>W?.key)))}function Ce(){H.current="",va(B.current,!1),B.current=null}async function Ge(N,{force:se=!1}={}){let W=String(N||"").trim();if(!W)return Rs({query:W});if(!se&&ft.current.has(W))return ft.current.get(W);if(!se&&X.current.has(W))return X.current.get(W);let Re=(async()=>{let ce=await su([W]),q=(Array.isArray(ce)?ce:[]).find(Be=>String(Be?.query||"").trim()===W)||{query:W},be=Rs(q,{fallbackQuery:W});return ft.current.set(W,be),be})();X.current.set(W,Re);try{return await Re}finally{X.current.delete(W)}}async function ao(N,{openMenu:se=!1,prefill:W=!1,modelId:Re=""}={}){let ce=ge.current.find(be=>be.key===N),q=String(Re||ce?.id||"").trim();if(!q)return null;se&&M(N),I(N,!0);try{let be=await Ge(q);if(w(Be=>({...Be,[N]:be})),W){let Be=Kf(be),Se=be?.exactMatch?.capabilities;(Be||Se)&&p(Le=>xe(Le.map(et=>{if(et.key!==N)return et;let we=String(et?.id||"").trim();if(!we||we!==q)return et;let ot={};return Be&&!String(et?.contextWindow||"").trim()&&(ot.contextWindow=Be),Se&&!eT(et.capabilities)&&(ot.capabilities=ZE(et.capabilities,Se)),Object.keys(ot).length>0?{...et,...ot}:et}),{preserveFocus:!1}))}return be}catch(be){let Be=be instanceof Error?be.message:String(be),Se={query:q,status:"error",error:Be,options:[]};return w(Le=>({...Le,[N]:Se})),Se}finally{I(N,!1)}}async function pn(N=[]){let se=new Set(Array.isArray(N)?N:[]),W=Ee.filter(Re=>!Re.id||String(Re?.contextWindow||"").trim()?!1:se.size===0?!0:se.has(Re.key)).map(Re=>({key:Re.key,id:Re.id}));if(W.length!==0){h(!0),E(null);try{let Re=await su(W.map(et=>et.id)),ce=KC(Re),q=new Map(W.map(et=>[et.key,et]));for(let et of ce.values())et?.query&&ft.current.set(et.query,et);let be=Array.isArray(ge.current)?ge.current:[],Be=0,Se=0,Le=be.map(et=>{let we=q.get(et.key);if(!we)return et;let ot=String(et?.id||"").trim(),Ln=String(et?.contextWindow||"").trim();if(!ot||ot!==we.id||Ln)return et;let Ea=ce.get(ot)||Rs({query:ot}),So=Kf(Ea);return So?(Be+=1,{...et,contextWindow:So}):(Se+=1,et)});p(xe(Le,{preserveFocus:!1})),E({tone:Be>0?"success":"warning",message:Be>0?`Filled ${Be} context size${Be===1?"":"s"}${Se>0?`; ${Se} still need a manual value`:""}.`:`Could not fill ${Se} model${Se===1?"":"s"}.`})}catch(Re){E({tone:"error",message:Re instanceof Error?Re.message:String(Re)})}finally{h(!1)}}}async function It(){if(Ve||mn||!Yt)return!1;let N=ho(e)==="api"&&Je.length>0;m(N?"testing":"saving");try{return await o(Ee.map(se=>({...se,contextWindow:Uo(se.contextWindow)})))}finally{m("")}}return(0,Ne.jsxs)("div",{className:F(a?"space-y-3 rounded-2xl border border-border/70 bg-background/60 p-4":"space-y-3"),children:[(0,Ne.jsx)("div",{className:"rounded-2xl border border-border/70 bg-secondary/35 px-4 py-3 text-sm leading-6 text-muted-foreground",children:"Direct routes follow this top-to-bottom order. Focus a context field to load suggested sizes, or use Fill missing context size to fill each empty row with a median size."}),(0,Ne.jsx)("div",{className:"space-y-2",children:f.map((N,se)=>{let W=String(N?.id||"").trim(),Re=String(N?.contextWindow||"").trim(),ce=!!W,q=ce?he.findIndex(we=>we.key===N.key):-1,be=x[N.key]||null,Be=!!g[N.key],Se=A===N.key&&!!W,Le=fn.has(N.key),et=W&&s?.[W]||"default";return(0,Ne.jsxs)("div",{ref:er(N.key),"data-reorder-row":"true",onDragOver:we=>{!Ve&&H.current&&H.current!==N.key&&(we.preventDefault(),we.dataTransfer.dropEffect="move")},onDrop:we=>{if(Ve)return;we.preventDefault();let ot=we.dataTransfer.getData("text/plain")||H.current;Ce(),p(Ln=>xe(_f(Ln,ot,N.key)))},className:F("space-y-2 rounded-xl border border-border/70 bg-card/90 p-3",ce?null:"border-dashed bg-background/85",Le?"border-amber-200 bg-amber-50/70":null,!Le&&et==="success"?"border-emerald-200 bg-emerald-50/70":null,!Le&&et==="error"?"border-rose-200 bg-rose-50/70":null,!Le&&et==="pending"?"border-sky-200 bg-sky-50/70":null),children:[(0,Ne.jsxs)("div",{className:"grid grid-cols-[auto_auto_auto_minmax(0,1fr)_minmax(12rem,14rem)_5.5rem] items-center gap-2",children:[(0,Ne.jsx)("span",{className:F("flex h-8 w-8 items-center justify-center rounded-full text-muted-foreground",ce&&!Ve?"cursor-grab":"opacity-45"),draggable:!Ve&&ce,onDragStart:we=>{if(Ve||!ce)return;let ot=Ss(we.currentTarget);we.dataTransfer.effectAllowed="move",we.dataTransfer.setData("text/plain",N.key),ot&&typeof we.dataTransfer?.setDragImage=="function"&&we.dataTransfer.setDragImage(ot,20,20),Ce(),H.current=N.key,B.current=ot,va(ot,!0)},onDragEnd:Ce,title:ce?"Drag to reorder":"New model draft row",children:(0,Ne.jsx)(vs,{className:"h-4 w-4"})}),(0,Ne.jsx)(Sa,{disabled:Ve||!ce||q<=0,label:!ce||q<=0?"Already first":`Move ${N.id||`model ${q+1}`} up`,onClick:()=>Te(N.key)}),(0,Ne.jsx)(dl,{disabled:Ve||!ce||se>=Vn,label:!ce||se>=Vn?"Already last":`Move ${N.id||`model ${q+1}`} down`,onClick:()=>Ze(N.key)}),(0,Ne.jsx)(wt,{ref:we=>{we?j.current.set(N.key,we):j.current.delete(N.key)},value:N.id,onChange:we=>ue(N.key,{id:we.target.value},{clearLookupState:!0,closeLookupMenu:!0}),placeholder:ce?"Model id":"Add a new model id",disabled:Ve}),(0,Ne.jsxs)("div",{ref:we=>{we?J.current.set(N.key,we):J.current.delete(N.key)},className:"relative min-w-0",children:[(0,Ne.jsx)(wt,{value:L===N.key?D[N.key]??lu(N.contextWindow):HC(N.contextWindow),onChange:we=>{let ot=we.target.value,Ln=Uo(ot);G(Ea=>({...Ea,[N.key]:lu(Ln)})),ue(N.key,{contextWindow:Ln},{clearStatus:!1})},onBlur:we=>{P(ot=>ot===N.key?"":ot),G(ot=>{if(!Object.prototype.hasOwnProperty.call(ot,N.key))return ot;let Ln={...ot};return delete Ln[N.key],Ln}),ue(N.key,{contextWindow:Uo(we.target.value)},{clearStatus:!1})},onFocus:()=>{W&&(P(N.key),G(we=>({...we,[N.key]:lu(N.contextWindow)})),ao(N.key,{openMenu:!0}))},onClick:()=>{W&&ao(N.key,{openMenu:!0})},onKeyDown:we=>{if(we.key==="ArrowDown"&&W){we.preventDefault(),ao(N.key,{openMenu:!0});return}we.key==="Escape"&&(we.preventDefault(),M(""))},placeholder:"Context window",inputMode:"numeric",disabled:Ve||!W,className:"font-medium tabular-nums","aria-label":W?`Context window for ${W}`:"Context window"}),Se?(0,Ne.jsx)(Rm,{open:Se,anchorRef:{current:J.current.get(N.key)||null},preferredSide:"top",desiredHeight:224,className:"z-20 rounded-lg bg-background/98 p-2",onMouseDown:we=>we.preventDefault(),children:Be?(0,Ne.jsxs)("div",{className:"inline-flex items-center gap-2 px-1 py-2 text-sm text-muted-foreground",children:[(0,Ne.jsx)(Dr,{}),"Fetching size options for ",(0,Ne.jsx)("code",{children:W}),"."]}):be?.status==="error"?(0,Ne.jsx)("div",{className:"rounded-lg border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-900",children:be.error||"Could not load suggested sizes."}):be?.options?.length>0?(0,Ne.jsx)("div",{className:"space-y-1",children:be.options.map(we=>(0,Ne.jsxs)("button",{type:"button",className:"flex w-full flex-col gap-2 rounded-lg border border-border/70 bg-background px-3 py-2 text-left text-sm text-foreground transition hover:border-accent hover:bg-accent disabled:cursor-not-allowed disabled:opacity-70",disabled:Ve,onMouseDown:ot=>ot.preventDefault(),onClick:()=>{G(ot=>({...ot,[N.key]:lu(we.contextWindow)})),ue(N.key,{contextWindow:String(we.contextWindow)},{clearStatus:!1}),M("")},title:`Use ${we.label}`,children:[(0,Ne.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,Ne.jsx)("div",{className:"break-words font-medium leading-5",children:we.label}),(0,Ne.jsx)("div",{className:"break-words text-xs leading-4 text-muted-foreground",children:we.detail})]}),(0,Ne.jsxs)("div",{className:"w-full rounded-md border border-border/70 bg-secondary/70 px-3 py-2",children:[(0,Ne.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Context size"}),(0,Ne.jsx)("div",{className:"mt-1 text-lg font-semibold leading-none tabular-nums text-foreground",children:gi(we.contextWindow)})]})]},we.key))}):(0,Ne.jsxs)("div",{className:"rounded-lg border border-dashed border-border/70 bg-background/80 px-3 py-2 text-xs text-muted-foreground",children:["No suggested size was found for ",(0,Ne.jsx)("code",{children:be?.query||W}),"."]})}):null]}),ce?(0,Ne.jsx)($,{type:"button",variant:"ghost",className:ys,onMouseDown:we=>we.preventDefault(),onClick:()=>Ra(N.key),disabled:Ve,children:"Remove"}):(0,Ne.jsx)($,{type:"button",variant:"ghost",className:F(ys,"pointer-events-none invisible"),tabIndex:-1,disabled:!0,"aria-hidden":"true",children:"Remove"})]}),ce&&(0,Ne.jsx)(tT,{capabilities:N.capabilities||{},disabled:Ve,onChange:(we,ot)=>{let Ln={...N.capabilities||{}};ot===void 0?delete Ln[we]:Ln[we]=ot,ue(N.key,{capabilities:Ln})}}),Be?(0,Ne.jsx)("div",{className:"flex justify-end text-xs",children:(0,Ne.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-sky-700",children:[(0,Ne.jsx)(Dr,{}),"Looking up sizes"]})}):null,Le?(0,Ne.jsxs)("div",{className:"rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900",children:["Enter a positive integer like ",(0,Ne.jsx)("code",{children:"128000"}),", or leave the field blank."]}):et==="pending"?(0,Ne.jsx)("div",{className:"rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-xs text-sky-900",children:"Testing this model against the provider endpoint now."}):et==="success"?(0,Ne.jsx)("div",{className:"rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-900",children:"Confirmed by the latest live provider test."}):et==="error"?(0,Ne.jsx)("div",{className:"rounded-lg border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-900",children:"This model failed the latest live provider test."}):null]},N.key)})}),mn?(0,Ne.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:mn}):null,C?(0,Ne.jsx)("div",{className:F("rounded-xl px-3 py-2 text-sm",C.tone==="error"?"border border-rose-200 bg-rose-50 text-rose-900":C.tone==="warning"?"border border-amber-200 bg-amber-50 text-amber-900":"border border-emerald-200 bg-emerald-50 text-emerald-900"),children:C.message}):null,(0,Ne.jsx)("div",{className:F("sticky z-10 border-t border-border/70 bg-background/95 pt-3 backdrop-blur",a?"bottom-0":"bottom-0 -mx-5 rounded-b-[1rem] px-5 pb-4"),children:(0,Ne.jsxs)("div",{className:"flex min-h-9 items-center justify-between gap-3",children:[(0,Ne.jsx)("div",{className:F("text-xs",c==="testing"?"text-sky-700":c==="saving"?"text-foreground":"text-muted-foreground"),children:c==="testing"?(0,Ne.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,Ne.jsx)(Dr,{}),d||"Testing new models before save."]}):c==="saving"?(0,Ne.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,Ne.jsx)(Dr,{}),d||"Saving provider models."]}):Je.length>0&&ho(e)==="api"?`${Je.length} new model${Je.length===1?"":"s"} will be tested before save.`:"Existing models keep their current configuration metadata."}),(0,Ne.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[!t&&!Ve&&Ft.length>0?(0,Ne.jsx)($,{type:"button",variant:"outline",onClick:()=>{pn()},children:b?"Filling\u2026":"Fill missing context size"}):null,!t&&!Ve&&Yt?(0,Ne.jsx)($,{type:"button",variant:"ghost",onClick:()=>{y({}),w({}),E(null),M(""),ft.current.clear(),X.current.clear(),p(xe(u,{preserveFocus:!0}))},children:"Reset"}):null,!t&&Yt&&!mn?(0,Ne.jsx)($,{type:"button",onClick:()=>{It()},disabled:Ve,children:c==="testing"||v==="testing"?"Testing\u2026":c==="saving"||v==="saving"||r?"Saving\u2026":"Save models"}):null]})]})})]})}var le=_(Z(),1);function s5({provider:e,onRemove:t,onCopyModelId:n,onApplyProviderDetails:r,onApplyProviderModels:o,onSaveAndCloseEditor:a,disabledReason:i="",busy:l=!1}){let s=(0,Wt.useMemo)(()=>mC(e),[e]),[c,d]=(0,Wt.useState)(s),[u,f]=(0,Wt.useState)(!1),[p,v]=(0,Wt.useState)(!1),[m,b]=(0,Wt.useState)(!1),[h,g]=(0,Wt.useState)("provider"),[y,x]=(0,Wt.useState)(""),[w,C]=(0,Wt.useState)(0),[E,A]=(0,Wt.useState)({isDirty:!1,issue:"",locked:!1,rows:[]}),[M,L]=(0,Wt.useState)({phase:"",modelStates:{},failedModelIds:[],message:""}),P=(0,Wt.useRef)(null),D=(0,Wt.useRef)(null),G=(0,Wt.useRef)(null),ae=(0,Wt.useRef)(null);(0,Wt.useEffect)(()=>{d(s)},[s]);let j=ho(e)!=="api",J=(Array.isArray(e?.models)?e.models:[]).map(Te=>String(Te?.id||"").trim()).filter(Boolean),Q=ba(e),H=j?"":iC(e?.rateLimits),B=j?[]:Yn(c?.endpoints,c?.endpointDraft),ft=j?[]:gr(c?.rateLimitRows),X=JSON.stringify({id:String(c?.id||"").trim(),name:String(c?.name||"").trim(),credentialInput:String(c?.credentialInput||"").trim(),endpoints:B,endpointDraft:String(c?.endpointDraft||"").trim(),rateLimitRows:Qh(c?.rateLimitRows)}),je=JSON.stringify({id:String(s?.id||"").trim(),name:String(s?.name||"").trim(),credentialInput:String(s?.credentialInput||"").trim(),endpoints:pr(s?.endpoints),endpointDraft:String(s?.endpointDraft||"").trim(),rateLimitRows:Qh(s?.rateLimitRows)}),ie=X!==je,xe=!!i||l,Ie=new Set((Array.isArray(E.rows)?E.rows:[]).map(Te=>String(Te?.id||"").trim()).filter(Boolean)),I=M.failedModelIds.filter(Te=>Ie.has(Te)),ue=xe||M.phase==="testing"||M.phase==="saving",he=j?"":Lo(ft,{knownModelIds:J,requireAtLeastOne:!0}),_e=i||(String(c?.id||"").trim()?Xi.test(String(c?.id||"").trim())?String(c?.name||"").trim()?!j&&B.length===0?"Add at least one endpoint for API Key providers.":!j&&B.some(Te=>!fi(Te))?"All endpoints must start with http:// or https://.":he:"Provider name is required.":"Provider id must start with a letter and use lowercase letters, digits, or dashes only.":"Provider id is required."),Ee=j?c:{...c,endpoints:B,endpointDraft:""},ve=!!E.isDirty,Fe=ie||ve,Je=[ie?"provider settings":"",ve?"model list":""].filter(Boolean),Ht=[ie&&_e?`Provider: ${_e}`:"",ve&&E.issue?`Models: ${E.issue}`:""].filter(Boolean).join(" "),wn=xe||M.phase==="testing"||M.phase==="saving"||ie&&!!_e||ve&&(!!E.issue||E.locked)||typeof a!="function";async function fn(){let Te=await r(e.id,Ee);return Te&&Ve(),Te}async function Ft(Te){let Ze=await o(e.id,Te,{providerDraft:ie?Ee:null,onModelTestStateChange:Ce=>{L({phase:String(Ce?.phase||""),modelStates:Ce?.modelStates&&typeof Ce.modelStates=="object"?Ce.modelStates:{},failedModelIds:Array.isArray(Ce?.failedModelIds)?Ce.failedModelIds:[],message:String(Ce?.message||"")})}});return Ze&&Ve(),Ze}function Yt(){d(s)}let st=(0,Wt.useCallback)(Te=>{A(Te)},[]);function Ve(){v(!1),b(!1),f(!1),g("provider"),x(""),d(s),A({isDirty:!1,issue:"",locked:!1,rows:[]}),L({phase:"",modelStates:{},failedModelIds:[],message:""})}async function Vn(){let Te=(Array.isArray(E.rows)?E.rows:[]).filter(Ce=>!I.includes(String(Ce?.id||"").trim()));return Te.length===0&&!ie||await a(e.id,{providerDraft:ie?Ee:null,modelRows:ve?Te:null,onModelTestStateChange:Ce=>{L({phase:String(Ce?.phase||""),modelStates:Ce?.modelStates&&typeof Ce.modelStates=="object"?Ce.modelStates:{},failedModelIds:Array.isArray(Ce?.failedModelIds)?Ce.failedModelIds:[],message:String(Ce?.message||"")})}})?(Ve(),!0):(g("models"),!1)}(0,Wt.useEffect)(()=>{L({phase:"",modelStates:{},failedModelIds:[],message:""})},[s]),(0,Wt.useEffect)(()=>{I.length>0||!m||b(!1)},[I,m]),(0,Wt.useEffect)(()=>{if(!u||h!=="provider"||y!=="endpoint"&&y!=="rate-limit"||typeof window>"u")return;let Te=window.requestAnimationFrame(()=>{let Ze=y==="endpoint"?P.current:G.current,Ce=y==="endpoint"?D.current:ae.current;Ze?.scrollIntoView?.({block:"nearest"}),Ce?.focus?.(),Ce?.select?.(),x("")});return()=>window.cancelAnimationFrame(Te)},[u,h,y]);function mn(Te="provider",Ze=""){v(!1),b(!1),g(Te),x(Ze),Te==="models"&&Ze==="models"&&C(Ce=>Ce+1),f(!0)}function er(){if(!ue){if(I.length>0){v(!1),b(!0);return}if(Fe){v(!0);return}Ve()}}async function Ra(){if(wn)return;if(!await a(e.id,{providerDraft:ie?Ee:null,modelRows:ve?E.rows:null,onModelTestStateChange:Ze=>{L({phase:String(Ze?.phase||""),modelStates:Ze?.modelStates&&typeof Ze.modelStates=="object"?Ze.modelStates:{},failedModelIds:Array.isArray(Ze?.failedModelIds)?Ze.failedModelIds:[],message:String(Ze?.message||"")})}})){ve&&(v(!1),g("models"));return}Ve()}return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Gt,{children:(0,le.jsxs)(qt,{className:"space-y-3 p-5",children:[(0,le.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,le.jsx)("div",{className:"min-w-0 flex-1 px-0.5 py-0.5",children:(0,le.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[(0,le.jsx)("span",{className:"text-base font-semibold text-foreground",children:e.name||e.id}),(0,le.jsxs)("span",{className:"text-sm text-muted-foreground",children:["(",e.id,")"]})]})}),(0,le.jsxs)("div",{className:"flex items-start gap-2 self-start",children:[(0,le.jsxs)($,{type:"button",variant:"outline",size:"sm",className:"gap-1.5 normal-case tracking-normal",onClick:()=>mn("provider"),disabled:xe,"aria-label":`Edit provider ${e.name||e.id}`,title:"Edit provider",children:[(0,le.jsx)(bs,{className:"h-4 w-4 shrink-0"}),"Edit"]}),(0,le.jsx)($,{type:"button",variant:"outline",size:"sm",className:"h-8 w-8 shrink-0 p-0 text-muted-foreground hover:border-destructive/35 hover:bg-destructive/5 hover:text-destructive",onClick:()=>t(e.id),disabled:l,"aria-label":"Remove provider",title:"Remove provider",children:(0,le.jsx)(Qc,{className:"h-4 w-4"})})]})]}),J.length>0?(0,le.jsx)("div",{className:"flex flex-wrap gap-2 pt-1",children:J.map(Te=>(0,le.jsx)(FE,{onClick:()=>n?.(Te),title:`Copy model id ${Te}`,className:"max-w-full",children:(0,le.jsx)("span",{className:"truncate",children:Te})},`${e.id}-${Te}`))}):null]})}),(0,le.jsx)(Zn,{open:u,onClose:er,title:`Edit \xB7 ${e.id}`,description:M.phase==="testing"?M.message||"Testing new models before save.":M.phase==="saving"?M.message||"Saving provider changes.":"Switch between provider settings and model list. Each tab saves independently.",closeDisabled:ue,closeOnBackdrop:!ue,closeOnEscape:!ue,contentClassName:"max-h-[92vh] max-w-5xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)] pb-0",children:(0,le.jsxs)(fs,{value:h,onValueChange:g,children:[(0,le.jsxs)(ms,{className:"w-full justify-start",children:[(0,le.jsx)(dr,{value:"provider",children:"Provider"}),(0,le.jsx)(dr,{value:"models",children:"Model list"})]}),(0,le.jsxs)(fr,{forceMount:!0,value:"provider",className:F("space-y-4 pb-4",h!=="provider"?"hidden":null),children:[(0,le.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/60 p-4",children:(0,le.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Provider"}),(0,le.jsx)("div",{className:"mt-1 text-sm text-muted-foreground",children:"Update provider identity and connection settings here."})]}),(0,le.jsx)(ut,{variant:"outline",children:j?"Subscription":"API Key"})]})}),(0,le.jsxs)("div",{className:F("grid gap-3",j?"md:grid-cols-2":"md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]"),children:[(0,le.jsx)(pt,{label:"Provider name",stacked:!0,children:(0,le.jsx)(wt,{value:c.name,onChange:Te=>d(Ze=>({...Ze,name:Te.target.value})),disabled:ue})}),(0,le.jsx)(pt,{label:"Provider id",hint:"Used in direct routes like provider/model",stacked:!0,children:(0,le.jsx)(wt,{value:c.id,onChange:Te=>d(Ze=>({...Ze,id:Lr(Te.target.value)})),disabled:ue})})]}),j?null:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(pt,{label:"API key or env",hint:"Use an env var like OPENAI_API_KEY or paste the direct key.",stacked:!0,children:(0,le.jsx)(Is,{value:c.credentialInput||"",onChange:Te=>d(Ze=>({...Ze,credentialInput:Te.target.value})),disabled:ue,placeholder:"Example: OPENAI_API_KEY or sk-...",isEnvVar:go(c.credentialInput)})}),(0,le.jsx)("div",{ref:P,children:(0,le.jsx)(pt,{label:"Endpoints",hint:Q.length>1?"Comma, space, or newline turns into chips. The first endpoint stays active until you re-test this provider.":"Comma, space, or newline turns into chips.",stacked:!0,children:(0,le.jsx)(bu,{values:c.endpoints,onChange:Te=>d(Ze=>({...Ze,endpoints:Te})),draftValue:c.endpointDraft,onDraftValueChange:Te=>d(Ze=>({...Ze,endpointDraft:Te})),commitOnBlur:!0,disabled:ue,isValueValid:fi,inputRef:D,inputClassName:"placeholder:text-muted-foreground/55",placeholder:"Click here to type new endpoint",helperText:"Paste one or more endpoints"})})}),(0,le.jsx)("div",{ref:G,className:"grid gap-3 md:grid-cols-2 xl:grid-cols-[minmax(0,1.35fr)_minmax(0,0.8fr)_minmax(0,0.8fr)_minmax(0,1fr)]",children:(0,le.jsx)("div",{className:"md:col-span-2 xl:col-span-4",children:(0,le.jsx)(pt,{label:"Rate limit",stacked:!0,headerAction:(0,le.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:()=>d(Te=>({...Te,rateLimitRows:Tm(Te.rateLimitRows)})),disabled:ue,children:"Add rate limit"}),children:(0,le.jsx)(Mm,{rows:c.rateLimitRows,onChange:Te=>d(Ze=>({...Ze,rateLimitRows:Te})),availableModelIds:J,disabled:ue,inputRef:ae})})})})]}),_e?(0,le.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900",children:_e}):null,(0,le.jsxs)("div",{className:"flex min-h-9 items-center justify-end gap-2",children:[!ue&&ie?(0,le.jsx)($,{type:"button",variant:"ghost",onClick:Yt,children:"Reset"}):null,ie&&!_e?(0,le.jsx)($,{type:"button",onClick:()=>{fn()},disabled:ue,children:M.phase==="saving"||l?"Saving\u2026":"Save provider"}):null]})]}),(0,le.jsx)(fr,{forceMount:!0,value:"models",className:F(h!=="models"?"hidden":null),children:(0,le.jsx)(nT,{provider:e,disabled:!!i,disabledReason:i,busy:l,framed:!1,focusRequest:w,onStateChange:st,onApply:Ft,testStateByModel:M.modelStates,savePhase:M.phase,saveMessage:M.message})})]})}),(0,le.jsx)(VE,{open:p,onKeepEditing:()=>v(!1),onDiscardAndClose:Ve,onSaveAndClose:Ra,saveDisabled:wn,dirtyLabels:Je,details:Ht}),(0,le.jsx)(HE,{open:m,failedModelIds:I,onKeepEditing:()=>b(!1),onRemoveFailedAndClose:Vn,removeDisabled:ue||typeof a!="function"})]})}function c5({providers:e,onRemove:t,onCopyModelId:n,onApplyProviderDetails:r,onApplyProviderModels:o,onSaveAndCloseEditor:a,disabledReason:i="",busy:l=!1}){return e.length?(0,le.jsx)("div",{className:"grid gap-4 xl:grid-cols-2",children:e.map(s=>(0,le.jsx)(s5,{provider:s,onRemove:t,onCopyModelId:n,onApplyProviderDetails:r,onApplyProviderModels:o,onSaveAndCloseEditor:a,disabledReason:i,busy:l},s.id))}):(0,le.jsx)(Gt,{children:(0,le.jsx)(qt,{className:"flex flex-col gap-4 p-5 text-sm text-muted-foreground",children:(0,le.jsx)("div",{children:"No enabled providers are configured yet. Use Add provider to create your first provider, model list, and rate limits."})})})}function rT({providers:e,onAddProvider:t,onRemove:n,onCopyModelId:r,onApplyProviderDetails:o,onApplyProviderModels:a,onSaveAndCloseEditor:i,disabledReason:l="",busy:s=!1}){return(0,le.jsxs)("section",{className:"rounded-2xl border border-border/70 bg-card p-4","aria-label":"Provider models",children:[(0,le.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,le.jsxs)("div",{className:"min-w-0",children:[(0,le.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Provider & Models"}),(0,le.jsx)("div",{className:"mt-1 text-sm text-muted-foreground",children:"Manage providers, direct model routes, endpoints, and rate limits in one place."})]}),(0,le.jsx)($,{onClick:t,children:"Add provider"})]}),(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(c5,{providers:e,onRemove:n,onCopyModelId:r,onApplyProviderDetails:o,onApplyProviderModels:a,onSaveAndCloseEditor:i,disabledReason:l,busy:s})})]})}var xu=_(me(),1);var ne=_(Z(),1);function oT({connected:e,snapshot:t,models:n,busy:r,refreshing:o,config:a,onRefresh:i,onLoad:l,onUnload:s,onPin:c,onKeepAlive:d,onContextLength:u,onAddToRouter:f,onRemoveFromRouter:p,onAutoLoad:v,onSaveSettings:m,onInstall:b,onStartServer:h,onStopServer:g,onSyncRouter:y}){let x=a?.ollama||{},[w,C]=(0,xu.useState)(x.baseUrl||"http://localhost:11434"),[E,A]=(0,xu.useState)(x.autoConnect!==!1),[M,L]=(0,xu.useState)(x.defaultKeepAlive||"5m"),P=t?.installed===!0;return(0,ne.jsxs)("div",{className:"space-y-4",children:[(0,ne.jsx)(Gt,{children:(0,ne.jsxs)(qt,{className:"p-4 space-y-3",children:[(0,ne.jsxs)("div",{className:"flex items-center justify-between",children:[(0,ne.jsxs)("div",{className:"flex items-center gap-2",children:[(0,ne.jsx)("h3",{className:"font-medium",children:"Ollama Connection"}),e?(0,ne.jsx)(ut,{variant:"success",children:"Connected"}):(0,ne.jsx)(ut,{variant:"outline",children:"Disconnected"})]}),(0,ne.jsxs)("div",{className:"flex gap-2",children:[!P&&(0,ne.jsx)($,{size:"sm",onClick:b,disabled:r._install,children:r._install?"Installing\u2026":"Install Ollama"}),P&&!e&&(0,ne.jsx)($,{size:"sm",onClick:h,disabled:r._startServer,children:r._startServer?"Starting\u2026":"Start Server"}),e&&(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:g,children:"Stop Server"})]})]}),t?.version&&(0,ne.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Version: ",t.version]})]})}),e&&(0,ne.jsx)(Gt,{children:(0,ne.jsxs)(qt,{className:"p-4 space-y-3",children:[(0,ne.jsxs)("div",{className:"flex items-center justify-between",children:[(0,ne.jsx)("h3",{className:"font-medium",children:"Models"}),(0,ne.jsxs)("div",{className:"flex gap-2",children:[(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:y,disabled:r._syncRouter,children:r._syncRouter?"Syncing\u2026":"Sync All to Router"}),(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:i,disabled:o,children:o?"Refreshing\u2026":"Reload Models"})]})]}),n.length===0&&!o&&(0,ne.jsxs)("p",{className:"text-sm text-muted-foreground",children:["No models found. Pull models with ",(0,ne.jsx)("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:"ollama pull <model>"})]}),(0,ne.jsx)("div",{className:"space-y-2",children:n.map(D=>(0,ne.jsx)(u5,{model:D,busy:r[D.name]||{},onLoad:l,onUnload:s,onPin:c,onKeepAlive:d,onContextLength:u,onAddToRouter:f,onRemoveFromRouter:p,onAutoLoad:v},D.name))})]})}),(0,ne.jsx)(Gt,{children:(0,ne.jsxs)(qt,{className:"p-4 space-y-3",children:[(0,ne.jsx)("h3",{className:"font-medium",children:"Settings"}),(0,ne.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("label",{className:"mb-1 block text-xs font-medium text-muted-foreground",children:"Base URL"}),(0,ne.jsx)(wt,{value:w,onChange:D=>C(D.target.value),placeholder:"http://localhost:11434"})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("label",{className:"mb-1 block text-xs font-medium text-muted-foreground",children:"Default Keep Alive"}),(0,ne.jsxs)(rn,{value:M,onValueChange:L,children:[(0,ne.jsx)(on,{children:(0,ne.jsx)(an,{})}),(0,ne.jsx)(ln,{children:$h.map(D=>(0,ne.jsx)(Dt,{value:D.value,children:D.label},D.value))})]})]})]}),(0,ne.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,ne.jsx)("label",{className:"text-sm text-foreground",children:"Auto-connect on startup"}),(0,ne.jsx)(Pc,{checked:E,onCheckedChange:A})]}),(0,ne.jsx)($,{size:"sm",onClick:()=>m({baseUrl:w,autoConnect:E,defaultKeepAlive:M}),children:"Save Settings"})]})})]})}function u5({model:e,busy:t,onLoad:n,onUnload:r,onPin:o,onKeepAlive:a,onContextLength:i,onAddToRouter:l,onRemoveFromRouter:s,onAutoLoad:c}){let[d,u]=(0,xu.useState)(e.contextLength||0);return(0,ne.jsxs)("div",{className:"rounded-lg border border-border p-3 space-y-2",children:[(0,ne.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[(0,ne.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,ne.jsx)("span",{className:"font-mono text-sm font-medium",children:e.name}),(0,ne.jsx)(ut,{variant:"outline",children:e.parameterSize||"?"}),(0,ne.jsx)(ut,{variant:"outline",children:e.quantizationLevel||"?"}),e.loaded?(0,ne.jsxs)(ut,{variant:"success",children:["Loaded",e.sizeVramFormatted?` (${e.sizeVramFormatted})`:""]}):(0,ne.jsx)(ut,{variant:"default",children:"Available"}),e.isPinned&&(0,ne.jsx)(ut,{variant:"warning",children:"Pinned"})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.loaded?(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:()=>r(e.name),disabled:t.unloading,children:t.unloading?"Unloading\u2026":"Unload"}):(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:()=>n(e.name),disabled:t.loading,children:t.loading?"Loading\u2026":"Load"}),(0,ne.jsx)($,{size:"sm",variant:e.isPinned?"default":"outline",onClick:()=>o(e.name,!e.isPinned),disabled:t.pinning,title:e.isPinned?"Unpin (allow auto-unload)":"Pin in memory (blocks eviction)",children:e.isPinned?"Unpin":"Pin"}),e.inRouter?(0,ne.jsx)($,{size:"sm",variant:"outline",onClick:()=>s(e.name),className:"text-red-600 hover:text-red-700",children:"Remove from Router"}):(0,ne.jsx)($,{size:"sm",variant:"default",onClick:()=>l(e.name),children:"Add to Router"})]})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-4 flex-wrap text-xs",children:[(0,ne.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ne.jsx)("label",{className:"text-muted-foreground whitespace-nowrap",children:"Keep Alive:"}),(0,ne.jsxs)(rn,{value:e.keepAlive||"5m",onValueChange:f=>a(e.name,f),children:[(0,ne.jsx)(on,{className:"h-7 w-[160px] text-xs",children:(0,ne.jsx)(an,{})}),(0,ne.jsx)(ln,{children:$h.map(f=>(0,ne.jsx)(Dt,{value:f.value,children:f.label},f.value))})]})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,ne.jsx)("label",{className:"text-muted-foreground whitespace-nowrap",children:"Context:"}),(0,ne.jsx)(wt,{type:"number",className:"h-7 w-24 text-xs",value:d,onChange:f=>u(Number(f.target.value)),onBlur:()=>{d!==e.contextLength&&i(e.name,d)},min:0,step:1024}),e.contextLength>0&&(0,ne.jsxs)("span",{className:"text-muted-foreground",children:["max: ",e.contextLength.toLocaleString()]})]}),(0,ne.jsxs)("div",{className:"flex items-center gap-2",children:[(0,ne.jsx)(Pc,{checked:e.autoLoad,onCheckedChange:f=>c(e.name,f)}),(0,ne.jsx)("label",{className:"text-muted-foreground",children:"Auto-load on start"})]}),e.estimatedVram&&(0,ne.jsxs)("span",{className:"text-muted-foreground",children:["Est. VRAM: ",e.estimatedVram]})]})]})}var Nm=_(me(),1);var re=_(Z(),1);function d5(e=[]){let t=[],n=new Map,r=null;for(let o of(Array.isArray(e)?e:[]).filter(Boolean)){let a=String(o?.groupKey||o?.groupLabel||"").trim(),i=String(o?.groupLabel||"").trim();if(!a){r||(r={key:"__ungrouped__",label:"",options:[]},t.push(r)),r.options.push(o);continue}let l=n.get(a);l||(l={key:a,label:i||a,options:[]},n.set(a,l),t.push(l)),l.options.push(o)}return t}function f5(e={},{includeHint:t=!1}={}){let n=String(e?.label||e?.value||"").trim()||String(e?.value||"").trim(),r=String(e?.hint||"").trim();return t&&r?`${n} \xB7 ${r}`:n}function aT(e=[],{keyPrefix:t="select-option",includeHint:n=!1}={}){return d5(e).map((r,o)=>{let a=r.options.map(i=>(0,re.jsx)(Dt,{value:i.value,searchText:`${i.label||""} ${i.value||""} ${i.hint||""} ${r.label||""}`,children:f5(i,{includeHint:n})},`${t}-${i.value}`));return r.label?(0,re.jsxs)(ul,{children:[(0,re.jsx)(Ls,{children:r.label}),a]},`${t}-group-${r.key||o}`):a})}function m5({className:e=""}){return(0,re.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,re.jsx)("path",{d:"M10 2.75 4.75 5v4.12c0 3.42 2.1 6.58 5.25 7.88 3.15-1.3 5.25-4.46 5.25-7.88V5L10 2.75Z"}),(0,re.jsx)("circle",{cx:"10",cy:"9",r:"1.4"}),(0,re.jsx)("path",{d:"M10 10.4v2.1"})]})}function iT({rows:e,routeOptions:t,webSearchSnapshot:n,ampClientUrl:r,ampClientGlobal:o,routingBusy:a,onToggleGlobalRouting:i,onInboundChange:l,onOutboundChange:s,onCreateEntry:c,onRemoveEntry:d,onOpenWebSearchTab:u,onOpenConfigPath:f,onOpenSecretsPath:p,hasMasterKey:v,disabledReason:m,autosaveState:b}){let[h,g]=(0,Nm.useState)(!1),[y,x]=(0,Nm.useState)(""),[w,C]=(0,Nm.useState)(String(t[0]?.value||"").trim()),E=e.some(H=>String(H?.inbound||"").trim()===String(y||"").trim()&&String(y||"").trim()),A=String(y||"").trim()&&String(w||"").trim()&&!E,M=o?.routedViaRouter===!0,L=String(o?.error||"").trim(),P=!!(v&&r&&!m&&!L),D=Number(n?.configuredProviderCount)||0,G=M&&D===0,ae=m?"warning":b.status==="error"?"danger":b.status==="pending"?"outline":b.status==="saving"?"info":b.savedAt?"success":"outline",ge=m?"Needs review":b.status==="error"?"Save failed":b.status==="pending"?"Unsaved":b.status==="saving"?"saving...":b.savedAt?"Saved":"Ready",j=m||(b.status==="error"?b.message:b.status==="pending"?"Unsaved changes queued. Auto-save will run shortly.":b.status==="saving"?"Saving changes...":b.savedAt?`Last saved ${As(b.savedAt)}.`:"AMP route changes auto-save after valid edits.");async function J(){!A||await c?.({inbound:y,outbound:w})===!1||(g(!1),x(""),C(String(t[0]?.value||"").trim()))}function Q(){g(!0),x(""),C(String(t[0]?.value||"").trim())}return(0,re.jsx)("div",{className:"grid gap-4",children:(0,re.jsxs)(Gt,{children:[(0,re.jsxs)(Qr,{className:"flex flex-col gap-3 p-4 pb-0 sm:flex-row sm:items-start sm:justify-between",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(_o,{className:"flex items-center gap-2",children:(0,re.jsx)("span",{children:"Use AMP via LLM Router"})}),(0,re.jsx)(Em,{primaryLabel:"Config file",primaryValue:o?.settingsFilePath||"",onOpenPrimary:f,secondaryLabel:"Secrets file",secondaryValue:o?.secretsFilePath||"",secondaryIcon:(0,re.jsx)(m5,{className:"h-3 w-3"}),onOpenSecondary:p})]}),(0,re.jsx)("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:(0,re.jsx)($,{type:"button",size:"sm",variant:M?"outline":void 0,onClick:i,disabled:a!==""||!M&&!P,children:a==="enable"?"Connecting\u2026":a==="disable"?"Disconnecting\u2026":M?"Disconnect":"Connect"})})]}),(0,re.jsxs)(qt,{className:"space-y-4 p-4",children:[L?(0,re.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:L}):null,!M&&!v?(0,re.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:["Set ",(0,re.jsx)("code",{children:"masterKey"})," first to connect AMP."]}):null,G?(0,re.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:[(0,re.jsx)("div",{className:"max-w-3xl",children:"AMP is connected, but no alternative web search provider is configured. AMP web search is only available through the shared Web Search tab."}),(0,re.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:u,children:"Open Web Search"})]}):null,m?(0,re.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:m}):(0,re.jsxs)("div",{className:"space-y-3 rounded-2xl border border-border/70 bg-background/60 p-4",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Route mapping editor"}),(0,re.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:"Map built-in AMP route keys and wildcard model matches to managed routes."})]}),(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,re.jsx)(ut,{variant:ae,children:ge}),(0,re.jsxs)(ut,{variant:"outline",children:[e.length," routes"]}),(0,re.jsx)($,{type:"button",size:"sm",onClick:Q,children:"Add custom mapping"})]})]}),(0,re.jsx)("div",{className:"text-xs text-muted-foreground",children:j}),h?(0,re.jsx)("div",{className:"rounded-2xl border border-dashed border-border bg-background/80 p-3",children:(0,re.jsxs)("div",{className:"grid gap-3 xl:grid-cols-[160px_minmax(0,1fr)_minmax(0,1fr)] xl:items-start",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Add custom mapping"}),(0,re.jsx)(ut,{variant:"info",children:"Custom"})]}),(0,re.jsxs)("div",{className:"text-xs leading-5 text-muted-foreground",children:["Match a built-in AMP route key like ",(0,re.jsx)("code",{children:"smart"})," or a wildcard such as ",(0,re.jsx)("code",{children:"gpt-*-codex*"}),", then send it to any managed route."]}),(0,re.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,re.jsx)($,{type:"button",size:"sm",onClick:J,disabled:!A,children:"Create mapping"}),(0,re.jsx)($,{type:"button",size:"sm",variant:"ghost",onClick:()=>g(!1),children:"Close"})]})]}),(0,re.jsx)(pt,{label:"Inbound match",hint:"Built-in route key or AMP model pattern",children:(0,re.jsx)(wt,{value:y,onChange:H=>x(H.target.value),placeholder:"smart or gpt-*-codex*"})}),(0,re.jsx)(pt,{label:"Route target",hint:"Alias or provider/model route in LLM Router",children:(0,re.jsxs)(rn,{value:w||void 0,onValueChange:C,children:[(0,re.jsx)(on,{children:(0,re.jsx)(an,{placeholder:"Select local route"})}),(0,re.jsx)(ln,{children:aT(t,{keyPrefix:"amp-route-create",includeHint:!0})})]})})]})}):null,(0,re.jsx)("div",{className:"space-y-2",children:e.map(H=>(0,re.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/75 p-3",children:(0,re.jsxs)("div",{className:"grid gap-3 xl:grid-cols-[160px_minmax(0,1fr)_minmax(0,1fr)] xl:items-start",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-foreground",children:H.label}),H.isCustom?(0,re.jsx)(ut,{variant:"info",children:"Custom"}):null]}),(0,re.jsx)("div",{className:"text-xs leading-5 text-muted-foreground",children:H.description}),H.removable?(0,re.jsx)($,{type:"button",size:"sm",variant:"ghost",onClick:()=>d(H.id),children:"Remove"}):null]}),(0,re.jsx)(pt,{label:"Inbound wildcard",hint:H.defaultMatch?`Default: ${H.defaultMatch}`:"AMP model pattern",children:(0,re.jsx)(Am,{commitOnBlur:!0,value:H.inbound,onValueCommit:B=>l(H.id,B),placeholder:H.defaultMatch||"gpt-*-codex*",onKeyDown:B=>{B.key==="Enter"&&(B.preventDefault(),B.currentTarget.blur())}})}),(0,re.jsx)(pt,{label:"Target route",hint:"Alias or provider/model route",children:(0,re.jsxs)(rn,{value:H.outbound||"__default__",onValueChange:B=>s(H.id,B),children:[(0,re.jsx)(on,{children:(0,re.jsx)(an,{placeholder:H.removable?"Choose target route":"Use default route"})}),(0,re.jsxs)(ln,{children:[H.removable?null:(0,re.jsx)(Dt,{value:"__default__",children:"Use default route"}),aT(t,{keyPrefix:`amp-route-${H.id}`,includeHint:!0})]})]})})]})},H.id))})]})]})]})})}var Ca=_(me(),1);var Y=_(Z(),1);function p5({className:e=""}){return(0,Y.jsxs)("svg",{viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:e,children:[(0,Y.jsx)("path",{d:"M8 3.5v9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),(0,Y.jsx)("path",{d:"M3.5 8h9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function g5({open:e=!1,onClose:t=()=>{},candidates:n=[],onTestAndAdd:r=async()=>{},disabledReason:o=""}){let[a,i]=(0,Ca.useState)(""),[l,s]=(0,Ca.useState)(""),[c,d]=(0,Ca.useState)(!1),[u,f]=(0,Ca.useState)(""),p=Array.isArray(n)?n:[],v=p.find(y=>y.providerId===a)||p[0]||null,m=Array.isArray(v?.models)?v.models:[];(0,Ca.useEffect)(()=>{if(!e){d(!1),f("");return}let y=p[0]?.providerId||"";i(x=>p.some(C=>C.providerId===x)?x:y)},[e,p]),(0,Ca.useEffect)(()=>{let y=m[0]?.value||"";s(x=>m.some(C=>C.value===x)?x:y)},[m]);let b=mi(a,l),h=e&&!c&&!o&&a&&l;async function g(){if(h){d(!0),f("");try{await r({providerId:a,modelId:l}),t()}catch(y){f(y instanceof Error?y.message:String(y))}finally{d(!1)}}}return(0,Y.jsx)(Zn,{open:e,onClose:()=>{c||t()},title:"Add ChatGPT Search Endpoint",description:"Choose a configured OpenAI-compatible GPT route. Test runs a live Responses API request with the native web search tool, then saves the route on success.",contentClassName:"max-h-[92vh] max-w-3xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",showCloseButton:!1,footer:(0,Y.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[(0,Y.jsx)($,{type:"button",variant:"ghost",onClick:t,disabled:c,children:"Cancel"}),(0,Y.jsx)($,{type:"button",onClick:()=>{g()},disabled:!h,children:c?"Testing\u2026":"Test connection"})]}),children:(0,Y.jsxs)("div",{className:"space-y-4",children:[o?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:o}):null,!o&&p.length===0?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:"No configured OpenAI-compatible GPT providers are available yet. Add a provider with a GPT model first."}):null,p.length>0?(0,Y.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,Y.jsx)(pt,{label:"Provider",hint:"Configured provider or ChatGPT subscription",stacked:!0,children:(0,Y.jsxs)(rn,{value:a||void 0,onValueChange:i,disabled:c||!!o,children:[(0,Y.jsx)(on,{children:(0,Y.jsx)(an,{placeholder:"Choose provider"})}),(0,Y.jsx)(ln,{children:p.map(y=>(0,Y.jsx)(Dt,{value:y.providerId,children:y.providerLabel},y.providerId))})]})}),(0,Y.jsx)(pt,{label:"GPT model",hint:"Only GPT models on OpenAI-compatible routes are listed",stacked:!0,children:(0,Y.jsxs)(rn,{value:l||void 0,onValueChange:s,disabled:c||!!o||m.length===0,children:[(0,Y.jsx)(on,{children:(0,Y.jsx)(an,{placeholder:"Choose model"})}),(0,Y.jsx)(ln,{children:m.map(y=>(0,Y.jsx)(Dt,{value:y.value,children:y.label},y.routeId))})]})})]}):null,b?(0,Y.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-4 py-3",children:[(0,Y.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Saved route id"}),(0,Y.jsx)("div",{className:"mt-1 text-sm font-medium text-foreground",children:b}),(0,Y.jsx)("div",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:"This route stores only the provider/model reference. No separate API key or quota is saved here."})]}):null,u?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:u}):null]})})}function lT({webSearchConfig:e,webSearchProviders:t,hostedSearchCandidates:n,onWebSearchStrategyChange:r,onWebSearchProviderChange:o,onWebSearchProviderMove:a,onRemoveWebSearchProvider:i,onAddHostedSearchEndpoint:l,disabledReason:s,autosaveState:c}){let[d,u]=(0,Ca.useState)(!1),f=String(e?.strategy||"ordered").trim()==="quota-balance"?"quota-balance":"ordered",p=Array.isArray(n)&&n.some(m=>Array.isArray(m?.models)&&m.models.length>0),v=s||(c.status==="error"?c.message:c.status==="pending"?"Unsaved changes queued. Auto-save will run shortly.":c.status==="saving"?"Saving changes...":c.savedAt?`Last saved ${As(c.savedAt)}.`:"");return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(Gt,{children:[(0,Y.jsxs)(Qr,{className:"flex flex-col gap-4 p-4 pb-0 xl:flex-row xl:items-start xl:justify-between",children:[(0,Y.jsxs)("div",{className:"space-y-1",children:[(0,Y.jsx)(_o,{children:"Web Search"}),(0,Y.jsx)(li,{className:"text-xs leading-5",children:"Shared web search routing for AMP and other router-managed tools."}),v?(0,Y.jsx)("div",{className:"text-xs text-muted-foreground",children:v}):null]}),(0,Y.jsxs)("div",{className:"flex w-full shrink-0 flex-wrap items-end justify-end gap-3 xl:w-auto",children:[(0,Y.jsxs)("div",{className:"min-w-[12rem] space-y-1",children:[(0,Y.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Routing strategy"}),(0,Y.jsxs)(rn,{value:f,onValueChange:r,disabled:!!s,children:[(0,Y.jsx)(on,{children:(0,Y.jsx)(an,{placeholder:"Choose strategy"})}),(0,Y.jsx)(ln,{children:FA.map(m=>(0,Y.jsx)(Dt,{value:m.value,children:m.label},m.value))})]})]}),(0,Y.jsxs)($,{type:"button",variant:"outline",className:"gap-2",onClick:()=>u(!0),disabled:!!s||!p,children:[(0,Y.jsx)(p5,{className:"h-3.5 w-3.5"}),(0,Y.jsx)("span",{children:"Endpoint"})]})]})]}),(0,Y.jsx)(qt,{className:"space-y-4 p-4",children:(0,Y.jsx)("div",{className:"space-y-3",children:(t||[]).map(m=>{if(m.kind==="hosted"){let g=m.runtimeState&&m.runtimeState.ready===!1?"This provider/model route is no longer available or is not OpenAI-compatible.":"";return(0,Y.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-4",children:(0,Y.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,Y.jsxs)("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-start xl:justify-between",children:[(0,Y.jsxs)("div",{className:"min-w-0",children:[(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,Y.jsx)(ev,{active:m.active}),(0,Y.jsx)("div",{className:"text-sm font-medium text-foreground",children:m.label}),(0,Y.jsx)(ut,{variant:"outline",children:"GPT Search"})]}),(0,Y.jsx)("div",{className:"mt-1 text-xs break-all text-muted-foreground",children:m.routeId}),(0,Y.jsx)("div",{className:"mt-2 text-xs leading-5 text-muted-foreground",children:"Uses the provider's native OpenAI Responses web search tool. No local API key or quota is stored here."})]}),(0,Y.jsxs)("div",{className:"flex items-center gap-2 self-start",children:[(0,Y.jsxs)("div",{className:"flex items-center gap-2 rounded-xl border border-border/70 bg-background/70 p-1",children:[(0,Y.jsx)(Sa,{disabled:!!s||m.displayIndex<=0,label:`Move ${m.routeId} up`,onClick:()=>a(m.id,"up")}),(0,Y.jsx)(dl,{disabled:!!s||m.displayIndex>=m.displayCount-1,label:`Move ${m.routeId} down`,onClick:()=>a(m.id,"down")})]}),(0,Y.jsx)($,{type:"button",size:"sm",variant:"ghost",onClick:()=>i(m.id),disabled:!!s,children:"Remove"})]})]}),g?(0,Y.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:g}):null]})},m.key)}let b=m.credentialField,h=String(m?.credentialValue||"").trim();return(0,Y.jsx)("div",{className:"rounded-2xl border border-border/70 bg-background/80 p-4",children:(0,Y.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,Y.jsxs)("div",{className:"flex flex-col gap-3 xl:flex-row xl:items-start xl:justify-between",children:[(0,Y.jsx)("div",{className:"min-w-0",children:(0,Y.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,Y.jsx)(ev,{active:m.active}),(0,Y.jsx)("div",{className:"text-sm font-medium text-foreground",children:m.label})]})}),(0,Y.jsxs)("div",{className:"flex items-center gap-2 self-start rounded-xl border border-border/70 bg-background/70 p-1",children:[(0,Y.jsx)(Sa,{disabled:!!s||m.displayIndex<=0,label:`Move ${m.label} up`,onClick:()=>a(m.id,"up")}),(0,Y.jsx)(dl,{disabled:!!s||m.displayIndex>=m.displayCount-1,label:`Move ${m.label} down`,onClick:()=>a(m.id,"down")})]})]}),(0,Y.jsxs)("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,0.9fr)_minmax(0,1.35fr)]",children:[(0,Y.jsx)(pt,{label:m.credentialLabel,hint:m.credentialField==="url"?"Required to enable this backend.":"Required to enable this backend. Stored in router config.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Is,{buffered:!0,value:h,placeholder:m.credentialPlaceholder,onValueChange:g=>o(m.id,b,g),disabled:!!s,isEnvVar:m.credentialField==="url"})}),(0,Y.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[(0,Y.jsx)(pt,{label:"Result per call",hint:"Empty keeps the default of 5.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Cm,{value:m.resultPerCallInput,placeholder:"Default: 5",allowEmptyCommit:!0,onValueChange:g=>o(m.id,"count",g),disabled:!!s})}),(0,Y.jsx)(pt,{label:"Monthly limit",hint:"0 keeps quotas self-managed.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Cm,{value:String(m.limit||0),onValueChange:g=>o(m.id,"limit",g),disabled:!!s})}),(0,Y.jsx)(pt,{label:"Synced remaining",hint:"Adjust after manual upstream sync.",stacked:!0,className:"gap-1",headerClassName:"min-h-0",hintClassName:"leading-4",children:(0,Y.jsx)(Cm,{value:String(m.remaining||0),onValueChange:g=>o(m.id,"remaining",g),disabled:!!s})})]})]})]})},m.key)})})})]}),(0,Y.jsx)(g5,{open:d,onClose:()=>u(!1),candidates:n,onTestAndAdd:l,disabledReason:s})]})}var Su=_(me(),1);var S=_(Z(),1);function h5(e=""){let t=String(e||"").trim();if(!t)return{};let n=Cf(t);if(n?.kind==="alias")return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};if(n?.kind==="model"&&n.providerId)return{kind:"model",providerId:n.providerId,groupKey:`provider:${n.providerId}`,groupLabel:n.providerId};if(n?.kind==="model")return{kind:"model",groupKey:"llm-router",groupLabel:"LLM Router"};let r=t.startsWith("alias:")?t.slice(6).trim():t;if(!r.includes("/"))return{kind:"alias",groupKey:"aliases",groupLabel:"Aliases"};let o=r.indexOf("/"),a=r.slice(0,o).trim();return a?{kind:"model",providerId:a,groupKey:`provider:${a}`,groupLabel:a}:{}}function y5(e=[],t=[]){let n=[...Array.isArray(e)?e:[]],r=new Set(n.map(o=>String(o?.value||"").trim()).filter(Boolean));for(let o of(Array.isArray(t)?t:[]).map(a=>String(a||"").trim()).filter(Boolean))r.has(o)||(r.add(o),n.push({value:o,label:o,hint:"Current config",...h5(o)}));return n}function v5(e=[]){let t=[],n=new Map,r=null;for(let o of(Array.isArray(e)?e:[]).filter(Boolean)){let a=String(o?.groupKey||o?.groupLabel||"").trim(),i=String(o?.groupLabel||"").trim();if(!a){r||(r={key:"__ungrouped__",label:"",options:[]},t.push(r)),r.options.push(o);continue}let l=n.get(a);l||(l={key:a,label:i||a,options:[]},n.set(a,l),t.push(l)),l.options.push(o)}return t}function b5(e={},{includeHint:t=!1}={}){let n=String(e?.label||e?.value||"").trim()||String(e?.value||"").trim(),r=String(e?.hint||"").trim();return t&&r?`${n} \xB7 ${r}`:n}function x5(e=[],{keyPrefix:t="select-option",includeHint:n=!1}={}){return v5(e).map((r,o)=>{let a=r.options.map(i=>(0,S.jsx)(Dt,{value:i.value,searchText:`${i.label||""} ${i.value||""} ${i.hint||""} ${r.label||""}`,children:b5(i,{includeHint:n})},`${t}-${i.value}`));return r.label?(0,S.jsxs)(ul,{children:[(0,S.jsx)(Ls,{children:r.label}),a]},`${t}-group-${r.key||o}`):a})}function S5({className:e=""}){return(0,S.jsxs)("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",className:e,"aria-hidden":"true",children:[(0,S.jsx)("path",{d:"M6 3.5h5.25L15 7.25V16A1.5 1.5 0 0 1 13.5 17.5h-7A1.5 1.5 0 0 1 5 16V5A1.5 1.5 0 0 1 6.5 3.5H6Z"}),(0,S.jsx)("path",{d:"M11 3.5V7.5H15"}),(0,S.jsx)("path",{d:"M7 12.25a3 3 0 1 1 2.85 2.99"}),(0,S.jsx)("path",{d:"M8.5 10.25h1.5v1.5"})]})}function cT({bindingValue:e="",thinkingLevel:t="",configFilePath:n="",endpointUrl:r=""}={}){let o=String(e||"").trim(),a=String(t||"").trim(),i=String(n||"").trim(),l=String(r||"").trim(),s=Af(o),c=s?"Mode: Inherit Codex model":o?`Mode: Pinned to ${o}`:"Mode: Choose a route",d=s?{variant:"success",title:"Inherit mode keeps Codex-native model picks intact.",body:(0,S.jsxs)(S.Fragment,{children:["Codex CLI still chooses its own model name. Create a same-name alias in the ",(0,S.jsx)("span",{className:"font-medium",children:"Alias & Fallback"})," tab so LLM Router can resolve that name to the real upstream target you want."]})}:o?{variant:"info",title:"Pinned mode forces one router target.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router writes ",(0,S.jsxs)("code",{children:["model=",o]})," into Codex CLI config. That is the simplest setup when every Codex session should use one managed route or alias."]})}:{variant:"warning",title:"Choose your model strategy before you connect.",body:(0,S.jsxs)(S.Fragment,{children:["Pick ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"})," if Codex should keep using its built-in model names, or pick one managed route/alias if you want a single fixed target."]})};return{title:"Codex CLI guide",description:"Quick setup for routing Codex CLI through LLM Router while keeping model routing easy to inspect and change later.",badges:[{label:c,variant:s?"success":o?"info":"outline"},{label:a?`Thinking: ${a}`:"Thinking: Codex default",variant:"outline"},{label:i?"Config file detected":"User config: ~/.codex/config.toml",variant:"outline"}],callout:d,highlights:[{eyebrow:"1. Connect",title:"Point Codex CLI at LLM Router",body:l?(0,S.jsxs)(S.Fragment,{children:["When connected, Codex sends requests to ",(0,S.jsx)("code",{children:l}),". LLM Router then handles upstream auth, alias resolution, and failover."]}):(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch Codex CLI so it talks to LLM Router instead of a provider directly."]})},{eyebrow:"2. Route",title:"Choose between inherit and pinned mode",body:s?(0,S.jsxs)(S.Fragment,{children:["Keep Codex model names such as ",(0,S.jsx)("code",{children:"gpt-5.4"}),", then create matching aliases in LLM Router, for example ",(0,S.jsx)("code",{children:"gpt-5.4"})," -> ",(0,S.jsx)("code",{children:"demo/gpt-4o-mini"}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Select one managed route or alias in ",(0,S.jsx)("span",{className:"font-medium",children:"Default model"})," when you want every Codex request to land on the same router target."]})},{eyebrow:"3. Tune",title:"Optional reasoning control",body:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("span",{className:"font-medium",children:"Thinking level"})," writes Codex CLI ",(0,S.jsx)("code",{children:"model_reasoning_effort"})," with the official values ",(0,S.jsx)("code",{children:"minimal"}),", ",(0,S.jsx)("code",{children:"low"}),", ",(0,S.jsx)("code",{children:"medium"}),", ",(0,S.jsx)("code",{children:"high"}),", or ",(0,S.jsx)("code",{children:"xhigh"}),"."]})}],sections:[{title:"Quick start",items:[(0,S.jsxs)(S.Fragment,{children:["Set a ",(0,S.jsx)("code",{children:"masterKey"})," in LLM Router first. The ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," button stays disabled until gateway auth is ready."]}),(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch the Codex CLI config file and router base URL."]}),s?(0,S.jsxs)(S.Fragment,{children:["Leave ",(0,S.jsx)("span",{className:"font-medium",children:"Default model"})," on ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"}),", then create aliases that match the Codex model names you actually use."]}):o?(0,S.jsxs)(S.Fragment,{children:["Your current default is pinned to ",(0,S.jsx)("code",{children:o}),". Change it only when you want Codex to use a different managed route or alias."]}):(0,S.jsxs)(S.Fragment,{children:["Choose either ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"})," or one managed route/alias in ",(0,S.jsx)("span",{className:"font-medium",children:"Default model"})," before you start using Codex through the router."]}),(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Thinking level"})," only when you want LLM Router to write ",(0,S.jsx)("code",{children:"model_reasoning_effort"}),"; leave it unset to keep Codex CLI defaults."]})]},{title:"Choose the right model strategy",items:[(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Inherit Codex CLI model"})," when you want Codex-native model names and model-specific UI/options to remain visible."]}),(0,S.jsx)(S.Fragment,{children:"Use a fixed route or alias when your team wants one centrally managed target regardless of what Codex would otherwise choose."}),(0,S.jsx)(S.Fragment,{children:"If Codex-specific options disappear after pinning a route, switch back to inherit mode and route those same model names through aliases instead."})]},{title:"Where these settings land",items:[i?(0,S.jsxs)(S.Fragment,{children:["This page is currently managing ",(0,S.jsx)("code",{children:i}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Codex CLI usually stores user settings in ",(0,S.jsx)("code",{children:"~/.codex/config.toml"}),". Trusted projects can also add overrides in ",(0,S.jsx)("code",{children:".codex/config.toml"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The router-managed bindings in this panel map to Codex CLI ",(0,S.jsx)("code",{children:"model"})," and ",(0,S.jsx)("code",{children:"model_reasoning_effort"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Open Codex CLI Config File"})," whenever you want to inspect the exact generated config."]})]},{title:"Quick verify",items:[(0,S.jsx)(S.Fragment,{children:"Open the config file from this page and confirm the values match the mode you intended."}),(0,S.jsx)(S.Fragment,{children:"Start Codex CLI and run a small prompt. If inherit mode is on, make sure the Codex model you selected has a same-name alias in LLM Router."}),(0,S.jsxs)(S.Fragment,{children:["If requests fail after switching models, check the ",(0,S.jsx)("span",{className:"font-medium",children:"Alias & Fallback"})," tab first because the alias behind that model name may be missing or pointed at the wrong target."]})]}]}}function uT({bindings:e={},settingsFilePath:t="",endpointUrl:n=""}={}){let r=String(e?.primaryModel||"").trim(),o=String(e?.defaultOpusModel||"").trim(),a=String(e?.defaultSonnetModel||"").trim(),i=String(e?.defaultHaikuModel||"").trim(),l=String(e?.subagentModel||"").trim(),s=OA(e?.thinkingLevel),c=String(t||"").trim(),d=String(n||"").trim(),u=[r,o,a,i,l,s].filter(Boolean).length,f=r?{variant:"info",title:"Primary model override is active.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router is currently writing ",(0,S.jsxs)("code",{children:["ANTHROPIC_MODEL=",r]}),". Leave that field blank if you want Claude Code to keep choosing its own primary model."]})}:u>0?{variant:"info",title:"Only filled fields are overridden.",body:(0,S.jsx)(S.Fragment,{children:"Claude Code continues to inherit its normal defaults for every blank field. This is useful when you only want to steer alias models, subagents, or effort level through LLM Router."})}:{variant:"success",title:"Blank fields are a valid setup.",body:(0,S.jsx)(S.Fragment,{children:"You do not need to fill every binding. Leave fields empty unless you want LLM Router to override that specific Claude Code setting."})};return{title:"Claude Code guide",description:"Quick setup for routing Claude Code through LLM Router while keeping only the model and effort level overrides you actually want.",badges:[{label:u>0?`${u} override${u===1?"":"s"} active`:"No router overrides",variant:u>0?"info":"outline"},{label:s?`Effort: ${s}`:"Effort: Claude adaptive default",variant:"outline"},{label:c?"Settings file detected":"Settings scope: local/project/user",variant:"outline"}],callout:f,highlights:[{eyebrow:"1. Connect",title:"Point Claude Code at the router",body:d?(0,S.jsxs)(S.Fragment,{children:["When connected, Claude Code sends requests to ",(0,S.jsx)("code",{children:d}),". LLM Router then handles upstream auth, route selection, and failover."]}):(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch Claude Code so it uses the router Anthropic endpoint instead of a provider directly."]})},{eyebrow:"2. Override",title:"Set only the bindings you need",body:(0,S.jsxs)(S.Fragment,{children:["Leave fields blank to inherit Claude Code defaults. Fill ",(0,S.jsx)("code",{children:"ANTHROPIC_MODEL"}),", the Opus/Sonnet/Haiku defaults, or ",(0,S.jsx)("code",{children:"CLAUDE_CODE_SUBAGENT_MODEL"})," only when you want LLM Router to manage those values."]})},{eyebrow:"3. Effort",title:"Set thinking effort level",body:(0,S.jsxs)(S.Fragment,{children:["The ",(0,S.jsx)("span",{className:"font-medium",children:"Effort level"})," dropdown writes ",(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"})," to your shell profile. If the shell profile cannot be updated, ",(0,S.jsx)("code",{children:"effortLevel"})," is set in ",(0,S.jsx)("code",{children:"settings.json"}),' as a fallback (only "high" is supported there).']})}],sections:[{title:"Quick start",items:[(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to patch Claude Code toward the router and keep provider credentials centralized inside LLM Router."]}),(0,S.jsxs)(S.Fragment,{children:["Leave ",(0,S.jsx)("span",{className:"font-medium",children:"Current model override"})," empty unless you explicitly want to replace Claude Code's own main model selection."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Default Opus"}),", ",(0,S.jsx)("span",{className:"font-medium",children:"Default Sonnet"}),", and ",(0,S.jsx)("span",{className:"font-medium",children:"Default Haiku"})," when you want Claude Code's built-in alias names to resolve to managed routes or aliases."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Sub-agent model"})," when background workers or helper agents should run on a different route than the main session."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Effort level"})," to set ",(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"})," in your shell profile; leave it unset to keep Claude Code's adaptive default. The ",(0,S.jsx)("code",{children:"effortLevel"})," key in ",(0,S.jsx)("code",{children:"settings.json"}),' (only "high") acts as a fallback when the shell profile cannot be updated.']})]},{title:"What each binding controls",items:[(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"ANTHROPIC_MODEL"}),": overrides the main model for the active Claude Code session."]}),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"ANTHROPIC_DEFAULT_OPUS_MODEL"}),", ",(0,S.jsx)("code",{children:"ANTHROPIC_DEFAULT_SONNET_MODEL"}),", and ",(0,S.jsx)("code",{children:"ANTHROPIC_DEFAULT_HAIKU_MODEL"}),": remap Claude Code's built-in alias names to managed routes or aliases."]}),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"CLAUDE_CODE_SUBAGENT_MODEL"}),": routes subagents and background workers to a specific managed model."]}),s?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"}),": currently set to ",(0,S.jsx)("span",{className:"font-medium",children:s})," in your shell profile."]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"}),": stays unset unless you choose an effort level."]})]},{title:"Settings scope and precedence",items:[(0,S.jsxs)(S.Fragment,{children:["Claude Code settings apply in this order: ",(0,S.jsx)("code",{children:"managed-settings.json"}),", CLI arguments, ",(0,S.jsx)("code",{children:".claude/settings.local.json"}),", ",(0,S.jsx)("code",{children:".claude/settings.json"}),", then ",(0,S.jsx)("code",{children:"~/.claude/settings.json"}),"."]}),c?(0,S.jsxs)(S.Fragment,{children:["This page is currently managing ",(0,S.jsx)("code",{children:c}),"."]}):(0,S.jsx)(S.Fragment,{children:"Claude Code can read from project-local, project-shared, or user settings files depending on what exists in your environment."}),(0,S.jsx)(S.Fragment,{children:"If a value seems ignored, check whether a higher-precedence file or command-line flag is overriding it."})]},{title:"Quick verify",items:[(0,S.jsxs)(S.Fragment,{children:["Open the settings file from this page and confirm the ",(0,S.jsx)("code",{children:"env"})," block contains only the overrides you meant to set."]}),(0,S.jsxs)(S.Fragment,{children:["Launch Claude Code and test both the main session and any subagents if you changed ",(0,S.jsx)("code",{children:"CLAUDE_CODE_SUBAGENT_MODEL"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["If thinking behavior is not what you expected, remember this UI writes ",(0,S.jsx)("code",{children:"CLAUDE_CODE_EFFORT_LEVEL"})," to your shell profile; clearing the field returns control to Claude Code's own default behavior."]})]}]}}function dT({bindings:e={},settingsFilePath:t="",endpointUrl:n=""}={}){let r=String(e?.defaultModel||"").trim(),o=String(e?.missionOrchestratorModel||"").trim(),a=String(e?.missionWorkerModel||"").trim(),i=String(e?.missionValidatorModel||"").trim(),l=_A(e?.reasoningEffort),s=String(t||"").trim(),c=String(n||"").trim(),d=r||o||a||i?{variant:"info",title:"Factory defaults are set.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router injects router-managed ",(0,S.jsx)("code",{children:"customModels"})," entries, sets each managed provider to ",(0,S.jsx)("code",{children:"openai"})," or ",(0,S.jsx)("code",{children:"anthropic"})," based on the routed model format, and writes separate defaults for normal sessions and Missions."]})}:{variant:"success",title:"Factory Droid connected via managed custom models.",body:(0,S.jsxs)(S.Fragment,{children:["LLM Router injects router-managed ",(0,S.jsx)("code",{children:"customModels"})," entries pointing at the gateway. Set normal or Mission defaults below, or use Factory Droid's ",(0,S.jsx)("code",{children:"/model"})," command to pick the routed model at runtime."]})};return{title:"Factory Droid guide",description:"Quick setup for routing Factory Droid through LLM Router via router-managed custom models.",badges:[{label:r?`Normal: ${r}`:"Normal: Factory default",variant:r?"info":"outline"},{label:o?`Orchestrator: ${o}`:"Orchestrator: Factory default",variant:o?"info":"outline"},{label:a?`Worker: ${a}`:"Worker: Factory default",variant:a?"info":"outline"},{label:i?`Validator: ${i}`:"Validator: Factory default",variant:i?"info":"outline"},{label:l?`Reasoning: ${l}`:"Reasoning: Droid default",variant:"outline"},{label:s?"Settings file detected":"User config: ~/.factory/settings.json",variant:"outline"}],callout:d,highlights:[{eyebrow:"1. Connect",title:"Point Factory Droid at LLM Router",body:c?(0,S.jsxs)(S.Fragment,{children:["When connected, Factory Droid sends requests to ",(0,S.jsx)("code",{children:c}),". LLM Router handles upstream auth, alias resolution, and failover."]}):(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to inject router-managed custom models into Factory Droid settings."]})},{eyebrow:"2. Route",title:"Set normal and Mission defaults",body:(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Normal mode model"})," for regular sessions, then set separate Mission bindings for the orchestrator, worker, and validator roles."]})},{eyebrow:"3. Tune",title:"Optional reasoning control",body:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("span",{className:"font-medium",children:"Reasoning effort"})," writes Factory Droid ",(0,S.jsx)("code",{children:"reasoningEffort"}),". Values: ",(0,S.jsx)("code",{children:"off"}),", ",(0,S.jsx)("code",{children:"none"}),", ",(0,S.jsx)("code",{children:"low"}),", ",(0,S.jsx)("code",{children:"medium"}),", or ",(0,S.jsx)("code",{children:"high"}),"."]})}],sections:[{title:"Quick start",items:[(0,S.jsxs)(S.Fragment,{children:["Set a ",(0,S.jsx)("code",{children:"masterKey"})," in LLM Router first. The ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," button stays disabled until gateway auth is ready."]}),(0,S.jsxs)(S.Fragment,{children:["Click ",(0,S.jsx)("span",{className:"font-medium",children:"Connect"})," to inject a managed ",(0,S.jsx)("code",{children:"customModels"})," entry into ",(0,S.jsx)("code",{children:"~/.factory/settings.json"}),"."]}),r?(0,S.jsxs)(S.Fragment,{children:["Your normal-session default is ",(0,S.jsx)("code",{children:r}),". Change it any time from this panel."]}):(0,S.jsxs)(S.Fragment,{children:["Choose a managed route or alias in ",(0,S.jsx)("span",{className:"font-medium",children:"Normal mode model"})," to set the default Factory session route."]}),o?(0,S.jsxs)(S.Fragment,{children:["Your Mission orchestrator default is ",(0,S.jsx)("code",{children:o}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Mission orchestrator"})," when mission planning should use a specific route."]}),a?(0,S.jsxs)(S.Fragment,{children:["Your Mission worker default is ",(0,S.jsx)("code",{children:a}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Mission worker"})," when implementation workers should use a specific route."]}),i?(0,S.jsxs)(S.Fragment,{children:["Your Mission validator default is ",(0,S.jsx)("code",{children:i}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Mission validator"})," when validation workers should use a specific route."]}),(0,S.jsxs)(S.Fragment,{children:["Set ",(0,S.jsx)("span",{className:"font-medium",children:"Reasoning effort"})," only when you want LLM Router to write ",(0,S.jsx)("code",{children:"reasoningEffort"}),"; leave it unset to keep Factory Droid defaults."]})]},{title:"How it works",items:[(0,S.jsxs)(S.Fragment,{children:["LLM Router adds router-managed ",(0,S.jsx)("code",{children:"customModels"})," entries with ",(0,S.jsx)("code",{children:'provider: "openai"'})," or ",(0,S.jsx)("code",{children:'provider: "anthropic"'}),", plus the matching gateway base URL for that request format."]}),(0,S.jsxs)(S.Fragment,{children:["Each injected entry has a ",(0,S.jsx)("code",{children:"_llmRouterManaged"})," marker so it can be cleanly updated or removed without touching your other custom models."]}),(0,S.jsxs)(S.Fragment,{children:["The router-managed bindings map to both the legacy root ",(0,S.jsx)("code",{children:"model"})," field and current Factory settings such as ",(0,S.jsx)("code",{children:"sessionDefaultSettings.model"}),", ",(0,S.jsx)("code",{children:"missionOrchestratorModel"}),", and ",(0,S.jsx)("code",{children:"missionModelSettings"}),"."]}),(0,S.jsx)(S.Fragment,{children:"Disconnecting removes only the router-managed entries and restores any backed-up session, Mission, or reasoning settings."})]},{title:"Where these settings land",items:[s?(0,S.jsxs)(S.Fragment,{children:["This page is managing ",(0,S.jsx)("code",{children:s}),"."]}):(0,S.jsxs)(S.Fragment,{children:["Factory Droid stores user settings in ",(0,S.jsx)("code",{children:"~/.factory/settings.json"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The normal-session binding maps to ",(0,S.jsx)("code",{children:"sessionDefaultSettings.model"})," and the legacy root ",(0,S.jsx)("code",{children:"model"})," field."]}),(0,S.jsxs)(S.Fragment,{children:["The Mission orchestrator binding maps to ",(0,S.jsx)("code",{children:"missionOrchestratorModel"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The Mission worker binding maps to ",(0,S.jsx)("code",{children:"missionModelSettings.workerModel"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["The Mission validator binding maps to ",(0,S.jsx)("code",{children:"missionModelSettings.validationWorkerModel"}),"."]}),(0,S.jsxs)(S.Fragment,{children:["Use ",(0,S.jsx)("span",{className:"font-medium",children:"Open Config File"})," to inspect the generated settings."]})]},{title:"Quick verify",items:[(0,S.jsxs)(S.Fragment,{children:["Open the settings file from this page and confirm the ",(0,S.jsx)("code",{children:"customModels"})," array contains the LLM Router entry."]}),(0,S.jsxs)(S.Fragment,{children:["Launch Factory Droid and run a small prompt. Use ",(0,S.jsx)("code",{children:"/model"})," to confirm the routed model is available."]}),(0,S.jsxs)(S.Fragment,{children:["If requests fail, check the ",(0,S.jsx)("span",{className:"font-medium",children:"Alias & Fallback"})," tab first to ensure the alias behind your model exists."]})]}]}}function w5(e="outline"){switch(e){case"success":return"border-emerald-200 bg-emerald-50";case"warning":return"border-amber-200 bg-amber-50";case"danger":return"border-rose-200 bg-rose-50";case"info":return"border-sky-200 bg-sky-50";default:return"border-border/70 bg-background/70"}}function sT(e="outline"){switch(e){case"success":return"text-emerald-950";case"warning":return"text-amber-950";case"danger":return"text-rose-950";case"info":return"text-sky-950";default:return"text-foreground"}}function A5({guideContent:e}){let[t,n]=(0,Su.useState)(!1),r=String(e?.title||"").trim()||"Guide",o=String(e?.description||"").trim(),a=Array.isArray(e?.badges)?e.badges.filter(Boolean):[],i=Array.isArray(e?.highlights)?e.highlights.filter(Boolean):[],l=Array.isArray(e?.sections)?e.sections.filter(Boolean):[],s=e?.callout&&e.callout.body?e.callout:null,c=s?.variant||"outline";return i.length===0&&l.length===0&&!s?null:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)($,{type:"button",size:"sm",variant:"outline","aria-label":r,onClick:()=>n(!0),children:"Guide"}),(0,S.jsx)(Zn,{open:t,onClose:()=>n(!1),title:r,description:o,contentClassName:"max-h-[92vh] max-w-4xl rounded-2xl border border-border/70 bg-background/98 shadow-[0_32px_120px_rgba(15,23,42,0.48)]",bodyClassName:"max-h-[calc(92vh-5.5rem)]",children:(0,S.jsxs)("div",{className:"space-y-4",children:[a.length>0?(0,S.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:a.map((d,u)=>(0,S.jsx)(ut,{variant:d?.variant||"outline",children:d?.label},`${r}-badge-${u}`))}):null,s?(0,S.jsxs)("div",{className:F("rounded-2xl border p-4",w5(c)),children:[(0,S.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,S.jsx)(ut,{variant:["success","warning","danger","info"].includes(c)?c:"outline",children:c==="success"?"Current best fit":c==="warning"?"Needs attention":c==="info"?"Current behavior":"Guide note"}),(0,S.jsx)("div",{className:F("text-sm font-medium",sT(c)),children:s.title})]}),(0,S.jsx)("div",{className:F("mt-3 text-sm leading-6",sT(c)),children:s.body})]}):null,i.length>0?(0,S.jsx)("div",{className:F("grid gap-4",i.length>2?"md:grid-cols-3":"md:grid-cols-2"),children:i.map((d,u)=>(0,S.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[d?.eyebrow?(0,S.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:d.eyebrow}):null,(0,S.jsx)("div",{className:"mt-2 text-sm font-medium text-foreground",children:d?.title}),(0,S.jsx)("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:d?.body})]},`${r}-highlight-${u}`))}):null,l.map((d,u)=>{let f=Array.isArray(d?.items)?d.items.filter(Boolean):[];return(0,S.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/70 p-4",children:[(0,S.jsx)("div",{className:"text-sm font-medium text-foreground",children:d?.title}),d?.description?(0,S.jsx)("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:d.description}):null,f.length>0?(0,S.jsx)("div",{className:"mt-3 space-y-3",children:f.map((p,v)=>(0,S.jsxs)("div",{className:"flex gap-3 text-sm leading-6 text-foreground",children:[(0,S.jsx)("span",{className:"mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-foreground/50"}),(0,S.jsx)("div",{className:"min-w-0",children:p})]},`${r}-section-${u}-item-${v}`))}):null]},`${r}-section-${u}`)})]})})]})}function C5({field:e,routeOptions:t,disabled:n=!1,onValueChange:r}){let o=String(e?.value||"").trim()||(e?.allowUnset?"__unset__":""),a=(0,Su.useMemo)(()=>{let i=e?.usesRouteOptions===!1?[]:t,l=Array.isArray(e?.options)?e.options:[],s=Array.isArray(e?.extraOptions)?e.extraOptions:[];return e?.allowUnset?[{value:"__unset__",label:"Inherit tool default",hint:""},...s,...l,...i]:[...s,...l,...i]},[e?.allowUnset,e?.extraOptions,e?.options,e?.usesRouteOptions,t]);return(0,S.jsxs)(rn,{value:o,onValueChange:r,disabled:n||a.length===0,children:[(0,S.jsx)(on,{children:(0,S.jsx)(an,{placeholder:e.placeholder||"Select a route"})}),(0,S.jsx)(ln,{children:a.length>0?x5(a,{keyPrefix:e.id||"binding-option"}):(0,S.jsx)(Dt,{value:"__no-route-options",disabled:!0,children:"No routes available"})})]})}function Om({toolName:e,toolState:t,endpointUrl:n,routeOptions:r,connectionBusy:o,bindingBusy:a,onToggleRouting:i,onBindingChange:l,hasMasterKey:s,disabledReason:c,onOpenPrimaryPath:d,onOpenSecondaryPath:u,secondaryPathLabel:f="Backup file",secondaryPathIcon:p=(0,S.jsx)(S5,{className:"h-3 w-3"}),bindingFields:v=[],guideContent:m=null}){let b=t?.routedViaRouter===!0,h=String(t?.error||"").trim(),g=!!(s&&n&&!c&&!h),y=(0,Su.useMemo)(()=>{let w=new Set(["__unset__"]);for(let C of v){for(let E of Array.isArray(C?.extraOptions)?C.extraOptions:[]){let A=String(E?.value||"").trim();A&&w.add(A)}for(let E of Array.isArray(C?.options)?C.options:[]){let A=String(E?.value||"").trim();A&&w.add(A)}}return v.filter(C=>C?.usesRouteOptions!==!1).map(C=>String(C?.value||"").trim()).filter(C=>C&&!w.has(C))},[v]),x=y5(r,y);return(0,S.jsxs)(Gt,{children:[(0,S.jsxs)(Qr,{className:"flex flex-col gap-3 p-4 pb-0 sm:flex-row sm:items-start sm:justify-between",children:[(0,S.jsxs)("div",{className:"space-y-2",children:[(0,S.jsx)(_o,{className:"flex items-center gap-2",children:(0,S.jsx)("span",{children:`Use ${e} via LLM Router`})}),(0,S.jsx)(Em,{primaryLabel:"Config file",primaryValue:t?.configFilePath||t?.settingsFilePath||"",onOpenPrimary:d,secondaryLabel:f,secondaryValue:t?.backupFilePath||"",secondaryIcon:p,onOpenSecondary:u})]}),(0,S.jsxs)("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[m?(0,S.jsx)(A5,{guideContent:m}):null,(0,S.jsx)($,{type:"button",size:"sm",variant:b?"outline":void 0,onClick:i,disabled:o!==""||!b&&!g,children:o==="enable"?"Connecting\u2026":o==="disable"?"Disconnecting\u2026":b?"Disconnect":"Connect"})]})]}),(0,S.jsxs)(qt,{className:"space-y-4 p-4",children:[h?(0,S.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:h}):null,!b&&!s?(0,S.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:["Set ",(0,S.jsx)("code",{children:"masterKey"})," first to connect ",e,"."]}):null,c?(0,S.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:c}):null,(0,S.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/60 p-4",children:[(0,S.jsx)("div",{children:(0,S.jsxs)("div",{children:[(0,S.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Model bindings"}),(0,S.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:"Prefer LLM Router aliases here so you can retarget models later from the Alias & Fallback tab."})]})}),v.length===0?(0,S.jsx)("div",{className:"mt-4 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:"No tool bindings are available yet."}):(0,S.jsx)("div",{className:"mt-4 grid gap-3",children:v.map(w=>(0,S.jsxs)("div",{className:"rounded-xl border border-border/70 bg-background/80 p-3",children:[(0,S.jsxs)("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[(0,S.jsx)("div",{className:"text-sm font-medium text-foreground",children:w.label}),(0,S.jsx)(ut,{variant:"outline",children:w.envKey})]}),(0,S.jsx)("div",{className:"mb-3 text-xs leading-5 text-muted-foreground",children:w.description}),(0,S.jsx)(C5,{field:w,routeOptions:x,disabled:w.standaloneWhenDisconnected?a:!b||a,onValueChange:C=>l(w.id,C==="__unset__"?"":C)})]},w.id))})]})]})]})}var At=_(Z(),1);function fT({logs:e,activityLogEnabled:t=!0,activityFilter:n="usage",busyAction:r="",onActivityFilterChange:o,onToggleEnabled:a,onClear:i}){let l=Array.isArray(e)?e:[],s=l.filter(d=>n==="all"?!0:Wh(d)===n),c=qc[n]||qc.usage;return(0,At.jsxs)(Gt,{children:[(0,At.jsx)(Qr,{children:(0,At.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,At.jsxs)("div",{className:"space-y-1",children:[(0,At.jsx)(_o,{children:"Activity"}),(0,At.jsx)(li,{children:t?"Router actions, request fallbacks, and runtime issues stream here.":"Activity logging is paused. Re-enable it to capture router actions, request fallbacks, and runtime issues."})]}),(0,At.jsxs)("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[(0,At.jsx)("div",{className:"min-w-[13rem]",children:(0,At.jsxs)(rn,{value:n,onValueChange:o,searchEnabled:!1,children:[(0,At.jsx)(on,{children:(0,At.jsx)(an,{placeholder:"Filter category"})}),(0,At.jsx)(ln,{children:kA.map(d=>(0,At.jsx)(Dt,{value:d.value,children:d.label},d.value))})]})}),(0,At.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:i,disabled:r!==""||!e?.length,children:r==="clear"?"Clearing\u2026":"Clear log"}),(0,At.jsx)($,{type:"button",size:"sm",variant:t?"outline":"default",onClick:a,disabled:r!=="",children:r==="toggle"?"Updating\u2026":t?"Disable log":"Enable log"})]})]})}),(0,At.jsx)(qt,{children:(0,At.jsx)("div",{className:"max-h-[32rem] space-y-3 overflow-auto pr-1",children:s.length?s.map(d=>{let u=Wh(d),f=qc[u]||qc.usage;return(0,At.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,At.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,At.jsxs)("div",{className:"flex items-center gap-2",children:[(0,At.jsx)("span",{className:F("inline-flex h-2.5 w-2.5 rounded-full ring-4",Hh[d.level]||Hh.info)}),(0,At.jsx)(ut,{variant:f.badgeVariant,children:f.label}),(0,At.jsx)("span",{className:"text-sm font-medium text-foreground",children:d.message})]}),(0,At.jsx)("span",{className:"text-xs text-muted-foreground",children:As(d.time)})]}),d.detail?(0,At.jsx)("div",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:d.detail}):null]},d.id)}):l.length?(0,At.jsxs)("div",{className:"rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground",children:["No ",c.emptyLabel," activity matches the current filter. Switch the dropdown to inspect the hidden categories."]}):(0,At.jsx)("div",{className:"rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground",children:"Activity is quiet. Save config changes or start the router to populate this stream."})})})]})}var Et=_(me(),1);var ov=_(me(),1);var dn=_(Z(),1);function mT({rows:e,onChange:t}){let n=Bf(e),r=n.length>0?n:[{name:"",value:""}];function o(l,s,c){s==="name"&&rC(r,c,l)||t(r.map((d,u)=>u===l?{...d,[s]:c}:d))}function a(){t([...r,{name:"",value:""}])}function i(l){let s=r.filter((c,d)=>d!==l);t(s.length>0?s:[{name:"",value:""}])}return(0,dn.jsxs)("div",{className:"space-y-2",children:[r.map((l,s)=>(0,dn.jsxs)("div",{className:"grid gap-2 md:grid-cols-[minmax(0,0.9fr)_minmax(0,1.3fr)_auto]",children:[(0,dn.jsx)(wt,{value:l.name,onChange:c=>o(s,"name",c.target.value),placeholder:s===0?"User-Agent":"Header name"}),(0,dn.jsx)(wt,{value:l.value,onChange:c=>o(s,"value",c.target.value),placeholder:s===0?eo:"Header value"}),(0,dn.jsx)($,{type:"button",variant:"ghost",onClick:()=>i(s),children:"Remove"})]},`header-row-${s}`)),(0,dn.jsxs)("div",{className:"flex items-center justify-between gap-3 text-xs text-muted-foreground",children:[(0,dn.jsx)("span",{children:"User-Agent is included by default. Add more only when a provider needs them."}),(0,dn.jsx)($,{type:"button",variant:"outline",onClick:a,children:"Add custom header"})]})]})}function pT({providerId:e,values:t,onChange:n}){let r=(t||[]).map(u=>String(u||"").trim()).filter(Boolean),o=zs(r),a=(0,ov.useRef)(""),i=(0,ov.useRef)(null);function l(u){n((t||[]).filter(f=>f!==u))}function s(u,f){if(!u||!f||u===f)return;let p=[...t||[]],v=p.indexOf(u),m=p.indexOf(f);if(v===-1||m===-1)return;let[b]=p.splice(v,1);p.splice(m,0,b),n(p)}function c(u){n(xs(t||[],u,f=>String(f||"").trim()))}function d(){a.current="",va(i.current,!1),i.current=null}return(0,dn.jsxs)("div",{className:"space-y-2",children:[(0,dn.jsx)("div",{className:"space-y-2 rounded-xl border border-input bg-background/80 px-3 py-3",children:r.length>0?r.map((u,f)=>(0,dn.jsxs)("div",{ref:o(u),"data-reorder-row":"true",onDragOver:p=>{a.current&&a.current!==u&&(p.preventDefault(),p.dataTransfer.dropEffect="move")},onDrop:p=>{p.preventDefault();let v=p.dataTransfer.getData("text/plain")||a.current;d(),s(v,u)},className:F("grid grid-cols-[auto_auto_minmax(0,1fr)_auto] items-center gap-2 rounded-xl border border-border/70 bg-card/90 p-3"),children:[(0,dn.jsx)("span",{className:"flex h-8 w-8 cursor-grab items-center justify-center rounded-full text-muted-foreground",draggable:!0,onDragStart:p=>{let v=Ss(p.currentTarget);p.dataTransfer.effectAllowed="move",p.dataTransfer.setData("text/plain",u),v&&typeof p.dataTransfer?.setDragImage=="function"&&p.dataTransfer.setDragImage(v,20,20),d(),a.current=u,i.current=v,va(v,!0)},onDragEnd:d,title:"Drag to reorder",children:(0,dn.jsx)(vs,{className:"h-4 w-4"})}),(0,dn.jsx)(Sa,{disabled:f===0,label:f===0?"Already first":`Move ${e}/${u} up`,onClick:()=>c(u)}),(0,dn.jsxs)("span",{className:"truncate text-sm font-medium text-foreground",children:[e,"/",u]}),(0,dn.jsx)("button",{className:"text-muted-foreground transition hover:text-foreground",type:"button",onMouseDown:p=>p.preventDefault(),onClick:()=>l(u),children:"\xD7"})]},u)):(0,dn.jsxs)("span",{className:"block px-1 text-xs text-muted-foreground",children:["Leave it empty for now, or add models to back the fixed ",(0,dn.jsx)("code",{children:"default"})," route. An empty default route returns 500 until you add a working model."]})}),(0,dn.jsx)("div",{className:"text-xs text-muted-foreground",children:"Drag rows to change the preferred order, use the arrow to move a model earlier, or remove any models you do not want in this route."})]})}var k=_(Z(),1);function av({baseConfig:e,onApplyDraft:t,onValidateDraft:n,onSaveDraft:r,onSaveAndStart:o,seedMode:a="blank",mode:i="add",targetProviderId:l="",defaultProviderUserAgent:s=eo,framed:c=!0,showHeader:d=!0}){let[u,f]=(0,Et.useState)(0),[p,v]=(0,Et.useState)(""),[m,b]=(0,Et.useState)(()=>vC(e,{seedMode:a,targetProviderId:l,defaultProviderUserAgent:s})),[h,g]=(0,Et.useState)(null),[y,x]=(0,Et.useState)(""),[w,C]=(0,Et.useState)({}),[E,A]=(0,Et.useState)(!1),[M,L]=(0,Et.useState)(null),[P,D]=(0,Et.useState)(""),[G,ae]=(0,Et.useState)(!1),[ge,j]=(0,Et.useState)(""),J=(0,Et.useRef)(!0),Q=(0,Et.useRef)(""),H=(0,Et.useRef)(Math.random().toString(36).slice(2,10)),B=i==="edit",ft=!B&&a==="blank"&&Vf(e),X=`llr-qs-endpoint-${H.current}`,je=`llr-qs-endpoint-input-${H.current}`,ie=`llr-qs-credential-${H.current}`,xe=`llr-qs-credential-input-${H.current}`,Ie=[{title:"Provider",detail:"Choose API Key or OAuth first, then enter the provider details needed for that connection type."},{title:"Models",detail:"Add model ids, then configure one or more rate limits for all models or selected models. API Key providers are tested before continue."},{title:"Default",detail:"Order the models behind the fixed `default` route before you finish."}],I=Yn(m.modelIds,m.modelDraft),ue=jf(m.aliasModelIds,I),he=m.connectionType==="api"?Yn(m.endpoints,m.endpointDraft):[],_e=(0,Et.useMemo)(()=>({...m,endpoints:he,modelIds:I,aliasModelIds:ue,rateLimitRows:gr(m.rateLimitRows)}),[m,he,I,ue]),Ee=(0,Et.useMemo)(()=>Uf(m.headerRows||[]),[m.headerRows]),ve=String(m.apiKeyEnv||"").trim(),Fe=(0,Et.useMemo)(()=>Jh(_e),[_e]),Je=M?.signature===Fe?M.result:null,Ht=Je?.models?.length>0?Je.models:ny(m.selectedConnection||"custom"),wn=Lr(m.providerId||m.providerName||"my-provider")||"my-provider",fn=ry(m),Ft=JSON.stringify({connectionType:m.connectionType,selectedConnection:m.selectedConnection,subscriptionProfile:fn}),Yt=I.filter(V=>w[V]==="error"),st=I.filter(V=>w[V]==="success"),Ve=I.some(V=>w[V]==="success"||w[V]==="error"),Vn=I.length>0&&I.every(V=>w[V]==="success"),mn=st.length>0,er=Yt.length>0,Ra=I.some(V=>!w[V]||w[V]==="default"),Te=h?.signature===Fe?h.result:null,Ze=m.connectionType!=="api"||mn,Ce=(0,Et.useMemo)(()=>bC(e,_e,Te,{targetProviderId:l}),[e,_e,Te,l]),Ge=(0,Et.useMemo)(()=>`${JSON.stringify(Ce,null,2)}
52
52
  `,[Ce]),ao=St,pn=Ie[u],It=xC(u,_e,e,{targetProviderId:l});(0,Et.useEffect)(()=>{tC()},[]),(0,Et.useEffect)(()=>{let V=Q.current!==""&&Q.current!==Fe;if(Q.current=Fe,V&&m.connectionType==="api"&&(C({}),g(null),x(""),J.current=!0,A(!1)),m.connectionType!=="api"){h!==null&&g(null),y&&x(""),Object.keys(w).length>0&&C({}),M!==null&&L(null),P&&D("");return}M?.signature&&M.signature!==Fe&&(L(null),D(""))},[m.connectionType,Fe,h,y,w,M,P]);function N(V,Ue){b(Ke=>({...Ke,[V]:Ue}))}function se(V){b(Ue=>{let Ke=Lr(Ue.providerName||""),mt=Lr(V||"")||"my-provider",gn=!Ue.providerId||Ue.providerId===Ke;return{...Ue,providerName:V,providerId:gn?mt:Ue.providerId}})}function W(V){x(""),g(null),C({}),L(null),D(""),J.current=!0,A(!1),ce(V,V==="api"?"custom":"oauth-gpt")}function Re(V){x(""),g(null),C({}),L(null),D(""),J.current=!0,A(!1);let Ue=kr(V);ce(Ue.category,V)}function ce(V,Ue){b(Ke=>yC(Ke,{baseConfig:e,nextCategory:V,nextPresetKey:Ue,defaultProviderUserAgent:s}))}async function q({force:V=!1,silent:Ue=!1}={}){if(m.connectionType!=="api")return!1;if(he.length===0||!ve)return Ue||D("Add endpoints and an API key or env before checking the model list API."),!1;if(!V&&M?.signature===Fe)return!!(M?.result?.models||[]).length;ae(!0),Ue||D("");try{let Ke=await Lt("/api/config/discover-provider-models",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({endpoints:he,...go(ve)?{apiKeyEnv:ve}:{apiKey:ve},...Object.keys(Ee).length>0?{headers:Ee}:{}})}),mt=(Ke.result?.models||[]).map(Tt=>String(Tt||"").trim()).filter(Boolean),gn={};if(mt.length>0){let Tt=m.selectedConnection;if(Tt&&Jc.set(Tt,mt),ty(he)){let Dn=await GC(he[0]||"",ve,mt.filter(Qt=>!Qt.includes("embed")&&!Qt.includes("tts")&&!Qt.includes("image")&&!Qt.includes("lyria")&&!Qt.includes("veo")));Dn&&(mt=Dn)}try{let Dn=await su(mt);gn=$C(Dn)}catch{gn={}}}let br={...Ke.result&&typeof Ke.result=="object"?Ke.result:{},modelContextWindows:gn};if(L({signature:Fe,result:br}),mt.length>0)return b(Tt=>{if(Jh(Tt)!==Fe||Tt.connectionType!=="api")return Tt;let sn=Array.isArray(Tt.modelIds)?Tt.modelIds:[],Dn=V&&sn.length>0?Array.from(new Set([...sn,...mt])):sn.length>0?sn:mt,Qt={...Tt.modelContextWindows&&typeof Tt.modelContextWindows=="object"?Tt.modelContextWindows:{},...gn},tr=ty(Tt.endpoints),xr=tr?gC(tr,Dn):null;return JSON.stringify(Dn)===JSON.stringify(sn)&&JSON.stringify(Qt)===JSON.stringify(Tt.modelContextWindows||{})&&!xr?Tt:{...Tt,modelIds:Dn,modelContextWindows:Qt,...xr?{rateLimitRows:xr}:{}}}),D(""),!0;let Ai=(Ke.result?.warnings||[]).join(" ")||"Model list API did not return any models. Add model ids manually if needed.";return D(Ai),!1}catch(Ke){let mt=Ke instanceof Error?Ke.message:String(Ke);return D(mt),!1}finally{ae(!1)}}async function be({onlyModels:V=null}={}){if(m.connectionType!=="api")return!0;let Ue=V||I;v("test"),x(""),C(Ke=>{let mt={...Ke};for(let gn of Ue)mt[gn]="pending";return mt});try{let Ke=await $f("/api/config/test-provider-stream",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({endpoints:he,models:Ue,...go(ve)?{apiKeyEnv:ve}:{apiKey:ve},...Object.keys(Ee).length>0?{headers:Ee}:{}})},{onMessage:sn=>{if(sn?.type!=="progress")return;let Dn=sn.event||{};Dn.phase==="model-done"&&C(Qt=>({...Qt,[Dn.model]:Dn.confirmed?"success":"error"}))}}),mt=new Set(Ke?.models||[]),gn=h?.signature===Fe?h.result:null,br=new Set(gn?.models||[]);for(let sn of Ue)mt.has(sn)?br.add(sn):br.delete(sn);let Ai={...gn||{},...Ke,models:Array.from(br),workingFormats:Array.from(new Set([...gn?.workingFormats||[],...Ke?.workingFormats||[]])),ok:I.every(sn=>br.has(sn))};g({signature:Fe,result:Ai}),C(sn=>{let Dn={...sn};for(let Qt of Ue)Dn[Qt]=mt.has(Qt)?"success":"error";return Dn});let Tt=Ue.filter(sn=>!mt.has(sn));return Tt.length>0?(x((Ke?.warnings||[]).join(" ")||`${Tt.length} model(s) failed the provider test.`),!1):!0}catch(Ke){return C(mt=>{let gn={...mt};for(let br of Ue)(!gn[br]||gn[br]==="pending")&&(gn[br]="error");return gn}),x(Ke instanceof Error?Ke.message:String(Ke)),!1}finally{v("")}}(0,Et.useEffect)(()=>{u!==1||m.connectionType!=="api"||I.length>0||!ve||he.length===0||G||M?.signature===Fe||q({silent:!0})},[u,m.connectionType,I.length,ve,he.length,G,M,Fe]);async function Be({force:V=!1}={}){if(m.connectionType==="api"||!V&&ge===Ft)return!0;let Ue=kr(m.selectedConnection||"oauth-gpt");v("oauth-login"),x("");try{return await Lt("/api/subscription/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({profileId:fn,providerId:wn,subscriptionType:Ue.subscriptionType||"chatgpt-codex"})}),j(Ft),!0}catch(Ke){return x(Ke instanceof Error?Ke.message:String(Ke)),!1}finally{v("")}}async function Se(){u===0&&m.connectionType==="subscription"&&!await Be()||(u===1&&A(!0),f(V=>Math.min(V+1,Ie.length-1)))}async function Le(){let V=I.filter(mt=>w[mt]!=="success"),Ue=J.current;J.current=!1,await be({onlyModels:V.length<I.length?V:null})&&Ue&&!E&&(A(!0),f(mt=>Math.min(mt+1,Ie.length-1)))}async function et(){let V=I.filter(Ue=>w[Ue]==="error");V.length!==0&&await be({onlyModels:V})}function we(){let V=I.filter(Ue=>w[Ue]==="error");b(Ue=>({...Ue,modelIds:(Ue.modelIds||[]).filter(Ke=>!V.includes(Ke))})),C(Ue=>{let Ke={...Ue};for(let mt of V)delete Ke[mt];return Ke}),x(""),A(!0),f(Ue=>Math.min(Ue+1,Ie.length-1))}async function ot(V){if((V==="save"||V==="save-start")&&m.connectionType==="api"&&!Ze){x("Finish is available after the provider test succeeds.");return}v(V);try{if(V==="apply"){await t(Ge);return}if(V==="validate"){await n(Ge);return}if(V==="save"){await r(Ge);return}V==="save-start"&&await o(Ge)}finally{v("")}}let Ln=y||It||(u===0&&m.connectionType==="subscription"&&ge!==Ft?"Continue opens the browser sign-in flow for this provider.":u===1&&m.connectionType==="api"&&!Ve?"Test the provider against the entered endpoints and model ids using your API key or env.":u===1&&m.connectionType==="api"&&er&&!Vn?`${st.length} of ${I.length} model(s) confirmed. Fix or skip failed model(s) to continue.`:Ie[u].detail),Ea=m.selectedConnection==="oauth-claude"?"Examples: claude-opus-4-6 claude-sonnet-4-6 claude-haiku-4-5":m.selectedConnection==="oauth-gpt"?"Examples: gpt-5.3-codex gpt-5.2-codex gpt-5.1-codex-mini":(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)("span",{children:["Examples: gpt-4o-mini gpt-4.1-mini",Object.keys(Je?.modelContextWindows||{}).length>0?` \xB7 ${Object.keys(Je?.modelContextWindows||{}).length} context size${Object.keys(Je?.modelContextWindows||{}).length===1?"":"s"} ready`:""]}),(0,k.jsx)("span",{className:"ml-2 text-amber-700",children:"Auto-discovered model ids may be incomplete or inaccurate if the provider is misconfigured. Verify the list and add or remove model ids yourself."})]}),So=B?"Edit provider":ft?"Add provider":"Quick start wizard",Au=B?"Update this provider in place. Change endpoints, model ids, rate limits, alias, or provider id, then save the refreshed config.":ft?"Add another provider with endpoints, model ids, rate limits, and a stable alias. API Key providers are auto-tested before save.":"",Cu=(0,k.jsx)("div",{className:"flex items-center gap-1",children:Ie.map((V,Ue)=>{let Ke=Ue===u,mt=Ue<u;return(0,k.jsxs)(Et.Fragment,{children:[Ue>0?(0,k.jsx)("span",{className:"text-[10px] text-muted-foreground/40 select-none",children:"/"}):null,(0,k.jsxs)("button",{type:"button",disabled:!mt,onClick:()=>{mt&&f(Ue)},className:F("inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium transition-colors",Ke?"bg-primary text-primary-foreground":mt?"text-emerald-700 hover:bg-emerald-50":"text-muted-foreground/50"),children:[(0,k.jsx)("span",{className:F("inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-[10px] font-bold leading-none",Ke?"bg-primary-foreground/20":mt?"bg-emerald-100 text-emerald-700":"bg-muted"),children:Ue+1}),V.title]})]},V.title)})}),Ru=(0,k.jsxs)("div",{className:"space-y-5",children:[u===0?(0,k.jsxs)("div",{className:"space-y-4",children:[(0,k.jsx)("div",{className:"grid gap-3 md:grid-cols-2",children:PA.map(V=>(0,k.jsxs)("button",{type:"button",className:F("rounded-2xl border px-4 py-3 text-left transition",m.connectionType===V.value?"border-ring bg-background shadow-sm":"border-border/70 bg-background/70 hover:border-border"),onClick:()=>W(V.value),children:[(0,k.jsx)("div",{className:"text-sm font-medium text-foreground",children:V.label}),(0,k.jsx)("div",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:V.description})]},V.value))}),(0,k.jsx)(pt,{label:"Provider preset",children:(0,k.jsxs)(rn,{value:m.selectedConnection||(m.connectionType==="api"?"custom":"oauth-gpt"),onValueChange:Re,children:[(0,k.jsx)(on,{children:(0,k.jsx)(an,{})}),(0,k.jsx)(ln,{children:eC(m.connectionType==="subscription"?"subscription":"api").map(V=>(0,k.jsxs)(Dt,{value:V.key,children:[V.label,(0,k.jsx)("span",{className:"ml-2 text-muted-foreground",children:V.description})]},V.key))})]})}),(0,k.jsxs)("div",{className:"grid gap-3 md:grid-cols-2",children:[(0,k.jsx)(pt,{label:"Provider name",children:(0,k.jsx)(wt,{value:m.providerName,onChange:V=>se(V.target.value),placeholder:kr(m.selectedConnection||"custom").providerName})}),(0,k.jsx)(pt,{label:"Provider id",hint:"lowercase-hyphenated",children:(0,k.jsx)(wt,{value:m.providerId,onChange:V=>N("providerId",V.target.value),onBlur:()=>N("providerId",Lr(m.providerId||m.providerName||"my-provider")||"my-provider"),placeholder:kr(m.selectedConnection||"custom").providerId})})]}),m.connectionType==="api"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(pt,{label:"Endpoints",hint:"comma, space, or newline turns into chips",children:(0,k.jsx)(bu,{values:m.endpoints,onChange:V=>N("endpoints",V),draftValue:m.endpointDraft,onDraftValueChange:V=>N("endpointDraft",V),commitOnBlur:!0,isValueValid:fi,placeholder:"Example: https://api.openai.com/v1",helperText:"Paste one or more endpoints",inputProps:{id:je,name:X,autoComplete:"off",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,inputMode:"url","data-form-type":"other"}})}),(0,k.jsx)(pt,{label:"API key or env",children:(0,k.jsx)(Is,{value:m.apiKeyEnv,onChange:V=>N("apiKeyEnv",V.target.value),placeholder:"Example: OPENAI_API_KEY or sk-...",isEnvVar:go(m.apiKeyEnv),maskMode:"obscured-text",inputProps:{id:xe,name:ie,autoComplete:"new-password",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,"data-form-type":"other","data-lpignore":"true","data-1p-ignore":"true"}})}),(0,k.jsx)(pt,{label:"Custom headers",hint:"User-Agent included by default",children:(0,k.jsx)(mT,{rows:m.headerRows,onChange:V=>N("headerRows",V)})})]}):(0,k.jsxs)("div",{className:"space-y-3",children:[(0,k.jsx)("div",{className:"rounded-2xl border border-border/70 bg-secondary/45 px-4 py-3 text-sm leading-6 text-muted-foreground",children:m.selectedConnection==="oauth-claude"?"Continue opens the Claude sign-in page in your browser and stores the login for this provider automatically.":"Continue opens the ChatGPT sign-in page in your browser and stores the login for this provider automatically."}),m.selectedConnection==="oauth-claude"?(0,k.jsxs)("div",{className:"rounded-2xl border border-amber-300/60 bg-amber-50/80 px-4 py-3 text-xs leading-5 text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/40 dark:text-amber-300",children:[(0,k.jsx)("span",{className:"font-medium",children:"Heads up:"})," Claude Code OAuth routes through Anthropic's API with your subscription credentials. Usage will count against your Claude Max/Pro plan's extra usage quota, not the included subscription messages. Make sure you have extra usage enabled on your Claude plan to avoid request failures."]}):(0,k.jsxs)("div",{className:"rounded-2xl border border-amber-300/60 bg-amber-50/80 px-4 py-3 text-xs leading-5 text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/40 dark:text-amber-300",children:[(0,k.jsx)("span",{className:"font-medium",children:"Heads up:"})," ChatGPT subscriptions (Plus / Pro / Team) are separate from the OpenAI API and are intended for use within OpenAI's own apps. Routing requests through your subscription here may violate OpenAI's terms of service and could result in account restrictions."]})]})]}):null,u===1?(0,k.jsxs)("div",{className:"space-y-4",children:[(0,k.jsx)(pt,{label:"Models",hint:"comma, space, or newline turns into chips",children:(0,k.jsx)(bu,{values:m.modelIds,onChange:V=>N("modelIds",V),draftValue:m.modelDraft,onDraftValueChange:V=>N("modelDraft",V),commitOnBlur:!0,disabled:p==="test",valueStates:m.connectionType==="api"?w:{},placeholder:"Paste model ids",helperText:Ea,suggestedValues:Ht})}),m.connectionType==="api"&&G?(0,k.jsxs)("div",{className:"rounded-2xl border border-sky-200 bg-sky-50 px-4 py-3 text-sm text-sky-900",children:[(0,k.jsxs)("div",{className:"flex items-center gap-2 font-medium",children:[(0,k.jsx)(Dr,{}),"Loading provider models"]}),(0,k.jsx)("div",{className:"mt-1 text-xs leading-5 text-sky-800/90",children:"LLM Router is checking the provider model list and matching context sizes for the discovered models."})]}):null,m.connectionType==="api"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(pt,{label:"Rate limit",stacked:!0,headerAction:(0,k.jsx)($,{type:"button",size:"sm",variant:"outline",onClick:()=>N("rateLimitRows",Tm(m.rateLimitRows)),disabled:p==="test",children:"Add rate limit"}),children:(0,k.jsx)(Mm,{rows:m.rateLimitRows,onChange:V=>N("rateLimitRows",V),availableModelIds:I,disabled:p==="test"})}),(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3 text-sm leading-6 text-muted-foreground",children:["The first model becomes the primary direct route. Add caps for ",(0,k.jsx)("code",{children:"all"})," models or target individual model ids when you need a narrower quota bucket."]})]}):null,m.connectionType==="api"?(0,k.jsxs)("div",{className:F("rounded-2xl border px-4 py-3 text-sm leading-6",Vn&&Ve?"border-emerald-200 bg-emerald-50 text-emerald-900":er?"border-amber-200 bg-amber-50 text-amber-900":mn?"border-emerald-200 bg-emerald-50 text-emerald-900":"border-border/70 bg-background/80 text-muted-foreground"),children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em]",children:"Provider test"}),(0,k.jsx)("div",{className:"mt-2",children:Vn&&Ve?`Confirmed ${st.length} model(s) across ${(Te?.workingFormats||[]).join(", ")||"detected formats"}.`:er?`${st.length} of ${I.length} model(s) confirmed. ${Yt.length} failed: ${Yt.join(", ")}.`:mn?`Confirmed ${st.length} of ${I.length} model(s) across ${(Te?.workingFormats||[]).join(", ")||"detected formats"}.`:"Test the provider before continuing so the wizard can auto-detect the working endpoint format(s)."})]}):null]}):null,u===2?(0,k.jsxs)("div",{className:"space-y-4",children:[(0,k.jsx)("div",{className:"grid gap-3 md:grid-cols-2",children:ft||B?(0,k.jsx)(jE,{label:"Use this provider order for the default route",hint:"Updates the fixed `default` alias",checked:m.useAliasAsDefault,onCheckedChange:V=>N("useAliasAsDefault",V)}):(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3 text-sm text-muted-foreground md:col-span-2",children:["The fixed ",(0,k.jsx)("code",{children:"default"})," route is created automatically. Arrange this provider's models in the order you want clients to try first."]})}),(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Model order"}),(0,k.jsx)("div",{className:"mt-3",children:(0,k.jsx)(pT,{providerId:wn,values:ue,onChange:V=>N("aliasModelIds",V)})})]}),(0,k.jsxs)("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:[(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Provider"}),(0,k.jsx)("div",{className:"mt-2 text-sm font-medium text-foreground",children:wn}),(0,k.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:m.providerName})]}),(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Connection"}),(0,k.jsx)("div",{className:"mt-2 text-sm font-medium text-foreground",children:pC(m.selectedConnection||"custom")}),(0,k.jsx)("div",{className:"mt-1 text-xs text-muted-foreground break-all",children:m.connectionType==="api"?`${he.length} endpoint candidate(s)`:"Browser sign-in flow"})]}),(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Models"}),(0,k.jsxs)("div",{className:"mt-2 text-sm font-medium text-foreground",children:[I.length," configured"]}),(0,k.jsx)("div",{className:"mt-1 text-xs text-muted-foreground break-all",children:I.join(", ")||"No models yet"})]}),(0,k.jsxs)("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-4 py-3",children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em] text-muted-foreground",children:"Default route"}),(0,k.jsx)("div",{className:"mt-2 text-sm font-medium text-foreground break-all",children:ao}),(0,k.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:m.useAliasAsDefault?"Requests to `default` and `smart` use this ordered list.":"This provider keeps its direct routes only until you opt it into the fixed default route."})]})]}),m.connectionType==="api"?(0,k.jsxs)("div",{className:F("rounded-2xl border px-4 py-3 text-sm leading-6",Ze?"border-emerald-200 bg-emerald-50 text-emerald-900":"border-amber-200 bg-amber-50 text-amber-900"),children:[(0,k.jsx)("div",{className:"text-xs font-medium uppercase tracking-[0.16em]",children:"Provider test"}),(0,k.jsx)("div",{className:"mt-2",children:Ze?`Using ${(Te?.workingFormats||[]).join(", ")||"detected formats"}. The saved provider keeps the tested endpoint selection and confirmed models.`:"Finish is available after the provider test succeeds."})]}):null]}):null,(0,k.jsxs)("div",{className:"flex flex-col gap-3 border-t border-border/70 pt-4 md:flex-row md:items-start md:justify-between md:gap-4",children:[(0,k.jsx)("div",{className:F("min-w-0 flex-1 text-sm md:max-w-2xl",It||y?"text-amber-700":"text-muted-foreground"),children:Ln}),(0,k.jsxs)("div",{className:"flex shrink-0 flex-wrap items-center gap-2 md:justify-end",children:[u>0?(0,k.jsx)($,{variant:"ghost",onClick:()=>f(V=>Math.max(V-1,0)),children:"Back"}):null,u<Ie.length-1?u===1&&m.connectionType==="api"?E?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)($,{variant:"outline",onClick:()=>{Le()},disabled:!!It||p!=="",children:p==="test"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Dr,{}),"Testing\u2026"]}):"Test"}),(0,k.jsx)($,{onClick:()=>{Se()},disabled:!!It||p!==""||!mn,children:"Continue"})]}):!Ve||Ra?(0,k.jsx)($,{onClick:()=>{Le()},disabled:!!It||p!=="",children:p==="test"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Dr,{}),"Testing provider\u2026"]}):"Test"}):Vn?(0,k.jsx)($,{onClick:()=>{Se()},disabled:!!It||p!=="",children:"Continue"}):er?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)($,{variant:"outline",onClick:()=>{et()},disabled:!!It||p!=="",children:p==="test"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Dr,{}),"Re-testing\u2026"]}):"Test again"}),mn?(0,k.jsx)($,{onClick:()=>{we()},disabled:p!=="",children:"Skip failed model(s) and continue"}):null]}):(0,k.jsx)($,{onClick:()=>{Le()},disabled:!!It||p!=="",children:p==="test"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Dr,{}),"Testing provider\u2026"]}):"Test"}):(0,k.jsx)($,{onClick:()=>{Se()},disabled:!!It||p!=="",children:p==="oauth-login"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Dr,{}),"Signing in\u2026"]}):"Continue"}):(0,k.jsx)($,{onClick:()=>{ot("save-start")},disabled:!!It||p!==""||m.connectionType==="api"&&!Ze,children:p==="save-start"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Dr,{}),"Finishing\u2026"]}):"Finish"})]})]})]});return c?(0,k.jsxs)(Gt,{className:"border-dashed",children:[(0,k.jsxs)(Qr,{children:[(0,k.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[d?(0,k.jsx)(_o,{children:So}):null,Cu]}),d?(0,k.jsx)(li,{children:Au}):null]}),(0,k.jsx)(qt,{className:"space-y-5",children:Ru})]}):(0,k.jsxs)("div",{children:[(0,k.jsx)("div",{className:"-mx-5 -mt-4 flex items-center gap-3 border-b border-border/70 bg-muted/30 px-5 py-2",children:Cu}),(0,k.jsxs)("div",{className:"space-y-5 pt-5",children:[d?(0,k.jsxs)("div",{children:[(0,k.jsx)("div",{className:"text-base font-semibold text-foreground",children:So}),(0,k.jsx)("div",{className:"mt-1 text-sm leading-6 text-muted-foreground",children:Au})]}):null,Ru]})]})}var K=_(Z(),1);async function wu(e){let t=String(e||"");if(!t)return;if(typeof navigator<"u"&&navigator.clipboard?.writeText){await navigator.clipboard.writeText(t);return}if(typeof document>"u")throw new Error("Clipboard is not available in this environment.");let n=document.createElement("textarea");n.value=t,n.setAttribute("readonly",""),n.style.position="absolute",n.style.left="-9999px",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n)}function hT(){let[e,t]=(0,fe.useState)(null),[n,r]=(0,fe.useState)(""),[o,a]=(0,fe.useState)(""),[i,l]=(0,fe.useState)(null),[s,c]=(0,fe.useState)([]),[d,u]=(0,fe.useState)(!0),[f,p]=(0,fe.useState)(!1),[v,m]=(0,fe.useState)(!1),[b,h]=(0,fe.useState)(!1),[g,y]=(0,fe.useState)(""),[x,w]=(0,fe.useState)(""),[C,E]=(0,fe.useState)("model-alias"),[A,M]=(0,fe.useState)(!1),[L,P]=(0,fe.useState)(!1),[D,G]=(0,fe.useState)(0),[ae,ge]=(0,fe.useState)(""),[j,J]=(0,fe.useState)(""),[Q,H]=(0,fe.useState)(""),[B,ft]=(0,fe.useState)(""),[X,je]=(0,fe.useState)(!1),[ie,xe]=(0,fe.useState)(!1),[Ie,I]=(0,fe.useState)(!1),[ue,he]=(0,fe.useState)(""),[_e,Ee]=(0,fe.useState)("usage"),[ve,Fe]=(0,fe.useState)(null),[Je,Ht]=(0,fe.useState)({status:"idle",message:"",savedAt:""}),wn=(0,fe.useRef)(""),fn=(0,fe.useRef)(""),Ft=(0,fe.useRef)(null),Yt=(0,fe.useRef)(null),st=(0,fe.useRef)(null),Ve=(0,fe.useRef)(0),Vn=(0,fe.useRef)(""),mn=(0,fe.useRef)(0);(0,fe.useEffect)(()=>{wn.current=n},[n]),(0,fe.useEffect)(()=>{fn.current=o},[o]),(0,fe.useEffect)(()=>()=>{st.current&&(clearTimeout(st.current),st.current=null)},[]);let er=n!==o,Ra=e?.config?.document,Te=i?.summary||e?.config||{},Ze=i?.validationMessages||e?.config?.validationMessages||[],Ce=(0,fe.useMemo)(()=>Xh(e?.config?.rawText||"{}",e?.config?.document||{}),[e?.config?.rawText,e?.config?.document]),Ge=(0,fe.useMemo)(()=>lC(n,Ce),[n,Ce]),ao=(0,fe.useMemo)(()=>Xh(n,Ce),[n,Ce]),pn=Ge.parseError?Ce:Ge.value,It=(0,fe.useMemo)(()=>Array.isArray(pn?.providers)?pn.providers:[],[pn]),N=(0,fe.useMemo)(()=>pn?.modelAliases&&typeof pn.modelAliases=="object"&&!Array.isArray(pn.modelAliases)?pn.modelAliases:{},[pn]),se=(0,fe.useMemo)(()=>Jy(pn),[pn]),W=Ge.parseError?`Fix the raw JSON parse error first: ${Ge.parseError}`:"",Re=pn,ce=(0,fe.useMemo)(()=>AC(),[]),q=e?.ampClient?.global||{},be=e?.webSearch||e?.ampWebSearch||null,Be=e?.codingTools?.codexCli||{},Se=e?.codingTools?.claudeCode||{},Le=e?.codingTools?.factoryDroid||{},et=q?.routedViaRouter===!0,we=Be?.routedViaRouter===!0,ot=Se?.routedViaRouter===!0,Ln=Le?.routedViaRouter===!0,Ea=e?.ollama||null,So=Ea?.connected===!0,[Au,Cu]=(0,fe.useState)([]),[Ru,V]=(0,fe.useState)({}),[Ue,Ke]=(0,fe.useState)(!1),gn=(e?.activityLog||{enabled:!0})?.enabled!==!1,br=(0,fe.useMemo)(()=>Jy(Re),[Re]),Ai=(0,fe.useMemo)(()=>oy(Re),[Re]),Tt=(0,fe.useMemo)(()=>pi(Qn(Re)),[Re]),sn=(0,fe.useMemo)(()=>kC(Re,be),[Re,be]),Dn=(0,fe.useMemo)(()=>{let R=new Set((Array.isArray(Tt?.providers)?Tt.providers:[]).map(T=>kn(T?.id)).filter(Boolean));return _C(Re,R)},[Re,Tt]),Qt=Ge.parseError?`Fix the raw JSON parse error first: ${Ge.parseError}`:br.length===0?"Add at least one alias or provider/model route before configuring AMP.":"",tr=Ge.parseError?`Fix the raw JSON parse error first: ${Ge.parseError}`:"",xr=Ge.parseError?`Fix the raw JSON parse error first: ${Ge.parseError}`:se.length===0?"Add at least one alias or provider/model route before configuring coding-tool bindings.":"",xT=(0,fe.useMemo)(()=>xi(se,Af(Be?.bindings?.defaultModel)?[]:[Be?.bindings?.defaultModel]),[se,Be?.bindings?.defaultModel]),ST=(0,fe.useMemo)(()=>xi(se,[Se?.bindings?.primaryModel,Se?.bindings?.defaultOpusModel,Se?.bindings?.defaultSonnetModel,Se?.bindings?.defaultHaikuModel,Se?.bindings?.subagentModel]),[se,Se?.bindings?.primaryModel,Se?.bindings?.defaultOpusModel,Se?.bindings?.defaultSonnetModel,Se?.bindings?.defaultHaikuModel,Se?.bindings?.subagentModel]),wT=(0,fe.useMemo)(()=>xi(se,[Le?.bindings?.defaultModel,Le?.bindings?.missionOrchestratorModel,Le?.bindings?.missionWorkerModel,Le?.bindings?.missionValidatorModel]),[se,Le?.bindings?.defaultModel,Le?.bindings?.missionOrchestratorModel,Le?.bindings?.missionWorkerModel,Le?.bindings?.missionValidatorModel]),_m=String(Re?.amp?.defaultRoute||Re?.defaultModel||ou(Re)||"").trim(),Hn=String(Re?.masterKey||e?.config?.document?.masterKey||"").trim(),AT=(0,fe.useMemo)(()=>CC(Hn),[Hn]),km=It.length>0,CT=km&&L,gl=e?.router?.running===!0,iv=e?.startup?.installed===!0,Lm=g==="start"?"Starting\u2026":g==="stop"?"Stopping\u2026":gl?"Stop server":"Start server",Dm=x==="enable"?"Enabling OS startup\u2026":x==="disable"?"Disabling OS startup\u2026":iv?"Disable OS startup":"Enable OS startup",lv=e?.router?.portBusy?e?.router?.portBusyReason||`Port ${8376} is occupied${e?.router?.listenerPids?.length>0?` by PID${e.router.listenerPids.length===1?"":"s"} ${e.router.listenerPids.join(", ")}`:""}.`:String(e?.router?.lastError||"").trim(),RT=!Vf(pn),sv=It.filter(R=>R?.type!=="ollama"),cv=sv.length>0?"existing":"blank",uv=sv[0]?.id||"",dv=e?.defaults?.providerUserAgent||eo;(0,fe.useEffect)(()=>{if(d||f||Ge.parseError)return;if(Hn){Vn.current="";return}let R=String(e?.config?.rawText||o||"__empty__");Vn.current!==R&&(Vn.current=R,OT({showSuccessNotice:!1}))},[o,Hn,d,Ge.parseError,f,e?.config?.rawText]),(0,fe.useEffect)(()=>{if(st.current&&(clearTimeout(st.current),st.current=null),!ve)return;let R=ve.immediate===!0?0:450;return st.current=setTimeout(()=>{st.current=null;let T=ve.sequence;Ht(O=>({...O,status:"saving",message:""})),(async()=>{try{let O=await Lt("/api/amp/apply",{method:"POST",headers:kt,body:JSON.stringify({rawText:ve.rawText,source:"autosave"})});if(T!==Ve.current)return;Ta(O,{preserveDraft:wn.current!==ve.rawText}),Ht({status:"saved",message:"",savedAt:new Date().toISOString()})}catch(O){if(T!==Ve.current)return;let oe=O instanceof Error?O.message:String(O);Ht({status:"error",message:oe,savedAt:""}),U("error",oe)}})()},R),()=>{st.current&&(clearTimeout(st.current),st.current=null)}},[ve]);function ET(){P(!0),G(R=>R+1)}function TT(){ET()}function Im(){P(!1)}(0,fe.useEffect)(()=>{!km&&L&&P(!1)},[km,L]);function U(R,T){mn.current+=1,c(O=>[...O,{id:`notice-${mn.current}`,tone:R,message:T}])}function fv(R){c(T=>T.filter(O=>O.id!==R))}function Ta(R,{preserveDraft:T=!1}={}){t(R);let O=String(R?.config?.rawText||"");if(!T||wn.current===fn.current){r(O),a(O),M(!1),l({rawText:O,summary:R?.config,validationMessages:R?.config?.validationMessages||[]});return}a(O),O!==fn.current&&M(!0)}async function Sr({preserveDraft:R=!1}={}){let T=await Lt("/api/state");Ta(T,{preserveDraft:R})}(0,fe.useEffect)(()=>{let R=!1;function T(){Ft.current&&(Ft.current.close(),Ft.current=null)}function O(){Yt.current&&(clearTimeout(Yt.current),Yt.current=null)}function oe(){R||Yt.current||(Yt.current=setTimeout(()=>{Yt.current=null,ke({isReconnect:!0})},IA))}function ke({isReconnect:qe=!1}={}){if(R)return;O(),T();let Pe=new EventSource("/api/events");Ft.current=Pe,Pe.onopen=()=>{R||Ft.current!==Pe||qe&&Sr({preserveDraft:wn.current!==fn.current}).catch(()=>{})},Pe.addEventListener("state",Ot=>{if(!(R||Ft.current!==Pe))try{let Mt=JSON.parse(Ot.data);Mt?.snapshot&&Ta(Mt.snapshot,{preserveDraft:!0})}catch(Mt){U("error",Mt instanceof Error?Mt.message:String(Mt))}}),Pe.addEventListener("log",Ot=>{if(!(R||Ft.current!==Pe))try{let Mt=JSON.parse(Ot.data);t(ze=>ze&&{...ze,logs:[Mt,...ze.logs||[]].slice(0,150)})}catch{}}),Pe.addEventListener("logs",Ot=>{if(!(R||Ft.current!==Pe))try{let Mt=JSON.parse(Ot.data);t(ze=>ze&&{...ze,...Mt?.activityLog?{activityLog:Mt.activityLog}:{},logs:Array.isArray(Mt?.logs)?Mt.logs:[]})}catch{}}),Pe.onerror=()=>{R||Ft.current!==Pe||(T(),oe())}}return(async()=>{try{await Sr()}catch(qe){R||U("error",qe instanceof Error?qe.message:String(qe))}finally{R||(u(!1),ke())}})(),()=>{R=!0,O(),T()}},[]);async function mv(R,{silent:T=!1}={}){m(!0);try{let O=await Lt("/api/config/validate",{method:"POST",headers:kt,body:JSON.stringify({rawText:R})});return l({rawText:R,summary:O.summary,validationMessages:O.validationMessages||[]}),T||U(sC(O.summary)==="success"?"success":"warning",O.summary.validationSummary),O}catch(O){throw T||U("error",O instanceof Error?O.message:String(O)),O}finally{m(!1)}}async function zm(R,{successMessage:T="Config saved.",showSuccessNotice:O=!0}={}){p(!0);try{let oe=await Lt("/api/config/save",{method:"POST",headers:kt,body:JSON.stringify({rawText:R})});return Ta(oe,{preserveDraft:wn.current!==R}),O&&T&&U("success",T),oe}catch(oe){throw U("error",oe instanceof Error?oe.message:String(oe)),oe}finally{p(!1)}}function Ci(R,{immediate:T=!1}={}){let O=Ve.current+1;Ve.current=O,Fe({sequence:O,rawText:R,immediate:T===!0}),Ht(oe=>({status:"pending",message:"",savedAt:oe.savedAt}))}function zr(R){r(R),l(null)}async function Ko(R,T,O={}){let oe=`${JSON.stringify(R,null,2)}
53
53
  `;zr(oe),M(!1),await zm(oe,{successMessage:T,...O})}async function pv({providerId:R,endpoints:T,newModelIds:O,credentialPayload:oe,headers:ke,onModelTestStateChange:qe}){if(!Array.isArray(O)||O.length===0)return qe?.({phase:"",modelStates:{},failedModelIds:[],message:""}),{ok:!0};let Pe=Object.fromEntries(O.map(ze=>[ze,"pending"])),Ot=({phase:ze="testing",message:In="",failedModelIds:tt=[]}={})=>{qe?.({phase:ze,modelStates:{...Pe},failedModelIds:tt,message:In})},Mt=()=>`Testing ${O.filter(In=>Pe[In]==="success"||Pe[In]==="error").length}/${O.length} new model${O.length===1?"":"s"} for ${R}.`;Ot({phase:"testing",message:Mt()});try{let ze=await $f("/api/config/test-provider-stream",{method:"POST",headers:kt,body:JSON.stringify({endpoints:T,models:O,...oe,...ke&&typeof ke=="object"&&!Array.isArray(ke)?{headers:ke}:{}})},{onMessage:zt=>{if(zt?.type!=="progress")return;let io=zt.event||{};if(io.phase!=="model-done")return;let $o=String(io.model||"").trim();!$o||!Object.prototype.hasOwnProperty.call(Pe,$o)||(Pe[$o]=io.confirmed?"success":"error",Ot({phase:"testing",message:Mt()}))}}),In=new Set(Array.isArray(ze?.models)?ze.models:[]),tt=O.filter(zt=>!In.has(zt));for(let zt of O)Pe[zt]=In.has(zt)?"success":"error";if(!ze?.ok||tt.length>0){let zt=tt.length>0?`New model test failed for ${R}: ${tt.join(", ")}.`:(ze?.warnings||[]).join(" ")||`New model test failed for ${R}.`;return Ot({phase:"",failedModelIds:tt,message:zt}),U("warning",zt),{ok:!1,failedModelIds:tt,result:ze}}return Ot({phase:"saving",message:`Saving ${O.length} confirmed new model${O.length===1?"":"s"} for ${R}.`}),{ok:!0,failedModelIds:[],result:ze}}catch(ze){for(let zt of O)Pe[zt]!=="success"&&(Pe[zt]="error");let In=ze instanceof Error?ze.message:String(ze),tt=O.filter(zt=>Pe[zt]==="error");return Ot({phase:"",failedModelIds:tt,message:In}),U("error",In),{ok:!1,failedModelIds:tt}}}async function MT(R,T,{showSuccessNotice:O=!0}={}){if(W)return U("warning",W),!1;let oe=String(T?.id||"").trim(),ke=String(T?.name||"").trim(),qe=Array.isArray(T?.endpoints)?pr(T.endpoints):Yn([],T?.endpoint||""),Pe=Array.isArray(T?.rateLimitRows)?gr(T.rateLimitRows):[],Ot=It.find(zt=>zt?.id===R),Mt=ho(Ot)==="api",ze=tu(Ot);if(!oe)return U("warning","Provider id is required."),!1;if(!Xi.test(oe))return U("warning","Provider id must start with a letter and use lowercase letters, digits, or dashes only."),!1;if(!ke)return U("warning","Provider name is required."),!1;if(oe!==R&&It.some(zt=>zt?.id===oe))return U("warning",`Provider id "${oe}" already exists.`),!1;if(Mt&&qe.length===0)return U("warning","API Key providers require at least one valid http(s) endpoint."),!1;if(Mt&&qe.some(zt=>!fi(zt)))return U("warning","One or more endpoints are invalid. Use full http:// or https:// URLs."),!1;let In=Mt?Lo(Pe,{knownModelIds:ze,requireAtLeastOne:!0}):"";if(In)return U("warning",In),!1;let tt=jh(Ge.value||Ce,R,{...T,endpoints:qe,rateLimitRows:Pe});try{return await Ko(tt,`Updated provider ${oe}.`,{showSuccessNotice:O}),!0}catch{return!1}}async function NT(R,{providerDraft:T=null,modelRows:O=null,showSuccessNotice:oe=!0,onModelTestStateChange:ke=null}={}){if(W)return U("warning",W),!1;let qe=It.find(Br=>Br?.id===R);if(!qe)return U("error",`Provider '${R}' was not found.`),!1;let Pe=!!(T&&typeof T=="object"),Ot=Array.isArray(O);if(!Pe&&!Ot)return!0;let Mt=ho(qe)==="api",ze=Pe?String(T?.id||"").trim():R,In=Pe?String(T?.name||"").trim():String(qe?.name||R).trim(),tt=Pe?Array.isArray(T?.endpoints)?pr(T.endpoints):Yn([],T?.endpoint||""):ba(qe),zt=Pe&&Array.isArray(T?.rateLimitRows)?gr(T.rateLimitRows):[],io=Ot?O.map(Br=>({...Br,id:String(Br?.id||"").trim(),contextWindow:Uo(Br?.contextWindow||"")})).filter(Br=>Br.id):[];if(Pe){let Br=Ot?io.map(Ur=>Ur.id):tu(qe);if(!ze)return U("warning","Provider id is required."),!1;if(!Xi.test(ze))return U("warning","Provider id must start with a letter and use lowercase letters, digits, or dashes only."),!1;if(!In)return U("warning","Provider name is required."),!1;if(ze!==R&&It.some(Ur=>Ur?.id===ze))return U("warning",`Provider id "${ze}" already exists.`),!1;if(Mt&&tt.length===0)return U("warning","API Key providers require at least one valid http(s) endpoint."),!1;if(Mt&&tt.some(Ur=>!fi(Ur)))return U("warning","One or more endpoints are invalid. Use full http:// or https:// URLs."),!1;let Na=Mt?Lo(zt,{knownModelIds:Br,requireAtLeastOne:!0}):"";if(Na)return U("warning",Na),!1}if(Ot){if(io.length===0)return U("warning","Keep at least one model id on the provider."),!1;if(ws(io.map(lo=>lo.id)))return U("warning","Model ids must be unique for each provider."),!1;if(io.some(lo=>{let Eu=String(lo?.contextWindow||"").trim();if(!Eu)return!1;let Pm=Number.parseInt(Eu,10);return!Number.isFinite(Pm)||Pm<=0||String(Pm)!==Eu}))return U("warning","Context windows must be positive integers when set."),!1;let Na=tu(qe),Ur=io.map(lo=>lo.id).filter(lo=>!Na.includes(lo));if(Mt&&Ur.length>0){if(tt.length===0)return U("warning",`Provider '${ze}' needs at least one endpoint before testing new models.`),!1;let lo=ey(T,qe);if(!lo.apiKey&&!lo.apiKeyEnv)return U("warning",`Provider '${ze}' needs an API key or env before testing new models.`),!1;if(!(await pv({providerId:ze,endpoints:tt,newModelIds:Ur,credentialPayload:lo,headers:qe?.headers,onModelTestStateChange:ke})).ok)return!1}}let $o=Ge.value||Ce;Pe&&($o=jh($o,R,{...T,endpoints:tt,rateLimitRows:zt})),Ot&&($o=Ph($o,Pe?ze:R,io));let SM=Pe&&Ot?`Updated provider ${ze} and saved its model list.`:Pe?`Updated provider ${ze}.`:(()=>{let Br=tu(qe),Na=io.map(Ur=>Ur.id).filter(Ur=>!Br.includes(Ur));return Na.length>0?`Tested ${Na.length} new model${Na.length===1?"":"s"} and updated ${ze}.`:`Updated models for ${ze}.`})();try{return await Ko($o,SM,{showSuccessNotice:oe}),ke?.({phase:"",modelStates:{},failedModelIds:[],message:""}),!0}catch{return!1}}async function OT({showSuccessNotice:R=!1}={}){if(Ge.parseError||String((Ge.value||Ce||{}).masterKey||"").trim())return!1;let T=Io(Ge.value||Ce||{});T.masterKey=eu();try{return await Ko(T,"Gateway key ready.",{showSuccessNotice:R}),!0}catch{return!1}}async function _T(){if(!Hn){U("warning","Gateway key is still generating. Try again in a second.");return}try{await wu(Hn),U("success","Gateway key copied to clipboard.")}catch(R){U("error",R instanceof Error?R.message:String(R))}}async function kT(){if(!ce){U("warning","API endpoint is not ready yet.");return}try{await wu(ce),U("success","API endpoint copied to clipboard.")}catch(R){U("error",R instanceof Error?R.message:String(R))}}async function LT(R){let T=String(R||"").trim();if(!T){U("warning","Alias id is not ready yet.");return}try{await wu(T),U("success",`Alias id ${T} copied to clipboard.`)}catch(O){U("error",O instanceof Error?O.message:String(O))}}async function Ma(R,T,{ensureMode:O="none",successMessage:oe=""}={}){let ke=String(R||"").trim();if(!ke){U("warning",`${T} is not resolved yet.`);return}try{await Lt("/api/file/open",{method:"POST",headers:kt,body:JSON.stringify({editorId:"default",filePath:ke,ensureMode:O})}),U("success",oe||`Opened ${T} in the default app.`)}catch(qe){U("error",qe instanceof Error?qe.message:String(qe))}}async function DT(R){let T=String(R||"").trim();if(!T){U("warning","Model id is not ready yet.");return}try{await wu(T),U("success",`Model id ${T} copied to clipboard.`)}catch(O){U("error",O instanceof Error?O.message:String(O))}}async function IT(){if(!(typeof window>"u"?!0:window.confirm("Rotate the gateway key? Existing clients using the old key will need the new one. Linked tools like AMP, Codex CLI, and Claude Code will auto-update to the new key.")))return;let T=Io(Ge.value||Ce||{});T.masterKey=eu();try{await Ko(T,"Rotated gateway key. Linked tools like AMP, Codex CLI, and Claude Code refreshed automatically.")}catch{}}async function zT(R,T,{providerDraft:O=null,onModelTestStateChange:oe=null}={}){if(W)return U("warning",W),!1;let ke=It.find(tt=>tt?.id===R);if(!ke)return U("error",`Provider '${R}' was not found.`),!1;let qe=(Array.isArray(T)?T:[]).map(tt=>({...tt,id:String(tt?.id||"").trim()})).filter(tt=>tt.id),Pe=O&&String(O?.id||"").trim()||R,Ot=O?Array.isArray(O?.endpoints)?pr(O.endpoints):Yn([],O?.endpoint||""):ba(ke),Mt=(Array.isArray(ke?.models)?ke.models:[]).map(tt=>String(tt?.id||"").trim()).filter(Boolean),ze=qe.map(tt=>tt.id).filter(tt=>!Mt.includes(tt));if(ho(ke)==="api"&&ze.length>0){if(Ot.length===0)return U("warning",`Provider '${Pe}' needs at least one endpoint before testing new models.`),!1;let tt=ey(O,ke);if(!tt.apiKey&&!tt.apiKeyEnv)return U("warning",`Provider '${Pe}' needs an API key or env before testing new models.`),!1;if(!(await pv({providerId:Pe,endpoints:Ot,newModelIds:ze,credentialPayload:tt,headers:ke?.headers,onModelTestStateChange:oe})).ok)return!1}let In=Ph(Ge.value||Ce,R,qe);try{let tt=ze.length>0?`Tested ${ze.length} new model${ze.length===1?"":"s"} and updated ${R}.`:`Updated models for ${R}.`;return await Ko(In,tt),oe?.({phase:"",modelStates:{},failedModelIds:[],message:""}),!0}catch{return!1}}async function BT(R,T,O={}){if(W)return U("warning",W),!1;let oe=EA(Ge.value||Ce,R,T),ke=String(T?.id||R||"").trim()||R;try{return await Ko(oe,O.successMessage||`Updated alias ${ke}.`,{showSuccessNotice:O.showSuccessNotice!==!1}),!0}catch{return!1}}async function UT(R){if(W){U("warning",W);return}if(!(typeof window>"u"?!0:window.confirm(`Remove alias "${R}" from the config?`)))return;let O=TA(Ge.value||Ce,R);try{await Ko(O,`Removed alias ${R}.`)}catch{}}async function R5(R){try{await wu(R?.url||""),U("success",`${R?.label||"Endpoint"} copied to clipboard.`)}catch(T){U("error",T instanceof Error?T.message:String(T))}}async function PT(){let T=!(q?.routedViaRouter===!0);if(T){if(Qt){U("warning",Qt);return}if(!Hn){U("warning","Gateway key is still generating. Try again in a second.");return}if(!ce){U("warning","API endpoint is not ready yet.");return}}ge(T?"enable":"disable");try{let O=!1,oe;try{oe=await Lt("/api/amp/global-route",{method:"POST",headers:kt,body:JSON.stringify({enabled:T,rawText:T?n:void 0,endpointUrl:ce})})}catch(qe){if(qe?.statusCode===404&&T)O=!0,oe=await Lt("/api/amp/apply",{method:"POST",headers:kt,body:JSON.stringify({rawText:n,source:"amp-global-route-compat",patchScope:"global",endpointUrl:ce})});else throw qe?.statusCode===404?new Error("Restart the web console so the AMP routing endpoint is available."):qe}await Sr({preserveDraft:!T});let ke=T?"AMP connected.":"AMP disconnected.";U("success",O?`${ke} Restart the web console if the AMP status does not refresh.`:ke)}catch(O){U("error",O instanceof Error?O.message:String(O))}finally{ge("")}}function jT(R,T){if(Qt){U("warning",Qt);return}let O=String(T||"").trim(),oe=Ai.find(Pe=>Pe.id!==R&&String(Pe?.inbound||"").trim()===O);if(O&&oe){U("warning",`AMP inbound match "${O}" already exists.`);return}let ke=ay(Ge.value||Ce,R,{inbound:T}),qe=`${JSON.stringify(ke,null,2)}
54
54
  `;zr(qe),Ci(qe)}function VT(R,T){if(Qt){U("warning",Qt);return}let O=ay(Ge.value||Ce,R,{outbound:T==="__default__"?"":T}),oe=`${JSON.stringify(O,null,2)}