@fudrouter/fsrouter 0.6.105 → 0.6.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/lib/db/restoreRunner.js +136 -0
  2. package/dist/routes/db/raw/route.js +40 -0
  3. package/dist/routes/db/restore-path/route.js +28 -0
  4. package/dist/routes/db/route.js +4 -171
  5. package/package.json +1 -1
  6. package/public/.vite/manifest.json +86 -86
  7. package/public/assets/EndpointPageClient.Y4DlHkTu.js +6 -0
  8. package/public/assets/Loading.DFQ28pFE.js +1 -0
  9. package/public/assets/NoAuthProxyCard.CZTUlj4t.js +89 -0
  10. package/public/assets/index.AIBoioDI.js +89 -0
  11. package/public/assets/index.C--zNQ3O.css +1 -0
  12. package/public/assets/page.4cDBHbw-.js +6 -0
  13. package/public/assets/page.BKEq519M.js +4 -0
  14. package/public/assets/page.BP6GAYzJ.js +1 -0
  15. package/public/assets/page.BSn6cIN6.js +1 -0
  16. package/public/assets/page.BZ_cZfHH.js +1 -0
  17. package/public/assets/page.B_eGnZ87.js +1 -0
  18. package/public/assets/page.BeKSN8d5.js +1 -0
  19. package/public/assets/page.BrKiDQss.js +1 -0
  20. package/public/assets/page.C5AiGRKH.js +1 -0
  21. package/public/assets/page.C8zACKBM.js +1 -0
  22. package/public/assets/page.CJLP_zJ7.js +1 -0
  23. package/public/assets/page.CSrGxSfO.js +1 -0
  24. package/public/assets/page.CZDbQNsn.js +1 -0
  25. package/public/assets/page.CdAUv8An.js +2 -0
  26. package/public/assets/page.Ce-kykhG.js +1 -0
  27. package/public/assets/page.Cff3z2jC.js +1 -0
  28. package/public/assets/page.CinUcqhI.js +23 -0
  29. package/public/assets/page.Cl4BXH-q.js +6 -0
  30. package/public/assets/page.Cq_2LsWB.js +2 -0
  31. package/public/assets/page.CudzOdqp.js +1 -0
  32. package/public/assets/page.CyElgSss.js +5 -0
  33. package/public/assets/page.D9BzRCo6.js +1 -0
  34. package/public/assets/page.DCn1Ir9m.js +1 -0
  35. package/public/assets/page.DE5z4wT0.js +7 -0
  36. package/public/assets/page.DOB5QnMp.js +1 -0
  37. package/public/assets/page.DPthpQJn.js +1 -0
  38. package/public/assets/page.DReP7jhx.js +1 -0
  39. package/public/assets/page.Dd_cOSCu.js +1 -0
  40. package/public/assets/page.DsT3YjTA.js +31 -0
  41. package/public/assets/page.Dw5UwTfS.js +1 -0
  42. package/public/assets/page.F2ClRfJd.js +1 -0
  43. package/public/assets/page.NPv76Z9i.js +64 -0
  44. package/public/assets/page.SGPaUlyq.js +1 -0
  45. package/public/assets/page.hoGohFe7.js +1 -0
  46. package/public/assets/page.mbHhHec7.js +5 -0
  47. package/public/assets/page.q9OWaAVY.js +1 -0
  48. package/public/assets/page.zM1PvG2b.js +1 -0
  49. package/public/index.html +4 -4
