@fudrouter/fsrouter 0.6.74 → 0.6.76

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 (46) hide show
  1. package/dist/routes/headroom/extras/route.js +2 -2
  2. package/package.json +1 -1
  3. package/public/assets/EndpointPageClient.BnlQVTIB.js +6 -0
  4. package/public/assets/{Loading.BHPtQ9vj.js → Loading.C1il44u0.js} +1 -1
  5. package/public/assets/{NoAuthProxyCard.BDcXaWvM.js → NoAuthProxyCard.WHGGEUIp.js} +1 -1
  6. package/public/assets/{index.Be3gbrBl.js → index.D4FwOBBU.js} +2 -2
  7. package/public/assets/{page.DiL4Gwqe.js → page.0Rt4rWPG.js} +1 -1
  8. package/public/assets/{page.B3QqvLep.js → page.1numFcXc.js} +1 -1
  9. package/public/assets/{page.C8sLEMa6.js → page.1w9bTOPd.js} +1 -1
  10. package/public/assets/{page.tE7PpWYW.js → page.3ARdH6tE.js} +1 -1
  11. package/public/assets/{page.B-dzeIUC.js → page.A4gD6oiw.js} +1 -1
  12. package/public/assets/{page.C6bYizL7.js → page.AhxgKhsm.js} +1 -1
  13. package/public/assets/{page.BFb7yUd8.js → page.B1og8_GD.js} +1 -1
  14. package/public/assets/{page.11hpNKmq.js → page.B5nk3H0f.js} +1 -1
  15. package/public/assets/{page.BgGJovOg.js → page.BGDrqCcI.js} +1 -1
  16. package/public/assets/{page.uziaGZsT.js → page.BJIIZWfZ.js} +1 -1
  17. package/public/assets/{page.Dl1apZE2.js → page.BdB6udZG.js} +1 -1
  18. package/public/assets/{page.sUIPWIiF.js → page.BfGkHTDS.js} +1 -1
  19. package/public/assets/{page.Df9qtrdG.js → page.Bfr4417O.js} +1 -1
  20. package/public/assets/{page.N1x4YL8_.js → page.BpcyRUKz.js} +1 -1
  21. package/public/assets/{page.CyUqJPmx.js → page.BvcbHe5b.js} +1 -1
  22. package/public/assets/{page.B-LxsnqU.js → page.C6WsIDgW.js} +1 -1
  23. package/public/assets/{page.P2Ny5veR.js → page.CCEJ5tPH.js} +1 -1
  24. package/public/assets/{page.Cged1bOZ.js → page.CMUifPIU.js} +1 -1
  25. package/public/assets/{page.HV0w1d5C.js → page.CR7Yees9.js} +1 -1
  26. package/public/assets/{page.B-nBR75u.js → page.CXCEdPh6.js} +1 -1
  27. package/public/assets/{page.B8xdkCWA.js → page.CsroRewc.js} +1 -1
  28. package/public/assets/{page.CF_YSLwP.js → page.CtLa-V_T.js} +1 -1
  29. package/public/assets/{page.C0gBvR4O.js → page.DINPUA6N.js} +1 -1
  30. package/public/assets/{page.BdS20a1O.js → page.DSEK9UW0.js} +1 -1
  31. package/public/assets/{page.CrBl7f8N.js → page.DSTzvOQ8.js} +1 -1
  32. package/public/assets/{page.fOOCr18J.js → page.DT7cpJ8d.js} +1 -1
  33. package/public/assets/{page.CpvXDkQF.js → page.DT_RnrSs.js} +1 -1
  34. package/public/assets/{page.Ch647dVk.js → page.DU7jwIPk.js} +1 -1
  35. package/public/assets/{page.D8Rp8fFR.js → page.DcmbyZGV.js} +1 -1
  36. package/public/assets/{page.-lpNgYAw.js → page.DjguJpCk.js} +1 -1
  37. package/public/assets/{page.CvUFZzXr.js → page.Dr6yAoTO.js} +1 -1
  38. package/public/assets/{page.CCNsZBXp.js → page.FR_Izkgi.js} +1 -1
  39. package/public/assets/{page.CrP7niA2.js → page.GhgvWftU.js} +1 -1
  40. package/public/assets/{page.CPTtRDxw.js → page.UoGOSKkx.js} +1 -1
  41. package/public/assets/page.cAR8tR7Z.js +1 -0
  42. package/public/assets/{page.BfmI9KYe.js → page.feKgaG20.js} +1 -1
  43. package/public/assets/{page.CdMmlUEm.js → page.t4nKFefI.js} +1 -1
  44. package/public/index.html +1 -1
  45. package/public/assets/EndpointPageClient.C2WMTYy0.js +0 -6
  46. package/public/assets/page.BbPPdoas.js +0 -1
