diff --git a/shadowlm/_static/assets/index-C5gMH3FJ.js b/shadowlm/_static/assets/index-ChIABspn.js
similarity index 99%
rename from shadowlm/_static/assets/index-C5gMH3FJ.js
rename to shadowlm/_static/assets/index-ChIABspn.js
index 84301c9..a5447f3 100644
--- a/shadowlm/_static/assets/index-C5gMH3FJ.js
+++ b/shadowlm/_static/assets/index-ChIABspn.js
@@ -56,6 +56,6 @@ Error generating stack: `+e.message+`
.allow-interactivity-${e} {pointer-events: all;}
`},rv=0,iv=[];function av(e){var t=_.useRef([]),n=_.useRef([0,0]),r=_.useRef(),i=_.useState(rv++)[0],a=_.useState(D_)[0],o=_.useRef(e);_.useEffect(function(){o.current=e},[e]),_.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=n_([e.lockRef.current],(e.shards||[]).map(ev),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=_.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=Q_(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=G_(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=G_(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return Z_(h,t,e,h===`h`?s:c,!0)},[]),c=_.useCallback(function(e){var n=e;if(!(!iv.length||iv[iv.length-1]!==a)){var r=`deltaY`in n?$_(n):Q_(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&tv(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(ev).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=_.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:ov(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=_.useCallback(function(e){n.current=Q_(e),r.current=void 0},[]),d=_.useCallback(function(t){l(t.type,$_(t),t.target,s(t,e.lockRef.current))},[]),f=_.useCallback(function(t){l(t.type,Q_(t),t.target,s(t,e.lockRef.current))},[]);_.useEffect(function(){return iv.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,B_),document.addEventListener(`touchmove`,c,B_),document.addEventListener(`touchstart`,u,B_),function(){iv=iv.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,B_),document.removeEventListener(`touchmove`,c,B_),document.removeEventListener(`touchstart`,u,B_)}},[]);var p=e.removeScrollBar,m=e.inert;return _.createElement(_.Fragment,null,m?_.createElement(a,{styles:nv(i)}):null,p?_.createElement(L_,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ov(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var sv=g_(__,av),cv=_.forwardRef(function(e,t){return _.createElement(y_,e_({},e,{ref:t,sideCar:sv}))});cv.classNames=y_.classNames;var lv=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},uv=new WeakMap,dv=new WeakMap,fv={},pv=0,mv=function(e){return e&&(e.host||mv(e.parentNode))},hv=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=mv(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},gv=function(e,t,n,r){var i=hv(t,Array.isArray(e)?e:[e]);fv[n]||(fv[n]=new WeakMap);var a=fv[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(uv.get(e)||0)+1,l=(a.get(e)||0)+1;uv.set(e,c),a.set(e,l),o.push(e),c===1&&i&&dv.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),pv++,function(){o.forEach(function(e){var t=uv.get(e)-1,i=a.get(e)-1;uv.set(e,t),a.set(e,i),t||(dv.has(e)||e.removeAttribute(r),dv.delete(e)),i||e.removeAttribute(n)}),pv--,pv||(uv=new WeakMap,uv=new WeakMap,dv=new WeakMap,fv={})}},_v=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||lv(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),gv(r,i,n,`aria-hidden`)):function(){return null}},vv=Object.defineProperty,yv=(e,t)=>vv(e,`name`,{value:t,configurable:!0}),bv=`Dialog`,[xv,Sv]=ah(bv),[Cv,wv]=xv(bv),Tv=yv(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=_.useRef(null),c=_.useRef(null),{nodes:l,registry:u}=Mg(),[d,f]=Lh({prop:r,defaultProp:i??!1,onChange:a,caller:bv}),[p,m]=_.useState(0),[h,g]=_.useState(0);return(0,B.jsx)(Cv,{scope:t,triggerRef:s,contentRef:c,contentId:tg(),titleId:tg(),descriptionId:tg(),titlePresent:p>0,descriptionPresent:h>0,setTitleCount:m,setDescriptionCount:g,open:d,onOpenChange:f,onOpenToggle:_.useCallback(()=>f(e=>!e),[f]),modal:o,branchNodes:l,branchRegistry:u,children:n})},`Dialog`),Ev=`DialogPortal`,[Dv,Ov]=xv(Ev,{forceMount:void 0}),kv=yv(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=wv(Ev,t);return(0,B.jsx)(Dv,{scope:t,forceMount:n,children:_.Children.map(r,e=>(0,B.jsx)(Gh,{present:n||a.open,children:(0,B.jsx)(Kg,{asChild:!0,container:i,children:e})}))})},`DialogPortal`),Av=`DialogOverlay`,jv=_.forwardRef(yv(function(e,t){let n=Ov(Av,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=wv(Av,e.__scopeDialog);return a.modal?(0,B.jsx)(Gh,{present:r||a.open,children:(0,B.jsx)(Nv,{...i,ref:t})}):null},`DialogOverlay`)),Mv=Im(`DialogOverlay.RemoveScroll`),Nv=_.forwardRef(yv(function(e,t){let{__scopeDialog:n,...r}=e,i=wv(Av,n),a=Nm(t,vg());return(0,B.jsx)(cv,{as:Mv,allowPinchZoom:!0,shards:_.useMemo(()=>[i.contentRef,...i.branchNodes.map(e=>({current:e}))],[i.contentRef,i.branchNodes]),children:(0,B.jsx)(eh.div,{"data-state":Wv(i.open),...r,ref:a,style:{pointerEvents:`auto`,...r.style}})})},`DialogOverlayImpl`)),Pv=`DialogContent`,Fv=_.forwardRef(yv(function(e,t){let n=Ov(Pv,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=wv(Pv,e.__scopeDialog);return(0,B.jsx)(Gh,{present:r||a.open,children:a.modal?(0,B.jsx)(Iv,{...i,ref:t}):(0,B.jsx)(Lv,{...i,ref:t})})},`DialogContent`)),Iv=_.forwardRef(yv(function(e,t){let n=wv(Pv,e.__scopeDialog),r=_.useRef(null),i=Nm(t,n.contentRef,r);return _.useEffect(()=>{let e=r.current;if(e)return _v(e)},[]),(0,B.jsx)(Rv,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:Ch(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Ch(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:Ch(e.onFocusOutside,e=>e.preventDefault())})},`DialogContentModal`)),Lv=_.forwardRef(yv(function(e,t){let n=wv(Pv,e.__scopeDialog),r=_.useRef(!1),i=_.useRef(!1);return(0,B.jsx)(Rv,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`DialogContentNonModal`)),Rv=_.forwardRef(yv(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,"aria-describedby":o,children:s,...c}=e,l=wv(Pv,n);return Qg(),(0,B.jsx)(jg,{registry:l.branchRegistry,children:(0,B.jsx)(kg,{asChild:!0,loop:!0,trapped:r,branches:l.branchNodes,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,B.jsx)(_g,{role:`dialog`,id:l.contentId,"aria-labelledby":l.titlePresent?l.titleId:void 0,"aria-describedby":l.descriptionPresent?Uv(o,l.descriptionId):o,"data-state":Wv(l.open),...c,ref:t,deferPointerDownOutside:!0,onDismiss:()=>l.onOpenChange(!1),children:s})})})},`DialogContentImpl`)),zv=_.forwardRef(yv(function(e,t){let{__scopeDialog:n,...r}=e,i=wv(`DialogTitle`,n),{setTitleCount:a}=i;return Oh(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,B.jsx)(eh.h2,{id:i.titleId,...r,ref:t})},`DialogTitle`)),Bv=_.forwardRef(yv(function(e,t){let{__scopeDialog:n,...r}=e,i=wv(`DialogDescription`,n),{setDescriptionCount:a}=i;return Oh(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,B.jsx)(eh.p,{id:i.descriptionId,...r,ref:t})},`DialogDescription`)),Vv=`DialogClose`,Hv=_.forwardRef(yv(function(e,t){let{__scopeDialog:n,...r}=e,i=wv(Vv,n);return(0,B.jsx)(eh.button,{type:`button`,...r,ref:t,onClick:Ch(e.onClick,()=>i.onOpenChange(!1))})},`DialogClose`));function Uv(...e){let t=new Set;for(let n of e)if(typeof n==`string`)for(let e of String(n).trim().split(/\s+/))e&&t.add(e);return t.size>0?Array.from(t).join(` `):void 0}yv(Uv,`concatAriaDescribedby`);function Wv(e){return e?`open`:`closed`}yv(Wv,`getState`);var Gv=Object.defineProperty,Kv=(e,t)=>Gv(e,`name`,{value:t,configurable:!0});function qv(e){let[t,n]=_.useState(void 0);return Oh(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=0,r=new ResizeObserver(r=>{if(!Array.isArray(r)||!r.length)return;let i=r[0];window.cancelAnimationFrame(t),t=window.requestAnimationFrame(()=>{let t,r;if(`borderBoxSize`in i){let e=i.borderBoxSize,n=Array.isArray(e)?e[0]:e;t=n.inlineSize,r=n.blockSize}else t=e.offsetWidth,r=e.offsetHeight;n({width:t,height:r})})});return r.observe(e,{box:`border-box`}),()=>{window.cancelAnimationFrame(t),r.unobserve(e)}}else n(void 0)},[e]),t}Kv(qv,`useSize`);var Jv=Object.defineProperty,Yv=(e,t)=>Jv(e,`name`,{value:t,configurable:!0}),Xv=`Popper`,[Zv,Qv]=ah(Xv),[$v,ey]=Zv(Xv),[ty,ny]=Zv(`PopperContent`);function ry(e){return e!==null}Yv(ry,`isNotNull`);function iy(e){let[t,n=`center`]=e.split(`-`);return[t,n]}Yv(iy,`getSideAndAlignFromPlacement`);var ay=Object.defineProperty,oy=(e,t)=>ay(e,`name`,{value:t,configurable:!0}),sy=!1;function cy(){let[e,t]=_.useState(sy);return _.useEffect(()=>{sy||(sy=!0,t(!0))},[]),e}oy(cy,`useIsHydrated`);var ly=_.useSyncExternalStore;function uy(){return()=>{}}oy(uy,`subscribe`);function dy(){return ly(uy,()=>!0,()=>!1)}oy(dy,`useIsHydratedModern`);var fy=typeof ly==`function`?dy:cy,py=Object.defineProperty,my=(e,t)=>py(e,`name`,{value:t,configurable:!0}),hy=`rovingFocusGroup.onEntryFocus`,gy={bubbles:!1,cancelable:!0},_y=`RovingFocusGroup`,[vy,yy,by]=lh(_y),[xy,Sy]=ah(_y,[by]),Cy={Vertical:`vertical`,Horizontal:`horizontal`},wy={LTR:`ltr`,RTL:`rtl`},[Ty,Ey]=xy(_y),Dy=_.forwardRef(my(function(e,t){return(0,B.jsx)(vy.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,B.jsx)(vy.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,B.jsx)(Oy,{...e,ref:t})})})},`RovingFocusGroup`)),Oy=_.forwardRef(my(function(e,t){let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=_.useRef(null),p=Nm(t,f),m=og(a),[h,g]=Lh({prop:o,defaultProp:s??null,onChange:c,caller:_y}),[v,y]=_.useState(!1),b=lg(l),x=yy(n),S=_.useRef(!1),[C,w]=_.useState(0);return _.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(hy,b),()=>e.removeEventListener(hy,b)},[b]),(0,B.jsx)(Ty,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:_.useCallback(e=>g(e),[g]),onItemShiftTab:_.useCallback(()=>y(!0),[]),onFocusableItemAdd:_.useCallback(()=>w(e=>e+1),[]),onFocusableItemRemove:_.useCallback(()=>w(e=>e-1),[]),children:(0,B.jsx)(eh.div,{tabIndex:v||C===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:Ch(e.onMouseDown,()=>{S.current=!0}),onFocus:Ch(e.onFocus,e=>{let t=!S.current;if(e.target===e.currentTarget&&t&&!v){let t=new CustomEvent(hy,gy);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=x().filter(e=>e.focusable);Py([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}S.current=!1}),onBlur:Ch(e.onBlur,()=>y(!1))})})},`RovingFocusGroupImpl`)),ky=`RovingFocusGroupItem`,Ay=_.forwardRef(my(function(e,t){let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=tg(),l=a||c,u=Ey(ky,n),d=u.currentTabStopId===l,f=yy(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u,g=fy();return Oh(()=>{if(!(!g||!r))return p(),()=>m()},[g,r,p,m]),_.useEffect(()=>{if(!(g||!r))return p(),()=>m()},[g,r,p,m]),(0,B.jsx)(vy.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,B.jsx)(eh.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:Ch(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:Ch(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:Ch(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Ny(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Fy(n,r+1):n.slice(r+1)}setTimeout(()=>Py(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})},`RovingFocusGroupItem`)),jy={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function My(e,t){return t===wy.RTL?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}my(My,`getDirectionAwareKey`);function Ny(e,t,n){let r=My(e.key,n);if(!(t===Cy.Vertical&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===Cy.Horizontal&&[`ArrowUp`,`ArrowDown`].includes(r)))return jy[r]}my(Ny,`getFocusIntent`);function Py(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}my(Py,`focusFirst`);function Fy(e,t){return e.map((n,r)=>e[(t+r)%e.length])}my(Fy,`wrapArray`);var Iy=Object.defineProperty,Ly=_.forwardRef(((e,t)=>Iy(e,`name`,{value:t,configurable:!0}))(function(e,t){return(0,B.jsx)(eh.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}})},`Label`)),Ry=Object.defineProperty,zy=(e,t)=>Ry(e,`name`,{value:t,configurable:!0}),By=`Switch`,[Vy,Hy]=ah(By),[Uy,Wy]=Vy(By);function Gy(e){let{__scopeSwitch:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:c,required:l,value:u=`on`,internal_do_not_use_render:d}=e,[f,p]=Lh({prop:n,defaultProp:i??!1,onChange:c,caller:By}),[m,h]=_.useState(null),[g,v]=_.useState(null),y=_.useRef(!1),[b,x]=_.useReducer(e=>e+1,0),S={checked:f,setChecked:p,disabled:a,control:m,setControl:h,name:s,form:o,value:u,hasConsumerStoppedPropagationRef:y,userInteractionCount:b,onUserInteraction:x,required:l,defaultChecked:i,isFormControl:m?!!o||!!m.closest(`form`):!0,bubbleInput:g,setBubbleInput:v};return(0,B.jsx)(Uy,{scope:t,...S,children:$y(d)?d(S):r})}zy(Gy,`SwitchProvider`);var Ky=`SwitchTrigger`,qy=_.forwardRef(zy(function({__scopeSwitch:e,onClick:t,...n},r){let{control:i,form:a,value:o,disabled:s,checked:c,required:l,setControl:u,setChecked:d,hasConsumerStoppedPropagationRef:f,onUserInteraction:p,isFormControl:m,bubbleInput:h}=Wy(Ky,e),g=Nm(r,u),v=_.useRef(c);return _.useEffect(()=>{let e=a?i?.ownerDocument.getElementById(a):i?.form;if(e instanceof HTMLFormElement){let t=zy(()=>d(v.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[i,a,d]),(0,B.jsx)(eh.button,{type:`button`,role:`switch`,"aria-checked":c,"aria-required":l,"data-state":eb(c),"data-disabled":s?``:void 0,disabled:s,value:o,...n,ref:g,onClick:Ch(t,e=>{p(),d(e=>!e),h&&m&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})})},`SwitchTrigger`)),Jy=_.forwardRef(zy(function(e,t){let{__scopeSwitch:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,B.jsx)(Gy,{__scopeSwitch:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(qy,{...d,ref:t,__scopeSwitch:n}),e&&(0,B.jsx)(Qy,{__scopeSwitch:n})]})})},`Switch`)),Yy=`SwitchThumb`,Xy=_.forwardRef(zy(function(e,t){let{__scopeSwitch:n,...r}=e,i=Wy(Yy,n);return(0,B.jsx)(eh.span,{"data-state":eb(i.checked),"data-disabled":i.disabled?``:void 0,...r,ref:t})},`SwitchThumb`)),Zy=`SwitchBubbleInput`,Qy=_.forwardRef(zy(function({__scopeSwitch:e,onClick:t,...n},r){let{control:i,hasConsumerStoppedPropagationRef:a,userInteractionCount:o,checked:s,defaultChecked:c,required:l,disabled:u,name:d,value:f,form:p,bubbleInput:m,setBubbleInput:h}=Wy(Zy,e),g=Nm(r,h),v=qv(i),y=_.useRef(!1),b=_.useRef(s),x=_.useRef(o);_.useEffect(()=>{let e=m;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=o!==x.current;x.current=o;let i=b.current!==s;b.current=s;let c=!(r&&a.current);if(i&&n){y.current=!r;let t=new Event(`click`,{bubbles:c});n.call(e,s),e.dispatchEvent(t),y.current=!1}},[m,s,a,o]);let S=_.useRef(s);return(0,B.jsx)(eh.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??S.current,required:l,disabled:u,name:d,value:f,form:p,...n,tabIndex:-1,ref:g,onClick:Ch(t,e=>{y.current&&e.stopPropagation()}),style:{...n.style,...v,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`SwitchBubbleInput`));function $y(e){return typeof e==`function`}zy($y,`isFunction`);function eb(e){return e?`checked`:`unchecked`}zy(eb,`getState`);var tb=Object.defineProperty,nb=(e,t)=>tb(e,`name`,{value:t,configurable:!0}),rb={Automatic:`automatic`,Manual:`manual`},ib=`Tabs`,[ab,ob]=ah(ib,[Sy]),sb=Sy(),[cb,lb]=ab(ib),ub=_.forwardRef(nb(function(e,t){let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=rb.Automatic,...l}=e,u=og(s),[d,f]=Lh({prop:r,onChange:i,defaultProp:a??``,caller:ib});return(0,B.jsx)(cb,{scope:n,baseId:tg(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,B.jsx)(eh.div,{dir:u,"data-orientation":o,...l,ref:t})})},`Tabs`)),db=`TabsList`,fb=_.forwardRef(nb(function(e,t){let{__scopeTabs:n,loop:r=!0,...i}=e,a=lb(db,n),o=sb(n);return(0,B.jsx)(Dy,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,B.jsx)(eh.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})},`TabsList`)),pb=`TabsTrigger`,mb=_.forwardRef(nb(function(e,t){let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=lb(pb,n),s=sb(n),c=_b(o.baseId,r),l=vb(o.baseId,r),u=r===o.value;return(0,B.jsx)(Ay,{asChild:!0,...s,focusable:!i,active:u,children:(0,B.jsx)(eh.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:Ch(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?(e.currentTarget.focus(),o.onValueChange(r)):e.preventDefault()}),onKeyDown:Ch(e.onKeyDown,e=>{i||e.target!==e.currentTarget||[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:Ch(e.onFocus,()=>{let e=o.activationMode!==rb.Manual;!u&&!i&&e&&o.onValueChange(r)})})})},`TabsTrigger`)),hb=`TabsContent`,gb=_.forwardRef(nb(function(e,t){let{__scopeTabs:n,value:r,forceMount:i,children:a,...o}=e,s=lb(hb,n),c=_b(s.baseId,r),l=vb(s.baseId,r),u=r===s.value,d=_.useRef(u);return _.useEffect(()=>{let e=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(e)},[]),(0,B.jsx)(Gh,{present:i||u,children:({present:n})=>(0,B.jsx)(eh.div,{"data-state":u?`active`:`inactive`,"data-orientation":s.orientation,role:`tabpanel`,"aria-labelledby":c,hidden:!n,id:l,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:d.current?`0s`:void 0},children:n&&a})})},`TabsContent`));function _b(e,t){return`${e}-trigger-${t}`}nb(_b,`makeTriggerId`);function vb(e,t){return`${e}-content-${t}`}nb(vb,`makeContentId`);var yb=Object.defineProperty,bb=(e,t)=>yb(e,`name`,{value:t,configurable:!0}),[xb,Sb]=ah(`Tooltip`,[Qv]);Qv();var Cb=`TooltipProvider`,wb=700,[Tb,Eb]=xb(Cb),Db=bb(e=>{let{__scopeTooltip:t,delayDuration:n=wb,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=_.useRef(!0),s=_.useRef(!1),c=_.useRef(0);return _.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,B.jsx)(Tb,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{r<=0||(window.clearTimeout(c.current),o.current=!1)},[r]),onClose:_.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r))},[r]),isPointerInTransitRef:s,onPointerInTransitChange:_.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})},`TooltipProvider`),[Ob,kb]=xb(`Tooltip`),[Ab,jb]=xb(`TooltipPortal`,{forceMount:void 0});function Mb(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}bb(Mb,`getExitSideFromRect`);function Nb(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}bb(Nb,`getPaddedExitPoints`);function Pb(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}bb(Pb,`getPointsFromRect`);function Fb(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;er!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}bb(Fb,`isPointInPolygon`);function Ib(e){let t=e.slice();return t.sort((e,t)=>e.xt.x?1:e.yt.y)),Lb(t)}bb(Ib,`getHull`);function Lb(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}bb(Lb,`getHullPresorted`);function Rb(...e){let t=new Set;for(let n of e)if(typeof n==`string`)for(let e of String(n).trim().split(/\s+/))e&&t.add(e);return t.size>0?Array.from(t).join(` `):void 0}bb(Rb,`concatAriaDescribedby`);var zb=rp(`group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`border-primary/20 bg-primary/10 text-primary hover:bg-primary/15 aria-expanded:bg-primary/15`,outline:`border-border bg-card text-foreground hover:bg-surface-2 aria-expanded:bg-surface-2`,secondary:`bg-surface-2 text-foreground hover:bg-surface aria-expanded:bg-surface`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function $({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,B.jsx)(r?Lm:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:Q(zb({variant:t,size:n,className:e})),...i})}function Bb({...e}){return(0,B.jsx)(Tv,{"data-slot":`dialog`,...e})}function Vb({...e}){return(0,B.jsx)(kv,{"data-slot":`dialog-portal`,...e})}function Hb({className:e,...t}){return(0,B.jsx)(jv,{"data-slot":`dialog-overlay`,className:Q(`fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,e),...t})}function Ub({className:e,children:t,showCloseButton:n=!0,...r}){return(0,B.jsxs)(Vb,{children:[(0,B.jsx)(Hb,{}),(0,B.jsxs)(Fv,{"data-slot":`dialog-content`,className:Q(`fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...r,children:[t,n&&(0,B.jsx)(Hv,{"data-slot":`dialog-close`,asChild:!0,children:(0,B.jsxs)($,{variant:`ghost`,className:`absolute top-2 right-2`,size:`icon-sm`,children:[(0,B.jsx)(Fe,{}),(0,B.jsx)(`span`,{className:`sr-only`,children:`Close`})]})})]})]})}function Wb({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`dialog-header`,className:Q(`flex flex-col gap-2`,e),...t})}function Gb({className:e,showCloseButton:t=!1,children:n,...r}){return(0,B.jsxs)(`div`,{"data-slot":`dialog-footer`,className:Q(`-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,B.jsx)(Hv,{asChild:!0,children:(0,B.jsx)($,{variant:`outline`,children:`Close`})})]})}function Kb({className:e,...t}){return(0,B.jsx)(zv,{"data-slot":`dialog-title`,className:Q(`font-heading text-base leading-none font-medium`,e),...t})}function qb({className:e,...t}){return(0,B.jsx)(Bv,{"data-slot":`dialog-description`,className:Q(`text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,e),...t})}function Jb({className:e,type:t,...n}){return(0,B.jsx)(`input`,{type:t,"data-slot":`input`,className:Q(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,e),...n})}function Yb({className:e,...t}){return(0,B.jsx)(Ly,{"data-slot":`label`,className:Q(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function Xb({data:e,width:t=120,height:n=32,className:r}){if(!e.length)return null;let i=Math.min(...e),a=Math.max(...e)-i||1,o=t/Math.max(1,e.length-1),s=`M${e.map((e,t)=>`${(t*o).toFixed(2)},${(n-(e-i)/a*n).toFixed(2)}`).join(` L`)}`;return(0,B.jsxs)(`svg`,{width:t,height:n,viewBox:`0 0 ${t} ${n}`,className:r,preserveAspectRatio:`none`,children:[(0,B.jsx)(`path`,{d:`${s} L${t},${n} L0,${n} Z`,fill:`currentColor`,opacity:.12}),(0,B.jsx)(`path`,{d:s,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`})]})}function Zb({steps:e,evals:t,height:n=240,totalSteps:r}){let i=e.map(e=>e.loss),a=n,o={l:44,r:16,t:16,b:28},s=800-o.l-o.r,c=a-o.t-o.b,{max:l,stepsCount:u}=(0,_.useMemo)(()=>{let e=[...i,...t.map(e=>e.loss)];return e.length?{max:Math.max(...e)*1.1,stepsCount:r??i.length}:{max:1,stepsCount:r??1}},[i,t,r]);if(!i.length)return(0,B.jsx)(`div`,{className:`flex items-center justify-center text-sm text-muted-foreground`,style:{height:a},children:(0,B.jsxs)(`div`,{className:`text-center`,children:[(0,B.jsx)(`div`,{className:`font-mono text-xs uppercase tracking-wider opacity-60`,children:`No training data yet`}),(0,B.jsx)(`div`,{className:`mt-1 text-xs opacity-50`,children:`Metrics appear as soon as the first step lands`})]})});let d=e=>o.l+e/Math.max(1,u-1)*s,f=e=>o.t+c-e/(l||1)*c,p=i.map((e,t)=>`${t===0?`M`:`L`}${d(t).toFixed(2)},${f(e).toFixed(2)}`).join(` `),m=.85,h=[];i.forEach((e,t)=>h.push(t===0?e:h[t-1]*m+e*(1-m)));let g=h.map((e,t)=>`${t===0?`M`:`L`}${d(t).toFixed(2)},${f(e).toFixed(2)}`).join(` `),v=Array.from({length:5},(e,t)=>l/4*t),y=Array.from({length:5},(e,t)=>Math.round(u/4*t));return(0,B.jsxs)(`svg`,{viewBox:`0 0 800 ${a}`,className:`w-full h-auto`,preserveAspectRatio:`none`,children:[v.map((e,t)=>(0,B.jsxs)(`g`,{children:[(0,B.jsx)(`line`,{x1:o.l,x2:800-o.r,y1:f(e),y2:f(e),className:`stroke-border-strong`,strokeDasharray:`2 4`,strokeWidth:.5}),(0,B.jsx)(`text`,{x:o.l-8,y:f(e)+3,textAnchor:`end`,fontSize:10,className:`fill-muted-foreground font-mono`,children:e.toFixed(2)})]},`y${t}`)),y.map((e,t)=>(0,B.jsx)(`text`,{x:d(e),y:a-8,textAnchor:`middle`,fontSize:10,className:`fill-muted-foreground font-mono`,children:e},`x${t}`)),(0,B.jsx)(`path`,{d:p,fill:`none`,className:`stroke-primary`,strokeWidth:1,opacity:.35}),(0,B.jsx)(`path`,{d:g,fill:`none`,className:`stroke-primary`,strokeWidth:1.8}),t.map((e,t)=>(0,B.jsxs)(`g`,{children:[(0,B.jsx)(`circle`,{cx:d(e.step),cy:f(e.loss),r:4,className:`fill-good`}),(0,B.jsx)(`circle`,{cx:d(e.step),cy:f(e.loss),r:4,fill:`none`,className:`stroke-good`,strokeOpacity:.3,strokeWidth:6})]},t)),t.length>1&&(0,B.jsx)(`path`,{d:t.map((e,t)=>`${t===0?`M`:`L`}${d(e.step)},${f(e.loss)}`).join(` `),fill:`none`,className:`stroke-good`,strokeWidth:1.5,strokeDasharray:`4 4`})]})}function Qb(){return(0,B.jsxs)(`div`,{className:`flex items-center gap-3 text-[10px] font-mono text-muted-foreground`,children:[(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{className:`size-2 rounded-full bg-primary`}),` train`]}),(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{className:`size-2 rounded-full bg-good`}),` eval`]})]})}var $b=rp(`group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!`,{variants:{variant:{default:`border-primary/20 bg-primary/10 text-primary [a]:hover:bg-primary/15`,secondary:`bg-surface-2 text-muted-foreground [a]:hover:bg-surface`,destructive:`border-destructive/25 bg-destructive/10 text-destructive focus-visible:ring-destructive/20 [a]:hover:bg-destructive/15`,outline:`border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground`,ghost:`hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50`,link:`text-primary underline-offset-4 hover:underline`}},defaultVariants:{variant:`default`}});function ex({className:e,variant:t=`default`,asChild:n=!1,...r}){return(0,B.jsx)(n?Lm:`span`,{"data-slot":`badge`,"data-variant":t,className:Q($b({variant:t}),e),...r})}function tx({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`skeleton`,className:Q(`animate-pulse rounded-md bg-muted`,e),...t})}function nx({title:e,description:t,actions:n}){return(0,B.jsxs)(`header`,{className:`mb-7 flex shrink-0 flex-wrap items-end justify-between gap-4 pt-1`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h1`,{className:`text-xl leading-tight font-semibold tracking-[-0.015em]`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-1 max-w-[64ch] text-[13px] text-muted-foreground`,children:t})]}),n&&(0,B.jsx)(`div`,{className:`flex items-center gap-2`,children:n})]})}function rx({title:e,description:t,actions:n}){return(0,B.jsxs)(`header`,{className:`mb-4 flex flex-wrap items-end justify-between gap-4`,children:[(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`h2`,{className:`text-base font-semibold tracking-[-0.01em]`,children:e}),t&&(0,B.jsx)(`p`,{className:`mt-1 max-w-[70ch] text-sm text-muted-foreground`,children:t})]}),n&&(0,B.jsx)(`div`,{className:`flex items-center gap-2`,children:n})]})}function ix({icon:e,title:t,children:n}){return(0,B.jsxs)(`div`,{className:`flex items-start gap-3 border border-border bg-surface/40 px-4 py-3.5`,children:[(0,B.jsx)(e,{className:`mt-0.5 size-4 shrink-0 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`p`,{className:`text-sm font-medium`,children:t}),n&&(0,B.jsx)(`div`,{className:`mt-0.5 max-w-prose text-sm text-muted-foreground`,children:n})]})]})}function ax({children:e,className:t}){return(0,B.jsx)(`div`,{className:Q(`grid grid-cols-2 gap-px overflow-hidden border border-border bg-border @2xl:grid-cols-4`,t),children:e})}function ox({label:e,value:t,sub:n,loading:r,href:i}){let a=(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e}),(0,B.jsx)(`div`,{className:`mt-1.5 text-2xl font-semibold tracking-[-0.01em] tabular-nums`,children:r?(0,B.jsx)(tx,{className:`h-7 w-16`}):t??`—`}),n&&!r&&(0,B.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:n})]});return i?(0,B.jsx)(`a`,{href:i,className:`block bg-card px-4 py-3.5 transition-colors hover:bg-surface`,children:a}):(0,B.jsx)(`div`,{className:`bg-card px-4 py-3.5`,children:a})}function sx({children:e,className:t}){return(0,B.jsx)(`span`,{className:Q(`font-mono text-xs break-all`,t),children:e})}function cx({label:e,hint:t,htmlFor:n,children:r,className:i}){return(0,B.jsxs)(`div`,{className:Q(`grid gap-1.5`,i),children:[(0,B.jsx)(Yb,{htmlFor:n,className:`text-xs text-muted-foreground`,children:e}),r,t&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t})]})}var lx={succeeded:{label:`Succeeded`,icon:le,className:`border-good/30 bg-good/10 text-good`},running:{label:`Running`,icon:_e,className:`border-primary/25 bg-primary/10 text-primary [&>svg]:animate-spin`},pending:{label:`Pending`,icon:ue,className:`text-muted-foreground`},failed:{label:`Failed`,icon:k,className:`border-destructive/25 bg-destructive/10 text-destructive`},stopped:{label:`Stopped`,icon:de,className:`text-muted-foreground`}};function ux({status:e}){let t=lx[e]??lx.stopped;return(0,B.jsxs)(ex,{variant:`outline`,className:Q(`gap-1 font-normal`,t.className),children:[(0,B.jsx)(t.icon,{className:`size-3`}),t.label]})}function dx(){return(0,B.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-current`}),(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-current [animation-delay:0.15s]`}),(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-current [animation-delay:0.3s]`}),(0,B.jsx)(`span`,{className:`ml-1`,children:`thinking…`})]})}function fx({className:e,size:t=`default`,...n}){return(0,B.jsx)(`div`,{"data-slot":`card`,"data-size":t,className:Q(`group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-md border border-border bg-card py-(--card-spacing) text-sm text-card-foreground [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl`,e),...n})}function px({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`card-header`,className:Q(`group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)`,e),...t})}function mx({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`card-title`,className:Q(`font-heading text-base leading-snug font-medium group-data-[size=sm]/card:text-sm`,e),...t})}function hx({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`card-description`,className:Q(`text-sm text-muted-foreground`,e),...t})}function gx({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`card-action`,className:Q(`col-start-2 row-span-2 row-start-1 self-start justify-self-end`,e),...t})}function _x({className:e,...t}){return(0,B.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,B.jsx)(`table`,{"data-slot":`table`,className:Q(`w-full caption-bottom text-sm`,e),...t})})}function vx({className:e,...t}){return(0,B.jsx)(`thead`,{"data-slot":`table-header`,className:Q(`[&_tr]:border-b`,e),...t})}function yx({className:e,...t}){return(0,B.jsx)(`tbody`,{"data-slot":`table-body`,className:Q(`[&_tr:last-child]:border-0`,e),...t})}function bx({className:e,...t}){return(0,B.jsx)(`tr`,{"data-slot":`table-row`,className:Q(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function xx({className:e,...t}){return(0,B.jsx)(`th`,{"data-slot":`table-head`,className:Q(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0`,e),...t})}function Sx({className:e,...t}){return(0,B.jsx)(`td`,{"data-slot":`table-cell`,className:Q(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0`,e),...t})}function Cx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(0),[o,s]=(0,_.useState)({}),[c,l]=(0,_.useState)([]);(0,_.useEffect)(()=>{let e=()=>{Bf().then(e=>l(e.workers)).catch(()=>{}),Wf().then(async({jobs:e})=>{t(e);let n=e.slice(0,6),r=await Promise.all(n.map(async e=>{try{let t=await Kf(e.job_id);return[e.job_id,t.steps.map(e=>e.loss)]}catch{return[e.job_id,[]]}}));s(Object.fromEntries(r))}).catch(()=>{})};e();let n=setInterval(e,3e3);return Cf().then(e=>r(e.datasets)).catch(()=>{}),Af().then(e=>a(e.catalog.length+e.recent.length)).catch(()=>{}),()=>clearInterval(n)},[]);let u=e.filter(e=>e.status===`running`||e.status===`pending`),d=e.slice(0,5),f=c.filter(e=>e.online).length;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Overview`,description:`Train any open model with any method. Then run it in the shadow of the frontier model behind your agent — until you own the weights.`,actions:(0,B.jsx)($,{asChild:!0,children:(0,B.jsxs)(`a`,{href:`#train`,children:[(0,B.jsx)(Ie,{}),` New training run`]})})}),(0,B.jsxs)(ax,{className:`@2xl:grid-cols-4`,children:[(0,B.jsx)(ox,{label:`Models`,value:i,sub:`Catalog + trained here`,href:`#models`}),(0,B.jsx)(ox,{label:`Active runs`,value:u.length,sub:u.length?`Currently training`:`Idle`,href:`#runs`}),(0,B.jsx)(ox,{label:`Datasets`,value:n.length,sub:`Uploaded to this server`,href:`#datasets`}),(0,B.jsx)(ox,{label:`Machines`,value:c.length?`${f}/${c.length}`:0,sub:c.length?`Online`:`Only this machine`,href:`#machines`})]}),u.length>0&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`h2`,{className:`mt-8 mb-3 text-sm font-medium text-muted-foreground`,children:`Active training`}),(0,B.jsx)(`div`,{className:`border`,children:(0,B.jsx)(`ul`,{className:`divide-y divide-border`,children:u.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`a`,{href:`#runs/${e.job_id}`,className:`flex items-center gap-4 px-4 py-3 transition-colors hover:bg-subtle`,children:[(0,B.jsx)(ux,{status:e.status}),(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.base_model}),(0,B.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e.method??`?`,` · `,e.steps,` steps so far`]})]}),(0,B.jsx)(`span`,{className:`text-primary`,children:(0,B.jsx)(Xb,{data:o[e.job_id]??[],width:120,height:32})})]})},e.job_id))})})]}),(0,B.jsxs)(`div`,{className:`mt-8 grid items-start gap-4 ${c.length>0?`@4xl:grid-cols-3`:``}`,children:[(0,B.jsxs)(`section`,{className:c.length>0?`@4xl:col-span-2`:``,children:[(0,B.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,B.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground`,children:`Recent runs`}),(0,B.jsx)($,{variant:`ghost`,size:`sm`,asChild:!0,children:(0,B.jsxs)(`a`,{href:`#runs`,children:[`All runs `,(0,B.jsx)(ne,{})]})})]}),d.length===0?(0,B.jsxs)(ix,{icon:me,title:`No runs yet`,children:[`Start one from `,(0,B.jsx)(`a`,{href:`#train`,className:`text-primary hover:underline`,children:`New run`}),`.`]}):(0,B.jsx)(`div`,{className:`border`,children:(0,B.jsxs)(_x,{children:[(0,B.jsx)(vx,{children:(0,B.jsxs)(bx,{children:[(0,B.jsx)(xx,{children:`Run`}),(0,B.jsx)(xx,{children:`Model`}),(0,B.jsx)(xx,{className:`hidden @2xl:table-cell`,children:`Method`}),(0,B.jsx)(xx,{children:`Status`}),(0,B.jsx)(xx,{className:`text-right`,children:`Loss`}),(0,B.jsx)(xx,{className:`hidden text-right @2xl:table-cell`,children:`Curve`})]})}),(0,B.jsx)(yx,{children:d.map(e=>(0,B.jsxs)(bx,{className:`cursor-pointer`,onClick:()=>window.location.hash=`#runs/${e.job_id}`,children:[(0,B.jsx)(Sx,{className:`max-w-40 truncate`,children:(0,B.jsx)(sx,{className:`text-muted-foreground`,children:e.name?.trim()||e.job_id.slice(0,10)})}),(0,B.jsx)(Sx,{className:`max-w-64 truncate`,children:(e.base_model||``).split(`/`).pop()}),(0,B.jsx)(Sx,{className:`hidden text-muted-foreground @2xl:table-cell`,children:e.method??`?`}),(0,B.jsx)(Sx,{children:(0,B.jsx)(ux,{status:e.status})}),(0,B.jsx)(Sx,{className:`text-right tabular-nums`,children:e.final_loss==null?`—`:e.final_loss.toFixed(4)}),(0,B.jsx)(Sx,{className:`hidden @2xl:table-cell`,children:(0,B.jsx)(`div`,{className:`flex justify-end text-primary`,children:(0,B.jsx)(Xb,{data:o[e.job_id]??[],width:100,height:28})})})]},e.job_id))})]})})]}),c.length>0&&(0,B.jsxs)(fx,{size:`sm`,children:[(0,B.jsxs)(px,{children:[(0,B.jsx)(mx,{children:`Machines`}),(0,B.jsxs)(hx,{children:[f,` of `,c.length,` online`]}),(0,B.jsx)(gx,{children:(0,B.jsx)($,{variant:`ghost`,size:`sm`,asChild:!0,children:(0,B.jsxs)(`a`,{href:`#machines`,children:[`All `,(0,B.jsx)(ne,{})]})})})]}),(0,B.jsx)(`ul`,{className:`divide-y divide-border border-t border-border`,children:c.map(e=>(0,B.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2.5 text-sm`,children:[(0,B.jsx)(`span`,{className:Q(`size-1.5 shrink-0 rounded-full`,e.online?`bg-good`:`bg-muted-foreground/40`)}),(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate font-medium`,children:e.name}),(0,B.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[e.backend,` · `,e.gpu_name||e.device,e.vram_gb?` · ${e.vram_gb} GB`:``]})]}),(0,B.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:e.online?e.queued?`${e.queued} queued`:`idle`:`last seen ${new Date(e.last_seen*1e3).toLocaleTimeString()}`})]},e.name))})]})]})]})}function wx({className:e,...t}){return(0,B.jsx)(`textarea`,{"data-slot":`textarea`,className:Q(`flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,e),...t})}var Tx={chat:`border-primary/20 bg-primary/10 text-primary`,sharegpt:`border-primary/20 bg-primary/10 text-primary`,instruction:`border-warning/25 bg-warning/10 text-warning`,preference:`border-good/30 bg-good/10 text-good`,text:`text-muted-foreground`};function Ex({format:e}){return(0,B.jsx)(ex,{variant:`outline`,className:Q(`font-mono font-normal`,Tx[e]??Tx.text),children:e})}function Dx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(`mine`),[o,s]=(0,_.useState)(`none`),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),f=()=>Cf().then(e=>t(e.datasets)).catch(()=>{});(0,_.useEffect)(()=>{f()},[]);async function p(e){d(e.dataset_id),l(null);try{if(e.source===`hf`){let t=await Df(e.repo,e.subset??`default`,e.split??`train`);l({title:`Dataset Preview`,source:`Hugging Face (${e.repo} / ${e.subset} / ${e.split})`,format:t.format,columns:t.columns,total:t.total,rows:t.preview})}else{let t=await wf(e.dataset_id);l({title:`${t.name} · first rows`,format:t.format,columns:Object.keys(t.preview?.[0]??{}),total:t.rows,rows:t.preview??[]})}}catch(e){l({title:`Preview failed`,format:`?`,columns:[],total:null,rows:[{error:e.message}]})}finally{d(null)}}let m={mine:e.filter(e=>!e.curated).length,explore:e.filter(e=>e.curated).length},h=e.filter(e=>(i===`explore`?!!e.curated:!e.curated)&&e.name.toLowerCase().includes(n.toLowerCase()));return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Datasets`,description:`Upload JSONL, or reference a Hugging Face dataset. Chat, instruction, preference, or raw text — the format is auto-detected.`,actions:rf(`operator`)&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)($,{variant:`outline`,onClick:()=>s(`hf`),children:[(0,B.jsx)(fe,{}),` Hugging Face`]}),(0,B.jsxs)($,{onClick:()=>s(`upload`),children:[(0,B.jsx)(Pe,{}),` Upload`]})]})}),(0,B.jsx)(Bb,{open:o===`upload`,onOpenChange:e=>!e&&s(`none`),children:(0,B.jsxs)(Ub,{className:`sm:max-w-xl`,children:[(0,B.jsxs)(Wb,{children:[(0,B.jsx)(Kb,{children:`Upload dataset`}),(0,B.jsx)(qb,{children:`One JSON row per line — paste it, or pick a .jsonl file.`})]}),(0,B.jsx)(Ox,{onDone:()=>{s(`none`),f()}})]})}),(0,B.jsx)(Bb,{open:o===`hf`,onOpenChange:e=>!e&&s(`none`),children:(0,B.jsxs)(Ub,{className:`sm:max-w-3xl`,children:[(0,B.jsxs)(Wb,{children:[(0,B.jsx)(Kb,{children:`Add a Hugging Face dataset`}),(0,B.jsx)(qb,{children:`Streamed preview first; nothing is downloaded until you train on it.`})]}),(0,B.jsx)(kx,{onDone:()=>{s(`none`),f()}})]})}),(0,B.jsx)(`div`,{className:`mb-4 flex self-start border border-border`,children:[`mine`,`explore`].map(e=>(0,B.jsxs)(`button`,{type:`button`,onClick:()=>a(e),className:Q(`h-9 px-4 text-sm`,i===e?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:[e===`mine`?`My datasets`:`Explore`,(0,B.jsx)(`span`,{className:`ml-1.5 tabular-nums opacity-70`,children:m[e]})]},e))}),i===`explore`&&(0,B.jsxs)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:[`Popular open datasets — curated starting points. `,(0,B.jsx)(`span`,{className:`text-foreground`,children:`Use to train`}),` picks one.`]}),(0,B.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`relative min-w-[220px] max-w-md flex-1`,children:[(0,B.jsx)(Oe,{className:`pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(Jb,{value:n,onChange:e=>r(e.target.value),placeholder:`Search datasets…`,className:`pl-8`})]}),(0,B.jsxs)(`div`,{className:`ml-auto text-xs text-muted-foreground tabular-nums`,children:[h.length,` of `,e.length,` datasets`]})]}),h.length===0?(0,B.jsx)(ix,{icon:fe,title:`No datasets yet`,children:`Upload one, or add a Hugging Face dataset.`}):(0,B.jsx)(`div`,{className:`@container rounded-xl border`,children:(0,B.jsxs)(_x,{children:[(0,B.jsx)(vx,{children:(0,B.jsxs)(bx,{children:[(0,B.jsx)(xx,{children:`Name`}),(0,B.jsx)(xx,{className:`hidden @2xl:table-cell`,children:`Source`}),(0,B.jsx)(xx,{children:`Format`}),(0,B.jsx)(xx,{className:`text-right`,children:`Actions`})]})}),(0,B.jsx)(yx,{children:h.map(e=>(0,B.jsxs)(bx,{children:[(0,B.jsx)(Sx,{className:`max-w-96`,children:(0,B.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,B.jsx)(fe,{className:`size-4 shrink-0 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`div`,{className:`truncate font-medium`,children:e.name}),(0,B.jsx)(`div`,{className:`truncate font-mono text-[11px] text-muted-foreground`,children:e.source===`hf`?`${e.subset}/${e.split}${e.eval_split?` · eval: ${e.eval_split}`:``}`:`${e.dataset_id}${e.rows==null?``:` · ${e.rows.toLocaleString()} rows`}`})]})]})}),(0,B.jsx)(Sx,{className:`hidden text-sm text-muted-foreground @2xl:table-cell`,children:e.source===`hf`?`Hugging Face`:`Upload`}),(0,B.jsx)(Sx,{children:(0,B.jsx)(Ex,{format:e.format})}),(0,B.jsx)(Sx,{children:(0,B.jsxs)(`div`,{className:`flex justify-end gap-1.5`,children:[(0,B.jsx)($,{size:`sm`,onClick:()=>{sessionStorage.setItem(`pick.dataset`,e.dataset_id),window.location.hash=`#train`},children:`Use to train`}),(0,B.jsx)($,{size:`sm`,variant:`outline`,disabled:u===e.dataset_id,onClick:()=>p(e),children:u===e.dataset_id?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(_e,{className:`animate-spin`}),` Loading…`]}):`Preview`}),rf(`operator`)&&(0,B.jsx)($,{size:`sm`,variant:`ghost`,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,onClick:()=>kf(e.dataset_id).then(f,()=>{}),children:`Delete`})]})})]},e.dataset_id))})]})}),(0,B.jsx)(Bb,{open:!!c,onOpenChange:e=>!e&&l(null),children:(0,B.jsx)(Ub,{className:`gap-0 p-0 sm:max-w-3xl`,children:c&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Wb,{className:`border-b border-border px-4 py-3.5`,children:(0,B.jsx)(Kb,{children:c.title})}),(0,B.jsx)(Ax,{...c})]})})})]})}function Ox({onDone:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),s=(0,_.useRef)(null);async function c(n){n.preventDefault(),o(``);try{let n=r.trim(),i=s.current?.files?.[0];i&&(n=await i.text());let a=n.split(`
`).filter(Boolean).map(e=>JSON.parse(e));if(!a.length)throw Error(`no rows — paste JSONL or pick a file`);await Tf(t,a),e()}catch(e){o(e.message)}}return(0,B.jsxs)(`form`,{onSubmit:c,className:`grid gap-3`,children:[(0,B.jsx)(cx,{label:`Name`,htmlFor:`ds-name`,children:(0,B.jsx)(Jb,{id:`ds-name`,placeholder:`support-tickets-v1`,value:t,onChange:e=>n(e.target.value)})}),(0,B.jsx)(cx,{label:`Rows`,htmlFor:`ds-rows`,children:(0,B.jsx)(wx,{id:`ds-rows`,rows:5,value:r,onChange:e=>i(e.target.value),className:`max-h-64 font-mono text-xs`,placeholder:`one JSON row per line:
-{"messages":[{"role":"user","content":"…"},{"role":"assistant","content":"…"}]}`})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,B.jsx)(`input`,{ref:s,type:`file`,accept:`.jsonl,.json`,className:`text-xs text-muted-foreground file:mr-2 file:rounded-md file:border file:border-border file:bg-card file:px-2.5 file:py-1 file:text-xs file:text-foreground hover:file:bg-surface-2`}),(0,B.jsx)($,{type:`submit`,className:`ml-auto`,children:`Upload`})]}),a&&(0,B.jsx)(`p`,{className:`text-sm text-destructive`,children:a})]})}function kx({onDone:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(``);(0,_.useEffect)(()=>{let e=t.trim();if(!e||!e.includes(`/`)){i([]),o([]);return}let n=setTimeout(async()=>{y(!0),C(``),g(null);try{let t=await Ef(e);i(t.configs),c(t.subset??``),o(t.splits),u(t.splits.includes(`train`)?`train`:t.splits[0]??``),f(``)}catch(e){i([]),o([]),C(e.message)}finally{y(!1)}},500);return()=>clearTimeout(n)},[t]);async function w(e){c(e),g(null);try{let n=await Ef(t.trim(),e);o(n.splits),u(n.splits.includes(`train`)?`train`:n.splits[0]??``),f(``)}catch(e){C(e.message)}}async function T(){if(!(!t.trim()||!l)){x(!0),C(``),g(null);try{g(await Df(t.trim(),s,l))}catch(e){C(e.message)}finally{x(!1)}}}async function ee(){if(h)try{await Of(t.trim(),s,l,h.format,d.trim()),e()}catch(e){C(e.message)}}let te=r.length>0||a.length>0;return(0,B.jsxs)(`div`,{className:`grid min-w-0 gap-3`,children:[(0,B.jsx)(cx,{label:`Repo`,htmlFor:`hf-repo`,children:(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Jb,{id:`hf-repo`,placeholder:`org/dataset (e.g. openai/gsm8k)`,value:t,onChange:e=>n(e.target.value),className:`pr-24 font-mono`}),v&&(0,B.jsxs)(`span`,{className:`absolute top-1/2 right-2.5 flex -translate-y-1/2 items-center gap-1 text-xs text-muted-foreground`,children:[(0,B.jsx)(_e,{className:`size-3 animate-spin`}),` loading…`]})]})}),(0,B.jsxs)(`div`,{className:Q(`grid grid-cols-3 gap-2`,!te&&`pointer-events-none opacity-40`),children:[(0,B.jsx)(cx,{label:`Subset`,children:(0,B.jsxs)(`select`,{value:s,onChange:e=>w(e.target.value),className:`w-full font-mono text-sm`,children:[r.length===0&&(0,B.jsx)(`option`,{value:``,children:`—`}),r.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})}),(0,B.jsx)(cx,{label:`Train split`,children:(0,B.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full font-mono text-sm`,children:[a.length===0&&(0,B.jsx)(`option`,{value:``,children:`—`}),a.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})}),(0,B.jsx)(cx,{label:`Eval split`,children:(0,B.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full font-mono text-sm`,children:[(0,B.jsx)(`option`,{value:``,children:`None`}),a.filter(e=>e!==l).map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})})]}),(0,B.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`flex w-fit items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[p?(0,B.jsx)(se,{className:`size-3.5`}):(0,B.jsx)(D,{className:`size-3.5`}),` Advanced`]}),p&&(0,B.jsxs)(`div`,{className:`border-l-2 border-border pl-3 text-xs text-muted-foreground`,children:[`Format is auto-detected from the streamed rows. Need column mapping or a row range? Do it once via the SDK (`,(0,B.jsx)(sx,{className:`text-foreground/80`,children:`Dataset.from_hf(...)`}),`) and upload the result.`]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)($,{variant:`outline`,onClick:T,disabled:b||!l,children:b?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(_e,{className:`animate-spin`}),` Loading…`]}):`Preview`}),h&&(0,B.jsx)($,{onClick:ee,children:`Add to library`}),S&&(0,B.jsx)(`span`,{className:`text-sm text-destructive`,children:S})]}),h&&(0,B.jsx)(jx,{title:`Dataset preview`,source:`Hugging Face (${t} / ${s} / ${l})`,format:h.format,columns:h.columns,total:h.total,rows:h.preview})]})}function Ax({source:e,format:t,columns:n,total:r,rows:i}){return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`grid gap-x-8 gap-y-1.5 border-b border-border px-4 py-3 text-xs sm:grid-cols-2`,children:[e&&(0,B.jsx)(Mx,{label:`Source`,value:e}),(0,B.jsx)(Mx,{label:`Format`,value:(0,B.jsx)(Ex,{format:t})}),(0,B.jsx)(Mx,{label:`Total rows`,value:r==null?`—`:r.toLocaleString()}),(0,B.jsx)(Mx,{label:`Columns`,value:n.join(`, `)||`—`})]}),(0,B.jsx)(`div`,{className:`scrollbar-thin max-h-[55vh] space-y-1 overflow-auto p-4 font-mono text-[11px] text-foreground/80`,children:i.map((e,t)=>(0,B.jsx)(`div`,{className:`border-b border-border/60 pb-1 break-words whitespace-pre-wrap`,children:JSON.stringify(e)},t))})]})}function jx(e){return(0,B.jsxs)(`div`,{className:`rise min-w-0 overflow-hidden rounded-lg border border-border`,children:[(0,B.jsx)(`div`,{className:`border-b border-border bg-surface/40 px-4 py-2.5 text-sm font-medium`,children:e.title}),(0,B.jsx)(Ax,{...e})]})}function Mx({label:e,value:t}){return(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground`,children:e}),(0,B.jsx)(`span`,{className:`min-w-0 truncate font-mono text-foreground/90`,children:t})]})}function Nx({text:e}){let[t,n]=(0,_.useState)(!1);return(0,B.jsx)($,{variant:`outline`,size:`icon-sm`,title:`Copy`,"aria-label":`Copy`,onClick:()=>navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}),children:t?(0,B.jsx)(oe,{className:`text-good`}):(0,B.jsx)(A,{})})}function Px(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(``),c=()=>{Vf().then(e=>t(e.tokens)).catch(()=>{})};(0,_.useEffect)(c,[]);async function l(){let e=n.trim()||`my-machine`;s(``);try{a(await Hf(e)),r(``),c()}catch(e){s(e.message)}}let u=i?`shadowlm worker --hub ${window.location.origin} --name ${i.name} --api-key ${i.token}`:null;return(0,B.jsxs)(`div`,{className:`grid gap-3`,children:[!rf(`admin`)&&(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:af(`admin`)}),(0,B.jsxs)(`div`,{className:rf(`admin`)?`flex items-center gap-2`:`hidden`,children:[(0,B.jsx)(Jb,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&l(),placeholder:`Machine name, e.g. macbook`,className:`flex-1 font-mono`}),(0,B.jsxs)($,{variant:`outline`,onClick:l,children:[(0,B.jsx)(he,{}),` Create machine token`]})]}),o&&(0,B.jsx)(`p`,{className:`text-sm text-destructive`,children:o}),u&&(0,B.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(`pre`,{className:`flex-1 overflow-x-auto border border-border bg-surface/60 px-3 py-2 font-mono text-xs`,children:u}),(0,B.jsx)(Nx,{text:u})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A long-lived token, shown once: copy it now. Revoke it here any time.`})]}),e.length>0&&(0,B.jsx)(`ul`,{className:`divide-y divide-border border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex items-center gap-2 px-3 py-1.5 text-sm`,children:[(0,B.jsx)(he,{className:`size-3.5 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsx)(sx,{className:`font-medium`,children:e.name}),(0,B.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:[`created `,new Date(e.created*1e3).toLocaleDateString()]}),rf(`admin`)&&(0,B.jsx)($,{variant:`ghost`,size:`icon-sm`,title:`Revoke`,"aria-label":`Revoke ${e.name}`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>Uf(e.name).then(c,()=>{}),children:(0,B.jsx)(Me,{})})]},e.name))})]})}function Fx(e){if(e.gpu_name){let t=e.backend===`mlx`?` unified`:``;return`${e.gpus>1?`${e.gpus}× `:``}${e.gpu_name}${e.vram_gb?` · ${e.vram_gb} GB${t}`:``}`}let t=[];return e.cores&&t.push(`${e.cores} cores`),e.ram_gb&&t.push(`${e.ram_gb} GB RAM`),t.join(` · `)||`—`}function Ix(e){let t=Math.max(0,Math.floor(Date.now()/1e3-e));return t<90?`${t}s ago`:t<5400?`${Math.round(t/60)}m ago`:`${Math.round(t/3600)}h ago`}function Lx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null);return(0,_.useEffect)(()=>{let e=()=>Bf().then(e=>{t(e.workers),r(!0)}).catch(()=>{});e();let n=setInterval(e,3e3);return()=>clearInterval(n)},[]),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Machines`,description:(0,B.jsxs)(B.Fragment,{children:[`Devices serving this hub over one outbound socket. They appear here the moment `,(0,B.jsx)(sx,{children:`shadowlm worker`}),` connects, and any of them can be picked as the training target.`]})}),n&&e.length===0?(0,B.jsxs)(`div`,{className:`grid max-w-2xl gap-4`,children:[(0,B.jsxs)(ix,{icon:be,title:`No machines connected`,children:[`On any machine with `,(0,B.jsx)(sx,{children:`shadowlm`}),` installed (a MacBook, an office GPU box; NAT is fine, it dials out), create a token and run the command it gives you.`]}),(0,B.jsx)(Px,{})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(rx,{title:`Connected machines`,actions:(0,B.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[e.filter(e=>e.online).length,`/`,e.length,` online`]})}),(0,B.jsx)(`div`,{className:`@container border`,children:(0,B.jsxs)(_x,{children:[(0,B.jsx)(vx,{children:(0,B.jsxs)(bx,{children:[(0,B.jsx)(xx,{children:`Machine`}),(0,B.jsx)(xx,{children:`Backend`}),(0,B.jsx)(xx,{className:`hidden @2xl:table-cell`,children:`Platform`}),(0,B.jsx)(xx,{children:`Compute`}),(0,B.jsx)(xx,{className:`text-right`,children:`Queue`}),(0,B.jsx)(xx,{className:`text-right`,children:`Status`})]})}),(0,B.jsx)(yx,{children:e.map(e=>(0,B.jsxs)(_.Fragment,{children:[(0,B.jsxs)(bx,{className:`cursor-pointer`,onClick:()=>a(i===e.name?null:e.name),children:[(0,B.jsx)(Sx,{children:(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 font-medium`,children:[(0,B.jsx)(`span`,{className:Q(`size-1.5 rounded-full`,e.online?`bg-good`:`bg-muted-foreground/40`)}),(0,B.jsx)(sx,{className:`text-sm`,children:e.name}),e.models.length>0&&(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-normal text-muted-foreground`,children:[i===e.name?(0,B.jsx)(se,{className:`size-3`}):(0,B.jsx)(D,{className:`size-3`}),e.models.length,` models`]})]})}),(0,B.jsx)(Sx,{className:`text-muted-foreground`,children:e.backend}),(0,B.jsx)(Sx,{className:`hidden text-muted-foreground @2xl:table-cell`,children:e.device}),(0,B.jsx)(Sx,{children:Fx(e)}),(0,B.jsx)(Sx,{className:`text-right tabular-nums`,children:e.queued||`—`}),(0,B.jsx)(Sx,{className:`text-right text-xs text-muted-foreground`,children:e.online?e.queued?`busy`:`idle`:`last seen ${Ix(e.last_seen)}`})]}),i===e.name&&e.models.length>0&&(0,B.jsx)(bx,{className:`bg-subtle hover:bg-subtle`,children:(0,B.jsxs)(Sx,{colSpan:6,className:`whitespace-normal`,children:[(0,B.jsxs)(`div`,{className:`pb-1.5 text-xs text-muted-foreground`,children:[`Models on `,e.name]}),(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.models.map(e=>(0,B.jsxs)(ex,{variant:`outline`,className:`font-mono font-normal`,children:[e.id,(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,e.size_gb,` GB`]})]},e.id))})]})})]},e.name))})]})}),e.length>0&&(0,B.jsxs)(`section`,{className:`mt-8 max-w-2xl`,children:[(0,B.jsx)(rx,{title:`Add another machine`,description:`Create a machine token, then run the command it gives you on that machine.`}),(0,B.jsx)(Px,{})]})]})]})}function Rx({className:e,orientation:t=`horizontal`,...n}){return(0,B.jsx)(ub,{"data-slot":`tabs`,"data-orientation":t,className:Q(`group/tabs flex gap-2 data-horizontal:flex-col`,e),...n})}var zx=rp(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function Bx({className:e,variant:t=`default`,...n}){return(0,B.jsx)(fb,{"data-slot":`tabs-list`,"data-variant":t,className:Q(zx({variant:t}),e),...n})}function Vx({className:e,...t}){return(0,B.jsx)(mb,{"data-slot":`tabs-trigger`,className:Q(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent`,`data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground`,`after:absolute after:bg-primary after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100`,e),...t})}function Hx({className:e,...t}){return(0,B.jsx)(gb,{"data-slot":`tabs-content`,className:Q(`flex-1 text-sm outline-none`,e),...t})}var Ux=e=>e?`${(e/1e9).toFixed(e<1e9?2:1)} GB`:``;function Wx(e,t,n){sessionStorage.setItem(`pick.${e}`,t),window.location.hash=n}var Gx=e=>{let t=e.toLowerCase();return t.includes(`qwen`)?`qwen`:t.includes(`llama`)?`llama`:t.includes(`gemma`)?`gemma`:t.includes(`smollm`)?`smollm`:`other`};function Kx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(`?`),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(`all`),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)({}),m=(0,_.useCallback)(()=>{Af().then(e=>{t(e.catalog),r(e.recent.filter(t=>!e.catalog.some(e=>e.id===t))),a(e.server_backend)}).catch(()=>{})},[]);(0,_.useEffect)(()=>{m()},[m]);async function h(e){let t=e.trim();if(t)try{await Nf(t),d(``),m()}catch{}}async function g(e){try{await Pf(e),m()}catch{}}(0,_.useEffect)(()=>{let e=()=>jf().then(e=>p(e.downloads)).catch(()=>{});e();let t=setInterval(e,1500);return()=>clearInterval(t)},[]);async function v(e){p(t=>({...t,[e]:{state:`downloading`,total:0}}));try{let t=await Mf(e);p(n=>({...n,[e]:t}))}catch{}}let y=(0,_.useMemo)(()=>[...n.map(e=>({id:e,note:`recently trained here`})),...e],[n,e]),b=[`all`,...Array.from(new Set(y.map(e=>Gx(e.id))))],x=y.filter(e=>e.id.toLowerCase().includes(o.toLowerCase())&&(c===`all`||Gx(e.id)===c));return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Models`,description:`Any open model on the Hugging Face hub works; these are good starting points. Server backend: ${i}.`,actions:rf(`operator`)&&(0,B.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),h(u)},children:[(0,B.jsx)(Jb,{value:u,onChange:e=>d(e.target.value),placeholder:`org/model, any HF id`,className:`w-56 font-mono`}),(0,B.jsxs)($,{type:`submit`,disabled:!u.trim(),children:[(0,B.jsx)(Ee,{}),` Add`]})]})}),(0,B.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`relative max-w-sm min-w-[220px] flex-1`,children:[(0,B.jsx)(Oe,{className:`pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(Jb,{value:o,onChange:e=>s(e.target.value),placeholder:`Search models…`,className:`pl-8`})]}),(0,B.jsx)(Rx,{value:c,onValueChange:l,children:(0,B.jsx)(Bx,{children:b.map(e=>(0,B.jsx)(Vx,{value:e,className:`px-2.5 capitalize`,children:e},e))})})]}),x.length===0?(0,B.jsx)(ix,{icon:ae,title:`No models match`,children:`Clear the search, or add any Hugging Face model id above.`}):(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-3 @2xl:grid-cols-2 @5xl:grid-cols-3`,children:x.map(e=>{let t=f[e.id],n=e.cached||t?.state===`ready`,r=t?.state===`downloading`;return(0,B.jsxs)(`div`,{className:`flex flex-col border border-border bg-card p-4 transition-colors hover:border-border-strong`,children:[(0,B.jsxs)(`div`,{className:`mb-2 flex items-start justify-between gap-2`,children:[(0,B.jsx)(`span`,{className:`grid size-7 shrink-0 place-items-center rounded-md border border-border bg-surface/60`,children:(0,B.jsx)(ae,{className:`size-3.5 text-muted-foreground`,strokeWidth:1.75})}),(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[n&&(0,B.jsxs)(ex,{variant:`outline`,className:`border-good/30 bg-good/10 font-normal text-good`,children:[(0,B.jsx)(oe,{}),` On disk`]}),e.dev&&(0,B.jsx)(ex,{variant:`secondary`,className:`font-normal`,children:`Dev pick`}),e.gated&&(0,B.jsx)(ex,{variant:`outline`,className:`border-warning/30 bg-warning/10 font-normal text-warning`,children:`HF token`}),e.custom&&rf(`operator`)&&(0,B.jsx)($,{variant:`ghost`,size:`icon-xs`,title:`Remove from library`,"aria-label":`Remove ${e.id}`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>g(e.id),children:(0,B.jsx)(Fe,{})})]})]}),(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:e.id.split(`/`).pop()}),(0,B.jsxs)(`div`,{className:`mt-0.5 truncate text-muted-foreground`,children:[(0,B.jsx)(sx,{children:e.id}),e.params?(0,B.jsxs)(`span`,{className:`text-xs`,children:[` · `,e.params]}):``]}),e.note&&(0,B.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e.note}),r&&(0,B.jsxs)(`div`,{className:`mt-3`,children:[(0,B.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${t.pct??5}%`}})}),(0,B.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-xs text-muted-foreground tabular-nums`,children:[(0,B.jsx)(_e,{className:`size-3 animate-spin`}),t.pct==null?`downloading…`:`${t.pct}% · ${Ux(t.downloaded)} / ${Ux(t.total)}`]})]}),t?.state===`error`&&(0,B.jsxs)(`div`,{className:`mt-2 flex items-center gap-1 truncate text-xs text-destructive`,title:t.error??``,children:[(0,B.jsx)(Ne,{className:`size-3 shrink-0`}),` `,t.error]}),(0,B.jsxs)(`div`,{className:`mt-auto flex gap-2 pt-4`,children:[(0,B.jsx)($,{className:`flex-1`,onClick:()=>Wx(`model`,e.id,`#train`),children:`Fine-tune`}),(0,B.jsx)($,{variant:`outline`,onClick:()=>Wx(`model`,e.id,`#playground`),children:`Try`}),!n&&!r&&rf(`operator`)&&(0,B.jsx)($,{variant:`outline`,size:`icon`,title:`Prefetch weights to disk`,"aria-label":`Download ${e.id}`,onClick:()=>v(e.id),children:(0,B.jsx)(M,{})})]})]},e.id)})})]})}function qx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(`mlx-community/Qwen2.5-0.5B-Instruct-4bit`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)([]),[C,w]=(0,_.useState)([]),[T,ee]=(0,_.useState)(!1),[te,E]=(0,_.useState)(!1),[ne,ie]=(0,_.useState)(``),ae=(0,_.useRef)(null),ce=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!rf(`operator`))return;let e=!1;ie(``);let t=f&&o?[o,null]:[o],n=async()=>{try{let r=await Promise.all(t.map(e=>Zf(i,e,e?u:null)));if(e)return;let a=r.find(e=>e.error);if(a){E(!1),ie(a.error);return}if(r.every(e=>e.ready)){E(!1);return}E(!0),setTimeout(n,3e3)}catch{e||E(!1)}};return n(),()=>{e=!0}},[i,o,u,f]),(0,_.useEffect)(()=>{Af().then(e=>{let n=[...e.recent,...e.catalog.map(e=>e.id)];if(t([...new Set(n)].map(t=>e.catalog.find(e=>e.id===t)??{id:t})),e.server_backend!==`mlx`&&!sessionStorage.getItem(`pick.model`)){let e=n.find(e=>!e.startsWith(`mlx-community/`));e&&a(t=>t.startsWith(`mlx-community/`)?e:t)}}).catch(()=>{}),Wf().then(({jobs:e})=>{r(e);let t=sessionStorage.getItem(`pick.adapter`),n=sessionStorage.getItem(`pick.model`);n&&(a(n),sessionStorage.removeItem(`pick.model`)),t&&(s(t),p(!0),sessionStorage.removeItem(`pick.adapter`))}).catch(()=>{})},[]),(0,_.useEffect)(()=>{ae.current?.focus()}),(0,_.useEffect)(()=>{ce.current&&(ce.current.scrollTop=1e9)},[x,C]),(0,_.useEffect)(()=>{l([]),d(null),o&&Jf(o).then(({checkpoints:e})=>{l(e);let t=sessionStorage.getItem(`pick.checkpoint`);t&&e.some(e=>!e.final&&e.step===Number(t))&&d(Number(t)),sessionStorage.removeItem(`pick.checkpoint`)}).catch(()=>{})},[o]);let O=n.filter(e=>e.status===`succeeded`),le=O.find(e=>e.job_id===o),ue=o?le?.name?.trim()||`${o.slice(0,8)} · ${le?.method??`finetuned`}`:i.split(`/`).pop(),de=(0,_.useMemo)(()=>{let t=g.toLowerCase(),n=e.filter(e=>e.id.toLowerCase().includes(t));return g&&!e.some(e=>e.id.toLowerCase()===t)&&n.push({id:g.trim()}),n},[e,g]),k=O.filter(e=>{let t=g.toLowerCase();return e.job_id.includes(g)||(e.name||``).toLowerCase().includes(t)||(e.base_model||``).toLowerCase().includes(t)});function A(e){a(e),s(null),p(!1),h(!1)}function j(e){s(e.job_id),a(e.base_model),p(!0),h(!1)}async function fe(){let e=y.trim();if(!e||T)return;b(``);let t=[...x,{role:`user`,content:e}];S(t);let n=f&&o;n&&w(t=>[...t,{role:`user`,content:e}]),ee(!0);let r=e=>e.replace(/[\s\S]*?<\/think>/g,``).trim()||e.trim(),a=(e,t)=>Qf({model:i,adapter:e,checkpoint:e?u:null,messages:t,max_new_tokens:256,temperature:.7,top_p:.95}).then(e=>r(e.text)).catch(e=>`⚠ ${e.message}`);try{let r=a(o,t).then(e=>S(t=>[...t,{role:`assistant`,content:e}]));if(n){let t=a(null,[...C,{role:`user`,content:e}]).then(e=>w(t=>[...t,{role:`assistant`,content:e}]));await Promise.all([r,t])}else await r}finally{ee(!1)}}let M=x.length===0;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 !shrink flex-col overflow-hidden border border-border bg-card`,children:[(0,B.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 border-b border-border px-4`,children:[(0,B.jsx)(ye,{className:`size-4 shrink-0 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsxs)(`button`,{onClick:()=>{h(e=>!e),v(``)},className:`flex min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-sm font-semibold transition-colors hover:bg-surface-2`,children:[(0,B.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:o?`Shadow`:`Base`}),(0,B.jsx)(`span`,{className:Q(`truncate`,o&&`text-primary`),children:ue}),(0,B.jsx)(se,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),o&&(0,B.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked)}),`Shadow mode `,(0,B.jsx)(`span`,{className:`text-muted-foreground/70`,children:`(base ↔ shadow)`})]}),o&&c.length>1&&(0,B.jsxs)(`div`,{className:`flex items-center gap-0.5 rounded-lg border border-border p-0.5 font-mono text-[11px]`,children:[(0,B.jsx)(`span`,{className:`px-1.5 text-muted-foreground select-none`,children:`ckpt`}),c.map(e=>{let t=e.final?u===null:u===e.step;return(0,B.jsx)(`button`,{title:e.path,onClick:()=>d(e.final?null:e.step),className:Q(`rounded-md px-2 py-0.5 transition-colors`,t?`bg-primary/10 text-primary`:`text-muted-foreground hover:text-foreground`),children:e.final?`final`:e.step},e.path)})]}),x.length>0&&(0,B.jsxs)($,{variant:`ghost`,size:`sm`,className:`ml-auto text-muted-foreground`,onClick:()=>{S([]),w([])},children:[(0,B.jsx)(De,{}),` Clear`]})]}),(0,B.jsx)(Bb,{open:m,onOpenChange:h,children:(0,B.jsxs)(Ub,{showCloseButton:!1,className:`top-[11vh] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-2xl data-open:zoom-in-100 data-closed:zoom-out-100`,children:[(0,B.jsx)(Kb,{className:`sr-only`,children:`Pick a model`}),(0,B.jsx)(qb,{className:`sr-only`,children:`Filter base models or your shadows, or paste any Hugging Face id.`}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-border px-4 py-3`,children:[(0,B.jsx)(Oe,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(`input`,{autoFocus:!0,value:g,onChange:e=>v(e.target.value),"data-slot":`palette-input`,onKeyDown:e=>{e.key===`Escape`&&h(!1),e.key===`Enter`&&(de[0]&&(!k.length||g)?A(de[0].id):k[0]&&j(k[0]))},placeholder:`Filter base models or your shadows · paste any HF id`,className:`flex-1 border-0 bg-transparent p-0 text-sm outline-none placeholder:text-muted-foreground`}),(0,B.jsx)(`kbd`,{className:`rounded border border-border px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:`esc`})]}),(0,B.jsxs)(`div`,{className:`max-h-[58vh] overflow-auto py-1.5 scrollbar-thin`,children:[(0,B.jsx)(`div`,{className:`px-4 pt-2 pb-1 text-[11px] font-medium text-muted-foreground`,children:`Base · open models`}),de.map(e=>{let t=e.id===i&&!o;return(0,B.jsxs)(`button`,{onClick:()=>A(e.id),className:`group flex w-full items-center gap-3 px-4 py-2 text-left text-sm hover:bg-subtle`,children:[(0,B.jsx)(`span`,{className:`w-3.5 shrink-0`,children:t?(0,B.jsx)(oe,{className:`size-3.5 text-primary`}):(0,B.jsx)(D,{className:`size-3.5 text-muted-foreground/40 group-hover:text-primary`})}),(0,B.jsx)(`span`,{className:Q(`flex-1 truncate font-mono text-[13px]`,t&&`text-primary`),children:e.id}),(0,B.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:e.dev?`dev pick`:e.gated?`HF token`:e.params??e.note??``})]},e.id)}),(0,B.jsx)(`div`,{className:`mt-1.5 border-t border-border px-4 pt-3 pb-1 text-[11px] font-medium text-muted-foreground`,children:`Shadows · your runs`}),k.length?k.map(e=>{let t=e.job_id===o;return(0,B.jsxs)(`button`,{onClick:()=>j(e),className:`group flex w-full items-center gap-3 px-4 py-2 text-left text-sm hover:bg-subtle`,children:[(0,B.jsx)(`span`,{className:`w-3.5 shrink-0`,children:t?(0,B.jsx)(oe,{className:`size-3.5 text-primary`}):(0,B.jsx)(D,{className:`size-3.5 text-muted-foreground/40 group-hover:text-primary`})}),(0,B.jsxs)(`span`,{className:Q(`flex-1 truncate`,t&&`text-primary`),children:[e.name?.trim()||(0,B.jsx)(`span`,{className:`font-mono text-[13px]`,children:e.job_id.slice(0,10)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.method]})]}),(0,B.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`shadows `,(e.base_model||``).split(`/`).pop()]})]},e.job_id)}):(0,B.jsxs)(`div`,{className:`px-4 py-3 text-sm text-muted-foreground`,children:[`No shadows yet. `,(0,B.jsx)(`a`,{href:`#train`,className:`font-medium text-primary hover:underline`,children:`Train one`}),` to see it here.`]})]})]})}),(0,B.jsx)(`div`,{ref:ce,className:`min-h-0 flex-1 overflow-auto px-6 scrollbar-thin`,onClick:()=>m&&h(!1),children:M?(0,B.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center`,children:[(0,B.jsx)(`img`,{src:`/logo.png`,alt:``,className:`mb-2 size-28 dark:hidden [filter:drop-shadow(0_0_40px_#e5484d55)_drop-shadow(0_0_14px_#e5484d44)]`}),(0,B.jsx)(`img`,{src:`/logo1.png`,alt:``,className:`mb-2 hidden size-28 dark:block [filter:drop-shadow(0_0_40px_#ffffff33)_drop-shadow(0_0_14px_#ffffff22)]`}),(0,B.jsx)(`h1`,{className:`text-xl font-semibold tracking-[-0.015em]`,children:o?`Does it cast the same shadow?`:`Talk to a model`}),(0,B.jsxs)(`p`,{className:`text-[13px] text-muted-foreground`,children:[`Base `,(0,B.jsx)(`span`,{className:`font-mono text-foreground`,children:i.split(`/`).pop()}),o&&(0,B.jsxs)(B.Fragment,{children:[` · shadow `,(0,B.jsx)(`span`,{className:`font-mono text-primary`,children:o.slice(0,8)})]})]})]}):f&&o?(0,B.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4 py-6`,children:[x.map((e,t)=>e.role===`user`?(0,B.jsx)(Jx,{text:e.content},t):(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,B.jsx)(Yx,{tone:`tuned`,label:`Shadow`,text:e.content}),(0,B.jsx)(Yx,{tone:`base`,label:`Base`,text:C[t]?.content})]},t)),T&&(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,B.jsx)(Yx,{tone:`tuned`,label:`Shadow`}),(0,B.jsx)(Yx,{tone:`base`,label:`Base`})]})]}):(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-4 py-6`,children:[x.map((e,t)=>e.role===`user`?(0,B.jsx)(Jx,{text:e.content},t):(0,B.jsxs)(`div`,{className:`text-[13px] leading-relaxed`,children:[(0,B.jsx)(`div`,{className:`mb-1 font-mono text-[11px] text-muted-foreground`,children:ue}),(0,B.jsx)(`div`,{className:`whitespace-pre-wrap`,children:e.content})]},t)),T&&(0,B.jsx)(dx,{})]})}),(0,B.jsxs)(`div`,{className:`shrink-0 border-t border-border p-3`,children:[(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-end gap-2`,children:[(0,B.jsx)(`textarea`,{ref:ae,value:y,rows:1,"data-slot":`composer`,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),fe())},placeholder:rf(`operator`)?te?`Warming up the model — first load can take a couple of minutes…`:`Say something to the shadow…`:af(`operator`),disabled:!rf(`operator`),className:`field-sizing-content max-h-40 min-h-9 min-w-0 grow resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-[13px] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50`}),(0,B.jsx)($,{size:`icon`,className:`size-9`,"aria-label":`Send`,onClick:fe,disabled:!y.trim()||T||te||!rf(`operator`),children:T?(0,B.jsx)(_e,{className:`size-3.5 animate-spin`}):(0,B.jsx)(re,{className:`size-4`})})]}),(0,B.jsx)(`div`,{className:`mx-auto mt-1.5 max-w-3xl text-center text-[11px] text-muted-foreground`,children:ne?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,B.jsx)(Ne,{className:`size-3`}),` Can't load this model here: `,ne]}):te?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-primary`,children:[(0,B.jsx)(_e,{className:`size-3 animate-spin`}),` Loading weights onto the GPU — send unlocks when it's hot`]}):`Enter to send · Shift+Enter for a new line`})]})]})}function Jx({text:e}){return(0,B.jsx)(`div`,{className:`flex justify-end`,children:(0,B.jsx)(`div`,{className:`max-w-[85%] border border-border bg-subtle px-3 py-2 text-[13px] whitespace-pre-wrap`,children:e})})}function Yx({tone:e,label:t,text:n}){return(0,B.jsxs)(`div`,{className:Q(`border bg-card px-3.5 py-2.5 text-[13px] leading-relaxed`,e===`tuned`?`border-primary/30`:`border-border`),children:[(0,B.jsx)(`div`,{className:Q(`mb-1.5 text-[11px] font-medium`,e===`tuned`?`text-primary`:`text-muted-foreground`),children:t}),(0,B.jsx)(`span`,{className:`whitespace-pre-wrap`,children:n??(0,B.jsx)(dx,{})})]})}function Xx({initialId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(e||null),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`all`),[l,u]=(0,_.useState)({});(0,_.useEffect)(()=>{e&&i(e)},[e]),(0,_.useEffect)(()=>{let e=async()=>{try{let{jobs:e}=await Wf();n(e),i(t=>t??e[0]?.job_id??null);let t=await Promise.all(e.slice(0,20).map(async e=>{try{let t=await Kf(e.job_id);return[e.job_id,t.steps.map(e=>e.loss)]}catch{return[e.job_id,[]]}}));u(Object.fromEntries(t))}catch{}};e();let t=setInterval(e,2500);return()=>clearInterval(t)},[]);let d=t.filter(e=>(s===`all`||e.status===s)&&(a===``||e.base_model.toLowerCase().includes(a.toLowerCase())||(e.name||``).toLowerCase().includes(a.toLowerCase())||e.job_id.includes(a))),f=t.find(e=>e.job_id===r)??null;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Training runs`,description:`Every finetune persists its config, metrics, and artifact. Watch live, compare in the playground, download the adapter.`}),(0,B.jsxs)(`div`,{className:`grid min-h-[520px] flex-1 !shrink grid-cols-1 overflow-hidden border border-border bg-card lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)]`,children:[(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-col border-b border-border lg:border-r lg:border-b-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border p-3`,children:[(0,B.jsxs)(`div`,{className:`relative flex-1`,children:[(0,B.jsx)(Oe,{className:`pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(Jb,{value:a,onChange:e=>o(e.target.value),placeholder:`Search runs…`,className:`pl-8`})]}),(0,B.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`h-8 text-sm`,children:[(0,B.jsx)(`option`,{value:`all`,children:`All status`}),(0,B.jsx)(`option`,{value:`succeeded`,children:`Succeeded`}),(0,B.jsx)(`option`,{value:`running`,children:`Running`}),(0,B.jsx)(`option`,{value:`failed`,children:`Failed`}),(0,B.jsx)(`option`,{value:`stopped`,children:`Stopped`})]})]}),(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 divide-y divide-border overflow-auto scrollbar-thin`,children:[d.length===0&&(0,B.jsx)(`div`,{className:`p-4`,children:(0,B.jsxs)(ix,{icon:me,title:`No runs yet`,children:[`Start one in `,(0,B.jsx)(`a`,{href:`#train`,className:`font-medium text-primary hover:underline`,children:`New run`}),`.`]})}),d.map(e=>(0,B.jsxs)(`button`,{onClick:()=>{i(e.job_id),window.location.hash=`#runs/${e.job_id}`},"aria-current":r===e.job_id?`true`:void 0,className:Q(`w-full border-l-2 px-4 py-3 text-left transition-colors`,r===e.job_id?`border-l-primary bg-primary/5`:`border-l-transparent hover:bg-subtle`),children:[(0,B.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,B.jsx)(`span`,{className:`truncate font-mono text-[11px] text-muted-foreground`,children:e.name?.trim()||e.job_id.slice(0,12)}),(0,B.jsx)(ux,{status:e.status})]}),(0,B.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.base_model}),(0,B.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2`,children:[(0,B.jsxs)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,children:[e.method??`?`,` · `,e.steps,` steps`]}),(0,B.jsx)(`span`,{className:e.status===`failed`?`text-destructive`:`text-primary`,children:(0,B.jsx)(Xb,{data:l[e.job_id]??[],width:64,height:20})})]})]},e.job_id))]})]}),f?(0,B.jsx)(Qx,{run:f},f.job_id):(0,B.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Select a run to see its curves, logs and artifact.`})]})]})}function Zx({title:e,sub:t,actions:n,children:r,className:i}){return(0,B.jsxs)(`section`,{className:Q(`overflow-hidden border border-border bg-card`,i),children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-border px-4 py-2.5`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),t&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t})]}),n]}),r]})}function Qx({run:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(`loss`);(0,_.useEffect)(()=>{let t=!0,r=async()=>{try{let[r,a,s]=await Promise.all([Gf(e.job_id),Kf(e.job_id),qf(e.job_id)]);if(!t)return;n(r),i(a.steps),o(a.evals),c(s.logs),r.checkpoint&&Jf(e.job_id).then(({checkpoints:e})=>t&&u(e)).catch(()=>{})}catch{}};r();let a=setInterval(r,1800);return()=>{t=!1,clearInterval(a)}},[e.job_id]);let p=r[r.length-1];async function m(){let t=await _f(`/v1/finetunes/${e.job_id}/artifact`);if(!t.ok){let e=(await vf(t)).message;return Bd?t.status!==403&&ff(`error`,e):alert(e)}let n=await t.blob(),r=document.createElement(`a`);r.href=URL.createObjectURL(n),r.download=`${e.job_id}-adapter.tar.gz`,r.click(),URL.revokeObjectURL(r.href)}let h=t?.status??e.status;return(0,B.jsx)(`div`,{className:`min-h-0 overflow-auto scrollbar-thin`,children:(0,B.jsxs)(`div`,{className:`max-w-[1000px] space-y-5 p-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[e.name?.trim()&&(0,B.jsx)(`span`,{className:`text-sm font-semibold text-primary`,children:e.name.trim()}),(0,B.jsx)(sx,{className:`text-muted-foreground`,children:e.job_id}),(0,B.jsx)(ux,{status:h})]}),(0,B.jsx)(`h2`,{className:`text-lg font-semibold tracking-[-0.01em]`,children:e.base_model}),(0,B.jsxs)(`p`,{className:`mt-0.5 font-mono text-xs text-muted-foreground`,children:[e.method??`?`,p?.tokens_per_s?` · ${Math.round(p.tokens_per_s)} tok/s`:``]})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(t?.status===`running`||t?.status===`pending`)&&rf(`operator`)&&(0,B.jsxs)($,{variant:`destructive`,onClick:()=>Yf(e.job_id).catch(()=>{}),children:[(0,B.jsx)(Ae,{}),` Cancel`]}),t?.status===`succeeded`&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)($,{variant:`outline`,onClick:()=>{sessionStorage.setItem(`pick.adapter`,e.job_id),sessionStorage.setItem(`pick.model`,e.base_model),window.location.hash=`#playground`},children:[(0,B.jsx)(ye,{}),` Playground`]}),rf(`operator`)&&(0,B.jsxs)($,{variant:`outline`,onClick:m,children:[(0,B.jsx)(M,{}),` Adapter`]})]})]})]}),(0,B.jsxs)(ax,{children:[(0,B.jsx)(ox,{label:`Final loss`,value:t?.final_loss==null?p?p.loss.toFixed(4):void 0:t.final_loss.toFixed(4)}),(0,B.jsx)(ox,{label:`Eval loss`,value:a.length?a[a.length-1].loss.toFixed(4):void 0}),(0,B.jsx)(ox,{label:`Steps`,value:String(p?.step??0)}),(0,B.jsx)(ox,{label:`Learning rate`,value:p?p.lr.toExponential(1):void 0})]}),(0,B.jsxs)(Rx,{value:d,onValueChange:e=>f(e),className:`gap-4`,children:[(0,B.jsxs)(Bx,{variant:`line`,className:`w-full justify-start border-b border-border`,children:[(0,B.jsx)(Vx,{value:`loss`,className:`flex-none`,children:`Loss curves`}),(0,B.jsxs)(Vx,{value:`logs`,className:`flex-none`,children:[`Training logs`,t?.status===`running`&&(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`})]}),(0,B.jsx)(Vx,{value:`artifact`,className:`flex-none`,children:`Artifact`})]}),(0,B.jsxs)(Hx,{value:`loss`,className:`space-y-4`,children:[(0,B.jsx)(Zx,{title:`Loss`,sub:`train (raw + EMA) with eval overlaid`,actions:(0,B.jsx)(Qb,{}),children:(0,B.jsx)(`div`,{className:`p-4`,children:(0,B.jsx)(Zb,{steps:r,evals:a})})}),(0,B.jsxs)(`div`,{className:`grid gap-4 @4xl:grid-cols-2`,children:[(0,B.jsx)(Zx,{title:`Training loss`,sub:`raw + EMA overlay`,children:(0,B.jsx)(`div`,{className:`p-4`,children:(0,B.jsx)(Zb,{steps:r,evals:[]})})}),(0,B.jsx)(Zx,{title:`Eval loss`,sub:`held-out validation`,children:(0,B.jsx)(`div`,{className:`p-4`,children:a.length?(0,B.jsx)(Zb,{steps:a,evals:[]}):(0,B.jsx)(`div`,{className:`flex h-[240px] items-center justify-center text-center`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`text-sm font-medium text-muted-foreground`,children:`No eval data`}),(0,B.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Train with a held-out eval split to see this`})]})})})})]})]}),(0,B.jsx)(Hx,{value:`logs`,children:s.length?(0,B.jsx)($x,{logs:s,live:t?.status===`running`}):(0,B.jsx)(ix,{icon:ke,title:`No console output`,children:`Nothing was captured for this run.`})}),(0,B.jsxs)(Hx,{value:`artifact`,className:`space-y-4`,children:[t?.error&&(0,B.jsxs)(`section`,{className:`border border-destructive/30 bg-destructive/5 p-4`,children:[(0,B.jsxs)(`h3`,{className:`mb-2 flex items-center gap-1.5 text-sm font-semibold text-destructive`,children:[(0,B.jsx)(O,{className:`size-4`}),` Error`]}),(0,B.jsx)(`pre`,{className:`font-mono text-xs whitespace-pre-wrap text-destructive`,children:t.error})]}),t?.checkpoint?(0,B.jsxs)(Zx,{title:`Trained adapter`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 text-sm`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(sx,{className:`text-muted-foreground`,children:t.checkpoint}),(0,B.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Load it back: `,(0,B.jsxs)(`code`,{className:`font-mono text-foreground/80`,children:[`slm.load("`,e.base_model,`", adapter="…")`]})]})]}),rf(`operator`)&&(0,B.jsxs)($,{variant:`outline`,onClick:m,children:[(0,B.jsx)(M,{}),` tar.gz`]})]}),l.length>1&&(0,B.jsxs)(`div`,{className:`border-t border-border`,children:[(0,B.jsxs)(`div`,{className:`px-4 pt-3 pb-1 text-xs text-muted-foreground`,children:[`Saved versions · `,l.length]}),(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:[...l].reverse().map(t=>(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2 text-sm`,children:[(0,B.jsx)(`span`,{className:`font-mono text-xs`,children:t.final?(0,B.jsx)(`span`,{className:`text-primary`,children:t.label}):`step ${t.step}`}),(0,B.jsxs)($,{variant:`ghost`,size:`xs`,className:`text-primary`,onClick:()=>{sessionStorage.setItem(`pick.adapter`,e.job_id),sessionStorage.setItem(`pick.model`,e.base_model),t.final?sessionStorage.removeItem(`pick.checkpoint`):sessionStorage.setItem(`pick.checkpoint`,String(t.step)),window.location.hash=`#playground`},children:[(0,B.jsx)(ye,{}),` Test this version`]})]},t.path))}),(0,B.jsxs)(`div`,{className:`px-4 py-2 text-[11px] text-muted-foreground`,children:[`Trained with `,(0,B.jsx)(`code`,{className:`font-mono text-foreground/70`,children:`save_steps`}),`: each is a point you can roll back to or A/B in the playground.`]})]})]}):!t?.error&&(0,B.jsx)(ix,{icon:Se,title:`No artifact yet`,children:`It appears when training succeeds.`})]})]})]})})}function $x({logs:e,live:t}){let n=(0,_.useRef)(null),[r,i]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{r&&n.current&&(n.current.scrollTop=n.current.scrollHeight)},[e,r]),(0,B.jsxs)(`section`,{className:`overflow-hidden border border-border bg-card`,children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-border px-4 py-2.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(ke,{className:`size-4 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Training console`}),t&&(0,B.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary`,children:[(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),` live`]})]}),(0,B.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:r,onChange:e=>i(e.target.checked)}),` Follow`]})]}),(0,B.jsx)(`pre`,{ref:n,onScroll:e=>{let t=e.currentTarget;i(t.scrollHeight-t.scrollTop-t.clientHeight<24)},className:`m-0 max-h-[460px] overflow-auto bg-ink p-4 font-mono text-[11px] leading-[1.35] whitespace-pre text-bone/90 scrollbar-thin`,children:e.join(`
+{"messages":[{"role":"user","content":"…"},{"role":"assistant","content":"…"}]}`})}),(0,B.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,B.jsx)(`input`,{ref:s,type:`file`,accept:`.jsonl,.json`,className:`text-xs text-muted-foreground file:mr-2 file:rounded-md file:border file:border-border file:bg-card file:px-2.5 file:py-1 file:text-xs file:text-foreground hover:file:bg-surface-2`}),(0,B.jsx)($,{type:`submit`,className:`ml-auto`,children:`Upload`})]}),a&&(0,B.jsx)(`p`,{className:`text-sm text-destructive`,children:a})]})}function kx({onDone:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(``);(0,_.useEffect)(()=>{let e=t.trim();if(!e||!e.includes(`/`)){i([]),o([]);return}let n=setTimeout(async()=>{y(!0),C(``),g(null);try{let t=await Ef(e);i(t.configs),c(t.subset??``),o(t.splits),u(t.splits.includes(`train`)?`train`:t.splits[0]??``),f(``)}catch(e){i([]),o([]),C(e.message)}finally{y(!1)}},500);return()=>clearTimeout(n)},[t]);async function w(e){c(e),g(null);try{let n=await Ef(t.trim(),e);o(n.splits),u(n.splits.includes(`train`)?`train`:n.splits[0]??``),f(``)}catch(e){C(e.message)}}async function T(){if(!(!t.trim()||!l)){x(!0),C(``),g(null);try{g(await Df(t.trim(),s,l))}catch(e){C(e.message)}finally{x(!1)}}}async function ee(){if(h)try{await Of(t.trim(),s,l,h.format,d.trim()),e()}catch(e){C(e.message)}}let te=r.length>0||a.length>0;return(0,B.jsxs)(`div`,{className:`grid min-w-0 gap-3`,children:[(0,B.jsx)(cx,{label:`Repo`,htmlFor:`hf-repo`,children:(0,B.jsxs)(`div`,{className:`relative`,children:[(0,B.jsx)(Jb,{id:`hf-repo`,placeholder:`org/dataset (e.g. openai/gsm8k)`,value:t,onChange:e=>n(e.target.value),className:`pr-24 font-mono`}),v&&(0,B.jsxs)(`span`,{className:`absolute top-1/2 right-2.5 flex -translate-y-1/2 items-center gap-1 text-xs text-muted-foreground`,children:[(0,B.jsx)(_e,{className:`size-3 animate-spin`}),` loading…`]})]})}),(0,B.jsxs)(`div`,{className:Q(`grid grid-cols-3 gap-2`,!te&&`pointer-events-none opacity-40`),children:[(0,B.jsx)(cx,{label:`Subset`,children:(0,B.jsxs)(`select`,{value:s,onChange:e=>w(e.target.value),className:`w-full font-mono text-sm`,children:[r.length===0&&(0,B.jsx)(`option`,{value:``,children:`—`}),r.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})}),(0,B.jsx)(cx,{label:`Train split`,children:(0,B.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full font-mono text-sm`,children:[a.length===0&&(0,B.jsx)(`option`,{value:``,children:`—`}),a.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})}),(0,B.jsx)(cx,{label:`Eval split`,children:(0,B.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full font-mono text-sm`,children:[(0,B.jsx)(`option`,{value:``,children:`None`}),a.filter(e=>e!==l).map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})})]}),(0,B.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`flex w-fit items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[p?(0,B.jsx)(se,{className:`size-3.5`}):(0,B.jsx)(D,{className:`size-3.5`}),` Advanced`]}),p&&(0,B.jsxs)(`div`,{className:`border-l-2 border-border pl-3 text-xs text-muted-foreground`,children:[`Format is auto-detected from the streamed rows. Need column mapping or a row range? Do it once via the SDK (`,(0,B.jsx)(sx,{className:`text-foreground/80`,children:`Dataset.from_hf(...)`}),`) and upload the result.`]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)($,{variant:`outline`,onClick:T,disabled:b||!l,children:b?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(_e,{className:`animate-spin`}),` Loading…`]}):`Preview`}),h&&(0,B.jsx)($,{onClick:ee,children:`Add to library`}),S&&(0,B.jsx)(`span`,{className:`text-sm text-destructive`,children:S})]}),h&&(0,B.jsx)(jx,{title:`Dataset preview`,source:`Hugging Face (${t} / ${s} / ${l})`,format:h.format,columns:h.columns,total:h.total,rows:h.preview})]})}function Ax({source:e,format:t,columns:n,total:r,rows:i}){return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`grid gap-x-8 gap-y-1.5 border-b border-border px-4 py-3 text-xs sm:grid-cols-2`,children:[e&&(0,B.jsx)(Mx,{label:`Source`,value:e}),(0,B.jsx)(Mx,{label:`Format`,value:(0,B.jsx)(Ex,{format:t})}),(0,B.jsx)(Mx,{label:`Total rows`,value:r==null?`—`:r.toLocaleString()}),(0,B.jsx)(Mx,{label:`Columns`,value:n.join(`, `)||`—`})]}),(0,B.jsx)(`div`,{className:`scrollbar-thin max-h-[55vh] space-y-1 overflow-auto p-4 font-mono text-[11px] text-foreground/80`,children:i.map((e,t)=>(0,B.jsx)(`div`,{className:`border-b border-border/60 pb-1 break-words whitespace-pre-wrap`,children:JSON.stringify(e)},t))})]})}function jx(e){return(0,B.jsxs)(`div`,{className:`rise min-w-0 overflow-hidden rounded-lg border border-border`,children:[(0,B.jsx)(`div`,{className:`border-b border-border bg-surface/40 px-4 py-2.5 text-sm font-medium`,children:e.title}),(0,B.jsx)(Ax,{...e})]})}function Mx({label:e,value:t}){return(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(`span`,{className:`w-20 shrink-0 text-muted-foreground`,children:e}),(0,B.jsx)(`span`,{className:`min-w-0 truncate font-mono text-foreground/90`,children:t})]})}function Nx({text:e}){let[t,n]=(0,_.useState)(!1);return(0,B.jsx)($,{variant:`outline`,size:`icon-sm`,title:`Copy`,"aria-label":`Copy`,onClick:()=>navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),1500)}),children:t?(0,B.jsx)(oe,{className:`text-good`}):(0,B.jsx)(A,{})})}function Px(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(``),c=()=>{Vf().then(e=>t(e.tokens)).catch(()=>{})};(0,_.useEffect)(c,[]);async function l(){let e=n.trim()||`my-machine`;s(``);try{a(await Hf(e)),r(``),c()}catch(e){s(e.message)}}let u=i?`shadowlm worker --hub ${window.location.origin} --name ${i.name} --api-key ${i.token}`:null;return(0,B.jsxs)(`div`,{className:`grid gap-3`,children:[!rf(`admin`)&&(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:af(`admin`)}),(0,B.jsxs)(`div`,{className:rf(`admin`)?`flex items-center gap-2`:`hidden`,children:[(0,B.jsx)(Jb,{value:n,onChange:e=>r(e.target.value),onKeyDown:e=>e.key===`Enter`&&l(),placeholder:`Machine name, e.g. macbook`,className:`flex-1 font-mono`}),(0,B.jsxs)($,{variant:`outline`,onClick:l,children:[(0,B.jsx)(he,{}),` Create machine token`]})]}),o&&(0,B.jsx)(`p`,{className:`text-sm text-destructive`,children:o}),u&&(0,B.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,B.jsx)(`pre`,{className:`flex-1 overflow-x-auto border border-border bg-surface/60 px-3 py-2 font-mono text-xs`,children:u}),(0,B.jsx)(Nx,{text:u})]}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A long-lived token, shown once: copy it now. Revoke it here any time.`})]}),e.length>0&&(0,B.jsx)(`ul`,{className:`divide-y divide-border border`,children:e.map(e=>(0,B.jsxs)(`li`,{className:`flex items-center gap-2 px-3 py-1.5 text-sm`,children:[(0,B.jsx)(he,{className:`size-3.5 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsx)(sx,{className:`font-medium`,children:e.name}),(0,B.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:[`created `,new Date(e.created*1e3).toLocaleDateString()]}),rf(`admin`)&&(0,B.jsx)($,{variant:`ghost`,size:`icon-sm`,title:`Revoke`,"aria-label":`Revoke ${e.name}`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>Uf(e.name).then(c,()=>{}),children:(0,B.jsx)(Me,{})})]},e.name))})]})}function Fx(e){if(e.gpu_name){let t=e.backend===`mlx`?` unified`:``;return`${e.gpus>1?`${e.gpus}× `:``}${e.gpu_name}${e.vram_gb?` · ${e.vram_gb} GB${t}`:``}`}let t=[];return e.cores&&t.push(`${e.cores} cores`),e.ram_gb&&t.push(`${e.ram_gb} GB RAM`),t.join(` · `)||`—`}function Ix(e){let t=Math.max(0,Math.floor(Date.now()/1e3-e));return t<90?`${t}s ago`:t<5400?`${Math.round(t/60)}m ago`:`${Math.round(t/3600)}h ago`}function Lx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null);return(0,_.useEffect)(()=>{let e=()=>Bf().then(e=>{t(e.workers),r(!0)}).catch(()=>{});e();let n=setInterval(e,3e3);return()=>clearInterval(n)},[]),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Machines`,description:(0,B.jsxs)(B.Fragment,{children:[`Devices serving this hub over one outbound socket. They appear here the moment `,(0,B.jsx)(sx,{children:`shadowlm worker`}),` connects, and any of them can be picked as the training target.`]})}),n&&e.length===0?(0,B.jsxs)(`div`,{className:`grid max-w-2xl gap-4`,children:[(0,B.jsxs)(ix,{icon:be,title:`No machines connected`,children:[`On any machine with `,(0,B.jsx)(sx,{children:`shadowlm`}),` installed (a MacBook, an office GPU box; NAT is fine, it dials out), create a token and run the command it gives you.`]}),(0,B.jsx)(Px,{})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(rx,{title:`Connected machines`,actions:(0,B.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[e.filter(e=>e.online).length,`/`,e.length,` online`]})}),(0,B.jsx)(`div`,{className:`@container border`,children:(0,B.jsxs)(_x,{children:[(0,B.jsx)(vx,{children:(0,B.jsxs)(bx,{children:[(0,B.jsx)(xx,{children:`Machine`}),(0,B.jsx)(xx,{children:`Backend`}),(0,B.jsx)(xx,{className:`hidden @2xl:table-cell`,children:`Platform`}),(0,B.jsx)(xx,{children:`Compute`}),(0,B.jsx)(xx,{className:`text-right`,children:`Queue`}),(0,B.jsx)(xx,{className:`text-right`,children:`Status`})]})}),(0,B.jsx)(yx,{children:e.map(e=>(0,B.jsxs)(_.Fragment,{children:[(0,B.jsxs)(bx,{className:`cursor-pointer`,onClick:()=>a(i===e.name?null:e.name),children:[(0,B.jsx)(Sx,{children:(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-2 font-medium`,children:[(0,B.jsx)(`span`,{className:Q(`size-1.5 rounded-full`,e.online?`bg-good`:`bg-muted-foreground/40`)}),(0,B.jsx)(sx,{className:`text-sm`,children:e.name}),e.models.length>0&&(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs font-normal text-muted-foreground`,children:[i===e.name?(0,B.jsx)(se,{className:`size-3`}):(0,B.jsx)(D,{className:`size-3`}),e.models.length,` models`]})]})}),(0,B.jsx)(Sx,{className:`text-muted-foreground`,children:e.backend}),(0,B.jsx)(Sx,{className:`hidden text-muted-foreground @2xl:table-cell`,children:e.device}),(0,B.jsx)(Sx,{children:Fx(e)}),(0,B.jsx)(Sx,{className:`text-right tabular-nums`,children:e.queued||`—`}),(0,B.jsx)(Sx,{className:`text-right text-xs text-muted-foreground`,children:e.online?e.queued?`busy`:`idle`:`last seen ${Ix(e.last_seen)}`})]}),i===e.name&&e.models.length>0&&(0,B.jsx)(bx,{className:`bg-subtle hover:bg-subtle`,children:(0,B.jsxs)(Sx,{colSpan:6,className:`whitespace-normal`,children:[(0,B.jsxs)(`div`,{className:`pb-1.5 text-xs text-muted-foreground`,children:[`Models on `,e.name]}),(0,B.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.models.map(e=>(0,B.jsxs)(ex,{variant:`outline`,className:`font-mono font-normal`,children:[e.id,(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,e.size_gb,` GB`]})]},e.id))})]})})]},e.name))})]})}),e.length>0&&(0,B.jsxs)(`section`,{className:`mt-8 max-w-2xl`,children:[(0,B.jsx)(rx,{title:`Add another machine`,description:`Create a machine token, then run the command it gives you on that machine.`}),(0,B.jsx)(Px,{})]})]})]})}function Rx({className:e,orientation:t=`horizontal`,...n}){return(0,B.jsx)(ub,{"data-slot":`tabs`,"data-orientation":t,className:Q(`group/tabs flex gap-2 data-horizontal:flex-col`,e),...n})}var zx=rp(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function Bx({className:e,variant:t=`default`,...n}){return(0,B.jsx)(fb,{"data-slot":`tabs-list`,"data-variant":t,className:Q(zx({variant:t}),e),...n})}function Vx({className:e,...t}){return(0,B.jsx)(mb,{"data-slot":`tabs-trigger`,className:Q(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent`,`data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground`,`after:absolute after:bg-primary after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100`,e),...t})}function Hx({className:e,...t}){return(0,B.jsx)(gb,{"data-slot":`tabs-content`,className:Q(`flex-1 text-sm outline-none`,e),...t})}var Ux=e=>e?`${(e/1e9).toFixed(e<1e9?2:1)} GB`:``;function Wx(e,t,n){sessionStorage.setItem(`pick.${e}`,t),window.location.hash=n}var Gx=e=>{let t=e.toLowerCase();return t.includes(`qwen`)?`qwen`:t.includes(`llama`)?`llama`:t.includes(`gemma`)?`gemma`:t.includes(`smollm`)?`smollm`:`other`};function Kx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(`?`),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(`all`),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)({}),m=(0,_.useCallback)(()=>{Af().then(e=>{t(e.catalog),r(e.recent.filter(t=>!e.catalog.some(e=>e.id===t))),a(e.server_backend)}).catch(()=>{})},[]);(0,_.useEffect)(()=>{m()},[m]);async function h(e){let t=e.trim();if(t)try{await Nf(t),d(``),m()}catch{}}async function g(e){try{await Pf(e),m()}catch{}}(0,_.useEffect)(()=>{let e=()=>jf().then(e=>p(e.downloads)).catch(()=>{});e();let t=setInterval(e,1500);return()=>clearInterval(t)},[]);async function v(e){p(t=>({...t,[e]:{state:`downloading`,total:0}}));try{let t=await Mf(e);p(n=>({...n,[e]:t}))}catch{}}let y=(0,_.useMemo)(()=>[...n.map(e=>({id:e,note:`recently trained here`})),...e],[n,e]),b=[`all`,...Array.from(new Set(y.map(e=>Gx(e.id))))],x=y.filter(e=>e.id.toLowerCase().includes(o.toLowerCase())&&(c===`all`||Gx(e.id)===c));return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Models`,description:`Any open model on the Hugging Face hub works; these are good starting points. Server backend: ${i}.`,actions:rf(`operator`)&&(0,B.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),h(u)},children:[(0,B.jsx)(Jb,{value:u,onChange:e=>d(e.target.value),placeholder:`org/model, any HF id`,className:`w-56 font-mono`}),(0,B.jsxs)($,{type:`submit`,disabled:!u.trim(),children:[(0,B.jsx)(Ee,{}),` Add`]})]})}),(0,B.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,B.jsxs)(`div`,{className:`relative max-w-sm min-w-[220px] flex-1`,children:[(0,B.jsx)(Oe,{className:`pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(Jb,{value:o,onChange:e=>s(e.target.value),placeholder:`Search models…`,className:`pl-8`})]}),(0,B.jsx)(Rx,{value:c,onValueChange:l,children:(0,B.jsx)(Bx,{children:b.map(e=>(0,B.jsx)(Vx,{value:e,className:`px-2.5 capitalize`,children:e},e))})})]}),x.length===0?(0,B.jsx)(ix,{icon:ae,title:`No models match`,children:`Clear the search, or add any Hugging Face model id above.`}):(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-3 @2xl:grid-cols-2 @5xl:grid-cols-3`,children:x.map(e=>{let t=f[e.id],n=e.cached||t?.state===`ready`,r=t?.state===`downloading`;return(0,B.jsxs)(`div`,{className:`flex flex-col border border-border bg-card p-4 transition-colors hover:border-border-strong`,children:[(0,B.jsxs)(`div`,{className:`mb-2 flex items-start justify-between gap-2`,children:[(0,B.jsx)(`span`,{className:`grid size-7 shrink-0 place-items-center rounded-md border border-border bg-surface/60`,children:(0,B.jsx)(ae,{className:`size-3.5 text-muted-foreground`,strokeWidth:1.75})}),(0,B.jsxs)(`span`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[n&&(0,B.jsxs)(ex,{variant:`outline`,className:`border-good/30 bg-good/10 font-normal text-good`,children:[(0,B.jsx)(oe,{}),` On disk`]}),e.dev&&(0,B.jsx)(ex,{variant:`secondary`,className:`font-normal`,children:`Dev pick`}),e.gated&&(0,B.jsx)(ex,{variant:`outline`,className:`border-warning/30 bg-warning/10 font-normal text-warning`,children:`HF token`}),e.custom&&rf(`operator`)&&(0,B.jsx)($,{variant:`ghost`,size:`icon-xs`,title:`Remove from library`,"aria-label":`Remove ${e.id}`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>g(e.id),children:(0,B.jsx)(Fe,{})})]})]}),(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:e.id.split(`/`).pop()}),(0,B.jsxs)(`div`,{className:`mt-0.5 truncate text-muted-foreground`,children:[(0,B.jsx)(sx,{children:e.id}),e.params?(0,B.jsxs)(`span`,{className:`text-xs`,children:[` · `,e.params]}):``]}),e.note&&(0,B.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e.note}),r&&(0,B.jsxs)(`div`,{className:`mt-3`,children:[(0,B.jsx)(`div`,{className:`h-1 overflow-hidden rounded-full bg-muted`,children:(0,B.jsx)(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${t.pct??5}%`}})}),(0,B.jsxs)(`div`,{className:`mt-1 flex items-center gap-1 text-xs text-muted-foreground tabular-nums`,children:[(0,B.jsx)(_e,{className:`size-3 animate-spin`}),t.pct==null?`downloading…`:`${t.pct}% · ${Ux(t.downloaded)} / ${Ux(t.total)}`]})]}),t?.state===`error`&&(0,B.jsxs)(`div`,{className:`mt-2 flex items-center gap-1 truncate text-xs text-destructive`,title:t.error??``,children:[(0,B.jsx)(Ne,{className:`size-3 shrink-0`}),` `,t.error]}),(0,B.jsxs)(`div`,{className:`mt-auto flex gap-2 pt-4`,children:[(0,B.jsx)($,{className:`flex-1`,onClick:()=>Wx(`model`,e.id,`#train`),children:`Fine-tune`}),(0,B.jsx)($,{variant:`outline`,onClick:()=>Wx(`model`,e.id,`#playground`),children:`Try`}),!n&&!r&&rf(`operator`)&&(0,B.jsx)($,{variant:`outline`,size:`icon`,title:`Prefetch weights to disk`,"aria-label":`Download ${e.id}`,onClick:()=>v(e.id),children:(0,B.jsx)(M,{})})]})]},e.id)})})]})}function qx(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(`mlx-community/Qwen2.5-0.5B-Instruct-4bit`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)([]),[C,w]=(0,_.useState)([]),[T,ee]=(0,_.useState)(!1),[te,E]=(0,_.useState)(!1),[ne,ie]=(0,_.useState)(``),ae=(0,_.useRef)(null),ce=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!rf(`operator`))return;let e=!1;ie(``);let t=f&&o?[o,null]:[o],n=async()=>{try{let r=await Promise.all(t.map(e=>Zf(i,e,e?u:null)));if(e)return;let a=r.find(e=>e.error);if(a){E(!1),ie(a.error);return}if(r.every(e=>e.ready)){E(!1);return}E(!0),setTimeout(n,3e3)}catch{e||E(!1)}};return n(),()=>{e=!0}},[i,o,u,f]),(0,_.useEffect)(()=>{Af().then(e=>{let n=[...e.recent,...e.catalog.map(e=>e.id)];if(t([...new Set(n)].map(t=>e.catalog.find(e=>e.id===t)??{id:t})),e.server_backend!==`mlx`&&!sessionStorage.getItem(`pick.model`)){let e=n.find(e=>!e.startsWith(`mlx-community/`));e&&a(t=>t.startsWith(`mlx-community/`)?e:t)}}).catch(()=>{}),Wf().then(({jobs:e})=>{r(e);let t=sessionStorage.getItem(`pick.adapter`),n=sessionStorage.getItem(`pick.model`);n&&(a(n),sessionStorage.removeItem(`pick.model`)),t&&(s(t),p(!0),sessionStorage.removeItem(`pick.adapter`))}).catch(()=>{})},[]),(0,_.useEffect)(()=>{ae.current?.focus()}),(0,_.useEffect)(()=>{ce.current&&(ce.current.scrollTop=1e9)},[x,C]),(0,_.useEffect)(()=>{l([]),d(null),o&&Jf(o).then(({checkpoints:e})=>{l(e);let t=sessionStorage.getItem(`pick.checkpoint`);t&&e.some(e=>!e.final&&e.step===Number(t))&&d(Number(t)),sessionStorage.removeItem(`pick.checkpoint`)}).catch(()=>{})},[o]);let O=n.filter(e=>e.status===`succeeded`),le=O.find(e=>e.job_id===o),ue=o?le?.name?.trim()||`${o.slice(0,8)} · ${le?.method??`finetuned`}`:i.split(`/`).pop(),de=(0,_.useMemo)(()=>{let t=g.toLowerCase(),n=e.filter(e=>e.id.toLowerCase().includes(t));return g&&!e.some(e=>e.id.toLowerCase()===t)&&n.push({id:g.trim()}),n},[e,g]),k=O.filter(e=>{let t=g.toLowerCase();return e.job_id.includes(g)||(e.name||``).toLowerCase().includes(t)||(e.base_model||``).toLowerCase().includes(t)});function A(e){a(e),s(null),p(!1),h(!1)}function j(e){s(e.job_id),a(e.base_model),p(!0),h(!1)}async function fe(){let e=y.trim();if(!e||T)return;b(``);let t=[...x,{role:`user`,content:e}];S(t);let n=f&&o;n&&w(t=>[...t,{role:`user`,content:e}]),ee(!0);let r=e=>e.replace(/[\s\S]*?<\/think>/g,``).trim()||e.trim(),a=(e,t)=>Qf({model:i,adapter:e,checkpoint:e?u:null,messages:t,max_new_tokens:256,temperature:.7,top_p:.95}).then(e=>r(e.text)).catch(e=>`⚠ ${e.message}`);try{let r=a(o,t).then(e=>S(t=>[...t,{role:`assistant`,content:e}]));if(n){let t=a(null,[...C,{role:`user`,content:e}]).then(e=>w(t=>[...t,{role:`assistant`,content:e}]));await Promise.all([r,t])}else await r}finally{ee(!1)}}let M=x.length===0;return(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-1 !shrink flex-col overflow-hidden border border-border bg-card`,children:[(0,B.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 border-b border-border px-4`,children:[(0,B.jsx)(ye,{className:`size-4 shrink-0 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsxs)(`button`,{onClick:()=>{h(e=>!e),v(``)},className:`flex min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-sm font-semibold transition-colors hover:bg-surface-2`,children:[(0,B.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:o?`Shadow`:`Base`}),(0,B.jsx)(`span`,{className:Q(`truncate`,o&&`text-primary`),children:ue}),(0,B.jsx)(se,{className:`size-3.5 shrink-0 text-muted-foreground`})]}),o&&(0,B.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked)}),`Shadow mode `,(0,B.jsx)(`span`,{className:`text-muted-foreground/70`,children:`(base ↔ shadow)`})]}),o&&c.length>1&&(0,B.jsxs)(`div`,{className:`flex items-center gap-0.5 rounded-lg border border-border p-0.5 font-mono text-[11px]`,children:[(0,B.jsx)(`span`,{className:`px-1.5 text-muted-foreground select-none`,children:`ckpt`}),c.map(e=>{let t=e.final?u===null:u===e.step;return(0,B.jsx)(`button`,{title:e.path,onClick:()=>d(e.final?null:e.step),className:Q(`rounded-md px-2 py-0.5 transition-colors`,t?`bg-primary/10 text-primary`:`text-muted-foreground hover:text-foreground`),children:e.final?`final`:e.step},e.path)})]}),x.length>0&&(0,B.jsxs)($,{variant:`ghost`,size:`sm`,className:`ml-auto text-muted-foreground`,onClick:()=>{S([]),w([])},children:[(0,B.jsx)(De,{}),` Clear`]})]}),(0,B.jsx)(Bb,{open:m,onOpenChange:h,children:(0,B.jsxs)(Ub,{showCloseButton:!1,className:`top-[11vh] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-2xl data-open:zoom-in-100 data-closed:zoom-out-100`,children:[(0,B.jsx)(Kb,{className:`sr-only`,children:`Pick a model`}),(0,B.jsx)(qb,{className:`sr-only`,children:`Filter base models or your shadows, or paste any Hugging Face id.`}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2.5 border-b border-border px-4 py-3`,children:[(0,B.jsx)(Oe,{className:`size-4 shrink-0 text-muted-foreground`}),(0,B.jsx)(`input`,{autoFocus:!0,value:g,onChange:e=>v(e.target.value),"data-slot":`palette-input`,onKeyDown:e=>{e.key===`Escape`&&h(!1),e.key===`Enter`&&(de[0]&&(!k.length||g)?A(de[0].id):k[0]&&j(k[0]))},placeholder:`Filter base models or your shadows · paste any HF id`,className:`flex-1 border-0 bg-transparent p-0 text-sm outline-none placeholder:text-muted-foreground`}),(0,B.jsx)(`kbd`,{className:`rounded border border-border px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:`esc`})]}),(0,B.jsxs)(`div`,{className:`max-h-[58vh] overflow-auto py-1.5 scrollbar-thin`,children:[(0,B.jsx)(`div`,{className:`px-4 pt-2 pb-1 text-[11px] font-medium text-muted-foreground`,children:`Base · open models`}),de.map(e=>{let t=e.id===i&&!o;return(0,B.jsxs)(`button`,{onClick:()=>A(e.id),className:`group flex w-full items-center gap-3 px-4 py-2 text-left text-sm hover:bg-subtle`,children:[(0,B.jsx)(`span`,{className:`w-3.5 shrink-0`,children:t?(0,B.jsx)(oe,{className:`size-3.5 text-primary`}):(0,B.jsx)(D,{className:`size-3.5 text-muted-foreground/40 group-hover:text-primary`})}),(0,B.jsx)(`span`,{className:Q(`flex-1 truncate font-mono text-[13px]`,t&&`text-primary`),children:e.id}),(0,B.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:e.dev?`dev pick`:e.gated?`HF token`:e.params??e.note??``})]},e.id)}),(0,B.jsx)(`div`,{className:`mt-1.5 border-t border-border px-4 pt-3 pb-1 text-[11px] font-medium text-muted-foreground`,children:`Shadows · your runs`}),k.length?k.map(e=>{let t=e.job_id===o;return(0,B.jsxs)(`button`,{onClick:()=>j(e),className:`group flex w-full items-center gap-3 px-4 py-2 text-left text-sm hover:bg-subtle`,children:[(0,B.jsx)(`span`,{className:`w-3.5 shrink-0`,children:t?(0,B.jsx)(oe,{className:`size-3.5 text-primary`}):(0,B.jsx)(D,{className:`size-3.5 text-muted-foreground/40 group-hover:text-primary`})}),(0,B.jsxs)(`span`,{className:Q(`flex-1 truncate`,t&&`text-primary`),children:[e.name?.trim()||(0,B.jsx)(`span`,{className:`font-mono text-[13px]`,children:e.job_id.slice(0,10)}),(0,B.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.method]})]}),(0,B.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[`shadows `,(e.base_model||``).split(`/`).pop()]})]},e.job_id)}):(0,B.jsxs)(`div`,{className:`px-4 py-3 text-sm text-muted-foreground`,children:[`No shadows yet. `,(0,B.jsx)(`a`,{href:`#train`,className:`font-medium text-primary hover:underline`,children:`Train one`}),` to see it here.`]})]})]})}),(0,B.jsx)(`div`,{ref:ce,className:`min-h-0 flex-1 overflow-auto px-6 scrollbar-thin`,onClick:()=>m&&h(!1),children:M?(0,B.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center`,children:[(0,B.jsx)(`img`,{src:`/logo.png`,alt:``,className:`mb-2 size-28 dark:hidden [filter:drop-shadow(0_0_40px_#e5484d55)_drop-shadow(0_0_14px_#e5484d44)]`}),(0,B.jsx)(`img`,{src:`/logo1.png`,alt:``,className:`mb-2 hidden size-28 dark:block [filter:drop-shadow(0_0_40px_#ffffff33)_drop-shadow(0_0_14px_#ffffff22)]`}),(0,B.jsx)(`h1`,{className:`text-xl font-semibold tracking-[-0.015em]`,children:o?`Does it cast the same shadow?`:`Talk to a model`}),(0,B.jsxs)(`p`,{className:`text-[13px] text-muted-foreground`,children:[`Base `,(0,B.jsx)(`span`,{className:`font-mono text-foreground`,children:i.split(`/`).pop()}),o&&(0,B.jsxs)(B.Fragment,{children:[` · shadow `,(0,B.jsx)(`span`,{className:`font-mono text-primary`,children:o.slice(0,8)})]})]})]}):f&&o?(0,B.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4 py-6`,children:[x.map((e,t)=>e.role===`user`?(0,B.jsx)(Jx,{text:e.content},t):(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,B.jsx)(Yx,{tone:`tuned`,label:`Shadow`,text:e.content}),(0,B.jsx)(Yx,{tone:`base`,label:`Base`,text:C[t]?.content})]},t)),T&&(0,B.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,B.jsx)(Yx,{tone:`tuned`,label:`Shadow`}),(0,B.jsx)(Yx,{tone:`base`,label:`Base`})]})]}):(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-4 py-6`,children:[x.map((e,t)=>e.role===`user`?(0,B.jsx)(Jx,{text:e.content},t):(0,B.jsxs)(`div`,{className:`text-[13px] leading-relaxed`,children:[(0,B.jsx)(`div`,{className:`mb-1 font-mono text-[11px] text-muted-foreground`,children:ue}),(0,B.jsx)(`div`,{className:`whitespace-pre-wrap`,children:e.content})]},t)),T&&(0,B.jsx)(dx,{})]})}),(0,B.jsxs)(`div`,{className:`shrink-0 border-t border-border p-3`,children:[(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-end gap-2`,children:[(0,B.jsx)(`textarea`,{ref:ae,value:y,rows:1,"data-slot":`composer`,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),fe())},placeholder:rf(`operator`)?te?`Warming up the model — first load can take a couple of minutes…`:`Say something to the shadow…`:af(`operator`),disabled:!rf(`operator`),className:`field-sizing-content max-h-40 min-h-9 min-w-0 grow resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-[13px] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50`}),(0,B.jsx)($,{size:`icon`,className:`size-9`,"aria-label":`Send`,onClick:fe,disabled:!y.trim()||T||te||!rf(`operator`),children:T?(0,B.jsx)(_e,{className:`size-3.5 animate-spin`}):(0,B.jsx)(re,{className:`size-4`})})]}),(0,B.jsx)(`div`,{className:`mx-auto mt-1.5 max-w-3xl text-center text-[11px] text-muted-foreground`,children:ne?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,B.jsx)(Ne,{className:`size-3`}),` Can't load this model here: `,ne]}):te?(0,B.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-primary`,children:[(0,B.jsx)(_e,{className:`size-3 animate-spin`}),` Loading weights onto the GPU — send unlocks when it's hot`]}):`Enter to send · Shift+Enter for a new line`})]})]})}function Jx({text:e}){return(0,B.jsx)(`div`,{className:`flex justify-end`,children:(0,B.jsx)(`div`,{className:`max-w-[85%] border border-border bg-subtle px-3 py-2 text-[13px] whitespace-pre-wrap`,children:e})})}function Yx({tone:e,label:t,text:n}){return(0,B.jsxs)(`div`,{className:Q(`border bg-card px-3.5 py-2.5 text-[13px] leading-relaxed`,e===`tuned`?`border-primary/30`:`border-border`),children:[(0,B.jsx)(`div`,{className:Q(`mb-1.5 text-[11px] font-medium`,e===`tuned`?`text-primary`:`text-muted-foreground`),children:t}),(0,B.jsx)(`span`,{className:`whitespace-pre-wrap`,children:n??(0,B.jsx)(dx,{})})]})}function Xx({initialId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(e||null),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`all`),[l,u]=(0,_.useState)({});(0,_.useEffect)(()=>{e&&i(e)},[e]),(0,_.useEffect)(()=>{let e=async()=>{try{let{jobs:e}=await Wf();n(e),i(t=>t??e[0]?.job_id??null);let t=await Promise.all(e.slice(0,20).map(async e=>{try{let t=await Kf(e.job_id);return[e.job_id,t.steps.map(e=>e.loss)]}catch{return[e.job_id,[]]}}));u(Object.fromEntries(t))}catch{}};e();let t=setInterval(e,2500);return()=>clearInterval(t)},[]);let d=t.filter(e=>(s===`all`||e.status===s)&&(a===``||e.base_model.toLowerCase().includes(a.toLowerCase())||(e.name||``).toLowerCase().includes(a.toLowerCase())||e.job_id.includes(a))),f=t.find(e=>e.job_id===r)??null;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Training runs`,description:`Every finetune persists its config, metrics, and artifact. Watch live, compare in the playground, download the adapter.`}),(0,B.jsxs)(`div`,{className:`grid min-h-[520px] flex-1 !shrink grid-cols-1 overflow-hidden border border-border bg-card lg:grid-cols-[minmax(0,1fr)_minmax(0,1.6fr)]`,children:[(0,B.jsxs)(`div`,{className:`flex min-h-0 flex-col border-b border-border lg:border-r lg:border-b-0`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border p-3`,children:[(0,B.jsxs)(`div`,{className:`relative flex-1`,children:[(0,B.jsx)(Oe,{className:`pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(Jb,{value:a,onChange:e=>o(e.target.value),placeholder:`Search runs…`,className:`pl-8`})]}),(0,B.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`h-8 text-sm`,children:[(0,B.jsx)(`option`,{value:`all`,children:`All status`}),(0,B.jsx)(`option`,{value:`succeeded`,children:`Succeeded`}),(0,B.jsx)(`option`,{value:`running`,children:`Running`}),(0,B.jsx)(`option`,{value:`failed`,children:`Failed`}),(0,B.jsx)(`option`,{value:`stopped`,children:`Stopped`})]})]}),(0,B.jsxs)(`div`,{className:`min-h-0 flex-1 divide-y divide-border overflow-auto scrollbar-thin`,children:[d.length===0&&(0,B.jsx)(`div`,{className:`p-4`,children:(0,B.jsxs)(ix,{icon:me,title:`No runs yet`,children:[`Start one in `,(0,B.jsx)(`a`,{href:`#train`,className:`font-medium text-primary hover:underline`,children:`New run`}),`.`]})}),d.map(e=>(0,B.jsxs)(`button`,{onClick:()=>{i(e.job_id),window.location.hash=`#runs/${e.job_id}`},"aria-current":r===e.job_id?`true`:void 0,className:Q(`w-full border-l-2 px-4 py-3 text-left transition-colors`,r===e.job_id?`border-l-primary bg-primary/5`:`border-l-transparent hover:bg-subtle`),children:[(0,B.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,B.jsx)(`span`,{className:`truncate font-mono text-[11px] text-muted-foreground`,children:e.name?.trim()||e.job_id.slice(0,12)}),(0,B.jsx)(ux,{status:e.status})]}),(0,B.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.base_model}),(0,B.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-2`,children:[(0,B.jsxs)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,children:[e.method??`?`,` · `,e.steps,` steps`]}),(0,B.jsx)(`span`,{className:e.status===`failed`?`text-destructive`:`text-primary`,children:(0,B.jsx)(Xb,{data:l[e.job_id]??[],width:64,height:20})})]})]},e.job_id))]})]}),f?(0,B.jsx)(Qx,{run:f},f.job_id):(0,B.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Select a run to see its curves, logs and artifact.`})]})]})}function Zx({title:e,sub:t,actions:n,children:r,className:i}){return(0,B.jsxs)(`section`,{className:Q(`overflow-hidden border border-border bg-card`,i),children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-border px-4 py-2.5`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),t&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t})]}),n]}),r]})}function Qx({run:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(`loss`);(0,_.useEffect)(()=>{let t=!0,r=async()=>{try{let[r,a,s]=await Promise.all([Gf(e.job_id),Kf(e.job_id),qf(e.job_id)]);if(!t)return;n(r),i(a.steps),o(a.evals),c(s.logs),r.checkpoint&&Jf(e.job_id).then(({checkpoints:e})=>t&&u(e)).catch(()=>{})}catch{}};r();let a=setInterval(r,1800);return()=>{t=!1,clearInterval(a)}},[e.job_id]);let p=r[r.length-1];async function m(){let t=await _f(`/v1/finetunes/${e.job_id}/artifact`);if(!t.ok){let e=(await vf(t)).message;return Bd?t.status!==403&&ff(`error`,e):alert(e)}let n=await t.blob(),r=document.createElement(`a`);r.href=URL.createObjectURL(n),r.download=`${e.job_id}-adapter.tar.gz`,r.click(),URL.revokeObjectURL(r.href)}let h=t?.status??e.status;return(0,B.jsx)(`div`,{className:`min-h-0 overflow-auto scrollbar-thin`,children:(0,B.jsxs)(`div`,{className:`max-w-[1000px] space-y-5 p-5`,children:[(0,B.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-4`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[e.name?.trim()&&(0,B.jsx)(`span`,{className:`text-sm font-semibold text-primary`,children:e.name.trim()}),(0,B.jsx)(sx,{className:`text-muted-foreground`,children:e.job_id}),(0,B.jsx)(ux,{status:h})]}),(0,B.jsx)(`h2`,{className:`text-lg font-semibold tracking-[-0.01em]`,children:e.base_model}),(0,B.jsxs)(`p`,{className:`mt-0.5 font-mono text-xs text-muted-foreground`,children:[e.method??`?`,p?.tokens_per_s?` · ${Math.round(p.tokens_per_s)} tok/s`:``]})]}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(t?.status===`running`||t?.status===`pending`)&&rf(`operator`)&&(0,B.jsxs)($,{variant:`destructive`,onClick:()=>Yf(e.job_id).catch(()=>{}),children:[(0,B.jsx)(Ae,{}),` Cancel`]}),t?.status===`succeeded`&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)($,{variant:`outline`,onClick:()=>{sessionStorage.setItem(`pick.adapter`,e.job_id),sessionStorage.setItem(`pick.model`,e.base_model),window.location.hash=`#playground`},children:[(0,B.jsx)(ye,{}),` Playground`]}),rf(`operator`)&&(0,B.jsxs)($,{variant:`outline`,onClick:m,children:[(0,B.jsx)(M,{}),` Adapter`]})]})]})]}),(0,B.jsxs)(ax,{children:[(0,B.jsx)(ox,{label:`Final loss`,value:t?.final_loss==null?p?p.loss.toFixed(4):void 0:t.final_loss.toFixed(4)}),(0,B.jsx)(ox,{label:`Eval loss`,value:a.length?a[a.length-1].loss.toFixed(4):void 0}),(0,B.jsx)(ox,{label:`Steps`,value:String(p?.step??0)}),(0,B.jsx)(ox,{label:`Learning rate`,value:p?p.lr.toExponential(1):void 0})]}),t?.error&&(0,B.jsxs)(`section`,{className:`border border-destructive/30 bg-destructive/5 p-4`,children:[(0,B.jsxs)(`h3`,{className:`mb-2 flex items-center gap-1.5 text-sm font-semibold text-destructive`,children:[(0,B.jsx)(O,{className:`size-4`}),` Why it failed`]}),(0,B.jsx)(`pre`,{className:`max-h-40 overflow-auto font-mono text-xs whitespace-pre-wrap text-destructive`,children:t.error})]}),(0,B.jsxs)(Rx,{value:d,onValueChange:e=>f(e),className:`gap-4`,children:[(0,B.jsxs)(Bx,{variant:`line`,className:`w-full justify-start border-b border-border`,children:[(0,B.jsx)(Vx,{value:`loss`,className:`flex-none`,children:`Loss curves`}),(0,B.jsxs)(Vx,{value:`logs`,className:`flex-none`,children:[`Training logs`,t?.status===`running`&&(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`})]}),(0,B.jsx)(Vx,{value:`artifact`,className:`flex-none`,children:`Artifact`})]}),(0,B.jsxs)(Hx,{value:`loss`,className:`space-y-4`,children:[(0,B.jsx)(Zx,{title:`Loss`,sub:`train (raw + EMA) with eval overlaid`,actions:(0,B.jsx)(Qb,{}),children:(0,B.jsx)(`div`,{className:`p-4`,children:(0,B.jsx)(Zb,{steps:r,evals:a})})}),(0,B.jsxs)(`div`,{className:`grid gap-4 @4xl:grid-cols-2`,children:[(0,B.jsx)(Zx,{title:`Training loss`,sub:`raw + EMA overlay`,children:(0,B.jsx)(`div`,{className:`p-4`,children:(0,B.jsx)(Zb,{steps:r,evals:[]})})}),(0,B.jsx)(Zx,{title:`Eval loss`,sub:`held-out validation`,children:(0,B.jsx)(`div`,{className:`p-4`,children:a.length?(0,B.jsx)(Zb,{steps:a,evals:[]}):(0,B.jsx)(`div`,{className:`flex h-[240px] items-center justify-center text-center`,children:(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`div`,{className:`text-sm font-medium text-muted-foreground`,children:`No eval data`}),(0,B.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:`Train with a held-out eval split to see this`})]})})})})]})]}),(0,B.jsx)(Hx,{value:`logs`,children:s.length?(0,B.jsx)($x,{logs:s,live:t?.status===`running`}):(0,B.jsx)(ix,{icon:ke,title:`No console output`,children:`Nothing was captured for this run.`})}),(0,B.jsx)(Hx,{value:`artifact`,className:`space-y-4`,children:t?.checkpoint?(0,B.jsxs)(Zx,{title:`Trained adapter`,children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 text-sm`,children:[(0,B.jsxs)(`div`,{className:`min-w-0`,children:[(0,B.jsx)(sx,{className:`text-muted-foreground`,children:t.checkpoint}),(0,B.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Load it back: `,(0,B.jsxs)(`code`,{className:`font-mono text-foreground/80`,children:[`slm.load("`,e.base_model,`", adapter="…")`]})]})]}),rf(`operator`)&&(0,B.jsxs)($,{variant:`outline`,onClick:m,children:[(0,B.jsx)(M,{}),` tar.gz`]})]}),l.length>1&&(0,B.jsxs)(`div`,{className:`border-t border-border`,children:[(0,B.jsxs)(`div`,{className:`px-4 pt-3 pb-1 text-xs text-muted-foreground`,children:[`Saved versions · `,l.length]}),(0,B.jsx)(`div`,{className:`divide-y divide-border`,children:[...l].reverse().map(t=>(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-2 text-sm`,children:[(0,B.jsx)(`span`,{className:`font-mono text-xs`,children:t.final?(0,B.jsx)(`span`,{className:`text-primary`,children:t.label}):`step ${t.step}`}),(0,B.jsxs)($,{variant:`ghost`,size:`xs`,className:`text-primary`,onClick:()=>{sessionStorage.setItem(`pick.adapter`,e.job_id),sessionStorage.setItem(`pick.model`,e.base_model),t.final?sessionStorage.removeItem(`pick.checkpoint`):sessionStorage.setItem(`pick.checkpoint`,String(t.step)),window.location.hash=`#playground`},children:[(0,B.jsx)(ye,{}),` Test this version`]})]},t.path))}),(0,B.jsxs)(`div`,{className:`px-4 py-2 text-[11px] text-muted-foreground`,children:[`Trained with `,(0,B.jsx)(`code`,{className:`font-mono text-foreground/70`,children:`save_steps`}),`: each is a point you can roll back to or A/B in the playground.`]})]})]}):!t?.error&&(0,B.jsx)(ix,{icon:Se,title:`No artifact yet`,children:`It appears when training succeeds.`})})]})]})})}function $x({logs:e,live:t}){let n=(0,_.useRef)(null),[r,i]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{r&&n.current&&(n.current.scrollTop=n.current.scrollHeight)},[e,r]),(0,B.jsxs)(`section`,{className:`overflow-hidden border border-border bg-card`,children:[(0,B.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-border px-4 py-2.5`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(ke,{className:`size-4 text-muted-foreground`,strokeWidth:1.75}),(0,B.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Training console`}),t&&(0,B.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary`,children:[(0,B.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),` live`]})]}),(0,B.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,B.jsx)(`input`,{type:`checkbox`,checked:r,onChange:e=>i(e.target.checked)}),` Follow`]})]}),(0,B.jsx)(`pre`,{ref:n,onScroll:e=>{let t=e.currentTarget;i(t.scrollHeight-t.scrollTop-t.clientHeight<24)},className:`m-0 max-h-[460px] overflow-auto bg-ink p-4 font-mono text-[11px] leading-[1.35] whitespace-pre text-bone/90 scrollbar-thin`,children:e.join(`
`)})]})}function eS({className:e,size:t=`default`,...n}){return(0,B.jsx)(Jy,{"data-slot":`switch`,"data-size":t,className:Q(`peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary/70 data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50`,e),...n,children:(0,B.jsx)(Xy,{"data-slot":`switch-thumb`,className:`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground`})})}var tS=[`Data`,`Model`,`Method`,`Tune`],nS=e=>e===`preference`?[`dpo`]:e===`text`?[`cpt`]:e===`prompt`?[`grpo`]:[`lora`,`qlora`,`dora`],rS=[{key:`max_steps`,label:`Max steps`,kind:`int`,def:`60`,hint:`total optimizer steps`},{key:`num_train_epochs`,label:`Epochs`,kind:`int`,def:``,hint:`overrides max steps when set`},{key:`learning_rate`,label:`Learning rate`,kind:`float`,def:``,hint:`blank = method default`},{key:`per_device_train_batch_size`,label:`Batch size`,kind:`int`,def:`2`},{key:`gradient_accumulation_steps`,label:`Grad accumulation`,kind:`int`,def:`4`},{key:`max_seq_length`,label:`Context length`,kind:`int`,def:`2048`},{key:`save_steps`,label:`Checkpoint every`,kind:`int`,def:``,hint:`save a version every N steps — test any of them later (blank = final only)`}],iS=[{key:`warmup_steps`,label:`Warmup steps`,kind:`int`,def:`5`},{key:`weight_decay`,label:`Weight decay`,kind:`float`,def:`0.01`},{key:`lr_scheduler_type`,label:`LR scheduler`,kind:`select`,def:`linear`,options:[`linear`,`cosine`,`constant`]},{key:`max_grad_norm`,label:`Grad clip`,kind:`float`,def:``,hint:`max grad norm (torch)`},{key:`optim`,label:`Optimizer`,kind:`select`,def:`adamw_8bit`,options:[`adamw_8bit`,`adamw_torch`,`adafactor`,`sgd`],hint:`torch; mlx uses Adam`},{key:`seed`,label:`Seed`,kind:`int`,def:`3407`}],aS=[{key:`packing`,label:`Pack sequences`,kind:`bool`,def:`false`,hint:`torch`},{key:`train_on_completions`,label:`Train on completions only`,kind:`bool`,def:`false`,hint:`mask the prompt (mlx)`}],oS=[{key:`lora_r`,label:`LoRA rank`,kind:`int`,def:`16`},{key:`lora_alpha`,label:`LoRA alpha`,kind:`int`,def:`16`},{key:`lora_dropout`,label:`LoRA dropout`,kind:`float`,def:`0`},{key:`target_modules`,label:`Target modules`,kind:`select`,def:`all`,options:[`all`,`attention`,`mlp`]},{key:`use_rslora`,label:`Rank-stabilized (rsLoRA)`,kind:`bool`,def:`false`,hint:`torch`}],sS={more:[{key:`retrieval_k`,label:`Retrieval k`,kind:`int`,def:`2`,hint:`memories per token`},{key:`retrieval_layers`,label:`Retrieval layers`,kind:`int`,def:`8`}],more_plus:[{key:`more_plus_k`,label:`Experts / query`,kind:`int`,def:`1`,hint:`experts merged per prompt (>1 can interfere)`},{key:`more_plus_expert_steps`,label:`Steps / expert`,kind:`int`,def:`0`,hint:`0 = auto (scales with model size)`},{key:`more_plus_group_size`,label:`Rows / expert`,kind:`int`,def:`1`,hint:`dataset rows folded into one expert`},{key:`lora_r`,label:`Expert LoRA rank`,kind:`int`,def:`4`},{key:`lora_alpha`,label:`Expert LoRA alpha`,kind:`int`,def:`4`}],dpo:[{key:`beta`,label:`Beta (KL)`,kind:`float`,def:`0.1`,hint:`higher = stay closer to reference`}],grpo:[{key:`beta`,label:`Beta (KL)`,kind:`float`,def:`0.1`},{key:`grpo_group_size`,label:`Group size`,kind:`int`,def:`4`,hint:`completions per prompt`},{key:`grpo_max_completion_length`,label:`Max completion`,kind:`int`,def:`256`}],prompt:[{key:`num_virtual_tokens`,label:`Virtual tokens`,kind:`int`,def:`16`}],ptuning:[{key:`num_virtual_tokens`,label:`Virtual tokens`,kind:`int`,def:`16`}]};function cS(e){return e===`lora`||e===`dora`||e===`more`?oS:e===`bottleneck`?[{key:`lora_r`,label:`Adapter width (r)`,kind:`int`,def:`16`}]:[]}function lS(e){return e?[...cS(e.adapter),...sS[e.name]??[]]:[]}function uS(e){return[...iS,...e?.trainer===`sft`?aS:[]]}function dS(e){return[...rS,...lS(e),...uS(e)]}var fS={lora:`peft`,qlora:`peft`,dora:`peft`,adapter:`peft`,bitfit:`peft`,prompt:`peft`,ptuning:`peft`,full:`sft`,cpt:`sft`,dpo:`rl`,grpo:`rl`,more:`memory`,more_plus:`memory`},pS={peft:`PEFT · parameter-efficient`,sft:`SFT · full & continued pretraining`,rl:`Preference & RL`,memory:`Memory · retrieval`,other:`Other`},mS=[`peft`,`sft`,`rl`,`memory`,`other`],hS=e=>fS[e]??`other`;function gS({methods:e}){let[t,n]=(0,_.useState)(0),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(``),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(()=>Object.fromEntries([...rS,...iS].map(e=>[e.key,e.def]))),[ee,te]=(0,_.useState)(!1),[E,ne]=(0,_.useState)(!1),[re,ie]=(0,_.useState)(`10`),[ae,O]=(0,_.useState)(!1),[le,ue]=(0,_.useState)(``),[de,k]=(0,_.useState)([]),[A,j]=(0,_.useState)(``);(0,_.useEffect)(()=>{Cf().then(e=>i(e.datasets)),Bf().then(e=>k(e.workers)).catch(()=>{}),Af().then(e=>{o(e.catalog),c(e.recent.filter(t=>!e.catalog.some(e=>e.id===t)))});let e=sessionStorage.getItem(`pick.dataset`),t=sessionStorage.getItem(`pick.model`),r=sessionStorage.getItem(`pick.method`),a=sessionStorage.getItem(`pick.steps`);e&&(u(e),n(1),sessionStorage.removeItem(`pick.dataset`)),t&&(f(t),n(t=>Math.max(t,e?2:0)),sessionStorage.removeItem(`pick.model`)),r&&(we(r),sessionStorage.removeItem(`pick.method`)),a&&(T(e=>({...e,max_steps:a})),sessionStorage.removeItem(`pick.steps`))},[]);let M=r.find(e=>e.dataset_id===l),pe=nS(M?.format),me=(0,_.useMemo)(()=>[...e].sort((e,t)=>Number(pe.includes(t.name))-Number(pe.includes(e.name))),[e,pe]),he=e.find(e=>e.name===p),ge=(0,_.useMemo)(()=>[...s.map(e=>({id:e,note:`recently trained here`})),...a],[s,a]).filter(e=>e.id.toLowerCase().includes(h.toLowerCase())),ve=lS(he),ye=uS(he),be=dS(he),xe=E&&he?.trainer!==`grpo`&&!M?.eval_split,Se=!!(l&&d&&p),Ce=[!!l,!!d,!!p,!0][t];function we(t){m(t);let n=e.find(e=>e.name===t);T(e=>{let t={...e};for(let e of lS(n))t[e.key]===void 0&&(t[e.key]=e.def);return t}),n&&!ee&&T(e=>({...e,learning_rate:String(n.default_lr)}))}let Ee=(e,t)=>{e===`learning_rate`&&te(!0),T(n=>({...n,[e]:t}))};function De(){let e={method:p};for(let t of be){let n=(w[t.key]??``).trim();if(t.kind===`bool`){n===`true`&&(e[t.key]=!0);continue}n!==``&&(e[t.key]=t.kind===`int`?parseInt(n):t.kind===`float`?parseFloat(n):n)}return e}async function ke(){if(!(!Se||S||!d||!l)){x(``),C(!0);try{let e=await Xf({base_model:d,name:le.trim(),config:De(),dataset_id:l,eval_dataset:xe?`${re}%`:null,worker:A||null,load_in_4bit:!1,max_seq_length:parseInt(w.max_seq_length||`2048`)});window.location.hash=`#runs/${e.job_id}`}catch(e){x(e.message),C(!1)}}}let Ae=(0,_.useMemo)(()=>{let e={max_steps:`--max-steps`,learning_rate:`--lr`,per_device_train_batch_size:`--batch-size`,lora_r:`--lora-r`},t=[`shadowlm finetune \\`,` --model ${d??``} \\`,` --method ${p??``}`];for(let n of be){let r=(w[n.key]??``).trim();if(n.kind===`bool`){r===`true`&&(t[t.length-1]+=` \\`,t.push(` --set ${n.key}=true`));continue}r===``||r===n.def&&n.key!==`max_steps`||(t[t.length-1]+=` \\`,t.push(e[n.key]?` ${e[n.key]} ${r}`:` --set ${n.key}=${r}`))}return xe&&(t[t.length-1]+=` \\`,t.push(` --eval ${re}%`)),t.join(`
`)},[d,p,w,be,E,re]),je=e=>(w[e]??``).trim();return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(nx,{title:`Configure and start training`,description:`Four decisions, in the order they depend on each other — the data ranks the methods, the method shapes the form.`}),(0,B.jsxs)(`div`,{className:`grid max-w-[1400px] grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,B.jsxs)(`div`,{className:`min-w-0 space-y-6`,children:[(0,B.jsx)(`ol`,{className:`grid grid-cols-2 gap-px overflow-hidden border border-border bg-border @2xl:grid-cols-4`,children:tS.map((e,r)=>{let i=r===t,a=r(a||i)&&n(r),"aria-current":i?`step`:void 0,disabled:!a&&!i,className:Q(`flex w-full items-center gap-2.5 px-4 py-3 text-left text-sm transition-colors disabled:cursor-default`,i?`bg-primary/10 text-primary`:a?`text-foreground hover:bg-surface`:`text-muted-foreground`),children:[(0,B.jsx)(`span`,{className:Q(`grid size-5 shrink-0 place-items-center rounded-full border text-[11px] tabular-nums`,i?`border-primary/30 bg-primary/10`:a?`border-good/30 bg-good/10 text-good`:`border-border`),children:a?(0,B.jsx)(oe,{className:`size-3`}):r+1}),(0,B.jsx)(`span`,{className:`font-medium`,children:e})]})},e)})}),t===0&&(0,B.jsxs)(_S,{children:[(0,B.jsx)(rx,{title:`Dataset`,description:`The data decides what training even means — formats are auto-detected and steer the method choice.`}),r.length===0?(0,B.jsxs)(ix,{icon:fe,title:`No datasets on this server yet`,children:[(0,B.jsx)(`a`,{href:`#datasets`,className:`text-primary hover:underline`,children:`Upload one`}),` first.`]}):(0,B.jsx)(vS,{children:r.map(e=>(0,B.jsx)(yS,{selected:l===e.dataset_id,onClick:()=>u(e.dataset_id),title:e.name,sub:`${e.format}${e.rows==null?``:` · ${e.rows.toLocaleString()} rows`}`},e.dataset_id))})]}),t===1&&(0,B.jsxs)(_S,{children:[(0,B.jsx)(rx,{title:`Base model`,description:`The catalog, models trained here before, or any HF hub id.`}),(0,B.jsxs)(`div`,{className:`relative mb-2`,children:[(0,B.jsx)(Oe,{className:`pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,B.jsx)(Jb,{value:h,onChange:e=>g(e.target.value),placeholder:`Search models…`,className:`pl-8`})]}),(0,B.jsx)(vS,{className:`max-h-64`,children:ge.map(e=>(0,B.jsx)(yS,{selected:d===e.id,onClick:()=>f(e.id),title:e.id,sub:`${e.params??``}${e.note?` · ${e.note}`:``}${e.gated?` · needs HF token`:``}`},e.id))}),(0,B.jsxs)(`form`,{className:`mt-3 flex gap-2`,onSubmit:e=>{e.preventDefault(),v.trim()&&f(v.trim())},children:[(0,B.jsx)(Jb,{value:v,onChange:e=>y(e.target.value),placeholder:`org/model-name — any HF hub id`,className:`flex-1 font-mono`}),(0,B.jsx)($,{type:`submit`,variant:`outline`,children:`Use custom`})]})]}),t===2&&(0,B.jsxs)(_S,{children:[(0,B.jsx)(rx,{title:`Method`,description:(0,B.jsxs)(B.Fragment,{children:[`Your dataset is `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:M?.format??`?`}),` — recommended methods first.`]})}),(0,B.jsx)(`div`,{className:`space-y-5`,children:mS.map(e=>{let t=me.filter(t=>hS(t.name)===e);return t.length?(0,B.jsxs)(`div`,{children:[(0,B.jsx)(`p`,{className:`mb-1.5 text-xs font-medium text-muted-foreground`,children:pS[e]}),(0,B.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5 sm:grid-cols-3`,children:t.map(e=>(0,B.jsxs)(`button`,{onClick:()=>we(e.name),title:e.description,className:Q(`rounded-md border px-3 py-2 text-left text-sm transition-colors`,p===e.name?`border-primary/40 bg-primary/5`:`border-border bg-card hover:bg-surface`),children:[(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,B.jsx)(`span`,{className:Q(`font-medium`,p===e.name&&`text-primary`),children:e.name}),pe.includes(e.name)&&(0,B.jsx)(ex,{variant:`default`,className:`h-4 px-1.5 text-[10px]`,children:`rec`})]}),(0,B.jsxs)(`div`,{className:`mt-0.5 font-mono text-[11px] text-muted-foreground`,children:[`lr `,e.default_lr,` · `,e.trainer]})]},e.name))})]},e):null})}),he&&(0,B.jsx)(`p`,{className:`mt-4 text-sm text-muted-foreground`,children:he.description})]}),t===3&&(0,B.jsxs)(_S,{className:`space-y-6`,children:[(0,B.jsx)(cx,{label:`Name this shadow`,htmlFor:`run-name`,hint:`What it'll be called in Runs & the playground — optional, the run id is the fallback.`,children:(0,B.jsx)(Jb,{id:`run-name`,value:le,onChange:e=>ue(e.target.value),placeholder:`e.g. ${p??`support`}-${(d??``).split(`/`).pop()?.split(`-`)[0]?.toLowerCase()||`v1`}`,className:`font-mono`})}),de.length>0&&(0,B.jsx)(cx,{label:`Train on`,htmlFor:`run-device`,hint:"Connected devices (`shadowlm worker`) — the run streams back here either way.",children:(0,B.jsxs)(`select`,{id:`run-device`,value:A,onChange:e=>j(e.target.value),className:`w-full font-mono`,children:[(0,B.jsx)(`option`,{value:``,children:`this server`}),de.map(e=>(0,B.jsxs)(`option`,{value:e.name,disabled:!e.online,children:[e.name,` — `,e.backend,` · `,e.gpu_name||e.device,e.vram_gb?` · ${e.vram_gb} GB`:``,e.online?``:` (offline)`]},e.name))]})}),(0,B.jsxs)(`div`,{className:`border-t border-border pt-5`,children:[(0,B.jsx)(rx,{title:`Hyperparameters`,description:(0,B.jsxs)(B.Fragment,{children:[`Everything `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:p??`this method`}),` uses — defaults are sensible, the `,p,`-specific knobs are set apart below.`]})}),(0,B.jsx)(xS,{params:rS,vals:w,setVal:Ee,methodInfo:he,method:p})]}),ve.length>0&&(0,B.jsxs)(`div`,{className:`border-t border-border pt-5`,children:[(0,B.jsxs)(`p`,{className:`mb-3 text-xs font-medium text-primary`,children:[p,` settings`]}),(0,B.jsx)(xS,{params:ve,vals:w,setVal:Ee})]}),(0,B.jsxs)(`div`,{className:`border-t border-border pt-5`,children:[(0,B.jsxs)(`button`,{onClick:()=>O(e=>!e),"aria-expanded":ae,className:`mb-3 inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground hover:text-foreground`,children:[(0,B.jsx)(se,{className:Q(`size-3.5 transition-transform`,!ae&&`-rotate-90`)}),`Advanced — optimizer`,he?.trainer===`sft`?` & data`:``]}),ae&&(0,B.jsx)(xS,{params:ye,vals:w,setVal:Ee})]}),M?.eval_split?(0,B.jsxs)(`div`,{className:`border-t border-border pt-5 text-sm text-muted-foreground`,children:[`Eval uses the dataset's own `,(0,B.jsx)(`span`,{className:`font-medium text-foreground`,children:M.eval_split}),` split.`]}):he?.trainer===`grpo`?null:(0,B.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-5`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,B.jsx)(eS,{id:`eval-split`,checked:E,onCheckedChange:ne}),(0,B.jsx)(Yb,{htmlFor:`eval-split`,className:`font-normal text-muted-foreground`,children:`Hold out a slice for eval — watch for overfitting, not just training loss`})]}),E&&(0,B.jsxs)(`div`,{className:`flex items-center gap-2 pl-11 text-sm text-muted-foreground`,children:[`Hold out`,(0,B.jsx)(Jb,{type:`number`,min:1,max:50,value:re,onChange:e=>ie(e.target.value),className:`w-16 text-center font-mono`}),`% of the data for evaluation`]})]})]}),(0,B.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,B.jsxs)($,{variant:`outline`,onClick:()=>n(Math.max(0,t-1)),disabled:t===0,children:[(0,B.jsx)(ce,{}),` Back`]}),tCe&&n(t+1),disabled:!Ce,children:[`Next: `,tS[t+1],` `,(0,B.jsx)(D,{})]})]})]}),(0,B.jsx)(`aside`,{children:(0,B.jsxs)(`div`,{className:`sticky top-0 space-y-4`,children:[(0,B.jsxs)(`section`,{className:`border border-border bg-card`,children:[(0,B.jsxs)(`header`,{className:`border-b border-border px-4 py-3`,children:[(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Run summary`}),(0,B.jsx)(`p`,{className:`mt-0.5 text-sm font-semibold`,children:Se?`Ready to launch`:`Working through the steps…`})]}),(0,B.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-2 px-4 py-3 text-xs`,children:[(0,B.jsx)(bS,{label:`Dataset`,value:M?M.rows==null?M.name:`${M.name} (${M.rows})`:`—`}),(0,B.jsx)(bS,{label:`Model`,value:d?d.split(`/`).pop():`—`}),(0,B.jsx)(bS,{label:`Method`,value:p??`—`}),(0,B.jsx)(bS,{label:`Steps`,value:je(`max_steps`)||`60`}),(0,B.jsx)(bS,{label:`LR`,value:je(`learning_rate`)||`method default`}),(0,B.jsx)(bS,{label:`Batch`,value:je(`per_device_train_batch_size`)||`2`}),ve.map(e=>(0,B.jsx)(bS,{label:e.label,value:je(e.key)||e.def},e.key)),(0,B.jsx)(bS,{label:`Eval`,value:E?`${re}% held out`:`off`})]}),(0,B.jsxs)(`div`,{className:`space-y-2 px-4 pt-1 pb-4`,children:[rf(`operator`)?(0,B.jsxs)($,{size:`lg`,onClick:ke,disabled:!Se||S,className:`h-10 w-full`,children:[S?(0,B.jsx)(_e,{className:`animate-spin`}):(0,B.jsx)(Te,{}),` `,S?`Starting…`:`Start training`]}):(0,B.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:af(`operator`)}),(0,B.jsx)(`p`,{className:`text-center text-[11px] text-muted-foreground`,children:`This exact config runs — nothing hidden.`}),b&&(0,B.jsx)(`p`,{className:`text-xs text-destructive`,children:b})]})]}),(0,B.jsxs)(`section`,{className:`border border-border bg-card p-4`,children:[(0,B.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`The same run, from your shell`}),(0,B.jsx)(`pre`,{className:`rounded-md bg-surface p-3 font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-all text-foreground/80`,children:Ae})]})]})})]})]})}function _S({children:e,className:t}){return(0,B.jsx)(`section`,{className:Q(`border border-border bg-card p-5`,t),children:e})}function vS({children:e,className:t}){return(0,B.jsx)(`div`,{className:Q(`max-h-72 divide-y divide-border overflow-auto border border-border scrollbar-thin`,t),children:e})}function yS({selected:e,onClick:t,title:n,sub:r}){return(0,B.jsxs)(`button`,{onClick:t,"aria-pressed":e,className:Q(`flex w-full items-center gap-3 px-3 py-2.5 text-left transition-colors`,e?`bg-primary/5`:`hover:bg-subtle`),children:[(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:Q(`truncate text-sm font-medium`,e&&`text-primary`),children:n}),(0,B.jsx)(sx,{className:`text-muted-foreground`,children:r})]}),e&&(0,B.jsx)(oe,{className:`size-4 shrink-0 text-primary`})]})}function bS({label:e,value:t}){return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,B.jsx)(`dd`,{className:`truncate text-right font-mono`,children:t})]})}function xS({params:e,vals:t,setVal:n,methodInfo:r,method:i}){return(0,B.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:e.map(e=>{let a=e.key===`learning_rate`&&r?`default for ${i}: ${r.default_lr}`:e.hint,o=`param-${e.key}`;return e.kind===`bool`?(0,B.jsxs)(`div`,{className:`flex items-start gap-2.5 self-end pb-1.5`,children:[(0,B.jsx)(eS,{id:o,checked:t[e.key]===`true`,onCheckedChange:t=>n(e.key,t?`true`:`false`),className:`mt-0.5`}),(0,B.jsxs)(Yb,{htmlFor:o,className:`grid gap-0.5 font-normal`,children:[(0,B.jsx)(`span`,{className:`text-sm`,children:e.label}),a&&(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a})]})]},e.key):(0,B.jsx)(cx,{label:e.label,hint:a,htmlFor:o,children:e.kind===`select`?(0,B.jsx)(`select`,{id:o,value:t[e.key]??e.def,className:`w-full font-mono`,onChange:t=>n(e.key,t.target.value),children:e.options.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))}):(0,B.jsx)(Jb,{id:o,value:t[e.key]??``,placeholder:e.def||`method default`,inputMode:e.kind===`int`?`numeric`:`decimal`,className:`font-mono`,onChange:t=>n(e.key,t.target.value)})},e.key)})})}function SS(){let[e,t]=(0,_.useState)(window.location.hash);return(0,_.useEffect)(()=>{let e=()=>t(window.location.hash);return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]),e.replace(/^#/,``)}var CS=[{items:[{hash:`playground`,label:`Playground`,icon:ye},{hash:``,label:`Overview`,icon:ge}]},{title:`Build`,items:[{hash:`datasets`,label:`Datasets`,icon:fe},{hash:`models`,label:`Models`,icon:ae}]},{title:`Train`,items:[{hash:`train`,label:`New run`,icon:j},{hash:`runs`,label:`Runs`,icon:me}]}],wS={hash:`machines`,label:`Machines`,icon:be},TS=[...CS.flatMap(e=>e.items),wS],ES=new Map([[ge,`layout-dashboard`],[ye,`messages-square`],[fe,`database`],[ae,`box`],[j,`cpu`],[me,`history`],[be,`monitor-smartphone`]]),DS=`https://github.com/open-gitagent/shadowLM`,OS=240,kS=48,AS=12,jS=24,MS=32,NS={type:`spring`,stiffness:380,damping:36},PS=`of-island-open`;function FS(){try{return localStorage.getItem(PS)!==`false`}catch{return!0}}function IS(){let e=pf();return(0,B.jsx)(Ad,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,forcedTheme:Bd?e:void 0,children:Bd?(0,B.jsx)(BS,{embeddedIn:!0}):(0,B.jsx)(LS,{})})}function LS(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(mf.get());return(0,_.useEffect)(()=>{yf().then(t).catch(()=>t({auth_required:!1,mode:`none`}))},[]),(0,_.useEffect)(()=>{let e=()=>r(``);return window.addEventListener(`slm-unauthorized`,e),()=>window.removeEventListener(`slm-unauthorized`,e)},[]),e===null?(0,B.jsx)(`div`,{className:`grid h-full place-items-center text-sm text-muted-foreground`,children:(0,B.jsx)(_e,{className:`size-4 animate-spin`})}):e.auth_required&&!n?(0,B.jsx)(RS,{apikeyMode:e.mode===`apikey`,onAuthed:()=>r(mf.get())}):(0,B.jsx)(BS,{onSignOut:e.auth_required?()=>{xf(),r(``)}:void 0})}function RS({apikeyMode:e,onAuthed:t}){let[n,r]=(0,_.useState)(`admin`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1);async function f(r){r.preventDefault(),d(!0),l(``);try{e?(mf.set(o.trim()),await Sf()):await bf(n,i),t()}catch(t){mf.clear(),l(e?`Invalid API key`:t.message)}finally{d(!1)}}return(0,B.jsx)(`main`,{className:`grid min-h-svh place-items-center bg-canvas px-4 py-10`,children:(0,B.jsxs)(`div`,{className:`w-full max-w-sm`,children:[(0,B.jsxs)(`div`,{className:`mb-6 flex items-center gap-2.5`,children:[(0,B.jsx)(zS,{}),(0,B.jsxs)(`span`,{className:`grid leading-tight`,children:[(0,B.jsx)(`span`,{className:`text-sm font-semibold tracking-[-0.01em]`,children:`openfinetuner`}),(0,B.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`formerly ShadowLM`})]})]}),(0,B.jsxs)(`section`,{className:`grid gap-5 border border-border bg-background p-6`,children:[(0,B.jsxs)(`header`,{className:`grid gap-1.5`,children:[(0,B.jsx)(`h1`,{className:`text-lg font-semibold tracking-[-0.01em]`,children:`Sign in to openfinetuner`}),(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e?`Use the API key this server was started with.`:`Use the username and password this server was started with.`})]}),(0,B.jsxs)(`form`,{onSubmit:f,className:`grid gap-3`,children:[e?(0,B.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,B.jsx)(Yb,{htmlFor:`key`,children:`API key`}),(0,B.jsx)(Jb,{id:`key`,type:`password`,autoFocus:!0,value:o,onChange:e=>s(e.target.value)})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,B.jsx)(Yb,{htmlFor:`username`,children:`Username`}),(0,B.jsx)(Jb,{id:`username`,autoComplete:`username`,autoFocus:!0,value:n,onChange:e=>r(e.target.value)})]}),(0,B.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,B.jsx)(Yb,{htmlFor:`password`,children:`Password`}),(0,B.jsx)(Jb,{id:`password`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value)})]})]}),c&&(0,B.jsx)(`p`,{className:`text-sm text-destructive`,children:c}),(0,B.jsxs)($,{type:`submit`,size:`lg`,disabled:u,className:`h-10 w-full justify-between px-3`,children:[u?`Signing in…`:`Sign in`,u?(0,B.jsx)(_e,{className:`animate-spin`}):(0,B.jsx)(ne,{})]})]})]}),(0,B.jsx)(`p`,{className:`mt-4 font-mono text-[11px] text-muted-foreground`,children:`from Lyzr Research Labs`})]})})}function zS(){return(0,B.jsx)(`span`,{className:`grid size-7 shrink-0 place-items-center rounded-md border border-primary/20 bg-primary/10 font-mono text-[10px] font-semibold text-primary`,children:`of`})}function BS({onSignOut:e,embeddedIn:t}){let n=SS(),[r,i]=n.split(`/`),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(FS);(0,_.useEffect)(()=>{zf().then(e=>o(e.methods)).catch(()=>{})},[]),(0,_.useEffect)(()=>{t&&(sf(qd(n)),cf(TS.find(e=>e.hash===r)?.label??`Overview`))},[t,n,r]);let l=()=>c(e=>{try{localStorage.setItem(PS,String(!e))}catch{}return!e}),u=r===`models`?(0,B.jsx)(Kx,{}):r===`datasets`?(0,B.jsx)(Dx,{}):r===`train`?(0,B.jsx)(gS,{methods:a}):r===`playground`?(0,B.jsx)(qx,{}):r===`runs`?(0,B.jsx)(Xx,{initialId:i}):r===`machines`?(0,B.jsx)(Lx,{}):(0,B.jsx)(Cx,{});return t?(0,B.jsxs)(`main`,{className:`@container flex h-full min-h-0 flex-col overflow-y-auto bg-canvas px-6 pt-6 pb-8 *:shrink-0`,children:[u,(0,B.jsx)(tC,{})]}):(0,B.jsx)(Hl,{reducedMotion:`user`,children:(0,B.jsxs)(`div`,{className:`h-full`,style:{"--nav-right":`${AS+(s?OS:kS)}px`},children:[(0,B.jsx)(HS,{open:s,onToggle:l,section:r,onSignOut:e}),(0,B.jsx)(Cd.main,{initial:!1,animate:{paddingLeft:AS+(s?OS:kS)+jS,paddingRight:MS},transition:NS,className:`@container flex h-full min-h-0 flex-col overflow-y-auto pt-6 pb-8 *:shrink-0`,children:u})]})})}var VS={initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12}};function HS({open:e,onToggle:t,section:n,onSignOut:r}){let[i,a]=(0,_.useState)(),[o,s]=(0,_.useState)(),[c,l]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{let e=!0,t=()=>Sf().then(t=>{e&&(l(!0),a(t.backend),s(t.version))}).catch(()=>e&&l(!1));t();let n=setInterval(t,15e3);return()=>{e=!1,clearInterval(n)}},[]),(0,B.jsxs)(Cd.nav,{"aria-label":`Navigation`,initial:!1,animate:{width:e?OS:kS},transition:NS,style:{left:AS,top:AS,bottom:AS},className:`fixed z-50 flex flex-col overflow-clip rounded-xl border border-border bg-sidebar p-1 text-foreground shadow-paper`,children:[(0,B.jsxs)(`a`,{href:`#`,title:`openfinetuner, formerly ShadowLM`,className:`flex h-12 shrink-0 items-center gap-2.5 px-1.5 outline-none focus-visible:ring-2 focus-visible:ring-ring/40`,children:[(0,B.jsx)(zS,{}),(0,B.jsxs)(`span`,{className:`grid min-w-0 leading-tight`,children:[(0,B.jsx)(qS,{open:e,className:`font-heading text-sm font-semibold tracking-[-0.01em]`,children:`openfinetuner`}),(0,B.jsx)(qS,{open:e,className:`text-[11px] text-muted-foreground`,children:`formerly ShadowLM`})]})]}),(0,B.jsx)(`div`,{className:`mt-2 flex min-h-0 flex-col gap-0.5 overflow-y-auto px-1.5 [scrollbar-width:none]`,children:CS.map((t,r)=>(0,B.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[t.title&&(0,B.jsx)(KS,{open:e,children:t.title}),t.items.map(t=>(0,B.jsx)(WS,{item:t,open:e,active:n===t.hash},t.hash))]},t.title??r))}),(0,B.jsx)(`div`,{className:`flex-1`}),(0,B.jsxs)(`div`,{className:`flex flex-col gap-0.5 px-1.5 pb-2`,children:[(0,B.jsx)(WS,{item:wS,open:e,active:n===wS.hash}),(0,B.jsx)(QS,{open:e}),(0,B.jsx)(eC,{open:e}),(0,B.jsx)(GS,{open:e,icon:ie,label:`Docs`,title:`The README: SDK, CLI, methods, studio`,onClick:()=>window.open(`${DS}#readme`,`_blank`,`noreferrer`)}),(0,B.jsx)(GS,{open:e,icon:pe,label:`GitHub`,title:`github.com/open-gitagent/shadowLM`,onClick:()=>window.open(DS,`_blank`,`noreferrer`)})]}),(0,B.jsxs)(`div`,{className:Q(`mx-1.5 flex gap-2.5 border-t border-border pt-3 pb-1.5`,e?`flex-col`:`flex-col items-center`),children:[(0,B.jsx)(Fl,{initial:!1,mode:`popLayout`,children:e?(0,B.jsxs)(Cd.div,{...VS,className:`grid min-w-0 gap-1.5 text-[11px] whitespace-nowrap text-muted-foreground`,children:[i&&(0,B.jsxs)(`span`,{className:`grid min-w-0 gap-0.5`,children:[(0,B.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground`,children:`This machine`}),(0,B.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`backend `,i]})]}),(0,B.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,B.jsx)(JS,{live:c,label:!0}),o&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,B.jsxs)(`span`,{className:`tabular-nums`,children:[`v`,o]})]})]})]},`status`):(0,B.jsx)(Cd.div,{...VS,className:`grid justify-items-center gap-2 py-1`,children:(0,B.jsx)(JS,{live:c})},`dot`)}),(0,B.jsxs)(`div`,{className:Q(`flex gap-0.5`,e?`-mx-1`:`flex-col`),children:[(0,B.jsx)(XS,{}),r&&(0,B.jsx)(YS,{label:`Sign out`,onClick:r,children:(0,B.jsx)(ve,{className:`size-3.5`})}),(0,B.jsx)(YS,{label:e?`Collapse navigation`:`Expand navigation`,onClick:t,children:e?(0,B.jsx)(Ce,{className:`size-3.5`}):(0,B.jsx)(we,{className:`size-3.5`})})]})]})]})}var US=e=>Q(`group flex h-8 shrink-0 items-center gap-3 rounded-md px-1.5 text-[13px] font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/40`,e?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-surface-2/70 hover:text-foreground`);function WS({item:e,open:t,active:n}){return(0,B.jsxs)(`a`,{href:`#${e.hash}`,"aria-current":n?`page`:void 0,title:t?void 0:e.label,className:US(n),children:[(0,B.jsx)(e.icon,{className:`size-4 shrink-0 opacity-70 group-aria-[current=page]:opacity-100`,strokeWidth:1.75,"aria-hidden":!0}),(0,B.jsx)(qS,{open:t,className:`min-w-0 flex-1`,children:e.label})]})}function GS({open:e,icon:t,label:n,hint:r,title:i,onClick:a}){return(0,B.jsxs)(`button`,{type:`button`,onClick:a,title:e?i:i??n,className:Q(US(!1),`w-full text-left`),children:[(0,B.jsx)(t,{className:`size-4 shrink-0 opacity-70`,strokeWidth:1.75,"aria-hidden":!0}),(0,B.jsx)(qS,{open:e,className:`min-w-0 flex-1`,children:n}),e&&r&&(0,B.jsx)(`span`,{className:`shrink-0 text-[11px] font-normal text-muted-foreground tabular-nums`,children:r})]})}function KS({open:e,children:t}){return(0,B.jsxs)(`div`,{className:`relative mt-4 mb-1 h-4 shrink-0`,children:[(0,B.jsx)(Cd.span,{initial:!1,animate:{opacity:+!e},transition:{duration:.12},className:`absolute inset-x-1.5 top-1/2 h-px bg-border`,"aria-hidden":!0}),(0,B.jsx)(`div`,{className:`absolute inset-x-0 -top-0.5 flex h-5 items-center px-1.5`,children:(0,B.jsx)(qS,{open:e,className:`text-[11px] font-medium text-muted-foreground/80`,children:t})})]})}function qS({open:e,className:t,children:n}){return(0,B.jsx)(Cd.span,{initial:!1,animate:{opacity:+!!e},transition:{duration:e?.2:.08,delay:e?.08:0},className:Q(`truncate whitespace-nowrap`,t),"aria-hidden":!e,children:n})}function JS({live:e,label:t}){return(0,B.jsxs)(`span`,{title:e?`API reachable`:`the API is not answering; what is shown may be out of date`,className:`flex items-center gap-1.5`,children:[(0,B.jsx)(`span`,{className:Q(`size-1.5 shrink-0 rounded-full`,e?`bg-good`:`bg-muted-foreground/40`)}),t&&(e?`live`:`offline`)]})}function YS({label:e,onClick:t,children:n}){return(0,B.jsx)(`button`,{type:`button`,"aria-label":e,title:e,onClick:t,className:`grid size-7 place-items-center rounded-md text-muted-foreground outline-none hover:bg-surface-2 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40`,children:n})}function XS(){let{resolvedTheme:e,setTheme:t}=kd(),n=e===`dark`;return(0,B.jsx)(YS,{label:`Toggle theme`,onClick:()=>t(n?`light`:`dark`),children:n?(0,B.jsx)(je,{className:`size-3.5`}):(0,B.jsx)(xe,{className:`size-3.5`})})}function ZS(){let[e,t]=(0,_.useState)(!1),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``);(0,_.useEffect)(()=>{Ff().then(e=>r(e.hf_token_set)).catch(()=>{})},[]);async function u(e){e.preventDefault(),s(!0),l(``);try{r((await If(i)).hf_token_set),a(``),t(!1)}catch(e){l(e.message)}finally{s(!1)}}return{isSet:n,setOpen:t,dialog:(0,B.jsx)(Bb,{open:e,onOpenChange:t,children:(0,B.jsx)(Ub,{className:`sm:max-w-md`,children:(0,B.jsxs)(`form`,{onSubmit:u,className:`grid gap-4`,children:[(0,B.jsxs)(Wb,{children:[(0,B.jsx)(Kb,{children:`Hugging Face token`}),(0,B.jsxs)(qb,{children:[`For gated and private models. It is stored on this server, never in the browser.`,n&&` A token is set; saving replaces it.`]})]}),(0,B.jsx)(Jb,{type:`password`,autoFocus:!0,placeholder:`hf_…`,value:i,onChange:e=>a(e.target.value)}),c&&(0,B.jsx)(`p`,{className:`text-sm text-destructive`,children:c}),(0,B.jsxs)(Gb,{children:[(0,B.jsx)($,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,B.jsx)($,{type:`submit`,disabled:!i.trim()||o,children:o?`Saving…`:`Save token`})]})]})})})}}function QS({open:e}){let t=ZS();return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(GS,{open:e,icon:he,label:`Hugging Face token`,hint:t.isSet?`set`:`not set`,title:`The token the server uses for gated and private models`,onClick:()=>t.setOpen(!0)}),t.dialog]})}function $S(){let[e,t]=(0,_.useState)(``),[n,r]=(0,_.useState)(!1),i=e=>`${(e/1024).toFixed(1)} GB`;(0,_.useEffect)(()=>{Lf().then(e=>e.used_mb!=null&&t(`${i(e.used_mb)} used`)).catch(()=>{})},[]);async function a(){r(!0);try{let e=await Rf();t(e.after_mb==null?`freed`:`freed · ${i(e.after_mb)}`)}catch{t(`failed`)}finally{r(!1)}}return{hint:n?`clearing…`:e,busy:n,clean:a}}function eC({open:e}){let t=$S();return(0,B.jsx)(GS,{open:e,icon:t.busy?_e:Ie,label:`Clean VRAM`,hint:t.hint,title:`Unload cached models and free GPU memory`,onClick:t.clean})}function tC(){let e=ZS(),t=$S(),n=rf(`admin`),r=rf(`operator`),{setOpen:i}=e,{clean:a}=t;return(0,_.useEffect)(()=>{let i=e=>({label:e.label,icon:ES.get(e.icon)??``,path:qd(e.hash)}),a=[i(wS)];n&&a.push({label:`Hugging Face token`,icon:`key-round`,hint:e.isSet?`set`:`not set`,action:`hf-token`}),r&&a.push({label:`Clean VRAM`,icon:t.busy?`loader-circle`:`zap`,hint:t.hint||void 0,action:`clear-vram`}),a.push({label:`Docs`,icon:`book-open`,href:`${DS}#readme`},{label:`GitHub`,icon:`external-link`,href:DS}),lf({groups:CS.map(e=>({title:e.title,items:e.items.map(i)})),foot:a})},[n,r,e.isSet,t.busy,t.hint]),(0,_.useEffect)(()=>df(e=>{e===`hf-token`&&n&&i(!0),e===`clear-vram`&&r&&a()}),[n,r,i,a]),e.dialog}function nC({delayDuration:e=0,...t}){return(0,B.jsx)(Db,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}var rC=()=>(0,v.createRoot)(document.getElementById(`root`)).render((0,B.jsx)(_.StrictMode,{children:(0,B.jsx)(nC,{delayDuration:300,children:(0,B.jsx)(IS,{})})}));Bd?$d(e=>{window.location.hash=Kd(e)}).then(e=>{history.replaceState(null,``,`#${Kd(e)}`),rC()}):rC();
\ No newline at end of file
diff --git a/shadowlm/_static/index.html b/shadowlm/_static/index.html
index 7957aa2..ccae28b 100644
--- a/shadowlm/_static/index.html
+++ b/shadowlm/_static/index.html
@@ -11,7 +11,7 @@
href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Sora:wght@500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap"
/>
openfinetuner
-
+
diff --git a/shadowlm/serve.py b/shadowlm/serve.py
index d28804f..c9392b8 100644
--- a/shadowlm/serve.py
+++ b/shadowlm/serve.py
@@ -774,6 +774,14 @@ def _worker(self) -> None:
payload["dataset"] = {"rows": train.rows, "format": train.format}
payload["eval_dataset"] = {"rows": ev.rows, "format": ev.format}
with self._model_lock:
+ # Playground models cached on the GPU would leave a big base
+ # too little room to train (an 8B in bf16 next to a cached
+ # 8B is an OOM on 48 GB), so a run starts on a clean card.
+ if self._infer_cache:
+ n, _ = self._drop_inference_models()
+ print(f"[{job_id[:8]}] unloaded {n} playground "
+ f"model{'s' if n != 1 else ''} to free the GPU "
+ "for training", flush=True)
be = select_backend(self.backend_name,
accelerator=self.accelerator,
device=self.device)
@@ -918,27 +926,33 @@ def _gpu_used_mb() -> int | None:
except Exception: # noqa: BLE001
return None
- def clear_vram(self) -> dict:
- """Drop every cached inference model and release the GPU allocator's
- cache — frees VRAM held after inference/compare without restarting the
- server. Queued/running training is untouched (one job at a time)."""
+ def _drop_inference_models(self) -> tuple[int, str | None]:
+ """Empty the inference cache and release the GPU allocator's cache.
+ Caller holds ``_model_lock``. Returns (models dropped, release error)."""
import gc # noqa: PLC0415
- before = self._gpu_used_mb()
- freed_error: str | None = None
- with self._model_lock:
- n = len(self._infer_cache)
- self._infer_cache.clear()
+ n = len(self._infer_cache)
+ self._infer_cache.clear()
gc.collect()
+ freed_error: str | None = None
try:
import torch # noqa: PLC0415
if torch.cuda.is_available():
torch.cuda.empty_cache()
torch.cuda.synchronize()
- except Exception as e: # noqa: BLE001 — report, don't fail the request
+ except Exception as e: # noqa: BLE001 — report, don't fail the caller
freed_error = f"{type(e).__name__}: {e}"
print(f"[serve] VRAM release failed ({freed_error})", flush=True)
gc.collect()
+ return n, freed_error
+
+ def clear_vram(self) -> dict:
+ """Drop every cached inference model and release the GPU allocator's
+ cache — frees VRAM held after inference/compare without restarting the
+ server. Queued/running training is untouched (one job at a time)."""
+ before = self._gpu_used_mb()
+ with self._model_lock:
+ n, freed_error = self._drop_inference_models()
out = {"unloaded": n, "before_mb": before, "after_mb": self._gpu_used_mb()}
if freed_error: # don't report a clean sweep when the allocator threw
out["error"] = freed_error
diff --git a/tests/test_serve_vram.py b/tests/test_serve_vram.py
new file mode 100644
index 0000000..722a878
--- /dev/null
+++ b/tests/test_serve_vram.py
@@ -0,0 +1,29 @@
+"""Training starts on a clean card: cached playground models are dropped
+first, so a big base isn't fighting an inference copy of itself for VRAM.
+"""
+
+from __future__ import annotations
+
+from shadowlm.serve import Server
+
+
+def _server(tmp_path) -> Server:
+ return Server(backend="auto", accelerator="auto", device="auto", work_root=tmp_path)
+
+
+def test_drop_inference_models_empties_the_cache(tmp_path):
+ s = _server(tmp_path)
+ s._infer_cache[("Qwen/Qwen3-8B", None, None)] = object()
+ s._infer_cache[("Qwen/Qwen3-8B", "/a", None)] = object()
+ with s._model_lock:
+ n, err = s._drop_inference_models()
+ assert (n, err) == (2, None)
+ assert s._infer_cache == {}
+
+
+def test_clear_vram_reports_what_it_unloaded(tmp_path):
+ s = _server(tmp_path)
+ s._infer_cache[("m", None, None)] = object()
+ out = s.clear_vram()
+ assert out["unloaded"] == 1 and "error" not in out
+ assert s._infer_cache == {}