@@ -0,0 +1,5 @@
1
+ import{u as On,j as f,B as Je,C as Ln,p as Jt,s as Qt,q as Zt,P as en,M as zn}from"./index.AIBoioDI.js";import{b as l,W as U,c as Te}from"./router.Cjj1--8t.js";import{C as tn,I as Pn,M as Bn}from"./NoAuthProxyCard.CZTUlj4t.js";import{C as Lt}from"./Loading.DFQ28pFE.js";import"./zustand.akaTi5uX.js";function $n(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return l.useMemo(()=>r=>{t.forEach(o=>o(r))},t)}const nt=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function De(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function bt(e){return"nodeType"in e}function X(e){var t,n;return e?De(e)?e:bt(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function xt(e){const{Document:t}=X(e);return e instanceof t}function Ue(e){return De(e)?!1:e instanceof X(e).HTMLElement}function nn(e){return e instanceof X(e).SVGElement}function Re(e){return e?De(e)?e.document:bt(e)?xt(e)?e:Ue(e)||nn(e)?e.ownerDocument:document:document:document}const re=nt?l.useLayoutEffect:l.useEffect;function yt(e){const t=l.useRef(e);return re(()=>{t.current=e}),l.useCallback(function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return t.current==null?void 0:t.current(...r)},[])}function Fn(){const e=l.useRef(null),t=l.useCallback((r,o)=>{e.current=setInterval(r,o)},[]),n=l.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function Pe(e,t){t===void 0&&(t=[e]);const n=l.useRef(e);return re(()=>{n.current!==e&&(n.current=e)},t),n}function Xe(e,t){const n=l.useRef();return l.useMemo(()=>{const r=e(n.current);return n.current=r,r},[...t])}function Qe(e){const t=yt(e),n=l.useRef(null),r=l.useCallback(o=>{o!==n.current&&(t==null||t(o,n.current)),n.current=o},[]);return[n,r]}function ht(e){const t=l.useRef();return l.useEffect(()=>{t.current=e},[e]),t.current}let ct={};function We(e,t){return l.useMemo(()=>{if(t)return t;const n=ct[e]==null?0:ct[e]+1;return ct[e]=n,e+"-"+n},[e,t])}function rn(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.reduce((s,i)=>{const a=Object.entries(i);for(const[c,d]of a){const h=s[c];h!=null&&(s[c]=h+e*d)}return s},{...t})}}const Se=rn(1),Be=rn(-1);function Un(e){return"clientX"in e&&"clientY"in e}function wt(e){if(!e)return!1;const{KeyboardEvent:t}=X(e.target);return t&&e instanceof t}function Xn(e){if(!e)return!1;const{TouchEvent:t}=X(e.target);return t&&e instanceof t}function gt(e){if(Xn(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Un(e)?{x:e.clientX,y:e.clientY}:null}const $e=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[$e.Translate.toString(e),$e.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),zt="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Wn(e){return e.matches(zt)?e:e.querySelector(zt)}const Yn={display:"none"};function Vn(e){let{id:t,value:n}=e;return U.createElement("div",{id:t,style:Yn},n)}function Hn(e){let{id:t,announcement:n,ariaLiveType:r="assertive"}=e;const o={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return U.createElement("div",{id:t,style:o,role:"status","aria-live":r,"aria-atomic":!0},n)}function Kn(){const[e,t]=l.useState("");return{announce:l.useCallback(r=>{r!=null&&t(r)},[]),announcement:e}}const on=l.createContext(null);function _n(e){const t=l.useContext(on);l.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function qn(){const[e]=l.useState(()=>new Set),t=l.useCallback(r=>(e.add(r),()=>e.delete(r)),[e]);return[l.useCallback(r=>{let{type:o,event:s}=r;e.forEach(i=>{var a;return(a=i[o])==null?void 0:a.call(i,s)})},[e]),t]}const Gn={draggable:`
2
+ To pick up a draggable item, press the space bar.
3
+ While dragging, use the arrow keys to move the item.
4
+ Press space again to drop the item in its new position, or press escape to cancel.
5
+ `},Jn={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function Qn(e){let{announcements:t=Jn,container:n,hiddenTextDescribedById:r,screenReaderInstructions:o=Gn}=e;const{announce:s,announcement:i}=Kn(),a=We("DndLiveRegion"),[c,d]=l.useState(!1);if(l.useEffect(()=>{d(!0)},[]),_n(l.useMemo(()=>({onDragStart(u){let{active:g}=u;s(t.onDragStart({active:g}))},onDragMove(u){let{active:g,over:p}=u;t.onDragMove&&s(t.onDragMove({active:g,over:p}))},onDragOver(u){let{active:g,over:p}=u;s(t.onDragOver({active:g,over:p}))},onDragEnd(u){let{active:g,over:p}=u;s(t.onDragEnd({active:g,over:p}))},onDragCancel(u){let{active:g,over:p}=u;s(t.onDragCancel({active:g,over:p}))}}),[s,t])),!c)return null;const h=U.createElement(U.Fragment,null,U.createElement(Vn,{id:r,value:o.draggable}),U.createElement(Hn,{id:a,announcement:i}));return n?Te.createPortal(h,n):h}var L;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(L||(L={}));function Ze(){}function Pt(e,t){return l.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Zn(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return l.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const Z=Object.freeze({x:0,y:0});function sn(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function an(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function er(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function Bt(e){let{left:t,top:n,height:r,width:o}=e;return[{x:t,y:n},{x:t+o,y:n},{x:t,y:n+r},{x:t+o,y:n+r}]}function ln(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function $t(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}const tr=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const o=$t(t,t.left,t.top),s=[];for(const i of r){const{id:a}=i,c=n.get(a);if(c){const d=sn($t(c),o);s.push({id:a,data:{droppableContainer:i,value:d}})}}return s.sort(an)},nr=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const o=Bt(t),s=[];for(const i of r){const{id:a}=i,c=n.get(a);if(c){const d=Bt(c),h=o.reduce((g,p,R)=>g+sn(d[R],p),0),u=Number((h/4).toFixed(4));s.push({id:a,data:{droppableContainer:i,value:u}})}}return s.sort(an)};function rr(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),o=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),i=o-r,a=s-n;if(r<o&&n<s){const c=t.width*t.height,d=e.width*e.height,h=i*a,u=h/(c+d-h);return Number(u.toFixed(4))}return 0}const or=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const o=[];for(const s of r){const{id:i}=s,a=n.get(i);if(a){const c=rr(a,t);c>0&&o.push({id:i,data:{droppableContainer:s,value:c}})}}return o.sort(er)};function sr(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function cn(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Z}function ir(e){return function(n){for(var r=arguments.length,o=new Array(r>1?r-1:0),s=1;s<r;s++)o[s-1]=arguments[s];return o.reduce((i,a)=>({...i,top:i.top+e*a.y,bottom:i.bottom+e*a.y,left:i.left+e*a.x,right:i.right+e*a.x}),{...n})}}const ar=ir(1);function lr(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function cr(e,t,n){const r=lr(t);if(!r)return e;const{scaleX:o,scaleY:s,x:i,y:a}=r,c=e.left-i-(1-o)*parseFloat(n),d=e.top-a-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),h=o?e.width/o:e.width,u=s?e.height/s:e.height;return{width:h,height:u,top:d,right:c+h,bottom:d+u,left:c}}const dr={ignoreTransform:!1};function Ee(e,t){t===void 0&&(t=dr);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:d,transformOrigin:h}=X(e).getComputedStyle(e);d&&(n=cr(n,d,h))}const{top:r,left:o,width:s,height:i,bottom:a,right:c}=n;return{top:r,left:o,width:s,height:i,bottom:a,right:c}}function Ft(e){return Ee(e,{ignoreTransform:!0})}function ur(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function fr(e,t){return t===void 0&&(t=X(e).getComputedStyle(e)),t.position==="fixed"}function hr(e,t){t===void 0&&(t=X(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(o=>{const s=t[o];return typeof s=="string"?n.test(s):!1})}function rt(e,t){const n=[];function r(o){if(t!=null&&n.length>=t||!o)return n;if(xt(o)&&o.scrollingElement!=null&&!n.includes(o.scrollingElement))return n.push(o.scrollingElement),n;if(!Ue(o)||nn(o)||n.includes(o))return n;const s=X(e).getComputedStyle(o);return o!==e&&hr(o,s)&&n.push(o),fr(o,s)?n:r(o.parentNode)}return e?r(e):n}function dn(e){const[t]=rt(e,1);return t??null}function dt(e){return!nt||!e?null:De(e)?e:bt(e)?xt(e)||e===Re(e).scrollingElement?window:Ue(e)?e:null:null}function un(e){return De(e)?e.scrollX:e.scrollLeft}function fn(e){return De(e)?e.scrollY:e.scrollTop}function pt(e){return{x:un(e),y:fn(e)}}var z;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(z||(z={}));function hn(e){return!nt||!e?!1:e===document.scrollingElement}function gn(e){const t={x:0,y:0},n=hn(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},o=e.scrollTop<=t.y,s=e.scrollLeft<=t.x,i=e.scrollTop>=r.y,a=e.scrollLeft>=r.x;return{isTop:o,isLeft:s,isBottom:i,isRight:a,maxScroll:r,minScroll:t}}const gr={x:.2,y:.2};function pr(e,t,n,r,o){let{top:s,left:i,right:a,bottom:c}=n;r===void 0&&(r=10),o===void 0&&(o=gr);const{isTop:d,isBottom:h,isLeft:u,isRight:g}=gn(e),p={x:0,y:0},R={x:0,y:0},b={height:t.height*o.y,width:t.width*o.x};return!d&&s<=t.top+b.height?(p.y=z.Backward,R.y=r*Math.abs((t.top+b.height-s)/b.height)):!h&&c>=t.bottom-b.height&&(p.y=z.Forward,R.y=r*Math.abs((t.bottom-b.height-c)/b.height)),!g&&a>=t.right-b.width?(p.x=z.Forward,R.x=r*Math.abs((t.right-b.width-a)/b.width)):!u&&i<=t.left+b.width&&(p.x=z.Backward,R.x=r*Math.abs((t.left+b.width-i)/b.width)),{direction:p,speed:R}}function vr(e){if(e===document.scrollingElement){const{innerWidth:s,innerHeight:i}=window;return{top:0,left:0,right:s,bottom:i,width:s,height:i}}const{top:t,left:n,right:r,bottom:o}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:o,width:e.clientWidth,height:e.clientHeight}}function pn(e){return e.reduce((t,n)=>Se(t,pt(n)),Z)}function mr(e){return e.reduce((t,n)=>t+un(n),0)}function br(e){return e.reduce((t,n)=>t+fn(n),0)}function xr(e,t){if(t===void 0&&(t=Ee),!e)return;const{top:n,left:r,bottom:o,right:s}=t(e);dn(e)&&(o<=0||s<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const yr=[["x",["left","right"],mr],["y",["top","bottom"],br]];class Ct{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=rt(n),o=pn(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[s,i,a]of yr)for(const c of i)Object.defineProperty(this,c,{get:()=>{const d=a(r),h=o[s]-d;return this.rect[c]+h},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Oe{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var o;(o=this.target)==null||o.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function wr(e){const{EventTarget:t}=X(e);return e instanceof t?e:Re(e)}function ut(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var J;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(J||(J={}));function Ut(e){e.preventDefault()}function Cr(e){e.stopPropagation()}var k;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(k||(k={}));const vn={start:[k.Space,k.Enter],cancel:[k.Esc],end:[k.Space,k.Enter,k.Tab]},Sr=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case k.Right:return{...n,x:n.x+25};case k.Left:return{...n,x:n.x-25};case k.Down:return{...n,y:n.y+25};case k.Up:return{...n,y:n.y-25}}};class St{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new Oe(Re(n)),this.windowListeners=new Oe(X(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(J.Resize,this.handleCancel),this.windowListeners.add(J.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(J.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&xr(r),n(Z)}handleKeyDown(t){if(wt(t)){const{active:n,context:r,options:o}=this.props,{keyboardCodes:s=vn,coordinateGetter:i=Sr,scrollBehavior:a="smooth"}=o,{code:c}=t;if(s.end.includes(c)){this.handleEnd(t);return}if(s.cancel.includes(c)){this.handleCancel(t);return}const{collisionRect:d}=r.current,h=d?{x:d.left,y:d.top}:Z;this.referenceCoordinates||(this.referenceCoordinates=h);const u=i(t,{active:n,context:r.current,currentCoordinates:h});if(u){const g=Be(u,h),p={x:0,y:0},{scrollableAncestors:R}=r.current;for(const b of R){const y=t.code,{isTop:D,isRight:S,isLeft:w,isBottom:N,maxScroll:v,minScroll:x}=gn(b),m=vr(b),E={x:Math.min(y===k.Right?m.right-m.width/2:m.right,Math.max(y===k.Right?m.left:m.left+m.width/2,u.x)),y:Math.min(y===k.Down?m.bottom-m.height/2:m.bottom,Math.max(y===k.Down?m.top:m.top+m.height/2,u.y))},T=y===k.Right&&!S||y===k.Left&&!w,O=y===k.Down&&!N||y===k.Up&&!D;if(T&&E.x!==u.x){const j=b.scrollLeft+g.x,W=y===k.Right&&j<=v.x||y===k.Left&&j>=x.x;if(W&&!g.y){b.scrollTo({left:j,behavior:a});return}W?p.x=b.scrollLeft-j:p.x=y===k.Right?b.scrollLeft-v.x:b.scrollLeft-x.x,p.x&&b.scrollBy({left:-p.x,behavior:a});break}else if(O&&E.y!==u.y){const j=b.scrollTop+g.y,W=y===k.Down&&j<=v.y||y===k.Up&&j>=x.y;if(W&&!g.x){b.scrollTo({top:j,behavior:a});return}W?p.y=b.scrollTop-j:p.y=y===k.Down?b.scrollTop-v.y:b.scrollTop-x.y,p.y&&b.scrollBy({top:-p.y,behavior:a});break}}this.handleMove(t,Se(Be(u,this.referenceCoordinates),p))}}}handleMove(t,n){const{onMove:r}=this.props;t.preventDefault(),r(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}St.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=vn,onActivation:o}=t,{active:s}=n;const{code:i}=e.nativeEvent;if(r.start.includes(i)){const a=s.activatorNode.current;return a&&e.target!==a?!1:(e.preventDefault(),o==null||o({event:e.nativeEvent}),!0)}return!1}}];function Xt(e){return!!(e&&"distance"in e)}function Wt(e){return!!(e&&"delay"in e)}class Dt{constructor(t,n,r){var o;r===void 0&&(r=wr(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:s}=t,{target:i}=s;this.props=t,this.events=n,this.document=Re(i),this.documentListeners=new Oe(this.document),this.listeners=new Oe(r),this.windowListeners=new Oe(X(i)),this.initialCoordinates=(o=gt(s))!=null?o:Z,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(J.Resize,this.handleCancel),this.windowListeners.add(J.DragStart,Ut),this.windowListeners.add(J.VisibilityChange,this.handleCancel),this.windowListeners.add(J.ContextMenu,Ut),this.documentListeners.add(J.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Wt(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(Xt(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:o}=this.props;o(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(J.Click,Cr,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(J.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:o,props:s}=this,{onMove:i,options:{activationConstraint:a}}=s;if(!o)return;const c=(n=gt(t))!=null?n:Z,d=Be(o,c);if(!r&&a){if(Xt(a)){if(a.tolerance!=null&&ut(d,a.tolerance))return this.handleCancel();if(ut(d,a.distance))return this.handleStart()}if(Wt(a)&&ut(d,a.tolerance))return this.handleCancel();this.handlePending(a,d);return}t.cancelable&&t.preventDefault(),i(c)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===k.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const Dr={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Rt extends Dt{constructor(t){const{event:n}=t,r=Re(n.target);super(t,Dr,r)}}Rt.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r==null||r({event:n}),!0)}}];const Rr={move:{name:"mousemove"},end:{name:"mouseup"}};var vt;(function(e){e[e.RightClick=2]="RightClick"})(vt||(vt={}));class Er extends Dt{constructor(t){super(t,Rr,Re(t.event.target))}}Er.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===vt.RightClick?!1:(r==null||r({event:n}),!0)}}];const ft={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Nr extends Dt{constructor(t){super(t,ft)}static setup(){return window.addEventListener(ft.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(ft.move.name,t)};function t(){}}}Nr.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:o}=n;return o.length>1?!1:(r==null||r({event:n}),!0)}}];var Le;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Le||(Le={}));var et;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(et||(et={}));function kr(e){let{acceleration:t,activator:n=Le.Pointer,canScroll:r,draggingRect:o,enabled:s,interval:i=5,order:a=et.TreeOrder,pointerCoordinates:c,scrollableAncestors:d,scrollableAncestorRects:h,delta:u,threshold:g}=e;const p=jr({delta:u,disabled:!s}),[R,b]=Fn(),y=l.useRef({x:0,y:0}),D=l.useRef({x:0,y:0}),S=l.useMemo(()=>{switch(n){case Le.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case Le.DraggableRect:return o}},[n,o,c]),w=l.useRef(null),N=l.useCallback(()=>{const x=w.current;if(!x)return;const m=y.current.x*D.current.x,E=y.current.y*D.current.y;x.scrollBy(m,E)},[]),v=l.useMemo(()=>a===et.TreeOrder?[...d].reverse():d,[a,d]);l.useEffect(()=>{if(!s||!d.length||!S){b();return}for(const x of v){if((r==null?void 0:r(x))===!1)continue;const m=d.indexOf(x),E=h[m];if(!E)continue;const{direction:T,speed:O}=pr(x,E,S,t,g);for(const j of["x","y"])p[j][T[j]]||(O[j]=0,T[j]=0);if(O.x>0||O.y>0){b(),w.current=x,R(N,i),y.current=O,D.current=T;return}}y.current={x:0,y:0},D.current={x:0,y:0},b()},[t,N,r,b,s,i,JSON.stringify(S),JSON.stringify(p),R,d,v,h,JSON.stringify(g)])}const Mr={x:{[z.Backward]:!1,[z.Forward]:!1},y:{[z.Backward]:!1,[z.Forward]:!1}};function jr(e){let{delta:t,disabled:n}=e;const r=ht(t);return Xe(o=>{if(n||!r||!o)return Mr;const s={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[z.Backward]:o.x[z.Backward]||s.x===-1,[z.Forward]:o.x[z.Forward]||s.x===1},y:{[z.Backward]:o.y[z.Backward]||s.y===-1,[z.Forward]:o.y[z.Forward]||s.y===1}}},[n,t,r])}function Ir(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return Xe(o=>{var s;return t==null?null:(s=r??o)!=null?s:null},[r,t])}function Ar(e,t){return l.useMemo(()=>e.reduce((n,r)=>{const{sensor:o}=r,s=o.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,r)}));return[...n,...s]},[]),[e,t])}var Fe;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Fe||(Fe={}));var mt;(function(e){e.Optimized="optimized"})(mt||(mt={}));const Yt=new Map;function Tr(e,t){let{dragging:n,dependencies:r,config:o}=t;const[s,i]=l.useState(null),{frequency:a,measure:c,strategy:d}=o,h=l.useRef(e),u=y(),g=Pe(u),p=l.useCallback(function(D){D===void 0&&(D=[]),!g.current&&i(S=>S===null?D:S.concat(D.filter(w=>!S.includes(w))))},[g]),R=l.useRef(null),b=Xe(D=>{if(u&&!n)return Yt;if(!D||D===Yt||h.current!==e||s!=null){const S=new Map;for(let w of e){if(!w)continue;if(s&&s.length>0&&!s.includes(w.id)&&w.rect.current){S.set(w.id,w.rect.current);continue}const N=w.node.current,v=N?new Ct(c(N),N):null;w.rect.current=v,v&&S.set(w.id,v)}return S}return D},[e,s,n,u,c]);return l.useEffect(()=>{h.current=e},[e]),l.useEffect(()=>{u||p()},[n,u]),l.useEffect(()=>{s&&s.length>0&&i(null)},[JSON.stringify(s)]),l.useEffect(()=>{u||typeof a!="number"||R.current!==null||(R.current=setTimeout(()=>{p(),R.current=null},a))},[a,u,p,...r]),{droppableRects:b,measureDroppableContainers:p,measuringScheduled:s!=null};function y(){switch(d){case Fe.Always:return!1;case Fe.BeforeDragging:return n;default:return!n}}}function mn(e,t){return Xe(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function Or(e,t){return mn(e,t)}function Lr(e){let{callback:t,disabled:n}=e;const r=yt(t),o=l.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:s}=window;return new s(r)},[r,n]);return l.useEffect(()=>()=>o==null?void 0:o.disconnect(),[o]),o}function ot(e){let{callback:t,disabled:n}=e;const r=yt(t),o=l.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:s}=window;return new s(r)},[n]);return l.useEffect(()=>()=>o==null?void 0:o.disconnect(),[o]),o}function zr(e){return new Ct(Ee(e),e)}function Vt(e,t,n){t===void 0&&(t=zr);const[r,o]=l.useState(null);function s(){o(c=>{if(!e)return null;if(e.isConnected===!1){var d;return(d=c??n)!=null?d:null}const h=t(e);return JSON.stringify(c)===JSON.stringify(h)?c:h})}const i=Lr({callback(c){if(e)for(const d of c){const{type:h,target:u}=d;if(h==="childList"&&u instanceof HTMLElement&&u.contains(e)){s();break}}}}),a=ot({callback:s});return re(()=>{s(),e?(a==null||a.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(a==null||a.disconnect(),i==null||i.disconnect())},[e]),r}function Pr(e){const t=mn(e);return cn(e,t)}const Ht=[];function Br(e){const t=l.useRef(e),n=Xe(r=>e?r&&r!==Ht&&e&&t.current&&e.parentNode===t.current.parentNode?r:rt(e):Ht,[e]);return l.useEffect(()=>{t.current=e},[e]),n}function $r(e){const[t,n]=l.useState(null),r=l.useRef(e),o=l.useCallback(s=>{const i=dt(s.target);i&&n(a=>a?(a.set(i,pt(i)),new Map(a)):null)},[]);return l.useEffect(()=>{const s=r.current;if(e!==s){i(s);const a=e.map(c=>{const d=dt(c);return d?(d.addEventListener("scroll",o,{passive:!0}),[d,pt(d)]):null}).filter(c=>c!=null);n(a.length?new Map(a):null),r.current=e}return()=>{i(e),i(s)};function i(a){a.forEach(c=>{const d=dt(c);d==null||d.removeEventListener("scroll",o)})}},[o,e]),l.useMemo(()=>e.length?t?Array.from(t.values()).reduce((s,i)=>Se(s,i),Z):pn(e):Z,[e,t])}function Kt(e,t){t===void 0&&(t=[]);const n=l.useRef(null);return l.useEffect(()=>{n.current=null},t),l.useEffect(()=>{const r=e!==Z;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?Be(e,n.current):Z}function Fr(e){l.useEffect(()=>{if(!nt)return;const t=e.map(n=>{let{sensor:r}=n;return r.setup==null?void 0:r.setup()});return()=>{for(const n of t)n==null||n()}},e.map(t=>{let{sensor:n}=t;return n}))}function Ur(e,t){return l.useMemo(()=>e.reduce((n,r)=>{let{eventName:o,handler:s}=r;return n[o]=i=>{s(i,t)},n},{}),[e,t])}function bn(e){return l.useMemo(()=>e?ur(e):null,[e])}const _t=[];function Xr(e,t){t===void 0&&(t=Ee);const[n]=e,r=bn(n?X(n):null),[o,s]=l.useState(_t);function i(){s(()=>e.length?e.map(c=>hn(c)?r:new Ct(t(c),c)):_t)}const a=ot({callback:i});return re(()=>{a==null||a.disconnect(),i(),e.forEach(c=>a==null?void 0:a.observe(c))},[e]),o}function Wr(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Ue(t)?t:e}function Yr(e){let{measure:t}=e;const[n,r]=l.useState(null),o=l.useCallback(d=>{for(const{target:h}of d)if(Ue(h)){r(u=>{const g=t(h);return u?{...u,width:g.width,height:g.height}:g});break}},[t]),s=ot({callback:o}),i=l.useCallback(d=>{const h=Wr(d);s==null||s.disconnect(),h&&(s==null||s.observe(h)),r(h?t(h):null)},[t,s]),[a,c]=Qe(i);return l.useMemo(()=>({nodeRef:a,rect:n,setRef:c}),[n,a,c])}const Vr=[{sensor:Rt,options:{}},{sensor:St,options:{}}],Hr={current:{}},Ge={draggable:{measure:Ft},droppable:{measure:Ft,strategy:Fe.WhileDragging,frequency:mt.Optimized},dragOverlay:{measure:Ee}};class ze extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,r;return(n=(r=this.get(t))==null?void 0:r.node.current)!=null?n:void 0}}const Kr={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new ze,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Ze},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:Ge,measureDroppableContainers:Ze,windowRect:null,measuringScheduled:!1},_r={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Ze,draggableNodes:new Map,over:null,measureDroppableContainers:Ze},st=l.createContext(_r),xn=l.createContext(Kr);function qr(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new ze}}}function Gr(e,t){switch(t.type){case L.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case L.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case L.DragEnd:case L.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case L.RegisterDroppable:{const{element:n}=t,{id:r}=n,o=new ze(e.droppable.containers);return o.set(r,n),{...e,droppable:{...e.droppable,containers:o}}}case L.SetDroppableDisabled:{const{id:n,key:r,disabled:o}=t,s=e.droppable.containers.get(n);if(!s||r!==s.key)return e;const i=new ze(e.droppable.containers);return i.set(n,{...s,disabled:o}),{...e,droppable:{...e.droppable,containers:i}}}case L.UnregisterDroppable:{const{id:n,key:r}=t,o=e.droppable.containers.get(n);if(!o||r!==o.key)return e;const s=new ze(e.droppable.containers);return s.delete(n),{...e,droppable:{...e.droppable,containers:s}}}default:return e}}function Jr(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:o}=l.useContext(st),s=ht(r),i=ht(n==null?void 0:n.id);return l.useEffect(()=>{if(!t&&!r&&s&&i!=null){if(!wt(s)||document.activeElement===s.target)return;const a=o.get(i);if(!a)return;const{activatorNode:c,node:d}=a;if(!c.current&&!d.current)return;requestAnimationFrame(()=>{for(const h of[c.current,d.current]){if(!h)continue;const u=Wn(h);if(u){u.focus();break}}})}},[r,t,o,i,s]),null}function Qr(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((o,s)=>s({transform:o,...r}),n):n}function Zr(e){return l.useMemo(()=>({draggable:{...Ge.draggable,...e==null?void 0:e.draggable},droppable:{...Ge.droppable,...e==null?void 0:e.droppable},dragOverlay:{...Ge.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function eo(e){let{activeNode:t,measure:n,initialRect:r,config:o=!0}=e;const s=l.useRef(!1),{x:i,y:a}=typeof o=="boolean"?{x:o,y:o}:o;re(()=>{if(!i&&!a||!t){s.current=!1;return}if(s.current||!r)return;const d=t==null?void 0:t.node.current;if(!d||d.isConnected===!1)return;const h=n(d),u=cn(h,r);if(i||(u.x=0),a||(u.y=0),s.current=!0,Math.abs(u.x)>0||Math.abs(u.y)>0){const g=dn(d);g&&g.scrollBy({top:u.y,left:u.x})}},[t,i,a,r,n])}const yn=l.createContext({...Z,scaleX:1,scaleY:1});var pe;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(pe||(pe={}));const to=l.memo(function(t){var n,r,o,s;let{id:i,accessibility:a,autoScroll:c=!0,children:d,sensors:h=Vr,collisionDetection:u=or,measuring:g,modifiers:p,...R}=t;const b=l.useReducer(Gr,void 0,qr),[y,D]=b,[S,w]=qn(),[N,v]=l.useState(pe.Uninitialized),x=N===pe.Initialized,{draggable:{active:m,nodes:E,translate:T},droppable:{containers:O}}=y,j=m!=null?E.get(m):null,W=l.useRef({initial:null,translated:null}),Y=l.useMemo(()=>{var B;return m!=null?{id:m,data:(B=j==null?void 0:j.data)!=null?B:Hr,rect:W}:null},[m,j]),V=l.useRef(null),[C,M]=l.useState(null),[A,oe]=l.useState(null),$=Pe(R,Object.values(R)),Q=We("DndDescribedBy",i),Ye=l.useMemo(()=>O.getEnabled(),[O]),F=Zr(g),{droppableRects:se,measureDroppableContainers:ve,measuringScheduled:Ne}=Tr(Ye,{dragging:x,dependencies:[T.x,T.y],config:F.droppable}),q=Ir(E,m),Ve=l.useMemo(()=>A?gt(A):null,[A]),ce=Tn(),ie=Or(q,F.draggable.measure);eo({activeNode:m!=null?E.get(m):null,config:ce.layoutShiftCompensation,initialRect:ie,measure:F.draggable.measure});const I=Vt(q,F.draggable.measure,ie),ke=Vt(q?q.parentElement:null),ee=l.useRef({activatorEvent:null,active:null,activeNode:q,collisionRect:null,collisions:null,droppableRects:se,draggableNodes:E,draggingNode:null,draggingNodeRect:null,droppableContainers:O,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),me=O.getNodeFor((n=ee.current.over)==null?void 0:n.id),ae=Yr({measure:F.dragOverlay.measure}),be=(r=ae.nodeRef.current)!=null?r:q,xe=x?(o=ae.rect)!=null?o:I:null,Nt=!!(ae.nodeRef.current&&ae.rect),kt=Pr(Nt?null:I),it=bn(be?X(be):null),de=Br(x?me??q:null),He=Xr(de),Ke=Qr(p,{transform:{x:T.x-kt.x,y:T.y-kt.y,scaleX:1,scaleY:1},activatorEvent:A,active:Y,activeNodeRect:I,containerNodeRect:ke,draggingNodeRect:xe,over:ee.current.over,overlayNodeRect:ae.rect,scrollableAncestors:de,scrollableAncestorRects:He,windowRect:it}),Mt=Ve?Se(Ve,T):null,jt=$r(de),En=Kt(jt),Nn=Kt(jt,[I]),ye=Se(Ke,En),we=xe?ar(xe,Ke):null,Me=Y&&we?u({active:Y,collisionRect:we,droppableRects:se,droppableContainers:Ye,pointerCoordinates:Mt}):null,It=ln(Me,"id"),[ue,At]=l.useState(null),kn=Nt?Ke:Se(Ke,Nn),Mn=sr(kn,(s=ue==null?void 0:ue.rect)!=null?s:null,I),at=l.useRef(null),Tt=l.useCallback((B,H)=>{let{sensor:K,options:fe}=H;if(V.current==null)return;const G=E.get(V.current);if(!G)return;const _=B.nativeEvent,te=new K({active:V.current,activeNode:G,event:_,options:fe,context:ee,onAbort(P){if(!E.get(P))return;const{onDragAbort:ne}=$.current,le={id:P};ne==null||ne(le),S({type:"onDragAbort",event:le})},onPending(P,he,ne,le){if(!E.get(P))return;const{onDragPending:Ie}=$.current,ge={id:P,constraint:he,initialCoordinates:ne,offset:le};Ie==null||Ie(ge),S({type:"onDragPending",event:ge})},onStart(P){const he=V.current;if(he==null)return;const ne=E.get(he);if(!ne)return;const{onDragStart:le}=$.current,je={activatorEvent:_,active:{id:he,data:ne.data,rect:W}};Te.unstable_batchedUpdates(()=>{le==null||le(je),v(pe.Initializing),D({type:L.DragStart,initialCoordinates:P,active:he}),S({type:"onDragStart",event:je}),M(at.current),oe(_)})},onMove(P){D({type:L.DragMove,coordinates:P})},onEnd:Ce(L.DragEnd),onCancel:Ce(L.DragCancel)});at.current=te;function Ce(P){return async function(){const{active:ne,collisions:le,over:je,scrollAdjustedTranslate:Ie}=ee.current;let ge=null;if(ne&&Ie){const{cancelDrop:Ae}=$.current;ge={activatorEvent:_,active:ne,collisions:le,delta:Ie,over:je},P===L.DragEnd&&typeof Ae=="function"&&await Promise.resolve(Ae(ge))&&(P=L.DragCancel)}V.current=null,Te.unstable_batchedUpdates(()=>{D({type:P}),v(pe.Uninitialized),At(null),M(null),oe(null),at.current=null;const Ae=P===L.DragEnd?"onDragEnd":"onDragCancel";if(ge){const lt=$.current[Ae];lt==null||lt(ge),S({type:Ae,event:ge})}})}}},[E]),jn=l.useCallback((B,H)=>(K,fe)=>{const G=K.nativeEvent,_=E.get(fe);if(V.current!==null||!_||G.dndKit||G.defaultPrevented)return;const te={active:_};B(K,H.options,te)===!0&&(G.dndKit={capturedBy:H.sensor},V.current=fe,Tt(K,H))},[E,Tt]),Ot=Ar(h,jn);Fr(h),re(()=>{I&&N===pe.Initializing&&v(pe.Initialized)},[I,N]),l.useEffect(()=>{const{onDragMove:B}=$.current,{active:H,activatorEvent:K,collisions:fe,over:G}=ee.current;if(!H||!K)return;const _={active:H,activatorEvent:K,collisions:fe,delta:{x:ye.x,y:ye.y},over:G};Te.unstable_batchedUpdates(()=>{B==null||B(_),S({type:"onDragMove",event:_})})},[ye.x,ye.y]),l.useEffect(()=>{const{active:B,activatorEvent:H,collisions:K,droppableContainers:fe,scrollAdjustedTranslate:G}=ee.current;if(!B||V.current==null||!H||!G)return;const{onDragOver:_}=$.current,te=fe.get(It),Ce=te&&te.rect.current?{id:te.id,rect:te.rect.current,data:te.data,disabled:te.disabled}:null,P={active:B,activatorEvent:H,collisions:K,delta:{x:G.x,y:G.y},over:Ce};Te.unstable_batchedUpdates(()=>{At(Ce),_==null||_(P),S({type:"onDragOver",event:P})})},[It]),re(()=>{ee.current={activatorEvent:A,active:Y,activeNode:q,collisionRect:we,collisions:Me,droppableRects:se,draggableNodes:E,draggingNode:be,draggingNodeRect:xe,droppableContainers:O,over:ue,scrollableAncestors:de,scrollAdjustedTranslate:ye},W.current={initial:xe,translated:we}},[Y,q,Me,we,E,be,xe,se,O,ue,de,ye]),kr({...ce,delta:T,draggingRect:we,pointerCoordinates:Mt,scrollableAncestors:de,scrollableAncestorRects:He});const In=l.useMemo(()=>({active:Y,activeNode:q,activeNodeRect:I,activatorEvent:A,collisions:Me,containerNodeRect:ke,dragOverlay:ae,draggableNodes:E,droppableContainers:O,droppableRects:se,over:ue,measureDroppableContainers:ve,scrollableAncestors:de,scrollableAncestorRects:He,measuringConfiguration:F,measuringScheduled:Ne,windowRect:it}),[Y,q,I,A,Me,ke,ae,E,O,se,ue,ve,de,He,F,Ne,it]),An=l.useMemo(()=>({activatorEvent:A,activators:Ot,active:Y,activeNodeRect:I,ariaDescribedById:{draggable:Q},dispatch:D,draggableNodes:E,over:ue,measureDroppableContainers:ve}),[A,Ot,Y,I,D,Q,E,ue,ve]);return U.createElement(on.Provider,{value:w},U.createElement(st.Provider,{value:An},U.createElement(xn.Provider,{value:In},U.createElement(yn.Provider,{value:Mn},d)),U.createElement(Jr,{disabled:(a==null?void 0:a.restoreFocus)===!1})),U.createElement(Qn,{...a,hiddenTextDescribedById:Q}));function Tn(){const B=(C==null?void 0:C.autoScrollEnabled)===!1,H=typeof c=="object"?c.enabled===!1:c===!1,K=x&&!B&&!H;return typeof c=="object"?{...c,enabled:K}:{enabled:K}}}),no=l.createContext(null),qt="button",ro="Draggable";function oo(e){let{id:t,data:n,disabled:r=!1,attributes:o}=e;const s=We(ro),{activators:i,activatorEvent:a,active:c,activeNodeRect:d,ariaDescribedById:h,draggableNodes:u,over:g}=l.useContext(st),{role:p=qt,roleDescription:R="draggable",tabIndex:b=0}=o??{},y=(c==null?void 0:c.id)===t,D=l.useContext(y?yn:no),[S,w]=Qe(),[N,v]=Qe(),x=Ur(i,t),m=Pe(n);re(()=>(u.set(t,{id:t,key:s,node:S,activatorNode:N,data:m}),()=>{const T=u.get(t);T&&T.key===s&&u.delete(t)}),[u,t]);const E=l.useMemo(()=>({role:p,tabIndex:b,"aria-disabled":r,"aria-pressed":y&&p===qt?!0:void 0,"aria-roledescription":R,"aria-describedby":h.draggable}),[r,p,b,y,R,h.draggable]);return{active:c,activatorEvent:a,activeNodeRect:d,attributes:E,isDragging:y,listeners:r?void 0:x,node:S,over:g,setNodeRef:w,setActivatorNodeRef:v,transform:D}}function so(){return l.useContext(xn)}const io="Droppable",ao={timeout:25};function lo(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:o}=e;const s=We(io),{active:i,dispatch:a,over:c,measureDroppableContainers:d}=l.useContext(st),h=l.useRef({disabled:n}),u=l.useRef(!1),g=l.useRef(null),p=l.useRef(null),{disabled:R,updateMeasurementsFor:b,timeout:y}={...ao,...o},D=Pe(b??r),S=l.useCallback(()=>{if(!u.current){u.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{d(Array.isArray(D.current)?D.current:[D.current]),p.current=null},y)},[y]),w=ot({callback:S,disabled:R||!i}),N=l.useCallback((E,T)=>{w&&(T&&(w.unobserve(T),u.current=!1),E&&w.observe(E))},[w]),[v,x]=Qe(N),m=Pe(t);return l.useEffect(()=>{!w||!v.current||(w.disconnect(),u.current=!1,w.observe(v.current))},[v,w]),l.useEffect(()=>(a({type:L.RegisterDroppable,element:{id:r,key:s,disabled:n,node:v,rect:g,data:m}}),()=>a({type:L.UnregisterDroppable,key:s,id:r})),[r]),l.useEffect(()=>{n!==h.current.disabled&&(a({type:L.SetDroppableDisabled,id:r,key:s,disabled:n}),h.current.disabled=n)},[r,s,n,a]),{active:i,rect:g,isOver:(c==null?void 0:c.id)===r,node:v,over:c,setNodeRef:x}}function Et(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function co(e,t){return e.reduce((n,r,o)=>{const s=t.get(r);return s&&(n[o]=s),n},Array(e.length))}function _e(e){return e!==null&&e>=0}function uo(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function fo(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const wn=e=>{let{rects:t,activeIndex:n,overIndex:r,index:o}=e;const s=Et(t,r,n),i=t[o],a=s[o];return!a||!i?null:{x:a.left-i.left,y:a.top-i.top,scaleX:a.width/i.width,scaleY:a.height/i.height}},qe={scaleX:1,scaleY:1},ho=e=>{var t;let{activeIndex:n,activeNodeRect:r,index:o,rects:s,overIndex:i}=e;const a=(t=s[n])!=null?t:r;if(!a)return null;if(o===n){const d=s[i];return d?{x:0,y:n<i?d.top+d.height-(a.top+a.height):d.top-a.top,...qe}:null}const c=go(s,o,n);return o>n&&o<=i?{x:0,y:-a.height-c,...qe}:o<n&&o>=i?{x:0,y:a.height+c,...qe}:{x:0,y:0,...qe}};function go(e,t,n){const r=e[t],o=e[t-1],s=e[t+1];return r?n<t?o?r.top-(o.top+o.height):s?s.top-(r.top+r.height):0:s?s.top-(r.top+r.height):o?r.top-(o.top+o.height):0:0}const Cn="Sortable",Sn=U.createContext({activeIndex:-1,containerId:Cn,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:wn,disabled:{draggable:!1,droppable:!1}});function po(e){let{children:t,id:n,items:r,strategy:o=wn,disabled:s=!1}=e;const{active:i,dragOverlay:a,droppableRects:c,over:d,measureDroppableContainers:h}=so(),u=We(Cn,n),g=a.rect!==null,p=l.useMemo(()=>r.map(x=>typeof x=="object"&&"id"in x?x.id:x),[r]),R=i!=null,b=i?p.indexOf(i.id):-1,y=d?p.indexOf(d.id):-1,D=l.useRef(p),S=!uo(p,D.current),w=y!==-1&&b===-1||S,N=fo(s);re(()=>{S&&R&&h(p)},[S,p,R,h]),l.useEffect(()=>{D.current=p},[p]);const v=l.useMemo(()=>({activeIndex:b,containerId:u,disabled:N,disableTransforms:w,items:p,overIndex:y,useDragOverlay:g,sortedRects:co(p,c),strategy:o}),[b,u,N.draggable,N.droppable,w,p,y,c,g,o]);return U.createElement(Sn.Provider,{value:v},t)}const vo=e=>{let{id:t,items:n,activeIndex:r,overIndex:o}=e;return Et(n,r,o).indexOf(t)},mo=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:o,items:s,newIndex:i,previousItems:a,previousContainerId:c,transition:d}=e;return!d||!r||a!==s&&o===i?!1:n?!0:i!==o&&t===c},bo={duration:200,easing:"ease"},Dn="transform",xo=$e.Transition.toString({property:Dn,duration:0,easing:"linear"}),yo={roleDescription:"sortable"};function wo(e){let{disabled:t,index:n,node:r,rect:o}=e;const[s,i]=l.useState(null),a=l.useRef(n);return re(()=>{if(!t&&n!==a.current&&r.current){const c=o.current;if(c){const d=Ee(r.current,{ignoreTransform:!0}),h={x:c.left-d.left,y:c.top-d.top,scaleX:c.width/d.width,scaleY:c.height/d.height};(h.x||h.y)&&i(h)}}n!==a.current&&(a.current=n)},[t,n,r,o]),l.useEffect(()=>{s&&i(null)},[s]),s}function Co(e){let{animateLayoutChanges:t=mo,attributes:n,disabled:r,data:o,getNewIndex:s=vo,id:i,strategy:a,resizeObserverConfig:c,transition:d=bo}=e;const{items:h,containerId:u,activeIndex:g,disabled:p,disableTransforms:R,sortedRects:b,overIndex:y,useDragOverlay:D,strategy:S}=l.useContext(Sn),w=So(r,p),N=h.indexOf(i),v=l.useMemo(()=>({sortable:{containerId:u,index:N,items:h},...o}),[u,o,N,h]),x=l.useMemo(()=>h.slice(h.indexOf(i)),[h,i]),{rect:m,node:E,isOver:T,setNodeRef:O}=lo({id:i,data:v,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:x,...c}}),{active:j,activatorEvent:W,activeNodeRect:Y,attributes:V,setNodeRef:C,listeners:M,isDragging:A,over:oe,setActivatorNodeRef:$,transform:Q}=oo({id:i,data:v,attributes:{...yo,...n},disabled:w.draggable}),Ye=$n(O,C),F=!!j,se=F&&!R&&_e(g)&&_e(y),ve=!D&&A,Ne=ve&&se?Q:null,Ve=se?Ne??(a??S)({rects:b,activeNodeRect:Y,activeIndex:g,overIndex:y,index:N}):null,ce=_e(g)&&_e(y)?s({id:i,items:h,activeIndex:g,overIndex:y}):N,ie=j==null?void 0:j.id,I=l.useRef({activeId:ie,items:h,newIndex:ce,containerId:u}),ke=h!==I.current.items,ee=t({active:j,containerId:u,isDragging:A,isSorting:F,id:i,index:N,items:h,newIndex:I.current.newIndex,previousItems:I.current.items,previousContainerId:I.current.containerId,transition:d,wasDragging:I.current.activeId!=null}),me=wo({disabled:!ee,index:N,node:E,rect:m});return l.useEffect(()=>{F&&I.current.newIndex!==ce&&(I.current.newIndex=ce),u!==I.current.containerId&&(I.current.containerId=u),h!==I.current.items&&(I.current.items=h)},[F,ce,u,h]),l.useEffect(()=>{if(ie===I.current.activeId)return;if(ie!=null&&I.current.activeId==null){I.current.activeId=ie;return}const be=setTimeout(()=>{I.current.activeId=ie},50);return()=>clearTimeout(be)},[ie]),{active:j,activeIndex:g,attributes:V,data:v,rect:m,index:N,newIndex:ce,items:h,isOver:T,isSorting:F,isDragging:A,listeners:M,node:E,overIndex:y,over:oe,setNodeRef:Ye,setActivatorNodeRef:$,setDroppableNodeRef:O,setDraggableNodeRef:C,transform:me??Ve,transition:ae()};function ae(){if(me||ke&&I.current.newIndex===N)return xo;if(!(ve&&!wt(W)||!d)&&(F||ee))return $e.Transition.toString({...d,property:Dn})}}function So(e,t){var n,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e==null?void 0:e.draggable)!=null?n:t.draggable,droppable:(r=e==null?void 0:e.droppable)!=null?r:t.droppable}}function tt(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const Do=[k.Down,k.Right,k.Up,k.Left],Ro=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:o,droppableContainers:s,over:i,scrollableAncestors:a}}=t;if(Do.includes(e.code)){if(e.preventDefault(),!n||!r)return;const c=[];s.getEnabled().forEach(u=>{if(!u||u!=null&&u.disabled)return;const g=o.get(u.id);if(g)switch(e.code){case k.Down:r.top<g.top&&c.push(u);break;case k.Up:r.top>g.top&&c.push(u);break;case k.Left:r.left>g.left&&c.push(u);break;case k.Right:r.left<g.left&&c.push(u);break}});const d=nr({collisionRect:r,droppableRects:o,droppableContainers:c});let h=ln(d,"id");if(h===(i==null?void 0:i.id)&&d.length>1&&(h=d[1].id),h!=null){const u=s.get(n.id),g=s.get(h),p=g?o.get(g.id):null,R=g==null?void 0:g.node.current;if(R&&p&&u&&g){const y=rt(R).some((x,m)=>a[m]!==x),D=Rn(u,g),S=Eo(u,g),w=y||!D?{x:0,y:0}:{x:S?r.width-p.width:0,y:S?r.height-p.height:0},N={x:p.left,y:p.top};return w.x&&w.y?N:Be(N,w)}}}};function Rn(e,t){return!tt(e)||!tt(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function Eo(e,t){return!tt(e)||!tt(t)||!Rn(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}function No(e,t,n){const r={...e};return t.top+e.y<=n.top?r.y=n.top-t.top:t.bottom+e.y>=n.top+n.height&&(r.y=n.top+n.height-t.bottom),t.left+e.x<=n.left?r.x=n.left-t.left:t.right+e.x>=n.left+n.width&&(r.x=n.left+n.width-t.right),r}const ko=e=>{let{containerNodeRect:t,draggingNodeRect:n,transform:r}=e;return!n||!t?r:No(r,n,t)},Mo=e=>{let{transform:t}=e;return{...t,x:0}},jo=/^[a-zA-Z0-9_.\-]+$/;function Bo(){const[e,t]=l.useState([]),[n,r]=l.useState(!0),[o,s]=l.useState(!1),[i,a]=l.useState(null),[c,d]=l.useState([]),[h,u]=l.useState({}),[g,p]=l.useState(null),{copied:R,copy:b}=On();l.useEffect(()=>{y()},[]);const y=async()=>{try{const[v,x,m]=await Promise.all([fetch("/api/combos"),fetch("/api/providers"),fetch("/api/settings")]),E=await v.json(),T=await x.json(),O=m.ok?await m.json():{};v.ok&&t((E.combos||[]).filter(j=>!j.kind)),x.ok&&d(T.connections||[]),u(O.comboStrategies||{})}catch(v){console.log("Error fetching data:",v)}finally{r(!1)}},D=async v=>{try{const x=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});if(x.ok)await y(),s(!1);else{const m=await x.json();alert(m.error||"Failed to create combo")}}catch(x){console.log("Error creating combo:",x)}},S=async(v,x)=>{try{const m=await fetch(`/api/combos/${v}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(m.ok)await y(),a(null);else{const E=await m.json();alert(E.error||"Failed to update combo")}}catch(m){console.log("Error updating combo:",m)}},w=async v=>{p({title:"Delete Combo",message:"Delete this combo?",onConfirm:async()=>{p(null);try{(await fetch(`/api/combos/${v}`,{method:"DELETE"})).ok&&t(e.filter(m=>m.id!==v))}catch(x){console.log("Error deleting combo:",x)}}})},N=async(v,x)=>{try{const m={...h};x&&x!=="fallback"?m[v]={fallbackStrategy:x}:delete m[v],await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({comboStrategies:m})}),u(m)}catch(m){console.log("Error updating combo strategy:",m)}};return n?f.jsxs("div",{className:"flex flex-col gap-6",children:[f.jsx(Lt,{}),f.jsx(Lt,{})]}):f.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[f.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[f.jsxs("div",{className:"min-w-0",children:[f.jsx("h1",{className:"text-2xl font-semibold",children:"Combos"}),f.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Create model combos with fallback support"})]}),f.jsx(Je,{icon:"add",onClick:()=>s(!0),className:"w-full sm:w-auto",children:"Create Combo"})]}),e.length===0?f.jsx(tn,{children:f.jsxs("div",{className:"text-center py-12",children:[f.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 text-primary mb-4",children:f.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"layers"})}),f.jsx("p",{className:"text-text-main font-medium mb-1",children:"No combos yet"}),f.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Create model combos with fallback support"}),f.jsx(Je,{icon:"add",onClick:()=>s(!0),className:"w-full sm:w-auto",children:"Create Combo"})]})}):f.jsx("div",{className:"flex flex-col gap-4",children:e.map(v=>{var x;return f.jsx(Io,{combo:v,copied:R,onCopy:b,onEdit:()=>a(v),onDelete:()=>w(v.id),currentStrategy:((x=h[v.name])==null?void 0:x.fallbackStrategy)||"fallback",onUpdateStrategy:m=>N(v.name,m)},v.id)})}),f.jsx(Gt,{isOpen:o,onClose:()=>s(!1),onSave:D,activeProviders:c},"create"),f.jsx(Gt,{isOpen:!!i,combo:i,onClose:()=>a(null),onSave:v=>S(i.id,v),activeProviders:c},(i==null?void 0:i.id)||"new"),f.jsx(Ln,{isOpen:!!g,onClose:()=>p(null),onConfirm:g==null?void 0:g.onConfirm,title:(g==null?void 0:g.title)||"Confirm",message:g==null?void 0:g.message,variant:"danger"})]})}function Io({combo:e,copied:t,onCopy:n,onEdit:r,onDelete:o,currentStrategy:s,onUpdateStrategy:i}){return f.jsx(tn,{padding:"sm",className:"group",children:f.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[f.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3 sm:items-center",children:[f.jsx("div",{className:"size-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:f.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"})}),f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsx("code",{className:"block truncate font-mono text-sm font-medium",children:e.name}),f.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1",children:[e.models.length===0?f.jsx("span",{className:"text-xs text-text-muted italic",children:"No models"}):e.models.slice(0,3).map((a,c)=>{const d=Jt(a),h=Qt(a),u=Zt(a);return f.jsxs("code",{className:"max-w-full inline-flex items-center gap-1 truncate rounded bg-black/5 px-1.5 py-0.5 font-mono text-[10px] text-text-muted dark:bg-white/5 sm:max-w-[220px]",children:[d&&f.jsx(en,{src:d==="codebuddy"||d==="cb"?"/providers/codebuddy.svg":`/providers/${d}.png`,alt:d,size:10,className:"shrink-0 rounded-sm",fallbackText:d.slice(0,2).toUpperCase()}),f.jsx("span",{className:"truncate",children:a}),h&&f.jsx("span",{className:"material-symbols-outlined shrink-0 text-blue-500",style:{fontSize:"10px"},title:"Vision",children:"visibility"}),u&&f.jsx("span",{className:"material-symbols-outlined shrink-0 text-orange-500",style:{fontSize:"10px"},title:"Thinking",children:"memory"})]},c)}),e.models.length>3&&f.jsxs("span",{className:"text-[10px] text-text-muted",children:["+",e.models.length-3," more"]})]})]})]}),f.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-3 sm:shrink-0",children:[f.jsxs("div",{className:"flex items-center justify-between gap-1.5 rounded-lg bg-black/[0.02] px-2 py-1 dark:bg-white/[0.02] sm:justify-start sm:bg-transparent sm:px-0 sm:py-0 sm:dark:bg-transparent",children:[f.jsx("span",{className:"text-xs text-text-muted font-medium mr-1",children:"Strategy:"}),f.jsxs("select",{value:s,onChange:a=>i(a.target.value),className:"text-xs font-medium rounded border border-black/10 bg-transparent py-1 px-2 outline-none dark:border-white/10 dark:bg-black/20 text-text-main cursor-pointer",children:[f.jsx("option",{value:"fallback",className:"dark:bg-zinc-900",children:"Fallback (Priority)"}),f.jsx("option",{value:"round-robin",className:"dark:bg-zinc-900",children:"Round Robin"}),f.jsx("option",{value:"fusion",className:"dark:bg-zinc-900",children:"Fusion (Synthesis)"})]})]}),f.jsxs("div",{className:"grid grid-cols-3 gap-1 sm:flex",children:[f.jsxs("button",{onClick:a=>{a.stopPropagation(),n(e.name,`combo-${e.id}`)},className:"flex flex-col items-center rounded px-2 py-1 text-text-muted transition-colors hover:bg-black/5 hover:text-primary dark:hover:bg-white/5",title:"Copy combo name",children:[f.jsx("span",{className:"material-symbols-outlined text-[18px]",children:t===`combo-${e.id}`?"check":"content_copy"}),f.jsx("span",{className:"text-[10px] leading-tight",children:"Copy"})]}),f.jsxs("button",{onClick:r,className:"flex flex-col items-center rounded px-2 py-1 text-text-muted transition-colors hover:bg-black/5 hover:text-primary dark:hover:bg-white/5",title:"Edit",children:[f.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"}),f.jsx("span",{className:"text-[10px] leading-tight",children:"Edit"})]}),f.jsxs("button",{onClick:o,className:"flex flex-col items-center rounded px-2 py-1 text-red-500 transition-colors hover:bg-red-500/10",title:"Delete",children:[f.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"}),f.jsx("span",{className:"text-[10px] leading-tight",children:"Delete"})]})]})]})]})})}function Ao({id:e,index:t,model:n,isFirst:r,isLast:o,onEdit:s,onMoveUp:i,onMoveDown:a,onRemove:c}){const{attributes:d,listeners:h,setNodeRef:u,transform:g,isDragging:p}=Co({id:e}),R={transform:$e.Transform.toString(g),opacity:p?.4:1,zIndex:p?999:void 0},[b,y]=l.useState(!1),[D,S]=l.useState(n),w=()=>{const v=D.trim();v&&v!==n?s(v):S(n),y(!1)},N=v=>{v.key==="Enter"&&w(),v.key==="Escape"&&(S(n),y(!1))};return f.jsxs("div",{ref:u,style:R,className:`group flex min-w-0 items-center gap-1.5 rounded-md px-2 py-1 bg-black/[0.02] hover:bg-black/[0.04] dark:bg-white/[0.02] dark:hover:bg-white/[0.04] transition-colors ${p?"shadow-md ring-1 ring-primary/30":""}`,children:[f.jsx("button",{...d,...h,type:"button",className:"cursor-grab touch-none p-0.5 rounded text-text-muted hover:text-primary active:cursor-grabbing shrink-0",title:"Drag to reorder",children:f.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[f.jsx("circle",{cx:"9",cy:"4",r:"2"}),f.jsx("circle",{cx:"15",cy:"4",r:"2"}),f.jsx("circle",{cx:"9",cy:"12",r:"2"}),f.jsx("circle",{cx:"15",cy:"12",r:"2"}),f.jsx("circle",{cx:"9",cy:"20",r:"2"}),f.jsx("circle",{cx:"15",cy:"20",r:"2"})]})}),f.jsx("span",{className:"text-[10px] font-medium text-text-muted w-3 text-center shrink-0",children:t+1}),b?f.jsx("input",{autoFocus:!0,value:D,onChange:v=>S(v.target.value),onBlur:w,onKeyDown:N,className:"min-w-0 flex-1 rounded border border-primary/40 bg-white px-1.5 py-0.5 font-mono text-xs text-text-main outline-none dark:bg-black/20"}):(()=>{const v=Jt(n),x=Qt(n),m=Zt(n);return f.jsxs("div",{className:"min-w-0 flex-1 cursor-text truncate rounded px-1.5 py-0.5 font-mono text-xs text-text-main hover:bg-black/5 dark:hover:bg-white/5 flex items-center gap-1.5",onClick:()=>y(!0),title:"Click to edit",children:[v&&f.jsx(en,{src:v==="codebuddy"||v==="cb"?"/providers/codebuddy.svg":`/providers/${v}.png`,alt:v,size:12,className:"shrink-0 rounded-sm",fallbackText:v.slice(0,2).toUpperCase()}),f.jsx("span",{className:"truncate",children:n}),x&&f.jsx("span",{className:"material-symbols-outlined shrink-0 text-blue-500",style:{fontSize:"12px"},title:"Vision",children:"visibility"}),m&&f.jsx("span",{className:"material-symbols-outlined shrink-0 text-orange-500",style:{fontSize:"12px"},title:"Thinking",children:"memory"})]})})(),f.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[f.jsx("button",{onClick:i,disabled:r,className:`p-0.5 rounded ${r?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:"Move up",children:f.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_upward"})}),f.jsx("button",{onClick:a,disabled:o,className:`p-0.5 rounded ${o?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:"Move down",children:f.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_downward"})})]}),f.jsx("button",{onClick:c,className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all",title:"Remove",children:f.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]})}function Gt({isOpen:e,combo:t,onClose:n,onSave:r,activeProviders:o,kindFilter:s=null}){const[i,a]=l.useState((t==null?void 0:t.name)||""),[c,d]=l.useState((t==null?void 0:t.models)||[]),[h,u]=l.useState(!1),[g,p]=l.useState(!1),[R,b]=l.useState(""),[y,D]=l.useState({}),S=Zn(Pt(Rt,{activationConstraint:{distance:5}}),Pt(St,{coordinateGetter:Ro})),w=c.map((C,M)=>({uid:`item-${M}`,model:C})),N=C=>{const{active:M,over:A}=C;if(A&&M.id!==A.id){const oe=w.findIndex(Q=>Q.uid===M.id),$=w.findIndex(Q=>Q.uid===A.id);oe!==-1&&$!==-1&&d(Q=>Et(Q,oe,$))}},v=async()=>{try{const C=await fetch("/api/models/alias");if(!C.ok)return;const M=await C.json();D(M.aliases||{})}catch(C){console.error("Error fetching modal data:",C)}};l.useEffect(()=>{e&&v()},[e]);const x=C=>C.trim()?jo.test(C)?(b(""),!0):(b("Only letters, numbers, -, _ and . allowed"),!1):(b("Name is required"),!1),m=C=>{const M=C.target.value;a(M),M?x(M):b("")},E=C=>{c.includes(C.value)||d([...c,C.value])},T=C=>{d(c.filter(M=>M!==C.value))},O=C=>{d(c.filter((M,A)=>A!==C))},j=C=>{if(C===0)return;const M=[...c];[M[C-1],M[C]]=[M[C],M[C-1]],d(M)},W=C=>{if(C===c.length-1)return;const M=[...c];[M[C],M[C+1]]=[M[C+1],M[C]],d(M)},Y=async()=>{x(i)&&(p(!0),await r({name:i.trim(),models:c}),p(!1))},V=!!t;return f.jsxs(f.Fragment,{children:[f.jsx(zn,{isOpen:e,onClose:n,title:V?"Edit Combo":"Create Combo",children:f.jsxs("div",{className:"flex flex-col gap-3",children:[f.jsxs("div",{children:[f.jsx(Pn,{label:"Combo Name",value:i,onChange:m,placeholder:"my-combo",error:R}),f.jsx("p",{className:"text-[10px] text-text-muted mt-0.5",children:"Only letters, numbers, -, _ and . allowed"})]}),f.jsxs("div",{children:[f.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Models"}),c.length===0?f.jsxs("div",{className:"text-center py-4 border border-dashed border-black/10 dark:border-white/10 rounded-lg bg-black/[0.01] dark:bg-white/[0.01]",children:[f.jsx("span",{className:"material-symbols-outlined text-text-muted text-xl mb-1",children:"layers"}),f.jsx("p",{className:"text-xs text-text-muted",children:"No models added yet"})]}):f.jsx(to,{sensors:S,collisionDetection:tr,onDragEnd:N,modifiers:[Mo,ko],children:f.jsx(po,{items:w.map(C=>C.uid),strategy:ho,children:f.jsx("div",{className:"flex max-h-[55vh] min-w-0 flex-col gap-1 overflow-y-auto sm:max-h-[350px]",children:w.map(({uid:C,model:M},A)=>f.jsx(Ao,{id:C,index:A,model:M,isFirst:A===0,isLast:A===w.length-1,onEdit:oe=>{const $=[...c];$[A]=oe,d($)},onMoveUp:()=>j(A),onMoveDown:()=>W(A),onRemove:()=>O(A)},C))})})}),f.jsxs("button",{onClick:()=>u(!0),className:"w-full mt-2 py-2 border border-dashed border-black/10 dark:border-white/10 rounded-lg text-xs text-primary font-medium hover:text-primary hover:border-primary/50 transition-colors flex items-center justify-center gap-1",children:[f.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Model"]})]}),f.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row",children:[f.jsx(Je,{onClick:n,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),f.jsx(Je,{onClick:Y,fullWidth:!0,size:"sm",disabled:!i.trim()||!!R||g,children:g?"Saving...":V?"Save":"Create"})]})]})}),f.jsx(Bn,{isOpen:h,onClose:()=>u(!1),onSelect:E,onDeselect:T,activeProviders:o,modelAliases:y,title:"Add Model to Combo",kindFilter:s,addedModelValues:c,closeOnSelect:!1})]})}export{Bo as default};
@@ -0,0 +1 @@
1
+ import{j as s,B as Be,k as je,l as Ie,h as Le}from"./index.AIBoioDI.js";import{b as d}from"./router.Cjj1--8t.js";import{B as qe}from"./NoAuthProxyCard.CZTUlj4t.js";import"./zustand.akaTi5uX.js";const O={sessions:"basic-chat.sessions",activeSessionId:"basic-chat.activeSessionId",activeProviderId:"basic-chat.activeProviderId",draft:"basic-chat.draft"};function J(){var e;return(e=globalThis.crypto)!=null&&e.randomUUID?globalThis.crypto.randomUUID():`chat_${Date.now()}_${Math.random().toString(16).slice(2)}`}function Fe(e,a){try{return JSON.parse(e)}catch{return a}}function S(e){if(typeof e=="string")return e;if(e==null)return"";if(Array.isArray(e))return e.map(S).filter(Boolean).join(" ");if(typeof e=="object"){if(typeof e.message=="string")return e.message;if(typeof e.error=="string")return e.error;try{return JSON.stringify(e)}catch{return String(e)}}return String(e)}function He(e=""){return String(e).replace(/[-_]/g," ").replace(/\b\w/g,a=>a.toUpperCase()).trim()||"Unknown"}function Je(e){if(!e)return"Now";const a=new Date(e).getTime();if(Number.isNaN(a))return"Now";const m=Math.max(1,Math.round((Date.now()-a)/6e4));if(m<60)return`${m}m`;const u=Math.round(m/60);return u<24?`${u}h`:`${Math.round(u/24)}d`}function Ne(e=""){const a=S(e).replace(/\s+/g," ").trim();return a?a.length>52?`${a.slice(0,52).trimEnd()}…`:a:"New chat"}function Ke(e){const a=S(e.content).trim(),m=Array.isArray(e.attachments)?e.attachments:[];if(m.length===0)return a;const u=[];a&&u.push({type:"text",text:a});for(const w of m)w!=null&&w.dataUrl&&u.push({type:"image_url",image_url:{url:w.dataUrl}});return u.length>0?u:a}function We(e){var w,A;if(!e||typeof e!="object")return"";const a=(w=e.choices)==null?void 0:w[0];return[((a==null?void 0:a.delta)||{}).content,(A=a==null?void 0:a.message)==null?void 0:A.content,e.output_text,e.text].map(S).filter(Boolean)[0]||""}async function Ye(e){return await new Promise((a,m)=>{const u=new FileReader;u.onload=()=>a(String(u.result||"")),u.onerror=()=>m(u.error||new Error("Failed to read file")),u.readAsDataURL(e)})}function Ve(e){return{...e,messages:Array.isArray(e.messages)?e.messages.map(a=>({...a})):[]}}function de(e){return(e==null?void 0:e.name)||He((e==null?void 0:e.provider)||(e==null?void 0:e.id)||"provider")}function Ge(e,a){return e!=null&&e.id?{id:`${a.provider}/${e.id}`,requestModel:`${a.provider}/${e.id}`,name:e.name||e.id,providerId:a.provider,providerName:de(a),source:"static"}:null}function Qe(e,a){const m=typeof e=="string"?e:(e==null?void 0:e.id)||(e==null?void 0:e.name)||(e==null?void 0:e.model)||"";if(!m)return null;const u=typeof e=="string"?e:(e==null?void 0:e.name)||(e==null?void 0:e.displayName)||m;let w=m;return(je(a.provider)||Ie(a.provider))&&!m.includes("/")&&(w=`${a.provider}/${m}`),{id:w,requestModel:w,name:u,providerId:a.provider,providerName:de(a),source:"live"}}function Xe(e){return Array.isArray(e==null?void 0:e.models)?e.models:Array.isArray(e==null?void 0:e.data)?e.data:Array.isArray(e==null?void 0:e.results)?e.results:Array.isArray(e)?e:[]}function Ze(e){const a=new Map;for(const m of e)m!=null&&m.id&&(a.has(m.id)||a.set(m.id,m));return Array.from(a.values())}function et(){const[e,a]=d.useState([]),[m,u]=d.useState(!0),[w,A]=d.useState(""),[h,D]=d.useState(()=>{if(typeof window>"u")return[];try{const t=Fe(globalThis.localStorage.getItem(O.sessions),[]);return Array.isArray(t)?t.map(r=>({...r,messages:Array.isArray(r.messages)?r.messages:[]})):[]}catch{return[]}}),[g,M]=d.useState(()=>typeof window>"u"?"":globalThis.localStorage.getItem(O.activeSessionId)||""),[R,P]=d.useState(()=>typeof window>"u"?"":globalThis.localStorage.getItem(O.activeProviderId)||""),[I,U]=d.useState(""),[_,ce]=d.useState(()=>typeof window>"u"?"":globalThis.localStorage.getItem(O.draft)||""),[z,Q]=d.useState([]),[me,ue]=d.useState(!1),[Se,pe]=d.useState(""),[fe,X]=d.useState(""),[K,Ae]=d.useState(!1),[Me,Z]=d.useState(!1),[De,ee]=d.useState(!1),xe=d.useRef(null),B=d.useRef(null),te=d.useRef(!1),se=d.useRef(null),re=d.useRef(null);d.useEffect(()=>{Ae(!0)},[]),d.useEffect(()=>{let t=!1;async function r(){u(!0),A("");try{const n=await(await fetch("/api/providers",{cache:"no-store"})).json().catch(()=>({})),o=Array.isArray(n.connections)?n.connections.filter(c=>(c==null?void 0:c.isActive)!==!1):[];if(o.length===0){t||(a([]),A("No providers connected yet."));return}const x=new Map;for(const c of o){const p=c.provider||c.id,b=de(c),$=je(p)?"openai-compatible":Ie(p)?"anthropic-compatible":p;x.has(p)||x.set(p,{providerId:p,providerName:b,providerType:$,connections:[],models:[]});const N=x.get(p);N.providerName=N.providerName||b,N.providerType=N.providerType||$,N.connections.push(c);const W=Le(p).map(Y=>Ge(Y,c)).filter(Boolean);N.models.push(...W)}const k=await Promise.all(o.map(async c=>{try{const p=await fetch(`/api/providers/${c.id}/models`,{cache:"no-store"}),b=await p.json().catch(()=>({}));if(!p.ok)return{connection:c,models:[]};const $=Xe(b).map(N=>Qe(N,c)).filter(Boolean);return{connection:c,models:$}}catch{return{connection:c,models:[]}}}));for(const c of k){const p=c.connection.provider||c.connection.id,b=x.get(p);b&&b.models.push(...c.models)}const q=Array.from(x.values()).map(c=>({...c,models:Ze(c.models).sort((p,b)=>p.name.localeCompare(b.name))})).filter(c=>c.models.length>0).sort((c,p)=>c.providerName.localeCompare(p.providerName));t||(a(q),q.length===0&&A("Providers connected but no models available."))}catch(i){t||(A(S(i==null?void 0:i.message)||"Failed to load providers/models."),a([]))}finally{t||u(!1)}}return r(),()=>{t=!0}},[]),d.useEffect(()=>{const t=r=>{se.current&&!se.current.contains(r.target)&&Z(!1),re.current&&!re.current.contains(r.target)&&ee(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[]);const y=d.useMemo(()=>{const t=new Map;for(const r of e)for(const i of r.models)t.set(i.id,{...i,providerId:r.providerId,providerName:r.providerName});return t},[e]),E=d.useMemo(()=>e.find(t=>t.providerId===R)||e[0]||null,[e,R]),v=d.useMemo(()=>{var t;if(I&&y.has(I))return y.get(I);if(g){const r=h.find(i=>i.id===g);if(r!=null&&r.modelId&&y.has(r.modelId))return y.get(r.modelId)}return((t=E==null?void 0:E.models)==null?void 0:t[0])||null},[I,y,E,h,g]),ie=d.useMemo(()=>h.find(t=>t.id===g)||null,[h,g]),he=(ie==null?void 0:ie.messages)||[],ge=d.useMemo(()=>[...h].sort((t,r)=>new Date(r.updatedAt).getTime()-new Date(t.updatedAt).getTime()),[h]),ae=!me&&!!v&&(_.trim().length>0||z.length>0);d.useEffect(()=>{if(K)try{globalThis.localStorage.setItem(O.sessions,JSON.stringify(h)),globalThis.localStorage.setItem(O.activeSessionId,g),globalThis.localStorage.setItem(O.activeProviderId,R),globalThis.localStorage.setItem(O.draft,_)}catch{}},[K,h,g,R,_]),d.useEffect(()=>{if(!K||m||te.current||e.length===0)return;const t=e.find(n=>n.providerId===R)||e[0],r=I&&y.has(I)?y.get(I):t.models[0];if(h.length>0){const n=h.find(x=>x.id===g)||h[0],o=n!=null&&n.modelId&&y.has(n.modelId)?y.get(n.modelId):r;te.current=!0,M(n.id),P((o==null?void 0:o.providerId)||t.providerId),U((o==null?void 0:o.id)||r.id);return}const i={id:J(),title:"New chat",providerId:t.providerId,providerName:t.providerName,modelId:r.id,modelName:r.name,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messages:[]};te.current=!0,D([i]),M(i.id),P(t.providerId),U(r.id)},[K,m,e,y,h,g,R,I]);const L=(t,r)=>{D(i=>i.map(n=>n.id===t?r(Ve(n)):n))},ne=t=>t?{id:J(),title:"New chat",providerId:t.providerId,providerName:t.providerName,modelId:t.id,modelName:t.name,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messages:[]}:null,ke=t=>{const r=h.find(i=>i.id===t);r&&(M(t),P(r.providerId||R),U(r.modelId||I),ee(!1))},Te=()=>{if(!g)return;const t=h.filter(i=>i.id!==g),r=t[0]||null;D(t),r?(M(r.id),P(r.providerId),U(r.modelId)):(M(""),P(""),U(""))},Ce=t=>{const r=y.get(t);if(!r)return;const i=h.find(n=>n.id===g);if(i&&i.messages.length>0){const n=ne(r);if(!n)return;D(o=>[n,...o]),M(n.id)}else if(i)D(n=>n.map(o=>o.id===i.id?{...o,providerId:r.providerId,providerName:r.providerName,modelId:r.id,modelName:r.name}:o)),M(i.id);else{const n=ne(r);if(!n)return;D(o=>[n,...o]),M(n.id)}P(r.providerId),U(r.id),Z(!1)},Oe=async t=>{const r=Array.from(t.target.files||[]);if(r.length===0)return;const i=r.filter(o=>o.type.startsWith("image/"));if(i.length===0){t.target.value="";return}const n=await Promise.all(i.map(async o=>({id:J(),name:o.name,type:o.type,size:o.size,dataUrl:await Ye(o)})));Q(o=>[...o,...n]),t.target.value=""},Re=t=>{Q(r=>r.filter(i=>i.id!==t))},Ee=()=>{var t;(t=B.current)==null||t.abort()},$e=(t,r)=>{const i=Ne(r);L(t,n=>({...n,title:n.title==="New chat"?i:n.title,updatedAt:new Date().toISOString()}))},we=async()=>{var p,b,$,N,W,Y;const t=v||((p=E==null?void 0:E.models)==null?void 0:p[0])||null;if(!t)return;const r=_.trim();if(!r&&z.length===0)return;let i=g,n=h.find(l=>l.id===i);if(!n){if(n=ne(t),!n)return;i=n.id,D(l=>[n,...l]),M(i)}const o={id:J(),role:"user",content:r,attachments:z.map(l=>({id:l.id,name:l.name,type:l.type,dataUrl:l.dataUrl})),createdAt:new Date().toISOString()},x=J(),k={id:x,role:"assistant",content:"",createdAt:new Date().toISOString(),status:"streaming"},q=[...n.messages||[],o,k];D(l=>l.map(j=>j.id===i?{...j,providerId:t.providerId,providerName:t.providerName,modelId:t.id,modelName:t.name,messages:q,updatedAt:new Date().toISOString(),title:j.title==="New chat"?Ne(r):j.title}:j)),ce(""),Q([]),ue(!0),pe(x),X(""),(b=B.current)==null||b.abort(),B.current=new AbortController;const c=q.filter(l=>!(l.role==="assistant"&&l.id===x)).map(l=>({role:l.role,content:l.role==="user"?Ke(l):l.content}));try{const l=await fetch("/api/dashboard/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify({model:t.requestModel||t.id,messages:c,stream:!0}),signal:B.current.signal});if(!l.ok){const f=await l.json().catch(()=>({}));throw new Error(S(f.error||f.message||`Request failed (${l.status})`))}const j=($=l.body)==null?void 0:$.getReader();if(!j){const f=await l.json().catch(()=>({})),C=S(((Y=(W=(N=f==null?void 0:f.choices)==null?void 0:N[0])==null?void 0:W.message)==null?void 0:Y.content)||(f==null?void 0:f.output_text)||(f==null?void 0:f.error)||(f==null?void 0:f.message)||"");L(i,F=>({...F,messages:F.messages.map(H=>H.id===x?{...H,content:C,status:"done"}:H),updatedAt:new Date().toISOString()}));return}const V=new TextDecoder;let T="",G="";for(;;){const{value:f,done:C}=await j.read();if(C)break;T+=V.decode(f,{stream:!0});const F=T.split(/\r?\n/);T=F.pop()||"";for(const H of F){const ve=H.trim();if(!ve.startsWith("data:"))continue;const oe=ve.slice(5).trim();if(!(!oe||oe==="[DONE]"))try{const ze=JSON.parse(oe),be=We(ze);if(!be)continue;G+=be,X(G),L(i,ye=>({...ye,messages:ye.messages.map(le=>le.id===x?{...le,content:G,status:"streaming"}:le),updatedAt:new Date().toISOString()}))}catch{}}}L(i,f=>({...f,messages:f.messages.map(C=>C.id===x?{...C,content:G||C.content,status:"done"}:C),updatedAt:new Date().toISOString()})),$e(i,r)}catch(l){if(l.name!=="AbortError"){const j=S((l==null?void 0:l.message)||l);L(i,V=>({...V,messages:V.messages.map(T=>T.id===x?{...T,content:T.content||`Error: ${j}`,status:"error"}:T),updatedAt:new Date().toISOString()})),A(j||"Failed to send message.")}}finally{ue(!1),pe(""),X(""),B.current=null}},Pe=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),ae&&we())},Ue=v?`${v.name}`:"Select model",_e=v?v.requestModel:"Choose from connected providers";return s.jsx("div",{className:"relative flex-1 flex flex-col h-full min-h-0 min-w-0 bg-[#212121] text-white overflow-hidden",children:s.jsxs("div",{className:"relative mx-auto flex flex-1 h-full min-h-0 w-full max-w-4xl flex-col",children:[s.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 px-4 py-3 lg:px-6",children:[s.jsxs("div",{ref:se,className:"relative",children:[s.jsx("button",{type:"button",onClick:()=>Z(t=>!t),className:"flex items-center gap-3 rounded-2xl border border-white/10 bg-white/5 px-4 py-3 text-left transition hover:bg-white/8",children:s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-sm font-semibold text-white",children:Ue}),s.jsx("span",{className:"material-symbols-outlined text-[18px] text-white/70",children:"expand_more"})]}),s.jsx("p",{className:"truncate text-xs text-white/55",children:_e})]})}),Me?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+10px)] z-30 w-[min(520px,calc(100vw-2rem))] overflow-hidden rounded-[20px] border border-white/10 bg-[#262626] shadow-2xl shadow-black/50",children:[s.jsxs("div",{className:"border-b border-white/10 px-4 py-3",children:[s.jsx("p",{className:"text-xs uppercase tracking-[0.22em] text-white/45",children:"Models"}),s.jsx("p",{className:"text-sm text-white/75",children:"Only from connected providers"})]}),s.jsx("div",{className:"max-h-[60vh] overflow-y-auto p-2 custom-scrollbar",children:e.map(t=>s.jsxs("div",{className:"mb-2 rounded-[16px] border border-white/10 bg-black/20 p-2",children:[s.jsxs("div",{className:"flex items-center justify-between px-2 py-2",children:[s.jsx("p",{className:"text-sm font-semibold text-white",children:t.providerName}),s.jsx(qe,{size:"sm",variant:"default",children:t.models.length})]}),s.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:t.models.map(r=>{const i=r.id===I;return s.jsx("button",{type:"button",onClick:()=>Ce(r.id),className:`rounded-[14px] border px-3 py-3 text-left transition ${i?"border-blue-400/40 bg-blue-500/15":"border-white/10 bg-white/5 hover:bg-white/8"}`,children:s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"truncate text-sm font-medium text-white",children:r.name}),s.jsx("p",{className:"truncate text-[11px] text-white/45",children:r.requestModel})]}),i?s.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-300",children:"check_circle"}):null]})},r.id)})})]},t.providerId))})]}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{type:"button",onClick:()=>ee(t=>!t),className:"rounded-2xl border border-white/10 bg-white/5 px-4 py-3 text-sm text-white/80 transition hover:bg-white/8",children:"History"}),s.jsx(Be,{variant:"ghost",size:"sm",icon:"delete",onClick:Te,disabled:!g||h.length===0,children:"Clear"})]})]}),De?s.jsxs("div",{ref:re,className:"absolute right-4 top-[72px] z-20 w-[min(360px,calc(100vw-2rem))] rounded-[20px] border border-white/10 bg-[#262626] p-2 shadow-2xl shadow-black/50 lg:right-6",children:[s.jsx("div",{className:"px-3 py-2",children:s.jsx("p",{className:"text-xs uppercase tracking-[0.22em] text-white/45",children:"Recent chats"})}),s.jsx("div",{className:"max-h-[48vh] space-y-2 overflow-y-auto p-1 custom-scrollbar",children:ge.length===0?s.jsx("div",{className:"rounded-[16px] border border-dashed border-white/10 bg-white/5 p-4 text-sm text-white/55",children:"No conversations yet."}):ge.map(t=>{var n;const r=t.id===g,i=[...t.messages||[]].reverse().find(o=>o.role==="user")||((n=t.messages)==null?void 0:n[0]);return s.jsx("button",{type:"button",onClick:()=>ke(t.id),className:`w-full rounded-[16px] border px-3 py-3 text-left transition ${r?"border-blue-400/40 bg-blue-500/15":"border-white/10 bg-white/5 hover:bg-white/8"}`,children:s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate text-sm font-medium text-white",children:t.title}),s.jsx("p",{className:"mt-1 truncate text-xs text-white/50",children:S(i==null?void 0:i.content)||"Empty chat"})]}),s.jsx("span",{className:"text-[10px] text-white/40 shrink-0",children:Je(t.updatedAt)})]})},t.id)})})]}):null,w?s.jsx("div",{className:"mt-4 rounded-[18px] border border-rose-500/20 bg-rose-500/10 px-4 py-3 text-rose-100",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"error"}),s.jsx("p",{className:"text-sm leading-6",children:w})]})}):null,s.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[s.jsxs("div",{className:"flex-1 overflow-y-auto py-4 custom-scrollbar",children:[he.length===0?s.jsx("div",{className:"flex min-h-[50vh] items-center justify-center px-4 text-center",children:s.jsxs("div",{className:"max-w-xl space-y-4",children:[s.jsx("div",{className:"mx-auto flex size-16 items-center justify-center rounded-[20px] border border-white/10 bg-white/5 text-white/80",children:s.jsx("span",{className:"material-symbols-outlined text-[30px]",children:"chat"})}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("h2",{className:"text-2xl font-semibold text-white",children:"Start a conversation"}),s.jsx("p",{className:"text-sm leading-6 text-white/60",children:"Simple chat interface to interact with any AI model from connected providers. Select a model and start chatting!"})]})]})}):null,s.jsx("div",{className:"mx-auto flex w-full max-w-3xl flex-col gap-4 px-4",children:he.map(t=>{var x;const r=t.role==="user",i=t.role==="assistant",n=i&&t.id===Se&&t.status==="streaming",o=S(t.content)||(i?fe:"");return s.jsx("div",{className:`flex w-full ${r?"justify-end":"justify-start"} mb-6`,children:s.jsxs("div",{className:`max-w-[min(88%,42rem)] ${r?"rounded-3xl bg-[#2f2f2f] px-5 py-3.5 text-white":"text-white/90"}`,children:[s.jsx("div",{className:"mb-1 flex items-center justify-between gap-3",children:s.jsx("span",{className:"text-xs font-semibold",children:r?"You":(v==null?void 0:v.name)||"Assistant"})}),(x=t.attachments)!=null&&x.length?s.jsx("div",{className:"mb-3 grid grid-cols-2 gap-2 sm:grid-cols-3 mt-2",children:t.attachments.map(k=>s.jsx("a",{href:k.dataUrl,target:"_blank",rel:"noreferrer",className:"overflow-hidden rounded-[18px] border border-white/10 bg-black/20",children:s.jsx("img",{src:k.dataUrl,alt:k.name,className:"h-28 w-full object-cover"})},k.id))}):null,s.jsxs("div",{className:"whitespace-pre-wrap break-words text-[15px] leading-7",children:[o,i&&n&&!fe?s.jsx("span",{className:"inline-block animate-pulse",children:"▋"}):null]})]})},t.id)})})]}),s.jsxs("div",{className:"shrink-0 pt-2",children:[z.length>0?s.jsx("div",{className:"mx-auto mb-3 flex w-full max-w-3xl flex-wrap gap-2 px-4",children:z.map(t=>s.jsxs("div",{className:"flex items-center gap-2 rounded-full border border-white/10 bg-white/5 px-3 py-2",children:[s.jsx("span",{className:"text-xs text-white/80 max-w-[12rem] truncate",children:t.name}),s.jsx("button",{type:"button",onClick:()=>Re(t.id),className:"text-white/55 hover:text-white","aria-label":"Remove attachment",children:s.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]},t.id))}):null,s.jsx("div",{className:"mx-auto w-full max-w-3xl px-4 pb-2",children:s.jsxs("div",{className:"rounded-[26px] bg-[#2f2f2f] px-3 pt-3 pb-2 shadow-[0_0_15px_rgba(0,0,0,0.10)] ring-1 ring-white/5",children:[s.jsx("textarea",{value:_,onChange:t=>ce(t.target.value),onKeyDown:Pe,placeholder:"Message AI",rows:1,className:"w-full resize-none bg-transparent px-2 text-[15px] leading-6 text-white outline-none placeholder:text-white/40 custom-scrollbar max-h-[25vh] overflow-y-auto"}),s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("button",{type:"button",onClick:()=>{var t;return(t=xe.current)==null?void 0:t.click()},disabled:!v||m,className:"p-2 text-white/50 hover:text-white transition rounded-full hover:bg-white/5",children:s.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"attach_file"})}),s.jsx("input",{ref:xe,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:Oe}),s.jsx("span",{className:"text-xs font-medium text-white/30 truncate max-w-[120px]",children:v?v.name:"No model"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[me?s.jsx("button",{type:"button",onClick:Ee,className:"p-2 text-white bg-white/10 hover:bg-white/20 transition rounded-full h-8 w-8 flex items-center justify-center",children:s.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"stop"})}):null,s.jsx("button",{onClick:we,disabled:!ae,className:`h-8 w-8 rounded-full flex items-center justify-center transition ${ae?"bg-white text-black hover:opacity-90":"bg-white/10 text-white/30 cursor-not-allowed"}`,children:s.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_upward"})})]})]})]})})]}),s.jsx("p",{className:"mx-auto mt-2 max-w-3xl px-4 pb-4 text-center text-[11px] text-white/30",children:"Model list is filtered from connected providers."})]})]})})}function at(){return s.jsx(et,{})}export{at as default};
@@ -0,0 +1 @@
1
+ import{u as Re,r as ce,v as Ue,j as t,M as Ie,B as b,C as Oe}from"./index.AIBoioDI.js";import{b as s}from"./router.Cjj1--8t.js";import{C as Be,T as y,I as Me}from"./NoAuthProxyCard.CZTUlj4t.js";import"./zustand.akaTi5uX.js";const $e=["zh-CN","zh-TW"],S=[{id:"lite",label:"Lite",desc:"Drop filler, keep grammar"},{id:"full",label:"Full",desc:"Drop articles, fragments OK"},{id:"ultra",label:"Ultra",desc:"Telegraphic, max compression"},{id:"wenyan-lite",label:"文 Lite",desc:"Classical Chinese, light compression",wenyan:!0},{id:"wenyan",label:"文 Full",desc:"Maximum 文言文, 80-90% reduction",wenyan:!0},{id:"wenyan-ultra",label:"文 Ultra",desc:"Extreme classical compression",wenyan:!0}],de=[{id:"lite",label:"Lite",desc:"Build asked, name lazier option"},{id:"full",label:"Full",desc:"Ladder enforced: stdlib/native first"},{id:"ultra",label:"Ultra",desc:"YAGNI extremist, deletion first"}];function Ke(){var le,ie;const[M,$]=s.useState(!0),[D,J]=s.useState(!1),[L,j]=s.useState("http://localhost:8787"),[l,T]=s.useState({installed:!1,running:!1,python:null,loading:!0}),[me,A]=s.useState(!1),[v,w]=s.useState(!1),[_,G]=s.useState(""),[N,h]=s.useState({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),[c,x]=s.useState([]),[P,K]=s.useState(!1),[W,p]=s.useState(""),[H,z]=s.useState(null),[F,Y]=s.useState(""),[n,C]=s.useState(null),[he,V]=s.useState(!1),[xe,q]=s.useState(!0),[Q,X]=s.useState(!1),u=s.useRef(null),[R,Z]=s.useState(!1),[k,U]=s.useState("full"),[I,ee]=s.useState(!1),[te,ae]=s.useState("full"),[pe,se]=s.useState("en"),{copied:ue,copy:fe}=Re();s.useEffect(()=>(se(ce()),Ue(()=>se(ce()))),[]);const O=$e.includes(pe),ge=O?S:S.filter(e=>!e.wenyan);s.useEffect(()=>{const e=S.find(a=>a.id===k);e!=null&&e.wenyan&&!O&&(U("ultra"),m({cavemanLevel:"ultra"}))},[O,k]);const m=async e=>{try{await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(a){console.log("Error updating setting:",a)}},be=async e=>{try{(await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({rtkEnabled:e})})).ok&&$(e)}catch(a){console.log("Error updating rtkEnabled:",a)}},ye=e=>{Z(e),m({cavemanEnabled:e})},je=e=>{U(e),m({cavemanLevel:e})},ve=e=>{const a=L.trim()||"http://localhost:8787";j(a),J(e),m({headroomEnabled:e,headroomUrl:a})},we=async()=>{const e=L.trim()||"http://localhost:8787";j(e),await m({headroomUrl:e}),i()},i=s.useCallback(async()=>{T(e=>({...e,loading:!0}));try{const a=await(await fetch("/api/headroom/status",{headers:{"Cache-Control":"no-store"}})).json();if(T({...a,loading:!1}),!(a!=null&&a.installed)){h({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),x([]);return}try{const r=await fetch("/api/headroom/extras",{headers:{"Cache-Control":"no-store"}});if(!r.ok)throw new Error("extras status failed");const o=await r.json();h(g=>({...g,version:o.version??null,extras:o.extras||{code:!1,ml:!1},available:o.available||["code","ml"],loading:!1})),x([])}catch{h({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),x([])}}catch{T({installed:!1,running:!1,python:null,loading:!1}),h({version:null,extras:{code:!1,ml:!1},available:["code","ml"],loading:!1}),x([])}},[]),Ne=s.useCallback(async()=>{G(""),w(!0);try{const e=await fetch("/api/headroom/start",{method:"POST"}),a=await e.json().catch(()=>({}));if(!e.ok)throw new Error(a.error||"Failed to start proxy");await i()}catch(e){G(e.message)}finally{w(!1)}},[i]),Ce=s.useCallback(async()=>{w(!0);try{await fetch("/api/headroom/stop",{method:"POST"}),await i()}finally{w(!1)}},[i]),ke=e=>{x(a=>a.includes(e)?a.filter(r=>r!==e):[...a,e])},E=s.useCallback(()=>{Y(""),u.current&&clearInterval(u.current);const e=async()=>{try{const r=await(await fetch("/api/headroom/extras?log=1",{headers:{"Cache-Control":"no-store"}})).json().catch(()=>({}));typeof r.log=="string"&&Y(r.log)}catch{}};e(),u.current=setInterval(e,1500)},[]),f=s.useCallback(()=>{u.current&&(clearInterval(u.current),u.current=null)},[]);s.useEffect(()=>()=>f(),[f]);const B=s.useCallback(async()=>{if(c.length!==0){K(!0),p(""),E();try{const e=await fetch("/api/headroom/extras",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({extras:c})}),a=await e.json().catch(()=>({}));if(!e.ok)throw new Error(a.error||"Install failed");h(r=>({...r,version:a.version??r.version,extras:a.extras||r.extras})),x([])}catch(e){p(e.message)}finally{f(),K(!1)}}},[c,E,f]),re=s.useCallback(async e=>{z(e),p(""),E();try{const a=await fetch("/api/headroom/extras",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({extras:[e]})}),r=await a.json().catch(()=>({}));if(!a.ok)throw new Error(r.error||"Remove failed");h(o=>({...o,version:r.version??o.version,extras:r.extras||o.extras}))}catch(a){p(a.message)}finally{f(),z(null)}},[E,f]),Ee=s.useCallback(()=>{if(c.length!==0){if(c.includes("ml")){C({title:"Install [ml]",message:"[ml] downloads ~1 GB (torch + huggingface-hub). Continue?",confirmText:"Install",variant:"primary",onConfirm:B});return}B()}},[c,B]),Se=s.useCallback(e=>{C({title:`Remove [${e}]`,message:`Remove [${e}] and its packages?`,confirmText:"Remove",variant:"danger",onConfirm:()=>re(e)})},[re]),Le=s.useCallback(async(e,a)=>{if(p(""),e==="code"&&V(a),e==="ml"&&q(a),await m({[e==="code"?"headroomCodeAware":"headroomKompress"]:a}),!!l.running){X(!0);try{const o=await fetch("/api/headroom/restart",{method:"POST"}),g=await o.json().catch(()=>({}));if(!o.ok)throw new Error(g.error||"Restart failed");await i()}catch(o){p(o.message)}finally{X(!1)}}},[l.running,i]),Te=e=>{ee(e),m({ponytailEnabled:e})},Ae=e=>{ae(e),m({ponytailLevel:e})};s.useEffect(()=>{(async()=>{try{const a=await fetch("/api/settings");if(!a.ok)return;const r=await a.json();$(r.rtkEnabled!==!1),J(!!r.headroomEnabled),j(r.headroomUrl||"http://localhost:8787"),V(r.headroomCodeAware===!0),q(r.headroomKompress!==!1),Z(!!r.cavemanEnabled),U(r.cavemanLevel||"full"),ee(!!r.ponytailEnabled),ae(r.ponytailLevel||"full"),i()}catch{}})()},[i]);const d=!!l.running,ne=l.loading?"Checking…":d?"Running":l.localUrl!==!1&&!l.installed?"Not installed":l.localUrl!==!1?"Stopped":"External",oe=l.localUrl!==!1,Pe=!!l.canStart,He=oe&&!!l.managedPid;return t.jsxs("div",{className:"space-y-6 p-6",children:[t.jsxs(Be,{id:"rtk",children:[t.jsx("div",{className:"flex items-center justify-between mb-2",children:t.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-primary",children:"bolt"}),"Token Saver"]})}),t.jsxs("div",{className:"flex items-center justify-between pt-2 pb-4 border-b border-border gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"font-medium",children:["Compress tool output"," ",t.jsx("a",{href:"https://github.com/rtk-ai/rtk",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(RTK)"})]}),t.jsx("p",{className:"text-sm text-text-muted",children:"git/grep/ls/tree/logs → 60-90% fewer input tokens"})]}),t.jsx(y,{checked:M,onChange:()=>be(!M)})]}),t.jsxs("div",{className:"flex items-center justify-between py-4 gap-4 flex-wrap",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsxs("p",{className:"font-medium",children:["Compress context"," ",t.jsx("a",{href:"https://github.com/chopratejas/headroom",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Headroom)"})]}),t.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${d?"bg-success/15 text-success":"bg-warning/15 text-warning"}`,children:ne}),t.jsx("button",{type:"button",onClick:()=>A(!0),className:"text-xs text-primary underline hover:opacity-80",children:d?"Manage":"Setup"})]}),t.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Compress prompts via /v1/compress before routing to the model"})]}),t.jsx(y,{checked:D&&d,disabled:!d,onChange:()=>ve(!D)})]}),l.installed&&t.jsxs("div",{className:"mb-3 ml-1 pl-3 pb-4 border-l-2 border-border",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsxs("span",{className:"text-xs text-text-muted",children:["Compression extras",N.version?` · v${N.version}`:"",":"]}),N.available.map(e=>{const a=!!N.extras[e],r=c.includes(e),o=e==="code"?"tree-sitter AST compression for code responses":"Kompress-v2 HF model for prose/agentic traces (~+1GB)";if(a){const g=e==="code"?he:xe;return t.jsxs("div",{className:"flex items-center gap-1.5 text-xs px-2 py-1 rounded border border-success/40 bg-success/5 text-text",title:o,children:[t.jsx(y,{size:"sm",checked:g,disabled:Q,onChange:()=>Le(e,!g)}),t.jsxs("span",{className:"font-medium",children:["[",e,"]"]}),t.jsx("button",{type:"button",onClick:()=>Se(e),disabled:H===e,className:"ml-1 text-error underline hover:opacity-80 disabled:opacity-50",title:`Uninstall [${e}]`,children:H===e?"Uninstalling…":"Uninstall"})]},e)}return t.jsxs("label",{className:`flex items-center gap-1.5 text-xs px-2 py-1 rounded border cursor-pointer transition-colors ${r?"border-primary bg-primary/10 text-primary":"border-border text-text-muted hover:bg-surface-2"}`,title:o,children:[t.jsx("input",{type:"checkbox",className:"w-3 h-3",checked:r,onChange:()=>ke(e)}),t.jsxs("span",{className:"font-medium",children:["[",e,"]"]}),t.jsx("span",{className:"opacity-70",children:"not installed"})]},e)}),c.length>0&&t.jsx("button",{onClick:Ee,disabled:P,className:"text-xs px-2.5 py-1 rounded bg-primary text-white hover:opacity-90 disabled:opacity-50",children:P?"Installing…":`Install [proxy,${c.join(",")}]`})]}),W&&t.jsx("p",{className:"text-xs text-error mt-1",children:W}),Q&&t.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Restarting proxy…"}),(P||H)&&F&&t.jsx("pre",{className:"mt-2 max-h-32 overflow-auto rounded bg-surface-2 p-2 text-[10px] leading-tight text-text-muted whitespace-pre-wrap",children:F}),t.jsxs("p",{className:"text-xs text-text-muted mt-1",children:["Installing adds the package; use ",t.jsx("code",{children:"on"}),"/",t.jsx("code",{children:"off"})," ","to activate it (restarts the proxy). Default install is"," ",t.jsx("code",{children:"[proxy]"})," only (SmartCrusher for JSON). Adding"," ",t.jsx("code",{children:"[code]"})," enables AST compression (Python/JS/TS/Go/Rust/Java/C/C++/Perl). Adding ",t.jsx("code",{children:"[ml]"})," ","enables the Kompress-v2 HF model for prose/agentic traces but adds ~1 GB (torch + huggingface-hub)."]})]}),t.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-border gap-4 flex-wrap",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"font-medium",children:["Compress LLM output"," ",t.jsx("a",{href:"https://github.com/JuliusBrussee/caveman",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Caveman)"})]}),t.jsx("p",{className:"text-sm text-text-muted",children:"Terse-style system prompt → ~65% fewer output tokens (up to 87%)"})]}),t.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[R&&t.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:ge.map(e=>t.jsx("button",{onClick:()=>je(e.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${k===e.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:e.desc,children:e.label},e.id))}),t.jsx("p",{className:"text-xs text-primary",children:(le=S.find(e=>e.id===k))==null?void 0:le.desc})]}),t.jsx(y,{checked:R,onChange:()=>ye(!R)})]})]}),t.jsxs("div",{className:"flex items-center justify-between pt-4 mt-4 border-t border-border gap-4 flex-wrap",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("p",{className:"font-medium",children:["Lazy senior dev"," ",t.jsx("a",{href:"https://github.com/DietrichGebert/ponytail",target:"_blank",rel:"noreferrer",className:"text-xs font-normal text-primary underline hover:opacity-80",children:"(Ponytail)"})]}),t.jsx("p",{className:"text-sm text-text-muted",children:"Bias the model toward minimal code: YAGNI, reuse stdlib, deletion over addition"})]}),t.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[I&&t.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:de.map(e=>t.jsx("button",{onClick:()=>Ae(e.id),className:`px-3 py-1.5 rounded text-xs font-medium border transition-colors ${te===e.id?"bg-primary text-white border-primary":"bg-transparent border-border text-text-muted hover:bg-surface-2"}`,title:e.desc,children:e.label},e.id))}),t.jsx("p",{className:"text-xs text-primary",children:(ie=de.find(e=>e.id===te))==null?void 0:ie.desc})]}),t.jsx(y,{checked:I,onChange:()=>Te(!I)})]})]})]}),t.jsx(Ie,{isOpen:me,title:d?"Headroom":"Setup Headroom",onClose:()=>A(!1),children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{children:"Status"}),t.jsx("span",{className:d?"text-success":"text-warning",children:ne})]}),d&&t.jsx("a",{href:"/api/headroom/proxy/dashboard",target:"_blank",rel:"noreferrer",className:"w-full rounded border border-border px-4 py-2 text-center text-sm hover:bg-surface-2",children:"Open Headroom Dashboard"}),t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("p",{className:"text-sm font-medium",children:"Proxy URL"}),t.jsx(Me,{value:L,onChange:e=>j(e.target.value),onBlur:we,placeholder:"http://localhost:8787",className:"font-mono text-sm"}),t.jsx("p",{className:"text-xs text-text-muted",children:"Use a local proxy for Start/Stop, or an external Docker sidecar like http://headroom:8787."})]}),He?t.jsx(b,{onClick:Ce,variant:"ghost",fullWidth:!0,disabled:v,children:v?"Stopping…":"Stop Headroom"}):d?t.jsx("p",{className:"text-sm text-success",children:"Headroom proxy is reachable. You can enable the token saver."}):Pe?t.jsx(b,{onClick:Ne,fullWidth:!0,disabled:v,children:v?"Starting…":"Start Headroom"}):oe?l.python?t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsx("p",{className:"text-sm font-medium",children:"Install then click Start:"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("pre",{className:"flex-1 rounded bg-black/5 dark:bg-white/5 p-2 text-xs font-mono overflow-x-auto",children:'pip install "headroom-ai[proxy]"'}),t.jsx(b,{size:"sm",variant:"ghost",onClick:()=>fe('pip install "headroom-ai[proxy]"'),children:ue?"Copied":"Copy"})]})]}):t.jsx("p",{className:"text-sm text-warning",children:"Python ≥ 3.10 required for local managed mode. Install Python first, or use an external proxy URL."}):t.jsx("p",{className:"text-sm text-warning",children:"Start Headroom separately at the configured URL, then recheck."}),_&&t.jsx("p",{className:"text-sm text-warning",children:_}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(b,{onClick:()=>i(),variant:"ghost",fullWidth:!0,children:"Recheck"}),t.jsx(b,{onClick:()=>A(!1),fullWidth:!0,children:"Done"})]})]})}),t.jsx(Oe,{isOpen:!!n,onClose:()=>C(null),onConfirm:()=>{const e=n==null?void 0:n.onConfirm;C(null),e==null||e()},title:n==null?void 0:n.title,message:n==null?void 0:n.message,confirmText:n==null?void 0:n.confirmText,variant:n==null?void 0:n.variant})]})}export{Ke as default};
@@ -0,0 +1,7 @@
1
+ import{j as t,B as P}from"./index.AIBoioDI.js";import{b as r}from"./router.Cjj1--8t.js";import"./NoAuthProxyCard.CZTUlj4t.js";import"./zustand.akaTi5uX.js";function X(){const[C,k]=r.useState(!1),[w,y]=r.useState(!1),[M,n]=r.useState(""),[A,j]=r.useState(""),[N,g]=r.useState(0),[$,R]=r.useState(""),[B,E]=r.useState([]),[S,F]=r.useState(""),[T,W]=r.useState(""),[J,L]=r.useState(!1),U=r.useRef(null),s=r.useCallback((e,a="info")=>{E(u=>[...u.slice(-300),{msg:e,level:a,ts:new Date().toLocaleTimeString()}])},[]),q=r.useCallback(async()=>{y(!0),n(""),s("Memulai backup data (logical)...");try{const e=await fetch("/api/db");if(!e.ok)throw new Error(`HTTP ${e.status}`);const a=Number(e.headers.get("Content-Length"))||0,u=e.body.getReader(),o=new TextDecoder;let l=0,d="";for(;;){const{done:b,value:p}=await u.read();if(b)break;l+=p.length,a&&g(Math.min(99,Math.round(l/a*100))),d+=o.decode(p,{stream:!0})}const m=JSON.parse(d),x=new Blob([JSON.stringify(m,null,2)],{type:"application/json"}),h=URL.createObjectURL(x),f=document.createElement("a");f.href=h,f.download="fsrouter-backup.fud",f.click(),URL.revokeObjectURL(h),g(100),s("✓ Backup selesai: fsrouter-backup.fud","info")}catch(e){s("ERROR: "+e.message,"error"),n("Gagal backup: "+e.message)}finally{y(!1)}},[s]),I=r.useCallback(async()=>{y(!0),n(""),s("Memulai backup database mentah (.sqlite)...");try{const e=await fetch("/api/db/raw");if(!e.ok)throw new Error(`HTTP ${e.status}`);const a=Number(e.headers.get("Content-Length"))||0,u=e.body.getReader(),o=[];let l=0;for(;;){const{done:h,value:f}=await u.read();if(h)break;l+=f.length,a&&g(Math.min(99,Math.round(l/a*100))),o.push(f)}const d=new Blob(o,{type:"application/octet-stream"}),m=URL.createObjectURL(d),x=document.createElement("a");x.href=m,x.download=`fsrouter-db-raw-${Date.now()}.sqlite`,x.click(),URL.revokeObjectURL(m),g(100),s("✓ Backup mentah selesai","info")}catch(e){s("ERROR: "+e.message,"error"),n("Gagal backup mentah: "+e.message)}finally{y(!1)}},[s]),v=r.useCallback(async e=>{n(""),j(""),E([]),g(0),R("Memulai restore..."),k(!0);try{const a=await fetch("/api/db",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!a.ok||!a.body){const m=await a.json().catch(()=>({}));throw new Error(m.error||`HTTP ${a.status}`)}const u=a.body.getReader(),o=new TextDecoder;let l="",d=!1;for(;!d;){const{done:m,value:x}=await u.read();if(m)break;l+=o.decode(x,{stream:!0});const h=l.split(`
2
+
3
+ `);l=h.pop()||"";for(const f of h){const b=f.split(`
4
+ `);let p="message",c="";for(const O of b)O.startsWith("event:")?p=O.slice(6).trim():O.startsWith("data:")&&(c=O.slice(5).trim());if(!c)continue;let i;try{i=JSON.parse(c)}catch{continue}p==="progress"?(g(i.percent||0),R(i.label||""),s(`[${i.percent}%] ${i.label}`,"info")):p==="log"?s(i.message,i.level||"info"):p==="error"?(s(`ERROR: ${i.message}`,"error"),n(i.message)):p==="done"&&(s("✓ "+(i.message||"Selesai"),"info"),j("Restore berhasil! Server sedang merestart, harap tunggu beberapa saat..."),d=!0,setTimeout(()=>window.location.reload(),5e3))}}d||(j("Restore selesai. Server sedang merestart..."),setTimeout(()=>window.location.reload(),5e3))}catch(a){s("ERROR: "+(a.message||a),"error"),n(a.message||"File backup corrupt atau tidak valid."),k(!1)}},[s]),D=r.useCallback(async e=>{if(!e)return;if(!e.name.endsWith(".fud")&&!e.name.endsWith(".json")&&!e.name.endsWith(".sqlite")){n("Format tidak didukung (.fud / .json / .sqlite)");return}if(!window.confirm("PERINGATAN: Restore akan MENIMPA semua data saat ini! Lanjutkan?"))return;if(e.name.endsWith(".sqlite")){const u=await new Promise(o=>{const l=new FileReader;l.onload=()=>o(btoa(new Uint8Array(l.result).reduce((d,m)=>d+String.fromCharCode(m),""))),l.readAsArrayBuffer(e)});return v({signature:"FUDROUTER_BACKUP",version:1,files:{"db/data.sqlite":u}})}const a=new FileReader;a.onload=async u=>{try{const o=JSON.parse(u.target.result);await v(o)}catch{n("File backup corrupt atau tidak valid."),k(!1)}},a.readAsText(e)},[v]),_=e=>D(e.target.files[0]),G=r.useCallback(async()=>{if(!S.trim()){n("Textarea kosong.");return}if(window.confirm("PERINGATAN: Restore akan MENIMPA semua data saat ini! Lanjutkan?"))try{const e=JSON.parse(S);await v(e)}catch{n("JSON tidak valid."),k(!1)}},[S,v]),H=r.useCallback(async()=>{if(!T.trim()){n("Path kosong.");return}if(window.confirm("PERINGATAN: Restore akan MENIMPA semua data saat ini! Lanjutkan?"))try{const e=await fetch("/api/db/restore-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:T.trim()})});if(!e.ok||!e.body){const d=await e.json().catch(()=>({}));throw new Error(d.error||`HTTP ${e.status}`)}const a=e.body.getReader(),u=new TextDecoder;let o="",l=!1;for(n(""),j(""),E([]),g(0),R("Memulai restore dari path..."),k(!0);!l;){const{done:d,value:m}=await a.read();if(d)break;o+=u.decode(m,{stream:!0});const x=o.split(`
5
+
6
+ `);o=x.pop()||"";for(const h of x){const f=h.split(`
7
+ `);let b="message",p="";for(const i of f)i.startsWith("event:")?b=i.slice(6).trim():i.startsWith("data:")&&(p=i.slice(5).trim());if(!p)continue;let c;try{c=JSON.parse(p)}catch{continue}b==="progress"?(g(c.percent||0),R(c.label||""),s(`[${c.percent}%] ${c.label}`)):b==="log"?s(c.message,c.level||"info"):b==="error"?(s("ERROR: "+c.message,"error"),n(c.message)):b==="done"&&(s("✓ "+(c.message||"Selesai")),j("Restore berhasil! Server merestart..."),l=!0,setTimeout(()=>window.location.reload(),5e3))}}}catch(e){s("ERROR: "+(e.message||e),"error"),n(e.message||"Gagal restore dari path."),k(!1)}},[T,s]);return t.jsxs("div",{className:"max-w-4xl mx-auto p-4 space-y-6",children:[t.jsxs("div",{className:"flex flex-col gap-1",children:[t.jsxs("h1",{className:"text-2xl font-bold text-text-main flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"backup"}),"Backup & Restore"]}),t.jsx("p",{className:"text-xs text-text-muted",children:"Amankan seluruh data FSRouter (provider, connections, akun automation, proxy, api keys) ke satu file, atau pulihkan dari file/teks/path."})]}),M&&t.jsxs("div",{className:"p-4 bg-red-500/10 border border-red-500/20 text-red-500 text-sm rounded-lg flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-sm",children:"error"}),M]}),A&&t.jsxs("div",{className:"p-4 bg-green-500/10 border border-green-500/20 text-green-500 text-sm rounded-lg flex items-center gap-2",children:[t.jsx("span",{className:"material-symbols-outlined text-sm",children:"check_circle"}),A]}),t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[t.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3 text-text-main",children:[t.jsx("div",{className:"size-10 rounded-full bg-blue-500/10 text-blue-500 flex items-center justify-center",children:t.jsx("span",{className:"material-symbols-outlined text-xl",children:"cloud_download"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-semibold",children:"Buat Backup"}),t.jsx("p",{className:"text-[11px] text-text-muted",children:"Simpan data ke perangkat"})]})]}),t.jsx("div",{className:"text-xs text-text-muted leading-relaxed flex-1",children:t.jsxs("ul",{className:"list-disc list-inside space-y-1 ml-1",children:[t.jsxs("li",{children:[t.jsx("b",{children:"Portabel (.fud)"}),": semua data sebagai JSON — bisa dipulihkan di OS berbeda."]}),t.jsxs("li",{children:[t.jsx("b",{children:"Mentah (.sqlite)"}),": copy langsung file database — paling akurat, sama OS."]})]})}),t.jsx(P,{variant:"primary",fullWidth:!0,onClick:q,disabled:w,icon:"download",children:w?`Membackup... ${N}%`:"Download Backup (.fud)"}),t.jsx(P,{variant:"secondary",fullWidth:!0,onClick:I,disabled:w,icon:"storage",children:"Download Database Mentah (.sqlite)"}),w&&t.jsx("div",{className:"w-full h-2.5 rounded-full bg-sidebar overflow-hidden",children:t.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-emerald-400 transition-all",style:{width:`${N}%`}})})]}),t.jsxs("div",{className:"p-6 rounded-[14px] border border-border-subtle bg-surface flex flex-col gap-4",children:[t.jsxs("div",{className:"flex items-center gap-3 text-text-main",children:[t.jsx("div",{className:"size-10 rounded-full bg-amber-500/10 text-amber-500 flex items-center justify-center",children:t.jsx("span",{className:"material-symbols-outlined text-xl",children:"restore"})}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-sm font-semibold",children:"Pulihkan Backup"}),t.jsx("p",{className:"text-[11px] text-text-muted",children:"Timpa data dari file/teks/path"})]})]}),t.jsxs("div",{onDragOver:e=>{e.preventDefault(),L(!0)},onDragLeave:()=>L(!1),onDrop:e=>{e.preventDefault(),L(!1),D(e.dataTransfer.files[0])},onClick:()=>{var e;return(e=U.current)==null?void 0:e.click()},className:`border-2 border-dashed rounded-lg p-5 text-center cursor-pointer transition-colors ${J?"border-primary bg-primary/5":"border-border-subtle hover:border-primary/50"}`,children:[t.jsx("span",{className:"material-symbols-outlined text-3xl text-text-muted",children:"upload_file"}),t.jsx("p",{className:"text-xs text-text-muted mt-1",children:"Klik atau seret file .fud / .json / .sqlite ke sini"})]}),t.jsx("input",{type:"file",accept:".fud,.json,.sqlite",ref:U,onChange:_,className:"hidden"}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-[11px] text-text-muted",children:"Atau tempel (paste) isi file backup JSON:"}),t.jsx("textarea",{value:S,onChange:e=>F(e.target.value),placeholder:'{ "signature": "FUDROUTER_BACKUP", ... }',className:"w-full h-20 text-[11px] font-mono bg-black/40 border border-border-subtle rounded p-2 text-text-main resize-none"}),t.jsx(P,{variant:"secondary",fullWidth:!0,onClick:G,disabled:C,icon:"content_paste",children:"Restore dari Teks"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("label",{className:"text-[11px] text-text-muted",children:"Atau path file di server (ganti file manual):"}),t.jsx("input",{value:T,onChange:e=>W(e.target.value),placeholder:"C:\\\\Users\\\\fud\\\\backups\\\\fsrouter-backup.fud",className:"w-full text-[11px] bg-black/40 border border-border-subtle rounded p-2 text-text-main"}),t.jsx(P,{variant:"secondary",fullWidth:!0,onClick:H,disabled:C,icon:"folder_open",children:"Restore dari Path"})]}),C&&t.jsxs("div",{className:"mt-2 space-y-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex justify-between text-[11px] text-text-muted mb-1",children:[t.jsx("span",{children:$||"Memproses..."}),t.jsxs("span",{children:[N,"%"]})]}),t.jsx("div",{className:"w-full h-2.5 rounded-full bg-sidebar overflow-hidden",children:t.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-emerald-400 transition-all duration-300",style:{width:`${N}%`}})})]}),t.jsx("div",{className:"bg-black/80 rounded-lg p-3 h-48 overflow-y-auto font-mono text-[10px] leading-relaxed",children:B.length===0?t.jsx("div",{className:"text-text-muted",children:"Menunggu output restore..."}):B.map((e,a)=>t.jsxs("div",{className:e.level==="error"?"text-red-400":e.level==="warn"?"text-amber-400":"text-green-300",children:[t.jsxs("span",{className:"text-text-muted",children:["[",e.ts,"]"]})," ",e.msg]},a))})]})]})]})]})}export{X as default};
@@ -0,0 +1 @@
1
+ import{N as B,K as I,j as e,B as E,g as A,P as z}from"./index.AIBoioDI.js";import{h as _,d as M,b,L as T}from"./router.Cjj1--8t.js";import{A as R,C as D,B as j,T as K}from"./NoAuthProxyCard.CZTUlj4t.js";import"./zustand.akaTi5uX.js";const F=new Set([]),L={image:"image-combo",tts:"tts-combo"};function P(s){const o=Object.entries(s).some(([i,d])=>i.startsWith("modelLock_")&&d&&new Date(d).getTime()>Date.now());return s.testStatus==="unavailable"&&!o?"active":s.testStatus}function $({provider:s,kind:o,connections:i,isCustom:d,onToggle:l}){var C;const n=A[s.id],y=!!(n!=null&&n.noAuth),p=i.filter(a=>a.provider===s.id),v=p.filter(a=>{const x=P(a);return x==="active"||x==="success"}).length,h=p.filter(a=>{const x=P(a);return x==="error"||x==="expired"||x==="unavailable"}).length,m=p.length,r=m>0&&p.every(a=>a.isActive===!1),u=a=>{a.preventDefault(),a.stopPropagation(),l&&l(s.id,r)},k=()=>y?e.jsx(j,{variant:"success",size:"sm",children:"Ready"}):r?e.jsx(j,{variant:"default",size:"sm",children:"Disabled"}):m===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No connections"}):e.jsxs(e.Fragment,{children:[v>0&&e.jsxs(j,{variant:"success",size:"sm",dot:!0,children:[v," Connected"]}),h>0&&e.jsxs(j,{variant:"error",size:"sm",dot:!0,children:[h," Error"]}),v===0&&h===0&&e.jsxs(j,{variant:"default",size:"sm",children:[m," Added"]})]});return e.jsx(T,{to:`/dashboard/media-providers/${o}/${s.id}`,className:"group",children:e.jsx(D,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${r?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${((C=s.color)==null?void 0:C.length)>7?s.color:(s.color??"#888")+"15"}`},children:e.jsx(z,{src:`/providers/${s.id}.png`,alt:s.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:s.textIcon||s.id.slice(0,2).toUpperCase(),fallbackColor:s.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-sm",children:s.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[d&&e.jsx(j,{variant:"default",size:"sm",children:"Custom"}),k()]})]})]}),m>0&&e.jsx("div",{className:"shrink-0 opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:u,children:e.jsx(K,{size:"sm",checked:!r,onChange:()=>{},title:r?"Enable provider":"Disable provider"})})]})})})}function U({combos:s}){return s.length===0?null:e.jsx("div",{className:"flex flex-col gap-2",children:s.map(o=>e.jsx(T,{to:`/dashboard/media-providers/combo/${o.id}`,children:e.jsx(D,{padding:"xs",className:"hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors cursor-pointer",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"}),e.jsx("code",{className:"text-sm font-mono font-medium flex-1 truncate",children:o.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:shrink-0",children:[o.models.slice(0,6).map((i,d)=>{const l=typeof i=="string"?i.split("/")[0]:"",n=A[l];return e.jsx("div",{title:(n==null?void 0:n.name)||i,className:"size-5 rounded flex items-center justify-center",style:{backgroundColor:`${(n==null?void 0:n.color)??"#888"}15`},children:e.jsx(z,{src:`/providers/${l}.png`,alt:(n==null?void 0:n.name)||l,size:18,className:"object-contain rounded max-w-[18px] max-h-[18px]",fallbackText:(n==null?void 0:n.textIcon)||l.slice(0,2).toUpperCase(),fallbackColor:n==null?void 0:n.color})},`${i}-${d}`)}),o.models.length>6&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1",children:["+",o.models.length-6]})]}),e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:o.models.length}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[16px]",children:"chevron_right"})]})})},o.id))})}function G(){const{kind:s}=_(),o=M(),[i,d]=b.useState([]),[l,n]=b.useState([]),[y,p]=b.useState([]),[v,h]=b.useState(!1);b.useEffect(()=>{(s==="webSearch"||s==="webFetch")&&o("/dashboard/media-providers/web")},[s,o]);const m=B.find(t=>t.id===s),r=s==="embedding",u=F.has(s);if(b.useEffect(()=>{m&&(fetch("/api/providers",{cache:"no-store"}).then(t=>t.json()).then(t=>d(t.connections||[])).catch(()=>{}),r&&fetch("/api/provider-nodes",{cache:"no-store"}).then(t=>t.json()).then(t=>n((t.nodes||[]).filter(c=>c.type==="custom-embedding"))).catch(()=>{}),u&&fetch("/api/combos",{cache:"no-store"}).then(t=>t.json()).then(t=>p(t.combos||[])).catch(()=>{}))},[r,u,m]),!m)return null;const k=I(s),C=y.filter(t=>t.kind===s),a=l.map(t=>({id:t.id,name:t.name||"Custom Embedding",color:"#6366F1",textIcon:"CE"})),x=[...k,...a],S=async(t,c)=>{const w=i.filter(f=>f.provider===t);d(f=>f.map(g=>g.provider===t?{...g,isActive:c}:g)),await Promise.allSettled(w.map(f=>fetch(`/api/providers/${f.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:c})})))},O=async()=>{const t=L[s]||`${s}-combo`;let c=t,w=1;const f=new Set(y.map(N=>N.name));for(;f.has(c);)c=`${t}-${w++}`;const g=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:c,models:[],kind:s})});if(g.ok){const N=await g.json();o(`/dashboard/media-providers/combo/${N.id}`)}else{const N=await g.json();alert(N.error||"Failed to create combo")}};return e.jsxs("div",{className:"flex flex-col gap-6",children:[(r||u)&&e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[u&&e.jsx(E,{size:"sm",icon:"add",onClick:O,children:"Create Combo"}),r&&e.jsx(E,{size:"sm",icon:"add",onClick:()=>h(!0),children:"Add Custom Embedding"})]}),u&&C.length>0&&e.jsx(U,{combos:C}),x.length===0?e.jsxs("div",{className:"text-center py-12 border border-dashed border-border rounded-xl text-text-muted text-sm",children:["No providers support ",e.jsx("strong",{children:m.label})," yet."]}):e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[k.map(t=>e.jsx($,{provider:t,kind:s,connections:i,onToggle:S},t.id)),a.map(t=>e.jsx($,{provider:t,kind:s,connections:i,isCustom:!0,onToggle:S},t.id))]}),r&&e.jsx(R,{isOpen:v,onClose:()=>h(!1),onCreated:t=>{n(c=>[...c,t]),h(!1)}})]})}export{G as default};
@@ -0,0 +1 @@
1
+ import{a as ae,j as e,B as _,b as Y,O as ve,F as ye,c as je,A as Ne,W as Ce,d as we,e as Te,P as re,M as ie,f as i}from"./index.AIBoioDI.js";import{b as c,L as le}from"./router.Cjj1--8t.js";import{C as ne,B as P,T as oe,I as O,S as ke}from"./NoAuthProxyCard.CZTUlj4t.js";import{C as ee}from"./Loading.DFQ28pFE.js";import"./zustand.akaTi5uX.js";function Ae(r){if(!r)return null;const a=r.match(/\b([45]\d{2})\b/);return a?a[1]:"ERR"}function Ie(r){if(!r)return"";const a=Date.now()-new Date(r).getTime(),m=Math.floor(a/6e4);if(m<1)return"just now";if(m<60)return`${m}m ago`;const s=Math.floor(m/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}const te={available:{icon:"check_circle",color:"#22c55e",label:"Available"},cooldown:{icon:"schedule",color:"#f59e0b",label:"Cooldown"},unavailable:{icon:"error",color:"#ef4444",label:"Unavailable"},unknown:{icon:"help",color:"#6b7280",label:"Unknown"}};function Se(){const[r,a]=c.useState(null),[m,s]=c.useState(!0),[l,h]=c.useState(!1),[w,v]=c.useState(null),y=c.useRef(null),u=ae(),N=c.useCallback(async()=>{try{const x=await fetch("/api/models/availability");if(x.ok){const g=await x.json();a(g)}}catch{}finally{s(!1)}},[]);c.useEffect(()=>{N();const x=setInterval(N,3e4);return()=>clearInterval(x)},[N]),c.useEffect(()=>{const x=g=>{y.current&&!y.current.contains(g.target)&&h(!1)};return l&&document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[l]);const C=async(x,g)=>{v(`${x}:${g}`);try{(await fetch("/api/models/availability",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"clearCooldown",provider:x,model:g})})).ok?(u.success(`Cooldown cleared for ${g}`),await N()):u.error("Failed to clear cooldown")}catch{u.error("Failed to clear cooldown")}finally{v(null)}};if(m)return null;const p=(r==null?void 0:r.models)||[],j=((r==null?void 0:r.unavailableCount)||p.filter(x=>x.status!=="available").length)===0,k={};return p.forEach(x=>{if(x.status==="available")return;const g=x.provider||"unknown";k[g]||(k[g]=[]),k[g].push(x)}),e.jsx("div",{className:"relative",ref:y,children:l&&e.jsxs("div",{className:"absolute top-full right-0 mt-2 w-80 bg-surface border border-border rounded-xl shadow-2xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",style:{color:j?"#22c55e":"#f59e0b"},children:j?"verified":"warning"}),e.jsx("span",{className:"text-sm font-semibold text-text-main",children:"Model Status"})]}),e.jsx("button",{onClick:N,className:"p-1 rounded-lg hover:bg-surface text-text-muted hover:text-text-main transition-colors",title:"Refresh",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"refresh"})})]}),e.jsx("div",{className:"px-4 py-3 max-h-60 overflow-y-auto",children:j?e.jsx("p",{className:"text-sm text-text-muted text-center py-2",children:"All models are responding normally."}):e.jsx("div",{className:"flex flex-col gap-2.5",children:Object.entries(k).map(([x,g])=>e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-text-main mb-1.5 capitalize",children:x}),e.jsx("div",{className:"flex flex-col gap-1",children:g.map(o=>{const n=te[o.status]||te.unknown,b=w===`${o.provider}:${o.model}`;return e.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5 rounded-lg bg-surface/30",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] shrink-0",style:{color:n.color},children:n.icon}),e.jsx("span",{className:"font-mono text-xs text-text-main truncate",children:o.model})]}),o.status==="cooldown"&&e.jsx(_,{size:"sm",variant:"ghost",onClick:()=>C(o.provider,o.model),disabled:b,className:"text-[10px] px-1.5! py-0.5! ml-2",children:b?"...":"Clear"})]},`${o.provider}-${o.model}`)})})]},x))})})]})})}function ce(r,a,m){const s=[];if(r>0&&s.push(e.jsxs(P,{variant:"success",size:"sm",dot:!0,children:[r," Connected"]},"connected")),a>0){const l=m?`${a} Error (${m})`:`${a} Error`;s.push(e.jsx(P,{variant:"error",size:"sm",dot:!0,children:l},"error"))}return s.length===0?e.jsx("span",{className:"text-text-muted",children:"No connections"}):s}function Re(r){if(!r)return null;const a=r.lastErrorType;if(a==="runtime_error")return"RUNTIME";if(a==="upstream_auth_error"||a==="auth_missing"||a==="token_refresh_failed"||a==="token_expired")return"AUTH";if(a==="upstream_rate_limited")return"429";if(a==="upstream_unavailable")return"5XX";if(a==="network_error")return"NET";const m=Number(r.errorCode);if(Number.isFinite(m)&&m>=400)return String(m);const s=Ae(r.lastError);if(s==="401"||s==="403")return"AUTH";if(s&&s!=="ERR")return s;const l=(r.lastError||"").toLowerCase();return l.includes("runtime")||l.includes("not runnable")||l.includes("not installed")?"RUNTIME":l.includes("invalid api key")||l.includes("token invalid")||l.includes("revoked")||l.includes("unauthorized")?"AUTH":"ERR"}const se=20;function De(){const[r,a]=c.useState([]),[m,s]=c.useState([]),[l,h]=c.useState(!0),[w,v]=c.useState(!1),[y,u]=c.useState(!1),[N,C]=c.useState(!1),[p,I]=c.useState(null),[j,k]=c.useState(null),x=ae(),g=Y(t=>t.query),o=Y(t=>t.register),n=Y(t=>t.unregister);c.useEffect(()=>(o("Search providers..."),()=>n()),[o,n]);const b=t=>!g.trim()||t.toLowerCase().includes(g.trim().toLowerCase()),K=(t,d)=>[...t].sort(([f,S],[A,R])=>{const q=D(f,d),F=D(A,d),L=q.connected>0?1:0,U=F.connected>0?1:0;return L!==U?U-L:(S.name||"").localeCompare(R.name||"")});c.useEffect(()=>{(async()=>{try{const[d,f]=await Promise.all([fetch("/api/providers"),fetch("/api/provider-nodes")]),S=await d.json(),A=await f.json();d.ok&&a(S.connections||[]),f.ok&&s(A.nodes||[])}catch(d){console.log("Error fetching data:",d)}finally{h(!1)}})()},[]);const D=(t,d)=>{const f=r.filter(T=>T.provider===t&&(T.authType===d||(t==="codebuddy"||t==="kimchi")&&T.authType==="apikey")),S=T=>{const E=Object.entries(T).some(([be,Z])=>be.startsWith("modelLock_")&&Z&&new Date(Z).getTime()>Date.now());return T.testStatus==="unavailable"&&!E?"active":T.testStatus},A=f.filter(T=>{const E=S(T);return E==="active"||E==="success"}).length,R=f.filter(T=>{const E=S(T);return E==="error"||E==="expired"||E==="unavailable"}),q=R.length,F=f.length,L=F>0&&f.every(T=>T.isActive===!1),U=R.sort((T,E)=>new Date(E.lastErrorAt||0)-new Date(T.lastErrorAt||0))[0],fe=U?Re(U):null,ge=U!=null&&U.lastErrorAt?Ie(U.lastErrorAt):null;return{connected:A,error:q,total:F,errorCode:fe,errorTime:ge,allDisabled:L}},$=async(t,d,f)=>{const S=r.filter(A=>A.provider===t&&A.authType===d);a(A=>A.map(R=>R.provider===t&&R.authType===d?{...R,isActive:f}:R)),await Promise.allSettled(S.map(A=>fetch(`/api/providers/${A.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:f})})))},V=async(t,d=null)=>{if(!p){I(t==="provider"?d:t),k(null);try{const S=await(await fetch("/api/providers/test-batch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:t,providerId:d})})).json();if(k(S),S.summary){const{passed:A,failed:R,total:q}=S.summary;R===0?x.success(`All ${q} tests passed`):x.warning(`${A}/${q} passed, ${R} failed`)}}catch{k({error:"Test request failed"}),x.error("Provider test failed")}finally{I(null)}}},B=m.filter(t=>t.type==="openai-compatible").map(t=>({id:t.id,name:t.name||"OpenAI Compatible",color:"#10A37F",textIcon:"OC",apiType:t.apiType})).filter(t=>b(t.name)),W=m.filter(t=>t.type==="anthropic-compatible").map(t=>({id:t.id,name:t.name||"Anthropic Compatible",color:"#D97757",textIcon:"AC"})).filter(t=>b(t.name)),H=Object.entries(ve).filter(([,t])=>!t.hidden&&b(t.name)),J=Object.entries(ye).filter(([,t])=>!t.hidden&&b(t.name)),X=Object.entries(je).filter(([,t])=>!t.hidden&&b(t.name)),M=K(Object.entries(Ne).filter(([,t])=>!t.hidden&&(t.serviceKinds??["llm"]).includes("llm")&&b(t.name)),"apikey"),Q=!!g.trim(),xe=Q||w?M:M.slice(0,se),ue=M.length-se;if(l)return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ee,{}),e.jsx(ee,{})]});const he=H.length>0||J.length>0||X.length>0||M.length>0||B.length>0||W.length>0;return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[!he&&e.jsxs("div",{className:"text-center py-8 border border-dashed border-border rounded-xl",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-text-muted mb-2",children:"search_off"}),e.jsx("p",{className:"text-text-muted text-sm",children:"No providers match your search"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:["Custom Providers (OpenAI/Anthropic Compatible)"," "]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:w-auto",children:[e.jsx(_,{size:"sm",icon:"add",onClick:()=>C(!0),className:"w-full sm:w-auto",children:"Add Anthropic Compatible"}),e.jsx(_,{size:"sm",variant:"secondary",icon:"add",onClick:()=>u(!0),className:"w-full !bg-white !text-black hover:!bg-gray-100 sm:w-auto",children:"Add OpenAI Compatible"})]})]}),B.length===0&&W.length===0?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-2 border border-dashed border-border rounded-xl text-text-muted text-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"extension"}),e.jsx("span",{children:"No custom providers — use buttons above to add OpenAI/Anthropic compatible endpoints"})]}):e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:[...B,...W].map(t=>e.jsx(z,{providerId:t.id,provider:t,stats:D(t.id,"apikey"),authType:"compatible",onToggle:d=>$(t.id,"apikey",d)},t.id))})]}),H.length>0&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:"OAuth Providers"}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center",children:[e.jsx(Se,{}),e.jsxs("button",{onClick:()=>V("oauth"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="oauth"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all OAuth connections","aria-label":"Test all OAuth connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="oauth"?" animate-spin":""}`,children:"play_arrow"}),p==="oauth"?"Testing...":"Test All"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:H.map(([t,d])=>e.jsx(G,{providerId:t,provider:d,stats:D(t,"oauth"),authType:"oauth",onToggle:f=>$(t,"oauth",f)},t))})]}),(J.length>0||X.length>0)&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:"Free Tier Providers"}),e.jsxs("button",{onClick:()=>V("free"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="free"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all Free connections","aria-label":"Test all Free provider connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="free"?" animate-spin":""}`,children:"play_arrow"}),p==="free"?"Testing...":"Test All"]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:[J.map(([t,d])=>e.jsx(G,{providerId:t,provider:d,stats:D(t,"oauth"),authType:"free",onToggle:f=>$(t,"oauth",f)},t)),X.map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))]})]}),M.length>0&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h2",{className:"text-lg sm:text-xl font-semibold flex items-center gap-2 leading-tight",children:["API Key Providers"," "]}),e.jsxs("button",{onClick:()=>V("apikey"),disabled:!!p,className:`flex w-full items-center justify-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors sm:w-auto sm:py-1.5 ${p==="apikey"?"bg-primary/20 border-primary/40 text-primary animate-pulse":"bg-bg border-border text-text-muted hover:text-text-main hover:border-primary/40"}`,title:"Test all API Key connections","aria-label":"Test all API Key connections",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px]${p==="apikey"?" animate-spin":""}`,children:"play_arrow"}),p==="apikey"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 sm:gap-4 lg:grid-cols-3 xl:grid-cols-4",children:xe.map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))}),!Q&&!w&&ue>0&&e.jsxs("button",{onClick:()=>v(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-primary/40 px-3 py-2.5 text-sm font-medium text-primary transition-colors hover:border-primary hover:bg-primary/5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"expand_more"}),"Show all ",M.length," providers"]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h2",{className:"text-xl font-semibold flex items-center gap-2",children:["Web Cookie Providers"," "]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:Object.entries(Ce).map(([t,d])=>e.jsx(z,{providerId:t,provider:d,stats:D(t,"apikey"),authType:"apikey",onToggle:f=>$(t,"apikey",f)},t))})]}),e.jsx(de,{isOpen:y,onClose:()=>u(!1),onCreated:t=>{s(d=>[...d,t]),u(!1)}}),e.jsx(me,{isOpen:N,onClose:()=>C(!1),onCreated:t=>{s(d=>[...d,t]),C(!1)}}),j&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-start justify-center px-3 pt-[6vh] sm:pt-[10vh]",onClick:()=>k(null),children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"relative bg-surface border border-border rounded-xl w-full max-w-[600px] max-h-[86vh] sm:max-h-[80vh] overflow-y-auto shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-5 py-3 border-b border-border bg-surface/95 backdrop-blur-sm rounded-t-xl",children:[e.jsx("h3",{className:"font-semibold",children:"Test Results"}),e.jsx("button",{onClick:()=>k(null),className:"p-1 rounded-lg hover:bg-bg text-text-muted hover:text-text-main transition-colors","aria-label":"Close test results",children:e.jsx("span",{className:"material-symbols-outlined text-lg",children:"close"})})]}),e.jsx("div",{className:"p-5",children:e.jsx(pe,{results:j})})]})]})]})}function G({providerId:r,provider:a,stats:m,authType:s,onToggle:l}){var C;const{connected:h,error:w,errorCode:v,errorTime:y,allDisabled:u}=m,N=!!a.noAuth;return e.jsx(le,{to:`/dashboard/providers/${r}`,className:"group min-w-0",children:e.jsx(ne,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${u?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${((C=a.color)==null?void 0:C.length)>7?a.color:a.color+"15"}`},children:e.jsx(re,{src:a.id==="codebuddy"||a.id==="cb"?"/providers/codebuddy.svg":`/providers/${a.id}.png`,alt:a.name,size:30,className:"object-contain rounded-lg max-w-[32px] max-h-[32px]",fallbackText:a.textIcon||a.id.slice(0,2).toUpperCase(),fallbackColor:a.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-semibold",children:a.name}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-xs flex-wrap",children:u?e.jsx(P,{variant:"default",size:"sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"pause_circle"}),"Disabled"]})}):N?e.jsx(P,{variant:"success",size:"sm",dot:!0,children:"Ready"}):e.jsxs(e.Fragment,{children:[ce(h,w,v),y&&e.jsx("span",{className:"text-text-muted",children:y})]})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:m.total>0&&e.jsx("div",{className:"opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:p=>{p.preventDefault(),p.stopPropagation(),l(!!u)},children:e.jsx(oe,{size:"sm",checked:!u,onChange:()=>{},title:u?"Enable provider":"Disable provider"})})})]})})})}G.propTypes={providerId:i.string.isRequired,provider:i.shape({id:i.string.isRequired,name:i.string.isRequired,color:i.string,textIcon:i.string}).isRequired,stats:i.shape({connected:i.number,error:i.number,errorCode:i.string,errorTime:i.string}).isRequired,authType:i.string,onToggle:i.func};function z({providerId:r,provider:a,stats:m,authType:s,onToggle:l}){var I;const{connected:h,error:w,errorCode:v,errorTime:y,allDisabled:u}=m,N=r.startsWith(we),C=r.startsWith(Te),p=()=>a.id==="codebuddy"||a.id==="cb"?"/providers/codebuddy.svg":N?a.apiType==="responses"?"/providers/oai-r.png":"/providers/oai-cc.png":C?"/providers/anthropic-m.png":`/providers/${a.id}.png`;return e.jsx(le,{to:`/dashboard/providers/${r}`,className:"group min-w-0",children:e.jsx(ne,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${u?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 shrink-0 rounded-lg flex items-center justify-center",style:{backgroundColor:`${((I=a.color)==null?void 0:I.length)>7?a.color:a.color+"15"}`},children:e.jsx(re,{src:p(),alt:a.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:a.textIcon||a.id.slice(0,2).toUpperCase(),fallbackColor:a.color})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-semibold",children:a.name}),e.jsx("div",{className:"flex min-w-0 items-center gap-1.5 text-xs flex-wrap",children:u?e.jsx(P,{variant:"default",size:"sm",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"pause_circle"}),"Disabled"]})}):e.jsxs(e.Fragment,{children:[ce(h,w,v),N&&e.jsx(P,{variant:"default",size:"sm",children:a.apiType==="responses"?"Responses":"Chat"}),C&&e.jsx(P,{variant:"default",size:"sm",children:"Messages"}),y&&e.jsx("span",{className:"text-text-muted",children:y})]})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:m.total>0&&e.jsx("div",{className:"opacity-100 transition-opacity sm:opacity-0 sm:group-hover:opacity-100",onClick:j=>{j.preventDefault(),j.stopPropagation(),l(!!u)},children:e.jsx(oe,{size:"sm",checked:!u,onChange:()=>{},title:u?"Enable provider":"Disable provider"})})})]})})})}z.propTypes={providerId:i.string.isRequired,provider:i.shape({id:i.string.isRequired,name:i.string.isRequired,color:i.string,textIcon:i.string,apiType:i.string}).isRequired,stats:i.shape({connected:i.number,error:i.number,errorCode:i.string,errorTime:i.string}).isRequired,authType:i.string,onToggle:i.func};function de({isOpen:r,onClose:a,onCreated:m}){const[s,l]=c.useState({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),[h,w]=c.useState(!1),[v,y]=c.useState(""),[u,N]=c.useState(""),[C,p]=c.useState(!1),[I,j]=c.useState(null),k=[{value:"chat",label:"Chat Completions"},{value:"responses",label:"Responses API"}];c.useEffect(()=>{const n="https://api.openai.com/v1";l(b=>({...b,baseUrl:n}))},[s.apiType]);const x=async()=>{if(!(!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim())){w(!0);try{const n=await fetch("/api/provider-nodes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,prefix:s.prefix,apiType:s.apiType,baseUrl:s.baseUrl,type:"openai-compatible"})}),b=await n.json();n.ok&&(m(b.node),l({name:"",prefix:"",apiType:"chat",baseUrl:"https://api.openai.com/v1"}),y(""),j(null))}catch(n){console.log("Error creating OpenAI Compatible node:",n)}finally{w(!1)}}},g=async()=>{p(!0);try{const b=await(await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:s.baseUrl,apiKey:v,type:"openai-compatible",modelId:u.trim()||void 0})})).json();j(b)}catch{j({valid:!1,error:"Network error"})}finally{p(!1)}},o=()=>{if(!I)return null;const{valid:n,error:b,method:K}=I;return n?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"success",children:"Valid"}),K==="chat"&&e.jsx("span",{className:"text-sm text-text-muted",children:"(via inference test)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(P,{variant:"error",children:"Invalid"}),b&&e.jsx("span",{className:"text-sm text-red-500",children:b})]})};return e.jsx(ie,{isOpen:r,title:"Add OpenAI Compatible",onClose:a,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(O,{label:"Name",value:s.name,onChange:n=>l({...s,name:n.target.value}),placeholder:"OpenAI Compatible (Prod)",hint:"Required. A friendly label for this node."}),e.jsx(O,{label:"Prefix",value:s.prefix,onChange:n=>l({...s,prefix:n.target.value}),placeholder:"oc-prod",hint:"Required. Used as the provider prefix for model IDs."}),e.jsx(ke,{label:"API Type",options:k,value:s.apiType,onChange:n=>l({...s,apiType:n.target.value})}),e.jsx(O,{label:"Base URL",value:s.baseUrl,onChange:n=>l({...s,baseUrl:n.target.value}),placeholder:"https://api.openai.com/v1",hint:"Use the base URL (ending in /v1) for your OpenAI-compatible API."}),e.jsx(O,{label:"API Key (for Check)",type:"password",value:v,onChange:n=>y(n.target.value)}),e.jsx(O,{label:"Model ID (optional)",value:u,onChange:n=>N(n.target.value),placeholder:"e.g. gpt-4, claude-3-opus",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsx(_,{onClick:g,disabled:!v||C||!s.baseUrl.trim(),variant:"secondary",className:"w-full sm:w-auto",children:C?"Checking...":"Check"}),o()]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(_,{onClick:x,fullWidth:!0,disabled:!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim()||h,children:h?"Creating...":"Create"}),e.jsx(_,{onClick:a,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}de.propTypes={isOpen:i.bool.isRequired,onClose:i.func.isRequired,onCreated:i.func.isRequired};function me({isOpen:r,onClose:a,onCreated:m}){const[s,l]=c.useState({name:"",prefix:"",baseUrl:"https://api.anthropic.com/v1"}),[h,w]=c.useState(!1),[v,y]=c.useState(""),[u,N]=c.useState(""),[C,p]=c.useState(!1),[I,j]=c.useState(null);c.useEffect(()=>{r&&(j(null),y(""),N(""))},[r]);const k=async()=>{if(!(!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim())){w(!0);try{const o=await fetch("/api/provider-nodes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,prefix:s.prefix,baseUrl:s.baseUrl,type:"anthropic-compatible"})}),n=await o.json();o.ok&&(m(n.node),l({name:"",prefix:"",baseUrl:"https://api.anthropic.com/v1"}),y(""),j(null))}catch(o){console.log("Error creating Anthropic Compatible node:",o)}finally{w(!1)}}},x=async()=>{p(!0);try{const n=await(await fetch("/api/provider-nodes/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:s.baseUrl,apiKey:v,type:"anthropic-compatible",modelId:u.trim()||void 0})})).json();j(n)}catch{j({valid:!1,error:"Network error"})}finally{p(!1)}},g=()=>{if(!I)return null;const{valid:o,error:n,method:b}=I;return o?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"success",children:"Valid"}),b==="chat"&&e.jsx("span",{className:"text-sm text-text-muted",children:"(via inference test)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(P,{variant:"error",children:"Invalid"}),n&&e.jsx("span",{className:"text-sm text-red-500",children:n})]})};return e.jsx(ie,{isOpen:r,title:"Add Anthropic Compatible",onClose:a,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(O,{label:"Name",value:s.name,onChange:o=>l({...s,name:o.target.value}),placeholder:"Anthropic Compatible (Prod)",hint:"Required. A friendly label for this node."}),e.jsx(O,{label:"Prefix",value:s.prefix,onChange:o=>l({...s,prefix:o.target.value}),placeholder:"ac-prod",hint:"Required. Used as the provider prefix for model IDs."}),e.jsx(O,{label:"Base URL",value:s.baseUrl,onChange:o=>l({...s,baseUrl:o.target.value}),placeholder:"https://api.anthropic.com/v1",hint:"Use the base URL (ending in /v1) for your Anthropic-compatible API. The system will append /messages."}),e.jsx(O,{label:"API Key (for Check)",type:"password",value:v,onChange:o=>y(o.target.value)}),e.jsx(O,{label:"Model ID (optional)",value:u,onChange:o=>N(o.target.value),placeholder:"e.g. claude-3-opus",hint:"If provider lacks /models endpoint, enter a model ID to validate via chat/completions instead."}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsx(_,{onClick:x,disabled:!v||C||!s.baseUrl.trim(),variant:"secondary",className:"w-full sm:w-auto",children:C?"Checking...":"Check"}),g()]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(_,{onClick:k,fullWidth:!0,disabled:!s.name.trim()||!s.prefix.trim()||!s.baseUrl.trim()||h,children:h?"Creating...":"Create"}),e.jsx(_,{onClick:a,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})})}me.propTypes={isOpen:i.bool.isRequired,onClose:i.func.isRequired,onCreated:i.func.isRequired};function pe({results:r}){if(r.error&&!r.results)return e.jsxs("div",{className:"text-center py-6",children:[e.jsx("span",{className:"material-symbols-outlined text-red-500 text-[32px] mb-2 block",children:"error"}),e.jsx("p",{className:"text-sm text-red-400",children:r.error})]});const{summary:a,mode:m}=r,s=r.results||[],l={oauth:"OAuth",free:"Free",apikey:"API Key",provider:"Provider",all:"All"}[m]||m;return e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[a&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs mb-1 sm:gap-3",children:[e.jsxs("span",{className:"text-text-muted",children:[l," Test"]}),e.jsxs("span",{className:"px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-400 font-medium",children:[a.passed," passed"]}),a.failed>0&&e.jsxs("span",{className:"px-2 py-0.5 rounded bg-red-500/15 text-red-400 font-medium",children:[a.failed," failed"]}),e.jsxs("span",{className:"text-text-muted sm:ml-auto",children:[a.total," tested"]})]}),s.map((h,w)=>{var v;return e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 rounded-lg bg-black/[0.03] px-3 py-2 text-xs dark:bg-white/[0.03] sm:flex-nowrap",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] ${h.valid?"text-emerald-500":"text-red-500"}`,children:h.valid?"check_circle":"error"}),e.jsxs("div",{className:"min-w-0 flex-[1_1_160px]",children:[e.jsx("span",{className:"block truncate font-medium sm:inline",children:h.connectionName}),e.jsxs("span",{className:"block truncate text-text-muted sm:ml-1.5 sm:inline",children:["(",h.provider,")"]})]}),h.latencyMs!==void 0&&e.jsxs("span",{className:"shrink-0 text-text-muted font-mono tabular-nums",children:[h.latencyMs,"ms"]}),e.jsx("span",{className:`shrink-0 text-[10px] uppercase font-bold px-1.5 py-0.5 rounded ${h.valid?"bg-emerald-500/15 text-emerald-400":"bg-red-500/15 text-red-400"}`,children:h.valid?"OK":((v=h.diagnosis)==null?void 0:v.type)||"ERROR"})]},h.connectionId||w)}),s.length===0&&e.jsx("div",{className:"text-center py-4 text-text-muted text-sm",children:"No active connections found for this group."})]})}pe.propTypes={results:i.shape({mode:i.string,results:i.array,summary:i.shape({total:i.number,passed:i.number,failed:i.number}),error:i.string}).isRequired};export{De as default};
@@ -0,0 +1 @@
1
+ import{j as a}from"./index.AIBoioDI.js";import{b as e}from"./router.Cjj1--8t.js";import{g as m}from"./machine.CagOtseJ.js";import{A as c}from"./EndpointPageClient.Y4DlHkTu.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.CZTUlj4t.js";import"./Loading.DFQ28pFE.js";function h(){const[i,s]=e.useState(null),[n,r]=e.useState(!0);return e.useEffect(()=>{let t=!0;return m().then(o=>{t&&(s(o),r(!1))}).catch(()=>{t&&r(!1)}),()=>{t=!1}},[]),n?a.jsx("div",{className:"text-text-muted text-sm py-12 text-center",children:"Loading..."}):a.jsx(c,{machineId:i})}export{h as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./index.AIBoioDI.js";import{b as r}from"./router.Cjj1--8t.js";import{C as j}from"./Loading.DFQ28pFE.js";import"./zustand.akaTi5uX.js";function P(){return e.jsx(r.Suspense,{fallback:e.jsx(j,{}),children:e.jsx(y,{})})}function y(){const[a,h]=r.useState([]),[p,b]=r.useState(!0),[s,f]=r.useState(""),[o,n]=r.useState(null),[i,d]=r.useState(!1),[l,c]=r.useState(""),[x,m]=r.useState(null);r.useEffect(()=>{fetch("/api/media-providers/webSearch").then(t=>t.json()).then(t=>{h(Array.isArray(t)?t:[]),t.length>0&&c(t[0].id)}).catch(()=>{}).finally(()=>b(!1))},[]);const u=async()=>{if(s.trim()){d(!0),m(null),n(null);try{const t=await fetch("/api/media/webSearch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:s,providerId:l||void 0})});if(!t.ok)throw new Error(`HTTP ${t.status}`);const g=await t.json();n(g)}catch(t){m(t.message)}finally{d(!1)}}};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 px-1 sm:px-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[28px] text-primary",children:"search"}),e.jsx("h1",{className:"text-xl font-semibold text-text-main",children:"Search"})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Search Providers"}),p?e.jsx("p",{className:"text-xs text-text-muted",children:"Loading providers..."}):a.length===0?e.jsx("p",{className:"text-xs text-text-muted",children:"No search providers configured. Add one in Media Providers."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(t=>e.jsx("button",{onClick:()=>c(t.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors cursor-pointer ${l===t.id?"bg-primary/10 text-primary border border-primary/30":"bg-surface-2 text-text-muted hover:text-text-main border border-transparent"}`,children:t.name||t.id},t.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Test Search"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:t=>f(t.target.value),onKeyDown:t=>t.key==="Enter"&&u(),placeholder:"Enter search query...",className:"flex-1 rounded-lg border border-border-subtle bg-surface-2 px-3 py-2 text-sm text-text-main placeholder:text-text-muted/50 focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsx("button",{onClick:u,disabled:i||!s.trim(),className:"px-4 py-2 rounded-lg bg-primary text-white text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer",children:i?"Searching...":"Search"})]})]}),x&&e.jsx("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-4",children:e.jsx("p",{className:"text-sm text-red-400",children:x})}),o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-surface p-4",children:[e.jsx("h2",{className:"text-sm font-semibold text-text-main mb-3",children:"Results"}),e.jsx("pre",{className:"text-xs text-text-muted overflow-auto max-h-96 bg-surface-2 rounded-lg p-3 font-mono whitespace-pre-wrap",children:JSON.stringify(o,null,2)})]})]})}export{P as default};