@@ -1,4 +1,4 @@
1
- import{u as ze,j as e,M as Ue,B as q,w as De,x as Be,y as ke,z as He,h as We}from"./index.Be3gbrBl.js";import{b as t,L as Te,h as Je,N as qe}from"./router.Cjj1--8t.js";import{C as Le}from"./cliTools.CsdwAybi.js";import{g as Pe}from"./machine.CagOtseJ.js";import{I as Ge,M as fe,C as ge}from"./NoAuthProxyCard.BDcXaWvM.js";import{C as Ve}from"./Loading.BHPtQ9vj.js";import"./zustand.akaTi5uX.js";function ye({isOpen:d,onClose:r,title:L="Manual Configuration",configs:Y=[]}){const{copy:g}=ze(),[l,A]=t.useState(null),O=(E,_)=>{g(E,`manualconfig-${_}`),A(_),setTimeout(()=>A(null),2e3)};return e.jsx(Ue,{isOpen:d,onClose:r,title:L,size:"xl",children:e.jsx("div",{className:"flex flex-col gap-4",children:Y.map((E,_)=>e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-text-main",children:E.filename}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>O(E.content,_),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:l===_?"check":"content_copy"}),l===_?"Copied!":"Copy"]})]}),e.jsx("pre",{className:"px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs overflow-x-auto whitespace-pre-wrap break-all max-h-60 overflow-y-auto border border-border",children:E.content})]},_))})})}const Ye=/^[a-zA-Z0-9_.\-]+$/;function Xe({index:d,model:r,isFirst:L,isLast:Y,onEdit:g,onMoveUp:l,onMoveDown:A,onRemove:O}){const[E,_]=t.useState(!1),[B,U]=t.useState(r),o=()=>{const i=B.trim();i&&i!==r?g(i):U(r),_(!1)},s=i=>{i.key==="Enter"&&o(),i.key==="Escape"&&(U(r),_(!1))};return e.jsxs("div",{className:"group flex min-w-0 items-center gap-1.5 rounded-md bg-black/[0.02] px-2 py-1 transition-colors hover:bg-black/[0.04] dark:bg-white/[0.02] dark:hover:bg-white/[0.04]",children:[e.jsx("span",{className:"text-[10px] font-medium text-text-muted w-3 text-center shrink-0",children:d+1}),E?e.jsx("input",{autoFocus:!0,value:B,onChange:i=>U(i.target.value),onBlur:o,onKeyDown:s,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"}):e.jsx("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",onClick:()=>_(!0),title:"Click to edit",children:r}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx("button",{onClick:l,disabled:L,className:`p-0.5 rounded ${L?"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:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_upward"})}),e.jsx("button",{onClick:A,disabled:Y,className:`p-0.5 rounded ${Y?"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:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_downward"})})]}),e.jsx("button",{onClick:O,className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]})}function Qe({isOpen:d,combo:r,onClose:L,onSave:Y,activeProviders:g,kindFilter:l=null,forcePrefix:A="",title:O}){const E=r!=null&&r.name?A&&r.name.startsWith(A)?r.name.slice(A.length):r.name:"",[_,B]=t.useState(E),[U,o]=t.useState((r==null?void 0:r.models)||[]),[s,i]=t.useState(!1),[M,Q]=t.useState(!1),[P,K]=t.useState(""),[ee,W]=t.useState({});t.useEffect(()=>{d&&fetch("/api/models/alias").then(m=>m.ok?m.json():null).then(m=>m&&W(m.aliases||{})).catch(()=>{})},[d]);const b=m=>{if(!m.trim())return K("Name is required"),!1;const h=A+m;return Ye.test(h)?(K(""),!0):(K("Only letters, numbers, -, _ and . allowed"),!1)},y=m=>{let h=m.target.value;A&&h.startsWith(A)&&(h=h.slice(A.length)),B(h),h?b(h):K("")},w=m=>{U.includes(m.value)||o([...U,m.value])},x=m=>{o(U.filter(h=>h!==m.value))},C=m=>o(U.filter((h,v)=>v!==m)),j=m=>{if(m===0)return;const h=[...U];[h[m-1],h[m]]=[h[m],h[m-1]],o(h)},T=m=>{if(m===U.length-1)return;const h=[...U];[h[m],h[m+1]]=[h[m+1],h[m]],o(h)},p=async()=>{b(_)&&(Q(!0),await Y({name:A+_.trim(),models:U}),Q(!1))},a=!!r;return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{isOpen:d,onClose:L,title:O||(a?"Edit Combo":"Create Combo"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[A?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Combo Name"}),e.jsxs("div",{className:"flex items-stretch",children:[e.jsx("span",{className:"inline-flex items-center px-2 rounded-l border border-r-0 border-black/10 dark:border-white/10 bg-black/[0.04] dark:bg-white/[0.04] text-text-muted font-mono text-sm",children:A}),e.jsx("input",{value:_,onChange:y,placeholder:"my-combo",className:"flex-1 min-w-0 rounded-r border border-black/10 dark:border-white/10 bg-white dark:bg-black/20 px-2 py-1.5 font-mono text-sm outline-none focus:border-primary"})]}),P&&e.jsx("p",{className:"text-[11px] text-red-500 mt-0.5",children:P})]}):e.jsx(Ge,{label:"Combo Name",value:_,onChange:y,placeholder:"my-combo",error:P}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-0.5",children:[A?`Auto-prefixed with "${A}". `:"","Only letters, numbers, -, _ and . allowed"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Models"}),U.length===0?e.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:[e.jsx("span",{className:"material-symbols-outlined text-text-muted text-xl mb-1",children:"layers"}),e.jsx("p",{className:"text-xs text-text-muted",children:"No models added yet"})]}):e.jsx("div",{className:"flex max-h-[55vh] min-w-0 flex-col gap-1 overflow-y-auto sm:max-h-[350px]",children:U.map((m,h)=>e.jsx(Xe,{index:h,model:m,isFirst:h===0,isLast:h===U.length-1,onEdit:v=>{const I=[...U];I[h]=v,o(I)},onMoveUp:()=>j(h),onMoveDown:()=>T(h),onRemove:()=>C(h)},h))}),e.jsxs("button",{onClick:()=>i(!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:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Model"]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row",children:[e.jsx(q,{onClick:L,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),e.jsx(q,{onClick:p,fullWidth:!0,size:"sm",disabled:!_.trim()||!!P||M,children:M?"Saving...":a?"Save":"Create"})]})]})}),e.jsx(fe,{isOpen:s,onClose:()=>i(!1),onSelect:w,onDeselect:x,activeProviders:g,modelAliases:ee,title:"Add Model to Combo",kindFilter:l,addedModelValues:U,closeOnSelect:!1})]})}const Ze="/api/cli-tools/cowork-mcp-registry",Ke="/api/cli-tools/cowork-mcp-tools";function et({isOpen:d,onClose:r,onAdd:L,addedNames:Y=[]}){const[g,l]=t.useState([]),[A,O]=t.useState(!1),[E,_]=t.useState(""),[B,U]=t.useState("all"),[o,s]=t.useState(null),[i,M]=t.useState(null),[Q,P]=t.useState({}),[K,ee]=t.useState({}),[W,b]=t.useState({});t.useEffect(()=>{d&&(g.length>0||(O(!0),fetch(Ze).then(a=>a.json()).then(a=>{a.error?s(a.error):l(a.servers||[])}).catch(a=>s(a.message)).finally(()=>O(!1))))},[d]);const y=t.useMemo(()=>new Set(Y),[Y]),w=t.useMemo(()=>{const a=E.trim().toLowerCase();return g.filter(m=>B==="authless"&&m.oauth||B==="oauth"&&!m.oauth?!1:a?(m.title||"").toLowerCase().includes(a)||(m.description||"").toLowerCase().includes(a)||(m.name||"").toLowerCase().includes(a):!0)},[g,E,B]),x=async a=>{if(!Q[a.url]){ee(m=>({...m,[a.url]:!0}));try{const h=await(await fetch(Ke,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:a.url})})).json(),v=h.tools||[],I=Array.isArray(a.toolNames)?a.toolNames:[],G=v.length>0?v.map(V=>V.name):I;P(V=>({...V,[a.url]:{tools:v,requiresAuth:!!h.requiresAuth,error:h.error}})),b(V=>({...V,[a.url]:Object.fromEntries(G.map(ae=>[ae,!0]))}))}catch(m){P(h=>({...h,[a.url]:{tools:[],error:m.message}}))}finally{ee(m=>({...m,[a.url]:!1}))}}},C=a=>{if(i===a.url){M(null);return}M(a.url),x(a)},j=(a,m)=>{b(h=>{var v;return{...h,[a]:{...h[a],[m]:!((v=h[a])!=null&&v[m])}}})},T=(a,m)=>{const h=W[a]||{};b(v=>({...v,[a]:Object.fromEntries(Object.keys(h).map(I=>[I,m]))}))},p=a=>{const m=W[a.url]||{},h=Object.keys(m).filter(v=>m[v]);L==null||L({name:a.slug||a.name,title:a.title,description:a.description,url:a.url,transport:a.transport,oauth:a.oauth,toolNames:h}),M(null)};return e.jsx(Ue,{isOpen:d,onClose:r,title:"Browse MCP Marketplace",size:"lg",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:E,onChange:a=>_(a.target.value),placeholder:"Search by name or description...",className:"flex-1 px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsxs("select",{value:B,onChange:a=>U(a.target.value),className:"px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[e.jsx("option",{value:"all",children:"All"}),e.jsx("option",{value:"authless",children:"Authless"}),e.jsx("option",{value:"oauth",children:"OAuth"})]})]}),o&&e.jsx("div",{className:"px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:o}),A&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted text-xs py-4 justify-center",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[18px]",children:"progress_activity"}),e.jsx("span",{children:"Loading registry..."})]}),!A&&e.jsxs("div",{className:"flex flex-col gap-1 max-h-[60vh] overflow-y-auto",children:[w.length===0&&e.jsx("div",{className:"text-center text-xs text-text-muted py-6",children:"No servers match filter"}),w.map(a=>{const m=y.has(a.slug||a.name),h=i===a.url,v=Q[a.url],I=K[a.url],G=W[a.url]||{},V=Object.keys(G),ae=Object.values(G).filter(Boolean).length;return e.jsxs("div",{className:"rounded border border-transparent hover:border-border",children:[e.jsxs("div",{className:"flex items-start gap-2 px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5",children:[a.iconUrl?e.jsx("img",{src:a.iconUrl,alt:"",className:"size-7 rounded shrink-0 object-contain",onError:F=>{F.target.style.display="none"}}):e.jsx("div",{className:"size-7 rounded bg-surface shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-medium text-xs",children:a.title}),a.oauth?e.jsx("span",{className:"px-1 py-0.5 text-[9px] rounded bg-amber-500/10 text-amber-600",children:"OAuth"}):e.jsx("span",{className:"px-1 py-0.5 text-[9px] rounded bg-green-500/10 text-green-600",children:"Authless"}),a.toolCount>0&&e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.toolCount," tools"]})]}),a.description&&e.jsx("p",{className:"text-[10px] text-text-muted line-clamp-2 mt-0.5",children:a.description})]}),e.jsx("button",{onClick:()=>m?null:C(a),disabled:m,className:`shrink-0 px-2 py-1 rounded text-[10px] font-medium transition-colors ${m?"bg-green-500/10 text-green-600 cursor-default":h?"bg-surface border border-border text-text-muted hover:bg-black/5":"bg-primary/10 border border-primary/40 text-primary hover:bg-primary/20"}`,children:m?"Added":h?"Cancel":"+ Add"})]}),h&&e.jsxs("div",{className:"px-3 py-2 bg-surface/40 border-t border-border flex flex-col gap-2",children:[I&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted text-[10px] py-1",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"progress_activity"}),e.jsx("span",{children:"Probing server for tools..."})]}),!I&&(v==null?void 0:v.requiresAuth)&&e.jsx("p",{className:"text-[10px] text-amber-600 bg-amber-500/10 px-2 py-1 rounded",children:"🔐 OAuth required. Add now and authenticate after Apply; tool list will be discovered after first connect."}),!I&&(v==null?void 0:v.error)&&!(v!=null&&v.requiresAuth)&&e.jsxs("p",{className:"text-[10px] text-red-600 bg-red-500/10 px-2 py-1 rounded",children:["Probe failed: ",v.error]}),!I&&V.length===0&&!(v!=null&&v.requiresAuth)&&!(v!=null&&v.error)&&e.jsx("p",{className:"text-[10px] text-text-muted",children:"No tools advertised by server."}),!I&&V.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[ae,"/",V.length," tools enabled"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>T(a.url,!0),className:"text-[10px] text-primary hover:underline",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"·"}),e.jsx("button",{onClick:()=>T(a.url,!1),className:"text-[10px] text-primary hover:underline",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1 max-h-40 overflow-y-auto",children:V.map(F=>e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] cursor-pointer hover:bg-black/5 dark:hover:bg-white/5 px-1 rounded",children:[e.jsx("input",{type:"checkbox",checked:!!G[F],onChange:()=>j(a.url,F),className:"size-3"}),e.jsx("span",{className:"truncate",children:F})]},F))})]}),e.jsx("button",{onClick:()=>p(a),className:"self-end px-2 py-1 rounded text-[10px] font-medium bg-primary text-white hover:bg-primary/90",children:"✓ Confirm Add"})]})]},a.url)})]}),e.jsxs("div",{className:"text-[10px] text-text-muted text-right",children:[w.length," of ",g.length," servers"]})]})})}const Fe="fsrouter.cliToolEndpointPresets",ve="__custom__",Re="__save__",tt=d=>{const r=(d||"").replace(/\/+$/,"");return r?/\/v1$/.test(r)?r:`${r}/v1`:""},st=()=>{if(typeof window>"u")return[];try{const d=JSON.parse(window.localStorage.getItem(Fe)||"[]");return Array.isArray(d)?d.filter(r=>(r==null?void 0:r.name)&&(r==null?void 0:r.baseUrl)):[]}catch{return[]}},Ie=d=>{typeof window>"u"||window.localStorage.setItem(Fe,JSON.stringify(d))},lt=({requiresExternalUrl:d,tunnelEnabled:r,tunnelPublicUrl:L,tailscaleEnabled:Y,tailscaleUrl:g,cloudEnabled:l,cloudUrl:A,savedPresets:O,withV1:E})=>{const _=[],B=U=>E?tt(U):(U||"").replace(/\/+$/,"");if(!d){const U=B(`http://127.0.0.1:${De()}`);_.push({value:"local",label:U,url:U})}if(r&&L){const U=B(L);_.push({value:"tunnel",label:U,url:U})}if(Y&&g){const U=B(g);_.push({value:"tailscale",label:U,url:U})}if(l&&A){const U=B(A);_.push({value:"cloud",label:U,url:U})}return O.forEach(U=>{_.push({value:`saved:${U.name}`,label:U.baseUrl,url:U.baseUrl,saved:!0})}),_.push({value:ve,label:"Custom URL...",url:""}),_};function je({value:d,onChange:r,requiresExternalUrl:L=!1,tunnelEnabled:Y=!1,tunnelPublicUrl:g="",tailscaleEnabled:l=!1,tailscaleUrl:A="",cloudEnabled:O=!1,cloudUrl:E="",withV1:_=!0}){const[B,U]=t.useState([]),[o,s]=t.useState(""),[i,M]=t.useState(""),Q=t.useRef(!1);t.useEffect(()=>{U(st())},[]);const P=t.useMemo(()=>lt({requiresExternalUrl:L,tunnelEnabled:Y,tunnelPublicUrl:g,tailscaleEnabled:l,tailscaleUrl:A,cloudEnabled:O,cloudUrl:E,savedPresets:B,withV1:_}),[L,Y,g,l,A,O,E,B,_]);t.useEffect(()=>{if(Q.current||P.length===0)return;Q.current=!0;const x=P.find(C=>C.value!==ve);x?(s(x.value),r(x.url)):s(ve)},[P,r]);const K=x=>{const C=x.target.value;if(C===Re){const T=(d||"").trim();if(!T)return;let p=T;try{p=new URL(T).host}catch{}const a=window.prompt("Save endpoint as:",p);if(!(a!=null&&a.trim()))return;const m=[...B.filter(h=>h.name!==a.trim()),{name:a.trim(),baseUrl:T}].sort((h,v)=>h.name.localeCompare(v.name));U(m),Ie(m);return}if(s(C),C===ve){M(""),r("");return}const j=P.find(T=>T.value===C);j&&r(j.url)},ee=x=>{const C=x.target.value;M(C),r(C)},W=()=>{if(!o.startsWith("saved:"))return;const x=o.slice(6),C=B.filter(j=>j.name!==x);U(C),Ie(C),s(ve),M(""),r("")},b=o.startsWith("saved:"),y=o===ve,w=y&&(i||"").trim().length>0;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:o,onChange:K,className:"flex-1 min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[P.map(x=>e.jsx("option",{value:x.value,children:x.label},x.value)),w&&e.jsx("option",{value:Re,children:"+ Save current as..."})]}),b&&e.jsx("button",{type:"button",onClick:W,className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors shrink-0",title:"Delete saved endpoint",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]}),y&&e.jsx("input",{type:"text",value:i,onChange:ee,placeholder:_?"https://example.com/v1":"https://example.com",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}const we="__custom__";function be({value:d,onChange:r,apiKeys:L=[],cloudEnabled:Y=!1,className:g=""}){const l=!L.some(s=>s.key===d)&&d!=="",[A,O]=t.useState(()=>d?L.some(s=>s.key===d)?d:we:L.length>0?L[0].key:we),[E,_]=t.useState(l?d:""),B=s=>{const i=s.target.value;O(i),i===we?(_(""),r("")):r(i)},U=s=>{const i=s.target.value;_(i),r(i)};return L.length===0&&A!==we&&A!==we?e.jsx("span",{className:`min-w-0 rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5 ${g}`,children:Y?"No API keys - Create one in Keys page":"sk_fsrouter (default)"}):e.jsxs("div",{className:`flex flex-col gap-1.5 ${g}`,children:[e.jsxs("select",{value:A,onChange:B,className:"w-full min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[L.map(s=>e.jsx("option",{value:s.key,children:s.key},s.id)),e.jsx("option",{value:we,children:"Custom..."})]}),A===we&&e.jsx("input",{type:"text",value:E,onChange:U,placeholder:"sk-...",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}const Se=d=>(d||"").replace(/\/+$/,"");function Ne(d,r={}){if(!d)return!1;const L=Se(d),{tunnelPublicUrl:Y,tailscaleUrl:g,cloudUrl:l}=r;return!!(/localhost|127\.0\.0\.1|0\.0\.0\.0/.test(L)||Y&&L.startsWith(Se(Y))||g&&L.startsWith(Se(g))||l&&L.startsWith(Se(l)))}var rt={};const at=rt.NEXT_PUBLIC_CLOUD_URL;function nt({tool:d,isExpanded:r,onToggle:L,activeProviders:Y,modelMappings:g,onModelMappingChange:l,baseUrl:A,hasActiveProviders:O,apiKeys:E,cloudEnabled:_,initialStatus:B,tunnelEnabled:U,tunnelPublicUrl:o,tailscaleEnabled:s,tailscaleUrl:i}){var pe,R;const[M,Q]=t.useState(B||null),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(!1),[w,x]=t.useState(null),[C,j]=t.useState(!1),[T,p]=t.useState(!1),[a,m]=t.useState(null),[h,v]=t.useState(""),[I,G]=t.useState({}),[V,ae]=t.useState(!1),[F,oe]=t.useState(""),[ie,te]=t.useState(!1),se=t.useRef(!1),ne=(()=>{var z,le;if(!(M!=null&&M.installed))return null;const n=(le=(z=M.settings)==null?void 0:z.env)==null?void 0:le.ANTHROPIC_BASE_URL;return n?Ne(n,{tunnelPublicUrl:o,tailscaleUrl:i,cloudUrl:_?at:null})?"configured":"other":"not_configured"})();t.useEffect(()=>{(E==null?void 0:E.length)>0&&!h&&v(E[0].key)},[E,h]),t.useEffect(()=>{B&&Q(B)},[B]),t.useEffect(()=>{r&&!M&&(f(),H()),r&&H()},[r]),t.useEffect(()=>{fetch("/api/settings").then(n=>n.json()).then(n=>{te(!!n.ccFilterNaming)}).catch(()=>{})},[]);const ue=async n=>{const z=n.target.checked;te(z),await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({ccFilterNaming:z})}).catch(()=>{})},H=async()=>{try{const n=await fetch("/api/models/alias"),z=await n.json();n.ok&&G(z.aliases||{})}catch(n){console.log("Error fetching model aliases:",n)}};t.useEffect(()=>{var n;if(M!=null&&M.installed&&!se.current){se.current=!0;const z=((n=M.settings)==null?void 0:n.env)||{};d.defaultModels.forEach(k=>{if(k.envKey){const J=z[k.envKey]||k.defaultValue||"";J&&l(k.alias,J)}});const le=z.ANTHROPIC_AUTH_TOKEN;le&&(E!=null&&E.some(k=>k.key===le))&&v(le)}},[M,E,d.defaultModels,l]);const f=async()=>{K(!0);try{const z=await(await fetch("/api/cli-tools/claude-settings")).json();Q(z)}catch(n){Q({installed:!1,error:n.message})}finally{K(!1)}},$=()=>{const n=F||A;return n.endsWith("/v1")?n:`${n}/v1`},X=()=>{const n=F||A;return n.endsWith("/v1")?n:`${n}/v1`},u=async()=>{W(!0),x(null);try{const n={ANTHROPIC_BASE_URL:$()},z=(h==null?void 0:h.trim())||((E==null?void 0:E.length)>0?E[0].key:null)||(_?null:"sk_fsrouter");z&&(n.ANTHROPIC_AUTH_TOKEN=z),d.defaultModels.forEach(J=>{const de=g[J.alias];de&&J.envKey&&(n[J.envKey]=de)});const le=await fetch("/api/cli-tools/claude-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:n})}),k=await le.json();le.ok?(x({type:"success",text:"Settings applied successfully!"}),Q(J=>({...J,hasBackup:!0,settings:{...J==null?void 0:J.settings,env:n}}))):x({type:"error",text:k.error||"Failed to apply settings"})}catch(n){x({type:"error",text:n.message})}finally{W(!1)}},N=async()=>{y(!0),x(null);try{const n=await fetch("/api/cli-tools/claude-settings",{method:"DELETE"}),z=await n.json();n.ok?(x({type:"success",text:"Settings reset successfully!"}),d.defaultModels.forEach(le=>l(le.alias,le.defaultValue||"")),v("")):x({type:"error",text:z.error||"Failed to reset settings"})}catch(n){x({type:"error",text:n.message})}finally{y(!1)}},S=n=>{m(n),p(!0)},ce=n=>{a&&l(a,n.value)},xe=()=>{const n=h&&h.trim()?h:_?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",z={ANTHROPIC_BASE_URL:$(),ANTHROPIC_AUTH_TOKEN:n};return d.defaultModels.forEach(le=>{const k=g[le.alias];k&&le.envKey&&(z[le.envKey]=k)}),[{filename:"~/.claude/settings.json",content:JSON.stringify({hasCompletedOnboarding:!0,env:z},null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/claude.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:n=>{n.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),ne==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),ne==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),ne==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[P&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Claude CLI..."})]}),!P&&M&&!M.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>ae(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>j(!C),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:C?"expand_less":"help"}),C?"Hide":"How to Install"]})]})]}),C&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),e.jsx("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @anthropic-ai/claude-code"})]}),e.jsxs("p",{className:"text-text-muted",children:["After installation, run ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"claude"})," to verify."]})]})]})]}),!P&&(M==null?void 0:M.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:F||X(),onChange:oe,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:U,tunnelPublicUrl:o,tailscaleEnabled:s,tailscaleUrl:i})]}),((R=(pe=M==null?void 0:M.settings)==null?void 0:pe.env)==null?void 0:R.ANTHROPIC_BASE_URL)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:M.settings.env.ANTHROPIC_BASE_URL})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:h,onChange:v,apiKeys:E,cloudEnabled:_})]}),d.defaultModels.map(n=>e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:n.name}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:g[n.alias]||"",onChange:z=>l(n.alias,z.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),g[n.alias]&&e.jsx("button",{onClick:()=>l(n.alias,""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>S(n.alias),disabled:!O,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${O?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]},n.alias)),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Filter naming"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:ie,onChange:ue,className:"w-3.5 h-3.5 accent-primary cursor-pointer"}),e.jsx("span",{className:"text-xs text-text-muted",children:"Filter naming requests"})]}),e.jsx(Be,{text:"Intercepts Claude Code's topic-naming requests and returns a fake response locally, saving API tokens.",children:e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] cursor-help",children:"info"})})]})]}),w&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${w.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:w.type==="success"?"check_circle":"error"}),e.jsx("span",{children:w.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:u,disabled:!O,loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:N,disabled:!(M!=null&&M.hasFSRouter),loading:b,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>ae(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:T,onClose:()=>p(!1),onSelect:ce,selectedModel:a?g[a]:null,activeProviders:Y,modelAliases:I,title:`Select model for ${a}`}),e.jsx(ye,{isOpen:V,onClose:()=>ae(!1),title:"Claude CLI - Manual Configuration",configs:xe()})]})}function ot({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(!1),[x,C]=t.useState(""),[j,T]=t.useState(""),[p,a]=t.useState(""),[m,h]=t.useState(!1),[v,I]=t.useState(!1),[G,V]=t.useState({}),[ae,F]=t.useState(!1),[oe,ie]=t.useState("");t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(H(),te()),r&&te()},[r]);const te=async()=>{try{const N=await fetch("/api/models/alias"),S=await N.json();N.ok&&V(S.aliases||{})}catch(N){console.log("Error fetching model aliases:",N)}};t.useEffect(()=>{if(o!=null&&o.config){const N=o.config.match(/^model\s*=\s*"([^"]+)"/m);N&&T(N[1]);const S=o.config.match(/\[agents\.subagent\]\s*\n\s*model\s*=\s*"([^"]+)"/m);S&&a(S[1])}},[o]);const Z=(()=>{if(!(o!=null&&o.installed))return null;if(!o.config)return"not_configured";const N=o.config.match(/base_url\s*=\s*"([^"]+)"/),S=N?N[1]:"";return Ne(S,{tunnelPublicUrl:_,tailscaleUrl:U})?"configured":"other"})(),ne=()=>{const N=oe||`${Y}/v1`;return N.endsWith("/v1")?N:`${N}/v1`},ue=()=>oe||`${Y}/v1`,H=async()=>{M(!0);try{const S=await(await fetch("/api/cli-tools/codex-settings")).json();s(S)}catch(N){s({installed:!1,error:N.message})}finally{M(!1)}},f=async()=>{P(!0),b(null);try{const N=x&&x.trim()||A?x:"sk_fsrouter",S=await fetch("/api/cli-tools/codex-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ne(),apiKey:N,model:j,subagentModel:p||j})}),ce=await S.json();S.ok?(b({type:"success",text:"Settings applied successfully!"}),H()):b({type:"error",text:ce.error||"Failed to apply settings"})}catch(N){b({type:"error",text:N.message})}finally{P(!1)}},$=async()=>{ee(!0),b(null);try{const N=await fetch("/api/cli-tools/codex-settings",{method:"DELETE"}),S=await N.json();N.ok?(b({type:"success",text:"Settings reset successfully!"}),T(""),a(""),H()):b({type:"error",text:S.error||"Failed to reset settings"})}catch(N){b({type:"error",text:N.message})}finally{ee(!1)}},X=N=>{T(N.value),p||a(N.value),h(!1)},u=()=>{const N=x&&x.trim()?x:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",S=p||j,ce=`# FSRouter Configuration for Codex CLI
1
+ import{u as ze,j as e,M as Ue,B as q,w as De,x as Be,y as ke,z as He,h as We}from"./index.D4FwOBBU.js";import{b as t,L as Te,h as Je,N as qe}from"./router.Cjj1--8t.js";import{C as Le}from"./cliTools.CsdwAybi.js";import{g as Pe}from"./machine.CagOtseJ.js";import{I as Ge,M as fe,C as ge}from"./NoAuthProxyCard.WHGGEUIp.js";import{C as Ve}from"./Loading.C1il44u0.js";import"./zustand.akaTi5uX.js";function ye({isOpen:d,onClose:r,title:L="Manual Configuration",configs:Y=[]}){const{copy:g}=ze(),[l,A]=t.useState(null),O=(E,_)=>{g(E,`manualconfig-${_}`),A(_),setTimeout(()=>A(null),2e3)};return e.jsx(Ue,{isOpen:d,onClose:r,title:L,size:"xl",children:e.jsx("div",{className:"flex flex-col gap-4",children:Y.map((E,_)=>e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-text-main",children:E.filename}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>O(E.content,_),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:l===_?"check":"content_copy"}),l===_?"Copied!":"Copy"]})]}),e.jsx("pre",{className:"px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs overflow-x-auto whitespace-pre-wrap break-all max-h-60 overflow-y-auto border border-border",children:E.content})]},_))})})}const Ye=/^[a-zA-Z0-9_.\-]+$/;function Xe({index:d,model:r,isFirst:L,isLast:Y,onEdit:g,onMoveUp:l,onMoveDown:A,onRemove:O}){const[E,_]=t.useState(!1),[B,U]=t.useState(r),o=()=>{const i=B.trim();i&&i!==r?g(i):U(r),_(!1)},s=i=>{i.key==="Enter"&&o(),i.key==="Escape"&&(U(r),_(!1))};return e.jsxs("div",{className:"group flex min-w-0 items-center gap-1.5 rounded-md bg-black/[0.02] px-2 py-1 transition-colors hover:bg-black/[0.04] dark:bg-white/[0.02] dark:hover:bg-white/[0.04]",children:[e.jsx("span",{className:"text-[10px] font-medium text-text-muted w-3 text-center shrink-0",children:d+1}),E?e.jsx("input",{autoFocus:!0,value:B,onChange:i=>U(i.target.value),onBlur:o,onKeyDown:s,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"}):e.jsx("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",onClick:()=>_(!0),title:"Click to edit",children:r}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx("button",{onClick:l,disabled:L,className:`p-0.5 rounded ${L?"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:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_upward"})}),e.jsx("button",{onClick:A,disabled:Y,className:`p-0.5 rounded ${Y?"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:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_downward"})})]}),e.jsx("button",{onClick:O,className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]})}function Qe({isOpen:d,combo:r,onClose:L,onSave:Y,activeProviders:g,kindFilter:l=null,forcePrefix:A="",title:O}){const E=r!=null&&r.name?A&&r.name.startsWith(A)?r.name.slice(A.length):r.name:"",[_,B]=t.useState(E),[U,o]=t.useState((r==null?void 0:r.models)||[]),[s,i]=t.useState(!1),[M,Q]=t.useState(!1),[P,K]=t.useState(""),[ee,W]=t.useState({});t.useEffect(()=>{d&&fetch("/api/models/alias").then(m=>m.ok?m.json():null).then(m=>m&&W(m.aliases||{})).catch(()=>{})},[d]);const b=m=>{if(!m.trim())return K("Name is required"),!1;const h=A+m;return Ye.test(h)?(K(""),!0):(K("Only letters, numbers, -, _ and . allowed"),!1)},y=m=>{let h=m.target.value;A&&h.startsWith(A)&&(h=h.slice(A.length)),B(h),h?b(h):K("")},w=m=>{U.includes(m.value)||o([...U,m.value])},x=m=>{o(U.filter(h=>h!==m.value))},C=m=>o(U.filter((h,v)=>v!==m)),j=m=>{if(m===0)return;const h=[...U];[h[m-1],h[m]]=[h[m],h[m-1]],o(h)},T=m=>{if(m===U.length-1)return;const h=[...U];[h[m],h[m+1]]=[h[m+1],h[m]],o(h)},p=async()=>{b(_)&&(Q(!0),await Y({name:A+_.trim(),models:U}),Q(!1))},a=!!r;return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{isOpen:d,onClose:L,title:O||(a?"Edit Combo":"Create Combo"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[A?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Combo Name"}),e.jsxs("div",{className:"flex items-stretch",children:[e.jsx("span",{className:"inline-flex items-center px-2 rounded-l border border-r-0 border-black/10 dark:border-white/10 bg-black/[0.04] dark:bg-white/[0.04] text-text-muted font-mono text-sm",children:A}),e.jsx("input",{value:_,onChange:y,placeholder:"my-combo",className:"flex-1 min-w-0 rounded-r border border-black/10 dark:border-white/10 bg-white dark:bg-black/20 px-2 py-1.5 font-mono text-sm outline-none focus:border-primary"})]}),P&&e.jsx("p",{className:"text-[11px] text-red-500 mt-0.5",children:P})]}):e.jsx(Ge,{label:"Combo Name",value:_,onChange:y,placeholder:"my-combo",error:P}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-0.5",children:[A?`Auto-prefixed with "${A}". `:"","Only letters, numbers, -, _ and . allowed"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Models"}),U.length===0?e.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:[e.jsx("span",{className:"material-symbols-outlined text-text-muted text-xl mb-1",children:"layers"}),e.jsx("p",{className:"text-xs text-text-muted",children:"No models added yet"})]}):e.jsx("div",{className:"flex max-h-[55vh] min-w-0 flex-col gap-1 overflow-y-auto sm:max-h-[350px]",children:U.map((m,h)=>e.jsx(Xe,{index:h,model:m,isFirst:h===0,isLast:h===U.length-1,onEdit:v=>{const I=[...U];I[h]=v,o(I)},onMoveUp:()=>j(h),onMoveDown:()=>T(h),onRemove:()=>C(h)},h))}),e.jsxs("button",{onClick:()=>i(!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:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Model"]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row",children:[e.jsx(q,{onClick:L,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),e.jsx(q,{onClick:p,fullWidth:!0,size:"sm",disabled:!_.trim()||!!P||M,children:M?"Saving...":a?"Save":"Create"})]})]})}),e.jsx(fe,{isOpen:s,onClose:()=>i(!1),onSelect:w,onDeselect:x,activeProviders:g,modelAliases:ee,title:"Add Model to Combo",kindFilter:l,addedModelValues:U,closeOnSelect:!1})]})}const Ze="/api/cli-tools/cowork-mcp-registry",Ke="/api/cli-tools/cowork-mcp-tools";function et({isOpen:d,onClose:r,onAdd:L,addedNames:Y=[]}){const[g,l]=t.useState([]),[A,O]=t.useState(!1),[E,_]=t.useState(""),[B,U]=t.useState("all"),[o,s]=t.useState(null),[i,M]=t.useState(null),[Q,P]=t.useState({}),[K,ee]=t.useState({}),[W,b]=t.useState({});t.useEffect(()=>{d&&(g.length>0||(O(!0),fetch(Ze).then(a=>a.json()).then(a=>{a.error?s(a.error):l(a.servers||[])}).catch(a=>s(a.message)).finally(()=>O(!1))))},[d]);const y=t.useMemo(()=>new Set(Y),[Y]),w=t.useMemo(()=>{const a=E.trim().toLowerCase();return g.filter(m=>B==="authless"&&m.oauth||B==="oauth"&&!m.oauth?!1:a?(m.title||"").toLowerCase().includes(a)||(m.description||"").toLowerCase().includes(a)||(m.name||"").toLowerCase().includes(a):!0)},[g,E,B]),x=async a=>{if(!Q[a.url]){ee(m=>({...m,[a.url]:!0}));try{const h=await(await fetch(Ke,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:a.url})})).json(),v=h.tools||[],I=Array.isArray(a.toolNames)?a.toolNames:[],G=v.length>0?v.map(V=>V.name):I;P(V=>({...V,[a.url]:{tools:v,requiresAuth:!!h.requiresAuth,error:h.error}})),b(V=>({...V,[a.url]:Object.fromEntries(G.map(ae=>[ae,!0]))}))}catch(m){P(h=>({...h,[a.url]:{tools:[],error:m.message}}))}finally{ee(m=>({...m,[a.url]:!1}))}}},C=a=>{if(i===a.url){M(null);return}M(a.url),x(a)},j=(a,m)=>{b(h=>{var v;return{...h,[a]:{...h[a],[m]:!((v=h[a])!=null&&v[m])}}})},T=(a,m)=>{const h=W[a]||{};b(v=>({...v,[a]:Object.fromEntries(Object.keys(h).map(I=>[I,m]))}))},p=a=>{const m=W[a.url]||{},h=Object.keys(m).filter(v=>m[v]);L==null||L({name:a.slug||a.name,title:a.title,description:a.description,url:a.url,transport:a.transport,oauth:a.oauth,toolNames:h}),M(null)};return e.jsx(Ue,{isOpen:d,onClose:r,title:"Browse MCP Marketplace",size:"lg",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:E,onChange:a=>_(a.target.value),placeholder:"Search by name or description...",className:"flex-1 px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsxs("select",{value:B,onChange:a=>U(a.target.value),className:"px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[e.jsx("option",{value:"all",children:"All"}),e.jsx("option",{value:"authless",children:"Authless"}),e.jsx("option",{value:"oauth",children:"OAuth"})]})]}),o&&e.jsx("div",{className:"px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:o}),A&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted text-xs py-4 justify-center",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[18px]",children:"progress_activity"}),e.jsx("span",{children:"Loading registry..."})]}),!A&&e.jsxs("div",{className:"flex flex-col gap-1 max-h-[60vh] overflow-y-auto",children:[w.length===0&&e.jsx("div",{className:"text-center text-xs text-text-muted py-6",children:"No servers match filter"}),w.map(a=>{const m=y.has(a.slug||a.name),h=i===a.url,v=Q[a.url],I=K[a.url],G=W[a.url]||{},V=Object.keys(G),ae=Object.values(G).filter(Boolean).length;return e.jsxs("div",{className:"rounded border border-transparent hover:border-border",children:[e.jsxs("div",{className:"flex items-start gap-2 px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5",children:[a.iconUrl?e.jsx("img",{src:a.iconUrl,alt:"",className:"size-7 rounded shrink-0 object-contain",onError:F=>{F.target.style.display="none"}}):e.jsx("div",{className:"size-7 rounded bg-surface shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-medium text-xs",children:a.title}),a.oauth?e.jsx("span",{className:"px-1 py-0.5 text-[9px] rounded bg-amber-500/10 text-amber-600",children:"OAuth"}):e.jsx("span",{className:"px-1 py-0.5 text-[9px] rounded bg-green-500/10 text-green-600",children:"Authless"}),a.toolCount>0&&e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.toolCount," tools"]})]}),a.description&&e.jsx("p",{className:"text-[10px] text-text-muted line-clamp-2 mt-0.5",children:a.description})]}),e.jsx("button",{onClick:()=>m?null:C(a),disabled:m,className:`shrink-0 px-2 py-1 rounded text-[10px] font-medium transition-colors ${m?"bg-green-500/10 text-green-600 cursor-default":h?"bg-surface border border-border text-text-muted hover:bg-black/5":"bg-primary/10 border border-primary/40 text-primary hover:bg-primary/20"}`,children:m?"Added":h?"Cancel":"+ Add"})]}),h&&e.jsxs("div",{className:"px-3 py-2 bg-surface/40 border-t border-border flex flex-col gap-2",children:[I&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted text-[10px] py-1",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"progress_activity"}),e.jsx("span",{children:"Probing server for tools..."})]}),!I&&(v==null?void 0:v.requiresAuth)&&e.jsx("p",{className:"text-[10px] text-amber-600 bg-amber-500/10 px-2 py-1 rounded",children:"🔐 OAuth required. Add now and authenticate after Apply; tool list will be discovered after first connect."}),!I&&(v==null?void 0:v.error)&&!(v!=null&&v.requiresAuth)&&e.jsxs("p",{className:"text-[10px] text-red-600 bg-red-500/10 px-2 py-1 rounded",children:["Probe failed: ",v.error]}),!I&&V.length===0&&!(v!=null&&v.requiresAuth)&&!(v!=null&&v.error)&&e.jsx("p",{className:"text-[10px] text-text-muted",children:"No tools advertised by server."}),!I&&V.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[ae,"/",V.length," tools enabled"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>T(a.url,!0),className:"text-[10px] text-primary hover:underline",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"·"}),e.jsx("button",{onClick:()=>T(a.url,!1),className:"text-[10px] text-primary hover:underline",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1 max-h-40 overflow-y-auto",children:V.map(F=>e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] cursor-pointer hover:bg-black/5 dark:hover:bg-white/5 px-1 rounded",children:[e.jsx("input",{type:"checkbox",checked:!!G[F],onChange:()=>j(a.url,F),className:"size-3"}),e.jsx("span",{className:"truncate",children:F})]},F))})]}),e.jsx("button",{onClick:()=>p(a),className:"self-end px-2 py-1 rounded text-[10px] font-medium bg-primary text-white hover:bg-primary/90",children:"✓ Confirm Add"})]})]},a.url)})]}),e.jsxs("div",{className:"text-[10px] text-text-muted text-right",children:[w.length," of ",g.length," servers"]})]})})}const Fe="fsrouter.cliToolEndpointPresets",ve="__custom__",Re="__save__",tt=d=>{const r=(d||"").replace(/\/+$/,"");return r?/\/v1$/.test(r)?r:`${r}/v1`:""},st=()=>{if(typeof window>"u")return[];try{const d=JSON.parse(window.localStorage.getItem(Fe)||"[]");return Array.isArray(d)?d.filter(r=>(r==null?void 0:r.name)&&(r==null?void 0:r.baseUrl)):[]}catch{return[]}},Ie=d=>{typeof window>"u"||window.localStorage.setItem(Fe,JSON.stringify(d))},lt=({requiresExternalUrl:d,tunnelEnabled:r,tunnelPublicUrl:L,tailscaleEnabled:Y,tailscaleUrl:g,cloudEnabled:l,cloudUrl:A,savedPresets:O,withV1:E})=>{const _=[],B=U=>E?tt(U):(U||"").replace(/\/+$/,"");if(!d){const U=B(`http://127.0.0.1:${De()}`);_.push({value:"local",label:U,url:U})}if(r&&L){const U=B(L);_.push({value:"tunnel",label:U,url:U})}if(Y&&g){const U=B(g);_.push({value:"tailscale",label:U,url:U})}if(l&&A){const U=B(A);_.push({value:"cloud",label:U,url:U})}return O.forEach(U=>{_.push({value:`saved:${U.name}`,label:U.baseUrl,url:U.baseUrl,saved:!0})}),_.push({value:ve,label:"Custom URL...",url:""}),_};function je({value:d,onChange:r,requiresExternalUrl:L=!1,tunnelEnabled:Y=!1,tunnelPublicUrl:g="",tailscaleEnabled:l=!1,tailscaleUrl:A="",cloudEnabled:O=!1,cloudUrl:E="",withV1:_=!0}){const[B,U]=t.useState([]),[o,s]=t.useState(""),[i,M]=t.useState(""),Q=t.useRef(!1);t.useEffect(()=>{U(st())},[]);const P=t.useMemo(()=>lt({requiresExternalUrl:L,tunnelEnabled:Y,tunnelPublicUrl:g,tailscaleEnabled:l,tailscaleUrl:A,cloudEnabled:O,cloudUrl:E,savedPresets:B,withV1:_}),[L,Y,g,l,A,O,E,B,_]);t.useEffect(()=>{if(Q.current||P.length===0)return;Q.current=!0;const x=P.find(C=>C.value!==ve);x?(s(x.value),r(x.url)):s(ve)},[P,r]);const K=x=>{const C=x.target.value;if(C===Re){const T=(d||"").trim();if(!T)return;let p=T;try{p=new URL(T).host}catch{}const a=window.prompt("Save endpoint as:",p);if(!(a!=null&&a.trim()))return;const m=[...B.filter(h=>h.name!==a.trim()),{name:a.trim(),baseUrl:T}].sort((h,v)=>h.name.localeCompare(v.name));U(m),Ie(m);return}if(s(C),C===ve){M(""),r("");return}const j=P.find(T=>T.value===C);j&&r(j.url)},ee=x=>{const C=x.target.value;M(C),r(C)},W=()=>{if(!o.startsWith("saved:"))return;const x=o.slice(6),C=B.filter(j=>j.name!==x);U(C),Ie(C),s(ve),M(""),r("")},b=o.startsWith("saved:"),y=o===ve,w=y&&(i||"").trim().length>0;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:o,onChange:K,className:"flex-1 min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[P.map(x=>e.jsx("option",{value:x.value,children:x.label},x.value)),w&&e.jsx("option",{value:Re,children:"+ Save current as..."})]}),b&&e.jsx("button",{type:"button",onClick:W,className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors shrink-0",title:"Delete saved endpoint",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]}),y&&e.jsx("input",{type:"text",value:i,onChange:ee,placeholder:_?"https://example.com/v1":"https://example.com",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}const we="__custom__";function be({value:d,onChange:r,apiKeys:L=[],cloudEnabled:Y=!1,className:g=""}){const l=!L.some(s=>s.key===d)&&d!=="",[A,O]=t.useState(()=>d?L.some(s=>s.key===d)?d:we:L.length>0?L[0].key:we),[E,_]=t.useState(l?d:""),B=s=>{const i=s.target.value;O(i),i===we?(_(""),r("")):r(i)},U=s=>{const i=s.target.value;_(i),r(i)};return L.length===0&&A!==we&&A!==we?e.jsx("span",{className:`min-w-0 rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5 ${g}`,children:Y?"No API keys - Create one in Keys page":"sk_fsrouter (default)"}):e.jsxs("div",{className:`flex flex-col gap-1.5 ${g}`,children:[e.jsxs("select",{value:A,onChange:B,className:"w-full min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[L.map(s=>e.jsx("option",{value:s.key,children:s.key},s.id)),e.jsx("option",{value:we,children:"Custom..."})]}),A===we&&e.jsx("input",{type:"text",value:E,onChange:U,placeholder:"sk-...",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}const Se=d=>(d||"").replace(/\/+$/,"");function Ne(d,r={}){if(!d)return!1;const L=Se(d),{tunnelPublicUrl:Y,tailscaleUrl:g,cloudUrl:l}=r;return!!(/localhost|127\.0\.0\.1|0\.0\.0\.0/.test(L)||Y&&L.startsWith(Se(Y))||g&&L.startsWith(Se(g))||l&&L.startsWith(Se(l)))}var rt={};const at=rt.NEXT_PUBLIC_CLOUD_URL;function nt({tool:d,isExpanded:r,onToggle:L,activeProviders:Y,modelMappings:g,onModelMappingChange:l,baseUrl:A,hasActiveProviders:O,apiKeys:E,cloudEnabled:_,initialStatus:B,tunnelEnabled:U,tunnelPublicUrl:o,tailscaleEnabled:s,tailscaleUrl:i}){var pe,R;const[M,Q]=t.useState(B||null),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(!1),[w,x]=t.useState(null),[C,j]=t.useState(!1),[T,p]=t.useState(!1),[a,m]=t.useState(null),[h,v]=t.useState(""),[I,G]=t.useState({}),[V,ae]=t.useState(!1),[F,oe]=t.useState(""),[ie,te]=t.useState(!1),se=t.useRef(!1),ne=(()=>{var z,le;if(!(M!=null&&M.installed))return null;const n=(le=(z=M.settings)==null?void 0:z.env)==null?void 0:le.ANTHROPIC_BASE_URL;return n?Ne(n,{tunnelPublicUrl:o,tailscaleUrl:i,cloudUrl:_?at:null})?"configured":"other":"not_configured"})();t.useEffect(()=>{(E==null?void 0:E.length)>0&&!h&&v(E[0].key)},[E,h]),t.useEffect(()=>{B&&Q(B)},[B]),t.useEffect(()=>{r&&!M&&(f(),H()),r&&H()},[r]),t.useEffect(()=>{fetch("/api/settings").then(n=>n.json()).then(n=>{te(!!n.ccFilterNaming)}).catch(()=>{})},[]);const ue=async n=>{const z=n.target.checked;te(z),await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({ccFilterNaming:z})}).catch(()=>{})},H=async()=>{try{const n=await fetch("/api/models/alias"),z=await n.json();n.ok&&G(z.aliases||{})}catch(n){console.log("Error fetching model aliases:",n)}};t.useEffect(()=>{var n;if(M!=null&&M.installed&&!se.current){se.current=!0;const z=((n=M.settings)==null?void 0:n.env)||{};d.defaultModels.forEach(k=>{if(k.envKey){const J=z[k.envKey]||k.defaultValue||"";J&&l(k.alias,J)}});const le=z.ANTHROPIC_AUTH_TOKEN;le&&(E!=null&&E.some(k=>k.key===le))&&v(le)}},[M,E,d.defaultModels,l]);const f=async()=>{K(!0);try{const z=await(await fetch("/api/cli-tools/claude-settings")).json();Q(z)}catch(n){Q({installed:!1,error:n.message})}finally{K(!1)}},$=()=>{const n=F||A;return n.endsWith("/v1")?n:`${n}/v1`},X=()=>{const n=F||A;return n.endsWith("/v1")?n:`${n}/v1`},u=async()=>{W(!0),x(null);try{const n={ANTHROPIC_BASE_URL:$()},z=(h==null?void 0:h.trim())||((E==null?void 0:E.length)>0?E[0].key:null)||(_?null:"sk_fsrouter");z&&(n.ANTHROPIC_AUTH_TOKEN=z),d.defaultModels.forEach(J=>{const de=g[J.alias];de&&J.envKey&&(n[J.envKey]=de)});const le=await fetch("/api/cli-tools/claude-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:n})}),k=await le.json();le.ok?(x({type:"success",text:"Settings applied successfully!"}),Q(J=>({...J,hasBackup:!0,settings:{...J==null?void 0:J.settings,env:n}}))):x({type:"error",text:k.error||"Failed to apply settings"})}catch(n){x({type:"error",text:n.message})}finally{W(!1)}},N=async()=>{y(!0),x(null);try{const n=await fetch("/api/cli-tools/claude-settings",{method:"DELETE"}),z=await n.json();n.ok?(x({type:"success",text:"Settings reset successfully!"}),d.defaultModels.forEach(le=>l(le.alias,le.defaultValue||"")),v("")):x({type:"error",text:z.error||"Failed to reset settings"})}catch(n){x({type:"error",text:n.message})}finally{y(!1)}},S=n=>{m(n),p(!0)},ce=n=>{a&&l(a,n.value)},xe=()=>{const n=h&&h.trim()?h:_?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",z={ANTHROPIC_BASE_URL:$(),ANTHROPIC_AUTH_TOKEN:n};return d.defaultModels.forEach(le=>{const k=g[le.alias];k&&le.envKey&&(z[le.envKey]=k)}),[{filename:"~/.claude/settings.json",content:JSON.stringify({hasCompletedOnboarding:!0,env:z},null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/claude.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:n=>{n.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),ne==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),ne==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),ne==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[P&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Claude CLI..."})]}),!P&&M&&!M.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>ae(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>j(!C),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:C?"expand_less":"help"}),C?"Hide":"How to Install"]})]})]}),C&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),e.jsx("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @anthropic-ai/claude-code"})]}),e.jsxs("p",{className:"text-text-muted",children:["After installation, run ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"claude"})," to verify."]})]})]})]}),!P&&(M==null?void 0:M.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:F||X(),onChange:oe,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:U,tunnelPublicUrl:o,tailscaleEnabled:s,tailscaleUrl:i})]}),((R=(pe=M==null?void 0:M.settings)==null?void 0:pe.env)==null?void 0:R.ANTHROPIC_BASE_URL)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:M.settings.env.ANTHROPIC_BASE_URL})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:h,onChange:v,apiKeys:E,cloudEnabled:_})]}),d.defaultModels.map(n=>e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:n.name}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:g[n.alias]||"",onChange:z=>l(n.alias,z.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),g[n.alias]&&e.jsx("button",{onClick:()=>l(n.alias,""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>S(n.alias),disabled:!O,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${O?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]},n.alias)),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Filter naming"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:ie,onChange:ue,className:"w-3.5 h-3.5 accent-primary cursor-pointer"}),e.jsx("span",{className:"text-xs text-text-muted",children:"Filter naming requests"})]}),e.jsx(Be,{text:"Intercepts Claude Code's topic-naming requests and returns a fake response locally, saving API tokens.",children:e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] cursor-help",children:"info"})})]})]}),w&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${w.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:w.type==="success"?"check_circle":"error"}),e.jsx("span",{children:w.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:u,disabled:!O,loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:N,disabled:!(M!=null&&M.hasFSRouter),loading:b,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>ae(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:T,onClose:()=>p(!1),onSelect:ce,selectedModel:a?g[a]:null,activeProviders:Y,modelAliases:I,title:`Select model for ${a}`}),e.jsx(ye,{isOpen:V,onClose:()=>ae(!1),title:"Claude CLI - Manual Configuration",configs:xe()})]})}function ot({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(!1),[x,C]=t.useState(""),[j,T]=t.useState(""),[p,a]=t.useState(""),[m,h]=t.useState(!1),[v,I]=t.useState(!1),[G,V]=t.useState({}),[ae,F]=t.useState(!1),[oe,ie]=t.useState("");t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(H(),te()),r&&te()},[r]);const te=async()=>{try{const N=await fetch("/api/models/alias"),S=await N.json();N.ok&&V(S.aliases||{})}catch(N){console.log("Error fetching model aliases:",N)}};t.useEffect(()=>{if(o!=null&&o.config){const N=o.config.match(/^model\s*=\s*"([^"]+)"/m);N&&T(N[1]);const S=o.config.match(/\[agents\.subagent\]\s*\n\s*model\s*=\s*"([^"]+)"/m);S&&a(S[1])}},[o]);const Z=(()=>{if(!(o!=null&&o.installed))return null;if(!o.config)return"not_configured";const N=o.config.match(/base_url\s*=\s*"([^"]+)"/),S=N?N[1]:"";return Ne(S,{tunnelPublicUrl:_,tailscaleUrl:U})?"configured":"other"})(),ne=()=>{const N=oe||`${Y}/v1`;return N.endsWith("/v1")?N:`${N}/v1`},ue=()=>oe||`${Y}/v1`,H=async()=>{M(!0);try{const S=await(await fetch("/api/cli-tools/codex-settings")).json();s(S)}catch(N){s({installed:!1,error:N.message})}finally{M(!1)}},f=async()=>{P(!0),b(null);try{const N=x&&x.trim()||A?x:"sk_fsrouter",S=await fetch("/api/cli-tools/codex-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ne(),apiKey:N,model:j,subagentModel:p||j})}),ce=await S.json();S.ok?(b({type:"success",text:"Settings applied successfully!"}),H()):b({type:"error",text:ce.error||"Failed to apply settings"})}catch(N){b({type:"error",text:N.message})}finally{P(!1)}},$=async()=>{ee(!0),b(null);try{const N=await fetch("/api/cli-tools/codex-settings",{method:"DELETE"}),S=await N.json();N.ok?(b({type:"success",text:"Settings reset successfully!"}),T(""),a(""),H()):b({type:"error",text:S.error||"Failed to reset settings"})}catch(N){b({type:"error",text:N.message})}finally{ee(!1)}},X=N=>{T(N.value),p||a(N.value),h(!1)},u=()=>{const N=x&&x.trim()?x:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",S=p||j,ce=`# FSRouter Configuration for Codex CLI
2
2
  model = "${j}"
3
3
  model_provider = "fsrouter"
4
4
 
@@ -1 +1 @@
1
- import{F as le,j as e,g as Y,n as k,B as q,o as oe}from"./index.Be3gbrBl.js";import{d as se,f as re,b as x}from"./router.Cjj1--8t.js";import{B as I,f as D,c as M,d as ie,P as de,U as ce,e as xe,C as V}from"./NoAuthProxyCard.BDcXaWvM.js";import{C as ae}from"./Loading.BHPtQ9vj.js";import"./zustand.akaTi5uX.js";function Q(s){if(s==="leonardo"||s==="weavy")return!0;const t=Y[s];return t!=null&&t.serviceKinds?t.serviceKinds.includes("llm"):!0}function me(s){const t=Math.floor((Date.now()-new Date(s))/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function ue({timestamp:s}){const[,t]=x.useState(0);return x.useEffect(()=>{const r=setInterval(()=>t(a=>a+1),1e3);return()=>clearInterval(r)},[]),e.jsx(e.Fragment,{children:me(s)})}function pe({requests:s=[]}){return e.jsxs(V,{className:"flex min-w-0 flex-col overflow-hidden",padding:"sm",style:{height:480},children:[e.jsx("div",{className:"px-1 py-2 border-b border-border shrink-0",children:e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide",children:"Recent Requests"})}),s.length?e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("table",{className:"w-full min-w-[300px] border-collapse text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-bg z-10",children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted w-2"}),e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted",children:"Model"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted whitespace-nowrap",children:"In / Out"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((t,r)=>{const a=t.status==="streaming",i=!t.status||t.status==="ok"||t.status==="success";return e.jsxs("tr",{className:"hover:bg-bg-subtle transition-colors",children:[e.jsx("td",{className:"py-1.5",children:a?e.jsx("span",{className:"block w-1.5 h-1.5 rounded-full bg-warning animate-pulse",title:"Streaming…"}):e.jsx("span",{className:`block w-1.5 h-1.5 rounded-full ${i?"bg-success":"bg-error"}`})}),e.jsx("td",{className:"py-1.5 font-mono truncate max-w-[120px]",title:t.model,children:t.model}),e.jsx("td",{className:"py-1.5 text-right whitespace-nowrap",children:a?e.jsx("span",{className:"text-warning italic text-[10px]",children:"streaming…"}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-primary",children:[D(t.promptTokens),"↑"]})," ",e.jsxs("span",{className:"text-success",children:[D(t.completionTokens),"↓"]})]})}),e.jsx("td",{className:"py-1.5 text-right text-text-muted whitespace-nowrap",children:e.jsx(ue,{timestamp:t.timestamp})})]},r)})})]})}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-text-muted text-sm",children:"No requests yet."})]})}function _(s,t={},r,a){return Object.entries(s||{}).map(([i,o])=>{const n=(o.promptTokens||0)+(o.completionTokens||0),l=o.cost||0,b=n>0?(o.promptTokens||0)*(l/n):0,p=n>0?(o.completionTokens||0)*(l/n):0;return{...o,key:i,totalTokens:n,totalCost:l,inputCost:b,outputCost:p,pending:t[i]||0}}).sort((i,o)=>{let n=i[r],l=o[r];return typeof n=="string"&&(n=n.toLowerCase()),typeof l=="string"&&(l=l.toLowerCase()),n<l?a==="asc"?-1:1:n>l?a==="asc"?1:-1:0})}function he(s,t){var r;switch(t){case"rawModel":return s.rawModel||"Unknown Model";case"accountName":return s.accountName||`Account ${(r=s.connectionId)==null?void 0:r.slice(0,8)}...`||"Unknown Account";case"keyName":return s.keyName||"Unknown Key";case"endpoint":return s.endpoint||"Unknown Endpoint";default:return s[t]||"Unknown"}}function K(s,t){if(!Array.isArray(s))return[];const r={};return s.forEach(a=>{const i=he(a,t);r[i]||(r[i]={groupKey:i,summary:{requests:0,promptTokens:0,completionTokens:0,totalTokens:0,cost:0,inputCost:0,outputCost:0,lastUsed:null,pending:0},items:[]});const o=r[i].summary;o.requests+=a.requests||0,o.promptTokens+=a.promptTokens||0,o.completionTokens+=a.completionTokens||0,o.totalTokens+=a.totalTokens||0,o.cost+=a.cost||0,o.inputCost+=a.inputCost||0,o.outputCost+=a.outputCost||0,o.pending+=a.pending||0,a.lastUsed&&(!o.lastUsed||new Date(a.lastUsed)>new Date(o.lastUsed))&&(o.lastUsed=a.lastUsed),r[i].items.push(a)}),Object.values(r)}const fe=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],be=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"accountName",label:"Account"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ge=[{field:"keyName",label:"API Key Name"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],je=[{field:"endpoint",label:"Endpoint"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ve=[{value:"model",label:"Usage by Model"},{value:"account",label:"Usage by Account"},{value:"apiKey",label:"Usage by API Key"},{value:"endpoint",label:"Usage by Endpoint"}],ye=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function X(s){if(!s)return s;const t={...s};if(t.byProvider&&(t.byProvider={...t.byProvider},t.byProvider.cb)){if(!t.byProvider.codebuddy)t.byProvider.codebuddy=t.byProvider.cb;else{const r=t.byProvider.cb,a=t.byProvider.codebuddy;t.byProvider.codebuddy={requests:(a.requests||0)+(r.requests||0),promptTokens:(a.promptTokens||0)+(r.promptTokens||0),completionTokens:(a.completionTokens||0)+(r.completionTokens||0),cost:(a.cost||0)+(r.cost||0)}}delete t.byProvider.cb}return t.byModel&&(t.byModel=Object.fromEntries(Object.entries(t.byModel).map(([r,a])=>r.endsWith(" (cb)")?[r.slice(0,-5)+" (codebuddy)",{...a,provider:"CodeBuddy"}]:[r,a]))),t.byAccount&&(t.byAccount=Object.fromEntries(Object.entries(t.byAccount).map(([r,a])=>a.provider==="cb"||a.provider==="Codebuddy"||a.provider==="codebuddy"?[r,{...a,provider:"CodeBuddy"}]:[r,a]))),Array.isArray(t.recentRequests)&&(t.recentRequests=t.recentRequests.map(r=>r.provider==="cb"?{...r,provider:"codebuddy"}:r)),t}function Ne({period:s,setPeriod:t,hidePeriodSelector:r=!1}={}){var E,c,w,C;const a=se(),[i]=re(),o=i.get("sortBy")||"rawModel",n=i.get("sortOrder")||"asc",[l,b]=x.useState(null),[p,j]=x.useState(!0),[f,P]=x.useState(!1),[y,h]=x.useState("model"),[N,L]=x.useState("costs"),[O,J]=x.useState([]),[G,W]=x.useState("today"),A=x.useRef(!0),T=s??G,F=t??W;x.useEffect(()=>{fetch("/api/providers").then(m=>m.ok?m.json():null).then(m=>{const v=new Set,d=((m==null?void 0:m.connections)||[]).filter(g=>g.isActive===!1||!Q(g.provider)||v.has(g.provider)?!1:(v.add(g.provider),!0)),u=Object.values(le).filter(g=>g.noAuth&&!v.has(g.id)&&Q(g.id)).map(g=>({provider:g.id,name:g.name}));J([...d,...u])}).catch(()=>{})},[]),x.useEffect(()=>{A.current?(A.current=!1,j(!0)):P(!0),fetch(`/api/usage/stats?period=${T}`).then(m=>m.ok?m.json():null).then(m=>{if(m){const v=X(m);b(d=>({...d,...v}))}}).catch(()=>{}).finally(()=>{j(!1),P(!1)})},[T]),x.useEffect(()=>{const m=new EventSource(`/api/usage/stream?period=${T}`);return m.onmessage=v=>{try{const d=JSON.parse(v.data),u=X(d);b(u),j(!1)}catch(d){console.error("[SSE CLIENT] parse error:",d)}},m.onerror=()=>j(!1),()=>m.close()},[T]);const $=x.useCallback((m,v)=>{const d=new URLSearchParams(i.toString());d.get("sortBy")===v?d.set("sortOrder",d.get("sortOrder")==="asc"?"desc":"asc"):(d.set("sortBy",v),d.set("sortOrder","asc")),a(`?${d.toString()}`,{scroll:!1})},[i,a]),S=x.useMemo(()=>{var m,v;if(!l)return null;switch(y){case"model":{const d=((m=l.pending)==null?void 0:m.byModel)||{};return{columns:fe,groupedData:K(_(l.byModel,d,o,n),"rawModel"),storageKey:"usage-stats:expanded-models",emptyMessage:"No usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}case"account":{const d={};return(v=l==null?void 0:l.pending)!=null&&v.byAccount&&Object.entries(l.byAccount||{}).forEach(([u,g])=>{const H=l.pending.byAccount[g.connectionId];if(H){const ne=g.provider?`${g.rawModel} (${g.provider})`:g.rawModel;d[u]=H[ne]||0}}),{columns:be,groupedData:K(_(l.byAccount,d,o,n),"accountName"),storageKey:"usage-stats:expanded-accounts",emptyMessage:"No account-specific usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>{var g;return e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.accountName||`Account ${(g=u.connectionId)==null?void 0:g.slice(0,8)}...`}),e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}}case"apiKey":return{columns:ge,groupedData:K(_(l.byApiKey,{},o,n),"keyName"),storageKey:"usage-stats:expanded-apikeys",emptyMessage:"No API key usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium",children:d.keyName}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})};case"endpoint":default:return{columns:je,groupedData:K(_(l.byEndpoint,{},o,n),"endpoint"),storageKey:"usage-stats:expanded-endpoints",emptyMessage:"No endpoint usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium font-mono text-sm",children:d.endpoint}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})}}},[l,y,o,n]);if(!l&&!p)return e.jsx("div",{className:"text-text-muted",children:"Failed to load usage statistics."});const R=e.jsx("div",{className:"flex items-center justify-center py-12 text-text-muted",children:e.jsx("span",{className:"material-symbols-outlined text-[32px] animate-spin",children:"progress_activity"})});return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[!r&&e.jsxs("div",{className:"flex w-full items-center gap-2 sm:w-auto sm:self-end",children:[e.jsx("div",{className:"grid flex-1 grid-cols-5 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex sm:flex-none",children:ye.map(m=>e.jsx("button",{onClick:()=>F(m.value),disabled:f,className:`rounded-md px-3 py-1 text-sm font-medium transition-colors ${T===m.value?"bg-primary text-white shadow-sm":"text-text-muted hover:bg-bg-hover hover:text-text"}`,children:m.label},m.value))}),f&&e.jsx("span",{className:"material-symbols-outlined text-[16px] text-text-muted animate-spin",children:"progress_activity"})]}),p?R:e.jsx(ie,{stats:l}),p?R:e.jsxs("div",{className:"grid min-w-0 grid-cols-1 items-stretch gap-2 lg:grid-cols-[minmax(0,2fr)_minmax(280px,1fr)]",children:[e.jsx(de,{providers:O,activeRequests:l.activeRequests||[],lastProvider:((c=(E=l.recentRequests)==null?void 0:E[0])==null?void 0:c.provider)||"",errorProvider:l.errorProvider||""}),e.jsx(pe,{requests:l.recentRequests||[]})]}),p?R:e.jsx(ce,{period:T,lastRequestTime:(C=(w=l==null?void 0:l.recentRequests)==null?void 0:w[0])==null?void 0:C.timestamp}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("select",{value:y,onChange:m=>h(m.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-1.5 text-sm font-medium text-text-main focus:outline-none focus:ring-2 focus:ring-primary/50 sm:w-auto",style:{colorScheme:"auto"},children:ve.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))}),e.jsxs("div",{className:"grid grid-cols-2 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex",children:[e.jsx("button",{onClick:()=>L("costs"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="costs"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Costs"}),e.jsx("button",{onClick:()=>L("tokens"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="tokens"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Tokens"})]})]}),p?R:S&&e.jsx(xe,{title:"",columns:S.columns,groupedData:S.groupedData,tableType:y,sortBy:o,sortOrder:n,onToggleSort:$,viewMode:N,storageKey:S.storageKey,renderSummaryCells:S.renderSummaryCells,renderDetailCells:S.renderDetailCells,emptyMessage:S.emptyMessage})]})]})}function we(){const[s,t]=x.useState([]),[r,a]=x.useState(!0),[i,o]=x.useState(!0);x.useEffect(()=>{n()},[]),x.useEffect(()=>{let l;return i&&(l=setInterval(()=>{n(!1)},3e3)),()=>clearInterval(l)},[i]);const n=async(l=!0)=>{l&&a(!0);try{const b=await fetch("/api/usage/request-logs");if(b.ok){const p=await b.json();t(p)}}catch(b){console.error("Failed to fetch logs:",b)}finally{l&&a(!1)}};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Request Logs"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("label",{className:"text-sm font-medium text-text-muted flex items-center gap-2 cursor-pointer",children:[e.jsx("span",{children:"Auto Refresh (3s)"}),e.jsx("div",{onClick:()=>o(!i),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none ${i?"bg-primary":"bg-bg-subtle border border-border"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${i?"translate-x-5":"translate-x-1"}`})})]})})]}),e.jsx(V,{className:"overflow-hidden bg-black/5 dark:bg-black/20",children:e.jsx("div",{className:"p-0 overflow-x-auto max-h-[600px] overflow-y-auto font-mono text-xs",children:r&&s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"Loading logs..."}):s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"No logs recorded yet."}):e.jsxs("table",{className:"w-full text-left border-collapse whitespace-nowrap",children:[e.jsx("thead",{className:"sticky top-0 bg-bg-subtle border-b border-border z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"DateTime"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Model"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Provider"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Account"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"In"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Out"}),e.jsx("th",{className:"px-3 py-2",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((l,b)=>{const p=l.split(" | ");if(p.length<7)return null;const j=p[6],f=j.includes("PENDING"),P=j.includes("FAILED"),y=j.includes("OK");return e.jsxs("tr",{className:`hover:bg-primary/5 transition-colors ${f?"bg-primary/5":""}`,children:[e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-text-muted",children:p[0]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border font-medium",children:p[1]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg-subtle border border-border text-[10px] uppercase font-bold",children:p[2]})}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border truncate max-w-[150px]",title:p[3],children:p[3]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-primary",children:p[4]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-success",children:p[5]}),e.jsx("td",{className:`px-3 py-1.5 font-bold ${y?"text-success":P?"text-error":"text-primary animate-pulse"}`,children:j})]},b)})})]})})}),e.jsx("div",{className:"text-[10px] text-text-muted italic",children:"Logs are loaded from the request history database."})]})}function Z({options:s=[],value:t,onChange:r,size:a="md",className:i}){const o={sm:"h-7 text-xs",md:"h-9 text-sm",lg:"h-11 text-base"};return e.jsx("div",{className:k("inline-flex items-center p-1 rounded-[10px] overflow-x-auto","bg-surface-2",i),children:s.map(n=>e.jsxs("button",{onClick:()=>r(n.value),className:k("shrink-0 px-4 rounded-[8px] font-medium transition-all",o[a],t===n.value?"bg-surface text-text-main shadow-sm":"text-text-muted hover:text-text-main"),children:[n.icon&&e.jsx("span",{className:"material-symbols-outlined text-[16px] mr-1.5",children:n.icon}),n.label]},n.value))})}function ke({isOpen:s,onClose:t,title:r,children:a,width:i="md",className:o}){const n={sm:"w-[400px]",md:"w-[500px]",lg:"w-[600px]",xl:"w-[800px]",full:"w-full"};return x.useEffect(()=>(s?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[s]),x.useEffect(()=>{const l=b=>{b.key==="Escape"&&s&&t()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[s,t]),s?e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[2px] fade-in cursor-pointer",onClick:t,"aria-hidden":"true"}),e.jsxs("div",{className:k("absolute right-0 top-0 h-full bg-surface flex flex-col","shadow-[var(--shadow-elev)]","slide-in-right","border-l border-border-subtle",n[i]||n.md,o),children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border-subtle flex-shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:r&&e.jsx("h2",{className:"text-lg font-semibold text-text-main",children:r})}),e.jsx("button",{type:"button",onClick:t,className:"p-1.5 rounded-[10px] text-text-muted hover:bg-surface-2 hover:text-text-main transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:a})]})]}):null}function Se({currentPage:s,pageSize:t,totalItems:r,onPageChange:a,onPageSizeChange:i,className:o}){const n=Math.ceil(r/t),l=r>0?(s-1)*t+1:0,b=Math.min(s*t,r),j=(()=>{const f=[];let y=Math.max(1,s-2),h=Math.min(n,y+5-1);h-y+1<5&&(y=Math.max(1,h-5+1));for(let N=y;N<=h;N++)f.push(N);return f})();return e.jsxs("div",{className:k("flex flex-col sm:flex-row items-center justify-between gap-4 py-4 px-2",o),children:[r>0&&e.jsxs("div",{className:"text-sm text-text-muted",children:["Showing ",e.jsx("span",{className:"font-medium text-text-main",children:l})," to"," ",e.jsx("span",{className:"font-medium text-text-main",children:b})," of"," ",e.jsx("span",{className:"font-medium text-text-main",children:r})," results"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2 sm:gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-text-muted",children:"Rows:"}),e.jsx("select",{value:t,onChange:f=>i(Number(f.target.value)),className:k("h-9 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","cursor-pointer"),style:{colorScheme:"auto"},children:[10,20,50].map(f=>e.jsx("option",{value:f,children:f},f))})]}),n>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s-1),disabled:s===1,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_left"})}),j[0]>1&&e.jsxs(e.Fragment,{children:[e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(1),className:"w-9 px-0 hidden sm:inline-flex",children:"1"}),j[0]>2&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."})]}),j.map(f=>e.jsx(q,{variant:s===f?"primary":"ghost",size:"sm",onClick:()=>a(f),className:k("w-9 px-0",s===f?"inline-flex":"hidden sm:inline-flex"),children:f},f)),j[j.length-1]<n&&e.jsxs(e.Fragment,{children:[j[j.length-1]<n-1&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."}),e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(n),className:"w-9 px-0 hidden sm:inline-flex",children:n})]}),e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s+1),disabled:s===n,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_right"})})]})]})]})}let z=null,U=null;async function Ce(){if(z&&U)return{providerNameCache:z,providerNodesCache:U};const r=(await(await fetch("/api/provider-nodes")).json()).nodes||[];U={};for(const a of r)U[a.id]=a.name;return z={...Y,...U},{providerNameCache:z,providerNodesCache:U}}function ee(s,t){if(!s||!t)return s;const r=t[s];if(typeof r=="string")return r;if(r!=null&&r.name)return r.name;const a=oe(s)||Y[s];return(a==null?void 0:a.name)||s}function B({title:s,children:t,defaultOpen:r=!1,icon:a=null}){const[i,o]=x.useState(r);return e.jsxs("div",{className:"border border-black/5 dark:border-white/5 rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"w-full flex items-center justify-between p-3 bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.04] dark:hover:bg-white/[0.04] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsx("span",{className:"material-symbols-outlined text-[18px] text-text-muted",children:a}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:s})]}),e.jsx("span",{className:k("material-symbols-outlined text-[20px] text-text-muted transition-transform duration-200",i?"rotate-90":""),children:"chevron_right"})]}),i&&e.jsx("div",{className:"p-4 border-t border-black/5 dark:border-white/5",children:t})]})}function te(s){const t=(s==null?void 0:s.prompt_tokens)||(s==null?void 0:s.input_tokens)||0,r=(s==null?void 0:s.cached_tokens)||(s==null?void 0:s.cache_read_input_tokens)||0;return t<r?r:t}function De(){var T,F,$,S,R,E;const[s,t]=x.useState([]),[r,a]=x.useState({page:1,pageSize:20,totalItems:0,totalPages:0}),[i,o]=x.useState(!1),[n,l]=x.useState(null),[b,p]=x.useState(!1),[j,f]=x.useState([]),[P,y]=x.useState(null),[h,N]=x.useState({provider:"",startDate:"",endDate:""}),L=x.useCallback(async()=>{try{const w=await(await fetch("/api/usage/providers")).json();f(w.providers||[]);const C=await Ce();y(C.providerNameCache)}catch(c){console.error("Failed to fetch providers:",c)}},[]),O=x.useCallback(async()=>{o(!0);try{const c=new URLSearchParams({page:r.page.toString(),pageSize:r.pageSize.toString()});h.provider&&c.append("provider",h.provider),h.startDate&&c.append("startDate",h.startDate),h.endDate&&c.append("endDate",h.endDate);const C=await(await fetch(`/api/usage/request-details?${c}`)).json();t(C.details||[]),a(m=>({...m,...C.pagination}))}catch(c){console.error("Failed to fetch request details:",c)}finally{o(!1)}},[r.page,r.pageSize,h]);x.useEffect(()=>{L()},[L]),x.useEffect(()=>{O()},[O]);const J=c=>{l(c),p(!0)},G=c=>{a(w=>({...w,page:c}))},W=c=>{a(w=>({...w,pageSize:c,page:1}))},A=()=>{N({provider:"",startDate:"",endDate:""})};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[e.jsx(V,{padding:"md",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"provider-filter",className:"text-sm font-medium text-text-main",children:"Provider"}),e.jsxs("select",{id:"provider-filter",value:h.provider,onChange:c=>N({...h,provider:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","w-full min-w-0 cursor-pointer"),style:{colorScheme:"auto"},children:[e.jsx("option",{value:"",children:"All Providers"}),j.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"start-date-filter",className:"text-sm font-medium text-text-main",children:"Start Date"}),e.jsx("input",{id:"start-date-filter",type:"datetime-local",value:h.startDate,onChange:c=>N({...h,startDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"end-date-filter",className:"text-sm font-medium text-text-main",children:"End Date"}),e.jsx("input",{id:"end-date-filter",type:"datetime-local",value:h.endDate,onChange:c=>N({...h,endDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:col-span-2 lg:col-span-1",children:[e.jsx("span",{className:"hidden text-sm font-medium text-text-main opacity-0 lg:block","aria-hidden":"true",children:"Clear"}),e.jsx(q,{variant:"ghost",onClick:A,disabled:!h.provider&&!h.startDate&&!h.endDate,className:"w-full",children:"Clear Filters"})]})]})}),e.jsxs(V,{padding:"none",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[880px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5",children:[e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Timestamp"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Model"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Provider"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Input Tokens"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Output Tokens"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Latency"}),e.jsx("th",{className:"text-center p-4 text-sm font-semibold text-text-main",children:"Action"})]})}),e.jsx("tbody",{children:i?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[20px]",children:"progress_activity"}),"Loading..."]})})}):s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:"No request details found"})}):s.map((c,w)=>{var C,m,v,d;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 last:border-b-0 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"whitespace-nowrap p-4 text-sm text-text-main",children:new Date(c.timestamp).toLocaleString()}),e.jsx("td",{className:"max-w-[260px] truncate p-4 font-mono text-sm text-text-main",children:c.model}),e.jsx("td",{className:"max-w-[180px] truncate p-4 text-sm text-text-main",children:e.jsx("span",{className:"font-medium",children:ee(c.provider,P)})}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:te(c.tokens).toLocaleString()}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:((m=(C=c.tokens)==null?void 0:C.completion_tokens)==null?void 0:m.toLocaleString())||0}),e.jsx("td",{className:"p-4 text-sm text-text-muted",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{children:["TTFT: ",e.jsxs("span",{className:"font-mono",children:[((v=c.latency)==null?void 0:v.ttft)||0,"ms"]})]}),e.jsxs("div",{children:["Total: ",e.jsxs("span",{className:"font-mono",children:[((d=c.latency)==null?void 0:d.total)||0,"ms"]})]})]})}),e.jsx("td",{className:"p-4 text-center",children:e.jsx(q,{variant:"outline",size:"sm",onClick:()=>J(c),children:"Detail"})})]},`${c.id}-${w}`)})})]})}),!i&&s.length>0&&e.jsx("div",{className:"border-t border-black/5 dark:border-white/5",children:e.jsx(Se,{currentPage:r.page,pageSize:r.pageSize,totalItems:r.totalItems,onPageChange:G,onPageSizeChange:W})})]}),e.jsx(ke,{isOpen:b,onClose:()=>p(!1),title:"Request Details",width:"lg",children:n&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"ID:"})," ",e.jsx("span",{className:"break-all font-mono text-text-main",children:n.id})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Timestamp:"})," ",e.jsx("span",{className:"text-text-main",children:new Date(n.timestamp).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Provider:"})," ",e.jsx("span",{className:"text-text-main font-medium",children:ee(n.provider,P)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Model:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:n.model})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Status:"})," ",e.jsx("span",{className:k("font-medium",n.status==="success"?"text-green-600":"text-red-600"),children:n.status})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Latency:"})," ",e.jsxs("span",{className:"text-text-main font-mono",children:["TTFT ",((T=n.latency)==null?void 0:T.ttft)||0,"ms / Total ",((F=n.latency)==null?void 0:F.total)||0,"ms"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Input Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:te(n.tokens).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Output Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:((S=($=n.tokens)==null?void 0:$.completion_tokens)==null?void 0:S.toLocaleString())||0})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(B,{title:"1. Client Request (Input)",defaultOpen:!0,icon:"input",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.request,null,2)})}),n.providerRequest&&e.jsx(B,{title:"2. Provider Request (Translated)",icon:"translate",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.providerRequest,null,2)})}),n.providerResponse&&e.jsx(B,{title:"3. Provider Response (Raw)",icon:"data_object",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:typeof n.providerResponse=="object"?JSON.stringify(n.providerResponse,null,2):n.providerResponse})}),e.jsxs(B,{title:"4. Client Response (Final)",defaultOpen:!0,icon:"output",children:[((R=n.response)==null?void 0:R.thinking)&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("h4",{className:"font-semibold text-text-main mb-2 flex items-center gap-2 text-xs uppercase tracking-wide opacity-70",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"psychology"}),"Thinking Process"]}),e.jsx("pre",{className:"max-h-[200px] max-w-full overflow-auto rounded-lg border border-amber-200 bg-amber-50 p-3 font-mono text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-100 sm:p-4",children:n.response.thinking})]}),e.jsx("h4",{className:"font-semibold text-text-main mb-2 text-xs uppercase tracking-wide opacity-70",children:"Content"}),e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:((E=n.response)==null?void 0:E.content)||"[No content]"})]})]})]})})]})}const Te=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function Ee(){return e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Pe,{})})}function Pe(){const[s]=re(),t=se(),[r,a]=x.useState("today"),i=s.get("tab"),o=i&&["overview","logs","details"].includes(i)?i:"overview",n=l=>{if(l===o)return;const b=new URLSearchParams(s);b.set("tab",l),t(`/dashboard/usage?${b.toString()}`,{scroll:!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 flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(Z,{options:[{value:"overview",label:"Overview"},{value:"details",label:"Details"}],value:o,onChange:n,className:"w-full sm:w-auto"}),o==="overview"&&e.jsx(Z,{options:Te,value:r,onChange:a,size:"sm",className:"w-full sm:w-auto"})]}),o==="overview"&&e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Ne,{period:r,setPeriod:a,hidePeriodSelector:!0})}),o==="logs"&&e.jsx(we,{}),o==="details"&&e.jsx(De,{})]})}export{Ee as default};
1
+ import{F as le,j as e,g as Y,n as k,B as q,o as oe}from"./index.D4FwOBBU.js";import{d as se,f as re,b as x}from"./router.Cjj1--8t.js";import{B as I,f as D,c as M,d as ie,P as de,U as ce,e as xe,C as V}from"./NoAuthProxyCard.WHGGEUIp.js";import{C as ae}from"./Loading.C1il44u0.js";import"./zustand.akaTi5uX.js";function Q(s){if(s==="leonardo"||s==="weavy")return!0;const t=Y[s];return t!=null&&t.serviceKinds?t.serviceKinds.includes("llm"):!0}function me(s){const t=Math.floor((Date.now()-new Date(s))/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function ue({timestamp:s}){const[,t]=x.useState(0);return x.useEffect(()=>{const r=setInterval(()=>t(a=>a+1),1e3);return()=>clearInterval(r)},[]),e.jsx(e.Fragment,{children:me(s)})}function pe({requests:s=[]}){return e.jsxs(V,{className:"flex min-w-0 flex-col overflow-hidden",padding:"sm",style:{height:480},children:[e.jsx("div",{className:"px-1 py-2 border-b border-border shrink-0",children:e.jsx("span",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide",children:"Recent Requests"})}),s.length?e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("table",{className:"w-full min-w-[300px] border-collapse text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-bg z-10",children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted w-2"}),e.jsx("th",{className:"py-1.5 text-left font-semibold text-text-muted",children:"Model"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted whitespace-nowrap",children:"In / Out"}),e.jsx("th",{className:"py-1.5 text-right font-semibold text-text-muted",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((t,r)=>{const a=t.status==="streaming",i=!t.status||t.status==="ok"||t.status==="success";return e.jsxs("tr",{className:"hover:bg-bg-subtle transition-colors",children:[e.jsx("td",{className:"py-1.5",children:a?e.jsx("span",{className:"block w-1.5 h-1.5 rounded-full bg-warning animate-pulse",title:"Streaming…"}):e.jsx("span",{className:`block w-1.5 h-1.5 rounded-full ${i?"bg-success":"bg-error"}`})}),e.jsx("td",{className:"py-1.5 font-mono truncate max-w-[120px]",title:t.model,children:t.model}),e.jsx("td",{className:"py-1.5 text-right whitespace-nowrap",children:a?e.jsx("span",{className:"text-warning italic text-[10px]",children:"streaming…"}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-primary",children:[D(t.promptTokens),"↑"]})," ",e.jsxs("span",{className:"text-success",children:[D(t.completionTokens),"↓"]})]})}),e.jsx("td",{className:"py-1.5 text-right text-text-muted whitespace-nowrap",children:e.jsx(ue,{timestamp:t.timestamp})})]},r)})})]})}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-text-muted text-sm",children:"No requests yet."})]})}function _(s,t={},r,a){return Object.entries(s||{}).map(([i,o])=>{const n=(o.promptTokens||0)+(o.completionTokens||0),l=o.cost||0,b=n>0?(o.promptTokens||0)*(l/n):0,p=n>0?(o.completionTokens||0)*(l/n):0;return{...o,key:i,totalTokens:n,totalCost:l,inputCost:b,outputCost:p,pending:t[i]||0}}).sort((i,o)=>{let n=i[r],l=o[r];return typeof n=="string"&&(n=n.toLowerCase()),typeof l=="string"&&(l=l.toLowerCase()),n<l?a==="asc"?-1:1:n>l?a==="asc"?1:-1:0})}function he(s,t){var r;switch(t){case"rawModel":return s.rawModel||"Unknown Model";case"accountName":return s.accountName||`Account ${(r=s.connectionId)==null?void 0:r.slice(0,8)}...`||"Unknown Account";case"keyName":return s.keyName||"Unknown Key";case"endpoint":return s.endpoint||"Unknown Endpoint";default:return s[t]||"Unknown"}}function K(s,t){if(!Array.isArray(s))return[];const r={};return s.forEach(a=>{const i=he(a,t);r[i]||(r[i]={groupKey:i,summary:{requests:0,promptTokens:0,completionTokens:0,totalTokens:0,cost:0,inputCost:0,outputCost:0,lastUsed:null,pending:0},items:[]});const o=r[i].summary;o.requests+=a.requests||0,o.promptTokens+=a.promptTokens||0,o.completionTokens+=a.completionTokens||0,o.totalTokens+=a.totalTokens||0,o.cost+=a.cost||0,o.inputCost+=a.inputCost||0,o.outputCost+=a.outputCost||0,o.pending+=a.pending||0,a.lastUsed&&(!o.lastUsed||new Date(a.lastUsed)>new Date(o.lastUsed))&&(o.lastUsed=a.lastUsed),r[i].items.push(a)}),Object.values(r)}const fe=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],be=[{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"accountName",label:"Account"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ge=[{field:"keyName",label:"API Key Name"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],je=[{field:"endpoint",label:"Endpoint"},{field:"rawModel",label:"Model"},{field:"provider",label:"Provider"},{field:"requests",label:"Requests",align:"right"},{field:"lastUsed",label:"Last Used",align:"right"}],ve=[{value:"model",label:"Usage by Model"},{value:"account",label:"Usage by Account"},{value:"apiKey",label:"Usage by API Key"},{value:"endpoint",label:"Usage by Endpoint"}],ye=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function X(s){if(!s)return s;const t={...s};if(t.byProvider&&(t.byProvider={...t.byProvider},t.byProvider.cb)){if(!t.byProvider.codebuddy)t.byProvider.codebuddy=t.byProvider.cb;else{const r=t.byProvider.cb,a=t.byProvider.codebuddy;t.byProvider.codebuddy={requests:(a.requests||0)+(r.requests||0),promptTokens:(a.promptTokens||0)+(r.promptTokens||0),completionTokens:(a.completionTokens||0)+(r.completionTokens||0),cost:(a.cost||0)+(r.cost||0)}}delete t.byProvider.cb}return t.byModel&&(t.byModel=Object.fromEntries(Object.entries(t.byModel).map(([r,a])=>r.endsWith(" (cb)")?[r.slice(0,-5)+" (codebuddy)",{...a,provider:"CodeBuddy"}]:[r,a]))),t.byAccount&&(t.byAccount=Object.fromEntries(Object.entries(t.byAccount).map(([r,a])=>a.provider==="cb"||a.provider==="Codebuddy"||a.provider==="codebuddy"?[r,{...a,provider:"CodeBuddy"}]:[r,a]))),Array.isArray(t.recentRequests)&&(t.recentRequests=t.recentRequests.map(r=>r.provider==="cb"?{...r,provider:"codebuddy"}:r)),t}function Ne({period:s,setPeriod:t,hidePeriodSelector:r=!1}={}){var E,c,w,C;const a=se(),[i]=re(),o=i.get("sortBy")||"rawModel",n=i.get("sortOrder")||"asc",[l,b]=x.useState(null),[p,j]=x.useState(!0),[f,P]=x.useState(!1),[y,h]=x.useState("model"),[N,L]=x.useState("costs"),[O,J]=x.useState([]),[G,W]=x.useState("today"),A=x.useRef(!0),T=s??G,F=t??W;x.useEffect(()=>{fetch("/api/providers").then(m=>m.ok?m.json():null).then(m=>{const v=new Set,d=((m==null?void 0:m.connections)||[]).filter(g=>g.isActive===!1||!Q(g.provider)||v.has(g.provider)?!1:(v.add(g.provider),!0)),u=Object.values(le).filter(g=>g.noAuth&&!v.has(g.id)&&Q(g.id)).map(g=>({provider:g.id,name:g.name}));J([...d,...u])}).catch(()=>{})},[]),x.useEffect(()=>{A.current?(A.current=!1,j(!0)):P(!0),fetch(`/api/usage/stats?period=${T}`).then(m=>m.ok?m.json():null).then(m=>{if(m){const v=X(m);b(d=>({...d,...v}))}}).catch(()=>{}).finally(()=>{j(!1),P(!1)})},[T]),x.useEffect(()=>{const m=new EventSource(`/api/usage/stream?period=${T}`);return m.onmessage=v=>{try{const d=JSON.parse(v.data),u=X(d);b(u),j(!1)}catch(d){console.error("[SSE CLIENT] parse error:",d)}},m.onerror=()=>j(!1),()=>m.close()},[T]);const $=x.useCallback((m,v)=>{const d=new URLSearchParams(i.toString());d.get("sortBy")===v?d.set("sortOrder",d.get("sortOrder")==="asc"?"desc":"asc"):(d.set("sortBy",v),d.set("sortOrder","asc")),a(`?${d.toString()}`,{scroll:!1})},[i,a]),S=x.useMemo(()=>{var m,v;if(!l)return null;switch(y){case"model":{const d=((m=l.pending)==null?void 0:m.byModel)||{};return{columns:fe,groupedData:K(_(l.byModel,d,o,n),"rawModel"),storageKey:"usage-stats:expanded-models",emptyMessage:"No usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}case"account":{const d={};return(v=l==null?void 0:l.pending)!=null&&v.byAccount&&Object.entries(l.byAccount||{}).forEach(([u,g])=>{const H=l.pending.byAccount[g.connectionId];if(H){const ne=g.provider?`${g.rawModel} (${g.provider})`:g.rawModel;d[u]=H[ne]||0}}),{columns:be,groupedData:K(_(l.byAccount,d,o,n),"accountName"),storageKey:"usage-stats:expanded-accounts",emptyMessage:"No account-specific usage recorded yet.",renderSummaryCells:u=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.summary.lastUsed)})]}),renderDetailCells:u=>{var g;return e.jsxs(e.Fragment,{children:[e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.accountName||`Account ${(g=u.connectionId)==null?void 0:g.slice(0,8)}...`}),e.jsx("td",{className:`px-6 py-3 font-medium transition-colors ${u.pending>0?"text-primary":""}`,children:u.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:u.pending>0?"primary":"neutral",size:"sm",children:u.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(u.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(u.lastUsed)})]})}}}case"apiKey":return{columns:ge,groupedData:K(_(l.byApiKey,{},o,n),"keyName"),storageKey:"usage-stats:expanded-apikeys",emptyMessage:"No API key usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium",children:d.keyName}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})};case"endpoint":default:return{columns:je,groupedData:K(_(l.byEndpoint,{},o,n),"endpoint"),storageKey:"usage-stats:expanded-endpoints",emptyMessage:"No endpoint usage recorded yet.",renderSummaryCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-text-muted",children:"—"}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.summary.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.summary.lastUsed)})]}),renderDetailCells:d=>e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"px-6 py-3 font-medium font-mono text-sm",children:d.endpoint}),e.jsx("td",{className:"px-6 py-3",children:d.rawModel}),e.jsx("td",{className:"px-6 py-3",children:e.jsx(I,{variant:"neutral",size:"sm",children:d.provider})}),e.jsx("td",{className:"px-6 py-3 text-right",children:D(d.requests)}),e.jsx("td",{className:"px-6 py-3 text-right text-text-muted whitespace-nowrap",children:M(d.lastUsed)})]})}}},[l,y,o,n]);if(!l&&!p)return e.jsx("div",{className:"text-text-muted",children:"Failed to load usage statistics."});const R=e.jsx("div",{className:"flex items-center justify-center py-12 text-text-muted",children:e.jsx("span",{className:"material-symbols-outlined text-[32px] animate-spin",children:"progress_activity"})});return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[!r&&e.jsxs("div",{className:"flex w-full items-center gap-2 sm:w-auto sm:self-end",children:[e.jsx("div",{className:"grid flex-1 grid-cols-5 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex sm:flex-none",children:ye.map(m=>e.jsx("button",{onClick:()=>F(m.value),disabled:f,className:`rounded-md px-3 py-1 text-sm font-medium transition-colors ${T===m.value?"bg-primary text-white shadow-sm":"text-text-muted hover:bg-bg-hover hover:text-text"}`,children:m.label},m.value))}),f&&e.jsx("span",{className:"material-symbols-outlined text-[16px] text-text-muted animate-spin",children:"progress_activity"})]}),p?R:e.jsx(ie,{stats:l}),p?R:e.jsxs("div",{className:"grid min-w-0 grid-cols-1 items-stretch gap-2 lg:grid-cols-[minmax(0,2fr)_minmax(280px,1fr)]",children:[e.jsx(de,{providers:O,activeRequests:l.activeRequests||[],lastProvider:((c=(E=l.recentRequests)==null?void 0:E[0])==null?void 0:c.provider)||"",errorProvider:l.errorProvider||""}),e.jsx(pe,{requests:l.recentRequests||[]})]}),p?R:e.jsx(ce,{period:T,lastRequestTime:(C=(w=l==null?void 0:l.recentRequests)==null?void 0:w[0])==null?void 0:C.timestamp}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("select",{value:y,onChange:m=>h(m.target.value),className:"w-full rounded-lg border border-border bg-surface px-3 py-1.5 text-sm font-medium text-text-main focus:outline-none focus:ring-2 focus:ring-primary/50 sm:w-auto",style:{colorScheme:"auto"},children:ve.map(m=>e.jsx("option",{value:m.value,children:m.label},m.value))}),e.jsxs("div",{className:"grid grid-cols-2 items-center gap-1 rounded-lg border border-border bg-bg-subtle p-1 sm:flex",children:[e.jsx("button",{onClick:()=>L("costs"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="costs"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Costs"}),e.jsx("button",{onClick:()=>L("tokens"),className:`px-3 py-1 rounded-md text-sm font-medium transition-colors ${N==="tokens"?"bg-primary text-white shadow-sm":"text-text-muted hover:text-text hover:bg-bg-hover"}`,children:"Tokens"})]})]}),p?R:S&&e.jsx(xe,{title:"",columns:S.columns,groupedData:S.groupedData,tableType:y,sortBy:o,sortOrder:n,onToggleSort:$,viewMode:N,storageKey:S.storageKey,renderSummaryCells:S.renderSummaryCells,renderDetailCells:S.renderDetailCells,emptyMessage:S.emptyMessage})]})]})}function we(){const[s,t]=x.useState([]),[r,a]=x.useState(!0),[i,o]=x.useState(!0);x.useEffect(()=>{n()},[]),x.useEffect(()=>{let l;return i&&(l=setInterval(()=>{n(!1)},3e3)),()=>clearInterval(l)},[i]);const n=async(l=!0)=>{l&&a(!0);try{const b=await fetch("/api/usage/request-logs");if(b.ok){const p=await b.json();t(p)}}catch(b){console.error("Failed to fetch logs:",b)}finally{l&&a(!1)}};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Request Logs"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("label",{className:"text-sm font-medium text-text-muted flex items-center gap-2 cursor-pointer",children:[e.jsx("span",{children:"Auto Refresh (3s)"}),e.jsx("div",{onClick:()=>o(!i),className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors focus:outline-none ${i?"bg-primary":"bg-bg-subtle border border-border"}`,children:e.jsx("span",{className:`inline-block h-3 w-3 transform rounded-full bg-white transition-transform ${i?"translate-x-5":"translate-x-1"}`})})]})})]}),e.jsx(V,{className:"overflow-hidden bg-black/5 dark:bg-black/20",children:e.jsx("div",{className:"p-0 overflow-x-auto max-h-[600px] overflow-y-auto font-mono text-xs",children:r&&s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"Loading logs..."}):s.length===0?e.jsx("div",{className:"p-8 text-center text-text-muted",children:"No logs recorded yet."}):e.jsxs("table",{className:"w-full text-left border-collapse whitespace-nowrap",children:[e.jsx("thead",{className:"sticky top-0 bg-bg-subtle border-b border-border z-10",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"DateTime"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Model"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Provider"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Account"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"In"}),e.jsx("th",{className:"px-3 py-2 border-r border-border",children:"Out"}),e.jsx("th",{className:"px-3 py-2",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:s.map((l,b)=>{const p=l.split(" | ");if(p.length<7)return null;const j=p[6],f=j.includes("PENDING"),P=j.includes("FAILED"),y=j.includes("OK");return e.jsxs("tr",{className:`hover:bg-primary/5 transition-colors ${f?"bg-primary/5":""}`,children:[e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-text-muted",children:p[0]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border font-medium",children:p[1]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-bg-subtle border border-border text-[10px] uppercase font-bold",children:p[2]})}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border truncate max-w-[150px]",title:p[3],children:p[3]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-primary",children:p[4]}),e.jsx("td",{className:"px-3 py-1.5 border-r border-border text-right text-success",children:p[5]}),e.jsx("td",{className:`px-3 py-1.5 font-bold ${y?"text-success":P?"text-error":"text-primary animate-pulse"}`,children:j})]},b)})})]})})}),e.jsx("div",{className:"text-[10px] text-text-muted italic",children:"Logs are loaded from the request history database."})]})}function Z({options:s=[],value:t,onChange:r,size:a="md",className:i}){const o={sm:"h-7 text-xs",md:"h-9 text-sm",lg:"h-11 text-base"};return e.jsx("div",{className:k("inline-flex items-center p-1 rounded-[10px] overflow-x-auto","bg-surface-2",i),children:s.map(n=>e.jsxs("button",{onClick:()=>r(n.value),className:k("shrink-0 px-4 rounded-[8px] font-medium transition-all",o[a],t===n.value?"bg-surface text-text-main shadow-sm":"text-text-muted hover:text-text-main"),children:[n.icon&&e.jsx("span",{className:"material-symbols-outlined text-[16px] mr-1.5",children:n.icon}),n.label]},n.value))})}function ke({isOpen:s,onClose:t,title:r,children:a,width:i="md",className:o}){const n={sm:"w-[400px]",md:"w-[500px]",lg:"w-[600px]",xl:"w-[800px]",full:"w-full"};return x.useEffect(()=>(s?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[s]),x.useEffect(()=>{const l=b=>{b.key==="Escape"&&s&&t()};return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[s,t]),s?e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-[2px] fade-in cursor-pointer",onClick:t,"aria-hidden":"true"}),e.jsxs("div",{className:k("absolute right-0 top-0 h-full bg-surface flex flex-col","shadow-[var(--shadow-elev)]","slide-in-right","border-l border-border-subtle",n[i]||n.md,o),children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-border-subtle flex-shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:r&&e.jsx("h2",{className:"text-lg font-semibold text-text-main",children:r})}),e.jsx("button",{type:"button",onClick:t,className:"p-1.5 rounded-[10px] text-text-muted hover:bg-surface-2 hover:text-text-main transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:a})]})]}):null}function Se({currentPage:s,pageSize:t,totalItems:r,onPageChange:a,onPageSizeChange:i,className:o}){const n=Math.ceil(r/t),l=r>0?(s-1)*t+1:0,b=Math.min(s*t,r),j=(()=>{const f=[];let y=Math.max(1,s-2),h=Math.min(n,y+5-1);h-y+1<5&&(y=Math.max(1,h-5+1));for(let N=y;N<=h;N++)f.push(N);return f})();return e.jsxs("div",{className:k("flex flex-col sm:flex-row items-center justify-between gap-4 py-4 px-2",o),children:[r>0&&e.jsxs("div",{className:"text-sm text-text-muted",children:["Showing ",e.jsx("span",{className:"font-medium text-text-main",children:l})," to"," ",e.jsx("span",{className:"font-medium text-text-main",children:b})," of"," ",e.jsx("span",{className:"font-medium text-text-main",children:r})," results"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2 sm:gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-text-muted",children:"Rows:"}),e.jsx("select",{value:t,onChange:f=>i(Number(f.target.value)),className:k("h-9 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","cursor-pointer"),style:{colorScheme:"auto"},children:[10,20,50].map(f=>e.jsx("option",{value:f,children:f},f))})]}),n>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s-1),disabled:s===1,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_left"})}),j[0]>1&&e.jsxs(e.Fragment,{children:[e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(1),className:"w-9 px-0 hidden sm:inline-flex",children:"1"}),j[0]>2&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."})]}),j.map(f=>e.jsx(q,{variant:s===f?"primary":"ghost",size:"sm",onClick:()=>a(f),className:k("w-9 px-0",s===f?"inline-flex":"hidden sm:inline-flex"),children:f},f)),j[j.length-1]<n&&e.jsxs(e.Fragment,{children:[j[j.length-1]<n-1&&e.jsx("span",{className:"text-text-muted px-1 hidden sm:inline",children:"..."}),e.jsx(q,{variant:"ghost",size:"sm",onClick:()=>a(n),className:"w-9 px-0 hidden sm:inline-flex",children:n})]}),e.jsx(q,{variant:"outline",size:"sm",onClick:()=>a(s+1),disabled:s===n,className:"w-9 px-0",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"chevron_right"})})]})]})]})}let z=null,U=null;async function Ce(){if(z&&U)return{providerNameCache:z,providerNodesCache:U};const r=(await(await fetch("/api/provider-nodes")).json()).nodes||[];U={};for(const a of r)U[a.id]=a.name;return z={...Y,...U},{providerNameCache:z,providerNodesCache:U}}function ee(s,t){if(!s||!t)return s;const r=t[s];if(typeof r=="string")return r;if(r!=null&&r.name)return r.name;const a=oe(s)||Y[s];return(a==null?void 0:a.name)||s}function B({title:s,children:t,defaultOpen:r=!1,icon:a=null}){const[i,o]=x.useState(r);return e.jsxs("div",{className:"border border-black/5 dark:border-white/5 rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"w-full flex items-center justify-between p-3 bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.04] dark:hover:bg-white/[0.04] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsx("span",{className:"material-symbols-outlined text-[18px] text-text-muted",children:a}),e.jsx("span",{className:"font-semibold text-sm text-text-main",children:s})]}),e.jsx("span",{className:k("material-symbols-outlined text-[20px] text-text-muted transition-transform duration-200",i?"rotate-90":""),children:"chevron_right"})]}),i&&e.jsx("div",{className:"p-4 border-t border-black/5 dark:border-white/5",children:t})]})}function te(s){const t=(s==null?void 0:s.prompt_tokens)||(s==null?void 0:s.input_tokens)||0,r=(s==null?void 0:s.cached_tokens)||(s==null?void 0:s.cache_read_input_tokens)||0;return t<r?r:t}function De(){var T,F,$,S,R,E;const[s,t]=x.useState([]),[r,a]=x.useState({page:1,pageSize:20,totalItems:0,totalPages:0}),[i,o]=x.useState(!1),[n,l]=x.useState(null),[b,p]=x.useState(!1),[j,f]=x.useState([]),[P,y]=x.useState(null),[h,N]=x.useState({provider:"",startDate:"",endDate:""}),L=x.useCallback(async()=>{try{const w=await(await fetch("/api/usage/providers")).json();f(w.providers||[]);const C=await Ce();y(C.providerNameCache)}catch(c){console.error("Failed to fetch providers:",c)}},[]),O=x.useCallback(async()=>{o(!0);try{const c=new URLSearchParams({page:r.page.toString(),pageSize:r.pageSize.toString()});h.provider&&c.append("provider",h.provider),h.startDate&&c.append("startDate",h.startDate),h.endDate&&c.append("endDate",h.endDate);const C=await(await fetch(`/api/usage/request-details?${c}`)).json();t(C.details||[]),a(m=>({...m,...C.pagination}))}catch(c){console.error("Failed to fetch request details:",c)}finally{o(!1)}},[r.page,r.pageSize,h]);x.useEffect(()=>{L()},[L]),x.useEffect(()=>{O()},[O]);const J=c=>{l(c),p(!0)},G=c=>{a(w=>({...w,page:c}))},W=c=>{a(w=>({...w,pageSize:c,page:1}))},A=()=>{N({provider:"",startDate:"",endDate:""})};return e.jsxs("div",{className:"flex min-w-0 flex-col gap-6",children:[e.jsx(V,{padding:"md",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"provider-filter",className:"text-sm font-medium text-text-main",children:"Provider"}),e.jsxs("select",{id:"provider-filter",value:h.provider,onChange:c=>N({...h,provider:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20","w-full min-w-0 cursor-pointer"),style:{colorScheme:"auto"},children:[e.jsx("option",{value:"",children:"All Providers"}),j.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"start-date-filter",className:"text-sm font-medium text-text-main",children:"Start Date"}),e.jsx("input",{id:"start-date-filter",type:"datetime-local",value:h.startDate,onChange:c=>N({...h,startDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsx("label",{htmlFor:"end-date-filter",className:"text-sm font-medium text-text-main",children:"End Date"}),e.jsx("input",{id:"end-date-filter",type:"datetime-local",value:h.endDate,onChange:c=>N({...h,endDate:c.target.value}),className:k("h-9 px-3 rounded-lg border border-black/10 dark:border-white/10 bg-surface","w-full min-w-0 text-sm text-text-main focus:outline-none focus:ring-2 focus:ring-primary/20")})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-2 sm:col-span-2 lg:col-span-1",children:[e.jsx("span",{className:"hidden text-sm font-medium text-text-main opacity-0 lg:block","aria-hidden":"true",children:"Clear"}),e.jsx(q,{variant:"ghost",onClick:A,disabled:!h.provider&&!h.startDate&&!h.endDate,className:"w-full",children:"Clear Filters"})]})]})}),e.jsxs(V,{padding:"none",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[880px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5",children:[e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Timestamp"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Model"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Provider"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Input Tokens"}),e.jsx("th",{className:"text-right p-4 text-sm font-semibold text-text-main",children:"Output Tokens"}),e.jsx("th",{className:"text-left p-4 text-sm font-semibold text-text-main",children:"Latency"}),e.jsx("th",{className:"text-center p-4 text-sm font-semibold text-text-main",children:"Action"})]})}),e.jsx("tbody",{children:i?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[20px]",children:"progress_activity"}),"Loading..."]})})}):s.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:"7",className:"p-8 text-center text-text-muted",children:"No request details found"})}):s.map((c,w)=>{var C,m,v,d;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 last:border-b-0 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:"whitespace-nowrap p-4 text-sm text-text-main",children:new Date(c.timestamp).toLocaleString()}),e.jsx("td",{className:"max-w-[260px] truncate p-4 font-mono text-sm text-text-main",children:c.model}),e.jsx("td",{className:"max-w-[180px] truncate p-4 text-sm text-text-main",children:e.jsx("span",{className:"font-medium",children:ee(c.provider,P)})}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:te(c.tokens).toLocaleString()}),e.jsx("td",{className:"p-4 text-sm text-text-main text-right font-mono",children:((m=(C=c.tokens)==null?void 0:C.completion_tokens)==null?void 0:m.toLocaleString())||0}),e.jsx("td",{className:"p-4 text-sm text-text-muted",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{children:["TTFT: ",e.jsxs("span",{className:"font-mono",children:[((v=c.latency)==null?void 0:v.ttft)||0,"ms"]})]}),e.jsxs("div",{children:["Total: ",e.jsxs("span",{className:"font-mono",children:[((d=c.latency)==null?void 0:d.total)||0,"ms"]})]})]})}),e.jsx("td",{className:"p-4 text-center",children:e.jsx(q,{variant:"outline",size:"sm",onClick:()=>J(c),children:"Detail"})})]},`${c.id}-${w}`)})})]})}),!i&&s.length>0&&e.jsx("div",{className:"border-t border-black/5 dark:border-white/5",children:e.jsx(Se,{currentPage:r.page,pageSize:r.pageSize,totalItems:r.totalItems,onPageChange:G,onPageSizeChange:W})})]}),e.jsx(ke,{isOpen:b,onClose:()=>p(!1),title:"Request Details",width:"lg",children:n&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-4 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"ID:"})," ",e.jsx("span",{className:"break-all font-mono text-text-main",children:n.id})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Timestamp:"})," ",e.jsx("span",{className:"text-text-main",children:new Date(n.timestamp).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Provider:"})," ",e.jsx("span",{className:"text-text-main font-medium",children:ee(n.provider,P)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Model:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:n.model})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Status:"})," ",e.jsx("span",{className:k("font-medium",n.status==="success"?"text-green-600":"text-red-600"),children:n.status})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Latency:"})," ",e.jsxs("span",{className:"text-text-main font-mono",children:["TTFT ",((T=n.latency)==null?void 0:T.ttft)||0,"ms / Total ",((F=n.latency)==null?void 0:F.total)||0,"ms"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Input Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:te(n.tokens).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-text-muted",children:"Output Tokens:"})," ",e.jsx("span",{className:"text-text-main font-mono",children:((S=($=n.tokens)==null?void 0:$.completion_tokens)==null?void 0:S.toLocaleString())||0})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(B,{title:"1. Client Request (Input)",defaultOpen:!0,icon:"input",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.request,null,2)})}),n.providerRequest&&e.jsx(B,{title:"2. Provider Request (Translated)",icon:"translate",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:JSON.stringify(n.providerRequest,null,2)})}),n.providerResponse&&e.jsx(B,{title:"3. Provider Response (Raw)",icon:"data_object",children:e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:typeof n.providerResponse=="object"?JSON.stringify(n.providerResponse,null,2):n.providerResponse})}),e.jsxs(B,{title:"4. Client Response (Final)",defaultOpen:!0,icon:"output",children:[((R=n.response)==null?void 0:R.thinking)&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("h4",{className:"font-semibold text-text-main mb-2 flex items-center gap-2 text-xs uppercase tracking-wide opacity-70",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"psychology"}),"Thinking Process"]}),e.jsx("pre",{className:"max-h-[200px] max-w-full overflow-auto rounded-lg border border-amber-200 bg-amber-50 p-3 font-mono text-xs text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-100 sm:p-4",children:n.response.thinking})]}),e.jsx("h4",{className:"font-semibold text-text-main mb-2 text-xs uppercase tracking-wide opacity-70",children:"Content"}),e.jsx("pre",{className:"max-h-[300px] max-w-full overflow-auto rounded-lg border border-black/5 bg-black/5 p-3 font-mono text-xs text-text-main dark:border-white/5 dark:bg-white/5 sm:p-4",children:((E=n.response)==null?void 0:E.content)||"[No content]"})]})]})]})})]})}const Te=[{value:"today",label:"Today"},{value:"24h",label:"24h"},{value:"7d",label:"7D"},{value:"30d",label:"30D"},{value:"60d",label:"60D"}];function Ee(){return e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Pe,{})})}function Pe(){const[s]=re(),t=se(),[r,a]=x.useState("today"),i=s.get("tab"),o=i&&["overview","logs","details"].includes(i)?i:"overview",n=l=>{if(l===o)return;const b=new URLSearchParams(s);b.set("tab",l),t(`/dashboard/usage?${b.toString()}`,{scroll:!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 flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(Z,{options:[{value:"overview",label:"Overview"},{value:"details",label:"Details"}],value:o,onChange:n,className:"w-full sm:w-auto"}),o==="overview"&&e.jsx(Z,{options:Te,value:r,onChange:a,size:"sm",className:"w-full sm:w-auto"})]}),o==="overview"&&e.jsx(x.Suspense,{fallback:e.jsx(ae,{}),children:e.jsx(Ne,{period:r,setPeriod:a,hidePeriodSelector:!0})}),o==="logs"&&e.jsx(we,{}),o==="details"&&e.jsx(De,{})]})}export{Ee as default};
@@ -0,0 +1 @@
1
+ import{j as o}from"./index.D4FwOBBU.js";import{b as r}from"./router.Cjj1--8t.js";import{g as a}from"./machine.CagOtseJ.js";import{A as i}from"./EndpointPageClient.BnlQVTIB.js";import"./zustand.akaTi5uX.js";import"./NoAuthProxyCard.WHGGEUIp.js";import"./Loading.C1il44u0.js";function d(){const[t,e]=r.useState("");return r.useEffect(()=>{a().then(e)},[]),t?o.jsx(i,{machineId:t}):null}export{d as default};