diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a61458b2080ad3dd.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-b69fceb3ef4b38ca.js similarity index 79% rename from litellm/proxy/_experimental/out/_next/static/chunks/app/page-a61458b2080ad3dd.js rename to litellm/proxy/_experimental/out/_next/static/chunks/app/page-b69fceb3ef4b38ca.js index 20bcc3e9bc1..74d5c51739b 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-a61458b2080ad3dd.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-b69fceb3ef4b38ca.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,s,l){Promise.resolve().then(l.bind(l,96564))},12011:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return v}});var t=l(57437),a=l(2265),r=l(99376),n=l(20831),i=l(94789),o=l(12514),d=l(49804),c=l(67101),m=l(84264),u=l(49566),h=l(96761),x=l(84566),p=l(19250),g=l(14474),j=l(13634),f=l(73002),_=l(3914);function v(){let[e]=j.Z.useForm(),s=(0,r.useSearchParams)();(0,_.e)("token");let l=s.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[k,S]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[T,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{l&&(0,p.W_)(l).then(e=>{let s=e.login_url;console.log("login_url:",s),I(s);let l=e.token,t=(0,g.o)(l);A(l),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),S(t.user_id)})},[l]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(i.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tier."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(n.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",T,"formValues:",e),v&&T&&(e.user_email=N,k&&l&&(0,p.m_)(v,l,k,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+T,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},96564:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return rT}});var t,a,r,n,i,o,d,c,m=l(57437),u=l(2265),h=l(99376),x=l(14474),p=l(21623),g=l(29827),j=l(27648),f=l(80795),_=l(15883),v=l(40428),y=l(3914),b=l(19250);let Z=async e=>{if(!e)return null;try{return await (0,b.g)(e)}catch(e){return console.error("Error fetching proxy settings:",e),null}};var N=e=>{let{userID:s,userEmail:l,userRole:t,premiumUser:a,proxySettings:r,setProxySettings:n,accessToken:i}=e,[o,d]=(0,u.useState)("");(0,u.useEffect)(()=>{(async()=>{if(i){let e=await Z(i);console.log("response from fetchProxySettings",e),e&&n(e)}})()},[i]),(0,u.useEffect)(()=>{d((null==r?void 0:r.PROXY_LOGOUT_URL)||"")},[r]);let c=[{key:"1",label:(0,m.jsxs)("div",{className:"py-1",children:[(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",l||"Unknown"]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,m.jsx)(_.Z,{})," ",s]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,m.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,y.b)(),window.location.href=o},children:[(0,m.jsx)(v.Z,{})," Logout"]})}];return(0,m.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,m.jsx)("div",{className:"w-full",children:(0,m.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,m.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,m.jsx)(j.default,{href:"/",className:"flex items-center",children:(0,m.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,m.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,m.jsx)(f.Z,{menu:{items:c,style:{padding:"4px",marginTop:"4px"}},children:(0,m.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,m.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})};let w=async(e,s,l,t,a)=>{let r;r="Admin"!=l&&"Admin Viewer"!=l?await (0,b.It)(e,(null==t?void 0:t.organization_id)||null,s):await (0,b.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var k=l(49804),S=l(67101),C=l(20831),I=l(49566),T=l(87452),A=l(88829),E=l(72208),P=l(84264),O=l(96761),L=l(29233),D=l(52787),M=l(13634),F=l(41021),R=l(91679),q=l(29967),U=l(73002),z=l(64482),V=l(30150),K=e=>{let{step:s=.01,style:l={width:"100%"},placeholder:t="Enter a numerical value",min:a,max:r,onChange:n,...i}=e;return(0,m.jsx)(V.Z,{onWheel:e=>e.currentTarget.blur(),step:s,style:l,placeholder:t,min:a,max:r,onChange:n,...i})};let B=async(e,s,l)=>{try{if(null===e||null===s)return;if(null!==l){let t=(await (0,b.So)(l,e,s,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},H=e=>{if(e.endsWith("/*")){let s=e.replace("/*","");return"All ".concat(s," models")}return e},J=(e,s)=>{let l=[],t=[];return console.log("teamModels",e),console.log("allModels",s),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=s.filter(e=>e.startsWith(a+"/"));t.push(...r),l.push(e)}else t.push(e)}),[...l,...t].filter((e,s,l)=>l.indexOf(e)===s)};var G=l(20577),W=l(15424),Y=l(89970);let $=(e,s)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===s.format,X=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},Q=(e,s,l)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[l]||"Text input";return $(e,s)?"".concat(t,"\nMust be valid JSON format"):s.enum?"Select from available options\nAllowed values: ".concat(s.enum.join(", ")):t};var ee=e=>{let{schemaComponent:s,excludedFields:l=[],form:t,overrideLabels:a={},overrideTooltips:r={},customValidation:n={},defaultValues:i={}}=e,[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null);(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.lP)()).components.schemas[s];if(!e)throw Error('Schema component "'.concat(s,'" not found'));d(e);let a={};Object.keys(e.properties).filter(e=>!l.includes(e)&&void 0!==i[e]).forEach(e=>{a[e]=i[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[s,t,l]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let s=e.anyOf.map(e=>e.type);if(s.includes("number")||s.includes("integer"))return"number";s.includes("string")}return"string"},p=(e,s)=>{var l;let t;let d=x(s),c=null==o?void 0:null===(l=o.required)||void 0===l?void 0:l.includes(e),u=a[e]||s.title||e,h=r[e]||s.description,p=[];c&&p.push({required:!0,message:"".concat(u," is required")}),n[e]&&p.push({validator:n[e]}),$(e,s)&&p.push({validator:async(e,s)=>{if(s&&!X(s))throw Error("Please enter valid JSON")}});let g=h?(0,m.jsxs)("span",{children:[u," ",(0,m.jsx)(Y.Z,{title:h,children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}):u;return t=$(e,s)?(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):s.enum?(0,m.jsx)(D.default,{children:s.enum.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"number"===d||"integer"===d?(0,m.jsx)(G.Z,{style:{width:"100%"},precision:"integer"===d?0:void 0}):"duration"===e?(0,m.jsx)(I.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,m.jsx)(I.Z,{placeholder:h||""}),(0,m.jsx)(M.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:i[e],help:(0,m.jsx)("div",{className:"text-xs text-gray-500",children:Q(e,s,d)}),children:t},e)};return c?(0,m.jsxs)("div",{className:"text-red-500",children:["Error: ",c]}):(null==o?void 0:o.properties)?(0,m.jsx)("div",{children:Object.entries(o.properties).filter(e=>{let[s]=e;return!l.includes(s)}).map(e=>{let[s,l]=e;return p(s,l)})}):null},es=e=>{let{teams:s,value:l,onChange:t}=e;return(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Search or select a team",value:l,onChange:t,filterOption:(e,s)=>{var l,t,a;return!!s&&((null===(a=s.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(l=t.props)||void 0===l?void 0:l.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==s?void 0:s.map(e=>(0,m.jsxs)(D.default.Option,{value:e.team_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},el=l(57365),et=l(93192);function ea(e){let{isInvitationLinkModalVisible:s,setIsInvitationLinkModalVisible:l,baseUrl:t,invitationLinkData:a}=e,{Title:r,Paragraph:n}=et.default,i=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,m.jsxs)(R.Z,{title:"Invitation Link",visible:s,width:800,footer:null,onOk:()=>{l(!1)},onCancel:()=>{l(!1)},children:[(0,m.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"User ID"}),(0,m.jsx)(P.Z,{children:null==a?void 0:a.user_id})]}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{children:"Invitation Link"}),(0,m.jsx)(P.Z,{children:(0,m.jsx)(P.Z,{children:i()})})]}),(0,m.jsx)("div",{className:"flex justify-end mt-5",children:(0,m.jsx)(L.CopyToClipboard,{text:i(),onCopy:()=>F.ZP.success("Copied!"),children:(0,m.jsx)(C.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var er=l(85010),en=l(72188),ei=l(73879),eo=l(34310),ed=l(38434),ec=l(26349),em=l(35291),eu=l(3632),eh=l(15452),ex=l.n(eh),ep=l(71157),eg=l(44643),ej=l(88532),ef=e=>{let{accessToken:s,teams:l,possibleUIRoles:t,onUsersCreated:a}=e,[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(null),[N,w]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.g)(s);Z(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),w(new URL("/",window.location.href).toString())},[s]);let k=async()=>{c(!0);let e=i.map(e=>({...e,status:"pending"}));o(e);let l=!1;for(let a=0;ae.trim()).filter(Boolean),0===e.teams.length&&delete e.teams),i.models&&"string"==typeof i.models&&""!==i.models.trim()&&(e.models=i.models.split(",").map(e=>e.trim()).filter(Boolean),0===e.models.length&&delete e.models),i.max_budget&&""!==i.max_budget.toString().trim()){let s=parseFloat(i.max_budget.toString());!isNaN(s)&&s>0&&(e.max_budget=s)}i.budget_duration&&""!==i.budget_duration.trim()&&(e.budget_duration=i.budget_duration.trim()),i.metadata&&"string"==typeof i.metadata&&""!==i.metadata.trim()&&(e.metadata=i.metadata.trim()),console.log("Sending user data:",e);let r=await (0,b.Ov)(s,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){l=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==y?void 0:y.SSO_ENABLED){let e=new URL("/ui",N).toString();o(s=>s.map((s,l)=>l===a?{...s,status:"success",key:r.key||r.user_id,invitation_link:e}:s))}else{let l=await (0,b.XO)(s,e),t=new URL("/ui?invitation_id=".concat(l.id),N).toString();o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}catch(s){console.error("Caught error:",s);let e=(null==s?void 0:null===(n=s.response)||void 0===n?void 0:null===(r=n.data)||void 0===r?void 0:r.error)||(null==s?void 0:s.message)||String(s);o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}c(!1),l&&a&&a()};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>n(!0),children:"+ Bulk Invite Users"}),(0,m.jsx)(R.Z,{title:"Bulk Invite Users",visible:r,width:800,onCancel:()=>n(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,m.jsx)("div",{className:"flex flex-col",children:0===i.length?(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,m.jsxs)("div",{className:"ml-11 mb-6",children:[(0,m.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,m.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,m.jsx)("li",{children:"Download our CSV template"}),(0,m.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,m.jsx)("li",{children:"Save the file and upload it here"}),(0,m.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_email"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_role"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"teams"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"models"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=new Blob([ex().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),s=window.URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download="bulk_users_template.csv",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)},size:"lg",className:"w-full md:w-auto",children:[(0,m.jsx)(ei.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,m.jsxs)("div",{className:"ml-11",children:[_?(0,m.jsxs)("div",{className:"mb-4 p-4 rounded-md border ".concat(j?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200"),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[j?(0,m.jsx)(eo.Z,{className:"text-red-500 text-xl mr-3"}):(0,m.jsx)(ed.Z,{className:"text-blue-500 text-xl mr-3"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:j?"text-red-800":"text-blue-800",children:_.name}),(0,m.jsxs)(et.default.Text,{className:"block text-xs ".concat(j?"text-red-600":"text-blue-600"),children:[(_.size/1024).toFixed(1)," KB • ",new Date().toLocaleDateString()]})]})]}),(0,m.jsxs)(C.Z,{size:"xs",variant:"secondary",onClick:()=>{v(null),o([]),x(null),g(null),f(null)},className:"flex items-center",children:[(0,m.jsx)(ec.Z,{className:"mr-1"})," Remove"]})]}),j?(0,m.jsxs)("div",{className:"mt-3 text-red-600 text-sm flex items-start",children:[(0,m.jsx)(em.Z,{className:"mr-2 mt-0.5"}),(0,m.jsx)("span",{children:j})]}):!p&&(0,m.jsxs)("div",{className:"mt-3 flex items-center",children:[(0,m.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,m.jsx)("div",{className:"bg-blue-500 h-1.5 rounded-full w-full animate-pulse"})}),(0,m.jsx)("span",{className:"ml-2 text-xs text-blue-600",children:"Processing..."})]})]}):(0,m.jsx)(er.Z,{beforeUpload:e=>((x(null),g(null),f(null),v(e),"text/csv"===e.type||e.name.endsWith(".csv"))?e.size>5242880?f("File is too large (".concat((e.size/1048576).toFixed(1)," MB). Please upload a CSV file smaller than 5MB.")):ex().parse(e,{complete:e=>{if(!e.data||0===e.data.length){g("The CSV file appears to be empty. Please upload a file with data."),o([]);return}if(1===e.data.length){g("The CSV file only contains headers but no user data. Please add user data to your CSV."),o([]);return}let s=e.data[0];if(0===s.length||1===s.length&&""===s[0]){g("The CSV file doesn't contain any column headers. Please make sure your CSV has headers."),o([]);return}let t=["user_email","user_role"].filter(e=>!s.includes(e));if(t.length>0){g("Your CSV is missing these required columns: ".concat(t.join(", "),". Please add these columns to your CSV file.")),o([]);return}try{let t=e.data.slice(1).map((e,t)=>{var a,r,n,i,o,d;if(0===e.length||1===e.length&&""===e[0])return null;if(e.length=parseFloat(c.max_budget.toString())&&m.push("Max budget must be greater than 0")),c.budget_duration&&!c.budget_duration.match(/^\d+[dhmwy]$|^\d+mo$/)&&m.push('Invalid budget duration format "'.concat(c.budget_duration,'". Use format like "30d", "1mo", "2w", "6h"')),c.teams&&"string"==typeof c.teams&&l&&l.length>0){let e=l.map(e=>e.team_id),s=c.teams.split(",").map(e=>e.trim()).filter(s=>!e.includes(s));s.length>0&&m.push("Unknown team(s): ".concat(s.join(", ")))}return m.length>0&&(c.isValid=!1,c.error=m.join(", ")),c}).filter(Boolean),a=t.filter(e=>e.isValid);o(t),0===t.length?g("No valid data rows found in the CSV file. Please check your file format."):0===a.length?x("No valid users found in the CSV. Please check the errors below and fix your CSV file."):a.length{x("Failed to parse CSV file: ".concat(e.message)),o([])},header:!1}):(f("Invalid file type: ".concat(e.name,". Please upload a CSV file (.csv extension).")),F.ZP.error("Invalid file type. Please upload a CSV file.")),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,m.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,m.jsx)(eu.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,m.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,m.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,m.jsx)(C.Z,{size:"sm",children:"Browse files"}),(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-4",children:"Only CSV files (.csv) are supported"})]})}),p&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(ej.Z,{className:"h-5 w-5 text-yellow-500 mr-2 mt-0.5"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:"text-yellow-800",children:"CSV Structure Error"}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-1 mb-0",children:p}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-2 mb-0",children:"Please download our template and ensure your CSV follows the required format."})]})]})})]})]}):(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:i.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,m.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(em.Z,{className:"text-red-500 mr-2 mt-1"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"text-red-600 font-medium",children:h}),i.some(e=>!e.isValid)&&(0,m.jsxs)("ul",{className:"mt-2 list-disc list-inside text-red-600 text-sm",children:[(0,m.jsx)("li",{children:"Check the table below for specific errors in each row"}),(0,m.jsx)("li",{children:"Common issues include invalid email formats, missing required fields, or incorrect role values"}),(0,m.jsx)("li",{children:"Fix these issues in your CSV file and upload again"})]})]})]})}),(0,m.jsxs)("div",{className:"ml-11",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,m.jsx)("div",{className:"flex items-center",children:i.some(e=>"success"===e.status||"failed"===e.status)?(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[i.filter(e=>"success"===e.status).length," Successful"]}),i.some(e=>"failed"===e.status)&&(0,m.jsxs)(P.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[i.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[i.filter(e=>e.isValid).length," of ",i.length," users valid"]})]})}),!i.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex space-x-3",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===i.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(i.filter(e=>e.isValid).length," Users")})]})]}),i.some(e=>"success"===e.status)&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"mr-3 mt-1",children:(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-blue-500"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,m.jsxs)(P.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,m.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,m.jsx)(en.Z,{dataSource:i,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,s)=>s.isValid?s.status&&"pending"!==s.status?"success"===s.status?(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,m.jsx)("span",{className:"text-green-500",children:"Success"})]}),s.invitation_link&&(0,m.jsx)("div",{className:"mt-1",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:s.invitation_link}),(0,m.jsx)(L.CopyToClipboard,{text:s.invitation_link,onCopy:()=>F.ZP.success("Invitation link copied!"),children:(0,m.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Failed"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(s.error)})]}):(0,m.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:s.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!i.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===i.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(i.filter(e=>e.isValid).length," Users")})]}),i.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=i.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),s=new Blob([ex().unparse(e)],{type:"text/csv"}),l=window.URL.createObjectURL(s),t=document.createElement("a");t.href=l,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(l)},variant:"primary",className:"flex items-center",children:[(0,m.jsx)(ei.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:e_}=D.default;var ev=e=>{let{userID:s,accessToken:l,teams:t,possibleUIRoles:a,onUserCreated:r,isEmbedded:n=!1}=e,i=(0,g.NL)(),[o,d]=(0,u.useState)(null),[c]=M.Z.useForm(),[x,p]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=(0,h.useRouter)(),[S,L]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.So)(l,s,"any"),t=[];for(let s=0;s{k&&L(new URL("/",window.location.href).toString())},[k]);let q=async e=>{var t,a,d;try{F.ZP.info("Making API Call"),n||p(!0),e.models&&0!==e.models.length||"proxy_admin"===e.user_role||(console.log("formValues.user_role",e.user_role),e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,b.Ov)(l,null,e);await i.invalidateQueries({queryKey:["userList"]}),console.log("user create Response:",a),f(!0);let d=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(r&&n){r(d),c.resetFields();return}if(null==o?void 0:o.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:d,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:s,updated_at:new Date,updated_by:s,has_user_setup_sso:!0};w(e),Z(!0)}else(0,b.XO)(l,d).then(e=>{e.has_user_setup_sso=!1,w(e),Z(!0)});F.ZP.success("API user Created"),c.resetFields(),localStorage.removeItem("userData"+s)}catch(s){let e=(null===(d=s.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.detail)||(null==s?void 0:s.message)||"Error creating the user";F.ZP.error(e),console.error("Error creating the user:",s)}};return n?(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>p(!0),children:"+ Invite User"}),(0,m.jsx)(ef,{accessToken:l,teams:t,possibleUIRoles:a}),(0,m.jsxs)(R.Z,{title:"Invite User",visible:x,width:800,footer:null,onOk:()=>{p(!1),c.resetFields()},onCancel:()=>{p(!1),f(!1),c.resetFields()},children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{children:"Personal Key Creation"})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(M.Z.Item,{className:"gap-2",label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Models user has access to, outside of team scope.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),_.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]})]}),j&&(0,m.jsx)(ea,{isInvitationLinkModalVisible:y,setIsInvitationLinkModalVisible:Z,baseUrl:S,invitationLinkData:N})]})},ey=l(7310),eb=l.n(ey),eZ=l(20347);let{Option:eN}=D.default,ew=e=>e?({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||e:"Not set";var ek=e=>{let{value:s,onChange:l,className:t="",style:a={}}=e;return(0,m.jsxs)(D.default,{style:{width:"100%",...a},value:s||void 0,onChange:l,className:t,placeholder:"n/a",children:[(0,m.jsx)(eN,{value:"24h",children:"daily"}),(0,m.jsx)(eN,{value:"7d",children:"weekly"}),(0,m.jsx)(eN,{value:"30d",children:"monthly"})]})};let{Option:eS}=D.default,eC=e=>{let s=[];if(console.log("data:",JSON.stringify(e)),e)for(let l of e)l.metadata&&l.metadata.tags&&s.push(...l.metadata.tags);let l=Array.from(new Set(s)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",l),l},eI=async(e,s,l,t)=>{try{if(null===e||null===s)return[];if(null!==l){let a=(await (0,b.So)(l,e,s,!0,t)).data.map(e=>e.id);return console.log("available_model_names:",a),a}return[]}catch(e){return console.error("Error fetching user models:",e),[]}},eT=async(e,s,l,t)=>{try{if(null===e||null===s)return;if(null!==l){let a=(await (0,b.So)(l,e,s)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eA=e=>{let{userID:s,team:l,teams:t,userRole:a,accessToken:r,data:n,addKey:i}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)("you"),[N,w]=(0,u.useState)(eC(n)),[V,B]=(0,u.useState)([]),[J,G]=(0,u.useState)(l),[$,X]=(0,u.useState)(!1),[Q,el]=(0,u.useState)(null),[et,ea]=(0,u.useState)({}),[er,en]=(0,u.useState)([]),[ei,eo]=(0,u.useState)(!1),ed=()=>{c(!1),o.resetFields()},ec=()=>{c(!1),x(null),G(null),o.resetFields()};(0,u.useEffect)(()=>{s&&a&&r&&eT(s,a,r,f)},[r,s,a]),(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.t3)(r)).guardrails.map(e=>e.guardrail_name);B(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[r]),(0,u.useEffect)(()=>{(async()=>{try{if(r){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,b.lg)(r);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[r]);let em=async e=>{try{var l,t,a;let d=null!==(l=null==e?void 0:e.key_alias)&&void 0!==l?l:"",m=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==n?void 0:n.filter(e=>e.team_id===m).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(d))throw Error("Key alias ".concat(d," already exists for team with ID ").concat(m,", please provide another key alias"));if(F.ZP.info("Making API Call"),c(!0),"you"===y&&(e.user_id=s),"service_account"===y){let s={};try{s=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}s.service_account_id=e.key_alias,e.metadata=JSON.stringify(s)}let u=await (0,b.wX)(r,s,e);console.log("key create Response:",u),i(u),x(u.key),g(u.soft_budget),F.ZP.success("API Key Created"),o.resetFields(),localStorage.removeItem("userData"+s)}catch(e){console.log("error in create key:",e),F.ZP.error("Error creating the key: ".concat(e))}};(0,u.useEffect)(()=>{if(s&&a&&r){var e;eI(s,a,r,null!==(e=null==J?void 0:J.team_id)&&void 0!==e?e:null).then(e=>{var s;v(Array.from(new Set([...null!==(s=null==J?void 0:J.models)&&void 0!==s?s:[],...e])))})}o.setFieldValue("models",[])},[J,r,s,a]);let eu=async e=>{if(!e){en([]);return}eo(!0);try{let s=new URLSearchParams;if(s.append("user_email",e),null==r)return;let l=(await (0,b.u5)(r,s)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));en(l)}catch(e){console.error("Error fetching users:",e),F.ZP.error("Failed to search for users")}finally{eo(!1)}},eh=(0,u.useCallback)(eb()(e=>eu(e),300),[r]),ex=(e,s)=>{let l=s.user;o.setFieldsValue({user_id:l.user_id})};return(0,m.jsxs)("div",{children:[a&&eZ.LQ.includes(a)&&(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Create New Key"}),(0,m.jsx)(R.Z,{visible:d,width:1e3,footer:null,onOk:ed,onCancel:ec,children:(0,m.jsxs)(M.Z,{form:o,onFinish:em,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Ownership"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Owned By"," ",(0,m.jsx)(Y.Z,{title:"Select who will own this API key",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,m.jsxs)(q.ZP.Group,{onChange:e=>Z(e.target.value),value:y,children:[(0,m.jsx)(q.ZP,{value:"you",children:"You"}),(0,m.jsx)(q.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,m.jsx)(q.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===y&&(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["User ID"," ",(0,m.jsx)(Y.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===y,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{eh(e)},onSelect:(e,s)=>ex(e,s),options:er,loading:ei,allowClear:!0,style:{width:"100%"},notFoundContent:ei?"Searching...":"No users found"}),(0,m.jsx)(U.ZP,{onClick:()=>X(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,m.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Team"," ",(0,m.jsx)(Y.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:l?l.team_id:null,className:"mt-4",children:(0,m.jsx)(es,{teams:t,onChange:e=>{G((null==t?void 0:t.find(s=>s.team_id===e))||null)}})})]}),(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Details"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["you"===y||"another_user"===y?"Key Name":"Service Account ID"," ",(0,m.jsx)(Y.Z,{title:"you"===y||"another_user"===y?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===y?"key name":"service account ID")}],help:"required",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&o.setFieldsValue({models:["all-team-models"]})},children:[(0,m.jsx)(eS,{value:"all-team-models",children:"All Team Models"},"all-team-models"),_.map(e=>(0,m.jsx)(eS,{value:e,children:H(e)},e))]})})]}),(0,m.jsx)("div",{className:"mb-8",children:(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{className:"m-0",children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Max Budget (USD)"," ",(0,m.jsx)(Y.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==l?void 0:l.max_budget)!==null&&(null==l?void 0:l.max_budget)!==void 0?null==l?void 0:l.max_budget:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.max_budget&&s>l.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(l.max_budget))}}],children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Reset Budget"," ",(0,m.jsx)(Y.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==l?void 0:l.budget_duration)!==null&&(null==l?void 0:l.budget_duration)!==void 0?null==l?void 0:l.budget_duration:"None"),children:(0,m.jsx)(ek,{onChange:e=>o.setFieldValue("budget_duration",e)})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==l?void 0:l.tpm_limit)!==null&&(null==l?void 0:l.tpm_limit)!==void 0?null==l?void 0:l.tpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.tpm_limit&&s>l.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(l.tpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==l?void 0:l.rpm_limit)!==null&&(null==l?void 0:l.rpm_limit)!==void 0?null==l?void 0:l.rpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.rpm_limit&&s>l.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(l.rpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Expire Key"," ",(0,m.jsx)(Y.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,m.jsx)(I.Z,{placeholder:"e.g., 30d"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:V.map(e=>({value:e,label:e}))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Tags"," ",(0,m.jsx)(Y.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:N})}),(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("b",{children:"Advanced Settings"}),(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,m.jsx)("a",{href:b.H2?"".concat(b.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,m.jsx)(W.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(ee,{schemaComponent:"GenerateKeyRequest",form:o,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Key"})})]})}),$&&(0,m.jsx)(R.Z,{title:"Create New User",visible:$,onCancel:()=>X(!1),footer:null,width:800,children:(0,m.jsx)(ev,{userID:s,accessToken:r,teams:t,possibleUIRoles:et,onUserCreated:e=>{el(e),o.setFieldsValue({user_id:e}),X(!1)},isEmbedded:!0})}),h&&(0,m.jsx)(R.Z,{visible:d,onOk:ed,onCancel:ec,footer:null,children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Save your Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:null!=h?(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:h})}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>{F.ZP.success("API Key copied to clipboard")},children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,m.jsx)(P.Z,{children:"Key being created, this might take 30s"})})]})})]})},eE=l(7366),eP=e=>{let{selectedTeam:s,currentOrg:l,selectedKeyAlias:t,accessToken:a,createClicked:r}=e,[n,i]=(0,u.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,u.useState)(!0),[c,m]=(0,u.useState)(null),h=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!a){console.log("accessToken",a);return}d(!0);let s="number"==typeof e.page?e.page:1,l="number"==typeof e.pageSize?e.pageSize:100,t=await (0,b.OD)(a,null,null,null,null,null,s,l);console.log("data",t),i(t),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,u.useEffect)(()=>{h(),console.log("selectedTeam",s,"currentOrg",l,"accessToken",a,"selectedKeyAlias",t)},[s,l,a,t,r]),{keys:n.keys,isLoading:o,error:c,pagination:{currentPage:n.current_page,totalPages:n.total_pages,totalCount:n.total_count},refresh:h,setKeys:e=>{i(s=>{let l="function"==typeof e?e(s.keys):e;return{...s,keys:l}})}}},eO=l(27281),eL=l(41649),eD=l(12514),eM=l(12485),eF=l(18135),eR=l(35242),eq=l(29706),eU=l(77991),ez=l(10900),eV=l(23628),eK=l(74998);function eB(e){var s,l;let{keyData:t,onCancel:a,onSubmit:r,teams:n,accessToken:i,userID:o,userRole:d}=e,[c]=M.Z.useForm(),[h,x]=(0,u.useState)([]),p=null==n?void 0:n.find(e=>e.team_id===t.team_id),[g,j]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(o&&d&&i)try{if(null===t.team_id){let e=(await (0,b.So)(i,o,d)).data.map(e=>e.id);j(e)}else if(null==p?void 0:p.team_id){let e=await eI(o,d,i,p.team_id);j(Array.from(new Set([...p.models,...e])))}}catch(e){console.error("Error fetching models:",e)}})()},[o,d,i,p,t.team_id]);let f={...t,budget_duration:(l=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[l]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(s=t.metadata)||void 0===s?void 0:s.guardrails)||[]};return(0,m.jsxs)(M.Z,{form:c,onFinish:r,initialValues:f,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[g.length>0&&(0,m.jsx)(D.default.Option,{value:"all-team-models",children:"All Team Models"}),g.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,style:{width:"100%"},placeholder:"Enter a numerical value"})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"daily",children:"Daily"}),(0,m.jsx)(D.default.Option,{value:"weekly",children:"Weekly"}),(0,m.jsx)(D.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsx)(M.Z.Item,{name:"token",hidden:!0,children:(0,m.jsx)(z.default,{})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(C.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]})}function eH(e){let{selectedToken:s,visible:l,onClose:t,accessToken:a}=e,[r]=M.Z.useForm(),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!1);(0,u.useEffect)(()=>{l&&s&&r.setFieldsValue({key_alias:s.key_alias,max_budget:s.max_budget,tpm_limit:s.tpm_limit,rpm_limit:s.rpm_limit,duration:s.duration||""})},[l,s,r]),(0,u.useEffect)(()=>{l||(i(null),p(!1),r.resetFields())},[l,r]),(0,u.useEffect)(()=>{(null==o?void 0:o.duration)?h((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString()}catch(e){return null}})(o.duration)):h(null)},[null==o?void 0:o.duration]);let g=async()=>{if(s&&a){p(!0);try{let e=await r.validateFields(),l=await (0,b.s0)(a,s.token,e);i(l.key),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key"),p(!1)}}},j=()=>{i(null),p(!1),r.resetFields(),t()};return(0,m.jsx)(R.Z,{title:"Regenerate API Key",open:l,onCancel:j,footer:n?[(0,m.jsx)(C.Z,{onClick:j,children:"Close"},"close")]:[(0,m.jsx)(C.Z,{onClick:j,className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:n?(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:(null==s?void 0:s.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:n})}),(0,m.jsx)(L.CopyToClipboard,{text:n,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,m.jsxs)(M.Z,{form:r,layout:"vertical",onValuesChange:e=>{"duration"in e&&d(s=>({...s,duration:e.duration}))},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==s?void 0:s.expires)?new Date(s.expires).toLocaleString():"Never"]}),c&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",c]})]})})}function eJ(e){var s,l;let{keyId:t,onClose:a,keyData:r,accessToken:n,userID:i,userRole:o,teams:d,onKeyDataUpdate:c,onDelete:h}=e,[x,p]=(0,u.useState)(!1),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1);if(!r)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(P.Z,{children:"Key not found"})]});let y=async e=>{try{var s,l;if(!n)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let l=JSON.parse(e.metadata);e.metadata={...l,...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),F.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]);let a=await (0,b.Nc)(n,e);c&&c(a),F.ZP.success("Key updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!n)return;await (0,b.I1)(n,r.token),F.ZP.success("Key deleted successfully"),h&&h(),a()}catch(e){console.error("Error deleting the key:",e),F.ZP.error("Failed to delete key")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(O.Z,{children:r.key_alias||"API Key"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:r.token})]}),o&&eZ.LQ.includes(o)&&(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{icon:eV.Z,variant:"secondary",onClick:()=>v(!0),className:"flex items-center",children:"Regenerate Key"}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>f(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,m.jsx)(eH,{selectedToken:r,visible:_,onClose:()=>v(!1),accessToken:n}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>f(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number(r.spend).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",null!==r.max_budget?"$".concat(r.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Key Settings"}),!x&&o&&eZ.LQ.includes(o)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>p(!0),children:"Edit Settings"})]}),x?(0,m.jsx)(eB,{keyData:r,onCancel:()=>p(!1),onSubmit:y,teams:d,accessToken:n,userID:i,userRole:o}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.token})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key Alias"}),(0,m.jsx)(P.Z,{children:r.key_alias||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Secret Key"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.key_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)(P.Z,{children:r.team_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),(0,m.jsx)(P.Z,{children:r.organization_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:new Date(r.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Expires"}),(0,m.jsx)(P.Z,{children:r.expires?new Date(r.expires).toLocaleString():"Never"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Spend"}),(0,m.jsxs)(P.Z,{children:["$",Number(r.spend).toFixed(4)," USD"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsx)(P.Z,{children:null!==r.max_budget?"$".concat(r.max_budget," USD"):"Unlimited"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",null!==r.max_parallel_requests?r.max_parallel_requests:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model TPM Limits: ",(null===(s=r.metadata)||void 0===s?void 0:s.model_tpm_limit)?JSON.stringify(r.metadata.model_tpm_limit):"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model RPM Limits: ",(null===(l=r.metadata)||void 0===l?void 0:l.model_rpm_limit)?JSON.stringify(r.metadata.model_rpm_limit):"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(r.metadata,null,2)})]})]})]})})]})]})]})}var eG=l(2356),eW=e=>{let{options:s,onApplyFilters:l,onResetFilters:t,initialValues:a={},buttonLabel:r="Filters"}=e,[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(a),[c,h]=(0,u.useState)({}),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)({}),f=(0,u.useCallback)(eb()(async(e,s)=>{if(s.isSearchable&&s.searchFn){p(e=>({...e,[s.name]:!0}));try{let l=await s.searchFn(e);h(e=>({...e,[s.name]:l}))}catch(e){console.error("Error searching:",e),h(e=>({...e,[s.name]:[]}))}finally{p(e=>({...e,[s.name]:!1}))}}},300),[]),_=(e,s)=>{let t={...o,[e]:s};d(t),l(t)};return(0,m.jsxs)("div",{className:"w-full",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eG.Z,{className:"h-4 w-4"}),onClick:()=>i(!n),className:"flex items-center gap-2",children:r}),(0,m.jsx)(U.ZP,{onClick:()=>{let e={};s.forEach(s=>{e[s.name]=""}),d(e),t()},children:"Reset Filters"})]}),n&&(0,m.jsx)("div",{className:"grid grid-cols-3 gap-x-6 gap-y-4 mb-6",children:["Team ID","Status","Organization ID","Key Alias","User ID","Key Hash"].map(e=>{let l=s.find(s=>s.label===e||s.name===e);return l?(0,m.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,m.jsx)("label",{className:"text-sm text-gray-600",children:l.label||l.name}),l.isSearchable?(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),onSearch:e=>{j(s=>({...s,[l.name]:e})),l.searchFn&&f(e,l)},filterOption:!1,loading:x[l.name],options:c[l.name]||[],allowClear:!0}):l.options?(0,m.jsx)(D.default,{className:"w-full",placeholder:"Select ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),allowClear:!0,children:l.options.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))}):(0,m.jsx)(z.default,{className:"w-full",placeholder:"Enter ".concat(l.label||l.name,"..."),value:o[l.name]||"",onChange:e=>_(l.name,e.target.value),allowClear:!0})]},l.name):null})})]})},eY=l(16593);let e$=async e=>{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.OD)(e,null,"",null,null,null,l,100),r=a.keys.map(e=>e.key_alias).filter(Boolean);s=[...s,...r],l{if(!e)return[];try{let l=[],t=1,a=!0;for(;a;){let r=await (0,b.It)(e,s||null,null);l=[...l,...r],t{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.r6)(e);s=[...s,...a],l{let[e,s]=(0,u.useState)("http://localhost:4000");return(0,u.useEffect)(()=>{{let{protocol:e,host:l}=window.location;s("".concat(e,"//").concat(l))}},[]),e};function e1(e,s){let l=structuredClone(e);for(let[e,t]of Object.entries(s))e in l&&(l[e]=t);return l}var e2=l(71594),e4=l(24525),e5=l(21626),e3=l(97214),e6=l(28241),e8=l(58834),e7=l(69552),e9=l(71876),se=l(44633),ss=l(86462),sl=l(49084);function st(e){let{keys:s,setKeys:l,isLoading:t=!1,pagination:a,onPageChange:r,pageSize:n=50,teams:i,selectedTeam:o,setSelectedTeam:d,selectedKeyAlias:c,setSelectedKeyAlias:h,accessToken:x,userID:p,userRole:g,organizations:j,setCurrentOrg:f,refresh:_,onSortChange:v,currentSort:y}=e,[Z,N]=(0,u.useState)(null),[w,k]=(0,u.useState)([]),[S,I]=u.useState(()=>y?[{id:y.sortBy,desc:"desc"===y.sortOrder}]:[{id:"created_at",desc:!0}]),{filters:T,filteredKeys:A,allKeyAliases:E,allTeams:P,allOrganizations:O,handleFilterChange:L,handleFilterReset:D}=function(e){let{keys:s,teams:l,organizations:t,accessToken:a}=e,r={"Team ID":"","Organization ID":"","Key Alias":"","User ID":"","Sort By":"created_at","Sort Order":"desc"},[n,i]=(0,u.useState)(r),[o,d]=(0,u.useState)(l||[]),[c,m]=(0,u.useState)(t||[]),[h,x]=(0,u.useState)(s),p=(0,u.useRef)(0),g=(0,u.useCallback)(eb()(async e=>{if(!a)return;let s=Date.now();p.current=s;try{let l=await (0,b.OD)(a,e["Organization ID"]||null,e["Team ID"]||null,e["Key Alias"]||null,e["User ID"]||null,e["Key Hash"]||null,1,25,e["Sort By"]||null,e["Sort Order"]||null);s===p.current&&l&&(x(l.keys),console.log("called from debouncedSearch filters:",JSON.stringify(e)),console.log("called from debouncedSearch data:",JSON.stringify(l)))}catch(e){console.error("Error searching users:",e)}},300),[a]);(0,u.useEffect)(()=>{if(!s){x([]);return}let e=[...s];n["Team ID"]&&(e=e.filter(e=>e.team_id===n["Team ID"])),n["Organization ID"]&&(e=e.filter(e=>e.organization_id===n["Organization ID"])),x(e)},[s,n]),(0,u.useEffect)(()=>{let e=async()=>{let e=await eX(a);e.length>0&&d(e);let s=await eQ(a);s.length>0&&m(s)};a&&e()},[a]);let j=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!a)throw Error("Access token required");return await e$(a)},enabled:!!a}).data||[];return(0,u.useEffect)(()=>{l&&l.length>0&&d(e=>e.length{t&&t.length>0&&m(e=>e.length{i({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||"","Key Alias":e["Key Alias"]||"","User ID":e["User ID"]||"","Sort By":e["Sort By"]||"created_at","Sort Order":e["Sort Order"]||"desc"}),g({...n,...e})},handleFilterReset:()=>{i(r),g(r)}}}({keys:s,teams:i,organizations:j,accessToken:x});(0,u.useEffect)(()=>{if(x){let e=s.map(e=>e.user_id).filter(e=>null!==e);(async()=>{k((await (0,b.Of)(x,e,1,100)).users)})()}},[x,s]),(0,u.useEffect)(()=>{if(_){let e=()=>{_()};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}},[_]);let M=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return s.getCanExpand()?(0,m.jsx)("button",{onClick:s.getToggleExpandedHandler(),style:{cursor:"pointer"},children:s.getIsExpanded()?"▼":"▶"}):null}},{id:"token",accessorKey:"token",header:"Key ID",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>N(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{id:"key_alias",accessorKey:"key_alias",header:"Key Alias",cell:e=>{let s=e.getValue();return(0,m.jsx)(Y.Z,{title:s,children:s?s.length>20?"".concat(s.slice(0,20),"..."):s:"-"})}},{id:"key_name",accessorKey:"key_name",header:"Secret Key",cell:e=>(0,m.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{id:"team_alias",accessorKey:"team_id",header:"Team Alias",cell:e=>{let{row:s,getValue:l}=e,t=l(),a=null==i?void 0:i.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{id:"team_id",accessorKey:"team_id",header:"Team ID",cell:e=>(0,m.jsx)(Y.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{id:"organization_id",accessorKey:"organization_id",header:"Organization ID",cell:e=>e.getValue()?e.renderValue():"-"},{id:"user_email",accessorKey:"user_id",header:"User Email",cell:e=>{let s=e.getValue(),l=w.find(e=>e.user_id===s);return(null==l?void 0:l.user_email)?l.user_email:"-"}},{id:"user_id",accessorKey:"user_id",header:"User ID",cell:e=>{let s=e.getValue();return s?(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsxs)("span",{children:[s.slice(0,7),"..."]})}):"-"}},{id:"created_at",accessorKey:"created_at",header:"Created At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"-"}},{id:"created_by",accessorKey:"created_by",header:"Created By",cell:e=>e.getValue()||"Unknown"},{id:"expires",accessorKey:"expires",header:"Expires",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"spend",accessorKey:"spend",header:"Spend (USD)",cell:e=>Number(e.getValue()).toFixed(4)},{id:"max_budget",accessorKey:"max_budget",header:"Budget (USD)",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{id:"budget_reset_at",accessorKey:"budget_reset_at",header:"Budget Reset",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleString():"Never"}},{id:"models",accessorKey:"models",header:"Models",cell:e=>{let s=e.getValue();return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:s&&s.length>0?s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):"-"})}},{id:"rate_limits",header:"Rate Limits",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:["TPM: ",null!==l.tpm_limit?l.tpm_limit:"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",null!==l.rpm_limit?l.rpm_limit:"Unlimited"]})]})}}];console.log("keys: ".concat(JSON.stringify(s)));let F=(0,e2.b7)({data:A,columns:M.filter(e=>"expander"!==e.id),state:{sorting:S},onSortingChange:e=>{let s="function"==typeof e?e(S):e;if(console.log("newSorting: ".concat(JSON.stringify(s))),I(s),s&&s.length>0){let e=s[0],l=e.id,t=e.desc?"desc":"asc";console.log("sortBy: ".concat(l,", sortOrder: ").concat(t)),L({...T,"Sort By":l,"Sort Order":t}),null==v||v(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,manualSorting:!1});return u.useEffect(()=>{y&&I([{id:y.sortBy,desc:"desc"===y.sortOrder}])},[y]),(0,m.jsx)("div",{className:"w-full h-full overflow-hidden",children:Z?(0,m.jsx)(eJ,{keyId:Z,onClose:()=>N(null),keyData:A.find(e=>e.token===Z),onKeyDataUpdate:e=>{l(s=>s.map(s=>s.token===e.token?e1(s,e):s))},onDelete:()=>{l(e=>e.filter(e=>e.token!==Z))},accessToken:x,userID:p,userRole:g,teams:P}):(0,m.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,m.jsx)("div",{className:"w-full mb-6",children:(0,m.jsx)(eW,{options:[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>P&&0!==P.length?P.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:async e=>O&&0!==O.length?O.filter(s=>{var l,t;return null!==(t=null===(l=s.organization_id)||void 0===l?void 0:l.toLowerCase().includes(e.toLowerCase()))&&void 0!==t&&t}).filter(e=>null!==e.organization_id&&void 0!==e.organization_id).map(e=>({label:"".concat(e.organization_id||"Unknown"," (").concat(e.organization_id,")"),value:e.organization_id})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>E.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))},{name:"User ID",label:"User ID",isSearchable:!1},{name:"Key Hash",label:"Key Hash",isSearchable:!1}],onApplyFilters:L,initialValues:T,onResetFilters:D})}),(0,m.jsxs)("div",{className:"flex items-center justify-between w-full mb-4",children:[(0,m.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",t?"...":"".concat((a.currentPage-1)*n+1," - ").concat(Math.min(a.currentPage*n,a.totalCount))," of ",t?"...":a.totalCount," results"]}),(0,m.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",t?"...":a.currentPage," of ",t?"...":a.totalPages]}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage-1),disabled:t||1===a.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage+1),disabled:t||a.currentPage===a.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]}),(0,m.jsx)("div",{className:"h-[75vh] overflow-auto",children:(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:F.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading keys..."})})})}):A.length>0?F.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No keys found"})})})})})]})})})})]})})}console.log=function(){};var sa=e=>{let{userID:s,userRole:l,accessToken:t,selectedTeam:a,setSelectedTeam:r,data:n,setData:i,teams:o,premiumUser:d,currentOrg:c,organizations:h,setCurrentOrg:x,selectedKeyAlias:p,setSelectedKeyAlias:g,createClicked:j}=e,[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(null),[w,T]=(0,u.useState)(null),[A,E]=(0,u.useState)(null),[D,q]=(0,u.useState)((null==a?void 0:a.team_id)||"");(0,u.useEffect)(()=>{q((null==a?void 0:a.team_id)||"")},[a]);let{keys:U,isLoading:z,error:V,pagination:K,refresh:H,setKeys:J}=eP({selectedTeam:a,currentOrg:c,selectedKeyAlias:p,accessToken:t,createClicked:j}),[W,Y]=(0,u.useState)(!1),[$,X]=(0,u.useState)(!1),[Q,ee]=(0,u.useState)(null),[es,el]=(0,u.useState)([]),et=new Set,[ea,er]=(0,u.useState)(!1),[en,ei]=(0,u.useState)(!1),[eo,ed]=(0,u.useState)(null),[ec,em]=(0,u.useState)(null),[eu]=M.Z.useForm(),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)(et),[ej,ef]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",Q),(null==ec?void 0:ec.duration)?ex((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(ec.duration)):ex(null),console.log("calculateNewExpiryTime:",eh)},[Q,null==ec?void 0:ec.duration]),(0,u.useEffect)(()=>{(async()=>{try{if(null===s||null===l||null===t)return;let e=await B(s,l,t);e&&el(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,s,l]),(0,u.useEffect)(()=>{if(o){let e=new Set;o.forEach((s,l)=>{let t=s.team_id;e.add(t)}),eg(e)}},[o]);let e_=async()=>{if(null!=Z&&null!=n){try{await (0,b.I1)(t,Z);let e=n.filter(e=>e.token!==Z);i(e)}catch(e){console.error("Error deleting the key:",e)}y(!1),N(null)}},ev=(e,s)=>{em(l=>({...l,[e]:s}))},ey=async()=>{if(!d){F.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=Q)try{let e=await eu.validateFields(),s=await (0,b.s0)(t,Q.token,e);if(ed(s.key),n){let l=n.map(l=>l.token===(null==Q?void 0:Q.token)?{...l,key_name:s.key_name,...e}:l);i(l)}ei(!1),eu.resetFields(),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key")}};return(0,m.jsxs)("div",{children:[(0,m.jsx)(st,{keys:U,setKeys:J,isLoading:z,pagination:K,onPageChange:e=>{H({page:e})},pageSize:100,teams:o,selectedTeam:a,setSelectedTeam:r,accessToken:t,userID:s,userRole:l,organizations:h,setCurrentOrg:x,refresh:H,selectedKeyAlias:p,setSelectedKeyAlias:g}),v&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{y(!1),N(null)},children:"Cancel"})]})]})]})}),(0,m.jsx)(R.Z,{title:"Regenerate API Key",visible:en,onCancel:()=>{ei(!1),eu.resetFields()},footer:[(0,m.jsx)(C.Z,{onClick:()=>{ei(!1),eu.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:ey,disabled:!d,children:d?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:d?(0,m.jsxs)(M.Z,{form:eu,layout:"vertical",onValuesChange:(e,s)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==Q?void 0:Q.expires)!=null?new Date(Q.expires).toLocaleString():"Never"]}),eh&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",eh]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),eo&&(0,m.jsx)(R.Z,{visible:!!eo,onCancel:()=>ed(null),footer:[(0,m.jsx)(C.Z,{onClick:()=>ed(null),children:"Close"},"close")],children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==Q?void 0:Q.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:eo})}),(0,m.jsx)(L.CopyToClipboard,{text:eo,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},sr=l(12011);console.log=function(){},console.log("isLocal:",!1);var sn=e=>{let{userID:s,userRole:l,teams:t,keys:a,setUserRole:r,userEmail:n,setUserEmail:i,setTeams:o,setKeys:d,premiumUser:c,organizations:p,addKey:g,createClicked:j}=e,[f,_]=(0,u.useState)(null),[v,Z]=(0,u.useState)(null),N=(0,h.useSearchParams)(),C=function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token"),I=N.get("invitation_id"),[T,A]=(0,u.useState)(null),[E,P]=(0,u.useState)(null),[O,L]=(0,u.useState)([]),[D,M]=(0,u.useState)(null),[F,R]=(0,u.useState)(null),[q,U]=(0,u.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,u.useEffect)(()=>{if(C){let e=(0,x.o)(C);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),A(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),r(s)}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e))}}if(s&&T&&l&&!a&&!f){let e=sessionStorage.getItem("userModels"+s);e?L(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(v))),(async()=>{try{let e=await (0,b.g)(T);M(e);let t=await (0,b.Br)(T,s,l,!1,null,null);_(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(f))),(null==t?void 0:t.teams[0].keys)?d(t.keys.concat(t.teams.filter(e=>"Admin"===l||e.user_id===s).flatMap(e=>e.keys))):d(t.keys),sessionStorage.setItem("userData"+s,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+s,JSON.stringify(t.user_info));let a=(await (0,b.So)(T,s,l)).data.map(e=>e.id);console.log("available_model_names:",a),L(a),console.log("userModels:",O),sessionStorage.setItem("userModels"+s,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e),e.message.includes("Invalid proxy server token passed")&&z()}})(),w(T,s,l,v,o))}},[s,C,T,a,l]),(0,u.useEffect)(()=>{T&&(async()=>{try{let e=await (0,b.e2)(T,[T]);console.log("keyInfo: ",e)}catch(e){e.message.includes("Invalid proxy server token passed")&&z()}})()},[T]),(0,u.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(v),", accessToken: ").concat(T,", userID: ").concat(s,", userRole: ").concat(l)),T&&(console.log("fetching teams"),w(T,s,l,v,o))},[v]),(0,u.useEffect)(()=>{if(null!==a&&null!=F&&null!==F.team_id){let e=0;for(let s of(console.log("keys: ".concat(JSON.stringify(a))),a))F.hasOwnProperty("team_id")&&null!==s.team_id&&s.team_id===F.team_id&&(e+=s.spend);console.log("sum: ".concat(e)),P(e)}else if(null!==a){let e=0;for(let s of a)e+=s.spend;P(e)}},[F]),null!=I)return(0,m.jsx)(sr.default,{});function z(){(0,y.b)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return console.log("All cookies before redirect:",document.cookie),z(),null;try{let e=(0,x.o)(C);console.log("Decoded token:",e);let s=e.exp,l=Math.floor(Date.now()/1e3);if(s&&l>=s){console.log("Token expired, redirecting to login"),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL for expired token:",e),window.location.href=e,null}}catch(s){console.error("Error decoding token:",s),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL after token decode error:",e),window.location.href=e,null}if(null==T)return null;if(null==s)return(0,m.jsx)("h1",{children:"User ID is not set"});if(null==l&&r("App Owner"),l&&"Admin Viewer"==l){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",F),console.log("All cookies after redirect:",document.cookie),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(k.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,m.jsx)(eA,{userID:s,team:F,teams:t,userRole:l,accessToken:T,data:a,addKey:g},F?F.team_id:null),(0,m.jsx)(sa,{userID:s,userRole:l,accessToken:T,selectedTeam:F||null,setSelectedTeam:R,selectedKeyAlias:q,setSelectedKeyAlias:U,data:a,setData:d,premiumUser:c,teams:t,currentOrg:v,setCurrentOrg:Z,organizations:p,createClicked:j})]})})})},si=l(97765);(t=i||(i={})).OpenAI="OpenAI",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.OpenAI_Text="OpenAI Text Completion",t.OpenAI_Text_Compatible="OpenAI-Compatible Text Completion Models (Together AI, etc.)",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI",t.Cerebras="Cerebras",t.Sambanova="Sambanova",t.Perplexity="Perplexity",t.TogetherAI="TogetherAI",t.Openrouter="Openrouter",t.FireworksAI="Fireworks AI",t.Triton="Triton";let so={OpenAI:"openai",OpenAI_Text:"text-completion-openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",OpenAI_Text_Compatible:"text-completion-openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai",Cerebras:"cerebras",Sambanova:"sambanova",Perplexity:"perplexity",TogetherAI:"together_ai",Openrouter:"openrouter",FireworksAI:"fireworks_ai",Triton:"triton"},sd="/ui/assets/logos/",sc={Anthropic:"".concat(sd,"anthropic.svg"),AssemblyAI:"".concat(sd,"assemblyai_small.png"),Azure:"".concat(sd,"microsoft_azure.svg"),"Azure AI Foundry (Studio)":"".concat(sd,"microsoft_azure.svg"),"Amazon Bedrock":"".concat(sd,"bedrock.svg"),Cerebras:"".concat(sd,"cerebras.svg"),Cohere:"".concat(sd,"cohere.svg"),Databricks:"".concat(sd,"databricks.svg"),Deepseek:"".concat(sd,"deepseek.svg"),"Fireworks AI":"".concat(sd,"fireworks.svg"),Groq:"".concat(sd,"groq.svg"),"Google AI Studio":"".concat(sd,"google.svg"),"Mistral AI":"".concat(sd,"mistral.svg"),Ollama:"".concat(sd,"ollama.svg"),OpenAI:"".concat(sd,"openai_small.svg"),"OpenAI Text Completion":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Text Completion Models (Together AI, etc.)":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Endpoints (Together AI, etc.)":"".concat(sd,"openai_small.svg"),Openrouter:"".concat(sd,"openrouter.svg"),Perplexity:"".concat(sd,"perplexity-ai.svg"),Sambanova:"".concat(sd,"sambanova.svg"),TogetherAI:"".concat(sd,"togetherai.svg"),"Vertex AI (Anthropic, Gemini, etc.)":"".concat(sd,"google.svg"),xAI:"".concat(sd,"xai.svg"),Triton:"".concat(sd,"nvidia_triton.png")},sm=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:sc[e],displayName:e}}let s=Object.keys(so).find(s=>so[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=i[s];return{logo:sc[l],displayName:l}},su=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",sh=(e,s)=>{console.log("Provider key: ".concat(e));let l=so[e];console.log("Provider mapped to: ".concat(l));let t=[];return e&&"object"==typeof s&&(Object.entries(s).forEach(e=>{let[s,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===l||a.litellm_provider.includes(l))&&t.push(s)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(s).forEach(e=>{let[s,l]=e;null!==l&&"object"==typeof l&&"litellm_provider"in l&&"cohere"===l.litellm_provider&&t.push(s)}))),t},sx=async(e,s,l)=>{try{console.log("handling submit for formValues:",e);let s=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=so[e.custom_llm_provider]+"/*";e.model_name=l,s.push({public_name:l,litellm_model:l}),e.model=l}let l=[];for(let t of s){let s={},a={},r=t.public_name;for(let[l,r]of(s.model=t.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),s.model=t.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l&&"cache_control"!==l){if("model_name"==l)s.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=so[r];s.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("mode"==l)console.log("placing mode in modelInfo"),a.mode=r,delete s.mode;else if("custom_model_name"===l)s.model=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[s,l]of Object.entries(e))a[s]=l}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(s[l]=Number(r));continue}else s[l]=r}l.push({litellmParamsObj:s,modelInfoObj:a,modelName:r})}return l}catch(e){F.ZP.error("Failed to create model: "+e,10)}},sp=async(e,s,l,t)=>{try{let a=await sx(e,s,l);if(!a||0===a.length)return;for(let e of a){let{litellmParamsObj:l,modelInfoObj:t,modelName:a}=e,r={model_name:a,litellm_params:l,model_info:t},n=await (0,b.kK)(s,r);console.log("response for model create call: ".concat(n.data))}t&&t(),l.resetFields()}catch(e){F.ZP.error("Failed to add model: "+e,10)}};var sg=l(53410),sj=l(47451),sf=l(69410);let{Link:s_}=et.default,sv={[i.OpenAI]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.OpenAI_Text]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.Vertex_AI]:[{key:"vertex_project",label:"Vertex Project",placeholder:"adroit-cadet-1234..",required:!0},{key:"vertex_location",label:"Vertex Location",placeholder:"us-east-1",required:!0},{key:"vertex_credentials",label:"Vertex Credentials",required:!0,type:"upload"}],[i.AssemblyAI]:[{key:"api_base",label:"API Base",type:"select",required:!0,options:["https://api.assemblyai.com","https://api.eu.assemblyai.com"]},{key:"api_key",label:"AssemblyAI API Key",type:"password",required:!0}],[i.Azure]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_version",label:"API Version",placeholder:"2023-07-01-preview",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here"},{key:"base_model",label:"Base Model",placeholder:"azure/gpt-3.5-turbo"},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[i.Azure_AI_Studio]:[{key:"api_base",label:"API Base",placeholder:"https://.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",tooltip:"Enter your full Target URI from Azure Foundry here. Example: https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",required:!0},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[i.OpenAI_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.OpenAI_Text_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.Bedrock]:[{key:"aws_access_key_id",label:"AWS Access Key ID",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[i.Ollama]:[{key:"api_base",label:"API Base",placeholder:"http://localhost:11434",defaultValue:"http://localhost:11434",required:!1,tooltip:"The base URL for your Ollama server. Defaults to http://localhost:11434 if not specified."}],[i.Anthropic]:[{key:"api_key",label:"API Key",placeholder:"sk-",type:"password",required:!0}],[i.Google_AI_Studio]:[{key:"api_key",label:"API Key",placeholder:"aig-",type:"password",required:!0}],[i.Groq]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.MistralAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Deepseek]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Cohere]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Databricks]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.xAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Cerebras]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Sambanova]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Perplexity]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.TogetherAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Openrouter]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.FireworksAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Triton]:[{key:"api_key",label:"API Key",type:"password",required:!1},{key:"api_base",label:"API Base",placeholder:"http://localhost:8000/generate",required:!1}]};var sy=e=>{let{selectedProvider:s,uploadProps:l}=e,t=i[s],a=M.Z.useFormInstance(),r=u.useMemo(()=>sv[t]||[],[t]),n={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Setting field value from JSON, length: ".concat(s.length)),a.setFieldsValue({vertex_credentials:s}),console.log("Form values after setting:",a.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered in ProviderSpecificFields"),console.log("Current form values:",a.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList)}};return(0,m.jsx)(m.Fragment,{children:r.map(e=>{var s;return(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:e.label,name:e.key,rules:e.required?[{required:!0,message:"Required"}]:void 0,tooltip:e.tooltip,className:"vertex_credentials"===e.key?"mb-0":void 0,children:"select"===e.type?(0,m.jsx)(D.default,{placeholder:e.placeholder,defaultValue:e.defaultValue,children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"upload"===e.type?(0,m.jsx)(er.Z,{...n,onChange:s=>{(null==l?void 0:l.onChange)&&l.onChange(s),setTimeout(()=>{let s=a.getFieldValue(e.key);console.log("".concat(e.key," value after upload:"),JSON.stringify(s))},500)},children:(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eu.Z,{}),children:"Click to Upload"})}):(0,m.jsx)(I.Z,{placeholder:e.placeholder,type:"password"===e.type?"password":"text"})}),"vertex_credentials"===e.key&&(0,m.jsx)(sj.Z,{children:(0,m.jsx)(sf.Z,{children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Give a gcp service account(.json file)"})})}),"base_model"===e.key&&(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,m.jsx)(s_,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]},e.key)})})};let{Title:sb,Link:sZ}=et.default;var sN=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,onUpdateCredential:a,uploadProps:r,addOrEdit:n,existingCredential:o}=e,[d]=M.Z.useForm(),[c,h]=(0,u.useState)(i.OpenAI),[x,p]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{o&&(d.setFieldsValue({credential_name:o.credential_name,custom_llm_provider:o.credential_info.custom_llm_provider,api_base:o.credential_values.api_base,api_version:o.credential_values.api_version,base_model:o.credential_values.base_model,api_key:o.credential_values.api_key}),h(o.credential_info.custom_llm_provider))},[o]),(0,m.jsx)(R.Z,{title:"add"===n?"Add New Credential":"Edit Credential",visible:s,onCancel:()=>{l(),d.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:d,onFinish:e=>{"add"===n?t(e):a(e),d.resetFields()},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==o?void 0:o.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials",disabled:null!=o&&!!o.credential_name})}),(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"Helper to auto-populate provider specific fields",children:(0,m.jsx)(D.default,{onChange:e=>{h(e),d.setFieldValue("custom_llm_provider",e)},children:Object.entries(i).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(sy,{selectedProvider:c,uploadProps:r}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sZ,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),d.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"add"===n?"Add Credential":"Update Credential"})]})]})]})})},sw=e=>{let{accessToken:s,uploadProps:l,credentialList:t,fetchCredentials:a}=e,[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(null),[h]=M.Z.useForm(),x=["credential_name","custom_llm_provider"],p=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.eZ)(s,e.credential_name,t),F.ZP.success("Credential updated successfully"),o(!1),a(s)},g=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.oC)(s,t),F.ZP.success("Credential added successfully"),n(!1),a(s)};(0,u.useEffect)(()=>{s&&a(s)},[s]);let j=e=>{let s={openai:"blue",azure:"indigo",anthropic:"purple",default:"gray"},l=s[e.toLowerCase()]||s.default;return(0,m.jsx)(eL.Z,{color:l,size:"xs",children:e})},f=async e=>{s&&(await (0,b.gX)(s,e),F.ZP.success("Credential deleted successfully"),a(s))};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)(P.Z,{children:["Configured credentials for different AI providers. Add and manage your API credentials."," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/credentials",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]})}),(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Credential Name"}),(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Description"})]})}),(0,m.jsx)(e3.Z,{children:t&&0!==t.length?t.map((e,s)=>{var l,t;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.credential_name}),(0,m.jsx)(e6.Z,{children:j((null===(l=e.credential_info)||void 0===l?void 0:l.custom_llm_provider)||"-")}),(0,m.jsx)(e6.Z,{children:(null===(t=e.credential_info)||void 0===t?void 0:t.description)||"-"}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{icon:sg.Z,variant:"light",size:"sm",onClick:()=>{c(e),o(!0)}}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"light",size:"sm",onClick:()=>f(e.credential_name)})]})]},s)}):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:4,className:"text-center py-4 text-gray-500",children:"No credentials configured"})})})]})}),(0,m.jsx)(C.Z,{onClick:()=>n(!0),className:"mt-4",children:"Add Credential"}),r&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:r,onCancel:()=>n(!1),uploadProps:l,addOrEdit:"add",onUpdateCredential:p,existingCredential:null}),i&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:i,existingCredential:d,onUpdateCredential:p,uploadProps:l,onCancel:()=>o(!1),addOrEdit:"edit"})]})};let sk=e=>{var s;return(null==e?void 0:null===(s=e.model_info)||void 0===s?void 0:s.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"};var sS=l(53003),sC=l(47323),sI=l(75105),sT=l(40278),sA=l(14301),sE=l(59664),sP=e=>{let{modelMetrics:s,modelMetricsCategories:l,customTooltip:t,premiumUser:a}=e;return(0,m.jsx)(sE.Z,{title:"Time to First token (s)",className:"h-72",data:s,index:"date",showLegend:!1,categories:l,colors:["indigo","rose"],connectNulls:!0,customTooltip:t})},sO=e=>{let{teamData:s,canEditTeam:l,handleMemberDelete:t,setSelectedEditMember:a,setIsEditMemberModalVisible:r,setIsAddMemberModalVisible:n}=e;return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"User Email"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:s.team_info.members_with_roles.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_email})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.role})}),(0,m.jsx)(e6.Z,{children:l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{a(e),r(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(e)})]})})]},s))})]})}),(0,m.jsx)(C.Z,{onClick:()=>n(!0),children:"Add Member"})]})},sL=l(61994),sD=l(85180),sM=l(89245),sF=l(78355);let sR={"/key/generate":"Member can generate a virtual key for this team","/key/update":"Member can update a virtual key belonging to this team","/key/delete":"Member can delete a virtual key belonging to this team","/key/info":"Member can get info about a virtual key belonging to this team","/key/regenerate":"Member can regenerate a virtual key belonging to this team","/key/{key_id}/regenerate":"Member can regenerate a virtual key belonging to this team","/key/list":"Member can list virtual keys belonging to this team","/key/block":"Member can block a virtual key belonging to this team","/key/unblock":"Member can unblock a virtual key belonging to this team"},sq=e=>e.includes("/info")||e.includes("/list")?"GET":"POST",sU=e=>{let s=sq(e),l=sR[e];if(!l){for(let[s,t]of Object.entries(sR))if(e.includes(s)){l=t;break}}return l||(l="Access ".concat(e)),{method:s,endpoint:e,description:l,route:e}};var sz=e=>{let{teamId:s,accessToken:l,canEditTeam:t}=e,[a,r]=(0,u.useState)([]),[n,i]=(0,u.useState)([]),[o,d]=(0,u.useState)(!0),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),g=async()=>{try{if(d(!0),!l)return;let e=await (0,b.aC)(l,s),t=e.all_available_permissions||[];r(t);let a=e.team_member_permissions||[];i(a),p(!1)}catch(e){F.ZP.error("Failed to load permissions"),console.error("Error fetching permissions:",e)}finally{d(!1)}};(0,u.useEffect)(()=>{g()},[s,l]);let j=(e,s)=>{i(s?[...n,e]:n.filter(s=>s!==e)),p(!0)},f=async()=>{try{if(!l)return;h(!0),await (0,b.TF)(l,s,n),F.ZP.success("Permissions updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update permissions"),console.error("Error updating permissions:",e)}finally{h(!1)}};if(o)return(0,m.jsx)("div",{className:"p-6 text-center",children:"Loading permissions..."});let _=a.length>0;return(0,m.jsxs)(eD.Z,{className:"bg-white shadow-md rounded-md p-6",children:[(0,m.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center border-b pb-4 mb-6",children:[(0,m.jsx)(O.Z,{className:"mb-2 sm:mb-0",children:"Member Permissions"}),t&&x&&(0,m.jsxs)("div",{className:"flex gap-3",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(sM.Z,{}),onClick:()=>{g()},children:"Reset"}),(0,m.jsxs)(C.Z,{onClick:f,loading:c,className:"flex items-center gap-2",children:[(0,m.jsx)(sF.Z,{})," Save Changes"]})]})]}),(0,m.jsx)(P.Z,{className:"mb-6 text-gray-600",children:"Control what team members can do when they are not team admins."}),_?(0,m.jsxs)(e5.Z,{className:"mt-4",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Method"}),(0,m.jsx)(e7.Z,{children:"Endpoint"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Access"})]})}),(0,m.jsx)(e3.Z,{children:a.map(e=>{let s=sU(e);return(0,m.jsxs)(e9.Z,{className:"hover:bg-gray-50 transition-colors",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat("GET"===s.method?"bg-blue-100 text-blue-800":"bg-green-100 text-green-800"),children:s.method})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"font-mono text-sm text-gray-800",children:s.endpoint})}),(0,m.jsx)(e6.Z,{className:"text-gray-700",children:s.description}),(0,m.jsx)(e6.Z,{className:"text-right",children:(0,m.jsx)(sL.Z,{checked:n.includes(e),onChange:s=>j(e,s.target.checked),disabled:!t})})]},e)})})]}):(0,m.jsx)("div",{className:"py-12",children:(0,m.jsx)(sD.Z,{description:"No permissions available"})})]})},sV=e=>{var s,l,t;let{visible:a,onCancel:r,onSubmit:n,initialData:i,mode:o,config:d}=e,[c]=M.Z.useForm();console.log("Initial Data:",i),(0,u.useEffect)(()=>{if(a){if("edit"===o&&i)c.setFieldsValue({...i,role:i.role||d.defaultRole});else{var e;c.resetFields(),c.setFieldsValue({role:d.defaultRole||(null===(e=d.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,i,o,c,d.defaultRole,d.roleOptions]);let h=async e=>{try{let s=Object.entries(e).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:"string"==typeof t?t.trim():t}},{});n(s),c.resetFields(),F.ZP.success("Successfully ".concat("add"===o?"added":"updated"," member"))}catch(e){F.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var s;return(0,m.jsx)(D.default,{children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,m.jsx)(R.Z,{title:d.title||("add"===o?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:r,children:(0,m.jsxs)(M.Z,{form:c,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[d.showEmail&&(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),d.showEmail&&d.showUserId&&(0,m.jsx)("div",{className:"text-center mb-4",children:(0,m.jsx)(P.Z,{children:"OR"})}),d.showUserId&&(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"Role"}),"edit"===o&&i&&(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(l=i.role,(null===(t=d.roleOptions.find(e=>e.value===l))||void 0===t?void 0:t.label)||l),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,m.jsx)(D.default,{children:"edit"===o&&i?[...d.roleOptions.filter(e=>e.value===i.role),...d.roleOptions.filter(e=>e.value!==i.role)].map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value)):d.roleOptions.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))})}),null===(s=d.additionalFields)||void 0===s?void 0:s.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,m.jsxs)("div",{className:"text-right mt-6",children:[(0,m.jsx)(U.ZP,{onClick:r,className:"mr-2",children:"Cancel"}),(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"add"===o?"Add Member":"Save Changes"})]})]})})},sK=e=>{let{isVisible:s,onCancel:l,onSubmit:t,accessToken:a,title:r="Add Team Member",roles:n=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:i="user"}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p,g]=(0,u.useState)("user_email"),j=async(e,s)=>{if(!e){c([]);return}x(!0);try{let l=new URLSearchParams;if(l.append(s,e),null==a)return;let t=(await (0,b.u5)(a,l)).map(e=>({label:"user_email"===s?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===s?e.user_email:e.user_id,user:e}));c(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},f=(0,u.useCallback)(eb()((e,s)=>j(e,s),300),[]),_=(e,s)=>{g(s),f(e,s)},v=(e,s)=>{let l=s.user;o.setFieldsValue({user_email:l.user_email,user_id:l.user_id,role:o.getFieldValue("role")})};return(0,m.jsx)(R.Z,{title:r,open:s,onCancel:()=>{o.resetFields(),c([]),l()},footer:null,width:800,children:(0,m.jsxs)(M.Z,{form:o,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:i},children:[(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>_(e,"user_email"),onSelect:(e,s)=>v(e,s),options:"user_email"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>_(e,"user_id"),onSelect:(e,s)=>v(e,s),options:"user_id"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:i,children:n.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:(0,m.jsxs)(Y.Z,{title:e.description,children:[(0,m.jsx)("span",{className:"font-medium",children:e.label}),(0,m.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,m.jsx)("div",{className:"text-right mt-4",children:(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},sB=e=>{var s;let{teamId:l,onClose:t,accessToken:a,is_team_admin:r,is_proxy_admin:n,userModels:i,editTeam:o}=e,[d,c]=(0,u.useState)(null),[h,x]=(0,u.useState)(!0),[p,g]=(0,u.useState)(!1),[j]=M.Z.useForm(),[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),[Z,N]=(0,u.useState)(!1);console.log("userModels in team info",i);let w=r||n,k=async()=>{try{if(x(!0),!a)return;let e=await (0,b.Xm)(a,l);c(e)}catch(e){F.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,u.useEffect)(()=>{k()},[l,a]);let I=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.cu)(a,l,s),F.ZP.success("Team member added successfully"),g(!1),j.resetFields(),k()}catch(e){F.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},T=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.sN)(a,l,s),F.ZP.success("Team member updated successfully"),_(!1),k()}catch(e){F.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},A=async e=>{try{if(null==a)return;await (0,b.Lp)(a,l,e),F.ZP.success("Team member removed successfully"),k()}catch(e){F.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},E=async e=>{try{if(!a)return;let s={};try{s=e.metadata?JSON.parse(e.metadata):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}let t={team_id:l,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...s,guardrails:e.guardrails||[]},organization_id:e.organization_id};await (0,b.Gh)(a,t),F.ZP.success("Team settings updated successfully"),N(!1),k()}catch(e){console.error("Error updating team:",e)}};if(h)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==d?void 0:d.team_info))return(0,m.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:L}=d;return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:L.team_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:L.team_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:o?3:0,children:[(0,m.jsx)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),...w?[(0,m.jsx)(eM.Z,{children:"Members"},"members"),(0,m.jsx)(eM.Z,{children:"Member Permissions"},"member-permissions"),(0,m.jsx)(eM.Z,{children:"Settings"},"settings")]:[]]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",L.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===L.max_budget?"Unlimited":"$".concat(L.max_budget)]}),L.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",L.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",L.rpm_limit||"Unlimited"]}),L.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",L.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sO,{teamData:d,canEditTeam:w,handleMemberDelete:A,setSelectedEditMember:y,setIsEditMemberModalVisible:_,setIsAddMemberModalVisible:g})}),w&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sz,{teamId:l,accessToken:a,canEditTeam:w})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Team Settings"}),w&&!Z&&(0,m.jsx)(C.Z,{onClick:()=>N(!0),children:"Edit Settings"})]}),Z?(0,m.jsxs)(M.Z,{form:j,onFinish:E,initialValues:{...L,team_alias:L.team_alias,models:L.models,tpm_limit:L.tpm_limit,rpm_limit:L.rpm_limit,max_budget:L.max_budget,budget_duration:L.budget_duration,guardrails:(null===(s=L.metadata)||void 0===s?void 0:s.guardrails)||[],metadata:L.metadata?JSON.stringify(L.metadata,null,2):"",organization_id:L.organization_id},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),i.map((e,s)=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},s))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>N(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team Name"}),(0,m.jsx)("div",{children:L.team_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"font-mono",children:L.team_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(L.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",L.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==L.max_budget?"$".concat(L.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",L.budget_duration||"Never"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{children:L.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Status"}),(0,m.jsx)(eL.Z,{color:L.blocked?"red":"green",children:L.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,m.jsx)(sV,{visible:f,onCancel:()=>_(!1),onSubmit:T,initialData:v,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,m.jsx)(sK,{isVisible:p,onCancel:()=>g(!1),onSubmit:I,accessToken:a})]})},sH=l(45589);let{Title:sJ,Link:sG}=et.default;var sW=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,existingCredential:a,setIsCredentialModalOpen:r}=e,[n]=M.Z.useForm();return console.log("existingCredential in add credentials tab: ".concat(JSON.stringify(a))),(0,m.jsx)(R.Z,{title:"Reuse Credentials",visible:s,onCancel:()=>{l(),n.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:n,onFinish:e=>{t(e),n.resetFields(),r(!1)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==a?void 0:a.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials"})}),Object.entries((null==a?void 0:a.credential_values)||{}).map(e=>{let[s,l]=e;return(0,m.jsx)(M.Z.Item,{label:s,name:s,initialValue:l,children:(0,m.jsx)(I.Z,{placeholder:"Enter ".concat(s),disabled:!0})},s)}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sG,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),n.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Reuse Credentials"})]})]})]})})},sY=l(63709),s$=l(45246),sX=l(96473);let{Text:sQ}=et.default;var s0=e=>{let{form:s,showCacheControl:l,onCacheControlChange:t}=e,a=e=>{let l=s.getFieldValue("litellm_extra_params");try{let t=l?JSON.parse(l):{};e.length>0?t.cache_control_injection_points=e:delete t.cache_control_injection_points,Object.keys(t).length>0?s.setFieldValue("litellm_extra_params",JSON.stringify(t,null,2)):s.setFieldValue("litellm_extra_params","")}catch(e){console.error("Error updating cache control points:",e)}};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Cache Control Injection Points",name:"cache_control",valuePropName:"checked",className:"mb-4",tooltip:"Tell litellm where to inject cache control checkpoints. You can specify either by role (to apply to all messages of that role) or by specific message index.",children:(0,m.jsx)(sY.Z,{onChange:t,className:"bg-gray-600"})}),l&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(sQ,{className:"text-sm text-gray-500 block mb-4",children:"Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature."}),(0,m.jsx)(M.Z.List,{name:"cache_control_injection_points",initialValue:[{location:"message"}],children:(e,l)=>{let{add:t,remove:r}=l;return(0,m.jsxs)(m.Fragment,{children:[e.map((l,t)=>(0,m.jsxs)("div",{className:"flex items-center mb-4 gap-4",children:[(0,m.jsx)(M.Z.Item,{...l,label:"Type",name:[l.name,"location"],initialValue:"message",className:"mb-0",style:{width:"180px"},children:(0,m.jsx)(D.default,{disabled:!0,options:[{value:"message",label:"Message"}]})}),(0,m.jsx)(M.Z.Item,{...l,label:"Role",name:[l.name,"role"],className:"mb-0",style:{width:"180px"},tooltip:"LiteLLM will mark all messages of this role as cacheable",children:(0,m.jsx)(D.default,{placeholder:"Select a role",allowClear:!0,options:[{value:"user",label:"User"},{value:"system",label:"System"},{value:"assistant",label:"Assistant"}],onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),(0,m.jsx)(M.Z.Item,{...l,label:"Index",name:[l.name,"index"],className:"mb-0",style:{width:"180px"},tooltip:"(Optional) If set litellm will mark the message at this index as cacheable",children:(0,m.jsx)(K,{type:"number",placeholder:"Optional",step:1,min:0,onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),e.length>1&&(0,m.jsx)(s$.Z,{className:"text-red-500 cursor-pointer text-lg ml-12",onClick:()=>{r(l.name),setTimeout(()=>{a(s.getFieldValue("cache_control_points"))},0)}})]},l.key)),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full border border-dashed border-gray-300 py-2 px-4 text-gray-600 hover:text-blue-600 hover:border-blue-300 transition-all rounded",onClick:()=>t(),children:[(0,m.jsx)(sX.Z,{className:"mr-2"}),"Add Injection Point"]})})]})}})]})]})};function s1(e){var s,l,t,a,r,n,i,o,d,c,h,x,p,g,j,f,_,v,y,Z,N;let{modelId:w,onClose:k,modelData:T,accessToken:A,userID:E,userRole:L,editModel:D,setEditModalVisible:q,setSelectedModel:z,onModelUpdate:V}=e,[B]=M.Z.useForm(),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)(!1),[X,Q]=(0,u.useState)(!1),[ee,es]=(0,u.useState)(!1),[el,et]=(0,u.useState)(!1),[ea,er]=(0,u.useState)(null),[en,ei]=(0,u.useState)(!1),eo="Admin"===L||T.model_info.created_by===E,ed=(null===(s=T.litellm_params)||void 0===s?void 0:s.litellm_credential_name)!=null&&(null===(l=T.litellm_params)||void 0===l?void 0:l.litellm_credential_name)!=void 0;console.log("usingExistingCredential, ",ed),console.log("modelData.litellm_params.litellm_credential_name, ",T.litellm_params.litellm_credential_name),(0,u.useEffect)(()=>{let e=async()=>{var e;if(!A)return;let s=await (0,b.ix)(A,w);console.log("modelInfoResponse, ",s);let l=s.data[0];J(l),(null==l?void 0:null===(e=l.litellm_params)||void 0===e?void 0:e.cache_control_injection_points)&&ei(!0)};(async()=>{if(console.log("accessToken, ",A),!A||ed)return;let e=await (0,b.Qg)(A,null,w);console.log("existingCredentialResponse, ",e),er({credential_name:e.credential_name,credential_values:e.credential_values,credential_info:e.credential_info})})(),e()},[A,w]);let ec=async e=>{var s;if(console.log("values, ",e),!A)return;let l={credential_name:e.credential_name,model_id:w,credential_info:{custom_llm_provider:null===(s=H.litellm_params)||void 0===s?void 0:s.custom_llm_provider}};F.ZP.info("Storing credential.."),console.log("credentialResponse, ",await (0,b.oC)(A,l)),F.ZP.success("Credential stored successfully")},em=async e=>{try{var s;if(!A)return;es(!0),console.log("values.model_name, ",e.model_name);let l={...H.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6};e.cache_control&&(null===(s=e.cache_control_injection_points)||void 0===s?void 0:s.length)>0?l.cache_control_injection_points=e.cache_control_injection_points:delete l.cache_control_injection_points;let t={model_name:e.model_name,litellm_params:l,model_info:{id:w}};await (0,b.$D)(A,t,w);let a={...H,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l};J(a),V&&V(a),F.ZP.success("Model settings updated successfully"),Q(!1),et(!1)}catch(e){console.error("Error updating model:",e),F.ZP.error("Failed to update model settings")}finally{es(!1)}};if(!T)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsx)(P.Z,{children:"Model not found"})]});let eu=async()=>{try{if(!A)return;await (0,b.Og)(A,w),F.ZP.success("Model deleted successfully"),V&&V({deleted:!0,model_info:{id:w}}),k()}catch(e){console.error("Error deleting the model:",e),F.ZP.error("Failed to delete model")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsxs)(O.Z,{children:["Public Model Name: ",sk(T)]}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),(0,m.jsxs)("div",{className:"flex gap-2",children:["Admin"===L&&(0,m.jsx)(C.Z,{icon:sH.Z,variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Re-use Credentials"}),eo&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>W(!0),className:"flex items-center",children:"Delete Model"})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-6",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Raw JSON"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,m.jsx)("img",{src:sm(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,l=s.parentElement;if(l){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",l.replaceChild(e,s)}}}),(0,m.jsx)(O.Z,{children:T.provider||"Not Set"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"LiteLLM Model"}),(0,m.jsx)("pre",{children:(0,m.jsx)(O.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Pricing"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,m.jsxs)(P.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,m.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Model Settings"}),eo&&!el&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>et(!0),className:"flex items-center",children:"Edit Model"})]}),H?(0,m.jsx)(M.Z,{form:B,onFinish:em,initialValues:{model_name:H.model_name,litellm_model_name:H.litellm_model_name,api_base:H.litellm_params.api_base,custom_llm_provider:H.litellm_params.custom_llm_provider,organization:H.litellm_params.organization,tpm:H.litellm_params.tpm,rpm:H.litellm_params.rpm,max_retries:H.litellm_params.max_retries,timeout:H.litellm_params.timeout,stream_timeout:H.litellm_params.stream_timeout,input_cost:H.litellm_params.input_cost_per_token?1e6*H.litellm_params.input_cost_per_token:(null===(t=H.model_info)||void 0===t?void 0:t.input_cost_per_token)*1e6||null,output_cost:(null===(a=H.litellm_params)||void 0===a?void 0:a.output_cost_per_token)?1e6*H.litellm_params.output_cost_per_token:(null===(r=H.model_info)||void 0===r?void 0:r.output_cost_per_token)*1e6||null,cache_control:null!==(n=H.litellm_params)&&void 0!==n&&!!n.cache_control_injection_points,cache_control_injection_points:(null===(i=H.litellm_params)||void 0===i?void 0:i.cache_control_injection_points)||[]},layout:"vertical",onValuesChange:()=>Q(!0),children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"LiteLLM Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter LiteLLM model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.litellm_model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"input_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter input cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(o=H.litellm_params)||void 0===o?void 0:o.input_cost_per_token)?((null===(d=H.litellm_params)||void 0===d?void 0:d.input_cost_per_token)*1e6).toFixed(4):(null==H?void 0:null===(c=H.model_info)||void 0===c?void 0:c.input_cost_per_token)?(1e6*H.model_info.input_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"output_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter output cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(h=H.litellm_params)||void 0===h?void 0:h.output_cost_per_token)?(1e6*H.litellm_params.output_cost_per_token).toFixed(4):(null==H?void 0:null===(x=H.model_info)||void 0===x?void 0:x.output_cost_per_token)?(1e6*H.model_info.output_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Base"}),el?(0,m.jsx)(M.Z.Item,{name:"api_base",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter API base"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=H.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Custom LLM Provider"}),el?(0,m.jsx)(M.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom LLM provider"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=H.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),el?(0,m.jsx)(M.Z.Item,{name:"organization",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter organization"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=H.litellm_params)||void 0===j?void 0:j.organization)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"tpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter TPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=H.litellm_params)||void 0===f?void 0:f.tpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"rpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter RPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=H.litellm_params)||void 0===_?void 0:_.rpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Max Retries"}),el?(0,m.jsx)(M.Z.Item,{name:"max_retries",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter max retries"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(v=H.litellm_params)||void 0===v?void 0:v.max_retries)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(y=H.litellm_params)||void 0===y?void 0:y.timeout)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter stream timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=H.litellm_params)||void 0===Z?void 0:Z.stream_timeout)||"Not Set"})]}),el?(0,m.jsx)(s0,{form:B,showCacheControl:en,onCacheControlChange:e=>ei(e)}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Cache Control"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=H.litellm_params)||void 0===N?void 0:N.cache_control_injection_points)?(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{children:"Enabled"}),(0,m.jsx)("div",{className:"mt-2",children:H.litellm_params.cache_control_injection_points.map((e,s)=>(0,m.jsxs)("div",{className:"text-sm text-gray-600 mb-1",children:["Location: ",e.location,",",e.role&&(0,m.jsxs)("span",{children:[" Role: ",e.role]}),void 0!==e.index&&(0,m.jsxs)("span",{children:[" Index: ",e.index]})]},s))})]}):"Disabled"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),el&&(0,m.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{B.resetFields(),Q(!1),et(!1)},children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",onClick:()=>B.submit(),loading:ee,children:"Save Changes"})]})]})}):(0,m.jsx)(P.Z,{children:"Loading..."})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),G&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Model"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this model?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(U.ZP,{onClick:eu,className:"ml-2",danger:!0,children:"Delete"}),(0,m.jsx)(U.ZP,{onClick:()=>W(!1),children:"Cancel"})]})]})]})}),Y&&!ed?(0,m.jsx)(sW,{isVisible:Y,onCancel:()=>$(!1),onAddCredential:ec,existingCredential:ea,setIsCredentialModalOpen:$}):(0,m.jsx)(R.Z,{open:Y,onCancel:()=>$(!1),title:"Using Existing Credential",children:(0,m.jsx)(P.Z,{children:T.litellm_params.litellm_credential_name})})]})}var s2=l(67960),s4=e=>{let{selectedProvider:s,providerModels:l,getPlaceholder:t}=e,a=M.Z.useFormInstance(),r=e=>{let s=e.target.value,l=(a.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:s,litellm_model:s}:e);a.setFieldsValue({model_mappings:l})};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(M.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,m.jsx)(M.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:s===i.Azure||s===i.OpenAI_Compatible||s===i.Ollama?(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(I.Z,{placeholder:t(s)})}):l.length>0?(0,m.jsx)(D.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let s=Array.isArray(e)?e:[e];if(s.includes("all-wildcard"))a.setFieldsValue({model_name:void 0,model_mappings:[]});else if(JSON.stringify(a.getFieldValue("model"))!==JSON.stringify(s)){let e=s.map(e=>({public_name:e,litellm_model:e}));a.setFieldsValue({model:s,model_mappings:e})}},optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(s," Models (Wildcard)"),value:"all-wildcard"},...l.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,m.jsx)(I.Z,{placeholder:t(s)})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.model!==s.model,children:e=>{let{getFieldValue:s}=e,l=s("model")||[];return(Array.isArray(l)?l:[l]).includes("custom")&&(0,m.jsx)(M.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom model name",onChange:r})})}})]}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},s5=()=>{let e=M.Z.useFormInstance(),[s,l]=(0,u.useState)(0),t=M.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],r=M.Z.useWatch("custom_model_name",e),n=!a.includes("all-wildcard");if((0,u.useEffect)(()=>{if(r&&a.includes("custom")){let s=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:r,litellm_model:r}:e);e.setFieldValue("model_mappings",s),l(e=>e+1)}},[r,a,e]),(0,u.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let s=e.getFieldValue("model_mappings")||[];if(s.length!==a.length||!a.every(e=>s.some(s=>s.public_name===e||"custom"===e&&s.public_name===r))){let s=a.map(e=>"custom"===e&&r?{public_name:r,litellm_model:r}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",s),l(e=>e+1)}}},[a,r,e]),!n)return null;let i=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(s,l,t)=>(0,m.jsx)(I.Z,{value:s,onChange:s=>{let l=[...e.getFieldValue("model_mappings")];l[t].public_name=s.target.value,e.setFieldValue("model_mappings",l)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(M.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,m.jsx)(en.Z,{dataSource:e.getFieldValue("model_mappings"),columns:i,pagination:!1,size:"small"},s)})})},s3=l(90464);let{Link:s6}=et.default;var s8=e=>{let{showAdvancedSettings:s,setShowAdvancedSettings:l,teams:t}=e,[a]=M.Z.useForm(),[r,n]=u.useState(!1),[i,o]=u.useState("per_token"),[d,c]=u.useState(!1),h=(e,s)=>s&&(isNaN(Number(s))||0>Number(s))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),x=(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(T.Z,{className:"mt-2 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Advanced Settings"})}),(0,m.jsx)(A.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,m.jsx)(M.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,m.jsx)(sY.Z,{onChange:e=>{n(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),r&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(M.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:"per_token",onChange:e=>o(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===i?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}):(0,m.jsx)(M.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)(M.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,m.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,m.jsx)(sY.Z,{onChange:e=>{let s=a.getFieldValue("litellm_extra_params");try{let l=s?JSON.parse(s):{};e?l.use_in_pass_through=!0:delete l.use_in_pass_through,Object.keys(l).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(l,null,2)):a.setFieldValue("litellm_extra_params","")}catch(s){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,m.jsx)(s0,{form:a,showCacheControl:d,onCacheControlChange:e=>{if(c(e),!e){let e=a.getFieldValue("litellm_extra_params");try{let s=e?JSON.parse(e):{};delete s.cache_control_injection_points,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(e){a.setFieldValue("litellm_extra_params","")}}}}),(0,m.jsx)(M.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,m.jsxs)(sj.Z,{className:"mb-4",children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,m.jsx)(M.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},s7=l(29),s9=l.n(s7),le=l(23496),ls=l(23639);let{Text:ll}=et.default;var lt=e=>{let{formValues:s,accessToken:l,testMode:t,modelName:a="this model",onClose:r,onTestComplete:n}=e,[i,o]=u.useState(null),[d,c]=u.useState(null),[h,x]=u.useState(null),[p,g]=u.useState(!0),[j,f]=u.useState(!1),[_,v]=u.useState(!1),y=async()=>{g(!0),v(!1),o(null),c(null),x(null),f(!1),await new Promise(e=>setTimeout(e,100));try{console.log("Testing connection with form values:",s);let a=await sx(s,l,null);if(!a){console.log("No result from prepareModelAddRequest"),o("Failed to prepare model data. Please check your form inputs."),f(!1),g(!1);return}console.log("Result from prepareModelAddRequest:",a);let{litellmParamsObj:r,modelInfoObj:n,modelName:i}=a[0],d=await (0,b.Hx)(l,r,null==n?void 0:n.mode);if("success"===d.status)F.ZP.success("Connection test successful!"),o(null),f(!0);else{var e,t;let s=(null===(e=d.result)||void 0===e?void 0:e.error)||d.message||"Unknown error";o(s),c(r),x(null===(t=d.result)||void 0===t?void 0:t.raw_request_typed_dict),f(!1)}}catch(e){console.error("Test connection error:",e),o(e instanceof Error?e.message:String(e)),f(!1)}finally{g(!1),n&&n()}};u.useEffect(()=>{let e=setTimeout(()=>{y()},200);return()=>clearTimeout(e)},[]);let Z=e=>e?e.split("stack trace:")[0].trim().replace(/^litellm\.(.*?)Error: /,""):"Unknown error",N="string"==typeof i?Z(i):(null==i?void 0:i.message)?Z(i.message):"Unknown error",w=h?((e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")})(h.raw_request_api_base,h.raw_request_body,h.raw_request_headers||{}):"";return(0,m.jsxs)("div",{style:{padding:"24px",borderRadius:"8px",backgroundColor:"#fff"},children:[p?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},className:"jsx-776cdcbc0448e4ea",children:[(0,m.jsx)("div",{style:{marginBottom:"16px"},className:"jsx-776cdcbc0448e4ea loading-spinner",children:(0,m.jsx)("div",{style:{border:"3px solid #f3f3f3",borderTop:"3px solid #1890ff",borderRadius:"50%",width:"30px",height:"30px",animation:"spin 1s linear infinite",margin:"0 auto"},className:"jsx-776cdcbc0448e4ea"})}),(0,m.jsxs)(ll,{style:{fontSize:"16px"},children:["Testing connection to ",a,"..."]}),(0,m.jsx)(s9(),{id:"776cdcbc0448e4ea",children:"@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(360deg);transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-o-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);transform:rotate(360deg)}}"})]}):j?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},children:[(0,m.jsx)("div",{style:{color:"#52c41a",fontSize:"32px",marginBottom:"16px"},children:(0,m.jsx)("svg",{viewBox:"64 64 896 896",focusable:"false","data-icon":"check-circle",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",children:(0,m.jsx)("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"})})}),(0,m.jsxs)(ll,{type:"success",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," successful!"]})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"20px"},children:[(0,m.jsx)(em.Z,{style:{color:"#ff4d4f",fontSize:"24px",marginRight:"12px"}}),(0,m.jsxs)(ll,{type:"danger",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," failed"]})]}),(0,m.jsxs)("div",{style:{backgroundColor:"#fff2f0",border:"1px solid #ffccc7",borderRadius:"8px",padding:"16px",marginBottom:"20px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px"},children:"Error: "}),(0,m.jsx)(ll,{type:"danger",style:{fontSize:"14px",lineHeight:"1.5"},children:N}),i&&(0,m.jsx)("div",{style:{marginTop:"12px"},children:(0,m.jsx)(U.ZP,{type:"link",onClick:()=>v(!_),style:{paddingLeft:0,height:"auto"},children:_?"Hide Details":"Show Details"})})]}),_&&(0,m.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"Troubleshooting Details"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"200px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:"string"==typeof i?i:JSON.stringify(i,null,2)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"API Request"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"250px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:w||"No request data available"}),(0,m.jsx)(U.ZP,{style:{marginTop:"8px"},icon:(0,m.jsx)(ls.Z,{}),onClick:()=>{navigator.clipboard.writeText(w||""),F.ZP.success("Copied to clipboard")},children:"Copy to Clipboard"})]})]})}),(0,m.jsx)(le.Z,{style:{margin:"24px 0 16px"}}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:(0,m.jsx)(U.ZP,{type:"link",href:"https://docs.litellm.ai/docs/providers",target:"_blank",icon:(0,m.jsx)(W.Z,{}),children:"View Documentation"})})]})};let la=[{value:"chat",label:"Chat - /chat/completions"},{value:"completion",label:"Completion - /completions"},{value:"embedding",label:"Embedding - /embeddings"},{value:"audio_speech",label:"Audio Speech - /audio/speech"},{value:"audio_transcription",label:"Audio Transcription - /audio/transcriptions"},{value:"image_generation",label:"Image Generation - /images/generations"},{value:"rerank",label:"Rerank - /rerank"},{value:"realtime",label:"Realtime - /realtime"}],{Title:lr,Link:ln}=et.default;var li=e=>{let{form:s,handleOk:l,selectedProvider:t,setSelectedProvider:a,providerModels:r,setProviderModelsFn:n,getPlaceholder:o,uploadProps:d,showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x,credentials:p,accessToken:g,userRole:j}=e,[f,_]=(0,u.useState)("chat"),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(""),k=async()=>{Z(!0),w("test-".concat(Date.now())),y(!0)},S=eZ.ZL.includes(j);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lr,{level:2,children:"Add new model"}),(0,m.jsx)(s2.Z,{children:(0,m.jsx)(M.Z,{form:s,onFinish:l,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,m.jsx)(D.default,{showSearch:!0,value:t,onChange:e=>{a(e),n(e),s.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(i).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(s4,{selectedProvider:t,providerModels:r,getPlaceholder:o}),(0,m.jsx)(s5,{}),(0,m.jsx)(M.Z.Item,{label:"Mode",name:"mode",className:"mb-1",children:(0,m.jsx)(D.default,{style:{width:"100%"},value:f,onChange:e=>_(e),options:la})}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-5 mt-1",children:[(0,m.jsx)("strong",{children:"Optional"})," - LiteLLM endpoint to use when health checking this model ",(0,m.jsx)(ln,{href:"https://docs.litellm.ai/docs/proxy/health#health",target:"_blank",children:"Learn more"})]})})]}),(0,m.jsx)("div",{className:"mb-4",children:(0,m.jsx)(et.default.Text,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter new provider credentials below"})}),(0,m.jsx)(M.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...p.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.litellm_credential_name!==s.litellm_credential_name||e.provider!==s.provider,children:e=>{let{getFieldValue:s}=e,l=s("litellm_credential_name");return(console.log("\uD83D\uDD11 Credential Name Changed:",l),l)?(0,m.jsx)("div",{className:"text-gray-500 text-sm text-center",children:"Using existing credentials - no additional provider fields needed"}):(0,m.jsx)(sy,{selectedProvider:t,uploadProps:d})}}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Team Settings"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{label:"Team",name:"team_id",className:"mb-4",tooltip:"Only keys for this team, will be able to call this model.",rules:[{required:!S,message:"Please select a team."}],children:(0,m.jsx)(es,{teams:x})}),(0,m.jsx)(s8,{showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x}),(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(et.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{className:"space-x-2",children:[(0,m.jsx)(U.ZP,{onClick:k,loading:b,children:"Test Connect"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Model"})]})]})]})})}),(0,m.jsx)(R.Z,{title:"Connection Test Results",open:v,onCancel:()=>{y(!1),Z(!1)},footer:[(0,m.jsx)(U.ZP,{onClick:()=>{y(!1),Z(!1)},children:"Close"},"close")],width:700,children:v&&(0,m.jsx)(lt,{formValues:s.getFieldsValue(),accessToken:g,testMode:f,modelName:s.getFieldValue("model_name")||s.getFieldValue("model"),onClose:()=>{y(!1),Z(!1)},onTestComplete:()=>Z(!1)},N)})]})};function lo(e){let{data:s=[],columns:l,isLoading:t=!1,table:a}=e,[r,n]=u.useState([{id:"model_info.created_at",desc:!0}]),[i]=u.useState("onChange"),[o,d]=u.useState({}),[c,h]=u.useState({}),x=(0,e2.b7)({data:s,columns:l,state:{sorting:r,columnSizing:o,columnVisibility:c},columnResizeMode:i,onSortingChange:n,onColumnSizingChange:d,onColumnVisibilityChange:h,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,enableColumnResizing:!0,defaultColumn:{minSize:40,maxSize:500}});return u.useEffect(()=>{a&&(a.current=x)},[x,a]),(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsx)("div",{className:"relative min-w-full",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1 w-full",children:[(0,m.jsx)(e8.Z,{children:x.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsxs)(e7.Z,{className:"py-1 h-8 relative ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.id?120:e.getSize(),position:"actions"===e.id?"sticky":"relative",right:"actions"===e.id?0:"auto"},onClick:e.column.getToggleSortingHandler(),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]}),e.column.getCanResize()&&(0,m.jsx)("div",{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),className:"absolute right-0 top-0 h-full w-2 cursor-col-resize select-none touch-none ".concat(e.column.getIsResizing()?"bg-blue-500":"hover:bg-blue-200")})]},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):x.getRowModel().rows.length>0?x.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.column.id?120:e.column.getSize(),position:"actions"===e.column.id?"sticky":"relative",right:"actions"===e.column.id?0:"auto"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No models found"})})})})})]})})})})}let ld=(e,s,l,t,a,r,n,i,o)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.model_info.id,children:(0,m.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>t(l.model_info.id),children:l.model_info.id})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:s}=e,l=r(s.original)||"-";return(0,m.jsx)(Y.Z,{title:l,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l.provider&&(0,m.jsx)("img",{src:sm(l.provider).logo,alt:"".concat(l.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,t=s.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=l.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,s)}}}),(0,m.jsx)("p",{className:"text-xs",children:l.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.litellm_model_name,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l.litellm_model_name||"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_at?new Date(l.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.updated_at?new Date(l.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_by||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.input_cost||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:s}=e,l=s.original;return l.model_info.team_id?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.model_info.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>a(l.model_info.team_id),children:[l.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Credentials",accessorKey:"litellm_credential_name",cell:e=>{let{row:s}=e,l=s.original;return l.litellm_params&&l.litellm_params.litellm_credential_name?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsxs)(Y.Z,{title:l.litellm_params.litellm_credential_name,children:[l.litellm_params.litellm_credential_name.slice(0,7),"..."]})}):(0,m.jsx)("span",{className:"text-gray-400",children:"-"})}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(l.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:l.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:l=>{var a;let{row:r}=l,n=r.original,i="Admin"===e||(null===(a=n.model_info)||void 0===a?void 0:a.created_by)===s;return(0,m.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{i&&(t(n.model_info.id),o(!0))},className:i?"cursor-pointer":"opacity-50 cursor-not-allowed"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{i&&(t(n.model_info.id),o(!1))},className:i?"cursor-pointer":"opacity-50 cursor-not-allowed"})]})}}],{Title:lc,Link:lm}=et.default,lu={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lh=e=>{let{accessToken:s,token:l,userRole:t,userID:a,modelData:r={data:[]},keys:n,setModelData:o,premiumUser:d,teams:c}=e,[h,x]=(0,u.useState)([]),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)([]);Object.values(i).filter(e=>isNaN(Number(e)));let[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(i.OpenAI),[I,T]=(0,u.useState)(""),[A,E]=(0,u.useState)(!1),[L,D]=(0,u.useState)(null),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)([]),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)([]),[J,W]=(0,u.useState)([]),[Y,$]=(0,u.useState)([]),[X,Q]=(0,u.useState)([]),[ee,es]=(0,u.useState)([]),[ea,er]=(0,u.useState)([]),[en,ei]=(0,u.useState)([]),[eo,ed]=(0,u.useState)([]),[ec,em]=(0,u.useState)([]),[eu,eh]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,u.useState)(null),[eg,ej]=(0,u.useState)(0),[ef,e_]=(0,u.useState)({}),[ev,ey]=(0,u.useState)([]),[eb,eN]=(0,u.useState)(!1),[ew,ek]=(0,u.useState)(null),[eS,eC]=(0,u.useState)(null),[eI,eT]=(0,u.useState)([]),[eA,eE]=(0,u.useState)([]),[eP,eL]=(0,u.useState)(!1),[ez,eK]=(0,u.useState)(null),[eB,eH]=(0,u.useState)(!1),[eJ,eW]=(0,u.useState)(null),[eY,e$]=(0,u.useState)(null),[eX,eQ]=(0,u.useState)(null),[e0,e1]=(0,u.useState)(!1),[e2,e4]=(0,u.useState)(!1),se=(0,u.useRef)(null),ss=(0,u.useRef)(null),sl=async(e,l,r)=>{if(console.log("Updating model metrics for group:",e),!s||!a||!t||!l||!r)return;console.log("inside updateModelMetrics - startTime:",l,"endTime:",r),K(e);let n=null==ew?void 0:ew.token;void 0===n&&(n=null);let i=eS;void 0===i&&(i=null),l.setHours(0),l.setMinutes(0),l.setSeconds(0),r.setHours(23),r.setMinutes(59),r.setSeconds(59);try{let o=await (0,b.o6)(s,a,t,e,l.toISOString(),r.toISOString(),n,i);console.log("Model metrics response:",o),W(o.data),$(o.all_api_bases);let d=await (0,b.Rg)(s,e,l.toISOString(),r.toISOString());Q(d.data),es(d.all_api_bases);let c=await (0,b.N8)(s,a,t,e,l.toISOString(),r.toISOString(),n,i);console.log("Model exceptions response:",c),er(c.data),ei(c.exception_types);let m=await (0,b.fP)(s,a,t,e,l.toISOString(),r.toISOString(),n,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,b.n$)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);e_(t);let a=await (0,b.v9)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);ey(a)}}catch(e){console.error("Failed to fetch model metrics",e)}},st=async e=>{try{let s=await (0,b.N3)(e);console.log("credentials: ".concat(JSON.stringify(s))),eE(s.credentials)}catch(e){console.error("Error fetching credentials:",e)}};(0,u.useEffect)(()=>{sl(V,eu.from,eu.to)},[ew,eS,eY]),(0,u.useEffect)(()=>{let e=e=>{se.current&&!se.current.contains(e.target)&&e4(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let sa={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Resetting vertex_credentials to JSON; jsonStr: ".concat(s)),p.setFieldsValue({vertex_credentials:s}),console.log("Form values right after setting:",p.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered with values:",e),console.log("Current form values:",p.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?F.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&F.ZP.error("".concat(e.file.name," file upload failed."))}},sr=()=>{_(new Date().toLocaleString())},sn=async()=>{if(!s){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,b.K_)(s,{router_settings:{model_group_retry_policy:ex}}),F.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),F.ZP.error("Failed to save retry settings")}};if((0,u.useEffect)(()=>{if(!s||!l||!t||!a)return;let e=async()=>{try{var e,l,r,n,i,d,c,m,u,h,x,p;let g=await (0,b.AZ)(s,a,t);console.log("Model data response:",g.data),o(g);let j=await (0,b.hy)(s);j&&N(j);let f=new Set;for(let e=0;e0&&(v=_[_.length-1],console.log("_initial_model_group:",v)),console.log("selectedModelGroup:",V);let y=await (0,b.o6)(s,a,t,v,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(l=eu.to)||void 0===l?void 0:l.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model metrics response:",y),W(y.data),$(y.all_api_bases);let Z=await (0,b.Rg)(s,v,null===(r=eu.from)||void 0===r?void 0:r.toISOString(),null===(n=eu.to)||void 0===n?void 0:n.toISOString());Q(Z.data),es(Z.all_api_bases);let w=await (0,b.N8)(s,a,t,v,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(d=eu.to)||void 0===d?void 0:d.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model exceptions response:",w),er(w.data),ei(w.exception_types);let k=await (0,b.fP)(s,a,t,v,null===(c=eu.from)||void 0===c?void 0:c.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eS),S=await (0,b.n$)(s,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],v);e_(S);let C=await (0,b.v9)(s,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],v);ey(C),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",C),console.log("slowResponses:",k),em(k);let I=await (0,b.j2)(s);eT(null==I?void 0:I.end_users);let T=(await (0,b.BL)(s,a,t)).router_settings;console.log("routerSettingsInfo:",T);let A=T.model_group_retry_policy,E=T.num_retries;console.log("model_group_retry_policy:",A),console.log("default_retries:",E),ep(A),ej(E)}catch(e){console.error("There was an error fetching the model data",e)}};s&&l&&t&&a&&e();let r=async()=>{let e=await (0,b.qm)(s);console.log("received model cost map data: ".concat(Object.keys(e))),j(e)};null==g&&r(),sr()},[s,l,t,a,g,f,eY]),!r||!s||!l||!t||!a)return(0,m.jsx)("div",{children:"Loading..."});let sd=[],sc=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(l){let e=l.split("/"),s=e[0];(n=t)||(n=1===e.length?u(l):s)}else n="-";a&&(i=null==a?void 0:a.input_cost_per_token,o=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==s?void 0:s.litellm_params)&&(m=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[s]=e;return"model"!==s&&"api_base"!==s}))),r.data[e].provider=n,r.data[e].input_cost=i,r.data[e].output_cost=o,r.data[e].litellm_model_name=l,sc.push(n),r.data[e].input_cost&&(r.data[e].input_cost=(1e6*Number(r.data[e].input_cost)).toFixed(2)),r.data[e].output_cost&&(r.data[e].output_cost=(1e6*Number(r.data[e].output_cost)).toFixed(2)),r.data[e].max_tokens=d,r.data[e].max_input_tokens=c,r.data[e].api_base=null==s?void 0:null===(sg=s.litellm_params)||void 0===sg?void 0:sg.api_base,r.data[e].cleanedLitellmParams=m,sd.push(s.model_name),console.log(r.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to view all models"})]})}let sj=async()=>{try{F.ZP.info("Running health check..."),T("");let e=await (0,b.EY)(s);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}},s_=(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Select API Key Name"}),d?(0,m.jsxs)("div",{children:[(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{ek(null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{ek(e)},children:e.key_alias},s):null)]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Customer Name"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-customers",children:[(0,m.jsx)(el.Z,{value:"all-customers",onClick:()=>{eC(null)},children:"All Customers"},"all-customers"),null==eI?void 0:eI.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>{eC(e)},children:e},s))]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]}),sv=e=>{var s,l;let{payload:t,active:a}=e;if(!a||!t)return null;let r=null===(l=t[0])||void 0===l?void 0:null===(s=l.payload)||void 0===s?void 0:s.date,n=t.sort((e,s)=>s.value-e.value);if(n.length>5){let e=n.length-5;(n=n.slice(0,5)).push({dataKey:"".concat(e," other deployments"),value:t.slice(5).reduce((e,s)=>e+s.value,0),color:"gray"})}return(0,m.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[r&&(0,m.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",r]}),n.map((e,s)=>{let l=parseFloat(e.value.toFixed(5)),t=0===l&&e.value>0?"<0.00001":l.toFixed(5);return(0,m.jsxs)("div",{className:"flex justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,m.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,m.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:t})]},s)})]})};console.log("selectedProvider: ".concat(w)),console.log("providerModels.length: ".concat(v.length));let sy=Object.keys(i).find(e=>i[e]===w);return(sy&&Z&&Z.find(e=>e.name===so[sy]),eJ)?(0,m.jsx)("div",{className:"w-full h-full",children:(0,m.jsx)(sB,{teamId:eJ,onClose:()=>eW(null),accessToken:s,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:sd,editTeam:!1,onUpdate:sr})}):(0,m.jsx)("div",{style:{width:"100%",height:"100%"},children:ez?(0,m.jsx)(s1,{modelId:ez,editModel:!0,onClose:()=>{eK(null),eH(!1)},modelData:r.data.find(e=>e.model_info.id===ez),accessToken:s,userID:a,userRole:t,setEditModalVisible:E,setSelectedModel:D,onModelUpdate:e=>{o({...r,data:r.data.map(s=>s.model_info.id===e.model_info.id?e:s)}),sr()}}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[eZ.ZL.includes(t)?(0,m.jsx)(eM.Z,{children:"All Models"}):(0,m.jsx)(eM.Z,{children:"Your Models"}),(0,m.jsx)(eM.Z,{children:"Add Model"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"LLM Credentials"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"/health Models"})}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Analytics"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Retry Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:sr})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(S.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(O.Z,{children:"Model Management"}),eZ.ZL.includes(t)?(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add and manage models for the proxy"}):(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add models for teams you are an admin for."})]})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex items-center justify-between",children:(0,m.jsxs)("div",{className:"flex items-center gap-3",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:null!=V?V:"all",onValueChange:e=>K("all"===e?"all":e),value:null!=V?V:"all",children:[(0,m.jsx)(el.Z,{value:"all",children:"All Models"}),R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,children:e},s))]})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Team:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]})}),(0,m.jsx)("div",{className:"flex justify-between items-center",children:(0,m.jsxs)(P.Z,{className:"text-sm text-gray-700",children:["Showing ",r&&r.data.length>0?r.data.length:0," results"]})})]})}),(0,m.jsx)(lo,{columns:ld(t,a,d,eK,eW,sk,e=>{D(e),E(!0)},sr,eH),data:r.data.filter(e=>("all"===V||e.model_name===V||!V)&&("all"===eX||e.model_info.team_id===eX||!eX)),isLoading:!1,table:ss})]})]})})}),(0,m.jsx)(eq.Z,{className:"h-full",children:(0,m.jsx)(li,{form:p,handleOk:()=>{p.validateFields().then(e=>{sp(e,s,p,sr)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:w,setSelectedProvider:k,providerModels:v,setProviderModelsFn:e=>{let s=sh(e,g);y(s),console.log("providerModels: ".concat(s))},getPlaceholder:su,uploadProps:sa,showAdvancedSettings:eP,setShowAdvancedSettings:eL,teams:c,credentials:eA,accessToken:s,userRole:t})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sw,{accessToken:s,uploadProps:sa,credentialList:eA,fetchCredentials:st})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,m.jsx)(C.Z,{onClick:sj,children:"Run `/health`"}),I&&(0,m.jsx)("pre",{children:JSON.stringify(I,null,2)})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:eu,className:"mr-2",onValueChange:e=>{eh(e),sl(V,e.from,e.to)}})]}),(0,m.jsxs)(sf.Z,{className:"ml-2",children:[(0,m.jsx)(P.Z,{children:"Select Model Group"}),(0,m.jsx)(eO.Z,{defaultValue:V||R[0],value:V||R[0],children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>sl(e,eu.from,eu.to),children:e},s))})]}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(sA.Z,{trigger:"click",content:s_,overlayStyle:{width:"20vw"},children:(0,m.jsx)(C.Z,{icon:eG.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>eN(!0)})})})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Avg. Latency per Token"}),(0,m.jsx)(eM.Z,{value:"2",children:"Time to first token"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,m.jsx)(P.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),J&&Y&&(0,m.jsx)(sI.Z,{title:"Model Latency",className:"h-72",data:J,showLegend:!1,index:"date",categories:Y,connectNulls:!0,customTooltip:sv})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sP,{modelMetrics:X,modelMetricsCategories:ee,customTooltip:sv,premiumUser:d})})]})]})})}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Deployment"}),(0,m.jsx)(e7.Z,{children:"Success Responses"}),(0,m.jsxs)(e7.Z,{children:["Slow Responses ",(0,m.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,m.jsx)(e3.Z,{children:ec.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.api_base}),(0,m.jsx)(e6.Z,{children:e.total_count}),(0,m.jsx)(e6.Z,{children:e.slow_count})]},s))})]})})})]}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Exceptions for ",V]}),(0,m.jsx)(sT.Z,{className:"h-60",data:ea,index:"model",categories:en,stack:!0,yAxisWidth:30})]})}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Up Rate Limit Errors (429) for ",V]}),(0,m.jsxs)(S.Z,{numItems:1,children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",ef.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:ef.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,m.jsx)(sf.Z,{})]})]}),d?(0,m.jsx)(m.Fragment,{children:ev.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},s))}):(0,m.jsx)(m.Fragment,{children:ev&&ev.length>0&&ev.slice(0,1).map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},s))})]})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name"}),(0,m.jsx)(eO.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:V||R[0],value:V||R[0],onValueChange:e=>K(e),children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>K(e),children:e},s))})]}),(0,m.jsxs)(O.Z,{children:["Retry Policy for ",V]}),(0,m.jsx)(P.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lu&&(0,m.jsx)("table",{children:(0,m.jsx)("tbody",{children:Object.entries(lu).map((e,s)=>{var l;let[t,a]=e,r=null==ex?void 0:null===(l=ex[V])||void 0===l?void 0:l[a];return null==r&&(r=eg),(0,m.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,m.jsx)("td",{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)("td",{children:(0,m.jsx)(G.Z,{className:"ml-5",value:r,min:0,step:1,onChange:e=>{ep(s=>{var l;let t=null!==(l=null==s?void 0:s[V])&&void 0!==l?l:{};return{...null!=s?s:{},[V]:{...t,[a]:e}}})}})})]},s)})})}),(0,m.jsx)(C.Z,{className:"mt-6 mr-8",onClick:sn,children:"Save"})]})]})]})})},lx=e=>{let{visible:s,possibleUIRoles:l,onCancel:t,user:a,onSubmit:r}=e,[n,i]=(0,u.useState)(a),[o]=M.Z.useForm();(0,u.useEffect)(()=>{o.resetFields()},[a]);let d=async()=>{o.resetFields(),t()},c=async e=>{r(e),o.resetFields(),t()};return a?(0,m.jsx)(R.Z,{visible:s,onCancel:d,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,m.jsx)(M.Z,{form:o,onFinish:c,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:l&&Object.entries(l).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,m.jsx)(G.Z,{min:0,step:.01})}),(0,m.jsx)(M.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Maximum budget of this user.",children:(0,m.jsx)(K,{min:0,step:.01})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lp=l(15731);let lg=(e,s,l)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)(Y.Z,{title:s.original.user_id,children:(0,m.jsx)("span",{className:"text-xs",children:s.original.user_id?"".concat(s.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:s=>{var l;let{row:t}=s;return(0,m.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(l=e[t.original.user_role])||void 0===l?void 0:l.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.spend?s.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.max_budget?s.original.max_budget:"Unlimited"})}},{header:()=>(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"SSO ID"}),(0,m.jsx)(Y.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,m.jsx)(lp.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.sso_user_id?s.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:s}=e;return(0,m.jsx)(S.Z,{numItems:2,children:s.original.key_count>0?(0,m.jsxs)(eL.Z,{size:"xs",color:"indigo",children:[s.original.key_count," Keys"]}):(0,m.jsx)(eL.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.created_at?new Date(s.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.updated_at?new Date(s.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>s(t.original)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.original.user_id)})]})}}];var lj=l(16853);function lf(e){let{userData:s,onCancel:l,onSubmit:t,teams:a,accessToken:r,userID:n,userRole:i,userModels:o,possibleUIRoles:d}=e,[c]=M.Z.useForm();return u.useEffect(()=>{var e,l,t,a,r;c.setFieldsValue({user_id:s.user_id,user_email:null===(e=s.user_info)||void 0===e?void 0:e.user_email,user_role:null===(l=s.user_info)||void 0===l?void 0:l.user_role,models:(null===(t=s.user_info)||void 0===t?void 0:t.models)||[],max_budget:null===(a=s.user_info)||void 0===a?void 0:a.max_budget,metadata:(null===(r=s.user_info)||void 0===r?void 0:r.metadata)?JSON.stringify(s.user_info.metadata,null,2):void 0})},[s,c]),(0,m.jsxs)(M.Z,{form:c,onFinish:e=>{if(e.metadata&&"string"==typeof e.metadata)try{e.metadata=JSON.parse(e.metadata)}catch(e){console.error("Error parsing metadata JSON:",e);return}t(e)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:d&&Object.entries(d).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Personal Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this user can access outside of team-scope. Choose 'All Proxy Models' to grant access to all models available on the proxy.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:!eZ.ZL.includes(i||""),children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(lj.Z,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:l,children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}function l_(e){var s,l,t,a,r,n,i,o,d,c,h,x,p,g,j,f,_,v,y,Z,N,w,k,I,T,A,E;let{userId:L,onClose:D,accessToken:M,userRole:R,onDelete:q,possibleUIRoles:U}=e,[z,V]=(0,u.useState)(null),[K,B]=(0,u.useState)(!1),[H,J]=(0,u.useState)(!0),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)([]);u.useEffect(()=>{console.log("userId: ".concat(L,", userRole: ").concat(R,", accessToken: ").concat(M)),(async()=>{try{if(!M)return;let e=await (0,b.Br)(M,L,R||"",!1,null,null,!0);V(e);let s=(await (0,b.So)(M,L,R||"")).data.map(e=>e.id);$(s)}catch(e){console.error("Error fetching user data:",e),F.ZP.error("Failed to fetch user data")}finally{J(!1)}})()},[M,L,R]);let X=async()=>{try{if(!M)return;await (0,b.Eb)(M,[L]),F.ZP.success("User deleted successfully"),q&&q(),D()}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}},Q=async e=>{try{if(!M||!z)return;await (0,b.pf)(M,e,null),V({...z,user_info:{...z.user_info,user_email:e.user_email,models:e.models,max_budget:e.max_budget,metadata:e.metadata}}),F.ZP.success("User updated successfully"),W(!1)}catch(e){console.error("Error updating user:",e),F.ZP.error("Failed to update user")}};return H?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"Loading user data..."})]}):z?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(O.Z,{children:(null===(s=z.user_info)||void 0===s?void 0:s.user_email)||"User"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:z.user_id})]}),R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete User"})]}),K&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:X,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>B(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Details"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number((null===(l=z.user_info)||void 0===l?void 0:l.spend)||0).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",(null===(t=z.user_info)||void 0===t?void 0:t.max_budget)!==null?"$".concat(z.user_info.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(a=z.teams)||void 0===a?void 0:a.length)||0," teams"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"API Keys"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(r=z.keys)||void 0===r?void 0:r.length)||0," keys"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Personal Models"}),(0,m.jsx)("div",{className:"mt-2",children:(null===(i=z.user_info)||void 0===i?void 0:null===(n=i.models)||void 0===n?void 0:n.length)&&(null===(d=z.user_info)||void 0===d?void 0:null===(o=d.models)||void 0===o?void 0:o.length)>0?null===(h=z.user_info)||void 0===h?void 0:null===(c=h.models)||void 0===c?void 0:c.map((e,s)=>(0,m.jsx)(P.Z,{children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"User Settings"}),!G&&R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>W(!0),children:"Edit Settings"})]}),G&&z?(0,m.jsx)(lf,{userData:z,onCancel:()=>W(!1),onSubmit:Q,teams:z.teams,accessToken:M,userID:L,userRole:R,userModels:Y,possibleUIRoles:U}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"User ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:z.user_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Email"}),(0,m.jsx)(P.Z,{children:(null===(x=z.user_info)||void 0===x?void 0:x.user_email)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Role"}),(0,m.jsx)(P.Z,{children:(null===(p=z.user_info)||void 0===p?void 0:p.user_role)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:(null===(g=z.user_info)||void 0===g?void 0:g.created_at)?new Date(z.user_info.created_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:(null===(j=z.user_info)||void 0===j?void 0:j.updated_at)?new Date(z.user_info.updated_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Teams"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(f=z.teams)||void 0===f?void 0:f.length)&&(null===(_=z.teams)||void 0===_?void 0:_.length)>0?null===(v=z.teams)||void 0===v?void 0:v.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e.team_alias||e.team_id},s)):(0,m.jsx)(P.Z,{children:"No teams"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(Z=z.user_info)||void 0===Z?void 0:null===(y=Z.models)||void 0===y?void 0:y.length)&&(null===(w=z.user_info)||void 0===w?void 0:null===(N=w.models)||void 0===N?void 0:N.length)>0?null===(I=z.user_info)||void 0===I?void 0:null===(k=I.models)||void 0===k?void 0:k.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Keys"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(T=z.keys)||void 0===T?void 0:T.length)&&(null===(A=z.keys)||void 0===A?void 0:A.length)>0?z.keys.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-green-100 rounded text-xs",children:e.key_alias||e.token},s)):(0,m.jsx)(P.Z,{children:"No API keys"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify((null===(E=z.user_info)||void 0===E?void 0:E.metadata)||{},null,2)})]})]})]})})]})]})]}):(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"User not found"})]})}function lv(e){let{data:s=[],columns:l,isLoading:t=!1,onSortChange:a,currentSort:r,accessToken:n,userRole:i,possibleUIRoles:o}=e,[d,c]=u.useState([{id:(null==r?void 0:r.sortBy)||"created_at",desc:(null==r?void 0:r.sortOrder)==="desc"}]),[h,x]=u.useState(null),p=(0,e2.b7)({data:s,columns:l,state:{sorting:d},onSortingChange:e=>{if(c(e),e.length>0){let s=e[0],l=s.id,t=s.desc?"desc":"asc";null==a||a(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0}),g=e=>{x(e)};return(u.useEffect(()=>{r&&c([{id:r.sortBy,desc:"desc"===r.sortOrder}])},[r]),h)?(0,m.jsx)(l_,{userId:h,onClose:()=>{x(null)},accessToken:n,userRole:i,possibleUIRoles:o}):(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:p.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):s.length>0?p.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:()=>{"user_id"===e.column.id&&g(e.getValue())},style:{cursor:"user_id"===e.column.id?"pointer":"default",color:"user_id"===e.column.id?"#3b82f6":"inherit"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No users found"})})})})})]})})})}var ly=l(67982),lb=l(87908),lZ=e=>{var s;let{accessToken:l,possibleUIRoles:t,userID:a,userRole:r}=e,[n,i]=(0,u.useState)(!0),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)([]),{Paragraph:v}=et.default,{Option:y}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){i(!1);return}try{let e=await (0,b.NL)(l);if(d(e),p(e.values||{}),l)try{let e=await (0,b.So)(l,a,r);if(e&&e.data){let s=e.data.map(e=>e.id);_(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching SSO settings:",e),F.ZP.error("Failed to fetch SSO settings")}finally{i(!1)}})()},[l]);let Z=async()=>{if(l){j(!0);try{let e=await (0,b.nd)(l,x);d({...o,values:e.settings}),h(!1)}catch(e){console.error("Error updating SSO settings:",e),F.ZP.error("Failed to update settings")}finally{j(!1)}}},N=(e,s)=>{p(l=>({...l,[e]:s}))},w=(e,s,l)=>{var a;let r=s.type;return"user_role"===e&&t?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:Object.entries(t).filter(e=>{let[s]=e;return s.includes("internal_user")}).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(y,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{children:l}),(0,m.jsx)("span",{className:"ml-2 text-xs text-gray-500",children:t})]})},s)})}):"budget_duration"===e?(0,m.jsx)(ek,{value:x[e]||null,onChange:s=>N(e,s),className:"mt-2"}):"boolean"===r?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!x[e],onChange:s=>N(e,s)})}):"array"===r&&(null===(a=s.items)||void 0===a?void 0:a.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:f.map(e=>(0,m.jsx)(y,{value:e,children:H(e)},e))}):"string"===r&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==x[e]?String(x[e]):"",onChange:s=>N(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},k=(e,s)=>{if(null==s)return(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"});if("user_role"===e&&t&&t[s]){let{ui_label:e,description:l}=t[s];return(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-medium",children:e}),l&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:l})]})}return"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)})};return n?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):o?(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex justify-end items-center mb-4",children:!n&&o&&(c?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{h(!1),p(o.values||{})},disabled:g,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:Z,loading:g,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>h(!0),children:"Edit Settings"}))}),(null==o?void 0:null===(s=o.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(v,{className:"mb-4",children:o.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=o;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(v,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),c?(0,m.jsx)("div",{className:"mt-2",children:w(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:k(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No settings available or you do not have permission to view them."})})},lN=l(19616);console.log=function(){};let lw={email:"",user_id:"",user_role:"",sso_user_id:"",team:"",model:"",min_spend:null,max_spend:null,sort_by:"created_at",sort_order:"desc"};var lk=e=>{var s;let{accessToken:l,token:t,userRole:a,userID:r,teams:n}=e,i=(0,g.NL)(),[o,d]=(0,u.useState)(1),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)("users"),[N,w]=(0,u.useState)(lw),[k,S,I]=(0,lN.G)(N,{wait:300}),[T,A]=(0,u.useState)(!1);(0,u.useEffect)(()=>()=>{I.cancel()},[I]);let E=e=>{w(s=>{let l={...s,...e};return S(l),l})},P=async()=>{if(_&&l)try{await (0,b.Eb)(l,[_]),i.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let s=e.users.filter(e=>e.user_id!==_);return{...e,users:s}}),F.ZP.success("User deleted successfully")}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}f(!1),v(null)},O=async()=>{p(null),h(!1)},L=async e=>{if(console.log("inside handleEditSubmit:",e),l&&t&&a&&r){try{let s=await (0,b.pf)(l,e,null);i.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let l=e.users.map(e=>e.user_id===s.data.user_id?e1(e,s.data):e);return{...e,users:l}}),F.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}p(null),h(!1)}},D=async e=>{d(e)},M=(0,eY.a)({queryKey:["userList",{debouncedFilter:k,currentPage:o}],queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.Of)(l,k.user_id?[k.user_id]:null,o,25,k.email||null,k.user_role||null,k.team||null,k.sso_user_id||null,k.sort_by,k.sort_order)},enabled:!!(l&&t&&a&&r),placeholderData:e=>e}),R=M.data,q=(0,eY.a)({queryKey:["userRoles"],initialData:()=>({}),queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.lg)(l)},enabled:!!(l&&t&&a&&r)}).data;if(M.isLoading||!l||!t||!a||!r)return(0,m.jsx)("div",{children:"Loading..."});let U=lg(q,e=>{p(e),h(!0)},e=>{v(e),f(!0)});return(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,m.jsx)("div",{className:"flex space-x-3",children:(0,m.jsx)(ev,{userID:r,accessToken:l,teams:n,possibleUIRoles:q})})]}),(0,m.jsxs)(eF.Z,{defaultIndex:0,onIndexChange:e=>Z(0===e?"users":"settings"),children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Users"}),(0,m.jsx)(eM.Z,{children:"Default User Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by email...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.email,onChange:e=>E({email:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(T?"bg-gray-100":""),onClick:()=>A(!T),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(N.user_id||N.user_role||N.team)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{E(lw)},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),T&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Filter by User ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.user_id,onChange:e=>E({user_id:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.user_role,onValueChange:e=>E({user_role:e}),placeholder:"Select Role",children:Object.entries(q).map(e=>{let[s,l]=e;return(0,m.jsx)(el.Z,{value:s,children:l.ui_label},s)})})}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.team,onValueChange:e=>E({team:e}),placeholder:"Select Team",children:null==n?void 0:n.map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias||e.team_id},e.team_id))})}),(0,m.jsx)("div",{className:"relative w-64",children:(0,m.jsx)("input",{type:"text",placeholder:"Filter by SSO ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.sso_user_id,onChange:e=>E({sso_user_id:e.target.value})})})]}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",R&&R.users&&R.users.length>0?(R.page-1)*R.page_size+1:0," ","-"," ",R&&R.users?Math.min(R.page*R.page_size,R.total):0," ","of ",R?R.total:0," results"]}),(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>D(o-1),disabled:1===o,className:"px-3 py-1 text-sm border rounded-md ".concat(1===o?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,m.jsx)("button",{onClick:()=>D(o+1),disabled:!R||o>=R.total_pages,className:"px-3 py-1 text-sm border rounded-md ".concat(!R||o>=R.total_pages?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,m.jsx)(lv,{data:(null===(s=M.data)||void 0===s?void 0:s.users)||[],columns:U,isLoading:M.isLoading,accessToken:l,userRole:a,onSortChange:(e,s)=>{E({sort_by:e,sort_order:s})},currentSort:{sortBy:N.sort_by,sortOrder:N.sort_order},possibleUIRoles:q})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lZ,{accessToken:l,possibleUIRoles:q,userID:r,userRole:a})})]})]}),(0,m.jsx)(lx,{visible:c,possibleUIRoles:q,onCancel:O,user:x,onSubmit:L}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,m.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",_]})]})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:P,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})})]})},lS=e=>{var s;let{accessToken:l,userID:t,userRole:a}=e,[r,n]=(0,u.useState)(!0),[i,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)({}),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)([]),{Paragraph:_}=et.default,{Option:v}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){n(!1);return}try{let e=await (0,b.EB)(l);if(o(e),x(e.values||{}),l)try{let e=await (0,b.So)(l,t,a);if(e&&e.data){let s=e.data.map(e=>e.id);f(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching team SSO settings:",e),F.ZP.error("Failed to fetch team settings")}finally{n(!1)}})()},[l]);let y=async()=>{if(l){g(!0);try{let e=await (0,b.r1)(l,h);o({...i,values:e.settings}),c(!1),F.ZP.success("Default team settings updated successfully")}catch(e){console.error("Error updating team settings:",e),F.ZP.error("Failed to update team settings")}finally{g(!1)}}},Z=(e,s)=>{x(l=>({...l,[e]:s}))},N=(e,s,l)=>{var t;let a=s.type;return"budget_duration"===e?(0,m.jsx)(ek,{value:h[e]||null,onChange:s=>Z(e,s),className:"mt-2"}):"boolean"===a?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!h[e],onChange:s=>Z(e,s)})}):"array"===a&&(null===(t=s.items)||void 0===t?void 0:t.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:j.map(e=>(0,m.jsx)(v,{value:e,children:H(e)},e))}):"string"===a&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>Z(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==h[e]?String(h[e]):"",onChange:s=>Z(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},w=(e,s)=>null==s?(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"}):"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)});return r?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):i?(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{className:"text-xl",children:"Default Team Settings"}),!r&&i&&(d?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{c(!1),x(i.values||{})},disabled:p,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:y,loading:p,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Settings"}))]}),(0,m.jsx)(P.Z,{children:"These settings will be applied by default when creating new teams."}),(null==i?void 0:null===(s=i.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(_,{className:"mb-4 mt-2",children:i.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=i;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(_,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),d?(0,m.jsx)("div",{className:"mt-2",children:N(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:w(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No team settings available or you do not have permission to view them."})})},lC=e=>{let{accessToken:s,userID:l}=e,[t,a]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(s&&l)try{let e=await (0,b.a6)(s);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[s,l]);let r=async e=>{if(s&&l)try{await (0,b.cu)(s,e,{user_id:l,role:"user"}),F.ZP.success("Successfully joined team"),a(s=>s.filter(s=>s.team_id!==e))}catch(e){console.error("Error joining team:",e),F.ZP.error("Failed to join team")}};return(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{children:"Members"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsxs)(e3.Z,{children:[t.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.team_alias})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.description||"No description available"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[e.members_with_roles.length," members"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,s)=>(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},s)):(0,m.jsx)(eL.Z,{size:"xs",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})})})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{size:"xs",variant:"secondary",onClick:()=>r(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:5,className:"text-center",children:(0,m.jsx)(P.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lI=(e,s)=>{let l=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),l=e.models):l=s,J(l,s)};var lT=e=>{let{teams:s,searchParams:l,accessToken:t,setTeams:a,userID:r,userRole:n,organizations:i}=e,[o,d]=(0,u.useState)(""),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,u.useEffect)(()=>{console.log("inside useeffect - ".concat(o)),t&&w(t,r,n,c,a),ew()},[o]);let[v]=M.Z.useForm(),[y]=M.Z.useForm(),{Title:Z,Paragraph:N}=et.default,[O,L]=(0,u.useState)(""),[q,V]=(0,u.useState)(!1),[J,G]=(0,u.useState)(null),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(!1),[es,ea]=(0,u.useState)(!1),[er,en]=(0,u.useState)(!1),[ei,eo]=(0,u.useState)(!1),[ed,ec]=(0,u.useState)([]),[em,eu]=(0,u.useState)(!1),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)([]),[ej,ef]=(0,u.useState)({}),[e_,ev]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lI(x,ed);console.log("models: ".concat(e)),eg(e),v.setFieldValue("models",[])},[x,ed]),(0,u.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,b.t3)(t)).guardrails.map(e=>e.guardrail_name);ev(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let ey=async e=>{ex(e),eu(!0)},eb=async()=>{if(null!=eh&&null!=s&&null!=t){try{await (0,b.rs)(t,eh),w(t,r,n,c,a)}catch(e){console.error("Error deleting the team:",e)}eu(!1),ex(null)}};(0,u.useEffect)(()=>{(async()=>{try{if(null===r||null===n||null===t)return;let e=await B(r,n,t);e&&ec(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,r,n,s]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var l;let r=null==e?void 0:e.team_alias,n=null!==(l=null==s?void 0:s.map(e=>e.team_alias))&&void 0!==l?l:[],i=(null==e?void 0:e.organization_id)||(null==c?void 0:c.organization_id);if(""===i||"string"!=typeof i?e.organization_id=null:e.organization_id=i.trim(),n.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));F.ZP.info("Creating Team");let o=await (0,b.hT)(t,e);null!==s?a([...s,o]):a([o]),console.log("response for team create call: ".concat(o)),F.ZP.success("Team created"),v.resetFields(),ea(!1)}}catch(e){console.error("Error creating the team:",e),F.ZP.error("Error creating the team: "+e,20)}},ew=()=>{d(new Date().toLocaleString())},ek=(e,s)=>{let l={...f,[e]:s};_(l),t&&(0,b.JO)(t,l.organization_id||null,null,l.team_id||null,l.team_alias||null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:$?(0,m.jsx)(sB,{teamId:$,onUpdate:e=>{a(s=>null==s?s:s.map(s=>e.team_id===s.team_id?e1(s,e):s))},onClose:()=>{X(null),ee(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let s=0;se.team_id===$)),is_proxy_admin:"Admin"==n,userModels:ed,editTeam:Q}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Your Teams"}),(0,m.jsx)(eM.Z,{children:"Available Teams"}),(0,eZ.tY)(n||"")&&(0,m.jsx)(eM.Z,{children:"Default Team Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",o]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(P.Z,{children:["Click on “Team ID” to view team details ",(0,m.jsx)("b",{children:"and"})," manage team members."]}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Team Name...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_alias,onChange:e=>ek("team_alias",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(g?"bg-gray-100":""),onClick:()=>j(!g),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(f.team_id||f.team_alias||f.organization_id)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{_({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"}),t&&(0,b.JO)(t,null,r||null,null,null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),g&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Enter Team ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_id,onChange:e=>ek("team_id",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:f.organization_id||"",onValueChange:e=>ek("organization_id",e),placeholder:"Select Organization",children:null==i?void 0:i.map(e=>(0,m.jsx)(el.Z,{value:e.organization_id||"",children:e.organization_alias||e.organization_id},e.organization_id))})})]})]})}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Team ID"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Organization"}),(0,m.jsx)(e7.Z,{children:"Info"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.filter(e=>!c||e.organization_id===c.organization_id).sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{X(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)})},s))}):null}),(0,m.jsx)(e6.Z,{children:e.organization_id}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].keys&&ej[e.team_id].keys.length," ","Keys"]}),(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].members_with_roles&&ej[e.team_id].members_with_roles.length," ","Members"]})]}),(0,m.jsx)(e6.Z,{children:"Admin"==n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{X(e.team_id),ee(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>ey(e.team_id),icon:eK.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),em&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:eb,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{eu(!1),ex(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==n||"Org Admin"==n?(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>ea(!0),children:"+ Create New Team"}),(0,m.jsx)(R.Z,{title:"Create Team",visible:es,width:800,footer:null,onOk:()=>{ea(!1),v.resetFields()},onCancel:()=>{ea(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Organization"," ",(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:c?c.organization_id:null,className:"mt-8",children:(0,m.jsx)(D.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{v.setFieldValue("organization_id",e),p((null==i?void 0:i.find(s=>s.organization_id===e))||null)},filterOption:(e,s)=>{var l;return!!s&&((null===(l=s.children)||void 0===l?void 0:l.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==i?void 0:i.map(e=>(0,m.jsxs)(D.default.Option,{value:e.organization_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"These are the models that your selected team has access to",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ep.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Additional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,m.jsx)(I.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:e_.map(e=>({value:e,label:e}))})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lC,{accessToken:t,userID:r})}),(0,eZ.tY)(n||"")&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lS,{accessToken:t,userID:r||"",userRole:n||""})})]})]})})},lA=e=>{var s,l;let{organizationId:t,onClose:a,accessToken:r,is_org_admin:n,is_proxy_admin:i,userModels:o,editOrg:d}=e,[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!0),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=n||i,T=async()=>{try{if(p(!0),!r)return;let e=await (0,b.t$)(r,t);h(e)}catch(e){F.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{p(!1)}};(0,u.useEffect)(()=>{T()},[t,r]);let A=async e=>{try{if(null==r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.vh)(r,t,s),F.ZP.success("Organization member added successfully"),v(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},E=async e=>{try{if(!r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.LY)(r,t,s),F.ZP.success("Organization member updated successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},L=async e=>{try{if(!r)return;await (0,b.Sb)(r,t,e.user_id),F.ZP.success("Organization member deleted successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},R=async e=>{try{if(!r)return;let s={organization_id:t,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,b.VA)(r,s),F.ZP.success("Organization settings updated successfully"),f(!1),T()}catch(e){F.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return x?(0,m.jsx)("div",{className:"p-4",children:"Loading..."}):c?(0,m.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:a,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:c.organization_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:c.organization_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:d?2:0,children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Members"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Organization Details"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Created: ",new Date(c.created_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Updated: ",new Date(c.updated_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Created By: ",c.created_by]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",c.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===c.litellm_budget_table.max_budget?"Unlimited":"$".concat(c.litellm_budget_table.max_budget)]}),c.litellm_budget_table.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",c.litellm_budget_table.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]}),c.litellm_budget_table.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",c.litellm_budget_table.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:null===(s=c.teams)||void 0===s?void 0:s.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e.team_id},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Created At"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:null===(l=c.members)||void 0===l?void 0:l.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_role})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["$",e.spend.toFixed(6)]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,m.jsx)(e6.Z,{children:k&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{w({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),Z(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{L(e)}})]})})]},s))})]})}),k&&(0,m.jsx)(C.Z,{onClick:()=>{v(!0)},children:"Add Member"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Organization Settings"}),k&&!j&&(0,m.jsx)(C.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,m.jsxs)(M.Z,{form:g,onFinish:R,initialValues:{organization_alias:c.organization_alias,models:c.models,tpm_limit:c.litellm_budget_table.tpm_limit,rpm_limit:c.litellm_budget_table.rpm_limit,max_budget:c.litellm_budget_table.max_budget,budget_duration:c.litellm_budget_table.budget_duration,metadata:c.metadata?JSON.stringify(c.metadata,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization Name"}),(0,m.jsx)("div",{children:c.organization_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{className:"font-mono",children:c.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(c.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==c.litellm_budget_table.max_budget?"$".concat(c.litellm_budget_table.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",c.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,m.jsx)(sK,{isVisible:_,onCancel:()=>v(!1),onSubmit:A,accessToken:r,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,m.jsx)(sV,{visible:y,onCancel:()=>Z(!1),onSubmit:E,initialData:N,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,m.jsx)("div",{className:"p-4",children:"Organization not found"})};let lE=async(e,s)=>{s(await (0,b.r6)(e))};var lP=e=>{let{organizations:s,userRole:l,userModels:t,accessToken:a,lastRefreshed:r,handleRefreshClick:n,currentOrg:i,guardrailsList:o=[],setOrganizations:d,premiumUser:c}=e,[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(!1),[N]=M.Z.useForm();(0,u.useEffect)(()=>{0===s.length&&a&&lE(a,d)},[s,a]);let w=e=>{e&&(v(e),f(!0))},T=async()=>{if(_&&a)try{await (0,b.cq)(a,_),F.ZP.success("Organization deleted successfully"),f(!1),v(null),lE(a,d)}catch(e){console.error("Error deleting organization:",e)}},A=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,b.H1)(a,e),Z(!1),N.resetFields(),lE(a,d)}catch(e){console.error("Error creating organization:",e)}};return c?h?(0,m.jsx)(lA,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===l,userModels:t,editOrg:p}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsx)("div",{className:"flex",children:(0,m.jsx)(eM.Z,{children:"Your Organizations"})}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[r&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",r]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:n})]})]}),(0,m.jsx)(eU.Z,{children:(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(P.Z,{children:"Click on “Organization ID” to view organization details."}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Organization ID"}),(0,m.jsx)(e7.Z,{children:"Organization Name"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"TPM / RPM Limits"}),(0,m.jsx)(e7.Z,{children:"Info"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var s,t,a,r,n,i,o,d,c;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.organization_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(s=e.organization_id)||void 0===s?void 0:s.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{children:e.organization_alias}),(0,m.jsx)(e6.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{children:e.spend}),(0,m.jsx)(e6.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(r=e.litellm_budget_table)||void 0===r?void 0:r.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{children:Array.isArray(e.models)&&(0,m.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)},s))})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.tpm_limit:"Unlimited",(0,m.jsx)("br",{}),"RPM: ",(null===(o=e.litellm_budget_table)||void 0===o?void 0:o.rpm_limit)?null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit:"Unlimited"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[(null===(c=e.members)||void 0===c?void 0:c.length)||0," Members"]})}),(0,m.jsx)(e6.Z,{children:"Admin"===l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>w(e.organization_id),icon:eK.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===l||"Org Admin"===l)&&(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>Z(!0),children:"+ Create New Organization"}),(0,m.jsx)(R.Z,{title:"Create Organization",visible:y,width:800,footer:null,onCancel:()=>{Z(!1),N.resetFields()},children:(0,m.jsxs)(M.Z,{form:N,onFinish:A,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),j?(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Organization"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this organization?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:T,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})}):(0,m.jsx)(m.Fragment,{})]}):(0,m.jsx)("div",{children:(0,m.jsxs)(P.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,m.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lO=l(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lM=e=>{let{isAddSSOModalVisible:s,isInstructionsModalVisible:l,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:r,handleInstructionsOk:n,handleInstructionsCancel:i,form:o}=e,d=e=>{let s=lD[e];return s?s.fields.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,m.jsx)(z.default.Password,{}):(0,m.jsx)(I.Z,{placeholder:e.placeholder})},e.name)):null};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(R.Z,{title:"Add SSO",visible:s,width:800,footer:null,onOk:t,onCancel:a,children:(0,m.jsxs)(M.Z,{form:o,onFinish:r,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,m.jsx)(D.default,{children:Object.entries(lL).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[l&&(0,m.jsx)("img",{src:l,alt:s,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,m.jsxs)("span",{children:[s.charAt(0).toUpperCase()+s.slice(1)," SSO"]})]})},s)})})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.sso_provider!==s.sso_provider,children:e=>{let{getFieldValue:s}=e,l=s("sso_provider");return l?d(l):null}}),(0,m.jsx)(M.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,m.jsxs)(R.Z,{title:"SSO Setup Instructions",visible:l,width:800,footer:null,onOk:n,onCancel:i,children:[(0,m.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{onClick:n,children:"Done"})})]})]})},lF=l(62272),lR=l(92403),lq=l(29271),lU=l(34419);let lz=e=>{if(!e)return"An unknown error occurred";if("string"==typeof e)return e;if(e.message)try{let s=JSON.parse(e.message);if(s.error&&s.error.message)return s.error.message;return"string"==typeof s?s:JSON.stringify(s,null,2)}catch(s){return e.message}if(e.response&&e.response.data){if("string"==typeof e.response.data)return e.response.data;if(e.response.data.message)return e.response.data.message;if(e.response.data.error)return"string"==typeof e.response.data.error?e.response.data.error:e.response.data.error.message||JSON.stringify(e.response.data.error)}return String(e)};var lV=e=>{let{accessToken:s,userID:l,proxySettings:t}=e,[a]=M.Z.useForm(),[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(null),[d,c]=(0,u.useState)("");(0,u.useEffect)(()=>{let e="";c(t&&t.PROXY_BASE_URL&&void 0!==t.PROXY_BASE_URL?t.PROXY_BASE_URL:window.location.origin)},[t]);let h="".concat(d,"/scim/v2"),x=async e=>{if(!s||!l){F.ZP.error("You need to be logged in to create a SCIM token");return}try{n(!0);let t={key_alias:e.key_alias||"SCIM Access Token",team_id:null,models:[],allowed_routes:["/scim/*"]},a=await (0,b.wX)(s,l,t);o(a),F.ZP.success("SCIM token created successfully")}catch(e){console.error("Error creating SCIM token:",e),F.ZP.error("Failed to create SCIM token: "+lz(e))}finally{n(!1)}};return(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex items-center mb-4",children:(0,m.jsx)(O.Z,{children:"SCIM Configuration"})}),(0,m.jsx)(P.Z,{className:"text-gray-600",children:"System for Cross-domain Identity Management (SCIM) allows you to automatically provision and manage users and groups in LiteLLM."}),(0,m.jsx)(ly.Z,{}),(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"1"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lF.Z,{className:"h-5 w-5 mr-2"}),"SCIM Tenant URL"]})]}),(0,m.jsx)(P.Z,{className:"text-gray-600 mb-3",children:"Use this URL in your identity provider SCIM integration settings."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:h,disabled:!0,className:"flex-grow"}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>F.ZP.success("URL copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"ml-2 flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"2"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-5 w-5 mr-2"}),"Authentication Token"]})]}),(0,m.jsx)(lO.Z,{title:"Using SCIM",color:"blue",className:"mb-4",children:"You need a SCIM token to authenticate with the SCIM API. Create one below and use it in your SCIM provider configuration."}),i?(0,m.jsxs)(eD.Z,{className:"border border-yellow-300 bg-yellow-50",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 text-yellow-800",children:[(0,m.jsx)(lq.Z,{className:"h-5 w-5 mr-2"}),(0,m.jsx)(O.Z,{className:"text-lg text-yellow-800",children:"Your SCIM Token"})]}),(0,m.jsx)(P.Z,{className:"text-yellow-800 mb-4 font-medium",children:"Make sure to copy this token now. You will not be able to see it again."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:i.token,className:"flex-grow mr-2 bg-white",type:"password",disabled:!0}),(0,m.jsx)(L.CopyToClipboard,{text:i.token,onCopy:()=>F.ZP.success("Token copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]}),(0,m.jsxs)(C.Z,{className:"mt-4 flex items-center",variant:"secondary",onClick:()=>o(null),children:[(0,m.jsx)(lU.Z,{className:"h-4 w-4 mr-1"}),"Create Another Token"]})]}):(0,m.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,m.jsxs)(M.Z,{form:a,onFinish:x,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Token Name",rules:[{required:!0,message:"Please enter a name for your token"}],children:(0,m.jsx)(I.Z,{placeholder:"SCIM Access Token"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)(C.Z,{variant:"primary",type:"submit",loading:r,className:"flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-4 w-4 mr-1"}),"Create SCIM Token"]})})]})})]})]})]})})},lK=e=>{let{searchParams:s,accessToken:l,userID:t,showSSOBanner:a,premiumUser:r,proxySettings:n}=e,[i]=M.Z.useForm(),[o]=M.Z.useForm(),{Title:d,Paragraph:c}=et.default,[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(!1),[w,k]=(0,u.useState)(!1),[S,I]=(0,u.useState)(!1),[T,A]=(0,u.useState)(!1),[E,P]=(0,u.useState)(!1),[O,L]=(0,u.useState)(!1),[D,q]=(0,u.useState)(!1),[V,K]=(0,u.useState)(!1),[B,H]=(0,u.useState)([]),[J,G]=(0,u.useState)(null);(0,h.useRouter)();let[W,Y]=(0,u.useState)(null);console.log=function(){};let $=e0(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==r){F.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(l){let e=await (0,b.PT)(l);H(e&&e.length>0?e:[X])}else H([X])}catch(e){console.error("Error fetching allowed IPs:",e),F.ZP.error("Failed to fetch allowed IPs ".concat(e)),H([X])}finally{!0===r&&L(!0)}},es=async e=>{try{if(l){await (0,b.eH)(l,e.ip);let s=await (0,b.PT)(l);H(s),F.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),F.ZP.error("Failed to add IP address ".concat(e))}finally{q(!1)}},el=async e=>{G(e),K(!0)},ea=async()=>{if(J&&l)try{await (0,b.$I)(l,J);let e=await (0,b.PT)(l);H(e.length>0?e:[X]),F.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),F.ZP.error("Failed to delete IP address ".concat(e))}finally{K(!1),G(null)}};(0,u.useEffect)(()=>{(async()=>{if(null!=l){let e=[],s=await (0,b.Xd)(l,"proxy_admin_viewer");console.log("proxy admin viewer response: ",s);let t=s.users;console.log("proxy viewers response: ".concat(t)),t.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,b.Xd)(l,"proxy_admin")).users;a.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),j(e),Y(await (0,b.lg)(l))}})()},[l]);let er=async e=>{try{if(null!=l&&null!=g){var s;F.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,b.pf)(l,e,"proxy_admin"),a=(null===(s=t.data)||void 0===s?void 0:s.user_id)||t.user_id;(0,b.XO)(l,a).then(e=>{_(e),y(!0)}),console.log("response for team create call: ".concat(t));let r=g.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),g.push(t),j(g)),i.resetFields(),k(!1)}}catch(e){console.error("Error creating the key:",e)}},en=async e=>{if(null==l)return;let s=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};s&&Object.entries(s.envVarMap).forEach(s=>{let[l,a]=s;e[l]&&(t[a]=e[l])}),(0,b.K_)(l,{environment_variables:t})};return console.log("admins: ".concat(null==g?void 0:g.length)),(0,m.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,m.jsx)(d,{level:4,children:"Admin Access "}),(0,m.jsx)(c,{children:"Go to 'Internal Users' page to add other admins."}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Security Settings"}),(0,m.jsx)(eM.Z,{children:"SCIM"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(d,{level:4,children:" ✨ Security Settings"}),(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:()=>!0===r?A(!0):F.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,m.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,m.jsx)(lM,{isAddSSOModalVisible:T,isInstructionsModalVisible:E,handleAddSSOOk:()=>{A(!1),i.resetFields()},handleAddSSOCancel:()=>{A(!1),i.resetFields()},handleShowInstructions:e=>{er(e),en(e),A(!1),P(!0)},handleInstructionsOk:()=>{P(!1)},handleInstructionsCancel:()=>{P(!1)},form:i}),(0,m.jsx)(R.Z,{title:"Manage Allowed IP Addresses",width:800,visible:O,onCancel:()=>L(!1),footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,m.jsx)(C.Z,{onClick:()=>L(!1),children:"Close"},"close")],children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"IP Address"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:B.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e}),(0,m.jsx)(e6.Z,{className:"text-right",children:e!==X&&(0,m.jsx)(C.Z,{onClick:()=>el(e),color:"red",size:"xs",children:"Delete"})})]},s))})]})}),(0,m.jsx)(R.Z,{title:"Add Allowed IP Address",visible:D,onCancel:()=>q(!1),footer:null,children:(0,m.jsxs)(M.Z,{onFinish:es,children:[(0,m.jsx)(M.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,m.jsx)(z.default,{placeholder:"Enter IP address"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,m.jsx)(R.Z,{title:"Confirm Delete",visible:V,onCancel:()=>K(!1),onOk:ea,footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>ea(),children:"Yes"},"delete"),(0,m.jsx)(C.Z,{onClick:()=>K(!1),children:"Close"},"close")],children:(0,m.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",J,"?"]})})]}),(0,m.jsxs)(lO.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,m.jsxs)("a",{href:Q,target:"_blank",children:[(0,m.jsx)("b",{children:Q})," "]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lV,{accessToken:l,userID:t,proxySettings:n})})]})]})]})},lB=l(92858);let{Title:lH}=et.default;var lJ=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)([]);(0,u.useEffect)(()=>{n()},[s]);let n=async()=>{if(s){t(!0);try{let e=await (0,b.pu)(s);r(e.settings)}catch(e){console.error("Failed to fetch email event settings:",e),F.ZP.error("Failed to fetch email event settings")}finally{t(!1)}}},i=(e,s)=>{r(a.map(l=>l.event===e?{...l,enabled:s}:l))},o=async()=>{if(s)try{await (0,b.qW)(s,{settings:a}),F.ZP.success("Email event settings updated successfully")}catch(e){console.error("Failed to update email event settings:",e),F.ZP.error("Failed to update email event settings")}},d=async()=>{if(s)try{await (0,b.jr)(s),F.ZP.success("Email event settings reset to defaults"),n()}catch(e){console.error("Failed to reset email event settings:",e),F.ZP.error("Failed to reset email event settings")}},c=e=>{if(e.includes("Virtual Key Created"))return"An email will be sent to the user when a new virtual key is created with their user ID";if(e.includes("New User Invitation"))return"An email will be sent to the email address of the user when a new user is created";{let s=e.split(/(?=[A-Z])/).join(" ").toLowerCase();return"Receive an email notification when ".concat(s)}};return(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lH,{level:4,children:"Email Notifications"}),(0,m.jsx)(P.Z,{children:"Select which events should trigger email notifications."}),(0,m.jsx)(le.Z,{}),l?(0,m.jsx)("div",{style:{textAlign:"center",padding:"20px"},children:(0,m.jsx)(lb.Z,{size:"large"})}):(0,m.jsx)("div",{className:"space-y-4",children:a.map(e=>(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(sL.Z,{checked:e.enabled,onChange:s=>i(e.event,s.target.checked)}),(0,m.jsxs)("div",{className:"ml-3",children:[(0,m.jsx)(P.Z,{children:e.event}),(0,m.jsx)("div",{className:"text-sm text-gray-500 block",children:c(e.event)})]})]},e.event))}),(0,m.jsxs)("div",{className:"mt-6 flex space-x-4",children:[(0,m.jsx)(C.Z,{onClick:o,disabled:l,children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:d,variant:"secondary",disabled:l,children:"Reset to Defaults"})]})]})};let{Title:lG}=et.default;var lW=e=>{let{accessToken:s,premiumUser:l,alerts:t}=e,a=()=>{if(!s)return;let e={};t.filter(e=>"email"===e.name).forEach(s=>{var l;Object.entries(null!==(l=s.variables)&&void 0!==l?l:{}).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));a&&a.value&&(e[l]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,b.K_)(s,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Email settings updated successfully")};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mt-6 mb-6",children:(0,m.jsx)(lJ,{accessToken:s})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lG,{level:4,children:"Email Server Settings"}),(0,m.jsxs)(P.Z,{children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,m.jsx)("br",{})]}),(0,m.jsx)("div",{className:"flex w-full",children:t.filter(e=>"email"===e.name).map((e,s)=>{var t;return(0,m.jsx)(e6.Z,{children:(0,m.jsx)("ul",{children:(0,m.jsx)(S.Z,{numItems:2,children:Object.entries(null!==(t=e.variables)&&void 0!==t?t:{}).map(e=>{let[s,t]=e;return(0,m.jsxs)("li",{className:"mx-2 my-2",children:[!0!=l&&("EMAIL_LOGO_URL"===s||"EMAIL_SUPPORT_CONTACT"===s)?(0,m.jsxs)("div",{children:[(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,m.jsxs)(P.Z,{className:"mt-2",children:[" ","✨ ",s]})}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-2",children:s}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",style:{width:"400px"}})]}),(0,m.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===s&&(0,m.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},s)})})})},s)})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>a(),children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>s&&(0,b.jE)(s,"email"),className:"mx-2",children:"Test Email Alerts"})]})]})},lY=e=>{let{alertingSettings:s,handleInputChange:l,handleResetField:t,handleSubmit:a,premiumUser:r}=e,[n]=M.Z.useForm();return(0,m.jsxs)(M.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),s=Object.entries(e).every(e=>{let[s,l]=e;return"boolean"!=typeof l&&(""===l||null==l)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(s)),s?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[s.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{align:"center",children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?r?(0,m.jsx)(M.Z.Item,{name:e.field_name,children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s)}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>l(e.field_name,s)}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}):(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,m.jsx)(M.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s),className:"p-0"}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>{l(e.field_name,s),n.setFieldsValue({[e.field_name]:s})}}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>t(e.field_name,s),children:"Reset"})})]},s)),(0,m.jsx)("div",{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Update Settings"})})]})},l$=e=>{let{accessToken:s,premiumUser:l}=e,[t,a]=(0,u.useState)([]);return(0,u.useEffect)(()=>{s&&(0,b.RQ)(s).then(e=>{a(e)})},[s]),(0,m.jsx)(lY,{alertingSettings:t,handleInputChange:(e,s)=>{let l=t.map(l=>l.field_name===e?{...l,field_value:s}:l);console.log("updatedSettings: ".concat(JSON.stringify(l))),a(l)},handleResetField:(e,l)=>{if(s)try{let s=t.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:s.field_default_value}:s);a(s)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!s||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let l={};t.forEach(e=>{l[e.field_name]=e.field_value});let a={...e,...l};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...n}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(n)));try{(0,b.jA)(s,"alerting_args",n),"boolean"==typeof r&&(!0==r?(0,b.jA)(s,"alerting",["slack"]):(0,b.jA)(s,"alerting",[])),F.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:l})},lX=l(86582);let{Title:lQ,Paragraph:l0}=et.default;console.log=function(){};var l1=e=>{let{accessToken:s,userRole:l,userID:t,premiumUser:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h]=M.Z.useForm(),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)({}),[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(!1),[T,A]=(0,u.useState)([]),[E,O]=(0,u.useState)(null),[L,q]=(0,u.useState)([]),[z,V]=(0,u.useState)(!1),[K,B]=(0,u.useState)(null),H=e=>{Z.includes(e)?N(Z.filter(s=>s!==e)):N([...Z,e])},J={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,u.useEffect)(()=>{s&&l&&t&&(0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e),n(e.callbacks),A(e.available_callbacks);let s=e.alerts;if(console.log("alerts_data",s),s&&s.length>0){let e=s[0];console.log("_alert_info",e);let l=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",l),N(e.active_alerts),_(l),y(e.alerts_to_webhook)}o(s)})},[s,l,t]);let G=e=>Z&&Z.includes(e),W=async e=>{if(!s)return;let l={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(l[s]=t)});try{await (0,b.K_)(s,{environment_variables:l}),F.ZP.success("Callback added successfully"),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},Y=async e=>{if(!s)return;let l=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[s,l]=e;"callback"!==s&&(t[s]=l)});try{await (0,b.K_)(s,{environment_variables:t,litellm_settings:{success_callback:[l]}}),F.ZP.success("Callback ".concat(l," added successfully")),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},$=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",T),e&&e.litellm_callback_params?(q(e.litellm_callback_params),console.log("selectedCallbackParams",L)):q([])};return s?(console.log("callbacks: ".concat(r)),(0,m.jsxs)("div",{className:"w-full mx-4",children:[(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Logging Callbacks"}),(0,m.jsx)(eM.Z,{value:"2",children:"Alerting Types"}),(0,m.jsx)(eM.Z,{value:"3",children:"Alerting Settings"}),(0,m.jsx)(eM.Z,{value:"4",children:"Email Alerts"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(lQ,{level:4,children:"Active Logging Callbacks"}),(0,m.jsx)(S.Z,{numItems:2,children:(0,m.jsx)(eD.Z,{className:"max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e7.Z,{children:"Callback Name"})})}),(0,m.jsx)(e3.Z,{children:r.map((e,l)=>(0,m.jsxs)(e9.Z,{className:"flex justify-between",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.name})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"flex justify-between",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{B(e),V(!0)}}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},l))})]})})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>k(!0),children:"Add Callback"})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(P.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,m.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{children:"Slack Webhook URL"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(J).map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:"region_outage_alerts"==l?a?(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)}):(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:l,type:"password",defaultValue:v&&v[l]?v[l]:f})})]},s)})})]}),(0,m.jsx)(C.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!s)return;let e={};Object.entries(J).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));console.log("key",l),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[l]=r}),console.log("updatedAlertToWebhooks",e);let l={general_settings:{alert_to_webhook_url:e,alert_types:Z}};console.log("payload",l);try{(0,b.K_)(s,l)}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(l$,{accessToken:s,premiumUser:a})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lW,{accessToken:s,premiumUser:a,alerts:i})})]})]})}),(0,m.jsxs)(R.Z,{title:"Add Logging Callback",visible:w,width:800,onCancel:()=>k(!1),footer:null,children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,m.jsx)(M.Z,{form:h,onFinish:Y,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lX.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,m.jsx)(D.default,{onChange:e=>{let s=T[e];s&&(console.log(s.ui_callback_name),$(s))},children:T&&Object.values(T).map(e=>(0,m.jsx)(el.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),L&&L.map(e=>(0,m.jsx)(lX.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,m.jsx)(I.Z,{type:"password"})},e)),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,m.jsx)(R.Z,{visible:z,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>V(!1),footer:null,children:(0,m.jsxs)(M.Z,{form:h,onFinish:W,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(m.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[s,l]=e;return(0,m.jsx)(lX.Z,{label:s,name:s,children:(0,m.jsx)(I.Z,{type:"password",defaultValue:l})},s)})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},l2=l(92414),l4=l(46030);let{Option:l5}=D.default;var l3=e=>{let{models:s,accessToken:l,routerSettings:t,setRouterSettings:a}=e,[r]=M.Z.useForm(),[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Add Fallbacks"}),(0,m.jsx)(R.Z,{title:"Add Fallbacks",visible:n,width:800,footer:null,onOk:()=>{i(!1),r.resetFields()},onCancel:()=>{i(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:e=>{console.log(e);let{model_name:s,models:n}=e,o=[...t.fallbacks||[],{[s]:n}],d={...t,fallbacks:o};console.log(d);try{(0,b.K_)(l,{router_settings:d}),a(d)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully"),i(!1),r.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,m.jsx)(eO.Z,{defaultValue:o,children:s&&s.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>d(e),children:e},s))})}),(0,m.jsx)(M.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,m.jsx)(l2.Z,{value:s,children:s&&s.filter(e=>e!=o).map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},l6=l(26433);async function l8(e,s){console.log=function(){},console.log("isLocal:",!1);let l=window.location.origin,t=new l6.ZP.OpenAI({apiKey:s,baseURL:l,dangerouslyAllowBrowser:!0});try{let s=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});F.ZP.success((0,m.jsxs)("span",{children:["Test model=",(0,m.jsx)("strong",{children:e}),", received model=",(0,m.jsx)("strong",{children:s.model}),". See"," ",(0,m.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l7={ttl:3600,lowest_latency_buffer:0},l9=e=>{let{selectedStrategy:s,strategyArgs:l,paramExplanation:t}=e;return(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,m.jsx)(A.Z,{children:"latency-based-routing"==s?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(l).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[s]})]}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]})}):(0,m.jsx)(P.Z,{children:"No specific settings"})})]})};var te=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,n]=(0,u.useState)({}),[i,o]=(0,u.useState)({}),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(null),Z={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,u.useEffect)(()=>{s&&l&&t&&((0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e);let s=e.router_settings;"model_group_retry_policy"in s&&delete s.model_group_retry_policy,n(s)}),(0,b.YU)(s).then(e=>{c(e)}))},[s,l,t]);let N=async e=>{if(!s)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(r.fallbacks));let l=r.fallbacks.map(s=>(e in s&&delete s[e],s)).filter(e=>Object.keys(e).length>0),t={...r,fallbacks:l};try{await (0,b.K_)(s,{router_settings:t}),n(t),F.ZP.success("Router settings updated successfully")}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}},w=(e,s)=>{c(d.map(l=>l.field_name===e?{...l,field_value:s}:l))},T=(e,l)=>{if(!s)return;let t=d[l].field_value;if(null!=t&&void 0!=t)try{(0,b.jA)(s,e,t);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:!0}:s);c(l)}catch(e){}},A=(e,l)=>{if(s)try{(0,b.ao)(s,e);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:null}:s);c(l)}catch(e){}},E=e=>{if(!s)return;console.log("router_settings",e);let l=Object.fromEntries(Object.entries(e).map(e=>{let[s,l]=e;if("routing_strategy_args"!==s&&"routing_strategy"!==s){var t;return[s,(null===(t=document.querySelector('input[name="'.concat(s,'"]')))||void 0===t?void 0:t.value)||l]}if("routing_strategy"==s)return[s,f];if("routing_strategy_args"==s&&"latency-based-routing"==f){let e={},s=document.querySelector('input[name="lowest_latency_buffer"]'),l=document.querySelector('input[name="ttl"]');return(null==s?void 0:s.value)&&(e.lowest_latency_buffer=Number(s.value)),(null==l?void 0:l.value)&&(e.ttl=Number(l.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",l);try{(0,b.K_)(s,{router_settings:l})}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully")};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Loadbalancing"}),(0,m.jsx)(eM.Z,{value:"2",children:"Fallbacks"}),(0,m.jsx)(eM.Z,{value:"3",children:"General"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,m.jsx)(O.Z,{children:"Router Settings"}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(r).filter(e=>{let[s,l]=e;return"fallbacks"!=s&&"context_window_fallbacks"!=s&&"routing_strategy_args"!=s}).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:Z[s]})]}),(0,m.jsx)(e6.Z,{children:"routing_strategy"==s?(0,m.jsxs)(eO.Z,{defaultValue:l,className:"w-full max-w-md",onValueChange:_,children:[(0,m.jsx)(el.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,m.jsx)(el.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,m.jsx)(el.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]}),(0,m.jsx)(l9,{selectedStrategy:f,strategyArgs:r&&r.routing_strategy_args&&Object.keys(r.routing_strategy_args).length>0?r.routing_strategy_args:l7,paramExplanation:Z})]}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>E(r),children:"Save Changes"})})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Model Name"}),(0,m.jsx)(e7.Z,{children:"Fallbacks"})]})}),(0,m.jsx)(e3.Z,{children:r.fallbacks&&r.fallbacks.map((e,l)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:t}),(0,m.jsx)(e6.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{onClick:()=>l8(t,s),children:"Test Fallback"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>N(t)})})]},l.toString()+t)}))})]}),(0,m.jsx)(l3,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:s,routerSettings:r,setRouterSettings:n})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"}),(0,m.jsx)(e7.Z,{children:"Status"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:d.filter(e=>"TypedDictionary"!==e.field_type).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,m.jsx)(e6.Z,{children:"Integer"==e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>w(e.field_name,s)}):null}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{onClick:()=>T(e.field_name,s),children:"Update"}),(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>A(e.field_name,s),children:"Reset"})]})]},s))})]})})})]})]})}):null},ts=l(93142),tl=e=>{let{value:s={},onChange:l}=e,[t,a]=(0,u.useState)(Object.entries(s)),r=e=>{let s=t.filter((s,l)=>l!==e);a(s),null==l||l(Object.fromEntries(s))},n=(e,s,r)=>{let n=[...t];n[e]=[s,r],a(n),null==l||l(Object.fromEntries(n))};return(0,m.jsxs)("div",{children:[t.map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(ts.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,m.jsx)(I.Z,{placeholder:"Header Name",value:l,onChange:e=>n(s,e.target.value,t)}),(0,m.jsx)(I.Z,{placeholder:"Header Value",value:t,onChange:e=>n(s,l,e.target.value)}),(0,m.jsx)(s$.Z,{onClick:()=>r(s)})]},s)}),(0,m.jsx)(U.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,m.jsx)(sX.Z,{}),children:"Add Header"})]})};let{Option:tt}=D.default;var ta=e=>{let{accessToken:s,setPassThroughItems:l,passThroughItems:t}=e,[a]=M.Z.useForm(),[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>n(!0),children:"+ Add Pass-Through Endpoint"}),(0,m.jsx)(R.Z,{title:"Add Pass-Through Endpoint",visible:r,width:800,footer:null,onOk:()=>{n(!1),a.resetFields()},onCancel:()=>{n(!1),a.resetFields()},children:(0,m.jsxs)(M.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,b.Vt)(s,e),l(r)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("Pass through endpoint successfully added"),n(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,m.jsx)(tl,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},tr=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,n]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&l&&t&&(0,b.mp)(s).then(e=>{n(e.endpoints)})},[s,l,t]);let i=(e,l)=>{if(s)try{(0,b.EG)(s,e);let l=r.filter(s=>s.path!==e);n(l),F.ZP.success("Endpoint deleted successfully.")}catch(e){}};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsx)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Path"}),(0,m.jsx)(e7.Z,{children:"Target"}),(0,m.jsx)(e7.Z,{children:"Headers"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:r.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.path})}),(0,m.jsx)(e6.Z,{children:e.target}),(0,m.jsx)(e6.Z,{children:JSON.stringify(e.headers)}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>i(e.path,s),children:"Reset"})})]},s))})]}),(0,m.jsx)(ta,{accessToken:s,setPassThroughItems:n,passThroughItems:r})]})})}):null},tn=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a}=e,[r]=M.Z.useForm(),n=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call");let s=await (0,b.Zr)(l,e);console.log("key create Response:",s),a(e=>e?[...e,s]:[s]),F.ZP.success("API Key Created"),r.resetFields()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Create Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),r.resetFields()},onCancel:()=>{t(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ti=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a,existingBudget:r,handleUpdateCall:n}=e;console.log("existingBudget",r);let[i]=M.Z.useForm();(0,u.useEffect)(()=>{i.setFieldsValue(r)},[r,i]);let o=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call"),t(!0);let s=await (0,b.qI)(l,e);a(e=>e?[...e,s]:[s]),F.ZP.success("Budget Updated"),i.resetFields(),n()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Edit Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,m.jsxs)(M.Z,{form:i,onFinish:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:r,children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})},to=l(17906),td=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&(0,b.O3)(s).then(e=>{d(e)})},[s]);let c=async(e,l)=>{console.log("budget_id",e),null!=s&&(i(o.find(s=>s.budget_id===e)||null),r(!0))},h=async(e,l)=>{if(null==s)return;F.ZP.info("Request made"),await (0,b.NV)(s,e);let t=[...o];t.splice(l,1),d(t),F.ZP.success("Budget Deleted.")},x=async()=>{null!=s&&(0,b.O3)(s).then(e=>{d(e)})};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)(C.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,m.jsx)(tn,{accessToken:s,isModalVisible:l,setIsModalVisible:t,setBudgetList:d}),n&&(0,m.jsx)(ti,{accessToken:s,isModalVisible:a,setIsModalVisible:r,setBudgetList:d,existingBudget:n,handleUpdateCall:x}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Create a budget to assign to customers."}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Budget ID"}),(0,m.jsx)(e7.Z,{children:"Max Budget"}),(0,m.jsx)(e7.Z,{children:"TPM"}),(0,m.jsx)(e7.Z,{children:"RPM"})]})}),(0,m.jsx)(e3.Z,{children:o.slice().sort((e,s)=>new Date(s.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.budget_id}),(0,m.jsx)(e6.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,m.jsx)(e6.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,m.jsx)(e6.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>c(e.budget_id,s)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>h(e.budget_id,s)})]},s))})]})]}),(0,m.jsxs)("div",{className:"mt-5",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"How to use budget id"}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Assign Budget to Customer"}),(0,m.jsx)(eM.Z,{children:"Test it (Curl)"}),(0,m.jsx)(eM.Z,{children:"Test it (OpenAI SDK)"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},tc=l(77398),tm=l.n(tc);function tu(e){let{data:s=[],columns:l,getRowCanExpand:t,renderSubComponent:a,isLoading:r=!1,loadingMessage:n="\uD83D\uDE85 Loading logs...",noDataMessage:i="No logs found"}=e,o=(0,e2.b7)({data:s,columns:l,getRowCanExpand:t,getRowId:(e,s)=>{var l;return null!==(l=null==e?void 0:e.request_id)&&void 0!==l?l:String(s)},getCoreRowModel:(0,e4.sC)(),getExpandedRowModel:(0,e4.rV)()});return(0,m.jsx)("div",{className:"rounded-lg custom-border",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:r?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:n})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:i})})})})})]})})}let th=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},tx=e=>{let{utcTime:s}=e;return(0,m.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:th(s)})},tp=(e,s)=>{var l,t;return(null===(t=e.metadata)||void 0===t?void 0:null===(l=t.mcp_tool_call_metadata)||void 0===l?void 0:l.mcp_server_logo_url)?e.metadata.mcp_tool_call_metadata.mcp_server_logo_url:s?sm(s).logo:""},tg=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,m.jsx)(()=>{let[e,l]=u.useState(s.getIsExpanded()),t=u.useCallback(()=>{l(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,m.jsx)("button",{onClick:t,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,m.jsx)("svg",{className:"w-4 h-4 transform transition-transform duration-75 ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,m.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Time",accessorKey:"startTime",cell:e=>(0,m.jsx)(tx,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let s="failure"!==(e.getValue()||"Success").toLowerCase();return(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(s?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s?"Success":"Failure"})}},{header:"Session ID",accessorKey:"session_id",cell:e=>{let s=String(e.getValue()||""),l=e.row.original.onSessionClick;return(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal text-xs max-w-[15ch] truncate block",onClick:()=>null==l?void 0:l(s),children:String(e.getValue()||"")})})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)("span",{className:"font-mono text-xs max-w-[15ch] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,m.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let s=String(e.getValue()||"-"),l=e.row.original.onKeyHashClick;return(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsx)("span",{className:"font-mono max-w-[15ch] truncate block cursor-pointer hover:text-blue-600",onClick:()=>null==l?void 0:l(s),children:s})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Model",accessorKey:"model",cell:e=>{let s=e.row.original,l=s.custom_llm_provider,t=String(e.getValue()||"");return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:tp(s,l),alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(Y.Z,{title:t,children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:t})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let s=e.row.original;return(0,m.jsxs)("span",{className:"text-sm",children:[String(s.total_tokens||"0"),(0,m.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(s.prompt_tokens||"0"),"+",String(s.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"End User",accessorKey:"end_user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let s=e.getValue();if(!s||0===Object.keys(s).length)return"-";let l=Object.entries(s),t=l[0],a=l.slice(1);return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,m.jsx)(Y.Z,{title:(0,m.jsx)("div",{className:"flex flex-col gap-1",children:l.map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{children:[s,": ",String(l)]},s)})}),children:(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],tj=async(e,s,l,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,s],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,b.qk)(l,e.request_id,s);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}};function tf(e){let{row:s,hasMessages:l,hasResponse:t,hasError:a,errorInfo:r,getRawRequest:n,formattedResponse:i}=e;return(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,m.jsx)("button",{onClick:()=>{try{navigator.clipboard.writeText(JSON.stringify(n(),null,2)),F.ZP.success("Request copied to clipboard")}catch(e){F.ZP.error("Failed to copy request")}},className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(n(),null,2)})})]}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsxs)("h3",{className:"text-lg font-medium",children:["Response",a&&(0,m.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==r?void 0:r.error_code)||400]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(i(),null,2)),F.ZP.success("Response copied to clipboard")},className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!t,children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:t?(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(i(),null,2)}):(0,m.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]})}let t_=e=>{var s;let{errorInfo:l}=e,[t,a]=u.useState({}),[r,n]=u.useState(!1),i=e=>{a(s=>({...s,[e]:!s[e]}))},o=l.traceback&&(s=l.traceback)?Array.from(s.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let l=e[1],t=e[2],a=l.split("/").pop()||l,r=e.index||0,n=s.indexOf('File "',r+1),i=n>-1?s.substring(r,n).trim():s.substring(r).trim(),o=i.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:l,fileName:a,lineNumber:t,code:d,inFunction:i.includes(" in ")?i.split(" in ")[1].split("\n")[0]:""}}):[];return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,m.jsx)("span",{className:"text-red-700",children:l.error_class||"Unknown Error"})]}),(0,m.jsxs)("div",{className:"flex mt-2",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20 flex-shrink-0",children:"Message:"}),(0,m.jsx)("span",{className:"text-red-700 break-words whitespace-pre-wrap",children:l.error_message||"Unknown error occurred"})]})]}),l.traceback&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,m.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsx)("button",{onClick:()=>{let e=!r;if(n(e),o.length>0){let s={};o.forEach((l,t)=>{s[t]=e}),a(s)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:r?"Collapse All":"Expand All"}),(0,m.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(l.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,m.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,m.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:o.map((e,s)=>(0,m.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,m.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>i(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,m.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,m.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,m.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,m.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[s]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[s]||!1)&&e.code&&(0,m.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},s))})]})]})]})},tv=e=>{let{show:s}=e;return s?(0,m.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,m.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,m.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,m.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,m.jsxs)("div",{children:[(0,m.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,m.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,m.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,m.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,m.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};var ty=l(35829);let tb=e=>{let{sessionId:s,logs:l,onBack:t}=e,[a,r]=(0,u.useState)(null),n=l.reduce((e,s)=>e+(s.spend||0),0),i=l.reduce((e,s)=>e+(s.total_tokens||0),0),o=l.length>0?new Date(l[0].startTime):new Date;return(((l.length>0?new Date(l[l.length-1].endTime):new Date).getTime()-o.getTime())/1e3).toFixed(2),l.map(e=>({time:new Date(e.startTime).toISOString(),tokens:e.total_tokens||0,cost:e.spend||0})),(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)("div",{className:"flex items-center space-x-4",children:(0,m.jsxs)("button",{onClick:t,className:"flex items-center text-gray-600 hover:text-gray-900 transition-colors",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),"Back to All Logs"]})}),(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsx)("h1",{className:"text-2xl font-semibold text-gray-900",children:"Session Details"}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500 font-mono",children:s}),(0,m.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/ui_logs_sessions",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Get started with session management here",(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(ty.Z,{children:l.length})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Cost"}),(0,m.jsxs)(ty.Z,{children:["$",n.toFixed(4)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(ty.Z,{children:i})]})]}),(0,m.jsx)(O.Z,{children:"Session Logs"}),(0,m.jsx)("div",{className:"mt-4",children:(0,m.jsx)(tu,{columns:tg,data:l,renderSubComponent:tS,getRowCanExpand:()=>!0,loadingMessage:"Loading logs...",noDataMessage:"No logs found"})})]})};function tZ(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)({});if(!s||0===s.length)return null;let n=e=>new Date(1e3*e).toLocaleString(),i=(e,s)=>"".concat(((s-e)*1e3).toFixed(2),"ms"),o=(e,s)=>{let l="".concat(e,"-").concat(s);r(e=>({...e,[l]:!e[l]}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Vector Store Requests"})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsx)("div",{className:"p-4",children:s.map((e,s)=>(0,m.jsxs)("div",{className:"mb-6 last:mb-0",children:[(0,m.jsx)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Query:"}),(0,m.jsx)("span",{className:"font-mono",children:e.query})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Vector Store ID:"}),(0,m.jsx)("span",{className:"font-mono",children:e.vector_store_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{className:"flex items-center",children:(()=>{let{logo:s,displayName:l}=sm(e.custom_llm_provider);return(0,m.jsxs)(m.Fragment,{children:[s&&(0,m.jsx)("img",{src:s,alt:"".concat(l," logo"),className:"h-5 w-5 mr-2"}),l]})})()})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:n(e.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:n(e.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsx)("span",{children:i(e.start_time,e.end_time)})]})]})]})}),(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Search Results"}),(0,m.jsx)("div",{className:"space-y-2",children:e.vector_store_search_response.data.map((e,l)=>{let t=a["".concat(s,"-").concat(l)]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center p-3 bg-gray-50 cursor-pointer",onClick:()=>o(s,l),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsxs)("span",{className:"font-medium mr-2",children:["Result ",l+1]}),(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["Score: ",(0,m.jsx)("span",{className:"font-mono",children:e.score.toFixed(4)})]})]})]}),t&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:e.content.map((e,s)=>(0,m.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,m.jsx)("div",{className:"text-xs text-gray-500 mb-1",children:e.type}),(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded",children:e.text})]},s))})]},l)})})]},s))})]})}function tN(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)(!0),[n,i]=(0,u.useState)({});if(!s)return null;let o=s.masked_entity_count?Object.values(s.masked_entity_count).reduce((e,s)=>e+s,0):0,d=e=>new Date(1e3*e).toLocaleString(),c=e=>{i(s=>({...s,[e]:!s[e]}))},h=e=>e>=.8?"text-green-600":"text-yellow-600";return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Guardrail Information"}),(0,m.jsx)("span",{className:"ml-3 px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status}),o>0&&(0,m.jsxs)("span",{className:"ml-3 px-2 py-1 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[o," masked ",1===o?"entity":"entities"]})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:[(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail Name:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_name})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Mode:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_mode})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:d(s.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:d(s.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsxs)("span",{children:[s.duration.toFixed(4),"s"]})]})]})]}),s.masked_entity_count&&Object.keys(s.masked_entity_count).length>0&&(0,m.jsxs)("div",{className:"mt-4 pt-4 border-t",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Masked Entity Summary"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(s.masked_entity_count).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-3 py-1.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[s,": ",l]},s)})})]})]}),s.guardrail_response&&s.guardrail_response.length>0&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 cursor-pointer",onClick:()=>r(!a),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(a?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("h4",{className:"font-medium",children:["Detected Entities (",s.guardrail_response.length,")"]})]}),a&&(0,m.jsx)("div",{className:"space-y-2",children:s.guardrail_response.map((e,s)=>{let l=n[s]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>c(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("span",{className:"font-medium mr-2",children:e.entity_type}),(0,m.jsxs)("span",{className:"font-mono ".concat(h(e.score)),children:["Score: ",e.score.toFixed(2)]})]}),(0,m.jsxs)("span",{className:"text-xs text-gray-500",children:["Position: ",e.start,"-",e.end]})]}),l&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Entity Type:"}),(0,m.jsx)("span",{children:e.entity_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Position:"}),(0,m.jsxs)("span",{children:["Characters ",e.start,"-",e.end]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Confidence:"}),(0,m.jsx)("span",{className:h(e.score),children:e.score.toFixed(2)})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[e.recognition_metadata&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Recognizer:"}),(0,m.jsx)("span",{children:e.recognition_metadata.recognizer_name})]}),(0,m.jsxs)("div",{className:"flex overflow-hidden",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Identifier:"}),(0,m.jsx)("span",{className:"truncate text-xs font-mono",children:e.recognition_metadata.recognizer_identifier})]})]}),e.analysis_explanation&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Explanation:"}),(0,m.jsx)("span",{children:e.analysis_explanation})]})]})]})})]},s)})})]})]})]})}let tw={TEAM_ID:"Team ID",KEY_HASH:"Key Hash",REQUEST_ID:"Request ID",MODEL:"Model",USER_ID:"User ID",STATUS:"Status",KEY_ALIAS:"Key Alias"};function tk(e){var s,l,t;let{accessToken:a,token:r,userRole:n,userID:i,allTeams:o}=e,[d,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(!1),[p,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(1),[v]=(0,u.useState)(50),y=(0,u.useRef)(null),Z=(0,u.useRef)(null),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(tm()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,C]=(0,u.useState)(tm()().format("YYYY-MM-DDTHH:mm")),[I,T]=(0,u.useState)(!1),[A,E]=(0,u.useState)(!1),[P,O]=(0,u.useState)(""),[L,D]=(0,u.useState)(""),[M,F]=(0,u.useState)(""),[R,q]=(0,u.useState)(""),[U,z]=(0,u.useState)(""),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)(null),[J,G]=(0,u.useState)(""),[W,Y]=(0,u.useState)(n&&eZ.lo.includes(n)),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(null),es=(0,g.NL)();(0,u.useEffect)(()=>{(async()=>{B&&a&&K({...(await (0,b.t0)(a,B)).info,token:B,api_key:B})})()},[B,a]),(0,u.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),Z.current&&!Z.current.contains(e.target)&&x(!1),N.current&&!N.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,u.useEffect)(()=>{n&&eZ.lo.includes(n)&&Y(!0)},[n]);let el=(0,eY.a)({queryKey:["logs","table",f,v,w,S,M,R,W?i:null,J,U],queryFn:async()=>{if(!a||!r||!n||!i)return{data:[],total:0,page:1,page_size:v,total_pages:0};let e=tm()(w).utc().format("YYYY-MM-DD HH:mm:ss"),s=I?tm()(S).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss"),l=await (0,b.h3)(a,R||void 0,M||void 0,void 0,e,s,f,v,W?i:void 0,J,U);return await tj(l.data,e,a,es),l.data=l.data.map(s=>{let l=es.getQueryData(["logDetails",s.request_id,e]);return(null==l?void 0:l.messages)&&(null==l?void 0:l.response)&&(s.messages=l.messages,s.response=l.response),s}),l},enabled:!!a&&!!r&&!!n&&!!i,refetchInterval:5e3,refetchIntervalInBackground:!0}),{filters:et,filteredLogs:ea,allTeams:er,allKeyAliases:en,allModels:ei,handleFilterChange:eo,handleFilterReset:ed}=function(e){let{logs:s,accessToken:l,startTime:t,endTime:a,pageSize:r=25,isCustomDate:n,setCurrentPage:i,userID:o,userRole:d}=e,c=(0,u.useMemo)(()=>({[tw.TEAM_ID]:"",[tw.KEY_HASH]:"",[tw.REQUEST_ID]:"",[tw.MODEL]:"",[tw.USER_ID]:"",[tw.STATUS]:"",[tw.KEY_ALIAS]:""}),[]),[m,h]=(0,u.useState)(c),[x,p]=(0,u.useState)(s),g=(0,u.useRef)(0),j=(0,u.useCallback)(async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!l)return;let i=Date.now();g.current=i;let o=tm()(t).utc().format("YYYY-MM-DD HH:mm:ss"),d=n?tm()(a).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss");try{let t=await (0,b.h3)(l,e[tw.KEY_HASH]||void 0,e[tw.TEAM_ID]||void 0,e[tw.REQUEST_ID]||void 0,o,d,s,r,e[tw.USER_ID]||void 0,e[tw.STATUS]||void 0,e[tw.MODEL]||void 0);i===g.current&&t.data&&p(t)}catch(e){console.error("Error searching users:",e)}},[l,t,a,n,r]),f=(0,u.useMemo)(()=>eb()((e,s)=>j(e,s),300),[j]);(0,u.useEffect)(()=>()=>f.cancel(),[f]);let _=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!l)throw Error("Access token required");return await e$(l)},enabled:!!l}).data||[];(0,u.useEffect)(()=>{if(!s||!s.data){p({data:[],total:0,page:1,page_size:50,total_pages:0});return}let e=[...s.data];if(m[tw.TEAM_ID]&&(e=e.filter(e=>e.team_id===m[tw.TEAM_ID])),m[tw.STATUS]&&(e=e.filter(e=>"success"===m[tw.STATUS]?!e.status||"success"===e.status:e.status===m[tw.STATUS])),m[tw.MODEL]&&(e=e.filter(e=>e.model===m[tw.MODEL])),m[tw.KEY_HASH]&&(e=e.filter(e=>e.api_key===m[tw.KEY_HASH])),m[tw.KEY_ALIAS])try{let s=m[tw.KEY_ALIAS];s&&(e=e.filter(e=>{var l;return(null===(l=e.metadata)||void 0===l?void 0:l.user_api_key_alias)===s}))}catch(e){console.error("Error fetching key info for alias:",e)}let l={data:e,total:s.total,page:s.page,page_size:s.page_size,total_pages:s.total_pages};JSON.stringify(l)!==JSON.stringify(x)&&p(l)},[s,m,x,l]);let{data:v}=(0,eY.a)({queryKey:["allTeamsForLogFilters",l],queryFn:async()=>l&&await eX(l)||[],enabled:!!l}),{data:y=[]}=(0,eY.a)({queryKey:["allModels",l,o,d],queryFn:async()=>l&&o&&d?(await (0,b.So)(l,o,d,!1,null)).data.map(e=>e.id):[],enabled:!!l&&!!o&&!!d});return{filters:m,filteredLogs:x,allKeyAliases:_,allTeams:v,allModels:y,handleFilterChange:e=>{h(s=>{let l={...s,...e};for(let e of Object.keys(c))e in l||(l[e]=c[e]);return JSON.stringify(l)!==JSON.stringify(s)&&(i(1),f(l,1)),l})},handleFilterReset:()=>{h(c),f(c,1)}}}({logs:el.data||{data:[],total:0,page:1,page_size:v||10,total_pages:1},accessToken:a,startTime:w,endTime:S,pageSize:v,isCustomDate:I,setCurrentPage:_,userID:i,userRole:n}),ec=(0,u.useCallback)(async e=>{if(a)try{let s=(await (0,b.OD)(a,null,null,e,null,null,f,v)).keys.find(s=>s.key_alias===e);s&&q(s.token)}catch(e){console.error("Error fetching key hash for alias:",e)}},[a,f,v]);(0,u.useEffect)(()=>{a&&(et["Team ID"]?F(et["Team ID"]):F(""),G(et.Status||""),z(et.Model||""),et["Key Hash"]?q(et["Key Hash"]):et["Key Alias"]?ec(et["Key Alias"]):q(""))},[et,a,ec]);let em=(0,eY.a)({queryKey:["sessionLogs",Q],queryFn:async()=>{if(!a||!Q)return{data:[],total:0,page:1,page_size:50,total_pages:1};let e=await (0,b.XB)(a,Q);return{data:e.data||e||[],total:(e.data||e||[]).length,page:1,page_size:1e3,total_pages:1}},enabled:!!a&&!!Q});if((0,u.useEffect)(()=>{var e;(null===(e=el.data)||void 0===e?void 0:e.data)&&$&&!el.data.data.some(e=>e.request_id===$)&&X(null)},[null===(s=el.data)||void 0===s?void 0:s.data,$]),!a||!r||!n||!i)return null;let eu=ea.data.filter(e=>!d||e.request_id.includes(d)||e.model.includes(d)||e.user&&e.user.includes(d)).map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{e&&ee(e)}}))||[],eh=(null===(t=em.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{}})))||[],ex=()=>{if(I)return"".concat(tm()(w).format("MMM D, h:mm A")," - ").concat(tm()(S).format("MMM D, h:mm A"));let e=tm()(),s=tm()(w),l=e.diff(s,"minutes");if(l<=15)return"Last 15 Minutes";if(l<=60)return"Last Hour";let t=e.diff(s,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(s.format("MMM D")," - ").concat(e.format("MMM D"))},ep=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>o&&0!==o.length?o.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Status",label:"Status",isSearchable:!1,options:[{label:"Success",value:"success"},{label:"Failure",value:"failure"}]},{name:"Model",label:"Model",isSearchable:!0,searchFn:async e=>ei&&0!==ei.length?ei.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>a?(await e$(a)).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Hash",label:"Key Hash",isSearchable:!1}];return Q&&em.data?(0,m.jsx)("div",{className:"w-full p-6",children:(0,m.jsx)(tb,{sessionId:Q,logs:em.data.data,onBack:()=>ee(null)})}):(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:Q?(0,m.jsxs)(m.Fragment,{children:["Session: ",(0,m.jsx)("span",{className:"font-mono",children:Q}),(0,m.jsx)("button",{className:"ml-4 px-3 py-1 text-sm border rounded hover:bg-gray-50",onClick:()=>ee(null),children:"← Back to All Logs"})]}):"Request Logs"})}),V&&B&&V.api_key===B?(0,m.jsx)(eJ,{keyId:B,keyData:V,accessToken:a,userID:i,userRole:n,teams:o,onClose:()=>H(null)}):Q?(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsx)(tu,{columns:tg,data:eh,renderSubComponent:tS,getRowCanExpand:()=>!0})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eW,{options:ep,onApplyFilters:eo,onResetFilters:ed}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:d,onChange:e=>c(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsxs)("div",{className:"relative",ref:N,children:[(0,m.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),ex()]}),A&&(0,m.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,m.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(ex()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{C(tm()().format("YYYY-MM-DDTHH:mm")),k(tm()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),T(!1)},children:e.label},e.label)),(0,m.jsx)("div",{className:"border-t my-2"}),(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(I?"bg-blue-50 text-blue-600":""),onClick:()=>T(!I),children:"Custom Range"})]})})]}),(0,m.jsxs)("button",{onClick:()=>{el.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,m.jsx)("svg",{className:"w-4 h-4 ".concat(el.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,m.jsx)("span",{children:"Refresh"})]})]}),I&&(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:w,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,m.jsx)("span",{className:"text-gray-500",children:"to"}),(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{C(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",el.isLoading?"...":ea?(f-1)*v+1:0," ","-"," ",el.isLoading?"...":ea?Math.min(f*v,ea.total):0," ","of"," ",el.isLoading?"...":ea?ea.total:0," ","results"]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",el.isLoading?"...":f," of"," ",el.isLoading?"...":ea?ea.total_pages:1]}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:el.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.min(ea.total_pages||1,e+1)),disabled:el.isLoading||f===(ea.total_pages||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,m.jsx)(tu,{columns:tg,data:eu,renderSubComponent:tS,getRowCanExpand:()=>!0})]})]})]})}function tS(e){var s,l,t,a,r;let{row:n}=e,i=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},o=n.original.metadata||{},d="failure"===o.status,c=d?o.error_information:null,u=n.original.messages&&(Array.isArray(n.original.messages)?n.original.messages.length>0:Object.keys(n.original.messages).length>0),h=n.original.response&&Object.keys(i(n.original.response)).length>0,x=o.vector_store_request_metadata&&Array.isArray(o.vector_store_request_metadata)&&o.vector_store_request_metadata.length>0,p=n.original.metadata&&n.original.metadata.guardrail_information,g=p&&(null===(r=n.original.metadata)||void 0===r?void 0:r.guardrail_information.masked_entity_count)?Object.values(n.original.metadata.guardrail_information.masked_entity_count).reduce((e,s)=>e+("number"==typeof s?s:0),0):0;return(0,m.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,m.jsx)("span",{className:"font-mono text-sm",children:n.original.request_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,m.jsx)("span",{children:n.original.model})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model ID:"}),(0,m.jsx)("span",{children:n.original.model_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,m.jsx)("span",{children:n.original.call_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{children:n.original.custom_llm_provider||"-"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"API Base:"}),(0,m.jsx)(Y.Z,{title:n.original.api_base||"-",children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:n.original.api_base||"-"})})]}),(null==n?void 0:null===(s=n.original)||void 0===s?void 0:s.requester_ip_address)&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,m.jsx)("span",{children:null==n?void 0:null===(l=n.original)||void 0===l?void 0:l.requester_ip_address})]}),p&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail:"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-mono",children:n.original.metadata.guardrail_information.guardrail_name}),g>0&&(0,m.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[g," masked"]})]})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,m.jsxs)("span",{children:[n.original.total_tokens," (",n.original.prompt_tokens,"+",n.original.completion_tokens,")"]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,m.jsxs)("span",{children:["$",Number(n.original.spend||0).toFixed(6)]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,m.jsx)("span",{children:n.original.cache_hit})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(t=n.original.metadata)||void 0===t?void 0:t.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(a=n.original.metadata)||void 0===a?void 0:a.status)||"Success").toLowerCase()?"Success":"Failure"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:n.original.startTime})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:n.original.endTime})]})]})]})]}),(0,m.jsx)(tv,{show:!u&&!h}),(0,m.jsx)(tf,{row:n,hasMessages:u,hasResponse:h,hasError:d,errorInfo:c,getRawRequest:()=>{var e;return(null===(e=n.original)||void 0===e?void 0:e.proxy_server_request)?i(n.original.proxy_server_request):i(n.original.messages)},formattedResponse:()=>d&&c?{error:{message:c.error_message||"An error occurred",type:c.error_class||"error",code:c.error_code||"unknown",param:null}}:i(n.original.response)}),p&&(0,m.jsx)(tN,{data:n.original.metadata.guardrail_information}),x&&(0,m.jsx)(tZ,{data:o.vector_store_request_metadata}),d&&c&&(0,m.jsx)(t_,{errorInfo:c}),n.original.request_tags&&Object.keys(n.original.request_tags).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(n.original.request_tags).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[s,": ",String(l)]},s)})})})]}),n.original.metadata&&Object.keys(n.original.metadata).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(n.original.metadata,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(n.original.metadata,null,2)})})]})]})}var tC=l(92699),tI=l(14042);console.log=function(){};var tT=e=>{let{userID:s,userRole:l,accessToken:t,userSpend:a,userMaxBudget:r,selectedTeam:n}=e;console.log("userSpend: ".concat(a));let[i,o]=(0,u.useState)(null!==a?a:0),[d,c]=(0,u.useState)(n?n.max_budget:null);(0,u.useEffect)(()=>{if(n){if("Default Team"===n.team_alias)c(r);else{let e=!1;if(n.team_memberships)for(let l of n.team_memberships)l.user_id===s&&"max_budget"in l.litellm_budget_table&&null!==l.litellm_budget_table.max_budget&&(c(l.litellm_budget_table.max_budget),e=!0);e||c(n.max_budget)}}},[n,r]);let[h,x]=(0,u.useState)([]);(0,u.useEffect)(()=>{let e=async()=>{if(!t||!s||!l)return};(async()=>{try{if(null===s||null===l)return;if(null!==t){let e=(await (0,b.So)(t,s,l)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[l,t,s]),(0,u.useEffect)(()=>{null!==a&&o(a)},[a]);let p=[];n&&n.models&&(p=n.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=n.models:p&&0===p.length&&(p=h);let g=void 0!==i?i.toFixed(4):null;return console.log("spend in view user spend: ".concat(i)),(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,m.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==d?"$".concat(d," limit"):"No limit"})]})]})})};let tA=e=>{let{key:s,info:l}=e;return{token:s,...l}};var tE=e=>{let{topKeys:s,accessToken:l,userID:t,userRole:a,teams:r}=e,[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(void 0),[x,p]=(0,u.useState)("table"),g=async e=>{if(l)try{let s=await (0,b.t0)(l,e.api_key),t=tA(s);h(t),d(e.api_key),i(!0)}catch(e){console.error("Error fetching key info:",e)}},j=()=>{i(!1),d(null),h(void 0)};return u.useEffect(()=>{let e=e=>{"Escape"===e.key&&n&&j()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mb-4 flex justify-end items-center",children:(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>p("table"),className:"px-3 py-1 text-sm rounded-md ".concat("table"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Table View"}),(0,m.jsx)("button",{onClick:()=>p("chart"),className:"px-3 py-1 text-sm rounded-md ".concat("chart"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Chart View"})]})}),"chart"===x?(0,m.jsx)("div",{className:"relative",children:(0,m.jsx)(sT.Z,{className:"mt-4 h-40 cursor-pointer hover:opacity-90",data:s,index:"key_alias",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>e?"$".concat(e.toFixed(2)):"No Key Alias",onValueChange:e=>g(e),showTooltip:!0,customTooltip:e=>{var s,l,t;let a=null===(l=e.payload)||void 0===l?void 0:null===(s=l[0])||void 0===s?void 0:s.payload;return(0,m.jsx)("div",{className:"p-3 bg-black/90 shadow-lg rounded-lg text-white",children:(0,m.jsxs)("div",{className:"space-y-1.5",children:[(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Key: "}),(0,m.jsxs)("span",{className:"font-mono text-gray-100",children:[null==a?void 0:null===(t=a.api_key)||void 0===t?void 0:t.slice(0,10),"..."]})]}),(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Spend: "}),(0,m.jsxs)("span",{className:"text-white font-medium",children:["$",null==a?void 0:a.spend.toFixed(2)]})]})]})})}})}):(0,m.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,m.jsx)(tu,{columns:[{header:"Key ID",accessorKey:"api_key",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>g(e.row.original),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>e.getValue()||"-"},{header:"Spend (USD)",accessorKey:"spend",cell:e=>"$".concat(Number(e.getValue()).toFixed(2))}],data:s,renderSubComponent:()=>(0,m.jsx)(m.Fragment,{}),getRowCanExpand:()=>!1,isLoading:!1})}),n&&o&&c&&(console.log("Rendering modal with:",{isModalOpen:n,selectedKey:o,keyData:c}),(0,m.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&j()},children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-xl relative w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto min-h-[750px]",children:[(0,m.jsx)("button",{onClick:j,className:"absolute top-4 right-4 text-gray-500 hover:text-gray-700 focus:outline-none","aria-label":"Close",children:(0,m.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),(0,m.jsx)("div",{className:"p-6 h-full",children:(0,m.jsx)(eJ,{keyId:o,onClose:j,keyData:c,accessToken:l,userID:t,userRole:a,teams:r})})]})}))]})},tP=l(44851);let tO=e=>{var s,l;let{modelName:t,metrics:a}=e;return(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:a.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:a.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:a.total_tokens.toLocaleString()}),(0,m.jsxs)(P.Z,{children:[Math.round(a.total_tokens/a.total_successful_requests)," avg per successful request"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",a.total_spend.toFixed(2)]}),(0,m.jsxs)(P.Z,{children:["$",(a.total_spend/a.total_successful_requests).toFixed(3)," per successful request"]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Requests per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.api_requests"],colors:["blue"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.spend"],colors:["green"],valueFormatter:e=>"$".concat(e.toFixed(2))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Success vs Failed Requests"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Prompt Caching Metrics"}),(0,m.jsxs)("div",{className:"mb-2",children:[(0,m.jsxs)(P.Z,{children:["Cache Read: ",(null===(s=a.total_cache_read_input_tokens)||void 0===s?void 0:s.toLocaleString())||0," tokens"]}),(0,m.jsxs)(P.Z,{children:["Cache Creation: ",(null===(l=a.total_cache_creation_input_tokens)||void 0===l?void 0:l.toLocaleString())||0," tokens"]})]}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"],valueFormatter:e=>e.toLocaleString()})]})]})]})},tL=e=>{let{modelMetrics:s}=e,l=Object.keys(s).sort((e,l)=>""===e?1:""===l?-1:s[l].total_spend-s[e].total_spend),t={total_requests:0,total_successful_requests:0,total_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:{}};Object.values(s).forEach(e=>{t.total_requests+=e.total_requests,t.total_successful_requests+=e.total_successful_requests,t.total_tokens+=e.total_tokens,t.total_spend+=e.total_spend,t.total_cache_read_input_tokens+=e.total_cache_read_input_tokens||0,t.total_cache_creation_input_tokens+=e.total_cache_creation_input_tokens||0,e.daily_data.forEach(e=>{t.daily_data[e.date]||(t.daily_data[e.date]={prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,spend:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0}),t.daily_data[e.date].prompt_tokens+=e.metrics.prompt_tokens,t.daily_data[e.date].completion_tokens+=e.metrics.completion_tokens,t.daily_data[e.date].total_tokens+=e.metrics.total_tokens,t.daily_data[e.date].api_requests+=e.metrics.api_requests,t.daily_data[e.date].spend+=e.metrics.spend,t.daily_data[e.date].successful_requests+=e.metrics.successful_requests,t.daily_data[e.date].failed_requests+=e.metrics.failed_requests,t.daily_data[e.date].cache_read_input_tokens+=e.metrics.cache_read_input_tokens||0,t.daily_data[e.date].cache_creation_input_tokens+=e.metrics.cache_creation_input_tokens||0})});let a=Object.entries(t.daily_data).map(e=>{let[s,l]=e;return{date:s,metrics:l}}).sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime());return(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,m.jsx)(O.Z,{children:"Overall Usage"}),(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4 mb-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:t.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:t.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:t.total_tokens.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",t.total_spend.toFixed(2)]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]})]})]}),(0,m.jsx)(tP.Z,{defaultActiveKey:l[0],children:l.map(e=>(0,m.jsx)(tP.Z.Panel,{header:(0,m.jsxs)("div",{className:"flex justify-between items-center w-full",children:[(0,m.jsx)(O.Z,{children:s[e].label||"Unknown Item"}),(0,m.jsxs)("div",{className:"flex space-x-4 text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["$",s[e].total_spend.toFixed(2)]}),(0,m.jsxs)("span",{children:[s[e].total_requests.toLocaleString()," requests"]})]})]}),children:(0,m.jsx)(tO,{modelName:e||"Unknown Model",metrics:s[e]})},e))})]})},tD=(e,s)=>{let l=e.metadata.key_alias||"key-hash-".concat(s),t=e.metadata.team_id;return t?"".concat(l," (team_id: ").concat(t,")"):l},tM=(e,s)=>{let l={};return e.results.forEach(e=>{Object.entries(e.breakdown[s]||{}).forEach(t=>{let[a,r]=t;l[a]||(l[a]={label:"api_keys"===s?tD(r,a):a,total_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0,prompt_tokens:0,completion_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:[]}),l[a].total_requests+=r.metrics.api_requests,l[a].prompt_tokens+=r.metrics.prompt_tokens,l[a].completion_tokens+=r.metrics.completion_tokens,l[a].total_tokens+=r.metrics.total_tokens,l[a].total_spend+=r.metrics.spend,l[a].total_successful_requests+=r.metrics.successful_requests,l[a].total_failed_requests+=r.metrics.failed_requests,l[a].total_cache_read_input_tokens+=r.metrics.cache_read_input_tokens||0,l[a].total_cache_creation_input_tokens+=r.metrics.cache_creation_input_tokens||0,l[a].daily_data.push({date:e.date,metrics:{prompt_tokens:r.metrics.prompt_tokens,completion_tokens:r.metrics.completion_tokens,total_tokens:r.metrics.total_tokens,api_requests:r.metrics.api_requests,spend:r.metrics.spend,successful_requests:r.metrics.successful_requests,failed_requests:r.metrics.failed_requests,cache_read_input_tokens:r.metrics.cache_read_input_tokens||0,cache_creation_input_tokens:r.metrics.cache_creation_input_tokens||0}})})}),Object.values(l).forEach(e=>{e.daily_data.sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime())}),l};var tF=e=>{let{accessToken:s,entityType:l,entityId:t,userID:a,userRole:r,entityList:n}=e,[i,o]=(0,u.useState)({results:[],metadata:{total_spend:0,total_api_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0}}),d=tM(i,"models"),c=tM(i,"api_keys"),[h,x]=(0,u.useState)([]),[p,g]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),j=async()=>{if(!s||!p.from||!p.to)return;let e=p.from,t=p.to;if("tag"===l)o(await (0,b.Z9)(s,e,t,1,h.length>0?h:null));else if("team"===l)o(await (0,b.ol)(s,e,t,1,h.length>0?h:null));else throw Error("Invalid entity type")};(0,u.useEffect)(()=>{j()},[s,p,t,h]);let f=()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={provider:l,spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend,e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens}catch(e){console.log("Error processing provider ".concat(l,": ").concat(e))}})}),Object.values(e).filter(e=>e.spend>0).sort((e,s)=>s.spend-e.spend)},_=e=>0===h.length?e:e.filter(e=>h.includes(e.metadata.id)),v=()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.entities||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{alias:t.metadata.team_alias||l,id:l}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.total_tokens+=t.metrics.total_tokens})}),_(Object.values(e).sort((e,s)=>s.metrics.spend-e.metrics.spend))};return(0,m.jsxs)("div",{style:{width:"100%"},children:[(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:p,onValueChange:g})]}),n&&n.length>0&&(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(P.Z,{children:["Filter by ","tag"===l?"Tags":"Teams"]}),(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select ".concat("tag"===l?"tags":"teams"," to filter..."),value:h,onChange:x,options:(()=>{if(n)return n})(),className:"mt-2",allowClear:!0})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["tag"===l?"Tag":"Team"," Spend Overview"]}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Spend"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",i.metadata.total_spend.toFixed(2)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:i.metadata.total_api_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:i.metadata.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:i.metadata.total_failed_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:i.metadata.total_tokens.toLocaleString()})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...i.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let a=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:a.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Total Spend: $",a.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",a.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",a.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",a.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Tokens: ",a.metrics.total_tokens]}),(0,m.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,m.jsxs)("p",{className:"font-semibold",children:["Spend by ","tag"===l?"Tag":"Team",":"]}),Object.entries(a.breakdown.entities||{}).map(e=>{let[s,l]=e;return(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[l.metadata.team_alias||s,": $",l.metrics.spend.toFixed(2)]},s)})]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,m.jsxs)(O.Z,{children:["Spend Per ","tag"===l?"Tag":"Team"]}),(0,m.jsxs)("div",{className:"flex items-center text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["Get Started Tracking cost per ",l," "]}),(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tags",className:"text-blue-500 hover:text-blue-700 ml-1",children:"here"})]})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sT.Z,{className:"mt-4 h-52",data:v(),index:"metadata.alias",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(4)),layout:"vertical",showLegend:!1,yAxisWidth:100})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"tag"===l?"Tag":"Team"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:v().filter(e=>e.metrics.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.metadata.alias}),(0,m.jsxs)(e6.Z,{children:["$",e.metrics.spend.toFixed(4)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.metrics.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.metrics.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.metrics.total_tokens.toLocaleString()})]},e.metadata.id))})]})})]})]})})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:s,userID:a,userRole:r,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend}catch(e){console.log("Error adding spend for ".concat(l,": ").concat(e,", got metrics: ").concat(JSON.stringify(t)))}e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,...l}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)(O.Z,{children:"Provider Usage"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:f(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan","blue","indigo","violet","purple"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:f().map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:d})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:c})})]})]})]})},tR=e=>{var s,l,t,a,r,n,i,o,d,c;let{accessToken:h,userRole:x,userID:p,teams:g}=e,[j,f]=(0,u.useState)({results:[],metadata:{}}),[_,v]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),[y,Z]=(0,u.useState)([]),N=async()=>{h&&Z(Object.values(await (0,b.UM)(h)).map(e=>({label:e.name,value:e.name})))};(0,u.useEffect)(()=>{N()},[h]);let w=(null===(s=j.metadata)||void 0===s?void 0:s.total_spend)||0,C=()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{provider:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}})},I=async()=>{if(!h||!_.from||!_.to)return;let e=_.from,s=_.to;try{let l=await (0,b.xX)(h,e,s);if(l.metadata.total_pages>10)throw Error("Too many pages of data (>10). Please select a smaller date range.");if(1===l.metadata.total_pages){f(l);return}let t=[...l.results];for(let a=2;a<=l.metadata.total_pages;a++){let l=await (0,b.xX)(h,e,s,a);t.push(...l.results)}f({results:t,metadata:l.metadata})}catch(e){throw console.error("Error fetching user spend data:",e),e}};(0,u.useEffect)(()=>{I()},[h,_]);let T=tM(j,"models"),A=tM(j,"api_keys");return(0,m.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,m.jsxs)(P.Z,{className:"text-sm text-gray-500 mb-4",children:["This is the new usage dashboard. ",(0,m.jsx)("br",{})," You may see empty data, as these use ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/blob/6de348125208dd4be81ff0e5813753df2fbe9735/schema.prisma#L320",className:"text-blue-500 hover:text-blue-700 ml-1",children:"new aggregate tables"})," to allow UI to work at 1M+ spend logs. To access the old dashboard, go to Experimental ",">"," Old Usage."]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Global Usage"}):(0,m.jsx)(eM.Z,{children:"Your Usage"}),(0,m.jsx)(eM.Z,{children:"Team Usage"}),eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Tag Usage"}):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:_,onValueChange:e=>{v(e)}})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:p,userRole:x,accessToken:h,userSpend:w,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Usage Metrics"}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(t=j.metadata)||void 0===t?void 0:null===(l=t.total_api_requests)||void 0===l?void 0:l.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:(null===(r=j.metadata)||void 0===r?void 0:null===(a=r.total_successful_requests)||void 0===a?void 0:a.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:(null===(i=j.metadata)||void 0===i?void 0:null===(n=i.total_failed_requests)||void 0===n?void 0:n.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(d=j.metadata)||void 0===d?void 0:null===(o=d.total_tokens)||void 0===o?void 0:o.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Average Cost per Request"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",((w||0)/((null===(c=j.metadata)||void 0===c?void 0:c.total_api_requests)||1)).toFixed(4)]})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...j.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Requests: ",t.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",t.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",t.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.metrics.total_tokens]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:h,userID:p,userRole:x,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Top Models"})}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.key}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",t.requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-green-600",children:["Successful: ",t.successful_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-red-600",children:["Failed: ",t.failed_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.tokens.toLocaleString()]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Spend by Provider"})}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:C(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:C().filter(e=>e.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend<1e-5?"less than 0.00001":e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:T})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:A})})]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"team",userID:p,userRole:x,entityList:(null==g?void 0:g.map(e=>({label:e.team_alias,value:e.team_id})))||null})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"tag",userID:p,userRole:x,entityList:y})})]})]})]})},tq=e=>{let{proxySettings:s}=e,l="";return s&&s.PROXY_BASE_URL&&void 0!==s.PROXY_BASE_URL&&(l=s.PROXY_BASE_URL),(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(S.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,m.jsxs)("div",{className:"mb-5",children:[(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,m.jsx)(P.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"OpenAI Python SDK"}),(0,m.jsx)(eM.Z,{children:"LlamaIndex"}),(0,m.jsx)(eM.Z,{children:"Langchain Py"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(l,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(l,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(l,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(l,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},tU=l(243),tz=l(93837);async function tV(e,s,l,t,a,r,n,i,o,d,c,m){console.log=function(){},console.log("isLocal:",!1);let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t;let a=Date.now(),u=!1;for await(let h of(await x.chat.completions.create({model:l,stream:!0,stream_options:{include_usage:!0},litellm_trace_id:d,messages:e,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r}))){var p,g,j,f,_,v,y,b;console.log("Stream chunk:",h);let e=null===(p=h.choices[0])||void 0===p?void 0:p.delta;if(console.log("Delta content:",null===(j=h.choices[0])||void 0===j?void 0:null===(g=j.delta)||void 0===g?void 0:g.content),console.log("Delta reasoning content:",null==e?void 0:e.reasoning_content),!u&&((null===(_=h.choices[0])||void 0===_?void 0:null===(f=_.delta)||void 0===f?void 0:f.content)||e&&e.reasoning_content)&&(u=!0,t=Date.now()-a,console.log("First token received! Time:",t,"ms"),i?(console.log("Calling onTimingData with:",t),i(t)):console.log("onTimingData callback is not defined!")),null===(y=h.choices[0])||void 0===y?void 0:null===(v=y.delta)||void 0===v?void 0:v.content){let e=h.choices[0].delta.content;s(e,h.model)}if(e&&e.reasoning_content){let s=e.reasoning_content;n&&n(s)}if(h.usage&&o){console.log("Usage data found:",h.usage);let e={completionTokens:h.usage.completion_tokens,promptTokens:h.usage.prompt_tokens,totalTokens:h.usage.total_tokens};(null===(b=h.usage.completion_tokens_details)||void 0===b?void 0:b.reasoning_tokens)&&(e.reasoningTokens=h.usage.completion_tokens_details.reasoning_tokens),o(e)}}}catch(e){throw(null==r?void 0:r.aborted)&&console.log("Chat completion request was cancelled"),e}}async function tK(e,s,l,t,a,r){console.log=function(){},console.log("isLocal:",!1);let n=window.location.origin,i=new l6.ZP.OpenAI({apiKey:t,baseURL:n,dangerouslyAllowBrowser:!0,defaultHeaders:a&&a.length>0?{"x-litellm-tags":a.join(",")}:void 0});try{let t=await i.images.generate({model:l,prompt:e},{signal:r});if(console.log(t.data),t.data&&t.data[0]){if(t.data[0].url)s(t.data[0].url,l);else if(t.data[0].b64_json){let e=t.data[0].b64_json;s("data:image/png;base64,".concat(e),l)}else throw Error("No image data found in response")}else throw Error("Invalid response format")}catch(e){throw(null==r?void 0:r.aborted)?console.log("Image generation request was cancelled"):F.ZP.error("Error occurred while generating image. Please try again. Error: ".concat(e),20),e}}async function tB(e,s,l,t){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,n=arguments.length>6?arguments[6]:void 0,i=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,d=arguments.length>9?arguments[9]:void 0,c=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0;if(!t)throw Error("API key is required");console.log=function(){};let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t=Date.now(),a=!1,u=e.map(e=>({role:e.role,content:e.content,type:"message"}));for await(let e of(await x.responses.create({model:l,input:u,stream:!0,litellm_trace_id:d,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r})))if(console.log("Response event:",e),"object"==typeof e&&null!==e){if("response.role.delta"===e.type)continue;if("response.output_text.delta"===e.type&&"string"==typeof e.delta){let r=e.delta;if(console.log("Text delta",r),r.trim().length>0&&(s("assistant",r,l),!a)){a=!0;let e=Date.now()-t;console.log("First token received! Time:",e,"ms"),i&&i(e)}}if("response.reasoning.delta"===e.type&&"delta"in e){let s=e.delta;"string"==typeof s&&n&&n(s)}if("response.completed"===e.type&&"response"in e){let s=e.response.usage;if(console.log("Usage data:",s),s&&o){var p;console.log("Usage data:",s);let e={completionTokens:s.output_tokens,promptTokens:s.input_tokens,totalTokens:s.total_tokens};(null===(p=s.completion_tokens_details)||void 0===p?void 0:p.reasoning_tokens)&&(e.reasoningTokens=s.completion_tokens_details.reasoning_tokens),o(e)}}}}catch(e){throw(null==r?void 0:r.aborted)?console.log("Responses API request was cancelled"):F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20),e}}let tH=async e=>{try{let s=await (0,b.kn)(e);if(console.log("model_info:",s),(null==s?void 0:s.data.length)>0){let e=s.data.map(e=>({model_group:e.model_group,mode:null==e?void 0:e.mode}));return e.sort((e,s)=>e.model_group.localeCompare(s.model_group)),e}return[]}catch(e){throw console.error("Error fetching model info:",e),e}};(a=o||(o={})).IMAGE_GENERATION="image_generation",a.CHAT="chat",a.RESPONSES="responses",(r=d||(d={})).IMAGE="image",r.CHAT="chat",r.RESPONSES="responses";let tJ={image_generation:"image",chat:"chat",responses:"responses"},tG=e=>{if(console.log("getEndpointType:",e),Object.values(o).includes(e)){let s=tJ[e];return console.log("endpointType:",s),s}return"chat"};var tW=l(94263),tY=e=>{let{endpointType:s,onEndpointChange:l,className:t}=e,a=[{value:d.CHAT,label:"/v1/chat/completions"},{value:d.RESPONSES,label:"/v1/responses"},{value:d.IMAGE,label:"/v1/images/generations"}];return(0,m.jsxs)("div",{className:t,children:[(0,m.jsx)(P.Z,{children:"Endpoint Type:"}),(0,m.jsx)(D.default,{value:s,style:{width:"100%"},onChange:l,options:a,className:"rounded-md"})]})},t$=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a)try{let e=await (0,b.UM)(a);console.log("List tags response:",e),n(Object.values(e))}catch(e){console.error("Error fetching tags:",e)}})()},[]),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select tags",onChange:s,value:l,loading:i,className:t,options:r.map(e=>({label:e.name,value:e.name,title:e.description||e.name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})},tX=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.Ou)(a);e.data&&n(e.data)}catch(e){console.error("Error fetching vector stores:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select vector stores",onChange:s,value:l,loading:i,className:t,options:r.map(e=>({label:"".concat(e.vector_store_name||e.vector_store_id," (").concat(e.vector_store_id,")"),value:e.vector_store_id,title:e.vector_store_description||e.vector_store_id})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})},tQ=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.t3)(a);console.log("Guardrails response:",e),e.guardrails&&(console.log("Guardrails data:",e.guardrails),n(e.guardrails))}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select guardrails",onChange:e=>{console.log("Selected guardrails:",e),s(e)},value:l,loading:i,className:t,options:r.map(e=>(console.log("Mapping guardrail:",e),{label:"".concat(e.guardrail_name),value:e.guardrail_name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})};let t0=(e,s)=>{let l=s.find(s=>s.model_group===e);return(null==l?void 0:l.mode)?tG(l.mode):d.CHAT};var t1=l(83322),t2=l(70464),t4=l(77565),t5=e=>{let{reasoningContent:s}=e,[l,t]=(0,u.useState)(!0);return s?(0,m.jsxs)("div",{className:"reasoning-content mt-1 mb-2",children:[(0,m.jsxs)(U.ZP,{type:"text",className:"flex items-center text-xs text-gray-500 hover:text-gray-700",onClick:()=>t(!l),icon:(0,m.jsx)(t1.Z,{}),children:[l?"Hide reasoning":"Show reasoning",l?(0,m.jsx)(t2.Z,{className:"ml-1"}):(0,m.jsx)(t4.Z,{className:"ml-1"})]}),l&&(0,m.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md text-sm text-gray-700",children:(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,n=/language-(\w+)/.exec(t||"");return!l&&n?(0,m.jsx)(to.Z,{style:tW.Z,language:n[1],PreTag:"div",className:"rounded-md my-2",...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),...r,children:a})}},children:s})})]}):null},t3=l(5540),t6=l(71282),t8=l(11741),t7=l(16601),t9=e=>{let{timeToFirstToken:s,usage:l}=e;return s||l?(0,m.jsxs)("div",{className:"response-metrics mt-2 pt-2 border-t border-gray-100 text-xs text-gray-500 flex flex-wrap gap-3",children:[void 0!==s&&(0,m.jsx)(Y.Z,{title:"Time to first token",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t3.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:[(s/1e3).toFixed(2),"s"]})]})}),(null==l?void 0:l.promptTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Prompt tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t6.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["In: ",l.promptTokens]})]})}),(null==l?void 0:l.completionTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Completion tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t8.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Out: ",l.completionTokens]})]})}),(null==l?void 0:l.reasoningTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Reasoning tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t1.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Reasoning: ",l.reasoningTokens]})]})}),(null==l?void 0:l.totalTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Total tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t7.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Total: ",l.totalTokens]})]})})]}):null},ae=l(61935),as=l(69993),al=l(12660),at=l(71891),aa=l(44625),ar=l(57400),an=l(26430),ai=l(23907);let{TextArea:ao}=z.default;var ad=e=>{let{accessToken:s,token:l,userRole:t,userID:a,disabledPersonalKeyCreation:r}=e,[n,i]=(0,u.useState)(r?"custom":"session"),[o,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(""),[p,g]=(0,u.useState)([]),[j,f]=(0,u.useState)(void 0),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)([]),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(d.CHAT),[S,T]=(0,u.useState)(!1),A=(0,u.useRef)(null),[E,O]=(0,u.useState)([]),[L,M]=(0,u.useState)([]),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)(null),V=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e="session"===n?s:o;if(!e||!l||!t||!a){console.log("userApiKey or token or userRole or userID is missing = ",e,l,t,a);return}(async()=>{try{if(!e){console.log("userApiKey is missing");return}let s=await tH(e);if(console.log("Fetched models:",s),s.length>0&&(Z(s),f(s[0].model_group),s[0].mode)){let e=t0(s[0].model_group,s);k(e)}}catch(e){console.error("Error fetching model info:",e)}})()},[s,a,t,n,o]),(0,u.useEffect)(()=>{V.current&&setTimeout(()=>{var e;null===(e=V.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[p]);let K=(e,s,l)=>{console.log("updateTextUI called with:",e,s,l),g(t=>{let a=t[t.length-1];if(!a||a.role!==e||a.isImage)return[...t,{role:e,content:s,model:l}];{var r;let e={...a,content:a.content+s,model:null!==(r=a.model)&&void 0!==r?r:l};return[...t.slice(0,-1),e]}})},B=e=>{g(s=>{let l=s[s.length-1];return l&&"assistant"===l.role&&!l.isImage?[...s.slice(0,s.length-1),{...l,reasoningContent:(l.reasoningContent||"")+e}]:s.length>0&&"user"===s[s.length-1].role?[...s,{role:"assistant",content:"",reasoningContent:e}]:s})},H=e=>{console.log("updateTimingData called with:",e),g(s=>{let l=s[s.length-1];if(console.log("Current last message:",l),l&&"assistant"===l.role){console.log("Updating assistant message with timeToFirstToken:",e);let t=[...s.slice(0,s.length-1),{...l,timeToFirstToken:e}];return console.log("Updated chat history:",t),t}return l&&"user"===l.role?(console.log("Creating new assistant message with timeToFirstToken:",e),[...s,{role:"assistant",content:"",timeToFirstToken:e}]):(console.log("No appropriate message found to update timing"),s)})},J=e=>{console.log("Received usage data:",e),g(s=>{let l=s[s.length-1];if(l&&"assistant"===l.role){console.log("Updating message with usage data:",e);let t={...l,usage:e};return console.log("Updated message:",t),[...s.slice(0,s.length-1),t]}return s})},G=(e,s)=>{g(l=>[...l,{role:"assistant",content:e,model:s,isImage:!0}])},$=async()=>{if(""===h.trim()||!l||!t||!a)return;let e="session"===n?s:o;if(!e){F.ZP.error("Please provide an API key or select Current UI Session");return}A.current=new AbortController;let r=A.current.signal,i={role:"user",content:h},c=U||(0,tz.Z)();U||z(c),g([...p,i]),T(!0);try{if(j){if(w===d.CHAT){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),i];await tV(s,(e,s)=>K("assistant",e,s),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}else if(w===d.IMAGE)await tK(h,(e,s)=>G(e,s),j,e,E,r);else if(w===d.RESPONSES){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),i];await tB(s,(e,s,l)=>K(e,s,l),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}}}catch(e){r.aborted?console.log("Request was cancelled"):(console.error("Error fetching response",e),K("assistant","Error fetching response:"+e))}finally{T(!1),A.current=null}x("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to test models"})]})}let X=(0,m.jsx)(ae.Z,{style:{fontSize:24},spin:!0});return(0,m.jsx)("div",{className:"w-full h-screen p-4 bg-white",children:(0,m.jsx)(eD.Z,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,m.jsxs)("div",{className:"flex h-[80vh] w-full",children:[(0,m.jsx)("div",{className:"w-1/4 p-4 border-r border-gray-200 bg-gray-50",children:(0,m.jsx)("div",{className:"mb-6",children:(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(lR.Z,{className:"mr-2"})," API Key Source"]}),(0,m.jsx)(D.default,{disabled:r,defaultValue:"session",style:{width:"100%"},onChange:e=>i(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}],className:"rounded-md"}),"custom"===n&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:c,value:o,icon:lR.Z})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(as.Z,{className:"mr-2"})," Select Model"]}),(0,m.jsx)(D.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),"custom"!==e&&k(t0(e,b)),y("custom"===e)},options:[...Array.from(new Set(b.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%"},showSearch:!0,className:"rounded-md"}),v&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{f(e)},500)}})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(al.Z,{className:"mr-2"})," Endpoint Type"]}),(0,m.jsx)(tY,{endpointType:w,onEndpointChange:e=>{k(e)},className:"mb-4"})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(at.Z,{className:"mr-2"})," Tags"]}),(0,m.jsx)(t$,{value:E,onChange:O,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(aa.Z,{className:"mr-2"})," Vector Store",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select vector store(s) to use for this LLM API call. You can set up your vector store ",(0,m.jsx)("a",{href:"?page=vector-stores",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tX,{value:L,onChange:M,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(ar.Z,{className:"mr-2"})," Guardrails",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select guardrail(s) to use for this LLM API call. You can set up your guardrails ",(0,m.jsx)("a",{href:"?page=guardrails",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tQ,{value:R,onChange:q,className:"mb-4",accessToken:s||""})]}),(0,m.jsx)(C.Z,{onClick:()=>{g([]),z(null),F.ZP.success("Chat history cleared.")},className:"w-full bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300 mt-4",icon:an.Z,children:"Clear Chat"})]})})}),(0,m.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,m.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===p.length&&(0,m.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,m.jsx)(as.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,m.jsx)(P.Z,{children:"Start a conversation or generate an image"})]}),p.map((e,s)=>(0,m.jsx)("div",{className:"mb-4 ".concat("user"===e.role?"text-right":"text-left"),children:(0,m.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"user"===e.role?"#f0f8ff":"#ffffff",border:"user"===e.role?"1px solid #e6f0fa":"1px solid #f0f0f0",textAlign:"left"},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"user"===e.role?"#e6f0fa":"#f5f5f5"},children:"user"===e.role?(0,m.jsx)(_.Z,{style:{fontSize:"12px",color:"#2563eb"}}):(0,m.jsx)(as.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,m.jsx)("strong",{className:"text-sm capitalize",children:e.role}),"assistant"===e.role&&e.model&&(0,m.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-normal",children:e.model})]}),e.reasoningContent&&(0,m.jsx)(t5,{reasoningContent:e.reasoningContent}),(0,m.jsxs)("div",{className:"whitespace-pre-wrap break-words max-w-full message-content",style:{wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",hyphens:"auto"},children:[e.isImage?(0,m.jsx)("img",{src:e.content,alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}}):(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,n=/language-(\w+)/.exec(t||"");return!l&&n?(0,m.jsx)(to.Z,{style:tW.Z,language:n[1],PreTag:"div",className:"rounded-md my-2",wrapLines:!0,wrapLongLines:!0,...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),style:{wordBreak:"break-word"},...r,children:a})},pre:e=>{let{node:s,...l}=e;return(0,m.jsx)("pre",{style:{overflowX:"auto",maxWidth:"100%"},...l})}},children:e.content}),"assistant"===e.role&&(e.timeToFirstToken||e.usage)&&(0,m.jsx)(t9,{timeToFirstToken:e.timeToFirstToken,usage:e.usage})]})]})},s)),S&&(0,m.jsx)("div",{className:"flex justify-center items-center my-4",children:(0,m.jsx)(lb.Z,{indicator:X})}),(0,m.jsx)("div",{ref:V,style:{height:"1px"}})]}),(0,m.jsx)("div",{className:"p-4 border-t border-gray-200 bg-white",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ao,{value:h,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),$())},placeholder:w===d.CHAT||w===d.RESPONSES?"Type your message... (Shift+Enter for new line)":"Describe the image you want to generate...",disabled:S,className:"flex-1",autoSize:{minRows:1,maxRows:6},style:{resize:"none",paddingRight:"10px",paddingLeft:"10px"}}),S?(0,m.jsx)(C.Z,{onClick:()=>{A.current&&(A.current.abort(),A.current=null,T(!1),F.ZP.info("Request cancelled"))},className:"ml-2 bg-red-50 hover:bg-red-100 text-red-600 border-red-200",icon:ec.Z,children:"Cancel"}):(0,m.jsx)(C.Z,{onClick:$,className:"ml-2 text-white",icon:w===d.CHAT?ai.Z:as.Z,children:w===d.CHAT?"Send":"Generate"})]})})]})]})})})},ac=l(19226),am=l(45937),au=l(28595),ah=l(68208),ax=l(9775),ap=l(41361),ag=l(37527),aj=l(88009),af=l(48231),a_=l(41169),av=l(58630),ay=l(55322);let{Sider:ab}=ac.default;var aZ=e=>{let{setPage:s,userRole:l,defaultSelectedKey:t}=e,a=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,m.jsx)(lR.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,m.jsx)(au.Z,{}),roles:eZ.LQ},{key:"2",page:"models",label:"Models",icon:(0,m.jsx)(ah.Z,{}),roles:eZ.LQ},{key:"12",page:"new_usage",label:"Usage",icon:(0,m.jsx)(ax.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"6",page:"teams",label:"Teams",icon:(0,m.jsx)(ap.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"5",page:"users",label:"Internal Users",icon:(0,m.jsx)(_.Z,{}),roles:eZ.ZL},{key:"14",page:"api_ref",label:"API Reference",icon:(0,m.jsx)(al.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,m.jsx)(aj.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,m.jsx)(af.Z,{})},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,m.jsx)(ar.Z,{}),roles:eZ.ZL},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,m.jsx)(a_.Z,{}),children:[{key:"9",page:"caching",label:"Caching",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"10",page:"budgets",label:"Budgets",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"20",page:"transform-request",label:"API Playground",icon:(0,m.jsx)(al.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"18",page:"mcp-tools",label:"MCP Tools",icon:(0,m.jsx)(av.Z,{}),roles:eZ.ZL},{key:"19",page:"tag-management",label:"Tag Management",icon:(0,m.jsx)(at.Z,{}),roles:eZ.ZL},{key:"21",page:"vector-stores",label:"Vector Stores",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"4",page:"usage",label:"Old Usage",icon:(0,m.jsx)(ax.Z,{})}]},{key:"settings",page:"settings",label:"Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,m.jsx)(al.Z,{}),roles:eZ.ZL},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL}]}],r=(e=>{let s=a.find(s=>s.page===e);if(s)return s.key;for(let s of a)if(s.children){let l=s.children.find(s=>s.page===e);if(l)return l.key}return"1"})(t),n=a.filter(e=>!!(!e.roles||e.roles.includes(l))&&(e.children&&(e.children=e.children.filter(e=>!e.roles||e.roles.includes(l))),!0));return(0,m.jsx)(ac.default,{style:{minHeight:"100vh"},children:(0,m.jsx)(ab,{theme:"light",width:220,children:(0,m.jsx)(am.Z,{mode:"inline",selectedKeys:[r],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:n.map(e=>{var l;return{key:e.key,icon:e.icon,label:e.label,children:null===(l=e.children)||void 0===l?void 0:l.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}})),onClick:e.children?void 0:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}}})})})})},aN=l(96889);console.log("process.env.NODE_ENV","production"),console.log=function(){};let aw=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var ak=e=>{let{accessToken:s,token:l,userRole:t,userID:a,keys:r,premiumUser:n}=e,i=new Date,[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)([]),[Z,N]=(0,u.useState)([]),[w,I]=(0,u.useState)([]),[T,A]=(0,u.useState)([]),[E,L]=(0,u.useState)([]),[D,M]=(0,u.useState)({}),[F,R]=(0,u.useState)([]),[q,U]=(0,u.useState)(""),[z,V]=(0,u.useState)(["all-tags"]),[K,B]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(0),Y=new Date(i.getFullYear(),i.getMonth(),1),$=new Date(i.getFullYear(),i.getMonth()+1,0),X=er(Y),Q=er($);function ee(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",r),console.log("premium user in usage",n);let es=async()=>{if(s)try{let e=await (0,b.g)(s);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,u.useEffect)(()=>{ea(K.from,K.to)},[K,z]);let et=async(e,l,t)=>{if(!e||!l||!s)return;l.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,b.b1)(s,t,e.toISOString(),l.toISOString());console.log("End user data updated successfully",a),j(a)},ea=async(e,l)=>{if(!e||!l||!s)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(l.setHours(23,59,59,999),e.setHours(0,0,0,0),y((await (0,b.J$)(s,e.toISOString(),l.toISOString(),0===z.length?void 0:z)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let s=e.getFullYear(),l=e.getMonth()+1,t=e.getDate();return"".concat(s,"-").concat(l<10?"0"+l:l,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(X)),console.log("End date is ".concat(Q));let en=async(e,s,l)=>{try{let l=await e();s(l)}catch(e){console.error(l,e)}},ei=(e,s,l,t)=>{let a=[],r=new Date(s),n=e=>{if(e.includes("-"))return e;{let[s,l]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(s," 01 2024")).getMonth(),parseInt(l)).toISOString().split("T")[0]}},i=new Map(e.map(e=>{let s=n(e.date);return[s,{...e,date:s}]}));for(;r<=l;){let e=r.toISOString().split("T")[0];if(i.has(e))a.push(i.get(e));else{let s={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{s[e]||(s[e]=0)}),a.push(s)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(s)try{let e=await (0,b.FC)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=ei(e,t,a,[]),n=Number(r.reduce((e,s)=>e+(s.spend||0),0).toFixed(2));W(n),d(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>en(()=>s&&l?(0,b.OU)(s,l,X,Q):Promise.reject("No access token or token"),L,"Error fetching provider spend"),ec=async()=>{s&&await en(async()=>(await (0,b.tN)(s)).map(e=>({key:e.api_key.substring(0,10),api_key:e.api_key,key_alias:e.key_alias,spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{s&&await en(async()=>(await (0,b.Au)(s)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{s&&await en(async()=>{let e=await (0,b.mR)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0);return _(ei(e.daily_spend,t,a,e.teams)),I(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},A,"Error fetching team spend")},eh=()=>{s&&en(async()=>(await (0,b.X)(s)).tag_names,N,"Error fetching tag names")},ex=()=>{s&&en(()=>{var e,l;return(0,b.J$)(s,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(l=K.to)||void 0===l?void 0:l.toISOString(),void 0)},e=>y(e.spend_per_tag),"Error fetching top tags")},ep=()=>{s&&en(()=>(0,b.b1)(s,null,void 0,void 0),j,"Error fetching top end users")},eg=async()=>{if(s)try{let e=await (0,b.wd)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=ei(e.daily_data||[],t,a,["api_requests","total_tokens"]);M({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(s)try{let e=await (0,b.xA)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=e.map(e=>({...e,daily_data:ei(e.daily_data||[],t,a,["api_requests","total_tokens"])}));R(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,u.useEffect)(()=>{(async()=>{if(s&&l&&t&&a){let e=await es();e&&(J(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),aw(t)&&(eu(),eh(),ex(),ep()))}})()},[s,l,t,a,X,Q]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Database Query Limit Reached"}),(0,m.jsxs)(P.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,m.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,m.jsx)(C.Z,{className:"mt-4",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mt-2",children:[(0,m.jsx)(eM.Z,{children:"All Up"}),aw(t)?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eM.Z,{children:"Team Based Usage"}),(0,m.jsx)(eM.Z,{children:"Customer Usage"}),(0,m.jsx)(eM.Z,{children:"Tag Based Usage"})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsx)("div",{})})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:a,userRole:t,accessToken:s,userSpend:G,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Monthly Spend"}),(0,m.jsx)(sT.Z,{data:o,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:c,accessToken:s,userID:a,userRole:t,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,m.jsx)(k.Z,{numColSpan:1}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Spend by Provider"}),(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",variant:"pie",data:E,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"})]})}),(0,m.jsx)(e3.Z,{children:E.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsx)(e6.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"All Up"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(D.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(D.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,m.jsx)(m.Fragment,{children:F.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.model}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(e.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:ee,onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(e.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:ee,onValueChange:e=>console.log(e)})]})]})]},s))})]})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Total Spend Per Team"}),(0,m.jsx)(aN.Z,{data:T})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend Per Team"}),(0,m.jsx)(sT.Z,{className:"h-72",data:f,showLegend:!0,index:"date",categories:w,yAxisWidth:80,stack:!0})]})]}),(0,m.jsx)(k.Z,{numColSpan:2})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Key"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==r?void 0:r.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},s):null)]})]})]}),(0,m.jsx)(eD.Z,{className:"mt-4",children:(0,m.jsxs)(e5.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Customer"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Total Events"})]})}),(0,m.jsx)(e3.Z,{children:null==g?void 0:g.map((e,s)=>{var l;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.end_user}),(0,m.jsx)(e6.Z,{children:null===(l=e.total_spend)||void 0===l?void 0:l.toFixed(4)}),(0,m.jsx)(e6.Z,{children:e.total_count})]},s)})})]})})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sS.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,m.jsx)(k.Z,{children:n?(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsx)(l4.Z,{value:String(e),children:e},e))]})}):(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsxs)(el.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend Per Tag"}),(0,m.jsxs)(P.Z,{children:["Get Started Tracking cost per tag ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,m.jsx)(sT.Z,{className:"h-72",data:v,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,m.jsx)(k.Z,{numColSpan:2})]})]})]})]})})},aS=l(51853);let aC=e=>{let{responseTimeMs:s}=e;return null==s?null:(0,m.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,m.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,m.jsxs)("span",{children:[s.toFixed(0),"ms"]})]})},aI=e=>{let s=e;if("string"==typeof s)try{s=JSON.parse(s)}catch(e){}return s},aT=e=>{let{label:s,value:l}=e,[t,a]=u.useState(!1),[r,n]=u.useState(!1),i=(null==l?void 0:l.toString())||"N/A",o=i.length>50?i.substring(0,50)+"...":i;return(0,m.jsx)("tr",{className:"hover:bg-gray-50",children:(0,m.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,m.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{className:"text-sm text-gray-600",children:s}),(0,m.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?i:o})]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(i),n(!0),setTimeout(()=>n(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,m.jsx)(aS.Z,{className:"h-4 w-4"})})]})})})},aA=e=>{var s,l,t,a,r,n,i,o,d,c,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=aI(j.litellm_params)||{},_=aI(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=aI(null==g?void 0:g.litellm_cache_params)||{},_=aI(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(r=n.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(i=_.connection_kwargs)||void 0===i?void 0:i.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(c=_.redis_client)||void 0===c?void 0:null===(d=c.connection_pool)||void 0===d?void 0:null===(o=d.connection_kwargs)||void 0===o?void 0:o.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,s,l,t,a,r,n,i,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(r=n.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(i=o.connection_kwargs)||void 0===i?void 0:i.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"border-b border-gray-200 px-4",children:[(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsxs)(P.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,m.jsx)("table",{className:"w-full border-collapse",children:(0,m.jsxs)("tbody",{children:[j&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,m.jsx)(aT,{label:"Error Message",value:j.message}),(0,m.jsx)(aT,{label:"Traceback",value:j.traceback})]}),(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,m.jsx)(aT,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,m.jsx)(aT,{label:"Ping Response",value:String(g.ping_response)}),(0,m.jsx)(aT,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,m.jsx)(aT,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,m.jsx)(aT,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,m.jsx)(aT,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,m.jsx)(aT,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,m.jsx)(aT,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,m.jsx)(aT,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,m.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},s=JSON.parse(JSON.stringify(e,(e,s)=>{if("string"==typeof s)try{return JSON.parse(s)}catch(e){}return s}));return JSON.stringify(s,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},aE=e=>{let{accessToken:s,healthCheckResponse:l,runCachingHealthCheck:t,responseTimeMs:a}=e,[r,n]=u.useState(null),[i,o]=u.useState(!1),d=async()=>{o(!0);let e=performance.now();await t(),n(performance.now()-e),o(!1)};return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsx)(C.Z,{onClick:d,disabled:i,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:i?"Running Health Check...":"Run Health Check"}),(0,m.jsx)(aC,{responseTimeMs:r})]}),l&&(0,m.jsx)(aA,{response:l})]})},aP=e=>{if(e)return e.toISOString().split("T")[0]};function aO(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var aL=e=>{let{accessToken:s,token:l,userRole:t,userID:a,premiumUser:r}=e,[n,i]=(0,u.useState)([]),[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)("0"),[f,_]=(0,u.useState)("0"),[v,y]=(0,u.useState)("0"),[Z,N]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[w,C]=(0,u.useState)(""),[I,T]=(0,u.useState)("");(0,u.useEffect)(()=>{s&&Z&&((async()=>{p(await (0,b.zg)(s,aP(Z.from),aP(Z.to)))})(),C(new Date().toLocaleString()))},[s]);let A=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.api_key)&&void 0!==s?s:""}))),E=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.model)&&void 0!==s?s:""})));Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.call_type)&&void 0!==s?s:""})));let O=async(e,l)=>{e&&l&&s&&(l.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,b.zg)(s,aP(e),aP(l))))};(0,u.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;o.length>0&&(e=e.filter(e=>o.includes(e.api_key))),c.length>0&&(e=e.filter(e=>c.includes(e.model))),console.log("before processed data in cache dashboard",e);let s=0,l=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),s+=(a.total_rows||0)-(a.cache_hit_true_rows||0),l+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);j(aO(l)),_(aO(t));let r=l+s;r>0?y((l/r*100).toFixed(2)):y("0"),i(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[o,c,Z,x]);let L=async()=>{try{F.ZP.info("Running cache health check..."),T("");let e=await (0,b.Tj)(null!==s?s:"");console.log("CACHING HEALTH CHECK RESPONSE",e),T(e)}catch(s){let e;if(console.error("Error running health check:",s),s&&s.message)try{let l=JSON.parse(s.message);l.error&&(l=l.error),e=l}catch(l){e={message:s.message}}else e={message:"Unknown error occurred"};T({error:e})}};return(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Cache Analytics"}),(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"Cache Health"})})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[w&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",w]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{C(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(S.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select API Keys",value:o,onValueChange:d,children:A.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select Models",value:c,onValueChange:h,children:E.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(sS.Z,{enableSelect:!0,value:Z,onValueChange:e=>{N(e),O(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[v,"%"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:f})})]})]}),(0,m.jsx)(si.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,m.jsx)(sT.Z,{title:"Cache Hits vs API Requests",data:n,stack:!0,index:"name",valueFormatter:aO,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,m.jsx)(si.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,m.jsx)(sT.Z,{className:"mt-6",data:n,stack:!0,index:"name",valueFormatter:aO,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(aE,{accessToken:s,healthCheckResponse:I,runCachingHealthCheck:L})})]})]})},aD=l(22452),aM=l(91810);(n=c||(c={})).PresidioPII="Presidio PII",n.Bedrock="Bedrock Guardrail",n.Lakera="Lakera";let aF={PresidioPII:"presidio",Bedrock:"bedrock",Lakera:"lakera_v2"},aR=e=>!!e&&"Presidio PII"===c[e],aq="../ui/assets/logos/",aU={"Presidio PII":"".concat(aq,"presidio.png"),"Bedrock Guardrail":"".concat(aq,"bedrock.svg"),Lakera:"".concat(aq,"lakeraai.jpeg")},az=e=>{if(!e)return{logo:"",displayName:"-"};let s=Object.keys(aF).find(s=>aF[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=c[s];return{logo:aU[l],displayName:l}};var aV=l(33866),aK=l(3810),aB=l(97416),aH=l(8881),aJ=l(10798),aG=l(49638);let{Text:aW}=et.default,{Option:aY}=D.default,a$=e=>e.replace(/_/g," "),aX=e=>{switch(e){case"MASK":return(0,m.jsx)(aB.Z,{style:{marginRight:4}});case"BLOCK":return(0,m.jsx)(aH.Z,{style:{marginRight:4}});default:return null}},aQ=e=>{let{categories:s,selectedCategories:l,onChange:t}=e;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)(aJ.Z,{className:"text-gray-500 mr-1"}),(0,m.jsx)(aW,{className:"text-gray-500 font-medium",children:"Filter by category"})]}),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select categories to filter by",style:{width:"100%"},onChange:t,value:l,allowClear:!0,showSearch:!0,optionFilterProp:"children",className:"mb-4",tagRender:e=>(0,m.jsx)(aK.Z,{color:"blue",closable:e.closable,onClose:e.onClose,className:"mr-2 mb-2",children:e.label}),children:s.map(e=>(0,m.jsx)(aY,{value:e.category,children:e.category},e.category))})]})},a0=e=>{let{onSelectAll:s,onUnselectAll:l,hasSelectedEntities:t}=e;return(0,m.jsxs)("div",{className:"bg-gray-50 p-5 rounded-lg mb-6 border border-gray-200 shadow-sm",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(aW,{strong:!0,className:"text-gray-700 text-base",children:"Quick Actions"}),(0,m.jsx)(Y.Z,{title:"Apply action to all PII types at once",children:(0,m.jsx)("div",{className:"ml-2 text-gray-400 cursor-help text-xs",children:"ⓘ"})})]}),(0,m.jsx)(U.ZP,{type:"default",onClick:l,disabled:!t,icon:(0,m.jsx)(aG.Z,{}),className:"border-gray-300 hover:text-red-600 hover:border-red-300",children:"Unselect All"})]}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("MASK"),className:"flex items-center justify-center h-10 border-blue-200 hover:border-blue-300 hover:text-blue-700 bg-blue-50 hover:bg-blue-100 text-blue-600",block:!0,icon:(0,m.jsx)(aB.Z,{}),children:"Select All & Mask"}),(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("BLOCK"),className:"flex items-center justify-center h-10 border-red-200 hover:border-red-300 hover:text-red-700 bg-red-50 hover:bg-red-100 text-red-600",block:!0,icon:(0,m.jsx)(aH.Z,{}),children:"Select All & Block"})]})]})},a1=e=>{let{entities:s,selectedEntities:l,selectedActions:t,actions:a,onEntitySelect:r,onActionSelect:n,entityToCategoryMap:i}=e;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden shadow-sm",children:[(0,m.jsxs)("div",{className:"bg-gray-50 px-5 py-3 border-b flex",children:[(0,m.jsx)(aW,{strong:!0,className:"flex-1 text-gray-700",children:"PII Type"}),(0,m.jsx)(aW,{strong:!0,className:"w-32 text-right text-gray-700",children:"Action"})]}),(0,m.jsx)("div",{className:"max-h-[400px] overflow-y-auto",children:0===s.length?(0,m.jsx)("div",{className:"py-10 text-center text-gray-500",children:"No PII types match your filter criteria"}):s.map(e=>(0,m.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between hover:bg-gray-50 border-b ".concat(l.includes(e)?"bg-blue-50":""),children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)(sL.Z,{checked:l.includes(e),onChange:()=>r(e),className:"mr-3"}),(0,m.jsx)(aW,{className:l.includes(e)?"font-medium text-gray-900":"text-gray-700",children:a$(e)}),i.get(e)&&(0,m.jsx)(aK.Z,{className:"ml-2 text-xs",color:"blue",children:i.get(e)})]}),(0,m.jsx)("div",{className:"w-32",children:(0,m.jsx)(D.default,{value:l.includes(e)&&t[e]||"MASK",onChange:s=>n(e,s),style:{width:120},disabled:!l.includes(e),className:"".concat(l.includes(e)?"":"opacity-50"),dropdownMatchSelectWidth:!1,children:a.map(e=>(0,m.jsx)(aY,{value:e,children:(0,m.jsxs)("div",{className:"flex items-center",children:[aX(e),e]})},e))})})]},e))})]})},{Title:a2,Text:a4}=et.default;var a5=e=>{let{entities:s,actions:l,selectedEntities:t,selectedActions:a,onEntitySelect:r,onActionSelect:n,entityCategories:i=[]}=e,[o,d]=(0,u.useState)([]),c=new Map;i.forEach(e=>{e.entities.forEach(s=>{c.set(s,e.category)})});let h=s.filter(e=>0===o.length||o.includes(c.get(e)||""));return(0,m.jsxs)("div",{className:"pii-configuration",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-5",children:[(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsx)(a2,{level:4,className:"mb-0 font-semibold text-gray-800",children:"Configure PII Protection"})}),(0,m.jsx)(aV.Z,{count:t.length,showZero:!0,style:{backgroundColor:t.length>0?"#4f46e5":"#d9d9d9"},overflowCount:999,children:(0,m.jsxs)(a4,{className:"text-gray-500",children:[t.length," items selected"]})})]}),(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsx)(aQ,{categories:i,selectedCategories:o,onChange:d}),(0,m.jsx)(a0,{onSelectAll:e=>{s.forEach(s=>{t.includes(s)||r(s),n(s,e)})},onUnselectAll:()=>{t.forEach(e=>{r(e)})},hasSelectedEntities:t.length>0})]}),(0,m.jsx)(a1,{entities:h,selectedEntities:t,selectedActions:a,actions:l,onEntitySelect:r,onActionSelect:n,entityToCategoryMap:c})]})},a3=e=>{var s;let{selectedProvider:l,accessToken:t,providerParams:a=null}=e,[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(a),[d,c]=(0,u.useState)(null);if((0,u.useEffect)(()=>{if(a){o(a);return}let e=async()=>{if(t){n(!0),c(null);try{let e=await (0,b.eW)(t);console.log("Provider params API response:",e),o(e)}catch(e){console.error("Error fetching provider params:",e),c("Failed to load provider parameters")}finally{n(!1)}}};a||e()},[t,a]),!l)return null;if(r)return(0,m.jsx)(lb.Z,{tip:"Loading provider parameters..."});if(d)return(0,m.jsx)("div",{className:"text-red-500",children:d});let h=null===(s=aF[l])||void 0===s?void 0:s.toLowerCase(),x=i&&i[h];return(console.log("Provider key:",h),console.log("Provider fields:",x),x&&0!==x.length)?(0,m.jsx)(m.Fragment,{children:x.map(e=>(0,m.jsx)(M.Z.Item,{name:e.param,label:e.param,tooltip:e.description,rules:e.required?[{required:!0,message:"".concat(e.param," is required")}]:void 0,children:"select"===e.type&&e.options?(0,m.jsx)(D.default,{placeholder:e.description,defaultValue:e.default_value,children:e.options.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):e.param.includes("password")||e.param.includes("secret")?(0,m.jsx)(I.Z,{placeholder:e.description,type:"password"}):(0,m.jsx)(I.Z,{placeholder:e.description,type:"text"})},e.param))}):(0,m.jsx)("div",{children:"No configuration fields available for this provider."})};let{Title:a6,Text:a8,Link:a7}=et.default,{Option:a9}=D.default,{Step:re}=aM.default;var rs=e=>{var s;let{visible:l,onClose:t,accessToken:a,onSuccess:r}=e,[n]=M.Z.useForm(),[i,o]=(0,u.useState)(!1),[d,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)({}),[v,y]=(0,u.useState)(0),[Z,N]=(0,u.useState)(null);(0,u.useEffect)(()=>{a&&(async()=>{try{let[e,s]=await Promise.all([(0,b.qd)(a),(0,b.eW)(a)]);p(e),N(s)}catch(e){console.error("Error fetching guardrail data:",e),F.ZP.error("Failed to load guardrail configuration")}})()},[a]);let w=e=>{h(e),n.setFieldsValue({config:void 0,presidio_analyzer_api_base:void 0,presidio_anonymizer_api_base:void 0}),j([]),_({})},k=e=>{j(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},S=(e,s)=>{_(l=>({...l,[e]:s}))},T=async()=>{try{if(0===v&&(await n.validateFields(["guardrail_name","provider","mode","default_on"]),d)){let e=["guardrail_name","provider","mode","default_on"];"PresidioPII"===d&&e.push("presidio_analyzer_api_base","presidio_anonymizer_api_base"),await n.validateFields(e)}y(v+1)}catch(e){console.error("Form validation failed:",e)}},A=()=>{n.resetFields(),h(null),j([]),_({}),y(0)},E=()=>{A(),t()},P=async()=>{try{o(!0),await n.validateFields();let s=n.getFieldsValue(!0),l=aF[s.provider],i={guardrail_name:s.guardrail_name,litellm_params:{guardrail:l,mode:s.mode,default_on:s.default_on},guardrail_info:{}};if("PresidioPII"===s.provider&&g.length>0){let e={};g.forEach(s=>{e[s]=f[s]||"MASK"}),i.litellm_params.pii_entities_config=e,s.presidio_analyzer_api_base&&(i.litellm_params.presidio_analyzer_api_base=s.presidio_analyzer_api_base),s.presidio_anonymizer_api_base&&(i.litellm_params.presidio_anonymizer_api_base=s.presidio_anonymizer_api_base)}else if(s.config)try{let e=JSON.parse(s.config);i.guardrail_info=e}catch(e){F.ZP.error("Invalid JSON in configuration"),o(!1);return}if(Z&&d){var e;let l=Z[null===(e=aF[d])||void 0===e?void 0:e.toLowerCase()]||[];new Set(l.map(e=>e.param)).forEach(e=>{let l=s[e];null!=l&&""!==l&&(i.litellm_params[e]=l)})}if(!a)throw Error("No access token available");console.log("Sending guardrail data:",JSON.stringify(i)),await (0,b.PC)(a,i),F.ZP.success("Guardrail created successfully"),A(),r(),t()}catch(e){console.error("Failed to create guardrail:",e),F.ZP.error("Failed to create guardrail: "+(e instanceof Error?e.message:String(e)))}finally{o(!1)}},O=()=>{var e;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:w,labelInValue:!1,optionLabelProp:"label",dropdownRender:e=>e,showSearch:!0,children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(a9,{value:s,label:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[aU[l]&&(0,m.jsx)("img",{src:aU[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]}),children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[aU[l]&&(0,m.jsx)("img",{src:aU[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(a3,{selectedProvider:d,accessToken:a,providerParams:Z}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{children:(null==x?void 0:null===(e=x.supported_modes)||void 0===e?void 0:e.map(e=>(0,m.jsx)(a9,{value:e,children:e},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(a9,{value:"pre_call",children:"pre_call"}),(0,m.jsx)(a9,{value:"post_call",children:"post_call"})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,m.jsx)(sY.Z,{})})]})},L=()=>x&&"PresidioPII"===d?(0,m.jsx)(a5,{entities:x.supported_entities,actions:x.supported_actions,selectedEntities:g,selectedActions:f,onEntitySelect:k,onActionSelect:S,entityCategories:x.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Add Guardrail",open:l,onCancel:E,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:n,layout:"vertical",initialValues:{mode:(null==x?void 0:null===(s=x.supported_modes)||void 0===s?void 0:s[0])||"pre_call",default_on:!1},children:[(0,m.jsxs)(aM.default,{current:v,className:"mb-6",children:[(0,m.jsx)(re,{title:"Basic Info"}),(0,m.jsx)(re,{title:"PresidioPII"===d?"PII Configuration":"Provider Configuration"})]}),(()=>{switch(v){case 0:return O();case 1:if(aR(d))return L();default:return null}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[v>0&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{y(v-1)},children:"Previous"}),v<1&&(0,m.jsx)(C.Z,{onClick:T,children:"Next"}),1===v&&(0,m.jsx)(C.Z,{onClick:P,loading:i,children:"Create Guardrail"}),(0,m.jsx)(C.Z,{variant:"secondary",onClick:E,children:"Cancel"})]})]})})};let{Title:rl,Text:rt}=et.default,{Option:ra}=D.default;var rr=e=>{var s;let{visible:l,onClose:t,accessToken:a,onSuccess:r,guardrailId:n,initialValues:i}=e,[o]=M.Z.useForm(),[d,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)((null==i?void 0:i.provider)||null),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)({});(0,u.useEffect)(()=>{(async()=>{try{if(!a)return;let e=await (0,b.qd)(a);j(e)}catch(e){console.error("Error fetching guardrail settings:",e),F.ZP.error("Failed to load guardrail settings")}})()},[a]),(0,u.useEffect)(()=>{(null==i?void 0:i.pii_entities_config)&&Object.keys(i.pii_entities_config).length>0&&(_(Object.keys(i.pii_entities_config)),y(i.pii_entities_config))},[i]);let Z=e=>{_(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},N=(e,s)=>{y(l=>({...l,[e]:s}))},w=async()=>{try{h(!0);let e=await o.validateFields(),s=aF[e.provider],l={guardrail_id:n,guardrail:{guardrail_name:e.guardrail_name,litellm_params:{guardrail:s,mode:e.mode,default_on:e.default_on},guardrail_info:{}}};if("PresidioPII"===e.provider&&f.length>0){let e={};f.forEach(s=>{e[s]=v[s]||"MASK"}),l.guardrail.litellm_params.pii_entities_config=e}else if(e.config)try{let s=JSON.parse(e.config);"Bedrock"===e.provider&&s?(s.guardrail_id&&(l.guardrail.litellm_params.guardrailIdentifier=s.guardrail_id),s.guardrail_version&&(l.guardrail.litellm_params.guardrailVersion=s.guardrail_version)):l.guardrail.guardrail_info=s}catch(e){F.ZP.error("Invalid JSON in configuration"),h(!1);return}if(!a)throw Error("No access token available");console.log("Sending guardrail update data:",JSON.stringify(l));let i=await fetch("/guardrails/".concat(n),{method:"PUT",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){let e=await i.text();throw Error(e||"Failed to update guardrail")}F.ZP.success("Guardrail updated successfully"),r(),t()}catch(e){console.error("Failed to update guardrail:",e),F.ZP.error("Failed to update guardrail: "+(e instanceof Error?e.message:String(e)))}finally{h(!1)}},k=()=>g&&x&&"PresidioPII"===x?(0,m.jsx)(a5,{entities:g.supported_entities,actions:g.supported_actions,selectedEntities:f,selectedActions:v,onEntitySelect:Z,onActionSelect:N,entityCategories:g.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Edit Guardrail",open:l,onCancel:t,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:o,layout:"vertical",initialValues:i,children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:e=>{p(e),o.setFieldsValue({config:void 0}),_([]),y({})},disabled:!0,optionLabelProp:"label",children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(ra,{value:s,label:l,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[aU[l]&&(0,m.jsx)("img",{src:aU[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{children:(null==g?void 0:null===(s=g.supported_modes)||void 0===s?void 0:s.map(e=>(0,m.jsx)(ra,{value:e,children:e},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(ra,{value:"pre_call",children:"pre_call"}),(0,m.jsx)(ra,{value:"post_call",children:"post_call"})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,m.jsx)(sY.Z,{})}),(()=>{if(!x)return null;if("PresidioPII"===x)return k();switch(x){case"Aporia":return(0,m.jsx)(M.Z.Item,{label:"Aporia Configuration",name:"config",tooltip:"JSON configuration for Aporia",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aporia_api_key",\n "project_name": "your_project_name"\n}'})});case"AimSecurity":return(0,m.jsx)(M.Z.Item,{label:"Aim Security Configuration",name:"config",tooltip:"JSON configuration for Aim Security",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aim_api_key"\n}'})});case"Bedrock":return(0,m.jsx)(M.Z.Item,{label:"Amazon Bedrock Configuration",name:"config",tooltip:"JSON configuration for Amazon Bedrock guardrails",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "guardrail_id": "your_guardrail_id",\n "guardrail_version": "your_guardrail_version"\n}'})});case"GuardrailsAI":return(0,m.jsx)(M.Z.Item,{label:"Guardrails.ai Configuration",name:"config",tooltip:"JSON configuration for Guardrails.ai",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_guardrails_api_key",\n "guardrail_id": "your_guardrail_id"\n}'})});case"LakeraAI":return(0,m.jsx)(M.Z.Item,{label:"Lakera AI Configuration",name:"config",tooltip:"JSON configuration for Lakera AI",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_lakera_api_key"\n}'})});case"PromptInjection":return(0,m.jsx)(M.Z.Item,{label:"Prompt Injection Configuration",name:"config",tooltip:"JSON configuration for prompt injection detection",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "threshold": 0.8\n}'})});default:return(0,m.jsx)(M.Z.Item,{label:"Custom Configuration",name:"config",tooltip:"JSON configuration for your custom guardrail",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "key1": "value1",\n "key2": "value2"\n}'})})}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:t,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:w,loading:d,children:"Update Guardrail"})]})]})})},rn=e=>{var s,l,t,a,r,n,i;let{guardrailId:o,onClose:d,accessToken:c,isAdmin:h}=e,[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!0),[f,_]=(0,u.useState)(!1),[v]=M.Z.useForm(),y=async()=>{try{if(j(!0),!c)return;let e=await (0,b.fk)(c,o);p(e)}catch(e){F.ZP.error("Failed to load guardrail information"),console.error("Error fetching guardrail info:",e)}finally{j(!1)}};(0,u.useEffect)(()=>{y()},[o,c]);let Z=async e=>{try{if(!c)return;let s={guardrail_name:e.guardrail_name,litellm_params:{default_on:e.default_on},guardrail_info:e.guardrail_info?JSON.parse(e.guardrail_info):void 0};await (0,b.Ko)(c,o,s),F.ZP.success("Guardrail updated successfully"),y(),_(!1)}catch(e){console.error("Error updating guardrail:",e),F.ZP.error("Failed to update guardrail")}};if(g)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!x)return(0,m.jsx)("div",{className:"p-4",children:"Guardrail not found"});let N=e=>e?new Date(e).toLocaleString():"-",{logo:w,displayName:k}=az((null===(s=x.litellm_params)||void 0===s?void 0:s.guardrail)||"");return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:d,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:x.guardrail_name||"Unnamed Guardrail"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:x.guardrail_id})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),h?(0,m.jsx)(eM.Z,{children:"Settings"},"settings"):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[w&&(0,m.jsx)("img",{src:w,alt:"".concat(k," logo"),className:"w-6 h-6",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(O.Z,{children:k})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Mode"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:(null===(l=x.litellm_params)||void 0===l?void 0:l.mode)||"-"}),(0,m.jsx)(eL.Z,{color:(null===(t=x.litellm_params)||void 0===t?void 0:t.default_on)?"green":"gray",children:(null===(a=x.litellm_params)||void 0===a?void 0:a.default_on)?"Default On":"Default Off"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Created At"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:N(x.created_at)}),(0,m.jsxs)(P.Z,{children:["Last Updated: ",N(x.updated_at)]})]})]})]}),x.guardrail_info&&Object.keys(x.guardrail_info).length>0&&(0,m.jsxs)(eD.Z,{className:"mt-6",children:[(0,m.jsx)(P.Z,{children:"Guardrail Info"}),(0,m.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(x.guardrail_info).map(e=>{let[s,l]=e;return(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(P.Z,{className:"font-medium w-1/3",children:s}),(0,m.jsx)(P.Z,{className:"w-2/3",children:"object"==typeof l?JSON.stringify(l,null,2):String(l)})]},s)})})]})]}),h&&(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Guardrail Settings"}),!f&&(0,m.jsx)(C.Z,{onClick:()=>_(!0),children:"Edit Settings"})]}),f?(0,m.jsxs)(M.Z,{form:v,onFinish:Z,initialValues:{guardrail_name:x.guardrail_name,...x.litellm_params,guardrail_info:x.guardrail_info?JSON.stringify(x.guardrail_info,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Guardrail Name",name:"guardrail_name",rules:[{required:!0,message:"Please input a guardrail name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Default On",name:"default_on",children:(0,m.jsxs)(D.default,{children:[(0,m.jsx)(D.default.Option,{value:!0,children:"Yes"}),(0,m.jsx)(D.default.Option,{value:!1,children:"No"})]})}),(0,m.jsx)(M.Z.Item,{label:"Guardrail Information",name:"guardrail_info",children:(0,m.jsx)(z.default.TextArea,{rows:5})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>_(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail ID"}),(0,m.jsx)("div",{className:"font-mono",children:x.guardrail_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail Name"}),(0,m.jsx)("div",{children:x.guardrail_name||"Unnamed Guardrail"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Provider"}),(0,m.jsx)("div",{children:k})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Mode"}),(0,m.jsx)("div",{children:(null===(r=x.litellm_params)||void 0===r?void 0:r.mode)||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Default On"}),(0,m.jsx)(eL.Z,{color:(null===(n=x.litellm_params)||void 0===n?void 0:n.default_on)?"green":"gray",children:(null===(i=x.litellm_params)||void 0===i?void 0:i.default_on)?"Yes":"No"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:N(x.created_at)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)("div",{children:N(x.updated_at)})]})]})]})})]})]})]})},ri=e=>{let{guardrailsList:s,isLoading:l,onDeleteClick:t,accessToken:a,onGuardrailUpdated:r,isAdmin:n=!1,onShowGuardrailInfo:i}=e,[o,d]=(0,u.useState)([{id:"created_at",desc:!0}]),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(null),v=e=>e?new Date(e).toLocaleString():"-",y=e=>{_(e),j(!0),null==i||i(!0)},b=[{header:"Guardrail ID",accessorKey:"guardrail_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>e.getValue()&&y(e.getValue()),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Name",accessorKey:"guardrail_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.guardrail_name,children:(0,m.jsx)("span",{className:"text-xs font-medium",children:l.guardrail_name||"-"})})}},{header:"Provider",accessorKey:"litellm_params.guardrail",cell:e=>{let{row:s}=e,{logo:l,displayName:t}=az(s.original.litellm_params.guardrail);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:l,alt:"".concat(t," logo"),className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)("span",{className:"text-xs",children:t})]})}},{header:"Mode",accessorKey:"litellm_params.mode",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.litellm_params.mode})}},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.created_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.updated_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.updated_at)})})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l.guardrail_id&&t(l.guardrail_id,l.guardrail_name||"Unnamed Guardrail"),className:"cursor-pointer hover:text-red-500",tooltip:"Delete guardrail"})})}}],Z=(0,e2.b7)({data:s,columns:b,state:{sorting:o},onSortingChange:d,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return g&&f?(0,m.jsx)(rn,{guardrailId:f,onClose:()=>{j(!1),_(null),null==i||i(!1)},accessToken:a,isAdmin:n}):(0,m.jsxs)("div",{className:"rounded-lg custom-border relative",children:[(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:Z.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:l?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"Loading..."})})})}):s.length>0?Z.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No guardrails found"})})})})})]})}),x&&(0,m.jsx)(rr,{visible:c,onClose:()=>h(!1),accessToken:a,onSuccess:()=>{h(!1),p(null),r()},guardrailId:x.guardrail_id||"",initialValues:{guardrail_name:x.guardrail_name||"",provider:Object.keys(aF).find(e=>aF[e]===(null==x?void 0:x.litellm_params.guardrail))||"",mode:x.litellm_params.mode,default_on:x.litellm_params.default_on,pii_entities_config:x.litellm_params.pii_entities_config,...x.guardrail_info}})]})},ro=e=>{let{accessToken:s,userRole:l}=e,[t,a]=(0,u.useState)([]),[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),j=!!l&&(0,eZ.tY)(l),f=async()=>{if(s){o(!0);try{let e=await (0,b.t3)(s);console.log("guardrails: ".concat(JSON.stringify(e))),a(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}};(0,u.useEffect)(()=>{f()},[s]);let _=async()=>{if(h&&s){c(!0);try{await (0,b.Yi)(s,h.id),F.ZP.success('Guardrail "'.concat(h.name,'" deleted successfully')),f()}catch(e){console.error("Error deleting guardrail:",e),F.ZP.error("Failed to delete guardrail")}finally{c(!1),x(null)}}};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[!p&&(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(C.Z,{icon:aD.Z,onClick:()=>{n(!0)},disabled:!s,children:"Add Guardrail"})}),(0,m.jsx)(ri,{guardrailsList:t,isLoading:i,onDeleteClick:(e,s)=>{x({id:e,name:s})},accessToken:s,onGuardrailUpdated:f,isAdmin:j,onShowGuardrailInfo:g}),(0,m.jsx)(rs,{visible:r,onClose:()=>{n(!1)},accessToken:s,onSuccess:()=>{f()}}),h&&(0,m.jsxs)(R.Z,{title:"Delete Guardrail",open:null!==h,onOk:_,onCancel:()=>{x(null)},confirmLoading:d,okText:"Delete",okButtonProps:{danger:!0},children:[(0,m.jsxs)("p",{children:["Are you sure you want to delete guardrail: ",h.name," ?"]}),(0,m.jsx)("p",{children:"This action cannot be undone."})]})]})},rd=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)('{\n "model": "openai/gpt-4o",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n },\n {\n "role": "user",\n "content": "Explain quantum computing in simple terms"\n }\n ],\n "temperature": 0.7,\n "max_tokens": 500,\n "stream": true\n}'),[a,r]=(0,u.useState)(""),[n,i]=(0,u.useState)(!1),o=(e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")},d=async()=>{i(!0);try{let e;try{e=JSON.parse(l)}catch(e){F.ZP.error("Invalid JSON in request body"),i(!1);return}let t={call_type:"completion",request_body:e};if(!s){F.ZP.error("No access token found"),i(!1);return}let a=await (0,b.Yo)(s,t);if(a.raw_request_api_base&&a.raw_request_body){let e=o(a.raw_request_api_base,a.raw_request_body,a.raw_request_headers||{});r(e),F.ZP.success("Request transformed successfully")}else{let e="string"==typeof a?a:JSON.stringify(a);r(e),F.ZP.info("Transformed request received in unexpected format")}}catch(e){console.error("Error transforming request:",e),F.ZP.error("Failed to transform request")}finally{i(!1)}};return(0,m.jsxs)("div",{className:"w-full m-2",style:{overflow:"hidden"},children:[(0,m.jsx)(O.Z,{children:"Playground"}),(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"See how LiteLLM transforms your request for the specified provider."}),(0,m.jsxs)("div",{style:{display:"flex",gap:"16px",width:"100%",minWidth:0,overflow:"hidden"},className:"mt-4",children:[(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"600px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Original Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"The request you would send to LiteLLM /chat/completions endpoint."})]}),(0,m.jsx)("textarea",{style:{flex:"1 1 auto",width:"100%",minHeight:"240px",padding:"16px",border:"1px solid #e8e8e8",borderRadius:"6px",fontFamily:"monospace",fontSize:"14px",resize:"none",marginBottom:"24px",overflow:"auto"},value:l,onChange:e=>t(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),d())},placeholder:"Press Cmd/Ctrl + Enter to transform"}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:(0,m.jsxs)(U.ZP,{type:"primary",style:{backgroundColor:"#000",display:"flex",alignItems:"center",gap:"8px"},onClick:d,loading:n,children:[(0,m.jsx)("span",{children:"Transform"}),(0,m.jsx)("span",{children:"→"})]})})]}),(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"800px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Transformed Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"How LiteLLM transforms your request for the specified provider."}),(0,m.jsx)("br",{}),(0,m.jsx)("p",{style:{color:"#666",margin:0},className:"text-xs",children:"Note: Sensitive headers are not shown."})]}),(0,m.jsxs)("div",{style:{position:"relative",backgroundColor:"#f5f5f5",borderRadius:"6px",flex:"1 1 auto",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,m.jsx)("pre",{style:{padding:"16px",fontFamily:"monospace",fontSize:"14px",margin:0,overflow:"auto",flex:"1 1 auto"},children:a||'curl -X POST \\\n https://api.openai.com/v1/chat/completions \\\n -H \'Authorization: Bearer sk-xxx\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{\n "model": "gpt-4",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n }\n ],\n "temperature": 0.7\n }\''}),(0,m.jsx)(U.ZP,{type:"text",icon:(0,m.jsx)(ls.Z,{}),style:{position:"absolute",right:"8px",top:"8px"},size:"small",onClick:()=>{navigator.clipboard.writeText(a||""),F.ZP.success("Copied to clipboard")}})]})]})]}),(0,m.jsx)("div",{className:"mt-4 text-right w-full",children:(0,m.jsxs)("p",{className:"text-sm text-gray-500",children:["Found an error? File an issue ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/issues",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})]})},rc=l(21770);let rm=[{accessorKey:"mcp_info.server_name",header:"Provider",cell:e=>{let{row:s}=e,l=s.original.mcp_info.server_name,t=s.original.mcp_info.logo_url;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:"".concat(l," logo"),className:"h-5 w-5 object-contain"}),(0,m.jsx)("span",{className:"font-medium",children:l})]})}},{accessorKey:"name",header:"Tool Name",cell:e=>{let{row:s}=e,l=s.getValue("name");return(0,m.jsx)("div",{children:(0,m.jsx)("span",{className:"font-mono text-sm",children:l})})}},{accessorKey:"description",header:"Description",cell:e=>{let{row:s}=e,l=s.getValue("description");return(0,m.jsx)("div",{className:"max-w-md",children:(0,m.jsx)("span",{className:"text-sm text-gray-700",children:l})})}},{id:"actions",header:"Actions",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex items-center space-x-2",children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{"function"==typeof s.original.onToolSelect&&s.original.onToolSelect(l)},children:"Test Tool"})})}}];function ru(e){let{tool:s,onSubmit:l,isLoading:t,result:a,error:r,onClose:n}=e,[i,o]=u.useState({}),d=u.useMemo(()=>"string"==typeof s.inputSchema?{type:"object",properties:{input:{type:"string",description:"Input for this tool"}},required:["input"]}:s.inputSchema,[s.inputSchema]),c=(e,s)=>{o(l=>({...l,[e]:s}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-lg border p-6 max-w-4xl w-full",children:[(0,m.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("h2",{className:"text-xl font-bold",children:["Test Tool: ",(0,m.jsx)("span",{className:"font-mono",children:s.name})]}),(0,m.jsx)("p",{className:"text-gray-600",children:s.description}),(0,m.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:["Provider: ",s.mcp_info.server_name]})]}),(0,m.jsx)("button",{onClick:n,className:"p-1 rounded-full hover:bg-gray-200",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,m.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Input Parameters"}),(0,m.jsxs)("form",{onSubmit:e=>{e.preventDefault(),l(i)},children:["string"==typeof s.inputSchema?(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"This tool uses a dynamic input schema."}),(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Input ",(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,m.jsx)("input",{type:"text",value:i.input||"",onChange:e=>c("input",e.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"})]})]}):Object.entries(d.properties).map(e=>{var s,l,t;let[a,r]=e;return(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[a," ",(null===(s=d.required)||void 0===s?void 0:s.includes(a))&&(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),r.description&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:r.description}),"string"===r.type&&(0,m.jsx)("input",{type:"text",value:i[a]||"",onChange:e=>c(a,e.target.value),required:null===(l=d.required)||void 0===l?void 0:l.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"number"===r.type&&(0,m.jsx)("input",{type:"number",value:i[a]||"",onChange:e=>c(a,parseFloat(e.target.value)),required:null===(t=d.required)||void 0===t?void 0:t.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"boolean"===r.type&&(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("input",{type:"checkbox",checked:i[a]||!1,onChange:e=>c(a,e.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),(0,m.jsx)("span",{className:"ml-2 text-sm text-gray-600",children:"Enable"})]})]},a)}),(0,m.jsx)("div",{className:"mt-6",children:(0,m.jsx)(C.Z,{type:"submit",disabled:t,className:"w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white",children:t?"Calling...":"Call Tool"})})]})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg overflow-auto max-h-[500px]",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Result"}),t&&(0,m.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,m.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-700"})}),r&&(0,m.jsxs)("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-md",children:[(0,m.jsx)("p",{className:"font-medium",children:"Error"}),(0,m.jsx)("pre",{className:"mt-2 text-xs overflow-auto whitespace-pre-wrap",children:r.message})]}),a&&!t&&!r&&(0,m.jsxs)("div",{children:[a.map((e,s)=>(0,m.jsxs)("div",{className:"mb-4",children:["text"===e.type&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("p",{className:"whitespace-pre-wrap text-sm",children:e.text})}),"image"===e.type&&e.url&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("img",{src:e.url,alt:"Tool result",className:"max-w-full h-auto rounded"})}),"embedded_resource"===e.type&&(0,m.jsxs)("div",{className:"bg-white border p-3 rounded-md",children:[(0,m.jsx)("p",{className:"text-sm font-medium",children:"Embedded Resource"}),(0,m.jsxs)("p",{className:"text-xs text-gray-500",children:["Type: ",e.resource_type]}),e.url&&(0,m.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"View Resource"})]})]},s)),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)("details",{className:"text-xs",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-gray-500 hover:text-gray-700",children:"Raw JSON Response"}),(0,m.jsx)("pre",{className:"mt-2 bg-gray-100 p-2 rounded-md overflow-auto max-h-[300px]",children:JSON.stringify(a,null,2)})]})})]}),!a&&!t&&!r&&(0,m.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,m.jsx)("p",{children:"The result will appear here after you call the tool."})})]})]})]})}function rh(e){let{columns:s,data:l,isLoading:t}=e;return(0,m.jsx)(tu,{columns:s,data:l,isLoading:t,renderSubComponent:()=>(0,m.jsx)("div",{}),getRowCanExpand:()=>!1,loadingMessage:"\uD83D\uDE85 Loading tools...",noDataMessage:"No tools found"})}function rx(e){let{accessToken:s,userRole:l,userID:t}=e,[a,r]=(0,u.useState)(""),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),{data:x,isLoading:p}=(0,eY.a)({queryKey:["mcpTools"],queryFn:()=>{if(!s)throw Error("Access Token required");return(0,b.lU)(s)},enabled:!!s}),{mutate:g,isPending:j}=(0,rc.D)({mutationFn:e=>{if(!s)throw Error("Access Token required");return(0,b.tB)(s,e.tool.name,e.arguments)},onSuccess:e=>{d(e),h(null)},onError:e=>{h(e),d(null)}}),f=u.useMemo(()=>x?x.map(e=>({...e,onToolSelect:e=>{i(e),d(null),h(null)}})):[],[x]),_=u.useMemo(()=>f.filter(e=>{let s=a.toLowerCase();return e.name.toLowerCase().includes(s)||e.description.toLowerCase().includes(s)||e.mcp_info.server_name.toLowerCase().includes(s)}),[f,a]);return s&&l&&t?(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"MCP Tools"})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search tools...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:a,onChange:e=>r(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"text-sm text-gray-500",children:[_.length," tool",1!==_.length?"s":""," available"]})]})}),(0,m.jsx)(rh,{columns:rm,data:_,isLoading:p})]}),n&&(0,m.jsx)("div",{className:"fixed inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center z-50 p-4",children:(0,m.jsx)(ru,{tool:n,onSubmit:e=>{n&&g({tool:n,arguments:e})},isLoading:j,result:o,error:c,onClose:()=>i(null)})})]}):(0,m.jsx)("div",{className:"p-6 text-center text-gray-500",children:"Missing required authentication parameters."})}var rp=e=>{let{tagId:s,onClose:l,accessToken:t,is_admin:a,editTag:r}=e,[n]=M.Z.useForm(),[i,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(r),[h,x]=(0,u.useState)([]),p=async()=>{if(t)try{let e=(await (0,b.mC)(t,[s]))[s];e&&(o(e),r&&n.setFieldsValue({name:e.name,description:e.description,models:e.models}))}catch(e){console.error("Error fetching tag details:",e),F.ZP.error("Error fetching tag details: "+e)}};(0,u.useEffect)(()=>{p()},[s,t]),(0,u.useEffect)(()=>{t&&eT("dummy-user","Admin",t,x)},[t]);let g=async e=>{if(t)try{await (0,b.n9)(t,{name:e.name,description:e.description,models:e.models}),F.ZP.success("Tag updated successfully"),c(!1),p()}catch(e){console.error("Error updating tag:",e),F.ZP.error("Error updating tag: "+e)}};return i?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{onClick:l,className:"mb-4",children:"← Back to Tags"}),(0,m.jsxs)(O.Z,{children:["Tag Name: ",i.name]}),(0,m.jsx)(P.Z,{className:"text-gray-500",children:i.description||"No description"})]}),a&&!d&&(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Tag"})]}),d?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(M.Z,{form:n,onFinish:g,layout:"vertical",initialValues:i,children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(z.default,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed LLMs"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process this type of data",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:h.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{onClick:()=>c(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}):(0,m.jsx)("div",{className:"space-y-6",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Tag Details"}),(0,m.jsxs)("div",{className:"space-y-4 mt-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Name"}),(0,m.jsx)(P.Z,{children:i.name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Description"}),(0,m.jsx)(P.Z,{children:i.description||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Allowed LLMs"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:0===i.models.length?(0,m.jsx)(eL.Z,{color:"red",children:"All Models"}):i.models.map(e=>{var s;return(0,m.jsx)(eL.Z,{color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(null===(s=i.model_info)||void 0===s?void 0:s[e])||e})},e)})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:i.created_at?new Date(i.created_at).toLocaleString():"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:i.updated_at?new Date(i.updated_at).toLocaleString():"-"})]})]})]})})]}):(0,m.jsx)("div",{children:"Loading..."})},rg=e=>{let{data:s,onEdit:l,onDelete:t,onSelectTag:a}=e,[r,n]=u.useState([{id:"created_at",desc:!0}]),i=[{header:"Tag Name",accessorKey:"name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.name,children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5",onClick:()=>a(l.name),children:l.name})})})}},{header:"Description",accessorKey:"description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.description,children:(0,m.jsx)("span",{className:"text-xs",children:l.description||"-"})})}},{header:"Allowed LLMs",accessorKey:"models",cell:e=>{var s,l;let{row:t}=e,a=t.original;return(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:(null==a?void 0:null===(s=a.models)||void 0===s?void 0:s.length)===0?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Models"}):null==a?void 0:null===(l=a.models)||void 0===l?void 0:l.map(e=>{var s;return(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(0,m.jsx)(P.Z,{children:(null===(s=a.model_info)||void 0===s?void 0:s[e])||e})})},e)})})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,a=s.original;return(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>l(a),className:"cursor-pointer"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(a.name),className:"cursor-pointer"})]})}}],o=(0,e2.b7)({data:s,columns:i,state:{sorting:r},onSortingChange:n,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:i.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No tags found"})})})})})]})})})},rj=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v]=M.Z.useForm(),[y,Z]=(0,u.useState)([]),N=async()=>{if(s)try{let e=await (0,b.UM)(s);console.log("List tags response:",e),r(Object.values(e))}catch(e){console.error("Error fetching tags:",e),F.ZP.error("Error fetching tags: "+e)}},w=async e=>{if(s)try{await (0,b.mY)(s,{name:e.tag_name,description:e.description,models:e.allowed_llms}),F.ZP.success("Tag created successfully"),i(!1),v.resetFields(),N()}catch(e){console.error("Error creating tag:",e),F.ZP.error("Error creating tag: "+e)}},T=async e=>{j(e),p(!0)},A=async()=>{if(s&&g){try{await (0,b.fE)(s,g),F.ZP.success("Tag deleted successfully"),N()}catch(e){console.error("Error deleting tag:",e),F.ZP.error("Error deleting tag: "+e)}p(!1),j(null)}};return(0,u.useEffect)(()=>{l&&t&&s&&(async()=>{try{let e=await (0,b.AZ)(s,l,t);e&&e.data&&Z(e.data)}catch(e){console.error("Error fetching models:",e),F.ZP.error("Error fetching models: "+e)}})()},[s,l,t]),(0,u.useEffect)(()=>{N()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:o?(0,m.jsx)(rp,{tagId:o,onClose:()=>{d(null),h(!1)},accessToken:s,is_admin:"Admin"===t,editTag:c}):(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Tag Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{N(),_(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(P.Z,{className:"mb-4",children:["Click on a tag name to view and edit its details.",(0,m.jsxs)("p",{children:["You can use tags to restrict the usage of certain LLMs based on tags passed in the request. Read more about tag routing ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tag_routing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})]}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>i(!0),children:"+ Create New Tag"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(rg,{data:a,onEdit:e=>{d(e.name),h(!0)},onDelete:T,onSelectTag:d})})}),(0,m.jsx)(R.Z,{title:"Create New Tag",visible:n,width:800,footer:null,onCancel:()=>{i(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"tag_name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed Models"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process requests from this tag",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_llms",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:y.map(e=>(0,m.jsx)(D.default.Option,{value:e.model_info.id,children:(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{children:e.model_name}),(0,m.jsxs)("span",{className:"text-gray-400 ml-2",children:["(",e.model_info.id,")"]})]})},e.model_info.id))})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Tag"})})]})}),x&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Tag"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this tag?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:A,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{p(!1),j(null)},children:"Cancel"})]})]})]})})]})})},rf=e=>{let{data:s,onDelete:l}=e,[t,a]=u.useState([{id:"created_at",desc:!0}]),r=[{header:"Vector Store ID",accessorKey:"vector_store_id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.vector_store_id,children:(0,m.jsx)("span",{className:"font-mono text-blue-500 text-xs font-normal",children:l.vector_store_id})})})}},{header:"Name",accessorKey:"vector_store_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_name,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_name||"-"})})}},{header:"Description",accessorKey:"vector_store_description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_description,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_description||"-"})})}},{header:"Provider",accessorKey:"custom_llm_provider",cell:e=>{let{row:s}=e,{displayName:l,logo:t}=sm(s.original.custom_llm_provider);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:l,className:"h-4 w-4"}),(0,m.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.vector_store_id),className:"cursor-pointer"})})}}],n=(0,e2.b7)({data:s,columns:r,state:{sorting:t},onSortingChange:a,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:n.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:n.getRowModel().rows.length>0?n.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:r.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No vector stores found"})})})})})]})})})},r_=e=>{let{isVisible:s,onCancel:l,onSuccess:t,accessToken:a,credentials:r}=e,[n]=M.Z.useForm(),[o,d]=(0,u.useState)("{}"),c=async e=>{if(a)try{let s={};try{s=o.trim()?JSON.parse(o):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}await (0,b.Mx)(a,{vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s,litellm_credential_name:e.litellm_credential_name}),F.ZP.success("Vector store created successfully"),n.resetFields(),d("{}"),t()}catch(e){console.error("Error creating vector store:",e),F.ZP.error("Error creating vector store: "+e)}},h=()=>{n.resetFields(),d("{}"),l()};return(0,m.jsx)(R.Z,{title:"Create New Vector Store",visible:s,width:800,footer:null,onCancel:h,children:(0,m.jsxs)(M.Z,{form:n,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Provider"," ",(0,m.jsx)(Y.Z,{title:"Select the provider for this vector store",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],initialValue:"bedrock",children:(0,m.jsx)(D.default,{children:Object.entries(i).map(e=>{let[s,l]=e;return"Bedrock"===s?(0,m.jsx)(D.default.Option,{value:so[s],children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s):null})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store ID"," ",(0,m.jsx)(Y.Z,{title:"Enter the vector store ID from your api provider",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_id",rules:[{required:!0,message:"Please input the vector store ID from your api provider"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store Name"," ",(0,m.jsx)(Y.Z,{title:"Custom name you want to give to the vector store, this name will be rendered on the LiteLLM UI",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_name",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"vector_store_description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Existing Credentials"," ",(0,m.jsx)(Y.Z,{title:"Optionally select API provider credentials for this vector store eg. Bedrock API KEY",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...r.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON metadata for the vector store (optional)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),children:(0,m.jsx)(z.default.TextArea,{rows:4,value:o,onChange:e=>d(e.target.value),placeholder:'{"key": "value"}'})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,m.jsx)(C.Z,{onClick:h,variant:"secondary",children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",type:"submit",children:"Create"})]})]})})},rv=e=>{let{isVisible:s,onCancel:l,onConfirm:t}=e;return(0,m.jsxs)(R.Z,{title:"Delete Vector Store",visible:s,footer:null,onCancel:l,children:[(0,m.jsx)("p",{children:"Are you sure you want to delete this vector store? This action cannot be undone."}),(0,m.jsxs)("div",{className:"px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:t,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:l,variant:"primary",children:"Cancel"})]})]})},ry=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(!1),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)([]),f=async()=>{if(s)try{let e=await (0,b.Ou)(s);console.log("List vector stores response:",e),r(e.data||[])}catch(e){console.error("Error fetching vector stores:",e),F.ZP.error("Error fetching vector stores: "+e)}},_=async()=>{if(s)try{let e=await (0,b.N3)(s);console.log("List credentials response:",e),j(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e),F.ZP.error("Error fetching credentials: "+e)}},v=async e=>{h(e),d(!0)},y=async()=>{if(s&&c){try{await (0,b.Pv)(s,c),F.ZP.success("Vector store deleted successfully"),f()}catch(e){console.error("Error deleting vector store:",e),F.ZP.error("Error deleting vector store: "+e)}d(!1),h(null)}};return(0,u.useEffect)(()=>{f(),_()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Vector Store Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[x&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",x]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{f(),_(),p(new Date().toLocaleString())}})]})]}),(0,m.jsx)(P.Z,{className:"mb-4",children:(0,m.jsx)("p",{children:"You can use vector stores to store and retrieve LLM embeddings. Currently, we support Amazon Bedrock vector stores."})}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>i(!0),children:"+ Create Vector Store"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(rf,{data:a,onDelete:v})})}),(0,m.jsx)(r_,{isVisible:n,onCancel:()=>i(!1),onSuccess:()=>{i(!1),f()},accessToken:s,credentials:g}),(0,m.jsx)(rv,{isVisible:o,onCancel:()=>d(!1),onConfirm:y})]})})},rb=l(49096),rZ=l(53335);let{cva:rN,cx:rw,compose:rk}=(0,rb.ZD)({hooks:{onComplete:e=>(0,rZ.m6)(e)}});function rS(e){var s,l;let{className:t="",...a}=e,r=(0,u.useId)();return s=()=>{let e=document.getAnimations().filter(e=>e instanceof CSSAnimation&&"spin"===e.animationName),s=e.find(e=>{var s;return(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))===r}),l=e.find(e=>{var s;return e.effect instanceof KeyframeEffect&&(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))!==r});s&&l&&(s.currentTime=l.currentTime)},l=[r],(0,u.useLayoutEffect)(s,l),(0,m.jsxs)("svg",{"data-spinner-id":r,className:rw("pointer-events-none size-12 animate-spin text-current",t),fill:"none",viewBox:"0 0 24 24",...a,children:[(0,m.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,m.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}let rC=new p.S;function rI(){return(0,m.jsxs)("div",{className:rw("h-screen","flex items-center justify-center gap-4"),children:[(0,m.jsx)("div",{className:"text-lg font-medium py-2 pr-4 border-r border-r-gray-200",children:"\uD83D\uDE85 LiteLLM"}),(0,m.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,m.jsx)(rS,{className:"size-4"}),(0,m.jsx)("span",{className:"text-gray-600 text-sm",children:"Loading..."})]})]})}function rT(){let[e,s]=(0,u.useState)(""),[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,p]=(0,u.useState)([]),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,S]=(0,u.useState)(!0),C=(0,h.useSearchParams)(),[I,T]=(0,u.useState)({data:[]}),[A,E]=(0,u.useState)(null),[P,O]=(0,u.useState)(!1),[L,D]=(0,u.useState)(!0),[M,F]=(0,u.useState)(null),R=C.get("invitation_id"),[q,U]=(0,u.useState)(()=>C.get("page")||"api-keys"),[z,V]=(0,u.useState)(null),K=e=>{p(s=>s?[...s,e]:[e]),O(()=>!P)},B=!1===L&&null===A&&null===R;return((0,u.useEffect)(()=>{E(function(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token")),D(!1)},[]),(0,u.useEffect)(()=>{B&&(window.location.href=(b.H2||"")+"/sso/key/generate")},[B]),(0,u.useEffect)(()=>{if(!A)return;let e=(0,x.o)(A);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),V(e.key),r(e.disabled_non_admin_personal_key_creation),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&U("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?S("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,b.K8)(e.auth_header_name),e.user_id&&F(e.user_id)}},[A]),(0,u.useEffect)(()=>{z&&M&&e&&eT(M,e,z,v),z&&M&&e&&w(z,M,e,null,d),z&&lE(z,f)},[z,M,e]),L||B)?(0,m.jsx)(rI,{}):(0,m.jsx)(u.Suspense,{fallback:(0,m.jsx)(rI,{}),children:(0,m.jsx)(g.aH,{client:rC,children:R?(0,m.jsx)(sn,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:n,setUserEmail:i,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):(0,m.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,m.jsx)(N,{userID:M,userRole:e,premiumUser:l,userEmail:n,setProxySettings:Z,proxySettings:y,accessToken:z}),(0,m.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,m.jsx)("div",{className:"mt-8",children:(0,m.jsx)(aZ,{setPage:e=>{let s=new URLSearchParams(C);s.set("page",e),window.history.pushState(null,"","?".concat(s.toString())),U(e)},userRole:e,defaultSelectedKey:q})}),"api-keys"==q?(0,m.jsx)(sn,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:n,setUserEmail:i,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):"models"==q?(0,m.jsx)(lh,{userID:M,userRole:e,token:A,keys:c,accessToken:z,modelData:I,setModelData:T,premiumUser:l,teams:o}):"llm-playground"==q?(0,m.jsx)(ad,{userID:M,userRole:e,token:A,accessToken:z,disabledPersonalKeyCreation:a}):"users"==q?(0,m.jsx)(lk,{userID:M,userRole:e,token:A,keys:c,teams:o,accessToken:z,setKeys:p}):"teams"==q?(0,m.jsx)(lT,{teams:o,setTeams:d,searchParams:C,accessToken:z,userID:M,userRole:e,organizations:j}):"organizations"==q?(0,m.jsx)(lP,{organizations:j,setOrganizations:f,userModels:_,accessToken:z,userRole:e,premiumUser:l}):"admin-panel"==q?(0,m.jsx)(lK,{setTeams:d,searchParams:C,accessToken:z,userID:M,showSSOBanner:k,premiumUser:l,proxySettings:y}):"api_ref"==q?(0,m.jsx)(tq,{proxySettings:y}):"settings"==q?(0,m.jsx)(l1,{userID:M,userRole:e,accessToken:z,premiumUser:l}):"budgets"==q?(0,m.jsx)(td,{accessToken:z}):"guardrails"==q?(0,m.jsx)(ro,{accessToken:z,userRole:e}):"transform-request"==q?(0,m.jsx)(rd,{accessToken:z}):"general-settings"==q?(0,m.jsx)(te,{userID:M,userRole:e,accessToken:z,modelData:I}):"model-hub"==q?(0,m.jsx)(tC.Z,{accessToken:z,publicPage:!1,premiumUser:l}):"caching"==q?(0,m.jsx)(aL,{userID:M,userRole:e,token:A,accessToken:z,premiumUser:l}):"pass-through-settings"==q?(0,m.jsx)(tr,{userID:M,userRole:e,accessToken:z,modelData:I}):"logs"==q?(0,m.jsx)(tk,{userID:M,userRole:e,token:A,accessToken:z,allTeams:null!=o?o:[]}):"mcp-tools"==q?(0,m.jsx)(rx,{accessToken:z,userRole:e,userID:M}):"tag-management"==q?(0,m.jsx)(rj,{accessToken:z,userRole:e,userID:M}):"vector-stores"==q?(0,m.jsx)(ry,{accessToken:z,userRole:e,userID:M}):"new_usage"==q?(0,m.jsx)(tR,{userID:M,userRole:e,accessToken:z,teams:null!=o?o:[]}):(0,m.jsx)(ak,{userID:M,userRole:e,token:A,accessToken:z,keys:c,premiumUser:l})]})]})})})}},3914:function(e,s,l){"use strict";function t(){let e=window.location.hostname,s=["Lax","Strict","None"];["/","/ui"].forEach(l=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,";"),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let t="None"===s?" Secure;":"";document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; SameSite=").concat(s,";").concat(t),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(t)})}),console.log("After clearing cookies:",document.cookie)}function a(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}l.d(s,{b:function(){return t},e:function(){return a}})}},function(e){e.O(0,[665,990,402,313,899,460,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,s,l){Promise.resolve().then(l.bind(l,96564))},12011:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return v}});var t=l(57437),a=l(2265),r=l(99376),i=l(20831),n=l(94789),o=l(12514),d=l(49804),c=l(67101),m=l(84264),u=l(49566),h=l(96761),x=l(84566),p=l(19250),g=l(14474),j=l(13634),f=l(73002),_=l(3914);function v(){let[e]=j.Z.useForm(),s=(0,r.useSearchParams)();(0,_.e)("token");let l=s.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[k,S]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[T,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{l&&(0,p.W_)(l).then(e=>{let s=e.login_url;console.log("login_url:",s),I(s);let l=e.token,t=(0,g.o)(l);A(l),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),S(t.user_id)})},[l]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tier."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",T,"formValues:",e),v&&T&&(e.user_email=N,k&&l&&(0,p.m_)(v,l,k,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+T,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},96564:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return rA}});var t,a,r,i,n,o,d,c,m=l(57437),u=l(2265),h=l(99376),x=l(14474),p=l(21623),g=l(29827),j=l(27648),f=l(80795),_=l(15883),v=l(40428),y=l(3914),b=l(19250);let Z=async e=>{if(!e)return null;try{return await (0,b.g)(e)}catch(e){return console.error("Error fetching proxy settings:",e),null}};var N=e=>{let{userID:s,userEmail:l,userRole:t,premiumUser:a,proxySettings:r,setProxySettings:i,accessToken:n}=e,[o,d]=(0,u.useState)("");(0,u.useEffect)(()=>{(async()=>{if(n){let e=await Z(n);console.log("response from fetchProxySettings",e),e&&i(e)}})()},[n]),(0,u.useEffect)(()=>{d((null==r?void 0:r.PROXY_LOGOUT_URL)||"")},[r]);let c=[{key:"1",label:(0,m.jsxs)("div",{className:"py-1",children:[(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",l||"Unknown"]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,m.jsx)(_.Z,{})," ",s]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,m.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,y.b)(),window.location.href=o},children:[(0,m.jsx)(v.Z,{})," Logout"]})}];return(0,m.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,m.jsx)("div",{className:"w-full",children:(0,m.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,m.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,m.jsx)(j.default,{href:"/",className:"flex items-center",children:(0,m.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,m.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,m.jsx)(f.Z,{menu:{items:c,style:{padding:"4px",marginTop:"4px"}},children:(0,m.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,m.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})};let w=async(e,s,l,t,a)=>{let r;r="Admin"!=l&&"Admin Viewer"!=l?await (0,b.It)(e,(null==t?void 0:t.organization_id)||null,s):await (0,b.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var k=l(49804),S=l(67101),C=l(20831),I=l(49566),T=l(87452),A=l(88829),E=l(72208),P=l(84264),O=l(96761),L=l(29233),D=l(52787),M=l(13634),F=l(41021),R=l(91679),q=l(29967),U=l(73002),z=l(64482),V=l(30150),K=e=>{let{step:s=.01,style:l={width:"100%"},placeholder:t="Enter a numerical value",min:a,max:r,onChange:i,...n}=e;return(0,m.jsx)(V.Z,{onWheel:e=>e.currentTarget.blur(),step:s,style:l,placeholder:t,min:a,max:r,onChange:i,...n})};let B=async(e,s,l)=>{try{if(null===e||null===s)return;if(null!==l){let t=(await (0,b.So)(l,e,s,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},H=e=>{if(e.endsWith("/*")){let s=e.replace("/*","");return"All ".concat(s," models")}return e},J=(e,s)=>{let l=[],t=[];return console.log("teamModels",e),console.log("allModels",s),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=s.filter(e=>e.startsWith(a+"/"));t.push(...r),l.push(e)}else t.push(e)}),[...l,...t].filter((e,s,l)=>l.indexOf(e)===s)};var G=l(20577),W=l(15424),Y=l(89970);let $=(e,s)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===s.format,X=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},Q=(e,s,l)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[l]||"Text input";return $(e,s)?"".concat(t,"\nMust be valid JSON format"):s.enum?"Select from available options\nAllowed values: ".concat(s.enum.join(", ")):t};var ee=e=>{let{schemaComponent:s,excludedFields:l=[],form:t,overrideLabels:a={},overrideTooltips:r={},customValidation:i={},defaultValues:n={}}=e,[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null);(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.lP)()).components.schemas[s];if(!e)throw Error('Schema component "'.concat(s,'" not found'));d(e);let a={};Object.keys(e.properties).filter(e=>!l.includes(e)&&void 0!==n[e]).forEach(e=>{a[e]=n[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[s,t,l]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let s=e.anyOf.map(e=>e.type);if(s.includes("number")||s.includes("integer"))return"number";s.includes("string")}return"string"},p=(e,s)=>{var l;let t;let d=x(s),c=null==o?void 0:null===(l=o.required)||void 0===l?void 0:l.includes(e),u=a[e]||s.title||e,h=r[e]||s.description,p=[];c&&p.push({required:!0,message:"".concat(u," is required")}),i[e]&&p.push({validator:i[e]}),$(e,s)&&p.push({validator:async(e,s)=>{if(s&&!X(s))throw Error("Please enter valid JSON")}});let g=h?(0,m.jsxs)("span",{children:[u," ",(0,m.jsx)(Y.Z,{title:h,children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}):u;return t=$(e,s)?(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):s.enum?(0,m.jsx)(D.default,{children:s.enum.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"number"===d||"integer"===d?(0,m.jsx)(G.Z,{style:{width:"100%"},precision:"integer"===d?0:void 0}):"duration"===e?(0,m.jsx)(I.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,m.jsx)(I.Z,{placeholder:h||""}),(0,m.jsx)(M.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:n[e],help:(0,m.jsx)("div",{className:"text-xs text-gray-500",children:Q(e,s,d)}),children:t},e)};return c?(0,m.jsxs)("div",{className:"text-red-500",children:["Error: ",c]}):(null==o?void 0:o.properties)?(0,m.jsx)("div",{children:Object.entries(o.properties).filter(e=>{let[s]=e;return!l.includes(s)}).map(e=>{let[s,l]=e;return p(s,l)})}):null},es=e=>{let{teams:s,value:l,onChange:t}=e;return(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Search or select a team",value:l,onChange:t,filterOption:(e,s)=>{var l,t,a;return!!s&&((null===(a=s.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(l=t.props)||void 0===l?void 0:l.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==s?void 0:s.map(e=>(0,m.jsxs)(D.default.Option,{value:e.team_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},el=l(57365),et=l(93192);function ea(e){let{isInvitationLinkModalVisible:s,setIsInvitationLinkModalVisible:l,baseUrl:t,invitationLinkData:a}=e,{Title:r,Paragraph:i}=et.default,n=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,m.jsxs)(R.Z,{title:"Invitation Link",visible:s,width:800,footer:null,onOk:()=>{l(!1)},onCancel:()=>{l(!1)},children:[(0,m.jsx)(i,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"User ID"}),(0,m.jsx)(P.Z,{children:null==a?void 0:a.user_id})]}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{children:"Invitation Link"}),(0,m.jsx)(P.Z,{children:(0,m.jsx)(P.Z,{children:n()})})]}),(0,m.jsx)("div",{className:"flex justify-end mt-5",children:(0,m.jsx)(L.CopyToClipboard,{text:n(),onCopy:()=>F.ZP.success("Copied!"),children:(0,m.jsx)(C.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var er=l(85010),ei=l(72188),en=l(73879),eo=l(34310),ed=l(38434),ec=l(26349),em=l(35291),eu=l(3632),eh=l(15452),ex=l.n(eh),ep=l(71157),eg=l(44643),ej=l(88532),ef=e=>{let{accessToken:s,teams:l,possibleUIRoles:t,onUsersCreated:a}=e,[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(null),[N,w]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.g)(s);Z(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),w(new URL("/",window.location.href).toString())},[s]);let k=async()=>{c(!0);let e=n.map(e=>({...e,status:"pending"}));o(e);let l=!1;for(let a=0;ae.trim()).filter(Boolean),0===e.teams.length&&delete e.teams),n.models&&"string"==typeof n.models&&""!==n.models.trim()&&(e.models=n.models.split(",").map(e=>e.trim()).filter(Boolean),0===e.models.length&&delete e.models),n.max_budget&&""!==n.max_budget.toString().trim()){let s=parseFloat(n.max_budget.toString());!isNaN(s)&&s>0&&(e.max_budget=s)}n.budget_duration&&""!==n.budget_duration.trim()&&(e.budget_duration=n.budget_duration.trim()),n.metadata&&"string"==typeof n.metadata&&""!==n.metadata.trim()&&(e.metadata=n.metadata.trim()),console.log("Sending user data:",e);let r=await (0,b.Ov)(s,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){l=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==y?void 0:y.SSO_ENABLED){let e=new URL("/ui",N).toString();o(s=>s.map((s,l)=>l===a?{...s,status:"success",key:r.key||r.user_id,invitation_link:e}:s))}else{let l=await (0,b.XO)(s,e),t=new URL("/ui?invitation_id=".concat(l.id),N).toString();o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}catch(s){console.error("Caught error:",s);let e=(null==s?void 0:null===(i=s.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==s?void 0:s.message)||String(s);o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}c(!1),l&&a&&a()};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>i(!0),children:"+ Bulk Invite Users"}),(0,m.jsx)(R.Z,{title:"Bulk Invite Users",visible:r,width:800,onCancel:()=>i(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,m.jsx)("div",{className:"flex flex-col",children:0===n.length?(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,m.jsxs)("div",{className:"ml-11 mb-6",children:[(0,m.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,m.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,m.jsx)("li",{children:"Download our CSV template"}),(0,m.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,m.jsx)("li",{children:"Save the file and upload it here"}),(0,m.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_email"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_role"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"teams"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"models"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=new Blob([ex().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),s=window.URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download="bulk_users_template.csv",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)},size:"lg",className:"w-full md:w-auto",children:[(0,m.jsx)(en.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,m.jsxs)("div",{className:"ml-11",children:[_?(0,m.jsxs)("div",{className:"mb-4 p-4 rounded-md border ".concat(j?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200"),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[j?(0,m.jsx)(eo.Z,{className:"text-red-500 text-xl mr-3"}):(0,m.jsx)(ed.Z,{className:"text-blue-500 text-xl mr-3"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:j?"text-red-800":"text-blue-800",children:_.name}),(0,m.jsxs)(et.default.Text,{className:"block text-xs ".concat(j?"text-red-600":"text-blue-600"),children:[(_.size/1024).toFixed(1)," KB • ",new Date().toLocaleDateString()]})]})]}),(0,m.jsxs)(C.Z,{size:"xs",variant:"secondary",onClick:()=>{v(null),o([]),x(null),g(null),f(null)},className:"flex items-center",children:[(0,m.jsx)(ec.Z,{className:"mr-1"})," Remove"]})]}),j?(0,m.jsxs)("div",{className:"mt-3 text-red-600 text-sm flex items-start",children:[(0,m.jsx)(em.Z,{className:"mr-2 mt-0.5"}),(0,m.jsx)("span",{children:j})]}):!p&&(0,m.jsxs)("div",{className:"mt-3 flex items-center",children:[(0,m.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,m.jsx)("div",{className:"bg-blue-500 h-1.5 rounded-full w-full animate-pulse"})}),(0,m.jsx)("span",{className:"ml-2 text-xs text-blue-600",children:"Processing..."})]})]}):(0,m.jsx)(er.Z,{beforeUpload:e=>((x(null),g(null),f(null),v(e),"text/csv"===e.type||e.name.endsWith(".csv"))?e.size>5242880?f("File is too large (".concat((e.size/1048576).toFixed(1)," MB). Please upload a CSV file smaller than 5MB.")):ex().parse(e,{complete:e=>{if(!e.data||0===e.data.length){g("The CSV file appears to be empty. Please upload a file with data."),o([]);return}if(1===e.data.length){g("The CSV file only contains headers but no user data. Please add user data to your CSV."),o([]);return}let s=e.data[0];if(0===s.length||1===s.length&&""===s[0]){g("The CSV file doesn't contain any column headers. Please make sure your CSV has headers."),o([]);return}let t=["user_email","user_role"].filter(e=>!s.includes(e));if(t.length>0){g("Your CSV is missing these required columns: ".concat(t.join(", "),". Please add these columns to your CSV file.")),o([]);return}try{let t=e.data.slice(1).map((e,t)=>{var a,r,i,n,o,d;if(0===e.length||1===e.length&&""===e[0])return null;if(e.length=parseFloat(c.max_budget.toString())&&m.push("Max budget must be greater than 0")),c.budget_duration&&!c.budget_duration.match(/^\d+[dhmwy]$|^\d+mo$/)&&m.push('Invalid budget duration format "'.concat(c.budget_duration,'". Use format like "30d", "1mo", "2w", "6h"')),c.teams&&"string"==typeof c.teams&&l&&l.length>0){let e=l.map(e=>e.team_id),s=c.teams.split(",").map(e=>e.trim()).filter(s=>!e.includes(s));s.length>0&&m.push("Unknown team(s): ".concat(s.join(", ")))}return m.length>0&&(c.isValid=!1,c.error=m.join(", ")),c}).filter(Boolean),a=t.filter(e=>e.isValid);o(t),0===t.length?g("No valid data rows found in the CSV file. Please check your file format."):0===a.length?x("No valid users found in the CSV. Please check the errors below and fix your CSV file."):a.length{x("Failed to parse CSV file: ".concat(e.message)),o([])},header:!1}):(f("Invalid file type: ".concat(e.name,". Please upload a CSV file (.csv extension).")),F.ZP.error("Invalid file type. Please upload a CSV file.")),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,m.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,m.jsx)(eu.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,m.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,m.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,m.jsx)(C.Z,{size:"sm",children:"Browse files"}),(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-4",children:"Only CSV files (.csv) are supported"})]})}),p&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(ej.Z,{className:"h-5 w-5 text-yellow-500 mr-2 mt-0.5"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:"text-yellow-800",children:"CSV Structure Error"}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-1 mb-0",children:p}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-2 mb-0",children:"Please download our template and ensure your CSV follows the required format."})]})]})})]})]}):(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:n.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,m.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(em.Z,{className:"text-red-500 mr-2 mt-1"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"text-red-600 font-medium",children:h}),n.some(e=>!e.isValid)&&(0,m.jsxs)("ul",{className:"mt-2 list-disc list-inside text-red-600 text-sm",children:[(0,m.jsx)("li",{children:"Check the table below for specific errors in each row"}),(0,m.jsx)("li",{children:"Common issues include invalid email formats, missing required fields, or incorrect role values"}),(0,m.jsx)("li",{children:"Fix these issues in your CSV file and upload again"})]})]})]})}),(0,m.jsxs)("div",{className:"ml-11",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,m.jsx)("div",{className:"flex items-center",children:n.some(e=>"success"===e.status||"failed"===e.status)?(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[n.filter(e=>"success"===e.status).length," Successful"]}),n.some(e=>"failed"===e.status)&&(0,m.jsxs)(P.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[n.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[n.filter(e=>e.isValid).length," of ",n.length," users valid"]})]})}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex space-x-3",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===n.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]})]}),n.some(e=>"success"===e.status)&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"mr-3 mt-1",children:(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-blue-500"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,m.jsxs)(P.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,m.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,m.jsx)(ei.Z,{dataSource:n,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,s)=>s.isValid?s.status&&"pending"!==s.status?"success"===s.status?(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,m.jsx)("span",{className:"text-green-500",children:"Success"})]}),s.invitation_link&&(0,m.jsx)("div",{className:"mt-1",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:s.invitation_link}),(0,m.jsx)(L.CopyToClipboard,{text:s.invitation_link,onCopy:()=>F.ZP.success("Invitation link copied!"),children:(0,m.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Failed"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(s.error)})]}):(0,m.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:s.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===n.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]}),n.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=n.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),s=new Blob([ex().unparse(e)],{type:"text/csv"}),l=window.URL.createObjectURL(s),t=document.createElement("a");t.href=l,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(l)},variant:"primary",className:"flex items-center",children:[(0,m.jsx)(en.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:e_}=D.default;var ev=e=>{let{userID:s,accessToken:l,teams:t,possibleUIRoles:a,onUserCreated:r,isEmbedded:i=!1}=e,n=(0,g.NL)(),[o,d]=(0,u.useState)(null),[c]=M.Z.useForm(),[x,p]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=(0,h.useRouter)(),[S,L]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.So)(l,s,"any"),t=[];for(let s=0;s{k&&L(new URL("/",window.location.href).toString())},[k]);let q=async e=>{var t,a,d;try{F.ZP.info("Making API Call"),i||p(!0),e.models&&0!==e.models.length||"proxy_admin"===e.user_role||(console.log("formValues.user_role",e.user_role),e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,b.Ov)(l,null,e);await n.invalidateQueries({queryKey:["userList"]}),console.log("user create Response:",a),f(!0);let d=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(r&&i){r(d),c.resetFields();return}if(null==o?void 0:o.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:d,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:s,updated_at:new Date,updated_by:s,has_user_setup_sso:!0};w(e),Z(!0)}else(0,b.XO)(l,d).then(e=>{e.has_user_setup_sso=!1,w(e),Z(!0)});F.ZP.success("API user Created"),c.resetFields(),localStorage.removeItem("userData"+s)}catch(s){let e=(null===(d=s.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.detail)||(null==s?void 0:s.message)||"Error creating the user";F.ZP.error(e),console.error("Error creating the user:",s)}};return i?(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>p(!0),children:"+ Invite User"}),(0,m.jsx)(ef,{accessToken:l,teams:t,possibleUIRoles:a}),(0,m.jsxs)(R.Z,{title:"Invite User",visible:x,width:800,footer:null,onOk:()=>{p(!1),c.resetFields()},onCancel:()=>{p(!1),f(!1),c.resetFields()},children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{children:"Personal Key Creation"})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(M.Z.Item,{className:"gap-2",label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Models user has access to, outside of team scope.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),_.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]})]}),j&&(0,m.jsx)(ea,{isInvitationLinkModalVisible:y,setIsInvitationLinkModalVisible:Z,baseUrl:S,invitationLinkData:N})]})},ey=l(7310),eb=l.n(ey),eZ=l(20347);let{Option:eN}=D.default,ew=e=>e?({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||e:"Not set";var ek=e=>{let{value:s,onChange:l,className:t="",style:a={}}=e;return(0,m.jsxs)(D.default,{style:{width:"100%",...a},value:s||void 0,onChange:l,className:t,placeholder:"n/a",children:[(0,m.jsx)(eN,{value:"24h",children:"daily"}),(0,m.jsx)(eN,{value:"7d",children:"weekly"}),(0,m.jsx)(eN,{value:"30d",children:"monthly"})]})};let{Option:eS}=D.default,eC=e=>{let s=[];if(console.log("data:",JSON.stringify(e)),e)for(let l of e)l.metadata&&l.metadata.tags&&s.push(...l.metadata.tags);let l=Array.from(new Set(s)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",l),l},eI=async(e,s,l,t)=>{try{if(null===e||null===s)return[];if(null!==l){let a=(await (0,b.So)(l,e,s,!0,t)).data.map(e=>e.id);return console.log("available_model_names:",a),a}return[]}catch(e){return console.error("Error fetching user models:",e),[]}},eT=async(e,s,l,t)=>{try{if(null===e||null===s)return;if(null!==l){let a=(await (0,b.So)(l,e,s)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eA=e=>{let{userID:s,team:l,teams:t,userRole:a,accessToken:r,data:i,addKey:n}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)("you"),[N,w]=(0,u.useState)(eC(i)),[V,B]=(0,u.useState)([]),[J,G]=(0,u.useState)(l),[$,X]=(0,u.useState)(!1),[Q,el]=(0,u.useState)(null),[et,ea]=(0,u.useState)({}),[er,ei]=(0,u.useState)([]),[en,eo]=(0,u.useState)(!1),ed=()=>{c(!1),o.resetFields()},ec=()=>{c(!1),x(null),G(null),o.resetFields()};(0,u.useEffect)(()=>{s&&a&&r&&eT(s,a,r,f)},[r,s,a]),(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.t3)(r)).guardrails.map(e=>e.guardrail_name);B(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[r]),(0,u.useEffect)(()=>{(async()=>{try{if(r){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,b.lg)(r);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[r]);let em=async e=>{try{var l,t,a;let d=null!==(l=null==e?void 0:e.key_alias)&&void 0!==l?l:"",m=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==i?void 0:i.filter(e=>e.team_id===m).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(d))throw Error("Key alias ".concat(d," already exists for team with ID ").concat(m,", please provide another key alias"));if(F.ZP.info("Making API Call"),c(!0),"you"===y&&(e.user_id=s),"service_account"===y){let s={};try{s=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}s.service_account_id=e.key_alias,e.metadata=JSON.stringify(s)}let u=await (0,b.wX)(r,s,e);console.log("key create Response:",u),n(u),x(u.key),g(u.soft_budget),F.ZP.success("API Key Created"),o.resetFields(),localStorage.removeItem("userData"+s)}catch(e){console.log("error in create key:",e),F.ZP.error("Error creating the key: ".concat(e))}};(0,u.useEffect)(()=>{if(s&&a&&r){var e;eI(s,a,r,null!==(e=null==J?void 0:J.team_id)&&void 0!==e?e:null).then(e=>{var s;v(Array.from(new Set([...null!==(s=null==J?void 0:J.models)&&void 0!==s?s:[],...e])))})}o.setFieldValue("models",[])},[J,r,s,a]);let eu=async e=>{if(!e){ei([]);return}eo(!0);try{let s=new URLSearchParams;if(s.append("user_email",e),null==r)return;let l=(await (0,b.u5)(r,s)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));ei(l)}catch(e){console.error("Error fetching users:",e),F.ZP.error("Failed to search for users")}finally{eo(!1)}},eh=(0,u.useCallback)(eb()(e=>eu(e),300),[r]),ex=(e,s)=>{let l=s.user;o.setFieldsValue({user_id:l.user_id})};return(0,m.jsxs)("div",{children:[a&&eZ.LQ.includes(a)&&(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Create New Key"}),(0,m.jsx)(R.Z,{visible:d,width:1e3,footer:null,onOk:ed,onCancel:ec,children:(0,m.jsxs)(M.Z,{form:o,onFinish:em,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Ownership"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Owned By"," ",(0,m.jsx)(Y.Z,{title:"Select who will own this API key",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,m.jsxs)(q.ZP.Group,{onChange:e=>Z(e.target.value),value:y,children:[(0,m.jsx)(q.ZP,{value:"you",children:"You"}),(0,m.jsx)(q.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,m.jsx)(q.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===y&&(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["User ID"," ",(0,m.jsx)(Y.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===y,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{eh(e)},onSelect:(e,s)=>ex(e,s),options:er,loading:en,allowClear:!0,style:{width:"100%"},notFoundContent:en?"Searching...":"No users found"}),(0,m.jsx)(U.ZP,{onClick:()=>X(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,m.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Team"," ",(0,m.jsx)(Y.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:l?l.team_id:null,className:"mt-4",children:(0,m.jsx)(es,{teams:t,onChange:e=>{G((null==t?void 0:t.find(s=>s.team_id===e))||null)}})})]}),(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Details"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["you"===y||"another_user"===y?"Key Name":"Service Account ID"," ",(0,m.jsx)(Y.Z,{title:"you"===y||"another_user"===y?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===y?"key name":"service account ID")}],help:"required",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&o.setFieldsValue({models:["all-team-models"]})},children:[(0,m.jsx)(eS,{value:"all-team-models",children:"All Team Models"},"all-team-models"),_.map(e=>(0,m.jsx)(eS,{value:e,children:H(e)},e))]})})]}),(0,m.jsx)("div",{className:"mb-8",children:(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{className:"m-0",children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Max Budget (USD)"," ",(0,m.jsx)(Y.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==l?void 0:l.max_budget)!==null&&(null==l?void 0:l.max_budget)!==void 0?null==l?void 0:l.max_budget:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.max_budget&&s>l.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(l.max_budget))}}],children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Reset Budget"," ",(0,m.jsx)(Y.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==l?void 0:l.budget_duration)!==null&&(null==l?void 0:l.budget_duration)!==void 0?null==l?void 0:l.budget_duration:"None"),children:(0,m.jsx)(ek,{onChange:e=>o.setFieldValue("budget_duration",e)})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==l?void 0:l.tpm_limit)!==null&&(null==l?void 0:l.tpm_limit)!==void 0?null==l?void 0:l.tpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.tpm_limit&&s>l.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(l.tpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==l?void 0:l.rpm_limit)!==null&&(null==l?void 0:l.rpm_limit)!==void 0?null==l?void 0:l.rpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.rpm_limit&&s>l.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(l.rpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Expire Key"," ",(0,m.jsx)(Y.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,m.jsx)(I.Z,{placeholder:"e.g., 30d"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:V.map(e=>({value:e,label:e}))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Tags"," ",(0,m.jsx)(Y.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:N})}),(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("b",{children:"Advanced Settings"}),(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,m.jsx)("a",{href:b.H2?"".concat(b.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,m.jsx)(W.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(ee,{schemaComponent:"GenerateKeyRequest",form:o,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Key"})})]})}),$&&(0,m.jsx)(R.Z,{title:"Create New User",visible:$,onCancel:()=>X(!1),footer:null,width:800,children:(0,m.jsx)(ev,{userID:s,accessToken:r,teams:t,possibleUIRoles:et,onUserCreated:e=>{el(e),o.setFieldsValue({user_id:e}),X(!1)},isEmbedded:!0})}),h&&(0,m.jsx)(R.Z,{visible:d,onOk:ed,onCancel:ec,footer:null,children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Save your Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:null!=h?(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:h})}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>{F.ZP.success("API Key copied to clipboard")},children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,m.jsx)(P.Z,{children:"Key being created, this might take 30s"})})]})})]})},eE=l(7366),eP=e=>{let{selectedTeam:s,currentOrg:l,selectedKeyAlias:t,accessToken:a,createClicked:r}=e,[i,n]=(0,u.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,u.useState)(!0),[c,m]=(0,u.useState)(null),h=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!a){console.log("accessToken",a);return}d(!0);let s="number"==typeof e.page?e.page:1,l="number"==typeof e.pageSize?e.pageSize:100,t=await (0,b.OD)(a,null,null,null,null,null,s,l);console.log("data",t),n(t),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,u.useEffect)(()=>{h(),console.log("selectedTeam",s,"currentOrg",l,"accessToken",a,"selectedKeyAlias",t)},[s,l,a,t,r]),{keys:i.keys,isLoading:o,error:c,pagination:{currentPage:i.current_page,totalPages:i.total_pages,totalCount:i.total_count},refresh:h,setKeys:e=>{n(s=>{let l="function"==typeof e?e(s.keys):e;return{...s,keys:l}})}}},eO=l(27281),eL=l(41649),eD=l(12514),eM=l(12485),eF=l(18135),eR=l(35242),eq=l(29706),eU=l(77991),ez=l(10900),eV=l(23628),eK=l(74998);function eB(e){var s,l;let{keyData:t,onCancel:a,onSubmit:r,teams:i,accessToken:n,userID:o,userRole:d}=e,[c]=M.Z.useForm(),[h,x]=(0,u.useState)([]),p=null==i?void 0:i.find(e=>e.team_id===t.team_id),[g,j]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(o&&d&&n)try{if(null===t.team_id){let e=(await (0,b.So)(n,o,d)).data.map(e=>e.id);j(e)}else if(null==p?void 0:p.team_id){let e=await eI(o,d,n,p.team_id);j(Array.from(new Set([...p.models,...e])))}}catch(e){console.error("Error fetching models:",e)}})()},[o,d,n,p,t.team_id]);let f={...t,budget_duration:(l=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[l]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(s=t.metadata)||void 0===s?void 0:s.guardrails)||[]};return(0,m.jsxs)(M.Z,{form:c,onFinish:r,initialValues:f,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[g.length>0&&(0,m.jsx)(D.default.Option,{value:"all-team-models",children:"All Team Models"}),g.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,style:{width:"100%"},placeholder:"Enter a numerical value"})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"daily",children:"Daily"}),(0,m.jsx)(D.default.Option,{value:"weekly",children:"Weekly"}),(0,m.jsx)(D.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsx)(M.Z.Item,{name:"token",hidden:!0,children:(0,m.jsx)(z.default,{})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(C.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]})}function eH(e){let{selectedToken:s,visible:l,onClose:t,accessToken:a}=e,[r]=M.Z.useForm(),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!1);(0,u.useEffect)(()=>{l&&s&&r.setFieldsValue({key_alias:s.key_alias,max_budget:s.max_budget,tpm_limit:s.tpm_limit,rpm_limit:s.rpm_limit,duration:s.duration||""})},[l,s,r]),(0,u.useEffect)(()=>{l||(n(null),p(!1),r.resetFields())},[l,r]),(0,u.useEffect)(()=>{(null==o?void 0:o.duration)?h((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString()}catch(e){return null}})(o.duration)):h(null)},[null==o?void 0:o.duration]);let g=async()=>{if(s&&a){p(!0);try{let e=await r.validateFields(),l=await (0,b.s0)(a,s.token,e);n(l.key),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key"),p(!1)}}},j=()=>{n(null),p(!1),r.resetFields(),t()};return(0,m.jsx)(R.Z,{title:"Regenerate API Key",open:l,onCancel:j,footer:i?[(0,m.jsx)(C.Z,{onClick:j,children:"Close"},"close")]:[(0,m.jsx)(C.Z,{onClick:j,className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:i?(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:(null==s?void 0:s.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:i})}),(0,m.jsx)(L.CopyToClipboard,{text:i,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,m.jsxs)(M.Z,{form:r,layout:"vertical",onValuesChange:e=>{"duration"in e&&d(s=>({...s,duration:e.duration}))},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==s?void 0:s.expires)?new Date(s.expires).toLocaleString():"Never"]}),c&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",c]})]})})}function eJ(e){var s,l;let{keyId:t,onClose:a,keyData:r,accessToken:i,userID:n,userRole:o,teams:d,onKeyDataUpdate:c,onDelete:h}=e,[x,p]=(0,u.useState)(!1),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1);if(!r)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(P.Z,{children:"Key not found"})]});let y=async e=>{try{var s,l;if(!i)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let l=JSON.parse(e.metadata);e.metadata={...l,...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),F.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]);let a=await (0,b.Nc)(i,e);c&&c(a),F.ZP.success("Key updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!i)return;await (0,b.I1)(i,r.token),F.ZP.success("Key deleted successfully"),h&&h(),a()}catch(e){console.error("Error deleting the key:",e),F.ZP.error("Failed to delete key")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(O.Z,{children:r.key_alias||"API Key"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:r.token})]}),o&&eZ.LQ.includes(o)&&(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{icon:eV.Z,variant:"secondary",onClick:()=>v(!0),className:"flex items-center",children:"Regenerate Key"}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>f(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,m.jsx)(eH,{selectedToken:r,visible:_,onClose:()=>v(!1),accessToken:i}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>f(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number(r.spend).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",null!==r.max_budget?"$".concat(r.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Key Settings"}),!x&&o&&eZ.LQ.includes(o)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>p(!0),children:"Edit Settings"})]}),x?(0,m.jsx)(eB,{keyData:r,onCancel:()=>p(!1),onSubmit:y,teams:d,accessToken:i,userID:n,userRole:o}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.token})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key Alias"}),(0,m.jsx)(P.Z,{children:r.key_alias||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Secret Key"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.key_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)(P.Z,{children:r.team_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),(0,m.jsx)(P.Z,{children:r.organization_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:new Date(r.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Expires"}),(0,m.jsx)(P.Z,{children:r.expires?new Date(r.expires).toLocaleString():"Never"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Spend"}),(0,m.jsxs)(P.Z,{children:["$",Number(r.spend).toFixed(4)," USD"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsx)(P.Z,{children:null!==r.max_budget?"$".concat(r.max_budget," USD"):"Unlimited"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",null!==r.max_parallel_requests?r.max_parallel_requests:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model TPM Limits: ",(null===(s=r.metadata)||void 0===s?void 0:s.model_tpm_limit)?JSON.stringify(r.metadata.model_tpm_limit):"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model RPM Limits: ",(null===(l=r.metadata)||void 0===l?void 0:l.model_rpm_limit)?JSON.stringify(r.metadata.model_rpm_limit):"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(r.metadata,null,2)})]})]})]})})]})]})]})}var eG=l(2356),eW=e=>{let{options:s,onApplyFilters:l,onResetFilters:t,initialValues:a={},buttonLabel:r="Filters"}=e,[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(a),[c,h]=(0,u.useState)({}),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)({}),f=(0,u.useCallback)(eb()(async(e,s)=>{if(s.isSearchable&&s.searchFn){p(e=>({...e,[s.name]:!0}));try{let l=await s.searchFn(e);h(e=>({...e,[s.name]:l}))}catch(e){console.error("Error searching:",e),h(e=>({...e,[s.name]:[]}))}finally{p(e=>({...e,[s.name]:!1}))}}},300),[]),_=(e,s)=>{let t={...o,[e]:s};d(t),l(t)};return(0,m.jsxs)("div",{className:"w-full",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eG.Z,{className:"h-4 w-4"}),onClick:()=>n(!i),className:"flex items-center gap-2",children:r}),(0,m.jsx)(U.ZP,{onClick:()=>{let e={};s.forEach(s=>{e[s.name]=""}),d(e),t()},children:"Reset Filters"})]}),i&&(0,m.jsx)("div",{className:"grid grid-cols-3 gap-x-6 gap-y-4 mb-6",children:["Team ID","Status","Organization ID","Key Alias","User ID","Key Hash"].map(e=>{let l=s.find(s=>s.label===e||s.name===e);return l?(0,m.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,m.jsx)("label",{className:"text-sm text-gray-600",children:l.label||l.name}),l.isSearchable?(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),onSearch:e=>{j(s=>({...s,[l.name]:e})),l.searchFn&&f(e,l)},filterOption:!1,loading:x[l.name],options:c[l.name]||[],allowClear:!0}):l.options?(0,m.jsx)(D.default,{className:"w-full",placeholder:"Select ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),allowClear:!0,children:l.options.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))}):(0,m.jsx)(z.default,{className:"w-full",placeholder:"Enter ".concat(l.label||l.name,"..."),value:o[l.name]||"",onChange:e=>_(l.name,e.target.value),allowClear:!0})]},l.name):null})})]})},eY=l(16593);let e$=async e=>{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.OD)(e,null,"",null,null,null,l,100),r=a.keys.map(e=>e.key_alias).filter(Boolean);s=[...s,...r],l{if(!e)return[];try{let l=[],t=1,a=!0;for(;a;){let r=await (0,b.It)(e,s||null,null);l=[...l,...r],t{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.r6)(e);s=[...s,...a],l{let[e,s]=(0,u.useState)("http://localhost:4000");return(0,u.useEffect)(()=>{{let{protocol:e,host:l}=window.location;s("".concat(e,"//").concat(l))}},[]),e};function e1(e,s){let l=structuredClone(e);for(let[e,t]of Object.entries(s))e in l&&(l[e]=t);return l}var e2=l(71594),e4=l(24525),e5=l(21626),e3=l(97214),e6=l(28241),e8=l(58834),e7=l(69552),e9=l(71876),se=l(44633),ss=l(86462),sl=l(49084);function st(e){let{keys:s,setKeys:l,isLoading:t=!1,pagination:a,onPageChange:r,pageSize:i=50,teams:n,selectedTeam:o,setSelectedTeam:d,selectedKeyAlias:c,setSelectedKeyAlias:h,accessToken:x,userID:p,userRole:g,organizations:j,setCurrentOrg:f,refresh:_,onSortChange:v,currentSort:y}=e,[Z,N]=(0,u.useState)(null),[w,k]=(0,u.useState)([]),[S,I]=u.useState(()=>y?[{id:y.sortBy,desc:"desc"===y.sortOrder}]:[{id:"created_at",desc:!0}]),{filters:T,filteredKeys:A,allKeyAliases:E,allTeams:P,allOrganizations:O,handleFilterChange:L,handleFilterReset:D}=function(e){let{keys:s,teams:l,organizations:t,accessToken:a}=e,r={"Team ID":"","Organization ID":"","Key Alias":"","User ID":"","Sort By":"created_at","Sort Order":"desc"},[i,n]=(0,u.useState)(r),[o,d]=(0,u.useState)(l||[]),[c,m]=(0,u.useState)(t||[]),[h,x]=(0,u.useState)(s),p=(0,u.useRef)(0),g=(0,u.useCallback)(eb()(async e=>{if(!a)return;let s=Date.now();p.current=s;try{let l=await (0,b.OD)(a,e["Organization ID"]||null,e["Team ID"]||null,e["Key Alias"]||null,e["User ID"]||null,e["Key Hash"]||null,1,25,e["Sort By"]||null,e["Sort Order"]||null);s===p.current&&l&&(x(l.keys),console.log("called from debouncedSearch filters:",JSON.stringify(e)),console.log("called from debouncedSearch data:",JSON.stringify(l)))}catch(e){console.error("Error searching users:",e)}},300),[a]);(0,u.useEffect)(()=>{if(!s){x([]);return}let e=[...s];i["Team ID"]&&(e=e.filter(e=>e.team_id===i["Team ID"])),i["Organization ID"]&&(e=e.filter(e=>e.organization_id===i["Organization ID"])),x(e)},[s,i]),(0,u.useEffect)(()=>{let e=async()=>{let e=await eX(a);e.length>0&&d(e);let s=await eQ(a);s.length>0&&m(s)};a&&e()},[a]);let j=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!a)throw Error("Access token required");return await e$(a)},enabled:!!a}).data||[];return(0,u.useEffect)(()=>{l&&l.length>0&&d(e=>e.length{t&&t.length>0&&m(e=>e.length{n({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||"","Key Alias":e["Key Alias"]||"","User ID":e["User ID"]||"","Sort By":e["Sort By"]||"created_at","Sort Order":e["Sort Order"]||"desc"}),g({...i,...e})},handleFilterReset:()=>{n(r),g(r)}}}({keys:s,teams:n,organizations:j,accessToken:x});(0,u.useEffect)(()=>{if(x){let e=s.map(e=>e.user_id).filter(e=>null!==e);(async()=>{k((await (0,b.Of)(x,e,1,100)).users)})()}},[x,s]),(0,u.useEffect)(()=>{if(_){let e=()=>{_()};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}},[_]);let M=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return s.getCanExpand()?(0,m.jsx)("button",{onClick:s.getToggleExpandedHandler(),style:{cursor:"pointer"},children:s.getIsExpanded()?"▼":"▶"}):null}},{id:"token",accessorKey:"token",header:"Key ID",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>N(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{id:"key_alias",accessorKey:"key_alias",header:"Key Alias",cell:e=>{let s=e.getValue();return(0,m.jsx)(Y.Z,{title:s,children:s?s.length>20?"".concat(s.slice(0,20),"..."):s:"-"})}},{id:"key_name",accessorKey:"key_name",header:"Secret Key",cell:e=>(0,m.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{id:"team_alias",accessorKey:"team_id",header:"Team Alias",cell:e=>{let{row:s,getValue:l}=e,t=l(),a=null==n?void 0:n.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{id:"team_id",accessorKey:"team_id",header:"Team ID",cell:e=>(0,m.jsx)(Y.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{id:"organization_id",accessorKey:"organization_id",header:"Organization ID",cell:e=>e.getValue()?e.renderValue():"-"},{id:"user_email",accessorKey:"user_id",header:"User Email",cell:e=>{let s=e.getValue(),l=w.find(e=>e.user_id===s);return(null==l?void 0:l.user_email)?l.user_email:"-"}},{id:"user_id",accessorKey:"user_id",header:"User ID",cell:e=>{let s=e.getValue();return s?(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsxs)("span",{children:[s.slice(0,7),"..."]})}):"-"}},{id:"created_at",accessorKey:"created_at",header:"Created At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"-"}},{id:"created_by",accessorKey:"created_by",header:"Created By",cell:e=>e.getValue()||"Unknown"},{id:"expires",accessorKey:"expires",header:"Expires",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"spend",accessorKey:"spend",header:"Spend (USD)",cell:e=>Number(e.getValue()).toFixed(4)},{id:"max_budget",accessorKey:"max_budget",header:"Budget (USD)",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{id:"budget_reset_at",accessorKey:"budget_reset_at",header:"Budget Reset",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleString():"Never"}},{id:"models",accessorKey:"models",header:"Models",cell:e=>{let s=e.getValue();return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:s&&s.length>0?s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):"-"})}},{id:"rate_limits",header:"Rate Limits",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:["TPM: ",null!==l.tpm_limit?l.tpm_limit:"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",null!==l.rpm_limit?l.rpm_limit:"Unlimited"]})]})}}];console.log("keys: ".concat(JSON.stringify(s)));let F=(0,e2.b7)({data:A,columns:M.filter(e=>"expander"!==e.id),state:{sorting:S},onSortingChange:e=>{let s="function"==typeof e?e(S):e;if(console.log("newSorting: ".concat(JSON.stringify(s))),I(s),s&&s.length>0){let e=s[0],l=e.id,t=e.desc?"desc":"asc";console.log("sortBy: ".concat(l,", sortOrder: ").concat(t)),L({...T,"Sort By":l,"Sort Order":t}),null==v||v(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,manualSorting:!1});return u.useEffect(()=>{y&&I([{id:y.sortBy,desc:"desc"===y.sortOrder}])},[y]),(0,m.jsx)("div",{className:"w-full h-full overflow-hidden",children:Z?(0,m.jsx)(eJ,{keyId:Z,onClose:()=>N(null),keyData:A.find(e=>e.token===Z),onKeyDataUpdate:e=>{l(s=>s.map(s=>s.token===e.token?e1(s,e):s))},onDelete:()=>{l(e=>e.filter(e=>e.token!==Z))},accessToken:x,userID:p,userRole:g,teams:P}):(0,m.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,m.jsx)("div",{className:"w-full mb-6",children:(0,m.jsx)(eW,{options:[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>P&&0!==P.length?P.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:async e=>O&&0!==O.length?O.filter(s=>{var l,t;return null!==(t=null===(l=s.organization_id)||void 0===l?void 0:l.toLowerCase().includes(e.toLowerCase()))&&void 0!==t&&t}).filter(e=>null!==e.organization_id&&void 0!==e.organization_id).map(e=>({label:"".concat(e.organization_id||"Unknown"," (").concat(e.organization_id,")"),value:e.organization_id})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>E.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))},{name:"User ID",label:"User ID",isSearchable:!1},{name:"Key Hash",label:"Key Hash",isSearchable:!1}],onApplyFilters:L,initialValues:T,onResetFilters:D})}),(0,m.jsxs)("div",{className:"flex items-center justify-between w-full mb-4",children:[(0,m.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",t?"...":"".concat((a.currentPage-1)*i+1," - ").concat(Math.min(a.currentPage*i,a.totalCount))," of ",t?"...":a.totalCount," results"]}),(0,m.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",t?"...":a.currentPage," of ",t?"...":a.totalPages]}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage-1),disabled:t||1===a.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage+1),disabled:t||a.currentPage===a.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]}),(0,m.jsx)("div",{className:"h-[75vh] overflow-auto",children:(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:F.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading keys..."})})})}):A.length>0?F.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No keys found"})})})})})]})})})})]})})}console.log=function(){};var sa=e=>{let{userID:s,userRole:l,accessToken:t,selectedTeam:a,setSelectedTeam:r,data:i,setData:n,teams:o,premiumUser:d,currentOrg:c,organizations:h,setCurrentOrg:x,selectedKeyAlias:p,setSelectedKeyAlias:g,createClicked:j}=e,[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(null),[w,T]=(0,u.useState)(null),[A,E]=(0,u.useState)(null),[D,q]=(0,u.useState)((null==a?void 0:a.team_id)||"");(0,u.useEffect)(()=>{q((null==a?void 0:a.team_id)||"")},[a]);let{keys:U,isLoading:z,error:V,pagination:K,refresh:H,setKeys:J}=eP({selectedTeam:a,currentOrg:c,selectedKeyAlias:p,accessToken:t,createClicked:j}),[W,Y]=(0,u.useState)(!1),[$,X]=(0,u.useState)(!1),[Q,ee]=(0,u.useState)(null),[es,el]=(0,u.useState)([]),et=new Set,[ea,er]=(0,u.useState)(!1),[ei,en]=(0,u.useState)(!1),[eo,ed]=(0,u.useState)(null),[ec,em]=(0,u.useState)(null),[eu]=M.Z.useForm(),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)(et),[ej,ef]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",Q),(null==ec?void 0:ec.duration)?ex((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(ec.duration)):ex(null),console.log("calculateNewExpiryTime:",eh)},[Q,null==ec?void 0:ec.duration]),(0,u.useEffect)(()=>{(async()=>{try{if(null===s||null===l||null===t)return;let e=await B(s,l,t);e&&el(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,s,l]),(0,u.useEffect)(()=>{if(o){let e=new Set;o.forEach((s,l)=>{let t=s.team_id;e.add(t)}),eg(e)}},[o]);let e_=async()=>{if(null!=Z&&null!=i){try{await (0,b.I1)(t,Z);let e=i.filter(e=>e.token!==Z);n(e)}catch(e){console.error("Error deleting the key:",e)}y(!1),N(null)}},ev=(e,s)=>{em(l=>({...l,[e]:s}))},ey=async()=>{if(!d){F.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=Q)try{let e=await eu.validateFields(),s=await (0,b.s0)(t,Q.token,e);if(ed(s.key),i){let l=i.map(l=>l.token===(null==Q?void 0:Q.token)?{...l,key_name:s.key_name,...e}:l);n(l)}en(!1),eu.resetFields(),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key")}};return(0,m.jsxs)("div",{children:[(0,m.jsx)(st,{keys:U,setKeys:J,isLoading:z,pagination:K,onPageChange:e=>{H({page:e})},pageSize:100,teams:o,selectedTeam:a,setSelectedTeam:r,accessToken:t,userID:s,userRole:l,organizations:h,setCurrentOrg:x,refresh:H,selectedKeyAlias:p,setSelectedKeyAlias:g}),v&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{y(!1),N(null)},children:"Cancel"})]})]})]})}),(0,m.jsx)(R.Z,{title:"Regenerate API Key",visible:ei,onCancel:()=>{en(!1),eu.resetFields()},footer:[(0,m.jsx)(C.Z,{onClick:()=>{en(!1),eu.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:ey,disabled:!d,children:d?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:d?(0,m.jsxs)(M.Z,{form:eu,layout:"vertical",onValuesChange:(e,s)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==Q?void 0:Q.expires)!=null?new Date(Q.expires).toLocaleString():"Never"]}),eh&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",eh]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),eo&&(0,m.jsx)(R.Z,{visible:!!eo,onCancel:()=>ed(null),footer:[(0,m.jsx)(C.Z,{onClick:()=>ed(null),children:"Close"},"close")],children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==Q?void 0:Q.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:eo})}),(0,m.jsx)(L.CopyToClipboard,{text:eo,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},sr=l(12011);console.log=function(){},console.log("isLocal:",!1);var si=e=>{let{userID:s,userRole:l,teams:t,keys:a,setUserRole:r,userEmail:i,setUserEmail:n,setTeams:o,setKeys:d,premiumUser:c,organizations:p,addKey:g,createClicked:j}=e,[f,_]=(0,u.useState)(null),[v,Z]=(0,u.useState)(null),N=(0,h.useSearchParams)(),C=function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token"),I=N.get("invitation_id"),[T,A]=(0,u.useState)(null),[E,P]=(0,u.useState)(null),[O,L]=(0,u.useState)([]),[D,M]=(0,u.useState)(null),[F,R]=(0,u.useState)(null),[q,U]=(0,u.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,u.useEffect)(()=>{if(C){let e=(0,x.o)(C);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),A(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),r(s)}else console.log("User role not defined");e.user_email?n(e.user_email):console.log("User Email is not set ".concat(e))}}if(s&&T&&l&&!a&&!f){let e=sessionStorage.getItem("userModels"+s);e?L(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(v))),(async()=>{try{let e=await (0,b.g)(T);M(e);let t=await (0,b.Br)(T,s,l,!1,null,null);_(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(f))),(null==t?void 0:t.teams[0].keys)?d(t.keys.concat(t.teams.filter(e=>"Admin"===l||e.user_id===s).flatMap(e=>e.keys))):d(t.keys),sessionStorage.setItem("userData"+s,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+s,JSON.stringify(t.user_info));let a=(await (0,b.So)(T,s,l)).data.map(e=>e.id);console.log("available_model_names:",a),L(a),console.log("userModels:",O),sessionStorage.setItem("userModels"+s,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e),e.message.includes("Invalid proxy server token passed")&&z()}})(),w(T,s,l,v,o))}},[s,C,T,a,l]),(0,u.useEffect)(()=>{T&&(async()=>{try{let e=await (0,b.e2)(T,[T]);console.log("keyInfo: ",e)}catch(e){e.message.includes("Invalid proxy server token passed")&&z()}})()},[T]),(0,u.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(v),", accessToken: ").concat(T,", userID: ").concat(s,", userRole: ").concat(l)),T&&(console.log("fetching teams"),w(T,s,l,v,o))},[v]),(0,u.useEffect)(()=>{if(null!==a&&null!=F&&null!==F.team_id){let e=0;for(let s of(console.log("keys: ".concat(JSON.stringify(a))),a))F.hasOwnProperty("team_id")&&null!==s.team_id&&s.team_id===F.team_id&&(e+=s.spend);console.log("sum: ".concat(e)),P(e)}else if(null!==a){let e=0;for(let s of a)e+=s.spend;P(e)}},[F]),null!=I)return(0,m.jsx)(sr.default,{});function z(){(0,y.b)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return console.log("All cookies before redirect:",document.cookie),z(),null;try{let e=(0,x.o)(C);console.log("Decoded token:",e);let s=e.exp,l=Math.floor(Date.now()/1e3);if(s&&l>=s){console.log("Token expired, redirecting to login"),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL for expired token:",e),window.location.href=e,null}}catch(s){console.error("Error decoding token:",s),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL after token decode error:",e),window.location.href=e,null}if(null==T)return null;if(null==s)return(0,m.jsx)("h1",{children:"User ID is not set"});if(null==l&&r("App Owner"),l&&"Admin Viewer"==l){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",F),console.log("All cookies after redirect:",document.cookie),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(k.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,m.jsx)(eA,{userID:s,team:F,teams:t,userRole:l,accessToken:T,data:a,addKey:g},F?F.team_id:null),(0,m.jsx)(sa,{userID:s,userRole:l,accessToken:T,selectedTeam:F||null,setSelectedTeam:R,selectedKeyAlias:q,setSelectedKeyAlias:U,data:a,setData:d,premiumUser:c,teams:t,currentOrg:v,setCurrentOrg:Z,organizations:p,createClicked:j})]})})})},sn=l(97765);(t=n||(n={})).OpenAI="OpenAI",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.OpenAI_Text="OpenAI Text Completion",t.OpenAI_Text_Compatible="OpenAI-Compatible Text Completion Models (Together AI, etc.)",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI",t.Cerebras="Cerebras",t.Sambanova="Sambanova",t.Perplexity="Perplexity",t.TogetherAI="TogetherAI",t.Openrouter="Openrouter",t.FireworksAI="Fireworks AI",t.Triton="Triton";let so={OpenAI:"openai",OpenAI_Text:"text-completion-openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",OpenAI_Text_Compatible:"text-completion-openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai",Cerebras:"cerebras",Sambanova:"sambanova",Perplexity:"perplexity",TogetherAI:"together_ai",Openrouter:"openrouter",FireworksAI:"fireworks_ai",Triton:"triton"},sd="/ui/assets/logos/",sc={Anthropic:"".concat(sd,"anthropic.svg"),AssemblyAI:"".concat(sd,"assemblyai_small.png"),Azure:"".concat(sd,"microsoft_azure.svg"),"Azure AI Foundry (Studio)":"".concat(sd,"microsoft_azure.svg"),"Amazon Bedrock":"".concat(sd,"bedrock.svg"),Cerebras:"".concat(sd,"cerebras.svg"),Cohere:"".concat(sd,"cohere.svg"),Databricks:"".concat(sd,"databricks.svg"),Deepseek:"".concat(sd,"deepseek.svg"),"Fireworks AI":"".concat(sd,"fireworks.svg"),Groq:"".concat(sd,"groq.svg"),"Google AI Studio":"".concat(sd,"google.svg"),"Mistral AI":"".concat(sd,"mistral.svg"),Ollama:"".concat(sd,"ollama.svg"),OpenAI:"".concat(sd,"openai_small.svg"),"OpenAI Text Completion":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Text Completion Models (Together AI, etc.)":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Endpoints (Together AI, etc.)":"".concat(sd,"openai_small.svg"),Openrouter:"".concat(sd,"openrouter.svg"),Perplexity:"".concat(sd,"perplexity-ai.svg"),Sambanova:"".concat(sd,"sambanova.svg"),TogetherAI:"".concat(sd,"togetherai.svg"),"Vertex AI (Anthropic, Gemini, etc.)":"".concat(sd,"google.svg"),xAI:"".concat(sd,"xai.svg"),Triton:"".concat(sd,"nvidia_triton.png")},sm=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:sc[e],displayName:e}}let s=Object.keys(so).find(s=>so[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=n[s];return{logo:sc[l],displayName:l}},su=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",sh=(e,s)=>{console.log("Provider key: ".concat(e));let l=so[e];console.log("Provider mapped to: ".concat(l));let t=[];return e&&"object"==typeof s&&(Object.entries(s).forEach(e=>{let[s,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===l||a.litellm_provider.includes(l))&&t.push(s)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(s).forEach(e=>{let[s,l]=e;null!==l&&"object"==typeof l&&"litellm_provider"in l&&"cohere"===l.litellm_provider&&t.push(s)}))),t},sx=async(e,s,l)=>{try{console.log("handling submit for formValues:",e);let s=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=so[e.custom_llm_provider]+"/*";e.model_name=l,s.push({public_name:l,litellm_model:l}),e.model=l}let l=[];for(let t of s){let s={},a={},r=t.public_name;for(let[l,r]of(s.model=t.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),s.model=t.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l&&"cache_control"!==l){if("model_name"==l)s.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=so[r];s.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("mode"==l)console.log("placing mode in modelInfo"),a.mode=r,delete s.mode;else if("custom_model_name"===l)s.model=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[s,l]of Object.entries(e))a[s]=l}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(s[l]=Number(r));continue}else s[l]=r}l.push({litellmParamsObj:s,modelInfoObj:a,modelName:r})}return l}catch(e){F.ZP.error("Failed to create model: "+e,10)}},sp=async(e,s,l,t)=>{try{let a=await sx(e,s,l);if(!a||0===a.length)return;for(let e of a){let{litellmParamsObj:l,modelInfoObj:t,modelName:a}=e,r={model_name:a,litellm_params:l,model_info:t},i=await (0,b.kK)(s,r);console.log("response for model create call: ".concat(i.data))}t&&t(),l.resetFields()}catch(e){F.ZP.error("Failed to add model: "+e,10)}};var sg=l(53410),sj=l(47451),sf=l(69410);let{Link:s_}=et.default,sv={[n.OpenAI]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.OpenAI_Text]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.Vertex_AI]:[{key:"vertex_project",label:"Vertex Project",placeholder:"adroit-cadet-1234..",required:!0},{key:"vertex_location",label:"Vertex Location",placeholder:"us-east-1",required:!0},{key:"vertex_credentials",label:"Vertex Credentials",required:!0,type:"upload"}],[n.AssemblyAI]:[{key:"api_base",label:"API Base",type:"select",required:!0,options:["https://api.assemblyai.com","https://api.eu.assemblyai.com"]},{key:"api_key",label:"AssemblyAI API Key",type:"password",required:!0}],[n.Azure]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_version",label:"API Version",placeholder:"2023-07-01-preview",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here"},{key:"base_model",label:"Base Model",placeholder:"azure/gpt-3.5-turbo"},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[n.Azure_AI_Studio]:[{key:"api_base",label:"API Base",placeholder:"https://.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",tooltip:"Enter your full Target URI from Azure Foundry here. Example: https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",required:!0},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[n.OpenAI_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.OpenAI_Text_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.Bedrock]:[{key:"aws_access_key_id",label:"AWS Access Key ID",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[n.Ollama]:[{key:"api_base",label:"API Base",placeholder:"http://localhost:11434",defaultValue:"http://localhost:11434",required:!1,tooltip:"The base URL for your Ollama server. Defaults to http://localhost:11434 if not specified."}],[n.Anthropic]:[{key:"api_key",label:"API Key",placeholder:"sk-",type:"password",required:!0}],[n.Google_AI_Studio]:[{key:"api_key",label:"API Key",placeholder:"aig-",type:"password",required:!0}],[n.Groq]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.MistralAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Deepseek]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Cohere]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Databricks]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.xAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Cerebras]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Sambanova]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Perplexity]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.TogetherAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Openrouter]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.FireworksAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Triton]:[{key:"api_key",label:"API Key",type:"password",required:!1},{key:"api_base",label:"API Base",placeholder:"http://localhost:8000/generate",required:!1}]};var sy=e=>{let{selectedProvider:s,uploadProps:l}=e,t=n[s],a=M.Z.useFormInstance(),r=u.useMemo(()=>sv[t]||[],[t]),i={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Setting field value from JSON, length: ".concat(s.length)),a.setFieldsValue({vertex_credentials:s}),console.log("Form values after setting:",a.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered in ProviderSpecificFields"),console.log("Current form values:",a.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList)}};return(0,m.jsx)(m.Fragment,{children:r.map(e=>{var s;return(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:e.label,name:e.key,rules:e.required?[{required:!0,message:"Required"}]:void 0,tooltip:e.tooltip,className:"vertex_credentials"===e.key?"mb-0":void 0,children:"select"===e.type?(0,m.jsx)(D.default,{placeholder:e.placeholder,defaultValue:e.defaultValue,children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"upload"===e.type?(0,m.jsx)(er.Z,{...i,onChange:s=>{(null==l?void 0:l.onChange)&&l.onChange(s),setTimeout(()=>{let s=a.getFieldValue(e.key);console.log("".concat(e.key," value after upload:"),JSON.stringify(s))},500)},children:(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eu.Z,{}),children:"Click to Upload"})}):(0,m.jsx)(I.Z,{placeholder:e.placeholder,type:"password"===e.type?"password":"text"})}),"vertex_credentials"===e.key&&(0,m.jsx)(sj.Z,{children:(0,m.jsx)(sf.Z,{children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Give a gcp service account(.json file)"})})}),"base_model"===e.key&&(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,m.jsx)(s_,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]},e.key)})})};let{Title:sb,Link:sZ}=et.default;var sN=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,onUpdateCredential:a,uploadProps:r,addOrEdit:i,existingCredential:o}=e,[d]=M.Z.useForm(),[c,h]=(0,u.useState)(n.OpenAI),[x,p]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{o&&(d.setFieldsValue({credential_name:o.credential_name,custom_llm_provider:o.credential_info.custom_llm_provider,api_base:o.credential_values.api_base,api_version:o.credential_values.api_version,base_model:o.credential_values.base_model,api_key:o.credential_values.api_key}),h(o.credential_info.custom_llm_provider))},[o]),(0,m.jsx)(R.Z,{title:"add"===i?"Add New Credential":"Edit Credential",visible:s,onCancel:()=>{l(),d.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:d,onFinish:e=>{"add"===i?t(e):a(e),d.resetFields()},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==o?void 0:o.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials",disabled:null!=o&&!!o.credential_name})}),(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"Helper to auto-populate provider specific fields",children:(0,m.jsx)(D.default,{onChange:e=>{h(e),d.setFieldValue("custom_llm_provider",e)},children:Object.entries(n).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(sy,{selectedProvider:c,uploadProps:r}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sZ,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),d.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"add"===i?"Add Credential":"Update Credential"})]})]})]})})},sw=e=>{let{accessToken:s,uploadProps:l,credentialList:t,fetchCredentials:a}=e,[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(null),[h]=M.Z.useForm(),x=["credential_name","custom_llm_provider"],p=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.eZ)(s,e.credential_name,t),F.ZP.success("Credential updated successfully"),o(!1),a(s)},g=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.oC)(s,t),F.ZP.success("Credential added successfully"),i(!1),a(s)};(0,u.useEffect)(()=>{s&&a(s)},[s]);let j=e=>{let s={openai:"blue",azure:"indigo",anthropic:"purple",default:"gray"},l=s[e.toLowerCase()]||s.default;return(0,m.jsx)(eL.Z,{color:l,size:"xs",children:e})},f=async e=>{s&&(await (0,b.gX)(s,e),F.ZP.success("Credential deleted successfully"),a(s))};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)(P.Z,{children:["Configured credentials for different AI providers. Add and manage your API credentials."," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/credentials",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]})}),(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Credential Name"}),(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Description"})]})}),(0,m.jsx)(e3.Z,{children:t&&0!==t.length?t.map((e,s)=>{var l,t;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.credential_name}),(0,m.jsx)(e6.Z,{children:j((null===(l=e.credential_info)||void 0===l?void 0:l.custom_llm_provider)||"-")}),(0,m.jsx)(e6.Z,{children:(null===(t=e.credential_info)||void 0===t?void 0:t.description)||"-"}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{icon:sg.Z,variant:"light",size:"sm",onClick:()=>{c(e),o(!0)}}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"light",size:"sm",onClick:()=>f(e.credential_name)})]})]},s)}):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:4,className:"text-center py-4 text-gray-500",children:"No credentials configured"})})})]})}),(0,m.jsx)(C.Z,{onClick:()=>i(!0),className:"mt-4",children:"Add Credential"}),r&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:r,onCancel:()=>i(!1),uploadProps:l,addOrEdit:"add",onUpdateCredential:p,existingCredential:null}),n&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:n,existingCredential:d,onUpdateCredential:p,uploadProps:l,onCancel:()=>o(!1),addOrEdit:"edit"})]})};let sk=e=>{var s;return(null==e?void 0:null===(s=e.model_info)||void 0===s?void 0:s.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"};var sS=l(53003),sC=l(47323),sI=l(75105),sT=l(40278),sA=l(14301),sE=l(59664),sP=e=>{let{modelMetrics:s,modelMetricsCategories:l,customTooltip:t,premiumUser:a}=e;return(0,m.jsx)(sE.Z,{title:"Time to First token (s)",className:"h-72",data:s,index:"date",showLegend:!1,categories:l,colors:["indigo","rose"],connectNulls:!0,customTooltip:t})},sO=e=>{let{teamData:s,canEditTeam:l,handleMemberDelete:t,setSelectedEditMember:a,setIsEditMemberModalVisible:r,setIsAddMemberModalVisible:i}=e;return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"User Email"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:s.team_info.members_with_roles.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_email})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.role})}),(0,m.jsx)(e6.Z,{children:l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{a(e),r(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(e)})]})})]},s))})]})}),(0,m.jsx)(C.Z,{onClick:()=>i(!0),children:"Add Member"})]})},sL=l(61994),sD=l(85180),sM=l(89245),sF=l(78355);let sR={"/key/generate":"Member can generate a virtual key for this team","/key/update":"Member can update a virtual key belonging to this team","/key/delete":"Member can delete a virtual key belonging to this team","/key/info":"Member can get info about a virtual key belonging to this team","/key/regenerate":"Member can regenerate a virtual key belonging to this team","/key/{key_id}/regenerate":"Member can regenerate a virtual key belonging to this team","/key/list":"Member can list virtual keys belonging to this team","/key/block":"Member can block a virtual key belonging to this team","/key/unblock":"Member can unblock a virtual key belonging to this team"},sq=e=>e.includes("/info")||e.includes("/list")?"GET":"POST",sU=e=>{let s=sq(e),l=sR[e];if(!l){for(let[s,t]of Object.entries(sR))if(e.includes(s)){l=t;break}}return l||(l="Access ".concat(e)),{method:s,endpoint:e,description:l,route:e}};var sz=e=>{let{teamId:s,accessToken:l,canEditTeam:t}=e,[a,r]=(0,u.useState)([]),[i,n]=(0,u.useState)([]),[o,d]=(0,u.useState)(!0),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),g=async()=>{try{if(d(!0),!l)return;let e=await (0,b.aC)(l,s),t=e.all_available_permissions||[];r(t);let a=e.team_member_permissions||[];n(a),p(!1)}catch(e){F.ZP.error("Failed to load permissions"),console.error("Error fetching permissions:",e)}finally{d(!1)}};(0,u.useEffect)(()=>{g()},[s,l]);let j=(e,s)=>{n(s?[...i,e]:i.filter(s=>s!==e)),p(!0)},f=async()=>{try{if(!l)return;h(!0),await (0,b.TF)(l,s,i),F.ZP.success("Permissions updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update permissions"),console.error("Error updating permissions:",e)}finally{h(!1)}};if(o)return(0,m.jsx)("div",{className:"p-6 text-center",children:"Loading permissions..."});let _=a.length>0;return(0,m.jsxs)(eD.Z,{className:"bg-white shadow-md rounded-md p-6",children:[(0,m.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center border-b pb-4 mb-6",children:[(0,m.jsx)(O.Z,{className:"mb-2 sm:mb-0",children:"Member Permissions"}),t&&x&&(0,m.jsxs)("div",{className:"flex gap-3",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(sM.Z,{}),onClick:()=>{g()},children:"Reset"}),(0,m.jsxs)(C.Z,{onClick:f,loading:c,className:"flex items-center gap-2",children:[(0,m.jsx)(sF.Z,{})," Save Changes"]})]})]}),(0,m.jsx)(P.Z,{className:"mb-6 text-gray-600",children:"Control what team members can do when they are not team admins."}),_?(0,m.jsxs)(e5.Z,{className:"mt-4",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Method"}),(0,m.jsx)(e7.Z,{children:"Endpoint"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Access"})]})}),(0,m.jsx)(e3.Z,{children:a.map(e=>{let s=sU(e);return(0,m.jsxs)(e9.Z,{className:"hover:bg-gray-50 transition-colors",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat("GET"===s.method?"bg-blue-100 text-blue-800":"bg-green-100 text-green-800"),children:s.method})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"font-mono text-sm text-gray-800",children:s.endpoint})}),(0,m.jsx)(e6.Z,{className:"text-gray-700",children:s.description}),(0,m.jsx)(e6.Z,{className:"text-right",children:(0,m.jsx)(sL.Z,{checked:i.includes(e),onChange:s=>j(e,s.target.checked),disabled:!t})})]},e)})})]}):(0,m.jsx)("div",{className:"py-12",children:(0,m.jsx)(sD.Z,{description:"No permissions available"})})]})},sV=e=>{var s,l,t;let{visible:a,onCancel:r,onSubmit:i,initialData:n,mode:o,config:d}=e,[c]=M.Z.useForm();console.log("Initial Data:",n),(0,u.useEffect)(()=>{if(a){if("edit"===o&&n)c.setFieldsValue({...n,role:n.role||d.defaultRole});else{var e;c.resetFields(),c.setFieldsValue({role:d.defaultRole||(null===(e=d.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,n,o,c,d.defaultRole,d.roleOptions]);let h=async e=>{try{let s=Object.entries(e).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:"string"==typeof t?t.trim():t}},{});i(s),c.resetFields(),F.ZP.success("Successfully ".concat("add"===o?"added":"updated"," member"))}catch(e){F.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var s;return(0,m.jsx)(D.default,{children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,m.jsx)(R.Z,{title:d.title||("add"===o?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:r,children:(0,m.jsxs)(M.Z,{form:c,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[d.showEmail&&(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),d.showEmail&&d.showUserId&&(0,m.jsx)("div",{className:"text-center mb-4",children:(0,m.jsx)(P.Z,{children:"OR"})}),d.showUserId&&(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"Role"}),"edit"===o&&n&&(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(l=n.role,(null===(t=d.roleOptions.find(e=>e.value===l))||void 0===t?void 0:t.label)||l),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,m.jsx)(D.default,{children:"edit"===o&&n?[...d.roleOptions.filter(e=>e.value===n.role),...d.roleOptions.filter(e=>e.value!==n.role)].map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value)):d.roleOptions.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))})}),null===(s=d.additionalFields)||void 0===s?void 0:s.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,m.jsxs)("div",{className:"text-right mt-6",children:[(0,m.jsx)(U.ZP,{onClick:r,className:"mr-2",children:"Cancel"}),(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"add"===o?"Add Member":"Save Changes"})]})]})})},sK=e=>{let{isVisible:s,onCancel:l,onSubmit:t,accessToken:a,title:r="Add Team Member",roles:i=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:n="user"}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p,g]=(0,u.useState)("user_email"),j=async(e,s)=>{if(!e){c([]);return}x(!0);try{let l=new URLSearchParams;if(l.append(s,e),null==a)return;let t=(await (0,b.u5)(a,l)).map(e=>({label:"user_email"===s?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===s?e.user_email:e.user_id,user:e}));c(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},f=(0,u.useCallback)(eb()((e,s)=>j(e,s),300),[]),_=(e,s)=>{g(s),f(e,s)},v=(e,s)=>{let l=s.user;o.setFieldsValue({user_email:l.user_email,user_id:l.user_id,role:o.getFieldValue("role")})};return(0,m.jsx)(R.Z,{title:r,open:s,onCancel:()=>{o.resetFields(),c([]),l()},footer:null,width:800,children:(0,m.jsxs)(M.Z,{form:o,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:n},children:[(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>_(e,"user_email"),onSelect:(e,s)=>v(e,s),options:"user_email"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>_(e,"user_id"),onSelect:(e,s)=>v(e,s),options:"user_id"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:n,children:i.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:(0,m.jsxs)(Y.Z,{title:e.description,children:[(0,m.jsx)("span",{className:"font-medium",children:e.label}),(0,m.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,m.jsx)("div",{className:"text-right mt-4",children:(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},sB=e=>{var s;let{teamId:l,onClose:t,accessToken:a,is_team_admin:r,is_proxy_admin:i,userModels:n,editTeam:o}=e,[d,c]=(0,u.useState)(null),[h,x]=(0,u.useState)(!0),[p,g]=(0,u.useState)(!1),[j]=M.Z.useForm(),[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),[Z,N]=(0,u.useState)(!1);console.log("userModels in team info",n);let w=r||i,k=async()=>{try{if(x(!0),!a)return;let e=await (0,b.Xm)(a,l);c(e)}catch(e){F.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,u.useEffect)(()=>{k()},[l,a]);let I=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.cu)(a,l,s),F.ZP.success("Team member added successfully"),g(!1),j.resetFields(),k()}catch(e){F.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},T=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.sN)(a,l,s),F.ZP.success("Team member updated successfully"),_(!1),k()}catch(e){F.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},A=async e=>{try{if(null==a)return;await (0,b.Lp)(a,l,e),F.ZP.success("Team member removed successfully"),k()}catch(e){F.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},E=async e=>{try{if(!a)return;let s={};try{s=e.metadata?JSON.parse(e.metadata):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}let t={team_id:l,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...s,guardrails:e.guardrails||[]},organization_id:e.organization_id};await (0,b.Gh)(a,t),F.ZP.success("Team settings updated successfully"),N(!1),k()}catch(e){console.error("Error updating team:",e)}};if(h)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==d?void 0:d.team_info))return(0,m.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:L}=d;return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:L.team_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:L.team_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:o?3:0,children:[(0,m.jsx)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),...w?[(0,m.jsx)(eM.Z,{children:"Members"},"members"),(0,m.jsx)(eM.Z,{children:"Member Permissions"},"member-permissions"),(0,m.jsx)(eM.Z,{children:"Settings"},"settings")]:[]]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",L.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===L.max_budget?"Unlimited":"$".concat(L.max_budget)]}),L.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",L.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",L.rpm_limit||"Unlimited"]}),L.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",L.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sO,{teamData:d,canEditTeam:w,handleMemberDelete:A,setSelectedEditMember:y,setIsEditMemberModalVisible:_,setIsAddMemberModalVisible:g})}),w&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sz,{teamId:l,accessToken:a,canEditTeam:w})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Team Settings"}),w&&!Z&&(0,m.jsx)(C.Z,{onClick:()=>N(!0),children:"Edit Settings"})]}),Z?(0,m.jsxs)(M.Z,{form:j,onFinish:E,initialValues:{...L,team_alias:L.team_alias,models:L.models,tpm_limit:L.tpm_limit,rpm_limit:L.rpm_limit,max_budget:L.max_budget,budget_duration:L.budget_duration,guardrails:(null===(s=L.metadata)||void 0===s?void 0:s.guardrails)||[],metadata:L.metadata?JSON.stringify(L.metadata,null,2):"",organization_id:L.organization_id},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),n.map((e,s)=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},s))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>N(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team Name"}),(0,m.jsx)("div",{children:L.team_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"font-mono",children:L.team_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(L.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",L.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==L.max_budget?"$".concat(L.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",L.budget_duration||"Never"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{children:L.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Status"}),(0,m.jsx)(eL.Z,{color:L.blocked?"red":"green",children:L.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,m.jsx)(sV,{visible:f,onCancel:()=>_(!1),onSubmit:T,initialData:v,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,m.jsx)(sK,{isVisible:p,onCancel:()=>g(!1),onSubmit:I,accessToken:a})]})},sH=l(45589);let{Title:sJ,Link:sG}=et.default;var sW=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,existingCredential:a,setIsCredentialModalOpen:r}=e,[i]=M.Z.useForm();return console.log("existingCredential in add credentials tab: ".concat(JSON.stringify(a))),(0,m.jsx)(R.Z,{title:"Reuse Credentials",visible:s,onCancel:()=>{l(),i.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:i,onFinish:e=>{t(e),i.resetFields(),r(!1)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==a?void 0:a.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials"})}),Object.entries((null==a?void 0:a.credential_values)||{}).map(e=>{let[s,l]=e;return(0,m.jsx)(M.Z.Item,{label:s,name:s,initialValue:l,children:(0,m.jsx)(I.Z,{placeholder:"Enter ".concat(s),disabled:!0})},s)}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sG,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),i.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Reuse Credentials"})]})]})]})})},sY=l(63709),s$=l(45246),sX=l(96473);let{Text:sQ}=et.default;var s0=e=>{let{form:s,showCacheControl:l,onCacheControlChange:t}=e,a=e=>{let l=s.getFieldValue("litellm_extra_params");try{let t=l?JSON.parse(l):{};e.length>0?t.cache_control_injection_points=e:delete t.cache_control_injection_points,Object.keys(t).length>0?s.setFieldValue("litellm_extra_params",JSON.stringify(t,null,2)):s.setFieldValue("litellm_extra_params","")}catch(e){console.error("Error updating cache control points:",e)}};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Cache Control Injection Points",name:"cache_control",valuePropName:"checked",className:"mb-4",tooltip:"Tell litellm where to inject cache control checkpoints. You can specify either by role (to apply to all messages of that role) or by specific message index.",children:(0,m.jsx)(sY.Z,{onChange:t,className:"bg-gray-600"})}),l&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(sQ,{className:"text-sm text-gray-500 block mb-4",children:"Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature."}),(0,m.jsx)(M.Z.List,{name:"cache_control_injection_points",initialValue:[{location:"message"}],children:(e,l)=>{let{add:t,remove:r}=l;return(0,m.jsxs)(m.Fragment,{children:[e.map((l,t)=>(0,m.jsxs)("div",{className:"flex items-center mb-4 gap-4",children:[(0,m.jsx)(M.Z.Item,{...l,label:"Type",name:[l.name,"location"],initialValue:"message",className:"mb-0",style:{width:"180px"},children:(0,m.jsx)(D.default,{disabled:!0,options:[{value:"message",label:"Message"}]})}),(0,m.jsx)(M.Z.Item,{...l,label:"Role",name:[l.name,"role"],className:"mb-0",style:{width:"180px"},tooltip:"LiteLLM will mark all messages of this role as cacheable",children:(0,m.jsx)(D.default,{placeholder:"Select a role",allowClear:!0,options:[{value:"user",label:"User"},{value:"system",label:"System"},{value:"assistant",label:"Assistant"}],onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),(0,m.jsx)(M.Z.Item,{...l,label:"Index",name:[l.name,"index"],className:"mb-0",style:{width:"180px"},tooltip:"(Optional) If set litellm will mark the message at this index as cacheable",children:(0,m.jsx)(K,{type:"number",placeholder:"Optional",step:1,min:0,onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),e.length>1&&(0,m.jsx)(s$.Z,{className:"text-red-500 cursor-pointer text-lg ml-12",onClick:()=>{r(l.name),setTimeout(()=>{a(s.getFieldValue("cache_control_points"))},0)}})]},l.key)),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full border border-dashed border-gray-300 py-2 px-4 text-gray-600 hover:text-blue-600 hover:border-blue-300 transition-all rounded",onClick:()=>t(),children:[(0,m.jsx)(sX.Z,{className:"mr-2"}),"Add Injection Point"]})})]})}})]})]})};function s1(e){var s,l,t,a,r,i,n,o,d,c,h,x,p,g,j,f,_,v,y,Z,N;let{modelId:w,onClose:k,modelData:T,accessToken:A,userID:E,userRole:L,editModel:D,setEditModalVisible:q,setSelectedModel:z,onModelUpdate:V}=e,[B]=M.Z.useForm(),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)(!1),[X,Q]=(0,u.useState)(!1),[ee,es]=(0,u.useState)(!1),[el,et]=(0,u.useState)(!1),[ea,er]=(0,u.useState)(null),[ei,en]=(0,u.useState)(!1),eo="Admin"===L||T.model_info.created_by===E,ed=(null===(s=T.litellm_params)||void 0===s?void 0:s.litellm_credential_name)!=null&&(null===(l=T.litellm_params)||void 0===l?void 0:l.litellm_credential_name)!=void 0;console.log("usingExistingCredential, ",ed),console.log("modelData.litellm_params.litellm_credential_name, ",T.litellm_params.litellm_credential_name),(0,u.useEffect)(()=>{let e=async()=>{var e;if(!A)return;let s=await (0,b.ix)(A,w);console.log("modelInfoResponse, ",s);let l=s.data[0];J(l),(null==l?void 0:null===(e=l.litellm_params)||void 0===e?void 0:e.cache_control_injection_points)&&en(!0)};(async()=>{if(console.log("accessToken, ",A),!A||ed)return;let e=await (0,b.Qg)(A,null,w);console.log("existingCredentialResponse, ",e),er({credential_name:e.credential_name,credential_values:e.credential_values,credential_info:e.credential_info})})(),e()},[A,w]);let ec=async e=>{var s;if(console.log("values, ",e),!A)return;let l={credential_name:e.credential_name,model_id:w,credential_info:{custom_llm_provider:null===(s=H.litellm_params)||void 0===s?void 0:s.custom_llm_provider}};F.ZP.info("Storing credential.."),console.log("credentialResponse, ",await (0,b.oC)(A,l)),F.ZP.success("Credential stored successfully")},em=async e=>{try{var s;if(!A)return;es(!0),console.log("values.model_name, ",e.model_name);let l={...H.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6};e.cache_control&&(null===(s=e.cache_control_injection_points)||void 0===s?void 0:s.length)>0?l.cache_control_injection_points=e.cache_control_injection_points:delete l.cache_control_injection_points;let t={model_name:e.model_name,litellm_params:l,model_info:{id:w}};await (0,b.$D)(A,t,w);let a={...H,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l};J(a),V&&V(a),F.ZP.success("Model settings updated successfully"),Q(!1),et(!1)}catch(e){console.error("Error updating model:",e),F.ZP.error("Failed to update model settings")}finally{es(!1)}};if(!T)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsx)(P.Z,{children:"Model not found"})]});let eu=async()=>{try{if(!A)return;await (0,b.Og)(A,w),F.ZP.success("Model deleted successfully"),V&&V({deleted:!0,model_info:{id:w}}),k()}catch(e){console.error("Error deleting the model:",e),F.ZP.error("Failed to delete model")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsxs)(O.Z,{children:["Public Model Name: ",sk(T)]}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),(0,m.jsxs)("div",{className:"flex gap-2",children:["Admin"===L&&(0,m.jsx)(C.Z,{icon:sH.Z,variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Re-use Credentials"}),eo&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>W(!0),className:"flex items-center",children:"Delete Model"})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-6",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Raw JSON"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,m.jsx)("img",{src:sm(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,l=s.parentElement;if(l){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",l.replaceChild(e,s)}}}),(0,m.jsx)(O.Z,{children:T.provider||"Not Set"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"LiteLLM Model"}),(0,m.jsx)("pre",{children:(0,m.jsx)(O.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Pricing"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,m.jsxs)(P.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,m.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Model Settings"}),eo&&!el&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>et(!0),className:"flex items-center",children:"Edit Model"})]}),H?(0,m.jsx)(M.Z,{form:B,onFinish:em,initialValues:{model_name:H.model_name,litellm_model_name:H.litellm_model_name,api_base:H.litellm_params.api_base,custom_llm_provider:H.litellm_params.custom_llm_provider,organization:H.litellm_params.organization,tpm:H.litellm_params.tpm,rpm:H.litellm_params.rpm,max_retries:H.litellm_params.max_retries,timeout:H.litellm_params.timeout,stream_timeout:H.litellm_params.stream_timeout,input_cost:H.litellm_params.input_cost_per_token?1e6*H.litellm_params.input_cost_per_token:(null===(t=H.model_info)||void 0===t?void 0:t.input_cost_per_token)*1e6||null,output_cost:(null===(a=H.litellm_params)||void 0===a?void 0:a.output_cost_per_token)?1e6*H.litellm_params.output_cost_per_token:(null===(r=H.model_info)||void 0===r?void 0:r.output_cost_per_token)*1e6||null,cache_control:null!==(i=H.litellm_params)&&void 0!==i&&!!i.cache_control_injection_points,cache_control_injection_points:(null===(n=H.litellm_params)||void 0===n?void 0:n.cache_control_injection_points)||[]},layout:"vertical",onValuesChange:()=>Q(!0),children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"LiteLLM Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter LiteLLM model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.litellm_model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"input_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter input cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(o=H.litellm_params)||void 0===o?void 0:o.input_cost_per_token)?((null===(d=H.litellm_params)||void 0===d?void 0:d.input_cost_per_token)*1e6).toFixed(4):(null==H?void 0:null===(c=H.model_info)||void 0===c?void 0:c.input_cost_per_token)?(1e6*H.model_info.input_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"output_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter output cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(h=H.litellm_params)||void 0===h?void 0:h.output_cost_per_token)?(1e6*H.litellm_params.output_cost_per_token).toFixed(4):(null==H?void 0:null===(x=H.model_info)||void 0===x?void 0:x.output_cost_per_token)?(1e6*H.model_info.output_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Base"}),el?(0,m.jsx)(M.Z.Item,{name:"api_base",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter API base"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=H.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Custom LLM Provider"}),el?(0,m.jsx)(M.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom LLM provider"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=H.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),el?(0,m.jsx)(M.Z.Item,{name:"organization",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter organization"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=H.litellm_params)||void 0===j?void 0:j.organization)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"tpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter TPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=H.litellm_params)||void 0===f?void 0:f.tpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"rpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter RPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=H.litellm_params)||void 0===_?void 0:_.rpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Max Retries"}),el?(0,m.jsx)(M.Z.Item,{name:"max_retries",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter max retries"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(v=H.litellm_params)||void 0===v?void 0:v.max_retries)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(y=H.litellm_params)||void 0===y?void 0:y.timeout)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter stream timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=H.litellm_params)||void 0===Z?void 0:Z.stream_timeout)||"Not Set"})]}),el?(0,m.jsx)(s0,{form:B,showCacheControl:ei,onCacheControlChange:e=>en(e)}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Cache Control"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=H.litellm_params)||void 0===N?void 0:N.cache_control_injection_points)?(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{children:"Enabled"}),(0,m.jsx)("div",{className:"mt-2",children:H.litellm_params.cache_control_injection_points.map((e,s)=>(0,m.jsxs)("div",{className:"text-sm text-gray-600 mb-1",children:["Location: ",e.location,",",e.role&&(0,m.jsxs)("span",{children:[" Role: ",e.role]}),void 0!==e.index&&(0,m.jsxs)("span",{children:[" Index: ",e.index]})]},s))})]}):"Disabled"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),el&&(0,m.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{B.resetFields(),Q(!1),et(!1)},children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",onClick:()=>B.submit(),loading:ee,children:"Save Changes"})]})]})}):(0,m.jsx)(P.Z,{children:"Loading..."})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),G&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Model"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this model?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(U.ZP,{onClick:eu,className:"ml-2",danger:!0,children:"Delete"}),(0,m.jsx)(U.ZP,{onClick:()=>W(!1),children:"Cancel"})]})]})]})}),Y&&!ed?(0,m.jsx)(sW,{isVisible:Y,onCancel:()=>$(!1),onAddCredential:ec,existingCredential:ea,setIsCredentialModalOpen:$}):(0,m.jsx)(R.Z,{open:Y,onCancel:()=>$(!1),title:"Using Existing Credential",children:(0,m.jsx)(P.Z,{children:T.litellm_params.litellm_credential_name})})]})}var s2=l(67960),s4=e=>{let{selectedProvider:s,providerModels:l,getPlaceholder:t}=e,a=M.Z.useFormInstance(),r=e=>{let s=e.target.value,l=(a.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:s,litellm_model:s}:e);a.setFieldsValue({model_mappings:l})};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(M.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,m.jsx)(M.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:s===n.Azure||s===n.OpenAI_Compatible||s===n.Ollama?(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(I.Z,{placeholder:t(s)})}):l.length>0?(0,m.jsx)(D.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let s=Array.isArray(e)?e:[e];if(s.includes("all-wildcard"))a.setFieldsValue({model_name:void 0,model_mappings:[]});else if(JSON.stringify(a.getFieldValue("model"))!==JSON.stringify(s)){let e=s.map(e=>({public_name:e,litellm_model:e}));a.setFieldsValue({model:s,model_mappings:e})}},optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(s," Models (Wildcard)"),value:"all-wildcard"},...l.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,m.jsx)(I.Z,{placeholder:t(s)})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.model!==s.model,children:e=>{let{getFieldValue:s}=e,l=s("model")||[];return(Array.isArray(l)?l:[l]).includes("custom")&&(0,m.jsx)(M.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom model name",onChange:r})})}})]}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},s5=()=>{let e=M.Z.useFormInstance(),[s,l]=(0,u.useState)(0),t=M.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],r=M.Z.useWatch("custom_model_name",e),i=!a.includes("all-wildcard");if((0,u.useEffect)(()=>{if(r&&a.includes("custom")){let s=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:r,litellm_model:r}:e);e.setFieldValue("model_mappings",s),l(e=>e+1)}},[r,a,e]),(0,u.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let s=e.getFieldValue("model_mappings")||[];if(s.length!==a.length||!a.every(e=>s.some(s=>s.public_name===e||"custom"===e&&s.public_name===r))){let s=a.map(e=>"custom"===e&&r?{public_name:r,litellm_model:r}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",s),l(e=>e+1)}}},[a,r,e]),!i)return null;let n=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(s,l,t)=>(0,m.jsx)(I.Z,{value:s,onChange:s=>{let l=[...e.getFieldValue("model_mappings")];l[t].public_name=s.target.value,e.setFieldValue("model_mappings",l)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(M.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,m.jsx)(ei.Z,{dataSource:e.getFieldValue("model_mappings"),columns:n,pagination:!1,size:"small"},s)})})},s3=l(90464);let{Link:s6}=et.default;var s8=e=>{let{showAdvancedSettings:s,setShowAdvancedSettings:l,teams:t}=e,[a]=M.Z.useForm(),[r,i]=u.useState(!1),[n,o]=u.useState("per_token"),[d,c]=u.useState(!1),h=(e,s)=>s&&(isNaN(Number(s))||0>Number(s))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),x=(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(T.Z,{className:"mt-2 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Advanced Settings"})}),(0,m.jsx)(A.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,m.jsx)(M.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,m.jsx)(sY.Z,{onChange:e=>{i(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),r&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(M.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:"per_token",onChange:e=>o(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}):(0,m.jsx)(M.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)(M.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,m.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,m.jsx)(sY.Z,{onChange:e=>{let s=a.getFieldValue("litellm_extra_params");try{let l=s?JSON.parse(s):{};e?l.use_in_pass_through=!0:delete l.use_in_pass_through,Object.keys(l).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(l,null,2)):a.setFieldValue("litellm_extra_params","")}catch(s){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,m.jsx)(s0,{form:a,showCacheControl:d,onCacheControlChange:e=>{if(c(e),!e){let e=a.getFieldValue("litellm_extra_params");try{let s=e?JSON.parse(e):{};delete s.cache_control_injection_points,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(e){a.setFieldValue("litellm_extra_params","")}}}}),(0,m.jsx)(M.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,m.jsxs)(sj.Z,{className:"mb-4",children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,m.jsx)(M.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},s7=l(29),s9=l.n(s7),le=l(23496),ls=l(23639);let{Text:ll}=et.default;var lt=e=>{let{formValues:s,accessToken:l,testMode:t,modelName:a="this model",onClose:r,onTestComplete:i}=e,[n,o]=u.useState(null),[d,c]=u.useState(null),[h,x]=u.useState(null),[p,g]=u.useState(!0),[j,f]=u.useState(!1),[_,v]=u.useState(!1),y=async()=>{g(!0),v(!1),o(null),c(null),x(null),f(!1),await new Promise(e=>setTimeout(e,100));try{console.log("Testing connection with form values:",s);let a=await sx(s,l,null);if(!a){console.log("No result from prepareModelAddRequest"),o("Failed to prepare model data. Please check your form inputs."),f(!1),g(!1);return}console.log("Result from prepareModelAddRequest:",a);let{litellmParamsObj:r,modelInfoObj:i,modelName:n}=a[0],d=await (0,b.Hx)(l,r,null==i?void 0:i.mode);if("success"===d.status)F.ZP.success("Connection test successful!"),o(null),f(!0);else{var e,t;let s=(null===(e=d.result)||void 0===e?void 0:e.error)||d.message||"Unknown error";o(s),c(r),x(null===(t=d.result)||void 0===t?void 0:t.raw_request_typed_dict),f(!1)}}catch(e){console.error("Test connection error:",e),o(e instanceof Error?e.message:String(e)),f(!1)}finally{g(!1),i&&i()}};u.useEffect(()=>{let e=setTimeout(()=>{y()},200);return()=>clearTimeout(e)},[]);let Z=e=>e?e.split("stack trace:")[0].trim().replace(/^litellm\.(.*?)Error: /,""):"Unknown error",N="string"==typeof n?Z(n):(null==n?void 0:n.message)?Z(n.message):"Unknown error",w=h?((e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")})(h.raw_request_api_base,h.raw_request_body,h.raw_request_headers||{}):"";return(0,m.jsxs)("div",{style:{padding:"24px",borderRadius:"8px",backgroundColor:"#fff"},children:[p?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},className:"jsx-776cdcbc0448e4ea",children:[(0,m.jsx)("div",{style:{marginBottom:"16px"},className:"jsx-776cdcbc0448e4ea loading-spinner",children:(0,m.jsx)("div",{style:{border:"3px solid #f3f3f3",borderTop:"3px solid #1890ff",borderRadius:"50%",width:"30px",height:"30px",animation:"spin 1s linear infinite",margin:"0 auto"},className:"jsx-776cdcbc0448e4ea"})}),(0,m.jsxs)(ll,{style:{fontSize:"16px"},children:["Testing connection to ",a,"..."]}),(0,m.jsx)(s9(),{id:"776cdcbc0448e4ea",children:"@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(360deg);transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-o-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);transform:rotate(360deg)}}"})]}):j?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},children:[(0,m.jsx)("div",{style:{color:"#52c41a",fontSize:"32px",marginBottom:"16px"},children:(0,m.jsx)("svg",{viewBox:"64 64 896 896",focusable:"false","data-icon":"check-circle",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",children:(0,m.jsx)("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"})})}),(0,m.jsxs)(ll,{type:"success",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," successful!"]})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"20px"},children:[(0,m.jsx)(em.Z,{style:{color:"#ff4d4f",fontSize:"24px",marginRight:"12px"}}),(0,m.jsxs)(ll,{type:"danger",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," failed"]})]}),(0,m.jsxs)("div",{style:{backgroundColor:"#fff2f0",border:"1px solid #ffccc7",borderRadius:"8px",padding:"16px",marginBottom:"20px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px"},children:"Error: "}),(0,m.jsx)(ll,{type:"danger",style:{fontSize:"14px",lineHeight:"1.5"},children:N}),n&&(0,m.jsx)("div",{style:{marginTop:"12px"},children:(0,m.jsx)(U.ZP,{type:"link",onClick:()=>v(!_),style:{paddingLeft:0,height:"auto"},children:_?"Hide Details":"Show Details"})})]}),_&&(0,m.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"Troubleshooting Details"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"200px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:"string"==typeof n?n:JSON.stringify(n,null,2)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"API Request"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"250px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:w||"No request data available"}),(0,m.jsx)(U.ZP,{style:{marginTop:"8px"},icon:(0,m.jsx)(ls.Z,{}),onClick:()=>{navigator.clipboard.writeText(w||""),F.ZP.success("Copied to clipboard")},children:"Copy to Clipboard"})]})]})}),(0,m.jsx)(le.Z,{style:{margin:"24px 0 16px"}}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:(0,m.jsx)(U.ZP,{type:"link",href:"https://docs.litellm.ai/docs/providers",target:"_blank",icon:(0,m.jsx)(W.Z,{}),children:"View Documentation"})})]})};let la=[{value:"chat",label:"Chat - /chat/completions"},{value:"completion",label:"Completion - /completions"},{value:"embedding",label:"Embedding - /embeddings"},{value:"audio_speech",label:"Audio Speech - /audio/speech"},{value:"audio_transcription",label:"Audio Transcription - /audio/transcriptions"},{value:"image_generation",label:"Image Generation - /images/generations"},{value:"rerank",label:"Rerank - /rerank"},{value:"realtime",label:"Realtime - /realtime"}],{Title:lr,Link:li}=et.default;var ln=e=>{let{form:s,handleOk:l,selectedProvider:t,setSelectedProvider:a,providerModels:r,setProviderModelsFn:i,getPlaceholder:o,uploadProps:d,showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x,credentials:p,accessToken:g,userRole:j}=e,[f,_]=(0,u.useState)("chat"),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(""),k=async()=>{Z(!0),w("test-".concat(Date.now())),y(!0)},S=eZ.ZL.includes(j);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lr,{level:2,children:"Add new model"}),(0,m.jsx)(s2.Z,{children:(0,m.jsx)(M.Z,{form:s,onFinish:l,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,m.jsx)(D.default,{showSearch:!0,value:t,onChange:e=>{a(e),i(e),s.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(n).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(s4,{selectedProvider:t,providerModels:r,getPlaceholder:o}),(0,m.jsx)(s5,{}),(0,m.jsx)(M.Z.Item,{label:"Mode",name:"mode",className:"mb-1",children:(0,m.jsx)(D.default,{style:{width:"100%"},value:f,onChange:e=>_(e),options:la})}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-5 mt-1",children:[(0,m.jsx)("strong",{children:"Optional"})," - LiteLLM endpoint to use when health checking this model ",(0,m.jsx)(li,{href:"https://docs.litellm.ai/docs/proxy/health#health",target:"_blank",children:"Learn more"})]})})]}),(0,m.jsx)("div",{className:"mb-4",children:(0,m.jsx)(et.default.Text,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter new provider credentials below"})}),(0,m.jsx)(M.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...p.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.litellm_credential_name!==s.litellm_credential_name||e.provider!==s.provider,children:e=>{let{getFieldValue:s}=e,l=s("litellm_credential_name");return(console.log("\uD83D\uDD11 Credential Name Changed:",l),l)?(0,m.jsx)("div",{className:"text-gray-500 text-sm text-center",children:"Using existing credentials - no additional provider fields needed"}):(0,m.jsx)(sy,{selectedProvider:t,uploadProps:d})}}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Team Settings"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{label:"Team",name:"team_id",className:"mb-4",tooltip:"Only keys for this team, will be able to call this model.",rules:[{required:!S,message:"Please select a team."}],children:(0,m.jsx)(es,{teams:x})}),(0,m.jsx)(s8,{showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x}),(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(et.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{className:"space-x-2",children:[(0,m.jsx)(U.ZP,{onClick:k,loading:b,children:"Test Connect"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Model"})]})]})]})})}),(0,m.jsx)(R.Z,{title:"Connection Test Results",open:v,onCancel:()=>{y(!1),Z(!1)},footer:[(0,m.jsx)(U.ZP,{onClick:()=>{y(!1),Z(!1)},children:"Close"},"close")],width:700,children:v&&(0,m.jsx)(lt,{formValues:s.getFieldsValue(),accessToken:g,testMode:f,modelName:s.getFieldValue("model_name")||s.getFieldValue("model"),onClose:()=>{y(!1),Z(!1)},onTestComplete:()=>Z(!1)},N)})]})};function lo(e){let{data:s=[],columns:l,isLoading:t=!1,table:a}=e,[r,i]=u.useState([{id:"model_info.created_at",desc:!0}]),[n]=u.useState("onChange"),[o,d]=u.useState({}),[c,h]=u.useState({}),x=(0,e2.b7)({data:s,columns:l,state:{sorting:r,columnSizing:o,columnVisibility:c},columnResizeMode:n,onSortingChange:i,onColumnSizingChange:d,onColumnVisibilityChange:h,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,enableColumnResizing:!0,defaultColumn:{minSize:40,maxSize:500}});return u.useEffect(()=>{a&&(a.current=x)},[x,a]),(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsx)("div",{className:"relative min-w-full",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1 w-full",children:[(0,m.jsx)(e8.Z,{children:x.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsxs)(e7.Z,{className:"py-1 h-8 relative ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.id?120:e.getSize(),position:"actions"===e.id?"sticky":"relative",right:"actions"===e.id?0:"auto"},onClick:e.column.getToggleSortingHandler(),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]}),e.column.getCanResize()&&(0,m.jsx)("div",{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),className:"absolute right-0 top-0 h-full w-2 cursor-col-resize select-none touch-none ".concat(e.column.getIsResizing()?"bg-blue-500":"hover:bg-blue-200")})]},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):x.getRowModel().rows.length>0?x.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.column.id?120:e.column.getSize(),position:"actions"===e.column.id?"sticky":"relative",right:"actions"===e.column.id?0:"auto"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No models found"})})})})})]})})})})}let ld=(e,s,l,t,a,r,i,n,o)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.model_info.id,children:(0,m.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>t(l.model_info.id),children:l.model_info.id})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:s}=e,l=r(s.original)||"-";return(0,m.jsx)(Y.Z,{title:l,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l.provider&&(0,m.jsx)("img",{src:sm(l.provider).logo,alt:"".concat(l.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,t=s.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=l.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,s)}}}),(0,m.jsx)("p",{className:"text-xs",children:l.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.litellm_model_name,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l.litellm_model_name||"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_at?new Date(l.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.updated_at?new Date(l.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_by||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.input_cost||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:s}=e,l=s.original;return l.model_info.team_id?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.model_info.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>a(l.model_info.team_id),children:[l.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Credentials",accessorKey:"litellm_credential_name",cell:e=>{let{row:s}=e,l=s.original;return l.litellm_params&&l.litellm_params.litellm_credential_name?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsxs)(Y.Z,{title:l.litellm_params.litellm_credential_name,children:[l.litellm_params.litellm_credential_name.slice(0,7),"..."]})}):(0,m.jsx)("span",{className:"text-gray-400",children:"-"})}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(l.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:l.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:l=>{var a;let{row:r}=l,i=r.original,n="Admin"===e||(null===(a=i.model_info)||void 0===a?void 0:a.created_by)===s;return(0,m.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{n&&(t(i.model_info.id),o(!0))},className:n?"cursor-pointer":"opacity-50 cursor-not-allowed"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{n&&(t(i.model_info.id),o(!1))},className:n?"cursor-pointer":"opacity-50 cursor-not-allowed"})]})}}],{Title:lc,Link:lm}=et.default,lu={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lh=e=>{let{accessToken:s,token:l,userRole:t,userID:a,modelData:r={data:[]},keys:i,setModelData:o,premiumUser:d,teams:c}=e,[h,x]=(0,u.useState)([]),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)([]);Object.values(n).filter(e=>isNaN(Number(e)));let[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(n.OpenAI),[I,T]=(0,u.useState)(""),[A,E]=(0,u.useState)(!1),[L,D]=(0,u.useState)(null),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)([]),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)([]),[J,W]=(0,u.useState)([]),[Y,$]=(0,u.useState)([]),[X,Q]=(0,u.useState)([]),[ee,es]=(0,u.useState)([]),[ea,er]=(0,u.useState)([]),[ei,en]=(0,u.useState)([]),[eo,ed]=(0,u.useState)([]),[ec,em]=(0,u.useState)([]),[eu,eh]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,u.useState)(null),[eg,ej]=(0,u.useState)(0),[ef,e_]=(0,u.useState)({}),[ev,ey]=(0,u.useState)([]),[eb,eN]=(0,u.useState)(!1),[ew,ek]=(0,u.useState)(null),[eS,eC]=(0,u.useState)(null),[eI,eT]=(0,u.useState)([]),[eA,eE]=(0,u.useState)([]),[eP,eL]=(0,u.useState)(!1),[ez,eK]=(0,u.useState)(null),[eB,eH]=(0,u.useState)(!1),[eJ,eW]=(0,u.useState)(null),[eY,e$]=(0,u.useState)(null),[eX,eQ]=(0,u.useState)(null),[e0,e1]=(0,u.useState)(!1),[e2,e4]=(0,u.useState)(!1),se=(0,u.useRef)(null),ss=(0,u.useRef)(null),sl=async(e,l,r)=>{if(console.log("Updating model metrics for group:",e),!s||!a||!t||!l||!r)return;console.log("inside updateModelMetrics - startTime:",l,"endTime:",r),K(e);let i=null==ew?void 0:ew.token;void 0===i&&(i=null);let n=eS;void 0===n&&(n=null),l.setHours(0),l.setMinutes(0),l.setSeconds(0),r.setHours(23),r.setMinutes(59),r.setSeconds(59);try{let o=await (0,b.o6)(s,a,t,e,l.toISOString(),r.toISOString(),i,n);console.log("Model metrics response:",o),W(o.data),$(o.all_api_bases);let d=await (0,b.Rg)(s,e,l.toISOString(),r.toISOString());Q(d.data),es(d.all_api_bases);let c=await (0,b.N8)(s,a,t,e,l.toISOString(),r.toISOString(),i,n);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,b.fP)(s,a,t,e,l.toISOString(),r.toISOString(),i,n);if(console.log("slowResponses:",m),em(m),e){let t=await (0,b.n$)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);e_(t);let a=await (0,b.v9)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);ey(a)}}catch(e){console.error("Failed to fetch model metrics",e)}},st=async e=>{try{let s=await (0,b.N3)(e);console.log("credentials: ".concat(JSON.stringify(s))),eE(s.credentials)}catch(e){console.error("Error fetching credentials:",e)}};(0,u.useEffect)(()=>{sl(V,eu.from,eu.to)},[ew,eS,eY]),(0,u.useEffect)(()=>{let e=e=>{se.current&&!se.current.contains(e.target)&&e4(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let sa={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Resetting vertex_credentials to JSON; jsonStr: ".concat(s)),p.setFieldsValue({vertex_credentials:s}),console.log("Form values right after setting:",p.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered with values:",e),console.log("Current form values:",p.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?F.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&F.ZP.error("".concat(e.file.name," file upload failed."))}},sr=()=>{_(new Date().toLocaleString())},si=async()=>{if(!s){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,b.K_)(s,{router_settings:{model_group_retry_policy:ex}}),F.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),F.ZP.error("Failed to save retry settings")}};if((0,u.useEffect)(()=>{if(!s||!l||!t||!a)return;let e=async()=>{try{var e,l,r,i,n,d,c,m,u,h,x,p;let g=await (0,b.AZ)(s,a,t);console.log("Model data response:",g.data),o(g);let j=await (0,b.hy)(s);j&&N(j);let f=new Set;for(let e=0;e0&&(v=_[_.length-1],console.log("_initial_model_group:",v)),console.log("selectedModelGroup:",V);let y=await (0,b.o6)(s,a,t,v,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(l=eu.to)||void 0===l?void 0:l.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model metrics response:",y),W(y.data),$(y.all_api_bases);let Z=await (0,b.Rg)(s,v,null===(r=eu.from)||void 0===r?void 0:r.toISOString(),null===(i=eu.to)||void 0===i?void 0:i.toISOString());Q(Z.data),es(Z.all_api_bases);let w=await (0,b.N8)(s,a,t,v,null===(n=eu.from)||void 0===n?void 0:n.toISOString(),null===(d=eu.to)||void 0===d?void 0:d.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model exceptions response:",w),er(w.data),en(w.exception_types);let k=await (0,b.fP)(s,a,t,v,null===(c=eu.from)||void 0===c?void 0:c.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eS),S=await (0,b.n$)(s,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],v);e_(S);let C=await (0,b.v9)(s,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],v);ey(C),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",C),console.log("slowResponses:",k),em(k);let I=await (0,b.j2)(s);eT(null==I?void 0:I.end_users);let T=(await (0,b.BL)(s,a,t)).router_settings;console.log("routerSettingsInfo:",T);let A=T.model_group_retry_policy,E=T.num_retries;console.log("model_group_retry_policy:",A),console.log("default_retries:",E),ep(A),ej(E)}catch(e){console.error("There was an error fetching the model data",e)}};s&&l&&t&&a&&e();let r=async()=>{let e=await (0,b.qm)(s);console.log("received model cost map data: ".concat(Object.keys(e))),j(e)};null==g&&r(),sr()},[s,l,t,a,g,f,eY]),!r||!s||!l||!t||!a)return(0,m.jsx)("div",{children:"Loading..."});let sd=[],sc=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(l){let e=l.split("/"),s=e[0];(i=t)||(i=1===e.length?u(l):s)}else i="-";a&&(n=null==a?void 0:a.input_cost_per_token,o=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==s?void 0:s.litellm_params)&&(m=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[s]=e;return"model"!==s&&"api_base"!==s}))),r.data[e].provider=i,r.data[e].input_cost=n,r.data[e].output_cost=o,r.data[e].litellm_model_name=l,sc.push(i),r.data[e].input_cost&&(r.data[e].input_cost=(1e6*Number(r.data[e].input_cost)).toFixed(2)),r.data[e].output_cost&&(r.data[e].output_cost=(1e6*Number(r.data[e].output_cost)).toFixed(2)),r.data[e].max_tokens=d,r.data[e].max_input_tokens=c,r.data[e].api_base=null==s?void 0:null===(sg=s.litellm_params)||void 0===sg?void 0:sg.api_base,r.data[e].cleanedLitellmParams=m,sd.push(s.model_name),console.log(r.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to view all models"})]})}let sj=async()=>{try{F.ZP.info("Running health check..."),T("");let e=await (0,b.EY)(s);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}},s_=(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Select API Key Name"}),d?(0,m.jsxs)("div",{children:[(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{ek(null)},children:"All Keys"},"all-keys"),null==i?void 0:i.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{ek(e)},children:e.key_alias},s):null)]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Customer Name"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-customers",children:[(0,m.jsx)(el.Z,{value:"all-customers",onClick:()=>{eC(null)},children:"All Customers"},"all-customers"),null==eI?void 0:eI.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>{eC(e)},children:e},s))]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]}),sv=e=>{var s,l;let{payload:t,active:a}=e;if(!a||!t)return null;let r=null===(l=t[0])||void 0===l?void 0:null===(s=l.payload)||void 0===s?void 0:s.date,i=t.sort((e,s)=>s.value-e.value);if(i.length>5){let e=i.length-5;(i=i.slice(0,5)).push({dataKey:"".concat(e," other deployments"),value:t.slice(5).reduce((e,s)=>e+s.value,0),color:"gray"})}return(0,m.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[r&&(0,m.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",r]}),i.map((e,s)=>{let l=parseFloat(e.value.toFixed(5)),t=0===l&&e.value>0?"<0.00001":l.toFixed(5);return(0,m.jsxs)("div",{className:"flex justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,m.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,m.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:t})]},s)})]})};console.log("selectedProvider: ".concat(w)),console.log("providerModels.length: ".concat(v.length));let sy=Object.keys(n).find(e=>n[e]===w);return(sy&&Z&&Z.find(e=>e.name===so[sy]),eJ)?(0,m.jsx)("div",{className:"w-full h-full",children:(0,m.jsx)(sB,{teamId:eJ,onClose:()=>eW(null),accessToken:s,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:sd,editTeam:!1,onUpdate:sr})}):(0,m.jsx)("div",{style:{width:"100%",height:"100%"},children:ez?(0,m.jsx)(s1,{modelId:ez,editModel:!0,onClose:()=>{eK(null),eH(!1)},modelData:r.data.find(e=>e.model_info.id===ez),accessToken:s,userID:a,userRole:t,setEditModalVisible:E,setSelectedModel:D,onModelUpdate:e=>{o({...r,data:r.data.map(s=>s.model_info.id===e.model_info.id?e:s)}),sr()}}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[eZ.ZL.includes(t)?(0,m.jsx)(eM.Z,{children:"All Models"}):(0,m.jsx)(eM.Z,{children:"Your Models"}),(0,m.jsx)(eM.Z,{children:"Add Model"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"LLM Credentials"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"/health Models"})}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Analytics"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Retry Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:sr})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(S.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(O.Z,{children:"Model Management"}),eZ.ZL.includes(t)?(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add and manage models for the proxy"}):(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add models for teams you are an admin for."})]})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex items-center justify-between",children:(0,m.jsxs)("div",{className:"flex items-center gap-3",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:null!=V?V:"all",onValueChange:e=>K("all"===e?"all":e),value:null!=V?V:"all",children:[(0,m.jsx)(el.Z,{value:"all",children:"All Models"}),R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,children:e},s))]})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Team:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]})}),(0,m.jsx)("div",{className:"flex justify-between items-center",children:(0,m.jsxs)(P.Z,{className:"text-sm text-gray-700",children:["Showing ",r&&r.data.length>0?r.data.length:0," results"]})})]})}),(0,m.jsx)(lo,{columns:ld(t,a,d,eK,eW,sk,e=>{D(e),E(!0)},sr,eH),data:r.data.filter(e=>("all"===V||e.model_name===V||!V)&&("all"===eX||e.model_info.team_id===eX||!eX)),isLoading:!1,table:ss})]})]})})}),(0,m.jsx)(eq.Z,{className:"h-full",children:(0,m.jsx)(ln,{form:p,handleOk:()=>{p.validateFields().then(e=>{sp(e,s,p,sr)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:w,setSelectedProvider:k,providerModels:v,setProviderModelsFn:e=>{let s=sh(e,g);y(s),console.log("providerModels: ".concat(s))},getPlaceholder:su,uploadProps:sa,showAdvancedSettings:eP,setShowAdvancedSettings:eL,teams:c,credentials:eA,accessToken:s,userRole:t})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sw,{accessToken:s,uploadProps:sa,credentialList:eA,fetchCredentials:st})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,m.jsx)(C.Z,{onClick:sj,children:"Run `/health`"}),I&&(0,m.jsx)("pre",{children:JSON.stringify(I,null,2)})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:eu,className:"mr-2",onValueChange:e=>{eh(e),sl(V,e.from,e.to)}})]}),(0,m.jsxs)(sf.Z,{className:"ml-2",children:[(0,m.jsx)(P.Z,{children:"Select Model Group"}),(0,m.jsx)(eO.Z,{defaultValue:V||R[0],value:V||R[0],children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>sl(e,eu.from,eu.to),children:e},s))})]}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(sA.Z,{trigger:"click",content:s_,overlayStyle:{width:"20vw"},children:(0,m.jsx)(C.Z,{icon:eG.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>eN(!0)})})})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Avg. Latency per Token"}),(0,m.jsx)(eM.Z,{value:"2",children:"Time to first token"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,m.jsx)(P.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),J&&Y&&(0,m.jsx)(sI.Z,{title:"Model Latency",className:"h-72",data:J,showLegend:!1,index:"date",categories:Y,connectNulls:!0,customTooltip:sv})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sP,{modelMetrics:X,modelMetricsCategories:ee,customTooltip:sv,premiumUser:d})})]})]})})}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Deployment"}),(0,m.jsx)(e7.Z,{children:"Success Responses"}),(0,m.jsxs)(e7.Z,{children:["Slow Responses ",(0,m.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,m.jsx)(e3.Z,{children:ec.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.api_base}),(0,m.jsx)(e6.Z,{children:e.total_count}),(0,m.jsx)(e6.Z,{children:e.slow_count})]},s))})]})})})]}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Exceptions for ",V]}),(0,m.jsx)(sT.Z,{className:"h-60",data:ea,index:"model",categories:ei,stack:!0,yAxisWidth:30})]})}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Up Rate Limit Errors (429) for ",V]}),(0,m.jsxs)(S.Z,{numItems:1,children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",ef.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:ef.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,m.jsx)(sf.Z,{})]})]}),d?(0,m.jsx)(m.Fragment,{children:ev.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},s))}):(0,m.jsx)(m.Fragment,{children:ev&&ev.length>0&&ev.slice(0,1).map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},s))})]})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name"}),(0,m.jsx)(eO.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:V||R[0],value:V||R[0],onValueChange:e=>K(e),children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>K(e),children:e},s))})]}),(0,m.jsxs)(O.Z,{children:["Retry Policy for ",V]}),(0,m.jsx)(P.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lu&&(0,m.jsx)("table",{children:(0,m.jsx)("tbody",{children:Object.entries(lu).map((e,s)=>{var l;let[t,a]=e,r=null==ex?void 0:null===(l=ex[V])||void 0===l?void 0:l[a];return null==r&&(r=eg),(0,m.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,m.jsx)("td",{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)("td",{children:(0,m.jsx)(G.Z,{className:"ml-5",value:r,min:0,step:1,onChange:e=>{ep(s=>{var l;let t=null!==(l=null==s?void 0:s[V])&&void 0!==l?l:{};return{...null!=s?s:{},[V]:{...t,[a]:e}}})}})})]},s)})})}),(0,m.jsx)(C.Z,{className:"mt-6 mr-8",onClick:si,children:"Save"})]})]})]})})},lx=e=>{let{visible:s,possibleUIRoles:l,onCancel:t,user:a,onSubmit:r}=e,[i,n]=(0,u.useState)(a),[o]=M.Z.useForm();(0,u.useEffect)(()=>{o.resetFields()},[a]);let d=async()=>{o.resetFields(),t()},c=async e=>{r(e),o.resetFields(),t()};return a?(0,m.jsx)(R.Z,{visible:s,onCancel:d,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,m.jsx)(M.Z,{form:o,onFinish:c,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:l&&Object.entries(l).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,m.jsx)(G.Z,{min:0,step:.01})}),(0,m.jsx)(M.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Maximum budget of this user.",children:(0,m.jsx)(K,{min:0,step:.01})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lp=l(15731);let lg=(e,s,l)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)(Y.Z,{title:s.original.user_id,children:(0,m.jsx)("span",{className:"text-xs",children:s.original.user_id?"".concat(s.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:s=>{var l;let{row:t}=s;return(0,m.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(l=e[t.original.user_role])||void 0===l?void 0:l.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.spend?s.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.max_budget?s.original.max_budget:"Unlimited"})}},{header:()=>(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"SSO ID"}),(0,m.jsx)(Y.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,m.jsx)(lp.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.sso_user_id?s.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:s}=e;return(0,m.jsx)(S.Z,{numItems:2,children:s.original.key_count>0?(0,m.jsxs)(eL.Z,{size:"xs",color:"indigo",children:[s.original.key_count," Keys"]}):(0,m.jsx)(eL.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.created_at?new Date(s.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.updated_at?new Date(s.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>s(t.original)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.original.user_id)})]})}}];var lj=l(16853);function lf(e){let{userData:s,onCancel:l,onSubmit:t,teams:a,accessToken:r,userID:i,userRole:n,userModels:o,possibleUIRoles:d}=e,[c]=M.Z.useForm();return u.useEffect(()=>{var e,l,t,a,r;c.setFieldsValue({user_id:s.user_id,user_email:null===(e=s.user_info)||void 0===e?void 0:e.user_email,user_role:null===(l=s.user_info)||void 0===l?void 0:l.user_role,models:(null===(t=s.user_info)||void 0===t?void 0:t.models)||[],max_budget:null===(a=s.user_info)||void 0===a?void 0:a.max_budget,metadata:(null===(r=s.user_info)||void 0===r?void 0:r.metadata)?JSON.stringify(s.user_info.metadata,null,2):void 0})},[s,c]),(0,m.jsxs)(M.Z,{form:c,onFinish:e=>{if(e.metadata&&"string"==typeof e.metadata)try{e.metadata=JSON.parse(e.metadata)}catch(e){console.error("Error parsing metadata JSON:",e);return}t(e)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:d&&Object.entries(d).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Personal Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this user can access outside of team-scope. Choose 'All Proxy Models' to grant access to all models available on the proxy.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:!eZ.ZL.includes(n||""),children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(lj.Z,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:l,children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}function l_(e){var s,l,t,a,r,i,n,o,d,c,h,x,p,g,j,f,_,v,y,Z,N,w,k,I,T,A,E;let{userId:L,onClose:D,accessToken:M,userRole:R,onDelete:q,possibleUIRoles:U}=e,[z,V]=(0,u.useState)(null),[K,B]=(0,u.useState)(!1),[H,J]=(0,u.useState)(!0),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)([]);u.useEffect(()=>{console.log("userId: ".concat(L,", userRole: ").concat(R,", accessToken: ").concat(M)),(async()=>{try{if(!M)return;let e=await (0,b.Br)(M,L,R||"",!1,null,null,!0);V(e);let s=(await (0,b.So)(M,L,R||"")).data.map(e=>e.id);$(s)}catch(e){console.error("Error fetching user data:",e),F.ZP.error("Failed to fetch user data")}finally{J(!1)}})()},[M,L,R]);let X=async()=>{try{if(!M)return;await (0,b.Eb)(M,[L]),F.ZP.success("User deleted successfully"),q&&q(),D()}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}},Q=async e=>{try{if(!M||!z)return;await (0,b.pf)(M,e,null),V({...z,user_info:{...z.user_info,user_email:e.user_email,models:e.models,max_budget:e.max_budget,metadata:e.metadata}}),F.ZP.success("User updated successfully"),W(!1)}catch(e){console.error("Error updating user:",e),F.ZP.error("Failed to update user")}};return H?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"Loading user data..."})]}):z?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(O.Z,{children:(null===(s=z.user_info)||void 0===s?void 0:s.user_email)||"User"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:z.user_id})]}),R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete User"})]}),K&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:X,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>B(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Details"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number((null===(l=z.user_info)||void 0===l?void 0:l.spend)||0).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",(null===(t=z.user_info)||void 0===t?void 0:t.max_budget)!==null?"$".concat(z.user_info.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(a=z.teams)||void 0===a?void 0:a.length)||0," teams"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"API Keys"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(r=z.keys)||void 0===r?void 0:r.length)||0," keys"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Personal Models"}),(0,m.jsx)("div",{className:"mt-2",children:(null===(n=z.user_info)||void 0===n?void 0:null===(i=n.models)||void 0===i?void 0:i.length)&&(null===(d=z.user_info)||void 0===d?void 0:null===(o=d.models)||void 0===o?void 0:o.length)>0?null===(h=z.user_info)||void 0===h?void 0:null===(c=h.models)||void 0===c?void 0:c.map((e,s)=>(0,m.jsx)(P.Z,{children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"User Settings"}),!G&&R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>W(!0),children:"Edit Settings"})]}),G&&z?(0,m.jsx)(lf,{userData:z,onCancel:()=>W(!1),onSubmit:Q,teams:z.teams,accessToken:M,userID:L,userRole:R,userModels:Y,possibleUIRoles:U}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"User ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:z.user_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Email"}),(0,m.jsx)(P.Z,{children:(null===(x=z.user_info)||void 0===x?void 0:x.user_email)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Role"}),(0,m.jsx)(P.Z,{children:(null===(p=z.user_info)||void 0===p?void 0:p.user_role)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:(null===(g=z.user_info)||void 0===g?void 0:g.created_at)?new Date(z.user_info.created_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:(null===(j=z.user_info)||void 0===j?void 0:j.updated_at)?new Date(z.user_info.updated_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Teams"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(f=z.teams)||void 0===f?void 0:f.length)&&(null===(_=z.teams)||void 0===_?void 0:_.length)>0?null===(v=z.teams)||void 0===v?void 0:v.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e.team_alias||e.team_id},s)):(0,m.jsx)(P.Z,{children:"No teams"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(Z=z.user_info)||void 0===Z?void 0:null===(y=Z.models)||void 0===y?void 0:y.length)&&(null===(w=z.user_info)||void 0===w?void 0:null===(N=w.models)||void 0===N?void 0:N.length)>0?null===(I=z.user_info)||void 0===I?void 0:null===(k=I.models)||void 0===k?void 0:k.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Keys"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(T=z.keys)||void 0===T?void 0:T.length)&&(null===(A=z.keys)||void 0===A?void 0:A.length)>0?z.keys.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-green-100 rounded text-xs",children:e.key_alias||e.token},s)):(0,m.jsx)(P.Z,{children:"No API keys"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify((null===(E=z.user_info)||void 0===E?void 0:E.metadata)||{},null,2)})]})]})]})})]})]})]}):(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"User not found"})]})}function lv(e){let{data:s=[],columns:l,isLoading:t=!1,onSortChange:a,currentSort:r,accessToken:i,userRole:n,possibleUIRoles:o}=e,[d,c]=u.useState([{id:(null==r?void 0:r.sortBy)||"created_at",desc:(null==r?void 0:r.sortOrder)==="desc"}]),[h,x]=u.useState(null),p=(0,e2.b7)({data:s,columns:l,state:{sorting:d},onSortingChange:e=>{if(c(e),e.length>0){let s=e[0],l=s.id,t=s.desc?"desc":"asc";null==a||a(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0}),g=e=>{x(e)};return(u.useEffect(()=>{r&&c([{id:r.sortBy,desc:"desc"===r.sortOrder}])},[r]),h)?(0,m.jsx)(l_,{userId:h,onClose:()=>{x(null)},accessToken:i,userRole:n,possibleUIRoles:o}):(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:p.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):s.length>0?p.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:()=>{"user_id"===e.column.id&&g(e.getValue())},style:{cursor:"user_id"===e.column.id?"pointer":"default",color:"user_id"===e.column.id?"#3b82f6":"inherit"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No users found"})})})})})]})})})}var ly=l(67982),lb=l(87908),lZ=e=>{var s;let{accessToken:l,possibleUIRoles:t,userID:a,userRole:r}=e,[i,n]=(0,u.useState)(!0),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)([]),{Paragraph:v}=et.default,{Option:y}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){n(!1);return}try{let e=await (0,b.NL)(l);if(d(e),p(e.values||{}),l)try{let e=await (0,b.So)(l,a,r);if(e&&e.data){let s=e.data.map(e=>e.id);_(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching SSO settings:",e),F.ZP.error("Failed to fetch SSO settings")}finally{n(!1)}})()},[l]);let Z=async()=>{if(l){j(!0);try{let e=await (0,b.nd)(l,x);d({...o,values:e.settings}),h(!1)}catch(e){console.error("Error updating SSO settings:",e),F.ZP.error("Failed to update settings")}finally{j(!1)}}},N=(e,s)=>{p(l=>({...l,[e]:s}))},w=(e,s,l)=>{var a;let r=s.type;return"user_role"===e&&t?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:Object.entries(t).filter(e=>{let[s]=e;return s.includes("internal_user")}).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(y,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{children:l}),(0,m.jsx)("span",{className:"ml-2 text-xs text-gray-500",children:t})]})},s)})}):"budget_duration"===e?(0,m.jsx)(ek,{value:x[e]||null,onChange:s=>N(e,s),className:"mt-2"}):"boolean"===r?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!x[e],onChange:s=>N(e,s)})}):"array"===r&&(null===(a=s.items)||void 0===a?void 0:a.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:f.map(e=>(0,m.jsx)(y,{value:e,children:H(e)},e))}):"string"===r&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==x[e]?String(x[e]):"",onChange:s=>N(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},k=(e,s)=>{if(null==s)return(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"});if("user_role"===e&&t&&t[s]){let{ui_label:e,description:l}=t[s];return(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-medium",children:e}),l&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:l})]})}return"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)})};return i?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):o?(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex justify-end items-center mb-4",children:!i&&o&&(c?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{h(!1),p(o.values||{})},disabled:g,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:Z,loading:g,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>h(!0),children:"Edit Settings"}))}),(null==o?void 0:null===(s=o.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(v,{className:"mb-4",children:o.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=o;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(v,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),c?(0,m.jsx)("div",{className:"mt-2",children:w(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:k(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No settings available or you do not have permission to view them."})})},lN=l(19616);console.log=function(){};let lw={email:"",user_id:"",user_role:"",sso_user_id:"",team:"",model:"",min_spend:null,max_spend:null,sort_by:"created_at",sort_order:"desc"};var lk=e=>{var s;let{accessToken:l,token:t,userRole:a,userID:r,teams:i}=e,n=(0,g.NL)(),[o,d]=(0,u.useState)(1),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)("users"),[N,w]=(0,u.useState)(lw),[k,S,I]=(0,lN.G)(N,{wait:300}),[T,A]=(0,u.useState)(!1);(0,u.useEffect)(()=>()=>{I.cancel()},[I]);let E=e=>{w(s=>{let l={...s,...e};return S(l),l})},P=async()=>{if(_&&l)try{await (0,b.Eb)(l,[_]),n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let s=e.users.filter(e=>e.user_id!==_);return{...e,users:s}}),F.ZP.success("User deleted successfully")}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}f(!1),v(null)},O=async()=>{p(null),h(!1)},L=async e=>{if(console.log("inside handleEditSubmit:",e),l&&t&&a&&r){try{let s=await (0,b.pf)(l,e,null);n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let l=e.users.map(e=>e.user_id===s.data.user_id?e1(e,s.data):e);return{...e,users:l}}),F.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}p(null),h(!1)}},D=async e=>{d(e)},M=(0,eY.a)({queryKey:["userList",{debouncedFilter:k,currentPage:o}],queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.Of)(l,k.user_id?[k.user_id]:null,o,25,k.email||null,k.user_role||null,k.team||null,k.sso_user_id||null,k.sort_by,k.sort_order)},enabled:!!(l&&t&&a&&r),placeholderData:e=>e}),R=M.data,q=(0,eY.a)({queryKey:["userRoles"],initialData:()=>({}),queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.lg)(l)},enabled:!!(l&&t&&a&&r)}).data;if(M.isLoading||!l||!t||!a||!r)return(0,m.jsx)("div",{children:"Loading..."});let U=lg(q,e=>{p(e),h(!0)},e=>{v(e),f(!0)});return(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,m.jsx)("div",{className:"flex space-x-3",children:(0,m.jsx)(ev,{userID:r,accessToken:l,teams:i,possibleUIRoles:q})})]}),(0,m.jsxs)(eF.Z,{defaultIndex:0,onIndexChange:e=>Z(0===e?"users":"settings"),children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Users"}),(0,m.jsx)(eM.Z,{children:"Default User Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by email...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.email,onChange:e=>E({email:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(T?"bg-gray-100":""),onClick:()=>A(!T),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(N.user_id||N.user_role||N.team)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{E(lw)},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),T&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Filter by User ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.user_id,onChange:e=>E({user_id:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.user_role,onValueChange:e=>E({user_role:e}),placeholder:"Select Role",children:Object.entries(q).map(e=>{let[s,l]=e;return(0,m.jsx)(el.Z,{value:s,children:l.ui_label},s)})})}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.team,onValueChange:e=>E({team:e}),placeholder:"Select Team",children:null==i?void 0:i.map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias||e.team_id},e.team_id))})}),(0,m.jsx)("div",{className:"relative w-64",children:(0,m.jsx)("input",{type:"text",placeholder:"Filter by SSO ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.sso_user_id,onChange:e=>E({sso_user_id:e.target.value})})})]}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",R&&R.users&&R.users.length>0?(R.page-1)*R.page_size+1:0," ","-"," ",R&&R.users?Math.min(R.page*R.page_size,R.total):0," ","of ",R?R.total:0," results"]}),(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>D(o-1),disabled:1===o,className:"px-3 py-1 text-sm border rounded-md ".concat(1===o?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,m.jsx)("button",{onClick:()=>D(o+1),disabled:!R||o>=R.total_pages,className:"px-3 py-1 text-sm border rounded-md ".concat(!R||o>=R.total_pages?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,m.jsx)(lv,{data:(null===(s=M.data)||void 0===s?void 0:s.users)||[],columns:U,isLoading:M.isLoading,accessToken:l,userRole:a,onSortChange:(e,s)=>{E({sort_by:e,sort_order:s})},currentSort:{sortBy:N.sort_by,sortOrder:N.sort_order},possibleUIRoles:q})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lZ,{accessToken:l,possibleUIRoles:q,userID:r,userRole:a})})]})]}),(0,m.jsx)(lx,{visible:c,possibleUIRoles:q,onCancel:O,user:x,onSubmit:L}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,m.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",_]})]})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:P,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})})]})},lS=e=>{var s;let{accessToken:l,userID:t,userRole:a}=e,[r,i]=(0,u.useState)(!0),[n,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)({}),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)([]),{Paragraph:_}=et.default,{Option:v}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){i(!1);return}try{let e=await (0,b.EB)(l);if(o(e),x(e.values||{}),l)try{let e=await (0,b.So)(l,t,a);if(e&&e.data){let s=e.data.map(e=>e.id);f(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching team SSO settings:",e),F.ZP.error("Failed to fetch team settings")}finally{i(!1)}})()},[l]);let y=async()=>{if(l){g(!0);try{let e=await (0,b.r1)(l,h);o({...n,values:e.settings}),c(!1),F.ZP.success("Default team settings updated successfully")}catch(e){console.error("Error updating team settings:",e),F.ZP.error("Failed to update team settings")}finally{g(!1)}}},Z=(e,s)=>{x(l=>({...l,[e]:s}))},N=(e,s,l)=>{var t;let a=s.type;return"budget_duration"===e?(0,m.jsx)(ek,{value:h[e]||null,onChange:s=>Z(e,s),className:"mt-2"}):"boolean"===a?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!h[e],onChange:s=>Z(e,s)})}):"array"===a&&(null===(t=s.items)||void 0===t?void 0:t.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:j.map(e=>(0,m.jsx)(v,{value:e,children:H(e)},e))}):"string"===a&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>Z(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==h[e]?String(h[e]):"",onChange:s=>Z(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},w=(e,s)=>null==s?(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"}):"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)});return r?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):n?(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{className:"text-xl",children:"Default Team Settings"}),!r&&n&&(d?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{c(!1),x(n.values||{})},disabled:p,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:y,loading:p,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Settings"}))]}),(0,m.jsx)(P.Z,{children:"These settings will be applied by default when creating new teams."}),(null==n?void 0:null===(s=n.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(_,{className:"mb-4 mt-2",children:n.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=n;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(_,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),d?(0,m.jsx)("div",{className:"mt-2",children:N(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:w(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No team settings available or you do not have permission to view them."})})},lC=e=>{let{accessToken:s,userID:l}=e,[t,a]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(s&&l)try{let e=await (0,b.a6)(s);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[s,l]);let r=async e=>{if(s&&l)try{await (0,b.cu)(s,e,{user_id:l,role:"user"}),F.ZP.success("Successfully joined team"),a(s=>s.filter(s=>s.team_id!==e))}catch(e){console.error("Error joining team:",e),F.ZP.error("Failed to join team")}};return(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{children:"Members"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsxs)(e3.Z,{children:[t.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.team_alias})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.description||"No description available"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[e.members_with_roles.length," members"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,s)=>(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},s)):(0,m.jsx)(eL.Z,{size:"xs",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})})})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{size:"xs",variant:"secondary",onClick:()=>r(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:5,className:"text-center",children:(0,m.jsx)(P.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lI=(e,s)=>{let l=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),l=e.models):l=s,J(l,s)};var lT=e=>{let{teams:s,searchParams:l,accessToken:t,setTeams:a,userID:r,userRole:i,organizations:n}=e,[o,d]=(0,u.useState)(""),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,u.useEffect)(()=>{console.log("inside useeffect - ".concat(o)),t&&w(t,r,i,c,a),ew()},[o]);let[v]=M.Z.useForm(),[y]=M.Z.useForm(),{Title:Z,Paragraph:N}=et.default,[O,L]=(0,u.useState)(""),[q,V]=(0,u.useState)(!1),[J,G]=(0,u.useState)(null),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(!1),[es,ea]=(0,u.useState)(!1),[er,ei]=(0,u.useState)(!1),[en,eo]=(0,u.useState)(!1),[ed,ec]=(0,u.useState)([]),[em,eu]=(0,u.useState)(!1),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)([]),[ej,ef]=(0,u.useState)({}),[e_,ev]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lI(x,ed);console.log("models: ".concat(e)),eg(e),v.setFieldValue("models",[])},[x,ed]),(0,u.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,b.t3)(t)).guardrails.map(e=>e.guardrail_name);ev(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let ey=async e=>{ex(e),eu(!0)},eb=async()=>{if(null!=eh&&null!=s&&null!=t){try{await (0,b.rs)(t,eh),w(t,r,i,c,a)}catch(e){console.error("Error deleting the team:",e)}eu(!1),ex(null)}};(0,u.useEffect)(()=>{(async()=>{try{if(null===r||null===i||null===t)return;let e=await B(r,i,t);e&&ec(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,r,i,s]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var l;let r=null==e?void 0:e.team_alias,i=null!==(l=null==s?void 0:s.map(e=>e.team_alias))&&void 0!==l?l:[],n=(null==e?void 0:e.organization_id)||(null==c?void 0:c.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));F.ZP.info("Creating Team");let o=await (0,b.hT)(t,e);null!==s?a([...s,o]):a([o]),console.log("response for team create call: ".concat(o)),F.ZP.success("Team created"),v.resetFields(),ea(!1)}}catch(e){console.error("Error creating the team:",e),F.ZP.error("Error creating the team: "+e,20)}},ew=()=>{d(new Date().toLocaleString())},ek=(e,s)=>{let l={...f,[e]:s};_(l),t&&(0,b.JO)(t,l.organization_id||null,null,l.team_id||null,l.team_alias||null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:$?(0,m.jsx)(sB,{teamId:$,onUpdate:e=>{a(s=>null==s?s:s.map(s=>e.team_id===s.team_id?e1(s,e):s))},onClose:()=>{X(null),ee(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let s=0;se.team_id===$)),is_proxy_admin:"Admin"==i,userModels:ed,editTeam:Q}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Your Teams"}),(0,m.jsx)(eM.Z,{children:"Available Teams"}),(0,eZ.tY)(i||"")&&(0,m.jsx)(eM.Z,{children:"Default Team Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",o]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(P.Z,{children:["Click on “Team ID” to view team details ",(0,m.jsx)("b",{children:"and"})," manage team members."]}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Team Name...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_alias,onChange:e=>ek("team_alias",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(g?"bg-gray-100":""),onClick:()=>j(!g),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(f.team_id||f.team_alias||f.organization_id)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{_({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"}),t&&(0,b.JO)(t,null,r||null,null,null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),g&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Enter Team ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_id,onChange:e=>ek("team_id",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:f.organization_id||"",onValueChange:e=>ek("organization_id",e),placeholder:"Select Organization",children:null==n?void 0:n.map(e=>(0,m.jsx)(el.Z,{value:e.organization_id||"",children:e.organization_alias||e.organization_id},e.organization_id))})})]})]})}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Team ID"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Organization"}),(0,m.jsx)(e7.Z,{children:"Info"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.filter(e=>!c||e.organization_id===c.organization_id).sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{X(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)})},s))}):null}),(0,m.jsx)(e6.Z,{children:e.organization_id}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].keys&&ej[e.team_id].keys.length," ","Keys"]}),(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].members_with_roles&&ej[e.team_id].members_with_roles.length," ","Members"]})]}),(0,m.jsx)(e6.Z,{children:"Admin"==i?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{X(e.team_id),ee(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>ey(e.team_id),icon:eK.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),em&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:eb,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{eu(!1),ex(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==i||"Org Admin"==i?(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>ea(!0),children:"+ Create New Team"}),(0,m.jsx)(R.Z,{title:"Create Team",visible:es,width:800,footer:null,onOk:()=>{ea(!1),v.resetFields()},onCancel:()=>{ea(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Organization"," ",(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:c?c.organization_id:null,className:"mt-8",children:(0,m.jsx)(D.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{v.setFieldValue("organization_id",e),p((null==n?void 0:n.find(s=>s.organization_id===e))||null)},filterOption:(e,s)=>{var l;return!!s&&((null===(l=s.children)||void 0===l?void 0:l.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==n?void 0:n.map(e=>(0,m.jsxs)(D.default.Option,{value:e.organization_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"These are the models that your selected team has access to",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ep.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Additional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,m.jsx)(I.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:e_.map(e=>({value:e,label:e}))})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lC,{accessToken:t,userID:r})}),(0,eZ.tY)(i||"")&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lS,{accessToken:t,userID:r||"",userRole:i||""})})]})]})})},lA=e=>{var s,l;let{organizationId:t,onClose:a,accessToken:r,is_org_admin:i,is_proxy_admin:n,userModels:o,editOrg:d}=e,[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!0),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=i||n,T=async()=>{try{if(p(!0),!r)return;let e=await (0,b.t$)(r,t);h(e)}catch(e){F.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{p(!1)}};(0,u.useEffect)(()=>{T()},[t,r]);let A=async e=>{try{if(null==r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.vh)(r,t,s),F.ZP.success("Organization member added successfully"),v(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},E=async e=>{try{if(!r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.LY)(r,t,s),F.ZP.success("Organization member updated successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},L=async e=>{try{if(!r)return;await (0,b.Sb)(r,t,e.user_id),F.ZP.success("Organization member deleted successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},R=async e=>{try{if(!r)return;let s={organization_id:t,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,b.VA)(r,s),F.ZP.success("Organization settings updated successfully"),f(!1),T()}catch(e){F.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return x?(0,m.jsx)("div",{className:"p-4",children:"Loading..."}):c?(0,m.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:a,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:c.organization_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:c.organization_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:d?2:0,children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Members"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Organization Details"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Created: ",new Date(c.created_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Updated: ",new Date(c.updated_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Created By: ",c.created_by]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",c.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===c.litellm_budget_table.max_budget?"Unlimited":"$".concat(c.litellm_budget_table.max_budget)]}),c.litellm_budget_table.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",c.litellm_budget_table.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]}),c.litellm_budget_table.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",c.litellm_budget_table.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:null===(s=c.teams)||void 0===s?void 0:s.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e.team_id},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Created At"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:null===(l=c.members)||void 0===l?void 0:l.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_role})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["$",e.spend.toFixed(6)]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,m.jsx)(e6.Z,{children:k&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{w({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),Z(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{L(e)}})]})})]},s))})]})}),k&&(0,m.jsx)(C.Z,{onClick:()=>{v(!0)},children:"Add Member"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Organization Settings"}),k&&!j&&(0,m.jsx)(C.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,m.jsxs)(M.Z,{form:g,onFinish:R,initialValues:{organization_alias:c.organization_alias,models:c.models,tpm_limit:c.litellm_budget_table.tpm_limit,rpm_limit:c.litellm_budget_table.rpm_limit,max_budget:c.litellm_budget_table.max_budget,budget_duration:c.litellm_budget_table.budget_duration,metadata:c.metadata?JSON.stringify(c.metadata,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization Name"}),(0,m.jsx)("div",{children:c.organization_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{className:"font-mono",children:c.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(c.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==c.litellm_budget_table.max_budget?"$".concat(c.litellm_budget_table.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",c.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,m.jsx)(sK,{isVisible:_,onCancel:()=>v(!1),onSubmit:A,accessToken:r,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,m.jsx)(sV,{visible:y,onCancel:()=>Z(!1),onSubmit:E,initialData:N,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,m.jsx)("div",{className:"p-4",children:"Organization not found"})};let lE=async(e,s)=>{s(await (0,b.r6)(e))};var lP=e=>{let{organizations:s,userRole:l,userModels:t,accessToken:a,lastRefreshed:r,handleRefreshClick:i,currentOrg:n,guardrailsList:o=[],setOrganizations:d,premiumUser:c}=e,[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(!1),[N]=M.Z.useForm();(0,u.useEffect)(()=>{0===s.length&&a&&lE(a,d)},[s,a]);let w=e=>{e&&(v(e),f(!0))},T=async()=>{if(_&&a)try{await (0,b.cq)(a,_),F.ZP.success("Organization deleted successfully"),f(!1),v(null),lE(a,d)}catch(e){console.error("Error deleting organization:",e)}},A=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,b.H1)(a,e),Z(!1),N.resetFields(),lE(a,d)}catch(e){console.error("Error creating organization:",e)}};return c?h?(0,m.jsx)(lA,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===l,userModels:t,editOrg:p}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsx)("div",{className:"flex",children:(0,m.jsx)(eM.Z,{children:"Your Organizations"})}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[r&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",r]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:i})]})]}),(0,m.jsx)(eU.Z,{children:(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(P.Z,{children:"Click on “Organization ID” to view organization details."}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Organization ID"}),(0,m.jsx)(e7.Z,{children:"Organization Name"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"TPM / RPM Limits"}),(0,m.jsx)(e7.Z,{children:"Info"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var s,t,a,r,i,n,o,d,c;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.organization_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(s=e.organization_id)||void 0===s?void 0:s.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{children:e.organization_alias}),(0,m.jsx)(e6.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{children:e.spend}),(0,m.jsx)(e6.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(r=e.litellm_budget_table)||void 0===r?void 0:r.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{children:Array.isArray(e.models)&&(0,m.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)},s))})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["TPM: ",(null===(i=e.litellm_budget_table)||void 0===i?void 0:i.tpm_limit)?null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit:"Unlimited",(0,m.jsx)("br",{}),"RPM: ",(null===(o=e.litellm_budget_table)||void 0===o?void 0:o.rpm_limit)?null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit:"Unlimited"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[(null===(c=e.members)||void 0===c?void 0:c.length)||0," Members"]})}),(0,m.jsx)(e6.Z,{children:"Admin"===l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>w(e.organization_id),icon:eK.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===l||"Org Admin"===l)&&(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>Z(!0),children:"+ Create New Organization"}),(0,m.jsx)(R.Z,{title:"Create Organization",visible:y,width:800,footer:null,onCancel:()=>{Z(!1),N.resetFields()},children:(0,m.jsxs)(M.Z,{form:N,onFinish:A,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),j?(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Organization"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this organization?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:T,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})}):(0,m.jsx)(m.Fragment,{})]}):(0,m.jsx)("div",{children:(0,m.jsxs)(P.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,m.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lO=l(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lM=e=>{let{isAddSSOModalVisible:s,isInstructionsModalVisible:l,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:r,handleInstructionsOk:i,handleInstructionsCancel:n,form:o}=e,d=e=>{let s=lD[e];return s?s.fields.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,m.jsx)(z.default.Password,{}):(0,m.jsx)(I.Z,{placeholder:e.placeholder})},e.name)):null};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(R.Z,{title:"Add SSO",visible:s,width:800,footer:null,onOk:t,onCancel:a,children:(0,m.jsxs)(M.Z,{form:o,onFinish:r,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,m.jsx)(D.default,{children:Object.entries(lL).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[l&&(0,m.jsx)("img",{src:l,alt:s,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,m.jsxs)("span",{children:[s.charAt(0).toUpperCase()+s.slice(1)," SSO"]})]})},s)})})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.sso_provider!==s.sso_provider,children:e=>{let{getFieldValue:s}=e,l=s("sso_provider");return l?d(l):null}}),(0,m.jsx)(M.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,m.jsxs)(R.Z,{title:"SSO Setup Instructions",visible:l,width:800,footer:null,onOk:i,onCancel:n,children:[(0,m.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{onClick:i,children:"Done"})})]})]})},lF=l(62272),lR=l(92403),lq=l(29271),lU=l(34419);let lz=e=>{if(!e)return"An unknown error occurred";if("string"==typeof e)return e;if(e.message)try{let s=JSON.parse(e.message);if(s.error&&s.error.message)return s.error.message;return"string"==typeof s?s:JSON.stringify(s,null,2)}catch(s){return e.message}if(e.response&&e.response.data){if("string"==typeof e.response.data)return e.response.data;if(e.response.data.message)return e.response.data.message;if(e.response.data.error)return"string"==typeof e.response.data.error?e.response.data.error:e.response.data.error.message||JSON.stringify(e.response.data.error)}return String(e)};var lV=e=>{let{accessToken:s,userID:l,proxySettings:t}=e,[a]=M.Z.useForm(),[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(null),[d,c]=(0,u.useState)("");(0,u.useEffect)(()=>{let e="";c(t&&t.PROXY_BASE_URL&&void 0!==t.PROXY_BASE_URL?t.PROXY_BASE_URL:window.location.origin)},[t]);let h="".concat(d,"/scim/v2"),x=async e=>{if(!s||!l){F.ZP.error("You need to be logged in to create a SCIM token");return}try{i(!0);let t={key_alias:e.key_alias||"SCIM Access Token",team_id:null,models:[],allowed_routes:["/scim/*"]},a=await (0,b.wX)(s,l,t);o(a),F.ZP.success("SCIM token created successfully")}catch(e){console.error("Error creating SCIM token:",e),F.ZP.error("Failed to create SCIM token: "+lz(e))}finally{i(!1)}};return(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex items-center mb-4",children:(0,m.jsx)(O.Z,{children:"SCIM Configuration"})}),(0,m.jsx)(P.Z,{className:"text-gray-600",children:"System for Cross-domain Identity Management (SCIM) allows you to automatically provision and manage users and groups in LiteLLM."}),(0,m.jsx)(ly.Z,{}),(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"1"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lF.Z,{className:"h-5 w-5 mr-2"}),"SCIM Tenant URL"]})]}),(0,m.jsx)(P.Z,{className:"text-gray-600 mb-3",children:"Use this URL in your identity provider SCIM integration settings."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:h,disabled:!0,className:"flex-grow"}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>F.ZP.success("URL copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"ml-2 flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"2"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-5 w-5 mr-2"}),"Authentication Token"]})]}),(0,m.jsx)(lO.Z,{title:"Using SCIM",color:"blue",className:"mb-4",children:"You need a SCIM token to authenticate with the SCIM API. Create one below and use it in your SCIM provider configuration."}),n?(0,m.jsxs)(eD.Z,{className:"border border-yellow-300 bg-yellow-50",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 text-yellow-800",children:[(0,m.jsx)(lq.Z,{className:"h-5 w-5 mr-2"}),(0,m.jsx)(O.Z,{className:"text-lg text-yellow-800",children:"Your SCIM Token"})]}),(0,m.jsx)(P.Z,{className:"text-yellow-800 mb-4 font-medium",children:"Make sure to copy this token now. You will not be able to see it again."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:n.token,className:"flex-grow mr-2 bg-white",type:"password",disabled:!0}),(0,m.jsx)(L.CopyToClipboard,{text:n.token,onCopy:()=>F.ZP.success("Token copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]}),(0,m.jsxs)(C.Z,{className:"mt-4 flex items-center",variant:"secondary",onClick:()=>o(null),children:[(0,m.jsx)(lU.Z,{className:"h-4 w-4 mr-1"}),"Create Another Token"]})]}):(0,m.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,m.jsxs)(M.Z,{form:a,onFinish:x,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Token Name",rules:[{required:!0,message:"Please enter a name for your token"}],children:(0,m.jsx)(I.Z,{placeholder:"SCIM Access Token"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)(C.Z,{variant:"primary",type:"submit",loading:r,className:"flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-4 w-4 mr-1"}),"Create SCIM Token"]})})]})})]})]})]})})},lK=e=>{let{searchParams:s,accessToken:l,userID:t,showSSOBanner:a,premiumUser:r,proxySettings:i}=e,[n]=M.Z.useForm(),[o]=M.Z.useForm(),{Title:d,Paragraph:c}=et.default,[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(!1),[w,k]=(0,u.useState)(!1),[S,I]=(0,u.useState)(!1),[T,A]=(0,u.useState)(!1),[E,P]=(0,u.useState)(!1),[O,L]=(0,u.useState)(!1),[D,q]=(0,u.useState)(!1),[V,K]=(0,u.useState)(!1),[B,H]=(0,u.useState)([]),[J,G]=(0,u.useState)(null);(0,h.useRouter)();let[W,Y]=(0,u.useState)(null);console.log=function(){};let $=e0(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==r){F.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(l){let e=await (0,b.PT)(l);H(e&&e.length>0?e:[X])}else H([X])}catch(e){console.error("Error fetching allowed IPs:",e),F.ZP.error("Failed to fetch allowed IPs ".concat(e)),H([X])}finally{!0===r&&L(!0)}},es=async e=>{try{if(l){await (0,b.eH)(l,e.ip);let s=await (0,b.PT)(l);H(s),F.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),F.ZP.error("Failed to add IP address ".concat(e))}finally{q(!1)}},el=async e=>{G(e),K(!0)},ea=async()=>{if(J&&l)try{await (0,b.$I)(l,J);let e=await (0,b.PT)(l);H(e.length>0?e:[X]),F.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),F.ZP.error("Failed to delete IP address ".concat(e))}finally{K(!1),G(null)}};(0,u.useEffect)(()=>{(async()=>{if(null!=l){let e=[],s=await (0,b.Xd)(l,"proxy_admin_viewer");console.log("proxy admin viewer response: ",s);let t=s.users;console.log("proxy viewers response: ".concat(t)),t.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,b.Xd)(l,"proxy_admin")).users;a.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),j(e),Y(await (0,b.lg)(l))}})()},[l]);let er=async e=>{try{if(null!=l&&null!=g){var s;F.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,b.pf)(l,e,"proxy_admin"),a=(null===(s=t.data)||void 0===s?void 0:s.user_id)||t.user_id;(0,b.XO)(l,a).then(e=>{_(e),y(!0)}),console.log("response for team create call: ".concat(t));let r=g.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),g.push(t),j(g)),n.resetFields(),k(!1)}}catch(e){console.error("Error creating the key:",e)}},ei=async e=>{if(null==l)return;let s=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};s&&Object.entries(s.envVarMap).forEach(s=>{let[l,a]=s;e[l]&&(t[a]=e[l])}),(0,b.K_)(l,{environment_variables:t})};return console.log("admins: ".concat(null==g?void 0:g.length)),(0,m.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,m.jsx)(d,{level:4,children:"Admin Access "}),(0,m.jsx)(c,{children:"Go to 'Internal Users' page to add other admins."}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Security Settings"}),(0,m.jsx)(eM.Z,{children:"SCIM"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(d,{level:4,children:" ✨ Security Settings"}),(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:()=>!0===r?A(!0):F.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,m.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,m.jsx)(lM,{isAddSSOModalVisible:T,isInstructionsModalVisible:E,handleAddSSOOk:()=>{A(!1),n.resetFields()},handleAddSSOCancel:()=>{A(!1),n.resetFields()},handleShowInstructions:e=>{er(e),ei(e),A(!1),P(!0)},handleInstructionsOk:()=>{P(!1)},handleInstructionsCancel:()=>{P(!1)},form:n}),(0,m.jsx)(R.Z,{title:"Manage Allowed IP Addresses",width:800,visible:O,onCancel:()=>L(!1),footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,m.jsx)(C.Z,{onClick:()=>L(!1),children:"Close"},"close")],children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"IP Address"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:B.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e}),(0,m.jsx)(e6.Z,{className:"text-right",children:e!==X&&(0,m.jsx)(C.Z,{onClick:()=>el(e),color:"red",size:"xs",children:"Delete"})})]},s))})]})}),(0,m.jsx)(R.Z,{title:"Add Allowed IP Address",visible:D,onCancel:()=>q(!1),footer:null,children:(0,m.jsxs)(M.Z,{onFinish:es,children:[(0,m.jsx)(M.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,m.jsx)(z.default,{placeholder:"Enter IP address"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,m.jsx)(R.Z,{title:"Confirm Delete",visible:V,onCancel:()=>K(!1),onOk:ea,footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>ea(),children:"Yes"},"delete"),(0,m.jsx)(C.Z,{onClick:()=>K(!1),children:"Close"},"close")],children:(0,m.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",J,"?"]})})]}),(0,m.jsxs)(lO.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,m.jsxs)("a",{href:Q,target:"_blank",children:[(0,m.jsx)("b",{children:Q})," "]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lV,{accessToken:l,userID:t,proxySettings:i})})]})]})]})},lB=l(92858);let{Title:lH}=et.default;var lJ=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)([]);(0,u.useEffect)(()=>{i()},[s]);let i=async()=>{if(s){t(!0);try{let e=await (0,b.pu)(s);r(e.settings)}catch(e){console.error("Failed to fetch email event settings:",e),F.ZP.error("Failed to fetch email event settings")}finally{t(!1)}}},n=(e,s)=>{r(a.map(l=>l.event===e?{...l,enabled:s}:l))},o=async()=>{if(s)try{await (0,b.qW)(s,{settings:a}),F.ZP.success("Email event settings updated successfully")}catch(e){console.error("Failed to update email event settings:",e),F.ZP.error("Failed to update email event settings")}},d=async()=>{if(s)try{await (0,b.jr)(s),F.ZP.success("Email event settings reset to defaults"),i()}catch(e){console.error("Failed to reset email event settings:",e),F.ZP.error("Failed to reset email event settings")}},c=e=>{if(e.includes("Virtual Key Created"))return"An email will be sent to the user when a new virtual key is created with their user ID";if(e.includes("New User Invitation"))return"An email will be sent to the email address of the user when a new user is created";{let s=e.split(/(?=[A-Z])/).join(" ").toLowerCase();return"Receive an email notification when ".concat(s)}};return(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lH,{level:4,children:"Email Notifications"}),(0,m.jsx)(P.Z,{children:"Select which events should trigger email notifications."}),(0,m.jsx)(le.Z,{}),l?(0,m.jsx)("div",{style:{textAlign:"center",padding:"20px"},children:(0,m.jsx)(lb.Z,{size:"large"})}):(0,m.jsx)("div",{className:"space-y-4",children:a.map(e=>(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(sL.Z,{checked:e.enabled,onChange:s=>n(e.event,s.target.checked)}),(0,m.jsxs)("div",{className:"ml-3",children:[(0,m.jsx)(P.Z,{children:e.event}),(0,m.jsx)("div",{className:"text-sm text-gray-500 block",children:c(e.event)})]})]},e.event))}),(0,m.jsxs)("div",{className:"mt-6 flex space-x-4",children:[(0,m.jsx)(C.Z,{onClick:o,disabled:l,children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:d,variant:"secondary",disabled:l,children:"Reset to Defaults"})]})]})};let{Title:lG}=et.default;var lW=e=>{let{accessToken:s,premiumUser:l,alerts:t}=e,a=()=>{if(!s)return;let e={};t.filter(e=>"email"===e.name).forEach(s=>{var l;Object.entries(null!==(l=s.variables)&&void 0!==l?l:{}).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));a&&a.value&&(e[l]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,b.K_)(s,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Email settings updated successfully")};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mt-6 mb-6",children:(0,m.jsx)(lJ,{accessToken:s})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lG,{level:4,children:"Email Server Settings"}),(0,m.jsxs)(P.Z,{children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,m.jsx)("br",{})]}),(0,m.jsx)("div",{className:"flex w-full",children:t.filter(e=>"email"===e.name).map((e,s)=>{var t;return(0,m.jsx)(e6.Z,{children:(0,m.jsx)("ul",{children:(0,m.jsx)(S.Z,{numItems:2,children:Object.entries(null!==(t=e.variables)&&void 0!==t?t:{}).map(e=>{let[s,t]=e;return(0,m.jsxs)("li",{className:"mx-2 my-2",children:[!0!=l&&("EMAIL_LOGO_URL"===s||"EMAIL_SUPPORT_CONTACT"===s)?(0,m.jsxs)("div",{children:[(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,m.jsxs)(P.Z,{className:"mt-2",children:[" ","✨ ",s]})}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-2",children:s}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",style:{width:"400px"}})]}),(0,m.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===s&&(0,m.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},s)})})})},s)})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>a(),children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>s&&(0,b.jE)(s,"email"),className:"mx-2",children:"Test Email Alerts"})]})]})},lY=e=>{let{alertingSettings:s,handleInputChange:l,handleResetField:t,handleSubmit:a,premiumUser:r}=e,[i]=M.Z.useForm();return(0,m.jsxs)(M.Z,{form:i,onFinish:()=>{console.log("INSIDE ONFINISH");let e=i.getFieldsValue(),s=Object.entries(e).every(e=>{let[s,l]=e;return"boolean"!=typeof l&&(""===l||null==l)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(s)),s?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[s.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{align:"center",children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?r?(0,m.jsx)(M.Z.Item,{name:e.field_name,children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s)}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>l(e.field_name,s)}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}):(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,m.jsx)(M.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s),className:"p-0"}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>{l(e.field_name,s),i.setFieldsValue({[e.field_name]:s})}}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>t(e.field_name,s),children:"Reset"})})]},s)),(0,m.jsx)("div",{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Update Settings"})})]})},l$=e=>{let{accessToken:s,premiumUser:l}=e,[t,a]=(0,u.useState)([]);return(0,u.useEffect)(()=>{s&&(0,b.RQ)(s).then(e=>{a(e)})},[s]),(0,m.jsx)(lY,{alertingSettings:t,handleInputChange:(e,s)=>{let l=t.map(l=>l.field_name===e?{...l,field_value:s}:l);console.log("updatedSettings: ".concat(JSON.stringify(l))),a(l)},handleResetField:(e,l)=>{if(s)try{let s=t.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:s.field_default_value}:s);a(s)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!s||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let l={};t.forEach(e=>{l[e.field_name]=e.field_value});let a={...e,...l};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,b.jA)(s,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,b.jA)(s,"alerting",["slack"]):(0,b.jA)(s,"alerting",[])),F.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:l})},lX=l(86582);let{Title:lQ,Paragraph:l0}=et.default;console.log=function(){};var l1=e=>{let{accessToken:s,userRole:l,userID:t,premiumUser:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h]=M.Z.useForm(),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)({}),[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(!1),[T,A]=(0,u.useState)([]),[E,O]=(0,u.useState)(null),[L,q]=(0,u.useState)([]),[z,V]=(0,u.useState)(!1),[K,B]=(0,u.useState)(null),H=e=>{Z.includes(e)?N(Z.filter(s=>s!==e)):N([...Z,e])},J={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,u.useEffect)(()=>{s&&l&&t&&(0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e),i(e.callbacks),A(e.available_callbacks);let s=e.alerts;if(console.log("alerts_data",s),s&&s.length>0){let e=s[0];console.log("_alert_info",e);let l=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",l),N(e.active_alerts),_(l),y(e.alerts_to_webhook)}o(s)})},[s,l,t]);let G=e=>Z&&Z.includes(e),W=async e=>{if(!s)return;let l={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(l[s]=t)});try{await (0,b.K_)(s,{environment_variables:l}),F.ZP.success("Callback added successfully"),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},Y=async e=>{if(!s)return;let l=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[s,l]=e;"callback"!==s&&(t[s]=l)});try{await (0,b.K_)(s,{environment_variables:t,litellm_settings:{success_callback:[l]}}),F.ZP.success("Callback ".concat(l," added successfully")),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},$=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",T),e&&e.litellm_callback_params?(q(e.litellm_callback_params),console.log("selectedCallbackParams",L)):q([])};return s?(console.log("callbacks: ".concat(r)),(0,m.jsxs)("div",{className:"w-full mx-4",children:[(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Logging Callbacks"}),(0,m.jsx)(eM.Z,{value:"2",children:"Alerting Types"}),(0,m.jsx)(eM.Z,{value:"3",children:"Alerting Settings"}),(0,m.jsx)(eM.Z,{value:"4",children:"Email Alerts"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(lQ,{level:4,children:"Active Logging Callbacks"}),(0,m.jsx)(S.Z,{numItems:2,children:(0,m.jsx)(eD.Z,{className:"max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e7.Z,{children:"Callback Name"})})}),(0,m.jsx)(e3.Z,{children:r.map((e,l)=>(0,m.jsxs)(e9.Z,{className:"flex justify-between",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.name})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"flex justify-between",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{B(e),V(!0)}}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},l))})]})})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>k(!0),children:"Add Callback"})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(P.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,m.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{children:"Slack Webhook URL"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(J).map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:"region_outage_alerts"==l?a?(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)}):(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:l,type:"password",defaultValue:v&&v[l]?v[l]:f})})]},s)})})]}),(0,m.jsx)(C.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!s)return;let e={};Object.entries(J).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));console.log("key",l),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[l]=r}),console.log("updatedAlertToWebhooks",e);let l={general_settings:{alert_to_webhook_url:e,alert_types:Z}};console.log("payload",l);try{(0,b.K_)(s,l)}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(l$,{accessToken:s,premiumUser:a})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lW,{accessToken:s,premiumUser:a,alerts:n})})]})]})}),(0,m.jsxs)(R.Z,{title:"Add Logging Callback",visible:w,width:800,onCancel:()=>k(!1),footer:null,children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,m.jsx)(M.Z,{form:h,onFinish:Y,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lX.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,m.jsx)(D.default,{onChange:e=>{let s=T[e];s&&(console.log(s.ui_callback_name),$(s))},children:T&&Object.values(T).map(e=>(0,m.jsx)(el.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),L&&L.map(e=>(0,m.jsx)(lX.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,m.jsx)(I.Z,{type:"password"})},e)),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,m.jsx)(R.Z,{visible:z,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>V(!1),footer:null,children:(0,m.jsxs)(M.Z,{form:h,onFinish:W,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(m.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[s,l]=e;return(0,m.jsx)(lX.Z,{label:s,name:s,children:(0,m.jsx)(I.Z,{type:"password",defaultValue:l})},s)})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},l2=l(92414),l4=l(46030);let{Option:l5}=D.default;var l3=e=>{let{models:s,accessToken:l,routerSettings:t,setRouterSettings:a}=e,[r]=M.Z.useForm(),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>n(!0),children:"+ Add Fallbacks"}),(0,m.jsx)(R.Z,{title:"Add Fallbacks",visible:i,width:800,footer:null,onOk:()=>{n(!1),r.resetFields()},onCancel:()=>{n(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:e=>{console.log(e);let{model_name:s,models:i}=e,o=[...t.fallbacks||[],{[s]:i}],d={...t,fallbacks:o};console.log(d);try{(0,b.K_)(l,{router_settings:d}),a(d)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully"),n(!1),r.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,m.jsx)(eO.Z,{defaultValue:o,children:s&&s.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>d(e),children:e},s))})}),(0,m.jsx)(M.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,m.jsx)(l2.Z,{value:s,children:s&&s.filter(e=>e!=o).map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},l6=l(26433);async function l8(e,s){console.log=function(){},console.log("isLocal:",!1);let l=window.location.origin,t=new l6.ZP.OpenAI({apiKey:s,baseURL:l,dangerouslyAllowBrowser:!0});try{let s=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});F.ZP.success((0,m.jsxs)("span",{children:["Test model=",(0,m.jsx)("strong",{children:e}),", received model=",(0,m.jsx)("strong",{children:s.model}),". See"," ",(0,m.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l7={ttl:3600,lowest_latency_buffer:0},l9=e=>{let{selectedStrategy:s,strategyArgs:l,paramExplanation:t}=e;return(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,m.jsx)(A.Z,{children:"latency-based-routing"==s?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(l).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[s]})]}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]})}):(0,m.jsx)(P.Z,{children:"No specific settings"})})]})};var te=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,i]=(0,u.useState)({}),[n,o]=(0,u.useState)({}),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(null),Z={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,u.useEffect)(()=>{s&&l&&t&&((0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e);let s=e.router_settings;"model_group_retry_policy"in s&&delete s.model_group_retry_policy,i(s)}),(0,b.YU)(s).then(e=>{c(e)}))},[s,l,t]);let N=async e=>{if(!s)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(r.fallbacks));let l=r.fallbacks.map(s=>(e in s&&delete s[e],s)).filter(e=>Object.keys(e).length>0),t={...r,fallbacks:l};try{await (0,b.K_)(s,{router_settings:t}),i(t),F.ZP.success("Router settings updated successfully")}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}},w=(e,s)=>{c(d.map(l=>l.field_name===e?{...l,field_value:s}:l))},T=(e,l)=>{if(!s)return;let t=d[l].field_value;if(null!=t&&void 0!=t)try{(0,b.jA)(s,e,t);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:!0}:s);c(l)}catch(e){}},A=(e,l)=>{if(s)try{(0,b.ao)(s,e);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:null}:s);c(l)}catch(e){}},E=e=>{if(!s)return;console.log("router_settings",e);let l=Object.fromEntries(Object.entries(e).map(e=>{let[s,l]=e;if("routing_strategy_args"!==s&&"routing_strategy"!==s){var t;return[s,(null===(t=document.querySelector('input[name="'.concat(s,'"]')))||void 0===t?void 0:t.value)||l]}if("routing_strategy"==s)return[s,f];if("routing_strategy_args"==s&&"latency-based-routing"==f){let e={},s=document.querySelector('input[name="lowest_latency_buffer"]'),l=document.querySelector('input[name="ttl"]');return(null==s?void 0:s.value)&&(e.lowest_latency_buffer=Number(s.value)),(null==l?void 0:l.value)&&(e.ttl=Number(l.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",l);try{(0,b.K_)(s,{router_settings:l})}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully")};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Loadbalancing"}),(0,m.jsx)(eM.Z,{value:"2",children:"Fallbacks"}),(0,m.jsx)(eM.Z,{value:"3",children:"General"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,m.jsx)(O.Z,{children:"Router Settings"}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(r).filter(e=>{let[s,l]=e;return"fallbacks"!=s&&"context_window_fallbacks"!=s&&"routing_strategy_args"!=s}).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:Z[s]})]}),(0,m.jsx)(e6.Z,{children:"routing_strategy"==s?(0,m.jsxs)(eO.Z,{defaultValue:l,className:"w-full max-w-md",onValueChange:_,children:[(0,m.jsx)(el.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,m.jsx)(el.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,m.jsx)(el.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]}),(0,m.jsx)(l9,{selectedStrategy:f,strategyArgs:r&&r.routing_strategy_args&&Object.keys(r.routing_strategy_args).length>0?r.routing_strategy_args:l7,paramExplanation:Z})]}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>E(r),children:"Save Changes"})})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Model Name"}),(0,m.jsx)(e7.Z,{children:"Fallbacks"})]})}),(0,m.jsx)(e3.Z,{children:r.fallbacks&&r.fallbacks.map((e,l)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:t}),(0,m.jsx)(e6.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{onClick:()=>l8(t,s),children:"Test Fallback"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>N(t)})})]},l.toString()+t)}))})]}),(0,m.jsx)(l3,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:s,routerSettings:r,setRouterSettings:i})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"}),(0,m.jsx)(e7.Z,{children:"Status"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:d.filter(e=>"TypedDictionary"!==e.field_type).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,m.jsx)(e6.Z,{children:"Integer"==e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>w(e.field_name,s)}):null}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{onClick:()=>T(e.field_name,s),children:"Update"}),(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>A(e.field_name,s),children:"Reset"})]})]},s))})]})})})]})]})}):null},ts=l(93142),tl=e=>{let{value:s={},onChange:l}=e,[t,a]=(0,u.useState)(Object.entries(s)),r=e=>{let s=t.filter((s,l)=>l!==e);a(s),null==l||l(Object.fromEntries(s))},i=(e,s,r)=>{let i=[...t];i[e]=[s,r],a(i),null==l||l(Object.fromEntries(i))};return(0,m.jsxs)("div",{children:[t.map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(ts.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,m.jsx)(I.Z,{placeholder:"Header Name",value:l,onChange:e=>i(s,e.target.value,t)}),(0,m.jsx)(I.Z,{placeholder:"Header Value",value:t,onChange:e=>i(s,l,e.target.value)}),(0,m.jsx)(s$.Z,{onClick:()=>r(s)})]},s)}),(0,m.jsx)(U.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,m.jsx)(sX.Z,{}),children:"Add Header"})]})};let{Option:tt}=D.default;var ta=e=>{let{accessToken:s,setPassThroughItems:l,passThroughItems:t}=e,[a]=M.Z.useForm(),[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Add Pass-Through Endpoint"}),(0,m.jsx)(R.Z,{title:"Add Pass-Through Endpoint",visible:r,width:800,footer:null,onOk:()=>{i(!1),a.resetFields()},onCancel:()=>{i(!1),a.resetFields()},children:(0,m.jsxs)(M.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,b.Vt)(s,e),l(r)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("Pass through endpoint successfully added"),i(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,m.jsx)(tl,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},tr=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,i]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&l&&t&&(0,b.mp)(s).then(e=>{i(e.endpoints)})},[s,l,t]);let n=(e,l)=>{if(s)try{(0,b.EG)(s,e);let l=r.filter(s=>s.path!==e);i(l),F.ZP.success("Endpoint deleted successfully.")}catch(e){}};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsx)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Path"}),(0,m.jsx)(e7.Z,{children:"Target"}),(0,m.jsx)(e7.Z,{children:"Headers"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:r.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.path})}),(0,m.jsx)(e6.Z,{children:e.target}),(0,m.jsx)(e6.Z,{children:JSON.stringify(e.headers)}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>n(e.path,s),children:"Reset"})})]},s))})]}),(0,m.jsx)(ta,{accessToken:s,setPassThroughItems:i,passThroughItems:r})]})})}):null},ti=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a}=e,[r]=M.Z.useForm(),i=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call");let s=await (0,b.Zr)(l,e);console.log("key create Response:",s),a(e=>e?[...e,s]:[s]),F.ZP.success("API Key Created"),r.resetFields()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Create Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),r.resetFields()},onCancel:()=>{t(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},tn=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a,existingBudget:r,handleUpdateCall:i}=e;console.log("existingBudget",r);let[n]=M.Z.useForm();(0,u.useEffect)(()=>{n.setFieldsValue(r)},[r,n]);let o=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call"),t(!0);let s=await (0,b.qI)(l,e);a(e=>e?[...e,s]:[s]),F.ZP.success("Budget Updated"),n.resetFields(),i()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Edit Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),n.resetFields()},onCancel:()=>{t(!1),n.resetFields()},children:(0,m.jsxs)(M.Z,{form:n,onFinish:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:r,children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})},to=l(17906),td=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&(0,b.O3)(s).then(e=>{d(e)})},[s]);let c=async(e,l)=>{console.log("budget_id",e),null!=s&&(n(o.find(s=>s.budget_id===e)||null),r(!0))},h=async(e,l)=>{if(null==s)return;F.ZP.info("Request made"),await (0,b.NV)(s,e);let t=[...o];t.splice(l,1),d(t),F.ZP.success("Budget Deleted.")},x=async()=>{null!=s&&(0,b.O3)(s).then(e=>{d(e)})};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)(C.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,m.jsx)(ti,{accessToken:s,isModalVisible:l,setIsModalVisible:t,setBudgetList:d}),i&&(0,m.jsx)(tn,{accessToken:s,isModalVisible:a,setIsModalVisible:r,setBudgetList:d,existingBudget:i,handleUpdateCall:x}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Create a budget to assign to customers."}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Budget ID"}),(0,m.jsx)(e7.Z,{children:"Max Budget"}),(0,m.jsx)(e7.Z,{children:"TPM"}),(0,m.jsx)(e7.Z,{children:"RPM"})]})}),(0,m.jsx)(e3.Z,{children:o.slice().sort((e,s)=>new Date(s.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.budget_id}),(0,m.jsx)(e6.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,m.jsx)(e6.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,m.jsx)(e6.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>c(e.budget_id,s)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>h(e.budget_id,s)})]},s))})]})]}),(0,m.jsxs)("div",{className:"mt-5",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"How to use budget id"}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Assign Budget to Customer"}),(0,m.jsx)(eM.Z,{children:"Test it (Curl)"}),(0,m.jsx)(eM.Z,{children:"Test it (OpenAI SDK)"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},tc=l(77398),tm=l.n(tc);function tu(e){let{data:s=[],columns:l,getRowCanExpand:t,renderSubComponent:a,isLoading:r=!1,loadingMessage:i="\uD83D\uDE85 Loading logs...",noDataMessage:n="No logs found"}=e,o=(0,e2.b7)({data:s,columns:l,getRowCanExpand:t,getRowId:(e,s)=>{var l;return null!==(l=null==e?void 0:e.request_id)&&void 0!==l?l:String(s)},getCoreRowModel:(0,e4.sC)(),getExpandedRowModel:(0,e4.rV)()});return(0,m.jsx)("div",{className:"rounded-lg custom-border",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:r?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:i})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:n})})})})})]})})}let th=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},tx=e=>{let{utcTime:s}=e;return(0,m.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:th(s)})},tp=(e,s)=>{var l,t;return(null===(t=e.metadata)||void 0===t?void 0:null===(l=t.mcp_tool_call_metadata)||void 0===l?void 0:l.mcp_server_logo_url)?e.metadata.mcp_tool_call_metadata.mcp_server_logo_url:s?sm(s).logo:""},tg=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,m.jsx)(()=>{let[e,l]=u.useState(s.getIsExpanded()),t=u.useCallback(()=>{l(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,m.jsx)("button",{onClick:t,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,m.jsx)("svg",{className:"w-4 h-4 transform transition-transform duration-75 ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,m.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Time",accessorKey:"startTime",cell:e=>(0,m.jsx)(tx,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let s="failure"!==(e.getValue()||"Success").toLowerCase();return(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(s?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s?"Success":"Failure"})}},{header:"Session ID",accessorKey:"session_id",cell:e=>{let s=String(e.getValue()||""),l=e.row.original.onSessionClick;return(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal text-xs max-w-[15ch] truncate block",onClick:()=>null==l?void 0:l(s),children:String(e.getValue()||"")})})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)("span",{className:"font-mono text-xs max-w-[15ch] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,m.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let s=String(e.getValue()||"-"),l=e.row.original.onKeyHashClick;return(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsx)("span",{className:"font-mono max-w-[15ch] truncate block cursor-pointer hover:text-blue-600",onClick:()=>null==l?void 0:l(s),children:s})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Model",accessorKey:"model",cell:e=>{let s=e.row.original,l=s.custom_llm_provider,t=String(e.getValue()||"");return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:tp(s,l),alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(Y.Z,{title:t,children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:t})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let s=e.row.original;return(0,m.jsxs)("span",{className:"text-sm",children:[String(s.total_tokens||"0"),(0,m.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(s.prompt_tokens||"0"),"+",String(s.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"End User",accessorKey:"end_user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let s=e.getValue();if(!s||0===Object.keys(s).length)return"-";let l=Object.entries(s),t=l[0],a=l.slice(1);return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,m.jsx)(Y.Z,{title:(0,m.jsx)("div",{className:"flex flex-col gap-1",children:l.map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{children:[s,": ",String(l)]},s)})}),children:(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],tj=async(e,s,l,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,s],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,b.qk)(l,e.request_id,s);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}};function tf(e){let{row:s,hasMessages:l,hasResponse:t,hasError:a,errorInfo:r,getRawRequest:i,formattedResponse:n}=e;return(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,m.jsx)("button",{onClick:()=>{try{navigator.clipboard.writeText(JSON.stringify(i(),null,2)),F.ZP.success("Request copied to clipboard")}catch(e){F.ZP.error("Failed to copy request")}},className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(i(),null,2)})})]}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsxs)("h3",{className:"text-lg font-medium",children:["Response",a&&(0,m.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==r?void 0:r.error_code)||400]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(n(),null,2)),F.ZP.success("Response copied to clipboard")},className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!t,children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:t?(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(n(),null,2)}):(0,m.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]})}let t_=e=>{var s;let{errorInfo:l}=e,[t,a]=u.useState({}),[r,i]=u.useState(!1),n=e=>{a(s=>({...s,[e]:!s[e]}))},o=l.traceback&&(s=l.traceback)?Array.from(s.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let l=e[1],t=e[2],a=l.split("/").pop()||l,r=e.index||0,i=s.indexOf('File "',r+1),n=i>-1?s.substring(r,i).trim():s.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:l,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,m.jsx)("span",{className:"text-red-700",children:l.error_class||"Unknown Error"})]}),(0,m.jsxs)("div",{className:"flex mt-2",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20 flex-shrink-0",children:"Message:"}),(0,m.jsx)("span",{className:"text-red-700 break-words whitespace-pre-wrap",children:l.error_message||"Unknown error occurred"})]})]}),l.traceback&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,m.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsx)("button",{onClick:()=>{let e=!r;if(i(e),o.length>0){let s={};o.forEach((l,t)=>{s[t]=e}),a(s)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:r?"Collapse All":"Expand All"}),(0,m.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(l.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,m.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,m.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:o.map((e,s)=>(0,m.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,m.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>n(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,m.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,m.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,m.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,m.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[s]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[s]||!1)&&e.code&&(0,m.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},s))})]})]})]})},tv=e=>{let{show:s}=e;return s?(0,m.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,m.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,m.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,m.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,m.jsxs)("div",{children:[(0,m.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,m.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,m.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,m.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,m.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};var ty=l(35829);let tb=e=>{let{sessionId:s,logs:l,onBack:t}=e,[a,r]=(0,u.useState)(null),i=l.reduce((e,s)=>e+(s.spend||0),0),n=l.reduce((e,s)=>e+(s.total_tokens||0),0),o=l.length>0?new Date(l[0].startTime):new Date;return(((l.length>0?new Date(l[l.length-1].endTime):new Date).getTime()-o.getTime())/1e3).toFixed(2),l.map(e=>({time:new Date(e.startTime).toISOString(),tokens:e.total_tokens||0,cost:e.spend||0})),(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)("div",{className:"flex items-center space-x-4",children:(0,m.jsxs)("button",{onClick:t,className:"flex items-center text-gray-600 hover:text-gray-900 transition-colors",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),"Back to All Logs"]})}),(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsx)("h1",{className:"text-2xl font-semibold text-gray-900",children:"Session Details"}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500 font-mono",children:s}),(0,m.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/ui_logs_sessions",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Get started with session management here",(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(ty.Z,{children:l.length})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Cost"}),(0,m.jsxs)(ty.Z,{children:["$",i.toFixed(4)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(ty.Z,{children:n})]})]}),(0,m.jsx)(O.Z,{children:"Session Logs"}),(0,m.jsx)("div",{className:"mt-4",children:(0,m.jsx)(tu,{columns:tg,data:l,renderSubComponent:tS,getRowCanExpand:()=>!0,loadingMessage:"Loading logs...",noDataMessage:"No logs found"})})]})};function tZ(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)({});if(!s||0===s.length)return null;let i=e=>new Date(1e3*e).toLocaleString(),n=(e,s)=>"".concat(((s-e)*1e3).toFixed(2),"ms"),o=(e,s)=>{let l="".concat(e,"-").concat(s);r(e=>({...e,[l]:!e[l]}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Vector Store Requests"})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsx)("div",{className:"p-4",children:s.map((e,s)=>(0,m.jsxs)("div",{className:"mb-6 last:mb-0",children:[(0,m.jsx)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Query:"}),(0,m.jsx)("span",{className:"font-mono",children:e.query})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Vector Store ID:"}),(0,m.jsx)("span",{className:"font-mono",children:e.vector_store_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{className:"flex items-center",children:(()=>{let{logo:s,displayName:l}=sm(e.custom_llm_provider);return(0,m.jsxs)(m.Fragment,{children:[s&&(0,m.jsx)("img",{src:s,alt:"".concat(l," logo"),className:"h-5 w-5 mr-2"}),l]})})()})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:i(e.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:i(e.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsx)("span",{children:n(e.start_time,e.end_time)})]})]})]})}),(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Search Results"}),(0,m.jsx)("div",{className:"space-y-2",children:e.vector_store_search_response.data.map((e,l)=>{let t=a["".concat(s,"-").concat(l)]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center p-3 bg-gray-50 cursor-pointer",onClick:()=>o(s,l),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsxs)("span",{className:"font-medium mr-2",children:["Result ",l+1]}),(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["Score: ",(0,m.jsx)("span",{className:"font-mono",children:e.score.toFixed(4)})]})]})]}),t&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:e.content.map((e,s)=>(0,m.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,m.jsx)("div",{className:"text-xs text-gray-500 mb-1",children:e.type}),(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded",children:e.text})]},s))})]},l)})})]},s))})]})}function tN(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)(!0),[i,n]=(0,u.useState)({});if(!s)return null;let o=s.masked_entity_count?Object.values(s.masked_entity_count).reduce((e,s)=>e+s,0):0,d=e=>new Date(1e3*e).toLocaleString(),c=e=>{n(s=>({...s,[e]:!s[e]}))},h=e=>e>=.8?"text-green-600":"text-yellow-600";return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Guardrail Information"}),(0,m.jsx)("span",{className:"ml-3 px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status}),o>0&&(0,m.jsxs)("span",{className:"ml-3 px-2 py-1 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[o," masked ",1===o?"entity":"entities"]})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:[(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail Name:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_name})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Mode:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_mode})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:d(s.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:d(s.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsxs)("span",{children:[s.duration.toFixed(4),"s"]})]})]})]}),s.masked_entity_count&&Object.keys(s.masked_entity_count).length>0&&(0,m.jsxs)("div",{className:"mt-4 pt-4 border-t",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Masked Entity Summary"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(s.masked_entity_count).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-3 py-1.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[s,": ",l]},s)})})]})]}),s.guardrail_response&&s.guardrail_response.length>0&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 cursor-pointer",onClick:()=>r(!a),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(a?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("h4",{className:"font-medium",children:["Detected Entities (",s.guardrail_response.length,")"]})]}),a&&(0,m.jsx)("div",{className:"space-y-2",children:s.guardrail_response.map((e,s)=>{let l=i[s]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>c(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("span",{className:"font-medium mr-2",children:e.entity_type}),(0,m.jsxs)("span",{className:"font-mono ".concat(h(e.score)),children:["Score: ",e.score.toFixed(2)]})]}),(0,m.jsxs)("span",{className:"text-xs text-gray-500",children:["Position: ",e.start,"-",e.end]})]}),l&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Entity Type:"}),(0,m.jsx)("span",{children:e.entity_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Position:"}),(0,m.jsxs)("span",{children:["Characters ",e.start,"-",e.end]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Confidence:"}),(0,m.jsx)("span",{className:h(e.score),children:e.score.toFixed(2)})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[e.recognition_metadata&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Recognizer:"}),(0,m.jsx)("span",{children:e.recognition_metadata.recognizer_name})]}),(0,m.jsxs)("div",{className:"flex overflow-hidden",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Identifier:"}),(0,m.jsx)("span",{className:"truncate text-xs font-mono",children:e.recognition_metadata.recognizer_identifier})]})]}),e.analysis_explanation&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Explanation:"}),(0,m.jsx)("span",{children:e.analysis_explanation})]})]})]})})]},s)})})]})]})]})}let tw={TEAM_ID:"Team ID",KEY_HASH:"Key Hash",REQUEST_ID:"Request ID",MODEL:"Model",USER_ID:"User ID",STATUS:"Status",KEY_ALIAS:"Key Alias"};function tk(e){var s,l,t;let{accessToken:a,token:r,userRole:i,userID:n,allTeams:o}=e,[d,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(!1),[p,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(1),[v]=(0,u.useState)(50),y=(0,u.useRef)(null),Z=(0,u.useRef)(null),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(tm()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,C]=(0,u.useState)(tm()().format("YYYY-MM-DDTHH:mm")),[I,T]=(0,u.useState)(!1),[A,E]=(0,u.useState)(!1),[P,O]=(0,u.useState)(""),[L,D]=(0,u.useState)(""),[M,F]=(0,u.useState)(""),[R,q]=(0,u.useState)(""),[U,z]=(0,u.useState)(""),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)(null),[J,G]=(0,u.useState)(""),[W,Y]=(0,u.useState)(i&&eZ.lo.includes(i)),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(null),es=(0,g.NL)();(0,u.useEffect)(()=>{(async()=>{B&&a&&K({...(await (0,b.t0)(a,B)).info,token:B,api_key:B})})()},[B,a]),(0,u.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),Z.current&&!Z.current.contains(e.target)&&x(!1),N.current&&!N.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,u.useEffect)(()=>{i&&eZ.lo.includes(i)&&Y(!0)},[i]);let el=(0,eY.a)({queryKey:["logs","table",f,v,w,S,M,R,W?n:null,J,U],queryFn:async()=>{if(!a||!r||!i||!n)return{data:[],total:0,page:1,page_size:v,total_pages:0};let e=tm()(w).utc().format("YYYY-MM-DD HH:mm:ss"),s=I?tm()(S).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss"),l=await (0,b.h3)(a,R||void 0,M||void 0,void 0,e,s,f,v,W?n:void 0,J,U);return await tj(l.data,e,a,es),l.data=l.data.map(s=>{let l=es.getQueryData(["logDetails",s.request_id,e]);return(null==l?void 0:l.messages)&&(null==l?void 0:l.response)&&(s.messages=l.messages,s.response=l.response),s}),l},enabled:!!a&&!!r&&!!i&&!!n,refetchInterval:5e3,refetchIntervalInBackground:!0}),{filters:et,filteredLogs:ea,allTeams:er,allKeyAliases:ei,allModels:en,handleFilterChange:eo,handleFilterReset:ed}=function(e){let{logs:s,accessToken:l,startTime:t,endTime:a,pageSize:r=25,isCustomDate:i,setCurrentPage:n,userID:o,userRole:d}=e,c=(0,u.useMemo)(()=>({[tw.TEAM_ID]:"",[tw.KEY_HASH]:"",[tw.REQUEST_ID]:"",[tw.MODEL]:"",[tw.USER_ID]:"",[tw.STATUS]:"",[tw.KEY_ALIAS]:""}),[]),[m,h]=(0,u.useState)(c),[x,p]=(0,u.useState)(s),g=(0,u.useRef)(0),j=(0,u.useCallback)(async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!l)return;let n=Date.now();g.current=n;let o=tm()(t).utc().format("YYYY-MM-DD HH:mm:ss"),d=i?tm()(a).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss");try{let t=await (0,b.h3)(l,e[tw.KEY_HASH]||void 0,e[tw.TEAM_ID]||void 0,e[tw.REQUEST_ID]||void 0,o,d,s,r,e[tw.USER_ID]||void 0,e[tw.STATUS]||void 0,e[tw.MODEL]||void 0);n===g.current&&t.data&&p(t)}catch(e){console.error("Error searching users:",e)}},[l,t,a,i,r]),f=(0,u.useMemo)(()=>eb()((e,s)=>j(e,s),300),[j]);(0,u.useEffect)(()=>()=>f.cancel(),[f]);let _=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!l)throw Error("Access token required");return await e$(l)},enabled:!!l}).data||[];(0,u.useEffect)(()=>{if(!s||!s.data){p({data:[],total:0,page:1,page_size:50,total_pages:0});return}let e=[...s.data];if(m[tw.TEAM_ID]&&(e=e.filter(e=>e.team_id===m[tw.TEAM_ID])),m[tw.STATUS]&&(e=e.filter(e=>"success"===m[tw.STATUS]?!e.status||"success"===e.status:e.status===m[tw.STATUS])),m[tw.MODEL]&&(e=e.filter(e=>e.model===m[tw.MODEL])),m[tw.KEY_HASH]&&(e=e.filter(e=>e.api_key===m[tw.KEY_HASH])),m[tw.KEY_ALIAS])try{let s=m[tw.KEY_ALIAS];s&&(e=e.filter(e=>{var l;return(null===(l=e.metadata)||void 0===l?void 0:l.user_api_key_alias)===s}))}catch(e){console.error("Error fetching key info for alias:",e)}let l={data:e,total:s.total,page:s.page,page_size:s.page_size,total_pages:s.total_pages};JSON.stringify(l)!==JSON.stringify(x)&&p(l)},[s,m,x,l]);let{data:v}=(0,eY.a)({queryKey:["allTeamsForLogFilters",l],queryFn:async()=>l&&await eX(l)||[],enabled:!!l}),{data:y=[]}=(0,eY.a)({queryKey:["allModels",l,o,d],queryFn:async()=>l&&o&&d?(await (0,b.So)(l,o,d,!1,null)).data.map(e=>e.id):[],enabled:!!l&&!!o&&!!d});return{filters:m,filteredLogs:x,allKeyAliases:_,allTeams:v,allModels:y,handleFilterChange:e=>{h(s=>{let l={...s,...e};for(let e of Object.keys(c))e in l||(l[e]=c[e]);return JSON.stringify(l)!==JSON.stringify(s)&&(n(1),f(l,1)),l})},handleFilterReset:()=>{h(c),f(c,1)}}}({logs:el.data||{data:[],total:0,page:1,page_size:v||10,total_pages:1},accessToken:a,startTime:w,endTime:S,pageSize:v,isCustomDate:I,setCurrentPage:_,userID:n,userRole:i}),ec=(0,u.useCallback)(async e=>{if(a)try{let s=(await (0,b.OD)(a,null,null,e,null,null,f,v)).keys.find(s=>s.key_alias===e);s&&q(s.token)}catch(e){console.error("Error fetching key hash for alias:",e)}},[a,f,v]);(0,u.useEffect)(()=>{a&&(et["Team ID"]?F(et["Team ID"]):F(""),G(et.Status||""),z(et.Model||""),et["Key Hash"]?q(et["Key Hash"]):et["Key Alias"]?ec(et["Key Alias"]):q(""))},[et,a,ec]);let em=(0,eY.a)({queryKey:["sessionLogs",Q],queryFn:async()=>{if(!a||!Q)return{data:[],total:0,page:1,page_size:50,total_pages:1};let e=await (0,b.XB)(a,Q);return{data:e.data||e||[],total:(e.data||e||[]).length,page:1,page_size:1e3,total_pages:1}},enabled:!!a&&!!Q});if((0,u.useEffect)(()=>{var e;(null===(e=el.data)||void 0===e?void 0:e.data)&&$&&!el.data.data.some(e=>e.request_id===$)&&X(null)},[null===(s=el.data)||void 0===s?void 0:s.data,$]),!a||!r||!i||!n)return null;let eu=ea.data.filter(e=>!d||e.request_id.includes(d)||e.model.includes(d)||e.user&&e.user.includes(d)).map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{e&&ee(e)}}))||[],eh=(null===(t=em.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{}})))||[],ex=()=>{if(I)return"".concat(tm()(w).format("MMM D, h:mm A")," - ").concat(tm()(S).format("MMM D, h:mm A"));let e=tm()(),s=tm()(w),l=e.diff(s,"minutes");if(l<=15)return"Last 15 Minutes";if(l<=60)return"Last Hour";let t=e.diff(s,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(s.format("MMM D")," - ").concat(e.format("MMM D"))},ep=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>o&&0!==o.length?o.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Status",label:"Status",isSearchable:!1,options:[{label:"Success",value:"success"},{label:"Failure",value:"failure"}]},{name:"Model",label:"Model",isSearchable:!0,searchFn:async e=>en&&0!==en.length?en.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>a?(await e$(a)).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Hash",label:"Key Hash",isSearchable:!1}];return Q&&em.data?(0,m.jsx)("div",{className:"w-full p-6",children:(0,m.jsx)(tb,{sessionId:Q,logs:em.data.data,onBack:()=>ee(null)})}):(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:Q?(0,m.jsxs)(m.Fragment,{children:["Session: ",(0,m.jsx)("span",{className:"font-mono",children:Q}),(0,m.jsx)("button",{className:"ml-4 px-3 py-1 text-sm border rounded hover:bg-gray-50",onClick:()=>ee(null),children:"← Back to All Logs"})]}):"Request Logs"})}),V&&B&&V.api_key===B?(0,m.jsx)(eJ,{keyId:B,keyData:V,accessToken:a,userID:n,userRole:i,teams:o,onClose:()=>H(null)}):Q?(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsx)(tu,{columns:tg,data:eh,renderSubComponent:tS,getRowCanExpand:()=>!0})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eW,{options:ep,onApplyFilters:eo,onResetFilters:ed}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:d,onChange:e=>c(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsxs)("div",{className:"relative",ref:N,children:[(0,m.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),ex()]}),A&&(0,m.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,m.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(ex()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{C(tm()().format("YYYY-MM-DDTHH:mm")),k(tm()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),T(!1)},children:e.label},e.label)),(0,m.jsx)("div",{className:"border-t my-2"}),(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(I?"bg-blue-50 text-blue-600":""),onClick:()=>T(!I),children:"Custom Range"})]})})]}),(0,m.jsxs)("button",{onClick:()=>{el.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,m.jsx)("svg",{className:"w-4 h-4 ".concat(el.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,m.jsx)("span",{children:"Refresh"})]})]}),I&&(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:w,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,m.jsx)("span",{className:"text-gray-500",children:"to"}),(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{C(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",el.isLoading?"...":ea?(f-1)*v+1:0," ","-"," ",el.isLoading?"...":ea?Math.min(f*v,ea.total):0," ","of"," ",el.isLoading?"...":ea?ea.total:0," ","results"]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",el.isLoading?"...":f," of"," ",el.isLoading?"...":ea?ea.total_pages:1]}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:el.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.min(ea.total_pages||1,e+1)),disabled:el.isLoading||f===(ea.total_pages||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,m.jsx)(tu,{columns:tg,data:eu,renderSubComponent:tS,getRowCanExpand:()=>!0})]})]})]})}function tS(e){var s,l,t,a,r;let{row:i}=e,n=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},o=i.original.metadata||{},d="failure"===o.status,c=d?o.error_information:null,u=i.original.messages&&(Array.isArray(i.original.messages)?i.original.messages.length>0:Object.keys(i.original.messages).length>0),h=i.original.response&&Object.keys(n(i.original.response)).length>0,x=o.vector_store_request_metadata&&Array.isArray(o.vector_store_request_metadata)&&o.vector_store_request_metadata.length>0,p=i.original.metadata&&i.original.metadata.guardrail_information,g=p&&(null===(r=i.original.metadata)||void 0===r?void 0:r.guardrail_information.masked_entity_count)?Object.values(i.original.metadata.guardrail_information.masked_entity_count).reduce((e,s)=>e+("number"==typeof s?s:0),0):0;return(0,m.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,m.jsx)("span",{className:"font-mono text-sm",children:i.original.request_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,m.jsx)("span",{children:i.original.model})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model ID:"}),(0,m.jsx)("span",{children:i.original.model_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,m.jsx)("span",{children:i.original.call_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{children:i.original.custom_llm_provider||"-"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"API Base:"}),(0,m.jsx)(Y.Z,{title:i.original.api_base||"-",children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:i.original.api_base||"-"})})]}),(null==i?void 0:null===(s=i.original)||void 0===s?void 0:s.requester_ip_address)&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,m.jsx)("span",{children:null==i?void 0:null===(l=i.original)||void 0===l?void 0:l.requester_ip_address})]}),p&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail:"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-mono",children:i.original.metadata.guardrail_information.guardrail_name}),g>0&&(0,m.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[g," masked"]})]})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,m.jsxs)("span",{children:[i.original.total_tokens," (",i.original.prompt_tokens,"+",i.original.completion_tokens,")"]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,m.jsxs)("span",{children:["$",Number(i.original.spend||0).toFixed(6)]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,m.jsx)("span",{children:i.original.cache_hit})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(t=i.original.metadata)||void 0===t?void 0:t.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(a=i.original.metadata)||void 0===a?void 0:a.status)||"Success").toLowerCase()?"Success":"Failure"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:i.original.startTime})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:i.original.endTime})]})]})]})]}),(0,m.jsx)(tv,{show:!u&&!h}),(0,m.jsx)(tf,{row:i,hasMessages:u,hasResponse:h,hasError:d,errorInfo:c,getRawRequest:()=>{var e;return(null===(e=i.original)||void 0===e?void 0:e.proxy_server_request)?n(i.original.proxy_server_request):n(i.original.messages)},formattedResponse:()=>d&&c?{error:{message:c.error_message||"An error occurred",type:c.error_class||"error",code:c.error_code||"unknown",param:null}}:n(i.original.response)}),p&&(0,m.jsx)(tN,{data:i.original.metadata.guardrail_information}),x&&(0,m.jsx)(tZ,{data:o.vector_store_request_metadata}),d&&c&&(0,m.jsx)(t_,{errorInfo:c}),i.original.request_tags&&Object.keys(i.original.request_tags).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(i.original.request_tags).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[s,": ",String(l)]},s)})})})]}),i.original.metadata&&Object.keys(i.original.metadata).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(i.original.metadata,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(i.original.metadata,null,2)})})]})]})}var tC=l(92699),tI=l(14042);console.log=function(){};var tT=e=>{let{userID:s,userRole:l,accessToken:t,userSpend:a,userMaxBudget:r,selectedTeam:i}=e;console.log("userSpend: ".concat(a));let[n,o]=(0,u.useState)(null!==a?a:0),[d,c]=(0,u.useState)(i?i.max_budget:null);(0,u.useEffect)(()=>{if(i){if("Default Team"===i.team_alias)c(r);else{let e=!1;if(i.team_memberships)for(let l of i.team_memberships)l.user_id===s&&"max_budget"in l.litellm_budget_table&&null!==l.litellm_budget_table.max_budget&&(c(l.litellm_budget_table.max_budget),e=!0);e||c(i.max_budget)}}},[i,r]);let[h,x]=(0,u.useState)([]);(0,u.useEffect)(()=>{let e=async()=>{if(!t||!s||!l)return};(async()=>{try{if(null===s||null===l)return;if(null!==t){let e=(await (0,b.So)(t,s,l)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[l,t,s]),(0,u.useEffect)(()=>{null!==a&&o(a)},[a]);let p=[];i&&i.models&&(p=i.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=i.models:p&&0===p.length&&(p=h);let g=void 0!==n?n.toFixed(4):null;return console.log("spend in view user spend: ".concat(n)),(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,m.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==d?"$".concat(d," limit"):"No limit"})]})]})})};let tA=e=>{let{key:s,info:l}=e;return{token:s,...l}};var tE=e=>{let{topKeys:s,accessToken:l,userID:t,userRole:a,teams:r}=e,[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(void 0),[x,p]=(0,u.useState)("table"),g=async e=>{if(l)try{let s=await (0,b.t0)(l,e.api_key),t=tA(s);h(t),d(e.api_key),n(!0)}catch(e){console.error("Error fetching key info:",e)}},j=()=>{n(!1),d(null),h(void 0)};return u.useEffect(()=>{let e=e=>{"Escape"===e.key&&i&&j()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[i]),(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mb-4 flex justify-end items-center",children:(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>p("table"),className:"px-3 py-1 text-sm rounded-md ".concat("table"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Table View"}),(0,m.jsx)("button",{onClick:()=>p("chart"),className:"px-3 py-1 text-sm rounded-md ".concat("chart"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Chart View"})]})}),"chart"===x?(0,m.jsx)("div",{className:"relative",children:(0,m.jsx)(sT.Z,{className:"mt-4 h-40 cursor-pointer hover:opacity-90",data:s,index:"key_alias",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>e?"$".concat(e.toFixed(2)):"No Key Alias",onValueChange:e=>g(e),showTooltip:!0,customTooltip:e=>{var s,l,t;let a=null===(l=e.payload)||void 0===l?void 0:null===(s=l[0])||void 0===s?void 0:s.payload;return(0,m.jsx)("div",{className:"p-3 bg-black/90 shadow-lg rounded-lg text-white",children:(0,m.jsxs)("div",{className:"space-y-1.5",children:[(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Key: "}),(0,m.jsxs)("span",{className:"font-mono text-gray-100",children:[null==a?void 0:null===(t=a.api_key)||void 0===t?void 0:t.slice(0,10),"..."]})]}),(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Spend: "}),(0,m.jsxs)("span",{className:"text-white font-medium",children:["$",null==a?void 0:a.spend.toFixed(2)]})]})]})})}})}):(0,m.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,m.jsx)(tu,{columns:[{header:"Key ID",accessorKey:"api_key",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>g(e.row.original),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>e.getValue()||"-"},{header:"Spend (USD)",accessorKey:"spend",cell:e=>"$".concat(Number(e.getValue()).toFixed(2))}],data:s,renderSubComponent:()=>(0,m.jsx)(m.Fragment,{}),getRowCanExpand:()=>!1,isLoading:!1})}),i&&o&&c&&(console.log("Rendering modal with:",{isModalOpen:i,selectedKey:o,keyData:c}),(0,m.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&j()},children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-xl relative w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto min-h-[750px]",children:[(0,m.jsx)("button",{onClick:j,className:"absolute top-4 right-4 text-gray-500 hover:text-gray-700 focus:outline-none","aria-label":"Close",children:(0,m.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),(0,m.jsx)("div",{className:"p-6 h-full",children:(0,m.jsx)(eJ,{keyId:o,onClose:j,keyData:c,accessToken:l,userID:t,userRole:a,teams:r})})]})}))]})},tP=l(44851);let tO=e=>{var s,l;let{modelName:t,metrics:a}=e;return(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:a.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:a.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:a.total_tokens.toLocaleString()}),(0,m.jsxs)(P.Z,{children:[Math.round(a.total_tokens/a.total_successful_requests)," avg per successful request"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",a.total_spend.toFixed(2)]}),(0,m.jsxs)(P.Z,{children:["$",(a.total_spend/a.total_successful_requests).toFixed(3)," per successful request"]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Requests per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.api_requests"],colors:["blue"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.spend"],colors:["green"],valueFormatter:e=>"$".concat(e.toFixed(2))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Success vs Failed Requests"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Prompt Caching Metrics"}),(0,m.jsxs)("div",{className:"mb-2",children:[(0,m.jsxs)(P.Z,{children:["Cache Read: ",(null===(s=a.total_cache_read_input_tokens)||void 0===s?void 0:s.toLocaleString())||0," tokens"]}),(0,m.jsxs)(P.Z,{children:["Cache Creation: ",(null===(l=a.total_cache_creation_input_tokens)||void 0===l?void 0:l.toLocaleString())||0," tokens"]})]}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"],valueFormatter:e=>e.toLocaleString()})]})]})]})},tL=e=>{let{modelMetrics:s}=e,l=Object.keys(s).sort((e,l)=>""===e?1:""===l?-1:s[l].total_spend-s[e].total_spend),t={total_requests:0,total_successful_requests:0,total_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:{}};Object.values(s).forEach(e=>{t.total_requests+=e.total_requests,t.total_successful_requests+=e.total_successful_requests,t.total_tokens+=e.total_tokens,t.total_spend+=e.total_spend,t.total_cache_read_input_tokens+=e.total_cache_read_input_tokens||0,t.total_cache_creation_input_tokens+=e.total_cache_creation_input_tokens||0,e.daily_data.forEach(e=>{t.daily_data[e.date]||(t.daily_data[e.date]={prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,spend:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0}),t.daily_data[e.date].prompt_tokens+=e.metrics.prompt_tokens,t.daily_data[e.date].completion_tokens+=e.metrics.completion_tokens,t.daily_data[e.date].total_tokens+=e.metrics.total_tokens,t.daily_data[e.date].api_requests+=e.metrics.api_requests,t.daily_data[e.date].spend+=e.metrics.spend,t.daily_data[e.date].successful_requests+=e.metrics.successful_requests,t.daily_data[e.date].failed_requests+=e.metrics.failed_requests,t.daily_data[e.date].cache_read_input_tokens+=e.metrics.cache_read_input_tokens||0,t.daily_data[e.date].cache_creation_input_tokens+=e.metrics.cache_creation_input_tokens||0})});let a=Object.entries(t.daily_data).map(e=>{let[s,l]=e;return{date:s,metrics:l}}).sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime());return(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,m.jsx)(O.Z,{children:"Overall Usage"}),(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4 mb-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:t.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:t.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:t.total_tokens.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",t.total_spend.toFixed(2)]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]})]})]}),(0,m.jsx)(tP.Z,{defaultActiveKey:l[0],children:l.map(e=>(0,m.jsx)(tP.Z.Panel,{header:(0,m.jsxs)("div",{className:"flex justify-between items-center w-full",children:[(0,m.jsx)(O.Z,{children:s[e].label||"Unknown Item"}),(0,m.jsxs)("div",{className:"flex space-x-4 text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["$",s[e].total_spend.toFixed(2)]}),(0,m.jsxs)("span",{children:[s[e].total_requests.toLocaleString()," requests"]})]})]}),children:(0,m.jsx)(tO,{modelName:e||"Unknown Model",metrics:s[e]})},e))})]})},tD=(e,s)=>{let l=e.metadata.key_alias||"key-hash-".concat(s),t=e.metadata.team_id;return t?"".concat(l," (team_id: ").concat(t,")"):l},tM=(e,s)=>{let l={};return e.results.forEach(e=>{Object.entries(e.breakdown[s]||{}).forEach(t=>{let[a,r]=t;l[a]||(l[a]={label:"api_keys"===s?tD(r,a):a,total_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0,prompt_tokens:0,completion_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:[]}),l[a].total_requests+=r.metrics.api_requests,l[a].prompt_tokens+=r.metrics.prompt_tokens,l[a].completion_tokens+=r.metrics.completion_tokens,l[a].total_tokens+=r.metrics.total_tokens,l[a].total_spend+=r.metrics.spend,l[a].total_successful_requests+=r.metrics.successful_requests,l[a].total_failed_requests+=r.metrics.failed_requests,l[a].total_cache_read_input_tokens+=r.metrics.cache_read_input_tokens||0,l[a].total_cache_creation_input_tokens+=r.metrics.cache_creation_input_tokens||0,l[a].daily_data.push({date:e.date,metrics:{prompt_tokens:r.metrics.prompt_tokens,completion_tokens:r.metrics.completion_tokens,total_tokens:r.metrics.total_tokens,api_requests:r.metrics.api_requests,spend:r.metrics.spend,successful_requests:r.metrics.successful_requests,failed_requests:r.metrics.failed_requests,cache_read_input_tokens:r.metrics.cache_read_input_tokens||0,cache_creation_input_tokens:r.metrics.cache_creation_input_tokens||0}})})}),Object.values(l).forEach(e=>{e.daily_data.sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime())}),l};var tF=e=>{let{accessToken:s,entityType:l,entityId:t,userID:a,userRole:r,entityList:i}=e,[n,o]=(0,u.useState)({results:[],metadata:{total_spend:0,total_api_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0}}),d=tM(n,"models"),c=tM(n,"api_keys"),[h,x]=(0,u.useState)([]),[p,g]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),j=async()=>{if(!s||!p.from||!p.to)return;let e=p.from,t=p.to;if("tag"===l)o(await (0,b.Z9)(s,e,t,1,h.length>0?h:null));else if("team"===l)o(await (0,b.ol)(s,e,t,1,h.length>0?h:null));else throw Error("Invalid entity type")};(0,u.useEffect)(()=>{j()},[s,p,t,h]);let f=()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={provider:l,spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend,e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens}catch(e){console.log("Error processing provider ".concat(l,": ").concat(e))}})}),Object.values(e).filter(e=>e.spend>0).sort((e,s)=>s.spend-e.spend)},_=e=>0===h.length?e:e.filter(e=>h.includes(e.metadata.id)),v=()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.entities||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{alias:t.metadata.team_alias||l,id:l}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.total_tokens+=t.metrics.total_tokens})}),_(Object.values(e).sort((e,s)=>s.metrics.spend-e.metrics.spend))};return(0,m.jsxs)("div",{style:{width:"100%"},children:[(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:p,onValueChange:g})]}),i&&i.length>0&&(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(P.Z,{children:["Filter by ","tag"===l?"Tags":"Teams"]}),(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select ".concat("tag"===l?"tags":"teams"," to filter..."),value:h,onChange:x,options:(()=>{if(i)return i})(),className:"mt-2",allowClear:!0})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["tag"===l?"Tag":"Team"," Spend Overview"]}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Spend"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",n.metadata.total_spend.toFixed(2)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:n.metadata.total_api_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:n.metadata.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:n.metadata.total_failed_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:n.metadata.total_tokens.toLocaleString()})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...n.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let a=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:a.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Total Spend: $",a.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",a.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",a.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",a.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Tokens: ",a.metrics.total_tokens]}),(0,m.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,m.jsxs)("p",{className:"font-semibold",children:["Spend by ","tag"===l?"Tag":"Team",":"]}),Object.entries(a.breakdown.entities||{}).map(e=>{let[s,l]=e;return(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[l.metadata.team_alias||s,": $",l.metrics.spend.toFixed(2)]},s)})]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,m.jsxs)(O.Z,{children:["Spend Per ","tag"===l?"Tag":"Team"]}),(0,m.jsxs)("div",{className:"flex items-center text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["Get Started Tracking cost per ",l," "]}),(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tags",className:"text-blue-500 hover:text-blue-700 ml-1",children:"here"})]})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sT.Z,{className:"mt-4 h-52",data:v(),index:"metadata.alias",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(4)),layout:"vertical",showLegend:!1,yAxisWidth:100})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"tag"===l?"Tag":"Team"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:v().filter(e=>e.metrics.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.metadata.alias}),(0,m.jsxs)(e6.Z,{children:["$",e.metrics.spend.toFixed(4)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.metrics.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.metrics.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.metrics.total_tokens.toLocaleString()})]},e.metadata.id))})]})})]})]})})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:s,userID:a,userRole:r,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend}catch(e){console.log("Error adding spend for ".concat(l,": ").concat(e,", got metrics: ").concat(JSON.stringify(t)))}e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,...l}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)(O.Z,{children:"Provider Usage"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:f(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan","blue","indigo","violet","purple"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:f().map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:d})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:c})})]})]})]})},tR=e=>{var s,l,t,a,r,i,n,o,d,c;let{accessToken:h,userRole:x,userID:p,teams:g}=e,[j,f]=(0,u.useState)({results:[],metadata:{}}),[_,v]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),[y,Z]=(0,u.useState)([]),N=async()=>{h&&Z(Object.values(await (0,b.UM)(h)).map(e=>({label:e.name,value:e.name})))};(0,u.useEffect)(()=>{N()},[h]);let w=(null===(s=j.metadata)||void 0===s?void 0:s.total_spend)||0,C=()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{provider:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}})},I=async()=>{if(!h||!_.from||!_.to)return;let e=_.from,s=_.to;try{let l=await (0,b.xX)(h,e,s);if(l.metadata.total_pages>10)throw Error("Too many pages of data (>10). Please select a smaller date range.");if(1===l.metadata.total_pages){f(l);return}let t=[...l.results];for(let a=2;a<=l.metadata.total_pages;a++){let l=await (0,b.xX)(h,e,s,a);t.push(...l.results)}f({results:t,metadata:l.metadata})}catch(e){throw console.error("Error fetching user spend data:",e),e}};(0,u.useEffect)(()=>{I()},[h,_]);let T=tM(j,"models"),A=tM(j,"api_keys");return(0,m.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,m.jsxs)(P.Z,{className:"text-sm text-gray-500 mb-4",children:["This is the new usage dashboard. ",(0,m.jsx)("br",{})," You may see empty data, as these use ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/blob/6de348125208dd4be81ff0e5813753df2fbe9735/schema.prisma#L320",className:"text-blue-500 hover:text-blue-700 ml-1",children:"new aggregate tables"})," to allow UI to work at 1M+ spend logs. To access the old dashboard, go to Experimental ",">"," Old Usage."]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Global Usage"}):(0,m.jsx)(eM.Z,{children:"Your Usage"}),(0,m.jsx)(eM.Z,{children:"Team Usage"}),eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Tag Usage"}):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:_,onValueChange:e=>{v(e)}})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:p,userRole:x,accessToken:h,userSpend:w,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Usage Metrics"}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(t=j.metadata)||void 0===t?void 0:null===(l=t.total_api_requests)||void 0===l?void 0:l.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:(null===(r=j.metadata)||void 0===r?void 0:null===(a=r.total_successful_requests)||void 0===a?void 0:a.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:(null===(n=j.metadata)||void 0===n?void 0:null===(i=n.total_failed_requests)||void 0===i?void 0:i.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(d=j.metadata)||void 0===d?void 0:null===(o=d.total_tokens)||void 0===o?void 0:o.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Average Cost per Request"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",((w||0)/((null===(c=j.metadata)||void 0===c?void 0:c.total_api_requests)||1)).toFixed(4)]})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...j.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Requests: ",t.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",t.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",t.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.metrics.total_tokens]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:h,userID:p,userRole:x,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Top Models"})}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.key}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",t.requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-green-600",children:["Successful: ",t.successful_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-red-600",children:["Failed: ",t.failed_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.tokens.toLocaleString()]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Spend by Provider"})}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:C(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:C().filter(e=>e.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend<1e-5?"less than 0.00001":e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:T})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:A})})]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"team",userID:p,userRole:x,entityList:(null==g?void 0:g.map(e=>({label:e.team_alias,value:e.team_id})))||null})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"tag",userID:p,userRole:x,entityList:y})})]})]})]})},tq=e=>{let{proxySettings:s}=e,l="";return s&&s.PROXY_BASE_URL&&void 0!==s.PROXY_BASE_URL&&(l=s.PROXY_BASE_URL),(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(S.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,m.jsxs)("div",{className:"mb-5",children:[(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,m.jsx)(P.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"OpenAI Python SDK"}),(0,m.jsx)(eM.Z,{children:"LlamaIndex"}),(0,m.jsx)(eM.Z,{children:"Langchain Py"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(l,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(l,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(l,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(l,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},tU=l(243),tz=l(93837);async function tV(e,s,l,t,a,r,i,n,o,d,c,m){console.log=function(){},console.log("isLocal:",!1);let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t;let a=Date.now(),u=!1;for await(let h of(await x.chat.completions.create({model:l,stream:!0,stream_options:{include_usage:!0},litellm_trace_id:d,messages:e,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r}))){var p,g,j,f,_,v,y,b;console.log("Stream chunk:",h);let e=null===(p=h.choices[0])||void 0===p?void 0:p.delta;if(console.log("Delta content:",null===(j=h.choices[0])||void 0===j?void 0:null===(g=j.delta)||void 0===g?void 0:g.content),console.log("Delta reasoning content:",null==e?void 0:e.reasoning_content),!u&&((null===(_=h.choices[0])||void 0===_?void 0:null===(f=_.delta)||void 0===f?void 0:f.content)||e&&e.reasoning_content)&&(u=!0,t=Date.now()-a,console.log("First token received! Time:",t,"ms"),n?(console.log("Calling onTimingData with:",t),n(t)):console.log("onTimingData callback is not defined!")),null===(y=h.choices[0])||void 0===y?void 0:null===(v=y.delta)||void 0===v?void 0:v.content){let e=h.choices[0].delta.content;s(e,h.model)}if(e&&e.reasoning_content){let s=e.reasoning_content;i&&i(s)}if(h.usage&&o){console.log("Usage data found:",h.usage);let e={completionTokens:h.usage.completion_tokens,promptTokens:h.usage.prompt_tokens,totalTokens:h.usage.total_tokens};(null===(b=h.usage.completion_tokens_details)||void 0===b?void 0:b.reasoning_tokens)&&(e.reasoningTokens=h.usage.completion_tokens_details.reasoning_tokens),o(e)}}}catch(e){throw(null==r?void 0:r.aborted)&&console.log("Chat completion request was cancelled"),e}}async function tK(e,s,l,t,a,r){console.log=function(){},console.log("isLocal:",!1);let i=window.location.origin,n=new l6.ZP.OpenAI({apiKey:t,baseURL:i,dangerouslyAllowBrowser:!0,defaultHeaders:a&&a.length>0?{"x-litellm-tags":a.join(",")}:void 0});try{let t=await n.images.generate({model:l,prompt:e},{signal:r});if(console.log(t.data),t.data&&t.data[0]){if(t.data[0].url)s(t.data[0].url,l);else if(t.data[0].b64_json){let e=t.data[0].b64_json;s("data:image/png;base64,".concat(e),l)}else throw Error("No image data found in response")}else throw Error("Invalid response format")}catch(e){throw(null==r?void 0:r.aborted)?console.log("Image generation request was cancelled"):F.ZP.error("Error occurred while generating image. Please try again. Error: ".concat(e),20),e}}async function tB(e,s,l,t){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,i=arguments.length>6?arguments[6]:void 0,n=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,d=arguments.length>9?arguments[9]:void 0,c=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0;if(!t)throw Error("API key is required");console.log=function(){};let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t=Date.now(),a=!1,u=e.map(e=>({role:e.role,content:e.content,type:"message"}));for await(let e of(await x.responses.create({model:l,input:u,stream:!0,litellm_trace_id:d,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r})))if(console.log("Response event:",e),"object"==typeof e&&null!==e){if("response.role.delta"===e.type)continue;if("response.output_text.delta"===e.type&&"string"==typeof e.delta){let r=e.delta;if(console.log("Text delta",r),r.trim().length>0&&(s("assistant",r,l),!a)){a=!0;let e=Date.now()-t;console.log("First token received! Time:",e,"ms"),n&&n(e)}}if("response.reasoning.delta"===e.type&&"delta"in e){let s=e.delta;"string"==typeof s&&i&&i(s)}if("response.completed"===e.type&&"response"in e){let s=e.response.usage;if(console.log("Usage data:",s),s&&o){var p;console.log("Usage data:",s);let e={completionTokens:s.output_tokens,promptTokens:s.input_tokens,totalTokens:s.total_tokens};(null===(p=s.completion_tokens_details)||void 0===p?void 0:p.reasoning_tokens)&&(e.reasoningTokens=s.completion_tokens_details.reasoning_tokens),o(e)}}}}catch(e){throw(null==r?void 0:r.aborted)?console.log("Responses API request was cancelled"):F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20),e}}let tH=async e=>{try{let s=await (0,b.kn)(e);if(console.log("model_info:",s),(null==s?void 0:s.data.length)>0){let e=s.data.map(e=>({model_group:e.model_group,mode:null==e?void 0:e.mode}));return e.sort((e,s)=>e.model_group.localeCompare(s.model_group)),e}return[]}catch(e){throw console.error("Error fetching model info:",e),e}};(a=o||(o={})).IMAGE_GENERATION="image_generation",a.CHAT="chat",a.RESPONSES="responses",(r=d||(d={})).IMAGE="image",r.CHAT="chat",r.RESPONSES="responses";let tJ={image_generation:"image",chat:"chat",responses:"responses"},tG=e=>{if(console.log("getEndpointType:",e),Object.values(o).includes(e)){let s=tJ[e];return console.log("endpointType:",s),s}return"chat"};var tW=l(94263),tY=e=>{let{endpointType:s,onEndpointChange:l,className:t}=e,a=[{value:d.CHAT,label:"/v1/chat/completions"},{value:d.RESPONSES,label:"/v1/responses"},{value:d.IMAGE,label:"/v1/images/generations"}];return(0,m.jsxs)("div",{className:t,children:[(0,m.jsx)(P.Z,{children:"Endpoint Type:"}),(0,m.jsx)(D.default,{value:s,style:{width:"100%"},onChange:l,options:a,className:"rounded-md"})]})},t$=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a)try{let e=await (0,b.UM)(a);console.log("List tags response:",e),i(Object.values(e))}catch(e){console.error("Error fetching tags:",e)}})()},[]),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select tags",onChange:s,value:l,loading:n,className:t,options:r.map(e=>({label:e.name,value:e.name,title:e.description||e.name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})},tX=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.Ou)(a);e.data&&i(e.data)}catch(e){console.error("Error fetching vector stores:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select vector stores",onChange:s,value:l,loading:n,className:t,options:r.map(e=>({label:"".concat(e.vector_store_name||e.vector_store_id," (").concat(e.vector_store_id,")"),value:e.vector_store_id,title:e.vector_store_description||e.vector_store_id})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})},tQ=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.t3)(a);console.log("Guardrails response:",e),e.guardrails&&(console.log("Guardrails data:",e.guardrails),i(e.guardrails))}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select guardrails",onChange:e=>{console.log("Selected guardrails:",e),s(e)},value:l,loading:n,className:t,options:r.map(e=>(console.log("Mapping guardrail:",e),{label:"".concat(e.guardrail_name),value:e.guardrail_name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})};let t0=(e,s)=>{let l=s.find(s=>s.model_group===e);return(null==l?void 0:l.mode)?tG(l.mode):d.CHAT};var t1=l(83322),t2=l(70464),t4=l(77565),t5=e=>{let{reasoningContent:s}=e,[l,t]=(0,u.useState)(!0);return s?(0,m.jsxs)("div",{className:"reasoning-content mt-1 mb-2",children:[(0,m.jsxs)(U.ZP,{type:"text",className:"flex items-center text-xs text-gray-500 hover:text-gray-700",onClick:()=>t(!l),icon:(0,m.jsx)(t1.Z,{}),children:[l?"Hide reasoning":"Show reasoning",l?(0,m.jsx)(t2.Z,{className:"ml-1"}):(0,m.jsx)(t4.Z,{className:"ml-1"})]}),l&&(0,m.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md text-sm text-gray-700",children:(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,i=/language-(\w+)/.exec(t||"");return!l&&i?(0,m.jsx)(to.Z,{style:tW.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),...r,children:a})}},children:s})})]}):null},t3=l(5540),t6=l(71282),t8=l(11741),t7=l(16601),t9=e=>{let{timeToFirstToken:s,usage:l}=e;return s||l?(0,m.jsxs)("div",{className:"response-metrics mt-2 pt-2 border-t border-gray-100 text-xs text-gray-500 flex flex-wrap gap-3",children:[void 0!==s&&(0,m.jsx)(Y.Z,{title:"Time to first token",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t3.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:[(s/1e3).toFixed(2),"s"]})]})}),(null==l?void 0:l.promptTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Prompt tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t6.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["In: ",l.promptTokens]})]})}),(null==l?void 0:l.completionTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Completion tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t8.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Out: ",l.completionTokens]})]})}),(null==l?void 0:l.reasoningTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Reasoning tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t1.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Reasoning: ",l.reasoningTokens]})]})}),(null==l?void 0:l.totalTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Total tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t7.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Total: ",l.totalTokens]})]})})]}):null},ae=l(61935),as=l(69993),al=l(12660),at=l(71891),aa=l(44625),ar=l(57400),ai=l(26430),an=l(23907);let{TextArea:ao}=z.default;var ad=e=>{let{accessToken:s,token:l,userRole:t,userID:a,disabledPersonalKeyCreation:r}=e,[i,n]=(0,u.useState)(r?"custom":"session"),[o,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(""),[p,g]=(0,u.useState)([]),[j,f]=(0,u.useState)(void 0),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)([]),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(d.CHAT),[S,T]=(0,u.useState)(!1),A=(0,u.useRef)(null),[E,O]=(0,u.useState)([]),[L,M]=(0,u.useState)([]),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)(null),V=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e="session"===i?s:o;if(!e||!l||!t||!a){console.log("userApiKey or token or userRole or userID is missing = ",e,l,t,a);return}(async()=>{try{if(!e){console.log("userApiKey is missing");return}let s=await tH(e);if(console.log("Fetched models:",s),s.length>0&&(Z(s),f(s[0].model_group),s[0].mode)){let e=t0(s[0].model_group,s);k(e)}}catch(e){console.error("Error fetching model info:",e)}})()},[s,a,t,i,o]),(0,u.useEffect)(()=>{V.current&&setTimeout(()=>{var e;null===(e=V.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[p]);let K=(e,s,l)=>{console.log("updateTextUI called with:",e,s,l),g(t=>{let a=t[t.length-1];if(!a||a.role!==e||a.isImage)return[...t,{role:e,content:s,model:l}];{var r;let e={...a,content:a.content+s,model:null!==(r=a.model)&&void 0!==r?r:l};return[...t.slice(0,-1),e]}})},B=e=>{g(s=>{let l=s[s.length-1];return l&&"assistant"===l.role&&!l.isImage?[...s.slice(0,s.length-1),{...l,reasoningContent:(l.reasoningContent||"")+e}]:s.length>0&&"user"===s[s.length-1].role?[...s,{role:"assistant",content:"",reasoningContent:e}]:s})},H=e=>{console.log("updateTimingData called with:",e),g(s=>{let l=s[s.length-1];if(console.log("Current last message:",l),l&&"assistant"===l.role){console.log("Updating assistant message with timeToFirstToken:",e);let t=[...s.slice(0,s.length-1),{...l,timeToFirstToken:e}];return console.log("Updated chat history:",t),t}return l&&"user"===l.role?(console.log("Creating new assistant message with timeToFirstToken:",e),[...s,{role:"assistant",content:"",timeToFirstToken:e}]):(console.log("No appropriate message found to update timing"),s)})},J=e=>{console.log("Received usage data:",e),g(s=>{let l=s[s.length-1];if(l&&"assistant"===l.role){console.log("Updating message with usage data:",e);let t={...l,usage:e};return console.log("Updated message:",t),[...s.slice(0,s.length-1),t]}return s})},G=(e,s)=>{g(l=>[...l,{role:"assistant",content:e,model:s,isImage:!0}])},$=async()=>{if(""===h.trim()||!l||!t||!a)return;let e="session"===i?s:o;if(!e){F.ZP.error("Please provide an API key or select Current UI Session");return}A.current=new AbortController;let r=A.current.signal,n={role:"user",content:h},c=U||(0,tz.Z)();U||z(c),g([...p,n]),T(!0);try{if(j){if(w===d.CHAT){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),n];await tV(s,(e,s)=>K("assistant",e,s),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}else if(w===d.IMAGE)await tK(h,(e,s)=>G(e,s),j,e,E,r);else if(w===d.RESPONSES){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),n];await tB(s,(e,s,l)=>K(e,s,l),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}}}catch(e){r.aborted?console.log("Request was cancelled"):(console.error("Error fetching response",e),K("assistant","Error fetching response:"+e))}finally{T(!1),A.current=null}x("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to test models"})]})}let X=(0,m.jsx)(ae.Z,{style:{fontSize:24},spin:!0});return(0,m.jsx)("div",{className:"w-full h-screen p-4 bg-white",children:(0,m.jsx)(eD.Z,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,m.jsxs)("div",{className:"flex h-[80vh] w-full",children:[(0,m.jsx)("div",{className:"w-1/4 p-4 border-r border-gray-200 bg-gray-50",children:(0,m.jsx)("div",{className:"mb-6",children:(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(lR.Z,{className:"mr-2"})," API Key Source"]}),(0,m.jsx)(D.default,{disabled:r,defaultValue:"session",style:{width:"100%"},onChange:e=>n(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}],className:"rounded-md"}),"custom"===i&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:c,value:o,icon:lR.Z})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(as.Z,{className:"mr-2"})," Select Model"]}),(0,m.jsx)(D.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),"custom"!==e&&k(t0(e,b)),y("custom"===e)},options:[...Array.from(new Set(b.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%"},showSearch:!0,className:"rounded-md"}),v&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{f(e)},500)}})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(al.Z,{className:"mr-2"})," Endpoint Type"]}),(0,m.jsx)(tY,{endpointType:w,onEndpointChange:e=>{k(e)},className:"mb-4"})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(at.Z,{className:"mr-2"})," Tags"]}),(0,m.jsx)(t$,{value:E,onChange:O,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(aa.Z,{className:"mr-2"})," Vector Store",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select vector store(s) to use for this LLM API call. You can set up your vector store ",(0,m.jsx)("a",{href:"?page=vector-stores",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tX,{value:L,onChange:M,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(ar.Z,{className:"mr-2"})," Guardrails",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select guardrail(s) to use for this LLM API call. You can set up your guardrails ",(0,m.jsx)("a",{href:"?page=guardrails",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tQ,{value:R,onChange:q,className:"mb-4",accessToken:s||""})]}),(0,m.jsx)(C.Z,{onClick:()=>{g([]),z(null),F.ZP.success("Chat history cleared.")},className:"w-full bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300 mt-4",icon:ai.Z,children:"Clear Chat"})]})})}),(0,m.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,m.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===p.length&&(0,m.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,m.jsx)(as.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,m.jsx)(P.Z,{children:"Start a conversation or generate an image"})]}),p.map((e,s)=>(0,m.jsx)("div",{className:"mb-4 ".concat("user"===e.role?"text-right":"text-left"),children:(0,m.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"user"===e.role?"#f0f8ff":"#ffffff",border:"user"===e.role?"1px solid #e6f0fa":"1px solid #f0f0f0",textAlign:"left"},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"user"===e.role?"#e6f0fa":"#f5f5f5"},children:"user"===e.role?(0,m.jsx)(_.Z,{style:{fontSize:"12px",color:"#2563eb"}}):(0,m.jsx)(as.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,m.jsx)("strong",{className:"text-sm capitalize",children:e.role}),"assistant"===e.role&&e.model&&(0,m.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-normal",children:e.model})]}),e.reasoningContent&&(0,m.jsx)(t5,{reasoningContent:e.reasoningContent}),(0,m.jsxs)("div",{className:"whitespace-pre-wrap break-words max-w-full message-content",style:{wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",hyphens:"auto"},children:[e.isImage?(0,m.jsx)("img",{src:e.content,alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}}):(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,i=/language-(\w+)/.exec(t||"");return!l&&i?(0,m.jsx)(to.Z,{style:tW.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",wrapLines:!0,wrapLongLines:!0,...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),style:{wordBreak:"break-word"},...r,children:a})},pre:e=>{let{node:s,...l}=e;return(0,m.jsx)("pre",{style:{overflowX:"auto",maxWidth:"100%"},...l})}},children:e.content}),"assistant"===e.role&&(e.timeToFirstToken||e.usage)&&(0,m.jsx)(t9,{timeToFirstToken:e.timeToFirstToken,usage:e.usage})]})]})},s)),S&&(0,m.jsx)("div",{className:"flex justify-center items-center my-4",children:(0,m.jsx)(lb.Z,{indicator:X})}),(0,m.jsx)("div",{ref:V,style:{height:"1px"}})]}),(0,m.jsx)("div",{className:"p-4 border-t border-gray-200 bg-white",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ao,{value:h,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),$())},placeholder:w===d.CHAT||w===d.RESPONSES?"Type your message... (Shift+Enter for new line)":"Describe the image you want to generate...",disabled:S,className:"flex-1",autoSize:{minRows:1,maxRows:6},style:{resize:"none",paddingRight:"10px",paddingLeft:"10px"}}),S?(0,m.jsx)(C.Z,{onClick:()=>{A.current&&(A.current.abort(),A.current=null,T(!1),F.ZP.info("Request cancelled"))},className:"ml-2 bg-red-50 hover:bg-red-100 text-red-600 border-red-200",icon:ec.Z,children:"Cancel"}):(0,m.jsx)(C.Z,{onClick:$,className:"ml-2 text-white",icon:w===d.CHAT?an.Z:as.Z,children:w===d.CHAT?"Send":"Generate"})]})})]})]})})})},ac=l(19226),am=l(45937),au=l(28595),ah=l(68208),ax=l(9775),ap=l(41361),ag=l(37527),aj=l(88009),af=l(48231),a_=l(41169),av=l(58630),ay=l(55322);let{Sider:ab}=ac.default;var aZ=e=>{let{setPage:s,userRole:l,defaultSelectedKey:t}=e,a=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,m.jsx)(lR.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,m.jsx)(au.Z,{}),roles:eZ.LQ},{key:"2",page:"models",label:"Models",icon:(0,m.jsx)(ah.Z,{}),roles:eZ.LQ},{key:"12",page:"new_usage",label:"Usage",icon:(0,m.jsx)(ax.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"6",page:"teams",label:"Teams",icon:(0,m.jsx)(ap.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"5",page:"users",label:"Internal Users",icon:(0,m.jsx)(_.Z,{}),roles:eZ.ZL},{key:"14",page:"api_ref",label:"API Reference",icon:(0,m.jsx)(al.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,m.jsx)(aj.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,m.jsx)(af.Z,{})},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,m.jsx)(ar.Z,{}),roles:eZ.ZL},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,m.jsx)(a_.Z,{}),children:[{key:"9",page:"caching",label:"Caching",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"10",page:"budgets",label:"Budgets",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"20",page:"transform-request",label:"API Playground",icon:(0,m.jsx)(al.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"18",page:"mcp-tools",label:"MCP Tools",icon:(0,m.jsx)(av.Z,{}),roles:eZ.ZL},{key:"19",page:"tag-management",label:"Tag Management",icon:(0,m.jsx)(at.Z,{}),roles:eZ.ZL},{key:"21",page:"vector-stores",label:"Vector Stores",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"4",page:"usage",label:"Old Usage",icon:(0,m.jsx)(ax.Z,{})}]},{key:"settings",page:"settings",label:"Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,m.jsx)(al.Z,{}),roles:eZ.ZL},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL}]}],r=(e=>{let s=a.find(s=>s.page===e);if(s)return s.key;for(let s of a)if(s.children){let l=s.children.find(s=>s.page===e);if(l)return l.key}return"1"})(t),i=a.filter(e=>!!(!e.roles||e.roles.includes(l))&&(e.children&&(e.children=e.children.filter(e=>!e.roles||e.roles.includes(l))),!0));return(0,m.jsx)(ac.default,{style:{minHeight:"100vh"},children:(0,m.jsx)(ab,{theme:"light",width:220,children:(0,m.jsx)(am.Z,{mode:"inline",selectedKeys:[r],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var l;return{key:e.key,icon:e.icon,label:e.label,children:null===(l=e.children)||void 0===l?void 0:l.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}})),onClick:e.children?void 0:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}}})})})})},aN=l(96889);console.log("process.env.NODE_ENV","production"),console.log=function(){};let aw=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var ak=e=>{let{accessToken:s,token:l,userRole:t,userID:a,keys:r,premiumUser:i}=e,n=new Date,[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)([]),[Z,N]=(0,u.useState)([]),[w,I]=(0,u.useState)([]),[T,A]=(0,u.useState)([]),[E,L]=(0,u.useState)([]),[D,M]=(0,u.useState)({}),[F,R]=(0,u.useState)([]),[q,U]=(0,u.useState)(""),[z,V]=(0,u.useState)(["all-tags"]),[K,B]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(0),Y=new Date(n.getFullYear(),n.getMonth(),1),$=new Date(n.getFullYear(),n.getMonth()+1,0),X=er(Y),Q=er($);function ee(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",r),console.log("premium user in usage",i);let es=async()=>{if(s)try{let e=await (0,b.g)(s);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,u.useEffect)(()=>{ea(K.from,K.to)},[K,z]);let et=async(e,l,t)=>{if(!e||!l||!s)return;l.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,b.b1)(s,t,e.toISOString(),l.toISOString());console.log("End user data updated successfully",a),j(a)},ea=async(e,l)=>{if(!e||!l||!s)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(l.setHours(23,59,59,999),e.setHours(0,0,0,0),y((await (0,b.J$)(s,e.toISOString(),l.toISOString(),0===z.length?void 0:z)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let s=e.getFullYear(),l=e.getMonth()+1,t=e.getDate();return"".concat(s,"-").concat(l<10?"0"+l:l,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(X)),console.log("End date is ".concat(Q));let ei=async(e,s,l)=>{try{let l=await e();s(l)}catch(e){console.error(l,e)}},en=(e,s,l,t)=>{let a=[],r=new Date(s),i=e=>{if(e.includes("-"))return e;{let[s,l]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(s," 01 2024")).getMonth(),parseInt(l)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let s=i(e.date);return[s,{...e,date:s}]}));for(;r<=l;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let s={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{s[e]||(s[e]=0)}),a.push(s)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(s)try{let e=await (0,b.FC)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,s)=>e+(s.spend||0),0).toFixed(2));W(i),d(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>s&&l?(0,b.OU)(s,l,X,Q):Promise.reject("No access token or token"),L,"Error fetching provider spend"),ec=async()=>{s&&await ei(async()=>(await (0,b.tN)(s)).map(e=>({key:e.api_key.substring(0,10),api_key:e.api_key,key_alias:e.key_alias,spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{s&&await ei(async()=>(await (0,b.Au)(s)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{s&&await ei(async()=>{let e=await (0,b.mR)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0);return _(en(e.daily_spend,t,a,e.teams)),I(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},A,"Error fetching team spend")},eh=()=>{s&&ei(async()=>(await (0,b.X)(s)).tag_names,N,"Error fetching tag names")},ex=()=>{s&&ei(()=>{var e,l;return(0,b.J$)(s,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(l=K.to)||void 0===l?void 0:l.toISOString(),void 0)},e=>y(e.spend_per_tag),"Error fetching top tags")},ep=()=>{s&&ei(()=>(0,b.b1)(s,null,void 0,void 0),j,"Error fetching top end users")},eg=async()=>{if(s)try{let e=await (0,b.wd)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);M({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(s)try{let e=await (0,b.xA)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));R(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,u.useEffect)(()=>{(async()=>{if(s&&l&&t&&a){let e=await es();e&&(J(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),aw(t)&&(eu(),eh(),ex(),ep()))}})()},[s,l,t,a,X,Q]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Database Query Limit Reached"}),(0,m.jsxs)(P.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,m.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,m.jsx)(C.Z,{className:"mt-4",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mt-2",children:[(0,m.jsx)(eM.Z,{children:"All Up"}),aw(t)?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eM.Z,{children:"Team Based Usage"}),(0,m.jsx)(eM.Z,{children:"Customer Usage"}),(0,m.jsx)(eM.Z,{children:"Tag Based Usage"})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsx)("div",{})})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:a,userRole:t,accessToken:s,userSpend:G,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Monthly Spend"}),(0,m.jsx)(sT.Z,{data:o,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:c,accessToken:s,userID:a,userRole:t,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,m.jsx)(k.Z,{numColSpan:1}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Spend by Provider"}),(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",variant:"pie",data:E,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"})]})}),(0,m.jsx)(e3.Z,{children:E.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsx)(e6.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"All Up"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(D.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(D.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,m.jsx)(m.Fragment,{children:F.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.model}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(e.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:ee,onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(e.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:ee,onValueChange:e=>console.log(e)})]})]})]},s))})]})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Total Spend Per Team"}),(0,m.jsx)(aN.Z,{data:T})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend Per Team"}),(0,m.jsx)(sT.Z,{className:"h-72",data:f,showLegend:!0,index:"date",categories:w,yAxisWidth:80,stack:!0})]})]}),(0,m.jsx)(k.Z,{numColSpan:2})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Key"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==r?void 0:r.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},s):null)]})]})]}),(0,m.jsx)(eD.Z,{className:"mt-4",children:(0,m.jsxs)(e5.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Customer"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Total Events"})]})}),(0,m.jsx)(e3.Z,{children:null==g?void 0:g.map((e,s)=>{var l;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.end_user}),(0,m.jsx)(e6.Z,{children:null===(l=e.total_spend)||void 0===l?void 0:l.toFixed(4)}),(0,m.jsx)(e6.Z,{children:e.total_count})]},s)})})]})})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sS.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,m.jsx)(k.Z,{children:i?(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsx)(l4.Z,{value:String(e),children:e},e))]})}):(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsxs)(el.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend Per Tag"}),(0,m.jsxs)(P.Z,{children:["Get Started Tracking cost per tag ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,m.jsx)(sT.Z,{className:"h-72",data:v,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,m.jsx)(k.Z,{numColSpan:2})]})]})]})]})})},aS=l(51853);let aC=e=>{let{responseTimeMs:s}=e;return null==s?null:(0,m.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,m.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,m.jsxs)("span",{children:[s.toFixed(0),"ms"]})]})},aI=e=>{let s=e;if("string"==typeof s)try{s=JSON.parse(s)}catch(e){}return s},aT=e=>{let{label:s,value:l}=e,[t,a]=u.useState(!1),[r,i]=u.useState(!1),n=(null==l?void 0:l.toString())||"N/A",o=n.length>50?n.substring(0,50)+"...":n;return(0,m.jsx)("tr",{className:"hover:bg-gray-50",children:(0,m.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,m.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{className:"text-sm text-gray-600",children:s}),(0,m.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?n:o})]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,m.jsx)(aS.Z,{className:"h-4 w-4"})})]})})})},aA=e=>{var s,l,t,a,r,i,n,o,d,c,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=aI(j.litellm_params)||{},_=aI(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=aI(null==g?void 0:g.litellm_cache_params)||{},_=aI(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(n=_.connection_kwargs)||void 0===n?void 0:n.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(c=_.redis_client)||void 0===c?void 0:null===(d=c.connection_pool)||void 0===d?void 0:null===(o=d.connection_kwargs)||void 0===o?void 0:o.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,s,l,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"border-b border-gray-200 px-4",children:[(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsxs)(P.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,m.jsx)("table",{className:"w-full border-collapse",children:(0,m.jsxs)("tbody",{children:[j&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,m.jsx)(aT,{label:"Error Message",value:j.message}),(0,m.jsx)(aT,{label:"Traceback",value:j.traceback})]}),(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,m.jsx)(aT,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,m.jsx)(aT,{label:"Ping Response",value:String(g.ping_response)}),(0,m.jsx)(aT,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,m.jsx)(aT,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,m.jsx)(aT,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,m.jsx)(aT,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,m.jsx)(aT,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,m.jsx)(aT,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,m.jsx)(aT,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,m.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},s=JSON.parse(JSON.stringify(e,(e,s)=>{if("string"==typeof s)try{return JSON.parse(s)}catch(e){}return s}));return JSON.stringify(s,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},aE=e=>{let{accessToken:s,healthCheckResponse:l,runCachingHealthCheck:t,responseTimeMs:a}=e,[r,i]=u.useState(null),[n,o]=u.useState(!1),d=async()=>{o(!0);let e=performance.now();await t(),i(performance.now()-e),o(!1)};return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsx)(C.Z,{onClick:d,disabled:n,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:n?"Running Health Check...":"Run Health Check"}),(0,m.jsx)(aC,{responseTimeMs:r})]}),l&&(0,m.jsx)(aA,{response:l})]})},aP=e=>{if(e)return e.toISOString().split("T")[0]};function aO(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var aL=e=>{let{accessToken:s,token:l,userRole:t,userID:a,premiumUser:r}=e,[i,n]=(0,u.useState)([]),[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)("0"),[f,_]=(0,u.useState)("0"),[v,y]=(0,u.useState)("0"),[Z,N]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[w,C]=(0,u.useState)(""),[I,T]=(0,u.useState)("");(0,u.useEffect)(()=>{s&&Z&&((async()=>{p(await (0,b.zg)(s,aP(Z.from),aP(Z.to)))})(),C(new Date().toLocaleString()))},[s]);let A=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.api_key)&&void 0!==s?s:""}))),E=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.model)&&void 0!==s?s:""})));Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.call_type)&&void 0!==s?s:""})));let O=async(e,l)=>{e&&l&&s&&(l.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,b.zg)(s,aP(e),aP(l))))};(0,u.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;o.length>0&&(e=e.filter(e=>o.includes(e.api_key))),c.length>0&&(e=e.filter(e=>c.includes(e.model))),console.log("before processed data in cache dashboard",e);let s=0,l=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),s+=(a.total_rows||0)-(a.cache_hit_true_rows||0),l+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);j(aO(l)),_(aO(t));let r=l+s;r>0?y((l/r*100).toFixed(2)):y("0"),n(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[o,c,Z,x]);let L=async()=>{try{F.ZP.info("Running cache health check..."),T("");let e=await (0,b.Tj)(null!==s?s:"");console.log("CACHING HEALTH CHECK RESPONSE",e),T(e)}catch(s){let e;if(console.error("Error running health check:",s),s&&s.message)try{let l=JSON.parse(s.message);l.error&&(l=l.error),e=l}catch(l){e={message:s.message}}else e={message:"Unknown error occurred"};T({error:e})}};return(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Cache Analytics"}),(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"Cache Health"})})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[w&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",w]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{C(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(S.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select API Keys",value:o,onValueChange:d,children:A.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select Models",value:c,onValueChange:h,children:E.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(sS.Z,{enableSelect:!0,value:Z,onValueChange:e=>{N(e),O(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[v,"%"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:f})})]})]}),(0,m.jsx)(sn.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,m.jsx)(sT.Z,{title:"Cache Hits vs API Requests",data:i,stack:!0,index:"name",valueFormatter:aO,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,m.jsx)(sn.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,m.jsx)(sT.Z,{className:"mt-6",data:i,stack:!0,index:"name",valueFormatter:aO,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(aE,{accessToken:s,healthCheckResponse:I,runCachingHealthCheck:L})})]})]})},aD=l(22452),aM=l(91810),aF=l(3810);(i=c||(c={})).PresidioPII="Presidio PII",i.Bedrock="Bedrock Guardrail",i.Lakera="Lakera";let aR={PresidioPII:"presidio",Bedrock:"bedrock",Lakera:"lakera_v2"},aq=e=>!!e&&"Presidio PII"===c[e],aU="../ui/assets/logos/",az={"Presidio PII":"".concat(aU,"presidio.png"),"Bedrock Guardrail":"".concat(aU,"bedrock.svg"),Lakera:"".concat(aU,"lakeraai.jpeg")},aV=e=>{if(!e)return{logo:"",displayName:"-"};let s=Object.keys(aR).find(s=>aR[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=c[s];return{logo:az[l],displayName:l}};var aK=l(33866),aB=l(97416),aH=l(8881),aJ=l(10798),aG=l(49638);let{Text:aW}=et.default,{Option:aY}=D.default,a$=e=>e.replace(/_/g," "),aX=e=>{switch(e){case"MASK":return(0,m.jsx)(aB.Z,{style:{marginRight:4}});case"BLOCK":return(0,m.jsx)(aH.Z,{style:{marginRight:4}});default:return null}},aQ=e=>{let{categories:s,selectedCategories:l,onChange:t}=e;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)(aJ.Z,{className:"text-gray-500 mr-1"}),(0,m.jsx)(aW,{className:"text-gray-500 font-medium",children:"Filter by category"})]}),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select categories to filter by",style:{width:"100%"},onChange:t,value:l,allowClear:!0,showSearch:!0,optionFilterProp:"children",className:"mb-4",tagRender:e=>(0,m.jsx)(aF.Z,{color:"blue",closable:e.closable,onClose:e.onClose,className:"mr-2 mb-2",children:e.label}),children:s.map(e=>(0,m.jsx)(aY,{value:e.category,children:e.category},e.category))})]})},a0=e=>{let{onSelectAll:s,onUnselectAll:l,hasSelectedEntities:t}=e;return(0,m.jsxs)("div",{className:"bg-gray-50 p-5 rounded-lg mb-6 border border-gray-200 shadow-sm",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(aW,{strong:!0,className:"text-gray-700 text-base",children:"Quick Actions"}),(0,m.jsx)(Y.Z,{title:"Apply action to all PII types at once",children:(0,m.jsx)("div",{className:"ml-2 text-gray-400 cursor-help text-xs",children:"ⓘ"})})]}),(0,m.jsx)(U.ZP,{type:"default",onClick:l,disabled:!t,icon:(0,m.jsx)(aG.Z,{}),className:"border-gray-300 hover:text-red-600 hover:border-red-300",children:"Unselect All"})]}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("MASK"),className:"flex items-center justify-center h-10 border-blue-200 hover:border-blue-300 hover:text-blue-700 bg-blue-50 hover:bg-blue-100 text-blue-600",block:!0,icon:(0,m.jsx)(aB.Z,{}),children:"Select All & Mask"}),(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("BLOCK"),className:"flex items-center justify-center h-10 border-red-200 hover:border-red-300 hover:text-red-700 bg-red-50 hover:bg-red-100 text-red-600",block:!0,icon:(0,m.jsx)(aH.Z,{}),children:"Select All & Block"})]})]})},a1=e=>{let{entities:s,selectedEntities:l,selectedActions:t,actions:a,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:n}=e;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden shadow-sm",children:[(0,m.jsxs)("div",{className:"bg-gray-50 px-5 py-3 border-b flex",children:[(0,m.jsx)(aW,{strong:!0,className:"flex-1 text-gray-700",children:"PII Type"}),(0,m.jsx)(aW,{strong:!0,className:"w-32 text-right text-gray-700",children:"Action"})]}),(0,m.jsx)("div",{className:"max-h-[400px] overflow-y-auto",children:0===s.length?(0,m.jsx)("div",{className:"py-10 text-center text-gray-500",children:"No PII types match your filter criteria"}):s.map(e=>(0,m.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between hover:bg-gray-50 border-b ".concat(l.includes(e)?"bg-blue-50":""),children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)(sL.Z,{checked:l.includes(e),onChange:()=>r(e),className:"mr-3"}),(0,m.jsx)(aW,{className:l.includes(e)?"font-medium text-gray-900":"text-gray-700",children:a$(e)}),n.get(e)&&(0,m.jsx)(aF.Z,{className:"ml-2 text-xs",color:"blue",children:n.get(e)})]}),(0,m.jsx)("div",{className:"w-32",children:(0,m.jsx)(D.default,{value:l.includes(e)&&t[e]||"MASK",onChange:s=>i(e,s),style:{width:120},disabled:!l.includes(e),className:"".concat(l.includes(e)?"":"opacity-50"),dropdownMatchSelectWidth:!1,children:a.map(e=>(0,m.jsx)(aY,{value:e,children:(0,m.jsxs)("div",{className:"flex items-center",children:[aX(e),e]})},e))})})]},e))})]})},{Title:a2,Text:a4}=et.default;var a5=e=>{let{entities:s,actions:l,selectedEntities:t,selectedActions:a,onEntitySelect:r,onActionSelect:i,entityCategories:n=[]}=e,[o,d]=(0,u.useState)([]),c=new Map;n.forEach(e=>{e.entities.forEach(s=>{c.set(s,e.category)})});let h=s.filter(e=>0===o.length||o.includes(c.get(e)||""));return(0,m.jsxs)("div",{className:"pii-configuration",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-5",children:[(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsx)(a2,{level:4,className:"mb-0 font-semibold text-gray-800",children:"Configure PII Protection"})}),(0,m.jsx)(aK.Z,{count:t.length,showZero:!0,style:{backgroundColor:t.length>0?"#4f46e5":"#d9d9d9"},overflowCount:999,children:(0,m.jsxs)(a4,{className:"text-gray-500",children:[t.length," items selected"]})})]}),(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsx)(aQ,{categories:n,selectedCategories:o,onChange:d}),(0,m.jsx)(a0,{onSelectAll:e=>{s.forEach(s=>{t.includes(s)||r(s),i(s,e)})},onUnselectAll:()=>{t.forEach(e=>{r(e)})},hasSelectedEntities:t.length>0})]}),(0,m.jsx)(a1,{entities:h,selectedEntities:t,selectedActions:a,actions:l,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:c})]})},a3=e=>{var s;let{selectedProvider:l,accessToken:t,providerParams:a=null}=e,[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(a),[d,c]=(0,u.useState)(null);if((0,u.useEffect)(()=>{if(a){o(a);return}let e=async()=>{if(t){i(!0),c(null);try{let e=await (0,b.eW)(t);console.log("Provider params API response:",e),o(e)}catch(e){console.error("Error fetching provider params:",e),c("Failed to load provider parameters")}finally{i(!1)}}};a||e()},[t,a]),!l)return null;if(r)return(0,m.jsx)(lb.Z,{tip:"Loading provider parameters..."});if(d)return(0,m.jsx)("div",{className:"text-red-500",children:d});let h=null===(s=aR[l])||void 0===s?void 0:s.toLowerCase(),x=n&&n[h];return(console.log("Provider key:",h),console.log("Provider fields:",x),x&&0!==x.length)?(0,m.jsx)(m.Fragment,{children:x.map(e=>(0,m.jsx)(M.Z.Item,{name:e.param,label:e.param,tooltip:e.description,rules:e.required?[{required:!0,message:"".concat(e.param," is required")}]:void 0,children:"select"===e.type&&e.options?(0,m.jsx)(D.default,{placeholder:e.description,defaultValue:e.default_value,children:e.options.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"bool"===e.type?(0,m.jsxs)(D.default,{placeholder:e.description,defaultValue:e.default_value,children:[(0,m.jsx)(D.default.Option,{value:"True",children:"True"}),(0,m.jsx)(D.default.Option,{value:"False",children:"False"})]}):e.param.includes("password")||e.param.includes("secret")?(0,m.jsx)(I.Z,{placeholder:e.description,type:"password"}):(0,m.jsx)(I.Z,{placeholder:e.description,type:"text"})},e.param))}):(0,m.jsx)("div",{children:"No configuration fields available for this provider."})};let{Title:a6,Text:a8,Link:a7}=et.default,{Option:a9}=D.default,{Step:re}=aM.default,rs={pre_call:"Before LLM Call - Runs before the LLM call and checks the input (Recommended)",during_call:"During LLM Call - Runs in parallel with the LLM call, with response held until check completes",post_call:"After LLM Call - Runs after the LLM call and checks only the output",logging_only:"Logging Only - Only runs on logging callbacks without affecting the LLM call"};var rl=e=>{let{visible:s,onClose:l,accessToken:t,onSuccess:a}=e,[r]=M.Z.useForm(),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)([]),[j,f]=(0,u.useState)({}),[_,v]=(0,u.useState)(0),[y,Z]=(0,u.useState)(null);(0,u.useEffect)(()=>{t&&(async()=>{try{let[e,s]=await Promise.all([(0,b.qd)(t),(0,b.eW)(t)]);x(e),Z(s)}catch(e){console.error("Error fetching guardrail data:",e),F.ZP.error("Failed to load guardrail configuration")}})()},[t]);let N=e=>{d(e),r.setFieldsValue({config:void 0,presidio_analyzer_api_base:void 0,presidio_anonymizer_api_base:void 0}),g([]),f({})},w=e=>{g(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},k=(e,s)=>{f(l=>({...l,[e]:s}))},S=async()=>{try{if(0===_&&(await r.validateFields(["guardrail_name","provider","mode","default_on"]),o)){let e=["guardrail_name","provider","mode","default_on"];"PresidioPII"===o&&e.push("presidio_analyzer_api_base","presidio_anonymizer_api_base"),await r.validateFields(e)}v(_+1)}catch(e){console.error("Form validation failed:",e)}},T=()=>{r.resetFields(),d(null),g([]),f({}),v(0)},A=()=>{T(),l()},E=async()=>{try{n(!0),await r.validateFields();let s=r.getFieldsValue(!0),i=aR[s.provider],d={guardrail_name:s.guardrail_name,litellm_params:{guardrail:i,mode:s.mode,default_on:s.default_on},guardrail_info:{}};if("PresidioPII"===s.provider&&p.length>0){let e={};p.forEach(s=>{e[s]=j[s]||"MASK"}),d.litellm_params.pii_entities_config=e,s.presidio_analyzer_api_base&&(d.litellm_params.presidio_analyzer_api_base=s.presidio_analyzer_api_base),s.presidio_anonymizer_api_base&&(d.litellm_params.presidio_anonymizer_api_base=s.presidio_anonymizer_api_base)}else if(s.config)try{let e=JSON.parse(s.config);d.guardrail_info=e}catch(e){F.ZP.error("Invalid JSON in configuration"),n(!1);return}if(y&&o){var e;let l=y[null===(e=aR[o])||void 0===e?void 0:e.toLowerCase()]||[];new Set(l.map(e=>e.param)).forEach(e=>{let l=s[e];null!=l&&""!==l&&(d.litellm_params[e]=l)})}if(!t)throw Error("No access token available");console.log("Sending guardrail data:",JSON.stringify(d)),await (0,b.PC)(t,d),F.ZP.success("Guardrail created successfully"),T(),a(),l()}catch(e){console.error("Failed to create guardrail:",e),F.ZP.error("Failed to create guardrail: "+(e instanceof Error?e.message:String(e)))}finally{n(!1)}},P=()=>{var e;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:N,labelInValue:!1,optionLabelProp:"label",dropdownRender:e=>e,showSearch:!0,children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(a9,{value:s,label:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[az[l]&&(0,m.jsx)("img",{src:az[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]}),children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[az[l]&&(0,m.jsx)("img",{src:az[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{optionLabelProp:"label",mode:"multiple",children:(null==h?void 0:null===(e=h.supported_modes)||void 0===e?void 0:e.map(e=>(0,m.jsx)(a9,{value:e,label:e,children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("strong",{children:e}),"pre_call"===e&&(0,m.jsx)(aF.Z,{color:"green",style:{marginLeft:"8px"},children:"Recommended"})]}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs[e]})]})},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(a9,{value:"pre_call",label:"pre_call",children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("strong",{children:"pre_call"})," ",(0,m.jsx)(aF.Z,{color:"green",children:"Recommended"})]}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.pre_call})]})}),(0,m.jsx)(a9,{value:"during_call",label:"during_call",children:(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{children:(0,m.jsx)("strong",{children:"during_call"})}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.during_call})]})}),(0,m.jsx)(a9,{value:"post_call",label:"post_call",children:(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{children:(0,m.jsx)("strong",{children:"post_call"})}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.post_call})]})}),(0,m.jsx)(a9,{value:"logging_only",label:"logging_only",children:(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{children:(0,m.jsx)("strong",{children:"logging_only"})}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.logging_only})]})})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default.",children:(0,m.jsxs)(D.default,{children:[(0,m.jsx)(D.default.Option,{value:!0,children:"Yes"}),(0,m.jsx)(D.default.Option,{value:!1,children:"No"})]})}),(0,m.jsx)(a3,{selectedProvider:o,accessToken:t,providerParams:y})]})},O=()=>h&&"PresidioPII"===o?(0,m.jsx)(a5,{entities:h.supported_entities,actions:h.supported_actions,selectedEntities:p,selectedActions:j,onEntitySelect:w,onActionSelect:k,entityCategories:h.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Add Guardrail",open:s,onCancel:A,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:r,layout:"vertical",initialValues:{mode:"pre_call",default_on:!1},children:[(0,m.jsxs)(aM.default,{current:_,className:"mb-6",children:[(0,m.jsx)(re,{title:"Basic Info"}),(0,m.jsx)(re,{title:"PresidioPII"===o?"PII Configuration":"Provider Configuration"})]}),(()=>{switch(_){case 0:return P();case 1:if(aq(o))return O();default:return null}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[_>0&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{v(_-1)},children:"Previous"}),_<1&&(0,m.jsx)(C.Z,{onClick:S,children:"Next"}),1===_&&(0,m.jsx)(C.Z,{onClick:E,loading:i,children:"Create Guardrail"}),(0,m.jsx)(C.Z,{variant:"secondary",onClick:A,children:"Cancel"})]})]})})};let{Title:rt,Text:ra}=et.default,{Option:rr}=D.default;var ri=e=>{var s;let{visible:l,onClose:t,accessToken:a,onSuccess:r,guardrailId:i,initialValues:n}=e,[o]=M.Z.useForm(),[d,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)((null==n?void 0:n.provider)||null),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)({});(0,u.useEffect)(()=>{(async()=>{try{if(!a)return;let e=await (0,b.qd)(a);j(e)}catch(e){console.error("Error fetching guardrail settings:",e),F.ZP.error("Failed to load guardrail settings")}})()},[a]),(0,u.useEffect)(()=>{(null==n?void 0:n.pii_entities_config)&&Object.keys(n.pii_entities_config).length>0&&(_(Object.keys(n.pii_entities_config)),y(n.pii_entities_config))},[n]);let Z=e=>{_(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},N=(e,s)=>{y(l=>({...l,[e]:s}))},w=async()=>{try{h(!0);let e=await o.validateFields(),s=aR[e.provider],l={guardrail_id:i,guardrail:{guardrail_name:e.guardrail_name,litellm_params:{guardrail:s,mode:e.mode,default_on:e.default_on},guardrail_info:{}}};if("PresidioPII"===e.provider&&f.length>0){let e={};f.forEach(s=>{e[s]=v[s]||"MASK"}),l.guardrail.litellm_params.pii_entities_config=e}else if(e.config)try{let s=JSON.parse(e.config);"Bedrock"===e.provider&&s?(s.guardrail_id&&(l.guardrail.litellm_params.guardrailIdentifier=s.guardrail_id),s.guardrail_version&&(l.guardrail.litellm_params.guardrailVersion=s.guardrail_version)):l.guardrail.guardrail_info=s}catch(e){F.ZP.error("Invalid JSON in configuration"),h(!1);return}if(!a)throw Error("No access token available");console.log("Sending guardrail update data:",JSON.stringify(l));let n=await fetch("/guardrails/".concat(i),{method:"PUT",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify(l)});if(!n.ok){let e=await n.text();throw Error(e||"Failed to update guardrail")}F.ZP.success("Guardrail updated successfully"),r(),t()}catch(e){console.error("Failed to update guardrail:",e),F.ZP.error("Failed to update guardrail: "+(e instanceof Error?e.message:String(e)))}finally{h(!1)}},k=()=>g&&x&&"PresidioPII"===x?(0,m.jsx)(a5,{entities:g.supported_entities,actions:g.supported_actions,selectedEntities:f,selectedActions:v,onEntitySelect:Z,onActionSelect:N,entityCategories:g.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Edit Guardrail",open:l,onCancel:t,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:o,layout:"vertical",initialValues:n,children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:e=>{p(e),o.setFieldsValue({config:void 0}),_([]),y({})},disabled:!0,optionLabelProp:"label",children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(rr,{value:s,label:l,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[az[l]&&(0,m.jsx)("img",{src:az[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{children:(null==g?void 0:null===(s=g.supported_modes)||void 0===s?void 0:s.map(e=>(0,m.jsx)(rr,{value:e,children:e},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(rr,{value:"pre_call",children:"pre_call"}),(0,m.jsx)(rr,{value:"post_call",children:"post_call"})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,m.jsx)(sY.Z,{})}),(()=>{if(!x)return null;if("PresidioPII"===x)return k();switch(x){case"Aporia":return(0,m.jsx)(M.Z.Item,{label:"Aporia Configuration",name:"config",tooltip:"JSON configuration for Aporia",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aporia_api_key",\n "project_name": "your_project_name"\n}'})});case"AimSecurity":return(0,m.jsx)(M.Z.Item,{label:"Aim Security Configuration",name:"config",tooltip:"JSON configuration for Aim Security",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aim_api_key"\n}'})});case"Bedrock":return(0,m.jsx)(M.Z.Item,{label:"Amazon Bedrock Configuration",name:"config",tooltip:"JSON configuration for Amazon Bedrock guardrails",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "guardrail_id": "your_guardrail_id",\n "guardrail_version": "your_guardrail_version"\n}'})});case"GuardrailsAI":return(0,m.jsx)(M.Z.Item,{label:"Guardrails.ai Configuration",name:"config",tooltip:"JSON configuration for Guardrails.ai",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_guardrails_api_key",\n "guardrail_id": "your_guardrail_id"\n}'})});case"LakeraAI":return(0,m.jsx)(M.Z.Item,{label:"Lakera AI Configuration",name:"config",tooltip:"JSON configuration for Lakera AI",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_lakera_api_key"\n}'})});case"PromptInjection":return(0,m.jsx)(M.Z.Item,{label:"Prompt Injection Configuration",name:"config",tooltip:"JSON configuration for prompt injection detection",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "threshold": 0.8\n}'})});default:return(0,m.jsx)(M.Z.Item,{label:"Custom Configuration",name:"config",tooltip:"JSON configuration for your custom guardrail",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "key1": "value1",\n "key2": "value2"\n}'})})}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:t,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:w,loading:d,children:"Update Guardrail"})]})]})})},rn=e=>{var s,l,t,a,r,i,n,o,d;let{guardrailId:c,onClose:h,accessToken:x,isAdmin:p}=e,[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(!0),[v,y]=(0,u.useState)(!1),[Z]=M.Z.useForm(),[N,w]=(0,u.useState)([]),[k,T]=(0,u.useState)({}),[A,E]=(0,u.useState)(null),L=async()=>{try{var e;if(_(!0),!x)return;let s=await (0,b.fk)(x,c);if(j(s),null===(e=s.litellm_params)||void 0===e?void 0:e.pii_entities_config){let e=s.litellm_params.pii_entities_config;if(w([]),T({}),Object.keys(e).length>0){let s=[],l={};Object.entries(e).forEach(e=>{let[t,a]=e;s.push(t),l[t]="string"==typeof a?a:"MASK"}),w(s),T(l)}}else w([]),T({})}catch(e){F.ZP.error("Failed to load guardrail information"),console.error("Error fetching guardrail info:",e)}finally{_(!1)}},R=async()=>{try{if(!x)return;let e=await (0,b.qd)(x);E(e)}catch(e){console.error("Error fetching guardrail UI settings:",e)}};(0,u.useEffect)(()=>{L(),R()},[c,x]);let q=async e=>{try{if(!x)return;let s={guardrail_name:e.guardrail_name,litellm_params:{default_on:e.default_on},guardrail_info:e.guardrail_info?JSON.parse(e.guardrail_info):void 0};if(N.length>0){let e={};N.forEach(s=>{e[s]=k[s]||"MASK"}),s.litellm_params.pii_entities_config=e}else s.litellm_params.pii_entities_config={};await (0,b.Ko)(x,c,s),F.ZP.success("Guardrail updated successfully"),L(),y(!1)}catch(e){console.error("Error updating guardrail:",e),F.ZP.error("Failed to update guardrail")}};if(f)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!g)return(0,m.jsx)("div",{className:"p-4",children:"Guardrail not found"});let V=e=>e?new Date(e).toLocaleString():"-",{logo:K,displayName:B}=aV((null===(s=g.litellm_params)||void 0===s?void 0:s.guardrail)||"");return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:h,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:g.guardrail_name||"Unnamed Guardrail"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:g.guardrail_id})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),p?(0,m.jsx)(eM.Z,{children:"Settings"},"settings"):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[K&&(0,m.jsx)("img",{src:K,alt:"".concat(B," logo"),className:"w-6 h-6",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(O.Z,{children:B})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Mode"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:(null===(l=g.litellm_params)||void 0===l?void 0:l.mode)||"-"}),(0,m.jsx)(eL.Z,{color:(null===(t=g.litellm_params)||void 0===t?void 0:t.default_on)?"green":"gray",children:(null===(a=g.litellm_params)||void 0===a?void 0:a.default_on)?"Default On":"Default Off"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Created At"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:V(g.created_at)}),(0,m.jsxs)(P.Z,{children:["Last Updated: ",V(g.updated_at)]})]})]})]}),(null===(r=g.litellm_params)||void 0===r?void 0:r.pii_entities_config)&&Object.keys(g.litellm_params.pii_entities_config).length>0&&(0,m.jsx)(eD.Z,{className:"mt-6",children:(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"PII Protection"}),(0,m.jsxs)(eL.Z,{color:"blue",children:[Object.keys(g.litellm_params.pii_entities_config).length," PII entities configured"]})]})}),g.guardrail_info&&Object.keys(g.guardrail_info).length>0&&(0,m.jsxs)(eD.Z,{className:"mt-6",children:[(0,m.jsx)(P.Z,{children:"Guardrail Info"}),(0,m.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(g.guardrail_info).map(e=>{let[s,l]=e;return(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(P.Z,{className:"font-medium w-1/3",children:s}),(0,m.jsx)(P.Z,{className:"w-2/3",children:"object"==typeof l?JSON.stringify(l,null,2):String(l)})]},s)})})]})]}),p&&(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Guardrail Settings"}),!v&&(0,m.jsx)(C.Z,{onClick:()=>y(!0),children:"Edit Settings"})]}),v?(0,m.jsxs)(M.Z,{form:Z,onFinish:q,initialValues:{guardrail_name:g.guardrail_name,...g.litellm_params,guardrail_info:g.guardrail_info?JSON.stringify(g.guardrail_info,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Guardrail Name",name:"guardrail_name",rules:[{required:!0,message:"Please input a guardrail name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Default On",name:"default_on",children:(0,m.jsxs)(D.default,{children:[(0,m.jsx)(D.default.Option,{value:!0,children:"Yes"}),(0,m.jsx)(D.default.Option,{value:!1,children:"No"})]})}),(0,m.jsx)(le.Z,{orientation:"left",children:"PII Protection"}),(0,m.jsx)("div",{className:"mb-6",children:A&&(0,m.jsx)(a5,{entities:A.supported_entities,actions:A.supported_actions,selectedEntities:N,selectedActions:k,onEntitySelect:e=>{w(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},onActionSelect:(e,s)=>{T(l=>({...l,[e]:s}))},entityCategories:A.pii_entity_categories})}),(0,m.jsx)(le.Z,{orientation:"left",children:"Advanced Settings"}),(0,m.jsx)(M.Z.Item,{label:"Guardrail Information",name:"guardrail_info",children:(0,m.jsx)(z.default.TextArea,{rows:5})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>y(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail ID"}),(0,m.jsx)("div",{className:"font-mono",children:g.guardrail_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail Name"}),(0,m.jsx)("div",{children:g.guardrail_name||"Unnamed Guardrail"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Provider"}),(0,m.jsx)("div",{children:B})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Mode"}),(0,m.jsx)("div",{children:(null===(i=g.litellm_params)||void 0===i?void 0:i.mode)||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Default On"}),(0,m.jsx)(eL.Z,{color:(null===(n=g.litellm_params)||void 0===n?void 0:n.default_on)?"green":"gray",children:(null===(o=g.litellm_params)||void 0===o?void 0:o.default_on)?"Yes":"No"})]}),(null===(d=g.litellm_params)||void 0===d?void 0:d.pii_entities_config)&&Object.keys(g.litellm_params.pii_entities_config).length>0&&(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"PII Protection"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(eL.Z,{color:"blue",children:[Object.keys(g.litellm_params.pii_entities_config).length," PII entities configured"]})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:V(g.created_at)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)("div",{children:V(g.updated_at)})]})]})]})})]})]})]})},ro=e=>{let{guardrailsList:s,isLoading:l,onDeleteClick:t,accessToken:a,onGuardrailUpdated:r,isAdmin:i=!1,onShowGuardrailInfo:n}=e,[o,d]=(0,u.useState)([{id:"created_at",desc:!0}]),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(null),v=e=>e?new Date(e).toLocaleString():"-",y=e=>{_(e),j(!0),null==n||n(!0)},b=[{header:"Guardrail ID",accessorKey:"guardrail_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>e.getValue()&&y(e.getValue()),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Name",accessorKey:"guardrail_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.guardrail_name,children:(0,m.jsx)("span",{className:"text-xs font-medium",children:l.guardrail_name||"-"})})}},{header:"Provider",accessorKey:"litellm_params.guardrail",cell:e=>{let{row:s}=e,{logo:l,displayName:t}=aV(s.original.litellm_params.guardrail);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:l,alt:"".concat(t," logo"),className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)("span",{className:"text-xs",children:t})]})}},{header:"Mode",accessorKey:"litellm_params.mode",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.litellm_params.mode})}},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.created_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.updated_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.updated_at)})})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l.guardrail_id&&t(l.guardrail_id,l.guardrail_name||"Unnamed Guardrail"),className:"cursor-pointer hover:text-red-500",tooltip:"Delete guardrail"})})}}],Z=(0,e2.b7)({data:s,columns:b,state:{sorting:o},onSortingChange:d,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return g&&f?(0,m.jsx)(rn,{guardrailId:f,onClose:()=>{j(!1),_(null),null==n||n(!1)},accessToken:a,isAdmin:i}):(0,m.jsxs)("div",{className:"rounded-lg custom-border relative",children:[(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:Z.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:l?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"Loading..."})})})}):s.length>0?Z.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No guardrails found"})})})})})]})}),x&&(0,m.jsx)(ri,{visible:c,onClose:()=>h(!1),accessToken:a,onSuccess:()=>{h(!1),p(null),r()},guardrailId:x.guardrail_id||"",initialValues:{guardrail_name:x.guardrail_name||"",provider:Object.keys(aR).find(e=>aR[e]===(null==x?void 0:x.litellm_params.guardrail))||"",mode:x.litellm_params.mode,default_on:x.litellm_params.default_on,pii_entities_config:x.litellm_params.pii_entities_config,...x.guardrail_info}})]})},rd=e=>{let{accessToken:s,userRole:l}=e,[t,a]=(0,u.useState)([]),[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),j=!!l&&(0,eZ.tY)(l),f=async()=>{if(s){o(!0);try{let e=await (0,b.t3)(s);console.log("guardrails: ".concat(JSON.stringify(e))),a(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}};(0,u.useEffect)(()=>{f()},[s]);let _=async()=>{if(h&&s){c(!0);try{await (0,b.Yi)(s,h.id),F.ZP.success('Guardrail "'.concat(h.name,'" deleted successfully')),f()}catch(e){console.error("Error deleting guardrail:",e),F.ZP.error("Failed to delete guardrail")}finally{c(!1),x(null)}}};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[!p&&(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(C.Z,{icon:aD.Z,onClick:()=>{i(!0)},disabled:!s,children:"Add Guardrail"})}),(0,m.jsx)(ro,{guardrailsList:t,isLoading:n,onDeleteClick:(e,s)=>{x({id:e,name:s})},accessToken:s,onGuardrailUpdated:f,isAdmin:j,onShowGuardrailInfo:g}),(0,m.jsx)(rl,{visible:r,onClose:()=>{i(!1)},accessToken:s,onSuccess:()=>{f()}}),h&&(0,m.jsxs)(R.Z,{title:"Delete Guardrail",open:null!==h,onOk:_,onCancel:()=>{x(null)},confirmLoading:d,okText:"Delete",okButtonProps:{danger:!0},children:[(0,m.jsxs)("p",{children:["Are you sure you want to delete guardrail: ",h.name," ?"]}),(0,m.jsx)("p",{children:"This action cannot be undone."})]})]})},rc=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)('{\n "model": "openai/gpt-4o",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n },\n {\n "role": "user",\n "content": "Explain quantum computing in simple terms"\n }\n ],\n "temperature": 0.7,\n "max_tokens": 500,\n "stream": true\n}'),[a,r]=(0,u.useState)(""),[i,n]=(0,u.useState)(!1),o=(e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")},d=async()=>{n(!0);try{let e;try{e=JSON.parse(l)}catch(e){F.ZP.error("Invalid JSON in request body"),n(!1);return}let t={call_type:"completion",request_body:e};if(!s){F.ZP.error("No access token found"),n(!1);return}let a=await (0,b.Yo)(s,t);if(a.raw_request_api_base&&a.raw_request_body){let e=o(a.raw_request_api_base,a.raw_request_body,a.raw_request_headers||{});r(e),F.ZP.success("Request transformed successfully")}else{let e="string"==typeof a?a:JSON.stringify(a);r(e),F.ZP.info("Transformed request received in unexpected format")}}catch(e){console.error("Error transforming request:",e),F.ZP.error("Failed to transform request")}finally{n(!1)}};return(0,m.jsxs)("div",{className:"w-full m-2",style:{overflow:"hidden"},children:[(0,m.jsx)(O.Z,{children:"Playground"}),(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"See how LiteLLM transforms your request for the specified provider."}),(0,m.jsxs)("div",{style:{display:"flex",gap:"16px",width:"100%",minWidth:0,overflow:"hidden"},className:"mt-4",children:[(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"600px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Original Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"The request you would send to LiteLLM /chat/completions endpoint."})]}),(0,m.jsx)("textarea",{style:{flex:"1 1 auto",width:"100%",minHeight:"240px",padding:"16px",border:"1px solid #e8e8e8",borderRadius:"6px",fontFamily:"monospace",fontSize:"14px",resize:"none",marginBottom:"24px",overflow:"auto"},value:l,onChange:e=>t(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),d())},placeholder:"Press Cmd/Ctrl + Enter to transform"}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:(0,m.jsxs)(U.ZP,{type:"primary",style:{backgroundColor:"#000",display:"flex",alignItems:"center",gap:"8px"},onClick:d,loading:i,children:[(0,m.jsx)("span",{children:"Transform"}),(0,m.jsx)("span",{children:"→"})]})})]}),(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"800px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Transformed Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"How LiteLLM transforms your request for the specified provider."}),(0,m.jsx)("br",{}),(0,m.jsx)("p",{style:{color:"#666",margin:0},className:"text-xs",children:"Note: Sensitive headers are not shown."})]}),(0,m.jsxs)("div",{style:{position:"relative",backgroundColor:"#f5f5f5",borderRadius:"6px",flex:"1 1 auto",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,m.jsx)("pre",{style:{padding:"16px",fontFamily:"monospace",fontSize:"14px",margin:0,overflow:"auto",flex:"1 1 auto"},children:a||'curl -X POST \\\n https://api.openai.com/v1/chat/completions \\\n -H \'Authorization: Bearer sk-xxx\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{\n "model": "gpt-4",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n }\n ],\n "temperature": 0.7\n }\''}),(0,m.jsx)(U.ZP,{type:"text",icon:(0,m.jsx)(ls.Z,{}),style:{position:"absolute",right:"8px",top:"8px"},size:"small",onClick:()=>{navigator.clipboard.writeText(a||""),F.ZP.success("Copied to clipboard")}})]})]})]}),(0,m.jsx)("div",{className:"mt-4 text-right w-full",children:(0,m.jsxs)("p",{className:"text-sm text-gray-500",children:["Found an error? File an issue ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/issues",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})]})},rm=l(21770);let ru=[{accessorKey:"mcp_info.server_name",header:"Provider",cell:e=>{let{row:s}=e,l=s.original.mcp_info.server_name,t=s.original.mcp_info.logo_url;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:"".concat(l," logo"),className:"h-5 w-5 object-contain"}),(0,m.jsx)("span",{className:"font-medium",children:l})]})}},{accessorKey:"name",header:"Tool Name",cell:e=>{let{row:s}=e,l=s.getValue("name");return(0,m.jsx)("div",{children:(0,m.jsx)("span",{className:"font-mono text-sm",children:l})})}},{accessorKey:"description",header:"Description",cell:e=>{let{row:s}=e,l=s.getValue("description");return(0,m.jsx)("div",{className:"max-w-md",children:(0,m.jsx)("span",{className:"text-sm text-gray-700",children:l})})}},{id:"actions",header:"Actions",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex items-center space-x-2",children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{"function"==typeof s.original.onToolSelect&&s.original.onToolSelect(l)},children:"Test Tool"})})}}];function rh(e){let{tool:s,onSubmit:l,isLoading:t,result:a,error:r,onClose:i}=e,[n,o]=u.useState({}),d=u.useMemo(()=>"string"==typeof s.inputSchema?{type:"object",properties:{input:{type:"string",description:"Input for this tool"}},required:["input"]}:s.inputSchema,[s.inputSchema]),c=(e,s)=>{o(l=>({...l,[e]:s}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-lg border p-6 max-w-4xl w-full",children:[(0,m.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("h2",{className:"text-xl font-bold",children:["Test Tool: ",(0,m.jsx)("span",{className:"font-mono",children:s.name})]}),(0,m.jsx)("p",{className:"text-gray-600",children:s.description}),(0,m.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:["Provider: ",s.mcp_info.server_name]})]}),(0,m.jsx)("button",{onClick:i,className:"p-1 rounded-full hover:bg-gray-200",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,m.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Input Parameters"}),(0,m.jsxs)("form",{onSubmit:e=>{e.preventDefault(),l(n)},children:["string"==typeof s.inputSchema?(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"This tool uses a dynamic input schema."}),(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Input ",(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,m.jsx)("input",{type:"text",value:n.input||"",onChange:e=>c("input",e.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"})]})]}):Object.entries(d.properties).map(e=>{var s,l,t;let[a,r]=e;return(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[a," ",(null===(s=d.required)||void 0===s?void 0:s.includes(a))&&(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),r.description&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:r.description}),"string"===r.type&&(0,m.jsx)("input",{type:"text",value:n[a]||"",onChange:e=>c(a,e.target.value),required:null===(l=d.required)||void 0===l?void 0:l.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"number"===r.type&&(0,m.jsx)("input",{type:"number",value:n[a]||"",onChange:e=>c(a,parseFloat(e.target.value)),required:null===(t=d.required)||void 0===t?void 0:t.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"boolean"===r.type&&(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("input",{type:"checkbox",checked:n[a]||!1,onChange:e=>c(a,e.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),(0,m.jsx)("span",{className:"ml-2 text-sm text-gray-600",children:"Enable"})]})]},a)}),(0,m.jsx)("div",{className:"mt-6",children:(0,m.jsx)(C.Z,{type:"submit",disabled:t,className:"w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white",children:t?"Calling...":"Call Tool"})})]})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg overflow-auto max-h-[500px]",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Result"}),t&&(0,m.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,m.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-700"})}),r&&(0,m.jsxs)("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-md",children:[(0,m.jsx)("p",{className:"font-medium",children:"Error"}),(0,m.jsx)("pre",{className:"mt-2 text-xs overflow-auto whitespace-pre-wrap",children:r.message})]}),a&&!t&&!r&&(0,m.jsxs)("div",{children:[a.map((e,s)=>(0,m.jsxs)("div",{className:"mb-4",children:["text"===e.type&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("p",{className:"whitespace-pre-wrap text-sm",children:e.text})}),"image"===e.type&&e.url&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("img",{src:e.url,alt:"Tool result",className:"max-w-full h-auto rounded"})}),"embedded_resource"===e.type&&(0,m.jsxs)("div",{className:"bg-white border p-3 rounded-md",children:[(0,m.jsx)("p",{className:"text-sm font-medium",children:"Embedded Resource"}),(0,m.jsxs)("p",{className:"text-xs text-gray-500",children:["Type: ",e.resource_type]}),e.url&&(0,m.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"View Resource"})]})]},s)),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)("details",{className:"text-xs",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-gray-500 hover:text-gray-700",children:"Raw JSON Response"}),(0,m.jsx)("pre",{className:"mt-2 bg-gray-100 p-2 rounded-md overflow-auto max-h-[300px]",children:JSON.stringify(a,null,2)})]})})]}),!a&&!t&&!r&&(0,m.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,m.jsx)("p",{children:"The result will appear here after you call the tool."})})]})]})]})}function rx(e){let{columns:s,data:l,isLoading:t}=e;return(0,m.jsx)(tu,{columns:s,data:l,isLoading:t,renderSubComponent:()=>(0,m.jsx)("div",{}),getRowCanExpand:()=>!1,loadingMessage:"\uD83D\uDE85 Loading tools...",noDataMessage:"No tools found"})}function rp(e){let{accessToken:s,userRole:l,userID:t}=e,[a,r]=(0,u.useState)(""),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),{data:x,isLoading:p}=(0,eY.a)({queryKey:["mcpTools"],queryFn:()=>{if(!s)throw Error("Access Token required");return(0,b.lU)(s)},enabled:!!s}),{mutate:g,isPending:j}=(0,rm.D)({mutationFn:e=>{if(!s)throw Error("Access Token required");return(0,b.tB)(s,e.tool.name,e.arguments)},onSuccess:e=>{d(e),h(null)},onError:e=>{h(e),d(null)}}),f=u.useMemo(()=>x?x.map(e=>({...e,onToolSelect:e=>{n(e),d(null),h(null)}})):[],[x]),_=u.useMemo(()=>f.filter(e=>{let s=a.toLowerCase();return e.name.toLowerCase().includes(s)||e.description.toLowerCase().includes(s)||e.mcp_info.server_name.toLowerCase().includes(s)}),[f,a]);return s&&l&&t?(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"MCP Tools"})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search tools...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:a,onChange:e=>r(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"text-sm text-gray-500",children:[_.length," tool",1!==_.length?"s":""," available"]})]})}),(0,m.jsx)(rx,{columns:ru,data:_,isLoading:p})]}),i&&(0,m.jsx)("div",{className:"fixed inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center z-50 p-4",children:(0,m.jsx)(rh,{tool:i,onSubmit:e=>{i&&g({tool:i,arguments:e})},isLoading:j,result:o,error:c,onClose:()=>n(null)})})]}):(0,m.jsx)("div",{className:"p-6 text-center text-gray-500",children:"Missing required authentication parameters."})}var rg=e=>{let{tagId:s,onClose:l,accessToken:t,is_admin:a,editTag:r}=e,[i]=M.Z.useForm(),[n,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(r),[h,x]=(0,u.useState)([]),p=async()=>{if(t)try{let e=(await (0,b.mC)(t,[s]))[s];e&&(o(e),r&&i.setFieldsValue({name:e.name,description:e.description,models:e.models}))}catch(e){console.error("Error fetching tag details:",e),F.ZP.error("Error fetching tag details: "+e)}};(0,u.useEffect)(()=>{p()},[s,t]),(0,u.useEffect)(()=>{t&&eT("dummy-user","Admin",t,x)},[t]);let g=async e=>{if(t)try{await (0,b.n9)(t,{name:e.name,description:e.description,models:e.models}),F.ZP.success("Tag updated successfully"),c(!1),p()}catch(e){console.error("Error updating tag:",e),F.ZP.error("Error updating tag: "+e)}};return n?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{onClick:l,className:"mb-4",children:"← Back to Tags"}),(0,m.jsxs)(O.Z,{children:["Tag Name: ",n.name]}),(0,m.jsx)(P.Z,{className:"text-gray-500",children:n.description||"No description"})]}),a&&!d&&(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Tag"})]}),d?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(M.Z,{form:i,onFinish:g,layout:"vertical",initialValues:n,children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(z.default,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed LLMs"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process this type of data",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:h.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{onClick:()=>c(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}):(0,m.jsx)("div",{className:"space-y-6",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Tag Details"}),(0,m.jsxs)("div",{className:"space-y-4 mt-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Name"}),(0,m.jsx)(P.Z,{children:n.name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Description"}),(0,m.jsx)(P.Z,{children:n.description||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Allowed LLMs"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:0===n.models.length?(0,m.jsx)(eL.Z,{color:"red",children:"All Models"}):n.models.map(e=>{var s;return(0,m.jsx)(eL.Z,{color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(null===(s=n.model_info)||void 0===s?void 0:s[e])||e})},e)})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:n.created_at?new Date(n.created_at).toLocaleString():"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:n.updated_at?new Date(n.updated_at).toLocaleString():"-"})]})]})]})})]}):(0,m.jsx)("div",{children:"Loading..."})},rj=e=>{let{data:s,onEdit:l,onDelete:t,onSelectTag:a}=e,[r,i]=u.useState([{id:"created_at",desc:!0}]),n=[{header:"Tag Name",accessorKey:"name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.name,children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5",onClick:()=>a(l.name),children:l.name})})})}},{header:"Description",accessorKey:"description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.description,children:(0,m.jsx)("span",{className:"text-xs",children:l.description||"-"})})}},{header:"Allowed LLMs",accessorKey:"models",cell:e=>{var s,l;let{row:t}=e,a=t.original;return(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:(null==a?void 0:null===(s=a.models)||void 0===s?void 0:s.length)===0?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Models"}):null==a?void 0:null===(l=a.models)||void 0===l?void 0:l.map(e=>{var s;return(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(0,m.jsx)(P.Z,{children:(null===(s=a.model_info)||void 0===s?void 0:s[e])||e})})},e)})})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,a=s.original;return(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>l(a),className:"cursor-pointer"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(a.name),className:"cursor-pointer"})]})}}],o=(0,e2.b7)({data:s,columns:n,state:{sorting:r},onSortingChange:i,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:n.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No tags found"})})})})})]})})})},rf=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v]=M.Z.useForm(),[y,Z]=(0,u.useState)([]),N=async()=>{if(s)try{let e=await (0,b.UM)(s);console.log("List tags response:",e),r(Object.values(e))}catch(e){console.error("Error fetching tags:",e),F.ZP.error("Error fetching tags: "+e)}},w=async e=>{if(s)try{await (0,b.mY)(s,{name:e.tag_name,description:e.description,models:e.allowed_llms}),F.ZP.success("Tag created successfully"),n(!1),v.resetFields(),N()}catch(e){console.error("Error creating tag:",e),F.ZP.error("Error creating tag: "+e)}},T=async e=>{j(e),p(!0)},A=async()=>{if(s&&g){try{await (0,b.fE)(s,g),F.ZP.success("Tag deleted successfully"),N()}catch(e){console.error("Error deleting tag:",e),F.ZP.error("Error deleting tag: "+e)}p(!1),j(null)}};return(0,u.useEffect)(()=>{l&&t&&s&&(async()=>{try{let e=await (0,b.AZ)(s,l,t);e&&e.data&&Z(e.data)}catch(e){console.error("Error fetching models:",e),F.ZP.error("Error fetching models: "+e)}})()},[s,l,t]),(0,u.useEffect)(()=>{N()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:o?(0,m.jsx)(rg,{tagId:o,onClose:()=>{d(null),h(!1)},accessToken:s,is_admin:"Admin"===t,editTag:c}):(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Tag Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{N(),_(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(P.Z,{className:"mb-4",children:["Click on a tag name to view and edit its details.",(0,m.jsxs)("p",{children:["You can use tags to restrict the usage of certain LLMs based on tags passed in the request. Read more about tag routing ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tag_routing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})]}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Create New Tag"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(rj,{data:a,onEdit:e=>{d(e.name),h(!0)},onDelete:T,onSelectTag:d})})}),(0,m.jsx)(R.Z,{title:"Create New Tag",visible:i,width:800,footer:null,onCancel:()=>{n(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"tag_name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed Models"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process requests from this tag",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_llms",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:y.map(e=>(0,m.jsx)(D.default.Option,{value:e.model_info.id,children:(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{children:e.model_name}),(0,m.jsxs)("span",{className:"text-gray-400 ml-2",children:["(",e.model_info.id,")"]})]})},e.model_info.id))})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Tag"})})]})}),x&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Tag"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this tag?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:A,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{p(!1),j(null)},children:"Cancel"})]})]})]})})]})})},r_=e=>{let{data:s,onDelete:l}=e,[t,a]=u.useState([{id:"created_at",desc:!0}]),r=[{header:"Vector Store ID",accessorKey:"vector_store_id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.vector_store_id,children:(0,m.jsx)("span",{className:"font-mono text-blue-500 text-xs font-normal",children:l.vector_store_id})})})}},{header:"Name",accessorKey:"vector_store_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_name,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_name||"-"})})}},{header:"Description",accessorKey:"vector_store_description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_description,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_description||"-"})})}},{header:"Provider",accessorKey:"custom_llm_provider",cell:e=>{let{row:s}=e,{displayName:l,logo:t}=sm(s.original.custom_llm_provider);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:l,className:"h-4 w-4"}),(0,m.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.vector_store_id),className:"cursor-pointer"})})}}],i=(0,e2.b7)({data:s,columns:r,state:{sorting:t},onSortingChange:a,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:i.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:i.getRowModel().rows.length>0?i.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:r.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No vector stores found"})})})})})]})})})},rv=e=>{let{isVisible:s,onCancel:l,onSuccess:t,accessToken:a,credentials:r}=e,[i]=M.Z.useForm(),[o,d]=(0,u.useState)("{}"),c=async e=>{if(a)try{let s={};try{s=o.trim()?JSON.parse(o):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}await (0,b.Mx)(a,{vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s,litellm_credential_name:e.litellm_credential_name}),F.ZP.success("Vector store created successfully"),i.resetFields(),d("{}"),t()}catch(e){console.error("Error creating vector store:",e),F.ZP.error("Error creating vector store: "+e)}},h=()=>{i.resetFields(),d("{}"),l()};return(0,m.jsx)(R.Z,{title:"Create New Vector Store",visible:s,width:800,footer:null,onCancel:h,children:(0,m.jsxs)(M.Z,{form:i,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Provider"," ",(0,m.jsx)(Y.Z,{title:"Select the provider for this vector store",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],initialValue:"bedrock",children:(0,m.jsx)(D.default,{children:Object.entries(n).map(e=>{let[s,l]=e;return"Bedrock"===s?(0,m.jsx)(D.default.Option,{value:so[s],children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s):null})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store ID"," ",(0,m.jsx)(Y.Z,{title:"Enter the vector store ID from your api provider",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_id",rules:[{required:!0,message:"Please input the vector store ID from your api provider"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store Name"," ",(0,m.jsx)(Y.Z,{title:"Custom name you want to give to the vector store, this name will be rendered on the LiteLLM UI",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_name",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"vector_store_description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Existing Credentials"," ",(0,m.jsx)(Y.Z,{title:"Optionally select API provider credentials for this vector store eg. Bedrock API KEY",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...r.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON metadata for the vector store (optional)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),children:(0,m.jsx)(z.default.TextArea,{rows:4,value:o,onChange:e=>d(e.target.value),placeholder:'{"key": "value"}'})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,m.jsx)(C.Z,{onClick:h,variant:"secondary",children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",type:"submit",children:"Create"})]})]})})},ry=e=>{let{isVisible:s,onCancel:l,onConfirm:t}=e;return(0,m.jsxs)(R.Z,{title:"Delete Vector Store",visible:s,footer:null,onCancel:l,children:[(0,m.jsx)("p",{children:"Are you sure you want to delete this vector store? This action cannot be undone."}),(0,m.jsxs)("div",{className:"px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:t,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:l,variant:"primary",children:"Cancel"})]})]})},rb=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(!1),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)([]),f=async()=>{if(s)try{let e=await (0,b.Ou)(s);console.log("List vector stores response:",e),r(e.data||[])}catch(e){console.error("Error fetching vector stores:",e),F.ZP.error("Error fetching vector stores: "+e)}},_=async()=>{if(s)try{let e=await (0,b.N3)(s);console.log("List credentials response:",e),j(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e),F.ZP.error("Error fetching credentials: "+e)}},v=async e=>{h(e),d(!0)},y=async()=>{if(s&&c){try{await (0,b.Pv)(s,c),F.ZP.success("Vector store deleted successfully"),f()}catch(e){console.error("Error deleting vector store:",e),F.ZP.error("Error deleting vector store: "+e)}d(!1),h(null)}};return(0,u.useEffect)(()=>{f(),_()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Vector Store Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[x&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",x]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{f(),_(),p(new Date().toLocaleString())}})]})]}),(0,m.jsx)(P.Z,{className:"mb-4",children:(0,m.jsx)("p",{children:"You can use vector stores to store and retrieve LLM embeddings. Currently, we support Amazon Bedrock vector stores."})}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Create Vector Store"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(r_,{data:a,onDelete:v})})}),(0,m.jsx)(rv,{isVisible:i,onCancel:()=>n(!1),onSuccess:()=>{n(!1),f()},accessToken:s,credentials:g}),(0,m.jsx)(ry,{isVisible:o,onCancel:()=>d(!1),onConfirm:y})]})})},rZ=l(49096),rN=l(53335);let{cva:rw,cx:rk,compose:rS}=(0,rZ.ZD)({hooks:{onComplete:e=>(0,rN.m6)(e)}});function rC(e){var s,l;let{className:t="",...a}=e,r=(0,u.useId)();return s=()=>{let e=document.getAnimations().filter(e=>e instanceof CSSAnimation&&"spin"===e.animationName),s=e.find(e=>{var s;return(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))===r}),l=e.find(e=>{var s;return e.effect instanceof KeyframeEffect&&(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))!==r});s&&l&&(s.currentTime=l.currentTime)},l=[r],(0,u.useLayoutEffect)(s,l),(0,m.jsxs)("svg",{"data-spinner-id":r,className:rk("pointer-events-none size-12 animate-spin text-current",t),fill:"none",viewBox:"0 0 24 24",...a,children:[(0,m.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,m.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}let rI=new p.S;function rT(){return(0,m.jsxs)("div",{className:rk("h-screen","flex items-center justify-center gap-4"),children:[(0,m.jsx)("div",{className:"text-lg font-medium py-2 pr-4 border-r border-r-gray-200",children:"\uD83D\uDE85 LiteLLM"}),(0,m.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,m.jsx)(rC,{className:"size-4"}),(0,m.jsx)("span",{className:"text-gray-600 text-sm",children:"Loading..."})]})]})}function rA(){let[e,s]=(0,u.useState)(""),[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,p]=(0,u.useState)([]),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,S]=(0,u.useState)(!0),C=(0,h.useSearchParams)(),[I,T]=(0,u.useState)({data:[]}),[A,E]=(0,u.useState)(null),[P,O]=(0,u.useState)(!1),[L,D]=(0,u.useState)(!0),[M,F]=(0,u.useState)(null),R=C.get("invitation_id"),[q,U]=(0,u.useState)(()=>C.get("page")||"api-keys"),[z,V]=(0,u.useState)(null),K=e=>{p(s=>s?[...s,e]:[e]),O(()=>!P)},B=!1===L&&null===A&&null===R;return((0,u.useEffect)(()=>{E(function(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token")),D(!1)},[]),(0,u.useEffect)(()=>{B&&(window.location.href=(b.H2||"")+"/sso/key/generate")},[B]),(0,u.useEffect)(()=>{if(!A)return;let e=(0,x.o)(A);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),V(e.key),r(e.disabled_non_admin_personal_key_creation),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&U("usage")}else console.log("User role not defined");e.user_email?n(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?S("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,b.K8)(e.auth_header_name),e.user_id&&F(e.user_id)}},[A]),(0,u.useEffect)(()=>{z&&M&&e&&eT(M,e,z,v),z&&M&&e&&w(z,M,e,null,d),z&&lE(z,f)},[z,M,e]),L||B)?(0,m.jsx)(rT,{}):(0,m.jsx)(u.Suspense,{fallback:(0,m.jsx)(rT,{}),children:(0,m.jsx)(g.aH,{client:rI,children:R?(0,m.jsx)(si,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):(0,m.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,m.jsx)(N,{userID:M,userRole:e,premiumUser:l,userEmail:i,setProxySettings:Z,proxySettings:y,accessToken:z}),(0,m.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,m.jsx)("div",{className:"mt-8",children:(0,m.jsx)(aZ,{setPage:e=>{let s=new URLSearchParams(C);s.set("page",e),window.history.pushState(null,"","?".concat(s.toString())),U(e)},userRole:e,defaultSelectedKey:q})}),"api-keys"==q?(0,m.jsx)(si,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):"models"==q?(0,m.jsx)(lh,{userID:M,userRole:e,token:A,keys:c,accessToken:z,modelData:I,setModelData:T,premiumUser:l,teams:o}):"llm-playground"==q?(0,m.jsx)(ad,{userID:M,userRole:e,token:A,accessToken:z,disabledPersonalKeyCreation:a}):"users"==q?(0,m.jsx)(lk,{userID:M,userRole:e,token:A,keys:c,teams:o,accessToken:z,setKeys:p}):"teams"==q?(0,m.jsx)(lT,{teams:o,setTeams:d,searchParams:C,accessToken:z,userID:M,userRole:e,organizations:j}):"organizations"==q?(0,m.jsx)(lP,{organizations:j,setOrganizations:f,userModels:_,accessToken:z,userRole:e,premiumUser:l}):"admin-panel"==q?(0,m.jsx)(lK,{setTeams:d,searchParams:C,accessToken:z,userID:M,showSSOBanner:k,premiumUser:l,proxySettings:y}):"api_ref"==q?(0,m.jsx)(tq,{proxySettings:y}):"settings"==q?(0,m.jsx)(l1,{userID:M,userRole:e,accessToken:z,premiumUser:l}):"budgets"==q?(0,m.jsx)(td,{accessToken:z}):"guardrails"==q?(0,m.jsx)(rd,{accessToken:z,userRole:e}):"transform-request"==q?(0,m.jsx)(rc,{accessToken:z}):"general-settings"==q?(0,m.jsx)(te,{userID:M,userRole:e,accessToken:z,modelData:I}):"model-hub"==q?(0,m.jsx)(tC.Z,{accessToken:z,publicPage:!1,premiumUser:l}):"caching"==q?(0,m.jsx)(aL,{userID:M,userRole:e,token:A,accessToken:z,premiumUser:l}):"pass-through-settings"==q?(0,m.jsx)(tr,{userID:M,userRole:e,accessToken:z,modelData:I}):"logs"==q?(0,m.jsx)(tk,{userID:M,userRole:e,token:A,accessToken:z,allTeams:null!=o?o:[]}):"mcp-tools"==q?(0,m.jsx)(rp,{accessToken:z,userRole:e,userID:M}):"tag-management"==q?(0,m.jsx)(rf,{accessToken:z,userRole:e,userID:M}):"vector-stores"==q?(0,m.jsx)(rb,{accessToken:z,userRole:e,userID:M}):"new_usage"==q?(0,m.jsx)(tR,{userID:M,userRole:e,accessToken:z,teams:null!=o?o:[]}):(0,m.jsx)(ak,{userID:M,userRole:e,token:A,accessToken:z,keys:c,premiumUser:l})]})]})})})}},3914:function(e,s,l){"use strict";function t(){let e=window.location.hostname,s=["Lax","Strict","None"];["/","/ui"].forEach(l=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,";"),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let t="None"===s?" Secure;":"";document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; SameSite=").concat(s,";").concat(t),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(t)})}),console.log("After clearing cookies:",document.cookie)}function a(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}l.d(s,{b:function(){return t},e:function(){return a}})}},function(e){e.O(0,[665,990,402,313,899,460,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/index.html b/litellm/proxy/_experimental/out/index.html index cf96cffc00f..fb47f3c8ce8 100644 --- a/litellm/proxy/_experimental/out/index.html +++ b/litellm/proxy/_experimental/out/index.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/index.txt b/litellm/proxy/_experimental/out/index.txt index 38ed1ea2619..a5430891ee4 100644 --- a/litellm/proxy/_experimental/out/index.txt +++ b/litellm/proxy/_experimental/out/index.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[96564,["665","static/chunks/3014691f-b7b79b78e27792f3.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","402","static/chunks/402-ba983153c902cb17.js","313","static/chunks/313-9496b55e0596d651.js","899","static/chunks/899-ebef5c8ffc176e86.js","460","static/chunks/460-f6ee8934fa9fc1ae.js","250","static/chunks/250-45f35de8b3449336.js","699","static/chunks/699-6fbb6ca66d95cf3c.js","931","static/chunks/app/page-a61458b2080ad3dd.js"],"default",1] +3:I[96564,["665","static/chunks/3014691f-b7b79b78e27792f3.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","402","static/chunks/402-ba983153c902cb17.js","313","static/chunks/313-9496b55e0596d651.js","899","static/chunks/899-ebef5c8ffc176e86.js","460","static/chunks/460-f6ee8934fa9fc1ae.js","250","static/chunks/250-45f35de8b3449336.js","699","static/chunks/699-6fbb6ca66d95cf3c.js","931","static/chunks/app/page-b69fceb3ef4b38ca.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["qsCBX7lGZ8wS9ItsE0Soj",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] +0:["zGtpf6gsLk3yIgGiM71ql",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"LiteLLM Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/litellm/proxy/_experimental/out/model_hub.txt b/litellm/proxy/_experimental/out/model_hub.txt index f98c604ffa8..059237305e8 100644 --- a/litellm/proxy/_experimental/out/model_hub.txt +++ b/litellm/proxy/_experimental/out/model_hub.txt @@ -2,6 +2,6 @@ 3:I[52829,["402","static/chunks/402-ba983153c902cb17.js","313","static/chunks/313-9496b55e0596d651.js","250","static/chunks/250-45f35de8b3449336.js","699","static/chunks/699-6fbb6ca66d95cf3c.js","418","static/chunks/app/model_hub/page-ce40c5a05f3174ca.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["qsCBX7lGZ8wS9ItsE0Soj",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] +0:["zGtpf6gsLk3yIgGiM71ql",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"LiteLLM Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.html index 31dfc72286e..51a7ab12d8d 100644 --- a/litellm/proxy/_experimental/out/onboarding.html +++ b/litellm/proxy/_experimental/out/onboarding.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/onboarding.txt b/litellm/proxy/_experimental/out/onboarding.txt index bcc9d435057..2bde17545e2 100644 --- a/litellm/proxy/_experimental/out/onboarding.txt +++ b/litellm/proxy/_experimental/out/onboarding.txt @@ -2,6 +2,6 @@ 3:I[12011,["665","static/chunks/3014691f-b7b79b78e27792f3.js","402","static/chunks/402-ba983153c902cb17.js","899","static/chunks/899-ebef5c8ffc176e86.js","250","static/chunks/250-45f35de8b3449336.js","461","static/chunks/app/onboarding/page-8c2f1d7b29a0b5ff.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["qsCBX7lGZ8wS9ItsE0Soj",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] +0:["zGtpf6gsLk3yIgGiM71ql",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"LiteLLM Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/ui/litellm-dashboard/out/404.html b/ui/litellm-dashboard/out/404.html index 4c364158957..3ec058d3997 100644 --- a/ui/litellm-dashboard/out/404.html +++ b/ui/litellm-dashboard/out/404.html @@ -1 +1 @@ -404: This page could not be found.LiteLLM Dashboard

404

This page could not be found.

\ No newline at end of file +404: This page could not be found.LiteLLM Dashboard

404

This page could not be found.

\ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-a61458b2080ad3dd.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-b69fceb3ef4b38ca.js similarity index 79% rename from ui/litellm-dashboard/out/_next/static/chunks/app/page-a61458b2080ad3dd.js rename to ui/litellm-dashboard/out/_next/static/chunks/app/page-b69fceb3ef4b38ca.js index 20bcc3e9bc1..74d5c51739b 100644 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/page-a61458b2080ad3dd.js +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/page-b69fceb3ef4b38ca.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,s,l){Promise.resolve().then(l.bind(l,96564))},12011:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return v}});var t=l(57437),a=l(2265),r=l(99376),n=l(20831),i=l(94789),o=l(12514),d=l(49804),c=l(67101),m=l(84264),u=l(49566),h=l(96761),x=l(84566),p=l(19250),g=l(14474),j=l(13634),f=l(73002),_=l(3914);function v(){let[e]=j.Z.useForm(),s=(0,r.useSearchParams)();(0,_.e)("token");let l=s.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[k,S]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[T,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{l&&(0,p.W_)(l).then(e=>{let s=e.login_url;console.log("login_url:",s),I(s);let l=e.token,t=(0,g.o)(l);A(l),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),S(t.user_id)})},[l]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(i.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tier."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(n.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",T,"formValues:",e),v&&T&&(e.user_email=N,k&&l&&(0,p.m_)(v,l,k,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+T,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},96564:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return rT}});var t,a,r,n,i,o,d,c,m=l(57437),u=l(2265),h=l(99376),x=l(14474),p=l(21623),g=l(29827),j=l(27648),f=l(80795),_=l(15883),v=l(40428),y=l(3914),b=l(19250);let Z=async e=>{if(!e)return null;try{return await (0,b.g)(e)}catch(e){return console.error("Error fetching proxy settings:",e),null}};var N=e=>{let{userID:s,userEmail:l,userRole:t,premiumUser:a,proxySettings:r,setProxySettings:n,accessToken:i}=e,[o,d]=(0,u.useState)("");(0,u.useEffect)(()=>{(async()=>{if(i){let e=await Z(i);console.log("response from fetchProxySettings",e),e&&n(e)}})()},[i]),(0,u.useEffect)(()=>{d((null==r?void 0:r.PROXY_LOGOUT_URL)||"")},[r]);let c=[{key:"1",label:(0,m.jsxs)("div",{className:"py-1",children:[(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",l||"Unknown"]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,m.jsx)(_.Z,{})," ",s]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,m.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,y.b)(),window.location.href=o},children:[(0,m.jsx)(v.Z,{})," Logout"]})}];return(0,m.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,m.jsx)("div",{className:"w-full",children:(0,m.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,m.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,m.jsx)(j.default,{href:"/",className:"flex items-center",children:(0,m.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,m.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,m.jsx)(f.Z,{menu:{items:c,style:{padding:"4px",marginTop:"4px"}},children:(0,m.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,m.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})};let w=async(e,s,l,t,a)=>{let r;r="Admin"!=l&&"Admin Viewer"!=l?await (0,b.It)(e,(null==t?void 0:t.organization_id)||null,s):await (0,b.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var k=l(49804),S=l(67101),C=l(20831),I=l(49566),T=l(87452),A=l(88829),E=l(72208),P=l(84264),O=l(96761),L=l(29233),D=l(52787),M=l(13634),F=l(41021),R=l(91679),q=l(29967),U=l(73002),z=l(64482),V=l(30150),K=e=>{let{step:s=.01,style:l={width:"100%"},placeholder:t="Enter a numerical value",min:a,max:r,onChange:n,...i}=e;return(0,m.jsx)(V.Z,{onWheel:e=>e.currentTarget.blur(),step:s,style:l,placeholder:t,min:a,max:r,onChange:n,...i})};let B=async(e,s,l)=>{try{if(null===e||null===s)return;if(null!==l){let t=(await (0,b.So)(l,e,s,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},H=e=>{if(e.endsWith("/*")){let s=e.replace("/*","");return"All ".concat(s," models")}return e},J=(e,s)=>{let l=[],t=[];return console.log("teamModels",e),console.log("allModels",s),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=s.filter(e=>e.startsWith(a+"/"));t.push(...r),l.push(e)}else t.push(e)}),[...l,...t].filter((e,s,l)=>l.indexOf(e)===s)};var G=l(20577),W=l(15424),Y=l(89970);let $=(e,s)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===s.format,X=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},Q=(e,s,l)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[l]||"Text input";return $(e,s)?"".concat(t,"\nMust be valid JSON format"):s.enum?"Select from available options\nAllowed values: ".concat(s.enum.join(", ")):t};var ee=e=>{let{schemaComponent:s,excludedFields:l=[],form:t,overrideLabels:a={},overrideTooltips:r={},customValidation:n={},defaultValues:i={}}=e,[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null);(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.lP)()).components.schemas[s];if(!e)throw Error('Schema component "'.concat(s,'" not found'));d(e);let a={};Object.keys(e.properties).filter(e=>!l.includes(e)&&void 0!==i[e]).forEach(e=>{a[e]=i[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[s,t,l]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let s=e.anyOf.map(e=>e.type);if(s.includes("number")||s.includes("integer"))return"number";s.includes("string")}return"string"},p=(e,s)=>{var l;let t;let d=x(s),c=null==o?void 0:null===(l=o.required)||void 0===l?void 0:l.includes(e),u=a[e]||s.title||e,h=r[e]||s.description,p=[];c&&p.push({required:!0,message:"".concat(u," is required")}),n[e]&&p.push({validator:n[e]}),$(e,s)&&p.push({validator:async(e,s)=>{if(s&&!X(s))throw Error("Please enter valid JSON")}});let g=h?(0,m.jsxs)("span",{children:[u," ",(0,m.jsx)(Y.Z,{title:h,children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}):u;return t=$(e,s)?(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):s.enum?(0,m.jsx)(D.default,{children:s.enum.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"number"===d||"integer"===d?(0,m.jsx)(G.Z,{style:{width:"100%"},precision:"integer"===d?0:void 0}):"duration"===e?(0,m.jsx)(I.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,m.jsx)(I.Z,{placeholder:h||""}),(0,m.jsx)(M.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:i[e],help:(0,m.jsx)("div",{className:"text-xs text-gray-500",children:Q(e,s,d)}),children:t},e)};return c?(0,m.jsxs)("div",{className:"text-red-500",children:["Error: ",c]}):(null==o?void 0:o.properties)?(0,m.jsx)("div",{children:Object.entries(o.properties).filter(e=>{let[s]=e;return!l.includes(s)}).map(e=>{let[s,l]=e;return p(s,l)})}):null},es=e=>{let{teams:s,value:l,onChange:t}=e;return(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Search or select a team",value:l,onChange:t,filterOption:(e,s)=>{var l,t,a;return!!s&&((null===(a=s.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(l=t.props)||void 0===l?void 0:l.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==s?void 0:s.map(e=>(0,m.jsxs)(D.default.Option,{value:e.team_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},el=l(57365),et=l(93192);function ea(e){let{isInvitationLinkModalVisible:s,setIsInvitationLinkModalVisible:l,baseUrl:t,invitationLinkData:a}=e,{Title:r,Paragraph:n}=et.default,i=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,m.jsxs)(R.Z,{title:"Invitation Link",visible:s,width:800,footer:null,onOk:()=>{l(!1)},onCancel:()=>{l(!1)},children:[(0,m.jsx)(n,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"User ID"}),(0,m.jsx)(P.Z,{children:null==a?void 0:a.user_id})]}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{children:"Invitation Link"}),(0,m.jsx)(P.Z,{children:(0,m.jsx)(P.Z,{children:i()})})]}),(0,m.jsx)("div",{className:"flex justify-end mt-5",children:(0,m.jsx)(L.CopyToClipboard,{text:i(),onCopy:()=>F.ZP.success("Copied!"),children:(0,m.jsx)(C.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var er=l(85010),en=l(72188),ei=l(73879),eo=l(34310),ed=l(38434),ec=l(26349),em=l(35291),eu=l(3632),eh=l(15452),ex=l.n(eh),ep=l(71157),eg=l(44643),ej=l(88532),ef=e=>{let{accessToken:s,teams:l,possibleUIRoles:t,onUsersCreated:a}=e,[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(null),[N,w]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.g)(s);Z(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),w(new URL("/",window.location.href).toString())},[s]);let k=async()=>{c(!0);let e=i.map(e=>({...e,status:"pending"}));o(e);let l=!1;for(let a=0;ae.trim()).filter(Boolean),0===e.teams.length&&delete e.teams),i.models&&"string"==typeof i.models&&""!==i.models.trim()&&(e.models=i.models.split(",").map(e=>e.trim()).filter(Boolean),0===e.models.length&&delete e.models),i.max_budget&&""!==i.max_budget.toString().trim()){let s=parseFloat(i.max_budget.toString());!isNaN(s)&&s>0&&(e.max_budget=s)}i.budget_duration&&""!==i.budget_duration.trim()&&(e.budget_duration=i.budget_duration.trim()),i.metadata&&"string"==typeof i.metadata&&""!==i.metadata.trim()&&(e.metadata=i.metadata.trim()),console.log("Sending user data:",e);let r=await (0,b.Ov)(s,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){l=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==y?void 0:y.SSO_ENABLED){let e=new URL("/ui",N).toString();o(s=>s.map((s,l)=>l===a?{...s,status:"success",key:r.key||r.user_id,invitation_link:e}:s))}else{let l=await (0,b.XO)(s,e),t=new URL("/ui?invitation_id=".concat(l.id),N).toString();o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}catch(s){console.error("Caught error:",s);let e=(null==s?void 0:null===(n=s.response)||void 0===n?void 0:null===(r=n.data)||void 0===r?void 0:r.error)||(null==s?void 0:s.message)||String(s);o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}c(!1),l&&a&&a()};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>n(!0),children:"+ Bulk Invite Users"}),(0,m.jsx)(R.Z,{title:"Bulk Invite Users",visible:r,width:800,onCancel:()=>n(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,m.jsx)("div",{className:"flex flex-col",children:0===i.length?(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,m.jsxs)("div",{className:"ml-11 mb-6",children:[(0,m.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,m.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,m.jsx)("li",{children:"Download our CSV template"}),(0,m.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,m.jsx)("li",{children:"Save the file and upload it here"}),(0,m.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_email"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_role"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"teams"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"models"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=new Blob([ex().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),s=window.URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download="bulk_users_template.csv",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)},size:"lg",className:"w-full md:w-auto",children:[(0,m.jsx)(ei.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,m.jsxs)("div",{className:"ml-11",children:[_?(0,m.jsxs)("div",{className:"mb-4 p-4 rounded-md border ".concat(j?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200"),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[j?(0,m.jsx)(eo.Z,{className:"text-red-500 text-xl mr-3"}):(0,m.jsx)(ed.Z,{className:"text-blue-500 text-xl mr-3"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:j?"text-red-800":"text-blue-800",children:_.name}),(0,m.jsxs)(et.default.Text,{className:"block text-xs ".concat(j?"text-red-600":"text-blue-600"),children:[(_.size/1024).toFixed(1)," KB • ",new Date().toLocaleDateString()]})]})]}),(0,m.jsxs)(C.Z,{size:"xs",variant:"secondary",onClick:()=>{v(null),o([]),x(null),g(null),f(null)},className:"flex items-center",children:[(0,m.jsx)(ec.Z,{className:"mr-1"})," Remove"]})]}),j?(0,m.jsxs)("div",{className:"mt-3 text-red-600 text-sm flex items-start",children:[(0,m.jsx)(em.Z,{className:"mr-2 mt-0.5"}),(0,m.jsx)("span",{children:j})]}):!p&&(0,m.jsxs)("div",{className:"mt-3 flex items-center",children:[(0,m.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,m.jsx)("div",{className:"bg-blue-500 h-1.5 rounded-full w-full animate-pulse"})}),(0,m.jsx)("span",{className:"ml-2 text-xs text-blue-600",children:"Processing..."})]})]}):(0,m.jsx)(er.Z,{beforeUpload:e=>((x(null),g(null),f(null),v(e),"text/csv"===e.type||e.name.endsWith(".csv"))?e.size>5242880?f("File is too large (".concat((e.size/1048576).toFixed(1)," MB). Please upload a CSV file smaller than 5MB.")):ex().parse(e,{complete:e=>{if(!e.data||0===e.data.length){g("The CSV file appears to be empty. Please upload a file with data."),o([]);return}if(1===e.data.length){g("The CSV file only contains headers but no user data. Please add user data to your CSV."),o([]);return}let s=e.data[0];if(0===s.length||1===s.length&&""===s[0]){g("The CSV file doesn't contain any column headers. Please make sure your CSV has headers."),o([]);return}let t=["user_email","user_role"].filter(e=>!s.includes(e));if(t.length>0){g("Your CSV is missing these required columns: ".concat(t.join(", "),". Please add these columns to your CSV file.")),o([]);return}try{let t=e.data.slice(1).map((e,t)=>{var a,r,n,i,o,d;if(0===e.length||1===e.length&&""===e[0])return null;if(e.length=parseFloat(c.max_budget.toString())&&m.push("Max budget must be greater than 0")),c.budget_duration&&!c.budget_duration.match(/^\d+[dhmwy]$|^\d+mo$/)&&m.push('Invalid budget duration format "'.concat(c.budget_duration,'". Use format like "30d", "1mo", "2w", "6h"')),c.teams&&"string"==typeof c.teams&&l&&l.length>0){let e=l.map(e=>e.team_id),s=c.teams.split(",").map(e=>e.trim()).filter(s=>!e.includes(s));s.length>0&&m.push("Unknown team(s): ".concat(s.join(", ")))}return m.length>0&&(c.isValid=!1,c.error=m.join(", ")),c}).filter(Boolean),a=t.filter(e=>e.isValid);o(t),0===t.length?g("No valid data rows found in the CSV file. Please check your file format."):0===a.length?x("No valid users found in the CSV. Please check the errors below and fix your CSV file."):a.length{x("Failed to parse CSV file: ".concat(e.message)),o([])},header:!1}):(f("Invalid file type: ".concat(e.name,". Please upload a CSV file (.csv extension).")),F.ZP.error("Invalid file type. Please upload a CSV file.")),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,m.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,m.jsx)(eu.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,m.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,m.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,m.jsx)(C.Z,{size:"sm",children:"Browse files"}),(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-4",children:"Only CSV files (.csv) are supported"})]})}),p&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(ej.Z,{className:"h-5 w-5 text-yellow-500 mr-2 mt-0.5"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:"text-yellow-800",children:"CSV Structure Error"}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-1 mb-0",children:p}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-2 mb-0",children:"Please download our template and ensure your CSV follows the required format."})]})]})})]})]}):(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:i.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,m.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(em.Z,{className:"text-red-500 mr-2 mt-1"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"text-red-600 font-medium",children:h}),i.some(e=>!e.isValid)&&(0,m.jsxs)("ul",{className:"mt-2 list-disc list-inside text-red-600 text-sm",children:[(0,m.jsx)("li",{children:"Check the table below for specific errors in each row"}),(0,m.jsx)("li",{children:"Common issues include invalid email formats, missing required fields, or incorrect role values"}),(0,m.jsx)("li",{children:"Fix these issues in your CSV file and upload again"})]})]})]})}),(0,m.jsxs)("div",{className:"ml-11",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,m.jsx)("div",{className:"flex items-center",children:i.some(e=>"success"===e.status||"failed"===e.status)?(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[i.filter(e=>"success"===e.status).length," Successful"]}),i.some(e=>"failed"===e.status)&&(0,m.jsxs)(P.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[i.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[i.filter(e=>e.isValid).length," of ",i.length," users valid"]})]})}),!i.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex space-x-3",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===i.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(i.filter(e=>e.isValid).length," Users")})]})]}),i.some(e=>"success"===e.status)&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"mr-3 mt-1",children:(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-blue-500"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,m.jsxs)(P.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,m.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,m.jsx)(en.Z,{dataSource:i,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,s)=>s.isValid?s.status&&"pending"!==s.status?"success"===s.status?(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,m.jsx)("span",{className:"text-green-500",children:"Success"})]}),s.invitation_link&&(0,m.jsx)("div",{className:"mt-1",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:s.invitation_link}),(0,m.jsx)(L.CopyToClipboard,{text:s.invitation_link,onCopy:()=>F.ZP.success("Invitation link copied!"),children:(0,m.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Failed"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(s.error)})]}):(0,m.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:s.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!i.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===i.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(i.filter(e=>e.isValid).length," Users")})]}),i.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=i.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),s=new Blob([ex().unparse(e)],{type:"text/csv"}),l=window.URL.createObjectURL(s),t=document.createElement("a");t.href=l,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(l)},variant:"primary",className:"flex items-center",children:[(0,m.jsx)(ei.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:e_}=D.default;var ev=e=>{let{userID:s,accessToken:l,teams:t,possibleUIRoles:a,onUserCreated:r,isEmbedded:n=!1}=e,i=(0,g.NL)(),[o,d]=(0,u.useState)(null),[c]=M.Z.useForm(),[x,p]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=(0,h.useRouter)(),[S,L]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.So)(l,s,"any"),t=[];for(let s=0;s{k&&L(new URL("/",window.location.href).toString())},[k]);let q=async e=>{var t,a,d;try{F.ZP.info("Making API Call"),n||p(!0),e.models&&0!==e.models.length||"proxy_admin"===e.user_role||(console.log("formValues.user_role",e.user_role),e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,b.Ov)(l,null,e);await i.invalidateQueries({queryKey:["userList"]}),console.log("user create Response:",a),f(!0);let d=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(r&&n){r(d),c.resetFields();return}if(null==o?void 0:o.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:d,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:s,updated_at:new Date,updated_by:s,has_user_setup_sso:!0};w(e),Z(!0)}else(0,b.XO)(l,d).then(e=>{e.has_user_setup_sso=!1,w(e),Z(!0)});F.ZP.success("API user Created"),c.resetFields(),localStorage.removeItem("userData"+s)}catch(s){let e=(null===(d=s.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.detail)||(null==s?void 0:s.message)||"Error creating the user";F.ZP.error(e),console.error("Error creating the user:",s)}};return n?(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>p(!0),children:"+ Invite User"}),(0,m.jsx)(ef,{accessToken:l,teams:t,possibleUIRoles:a}),(0,m.jsxs)(R.Z,{title:"Invite User",visible:x,width:800,footer:null,onOk:()=>{p(!1),c.resetFields()},onCancel:()=>{p(!1),f(!1),c.resetFields()},children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{children:"Personal Key Creation"})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(M.Z.Item,{className:"gap-2",label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Models user has access to, outside of team scope.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),_.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]})]}),j&&(0,m.jsx)(ea,{isInvitationLinkModalVisible:y,setIsInvitationLinkModalVisible:Z,baseUrl:S,invitationLinkData:N})]})},ey=l(7310),eb=l.n(ey),eZ=l(20347);let{Option:eN}=D.default,ew=e=>e?({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||e:"Not set";var ek=e=>{let{value:s,onChange:l,className:t="",style:a={}}=e;return(0,m.jsxs)(D.default,{style:{width:"100%",...a},value:s||void 0,onChange:l,className:t,placeholder:"n/a",children:[(0,m.jsx)(eN,{value:"24h",children:"daily"}),(0,m.jsx)(eN,{value:"7d",children:"weekly"}),(0,m.jsx)(eN,{value:"30d",children:"monthly"})]})};let{Option:eS}=D.default,eC=e=>{let s=[];if(console.log("data:",JSON.stringify(e)),e)for(let l of e)l.metadata&&l.metadata.tags&&s.push(...l.metadata.tags);let l=Array.from(new Set(s)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",l),l},eI=async(e,s,l,t)=>{try{if(null===e||null===s)return[];if(null!==l){let a=(await (0,b.So)(l,e,s,!0,t)).data.map(e=>e.id);return console.log("available_model_names:",a),a}return[]}catch(e){return console.error("Error fetching user models:",e),[]}},eT=async(e,s,l,t)=>{try{if(null===e||null===s)return;if(null!==l){let a=(await (0,b.So)(l,e,s)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eA=e=>{let{userID:s,team:l,teams:t,userRole:a,accessToken:r,data:n,addKey:i}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)("you"),[N,w]=(0,u.useState)(eC(n)),[V,B]=(0,u.useState)([]),[J,G]=(0,u.useState)(l),[$,X]=(0,u.useState)(!1),[Q,el]=(0,u.useState)(null),[et,ea]=(0,u.useState)({}),[er,en]=(0,u.useState)([]),[ei,eo]=(0,u.useState)(!1),ed=()=>{c(!1),o.resetFields()},ec=()=>{c(!1),x(null),G(null),o.resetFields()};(0,u.useEffect)(()=>{s&&a&&r&&eT(s,a,r,f)},[r,s,a]),(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.t3)(r)).guardrails.map(e=>e.guardrail_name);B(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[r]),(0,u.useEffect)(()=>{(async()=>{try{if(r){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,b.lg)(r);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[r]);let em=async e=>{try{var l,t,a;let d=null!==(l=null==e?void 0:e.key_alias)&&void 0!==l?l:"",m=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==n?void 0:n.filter(e=>e.team_id===m).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(d))throw Error("Key alias ".concat(d," already exists for team with ID ").concat(m,", please provide another key alias"));if(F.ZP.info("Making API Call"),c(!0),"you"===y&&(e.user_id=s),"service_account"===y){let s={};try{s=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}s.service_account_id=e.key_alias,e.metadata=JSON.stringify(s)}let u=await (0,b.wX)(r,s,e);console.log("key create Response:",u),i(u),x(u.key),g(u.soft_budget),F.ZP.success("API Key Created"),o.resetFields(),localStorage.removeItem("userData"+s)}catch(e){console.log("error in create key:",e),F.ZP.error("Error creating the key: ".concat(e))}};(0,u.useEffect)(()=>{if(s&&a&&r){var e;eI(s,a,r,null!==(e=null==J?void 0:J.team_id)&&void 0!==e?e:null).then(e=>{var s;v(Array.from(new Set([...null!==(s=null==J?void 0:J.models)&&void 0!==s?s:[],...e])))})}o.setFieldValue("models",[])},[J,r,s,a]);let eu=async e=>{if(!e){en([]);return}eo(!0);try{let s=new URLSearchParams;if(s.append("user_email",e),null==r)return;let l=(await (0,b.u5)(r,s)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));en(l)}catch(e){console.error("Error fetching users:",e),F.ZP.error("Failed to search for users")}finally{eo(!1)}},eh=(0,u.useCallback)(eb()(e=>eu(e),300),[r]),ex=(e,s)=>{let l=s.user;o.setFieldsValue({user_id:l.user_id})};return(0,m.jsxs)("div",{children:[a&&eZ.LQ.includes(a)&&(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Create New Key"}),(0,m.jsx)(R.Z,{visible:d,width:1e3,footer:null,onOk:ed,onCancel:ec,children:(0,m.jsxs)(M.Z,{form:o,onFinish:em,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Ownership"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Owned By"," ",(0,m.jsx)(Y.Z,{title:"Select who will own this API key",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,m.jsxs)(q.ZP.Group,{onChange:e=>Z(e.target.value),value:y,children:[(0,m.jsx)(q.ZP,{value:"you",children:"You"}),(0,m.jsx)(q.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,m.jsx)(q.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===y&&(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["User ID"," ",(0,m.jsx)(Y.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===y,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{eh(e)},onSelect:(e,s)=>ex(e,s),options:er,loading:ei,allowClear:!0,style:{width:"100%"},notFoundContent:ei?"Searching...":"No users found"}),(0,m.jsx)(U.ZP,{onClick:()=>X(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,m.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Team"," ",(0,m.jsx)(Y.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:l?l.team_id:null,className:"mt-4",children:(0,m.jsx)(es,{teams:t,onChange:e=>{G((null==t?void 0:t.find(s=>s.team_id===e))||null)}})})]}),(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Details"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["you"===y||"another_user"===y?"Key Name":"Service Account ID"," ",(0,m.jsx)(Y.Z,{title:"you"===y||"another_user"===y?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===y?"key name":"service account ID")}],help:"required",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&o.setFieldsValue({models:["all-team-models"]})},children:[(0,m.jsx)(eS,{value:"all-team-models",children:"All Team Models"},"all-team-models"),_.map(e=>(0,m.jsx)(eS,{value:e,children:H(e)},e))]})})]}),(0,m.jsx)("div",{className:"mb-8",children:(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{className:"m-0",children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Max Budget (USD)"," ",(0,m.jsx)(Y.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==l?void 0:l.max_budget)!==null&&(null==l?void 0:l.max_budget)!==void 0?null==l?void 0:l.max_budget:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.max_budget&&s>l.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(l.max_budget))}}],children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Reset Budget"," ",(0,m.jsx)(Y.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==l?void 0:l.budget_duration)!==null&&(null==l?void 0:l.budget_duration)!==void 0?null==l?void 0:l.budget_duration:"None"),children:(0,m.jsx)(ek,{onChange:e=>o.setFieldValue("budget_duration",e)})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==l?void 0:l.tpm_limit)!==null&&(null==l?void 0:l.tpm_limit)!==void 0?null==l?void 0:l.tpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.tpm_limit&&s>l.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(l.tpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==l?void 0:l.rpm_limit)!==null&&(null==l?void 0:l.rpm_limit)!==void 0?null==l?void 0:l.rpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.rpm_limit&&s>l.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(l.rpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Expire Key"," ",(0,m.jsx)(Y.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,m.jsx)(I.Z,{placeholder:"e.g., 30d"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:V.map(e=>({value:e,label:e}))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Tags"," ",(0,m.jsx)(Y.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:N})}),(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("b",{children:"Advanced Settings"}),(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,m.jsx)("a",{href:b.H2?"".concat(b.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,m.jsx)(W.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(ee,{schemaComponent:"GenerateKeyRequest",form:o,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Key"})})]})}),$&&(0,m.jsx)(R.Z,{title:"Create New User",visible:$,onCancel:()=>X(!1),footer:null,width:800,children:(0,m.jsx)(ev,{userID:s,accessToken:r,teams:t,possibleUIRoles:et,onUserCreated:e=>{el(e),o.setFieldsValue({user_id:e}),X(!1)},isEmbedded:!0})}),h&&(0,m.jsx)(R.Z,{visible:d,onOk:ed,onCancel:ec,footer:null,children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Save your Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:null!=h?(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:h})}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>{F.ZP.success("API Key copied to clipboard")},children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,m.jsx)(P.Z,{children:"Key being created, this might take 30s"})})]})})]})},eE=l(7366),eP=e=>{let{selectedTeam:s,currentOrg:l,selectedKeyAlias:t,accessToken:a,createClicked:r}=e,[n,i]=(0,u.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,u.useState)(!0),[c,m]=(0,u.useState)(null),h=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!a){console.log("accessToken",a);return}d(!0);let s="number"==typeof e.page?e.page:1,l="number"==typeof e.pageSize?e.pageSize:100,t=await (0,b.OD)(a,null,null,null,null,null,s,l);console.log("data",t),i(t),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,u.useEffect)(()=>{h(),console.log("selectedTeam",s,"currentOrg",l,"accessToken",a,"selectedKeyAlias",t)},[s,l,a,t,r]),{keys:n.keys,isLoading:o,error:c,pagination:{currentPage:n.current_page,totalPages:n.total_pages,totalCount:n.total_count},refresh:h,setKeys:e=>{i(s=>{let l="function"==typeof e?e(s.keys):e;return{...s,keys:l}})}}},eO=l(27281),eL=l(41649),eD=l(12514),eM=l(12485),eF=l(18135),eR=l(35242),eq=l(29706),eU=l(77991),ez=l(10900),eV=l(23628),eK=l(74998);function eB(e){var s,l;let{keyData:t,onCancel:a,onSubmit:r,teams:n,accessToken:i,userID:o,userRole:d}=e,[c]=M.Z.useForm(),[h,x]=(0,u.useState)([]),p=null==n?void 0:n.find(e=>e.team_id===t.team_id),[g,j]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(o&&d&&i)try{if(null===t.team_id){let e=(await (0,b.So)(i,o,d)).data.map(e=>e.id);j(e)}else if(null==p?void 0:p.team_id){let e=await eI(o,d,i,p.team_id);j(Array.from(new Set([...p.models,...e])))}}catch(e){console.error("Error fetching models:",e)}})()},[o,d,i,p,t.team_id]);let f={...t,budget_duration:(l=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[l]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(s=t.metadata)||void 0===s?void 0:s.guardrails)||[]};return(0,m.jsxs)(M.Z,{form:c,onFinish:r,initialValues:f,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[g.length>0&&(0,m.jsx)(D.default.Option,{value:"all-team-models",children:"All Team Models"}),g.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,style:{width:"100%"},placeholder:"Enter a numerical value"})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"daily",children:"Daily"}),(0,m.jsx)(D.default.Option,{value:"weekly",children:"Weekly"}),(0,m.jsx)(D.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsx)(M.Z.Item,{name:"token",hidden:!0,children:(0,m.jsx)(z.default,{})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(C.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]})}function eH(e){let{selectedToken:s,visible:l,onClose:t,accessToken:a}=e,[r]=M.Z.useForm(),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!1);(0,u.useEffect)(()=>{l&&s&&r.setFieldsValue({key_alias:s.key_alias,max_budget:s.max_budget,tpm_limit:s.tpm_limit,rpm_limit:s.rpm_limit,duration:s.duration||""})},[l,s,r]),(0,u.useEffect)(()=>{l||(i(null),p(!1),r.resetFields())},[l,r]),(0,u.useEffect)(()=>{(null==o?void 0:o.duration)?h((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString()}catch(e){return null}})(o.duration)):h(null)},[null==o?void 0:o.duration]);let g=async()=>{if(s&&a){p(!0);try{let e=await r.validateFields(),l=await (0,b.s0)(a,s.token,e);i(l.key),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key"),p(!1)}}},j=()=>{i(null),p(!1),r.resetFields(),t()};return(0,m.jsx)(R.Z,{title:"Regenerate API Key",open:l,onCancel:j,footer:n?[(0,m.jsx)(C.Z,{onClick:j,children:"Close"},"close")]:[(0,m.jsx)(C.Z,{onClick:j,className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:n?(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:(null==s?void 0:s.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:n})}),(0,m.jsx)(L.CopyToClipboard,{text:n,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,m.jsxs)(M.Z,{form:r,layout:"vertical",onValuesChange:e=>{"duration"in e&&d(s=>({...s,duration:e.duration}))},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==s?void 0:s.expires)?new Date(s.expires).toLocaleString():"Never"]}),c&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",c]})]})})}function eJ(e){var s,l;let{keyId:t,onClose:a,keyData:r,accessToken:n,userID:i,userRole:o,teams:d,onKeyDataUpdate:c,onDelete:h}=e,[x,p]=(0,u.useState)(!1),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1);if(!r)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(P.Z,{children:"Key not found"})]});let y=async e=>{try{var s,l;if(!n)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let l=JSON.parse(e.metadata);e.metadata={...l,...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),F.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]);let a=await (0,b.Nc)(n,e);c&&c(a),F.ZP.success("Key updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!n)return;await (0,b.I1)(n,r.token),F.ZP.success("Key deleted successfully"),h&&h(),a()}catch(e){console.error("Error deleting the key:",e),F.ZP.error("Failed to delete key")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(O.Z,{children:r.key_alias||"API Key"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:r.token})]}),o&&eZ.LQ.includes(o)&&(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{icon:eV.Z,variant:"secondary",onClick:()=>v(!0),className:"flex items-center",children:"Regenerate Key"}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>f(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,m.jsx)(eH,{selectedToken:r,visible:_,onClose:()=>v(!1),accessToken:n}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>f(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number(r.spend).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",null!==r.max_budget?"$".concat(r.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Key Settings"}),!x&&o&&eZ.LQ.includes(o)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>p(!0),children:"Edit Settings"})]}),x?(0,m.jsx)(eB,{keyData:r,onCancel:()=>p(!1),onSubmit:y,teams:d,accessToken:n,userID:i,userRole:o}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.token})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key Alias"}),(0,m.jsx)(P.Z,{children:r.key_alias||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Secret Key"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.key_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)(P.Z,{children:r.team_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),(0,m.jsx)(P.Z,{children:r.organization_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:new Date(r.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Expires"}),(0,m.jsx)(P.Z,{children:r.expires?new Date(r.expires).toLocaleString():"Never"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Spend"}),(0,m.jsxs)(P.Z,{children:["$",Number(r.spend).toFixed(4)," USD"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsx)(P.Z,{children:null!==r.max_budget?"$".concat(r.max_budget," USD"):"Unlimited"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",null!==r.max_parallel_requests?r.max_parallel_requests:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model TPM Limits: ",(null===(s=r.metadata)||void 0===s?void 0:s.model_tpm_limit)?JSON.stringify(r.metadata.model_tpm_limit):"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model RPM Limits: ",(null===(l=r.metadata)||void 0===l?void 0:l.model_rpm_limit)?JSON.stringify(r.metadata.model_rpm_limit):"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(r.metadata,null,2)})]})]})]})})]})]})]})}var eG=l(2356),eW=e=>{let{options:s,onApplyFilters:l,onResetFilters:t,initialValues:a={},buttonLabel:r="Filters"}=e,[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(a),[c,h]=(0,u.useState)({}),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)({}),f=(0,u.useCallback)(eb()(async(e,s)=>{if(s.isSearchable&&s.searchFn){p(e=>({...e,[s.name]:!0}));try{let l=await s.searchFn(e);h(e=>({...e,[s.name]:l}))}catch(e){console.error("Error searching:",e),h(e=>({...e,[s.name]:[]}))}finally{p(e=>({...e,[s.name]:!1}))}}},300),[]),_=(e,s)=>{let t={...o,[e]:s};d(t),l(t)};return(0,m.jsxs)("div",{className:"w-full",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eG.Z,{className:"h-4 w-4"}),onClick:()=>i(!n),className:"flex items-center gap-2",children:r}),(0,m.jsx)(U.ZP,{onClick:()=>{let e={};s.forEach(s=>{e[s.name]=""}),d(e),t()},children:"Reset Filters"})]}),n&&(0,m.jsx)("div",{className:"grid grid-cols-3 gap-x-6 gap-y-4 mb-6",children:["Team ID","Status","Organization ID","Key Alias","User ID","Key Hash"].map(e=>{let l=s.find(s=>s.label===e||s.name===e);return l?(0,m.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,m.jsx)("label",{className:"text-sm text-gray-600",children:l.label||l.name}),l.isSearchable?(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),onSearch:e=>{j(s=>({...s,[l.name]:e})),l.searchFn&&f(e,l)},filterOption:!1,loading:x[l.name],options:c[l.name]||[],allowClear:!0}):l.options?(0,m.jsx)(D.default,{className:"w-full",placeholder:"Select ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),allowClear:!0,children:l.options.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))}):(0,m.jsx)(z.default,{className:"w-full",placeholder:"Enter ".concat(l.label||l.name,"..."),value:o[l.name]||"",onChange:e=>_(l.name,e.target.value),allowClear:!0})]},l.name):null})})]})},eY=l(16593);let e$=async e=>{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.OD)(e,null,"",null,null,null,l,100),r=a.keys.map(e=>e.key_alias).filter(Boolean);s=[...s,...r],l{if(!e)return[];try{let l=[],t=1,a=!0;for(;a;){let r=await (0,b.It)(e,s||null,null);l=[...l,...r],t{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.r6)(e);s=[...s,...a],l{let[e,s]=(0,u.useState)("http://localhost:4000");return(0,u.useEffect)(()=>{{let{protocol:e,host:l}=window.location;s("".concat(e,"//").concat(l))}},[]),e};function e1(e,s){let l=structuredClone(e);for(let[e,t]of Object.entries(s))e in l&&(l[e]=t);return l}var e2=l(71594),e4=l(24525),e5=l(21626),e3=l(97214),e6=l(28241),e8=l(58834),e7=l(69552),e9=l(71876),se=l(44633),ss=l(86462),sl=l(49084);function st(e){let{keys:s,setKeys:l,isLoading:t=!1,pagination:a,onPageChange:r,pageSize:n=50,teams:i,selectedTeam:o,setSelectedTeam:d,selectedKeyAlias:c,setSelectedKeyAlias:h,accessToken:x,userID:p,userRole:g,organizations:j,setCurrentOrg:f,refresh:_,onSortChange:v,currentSort:y}=e,[Z,N]=(0,u.useState)(null),[w,k]=(0,u.useState)([]),[S,I]=u.useState(()=>y?[{id:y.sortBy,desc:"desc"===y.sortOrder}]:[{id:"created_at",desc:!0}]),{filters:T,filteredKeys:A,allKeyAliases:E,allTeams:P,allOrganizations:O,handleFilterChange:L,handleFilterReset:D}=function(e){let{keys:s,teams:l,organizations:t,accessToken:a}=e,r={"Team ID":"","Organization ID":"","Key Alias":"","User ID":"","Sort By":"created_at","Sort Order":"desc"},[n,i]=(0,u.useState)(r),[o,d]=(0,u.useState)(l||[]),[c,m]=(0,u.useState)(t||[]),[h,x]=(0,u.useState)(s),p=(0,u.useRef)(0),g=(0,u.useCallback)(eb()(async e=>{if(!a)return;let s=Date.now();p.current=s;try{let l=await (0,b.OD)(a,e["Organization ID"]||null,e["Team ID"]||null,e["Key Alias"]||null,e["User ID"]||null,e["Key Hash"]||null,1,25,e["Sort By"]||null,e["Sort Order"]||null);s===p.current&&l&&(x(l.keys),console.log("called from debouncedSearch filters:",JSON.stringify(e)),console.log("called from debouncedSearch data:",JSON.stringify(l)))}catch(e){console.error("Error searching users:",e)}},300),[a]);(0,u.useEffect)(()=>{if(!s){x([]);return}let e=[...s];n["Team ID"]&&(e=e.filter(e=>e.team_id===n["Team ID"])),n["Organization ID"]&&(e=e.filter(e=>e.organization_id===n["Organization ID"])),x(e)},[s,n]),(0,u.useEffect)(()=>{let e=async()=>{let e=await eX(a);e.length>0&&d(e);let s=await eQ(a);s.length>0&&m(s)};a&&e()},[a]);let j=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!a)throw Error("Access token required");return await e$(a)},enabled:!!a}).data||[];return(0,u.useEffect)(()=>{l&&l.length>0&&d(e=>e.length{t&&t.length>0&&m(e=>e.length{i({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||"","Key Alias":e["Key Alias"]||"","User ID":e["User ID"]||"","Sort By":e["Sort By"]||"created_at","Sort Order":e["Sort Order"]||"desc"}),g({...n,...e})},handleFilterReset:()=>{i(r),g(r)}}}({keys:s,teams:i,organizations:j,accessToken:x});(0,u.useEffect)(()=>{if(x){let e=s.map(e=>e.user_id).filter(e=>null!==e);(async()=>{k((await (0,b.Of)(x,e,1,100)).users)})()}},[x,s]),(0,u.useEffect)(()=>{if(_){let e=()=>{_()};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}},[_]);let M=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return s.getCanExpand()?(0,m.jsx)("button",{onClick:s.getToggleExpandedHandler(),style:{cursor:"pointer"},children:s.getIsExpanded()?"▼":"▶"}):null}},{id:"token",accessorKey:"token",header:"Key ID",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>N(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{id:"key_alias",accessorKey:"key_alias",header:"Key Alias",cell:e=>{let s=e.getValue();return(0,m.jsx)(Y.Z,{title:s,children:s?s.length>20?"".concat(s.slice(0,20),"..."):s:"-"})}},{id:"key_name",accessorKey:"key_name",header:"Secret Key",cell:e=>(0,m.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{id:"team_alias",accessorKey:"team_id",header:"Team Alias",cell:e=>{let{row:s,getValue:l}=e,t=l(),a=null==i?void 0:i.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{id:"team_id",accessorKey:"team_id",header:"Team ID",cell:e=>(0,m.jsx)(Y.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{id:"organization_id",accessorKey:"organization_id",header:"Organization ID",cell:e=>e.getValue()?e.renderValue():"-"},{id:"user_email",accessorKey:"user_id",header:"User Email",cell:e=>{let s=e.getValue(),l=w.find(e=>e.user_id===s);return(null==l?void 0:l.user_email)?l.user_email:"-"}},{id:"user_id",accessorKey:"user_id",header:"User ID",cell:e=>{let s=e.getValue();return s?(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsxs)("span",{children:[s.slice(0,7),"..."]})}):"-"}},{id:"created_at",accessorKey:"created_at",header:"Created At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"-"}},{id:"created_by",accessorKey:"created_by",header:"Created By",cell:e=>e.getValue()||"Unknown"},{id:"expires",accessorKey:"expires",header:"Expires",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"spend",accessorKey:"spend",header:"Spend (USD)",cell:e=>Number(e.getValue()).toFixed(4)},{id:"max_budget",accessorKey:"max_budget",header:"Budget (USD)",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{id:"budget_reset_at",accessorKey:"budget_reset_at",header:"Budget Reset",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleString():"Never"}},{id:"models",accessorKey:"models",header:"Models",cell:e=>{let s=e.getValue();return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:s&&s.length>0?s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):"-"})}},{id:"rate_limits",header:"Rate Limits",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:["TPM: ",null!==l.tpm_limit?l.tpm_limit:"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",null!==l.rpm_limit?l.rpm_limit:"Unlimited"]})]})}}];console.log("keys: ".concat(JSON.stringify(s)));let F=(0,e2.b7)({data:A,columns:M.filter(e=>"expander"!==e.id),state:{sorting:S},onSortingChange:e=>{let s="function"==typeof e?e(S):e;if(console.log("newSorting: ".concat(JSON.stringify(s))),I(s),s&&s.length>0){let e=s[0],l=e.id,t=e.desc?"desc":"asc";console.log("sortBy: ".concat(l,", sortOrder: ").concat(t)),L({...T,"Sort By":l,"Sort Order":t}),null==v||v(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,manualSorting:!1});return u.useEffect(()=>{y&&I([{id:y.sortBy,desc:"desc"===y.sortOrder}])},[y]),(0,m.jsx)("div",{className:"w-full h-full overflow-hidden",children:Z?(0,m.jsx)(eJ,{keyId:Z,onClose:()=>N(null),keyData:A.find(e=>e.token===Z),onKeyDataUpdate:e=>{l(s=>s.map(s=>s.token===e.token?e1(s,e):s))},onDelete:()=>{l(e=>e.filter(e=>e.token!==Z))},accessToken:x,userID:p,userRole:g,teams:P}):(0,m.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,m.jsx)("div",{className:"w-full mb-6",children:(0,m.jsx)(eW,{options:[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>P&&0!==P.length?P.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:async e=>O&&0!==O.length?O.filter(s=>{var l,t;return null!==(t=null===(l=s.organization_id)||void 0===l?void 0:l.toLowerCase().includes(e.toLowerCase()))&&void 0!==t&&t}).filter(e=>null!==e.organization_id&&void 0!==e.organization_id).map(e=>({label:"".concat(e.organization_id||"Unknown"," (").concat(e.organization_id,")"),value:e.organization_id})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>E.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))},{name:"User ID",label:"User ID",isSearchable:!1},{name:"Key Hash",label:"Key Hash",isSearchable:!1}],onApplyFilters:L,initialValues:T,onResetFilters:D})}),(0,m.jsxs)("div",{className:"flex items-center justify-between w-full mb-4",children:[(0,m.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",t?"...":"".concat((a.currentPage-1)*n+1," - ").concat(Math.min(a.currentPage*n,a.totalCount))," of ",t?"...":a.totalCount," results"]}),(0,m.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",t?"...":a.currentPage," of ",t?"...":a.totalPages]}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage-1),disabled:t||1===a.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage+1),disabled:t||a.currentPage===a.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]}),(0,m.jsx)("div",{className:"h-[75vh] overflow-auto",children:(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:F.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading keys..."})})})}):A.length>0?F.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No keys found"})})})})})]})})})})]})})}console.log=function(){};var sa=e=>{let{userID:s,userRole:l,accessToken:t,selectedTeam:a,setSelectedTeam:r,data:n,setData:i,teams:o,premiumUser:d,currentOrg:c,organizations:h,setCurrentOrg:x,selectedKeyAlias:p,setSelectedKeyAlias:g,createClicked:j}=e,[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(null),[w,T]=(0,u.useState)(null),[A,E]=(0,u.useState)(null),[D,q]=(0,u.useState)((null==a?void 0:a.team_id)||"");(0,u.useEffect)(()=>{q((null==a?void 0:a.team_id)||"")},[a]);let{keys:U,isLoading:z,error:V,pagination:K,refresh:H,setKeys:J}=eP({selectedTeam:a,currentOrg:c,selectedKeyAlias:p,accessToken:t,createClicked:j}),[W,Y]=(0,u.useState)(!1),[$,X]=(0,u.useState)(!1),[Q,ee]=(0,u.useState)(null),[es,el]=(0,u.useState)([]),et=new Set,[ea,er]=(0,u.useState)(!1),[en,ei]=(0,u.useState)(!1),[eo,ed]=(0,u.useState)(null),[ec,em]=(0,u.useState)(null),[eu]=M.Z.useForm(),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)(et),[ej,ef]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",Q),(null==ec?void 0:ec.duration)?ex((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(ec.duration)):ex(null),console.log("calculateNewExpiryTime:",eh)},[Q,null==ec?void 0:ec.duration]),(0,u.useEffect)(()=>{(async()=>{try{if(null===s||null===l||null===t)return;let e=await B(s,l,t);e&&el(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,s,l]),(0,u.useEffect)(()=>{if(o){let e=new Set;o.forEach((s,l)=>{let t=s.team_id;e.add(t)}),eg(e)}},[o]);let e_=async()=>{if(null!=Z&&null!=n){try{await (0,b.I1)(t,Z);let e=n.filter(e=>e.token!==Z);i(e)}catch(e){console.error("Error deleting the key:",e)}y(!1),N(null)}},ev=(e,s)=>{em(l=>({...l,[e]:s}))},ey=async()=>{if(!d){F.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=Q)try{let e=await eu.validateFields(),s=await (0,b.s0)(t,Q.token,e);if(ed(s.key),n){let l=n.map(l=>l.token===(null==Q?void 0:Q.token)?{...l,key_name:s.key_name,...e}:l);i(l)}ei(!1),eu.resetFields(),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key")}};return(0,m.jsxs)("div",{children:[(0,m.jsx)(st,{keys:U,setKeys:J,isLoading:z,pagination:K,onPageChange:e=>{H({page:e})},pageSize:100,teams:o,selectedTeam:a,setSelectedTeam:r,accessToken:t,userID:s,userRole:l,organizations:h,setCurrentOrg:x,refresh:H,selectedKeyAlias:p,setSelectedKeyAlias:g}),v&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{y(!1),N(null)},children:"Cancel"})]})]})]})}),(0,m.jsx)(R.Z,{title:"Regenerate API Key",visible:en,onCancel:()=>{ei(!1),eu.resetFields()},footer:[(0,m.jsx)(C.Z,{onClick:()=>{ei(!1),eu.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:ey,disabled:!d,children:d?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:d?(0,m.jsxs)(M.Z,{form:eu,layout:"vertical",onValuesChange:(e,s)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==Q?void 0:Q.expires)!=null?new Date(Q.expires).toLocaleString():"Never"]}),eh&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",eh]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),eo&&(0,m.jsx)(R.Z,{visible:!!eo,onCancel:()=>ed(null),footer:[(0,m.jsx)(C.Z,{onClick:()=>ed(null),children:"Close"},"close")],children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==Q?void 0:Q.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:eo})}),(0,m.jsx)(L.CopyToClipboard,{text:eo,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},sr=l(12011);console.log=function(){},console.log("isLocal:",!1);var sn=e=>{let{userID:s,userRole:l,teams:t,keys:a,setUserRole:r,userEmail:n,setUserEmail:i,setTeams:o,setKeys:d,premiumUser:c,organizations:p,addKey:g,createClicked:j}=e,[f,_]=(0,u.useState)(null),[v,Z]=(0,u.useState)(null),N=(0,h.useSearchParams)(),C=function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token"),I=N.get("invitation_id"),[T,A]=(0,u.useState)(null),[E,P]=(0,u.useState)(null),[O,L]=(0,u.useState)([]),[D,M]=(0,u.useState)(null),[F,R]=(0,u.useState)(null),[q,U]=(0,u.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,u.useEffect)(()=>{if(C){let e=(0,x.o)(C);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),A(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),r(s)}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e))}}if(s&&T&&l&&!a&&!f){let e=sessionStorage.getItem("userModels"+s);e?L(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(v))),(async()=>{try{let e=await (0,b.g)(T);M(e);let t=await (0,b.Br)(T,s,l,!1,null,null);_(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(f))),(null==t?void 0:t.teams[0].keys)?d(t.keys.concat(t.teams.filter(e=>"Admin"===l||e.user_id===s).flatMap(e=>e.keys))):d(t.keys),sessionStorage.setItem("userData"+s,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+s,JSON.stringify(t.user_info));let a=(await (0,b.So)(T,s,l)).data.map(e=>e.id);console.log("available_model_names:",a),L(a),console.log("userModels:",O),sessionStorage.setItem("userModels"+s,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e),e.message.includes("Invalid proxy server token passed")&&z()}})(),w(T,s,l,v,o))}},[s,C,T,a,l]),(0,u.useEffect)(()=>{T&&(async()=>{try{let e=await (0,b.e2)(T,[T]);console.log("keyInfo: ",e)}catch(e){e.message.includes("Invalid proxy server token passed")&&z()}})()},[T]),(0,u.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(v),", accessToken: ").concat(T,", userID: ").concat(s,", userRole: ").concat(l)),T&&(console.log("fetching teams"),w(T,s,l,v,o))},[v]),(0,u.useEffect)(()=>{if(null!==a&&null!=F&&null!==F.team_id){let e=0;for(let s of(console.log("keys: ".concat(JSON.stringify(a))),a))F.hasOwnProperty("team_id")&&null!==s.team_id&&s.team_id===F.team_id&&(e+=s.spend);console.log("sum: ".concat(e)),P(e)}else if(null!==a){let e=0;for(let s of a)e+=s.spend;P(e)}},[F]),null!=I)return(0,m.jsx)(sr.default,{});function z(){(0,y.b)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return console.log("All cookies before redirect:",document.cookie),z(),null;try{let e=(0,x.o)(C);console.log("Decoded token:",e);let s=e.exp,l=Math.floor(Date.now()/1e3);if(s&&l>=s){console.log("Token expired, redirecting to login"),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL for expired token:",e),window.location.href=e,null}}catch(s){console.error("Error decoding token:",s),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL after token decode error:",e),window.location.href=e,null}if(null==T)return null;if(null==s)return(0,m.jsx)("h1",{children:"User ID is not set"});if(null==l&&r("App Owner"),l&&"Admin Viewer"==l){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",F),console.log("All cookies after redirect:",document.cookie),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(k.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,m.jsx)(eA,{userID:s,team:F,teams:t,userRole:l,accessToken:T,data:a,addKey:g},F?F.team_id:null),(0,m.jsx)(sa,{userID:s,userRole:l,accessToken:T,selectedTeam:F||null,setSelectedTeam:R,selectedKeyAlias:q,setSelectedKeyAlias:U,data:a,setData:d,premiumUser:c,teams:t,currentOrg:v,setCurrentOrg:Z,organizations:p,createClicked:j})]})})})},si=l(97765);(t=i||(i={})).OpenAI="OpenAI",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.OpenAI_Text="OpenAI Text Completion",t.OpenAI_Text_Compatible="OpenAI-Compatible Text Completion Models (Together AI, etc.)",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI",t.Cerebras="Cerebras",t.Sambanova="Sambanova",t.Perplexity="Perplexity",t.TogetherAI="TogetherAI",t.Openrouter="Openrouter",t.FireworksAI="Fireworks AI",t.Triton="Triton";let so={OpenAI:"openai",OpenAI_Text:"text-completion-openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",OpenAI_Text_Compatible:"text-completion-openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai",Cerebras:"cerebras",Sambanova:"sambanova",Perplexity:"perplexity",TogetherAI:"together_ai",Openrouter:"openrouter",FireworksAI:"fireworks_ai",Triton:"triton"},sd="/ui/assets/logos/",sc={Anthropic:"".concat(sd,"anthropic.svg"),AssemblyAI:"".concat(sd,"assemblyai_small.png"),Azure:"".concat(sd,"microsoft_azure.svg"),"Azure AI Foundry (Studio)":"".concat(sd,"microsoft_azure.svg"),"Amazon Bedrock":"".concat(sd,"bedrock.svg"),Cerebras:"".concat(sd,"cerebras.svg"),Cohere:"".concat(sd,"cohere.svg"),Databricks:"".concat(sd,"databricks.svg"),Deepseek:"".concat(sd,"deepseek.svg"),"Fireworks AI":"".concat(sd,"fireworks.svg"),Groq:"".concat(sd,"groq.svg"),"Google AI Studio":"".concat(sd,"google.svg"),"Mistral AI":"".concat(sd,"mistral.svg"),Ollama:"".concat(sd,"ollama.svg"),OpenAI:"".concat(sd,"openai_small.svg"),"OpenAI Text Completion":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Text Completion Models (Together AI, etc.)":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Endpoints (Together AI, etc.)":"".concat(sd,"openai_small.svg"),Openrouter:"".concat(sd,"openrouter.svg"),Perplexity:"".concat(sd,"perplexity-ai.svg"),Sambanova:"".concat(sd,"sambanova.svg"),TogetherAI:"".concat(sd,"togetherai.svg"),"Vertex AI (Anthropic, Gemini, etc.)":"".concat(sd,"google.svg"),xAI:"".concat(sd,"xai.svg"),Triton:"".concat(sd,"nvidia_triton.png")},sm=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:sc[e],displayName:e}}let s=Object.keys(so).find(s=>so[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=i[s];return{logo:sc[l],displayName:l}},su=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",sh=(e,s)=>{console.log("Provider key: ".concat(e));let l=so[e];console.log("Provider mapped to: ".concat(l));let t=[];return e&&"object"==typeof s&&(Object.entries(s).forEach(e=>{let[s,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===l||a.litellm_provider.includes(l))&&t.push(s)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(s).forEach(e=>{let[s,l]=e;null!==l&&"object"==typeof l&&"litellm_provider"in l&&"cohere"===l.litellm_provider&&t.push(s)}))),t},sx=async(e,s,l)=>{try{console.log("handling submit for formValues:",e);let s=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=so[e.custom_llm_provider]+"/*";e.model_name=l,s.push({public_name:l,litellm_model:l}),e.model=l}let l=[];for(let t of s){let s={},a={},r=t.public_name;for(let[l,r]of(s.model=t.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),s.model=t.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l&&"cache_control"!==l){if("model_name"==l)s.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=so[r];s.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("mode"==l)console.log("placing mode in modelInfo"),a.mode=r,delete s.mode;else if("custom_model_name"===l)s.model=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[s,l]of Object.entries(e))a[s]=l}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(s[l]=Number(r));continue}else s[l]=r}l.push({litellmParamsObj:s,modelInfoObj:a,modelName:r})}return l}catch(e){F.ZP.error("Failed to create model: "+e,10)}},sp=async(e,s,l,t)=>{try{let a=await sx(e,s,l);if(!a||0===a.length)return;for(let e of a){let{litellmParamsObj:l,modelInfoObj:t,modelName:a}=e,r={model_name:a,litellm_params:l,model_info:t},n=await (0,b.kK)(s,r);console.log("response for model create call: ".concat(n.data))}t&&t(),l.resetFields()}catch(e){F.ZP.error("Failed to add model: "+e,10)}};var sg=l(53410),sj=l(47451),sf=l(69410);let{Link:s_}=et.default,sv={[i.OpenAI]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.OpenAI_Text]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.Vertex_AI]:[{key:"vertex_project",label:"Vertex Project",placeholder:"adroit-cadet-1234..",required:!0},{key:"vertex_location",label:"Vertex Location",placeholder:"us-east-1",required:!0},{key:"vertex_credentials",label:"Vertex Credentials",required:!0,type:"upload"}],[i.AssemblyAI]:[{key:"api_base",label:"API Base",type:"select",required:!0,options:["https://api.assemblyai.com","https://api.eu.assemblyai.com"]},{key:"api_key",label:"AssemblyAI API Key",type:"password",required:!0}],[i.Azure]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_version",label:"API Version",placeholder:"2023-07-01-preview",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here"},{key:"base_model",label:"Base Model",placeholder:"azure/gpt-3.5-turbo"},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[i.Azure_AI_Studio]:[{key:"api_base",label:"API Base",placeholder:"https://.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",tooltip:"Enter your full Target URI from Azure Foundry here. Example: https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",required:!0},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[i.OpenAI_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.OpenAI_Text_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[i.Bedrock]:[{key:"aws_access_key_id",label:"AWS Access Key ID",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[i.Ollama]:[{key:"api_base",label:"API Base",placeholder:"http://localhost:11434",defaultValue:"http://localhost:11434",required:!1,tooltip:"The base URL for your Ollama server. Defaults to http://localhost:11434 if not specified."}],[i.Anthropic]:[{key:"api_key",label:"API Key",placeholder:"sk-",type:"password",required:!0}],[i.Google_AI_Studio]:[{key:"api_key",label:"API Key",placeholder:"aig-",type:"password",required:!0}],[i.Groq]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.MistralAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Deepseek]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Cohere]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Databricks]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.xAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Cerebras]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Sambanova]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Perplexity]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.TogetherAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Openrouter]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.FireworksAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[i.Triton]:[{key:"api_key",label:"API Key",type:"password",required:!1},{key:"api_base",label:"API Base",placeholder:"http://localhost:8000/generate",required:!1}]};var sy=e=>{let{selectedProvider:s,uploadProps:l}=e,t=i[s],a=M.Z.useFormInstance(),r=u.useMemo(()=>sv[t]||[],[t]),n={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Setting field value from JSON, length: ".concat(s.length)),a.setFieldsValue({vertex_credentials:s}),console.log("Form values after setting:",a.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered in ProviderSpecificFields"),console.log("Current form values:",a.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList)}};return(0,m.jsx)(m.Fragment,{children:r.map(e=>{var s;return(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:e.label,name:e.key,rules:e.required?[{required:!0,message:"Required"}]:void 0,tooltip:e.tooltip,className:"vertex_credentials"===e.key?"mb-0":void 0,children:"select"===e.type?(0,m.jsx)(D.default,{placeholder:e.placeholder,defaultValue:e.defaultValue,children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"upload"===e.type?(0,m.jsx)(er.Z,{...n,onChange:s=>{(null==l?void 0:l.onChange)&&l.onChange(s),setTimeout(()=>{let s=a.getFieldValue(e.key);console.log("".concat(e.key," value after upload:"),JSON.stringify(s))},500)},children:(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eu.Z,{}),children:"Click to Upload"})}):(0,m.jsx)(I.Z,{placeholder:e.placeholder,type:"password"===e.type?"password":"text"})}),"vertex_credentials"===e.key&&(0,m.jsx)(sj.Z,{children:(0,m.jsx)(sf.Z,{children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Give a gcp service account(.json file)"})})}),"base_model"===e.key&&(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,m.jsx)(s_,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]},e.key)})})};let{Title:sb,Link:sZ}=et.default;var sN=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,onUpdateCredential:a,uploadProps:r,addOrEdit:n,existingCredential:o}=e,[d]=M.Z.useForm(),[c,h]=(0,u.useState)(i.OpenAI),[x,p]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{o&&(d.setFieldsValue({credential_name:o.credential_name,custom_llm_provider:o.credential_info.custom_llm_provider,api_base:o.credential_values.api_base,api_version:o.credential_values.api_version,base_model:o.credential_values.base_model,api_key:o.credential_values.api_key}),h(o.credential_info.custom_llm_provider))},[o]),(0,m.jsx)(R.Z,{title:"add"===n?"Add New Credential":"Edit Credential",visible:s,onCancel:()=>{l(),d.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:d,onFinish:e=>{"add"===n?t(e):a(e),d.resetFields()},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==o?void 0:o.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials",disabled:null!=o&&!!o.credential_name})}),(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"Helper to auto-populate provider specific fields",children:(0,m.jsx)(D.default,{onChange:e=>{h(e),d.setFieldValue("custom_llm_provider",e)},children:Object.entries(i).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(sy,{selectedProvider:c,uploadProps:r}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sZ,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),d.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"add"===n?"Add Credential":"Update Credential"})]})]})]})})},sw=e=>{let{accessToken:s,uploadProps:l,credentialList:t,fetchCredentials:a}=e,[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(null),[h]=M.Z.useForm(),x=["credential_name","custom_llm_provider"],p=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.eZ)(s,e.credential_name,t),F.ZP.success("Credential updated successfully"),o(!1),a(s)},g=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.oC)(s,t),F.ZP.success("Credential added successfully"),n(!1),a(s)};(0,u.useEffect)(()=>{s&&a(s)},[s]);let j=e=>{let s={openai:"blue",azure:"indigo",anthropic:"purple",default:"gray"},l=s[e.toLowerCase()]||s.default;return(0,m.jsx)(eL.Z,{color:l,size:"xs",children:e})},f=async e=>{s&&(await (0,b.gX)(s,e),F.ZP.success("Credential deleted successfully"),a(s))};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)(P.Z,{children:["Configured credentials for different AI providers. Add and manage your API credentials."," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/credentials",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]})}),(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Credential Name"}),(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Description"})]})}),(0,m.jsx)(e3.Z,{children:t&&0!==t.length?t.map((e,s)=>{var l,t;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.credential_name}),(0,m.jsx)(e6.Z,{children:j((null===(l=e.credential_info)||void 0===l?void 0:l.custom_llm_provider)||"-")}),(0,m.jsx)(e6.Z,{children:(null===(t=e.credential_info)||void 0===t?void 0:t.description)||"-"}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{icon:sg.Z,variant:"light",size:"sm",onClick:()=>{c(e),o(!0)}}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"light",size:"sm",onClick:()=>f(e.credential_name)})]})]},s)}):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:4,className:"text-center py-4 text-gray-500",children:"No credentials configured"})})})]})}),(0,m.jsx)(C.Z,{onClick:()=>n(!0),className:"mt-4",children:"Add Credential"}),r&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:r,onCancel:()=>n(!1),uploadProps:l,addOrEdit:"add",onUpdateCredential:p,existingCredential:null}),i&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:i,existingCredential:d,onUpdateCredential:p,uploadProps:l,onCancel:()=>o(!1),addOrEdit:"edit"})]})};let sk=e=>{var s;return(null==e?void 0:null===(s=e.model_info)||void 0===s?void 0:s.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"};var sS=l(53003),sC=l(47323),sI=l(75105),sT=l(40278),sA=l(14301),sE=l(59664),sP=e=>{let{modelMetrics:s,modelMetricsCategories:l,customTooltip:t,premiumUser:a}=e;return(0,m.jsx)(sE.Z,{title:"Time to First token (s)",className:"h-72",data:s,index:"date",showLegend:!1,categories:l,colors:["indigo","rose"],connectNulls:!0,customTooltip:t})},sO=e=>{let{teamData:s,canEditTeam:l,handleMemberDelete:t,setSelectedEditMember:a,setIsEditMemberModalVisible:r,setIsAddMemberModalVisible:n}=e;return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"User Email"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:s.team_info.members_with_roles.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_email})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.role})}),(0,m.jsx)(e6.Z,{children:l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{a(e),r(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(e)})]})})]},s))})]})}),(0,m.jsx)(C.Z,{onClick:()=>n(!0),children:"Add Member"})]})},sL=l(61994),sD=l(85180),sM=l(89245),sF=l(78355);let sR={"/key/generate":"Member can generate a virtual key for this team","/key/update":"Member can update a virtual key belonging to this team","/key/delete":"Member can delete a virtual key belonging to this team","/key/info":"Member can get info about a virtual key belonging to this team","/key/regenerate":"Member can regenerate a virtual key belonging to this team","/key/{key_id}/regenerate":"Member can regenerate a virtual key belonging to this team","/key/list":"Member can list virtual keys belonging to this team","/key/block":"Member can block a virtual key belonging to this team","/key/unblock":"Member can unblock a virtual key belonging to this team"},sq=e=>e.includes("/info")||e.includes("/list")?"GET":"POST",sU=e=>{let s=sq(e),l=sR[e];if(!l){for(let[s,t]of Object.entries(sR))if(e.includes(s)){l=t;break}}return l||(l="Access ".concat(e)),{method:s,endpoint:e,description:l,route:e}};var sz=e=>{let{teamId:s,accessToken:l,canEditTeam:t}=e,[a,r]=(0,u.useState)([]),[n,i]=(0,u.useState)([]),[o,d]=(0,u.useState)(!0),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),g=async()=>{try{if(d(!0),!l)return;let e=await (0,b.aC)(l,s),t=e.all_available_permissions||[];r(t);let a=e.team_member_permissions||[];i(a),p(!1)}catch(e){F.ZP.error("Failed to load permissions"),console.error("Error fetching permissions:",e)}finally{d(!1)}};(0,u.useEffect)(()=>{g()},[s,l]);let j=(e,s)=>{i(s?[...n,e]:n.filter(s=>s!==e)),p(!0)},f=async()=>{try{if(!l)return;h(!0),await (0,b.TF)(l,s,n),F.ZP.success("Permissions updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update permissions"),console.error("Error updating permissions:",e)}finally{h(!1)}};if(o)return(0,m.jsx)("div",{className:"p-6 text-center",children:"Loading permissions..."});let _=a.length>0;return(0,m.jsxs)(eD.Z,{className:"bg-white shadow-md rounded-md p-6",children:[(0,m.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center border-b pb-4 mb-6",children:[(0,m.jsx)(O.Z,{className:"mb-2 sm:mb-0",children:"Member Permissions"}),t&&x&&(0,m.jsxs)("div",{className:"flex gap-3",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(sM.Z,{}),onClick:()=>{g()},children:"Reset"}),(0,m.jsxs)(C.Z,{onClick:f,loading:c,className:"flex items-center gap-2",children:[(0,m.jsx)(sF.Z,{})," Save Changes"]})]})]}),(0,m.jsx)(P.Z,{className:"mb-6 text-gray-600",children:"Control what team members can do when they are not team admins."}),_?(0,m.jsxs)(e5.Z,{className:"mt-4",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Method"}),(0,m.jsx)(e7.Z,{children:"Endpoint"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Access"})]})}),(0,m.jsx)(e3.Z,{children:a.map(e=>{let s=sU(e);return(0,m.jsxs)(e9.Z,{className:"hover:bg-gray-50 transition-colors",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat("GET"===s.method?"bg-blue-100 text-blue-800":"bg-green-100 text-green-800"),children:s.method})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"font-mono text-sm text-gray-800",children:s.endpoint})}),(0,m.jsx)(e6.Z,{className:"text-gray-700",children:s.description}),(0,m.jsx)(e6.Z,{className:"text-right",children:(0,m.jsx)(sL.Z,{checked:n.includes(e),onChange:s=>j(e,s.target.checked),disabled:!t})})]},e)})})]}):(0,m.jsx)("div",{className:"py-12",children:(0,m.jsx)(sD.Z,{description:"No permissions available"})})]})},sV=e=>{var s,l,t;let{visible:a,onCancel:r,onSubmit:n,initialData:i,mode:o,config:d}=e,[c]=M.Z.useForm();console.log("Initial Data:",i),(0,u.useEffect)(()=>{if(a){if("edit"===o&&i)c.setFieldsValue({...i,role:i.role||d.defaultRole});else{var e;c.resetFields(),c.setFieldsValue({role:d.defaultRole||(null===(e=d.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,i,o,c,d.defaultRole,d.roleOptions]);let h=async e=>{try{let s=Object.entries(e).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:"string"==typeof t?t.trim():t}},{});n(s),c.resetFields(),F.ZP.success("Successfully ".concat("add"===o?"added":"updated"," member"))}catch(e){F.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var s;return(0,m.jsx)(D.default,{children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,m.jsx)(R.Z,{title:d.title||("add"===o?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:r,children:(0,m.jsxs)(M.Z,{form:c,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[d.showEmail&&(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),d.showEmail&&d.showUserId&&(0,m.jsx)("div",{className:"text-center mb-4",children:(0,m.jsx)(P.Z,{children:"OR"})}),d.showUserId&&(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"Role"}),"edit"===o&&i&&(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(l=i.role,(null===(t=d.roleOptions.find(e=>e.value===l))||void 0===t?void 0:t.label)||l),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,m.jsx)(D.default,{children:"edit"===o&&i?[...d.roleOptions.filter(e=>e.value===i.role),...d.roleOptions.filter(e=>e.value!==i.role)].map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value)):d.roleOptions.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))})}),null===(s=d.additionalFields)||void 0===s?void 0:s.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,m.jsxs)("div",{className:"text-right mt-6",children:[(0,m.jsx)(U.ZP,{onClick:r,className:"mr-2",children:"Cancel"}),(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"add"===o?"Add Member":"Save Changes"})]})]})})},sK=e=>{let{isVisible:s,onCancel:l,onSubmit:t,accessToken:a,title:r="Add Team Member",roles:n=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:i="user"}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p,g]=(0,u.useState)("user_email"),j=async(e,s)=>{if(!e){c([]);return}x(!0);try{let l=new URLSearchParams;if(l.append(s,e),null==a)return;let t=(await (0,b.u5)(a,l)).map(e=>({label:"user_email"===s?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===s?e.user_email:e.user_id,user:e}));c(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},f=(0,u.useCallback)(eb()((e,s)=>j(e,s),300),[]),_=(e,s)=>{g(s),f(e,s)},v=(e,s)=>{let l=s.user;o.setFieldsValue({user_email:l.user_email,user_id:l.user_id,role:o.getFieldValue("role")})};return(0,m.jsx)(R.Z,{title:r,open:s,onCancel:()=>{o.resetFields(),c([]),l()},footer:null,width:800,children:(0,m.jsxs)(M.Z,{form:o,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:i},children:[(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>_(e,"user_email"),onSelect:(e,s)=>v(e,s),options:"user_email"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>_(e,"user_id"),onSelect:(e,s)=>v(e,s),options:"user_id"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:i,children:n.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:(0,m.jsxs)(Y.Z,{title:e.description,children:[(0,m.jsx)("span",{className:"font-medium",children:e.label}),(0,m.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,m.jsx)("div",{className:"text-right mt-4",children:(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},sB=e=>{var s;let{teamId:l,onClose:t,accessToken:a,is_team_admin:r,is_proxy_admin:n,userModels:i,editTeam:o}=e,[d,c]=(0,u.useState)(null),[h,x]=(0,u.useState)(!0),[p,g]=(0,u.useState)(!1),[j]=M.Z.useForm(),[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),[Z,N]=(0,u.useState)(!1);console.log("userModels in team info",i);let w=r||n,k=async()=>{try{if(x(!0),!a)return;let e=await (0,b.Xm)(a,l);c(e)}catch(e){F.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,u.useEffect)(()=>{k()},[l,a]);let I=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.cu)(a,l,s),F.ZP.success("Team member added successfully"),g(!1),j.resetFields(),k()}catch(e){F.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},T=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.sN)(a,l,s),F.ZP.success("Team member updated successfully"),_(!1),k()}catch(e){F.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},A=async e=>{try{if(null==a)return;await (0,b.Lp)(a,l,e),F.ZP.success("Team member removed successfully"),k()}catch(e){F.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},E=async e=>{try{if(!a)return;let s={};try{s=e.metadata?JSON.parse(e.metadata):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}let t={team_id:l,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...s,guardrails:e.guardrails||[]},organization_id:e.organization_id};await (0,b.Gh)(a,t),F.ZP.success("Team settings updated successfully"),N(!1),k()}catch(e){console.error("Error updating team:",e)}};if(h)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==d?void 0:d.team_info))return(0,m.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:L}=d;return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:L.team_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:L.team_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:o?3:0,children:[(0,m.jsx)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),...w?[(0,m.jsx)(eM.Z,{children:"Members"},"members"),(0,m.jsx)(eM.Z,{children:"Member Permissions"},"member-permissions"),(0,m.jsx)(eM.Z,{children:"Settings"},"settings")]:[]]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",L.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===L.max_budget?"Unlimited":"$".concat(L.max_budget)]}),L.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",L.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",L.rpm_limit||"Unlimited"]}),L.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",L.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sO,{teamData:d,canEditTeam:w,handleMemberDelete:A,setSelectedEditMember:y,setIsEditMemberModalVisible:_,setIsAddMemberModalVisible:g})}),w&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sz,{teamId:l,accessToken:a,canEditTeam:w})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Team Settings"}),w&&!Z&&(0,m.jsx)(C.Z,{onClick:()=>N(!0),children:"Edit Settings"})]}),Z?(0,m.jsxs)(M.Z,{form:j,onFinish:E,initialValues:{...L,team_alias:L.team_alias,models:L.models,tpm_limit:L.tpm_limit,rpm_limit:L.rpm_limit,max_budget:L.max_budget,budget_duration:L.budget_duration,guardrails:(null===(s=L.metadata)||void 0===s?void 0:s.guardrails)||[],metadata:L.metadata?JSON.stringify(L.metadata,null,2):"",organization_id:L.organization_id},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),i.map((e,s)=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},s))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>N(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team Name"}),(0,m.jsx)("div",{children:L.team_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"font-mono",children:L.team_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(L.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",L.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==L.max_budget?"$".concat(L.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",L.budget_duration||"Never"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{children:L.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Status"}),(0,m.jsx)(eL.Z,{color:L.blocked?"red":"green",children:L.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,m.jsx)(sV,{visible:f,onCancel:()=>_(!1),onSubmit:T,initialData:v,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,m.jsx)(sK,{isVisible:p,onCancel:()=>g(!1),onSubmit:I,accessToken:a})]})},sH=l(45589);let{Title:sJ,Link:sG}=et.default;var sW=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,existingCredential:a,setIsCredentialModalOpen:r}=e,[n]=M.Z.useForm();return console.log("existingCredential in add credentials tab: ".concat(JSON.stringify(a))),(0,m.jsx)(R.Z,{title:"Reuse Credentials",visible:s,onCancel:()=>{l(),n.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:n,onFinish:e=>{t(e),n.resetFields(),r(!1)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==a?void 0:a.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials"})}),Object.entries((null==a?void 0:a.credential_values)||{}).map(e=>{let[s,l]=e;return(0,m.jsx)(M.Z.Item,{label:s,name:s,initialValue:l,children:(0,m.jsx)(I.Z,{placeholder:"Enter ".concat(s),disabled:!0})},s)}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sG,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),n.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Reuse Credentials"})]})]})]})})},sY=l(63709),s$=l(45246),sX=l(96473);let{Text:sQ}=et.default;var s0=e=>{let{form:s,showCacheControl:l,onCacheControlChange:t}=e,a=e=>{let l=s.getFieldValue("litellm_extra_params");try{let t=l?JSON.parse(l):{};e.length>0?t.cache_control_injection_points=e:delete t.cache_control_injection_points,Object.keys(t).length>0?s.setFieldValue("litellm_extra_params",JSON.stringify(t,null,2)):s.setFieldValue("litellm_extra_params","")}catch(e){console.error("Error updating cache control points:",e)}};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Cache Control Injection Points",name:"cache_control",valuePropName:"checked",className:"mb-4",tooltip:"Tell litellm where to inject cache control checkpoints. You can specify either by role (to apply to all messages of that role) or by specific message index.",children:(0,m.jsx)(sY.Z,{onChange:t,className:"bg-gray-600"})}),l&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(sQ,{className:"text-sm text-gray-500 block mb-4",children:"Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature."}),(0,m.jsx)(M.Z.List,{name:"cache_control_injection_points",initialValue:[{location:"message"}],children:(e,l)=>{let{add:t,remove:r}=l;return(0,m.jsxs)(m.Fragment,{children:[e.map((l,t)=>(0,m.jsxs)("div",{className:"flex items-center mb-4 gap-4",children:[(0,m.jsx)(M.Z.Item,{...l,label:"Type",name:[l.name,"location"],initialValue:"message",className:"mb-0",style:{width:"180px"},children:(0,m.jsx)(D.default,{disabled:!0,options:[{value:"message",label:"Message"}]})}),(0,m.jsx)(M.Z.Item,{...l,label:"Role",name:[l.name,"role"],className:"mb-0",style:{width:"180px"},tooltip:"LiteLLM will mark all messages of this role as cacheable",children:(0,m.jsx)(D.default,{placeholder:"Select a role",allowClear:!0,options:[{value:"user",label:"User"},{value:"system",label:"System"},{value:"assistant",label:"Assistant"}],onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),(0,m.jsx)(M.Z.Item,{...l,label:"Index",name:[l.name,"index"],className:"mb-0",style:{width:"180px"},tooltip:"(Optional) If set litellm will mark the message at this index as cacheable",children:(0,m.jsx)(K,{type:"number",placeholder:"Optional",step:1,min:0,onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),e.length>1&&(0,m.jsx)(s$.Z,{className:"text-red-500 cursor-pointer text-lg ml-12",onClick:()=>{r(l.name),setTimeout(()=>{a(s.getFieldValue("cache_control_points"))},0)}})]},l.key)),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full border border-dashed border-gray-300 py-2 px-4 text-gray-600 hover:text-blue-600 hover:border-blue-300 transition-all rounded",onClick:()=>t(),children:[(0,m.jsx)(sX.Z,{className:"mr-2"}),"Add Injection Point"]})})]})}})]})]})};function s1(e){var s,l,t,a,r,n,i,o,d,c,h,x,p,g,j,f,_,v,y,Z,N;let{modelId:w,onClose:k,modelData:T,accessToken:A,userID:E,userRole:L,editModel:D,setEditModalVisible:q,setSelectedModel:z,onModelUpdate:V}=e,[B]=M.Z.useForm(),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)(!1),[X,Q]=(0,u.useState)(!1),[ee,es]=(0,u.useState)(!1),[el,et]=(0,u.useState)(!1),[ea,er]=(0,u.useState)(null),[en,ei]=(0,u.useState)(!1),eo="Admin"===L||T.model_info.created_by===E,ed=(null===(s=T.litellm_params)||void 0===s?void 0:s.litellm_credential_name)!=null&&(null===(l=T.litellm_params)||void 0===l?void 0:l.litellm_credential_name)!=void 0;console.log("usingExistingCredential, ",ed),console.log("modelData.litellm_params.litellm_credential_name, ",T.litellm_params.litellm_credential_name),(0,u.useEffect)(()=>{let e=async()=>{var e;if(!A)return;let s=await (0,b.ix)(A,w);console.log("modelInfoResponse, ",s);let l=s.data[0];J(l),(null==l?void 0:null===(e=l.litellm_params)||void 0===e?void 0:e.cache_control_injection_points)&&ei(!0)};(async()=>{if(console.log("accessToken, ",A),!A||ed)return;let e=await (0,b.Qg)(A,null,w);console.log("existingCredentialResponse, ",e),er({credential_name:e.credential_name,credential_values:e.credential_values,credential_info:e.credential_info})})(),e()},[A,w]);let ec=async e=>{var s;if(console.log("values, ",e),!A)return;let l={credential_name:e.credential_name,model_id:w,credential_info:{custom_llm_provider:null===(s=H.litellm_params)||void 0===s?void 0:s.custom_llm_provider}};F.ZP.info("Storing credential.."),console.log("credentialResponse, ",await (0,b.oC)(A,l)),F.ZP.success("Credential stored successfully")},em=async e=>{try{var s;if(!A)return;es(!0),console.log("values.model_name, ",e.model_name);let l={...H.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6};e.cache_control&&(null===(s=e.cache_control_injection_points)||void 0===s?void 0:s.length)>0?l.cache_control_injection_points=e.cache_control_injection_points:delete l.cache_control_injection_points;let t={model_name:e.model_name,litellm_params:l,model_info:{id:w}};await (0,b.$D)(A,t,w);let a={...H,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l};J(a),V&&V(a),F.ZP.success("Model settings updated successfully"),Q(!1),et(!1)}catch(e){console.error("Error updating model:",e),F.ZP.error("Failed to update model settings")}finally{es(!1)}};if(!T)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsx)(P.Z,{children:"Model not found"})]});let eu=async()=>{try{if(!A)return;await (0,b.Og)(A,w),F.ZP.success("Model deleted successfully"),V&&V({deleted:!0,model_info:{id:w}}),k()}catch(e){console.error("Error deleting the model:",e),F.ZP.error("Failed to delete model")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsxs)(O.Z,{children:["Public Model Name: ",sk(T)]}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),(0,m.jsxs)("div",{className:"flex gap-2",children:["Admin"===L&&(0,m.jsx)(C.Z,{icon:sH.Z,variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Re-use Credentials"}),eo&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>W(!0),className:"flex items-center",children:"Delete Model"})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-6",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Raw JSON"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,m.jsx)("img",{src:sm(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,l=s.parentElement;if(l){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",l.replaceChild(e,s)}}}),(0,m.jsx)(O.Z,{children:T.provider||"Not Set"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"LiteLLM Model"}),(0,m.jsx)("pre",{children:(0,m.jsx)(O.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Pricing"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,m.jsxs)(P.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,m.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Model Settings"}),eo&&!el&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>et(!0),className:"flex items-center",children:"Edit Model"})]}),H?(0,m.jsx)(M.Z,{form:B,onFinish:em,initialValues:{model_name:H.model_name,litellm_model_name:H.litellm_model_name,api_base:H.litellm_params.api_base,custom_llm_provider:H.litellm_params.custom_llm_provider,organization:H.litellm_params.organization,tpm:H.litellm_params.tpm,rpm:H.litellm_params.rpm,max_retries:H.litellm_params.max_retries,timeout:H.litellm_params.timeout,stream_timeout:H.litellm_params.stream_timeout,input_cost:H.litellm_params.input_cost_per_token?1e6*H.litellm_params.input_cost_per_token:(null===(t=H.model_info)||void 0===t?void 0:t.input_cost_per_token)*1e6||null,output_cost:(null===(a=H.litellm_params)||void 0===a?void 0:a.output_cost_per_token)?1e6*H.litellm_params.output_cost_per_token:(null===(r=H.model_info)||void 0===r?void 0:r.output_cost_per_token)*1e6||null,cache_control:null!==(n=H.litellm_params)&&void 0!==n&&!!n.cache_control_injection_points,cache_control_injection_points:(null===(i=H.litellm_params)||void 0===i?void 0:i.cache_control_injection_points)||[]},layout:"vertical",onValuesChange:()=>Q(!0),children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"LiteLLM Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter LiteLLM model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.litellm_model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"input_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter input cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(o=H.litellm_params)||void 0===o?void 0:o.input_cost_per_token)?((null===(d=H.litellm_params)||void 0===d?void 0:d.input_cost_per_token)*1e6).toFixed(4):(null==H?void 0:null===(c=H.model_info)||void 0===c?void 0:c.input_cost_per_token)?(1e6*H.model_info.input_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"output_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter output cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(h=H.litellm_params)||void 0===h?void 0:h.output_cost_per_token)?(1e6*H.litellm_params.output_cost_per_token).toFixed(4):(null==H?void 0:null===(x=H.model_info)||void 0===x?void 0:x.output_cost_per_token)?(1e6*H.model_info.output_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Base"}),el?(0,m.jsx)(M.Z.Item,{name:"api_base",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter API base"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=H.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Custom LLM Provider"}),el?(0,m.jsx)(M.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom LLM provider"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=H.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),el?(0,m.jsx)(M.Z.Item,{name:"organization",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter organization"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=H.litellm_params)||void 0===j?void 0:j.organization)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"tpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter TPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=H.litellm_params)||void 0===f?void 0:f.tpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"rpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter RPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=H.litellm_params)||void 0===_?void 0:_.rpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Max Retries"}),el?(0,m.jsx)(M.Z.Item,{name:"max_retries",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter max retries"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(v=H.litellm_params)||void 0===v?void 0:v.max_retries)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(y=H.litellm_params)||void 0===y?void 0:y.timeout)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter stream timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=H.litellm_params)||void 0===Z?void 0:Z.stream_timeout)||"Not Set"})]}),el?(0,m.jsx)(s0,{form:B,showCacheControl:en,onCacheControlChange:e=>ei(e)}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Cache Control"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=H.litellm_params)||void 0===N?void 0:N.cache_control_injection_points)?(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{children:"Enabled"}),(0,m.jsx)("div",{className:"mt-2",children:H.litellm_params.cache_control_injection_points.map((e,s)=>(0,m.jsxs)("div",{className:"text-sm text-gray-600 mb-1",children:["Location: ",e.location,",",e.role&&(0,m.jsxs)("span",{children:[" Role: ",e.role]}),void 0!==e.index&&(0,m.jsxs)("span",{children:[" Index: ",e.index]})]},s))})]}):"Disabled"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),el&&(0,m.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{B.resetFields(),Q(!1),et(!1)},children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",onClick:()=>B.submit(),loading:ee,children:"Save Changes"})]})]})}):(0,m.jsx)(P.Z,{children:"Loading..."})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),G&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Model"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this model?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(U.ZP,{onClick:eu,className:"ml-2",danger:!0,children:"Delete"}),(0,m.jsx)(U.ZP,{onClick:()=>W(!1),children:"Cancel"})]})]})]})}),Y&&!ed?(0,m.jsx)(sW,{isVisible:Y,onCancel:()=>$(!1),onAddCredential:ec,existingCredential:ea,setIsCredentialModalOpen:$}):(0,m.jsx)(R.Z,{open:Y,onCancel:()=>$(!1),title:"Using Existing Credential",children:(0,m.jsx)(P.Z,{children:T.litellm_params.litellm_credential_name})})]})}var s2=l(67960),s4=e=>{let{selectedProvider:s,providerModels:l,getPlaceholder:t}=e,a=M.Z.useFormInstance(),r=e=>{let s=e.target.value,l=(a.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:s,litellm_model:s}:e);a.setFieldsValue({model_mappings:l})};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(M.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,m.jsx)(M.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:s===i.Azure||s===i.OpenAI_Compatible||s===i.Ollama?(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(I.Z,{placeholder:t(s)})}):l.length>0?(0,m.jsx)(D.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let s=Array.isArray(e)?e:[e];if(s.includes("all-wildcard"))a.setFieldsValue({model_name:void 0,model_mappings:[]});else if(JSON.stringify(a.getFieldValue("model"))!==JSON.stringify(s)){let e=s.map(e=>({public_name:e,litellm_model:e}));a.setFieldsValue({model:s,model_mappings:e})}},optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(s," Models (Wildcard)"),value:"all-wildcard"},...l.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,m.jsx)(I.Z,{placeholder:t(s)})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.model!==s.model,children:e=>{let{getFieldValue:s}=e,l=s("model")||[];return(Array.isArray(l)?l:[l]).includes("custom")&&(0,m.jsx)(M.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom model name",onChange:r})})}})]}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},s5=()=>{let e=M.Z.useFormInstance(),[s,l]=(0,u.useState)(0),t=M.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],r=M.Z.useWatch("custom_model_name",e),n=!a.includes("all-wildcard");if((0,u.useEffect)(()=>{if(r&&a.includes("custom")){let s=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:r,litellm_model:r}:e);e.setFieldValue("model_mappings",s),l(e=>e+1)}},[r,a,e]),(0,u.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let s=e.getFieldValue("model_mappings")||[];if(s.length!==a.length||!a.every(e=>s.some(s=>s.public_name===e||"custom"===e&&s.public_name===r))){let s=a.map(e=>"custom"===e&&r?{public_name:r,litellm_model:r}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",s),l(e=>e+1)}}},[a,r,e]),!n)return null;let i=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(s,l,t)=>(0,m.jsx)(I.Z,{value:s,onChange:s=>{let l=[...e.getFieldValue("model_mappings")];l[t].public_name=s.target.value,e.setFieldValue("model_mappings",l)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(M.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,m.jsx)(en.Z,{dataSource:e.getFieldValue("model_mappings"),columns:i,pagination:!1,size:"small"},s)})})},s3=l(90464);let{Link:s6}=et.default;var s8=e=>{let{showAdvancedSettings:s,setShowAdvancedSettings:l,teams:t}=e,[a]=M.Z.useForm(),[r,n]=u.useState(!1),[i,o]=u.useState("per_token"),[d,c]=u.useState(!1),h=(e,s)=>s&&(isNaN(Number(s))||0>Number(s))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),x=(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(T.Z,{className:"mt-2 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Advanced Settings"})}),(0,m.jsx)(A.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,m.jsx)(M.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,m.jsx)(sY.Z,{onChange:e=>{n(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),r&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(M.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:"per_token",onChange:e=>o(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===i?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}):(0,m.jsx)(M.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)(M.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,m.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,m.jsx)(sY.Z,{onChange:e=>{let s=a.getFieldValue("litellm_extra_params");try{let l=s?JSON.parse(s):{};e?l.use_in_pass_through=!0:delete l.use_in_pass_through,Object.keys(l).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(l,null,2)):a.setFieldValue("litellm_extra_params","")}catch(s){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,m.jsx)(s0,{form:a,showCacheControl:d,onCacheControlChange:e=>{if(c(e),!e){let e=a.getFieldValue("litellm_extra_params");try{let s=e?JSON.parse(e):{};delete s.cache_control_injection_points,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(e){a.setFieldValue("litellm_extra_params","")}}}}),(0,m.jsx)(M.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,m.jsxs)(sj.Z,{className:"mb-4",children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,m.jsx)(M.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},s7=l(29),s9=l.n(s7),le=l(23496),ls=l(23639);let{Text:ll}=et.default;var lt=e=>{let{formValues:s,accessToken:l,testMode:t,modelName:a="this model",onClose:r,onTestComplete:n}=e,[i,o]=u.useState(null),[d,c]=u.useState(null),[h,x]=u.useState(null),[p,g]=u.useState(!0),[j,f]=u.useState(!1),[_,v]=u.useState(!1),y=async()=>{g(!0),v(!1),o(null),c(null),x(null),f(!1),await new Promise(e=>setTimeout(e,100));try{console.log("Testing connection with form values:",s);let a=await sx(s,l,null);if(!a){console.log("No result from prepareModelAddRequest"),o("Failed to prepare model data. Please check your form inputs."),f(!1),g(!1);return}console.log("Result from prepareModelAddRequest:",a);let{litellmParamsObj:r,modelInfoObj:n,modelName:i}=a[0],d=await (0,b.Hx)(l,r,null==n?void 0:n.mode);if("success"===d.status)F.ZP.success("Connection test successful!"),o(null),f(!0);else{var e,t;let s=(null===(e=d.result)||void 0===e?void 0:e.error)||d.message||"Unknown error";o(s),c(r),x(null===(t=d.result)||void 0===t?void 0:t.raw_request_typed_dict),f(!1)}}catch(e){console.error("Test connection error:",e),o(e instanceof Error?e.message:String(e)),f(!1)}finally{g(!1),n&&n()}};u.useEffect(()=>{let e=setTimeout(()=>{y()},200);return()=>clearTimeout(e)},[]);let Z=e=>e?e.split("stack trace:")[0].trim().replace(/^litellm\.(.*?)Error: /,""):"Unknown error",N="string"==typeof i?Z(i):(null==i?void 0:i.message)?Z(i.message):"Unknown error",w=h?((e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")})(h.raw_request_api_base,h.raw_request_body,h.raw_request_headers||{}):"";return(0,m.jsxs)("div",{style:{padding:"24px",borderRadius:"8px",backgroundColor:"#fff"},children:[p?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},className:"jsx-776cdcbc0448e4ea",children:[(0,m.jsx)("div",{style:{marginBottom:"16px"},className:"jsx-776cdcbc0448e4ea loading-spinner",children:(0,m.jsx)("div",{style:{border:"3px solid #f3f3f3",borderTop:"3px solid #1890ff",borderRadius:"50%",width:"30px",height:"30px",animation:"spin 1s linear infinite",margin:"0 auto"},className:"jsx-776cdcbc0448e4ea"})}),(0,m.jsxs)(ll,{style:{fontSize:"16px"},children:["Testing connection to ",a,"..."]}),(0,m.jsx)(s9(),{id:"776cdcbc0448e4ea",children:"@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(360deg);transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-o-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);transform:rotate(360deg)}}"})]}):j?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},children:[(0,m.jsx)("div",{style:{color:"#52c41a",fontSize:"32px",marginBottom:"16px"},children:(0,m.jsx)("svg",{viewBox:"64 64 896 896",focusable:"false","data-icon":"check-circle",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",children:(0,m.jsx)("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"})})}),(0,m.jsxs)(ll,{type:"success",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," successful!"]})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"20px"},children:[(0,m.jsx)(em.Z,{style:{color:"#ff4d4f",fontSize:"24px",marginRight:"12px"}}),(0,m.jsxs)(ll,{type:"danger",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," failed"]})]}),(0,m.jsxs)("div",{style:{backgroundColor:"#fff2f0",border:"1px solid #ffccc7",borderRadius:"8px",padding:"16px",marginBottom:"20px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px"},children:"Error: "}),(0,m.jsx)(ll,{type:"danger",style:{fontSize:"14px",lineHeight:"1.5"},children:N}),i&&(0,m.jsx)("div",{style:{marginTop:"12px"},children:(0,m.jsx)(U.ZP,{type:"link",onClick:()=>v(!_),style:{paddingLeft:0,height:"auto"},children:_?"Hide Details":"Show Details"})})]}),_&&(0,m.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"Troubleshooting Details"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"200px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:"string"==typeof i?i:JSON.stringify(i,null,2)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"API Request"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"250px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:w||"No request data available"}),(0,m.jsx)(U.ZP,{style:{marginTop:"8px"},icon:(0,m.jsx)(ls.Z,{}),onClick:()=>{navigator.clipboard.writeText(w||""),F.ZP.success("Copied to clipboard")},children:"Copy to Clipboard"})]})]})}),(0,m.jsx)(le.Z,{style:{margin:"24px 0 16px"}}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:(0,m.jsx)(U.ZP,{type:"link",href:"https://docs.litellm.ai/docs/providers",target:"_blank",icon:(0,m.jsx)(W.Z,{}),children:"View Documentation"})})]})};let la=[{value:"chat",label:"Chat - /chat/completions"},{value:"completion",label:"Completion - /completions"},{value:"embedding",label:"Embedding - /embeddings"},{value:"audio_speech",label:"Audio Speech - /audio/speech"},{value:"audio_transcription",label:"Audio Transcription - /audio/transcriptions"},{value:"image_generation",label:"Image Generation - /images/generations"},{value:"rerank",label:"Rerank - /rerank"},{value:"realtime",label:"Realtime - /realtime"}],{Title:lr,Link:ln}=et.default;var li=e=>{let{form:s,handleOk:l,selectedProvider:t,setSelectedProvider:a,providerModels:r,setProviderModelsFn:n,getPlaceholder:o,uploadProps:d,showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x,credentials:p,accessToken:g,userRole:j}=e,[f,_]=(0,u.useState)("chat"),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(""),k=async()=>{Z(!0),w("test-".concat(Date.now())),y(!0)},S=eZ.ZL.includes(j);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lr,{level:2,children:"Add new model"}),(0,m.jsx)(s2.Z,{children:(0,m.jsx)(M.Z,{form:s,onFinish:l,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,m.jsx)(D.default,{showSearch:!0,value:t,onChange:e=>{a(e),n(e),s.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(i).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(s4,{selectedProvider:t,providerModels:r,getPlaceholder:o}),(0,m.jsx)(s5,{}),(0,m.jsx)(M.Z.Item,{label:"Mode",name:"mode",className:"mb-1",children:(0,m.jsx)(D.default,{style:{width:"100%"},value:f,onChange:e=>_(e),options:la})}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-5 mt-1",children:[(0,m.jsx)("strong",{children:"Optional"})," - LiteLLM endpoint to use when health checking this model ",(0,m.jsx)(ln,{href:"https://docs.litellm.ai/docs/proxy/health#health",target:"_blank",children:"Learn more"})]})})]}),(0,m.jsx)("div",{className:"mb-4",children:(0,m.jsx)(et.default.Text,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter new provider credentials below"})}),(0,m.jsx)(M.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...p.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.litellm_credential_name!==s.litellm_credential_name||e.provider!==s.provider,children:e=>{let{getFieldValue:s}=e,l=s("litellm_credential_name");return(console.log("\uD83D\uDD11 Credential Name Changed:",l),l)?(0,m.jsx)("div",{className:"text-gray-500 text-sm text-center",children:"Using existing credentials - no additional provider fields needed"}):(0,m.jsx)(sy,{selectedProvider:t,uploadProps:d})}}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Team Settings"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{label:"Team",name:"team_id",className:"mb-4",tooltip:"Only keys for this team, will be able to call this model.",rules:[{required:!S,message:"Please select a team."}],children:(0,m.jsx)(es,{teams:x})}),(0,m.jsx)(s8,{showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x}),(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(et.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{className:"space-x-2",children:[(0,m.jsx)(U.ZP,{onClick:k,loading:b,children:"Test Connect"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Model"})]})]})]})})}),(0,m.jsx)(R.Z,{title:"Connection Test Results",open:v,onCancel:()=>{y(!1),Z(!1)},footer:[(0,m.jsx)(U.ZP,{onClick:()=>{y(!1),Z(!1)},children:"Close"},"close")],width:700,children:v&&(0,m.jsx)(lt,{formValues:s.getFieldsValue(),accessToken:g,testMode:f,modelName:s.getFieldValue("model_name")||s.getFieldValue("model"),onClose:()=>{y(!1),Z(!1)},onTestComplete:()=>Z(!1)},N)})]})};function lo(e){let{data:s=[],columns:l,isLoading:t=!1,table:a}=e,[r,n]=u.useState([{id:"model_info.created_at",desc:!0}]),[i]=u.useState("onChange"),[o,d]=u.useState({}),[c,h]=u.useState({}),x=(0,e2.b7)({data:s,columns:l,state:{sorting:r,columnSizing:o,columnVisibility:c},columnResizeMode:i,onSortingChange:n,onColumnSizingChange:d,onColumnVisibilityChange:h,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,enableColumnResizing:!0,defaultColumn:{minSize:40,maxSize:500}});return u.useEffect(()=>{a&&(a.current=x)},[x,a]),(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsx)("div",{className:"relative min-w-full",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1 w-full",children:[(0,m.jsx)(e8.Z,{children:x.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsxs)(e7.Z,{className:"py-1 h-8 relative ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.id?120:e.getSize(),position:"actions"===e.id?"sticky":"relative",right:"actions"===e.id?0:"auto"},onClick:e.column.getToggleSortingHandler(),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]}),e.column.getCanResize()&&(0,m.jsx)("div",{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),className:"absolute right-0 top-0 h-full w-2 cursor-col-resize select-none touch-none ".concat(e.column.getIsResizing()?"bg-blue-500":"hover:bg-blue-200")})]},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):x.getRowModel().rows.length>0?x.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.column.id?120:e.column.getSize(),position:"actions"===e.column.id?"sticky":"relative",right:"actions"===e.column.id?0:"auto"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No models found"})})})})})]})})})})}let ld=(e,s,l,t,a,r,n,i,o)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.model_info.id,children:(0,m.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>t(l.model_info.id),children:l.model_info.id})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:s}=e,l=r(s.original)||"-";return(0,m.jsx)(Y.Z,{title:l,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l.provider&&(0,m.jsx)("img",{src:sm(l.provider).logo,alt:"".concat(l.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,t=s.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=l.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,s)}}}),(0,m.jsx)("p",{className:"text-xs",children:l.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.litellm_model_name,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l.litellm_model_name||"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_at?new Date(l.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.updated_at?new Date(l.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_by||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.input_cost||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:s}=e,l=s.original;return l.model_info.team_id?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.model_info.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>a(l.model_info.team_id),children:[l.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Credentials",accessorKey:"litellm_credential_name",cell:e=>{let{row:s}=e,l=s.original;return l.litellm_params&&l.litellm_params.litellm_credential_name?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsxs)(Y.Z,{title:l.litellm_params.litellm_credential_name,children:[l.litellm_params.litellm_credential_name.slice(0,7),"..."]})}):(0,m.jsx)("span",{className:"text-gray-400",children:"-"})}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(l.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:l.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:l=>{var a;let{row:r}=l,n=r.original,i="Admin"===e||(null===(a=n.model_info)||void 0===a?void 0:a.created_by)===s;return(0,m.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{i&&(t(n.model_info.id),o(!0))},className:i?"cursor-pointer":"opacity-50 cursor-not-allowed"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{i&&(t(n.model_info.id),o(!1))},className:i?"cursor-pointer":"opacity-50 cursor-not-allowed"})]})}}],{Title:lc,Link:lm}=et.default,lu={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lh=e=>{let{accessToken:s,token:l,userRole:t,userID:a,modelData:r={data:[]},keys:n,setModelData:o,premiumUser:d,teams:c}=e,[h,x]=(0,u.useState)([]),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)([]);Object.values(i).filter(e=>isNaN(Number(e)));let[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(i.OpenAI),[I,T]=(0,u.useState)(""),[A,E]=(0,u.useState)(!1),[L,D]=(0,u.useState)(null),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)([]),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)([]),[J,W]=(0,u.useState)([]),[Y,$]=(0,u.useState)([]),[X,Q]=(0,u.useState)([]),[ee,es]=(0,u.useState)([]),[ea,er]=(0,u.useState)([]),[en,ei]=(0,u.useState)([]),[eo,ed]=(0,u.useState)([]),[ec,em]=(0,u.useState)([]),[eu,eh]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,u.useState)(null),[eg,ej]=(0,u.useState)(0),[ef,e_]=(0,u.useState)({}),[ev,ey]=(0,u.useState)([]),[eb,eN]=(0,u.useState)(!1),[ew,ek]=(0,u.useState)(null),[eS,eC]=(0,u.useState)(null),[eI,eT]=(0,u.useState)([]),[eA,eE]=(0,u.useState)([]),[eP,eL]=(0,u.useState)(!1),[ez,eK]=(0,u.useState)(null),[eB,eH]=(0,u.useState)(!1),[eJ,eW]=(0,u.useState)(null),[eY,e$]=(0,u.useState)(null),[eX,eQ]=(0,u.useState)(null),[e0,e1]=(0,u.useState)(!1),[e2,e4]=(0,u.useState)(!1),se=(0,u.useRef)(null),ss=(0,u.useRef)(null),sl=async(e,l,r)=>{if(console.log("Updating model metrics for group:",e),!s||!a||!t||!l||!r)return;console.log("inside updateModelMetrics - startTime:",l,"endTime:",r),K(e);let n=null==ew?void 0:ew.token;void 0===n&&(n=null);let i=eS;void 0===i&&(i=null),l.setHours(0),l.setMinutes(0),l.setSeconds(0),r.setHours(23),r.setMinutes(59),r.setSeconds(59);try{let o=await (0,b.o6)(s,a,t,e,l.toISOString(),r.toISOString(),n,i);console.log("Model metrics response:",o),W(o.data),$(o.all_api_bases);let d=await (0,b.Rg)(s,e,l.toISOString(),r.toISOString());Q(d.data),es(d.all_api_bases);let c=await (0,b.N8)(s,a,t,e,l.toISOString(),r.toISOString(),n,i);console.log("Model exceptions response:",c),er(c.data),ei(c.exception_types);let m=await (0,b.fP)(s,a,t,e,l.toISOString(),r.toISOString(),n,i);if(console.log("slowResponses:",m),em(m),e){let t=await (0,b.n$)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);e_(t);let a=await (0,b.v9)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);ey(a)}}catch(e){console.error("Failed to fetch model metrics",e)}},st=async e=>{try{let s=await (0,b.N3)(e);console.log("credentials: ".concat(JSON.stringify(s))),eE(s.credentials)}catch(e){console.error("Error fetching credentials:",e)}};(0,u.useEffect)(()=>{sl(V,eu.from,eu.to)},[ew,eS,eY]),(0,u.useEffect)(()=>{let e=e=>{se.current&&!se.current.contains(e.target)&&e4(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let sa={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Resetting vertex_credentials to JSON; jsonStr: ".concat(s)),p.setFieldsValue({vertex_credentials:s}),console.log("Form values right after setting:",p.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered with values:",e),console.log("Current form values:",p.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?F.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&F.ZP.error("".concat(e.file.name," file upload failed."))}},sr=()=>{_(new Date().toLocaleString())},sn=async()=>{if(!s){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,b.K_)(s,{router_settings:{model_group_retry_policy:ex}}),F.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),F.ZP.error("Failed to save retry settings")}};if((0,u.useEffect)(()=>{if(!s||!l||!t||!a)return;let e=async()=>{try{var e,l,r,n,i,d,c,m,u,h,x,p;let g=await (0,b.AZ)(s,a,t);console.log("Model data response:",g.data),o(g);let j=await (0,b.hy)(s);j&&N(j);let f=new Set;for(let e=0;e0&&(v=_[_.length-1],console.log("_initial_model_group:",v)),console.log("selectedModelGroup:",V);let y=await (0,b.o6)(s,a,t,v,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(l=eu.to)||void 0===l?void 0:l.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model metrics response:",y),W(y.data),$(y.all_api_bases);let Z=await (0,b.Rg)(s,v,null===(r=eu.from)||void 0===r?void 0:r.toISOString(),null===(n=eu.to)||void 0===n?void 0:n.toISOString());Q(Z.data),es(Z.all_api_bases);let w=await (0,b.N8)(s,a,t,v,null===(i=eu.from)||void 0===i?void 0:i.toISOString(),null===(d=eu.to)||void 0===d?void 0:d.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model exceptions response:",w),er(w.data),ei(w.exception_types);let k=await (0,b.fP)(s,a,t,v,null===(c=eu.from)||void 0===c?void 0:c.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eS),S=await (0,b.n$)(s,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],v);e_(S);let C=await (0,b.v9)(s,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],v);ey(C),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",C),console.log("slowResponses:",k),em(k);let I=await (0,b.j2)(s);eT(null==I?void 0:I.end_users);let T=(await (0,b.BL)(s,a,t)).router_settings;console.log("routerSettingsInfo:",T);let A=T.model_group_retry_policy,E=T.num_retries;console.log("model_group_retry_policy:",A),console.log("default_retries:",E),ep(A),ej(E)}catch(e){console.error("There was an error fetching the model data",e)}};s&&l&&t&&a&&e();let r=async()=>{let e=await (0,b.qm)(s);console.log("received model cost map data: ".concat(Object.keys(e))),j(e)};null==g&&r(),sr()},[s,l,t,a,g,f,eY]),!r||!s||!l||!t||!a)return(0,m.jsx)("div",{children:"Loading..."});let sd=[],sc=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(l){let e=l.split("/"),s=e[0];(n=t)||(n=1===e.length?u(l):s)}else n="-";a&&(i=null==a?void 0:a.input_cost_per_token,o=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==s?void 0:s.litellm_params)&&(m=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[s]=e;return"model"!==s&&"api_base"!==s}))),r.data[e].provider=n,r.data[e].input_cost=i,r.data[e].output_cost=o,r.data[e].litellm_model_name=l,sc.push(n),r.data[e].input_cost&&(r.data[e].input_cost=(1e6*Number(r.data[e].input_cost)).toFixed(2)),r.data[e].output_cost&&(r.data[e].output_cost=(1e6*Number(r.data[e].output_cost)).toFixed(2)),r.data[e].max_tokens=d,r.data[e].max_input_tokens=c,r.data[e].api_base=null==s?void 0:null===(sg=s.litellm_params)||void 0===sg?void 0:sg.api_base,r.data[e].cleanedLitellmParams=m,sd.push(s.model_name),console.log(r.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to view all models"})]})}let sj=async()=>{try{F.ZP.info("Running health check..."),T("");let e=await (0,b.EY)(s);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}},s_=(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Select API Key Name"}),d?(0,m.jsxs)("div",{children:[(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{ek(null)},children:"All Keys"},"all-keys"),null==n?void 0:n.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{ek(e)},children:e.key_alias},s):null)]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Customer Name"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-customers",children:[(0,m.jsx)(el.Z,{value:"all-customers",onClick:()=>{eC(null)},children:"All Customers"},"all-customers"),null==eI?void 0:eI.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>{eC(e)},children:e},s))]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]}),sv=e=>{var s,l;let{payload:t,active:a}=e;if(!a||!t)return null;let r=null===(l=t[0])||void 0===l?void 0:null===(s=l.payload)||void 0===s?void 0:s.date,n=t.sort((e,s)=>s.value-e.value);if(n.length>5){let e=n.length-5;(n=n.slice(0,5)).push({dataKey:"".concat(e," other deployments"),value:t.slice(5).reduce((e,s)=>e+s.value,0),color:"gray"})}return(0,m.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[r&&(0,m.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",r]}),n.map((e,s)=>{let l=parseFloat(e.value.toFixed(5)),t=0===l&&e.value>0?"<0.00001":l.toFixed(5);return(0,m.jsxs)("div",{className:"flex justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,m.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,m.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:t})]},s)})]})};console.log("selectedProvider: ".concat(w)),console.log("providerModels.length: ".concat(v.length));let sy=Object.keys(i).find(e=>i[e]===w);return(sy&&Z&&Z.find(e=>e.name===so[sy]),eJ)?(0,m.jsx)("div",{className:"w-full h-full",children:(0,m.jsx)(sB,{teamId:eJ,onClose:()=>eW(null),accessToken:s,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:sd,editTeam:!1,onUpdate:sr})}):(0,m.jsx)("div",{style:{width:"100%",height:"100%"},children:ez?(0,m.jsx)(s1,{modelId:ez,editModel:!0,onClose:()=>{eK(null),eH(!1)},modelData:r.data.find(e=>e.model_info.id===ez),accessToken:s,userID:a,userRole:t,setEditModalVisible:E,setSelectedModel:D,onModelUpdate:e=>{o({...r,data:r.data.map(s=>s.model_info.id===e.model_info.id?e:s)}),sr()}}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[eZ.ZL.includes(t)?(0,m.jsx)(eM.Z,{children:"All Models"}):(0,m.jsx)(eM.Z,{children:"Your Models"}),(0,m.jsx)(eM.Z,{children:"Add Model"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"LLM Credentials"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"/health Models"})}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Analytics"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Retry Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:sr})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(S.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(O.Z,{children:"Model Management"}),eZ.ZL.includes(t)?(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add and manage models for the proxy"}):(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add models for teams you are an admin for."})]})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex items-center justify-between",children:(0,m.jsxs)("div",{className:"flex items-center gap-3",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:null!=V?V:"all",onValueChange:e=>K("all"===e?"all":e),value:null!=V?V:"all",children:[(0,m.jsx)(el.Z,{value:"all",children:"All Models"}),R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,children:e},s))]})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Team:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]})}),(0,m.jsx)("div",{className:"flex justify-between items-center",children:(0,m.jsxs)(P.Z,{className:"text-sm text-gray-700",children:["Showing ",r&&r.data.length>0?r.data.length:0," results"]})})]})}),(0,m.jsx)(lo,{columns:ld(t,a,d,eK,eW,sk,e=>{D(e),E(!0)},sr,eH),data:r.data.filter(e=>("all"===V||e.model_name===V||!V)&&("all"===eX||e.model_info.team_id===eX||!eX)),isLoading:!1,table:ss})]})]})})}),(0,m.jsx)(eq.Z,{className:"h-full",children:(0,m.jsx)(li,{form:p,handleOk:()=>{p.validateFields().then(e=>{sp(e,s,p,sr)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:w,setSelectedProvider:k,providerModels:v,setProviderModelsFn:e=>{let s=sh(e,g);y(s),console.log("providerModels: ".concat(s))},getPlaceholder:su,uploadProps:sa,showAdvancedSettings:eP,setShowAdvancedSettings:eL,teams:c,credentials:eA,accessToken:s,userRole:t})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sw,{accessToken:s,uploadProps:sa,credentialList:eA,fetchCredentials:st})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,m.jsx)(C.Z,{onClick:sj,children:"Run `/health`"}),I&&(0,m.jsx)("pre",{children:JSON.stringify(I,null,2)})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:eu,className:"mr-2",onValueChange:e=>{eh(e),sl(V,e.from,e.to)}})]}),(0,m.jsxs)(sf.Z,{className:"ml-2",children:[(0,m.jsx)(P.Z,{children:"Select Model Group"}),(0,m.jsx)(eO.Z,{defaultValue:V||R[0],value:V||R[0],children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>sl(e,eu.from,eu.to),children:e},s))})]}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(sA.Z,{trigger:"click",content:s_,overlayStyle:{width:"20vw"},children:(0,m.jsx)(C.Z,{icon:eG.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>eN(!0)})})})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Avg. Latency per Token"}),(0,m.jsx)(eM.Z,{value:"2",children:"Time to first token"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,m.jsx)(P.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),J&&Y&&(0,m.jsx)(sI.Z,{title:"Model Latency",className:"h-72",data:J,showLegend:!1,index:"date",categories:Y,connectNulls:!0,customTooltip:sv})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sP,{modelMetrics:X,modelMetricsCategories:ee,customTooltip:sv,premiumUser:d})})]})]})})}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Deployment"}),(0,m.jsx)(e7.Z,{children:"Success Responses"}),(0,m.jsxs)(e7.Z,{children:["Slow Responses ",(0,m.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,m.jsx)(e3.Z,{children:ec.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.api_base}),(0,m.jsx)(e6.Z,{children:e.total_count}),(0,m.jsx)(e6.Z,{children:e.slow_count})]},s))})]})})})]}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Exceptions for ",V]}),(0,m.jsx)(sT.Z,{className:"h-60",data:ea,index:"model",categories:en,stack:!0,yAxisWidth:30})]})}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Up Rate Limit Errors (429) for ",V]}),(0,m.jsxs)(S.Z,{numItems:1,children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",ef.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:ef.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,m.jsx)(sf.Z,{})]})]}),d?(0,m.jsx)(m.Fragment,{children:ev.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},s))}):(0,m.jsx)(m.Fragment,{children:ev&&ev.length>0&&ev.slice(0,1).map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},s))})]})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name"}),(0,m.jsx)(eO.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:V||R[0],value:V||R[0],onValueChange:e=>K(e),children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>K(e),children:e},s))})]}),(0,m.jsxs)(O.Z,{children:["Retry Policy for ",V]}),(0,m.jsx)(P.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lu&&(0,m.jsx)("table",{children:(0,m.jsx)("tbody",{children:Object.entries(lu).map((e,s)=>{var l;let[t,a]=e,r=null==ex?void 0:null===(l=ex[V])||void 0===l?void 0:l[a];return null==r&&(r=eg),(0,m.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,m.jsx)("td",{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)("td",{children:(0,m.jsx)(G.Z,{className:"ml-5",value:r,min:0,step:1,onChange:e=>{ep(s=>{var l;let t=null!==(l=null==s?void 0:s[V])&&void 0!==l?l:{};return{...null!=s?s:{},[V]:{...t,[a]:e}}})}})})]},s)})})}),(0,m.jsx)(C.Z,{className:"mt-6 mr-8",onClick:sn,children:"Save"})]})]})]})})},lx=e=>{let{visible:s,possibleUIRoles:l,onCancel:t,user:a,onSubmit:r}=e,[n,i]=(0,u.useState)(a),[o]=M.Z.useForm();(0,u.useEffect)(()=>{o.resetFields()},[a]);let d=async()=>{o.resetFields(),t()},c=async e=>{r(e),o.resetFields(),t()};return a?(0,m.jsx)(R.Z,{visible:s,onCancel:d,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,m.jsx)(M.Z,{form:o,onFinish:c,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:l&&Object.entries(l).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,m.jsx)(G.Z,{min:0,step:.01})}),(0,m.jsx)(M.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Maximum budget of this user.",children:(0,m.jsx)(K,{min:0,step:.01})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lp=l(15731);let lg=(e,s,l)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)(Y.Z,{title:s.original.user_id,children:(0,m.jsx)("span",{className:"text-xs",children:s.original.user_id?"".concat(s.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:s=>{var l;let{row:t}=s;return(0,m.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(l=e[t.original.user_role])||void 0===l?void 0:l.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.spend?s.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.max_budget?s.original.max_budget:"Unlimited"})}},{header:()=>(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"SSO ID"}),(0,m.jsx)(Y.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,m.jsx)(lp.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.sso_user_id?s.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:s}=e;return(0,m.jsx)(S.Z,{numItems:2,children:s.original.key_count>0?(0,m.jsxs)(eL.Z,{size:"xs",color:"indigo",children:[s.original.key_count," Keys"]}):(0,m.jsx)(eL.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.created_at?new Date(s.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.updated_at?new Date(s.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>s(t.original)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.original.user_id)})]})}}];var lj=l(16853);function lf(e){let{userData:s,onCancel:l,onSubmit:t,teams:a,accessToken:r,userID:n,userRole:i,userModels:o,possibleUIRoles:d}=e,[c]=M.Z.useForm();return u.useEffect(()=>{var e,l,t,a,r;c.setFieldsValue({user_id:s.user_id,user_email:null===(e=s.user_info)||void 0===e?void 0:e.user_email,user_role:null===(l=s.user_info)||void 0===l?void 0:l.user_role,models:(null===(t=s.user_info)||void 0===t?void 0:t.models)||[],max_budget:null===(a=s.user_info)||void 0===a?void 0:a.max_budget,metadata:(null===(r=s.user_info)||void 0===r?void 0:r.metadata)?JSON.stringify(s.user_info.metadata,null,2):void 0})},[s,c]),(0,m.jsxs)(M.Z,{form:c,onFinish:e=>{if(e.metadata&&"string"==typeof e.metadata)try{e.metadata=JSON.parse(e.metadata)}catch(e){console.error("Error parsing metadata JSON:",e);return}t(e)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:d&&Object.entries(d).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Personal Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this user can access outside of team-scope. Choose 'All Proxy Models' to grant access to all models available on the proxy.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:!eZ.ZL.includes(i||""),children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(lj.Z,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:l,children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}function l_(e){var s,l,t,a,r,n,i,o,d,c,h,x,p,g,j,f,_,v,y,Z,N,w,k,I,T,A,E;let{userId:L,onClose:D,accessToken:M,userRole:R,onDelete:q,possibleUIRoles:U}=e,[z,V]=(0,u.useState)(null),[K,B]=(0,u.useState)(!1),[H,J]=(0,u.useState)(!0),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)([]);u.useEffect(()=>{console.log("userId: ".concat(L,", userRole: ").concat(R,", accessToken: ").concat(M)),(async()=>{try{if(!M)return;let e=await (0,b.Br)(M,L,R||"",!1,null,null,!0);V(e);let s=(await (0,b.So)(M,L,R||"")).data.map(e=>e.id);$(s)}catch(e){console.error("Error fetching user data:",e),F.ZP.error("Failed to fetch user data")}finally{J(!1)}})()},[M,L,R]);let X=async()=>{try{if(!M)return;await (0,b.Eb)(M,[L]),F.ZP.success("User deleted successfully"),q&&q(),D()}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}},Q=async e=>{try{if(!M||!z)return;await (0,b.pf)(M,e,null),V({...z,user_info:{...z.user_info,user_email:e.user_email,models:e.models,max_budget:e.max_budget,metadata:e.metadata}}),F.ZP.success("User updated successfully"),W(!1)}catch(e){console.error("Error updating user:",e),F.ZP.error("Failed to update user")}};return H?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"Loading user data..."})]}):z?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(O.Z,{children:(null===(s=z.user_info)||void 0===s?void 0:s.user_email)||"User"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:z.user_id})]}),R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete User"})]}),K&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:X,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>B(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Details"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number((null===(l=z.user_info)||void 0===l?void 0:l.spend)||0).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",(null===(t=z.user_info)||void 0===t?void 0:t.max_budget)!==null?"$".concat(z.user_info.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(a=z.teams)||void 0===a?void 0:a.length)||0," teams"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"API Keys"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(r=z.keys)||void 0===r?void 0:r.length)||0," keys"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Personal Models"}),(0,m.jsx)("div",{className:"mt-2",children:(null===(i=z.user_info)||void 0===i?void 0:null===(n=i.models)||void 0===n?void 0:n.length)&&(null===(d=z.user_info)||void 0===d?void 0:null===(o=d.models)||void 0===o?void 0:o.length)>0?null===(h=z.user_info)||void 0===h?void 0:null===(c=h.models)||void 0===c?void 0:c.map((e,s)=>(0,m.jsx)(P.Z,{children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"User Settings"}),!G&&R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>W(!0),children:"Edit Settings"})]}),G&&z?(0,m.jsx)(lf,{userData:z,onCancel:()=>W(!1),onSubmit:Q,teams:z.teams,accessToken:M,userID:L,userRole:R,userModels:Y,possibleUIRoles:U}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"User ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:z.user_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Email"}),(0,m.jsx)(P.Z,{children:(null===(x=z.user_info)||void 0===x?void 0:x.user_email)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Role"}),(0,m.jsx)(P.Z,{children:(null===(p=z.user_info)||void 0===p?void 0:p.user_role)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:(null===(g=z.user_info)||void 0===g?void 0:g.created_at)?new Date(z.user_info.created_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:(null===(j=z.user_info)||void 0===j?void 0:j.updated_at)?new Date(z.user_info.updated_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Teams"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(f=z.teams)||void 0===f?void 0:f.length)&&(null===(_=z.teams)||void 0===_?void 0:_.length)>0?null===(v=z.teams)||void 0===v?void 0:v.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e.team_alias||e.team_id},s)):(0,m.jsx)(P.Z,{children:"No teams"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(Z=z.user_info)||void 0===Z?void 0:null===(y=Z.models)||void 0===y?void 0:y.length)&&(null===(w=z.user_info)||void 0===w?void 0:null===(N=w.models)||void 0===N?void 0:N.length)>0?null===(I=z.user_info)||void 0===I?void 0:null===(k=I.models)||void 0===k?void 0:k.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Keys"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(T=z.keys)||void 0===T?void 0:T.length)&&(null===(A=z.keys)||void 0===A?void 0:A.length)>0?z.keys.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-green-100 rounded text-xs",children:e.key_alias||e.token},s)):(0,m.jsx)(P.Z,{children:"No API keys"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify((null===(E=z.user_info)||void 0===E?void 0:E.metadata)||{},null,2)})]})]})]})})]})]})]}):(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"User not found"})]})}function lv(e){let{data:s=[],columns:l,isLoading:t=!1,onSortChange:a,currentSort:r,accessToken:n,userRole:i,possibleUIRoles:o}=e,[d,c]=u.useState([{id:(null==r?void 0:r.sortBy)||"created_at",desc:(null==r?void 0:r.sortOrder)==="desc"}]),[h,x]=u.useState(null),p=(0,e2.b7)({data:s,columns:l,state:{sorting:d},onSortingChange:e=>{if(c(e),e.length>0){let s=e[0],l=s.id,t=s.desc?"desc":"asc";null==a||a(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0}),g=e=>{x(e)};return(u.useEffect(()=>{r&&c([{id:r.sortBy,desc:"desc"===r.sortOrder}])},[r]),h)?(0,m.jsx)(l_,{userId:h,onClose:()=>{x(null)},accessToken:n,userRole:i,possibleUIRoles:o}):(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:p.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):s.length>0?p.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:()=>{"user_id"===e.column.id&&g(e.getValue())},style:{cursor:"user_id"===e.column.id?"pointer":"default",color:"user_id"===e.column.id?"#3b82f6":"inherit"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No users found"})})})})})]})})})}var ly=l(67982),lb=l(87908),lZ=e=>{var s;let{accessToken:l,possibleUIRoles:t,userID:a,userRole:r}=e,[n,i]=(0,u.useState)(!0),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)([]),{Paragraph:v}=et.default,{Option:y}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){i(!1);return}try{let e=await (0,b.NL)(l);if(d(e),p(e.values||{}),l)try{let e=await (0,b.So)(l,a,r);if(e&&e.data){let s=e.data.map(e=>e.id);_(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching SSO settings:",e),F.ZP.error("Failed to fetch SSO settings")}finally{i(!1)}})()},[l]);let Z=async()=>{if(l){j(!0);try{let e=await (0,b.nd)(l,x);d({...o,values:e.settings}),h(!1)}catch(e){console.error("Error updating SSO settings:",e),F.ZP.error("Failed to update settings")}finally{j(!1)}}},N=(e,s)=>{p(l=>({...l,[e]:s}))},w=(e,s,l)=>{var a;let r=s.type;return"user_role"===e&&t?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:Object.entries(t).filter(e=>{let[s]=e;return s.includes("internal_user")}).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(y,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{children:l}),(0,m.jsx)("span",{className:"ml-2 text-xs text-gray-500",children:t})]})},s)})}):"budget_duration"===e?(0,m.jsx)(ek,{value:x[e]||null,onChange:s=>N(e,s),className:"mt-2"}):"boolean"===r?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!x[e],onChange:s=>N(e,s)})}):"array"===r&&(null===(a=s.items)||void 0===a?void 0:a.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:f.map(e=>(0,m.jsx)(y,{value:e,children:H(e)},e))}):"string"===r&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==x[e]?String(x[e]):"",onChange:s=>N(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},k=(e,s)=>{if(null==s)return(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"});if("user_role"===e&&t&&t[s]){let{ui_label:e,description:l}=t[s];return(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-medium",children:e}),l&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:l})]})}return"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)})};return n?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):o?(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex justify-end items-center mb-4",children:!n&&o&&(c?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{h(!1),p(o.values||{})},disabled:g,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:Z,loading:g,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>h(!0),children:"Edit Settings"}))}),(null==o?void 0:null===(s=o.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(v,{className:"mb-4",children:o.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=o;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(v,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),c?(0,m.jsx)("div",{className:"mt-2",children:w(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:k(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No settings available or you do not have permission to view them."})})},lN=l(19616);console.log=function(){};let lw={email:"",user_id:"",user_role:"",sso_user_id:"",team:"",model:"",min_spend:null,max_spend:null,sort_by:"created_at",sort_order:"desc"};var lk=e=>{var s;let{accessToken:l,token:t,userRole:a,userID:r,teams:n}=e,i=(0,g.NL)(),[o,d]=(0,u.useState)(1),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)("users"),[N,w]=(0,u.useState)(lw),[k,S,I]=(0,lN.G)(N,{wait:300}),[T,A]=(0,u.useState)(!1);(0,u.useEffect)(()=>()=>{I.cancel()},[I]);let E=e=>{w(s=>{let l={...s,...e};return S(l),l})},P=async()=>{if(_&&l)try{await (0,b.Eb)(l,[_]),i.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let s=e.users.filter(e=>e.user_id!==_);return{...e,users:s}}),F.ZP.success("User deleted successfully")}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}f(!1),v(null)},O=async()=>{p(null),h(!1)},L=async e=>{if(console.log("inside handleEditSubmit:",e),l&&t&&a&&r){try{let s=await (0,b.pf)(l,e,null);i.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let l=e.users.map(e=>e.user_id===s.data.user_id?e1(e,s.data):e);return{...e,users:l}}),F.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}p(null),h(!1)}},D=async e=>{d(e)},M=(0,eY.a)({queryKey:["userList",{debouncedFilter:k,currentPage:o}],queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.Of)(l,k.user_id?[k.user_id]:null,o,25,k.email||null,k.user_role||null,k.team||null,k.sso_user_id||null,k.sort_by,k.sort_order)},enabled:!!(l&&t&&a&&r),placeholderData:e=>e}),R=M.data,q=(0,eY.a)({queryKey:["userRoles"],initialData:()=>({}),queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.lg)(l)},enabled:!!(l&&t&&a&&r)}).data;if(M.isLoading||!l||!t||!a||!r)return(0,m.jsx)("div",{children:"Loading..."});let U=lg(q,e=>{p(e),h(!0)},e=>{v(e),f(!0)});return(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,m.jsx)("div",{className:"flex space-x-3",children:(0,m.jsx)(ev,{userID:r,accessToken:l,teams:n,possibleUIRoles:q})})]}),(0,m.jsxs)(eF.Z,{defaultIndex:0,onIndexChange:e=>Z(0===e?"users":"settings"),children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Users"}),(0,m.jsx)(eM.Z,{children:"Default User Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by email...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.email,onChange:e=>E({email:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(T?"bg-gray-100":""),onClick:()=>A(!T),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(N.user_id||N.user_role||N.team)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{E(lw)},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),T&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Filter by User ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.user_id,onChange:e=>E({user_id:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.user_role,onValueChange:e=>E({user_role:e}),placeholder:"Select Role",children:Object.entries(q).map(e=>{let[s,l]=e;return(0,m.jsx)(el.Z,{value:s,children:l.ui_label},s)})})}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.team,onValueChange:e=>E({team:e}),placeholder:"Select Team",children:null==n?void 0:n.map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias||e.team_id},e.team_id))})}),(0,m.jsx)("div",{className:"relative w-64",children:(0,m.jsx)("input",{type:"text",placeholder:"Filter by SSO ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.sso_user_id,onChange:e=>E({sso_user_id:e.target.value})})})]}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",R&&R.users&&R.users.length>0?(R.page-1)*R.page_size+1:0," ","-"," ",R&&R.users?Math.min(R.page*R.page_size,R.total):0," ","of ",R?R.total:0," results"]}),(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>D(o-1),disabled:1===o,className:"px-3 py-1 text-sm border rounded-md ".concat(1===o?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,m.jsx)("button",{onClick:()=>D(o+1),disabled:!R||o>=R.total_pages,className:"px-3 py-1 text-sm border rounded-md ".concat(!R||o>=R.total_pages?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,m.jsx)(lv,{data:(null===(s=M.data)||void 0===s?void 0:s.users)||[],columns:U,isLoading:M.isLoading,accessToken:l,userRole:a,onSortChange:(e,s)=>{E({sort_by:e,sort_order:s})},currentSort:{sortBy:N.sort_by,sortOrder:N.sort_order},possibleUIRoles:q})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lZ,{accessToken:l,possibleUIRoles:q,userID:r,userRole:a})})]})]}),(0,m.jsx)(lx,{visible:c,possibleUIRoles:q,onCancel:O,user:x,onSubmit:L}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,m.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",_]})]})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:P,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})})]})},lS=e=>{var s;let{accessToken:l,userID:t,userRole:a}=e,[r,n]=(0,u.useState)(!0),[i,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)({}),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)([]),{Paragraph:_}=et.default,{Option:v}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){n(!1);return}try{let e=await (0,b.EB)(l);if(o(e),x(e.values||{}),l)try{let e=await (0,b.So)(l,t,a);if(e&&e.data){let s=e.data.map(e=>e.id);f(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching team SSO settings:",e),F.ZP.error("Failed to fetch team settings")}finally{n(!1)}})()},[l]);let y=async()=>{if(l){g(!0);try{let e=await (0,b.r1)(l,h);o({...i,values:e.settings}),c(!1),F.ZP.success("Default team settings updated successfully")}catch(e){console.error("Error updating team settings:",e),F.ZP.error("Failed to update team settings")}finally{g(!1)}}},Z=(e,s)=>{x(l=>({...l,[e]:s}))},N=(e,s,l)=>{var t;let a=s.type;return"budget_duration"===e?(0,m.jsx)(ek,{value:h[e]||null,onChange:s=>Z(e,s),className:"mt-2"}):"boolean"===a?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!h[e],onChange:s=>Z(e,s)})}):"array"===a&&(null===(t=s.items)||void 0===t?void 0:t.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:j.map(e=>(0,m.jsx)(v,{value:e,children:H(e)},e))}):"string"===a&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>Z(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==h[e]?String(h[e]):"",onChange:s=>Z(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},w=(e,s)=>null==s?(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"}):"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)});return r?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):i?(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{className:"text-xl",children:"Default Team Settings"}),!r&&i&&(d?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{c(!1),x(i.values||{})},disabled:p,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:y,loading:p,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Settings"}))]}),(0,m.jsx)(P.Z,{children:"These settings will be applied by default when creating new teams."}),(null==i?void 0:null===(s=i.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(_,{className:"mb-4 mt-2",children:i.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=i;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(_,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),d?(0,m.jsx)("div",{className:"mt-2",children:N(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:w(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No team settings available or you do not have permission to view them."})})},lC=e=>{let{accessToken:s,userID:l}=e,[t,a]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(s&&l)try{let e=await (0,b.a6)(s);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[s,l]);let r=async e=>{if(s&&l)try{await (0,b.cu)(s,e,{user_id:l,role:"user"}),F.ZP.success("Successfully joined team"),a(s=>s.filter(s=>s.team_id!==e))}catch(e){console.error("Error joining team:",e),F.ZP.error("Failed to join team")}};return(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{children:"Members"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsxs)(e3.Z,{children:[t.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.team_alias})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.description||"No description available"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[e.members_with_roles.length," members"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,s)=>(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},s)):(0,m.jsx)(eL.Z,{size:"xs",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})})})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{size:"xs",variant:"secondary",onClick:()=>r(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:5,className:"text-center",children:(0,m.jsx)(P.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lI=(e,s)=>{let l=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),l=e.models):l=s,J(l,s)};var lT=e=>{let{teams:s,searchParams:l,accessToken:t,setTeams:a,userID:r,userRole:n,organizations:i}=e,[o,d]=(0,u.useState)(""),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,u.useEffect)(()=>{console.log("inside useeffect - ".concat(o)),t&&w(t,r,n,c,a),ew()},[o]);let[v]=M.Z.useForm(),[y]=M.Z.useForm(),{Title:Z,Paragraph:N}=et.default,[O,L]=(0,u.useState)(""),[q,V]=(0,u.useState)(!1),[J,G]=(0,u.useState)(null),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(!1),[es,ea]=(0,u.useState)(!1),[er,en]=(0,u.useState)(!1),[ei,eo]=(0,u.useState)(!1),[ed,ec]=(0,u.useState)([]),[em,eu]=(0,u.useState)(!1),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)([]),[ej,ef]=(0,u.useState)({}),[e_,ev]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lI(x,ed);console.log("models: ".concat(e)),eg(e),v.setFieldValue("models",[])},[x,ed]),(0,u.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,b.t3)(t)).guardrails.map(e=>e.guardrail_name);ev(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let ey=async e=>{ex(e),eu(!0)},eb=async()=>{if(null!=eh&&null!=s&&null!=t){try{await (0,b.rs)(t,eh),w(t,r,n,c,a)}catch(e){console.error("Error deleting the team:",e)}eu(!1),ex(null)}};(0,u.useEffect)(()=>{(async()=>{try{if(null===r||null===n||null===t)return;let e=await B(r,n,t);e&&ec(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,r,n,s]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var l;let r=null==e?void 0:e.team_alias,n=null!==(l=null==s?void 0:s.map(e=>e.team_alias))&&void 0!==l?l:[],i=(null==e?void 0:e.organization_id)||(null==c?void 0:c.organization_id);if(""===i||"string"!=typeof i?e.organization_id=null:e.organization_id=i.trim(),n.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));F.ZP.info("Creating Team");let o=await (0,b.hT)(t,e);null!==s?a([...s,o]):a([o]),console.log("response for team create call: ".concat(o)),F.ZP.success("Team created"),v.resetFields(),ea(!1)}}catch(e){console.error("Error creating the team:",e),F.ZP.error("Error creating the team: "+e,20)}},ew=()=>{d(new Date().toLocaleString())},ek=(e,s)=>{let l={...f,[e]:s};_(l),t&&(0,b.JO)(t,l.organization_id||null,null,l.team_id||null,l.team_alias||null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:$?(0,m.jsx)(sB,{teamId:$,onUpdate:e=>{a(s=>null==s?s:s.map(s=>e.team_id===s.team_id?e1(s,e):s))},onClose:()=>{X(null),ee(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let s=0;se.team_id===$)),is_proxy_admin:"Admin"==n,userModels:ed,editTeam:Q}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Your Teams"}),(0,m.jsx)(eM.Z,{children:"Available Teams"}),(0,eZ.tY)(n||"")&&(0,m.jsx)(eM.Z,{children:"Default Team Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",o]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(P.Z,{children:["Click on “Team ID” to view team details ",(0,m.jsx)("b",{children:"and"})," manage team members."]}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Team Name...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_alias,onChange:e=>ek("team_alias",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(g?"bg-gray-100":""),onClick:()=>j(!g),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(f.team_id||f.team_alias||f.organization_id)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{_({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"}),t&&(0,b.JO)(t,null,r||null,null,null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),g&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Enter Team ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_id,onChange:e=>ek("team_id",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:f.organization_id||"",onValueChange:e=>ek("organization_id",e),placeholder:"Select Organization",children:null==i?void 0:i.map(e=>(0,m.jsx)(el.Z,{value:e.organization_id||"",children:e.organization_alias||e.organization_id},e.organization_id))})})]})]})}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Team ID"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Organization"}),(0,m.jsx)(e7.Z,{children:"Info"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.filter(e=>!c||e.organization_id===c.organization_id).sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{X(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)})},s))}):null}),(0,m.jsx)(e6.Z,{children:e.organization_id}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].keys&&ej[e.team_id].keys.length," ","Keys"]}),(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].members_with_roles&&ej[e.team_id].members_with_roles.length," ","Members"]})]}),(0,m.jsx)(e6.Z,{children:"Admin"==n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{X(e.team_id),ee(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>ey(e.team_id),icon:eK.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),em&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:eb,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{eu(!1),ex(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==n||"Org Admin"==n?(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>ea(!0),children:"+ Create New Team"}),(0,m.jsx)(R.Z,{title:"Create Team",visible:es,width:800,footer:null,onOk:()=>{ea(!1),v.resetFields()},onCancel:()=>{ea(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Organization"," ",(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:c?c.organization_id:null,className:"mt-8",children:(0,m.jsx)(D.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{v.setFieldValue("organization_id",e),p((null==i?void 0:i.find(s=>s.organization_id===e))||null)},filterOption:(e,s)=>{var l;return!!s&&((null===(l=s.children)||void 0===l?void 0:l.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==i?void 0:i.map(e=>(0,m.jsxs)(D.default.Option,{value:e.organization_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"These are the models that your selected team has access to",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ep.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Additional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,m.jsx)(I.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:e_.map(e=>({value:e,label:e}))})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lC,{accessToken:t,userID:r})}),(0,eZ.tY)(n||"")&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lS,{accessToken:t,userID:r||"",userRole:n||""})})]})]})})},lA=e=>{var s,l;let{organizationId:t,onClose:a,accessToken:r,is_org_admin:n,is_proxy_admin:i,userModels:o,editOrg:d}=e,[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!0),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=n||i,T=async()=>{try{if(p(!0),!r)return;let e=await (0,b.t$)(r,t);h(e)}catch(e){F.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{p(!1)}};(0,u.useEffect)(()=>{T()},[t,r]);let A=async e=>{try{if(null==r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.vh)(r,t,s),F.ZP.success("Organization member added successfully"),v(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},E=async e=>{try{if(!r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.LY)(r,t,s),F.ZP.success("Organization member updated successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},L=async e=>{try{if(!r)return;await (0,b.Sb)(r,t,e.user_id),F.ZP.success("Organization member deleted successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},R=async e=>{try{if(!r)return;let s={organization_id:t,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,b.VA)(r,s),F.ZP.success("Organization settings updated successfully"),f(!1),T()}catch(e){F.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return x?(0,m.jsx)("div",{className:"p-4",children:"Loading..."}):c?(0,m.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:a,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:c.organization_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:c.organization_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:d?2:0,children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Members"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Organization Details"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Created: ",new Date(c.created_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Updated: ",new Date(c.updated_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Created By: ",c.created_by]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",c.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===c.litellm_budget_table.max_budget?"Unlimited":"$".concat(c.litellm_budget_table.max_budget)]}),c.litellm_budget_table.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",c.litellm_budget_table.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]}),c.litellm_budget_table.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",c.litellm_budget_table.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:null===(s=c.teams)||void 0===s?void 0:s.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e.team_id},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Created At"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:null===(l=c.members)||void 0===l?void 0:l.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_role})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["$",e.spend.toFixed(6)]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,m.jsx)(e6.Z,{children:k&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{w({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),Z(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{L(e)}})]})})]},s))})]})}),k&&(0,m.jsx)(C.Z,{onClick:()=>{v(!0)},children:"Add Member"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Organization Settings"}),k&&!j&&(0,m.jsx)(C.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,m.jsxs)(M.Z,{form:g,onFinish:R,initialValues:{organization_alias:c.organization_alias,models:c.models,tpm_limit:c.litellm_budget_table.tpm_limit,rpm_limit:c.litellm_budget_table.rpm_limit,max_budget:c.litellm_budget_table.max_budget,budget_duration:c.litellm_budget_table.budget_duration,metadata:c.metadata?JSON.stringify(c.metadata,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization Name"}),(0,m.jsx)("div",{children:c.organization_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{className:"font-mono",children:c.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(c.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==c.litellm_budget_table.max_budget?"$".concat(c.litellm_budget_table.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",c.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,m.jsx)(sK,{isVisible:_,onCancel:()=>v(!1),onSubmit:A,accessToken:r,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,m.jsx)(sV,{visible:y,onCancel:()=>Z(!1),onSubmit:E,initialData:N,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,m.jsx)("div",{className:"p-4",children:"Organization not found"})};let lE=async(e,s)=>{s(await (0,b.r6)(e))};var lP=e=>{let{organizations:s,userRole:l,userModels:t,accessToken:a,lastRefreshed:r,handleRefreshClick:n,currentOrg:i,guardrailsList:o=[],setOrganizations:d,premiumUser:c}=e,[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(!1),[N]=M.Z.useForm();(0,u.useEffect)(()=>{0===s.length&&a&&lE(a,d)},[s,a]);let w=e=>{e&&(v(e),f(!0))},T=async()=>{if(_&&a)try{await (0,b.cq)(a,_),F.ZP.success("Organization deleted successfully"),f(!1),v(null),lE(a,d)}catch(e){console.error("Error deleting organization:",e)}},A=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,b.H1)(a,e),Z(!1),N.resetFields(),lE(a,d)}catch(e){console.error("Error creating organization:",e)}};return c?h?(0,m.jsx)(lA,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===l,userModels:t,editOrg:p}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsx)("div",{className:"flex",children:(0,m.jsx)(eM.Z,{children:"Your Organizations"})}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[r&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",r]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:n})]})]}),(0,m.jsx)(eU.Z,{children:(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(P.Z,{children:"Click on “Organization ID” to view organization details."}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Organization ID"}),(0,m.jsx)(e7.Z,{children:"Organization Name"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"TPM / RPM Limits"}),(0,m.jsx)(e7.Z,{children:"Info"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var s,t,a,r,n,i,o,d,c;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.organization_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(s=e.organization_id)||void 0===s?void 0:s.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{children:e.organization_alias}),(0,m.jsx)(e6.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{children:e.spend}),(0,m.jsx)(e6.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(r=e.litellm_budget_table)||void 0===r?void 0:r.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{children:Array.isArray(e.models)&&(0,m.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)},s))})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["TPM: ",(null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit)?null===(i=e.litellm_budget_table)||void 0===i?void 0:i.tpm_limit:"Unlimited",(0,m.jsx)("br",{}),"RPM: ",(null===(o=e.litellm_budget_table)||void 0===o?void 0:o.rpm_limit)?null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit:"Unlimited"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[(null===(c=e.members)||void 0===c?void 0:c.length)||0," Members"]})}),(0,m.jsx)(e6.Z,{children:"Admin"===l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>w(e.organization_id),icon:eK.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===l||"Org Admin"===l)&&(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>Z(!0),children:"+ Create New Organization"}),(0,m.jsx)(R.Z,{title:"Create Organization",visible:y,width:800,footer:null,onCancel:()=>{Z(!1),N.resetFields()},children:(0,m.jsxs)(M.Z,{form:N,onFinish:A,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),j?(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Organization"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this organization?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:T,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})}):(0,m.jsx)(m.Fragment,{})]}):(0,m.jsx)("div",{children:(0,m.jsxs)(P.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,m.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lO=l(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lM=e=>{let{isAddSSOModalVisible:s,isInstructionsModalVisible:l,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:r,handleInstructionsOk:n,handleInstructionsCancel:i,form:o}=e,d=e=>{let s=lD[e];return s?s.fields.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,m.jsx)(z.default.Password,{}):(0,m.jsx)(I.Z,{placeholder:e.placeholder})},e.name)):null};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(R.Z,{title:"Add SSO",visible:s,width:800,footer:null,onOk:t,onCancel:a,children:(0,m.jsxs)(M.Z,{form:o,onFinish:r,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,m.jsx)(D.default,{children:Object.entries(lL).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[l&&(0,m.jsx)("img",{src:l,alt:s,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,m.jsxs)("span",{children:[s.charAt(0).toUpperCase()+s.slice(1)," SSO"]})]})},s)})})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.sso_provider!==s.sso_provider,children:e=>{let{getFieldValue:s}=e,l=s("sso_provider");return l?d(l):null}}),(0,m.jsx)(M.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,m.jsxs)(R.Z,{title:"SSO Setup Instructions",visible:l,width:800,footer:null,onOk:n,onCancel:i,children:[(0,m.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{onClick:n,children:"Done"})})]})]})},lF=l(62272),lR=l(92403),lq=l(29271),lU=l(34419);let lz=e=>{if(!e)return"An unknown error occurred";if("string"==typeof e)return e;if(e.message)try{let s=JSON.parse(e.message);if(s.error&&s.error.message)return s.error.message;return"string"==typeof s?s:JSON.stringify(s,null,2)}catch(s){return e.message}if(e.response&&e.response.data){if("string"==typeof e.response.data)return e.response.data;if(e.response.data.message)return e.response.data.message;if(e.response.data.error)return"string"==typeof e.response.data.error?e.response.data.error:e.response.data.error.message||JSON.stringify(e.response.data.error)}return String(e)};var lV=e=>{let{accessToken:s,userID:l,proxySettings:t}=e,[a]=M.Z.useForm(),[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(null),[d,c]=(0,u.useState)("");(0,u.useEffect)(()=>{let e="";c(t&&t.PROXY_BASE_URL&&void 0!==t.PROXY_BASE_URL?t.PROXY_BASE_URL:window.location.origin)},[t]);let h="".concat(d,"/scim/v2"),x=async e=>{if(!s||!l){F.ZP.error("You need to be logged in to create a SCIM token");return}try{n(!0);let t={key_alias:e.key_alias||"SCIM Access Token",team_id:null,models:[],allowed_routes:["/scim/*"]},a=await (0,b.wX)(s,l,t);o(a),F.ZP.success("SCIM token created successfully")}catch(e){console.error("Error creating SCIM token:",e),F.ZP.error("Failed to create SCIM token: "+lz(e))}finally{n(!1)}};return(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex items-center mb-4",children:(0,m.jsx)(O.Z,{children:"SCIM Configuration"})}),(0,m.jsx)(P.Z,{className:"text-gray-600",children:"System for Cross-domain Identity Management (SCIM) allows you to automatically provision and manage users and groups in LiteLLM."}),(0,m.jsx)(ly.Z,{}),(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"1"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lF.Z,{className:"h-5 w-5 mr-2"}),"SCIM Tenant URL"]})]}),(0,m.jsx)(P.Z,{className:"text-gray-600 mb-3",children:"Use this URL in your identity provider SCIM integration settings."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:h,disabled:!0,className:"flex-grow"}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>F.ZP.success("URL copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"ml-2 flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"2"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-5 w-5 mr-2"}),"Authentication Token"]})]}),(0,m.jsx)(lO.Z,{title:"Using SCIM",color:"blue",className:"mb-4",children:"You need a SCIM token to authenticate with the SCIM API. Create one below and use it in your SCIM provider configuration."}),i?(0,m.jsxs)(eD.Z,{className:"border border-yellow-300 bg-yellow-50",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 text-yellow-800",children:[(0,m.jsx)(lq.Z,{className:"h-5 w-5 mr-2"}),(0,m.jsx)(O.Z,{className:"text-lg text-yellow-800",children:"Your SCIM Token"})]}),(0,m.jsx)(P.Z,{className:"text-yellow-800 mb-4 font-medium",children:"Make sure to copy this token now. You will not be able to see it again."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:i.token,className:"flex-grow mr-2 bg-white",type:"password",disabled:!0}),(0,m.jsx)(L.CopyToClipboard,{text:i.token,onCopy:()=>F.ZP.success("Token copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]}),(0,m.jsxs)(C.Z,{className:"mt-4 flex items-center",variant:"secondary",onClick:()=>o(null),children:[(0,m.jsx)(lU.Z,{className:"h-4 w-4 mr-1"}),"Create Another Token"]})]}):(0,m.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,m.jsxs)(M.Z,{form:a,onFinish:x,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Token Name",rules:[{required:!0,message:"Please enter a name for your token"}],children:(0,m.jsx)(I.Z,{placeholder:"SCIM Access Token"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)(C.Z,{variant:"primary",type:"submit",loading:r,className:"flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-4 w-4 mr-1"}),"Create SCIM Token"]})})]})})]})]})]})})},lK=e=>{let{searchParams:s,accessToken:l,userID:t,showSSOBanner:a,premiumUser:r,proxySettings:n}=e,[i]=M.Z.useForm(),[o]=M.Z.useForm(),{Title:d,Paragraph:c}=et.default,[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(!1),[w,k]=(0,u.useState)(!1),[S,I]=(0,u.useState)(!1),[T,A]=(0,u.useState)(!1),[E,P]=(0,u.useState)(!1),[O,L]=(0,u.useState)(!1),[D,q]=(0,u.useState)(!1),[V,K]=(0,u.useState)(!1),[B,H]=(0,u.useState)([]),[J,G]=(0,u.useState)(null);(0,h.useRouter)();let[W,Y]=(0,u.useState)(null);console.log=function(){};let $=e0(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==r){F.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(l){let e=await (0,b.PT)(l);H(e&&e.length>0?e:[X])}else H([X])}catch(e){console.error("Error fetching allowed IPs:",e),F.ZP.error("Failed to fetch allowed IPs ".concat(e)),H([X])}finally{!0===r&&L(!0)}},es=async e=>{try{if(l){await (0,b.eH)(l,e.ip);let s=await (0,b.PT)(l);H(s),F.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),F.ZP.error("Failed to add IP address ".concat(e))}finally{q(!1)}},el=async e=>{G(e),K(!0)},ea=async()=>{if(J&&l)try{await (0,b.$I)(l,J);let e=await (0,b.PT)(l);H(e.length>0?e:[X]),F.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),F.ZP.error("Failed to delete IP address ".concat(e))}finally{K(!1),G(null)}};(0,u.useEffect)(()=>{(async()=>{if(null!=l){let e=[],s=await (0,b.Xd)(l,"proxy_admin_viewer");console.log("proxy admin viewer response: ",s);let t=s.users;console.log("proxy viewers response: ".concat(t)),t.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,b.Xd)(l,"proxy_admin")).users;a.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),j(e),Y(await (0,b.lg)(l))}})()},[l]);let er=async e=>{try{if(null!=l&&null!=g){var s;F.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,b.pf)(l,e,"proxy_admin"),a=(null===(s=t.data)||void 0===s?void 0:s.user_id)||t.user_id;(0,b.XO)(l,a).then(e=>{_(e),y(!0)}),console.log("response for team create call: ".concat(t));let r=g.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),g.push(t),j(g)),i.resetFields(),k(!1)}}catch(e){console.error("Error creating the key:",e)}},en=async e=>{if(null==l)return;let s=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};s&&Object.entries(s.envVarMap).forEach(s=>{let[l,a]=s;e[l]&&(t[a]=e[l])}),(0,b.K_)(l,{environment_variables:t})};return console.log("admins: ".concat(null==g?void 0:g.length)),(0,m.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,m.jsx)(d,{level:4,children:"Admin Access "}),(0,m.jsx)(c,{children:"Go to 'Internal Users' page to add other admins."}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Security Settings"}),(0,m.jsx)(eM.Z,{children:"SCIM"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(d,{level:4,children:" ✨ Security Settings"}),(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:()=>!0===r?A(!0):F.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,m.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,m.jsx)(lM,{isAddSSOModalVisible:T,isInstructionsModalVisible:E,handleAddSSOOk:()=>{A(!1),i.resetFields()},handleAddSSOCancel:()=>{A(!1),i.resetFields()},handleShowInstructions:e=>{er(e),en(e),A(!1),P(!0)},handleInstructionsOk:()=>{P(!1)},handleInstructionsCancel:()=>{P(!1)},form:i}),(0,m.jsx)(R.Z,{title:"Manage Allowed IP Addresses",width:800,visible:O,onCancel:()=>L(!1),footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,m.jsx)(C.Z,{onClick:()=>L(!1),children:"Close"},"close")],children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"IP Address"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:B.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e}),(0,m.jsx)(e6.Z,{className:"text-right",children:e!==X&&(0,m.jsx)(C.Z,{onClick:()=>el(e),color:"red",size:"xs",children:"Delete"})})]},s))})]})}),(0,m.jsx)(R.Z,{title:"Add Allowed IP Address",visible:D,onCancel:()=>q(!1),footer:null,children:(0,m.jsxs)(M.Z,{onFinish:es,children:[(0,m.jsx)(M.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,m.jsx)(z.default,{placeholder:"Enter IP address"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,m.jsx)(R.Z,{title:"Confirm Delete",visible:V,onCancel:()=>K(!1),onOk:ea,footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>ea(),children:"Yes"},"delete"),(0,m.jsx)(C.Z,{onClick:()=>K(!1),children:"Close"},"close")],children:(0,m.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",J,"?"]})})]}),(0,m.jsxs)(lO.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,m.jsxs)("a",{href:Q,target:"_blank",children:[(0,m.jsx)("b",{children:Q})," "]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lV,{accessToken:l,userID:t,proxySettings:n})})]})]})]})},lB=l(92858);let{Title:lH}=et.default;var lJ=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)([]);(0,u.useEffect)(()=>{n()},[s]);let n=async()=>{if(s){t(!0);try{let e=await (0,b.pu)(s);r(e.settings)}catch(e){console.error("Failed to fetch email event settings:",e),F.ZP.error("Failed to fetch email event settings")}finally{t(!1)}}},i=(e,s)=>{r(a.map(l=>l.event===e?{...l,enabled:s}:l))},o=async()=>{if(s)try{await (0,b.qW)(s,{settings:a}),F.ZP.success("Email event settings updated successfully")}catch(e){console.error("Failed to update email event settings:",e),F.ZP.error("Failed to update email event settings")}},d=async()=>{if(s)try{await (0,b.jr)(s),F.ZP.success("Email event settings reset to defaults"),n()}catch(e){console.error("Failed to reset email event settings:",e),F.ZP.error("Failed to reset email event settings")}},c=e=>{if(e.includes("Virtual Key Created"))return"An email will be sent to the user when a new virtual key is created with their user ID";if(e.includes("New User Invitation"))return"An email will be sent to the email address of the user when a new user is created";{let s=e.split(/(?=[A-Z])/).join(" ").toLowerCase();return"Receive an email notification when ".concat(s)}};return(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lH,{level:4,children:"Email Notifications"}),(0,m.jsx)(P.Z,{children:"Select which events should trigger email notifications."}),(0,m.jsx)(le.Z,{}),l?(0,m.jsx)("div",{style:{textAlign:"center",padding:"20px"},children:(0,m.jsx)(lb.Z,{size:"large"})}):(0,m.jsx)("div",{className:"space-y-4",children:a.map(e=>(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(sL.Z,{checked:e.enabled,onChange:s=>i(e.event,s.target.checked)}),(0,m.jsxs)("div",{className:"ml-3",children:[(0,m.jsx)(P.Z,{children:e.event}),(0,m.jsx)("div",{className:"text-sm text-gray-500 block",children:c(e.event)})]})]},e.event))}),(0,m.jsxs)("div",{className:"mt-6 flex space-x-4",children:[(0,m.jsx)(C.Z,{onClick:o,disabled:l,children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:d,variant:"secondary",disabled:l,children:"Reset to Defaults"})]})]})};let{Title:lG}=et.default;var lW=e=>{let{accessToken:s,premiumUser:l,alerts:t}=e,a=()=>{if(!s)return;let e={};t.filter(e=>"email"===e.name).forEach(s=>{var l;Object.entries(null!==(l=s.variables)&&void 0!==l?l:{}).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));a&&a.value&&(e[l]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,b.K_)(s,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Email settings updated successfully")};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mt-6 mb-6",children:(0,m.jsx)(lJ,{accessToken:s})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lG,{level:4,children:"Email Server Settings"}),(0,m.jsxs)(P.Z,{children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,m.jsx)("br",{})]}),(0,m.jsx)("div",{className:"flex w-full",children:t.filter(e=>"email"===e.name).map((e,s)=>{var t;return(0,m.jsx)(e6.Z,{children:(0,m.jsx)("ul",{children:(0,m.jsx)(S.Z,{numItems:2,children:Object.entries(null!==(t=e.variables)&&void 0!==t?t:{}).map(e=>{let[s,t]=e;return(0,m.jsxs)("li",{className:"mx-2 my-2",children:[!0!=l&&("EMAIL_LOGO_URL"===s||"EMAIL_SUPPORT_CONTACT"===s)?(0,m.jsxs)("div",{children:[(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,m.jsxs)(P.Z,{className:"mt-2",children:[" ","✨ ",s]})}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-2",children:s}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",style:{width:"400px"}})]}),(0,m.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===s&&(0,m.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},s)})})})},s)})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>a(),children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>s&&(0,b.jE)(s,"email"),className:"mx-2",children:"Test Email Alerts"})]})]})},lY=e=>{let{alertingSettings:s,handleInputChange:l,handleResetField:t,handleSubmit:a,premiumUser:r}=e,[n]=M.Z.useForm();return(0,m.jsxs)(M.Z,{form:n,onFinish:()=>{console.log("INSIDE ONFINISH");let e=n.getFieldsValue(),s=Object.entries(e).every(e=>{let[s,l]=e;return"boolean"!=typeof l&&(""===l||null==l)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(s)),s?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[s.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{align:"center",children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?r?(0,m.jsx)(M.Z.Item,{name:e.field_name,children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s)}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>l(e.field_name,s)}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}):(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,m.jsx)(M.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s),className:"p-0"}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>{l(e.field_name,s),n.setFieldsValue({[e.field_name]:s})}}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>t(e.field_name,s),children:"Reset"})})]},s)),(0,m.jsx)("div",{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Update Settings"})})]})},l$=e=>{let{accessToken:s,premiumUser:l}=e,[t,a]=(0,u.useState)([]);return(0,u.useEffect)(()=>{s&&(0,b.RQ)(s).then(e=>{a(e)})},[s]),(0,m.jsx)(lY,{alertingSettings:t,handleInputChange:(e,s)=>{let l=t.map(l=>l.field_name===e?{...l,field_value:s}:l);console.log("updatedSettings: ".concat(JSON.stringify(l))),a(l)},handleResetField:(e,l)=>{if(s)try{let s=t.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:s.field_default_value}:s);a(s)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!s||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let l={};t.forEach(e=>{l[e.field_name]=e.field_value});let a={...e,...l};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...n}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(n)));try{(0,b.jA)(s,"alerting_args",n),"boolean"==typeof r&&(!0==r?(0,b.jA)(s,"alerting",["slack"]):(0,b.jA)(s,"alerting",[])),F.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:l})},lX=l(86582);let{Title:lQ,Paragraph:l0}=et.default;console.log=function(){};var l1=e=>{let{accessToken:s,userRole:l,userID:t,premiumUser:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h]=M.Z.useForm(),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)({}),[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(!1),[T,A]=(0,u.useState)([]),[E,O]=(0,u.useState)(null),[L,q]=(0,u.useState)([]),[z,V]=(0,u.useState)(!1),[K,B]=(0,u.useState)(null),H=e=>{Z.includes(e)?N(Z.filter(s=>s!==e)):N([...Z,e])},J={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,u.useEffect)(()=>{s&&l&&t&&(0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e),n(e.callbacks),A(e.available_callbacks);let s=e.alerts;if(console.log("alerts_data",s),s&&s.length>0){let e=s[0];console.log("_alert_info",e);let l=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",l),N(e.active_alerts),_(l),y(e.alerts_to_webhook)}o(s)})},[s,l,t]);let G=e=>Z&&Z.includes(e),W=async e=>{if(!s)return;let l={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(l[s]=t)});try{await (0,b.K_)(s,{environment_variables:l}),F.ZP.success("Callback added successfully"),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},Y=async e=>{if(!s)return;let l=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[s,l]=e;"callback"!==s&&(t[s]=l)});try{await (0,b.K_)(s,{environment_variables:t,litellm_settings:{success_callback:[l]}}),F.ZP.success("Callback ".concat(l," added successfully")),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},$=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",T),e&&e.litellm_callback_params?(q(e.litellm_callback_params),console.log("selectedCallbackParams",L)):q([])};return s?(console.log("callbacks: ".concat(r)),(0,m.jsxs)("div",{className:"w-full mx-4",children:[(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Logging Callbacks"}),(0,m.jsx)(eM.Z,{value:"2",children:"Alerting Types"}),(0,m.jsx)(eM.Z,{value:"3",children:"Alerting Settings"}),(0,m.jsx)(eM.Z,{value:"4",children:"Email Alerts"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(lQ,{level:4,children:"Active Logging Callbacks"}),(0,m.jsx)(S.Z,{numItems:2,children:(0,m.jsx)(eD.Z,{className:"max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e7.Z,{children:"Callback Name"})})}),(0,m.jsx)(e3.Z,{children:r.map((e,l)=>(0,m.jsxs)(e9.Z,{className:"flex justify-between",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.name})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"flex justify-between",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{B(e),V(!0)}}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},l))})]})})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>k(!0),children:"Add Callback"})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(P.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,m.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{children:"Slack Webhook URL"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(J).map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:"region_outage_alerts"==l?a?(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)}):(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:l,type:"password",defaultValue:v&&v[l]?v[l]:f})})]},s)})})]}),(0,m.jsx)(C.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!s)return;let e={};Object.entries(J).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));console.log("key",l),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[l]=r}),console.log("updatedAlertToWebhooks",e);let l={general_settings:{alert_to_webhook_url:e,alert_types:Z}};console.log("payload",l);try{(0,b.K_)(s,l)}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(l$,{accessToken:s,premiumUser:a})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lW,{accessToken:s,premiumUser:a,alerts:i})})]})]})}),(0,m.jsxs)(R.Z,{title:"Add Logging Callback",visible:w,width:800,onCancel:()=>k(!1),footer:null,children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,m.jsx)(M.Z,{form:h,onFinish:Y,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lX.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,m.jsx)(D.default,{onChange:e=>{let s=T[e];s&&(console.log(s.ui_callback_name),$(s))},children:T&&Object.values(T).map(e=>(0,m.jsx)(el.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),L&&L.map(e=>(0,m.jsx)(lX.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,m.jsx)(I.Z,{type:"password"})},e)),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,m.jsx)(R.Z,{visible:z,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>V(!1),footer:null,children:(0,m.jsxs)(M.Z,{form:h,onFinish:W,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(m.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[s,l]=e;return(0,m.jsx)(lX.Z,{label:s,name:s,children:(0,m.jsx)(I.Z,{type:"password",defaultValue:l})},s)})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},l2=l(92414),l4=l(46030);let{Option:l5}=D.default;var l3=e=>{let{models:s,accessToken:l,routerSettings:t,setRouterSettings:a}=e,[r]=M.Z.useForm(),[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Add Fallbacks"}),(0,m.jsx)(R.Z,{title:"Add Fallbacks",visible:n,width:800,footer:null,onOk:()=>{i(!1),r.resetFields()},onCancel:()=>{i(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:e=>{console.log(e);let{model_name:s,models:n}=e,o=[...t.fallbacks||[],{[s]:n}],d={...t,fallbacks:o};console.log(d);try{(0,b.K_)(l,{router_settings:d}),a(d)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully"),i(!1),r.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,m.jsx)(eO.Z,{defaultValue:o,children:s&&s.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>d(e),children:e},s))})}),(0,m.jsx)(M.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,m.jsx)(l2.Z,{value:s,children:s&&s.filter(e=>e!=o).map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},l6=l(26433);async function l8(e,s){console.log=function(){},console.log("isLocal:",!1);let l=window.location.origin,t=new l6.ZP.OpenAI({apiKey:s,baseURL:l,dangerouslyAllowBrowser:!0});try{let s=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});F.ZP.success((0,m.jsxs)("span",{children:["Test model=",(0,m.jsx)("strong",{children:e}),", received model=",(0,m.jsx)("strong",{children:s.model}),". See"," ",(0,m.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l7={ttl:3600,lowest_latency_buffer:0},l9=e=>{let{selectedStrategy:s,strategyArgs:l,paramExplanation:t}=e;return(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,m.jsx)(A.Z,{children:"latency-based-routing"==s?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(l).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[s]})]}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]})}):(0,m.jsx)(P.Z,{children:"No specific settings"})})]})};var te=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,n]=(0,u.useState)({}),[i,o]=(0,u.useState)({}),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(null),Z={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,u.useEffect)(()=>{s&&l&&t&&((0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e);let s=e.router_settings;"model_group_retry_policy"in s&&delete s.model_group_retry_policy,n(s)}),(0,b.YU)(s).then(e=>{c(e)}))},[s,l,t]);let N=async e=>{if(!s)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(r.fallbacks));let l=r.fallbacks.map(s=>(e in s&&delete s[e],s)).filter(e=>Object.keys(e).length>0),t={...r,fallbacks:l};try{await (0,b.K_)(s,{router_settings:t}),n(t),F.ZP.success("Router settings updated successfully")}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}},w=(e,s)=>{c(d.map(l=>l.field_name===e?{...l,field_value:s}:l))},T=(e,l)=>{if(!s)return;let t=d[l].field_value;if(null!=t&&void 0!=t)try{(0,b.jA)(s,e,t);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:!0}:s);c(l)}catch(e){}},A=(e,l)=>{if(s)try{(0,b.ao)(s,e);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:null}:s);c(l)}catch(e){}},E=e=>{if(!s)return;console.log("router_settings",e);let l=Object.fromEntries(Object.entries(e).map(e=>{let[s,l]=e;if("routing_strategy_args"!==s&&"routing_strategy"!==s){var t;return[s,(null===(t=document.querySelector('input[name="'.concat(s,'"]')))||void 0===t?void 0:t.value)||l]}if("routing_strategy"==s)return[s,f];if("routing_strategy_args"==s&&"latency-based-routing"==f){let e={},s=document.querySelector('input[name="lowest_latency_buffer"]'),l=document.querySelector('input[name="ttl"]');return(null==s?void 0:s.value)&&(e.lowest_latency_buffer=Number(s.value)),(null==l?void 0:l.value)&&(e.ttl=Number(l.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",l);try{(0,b.K_)(s,{router_settings:l})}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully")};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Loadbalancing"}),(0,m.jsx)(eM.Z,{value:"2",children:"Fallbacks"}),(0,m.jsx)(eM.Z,{value:"3",children:"General"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,m.jsx)(O.Z,{children:"Router Settings"}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(r).filter(e=>{let[s,l]=e;return"fallbacks"!=s&&"context_window_fallbacks"!=s&&"routing_strategy_args"!=s}).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:Z[s]})]}),(0,m.jsx)(e6.Z,{children:"routing_strategy"==s?(0,m.jsxs)(eO.Z,{defaultValue:l,className:"w-full max-w-md",onValueChange:_,children:[(0,m.jsx)(el.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,m.jsx)(el.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,m.jsx)(el.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]}),(0,m.jsx)(l9,{selectedStrategy:f,strategyArgs:r&&r.routing_strategy_args&&Object.keys(r.routing_strategy_args).length>0?r.routing_strategy_args:l7,paramExplanation:Z})]}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>E(r),children:"Save Changes"})})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Model Name"}),(0,m.jsx)(e7.Z,{children:"Fallbacks"})]})}),(0,m.jsx)(e3.Z,{children:r.fallbacks&&r.fallbacks.map((e,l)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:t}),(0,m.jsx)(e6.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{onClick:()=>l8(t,s),children:"Test Fallback"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>N(t)})})]},l.toString()+t)}))})]}),(0,m.jsx)(l3,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:s,routerSettings:r,setRouterSettings:n})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"}),(0,m.jsx)(e7.Z,{children:"Status"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:d.filter(e=>"TypedDictionary"!==e.field_type).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,m.jsx)(e6.Z,{children:"Integer"==e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>w(e.field_name,s)}):null}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{onClick:()=>T(e.field_name,s),children:"Update"}),(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>A(e.field_name,s),children:"Reset"})]})]},s))})]})})})]})]})}):null},ts=l(93142),tl=e=>{let{value:s={},onChange:l}=e,[t,a]=(0,u.useState)(Object.entries(s)),r=e=>{let s=t.filter((s,l)=>l!==e);a(s),null==l||l(Object.fromEntries(s))},n=(e,s,r)=>{let n=[...t];n[e]=[s,r],a(n),null==l||l(Object.fromEntries(n))};return(0,m.jsxs)("div",{children:[t.map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(ts.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,m.jsx)(I.Z,{placeholder:"Header Name",value:l,onChange:e=>n(s,e.target.value,t)}),(0,m.jsx)(I.Z,{placeholder:"Header Value",value:t,onChange:e=>n(s,l,e.target.value)}),(0,m.jsx)(s$.Z,{onClick:()=>r(s)})]},s)}),(0,m.jsx)(U.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,m.jsx)(sX.Z,{}),children:"Add Header"})]})};let{Option:tt}=D.default;var ta=e=>{let{accessToken:s,setPassThroughItems:l,passThroughItems:t}=e,[a]=M.Z.useForm(),[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>n(!0),children:"+ Add Pass-Through Endpoint"}),(0,m.jsx)(R.Z,{title:"Add Pass-Through Endpoint",visible:r,width:800,footer:null,onOk:()=>{n(!1),a.resetFields()},onCancel:()=>{n(!1),a.resetFields()},children:(0,m.jsxs)(M.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,b.Vt)(s,e),l(r)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("Pass through endpoint successfully added"),n(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,m.jsx)(tl,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},tr=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,n]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&l&&t&&(0,b.mp)(s).then(e=>{n(e.endpoints)})},[s,l,t]);let i=(e,l)=>{if(s)try{(0,b.EG)(s,e);let l=r.filter(s=>s.path!==e);n(l),F.ZP.success("Endpoint deleted successfully.")}catch(e){}};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsx)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Path"}),(0,m.jsx)(e7.Z,{children:"Target"}),(0,m.jsx)(e7.Z,{children:"Headers"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:r.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.path})}),(0,m.jsx)(e6.Z,{children:e.target}),(0,m.jsx)(e6.Z,{children:JSON.stringify(e.headers)}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>i(e.path,s),children:"Reset"})})]},s))})]}),(0,m.jsx)(ta,{accessToken:s,setPassThroughItems:n,passThroughItems:r})]})})}):null},tn=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a}=e,[r]=M.Z.useForm(),n=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call");let s=await (0,b.Zr)(l,e);console.log("key create Response:",s),a(e=>e?[...e,s]:[s]),F.ZP.success("API Key Created"),r.resetFields()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Create Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),r.resetFields()},onCancel:()=>{t(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:n,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},ti=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a,existingBudget:r,handleUpdateCall:n}=e;console.log("existingBudget",r);let[i]=M.Z.useForm();(0,u.useEffect)(()=>{i.setFieldsValue(r)},[r,i]);let o=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call"),t(!0);let s=await (0,b.qI)(l,e);a(e=>e?[...e,s]:[s]),F.ZP.success("Budget Updated"),i.resetFields(),n()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Edit Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),i.resetFields()},onCancel:()=>{t(!1),i.resetFields()},children:(0,m.jsxs)(M.Z,{form:i,onFinish:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:r,children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})},to=l(17906),td=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&(0,b.O3)(s).then(e=>{d(e)})},[s]);let c=async(e,l)=>{console.log("budget_id",e),null!=s&&(i(o.find(s=>s.budget_id===e)||null),r(!0))},h=async(e,l)=>{if(null==s)return;F.ZP.info("Request made"),await (0,b.NV)(s,e);let t=[...o];t.splice(l,1),d(t),F.ZP.success("Budget Deleted.")},x=async()=>{null!=s&&(0,b.O3)(s).then(e=>{d(e)})};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)(C.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,m.jsx)(tn,{accessToken:s,isModalVisible:l,setIsModalVisible:t,setBudgetList:d}),n&&(0,m.jsx)(ti,{accessToken:s,isModalVisible:a,setIsModalVisible:r,setBudgetList:d,existingBudget:n,handleUpdateCall:x}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Create a budget to assign to customers."}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Budget ID"}),(0,m.jsx)(e7.Z,{children:"Max Budget"}),(0,m.jsx)(e7.Z,{children:"TPM"}),(0,m.jsx)(e7.Z,{children:"RPM"})]})}),(0,m.jsx)(e3.Z,{children:o.slice().sort((e,s)=>new Date(s.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.budget_id}),(0,m.jsx)(e6.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,m.jsx)(e6.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,m.jsx)(e6.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>c(e.budget_id,s)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>h(e.budget_id,s)})]},s))})]})]}),(0,m.jsxs)("div",{className:"mt-5",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"How to use budget id"}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Assign Budget to Customer"}),(0,m.jsx)(eM.Z,{children:"Test it (Curl)"}),(0,m.jsx)(eM.Z,{children:"Test it (OpenAI SDK)"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},tc=l(77398),tm=l.n(tc);function tu(e){let{data:s=[],columns:l,getRowCanExpand:t,renderSubComponent:a,isLoading:r=!1,loadingMessage:n="\uD83D\uDE85 Loading logs...",noDataMessage:i="No logs found"}=e,o=(0,e2.b7)({data:s,columns:l,getRowCanExpand:t,getRowId:(e,s)=>{var l;return null!==(l=null==e?void 0:e.request_id)&&void 0!==l?l:String(s)},getCoreRowModel:(0,e4.sC)(),getExpandedRowModel:(0,e4.rV)()});return(0,m.jsx)("div",{className:"rounded-lg custom-border",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:r?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:n})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:i})})})})})]})})}let th=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},tx=e=>{let{utcTime:s}=e;return(0,m.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:th(s)})},tp=(e,s)=>{var l,t;return(null===(t=e.metadata)||void 0===t?void 0:null===(l=t.mcp_tool_call_metadata)||void 0===l?void 0:l.mcp_server_logo_url)?e.metadata.mcp_tool_call_metadata.mcp_server_logo_url:s?sm(s).logo:""},tg=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,m.jsx)(()=>{let[e,l]=u.useState(s.getIsExpanded()),t=u.useCallback(()=>{l(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,m.jsx)("button",{onClick:t,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,m.jsx)("svg",{className:"w-4 h-4 transform transition-transform duration-75 ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,m.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Time",accessorKey:"startTime",cell:e=>(0,m.jsx)(tx,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let s="failure"!==(e.getValue()||"Success").toLowerCase();return(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(s?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s?"Success":"Failure"})}},{header:"Session ID",accessorKey:"session_id",cell:e=>{let s=String(e.getValue()||""),l=e.row.original.onSessionClick;return(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal text-xs max-w-[15ch] truncate block",onClick:()=>null==l?void 0:l(s),children:String(e.getValue()||"")})})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)("span",{className:"font-mono text-xs max-w-[15ch] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,m.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let s=String(e.getValue()||"-"),l=e.row.original.onKeyHashClick;return(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsx)("span",{className:"font-mono max-w-[15ch] truncate block cursor-pointer hover:text-blue-600",onClick:()=>null==l?void 0:l(s),children:s})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Model",accessorKey:"model",cell:e=>{let s=e.row.original,l=s.custom_llm_provider,t=String(e.getValue()||"");return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:tp(s,l),alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(Y.Z,{title:t,children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:t})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let s=e.row.original;return(0,m.jsxs)("span",{className:"text-sm",children:[String(s.total_tokens||"0"),(0,m.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(s.prompt_tokens||"0"),"+",String(s.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"End User",accessorKey:"end_user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let s=e.getValue();if(!s||0===Object.keys(s).length)return"-";let l=Object.entries(s),t=l[0],a=l.slice(1);return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,m.jsx)(Y.Z,{title:(0,m.jsx)("div",{className:"flex flex-col gap-1",children:l.map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{children:[s,": ",String(l)]},s)})}),children:(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],tj=async(e,s,l,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,s],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,b.qk)(l,e.request_id,s);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}};function tf(e){let{row:s,hasMessages:l,hasResponse:t,hasError:a,errorInfo:r,getRawRequest:n,formattedResponse:i}=e;return(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,m.jsx)("button",{onClick:()=>{try{navigator.clipboard.writeText(JSON.stringify(n(),null,2)),F.ZP.success("Request copied to clipboard")}catch(e){F.ZP.error("Failed to copy request")}},className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(n(),null,2)})})]}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsxs)("h3",{className:"text-lg font-medium",children:["Response",a&&(0,m.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==r?void 0:r.error_code)||400]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(i(),null,2)),F.ZP.success("Response copied to clipboard")},className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!t,children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:t?(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(i(),null,2)}):(0,m.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]})}let t_=e=>{var s;let{errorInfo:l}=e,[t,a]=u.useState({}),[r,n]=u.useState(!1),i=e=>{a(s=>({...s,[e]:!s[e]}))},o=l.traceback&&(s=l.traceback)?Array.from(s.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let l=e[1],t=e[2],a=l.split("/").pop()||l,r=e.index||0,n=s.indexOf('File "',r+1),i=n>-1?s.substring(r,n).trim():s.substring(r).trim(),o=i.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:l,fileName:a,lineNumber:t,code:d,inFunction:i.includes(" in ")?i.split(" in ")[1].split("\n")[0]:""}}):[];return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,m.jsx)("span",{className:"text-red-700",children:l.error_class||"Unknown Error"})]}),(0,m.jsxs)("div",{className:"flex mt-2",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20 flex-shrink-0",children:"Message:"}),(0,m.jsx)("span",{className:"text-red-700 break-words whitespace-pre-wrap",children:l.error_message||"Unknown error occurred"})]})]}),l.traceback&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,m.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsx)("button",{onClick:()=>{let e=!r;if(n(e),o.length>0){let s={};o.forEach((l,t)=>{s[t]=e}),a(s)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:r?"Collapse All":"Expand All"}),(0,m.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(l.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,m.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,m.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:o.map((e,s)=>(0,m.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,m.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>i(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,m.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,m.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,m.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,m.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[s]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[s]||!1)&&e.code&&(0,m.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},s))})]})]})]})},tv=e=>{let{show:s}=e;return s?(0,m.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,m.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,m.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,m.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,m.jsxs)("div",{children:[(0,m.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,m.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,m.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,m.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,m.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};var ty=l(35829);let tb=e=>{let{sessionId:s,logs:l,onBack:t}=e,[a,r]=(0,u.useState)(null),n=l.reduce((e,s)=>e+(s.spend||0),0),i=l.reduce((e,s)=>e+(s.total_tokens||0),0),o=l.length>0?new Date(l[0].startTime):new Date;return(((l.length>0?new Date(l[l.length-1].endTime):new Date).getTime()-o.getTime())/1e3).toFixed(2),l.map(e=>({time:new Date(e.startTime).toISOString(),tokens:e.total_tokens||0,cost:e.spend||0})),(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)("div",{className:"flex items-center space-x-4",children:(0,m.jsxs)("button",{onClick:t,className:"flex items-center text-gray-600 hover:text-gray-900 transition-colors",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),"Back to All Logs"]})}),(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsx)("h1",{className:"text-2xl font-semibold text-gray-900",children:"Session Details"}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500 font-mono",children:s}),(0,m.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/ui_logs_sessions",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Get started with session management here",(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(ty.Z,{children:l.length})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Cost"}),(0,m.jsxs)(ty.Z,{children:["$",n.toFixed(4)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(ty.Z,{children:i})]})]}),(0,m.jsx)(O.Z,{children:"Session Logs"}),(0,m.jsx)("div",{className:"mt-4",children:(0,m.jsx)(tu,{columns:tg,data:l,renderSubComponent:tS,getRowCanExpand:()=>!0,loadingMessage:"Loading logs...",noDataMessage:"No logs found"})})]})};function tZ(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)({});if(!s||0===s.length)return null;let n=e=>new Date(1e3*e).toLocaleString(),i=(e,s)=>"".concat(((s-e)*1e3).toFixed(2),"ms"),o=(e,s)=>{let l="".concat(e,"-").concat(s);r(e=>({...e,[l]:!e[l]}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Vector Store Requests"})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsx)("div",{className:"p-4",children:s.map((e,s)=>(0,m.jsxs)("div",{className:"mb-6 last:mb-0",children:[(0,m.jsx)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Query:"}),(0,m.jsx)("span",{className:"font-mono",children:e.query})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Vector Store ID:"}),(0,m.jsx)("span",{className:"font-mono",children:e.vector_store_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{className:"flex items-center",children:(()=>{let{logo:s,displayName:l}=sm(e.custom_llm_provider);return(0,m.jsxs)(m.Fragment,{children:[s&&(0,m.jsx)("img",{src:s,alt:"".concat(l," logo"),className:"h-5 w-5 mr-2"}),l]})})()})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:n(e.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:n(e.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsx)("span",{children:i(e.start_time,e.end_time)})]})]})]})}),(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Search Results"}),(0,m.jsx)("div",{className:"space-y-2",children:e.vector_store_search_response.data.map((e,l)=>{let t=a["".concat(s,"-").concat(l)]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center p-3 bg-gray-50 cursor-pointer",onClick:()=>o(s,l),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsxs)("span",{className:"font-medium mr-2",children:["Result ",l+1]}),(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["Score: ",(0,m.jsx)("span",{className:"font-mono",children:e.score.toFixed(4)})]})]})]}),t&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:e.content.map((e,s)=>(0,m.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,m.jsx)("div",{className:"text-xs text-gray-500 mb-1",children:e.type}),(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded",children:e.text})]},s))})]},l)})})]},s))})]})}function tN(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)(!0),[n,i]=(0,u.useState)({});if(!s)return null;let o=s.masked_entity_count?Object.values(s.masked_entity_count).reduce((e,s)=>e+s,0):0,d=e=>new Date(1e3*e).toLocaleString(),c=e=>{i(s=>({...s,[e]:!s[e]}))},h=e=>e>=.8?"text-green-600":"text-yellow-600";return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Guardrail Information"}),(0,m.jsx)("span",{className:"ml-3 px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status}),o>0&&(0,m.jsxs)("span",{className:"ml-3 px-2 py-1 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[o," masked ",1===o?"entity":"entities"]})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:[(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail Name:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_name})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Mode:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_mode})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:d(s.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:d(s.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsxs)("span",{children:[s.duration.toFixed(4),"s"]})]})]})]}),s.masked_entity_count&&Object.keys(s.masked_entity_count).length>0&&(0,m.jsxs)("div",{className:"mt-4 pt-4 border-t",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Masked Entity Summary"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(s.masked_entity_count).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-3 py-1.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[s,": ",l]},s)})})]})]}),s.guardrail_response&&s.guardrail_response.length>0&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 cursor-pointer",onClick:()=>r(!a),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(a?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("h4",{className:"font-medium",children:["Detected Entities (",s.guardrail_response.length,")"]})]}),a&&(0,m.jsx)("div",{className:"space-y-2",children:s.guardrail_response.map((e,s)=>{let l=n[s]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>c(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("span",{className:"font-medium mr-2",children:e.entity_type}),(0,m.jsxs)("span",{className:"font-mono ".concat(h(e.score)),children:["Score: ",e.score.toFixed(2)]})]}),(0,m.jsxs)("span",{className:"text-xs text-gray-500",children:["Position: ",e.start,"-",e.end]})]}),l&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Entity Type:"}),(0,m.jsx)("span",{children:e.entity_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Position:"}),(0,m.jsxs)("span",{children:["Characters ",e.start,"-",e.end]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Confidence:"}),(0,m.jsx)("span",{className:h(e.score),children:e.score.toFixed(2)})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[e.recognition_metadata&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Recognizer:"}),(0,m.jsx)("span",{children:e.recognition_metadata.recognizer_name})]}),(0,m.jsxs)("div",{className:"flex overflow-hidden",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Identifier:"}),(0,m.jsx)("span",{className:"truncate text-xs font-mono",children:e.recognition_metadata.recognizer_identifier})]})]}),e.analysis_explanation&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Explanation:"}),(0,m.jsx)("span",{children:e.analysis_explanation})]})]})]})})]},s)})})]})]})]})}let tw={TEAM_ID:"Team ID",KEY_HASH:"Key Hash",REQUEST_ID:"Request ID",MODEL:"Model",USER_ID:"User ID",STATUS:"Status",KEY_ALIAS:"Key Alias"};function tk(e){var s,l,t;let{accessToken:a,token:r,userRole:n,userID:i,allTeams:o}=e,[d,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(!1),[p,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(1),[v]=(0,u.useState)(50),y=(0,u.useRef)(null),Z=(0,u.useRef)(null),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(tm()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,C]=(0,u.useState)(tm()().format("YYYY-MM-DDTHH:mm")),[I,T]=(0,u.useState)(!1),[A,E]=(0,u.useState)(!1),[P,O]=(0,u.useState)(""),[L,D]=(0,u.useState)(""),[M,F]=(0,u.useState)(""),[R,q]=(0,u.useState)(""),[U,z]=(0,u.useState)(""),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)(null),[J,G]=(0,u.useState)(""),[W,Y]=(0,u.useState)(n&&eZ.lo.includes(n)),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(null),es=(0,g.NL)();(0,u.useEffect)(()=>{(async()=>{B&&a&&K({...(await (0,b.t0)(a,B)).info,token:B,api_key:B})})()},[B,a]),(0,u.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),Z.current&&!Z.current.contains(e.target)&&x(!1),N.current&&!N.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,u.useEffect)(()=>{n&&eZ.lo.includes(n)&&Y(!0)},[n]);let el=(0,eY.a)({queryKey:["logs","table",f,v,w,S,M,R,W?i:null,J,U],queryFn:async()=>{if(!a||!r||!n||!i)return{data:[],total:0,page:1,page_size:v,total_pages:0};let e=tm()(w).utc().format("YYYY-MM-DD HH:mm:ss"),s=I?tm()(S).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss"),l=await (0,b.h3)(a,R||void 0,M||void 0,void 0,e,s,f,v,W?i:void 0,J,U);return await tj(l.data,e,a,es),l.data=l.data.map(s=>{let l=es.getQueryData(["logDetails",s.request_id,e]);return(null==l?void 0:l.messages)&&(null==l?void 0:l.response)&&(s.messages=l.messages,s.response=l.response),s}),l},enabled:!!a&&!!r&&!!n&&!!i,refetchInterval:5e3,refetchIntervalInBackground:!0}),{filters:et,filteredLogs:ea,allTeams:er,allKeyAliases:en,allModels:ei,handleFilterChange:eo,handleFilterReset:ed}=function(e){let{logs:s,accessToken:l,startTime:t,endTime:a,pageSize:r=25,isCustomDate:n,setCurrentPage:i,userID:o,userRole:d}=e,c=(0,u.useMemo)(()=>({[tw.TEAM_ID]:"",[tw.KEY_HASH]:"",[tw.REQUEST_ID]:"",[tw.MODEL]:"",[tw.USER_ID]:"",[tw.STATUS]:"",[tw.KEY_ALIAS]:""}),[]),[m,h]=(0,u.useState)(c),[x,p]=(0,u.useState)(s),g=(0,u.useRef)(0),j=(0,u.useCallback)(async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!l)return;let i=Date.now();g.current=i;let o=tm()(t).utc().format("YYYY-MM-DD HH:mm:ss"),d=n?tm()(a).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss");try{let t=await (0,b.h3)(l,e[tw.KEY_HASH]||void 0,e[tw.TEAM_ID]||void 0,e[tw.REQUEST_ID]||void 0,o,d,s,r,e[tw.USER_ID]||void 0,e[tw.STATUS]||void 0,e[tw.MODEL]||void 0);i===g.current&&t.data&&p(t)}catch(e){console.error("Error searching users:",e)}},[l,t,a,n,r]),f=(0,u.useMemo)(()=>eb()((e,s)=>j(e,s),300),[j]);(0,u.useEffect)(()=>()=>f.cancel(),[f]);let _=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!l)throw Error("Access token required");return await e$(l)},enabled:!!l}).data||[];(0,u.useEffect)(()=>{if(!s||!s.data){p({data:[],total:0,page:1,page_size:50,total_pages:0});return}let e=[...s.data];if(m[tw.TEAM_ID]&&(e=e.filter(e=>e.team_id===m[tw.TEAM_ID])),m[tw.STATUS]&&(e=e.filter(e=>"success"===m[tw.STATUS]?!e.status||"success"===e.status:e.status===m[tw.STATUS])),m[tw.MODEL]&&(e=e.filter(e=>e.model===m[tw.MODEL])),m[tw.KEY_HASH]&&(e=e.filter(e=>e.api_key===m[tw.KEY_HASH])),m[tw.KEY_ALIAS])try{let s=m[tw.KEY_ALIAS];s&&(e=e.filter(e=>{var l;return(null===(l=e.metadata)||void 0===l?void 0:l.user_api_key_alias)===s}))}catch(e){console.error("Error fetching key info for alias:",e)}let l={data:e,total:s.total,page:s.page,page_size:s.page_size,total_pages:s.total_pages};JSON.stringify(l)!==JSON.stringify(x)&&p(l)},[s,m,x,l]);let{data:v}=(0,eY.a)({queryKey:["allTeamsForLogFilters",l],queryFn:async()=>l&&await eX(l)||[],enabled:!!l}),{data:y=[]}=(0,eY.a)({queryKey:["allModels",l,o,d],queryFn:async()=>l&&o&&d?(await (0,b.So)(l,o,d,!1,null)).data.map(e=>e.id):[],enabled:!!l&&!!o&&!!d});return{filters:m,filteredLogs:x,allKeyAliases:_,allTeams:v,allModels:y,handleFilterChange:e=>{h(s=>{let l={...s,...e};for(let e of Object.keys(c))e in l||(l[e]=c[e]);return JSON.stringify(l)!==JSON.stringify(s)&&(i(1),f(l,1)),l})},handleFilterReset:()=>{h(c),f(c,1)}}}({logs:el.data||{data:[],total:0,page:1,page_size:v||10,total_pages:1},accessToken:a,startTime:w,endTime:S,pageSize:v,isCustomDate:I,setCurrentPage:_,userID:i,userRole:n}),ec=(0,u.useCallback)(async e=>{if(a)try{let s=(await (0,b.OD)(a,null,null,e,null,null,f,v)).keys.find(s=>s.key_alias===e);s&&q(s.token)}catch(e){console.error("Error fetching key hash for alias:",e)}},[a,f,v]);(0,u.useEffect)(()=>{a&&(et["Team ID"]?F(et["Team ID"]):F(""),G(et.Status||""),z(et.Model||""),et["Key Hash"]?q(et["Key Hash"]):et["Key Alias"]?ec(et["Key Alias"]):q(""))},[et,a,ec]);let em=(0,eY.a)({queryKey:["sessionLogs",Q],queryFn:async()=>{if(!a||!Q)return{data:[],total:0,page:1,page_size:50,total_pages:1};let e=await (0,b.XB)(a,Q);return{data:e.data||e||[],total:(e.data||e||[]).length,page:1,page_size:1e3,total_pages:1}},enabled:!!a&&!!Q});if((0,u.useEffect)(()=>{var e;(null===(e=el.data)||void 0===e?void 0:e.data)&&$&&!el.data.data.some(e=>e.request_id===$)&&X(null)},[null===(s=el.data)||void 0===s?void 0:s.data,$]),!a||!r||!n||!i)return null;let eu=ea.data.filter(e=>!d||e.request_id.includes(d)||e.model.includes(d)||e.user&&e.user.includes(d)).map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{e&&ee(e)}}))||[],eh=(null===(t=em.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{}})))||[],ex=()=>{if(I)return"".concat(tm()(w).format("MMM D, h:mm A")," - ").concat(tm()(S).format("MMM D, h:mm A"));let e=tm()(),s=tm()(w),l=e.diff(s,"minutes");if(l<=15)return"Last 15 Minutes";if(l<=60)return"Last Hour";let t=e.diff(s,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(s.format("MMM D")," - ").concat(e.format("MMM D"))},ep=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>o&&0!==o.length?o.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Status",label:"Status",isSearchable:!1,options:[{label:"Success",value:"success"},{label:"Failure",value:"failure"}]},{name:"Model",label:"Model",isSearchable:!0,searchFn:async e=>ei&&0!==ei.length?ei.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>a?(await e$(a)).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Hash",label:"Key Hash",isSearchable:!1}];return Q&&em.data?(0,m.jsx)("div",{className:"w-full p-6",children:(0,m.jsx)(tb,{sessionId:Q,logs:em.data.data,onBack:()=>ee(null)})}):(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:Q?(0,m.jsxs)(m.Fragment,{children:["Session: ",(0,m.jsx)("span",{className:"font-mono",children:Q}),(0,m.jsx)("button",{className:"ml-4 px-3 py-1 text-sm border rounded hover:bg-gray-50",onClick:()=>ee(null),children:"← Back to All Logs"})]}):"Request Logs"})}),V&&B&&V.api_key===B?(0,m.jsx)(eJ,{keyId:B,keyData:V,accessToken:a,userID:i,userRole:n,teams:o,onClose:()=>H(null)}):Q?(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsx)(tu,{columns:tg,data:eh,renderSubComponent:tS,getRowCanExpand:()=>!0})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eW,{options:ep,onApplyFilters:eo,onResetFilters:ed}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:d,onChange:e=>c(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsxs)("div",{className:"relative",ref:N,children:[(0,m.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),ex()]}),A&&(0,m.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,m.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(ex()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{C(tm()().format("YYYY-MM-DDTHH:mm")),k(tm()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),T(!1)},children:e.label},e.label)),(0,m.jsx)("div",{className:"border-t my-2"}),(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(I?"bg-blue-50 text-blue-600":""),onClick:()=>T(!I),children:"Custom Range"})]})})]}),(0,m.jsxs)("button",{onClick:()=>{el.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,m.jsx)("svg",{className:"w-4 h-4 ".concat(el.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,m.jsx)("span",{children:"Refresh"})]})]}),I&&(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:w,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,m.jsx)("span",{className:"text-gray-500",children:"to"}),(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{C(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",el.isLoading?"...":ea?(f-1)*v+1:0," ","-"," ",el.isLoading?"...":ea?Math.min(f*v,ea.total):0," ","of"," ",el.isLoading?"...":ea?ea.total:0," ","results"]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",el.isLoading?"...":f," of"," ",el.isLoading?"...":ea?ea.total_pages:1]}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:el.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.min(ea.total_pages||1,e+1)),disabled:el.isLoading||f===(ea.total_pages||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,m.jsx)(tu,{columns:tg,data:eu,renderSubComponent:tS,getRowCanExpand:()=>!0})]})]})]})}function tS(e){var s,l,t,a,r;let{row:n}=e,i=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},o=n.original.metadata||{},d="failure"===o.status,c=d?o.error_information:null,u=n.original.messages&&(Array.isArray(n.original.messages)?n.original.messages.length>0:Object.keys(n.original.messages).length>0),h=n.original.response&&Object.keys(i(n.original.response)).length>0,x=o.vector_store_request_metadata&&Array.isArray(o.vector_store_request_metadata)&&o.vector_store_request_metadata.length>0,p=n.original.metadata&&n.original.metadata.guardrail_information,g=p&&(null===(r=n.original.metadata)||void 0===r?void 0:r.guardrail_information.masked_entity_count)?Object.values(n.original.metadata.guardrail_information.masked_entity_count).reduce((e,s)=>e+("number"==typeof s?s:0),0):0;return(0,m.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,m.jsx)("span",{className:"font-mono text-sm",children:n.original.request_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,m.jsx)("span",{children:n.original.model})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model ID:"}),(0,m.jsx)("span",{children:n.original.model_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,m.jsx)("span",{children:n.original.call_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{children:n.original.custom_llm_provider||"-"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"API Base:"}),(0,m.jsx)(Y.Z,{title:n.original.api_base||"-",children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:n.original.api_base||"-"})})]}),(null==n?void 0:null===(s=n.original)||void 0===s?void 0:s.requester_ip_address)&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,m.jsx)("span",{children:null==n?void 0:null===(l=n.original)||void 0===l?void 0:l.requester_ip_address})]}),p&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail:"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-mono",children:n.original.metadata.guardrail_information.guardrail_name}),g>0&&(0,m.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[g," masked"]})]})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,m.jsxs)("span",{children:[n.original.total_tokens," (",n.original.prompt_tokens,"+",n.original.completion_tokens,")"]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,m.jsxs)("span",{children:["$",Number(n.original.spend||0).toFixed(6)]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,m.jsx)("span",{children:n.original.cache_hit})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(t=n.original.metadata)||void 0===t?void 0:t.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(a=n.original.metadata)||void 0===a?void 0:a.status)||"Success").toLowerCase()?"Success":"Failure"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:n.original.startTime})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:n.original.endTime})]})]})]})]}),(0,m.jsx)(tv,{show:!u&&!h}),(0,m.jsx)(tf,{row:n,hasMessages:u,hasResponse:h,hasError:d,errorInfo:c,getRawRequest:()=>{var e;return(null===(e=n.original)||void 0===e?void 0:e.proxy_server_request)?i(n.original.proxy_server_request):i(n.original.messages)},formattedResponse:()=>d&&c?{error:{message:c.error_message||"An error occurred",type:c.error_class||"error",code:c.error_code||"unknown",param:null}}:i(n.original.response)}),p&&(0,m.jsx)(tN,{data:n.original.metadata.guardrail_information}),x&&(0,m.jsx)(tZ,{data:o.vector_store_request_metadata}),d&&c&&(0,m.jsx)(t_,{errorInfo:c}),n.original.request_tags&&Object.keys(n.original.request_tags).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(n.original.request_tags).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[s,": ",String(l)]},s)})})})]}),n.original.metadata&&Object.keys(n.original.metadata).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(n.original.metadata,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(n.original.metadata,null,2)})})]})]})}var tC=l(92699),tI=l(14042);console.log=function(){};var tT=e=>{let{userID:s,userRole:l,accessToken:t,userSpend:a,userMaxBudget:r,selectedTeam:n}=e;console.log("userSpend: ".concat(a));let[i,o]=(0,u.useState)(null!==a?a:0),[d,c]=(0,u.useState)(n?n.max_budget:null);(0,u.useEffect)(()=>{if(n){if("Default Team"===n.team_alias)c(r);else{let e=!1;if(n.team_memberships)for(let l of n.team_memberships)l.user_id===s&&"max_budget"in l.litellm_budget_table&&null!==l.litellm_budget_table.max_budget&&(c(l.litellm_budget_table.max_budget),e=!0);e||c(n.max_budget)}}},[n,r]);let[h,x]=(0,u.useState)([]);(0,u.useEffect)(()=>{let e=async()=>{if(!t||!s||!l)return};(async()=>{try{if(null===s||null===l)return;if(null!==t){let e=(await (0,b.So)(t,s,l)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[l,t,s]),(0,u.useEffect)(()=>{null!==a&&o(a)},[a]);let p=[];n&&n.models&&(p=n.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=n.models:p&&0===p.length&&(p=h);let g=void 0!==i?i.toFixed(4):null;return console.log("spend in view user spend: ".concat(i)),(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,m.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==d?"$".concat(d," limit"):"No limit"})]})]})})};let tA=e=>{let{key:s,info:l}=e;return{token:s,...l}};var tE=e=>{let{topKeys:s,accessToken:l,userID:t,userRole:a,teams:r}=e,[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(void 0),[x,p]=(0,u.useState)("table"),g=async e=>{if(l)try{let s=await (0,b.t0)(l,e.api_key),t=tA(s);h(t),d(e.api_key),i(!0)}catch(e){console.error("Error fetching key info:",e)}},j=()=>{i(!1),d(null),h(void 0)};return u.useEffect(()=>{let e=e=>{"Escape"===e.key&&n&&j()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mb-4 flex justify-end items-center",children:(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>p("table"),className:"px-3 py-1 text-sm rounded-md ".concat("table"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Table View"}),(0,m.jsx)("button",{onClick:()=>p("chart"),className:"px-3 py-1 text-sm rounded-md ".concat("chart"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Chart View"})]})}),"chart"===x?(0,m.jsx)("div",{className:"relative",children:(0,m.jsx)(sT.Z,{className:"mt-4 h-40 cursor-pointer hover:opacity-90",data:s,index:"key_alias",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>e?"$".concat(e.toFixed(2)):"No Key Alias",onValueChange:e=>g(e),showTooltip:!0,customTooltip:e=>{var s,l,t;let a=null===(l=e.payload)||void 0===l?void 0:null===(s=l[0])||void 0===s?void 0:s.payload;return(0,m.jsx)("div",{className:"p-3 bg-black/90 shadow-lg rounded-lg text-white",children:(0,m.jsxs)("div",{className:"space-y-1.5",children:[(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Key: "}),(0,m.jsxs)("span",{className:"font-mono text-gray-100",children:[null==a?void 0:null===(t=a.api_key)||void 0===t?void 0:t.slice(0,10),"..."]})]}),(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Spend: "}),(0,m.jsxs)("span",{className:"text-white font-medium",children:["$",null==a?void 0:a.spend.toFixed(2)]})]})]})})}})}):(0,m.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,m.jsx)(tu,{columns:[{header:"Key ID",accessorKey:"api_key",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>g(e.row.original),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>e.getValue()||"-"},{header:"Spend (USD)",accessorKey:"spend",cell:e=>"$".concat(Number(e.getValue()).toFixed(2))}],data:s,renderSubComponent:()=>(0,m.jsx)(m.Fragment,{}),getRowCanExpand:()=>!1,isLoading:!1})}),n&&o&&c&&(console.log("Rendering modal with:",{isModalOpen:n,selectedKey:o,keyData:c}),(0,m.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&j()},children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-xl relative w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto min-h-[750px]",children:[(0,m.jsx)("button",{onClick:j,className:"absolute top-4 right-4 text-gray-500 hover:text-gray-700 focus:outline-none","aria-label":"Close",children:(0,m.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),(0,m.jsx)("div",{className:"p-6 h-full",children:(0,m.jsx)(eJ,{keyId:o,onClose:j,keyData:c,accessToken:l,userID:t,userRole:a,teams:r})})]})}))]})},tP=l(44851);let tO=e=>{var s,l;let{modelName:t,metrics:a}=e;return(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:a.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:a.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:a.total_tokens.toLocaleString()}),(0,m.jsxs)(P.Z,{children:[Math.round(a.total_tokens/a.total_successful_requests)," avg per successful request"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",a.total_spend.toFixed(2)]}),(0,m.jsxs)(P.Z,{children:["$",(a.total_spend/a.total_successful_requests).toFixed(3)," per successful request"]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Requests per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.api_requests"],colors:["blue"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.spend"],colors:["green"],valueFormatter:e=>"$".concat(e.toFixed(2))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Success vs Failed Requests"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Prompt Caching Metrics"}),(0,m.jsxs)("div",{className:"mb-2",children:[(0,m.jsxs)(P.Z,{children:["Cache Read: ",(null===(s=a.total_cache_read_input_tokens)||void 0===s?void 0:s.toLocaleString())||0," tokens"]}),(0,m.jsxs)(P.Z,{children:["Cache Creation: ",(null===(l=a.total_cache_creation_input_tokens)||void 0===l?void 0:l.toLocaleString())||0," tokens"]})]}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"],valueFormatter:e=>e.toLocaleString()})]})]})]})},tL=e=>{let{modelMetrics:s}=e,l=Object.keys(s).sort((e,l)=>""===e?1:""===l?-1:s[l].total_spend-s[e].total_spend),t={total_requests:0,total_successful_requests:0,total_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:{}};Object.values(s).forEach(e=>{t.total_requests+=e.total_requests,t.total_successful_requests+=e.total_successful_requests,t.total_tokens+=e.total_tokens,t.total_spend+=e.total_spend,t.total_cache_read_input_tokens+=e.total_cache_read_input_tokens||0,t.total_cache_creation_input_tokens+=e.total_cache_creation_input_tokens||0,e.daily_data.forEach(e=>{t.daily_data[e.date]||(t.daily_data[e.date]={prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,spend:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0}),t.daily_data[e.date].prompt_tokens+=e.metrics.prompt_tokens,t.daily_data[e.date].completion_tokens+=e.metrics.completion_tokens,t.daily_data[e.date].total_tokens+=e.metrics.total_tokens,t.daily_data[e.date].api_requests+=e.metrics.api_requests,t.daily_data[e.date].spend+=e.metrics.spend,t.daily_data[e.date].successful_requests+=e.metrics.successful_requests,t.daily_data[e.date].failed_requests+=e.metrics.failed_requests,t.daily_data[e.date].cache_read_input_tokens+=e.metrics.cache_read_input_tokens||0,t.daily_data[e.date].cache_creation_input_tokens+=e.metrics.cache_creation_input_tokens||0})});let a=Object.entries(t.daily_data).map(e=>{let[s,l]=e;return{date:s,metrics:l}}).sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime());return(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,m.jsx)(O.Z,{children:"Overall Usage"}),(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4 mb-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:t.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:t.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:t.total_tokens.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",t.total_spend.toFixed(2)]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]})]})]}),(0,m.jsx)(tP.Z,{defaultActiveKey:l[0],children:l.map(e=>(0,m.jsx)(tP.Z.Panel,{header:(0,m.jsxs)("div",{className:"flex justify-between items-center w-full",children:[(0,m.jsx)(O.Z,{children:s[e].label||"Unknown Item"}),(0,m.jsxs)("div",{className:"flex space-x-4 text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["$",s[e].total_spend.toFixed(2)]}),(0,m.jsxs)("span",{children:[s[e].total_requests.toLocaleString()," requests"]})]})]}),children:(0,m.jsx)(tO,{modelName:e||"Unknown Model",metrics:s[e]})},e))})]})},tD=(e,s)=>{let l=e.metadata.key_alias||"key-hash-".concat(s),t=e.metadata.team_id;return t?"".concat(l," (team_id: ").concat(t,")"):l},tM=(e,s)=>{let l={};return e.results.forEach(e=>{Object.entries(e.breakdown[s]||{}).forEach(t=>{let[a,r]=t;l[a]||(l[a]={label:"api_keys"===s?tD(r,a):a,total_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0,prompt_tokens:0,completion_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:[]}),l[a].total_requests+=r.metrics.api_requests,l[a].prompt_tokens+=r.metrics.prompt_tokens,l[a].completion_tokens+=r.metrics.completion_tokens,l[a].total_tokens+=r.metrics.total_tokens,l[a].total_spend+=r.metrics.spend,l[a].total_successful_requests+=r.metrics.successful_requests,l[a].total_failed_requests+=r.metrics.failed_requests,l[a].total_cache_read_input_tokens+=r.metrics.cache_read_input_tokens||0,l[a].total_cache_creation_input_tokens+=r.metrics.cache_creation_input_tokens||0,l[a].daily_data.push({date:e.date,metrics:{prompt_tokens:r.metrics.prompt_tokens,completion_tokens:r.metrics.completion_tokens,total_tokens:r.metrics.total_tokens,api_requests:r.metrics.api_requests,spend:r.metrics.spend,successful_requests:r.metrics.successful_requests,failed_requests:r.metrics.failed_requests,cache_read_input_tokens:r.metrics.cache_read_input_tokens||0,cache_creation_input_tokens:r.metrics.cache_creation_input_tokens||0}})})}),Object.values(l).forEach(e=>{e.daily_data.sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime())}),l};var tF=e=>{let{accessToken:s,entityType:l,entityId:t,userID:a,userRole:r,entityList:n}=e,[i,o]=(0,u.useState)({results:[],metadata:{total_spend:0,total_api_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0}}),d=tM(i,"models"),c=tM(i,"api_keys"),[h,x]=(0,u.useState)([]),[p,g]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),j=async()=>{if(!s||!p.from||!p.to)return;let e=p.from,t=p.to;if("tag"===l)o(await (0,b.Z9)(s,e,t,1,h.length>0?h:null));else if("team"===l)o(await (0,b.ol)(s,e,t,1,h.length>0?h:null));else throw Error("Invalid entity type")};(0,u.useEffect)(()=>{j()},[s,p,t,h]);let f=()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={provider:l,spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend,e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens}catch(e){console.log("Error processing provider ".concat(l,": ").concat(e))}})}),Object.values(e).filter(e=>e.spend>0).sort((e,s)=>s.spend-e.spend)},_=e=>0===h.length?e:e.filter(e=>h.includes(e.metadata.id)),v=()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.entities||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{alias:t.metadata.team_alias||l,id:l}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.total_tokens+=t.metrics.total_tokens})}),_(Object.values(e).sort((e,s)=>s.metrics.spend-e.metrics.spend))};return(0,m.jsxs)("div",{style:{width:"100%"},children:[(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:p,onValueChange:g})]}),n&&n.length>0&&(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(P.Z,{children:["Filter by ","tag"===l?"Tags":"Teams"]}),(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select ".concat("tag"===l?"tags":"teams"," to filter..."),value:h,onChange:x,options:(()=>{if(n)return n})(),className:"mt-2",allowClear:!0})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["tag"===l?"Tag":"Team"," Spend Overview"]}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Spend"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",i.metadata.total_spend.toFixed(2)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:i.metadata.total_api_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:i.metadata.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:i.metadata.total_failed_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:i.metadata.total_tokens.toLocaleString()})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...i.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let a=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:a.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Total Spend: $",a.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",a.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",a.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",a.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Tokens: ",a.metrics.total_tokens]}),(0,m.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,m.jsxs)("p",{className:"font-semibold",children:["Spend by ","tag"===l?"Tag":"Team",":"]}),Object.entries(a.breakdown.entities||{}).map(e=>{let[s,l]=e;return(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[l.metadata.team_alias||s,": $",l.metrics.spend.toFixed(2)]},s)})]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,m.jsxs)(O.Z,{children:["Spend Per ","tag"===l?"Tag":"Team"]}),(0,m.jsxs)("div",{className:"flex items-center text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["Get Started Tracking cost per ",l," "]}),(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tags",className:"text-blue-500 hover:text-blue-700 ml-1",children:"here"})]})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sT.Z,{className:"mt-4 h-52",data:v(),index:"metadata.alias",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(4)),layout:"vertical",showLegend:!1,yAxisWidth:100})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"tag"===l?"Tag":"Team"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:v().filter(e=>e.metrics.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.metadata.alias}),(0,m.jsxs)(e6.Z,{children:["$",e.metrics.spend.toFixed(4)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.metrics.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.metrics.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.metrics.total_tokens.toLocaleString()})]},e.metadata.id))})]})})]})]})})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:s,userID:a,userRole:r,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return i.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend}catch(e){console.log("Error adding spend for ".concat(l,": ").concat(e,", got metrics: ").concat(JSON.stringify(t)))}e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,...l}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)(O.Z,{children:"Provider Usage"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:f(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan","blue","indigo","violet","purple"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:f().map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:d})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:c})})]})]})]})},tR=e=>{var s,l,t,a,r,n,i,o,d,c;let{accessToken:h,userRole:x,userID:p,teams:g}=e,[j,f]=(0,u.useState)({results:[],metadata:{}}),[_,v]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),[y,Z]=(0,u.useState)([]),N=async()=>{h&&Z(Object.values(await (0,b.UM)(h)).map(e=>({label:e.name,value:e.name})))};(0,u.useEffect)(()=>{N()},[h]);let w=(null===(s=j.metadata)||void 0===s?void 0:s.total_spend)||0,C=()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{provider:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}})},I=async()=>{if(!h||!_.from||!_.to)return;let e=_.from,s=_.to;try{let l=await (0,b.xX)(h,e,s);if(l.metadata.total_pages>10)throw Error("Too many pages of data (>10). Please select a smaller date range.");if(1===l.metadata.total_pages){f(l);return}let t=[...l.results];for(let a=2;a<=l.metadata.total_pages;a++){let l=await (0,b.xX)(h,e,s,a);t.push(...l.results)}f({results:t,metadata:l.metadata})}catch(e){throw console.error("Error fetching user spend data:",e),e}};(0,u.useEffect)(()=>{I()},[h,_]);let T=tM(j,"models"),A=tM(j,"api_keys");return(0,m.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,m.jsxs)(P.Z,{className:"text-sm text-gray-500 mb-4",children:["This is the new usage dashboard. ",(0,m.jsx)("br",{})," You may see empty data, as these use ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/blob/6de348125208dd4be81ff0e5813753df2fbe9735/schema.prisma#L320",className:"text-blue-500 hover:text-blue-700 ml-1",children:"new aggregate tables"})," to allow UI to work at 1M+ spend logs. To access the old dashboard, go to Experimental ",">"," Old Usage."]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Global Usage"}):(0,m.jsx)(eM.Z,{children:"Your Usage"}),(0,m.jsx)(eM.Z,{children:"Team Usage"}),eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Tag Usage"}):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:_,onValueChange:e=>{v(e)}})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:p,userRole:x,accessToken:h,userSpend:w,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Usage Metrics"}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(t=j.metadata)||void 0===t?void 0:null===(l=t.total_api_requests)||void 0===l?void 0:l.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:(null===(r=j.metadata)||void 0===r?void 0:null===(a=r.total_successful_requests)||void 0===a?void 0:a.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:(null===(i=j.metadata)||void 0===i?void 0:null===(n=i.total_failed_requests)||void 0===n?void 0:n.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(d=j.metadata)||void 0===d?void 0:null===(o=d.total_tokens)||void 0===o?void 0:o.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Average Cost per Request"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",((w||0)/((null===(c=j.metadata)||void 0===c?void 0:c.total_api_requests)||1)).toFixed(4)]})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...j.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Requests: ",t.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",t.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",t.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.metrics.total_tokens]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:h,userID:p,userRole:x,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Top Models"})}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.key}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",t.requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-green-600",children:["Successful: ",t.successful_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-red-600",children:["Failed: ",t.failed_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.tokens.toLocaleString()]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Spend by Provider"})}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:C(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:C().filter(e=>e.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend<1e-5?"less than 0.00001":e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:T})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:A})})]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"team",userID:p,userRole:x,entityList:(null==g?void 0:g.map(e=>({label:e.team_alias,value:e.team_id})))||null})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"tag",userID:p,userRole:x,entityList:y})})]})]})]})},tq=e=>{let{proxySettings:s}=e,l="";return s&&s.PROXY_BASE_URL&&void 0!==s.PROXY_BASE_URL&&(l=s.PROXY_BASE_URL),(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(S.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,m.jsxs)("div",{className:"mb-5",children:[(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,m.jsx)(P.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"OpenAI Python SDK"}),(0,m.jsx)(eM.Z,{children:"LlamaIndex"}),(0,m.jsx)(eM.Z,{children:"Langchain Py"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(l,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(l,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(l,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(l,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},tU=l(243),tz=l(93837);async function tV(e,s,l,t,a,r,n,i,o,d,c,m){console.log=function(){},console.log("isLocal:",!1);let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t;let a=Date.now(),u=!1;for await(let h of(await x.chat.completions.create({model:l,stream:!0,stream_options:{include_usage:!0},litellm_trace_id:d,messages:e,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r}))){var p,g,j,f,_,v,y,b;console.log("Stream chunk:",h);let e=null===(p=h.choices[0])||void 0===p?void 0:p.delta;if(console.log("Delta content:",null===(j=h.choices[0])||void 0===j?void 0:null===(g=j.delta)||void 0===g?void 0:g.content),console.log("Delta reasoning content:",null==e?void 0:e.reasoning_content),!u&&((null===(_=h.choices[0])||void 0===_?void 0:null===(f=_.delta)||void 0===f?void 0:f.content)||e&&e.reasoning_content)&&(u=!0,t=Date.now()-a,console.log("First token received! Time:",t,"ms"),i?(console.log("Calling onTimingData with:",t),i(t)):console.log("onTimingData callback is not defined!")),null===(y=h.choices[0])||void 0===y?void 0:null===(v=y.delta)||void 0===v?void 0:v.content){let e=h.choices[0].delta.content;s(e,h.model)}if(e&&e.reasoning_content){let s=e.reasoning_content;n&&n(s)}if(h.usage&&o){console.log("Usage data found:",h.usage);let e={completionTokens:h.usage.completion_tokens,promptTokens:h.usage.prompt_tokens,totalTokens:h.usage.total_tokens};(null===(b=h.usage.completion_tokens_details)||void 0===b?void 0:b.reasoning_tokens)&&(e.reasoningTokens=h.usage.completion_tokens_details.reasoning_tokens),o(e)}}}catch(e){throw(null==r?void 0:r.aborted)&&console.log("Chat completion request was cancelled"),e}}async function tK(e,s,l,t,a,r){console.log=function(){},console.log("isLocal:",!1);let n=window.location.origin,i=new l6.ZP.OpenAI({apiKey:t,baseURL:n,dangerouslyAllowBrowser:!0,defaultHeaders:a&&a.length>0?{"x-litellm-tags":a.join(",")}:void 0});try{let t=await i.images.generate({model:l,prompt:e},{signal:r});if(console.log(t.data),t.data&&t.data[0]){if(t.data[0].url)s(t.data[0].url,l);else if(t.data[0].b64_json){let e=t.data[0].b64_json;s("data:image/png;base64,".concat(e),l)}else throw Error("No image data found in response")}else throw Error("Invalid response format")}catch(e){throw(null==r?void 0:r.aborted)?console.log("Image generation request was cancelled"):F.ZP.error("Error occurred while generating image. Please try again. Error: ".concat(e),20),e}}async function tB(e,s,l,t){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,n=arguments.length>6?arguments[6]:void 0,i=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,d=arguments.length>9?arguments[9]:void 0,c=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0;if(!t)throw Error("API key is required");console.log=function(){};let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t=Date.now(),a=!1,u=e.map(e=>({role:e.role,content:e.content,type:"message"}));for await(let e of(await x.responses.create({model:l,input:u,stream:!0,litellm_trace_id:d,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r})))if(console.log("Response event:",e),"object"==typeof e&&null!==e){if("response.role.delta"===e.type)continue;if("response.output_text.delta"===e.type&&"string"==typeof e.delta){let r=e.delta;if(console.log("Text delta",r),r.trim().length>0&&(s("assistant",r,l),!a)){a=!0;let e=Date.now()-t;console.log("First token received! Time:",e,"ms"),i&&i(e)}}if("response.reasoning.delta"===e.type&&"delta"in e){let s=e.delta;"string"==typeof s&&n&&n(s)}if("response.completed"===e.type&&"response"in e){let s=e.response.usage;if(console.log("Usage data:",s),s&&o){var p;console.log("Usage data:",s);let e={completionTokens:s.output_tokens,promptTokens:s.input_tokens,totalTokens:s.total_tokens};(null===(p=s.completion_tokens_details)||void 0===p?void 0:p.reasoning_tokens)&&(e.reasoningTokens=s.completion_tokens_details.reasoning_tokens),o(e)}}}}catch(e){throw(null==r?void 0:r.aborted)?console.log("Responses API request was cancelled"):F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20),e}}let tH=async e=>{try{let s=await (0,b.kn)(e);if(console.log("model_info:",s),(null==s?void 0:s.data.length)>0){let e=s.data.map(e=>({model_group:e.model_group,mode:null==e?void 0:e.mode}));return e.sort((e,s)=>e.model_group.localeCompare(s.model_group)),e}return[]}catch(e){throw console.error("Error fetching model info:",e),e}};(a=o||(o={})).IMAGE_GENERATION="image_generation",a.CHAT="chat",a.RESPONSES="responses",(r=d||(d={})).IMAGE="image",r.CHAT="chat",r.RESPONSES="responses";let tJ={image_generation:"image",chat:"chat",responses:"responses"},tG=e=>{if(console.log("getEndpointType:",e),Object.values(o).includes(e)){let s=tJ[e];return console.log("endpointType:",s),s}return"chat"};var tW=l(94263),tY=e=>{let{endpointType:s,onEndpointChange:l,className:t}=e,a=[{value:d.CHAT,label:"/v1/chat/completions"},{value:d.RESPONSES,label:"/v1/responses"},{value:d.IMAGE,label:"/v1/images/generations"}];return(0,m.jsxs)("div",{className:t,children:[(0,m.jsx)(P.Z,{children:"Endpoint Type:"}),(0,m.jsx)(D.default,{value:s,style:{width:"100%"},onChange:l,options:a,className:"rounded-md"})]})},t$=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a)try{let e=await (0,b.UM)(a);console.log("List tags response:",e),n(Object.values(e))}catch(e){console.error("Error fetching tags:",e)}})()},[]),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select tags",onChange:s,value:l,loading:i,className:t,options:r.map(e=>({label:e.name,value:e.name,title:e.description||e.name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})},tX=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.Ou)(a);e.data&&n(e.data)}catch(e){console.error("Error fetching vector stores:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select vector stores",onChange:s,value:l,loading:i,className:t,options:r.map(e=>({label:"".concat(e.vector_store_name||e.vector_store_id," (").concat(e.vector_store_id,")"),value:e.vector_store_id,title:e.vector_store_description||e.vector_store_id})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})},tQ=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,n]=(0,u.useState)([]),[i,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.t3)(a);console.log("Guardrails response:",e),e.guardrails&&(console.log("Guardrails data:",e.guardrails),n(e.guardrails))}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select guardrails",onChange:e=>{console.log("Selected guardrails:",e),s(e)},value:l,loading:i,className:t,options:r.map(e=>(console.log("Mapping guardrail:",e),{label:"".concat(e.guardrail_name),value:e.guardrail_name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})};let t0=(e,s)=>{let l=s.find(s=>s.model_group===e);return(null==l?void 0:l.mode)?tG(l.mode):d.CHAT};var t1=l(83322),t2=l(70464),t4=l(77565),t5=e=>{let{reasoningContent:s}=e,[l,t]=(0,u.useState)(!0);return s?(0,m.jsxs)("div",{className:"reasoning-content mt-1 mb-2",children:[(0,m.jsxs)(U.ZP,{type:"text",className:"flex items-center text-xs text-gray-500 hover:text-gray-700",onClick:()=>t(!l),icon:(0,m.jsx)(t1.Z,{}),children:[l?"Hide reasoning":"Show reasoning",l?(0,m.jsx)(t2.Z,{className:"ml-1"}):(0,m.jsx)(t4.Z,{className:"ml-1"})]}),l&&(0,m.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md text-sm text-gray-700",children:(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,n=/language-(\w+)/.exec(t||"");return!l&&n?(0,m.jsx)(to.Z,{style:tW.Z,language:n[1],PreTag:"div",className:"rounded-md my-2",...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),...r,children:a})}},children:s})})]}):null},t3=l(5540),t6=l(71282),t8=l(11741),t7=l(16601),t9=e=>{let{timeToFirstToken:s,usage:l}=e;return s||l?(0,m.jsxs)("div",{className:"response-metrics mt-2 pt-2 border-t border-gray-100 text-xs text-gray-500 flex flex-wrap gap-3",children:[void 0!==s&&(0,m.jsx)(Y.Z,{title:"Time to first token",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t3.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:[(s/1e3).toFixed(2),"s"]})]})}),(null==l?void 0:l.promptTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Prompt tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t6.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["In: ",l.promptTokens]})]})}),(null==l?void 0:l.completionTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Completion tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t8.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Out: ",l.completionTokens]})]})}),(null==l?void 0:l.reasoningTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Reasoning tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t1.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Reasoning: ",l.reasoningTokens]})]})}),(null==l?void 0:l.totalTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Total tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t7.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Total: ",l.totalTokens]})]})})]}):null},ae=l(61935),as=l(69993),al=l(12660),at=l(71891),aa=l(44625),ar=l(57400),an=l(26430),ai=l(23907);let{TextArea:ao}=z.default;var ad=e=>{let{accessToken:s,token:l,userRole:t,userID:a,disabledPersonalKeyCreation:r}=e,[n,i]=(0,u.useState)(r?"custom":"session"),[o,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(""),[p,g]=(0,u.useState)([]),[j,f]=(0,u.useState)(void 0),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)([]),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(d.CHAT),[S,T]=(0,u.useState)(!1),A=(0,u.useRef)(null),[E,O]=(0,u.useState)([]),[L,M]=(0,u.useState)([]),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)(null),V=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e="session"===n?s:o;if(!e||!l||!t||!a){console.log("userApiKey or token or userRole or userID is missing = ",e,l,t,a);return}(async()=>{try{if(!e){console.log("userApiKey is missing");return}let s=await tH(e);if(console.log("Fetched models:",s),s.length>0&&(Z(s),f(s[0].model_group),s[0].mode)){let e=t0(s[0].model_group,s);k(e)}}catch(e){console.error("Error fetching model info:",e)}})()},[s,a,t,n,o]),(0,u.useEffect)(()=>{V.current&&setTimeout(()=>{var e;null===(e=V.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[p]);let K=(e,s,l)=>{console.log("updateTextUI called with:",e,s,l),g(t=>{let a=t[t.length-1];if(!a||a.role!==e||a.isImage)return[...t,{role:e,content:s,model:l}];{var r;let e={...a,content:a.content+s,model:null!==(r=a.model)&&void 0!==r?r:l};return[...t.slice(0,-1),e]}})},B=e=>{g(s=>{let l=s[s.length-1];return l&&"assistant"===l.role&&!l.isImage?[...s.slice(0,s.length-1),{...l,reasoningContent:(l.reasoningContent||"")+e}]:s.length>0&&"user"===s[s.length-1].role?[...s,{role:"assistant",content:"",reasoningContent:e}]:s})},H=e=>{console.log("updateTimingData called with:",e),g(s=>{let l=s[s.length-1];if(console.log("Current last message:",l),l&&"assistant"===l.role){console.log("Updating assistant message with timeToFirstToken:",e);let t=[...s.slice(0,s.length-1),{...l,timeToFirstToken:e}];return console.log("Updated chat history:",t),t}return l&&"user"===l.role?(console.log("Creating new assistant message with timeToFirstToken:",e),[...s,{role:"assistant",content:"",timeToFirstToken:e}]):(console.log("No appropriate message found to update timing"),s)})},J=e=>{console.log("Received usage data:",e),g(s=>{let l=s[s.length-1];if(l&&"assistant"===l.role){console.log("Updating message with usage data:",e);let t={...l,usage:e};return console.log("Updated message:",t),[...s.slice(0,s.length-1),t]}return s})},G=(e,s)=>{g(l=>[...l,{role:"assistant",content:e,model:s,isImage:!0}])},$=async()=>{if(""===h.trim()||!l||!t||!a)return;let e="session"===n?s:o;if(!e){F.ZP.error("Please provide an API key or select Current UI Session");return}A.current=new AbortController;let r=A.current.signal,i={role:"user",content:h},c=U||(0,tz.Z)();U||z(c),g([...p,i]),T(!0);try{if(j){if(w===d.CHAT){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),i];await tV(s,(e,s)=>K("assistant",e,s),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}else if(w===d.IMAGE)await tK(h,(e,s)=>G(e,s),j,e,E,r);else if(w===d.RESPONSES){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),i];await tB(s,(e,s,l)=>K(e,s,l),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}}}catch(e){r.aborted?console.log("Request was cancelled"):(console.error("Error fetching response",e),K("assistant","Error fetching response:"+e))}finally{T(!1),A.current=null}x("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to test models"})]})}let X=(0,m.jsx)(ae.Z,{style:{fontSize:24},spin:!0});return(0,m.jsx)("div",{className:"w-full h-screen p-4 bg-white",children:(0,m.jsx)(eD.Z,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,m.jsxs)("div",{className:"flex h-[80vh] w-full",children:[(0,m.jsx)("div",{className:"w-1/4 p-4 border-r border-gray-200 bg-gray-50",children:(0,m.jsx)("div",{className:"mb-6",children:(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(lR.Z,{className:"mr-2"})," API Key Source"]}),(0,m.jsx)(D.default,{disabled:r,defaultValue:"session",style:{width:"100%"},onChange:e=>i(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}],className:"rounded-md"}),"custom"===n&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:c,value:o,icon:lR.Z})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(as.Z,{className:"mr-2"})," Select Model"]}),(0,m.jsx)(D.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),"custom"!==e&&k(t0(e,b)),y("custom"===e)},options:[...Array.from(new Set(b.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%"},showSearch:!0,className:"rounded-md"}),v&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{f(e)},500)}})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(al.Z,{className:"mr-2"})," Endpoint Type"]}),(0,m.jsx)(tY,{endpointType:w,onEndpointChange:e=>{k(e)},className:"mb-4"})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(at.Z,{className:"mr-2"})," Tags"]}),(0,m.jsx)(t$,{value:E,onChange:O,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(aa.Z,{className:"mr-2"})," Vector Store",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select vector store(s) to use for this LLM API call. You can set up your vector store ",(0,m.jsx)("a",{href:"?page=vector-stores",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tX,{value:L,onChange:M,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(ar.Z,{className:"mr-2"})," Guardrails",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select guardrail(s) to use for this LLM API call. You can set up your guardrails ",(0,m.jsx)("a",{href:"?page=guardrails",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tQ,{value:R,onChange:q,className:"mb-4",accessToken:s||""})]}),(0,m.jsx)(C.Z,{onClick:()=>{g([]),z(null),F.ZP.success("Chat history cleared.")},className:"w-full bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300 mt-4",icon:an.Z,children:"Clear Chat"})]})})}),(0,m.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,m.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===p.length&&(0,m.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,m.jsx)(as.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,m.jsx)(P.Z,{children:"Start a conversation or generate an image"})]}),p.map((e,s)=>(0,m.jsx)("div",{className:"mb-4 ".concat("user"===e.role?"text-right":"text-left"),children:(0,m.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"user"===e.role?"#f0f8ff":"#ffffff",border:"user"===e.role?"1px solid #e6f0fa":"1px solid #f0f0f0",textAlign:"left"},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"user"===e.role?"#e6f0fa":"#f5f5f5"},children:"user"===e.role?(0,m.jsx)(_.Z,{style:{fontSize:"12px",color:"#2563eb"}}):(0,m.jsx)(as.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,m.jsx)("strong",{className:"text-sm capitalize",children:e.role}),"assistant"===e.role&&e.model&&(0,m.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-normal",children:e.model})]}),e.reasoningContent&&(0,m.jsx)(t5,{reasoningContent:e.reasoningContent}),(0,m.jsxs)("div",{className:"whitespace-pre-wrap break-words max-w-full message-content",style:{wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",hyphens:"auto"},children:[e.isImage?(0,m.jsx)("img",{src:e.content,alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}}):(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,n=/language-(\w+)/.exec(t||"");return!l&&n?(0,m.jsx)(to.Z,{style:tW.Z,language:n[1],PreTag:"div",className:"rounded-md my-2",wrapLines:!0,wrapLongLines:!0,...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),style:{wordBreak:"break-word"},...r,children:a})},pre:e=>{let{node:s,...l}=e;return(0,m.jsx)("pre",{style:{overflowX:"auto",maxWidth:"100%"},...l})}},children:e.content}),"assistant"===e.role&&(e.timeToFirstToken||e.usage)&&(0,m.jsx)(t9,{timeToFirstToken:e.timeToFirstToken,usage:e.usage})]})]})},s)),S&&(0,m.jsx)("div",{className:"flex justify-center items-center my-4",children:(0,m.jsx)(lb.Z,{indicator:X})}),(0,m.jsx)("div",{ref:V,style:{height:"1px"}})]}),(0,m.jsx)("div",{className:"p-4 border-t border-gray-200 bg-white",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ao,{value:h,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),$())},placeholder:w===d.CHAT||w===d.RESPONSES?"Type your message... (Shift+Enter for new line)":"Describe the image you want to generate...",disabled:S,className:"flex-1",autoSize:{minRows:1,maxRows:6},style:{resize:"none",paddingRight:"10px",paddingLeft:"10px"}}),S?(0,m.jsx)(C.Z,{onClick:()=>{A.current&&(A.current.abort(),A.current=null,T(!1),F.ZP.info("Request cancelled"))},className:"ml-2 bg-red-50 hover:bg-red-100 text-red-600 border-red-200",icon:ec.Z,children:"Cancel"}):(0,m.jsx)(C.Z,{onClick:$,className:"ml-2 text-white",icon:w===d.CHAT?ai.Z:as.Z,children:w===d.CHAT?"Send":"Generate"})]})})]})]})})})},ac=l(19226),am=l(45937),au=l(28595),ah=l(68208),ax=l(9775),ap=l(41361),ag=l(37527),aj=l(88009),af=l(48231),a_=l(41169),av=l(58630),ay=l(55322);let{Sider:ab}=ac.default;var aZ=e=>{let{setPage:s,userRole:l,defaultSelectedKey:t}=e,a=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,m.jsx)(lR.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,m.jsx)(au.Z,{}),roles:eZ.LQ},{key:"2",page:"models",label:"Models",icon:(0,m.jsx)(ah.Z,{}),roles:eZ.LQ},{key:"12",page:"new_usage",label:"Usage",icon:(0,m.jsx)(ax.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"6",page:"teams",label:"Teams",icon:(0,m.jsx)(ap.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"5",page:"users",label:"Internal Users",icon:(0,m.jsx)(_.Z,{}),roles:eZ.ZL},{key:"14",page:"api_ref",label:"API Reference",icon:(0,m.jsx)(al.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,m.jsx)(aj.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,m.jsx)(af.Z,{})},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,m.jsx)(ar.Z,{}),roles:eZ.ZL},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,m.jsx)(a_.Z,{}),children:[{key:"9",page:"caching",label:"Caching",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"10",page:"budgets",label:"Budgets",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"20",page:"transform-request",label:"API Playground",icon:(0,m.jsx)(al.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"18",page:"mcp-tools",label:"MCP Tools",icon:(0,m.jsx)(av.Z,{}),roles:eZ.ZL},{key:"19",page:"tag-management",label:"Tag Management",icon:(0,m.jsx)(at.Z,{}),roles:eZ.ZL},{key:"21",page:"vector-stores",label:"Vector Stores",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"4",page:"usage",label:"Old Usage",icon:(0,m.jsx)(ax.Z,{})}]},{key:"settings",page:"settings",label:"Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,m.jsx)(al.Z,{}),roles:eZ.ZL},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL}]}],r=(e=>{let s=a.find(s=>s.page===e);if(s)return s.key;for(let s of a)if(s.children){let l=s.children.find(s=>s.page===e);if(l)return l.key}return"1"})(t),n=a.filter(e=>!!(!e.roles||e.roles.includes(l))&&(e.children&&(e.children=e.children.filter(e=>!e.roles||e.roles.includes(l))),!0));return(0,m.jsx)(ac.default,{style:{minHeight:"100vh"},children:(0,m.jsx)(ab,{theme:"light",width:220,children:(0,m.jsx)(am.Z,{mode:"inline",selectedKeys:[r],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:n.map(e=>{var l;return{key:e.key,icon:e.icon,label:e.label,children:null===(l=e.children)||void 0===l?void 0:l.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}})),onClick:e.children?void 0:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}}})})})})},aN=l(96889);console.log("process.env.NODE_ENV","production"),console.log=function(){};let aw=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var ak=e=>{let{accessToken:s,token:l,userRole:t,userID:a,keys:r,premiumUser:n}=e,i=new Date,[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)([]),[Z,N]=(0,u.useState)([]),[w,I]=(0,u.useState)([]),[T,A]=(0,u.useState)([]),[E,L]=(0,u.useState)([]),[D,M]=(0,u.useState)({}),[F,R]=(0,u.useState)([]),[q,U]=(0,u.useState)(""),[z,V]=(0,u.useState)(["all-tags"]),[K,B]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(0),Y=new Date(i.getFullYear(),i.getMonth(),1),$=new Date(i.getFullYear(),i.getMonth()+1,0),X=er(Y),Q=er($);function ee(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",r),console.log("premium user in usage",n);let es=async()=>{if(s)try{let e=await (0,b.g)(s);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,u.useEffect)(()=>{ea(K.from,K.to)},[K,z]);let et=async(e,l,t)=>{if(!e||!l||!s)return;l.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,b.b1)(s,t,e.toISOString(),l.toISOString());console.log("End user data updated successfully",a),j(a)},ea=async(e,l)=>{if(!e||!l||!s)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(l.setHours(23,59,59,999),e.setHours(0,0,0,0),y((await (0,b.J$)(s,e.toISOString(),l.toISOString(),0===z.length?void 0:z)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let s=e.getFullYear(),l=e.getMonth()+1,t=e.getDate();return"".concat(s,"-").concat(l<10?"0"+l:l,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(X)),console.log("End date is ".concat(Q));let en=async(e,s,l)=>{try{let l=await e();s(l)}catch(e){console.error(l,e)}},ei=(e,s,l,t)=>{let a=[],r=new Date(s),n=e=>{if(e.includes("-"))return e;{let[s,l]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(s," 01 2024")).getMonth(),parseInt(l)).toISOString().split("T")[0]}},i=new Map(e.map(e=>{let s=n(e.date);return[s,{...e,date:s}]}));for(;r<=l;){let e=r.toISOString().split("T")[0];if(i.has(e))a.push(i.get(e));else{let s={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{s[e]||(s[e]=0)}),a.push(s)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(s)try{let e=await (0,b.FC)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=ei(e,t,a,[]),n=Number(r.reduce((e,s)=>e+(s.spend||0),0).toFixed(2));W(n),d(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>en(()=>s&&l?(0,b.OU)(s,l,X,Q):Promise.reject("No access token or token"),L,"Error fetching provider spend"),ec=async()=>{s&&await en(async()=>(await (0,b.tN)(s)).map(e=>({key:e.api_key.substring(0,10),api_key:e.api_key,key_alias:e.key_alias,spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{s&&await en(async()=>(await (0,b.Au)(s)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{s&&await en(async()=>{let e=await (0,b.mR)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0);return _(ei(e.daily_spend,t,a,e.teams)),I(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},A,"Error fetching team spend")},eh=()=>{s&&en(async()=>(await (0,b.X)(s)).tag_names,N,"Error fetching tag names")},ex=()=>{s&&en(()=>{var e,l;return(0,b.J$)(s,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(l=K.to)||void 0===l?void 0:l.toISOString(),void 0)},e=>y(e.spend_per_tag),"Error fetching top tags")},ep=()=>{s&&en(()=>(0,b.b1)(s,null,void 0,void 0),j,"Error fetching top end users")},eg=async()=>{if(s)try{let e=await (0,b.wd)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=ei(e.daily_data||[],t,a,["api_requests","total_tokens"]);M({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(s)try{let e=await (0,b.xA)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=e.map(e=>({...e,daily_data:ei(e.daily_data||[],t,a,["api_requests","total_tokens"])}));R(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,u.useEffect)(()=>{(async()=>{if(s&&l&&t&&a){let e=await es();e&&(J(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),aw(t)&&(eu(),eh(),ex(),ep()))}})()},[s,l,t,a,X,Q]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Database Query Limit Reached"}),(0,m.jsxs)(P.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,m.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,m.jsx)(C.Z,{className:"mt-4",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mt-2",children:[(0,m.jsx)(eM.Z,{children:"All Up"}),aw(t)?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eM.Z,{children:"Team Based Usage"}),(0,m.jsx)(eM.Z,{children:"Customer Usage"}),(0,m.jsx)(eM.Z,{children:"Tag Based Usage"})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsx)("div",{})})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:a,userRole:t,accessToken:s,userSpend:G,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Monthly Spend"}),(0,m.jsx)(sT.Z,{data:o,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:c,accessToken:s,userID:a,userRole:t,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,m.jsx)(k.Z,{numColSpan:1}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Spend by Provider"}),(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",variant:"pie",data:E,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"})]})}),(0,m.jsx)(e3.Z,{children:E.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsx)(e6.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"All Up"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(D.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(D.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,m.jsx)(m.Fragment,{children:F.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.model}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(e.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:ee,onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(si.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(e.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:ee,onValueChange:e=>console.log(e)})]})]})]},s))})]})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Total Spend Per Team"}),(0,m.jsx)(aN.Z,{data:T})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend Per Team"}),(0,m.jsx)(sT.Z,{className:"h-72",data:f,showLegend:!0,index:"date",categories:w,yAxisWidth:80,stack:!0})]})]}),(0,m.jsx)(k.Z,{numColSpan:2})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Key"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==r?void 0:r.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},s):null)]})]})]}),(0,m.jsx)(eD.Z,{className:"mt-4",children:(0,m.jsxs)(e5.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Customer"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Total Events"})]})}),(0,m.jsx)(e3.Z,{children:null==g?void 0:g.map((e,s)=>{var l;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.end_user}),(0,m.jsx)(e6.Z,{children:null===(l=e.total_spend)||void 0===l?void 0:l.toFixed(4)}),(0,m.jsx)(e6.Z,{children:e.total_count})]},s)})})]})})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sS.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,m.jsx)(k.Z,{children:n?(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsx)(l4.Z,{value:String(e),children:e},e))]})}):(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsxs)(el.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend Per Tag"}),(0,m.jsxs)(P.Z,{children:["Get Started Tracking cost per tag ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,m.jsx)(sT.Z,{className:"h-72",data:v,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,m.jsx)(k.Z,{numColSpan:2})]})]})]})]})})},aS=l(51853);let aC=e=>{let{responseTimeMs:s}=e;return null==s?null:(0,m.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,m.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,m.jsxs)("span",{children:[s.toFixed(0),"ms"]})]})},aI=e=>{let s=e;if("string"==typeof s)try{s=JSON.parse(s)}catch(e){}return s},aT=e=>{let{label:s,value:l}=e,[t,a]=u.useState(!1),[r,n]=u.useState(!1),i=(null==l?void 0:l.toString())||"N/A",o=i.length>50?i.substring(0,50)+"...":i;return(0,m.jsx)("tr",{className:"hover:bg-gray-50",children:(0,m.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,m.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{className:"text-sm text-gray-600",children:s}),(0,m.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?i:o})]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(i),n(!0),setTimeout(()=>n(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,m.jsx)(aS.Z,{className:"h-4 w-4"})})]})})})},aA=e=>{var s,l,t,a,r,n,i,o,d,c,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=aI(j.litellm_params)||{},_=aI(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=aI(null==g?void 0:g.litellm_cache_params)||{},_=aI(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(r=n.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(i=_.connection_kwargs)||void 0===i?void 0:i.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(c=_.redis_client)||void 0===c?void 0:null===(d=c.connection_pool)||void 0===d?void 0:null===(o=d.connection_kwargs)||void 0===o?void 0:o.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,s,l,t,a,r,n,i,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(n=_.redis_async_client)||void 0===n?void 0:null===(r=n.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(i=o.connection_kwargs)||void 0===i?void 0:i.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"border-b border-gray-200 px-4",children:[(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsxs)(P.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,m.jsx)("table",{className:"w-full border-collapse",children:(0,m.jsxs)("tbody",{children:[j&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,m.jsx)(aT,{label:"Error Message",value:j.message}),(0,m.jsx)(aT,{label:"Traceback",value:j.traceback})]}),(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,m.jsx)(aT,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,m.jsx)(aT,{label:"Ping Response",value:String(g.ping_response)}),(0,m.jsx)(aT,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,m.jsx)(aT,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,m.jsx)(aT,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,m.jsx)(aT,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,m.jsx)(aT,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,m.jsx)(aT,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,m.jsx)(aT,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,m.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},s=JSON.parse(JSON.stringify(e,(e,s)=>{if("string"==typeof s)try{return JSON.parse(s)}catch(e){}return s}));return JSON.stringify(s,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},aE=e=>{let{accessToken:s,healthCheckResponse:l,runCachingHealthCheck:t,responseTimeMs:a}=e,[r,n]=u.useState(null),[i,o]=u.useState(!1),d=async()=>{o(!0);let e=performance.now();await t(),n(performance.now()-e),o(!1)};return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsx)(C.Z,{onClick:d,disabled:i,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:i?"Running Health Check...":"Run Health Check"}),(0,m.jsx)(aC,{responseTimeMs:r})]}),l&&(0,m.jsx)(aA,{response:l})]})},aP=e=>{if(e)return e.toISOString().split("T")[0]};function aO(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var aL=e=>{let{accessToken:s,token:l,userRole:t,userID:a,premiumUser:r}=e,[n,i]=(0,u.useState)([]),[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)("0"),[f,_]=(0,u.useState)("0"),[v,y]=(0,u.useState)("0"),[Z,N]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[w,C]=(0,u.useState)(""),[I,T]=(0,u.useState)("");(0,u.useEffect)(()=>{s&&Z&&((async()=>{p(await (0,b.zg)(s,aP(Z.from),aP(Z.to)))})(),C(new Date().toLocaleString()))},[s]);let A=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.api_key)&&void 0!==s?s:""}))),E=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.model)&&void 0!==s?s:""})));Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.call_type)&&void 0!==s?s:""})));let O=async(e,l)=>{e&&l&&s&&(l.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,b.zg)(s,aP(e),aP(l))))};(0,u.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;o.length>0&&(e=e.filter(e=>o.includes(e.api_key))),c.length>0&&(e=e.filter(e=>c.includes(e.model))),console.log("before processed data in cache dashboard",e);let s=0,l=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),s+=(a.total_rows||0)-(a.cache_hit_true_rows||0),l+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);j(aO(l)),_(aO(t));let r=l+s;r>0?y((l/r*100).toFixed(2)):y("0"),i(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[o,c,Z,x]);let L=async()=>{try{F.ZP.info("Running cache health check..."),T("");let e=await (0,b.Tj)(null!==s?s:"");console.log("CACHING HEALTH CHECK RESPONSE",e),T(e)}catch(s){let e;if(console.error("Error running health check:",s),s&&s.message)try{let l=JSON.parse(s.message);l.error&&(l=l.error),e=l}catch(l){e={message:s.message}}else e={message:"Unknown error occurred"};T({error:e})}};return(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Cache Analytics"}),(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"Cache Health"})})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[w&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",w]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{C(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(S.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select API Keys",value:o,onValueChange:d,children:A.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select Models",value:c,onValueChange:h,children:E.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(sS.Z,{enableSelect:!0,value:Z,onValueChange:e=>{N(e),O(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[v,"%"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:f})})]})]}),(0,m.jsx)(si.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,m.jsx)(sT.Z,{title:"Cache Hits vs API Requests",data:n,stack:!0,index:"name",valueFormatter:aO,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,m.jsx)(si.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,m.jsx)(sT.Z,{className:"mt-6",data:n,stack:!0,index:"name",valueFormatter:aO,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(aE,{accessToken:s,healthCheckResponse:I,runCachingHealthCheck:L})})]})]})},aD=l(22452),aM=l(91810);(n=c||(c={})).PresidioPII="Presidio PII",n.Bedrock="Bedrock Guardrail",n.Lakera="Lakera";let aF={PresidioPII:"presidio",Bedrock:"bedrock",Lakera:"lakera_v2"},aR=e=>!!e&&"Presidio PII"===c[e],aq="../ui/assets/logos/",aU={"Presidio PII":"".concat(aq,"presidio.png"),"Bedrock Guardrail":"".concat(aq,"bedrock.svg"),Lakera:"".concat(aq,"lakeraai.jpeg")},az=e=>{if(!e)return{logo:"",displayName:"-"};let s=Object.keys(aF).find(s=>aF[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=c[s];return{logo:aU[l],displayName:l}};var aV=l(33866),aK=l(3810),aB=l(97416),aH=l(8881),aJ=l(10798),aG=l(49638);let{Text:aW}=et.default,{Option:aY}=D.default,a$=e=>e.replace(/_/g," "),aX=e=>{switch(e){case"MASK":return(0,m.jsx)(aB.Z,{style:{marginRight:4}});case"BLOCK":return(0,m.jsx)(aH.Z,{style:{marginRight:4}});default:return null}},aQ=e=>{let{categories:s,selectedCategories:l,onChange:t}=e;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)(aJ.Z,{className:"text-gray-500 mr-1"}),(0,m.jsx)(aW,{className:"text-gray-500 font-medium",children:"Filter by category"})]}),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select categories to filter by",style:{width:"100%"},onChange:t,value:l,allowClear:!0,showSearch:!0,optionFilterProp:"children",className:"mb-4",tagRender:e=>(0,m.jsx)(aK.Z,{color:"blue",closable:e.closable,onClose:e.onClose,className:"mr-2 mb-2",children:e.label}),children:s.map(e=>(0,m.jsx)(aY,{value:e.category,children:e.category},e.category))})]})},a0=e=>{let{onSelectAll:s,onUnselectAll:l,hasSelectedEntities:t}=e;return(0,m.jsxs)("div",{className:"bg-gray-50 p-5 rounded-lg mb-6 border border-gray-200 shadow-sm",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(aW,{strong:!0,className:"text-gray-700 text-base",children:"Quick Actions"}),(0,m.jsx)(Y.Z,{title:"Apply action to all PII types at once",children:(0,m.jsx)("div",{className:"ml-2 text-gray-400 cursor-help text-xs",children:"ⓘ"})})]}),(0,m.jsx)(U.ZP,{type:"default",onClick:l,disabled:!t,icon:(0,m.jsx)(aG.Z,{}),className:"border-gray-300 hover:text-red-600 hover:border-red-300",children:"Unselect All"})]}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("MASK"),className:"flex items-center justify-center h-10 border-blue-200 hover:border-blue-300 hover:text-blue-700 bg-blue-50 hover:bg-blue-100 text-blue-600",block:!0,icon:(0,m.jsx)(aB.Z,{}),children:"Select All & Mask"}),(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("BLOCK"),className:"flex items-center justify-center h-10 border-red-200 hover:border-red-300 hover:text-red-700 bg-red-50 hover:bg-red-100 text-red-600",block:!0,icon:(0,m.jsx)(aH.Z,{}),children:"Select All & Block"})]})]})},a1=e=>{let{entities:s,selectedEntities:l,selectedActions:t,actions:a,onEntitySelect:r,onActionSelect:n,entityToCategoryMap:i}=e;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden shadow-sm",children:[(0,m.jsxs)("div",{className:"bg-gray-50 px-5 py-3 border-b flex",children:[(0,m.jsx)(aW,{strong:!0,className:"flex-1 text-gray-700",children:"PII Type"}),(0,m.jsx)(aW,{strong:!0,className:"w-32 text-right text-gray-700",children:"Action"})]}),(0,m.jsx)("div",{className:"max-h-[400px] overflow-y-auto",children:0===s.length?(0,m.jsx)("div",{className:"py-10 text-center text-gray-500",children:"No PII types match your filter criteria"}):s.map(e=>(0,m.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between hover:bg-gray-50 border-b ".concat(l.includes(e)?"bg-blue-50":""),children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)(sL.Z,{checked:l.includes(e),onChange:()=>r(e),className:"mr-3"}),(0,m.jsx)(aW,{className:l.includes(e)?"font-medium text-gray-900":"text-gray-700",children:a$(e)}),i.get(e)&&(0,m.jsx)(aK.Z,{className:"ml-2 text-xs",color:"blue",children:i.get(e)})]}),(0,m.jsx)("div",{className:"w-32",children:(0,m.jsx)(D.default,{value:l.includes(e)&&t[e]||"MASK",onChange:s=>n(e,s),style:{width:120},disabled:!l.includes(e),className:"".concat(l.includes(e)?"":"opacity-50"),dropdownMatchSelectWidth:!1,children:a.map(e=>(0,m.jsx)(aY,{value:e,children:(0,m.jsxs)("div",{className:"flex items-center",children:[aX(e),e]})},e))})})]},e))})]})},{Title:a2,Text:a4}=et.default;var a5=e=>{let{entities:s,actions:l,selectedEntities:t,selectedActions:a,onEntitySelect:r,onActionSelect:n,entityCategories:i=[]}=e,[o,d]=(0,u.useState)([]),c=new Map;i.forEach(e=>{e.entities.forEach(s=>{c.set(s,e.category)})});let h=s.filter(e=>0===o.length||o.includes(c.get(e)||""));return(0,m.jsxs)("div",{className:"pii-configuration",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-5",children:[(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsx)(a2,{level:4,className:"mb-0 font-semibold text-gray-800",children:"Configure PII Protection"})}),(0,m.jsx)(aV.Z,{count:t.length,showZero:!0,style:{backgroundColor:t.length>0?"#4f46e5":"#d9d9d9"},overflowCount:999,children:(0,m.jsxs)(a4,{className:"text-gray-500",children:[t.length," items selected"]})})]}),(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsx)(aQ,{categories:i,selectedCategories:o,onChange:d}),(0,m.jsx)(a0,{onSelectAll:e=>{s.forEach(s=>{t.includes(s)||r(s),n(s,e)})},onUnselectAll:()=>{t.forEach(e=>{r(e)})},hasSelectedEntities:t.length>0})]}),(0,m.jsx)(a1,{entities:h,selectedEntities:t,selectedActions:a,actions:l,onEntitySelect:r,onActionSelect:n,entityToCategoryMap:c})]})},a3=e=>{var s;let{selectedProvider:l,accessToken:t,providerParams:a=null}=e,[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(a),[d,c]=(0,u.useState)(null);if((0,u.useEffect)(()=>{if(a){o(a);return}let e=async()=>{if(t){n(!0),c(null);try{let e=await (0,b.eW)(t);console.log("Provider params API response:",e),o(e)}catch(e){console.error("Error fetching provider params:",e),c("Failed to load provider parameters")}finally{n(!1)}}};a||e()},[t,a]),!l)return null;if(r)return(0,m.jsx)(lb.Z,{tip:"Loading provider parameters..."});if(d)return(0,m.jsx)("div",{className:"text-red-500",children:d});let h=null===(s=aF[l])||void 0===s?void 0:s.toLowerCase(),x=i&&i[h];return(console.log("Provider key:",h),console.log("Provider fields:",x),x&&0!==x.length)?(0,m.jsx)(m.Fragment,{children:x.map(e=>(0,m.jsx)(M.Z.Item,{name:e.param,label:e.param,tooltip:e.description,rules:e.required?[{required:!0,message:"".concat(e.param," is required")}]:void 0,children:"select"===e.type&&e.options?(0,m.jsx)(D.default,{placeholder:e.description,defaultValue:e.default_value,children:e.options.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):e.param.includes("password")||e.param.includes("secret")?(0,m.jsx)(I.Z,{placeholder:e.description,type:"password"}):(0,m.jsx)(I.Z,{placeholder:e.description,type:"text"})},e.param))}):(0,m.jsx)("div",{children:"No configuration fields available for this provider."})};let{Title:a6,Text:a8,Link:a7}=et.default,{Option:a9}=D.default,{Step:re}=aM.default;var rs=e=>{var s;let{visible:l,onClose:t,accessToken:a,onSuccess:r}=e,[n]=M.Z.useForm(),[i,o]=(0,u.useState)(!1),[d,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)({}),[v,y]=(0,u.useState)(0),[Z,N]=(0,u.useState)(null);(0,u.useEffect)(()=>{a&&(async()=>{try{let[e,s]=await Promise.all([(0,b.qd)(a),(0,b.eW)(a)]);p(e),N(s)}catch(e){console.error("Error fetching guardrail data:",e),F.ZP.error("Failed to load guardrail configuration")}})()},[a]);let w=e=>{h(e),n.setFieldsValue({config:void 0,presidio_analyzer_api_base:void 0,presidio_anonymizer_api_base:void 0}),j([]),_({})},k=e=>{j(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},S=(e,s)=>{_(l=>({...l,[e]:s}))},T=async()=>{try{if(0===v&&(await n.validateFields(["guardrail_name","provider","mode","default_on"]),d)){let e=["guardrail_name","provider","mode","default_on"];"PresidioPII"===d&&e.push("presidio_analyzer_api_base","presidio_anonymizer_api_base"),await n.validateFields(e)}y(v+1)}catch(e){console.error("Form validation failed:",e)}},A=()=>{n.resetFields(),h(null),j([]),_({}),y(0)},E=()=>{A(),t()},P=async()=>{try{o(!0),await n.validateFields();let s=n.getFieldsValue(!0),l=aF[s.provider],i={guardrail_name:s.guardrail_name,litellm_params:{guardrail:l,mode:s.mode,default_on:s.default_on},guardrail_info:{}};if("PresidioPII"===s.provider&&g.length>0){let e={};g.forEach(s=>{e[s]=f[s]||"MASK"}),i.litellm_params.pii_entities_config=e,s.presidio_analyzer_api_base&&(i.litellm_params.presidio_analyzer_api_base=s.presidio_analyzer_api_base),s.presidio_anonymizer_api_base&&(i.litellm_params.presidio_anonymizer_api_base=s.presidio_anonymizer_api_base)}else if(s.config)try{let e=JSON.parse(s.config);i.guardrail_info=e}catch(e){F.ZP.error("Invalid JSON in configuration"),o(!1);return}if(Z&&d){var e;let l=Z[null===(e=aF[d])||void 0===e?void 0:e.toLowerCase()]||[];new Set(l.map(e=>e.param)).forEach(e=>{let l=s[e];null!=l&&""!==l&&(i.litellm_params[e]=l)})}if(!a)throw Error("No access token available");console.log("Sending guardrail data:",JSON.stringify(i)),await (0,b.PC)(a,i),F.ZP.success("Guardrail created successfully"),A(),r(),t()}catch(e){console.error("Failed to create guardrail:",e),F.ZP.error("Failed to create guardrail: "+(e instanceof Error?e.message:String(e)))}finally{o(!1)}},O=()=>{var e;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:w,labelInValue:!1,optionLabelProp:"label",dropdownRender:e=>e,showSearch:!0,children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(a9,{value:s,label:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[aU[l]&&(0,m.jsx)("img",{src:aU[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]}),children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[aU[l]&&(0,m.jsx)("img",{src:aU[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(a3,{selectedProvider:d,accessToken:a,providerParams:Z}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{children:(null==x?void 0:null===(e=x.supported_modes)||void 0===e?void 0:e.map(e=>(0,m.jsx)(a9,{value:e,children:e},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(a9,{value:"pre_call",children:"pre_call"}),(0,m.jsx)(a9,{value:"post_call",children:"post_call"})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,m.jsx)(sY.Z,{})})]})},L=()=>x&&"PresidioPII"===d?(0,m.jsx)(a5,{entities:x.supported_entities,actions:x.supported_actions,selectedEntities:g,selectedActions:f,onEntitySelect:k,onActionSelect:S,entityCategories:x.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Add Guardrail",open:l,onCancel:E,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:n,layout:"vertical",initialValues:{mode:(null==x?void 0:null===(s=x.supported_modes)||void 0===s?void 0:s[0])||"pre_call",default_on:!1},children:[(0,m.jsxs)(aM.default,{current:v,className:"mb-6",children:[(0,m.jsx)(re,{title:"Basic Info"}),(0,m.jsx)(re,{title:"PresidioPII"===d?"PII Configuration":"Provider Configuration"})]}),(()=>{switch(v){case 0:return O();case 1:if(aR(d))return L();default:return null}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[v>0&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{y(v-1)},children:"Previous"}),v<1&&(0,m.jsx)(C.Z,{onClick:T,children:"Next"}),1===v&&(0,m.jsx)(C.Z,{onClick:P,loading:i,children:"Create Guardrail"}),(0,m.jsx)(C.Z,{variant:"secondary",onClick:E,children:"Cancel"})]})]})})};let{Title:rl,Text:rt}=et.default,{Option:ra}=D.default;var rr=e=>{var s;let{visible:l,onClose:t,accessToken:a,onSuccess:r,guardrailId:n,initialValues:i}=e,[o]=M.Z.useForm(),[d,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)((null==i?void 0:i.provider)||null),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)({});(0,u.useEffect)(()=>{(async()=>{try{if(!a)return;let e=await (0,b.qd)(a);j(e)}catch(e){console.error("Error fetching guardrail settings:",e),F.ZP.error("Failed to load guardrail settings")}})()},[a]),(0,u.useEffect)(()=>{(null==i?void 0:i.pii_entities_config)&&Object.keys(i.pii_entities_config).length>0&&(_(Object.keys(i.pii_entities_config)),y(i.pii_entities_config))},[i]);let Z=e=>{_(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},N=(e,s)=>{y(l=>({...l,[e]:s}))},w=async()=>{try{h(!0);let e=await o.validateFields(),s=aF[e.provider],l={guardrail_id:n,guardrail:{guardrail_name:e.guardrail_name,litellm_params:{guardrail:s,mode:e.mode,default_on:e.default_on},guardrail_info:{}}};if("PresidioPII"===e.provider&&f.length>0){let e={};f.forEach(s=>{e[s]=v[s]||"MASK"}),l.guardrail.litellm_params.pii_entities_config=e}else if(e.config)try{let s=JSON.parse(e.config);"Bedrock"===e.provider&&s?(s.guardrail_id&&(l.guardrail.litellm_params.guardrailIdentifier=s.guardrail_id),s.guardrail_version&&(l.guardrail.litellm_params.guardrailVersion=s.guardrail_version)):l.guardrail.guardrail_info=s}catch(e){F.ZP.error("Invalid JSON in configuration"),h(!1);return}if(!a)throw Error("No access token available");console.log("Sending guardrail update data:",JSON.stringify(l));let i=await fetch("/guardrails/".concat(n),{method:"PUT",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify(l)});if(!i.ok){let e=await i.text();throw Error(e||"Failed to update guardrail")}F.ZP.success("Guardrail updated successfully"),r(),t()}catch(e){console.error("Failed to update guardrail:",e),F.ZP.error("Failed to update guardrail: "+(e instanceof Error?e.message:String(e)))}finally{h(!1)}},k=()=>g&&x&&"PresidioPII"===x?(0,m.jsx)(a5,{entities:g.supported_entities,actions:g.supported_actions,selectedEntities:f,selectedActions:v,onEntitySelect:Z,onActionSelect:N,entityCategories:g.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Edit Guardrail",open:l,onCancel:t,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:o,layout:"vertical",initialValues:i,children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:e=>{p(e),o.setFieldsValue({config:void 0}),_([]),y({})},disabled:!0,optionLabelProp:"label",children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(ra,{value:s,label:l,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[aU[l]&&(0,m.jsx)("img",{src:aU[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{children:(null==g?void 0:null===(s=g.supported_modes)||void 0===s?void 0:s.map(e=>(0,m.jsx)(ra,{value:e,children:e},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(ra,{value:"pre_call",children:"pre_call"}),(0,m.jsx)(ra,{value:"post_call",children:"post_call"})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,m.jsx)(sY.Z,{})}),(()=>{if(!x)return null;if("PresidioPII"===x)return k();switch(x){case"Aporia":return(0,m.jsx)(M.Z.Item,{label:"Aporia Configuration",name:"config",tooltip:"JSON configuration for Aporia",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aporia_api_key",\n "project_name": "your_project_name"\n}'})});case"AimSecurity":return(0,m.jsx)(M.Z.Item,{label:"Aim Security Configuration",name:"config",tooltip:"JSON configuration for Aim Security",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aim_api_key"\n}'})});case"Bedrock":return(0,m.jsx)(M.Z.Item,{label:"Amazon Bedrock Configuration",name:"config",tooltip:"JSON configuration for Amazon Bedrock guardrails",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "guardrail_id": "your_guardrail_id",\n "guardrail_version": "your_guardrail_version"\n}'})});case"GuardrailsAI":return(0,m.jsx)(M.Z.Item,{label:"Guardrails.ai Configuration",name:"config",tooltip:"JSON configuration for Guardrails.ai",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_guardrails_api_key",\n "guardrail_id": "your_guardrail_id"\n}'})});case"LakeraAI":return(0,m.jsx)(M.Z.Item,{label:"Lakera AI Configuration",name:"config",tooltip:"JSON configuration for Lakera AI",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_lakera_api_key"\n}'})});case"PromptInjection":return(0,m.jsx)(M.Z.Item,{label:"Prompt Injection Configuration",name:"config",tooltip:"JSON configuration for prompt injection detection",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "threshold": 0.8\n}'})});default:return(0,m.jsx)(M.Z.Item,{label:"Custom Configuration",name:"config",tooltip:"JSON configuration for your custom guardrail",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "key1": "value1",\n "key2": "value2"\n}'})})}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:t,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:w,loading:d,children:"Update Guardrail"})]})]})})},rn=e=>{var s,l,t,a,r,n,i;let{guardrailId:o,onClose:d,accessToken:c,isAdmin:h}=e,[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!0),[f,_]=(0,u.useState)(!1),[v]=M.Z.useForm(),y=async()=>{try{if(j(!0),!c)return;let e=await (0,b.fk)(c,o);p(e)}catch(e){F.ZP.error("Failed to load guardrail information"),console.error("Error fetching guardrail info:",e)}finally{j(!1)}};(0,u.useEffect)(()=>{y()},[o,c]);let Z=async e=>{try{if(!c)return;let s={guardrail_name:e.guardrail_name,litellm_params:{default_on:e.default_on},guardrail_info:e.guardrail_info?JSON.parse(e.guardrail_info):void 0};await (0,b.Ko)(c,o,s),F.ZP.success("Guardrail updated successfully"),y(),_(!1)}catch(e){console.error("Error updating guardrail:",e),F.ZP.error("Failed to update guardrail")}};if(g)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!x)return(0,m.jsx)("div",{className:"p-4",children:"Guardrail not found"});let N=e=>e?new Date(e).toLocaleString():"-",{logo:w,displayName:k}=az((null===(s=x.litellm_params)||void 0===s?void 0:s.guardrail)||"");return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:d,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:x.guardrail_name||"Unnamed Guardrail"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:x.guardrail_id})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),h?(0,m.jsx)(eM.Z,{children:"Settings"},"settings"):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[w&&(0,m.jsx)("img",{src:w,alt:"".concat(k," logo"),className:"w-6 h-6",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(O.Z,{children:k})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Mode"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:(null===(l=x.litellm_params)||void 0===l?void 0:l.mode)||"-"}),(0,m.jsx)(eL.Z,{color:(null===(t=x.litellm_params)||void 0===t?void 0:t.default_on)?"green":"gray",children:(null===(a=x.litellm_params)||void 0===a?void 0:a.default_on)?"Default On":"Default Off"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Created At"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:N(x.created_at)}),(0,m.jsxs)(P.Z,{children:["Last Updated: ",N(x.updated_at)]})]})]})]}),x.guardrail_info&&Object.keys(x.guardrail_info).length>0&&(0,m.jsxs)(eD.Z,{className:"mt-6",children:[(0,m.jsx)(P.Z,{children:"Guardrail Info"}),(0,m.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(x.guardrail_info).map(e=>{let[s,l]=e;return(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(P.Z,{className:"font-medium w-1/3",children:s}),(0,m.jsx)(P.Z,{className:"w-2/3",children:"object"==typeof l?JSON.stringify(l,null,2):String(l)})]},s)})})]})]}),h&&(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Guardrail Settings"}),!f&&(0,m.jsx)(C.Z,{onClick:()=>_(!0),children:"Edit Settings"})]}),f?(0,m.jsxs)(M.Z,{form:v,onFinish:Z,initialValues:{guardrail_name:x.guardrail_name,...x.litellm_params,guardrail_info:x.guardrail_info?JSON.stringify(x.guardrail_info,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Guardrail Name",name:"guardrail_name",rules:[{required:!0,message:"Please input a guardrail name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Default On",name:"default_on",children:(0,m.jsxs)(D.default,{children:[(0,m.jsx)(D.default.Option,{value:!0,children:"Yes"}),(0,m.jsx)(D.default.Option,{value:!1,children:"No"})]})}),(0,m.jsx)(M.Z.Item,{label:"Guardrail Information",name:"guardrail_info",children:(0,m.jsx)(z.default.TextArea,{rows:5})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>_(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail ID"}),(0,m.jsx)("div",{className:"font-mono",children:x.guardrail_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail Name"}),(0,m.jsx)("div",{children:x.guardrail_name||"Unnamed Guardrail"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Provider"}),(0,m.jsx)("div",{children:k})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Mode"}),(0,m.jsx)("div",{children:(null===(r=x.litellm_params)||void 0===r?void 0:r.mode)||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Default On"}),(0,m.jsx)(eL.Z,{color:(null===(n=x.litellm_params)||void 0===n?void 0:n.default_on)?"green":"gray",children:(null===(i=x.litellm_params)||void 0===i?void 0:i.default_on)?"Yes":"No"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:N(x.created_at)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)("div",{children:N(x.updated_at)})]})]})]})})]})]})]})},ri=e=>{let{guardrailsList:s,isLoading:l,onDeleteClick:t,accessToken:a,onGuardrailUpdated:r,isAdmin:n=!1,onShowGuardrailInfo:i}=e,[o,d]=(0,u.useState)([{id:"created_at",desc:!0}]),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(null),v=e=>e?new Date(e).toLocaleString():"-",y=e=>{_(e),j(!0),null==i||i(!0)},b=[{header:"Guardrail ID",accessorKey:"guardrail_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>e.getValue()&&y(e.getValue()),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Name",accessorKey:"guardrail_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.guardrail_name,children:(0,m.jsx)("span",{className:"text-xs font-medium",children:l.guardrail_name||"-"})})}},{header:"Provider",accessorKey:"litellm_params.guardrail",cell:e=>{let{row:s}=e,{logo:l,displayName:t}=az(s.original.litellm_params.guardrail);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:l,alt:"".concat(t," logo"),className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)("span",{className:"text-xs",children:t})]})}},{header:"Mode",accessorKey:"litellm_params.mode",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.litellm_params.mode})}},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.created_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.updated_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.updated_at)})})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l.guardrail_id&&t(l.guardrail_id,l.guardrail_name||"Unnamed Guardrail"),className:"cursor-pointer hover:text-red-500",tooltip:"Delete guardrail"})})}}],Z=(0,e2.b7)({data:s,columns:b,state:{sorting:o},onSortingChange:d,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return g&&f?(0,m.jsx)(rn,{guardrailId:f,onClose:()=>{j(!1),_(null),null==i||i(!1)},accessToken:a,isAdmin:n}):(0,m.jsxs)("div",{className:"rounded-lg custom-border relative",children:[(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:Z.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:l?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"Loading..."})})})}):s.length>0?Z.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No guardrails found"})})})})})]})}),x&&(0,m.jsx)(rr,{visible:c,onClose:()=>h(!1),accessToken:a,onSuccess:()=>{h(!1),p(null),r()},guardrailId:x.guardrail_id||"",initialValues:{guardrail_name:x.guardrail_name||"",provider:Object.keys(aF).find(e=>aF[e]===(null==x?void 0:x.litellm_params.guardrail))||"",mode:x.litellm_params.mode,default_on:x.litellm_params.default_on,pii_entities_config:x.litellm_params.pii_entities_config,...x.guardrail_info}})]})},ro=e=>{let{accessToken:s,userRole:l}=e,[t,a]=(0,u.useState)([]),[r,n]=(0,u.useState)(!1),[i,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),j=!!l&&(0,eZ.tY)(l),f=async()=>{if(s){o(!0);try{let e=await (0,b.t3)(s);console.log("guardrails: ".concat(JSON.stringify(e))),a(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}};(0,u.useEffect)(()=>{f()},[s]);let _=async()=>{if(h&&s){c(!0);try{await (0,b.Yi)(s,h.id),F.ZP.success('Guardrail "'.concat(h.name,'" deleted successfully')),f()}catch(e){console.error("Error deleting guardrail:",e),F.ZP.error("Failed to delete guardrail")}finally{c(!1),x(null)}}};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[!p&&(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(C.Z,{icon:aD.Z,onClick:()=>{n(!0)},disabled:!s,children:"Add Guardrail"})}),(0,m.jsx)(ri,{guardrailsList:t,isLoading:i,onDeleteClick:(e,s)=>{x({id:e,name:s})},accessToken:s,onGuardrailUpdated:f,isAdmin:j,onShowGuardrailInfo:g}),(0,m.jsx)(rs,{visible:r,onClose:()=>{n(!1)},accessToken:s,onSuccess:()=>{f()}}),h&&(0,m.jsxs)(R.Z,{title:"Delete Guardrail",open:null!==h,onOk:_,onCancel:()=>{x(null)},confirmLoading:d,okText:"Delete",okButtonProps:{danger:!0},children:[(0,m.jsxs)("p",{children:["Are you sure you want to delete guardrail: ",h.name," ?"]}),(0,m.jsx)("p",{children:"This action cannot be undone."})]})]})},rd=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)('{\n "model": "openai/gpt-4o",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n },\n {\n "role": "user",\n "content": "Explain quantum computing in simple terms"\n }\n ],\n "temperature": 0.7,\n "max_tokens": 500,\n "stream": true\n}'),[a,r]=(0,u.useState)(""),[n,i]=(0,u.useState)(!1),o=(e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")},d=async()=>{i(!0);try{let e;try{e=JSON.parse(l)}catch(e){F.ZP.error("Invalid JSON in request body"),i(!1);return}let t={call_type:"completion",request_body:e};if(!s){F.ZP.error("No access token found"),i(!1);return}let a=await (0,b.Yo)(s,t);if(a.raw_request_api_base&&a.raw_request_body){let e=o(a.raw_request_api_base,a.raw_request_body,a.raw_request_headers||{});r(e),F.ZP.success("Request transformed successfully")}else{let e="string"==typeof a?a:JSON.stringify(a);r(e),F.ZP.info("Transformed request received in unexpected format")}}catch(e){console.error("Error transforming request:",e),F.ZP.error("Failed to transform request")}finally{i(!1)}};return(0,m.jsxs)("div",{className:"w-full m-2",style:{overflow:"hidden"},children:[(0,m.jsx)(O.Z,{children:"Playground"}),(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"See how LiteLLM transforms your request for the specified provider."}),(0,m.jsxs)("div",{style:{display:"flex",gap:"16px",width:"100%",minWidth:0,overflow:"hidden"},className:"mt-4",children:[(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"600px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Original Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"The request you would send to LiteLLM /chat/completions endpoint."})]}),(0,m.jsx)("textarea",{style:{flex:"1 1 auto",width:"100%",minHeight:"240px",padding:"16px",border:"1px solid #e8e8e8",borderRadius:"6px",fontFamily:"monospace",fontSize:"14px",resize:"none",marginBottom:"24px",overflow:"auto"},value:l,onChange:e=>t(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),d())},placeholder:"Press Cmd/Ctrl + Enter to transform"}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:(0,m.jsxs)(U.ZP,{type:"primary",style:{backgroundColor:"#000",display:"flex",alignItems:"center",gap:"8px"},onClick:d,loading:n,children:[(0,m.jsx)("span",{children:"Transform"}),(0,m.jsx)("span",{children:"→"})]})})]}),(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"800px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Transformed Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"How LiteLLM transforms your request for the specified provider."}),(0,m.jsx)("br",{}),(0,m.jsx)("p",{style:{color:"#666",margin:0},className:"text-xs",children:"Note: Sensitive headers are not shown."})]}),(0,m.jsxs)("div",{style:{position:"relative",backgroundColor:"#f5f5f5",borderRadius:"6px",flex:"1 1 auto",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,m.jsx)("pre",{style:{padding:"16px",fontFamily:"monospace",fontSize:"14px",margin:0,overflow:"auto",flex:"1 1 auto"},children:a||'curl -X POST \\\n https://api.openai.com/v1/chat/completions \\\n -H \'Authorization: Bearer sk-xxx\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{\n "model": "gpt-4",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n }\n ],\n "temperature": 0.7\n }\''}),(0,m.jsx)(U.ZP,{type:"text",icon:(0,m.jsx)(ls.Z,{}),style:{position:"absolute",right:"8px",top:"8px"},size:"small",onClick:()=>{navigator.clipboard.writeText(a||""),F.ZP.success("Copied to clipboard")}})]})]})]}),(0,m.jsx)("div",{className:"mt-4 text-right w-full",children:(0,m.jsxs)("p",{className:"text-sm text-gray-500",children:["Found an error? File an issue ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/issues",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})]})},rc=l(21770);let rm=[{accessorKey:"mcp_info.server_name",header:"Provider",cell:e=>{let{row:s}=e,l=s.original.mcp_info.server_name,t=s.original.mcp_info.logo_url;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:"".concat(l," logo"),className:"h-5 w-5 object-contain"}),(0,m.jsx)("span",{className:"font-medium",children:l})]})}},{accessorKey:"name",header:"Tool Name",cell:e=>{let{row:s}=e,l=s.getValue("name");return(0,m.jsx)("div",{children:(0,m.jsx)("span",{className:"font-mono text-sm",children:l})})}},{accessorKey:"description",header:"Description",cell:e=>{let{row:s}=e,l=s.getValue("description");return(0,m.jsx)("div",{className:"max-w-md",children:(0,m.jsx)("span",{className:"text-sm text-gray-700",children:l})})}},{id:"actions",header:"Actions",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex items-center space-x-2",children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{"function"==typeof s.original.onToolSelect&&s.original.onToolSelect(l)},children:"Test Tool"})})}}];function ru(e){let{tool:s,onSubmit:l,isLoading:t,result:a,error:r,onClose:n}=e,[i,o]=u.useState({}),d=u.useMemo(()=>"string"==typeof s.inputSchema?{type:"object",properties:{input:{type:"string",description:"Input for this tool"}},required:["input"]}:s.inputSchema,[s.inputSchema]),c=(e,s)=>{o(l=>({...l,[e]:s}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-lg border p-6 max-w-4xl w-full",children:[(0,m.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("h2",{className:"text-xl font-bold",children:["Test Tool: ",(0,m.jsx)("span",{className:"font-mono",children:s.name})]}),(0,m.jsx)("p",{className:"text-gray-600",children:s.description}),(0,m.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:["Provider: ",s.mcp_info.server_name]})]}),(0,m.jsx)("button",{onClick:n,className:"p-1 rounded-full hover:bg-gray-200",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,m.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Input Parameters"}),(0,m.jsxs)("form",{onSubmit:e=>{e.preventDefault(),l(i)},children:["string"==typeof s.inputSchema?(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"This tool uses a dynamic input schema."}),(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Input ",(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,m.jsx)("input",{type:"text",value:i.input||"",onChange:e=>c("input",e.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"})]})]}):Object.entries(d.properties).map(e=>{var s,l,t;let[a,r]=e;return(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[a," ",(null===(s=d.required)||void 0===s?void 0:s.includes(a))&&(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),r.description&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:r.description}),"string"===r.type&&(0,m.jsx)("input",{type:"text",value:i[a]||"",onChange:e=>c(a,e.target.value),required:null===(l=d.required)||void 0===l?void 0:l.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"number"===r.type&&(0,m.jsx)("input",{type:"number",value:i[a]||"",onChange:e=>c(a,parseFloat(e.target.value)),required:null===(t=d.required)||void 0===t?void 0:t.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"boolean"===r.type&&(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("input",{type:"checkbox",checked:i[a]||!1,onChange:e=>c(a,e.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),(0,m.jsx)("span",{className:"ml-2 text-sm text-gray-600",children:"Enable"})]})]},a)}),(0,m.jsx)("div",{className:"mt-6",children:(0,m.jsx)(C.Z,{type:"submit",disabled:t,className:"w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white",children:t?"Calling...":"Call Tool"})})]})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg overflow-auto max-h-[500px]",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Result"}),t&&(0,m.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,m.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-700"})}),r&&(0,m.jsxs)("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-md",children:[(0,m.jsx)("p",{className:"font-medium",children:"Error"}),(0,m.jsx)("pre",{className:"mt-2 text-xs overflow-auto whitespace-pre-wrap",children:r.message})]}),a&&!t&&!r&&(0,m.jsxs)("div",{children:[a.map((e,s)=>(0,m.jsxs)("div",{className:"mb-4",children:["text"===e.type&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("p",{className:"whitespace-pre-wrap text-sm",children:e.text})}),"image"===e.type&&e.url&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("img",{src:e.url,alt:"Tool result",className:"max-w-full h-auto rounded"})}),"embedded_resource"===e.type&&(0,m.jsxs)("div",{className:"bg-white border p-3 rounded-md",children:[(0,m.jsx)("p",{className:"text-sm font-medium",children:"Embedded Resource"}),(0,m.jsxs)("p",{className:"text-xs text-gray-500",children:["Type: ",e.resource_type]}),e.url&&(0,m.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"View Resource"})]})]},s)),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)("details",{className:"text-xs",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-gray-500 hover:text-gray-700",children:"Raw JSON Response"}),(0,m.jsx)("pre",{className:"mt-2 bg-gray-100 p-2 rounded-md overflow-auto max-h-[300px]",children:JSON.stringify(a,null,2)})]})})]}),!a&&!t&&!r&&(0,m.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,m.jsx)("p",{children:"The result will appear here after you call the tool."})})]})]})]})}function rh(e){let{columns:s,data:l,isLoading:t}=e;return(0,m.jsx)(tu,{columns:s,data:l,isLoading:t,renderSubComponent:()=>(0,m.jsx)("div",{}),getRowCanExpand:()=>!1,loadingMessage:"\uD83D\uDE85 Loading tools...",noDataMessage:"No tools found"})}function rx(e){let{accessToken:s,userRole:l,userID:t}=e,[a,r]=(0,u.useState)(""),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),{data:x,isLoading:p}=(0,eY.a)({queryKey:["mcpTools"],queryFn:()=>{if(!s)throw Error("Access Token required");return(0,b.lU)(s)},enabled:!!s}),{mutate:g,isPending:j}=(0,rc.D)({mutationFn:e=>{if(!s)throw Error("Access Token required");return(0,b.tB)(s,e.tool.name,e.arguments)},onSuccess:e=>{d(e),h(null)},onError:e=>{h(e),d(null)}}),f=u.useMemo(()=>x?x.map(e=>({...e,onToolSelect:e=>{i(e),d(null),h(null)}})):[],[x]),_=u.useMemo(()=>f.filter(e=>{let s=a.toLowerCase();return e.name.toLowerCase().includes(s)||e.description.toLowerCase().includes(s)||e.mcp_info.server_name.toLowerCase().includes(s)}),[f,a]);return s&&l&&t?(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"MCP Tools"})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search tools...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:a,onChange:e=>r(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"text-sm text-gray-500",children:[_.length," tool",1!==_.length?"s":""," available"]})]})}),(0,m.jsx)(rh,{columns:rm,data:_,isLoading:p})]}),n&&(0,m.jsx)("div",{className:"fixed inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center z-50 p-4",children:(0,m.jsx)(ru,{tool:n,onSubmit:e=>{n&&g({tool:n,arguments:e})},isLoading:j,result:o,error:c,onClose:()=>i(null)})})]}):(0,m.jsx)("div",{className:"p-6 text-center text-gray-500",children:"Missing required authentication parameters."})}var rp=e=>{let{tagId:s,onClose:l,accessToken:t,is_admin:a,editTag:r}=e,[n]=M.Z.useForm(),[i,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(r),[h,x]=(0,u.useState)([]),p=async()=>{if(t)try{let e=(await (0,b.mC)(t,[s]))[s];e&&(o(e),r&&n.setFieldsValue({name:e.name,description:e.description,models:e.models}))}catch(e){console.error("Error fetching tag details:",e),F.ZP.error("Error fetching tag details: "+e)}};(0,u.useEffect)(()=>{p()},[s,t]),(0,u.useEffect)(()=>{t&&eT("dummy-user","Admin",t,x)},[t]);let g=async e=>{if(t)try{await (0,b.n9)(t,{name:e.name,description:e.description,models:e.models}),F.ZP.success("Tag updated successfully"),c(!1),p()}catch(e){console.error("Error updating tag:",e),F.ZP.error("Error updating tag: "+e)}};return i?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{onClick:l,className:"mb-4",children:"← Back to Tags"}),(0,m.jsxs)(O.Z,{children:["Tag Name: ",i.name]}),(0,m.jsx)(P.Z,{className:"text-gray-500",children:i.description||"No description"})]}),a&&!d&&(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Tag"})]}),d?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(M.Z,{form:n,onFinish:g,layout:"vertical",initialValues:i,children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(z.default,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed LLMs"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process this type of data",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:h.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{onClick:()=>c(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}):(0,m.jsx)("div",{className:"space-y-6",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Tag Details"}),(0,m.jsxs)("div",{className:"space-y-4 mt-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Name"}),(0,m.jsx)(P.Z,{children:i.name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Description"}),(0,m.jsx)(P.Z,{children:i.description||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Allowed LLMs"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:0===i.models.length?(0,m.jsx)(eL.Z,{color:"red",children:"All Models"}):i.models.map(e=>{var s;return(0,m.jsx)(eL.Z,{color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(null===(s=i.model_info)||void 0===s?void 0:s[e])||e})},e)})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:i.created_at?new Date(i.created_at).toLocaleString():"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:i.updated_at?new Date(i.updated_at).toLocaleString():"-"})]})]})]})})]}):(0,m.jsx)("div",{children:"Loading..."})},rg=e=>{let{data:s,onEdit:l,onDelete:t,onSelectTag:a}=e,[r,n]=u.useState([{id:"created_at",desc:!0}]),i=[{header:"Tag Name",accessorKey:"name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.name,children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5",onClick:()=>a(l.name),children:l.name})})})}},{header:"Description",accessorKey:"description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.description,children:(0,m.jsx)("span",{className:"text-xs",children:l.description||"-"})})}},{header:"Allowed LLMs",accessorKey:"models",cell:e=>{var s,l;let{row:t}=e,a=t.original;return(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:(null==a?void 0:null===(s=a.models)||void 0===s?void 0:s.length)===0?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Models"}):null==a?void 0:null===(l=a.models)||void 0===l?void 0:l.map(e=>{var s;return(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(0,m.jsx)(P.Z,{children:(null===(s=a.model_info)||void 0===s?void 0:s[e])||e})})},e)})})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,a=s.original;return(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>l(a),className:"cursor-pointer"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(a.name),className:"cursor-pointer"})]})}}],o=(0,e2.b7)({data:s,columns:i,state:{sorting:r},onSortingChange:n,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:i.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No tags found"})})})})})]})})})},rj=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v]=M.Z.useForm(),[y,Z]=(0,u.useState)([]),N=async()=>{if(s)try{let e=await (0,b.UM)(s);console.log("List tags response:",e),r(Object.values(e))}catch(e){console.error("Error fetching tags:",e),F.ZP.error("Error fetching tags: "+e)}},w=async e=>{if(s)try{await (0,b.mY)(s,{name:e.tag_name,description:e.description,models:e.allowed_llms}),F.ZP.success("Tag created successfully"),i(!1),v.resetFields(),N()}catch(e){console.error("Error creating tag:",e),F.ZP.error("Error creating tag: "+e)}},T=async e=>{j(e),p(!0)},A=async()=>{if(s&&g){try{await (0,b.fE)(s,g),F.ZP.success("Tag deleted successfully"),N()}catch(e){console.error("Error deleting tag:",e),F.ZP.error("Error deleting tag: "+e)}p(!1),j(null)}};return(0,u.useEffect)(()=>{l&&t&&s&&(async()=>{try{let e=await (0,b.AZ)(s,l,t);e&&e.data&&Z(e.data)}catch(e){console.error("Error fetching models:",e),F.ZP.error("Error fetching models: "+e)}})()},[s,l,t]),(0,u.useEffect)(()=>{N()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:o?(0,m.jsx)(rp,{tagId:o,onClose:()=>{d(null),h(!1)},accessToken:s,is_admin:"Admin"===t,editTag:c}):(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Tag Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{N(),_(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(P.Z,{className:"mb-4",children:["Click on a tag name to view and edit its details.",(0,m.jsxs)("p",{children:["You can use tags to restrict the usage of certain LLMs based on tags passed in the request. Read more about tag routing ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tag_routing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})]}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>i(!0),children:"+ Create New Tag"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(rg,{data:a,onEdit:e=>{d(e.name),h(!0)},onDelete:T,onSelectTag:d})})}),(0,m.jsx)(R.Z,{title:"Create New Tag",visible:n,width:800,footer:null,onCancel:()=>{i(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"tag_name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed Models"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process requests from this tag",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_llms",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:y.map(e=>(0,m.jsx)(D.default.Option,{value:e.model_info.id,children:(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{children:e.model_name}),(0,m.jsxs)("span",{className:"text-gray-400 ml-2",children:["(",e.model_info.id,")"]})]})},e.model_info.id))})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Tag"})})]})}),x&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Tag"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this tag?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:A,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{p(!1),j(null)},children:"Cancel"})]})]})]})})]})})},rf=e=>{let{data:s,onDelete:l}=e,[t,a]=u.useState([{id:"created_at",desc:!0}]),r=[{header:"Vector Store ID",accessorKey:"vector_store_id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.vector_store_id,children:(0,m.jsx)("span",{className:"font-mono text-blue-500 text-xs font-normal",children:l.vector_store_id})})})}},{header:"Name",accessorKey:"vector_store_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_name,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_name||"-"})})}},{header:"Description",accessorKey:"vector_store_description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_description,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_description||"-"})})}},{header:"Provider",accessorKey:"custom_llm_provider",cell:e=>{let{row:s}=e,{displayName:l,logo:t}=sm(s.original.custom_llm_provider);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:l,className:"h-4 w-4"}),(0,m.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.vector_store_id),className:"cursor-pointer"})})}}],n=(0,e2.b7)({data:s,columns:r,state:{sorting:t},onSortingChange:a,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:n.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:n.getRowModel().rows.length>0?n.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:r.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No vector stores found"})})})})})]})})})},r_=e=>{let{isVisible:s,onCancel:l,onSuccess:t,accessToken:a,credentials:r}=e,[n]=M.Z.useForm(),[o,d]=(0,u.useState)("{}"),c=async e=>{if(a)try{let s={};try{s=o.trim()?JSON.parse(o):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}await (0,b.Mx)(a,{vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s,litellm_credential_name:e.litellm_credential_name}),F.ZP.success("Vector store created successfully"),n.resetFields(),d("{}"),t()}catch(e){console.error("Error creating vector store:",e),F.ZP.error("Error creating vector store: "+e)}},h=()=>{n.resetFields(),d("{}"),l()};return(0,m.jsx)(R.Z,{title:"Create New Vector Store",visible:s,width:800,footer:null,onCancel:h,children:(0,m.jsxs)(M.Z,{form:n,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Provider"," ",(0,m.jsx)(Y.Z,{title:"Select the provider for this vector store",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],initialValue:"bedrock",children:(0,m.jsx)(D.default,{children:Object.entries(i).map(e=>{let[s,l]=e;return"Bedrock"===s?(0,m.jsx)(D.default.Option,{value:so[s],children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s):null})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store ID"," ",(0,m.jsx)(Y.Z,{title:"Enter the vector store ID from your api provider",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_id",rules:[{required:!0,message:"Please input the vector store ID from your api provider"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store Name"," ",(0,m.jsx)(Y.Z,{title:"Custom name you want to give to the vector store, this name will be rendered on the LiteLLM UI",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_name",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"vector_store_description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Existing Credentials"," ",(0,m.jsx)(Y.Z,{title:"Optionally select API provider credentials for this vector store eg. Bedrock API KEY",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...r.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON metadata for the vector store (optional)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),children:(0,m.jsx)(z.default.TextArea,{rows:4,value:o,onChange:e=>d(e.target.value),placeholder:'{"key": "value"}'})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,m.jsx)(C.Z,{onClick:h,variant:"secondary",children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",type:"submit",children:"Create"})]})]})})},rv=e=>{let{isVisible:s,onCancel:l,onConfirm:t}=e;return(0,m.jsxs)(R.Z,{title:"Delete Vector Store",visible:s,footer:null,onCancel:l,children:[(0,m.jsx)("p",{children:"Are you sure you want to delete this vector store? This action cannot be undone."}),(0,m.jsxs)("div",{className:"px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:t,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:l,variant:"primary",children:"Cancel"})]})]})},ry=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[n,i]=(0,u.useState)(!1),[o,d]=(0,u.useState)(!1),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)([]),f=async()=>{if(s)try{let e=await (0,b.Ou)(s);console.log("List vector stores response:",e),r(e.data||[])}catch(e){console.error("Error fetching vector stores:",e),F.ZP.error("Error fetching vector stores: "+e)}},_=async()=>{if(s)try{let e=await (0,b.N3)(s);console.log("List credentials response:",e),j(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e),F.ZP.error("Error fetching credentials: "+e)}},v=async e=>{h(e),d(!0)},y=async()=>{if(s&&c){try{await (0,b.Pv)(s,c),F.ZP.success("Vector store deleted successfully"),f()}catch(e){console.error("Error deleting vector store:",e),F.ZP.error("Error deleting vector store: "+e)}d(!1),h(null)}};return(0,u.useEffect)(()=>{f(),_()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Vector Store Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[x&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",x]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{f(),_(),p(new Date().toLocaleString())}})]})]}),(0,m.jsx)(P.Z,{className:"mb-4",children:(0,m.jsx)("p",{children:"You can use vector stores to store and retrieve LLM embeddings. Currently, we support Amazon Bedrock vector stores."})}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>i(!0),children:"+ Create Vector Store"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(rf,{data:a,onDelete:v})})}),(0,m.jsx)(r_,{isVisible:n,onCancel:()=>i(!1),onSuccess:()=>{i(!1),f()},accessToken:s,credentials:g}),(0,m.jsx)(rv,{isVisible:o,onCancel:()=>d(!1),onConfirm:y})]})})},rb=l(49096),rZ=l(53335);let{cva:rN,cx:rw,compose:rk}=(0,rb.ZD)({hooks:{onComplete:e=>(0,rZ.m6)(e)}});function rS(e){var s,l;let{className:t="",...a}=e,r=(0,u.useId)();return s=()=>{let e=document.getAnimations().filter(e=>e instanceof CSSAnimation&&"spin"===e.animationName),s=e.find(e=>{var s;return(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))===r}),l=e.find(e=>{var s;return e.effect instanceof KeyframeEffect&&(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))!==r});s&&l&&(s.currentTime=l.currentTime)},l=[r],(0,u.useLayoutEffect)(s,l),(0,m.jsxs)("svg",{"data-spinner-id":r,className:rw("pointer-events-none size-12 animate-spin text-current",t),fill:"none",viewBox:"0 0 24 24",...a,children:[(0,m.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,m.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}let rC=new p.S;function rI(){return(0,m.jsxs)("div",{className:rw("h-screen","flex items-center justify-center gap-4"),children:[(0,m.jsx)("div",{className:"text-lg font-medium py-2 pr-4 border-r border-r-gray-200",children:"\uD83D\uDE85 LiteLLM"}),(0,m.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,m.jsx)(rS,{className:"size-4"}),(0,m.jsx)("span",{className:"text-gray-600 text-sm",children:"Loading..."})]})]})}function rT(){let[e,s]=(0,u.useState)(""),[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[n,i]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,p]=(0,u.useState)([]),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,S]=(0,u.useState)(!0),C=(0,h.useSearchParams)(),[I,T]=(0,u.useState)({data:[]}),[A,E]=(0,u.useState)(null),[P,O]=(0,u.useState)(!1),[L,D]=(0,u.useState)(!0),[M,F]=(0,u.useState)(null),R=C.get("invitation_id"),[q,U]=(0,u.useState)(()=>C.get("page")||"api-keys"),[z,V]=(0,u.useState)(null),K=e=>{p(s=>s?[...s,e]:[e]),O(()=>!P)},B=!1===L&&null===A&&null===R;return((0,u.useEffect)(()=>{E(function(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token")),D(!1)},[]),(0,u.useEffect)(()=>{B&&(window.location.href=(b.H2||"")+"/sso/key/generate")},[B]),(0,u.useEffect)(()=>{if(!A)return;let e=(0,x.o)(A);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),V(e.key),r(e.disabled_non_admin_personal_key_creation),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&U("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?S("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,b.K8)(e.auth_header_name),e.user_id&&F(e.user_id)}},[A]),(0,u.useEffect)(()=>{z&&M&&e&&eT(M,e,z,v),z&&M&&e&&w(z,M,e,null,d),z&&lE(z,f)},[z,M,e]),L||B)?(0,m.jsx)(rI,{}):(0,m.jsx)(u.Suspense,{fallback:(0,m.jsx)(rI,{}),children:(0,m.jsx)(g.aH,{client:rC,children:R?(0,m.jsx)(sn,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:n,setUserEmail:i,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):(0,m.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,m.jsx)(N,{userID:M,userRole:e,premiumUser:l,userEmail:n,setProxySettings:Z,proxySettings:y,accessToken:z}),(0,m.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,m.jsx)("div",{className:"mt-8",children:(0,m.jsx)(aZ,{setPage:e=>{let s=new URLSearchParams(C);s.set("page",e),window.history.pushState(null,"","?".concat(s.toString())),U(e)},userRole:e,defaultSelectedKey:q})}),"api-keys"==q?(0,m.jsx)(sn,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:n,setUserEmail:i,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):"models"==q?(0,m.jsx)(lh,{userID:M,userRole:e,token:A,keys:c,accessToken:z,modelData:I,setModelData:T,premiumUser:l,teams:o}):"llm-playground"==q?(0,m.jsx)(ad,{userID:M,userRole:e,token:A,accessToken:z,disabledPersonalKeyCreation:a}):"users"==q?(0,m.jsx)(lk,{userID:M,userRole:e,token:A,keys:c,teams:o,accessToken:z,setKeys:p}):"teams"==q?(0,m.jsx)(lT,{teams:o,setTeams:d,searchParams:C,accessToken:z,userID:M,userRole:e,organizations:j}):"organizations"==q?(0,m.jsx)(lP,{organizations:j,setOrganizations:f,userModels:_,accessToken:z,userRole:e,premiumUser:l}):"admin-panel"==q?(0,m.jsx)(lK,{setTeams:d,searchParams:C,accessToken:z,userID:M,showSSOBanner:k,premiumUser:l,proxySettings:y}):"api_ref"==q?(0,m.jsx)(tq,{proxySettings:y}):"settings"==q?(0,m.jsx)(l1,{userID:M,userRole:e,accessToken:z,premiumUser:l}):"budgets"==q?(0,m.jsx)(td,{accessToken:z}):"guardrails"==q?(0,m.jsx)(ro,{accessToken:z,userRole:e}):"transform-request"==q?(0,m.jsx)(rd,{accessToken:z}):"general-settings"==q?(0,m.jsx)(te,{userID:M,userRole:e,accessToken:z,modelData:I}):"model-hub"==q?(0,m.jsx)(tC.Z,{accessToken:z,publicPage:!1,premiumUser:l}):"caching"==q?(0,m.jsx)(aL,{userID:M,userRole:e,token:A,accessToken:z,premiumUser:l}):"pass-through-settings"==q?(0,m.jsx)(tr,{userID:M,userRole:e,accessToken:z,modelData:I}):"logs"==q?(0,m.jsx)(tk,{userID:M,userRole:e,token:A,accessToken:z,allTeams:null!=o?o:[]}):"mcp-tools"==q?(0,m.jsx)(rx,{accessToken:z,userRole:e,userID:M}):"tag-management"==q?(0,m.jsx)(rj,{accessToken:z,userRole:e,userID:M}):"vector-stores"==q?(0,m.jsx)(ry,{accessToken:z,userRole:e,userID:M}):"new_usage"==q?(0,m.jsx)(tR,{userID:M,userRole:e,accessToken:z,teams:null!=o?o:[]}):(0,m.jsx)(ak,{userID:M,userRole:e,token:A,accessToken:z,keys:c,premiumUser:l})]})]})})})}},3914:function(e,s,l){"use strict";function t(){let e=window.location.hostname,s=["Lax","Strict","None"];["/","/ui"].forEach(l=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,";"),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let t="None"===s?" Secure;":"";document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; SameSite=").concat(s,";").concat(t),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(t)})}),console.log("After clearing cookies:",document.cookie)}function a(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}l.d(s,{b:function(){return t},e:function(){return a}})}},function(e){e.O(0,[665,990,402,313,899,460,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,s,l){Promise.resolve().then(l.bind(l,96564))},12011:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return v}});var t=l(57437),a=l(2265),r=l(99376),i=l(20831),n=l(94789),o=l(12514),d=l(49804),c=l(67101),m=l(84264),u=l(49566),h=l(96761),x=l(84566),p=l(19250),g=l(14474),j=l(13634),f=l(73002),_=l(3914);function v(){let[e]=j.Z.useForm(),s=(0,r.useSearchParams)();(0,_.e)("token");let l=s.get("invitation_id"),[v,y]=(0,a.useState)(null),[b,Z]=(0,a.useState)(""),[N,w]=(0,a.useState)(""),[k,S]=(0,a.useState)(null),[C,I]=(0,a.useState)(""),[T,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{l&&(0,p.W_)(l).then(e=>{let s=e.login_url;console.log("login_url:",s),I(s);let l=e.token,t=(0,g.o)(l);A(l),console.log("decoded:",t),y(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),S(t.user_id)})},[l]),(0,t.jsx)("div",{className:"mx-auto w-full max-w-md mt-10",children:(0,t.jsxs)(o.Z,{children:[(0,t.jsx)(h.Z,{className:"text-sm mb-5 text-center",children:"\uD83D\uDE85 LiteLLM"}),(0,t.jsx)(h.Z,{className:"text-xl",children:"Sign up"}),(0,t.jsx)(m.Z,{children:"Claim your user account to login to Admin UI."}),(0,t.jsx)(n.Z,{className:"mt-4",title:"SSO",icon:x.GH$,color:"sky",children:(0,t.jsxs)(c.Z,{numItems:2,className:"flex justify-between items-center",children:[(0,t.jsx)(d.Z,{children:"SSO is under the Enterprise Tier."}),(0,t.jsx)(d.Z,{children:(0,t.jsx)(i.Z,{variant:"primary",className:"mb-2",children:(0,t.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})})})]})}),(0,t.jsxs)(j.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",v,"token:",T,"formValues:",e),v&&T&&(e.user_email=N,k&&l&&(0,p.m_)(v,l,k,e.password).then(e=>{let s="/ui/";s+="?login=success",document.cookie="token="+T,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(j.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:N,defaultValue:N,className:"max-w-md"})}),(0,t.jsx)(j.Z.Item,{label:"Password",name:"password",rules:[{required:!0,message:"password required to sign up"}],help:"Create a password for your account",children:(0,t.jsx)(u.Z,{placeholder:"",type:"password",className:"max-w-md"})})]}),(0,t.jsx)("div",{className:"mt-10",children:(0,t.jsx)(f.ZP,{htmlType:"submit",children:"Sign Up"})})]})]})})}},96564:function(e,s,l){"use strict";l.r(s),l.d(s,{default:function(){return rA}});var t,a,r,i,n,o,d,c,m=l(57437),u=l(2265),h=l(99376),x=l(14474),p=l(21623),g=l(29827),j=l(27648),f=l(80795),_=l(15883),v=l(40428),y=l(3914),b=l(19250);let Z=async e=>{if(!e)return null;try{return await (0,b.g)(e)}catch(e){return console.error("Error fetching proxy settings:",e),null}};var N=e=>{let{userID:s,userEmail:l,userRole:t,premiumUser:a,proxySettings:r,setProxySettings:i,accessToken:n}=e,[o,d]=(0,u.useState)("");(0,u.useEffect)(()=>{(async()=>{if(n){let e=await Z(n);console.log("response from fetchProxySettings",e),e&&i(e)}})()},[n]),(0,u.useEffect)(()=>{d((null==r?void 0:r.PROXY_LOGOUT_URL)||"")},[r]);let c=[{key:"1",label:(0,m.jsxs)("div",{className:"py-1",children:[(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Role: ",t]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Email: ",l||"Unknown"]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[(0,m.jsx)(_.Z,{})," ",s]}),(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,m.jsxs)("p",{className:"text-sm hover:text-gray-900",onClick:()=>{(0,y.b)(),window.location.href=o},children:[(0,m.jsx)(v.Z,{})," Logout"]})}];return(0,m.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,m.jsx)("div",{className:"w-full",children:(0,m.jsxs)("div",{className:"flex items-center h-12 px-4",children:[(0,m.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,m.jsx)(j.default,{href:"/",className:"flex items-center",children:(0,m.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-8 w-auto"})})}),(0,m.jsxs)("div",{className:"flex items-center space-x-5 ml-auto",children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:"Docs"}),(0,m.jsx)(f.Z,{menu:{items:c,style:{padding:"4px",marginTop:"4px"}},children:(0,m.jsxs)("button",{className:"inline-flex items-center text-[13px] text-gray-600 hover:text-gray-900 transition-colors",children:["User",(0,m.jsx)("svg",{className:"ml-1 w-4 h-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})};let w=async(e,s,l,t,a)=>{let r;r="Admin"!=l&&"Admin Viewer"!=l?await (0,b.It)(e,(null==t?void 0:t.organization_id)||null,s):await (0,b.It)(e,(null==t?void 0:t.organization_id)||null),console.log("givenTeams: ".concat(r)),a(r)};var k=l(49804),S=l(67101),C=l(20831),I=l(49566),T=l(87452),A=l(88829),E=l(72208),P=l(84264),O=l(96761),L=l(29233),D=l(52787),M=l(13634),F=l(41021),R=l(91679),q=l(29967),U=l(73002),z=l(64482),V=l(30150),K=e=>{let{step:s=.01,style:l={width:"100%"},placeholder:t="Enter a numerical value",min:a,max:r,onChange:i,...n}=e;return(0,m.jsx)(V.Z,{onWheel:e=>e.currentTarget.blur(),step:s,style:l,placeholder:t,min:a,max:r,onChange:i,...n})};let B=async(e,s,l)=>{try{if(null===e||null===s)return;if(null!==l){let t=(await (0,b.So)(l,e,s,!0)).data.map(e=>e.id),a=[],r=[];return t.forEach(e=>{e.endsWith("/*")?a.push(e):r.push(e)}),[...a,...r]}}catch(e){console.error("Error fetching user models:",e)}},H=e=>{if(e.endsWith("/*")){let s=e.replace("/*","");return"All ".concat(s," models")}return e},J=(e,s)=>{let l=[],t=[];return console.log("teamModels",e),console.log("allModels",s),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=s.filter(e=>e.startsWith(a+"/"));t.push(...r),l.push(e)}else t.push(e)}),[...l,...t].filter((e,s,l)=>l.indexOf(e)===s)};var G=l(20577),W=l(15424),Y=l(89970);let $=(e,s)=>["metadata","config","enforced_params","aliases"].includes(e)||"json"===s.format,X=e=>{if(!e)return!0;try{return JSON.parse(e),!0}catch(e){return!1}},Q=(e,s,l)=>{let t={max_budget:"Enter maximum budget in USD (e.g., 100.50)",budget_duration:"Select a time period for budget reset",tpm_limit:"Enter maximum tokens per minute (whole number)",rpm_limit:"Enter maximum requests per minute (whole number)",duration:"Enter duration (e.g., 30s, 24h, 7d)",metadata:'Enter JSON object with key-value pairs\nExample: {"team": "research", "project": "nlp"}',config:'Enter configuration as JSON object\nExample: {"setting": "value"}',permissions:"Enter comma-separated permission strings",enforced_params:'Enter parameters as JSON object\nExample: {"param": "value"}',blocked:"Enter true/false or specific block conditions",aliases:'Enter aliases as JSON object\nExample: {"alias1": "value1", "alias2": "value2"}',models:"Select one or more model names",key_alias:"Enter a unique identifier for this key",tags:"Enter comma-separated tag strings"}[e]||({string:"Text input",number:"Numeric input",integer:"Whole number input",boolean:"True/False value"})[l]||"Text input";return $(e,s)?"".concat(t,"\nMust be valid JSON format"):s.enum?"Select from available options\nAllowed values: ".concat(s.enum.join(", ")):t};var ee=e=>{let{schemaComponent:s,excludedFields:l=[],form:t,overrideLabels:a={},overrideTooltips:r={},customValidation:i={},defaultValues:n={}}=e,[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null);(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.lP)()).components.schemas[s];if(!e)throw Error('Schema component "'.concat(s,'" not found'));d(e);let a={};Object.keys(e.properties).filter(e=>!l.includes(e)&&void 0!==n[e]).forEach(e=>{a[e]=n[e]}),t.setFieldsValue(a)}catch(e){console.error("Schema fetch error:",e),h(e instanceof Error?e.message:"Failed to fetch schema")}})()},[s,t,l]);let x=e=>{if(e.type)return e.type;if(e.anyOf){let s=e.anyOf.map(e=>e.type);if(s.includes("number")||s.includes("integer"))return"number";s.includes("string")}return"string"},p=(e,s)=>{var l;let t;let d=x(s),c=null==o?void 0:null===(l=o.required)||void 0===l?void 0:l.includes(e),u=a[e]||s.title||e,h=r[e]||s.description,p=[];c&&p.push({required:!0,message:"".concat(u," is required")}),i[e]&&p.push({validator:i[e]}),$(e,s)&&p.push({validator:async(e,s)=>{if(s&&!X(s))throw Error("Please enter valid JSON")}});let g=h?(0,m.jsxs)("span",{children:[u," ",(0,m.jsx)(Y.Z,{title:h,children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}):u;return t=$(e,s)?(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter as JSON",className:"font-mono"}):s.enum?(0,m.jsx)(D.default,{children:s.enum.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"number"===d||"integer"===d?(0,m.jsx)(G.Z,{style:{width:"100%"},precision:"integer"===d?0:void 0}):"duration"===e?(0,m.jsx)(I.Z,{placeholder:"eg: 30s, 30h, 30d"}):(0,m.jsx)(I.Z,{placeholder:h||""}),(0,m.jsx)(M.Z.Item,{label:g,name:e,className:"mt-8",rules:p,initialValue:n[e],help:(0,m.jsx)("div",{className:"text-xs text-gray-500",children:Q(e,s,d)}),children:t},e)};return c?(0,m.jsxs)("div",{className:"text-red-500",children:["Error: ",c]}):(null==o?void 0:o.properties)?(0,m.jsx)("div",{children:Object.entries(o.properties).filter(e=>{let[s]=e;return!l.includes(s)}).map(e=>{let[s,l]=e;return p(s,l)})}):null},es=e=>{let{teams:s,value:l,onChange:t}=e;return(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Search or select a team",value:l,onChange:t,filterOption:(e,s)=>{var l,t,a;return!!s&&((null===(a=s.children)||void 0===a?void 0:null===(t=a[0])||void 0===t?void 0:null===(l=t.props)||void 0===l?void 0:l.children)||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==s?void 0:s.map(e=>(0,m.jsxs)(D.default.Option,{value:e.team_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.team_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.team_id,")"]})]},e.team_id))})},el=l(57365),et=l(93192);function ea(e){let{isInvitationLinkModalVisible:s,setIsInvitationLinkModalVisible:l,baseUrl:t,invitationLinkData:a}=e,{Title:r,Paragraph:i}=et.default,n=()=>(null==a?void 0:a.has_user_setup_sso)?new URL("/ui",t).toString():new URL("/ui?invitation_id=".concat(null==a?void 0:a.id),t).toString();return(0,m.jsxs)(R.Z,{title:"Invitation Link",visible:s,width:800,footer:null,onOk:()=>{l(!1)},onCancel:()=>{l(!1)},children:[(0,m.jsx)(i,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"User ID"}),(0,m.jsx)(P.Z,{children:null==a?void 0:a.user_id})]}),(0,m.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,m.jsx)(P.Z,{children:"Invitation Link"}),(0,m.jsx)(P.Z,{children:(0,m.jsx)(P.Z,{children:n()})})]}),(0,m.jsx)("div",{className:"flex justify-end mt-5",children:(0,m.jsx)(L.CopyToClipboard,{text:n(),onCopy:()=>F.ZP.success("Copied!"),children:(0,m.jsx)(C.Z,{variant:"primary",children:"Copy invitation link"})})})]})}var er=l(85010),ei=l(72188),en=l(73879),eo=l(34310),ed=l(38434),ec=l(26349),em=l(35291),eu=l(3632),eh=l(15452),ex=l.n(eh),ep=l(71157),eg=l(44643),ej=l(88532),ef=e=>{let{accessToken:s,teams:l,possibleUIRoles:t,onUsersCreated:a}=e,[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(null),[N,w]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.g)(s);Z(e)}catch(e){console.error("Error fetching UI settings:",e)}})(),w(new URL("/",window.location.href).toString())},[s]);let k=async()=>{c(!0);let e=n.map(e=>({...e,status:"pending"}));o(e);let l=!1;for(let a=0;ae.trim()).filter(Boolean),0===e.teams.length&&delete e.teams),n.models&&"string"==typeof n.models&&""!==n.models.trim()&&(e.models=n.models.split(",").map(e=>e.trim()).filter(Boolean),0===e.models.length&&delete e.models),n.max_budget&&""!==n.max_budget.toString().trim()){let s=parseFloat(n.max_budget.toString());!isNaN(s)&&s>0&&(e.max_budget=s)}n.budget_duration&&""!==n.budget_duration.trim()&&(e.budget_duration=n.budget_duration.trim()),n.metadata&&"string"==typeof n.metadata&&""!==n.metadata.trim()&&(e.metadata=n.metadata.trim()),console.log("Sending user data:",e);let r=await (0,b.Ov)(s,null,e);if(console.log("Full response:",r),r&&(r.key||r.user_id)){l=!0,console.log("Success case triggered");let e=(null===(t=r.data)||void 0===t?void 0:t.user_id)||r.user_id;try{if(null==y?void 0:y.SSO_ENABLED){let e=new URL("/ui",N).toString();o(s=>s.map((s,l)=>l===a?{...s,status:"success",key:r.key||r.user_id,invitation_link:e}:s))}else{let l=await (0,b.XO)(s,e),t=new URL("/ui?invitation_id=".concat(l.id),N).toString();o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,invitation_link:t}:e))}}catch(e){console.error("Error creating invitation:",e),o(e=>e.map((e,s)=>s===a?{...e,status:"success",key:r.key||r.user_id,error:"User created but failed to generate invitation link"}:e))}}else{console.log("Error case triggered");let e=(null==r?void 0:r.error)||"Failed to create user";console.log("Error message:",e),o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}catch(s){console.error("Caught error:",s);let e=(null==s?void 0:null===(i=s.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:r.error)||(null==s?void 0:s.message)||String(s);o(s=>s.map((s,l)=>l===a?{...s,status:"failed",error:e}:s))}}c(!1),l&&a&&a()};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>i(!0),children:"+ Bulk Invite Users"}),(0,m.jsx)(R.Z,{title:"Bulk Invite Users",visible:r,width:800,onCancel:()=>i(!1),bodyStyle:{maxHeight:"70vh",overflow:"auto"},footer:null,children:(0,m.jsx)("div",{className:"flex flex-col",children:0===n.length?(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"1"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Download and fill the template"})]}),(0,m.jsxs)("div",{className:"ml-11 mb-6",children:[(0,m.jsx)("p",{className:"mb-4",children:"Add multiple users at once by following these steps:"}),(0,m.jsxs)("ol",{className:"list-decimal list-inside space-y-2 ml-2 mb-4",children:[(0,m.jsx)("li",{children:"Download our CSV template"}),(0,m.jsx)("li",{children:"Add your users' information to the spreadsheet"}),(0,m.jsx)("li",{children:"Save the file and upload it here"}),(0,m.jsx)("li",{children:"After creation, download the results file containing the API keys for each user"})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-md border border-gray-200 mb-4",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Template Column Names"}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_email"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:"User's email address (required)"})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-red-500 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"user_role"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'User\'s role (one of: "proxy_admin", "proxy_admin_view_only", "internal_user", "internal_user_view_only")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"teams"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated team IDs (e.g., "team-1,team-2")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"max_budget"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Maximum budget as a number (e.g., "100")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"budget_duration"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Budget reset period (e.g., "30d", "1mo")'})]})]}),(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"w-3 h-3 rounded-full bg-gray-300 mt-1.5 mr-2 flex-shrink-0"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"font-medium",children:"models"}),(0,m.jsx)("p",{className:"text-sm text-gray-600",children:'Comma-separated allowed models (e.g., "gpt-3.5-turbo,gpt-4")'})]})]})]})]}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=new Blob([ex().unparse([["user_email","user_role","teams","max_budget","budget_duration","models"],["user@example.com","internal_user","team-id-1,team-id-2","100","30d","gpt-3.5-turbo,gpt-4"]])],{type:"text/csv"}),s=window.URL.createObjectURL(e),l=document.createElement("a");l.href=s,l.download="bulk_users_template.csv",document.body.appendChild(l),l.click(),document.body.removeChild(l),window.URL.revokeObjectURL(s)},size:"lg",className:"w-full md:w-auto",children:[(0,m.jsx)(en.Z,{className:"mr-2"})," Download CSV Template"]})]}),(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"2"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Upload your completed CSV"})]}),(0,m.jsxs)("div",{className:"ml-11",children:[_?(0,m.jsxs)("div",{className:"mb-4 p-4 rounded-md border ".concat(j?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200"),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[j?(0,m.jsx)(eo.Z,{className:"text-red-500 text-xl mr-3"}):(0,m.jsx)(ed.Z,{className:"text-blue-500 text-xl mr-3"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:j?"text-red-800":"text-blue-800",children:_.name}),(0,m.jsxs)(et.default.Text,{className:"block text-xs ".concat(j?"text-red-600":"text-blue-600"),children:[(_.size/1024).toFixed(1)," KB • ",new Date().toLocaleDateString()]})]})]}),(0,m.jsxs)(C.Z,{size:"xs",variant:"secondary",onClick:()=>{v(null),o([]),x(null),g(null),f(null)},className:"flex items-center",children:[(0,m.jsx)(ec.Z,{className:"mr-1"})," Remove"]})]}),j?(0,m.jsxs)("div",{className:"mt-3 text-red-600 text-sm flex items-start",children:[(0,m.jsx)(em.Z,{className:"mr-2 mt-0.5"}),(0,m.jsx)("span",{children:j})]}):!p&&(0,m.jsxs)("div",{className:"mt-3 flex items-center",children:[(0,m.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,m.jsx)("div",{className:"bg-blue-500 h-1.5 rounded-full w-full animate-pulse"})}),(0,m.jsx)("span",{className:"ml-2 text-xs text-blue-600",children:"Processing..."})]})]}):(0,m.jsx)(er.Z,{beforeUpload:e=>((x(null),g(null),f(null),v(e),"text/csv"===e.type||e.name.endsWith(".csv"))?e.size>5242880?f("File is too large (".concat((e.size/1048576).toFixed(1)," MB). Please upload a CSV file smaller than 5MB.")):ex().parse(e,{complete:e=>{if(!e.data||0===e.data.length){g("The CSV file appears to be empty. Please upload a file with data."),o([]);return}if(1===e.data.length){g("The CSV file only contains headers but no user data. Please add user data to your CSV."),o([]);return}let s=e.data[0];if(0===s.length||1===s.length&&""===s[0]){g("The CSV file doesn't contain any column headers. Please make sure your CSV has headers."),o([]);return}let t=["user_email","user_role"].filter(e=>!s.includes(e));if(t.length>0){g("Your CSV is missing these required columns: ".concat(t.join(", "),". Please add these columns to your CSV file.")),o([]);return}try{let t=e.data.slice(1).map((e,t)=>{var a,r,i,n,o,d;if(0===e.length||1===e.length&&""===e[0])return null;if(e.length=parseFloat(c.max_budget.toString())&&m.push("Max budget must be greater than 0")),c.budget_duration&&!c.budget_duration.match(/^\d+[dhmwy]$|^\d+mo$/)&&m.push('Invalid budget duration format "'.concat(c.budget_duration,'". Use format like "30d", "1mo", "2w", "6h"')),c.teams&&"string"==typeof c.teams&&l&&l.length>0){let e=l.map(e=>e.team_id),s=c.teams.split(",").map(e=>e.trim()).filter(s=>!e.includes(s));s.length>0&&m.push("Unknown team(s): ".concat(s.join(", ")))}return m.length>0&&(c.isValid=!1,c.error=m.join(", ")),c}).filter(Boolean),a=t.filter(e=>e.isValid);o(t),0===t.length?g("No valid data rows found in the CSV file. Please check your file format."):0===a.length?x("No valid users found in the CSV. Please check the errors below and fix your CSV file."):a.length{x("Failed to parse CSV file: ".concat(e.message)),o([])},header:!1}):(f("Invalid file type: ".concat(e.name,". Please upload a CSV file (.csv extension).")),F.ZP.error("Invalid file type. Please upload a CSV file.")),!1),accept:".csv",maxCount:1,showUploadList:!1,children:(0,m.jsxs)("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-blue-500 transition-colors cursor-pointer",children:[(0,m.jsx)(eu.Z,{className:"text-3xl text-gray-400 mb-2"}),(0,m.jsx)("p",{className:"mb-1",children:"Drag and drop your CSV file here"}),(0,m.jsx)("p",{className:"text-sm text-gray-500 mb-3",children:"or"}),(0,m.jsx)(C.Z,{size:"sm",children:"Browse files"}),(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-4",children:"Only CSV files (.csv) are supported"})]})}),p&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(ej.Z,{className:"h-5 w-5 text-yellow-500 mr-2 mt-0.5"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(et.default.Text,{strong:!0,className:"text-yellow-800",children:"CSV Structure Error"}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-1 mb-0",children:p}),(0,m.jsx)(et.default.Paragraph,{className:"text-yellow-700 mt-2 mb-0",children:"Please download our template and ensure your CSV follows the required format."})]})]})})]})]}):(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsxs)("div",{className:"flex items-center mb-4",children:[(0,m.jsx)("div",{className:"w-8 h-8 rounded-full bg-blue-500 text-white flex items-center justify-center mr-3",children:"3"}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:n.some(e=>"success"===e.status||"failed"===e.status)?"User Creation Results":"Review and create users"})]}),h&&(0,m.jsx)("div",{className:"ml-11 mb-4 p-4 bg-red-50 border border-red-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)(em.Z,{className:"text-red-500 mr-2 mt-1"}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"text-red-600 font-medium",children:h}),n.some(e=>!e.isValid)&&(0,m.jsxs)("ul",{className:"mt-2 list-disc list-inside text-red-600 text-sm",children:[(0,m.jsx)("li",{children:"Check the table below for specific errors in each row"}),(0,m.jsx)("li",{children:"Common issues include invalid email formats, missing required fields, or incorrect role values"}),(0,m.jsx)("li",{children:"Fix these issues in your CSV file and upload again"})]})]})]})}),(0,m.jsxs)("div",{className:"ml-11",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-3",children:[(0,m.jsx)("div",{className:"flex items-center",children:n.some(e=>"success"===e.status||"failed"===e.status)?(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"Creation Summary"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-green-100 text-green-800 px-2 py-1 rounded mr-2",children:[n.filter(e=>"success"===e.status).length," Successful"]}),n.some(e=>"failed"===e.status)&&(0,m.jsxs)(P.Z,{className:"text-sm bg-red-100 text-red-800 px-2 py-1 rounded",children:[n.filter(e=>"failed"===e.status).length," Failed"]})]}):(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{className:"text-lg font-medium mr-3",children:"User Preview"}),(0,m.jsxs)(P.Z,{className:"text-sm bg-blue-100 text-blue-800 px-2 py-1 rounded",children:[n.filter(e=>e.isValid).length," of ",n.length," users valid"]})]})}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex space-x-3",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===n.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]})]}),n.some(e=>"success"===e.status)&&(0,m.jsx)("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:(0,m.jsxs)("div",{className:"flex items-start",children:[(0,m.jsx)("div",{className:"mr-3 mt-1",children:(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-blue-500"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium text-blue-800",children:"User creation complete"}),(0,m.jsxs)(P.Z,{className:"block text-sm text-blue-700 mt-1",children:[(0,m.jsx)("span",{className:"font-medium",children:"Next step:"})," Download the credentials file containing API keys and invitation links. Users will need these API keys to make LLM requests through LiteLLM."]})]})]})}),(0,m.jsx)(ei.Z,{dataSource:n,columns:[{title:"Row",dataIndex:"rowNumber",key:"rowNumber",width:80},{title:"Email",dataIndex:"user_email",key:"user_email"},{title:"Role",dataIndex:"user_role",key:"user_role"},{title:"Teams",dataIndex:"teams",key:"teams"},{title:"Budget",dataIndex:"max_budget",key:"max_budget"},{title:"Status",key:"status",render:(e,s)=>s.isValid?s.status&&"pending"!==s.status?"success"===s.status?(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}),(0,m.jsx)("span",{className:"text-green-500",children:"Success"})]}),s.invitation_link&&(0,m.jsx)("div",{className:"mt-1",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-xs text-gray-500 truncate max-w-[150px]",children:s.invitation_link}),(0,m.jsx)(L.CopyToClipboard,{text:s.invitation_link,onCopy:()=>F.ZP.success("Invitation link copied!"),children:(0,m.jsx)("button",{className:"ml-1 text-blue-500 text-xs hover:text-blue-700",children:"Copy"})})]})})]}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Failed"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:JSON.stringify(s.error)})]}):(0,m.jsx)("span",{className:"text-gray-500",children:"Pending"}):(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsx)("span",{className:"text-red-500",children:"Invalid"})]}),s.error&&(0,m.jsx)("span",{className:"text-sm text-red-500 ml-7",children:s.error})]})}],size:"small",pagination:{pageSize:5},scroll:{y:300},rowClassName:e=>e.isValid?"":"bg-red-50"}),!n.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Back"}),(0,m.jsx)(C.Z,{onClick:k,disabled:0===n.filter(e=>e.isValid).length||d,children:d?"Creating...":"Create ".concat(n.filter(e=>e.isValid).length," Users")})]}),n.some(e=>"success"===e.status||"failed"===e.status)&&(0,m.jsxs)("div",{className:"flex justify-end mt-4",children:[(0,m.jsx)(C.Z,{onClick:()=>{o([]),x(null)},variant:"secondary",className:"mr-3",children:"Start New Bulk Import"}),(0,m.jsxs)(C.Z,{onClick:()=>{let e=n.map(e=>({user_email:e.user_email,user_role:e.user_role,status:e.status,key:e.key||"",invitation_link:e.invitation_link||"",error:e.error||""})),s=new Blob([ex().unparse(e)],{type:"text/csv"}),l=window.URL.createObjectURL(s),t=document.createElement("a");t.href=l,t.download="bulk_users_results.csv",document.body.appendChild(t),t.click(),document.body.removeChild(t),window.URL.revokeObjectURL(l)},variant:"primary",className:"flex items-center",children:[(0,m.jsx)(en.Z,{className:"mr-2"})," Download User Credentials"]})]})]})]})})})]})};let{Option:e_}=D.default;var ev=e=>{let{userID:s,accessToken:l,teams:t,possibleUIRoles:a,onUserCreated:r,isEmbedded:i=!1}=e,n=(0,g.NL)(),[o,d]=(0,u.useState)(null),[c]=M.Z.useForm(),[x,p]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=(0,h.useRouter)(),[S,L]=(0,u.useState)("http://localhost:4000");(0,u.useEffect)(()=>{(async()=>{try{let e=await (0,b.So)(l,s,"any"),t=[];for(let s=0;s{k&&L(new URL("/",window.location.href).toString())},[k]);let q=async e=>{var t,a,d;try{F.ZP.info("Making API Call"),i||p(!0),e.models&&0!==e.models.length||"proxy_admin"===e.user_role||(console.log("formValues.user_role",e.user_role),e.models=["no-default-models"]),console.log("formValues in create user:",e);let a=await (0,b.Ov)(l,null,e);await n.invalidateQueries({queryKey:["userList"]}),console.log("user create Response:",a),f(!0);let d=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(r&&i){r(d),c.resetFields();return}if(null==o?void 0:o.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:d,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:s,updated_at:new Date,updated_by:s,has_user_setup_sso:!0};w(e),Z(!0)}else(0,b.XO)(l,d).then(e=>{e.has_user_setup_sso=!1,w(e),Z(!0)});F.ZP.success("API user Created"),c.resetFields(),localStorage.removeItem("userData"+s)}catch(s){let e=(null===(d=s.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.detail)||(null==s?void 0:s.message)||"Error creating the user";F.ZP.error(e),console.error("Error creating the user:",s)}};return i?(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]}):(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{className:"mx-auto mb-0",onClick:()=>p(!0),children:"+ Invite User"}),(0,m.jsx)(ef,{accessToken:l,teams:t,possibleUIRoles:a}),(0,m.jsxs)(R.Z,{title:"Invite User",visible:x,width:800,footer:null,onOk:()=>{p(!1),c.resetFields()},onCancel:()=>{p(!1),f(!1),c.resetFields()},children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,m.jsxs)(M.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"User Email",name:"user_email",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:a&&Object.entries(a).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Team ID",className:"gap-2",name:"team_id",help:"If selected, user will be added as a 'user' role to the team.",children:(0,m.jsx)(D.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,m.jsx)(e_,{value:e.team_id,children:e.team_alias},e.team_id)):(0,m.jsx)(e_,{value:null,children:"Default Team"},"default")})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{children:"Personal Key Creation"})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(M.Z.Item,{className:"gap-2",label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Models user has access to, outside of team scope.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",help:"Models user has access to, outside of team scope.",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),_.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create User"})})]})]}),j&&(0,m.jsx)(ea,{isInvitationLinkModalVisible:y,setIsInvitationLinkModalVisible:Z,baseUrl:S,invitationLinkData:N})]})},ey=l(7310),eb=l.n(ey),eZ=l(20347);let{Option:eN}=D.default,ew=e=>e?({"24h":"daily","7d":"weekly","30d":"monthly"})[e]||e:"Not set";var ek=e=>{let{value:s,onChange:l,className:t="",style:a={}}=e;return(0,m.jsxs)(D.default,{style:{width:"100%",...a},value:s||void 0,onChange:l,className:t,placeholder:"n/a",children:[(0,m.jsx)(eN,{value:"24h",children:"daily"}),(0,m.jsx)(eN,{value:"7d",children:"weekly"}),(0,m.jsx)(eN,{value:"30d",children:"monthly"})]})};let{Option:eS}=D.default,eC=e=>{let s=[];if(console.log("data:",JSON.stringify(e)),e)for(let l of e)l.metadata&&l.metadata.tags&&s.push(...l.metadata.tags);let l=Array.from(new Set(s)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",l),l},eI=async(e,s,l,t)=>{try{if(null===e||null===s)return[];if(null!==l){let a=(await (0,b.So)(l,e,s,!0,t)).data.map(e=>e.id);return console.log("available_model_names:",a),a}return[]}catch(e){return console.error("Error fetching user models:",e),[]}},eT=async(e,s,l,t)=>{try{if(null===e||null===s)return;if(null!==l){let a=(await (0,b.So)(l,e,s)).data.map(e=>e.id);console.log("available_model_names:",a),t(a)}}catch(e){console.error("Error fetching user models:",e)}};var eA=e=>{let{userID:s,team:l,teams:t,userRole:a,accessToken:r,data:i,addKey:n}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(null),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)("you"),[N,w]=(0,u.useState)(eC(i)),[V,B]=(0,u.useState)([]),[J,G]=(0,u.useState)(l),[$,X]=(0,u.useState)(!1),[Q,el]=(0,u.useState)(null),[et,ea]=(0,u.useState)({}),[er,ei]=(0,u.useState)([]),[en,eo]=(0,u.useState)(!1),ed=()=>{c(!1),o.resetFields()},ec=()=>{c(!1),x(null),G(null),o.resetFields()};(0,u.useEffect)(()=>{s&&a&&r&&eT(s,a,r,f)},[r,s,a]),(0,u.useEffect)(()=>{(async()=>{try{let e=(await (0,b.t3)(r)).guardrails.map(e=>e.guardrail_name);B(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[r]),(0,u.useEffect)(()=>{(async()=>{try{if(r){let e=sessionStorage.getItem("possibleUserRoles");if(e)ea(JSON.parse(e));else{let e=await (0,b.lg)(r);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),ea(e)}}}catch(e){console.error("Error fetching possible user roles:",e)}})()},[r]);let em=async e=>{try{var l,t,a;let d=null!==(l=null==e?void 0:e.key_alias)&&void 0!==l?l:"",m=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(a=null==i?void 0:i.filter(e=>e.team_id===m).map(e=>e.key_alias))&&void 0!==a?a:[]).includes(d))throw Error("Key alias ".concat(d," already exists for team with ID ").concat(m,", please provide another key alias"));if(F.ZP.info("Making API Call"),c(!0),"you"===y&&(e.user_id=s),"service_account"===y){let s={};try{s=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}s.service_account_id=e.key_alias,e.metadata=JSON.stringify(s)}let u=await (0,b.wX)(r,s,e);console.log("key create Response:",u),n(u),x(u.key),g(u.soft_budget),F.ZP.success("API Key Created"),o.resetFields(),localStorage.removeItem("userData"+s)}catch(e){console.log("error in create key:",e),F.ZP.error("Error creating the key: ".concat(e))}};(0,u.useEffect)(()=>{if(s&&a&&r){var e;eI(s,a,r,null!==(e=null==J?void 0:J.team_id)&&void 0!==e?e:null).then(e=>{var s;v(Array.from(new Set([...null!==(s=null==J?void 0:J.models)&&void 0!==s?s:[],...e])))})}o.setFieldValue("models",[])},[J,r,s,a]);let eu=async e=>{if(!e){ei([]);return}eo(!0);try{let s=new URLSearchParams;if(s.append("user_email",e),null==r)return;let l=(await (0,b.u5)(r,s)).map(e=>({label:"".concat(e.user_email," (").concat(e.user_id,")"),value:e.user_id,user:e}));ei(l)}catch(e){console.error("Error fetching users:",e),F.ZP.error("Failed to search for users")}finally{eo(!1)}},eh=(0,u.useCallback)(eb()(e=>eu(e),300),[r]),ex=(e,s)=>{let l=s.user;o.setFieldsValue({user_id:l.user_id})};return(0,m.jsxs)("div",{children:[a&&eZ.LQ.includes(a)&&(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Create New Key"}),(0,m.jsx)(R.Z,{visible:d,width:1e3,footer:null,onOk:ed,onCancel:ec,children:(0,m.jsxs)(M.Z,{form:o,onFinish:em,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Ownership"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Owned By"," ",(0,m.jsx)(Y.Z,{title:"Select who will own this API key",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),className:"mb-4",children:(0,m.jsxs)(q.ZP.Group,{onChange:e=>Z(e.target.value),value:y,children:[(0,m.jsx)(q.ZP,{value:"you",children:"You"}),(0,m.jsx)(q.ZP,{value:"service_account",children:"Service Account"}),"Admin"===a&&(0,m.jsx)(q.ZP,{value:"another_user",children:"Another User"})]})}),"another_user"===y&&(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["User ID"," ",(0,m.jsx)(Y.Z,{title:"The user who will own this key and be responsible for its usage",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"user_id",className:"mt-4",rules:[{required:"another_user"===y,message:"Please input the user ID of the user you are assigning the key to"}],children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",marginBottom:"8px"},children:[(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Type email to search for users",filterOption:!1,onSearch:e=>{eh(e)},onSelect:(e,s)=>ex(e,s),options:er,loading:en,allowClear:!0,style:{width:"100%"},notFoundContent:en?"Searching...":"No users found"}),(0,m.jsx)(U.ZP,{onClick:()=>X(!0),style:{marginLeft:"8px"},children:"Create User"})]}),(0,m.jsx)("div",{className:"text-xs text-gray-500",children:"Search by email to find users"})]})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Team"," ",(0,m.jsx)(Y.Z,{title:"The team this key belongs to, which determines available models and budget limits",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"team_id",initialValue:l?l.team_id:null,className:"mt-4",children:(0,m.jsx)(es,{teams:t,onChange:e=>{G((null==t?void 0:t.find(s=>s.team_id===e))||null)}})})]}),(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)(O.Z,{className:"mb-4",children:"Key Details"}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["you"===y||"another_user"===y?"Key Name":"Service Account ID"," ",(0,m.jsx)(Y.Z,{title:"you"===y||"another_user"===y?"A descriptive name to identify this key":"Unique identifier for this service account",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===y?"key name":"service account ID")}],help:"required",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this key can access. Choose 'All Team Models' to grant access to all models available to the team",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",className:"mt-4",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&o.setFieldsValue({models:["all-team-models"]})},children:[(0,m.jsx)(eS,{value:"all-team-models",children:"All Team Models"},"all-team-models"),_.map(e=>(0,m.jsx)(eS,{value:e,children:H(e)},e))]})})]}),(0,m.jsx)("div",{className:"mb-8",children:(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)(O.Z,{className:"m-0",children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Max Budget (USD)"," ",(0,m.jsx)(Y.Z,{title:"Maximum amount in USD this key can spend. When reached, the key will be blocked from making further requests",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==l?void 0:l.max_budget)!==null&&(null==l?void 0:l.max_budget)!==void 0?null==l?void 0:l.max_budget:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.max_budget&&s>l.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(l.max_budget))}}],children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Reset Budget"," ",(0,m.jsx)(Y.Z,{title:"How often the budget should reset. For example, setting 'daily' will reset the budget every 24 hours",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"budget_duration",help:"Team Reset Budget: ".concat((null==l?void 0:l.budget_duration)!==null&&(null==l?void 0:l.budget_duration)!==void 0?null==l?void 0:l.budget_duration:"None"),children:(0,m.jsx)(ek,{onChange:e=>o.setFieldValue("budget_duration",e)})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Tokens per minute Limit (TPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of tokens this key can process per minute. Helps control usage and costs",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==l?void 0:l.tpm_limit)!==null&&(null==l?void 0:l.tpm_limit)!==void 0?null==l?void 0:l.tpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.tpm_limit&&s>l.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(l.tpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{className:"mt-4",label:(0,m.jsxs)("span",{children:["Requests per minute Limit (RPM)"," ",(0,m.jsx)(Y.Z,{title:"Maximum number of API requests this key can make per minute. Helps prevent abuse and manage load",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==l?void 0:l.rpm_limit)!==null&&(null==l?void 0:l.rpm_limit)!==void 0?null==l?void 0:l.rpm_limit:"unlimited"),rules:[{validator:async(e,s)=>{if(s&&l&&null!==l.rpm_limit&&s>l.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(l.rpm_limit))}}],children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Expire Key"," ",(0,m.jsx)(Y.Z,{title:"Set when this key should expire. Format: 30s (seconds), 30m (minutes), 30h (hours), 30d (days)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"duration",className:"mt-4",children:(0,m.jsx)(I.Z,{placeholder:"e.g., 30d"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Apply safety guardrails to this key to filter content or enforce policies",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-4",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:V.map(e=>({value:e,label:e}))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON object with additional information about this key. Used for tracking or custom logic",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"metadata",className:"mt-4",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Tags"," ",(0,m.jsx)(Y.Z,{title:"Tags for tracking spend and/or doing tag-based routing. Used for analytics and filtering",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"tags",className:"mt-4",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:N})}),(0,m.jsxs)(T.Z,{className:"mt-4 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("b",{children:"Advanced Settings"}),(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Learn more about advanced settings in our"," ",(0,m.jsx)("a",{href:b.H2?"".concat(b.H2,"/#/key%20management/generate_key_fn_key_generate_post"):"/#/key%20management/generate_key_fn_key_generate_post",target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300",children:"documentation"})]}),children:(0,m.jsx)(W.Z,{className:"text-gray-400 hover:text-gray-300 cursor-help"})})]})}),(0,m.jsx)(A.Z,{children:(0,m.jsx)(ee,{schemaComponent:"GenerateKeyRequest",form:o,excludedFields:["key_alias","team_id","models","duration","metadata","tags","guardrails","max_budget","budget_duration","tpm_limit","rpm_limit"]})})]})]})]})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Key"})})]})}),$&&(0,m.jsx)(R.Z,{title:"Create New User",visible:$,onCancel:()=>X(!1),footer:null,width:800,children:(0,m.jsx)(ev,{userID:s,accessToken:r,teams:t,possibleUIRoles:et,onUserCreated:e=>{el(e),o.setFieldsValue({user_id:e}),X(!1)},isEmbedded:!0})}),h&&(0,m.jsx)(R.Z,{visible:d,onOk:ed,onCancel:ec,footer:null,children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Save your Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:null!=h?(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:h})}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>{F.ZP.success("API Key copied to clipboard")},children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,m.jsx)(P.Z,{children:"Key being created, this might take 30s"})})]})})]})},eE=l(7366),eP=e=>{let{selectedTeam:s,currentOrg:l,selectedKeyAlias:t,accessToken:a,createClicked:r}=e,[i,n]=(0,u.useState)({keys:[],total_count:0,current_page:1,total_pages:0}),[o,d]=(0,u.useState)(!0),[c,m]=(0,u.useState)(null),h=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{if(console.log("calling fetchKeys"),!a){console.log("accessToken",a);return}d(!0);let s="number"==typeof e.page?e.page:1,l="number"==typeof e.pageSize?e.pageSize:100,t=await (0,b.OD)(a,null,null,null,null,null,s,l);console.log("data",t),n(t),m(null)}catch(e){m(e instanceof Error?e:Error("An error occurred"))}finally{d(!1)}};return(0,u.useEffect)(()=>{h(),console.log("selectedTeam",s,"currentOrg",l,"accessToken",a,"selectedKeyAlias",t)},[s,l,a,t,r]),{keys:i.keys,isLoading:o,error:c,pagination:{currentPage:i.current_page,totalPages:i.total_pages,totalCount:i.total_count},refresh:h,setKeys:e=>{n(s=>{let l="function"==typeof e?e(s.keys):e;return{...s,keys:l}})}}},eO=l(27281),eL=l(41649),eD=l(12514),eM=l(12485),eF=l(18135),eR=l(35242),eq=l(29706),eU=l(77991),ez=l(10900),eV=l(23628),eK=l(74998);function eB(e){var s,l;let{keyData:t,onCancel:a,onSubmit:r,teams:i,accessToken:n,userID:o,userRole:d}=e,[c]=M.Z.useForm(),[h,x]=(0,u.useState)([]),p=null==i?void 0:i.find(e=>e.team_id===t.team_id),[g,j]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(o&&d&&n)try{if(null===t.team_id){let e=(await (0,b.So)(n,o,d)).data.map(e=>e.id);j(e)}else if(null==p?void 0:p.team_id){let e=await eI(o,d,n,p.team_id);j(Array.from(new Set([...p.models,...e])))}}catch(e){console.error("Error fetching models:",e)}})()},[o,d,n,p,t.team_id]);let f={...t,budget_duration:(l=t.budget_duration)&&({"24h":"daily","7d":"weekly","30d":"monthly"})[l]||null,metadata:t.metadata?JSON.stringify(t.metadata,null,2):"",guardrails:(null===(s=t.metadata)||void 0===s?void 0:s.guardrails)||[]};return(0,m.jsxs)(M.Z,{form:c,onFinish:r,initialValues:f,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Key Alias",name:"key_alias",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[g.length>0&&(0,m.jsx)(D.default.Option,{value:"all-team-models",children:"All Team Models"}),g.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,style:{width:"100%"},placeholder:"Enter a numerical value"})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"daily",children:"Daily"}),(0,m.jsx)(D.default.Option,{value:"weekly",children:"Weekly"}),(0,m.jsx)(D.default.Option,{value:"monthly",children:"Monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"TPM Limit",name:"tpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"RPM Limit",name:"rpm_limit",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Max Parallel Requests",name:"max_parallel_requests",children:(0,m.jsx)(K,{min:0})}),(0,m.jsx)(M.Z.Item,{label:"Model TPM Limit",name:"model_tpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Model RPM Limit",name:"model_rpm_limit",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{"gpt-4": 100, "claude-v1": 200}'})}),(0,m.jsx)(M.Z.Item,{label:"Guardrails",name:"guardrails",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsx)(M.Z.Item,{name:"token",hidden:!0,children:(0,m.jsx)(z.default,{})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(C.Z,{variant:"light",onClick:a,children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]})}function eH(e){let{selectedToken:s,visible:l,onClose:t,accessToken:a}=e,[r]=M.Z.useForm(),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!1);(0,u.useEffect)(()=>{l&&s&&r.setFieldsValue({key_alias:s.key_alias,max_budget:s.max_budget,tpm_limit:s.tpm_limit,rpm_limit:s.rpm_limit,duration:s.duration||""})},[l,s,r]),(0,u.useEffect)(()=>{l||(n(null),p(!1),r.resetFields())},[l,r]),(0,u.useEffect)(()=>{(null==o?void 0:o.duration)?h((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString()}catch(e){return null}})(o.duration)):h(null)},[null==o?void 0:o.duration]);let g=async()=>{if(s&&a){p(!0);try{let e=await r.validateFields(),l=await (0,b.s0)(a,s.token,e);n(l.key),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key"),p(!1)}}},j=()=>{n(null),p(!1),r.resetFields(),t()};return(0,m.jsx)(R.Z,{title:"Regenerate API Key",open:l,onCancel:j,footer:i?[(0,m.jsx)(C.Z,{onClick:j,children:"Close"},"close")]:[(0,m.jsx)(C.Z,{onClick:j,className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:g,disabled:x,children:x?"Regenerating...":"Regenerate"},"regenerate")],children:i?(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:(null==s?void 0:s.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{className:"bg-gray-100 p-2 rounded mb-2",children:(0,m.jsx)("pre",{className:"break-words whitespace-normal",children:i})}),(0,m.jsx)(L.CopyToClipboard,{text:i,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]}):(0,m.jsxs)(M.Z,{form:r,layout:"vertical",onValuesChange:e=>{"duration"in e&&d(s=>({...s,duration:e.duration}))},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry: ",(null==s?void 0:s.expires)?new Date(s.expires).toLocaleString():"Never"]}),c&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",c]})]})})}function eJ(e){var s,l;let{keyId:t,onClose:a,keyData:r,accessToken:i,userID:n,userRole:o,teams:d,onKeyDataUpdate:c,onDelete:h}=e,[x,p]=(0,u.useState)(!1),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1);if(!r)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(P.Z,{children:"Key not found"})]});let y=async e=>{try{var s,l;if(!i)return;let t=e.token;if(e.key=t,e.metadata&&"string"==typeof e.metadata)try{let l=JSON.parse(e.metadata);e.metadata={...l,...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}}}catch(e){console.error("Error parsing metadata JSON:",e),F.ZP.error("Invalid metadata JSON");return}else e.metadata={...e.metadata||{},...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}};e.budget_duration&&(e.budget_duration=({daily:"24h",weekly:"7d",monthly:"30d"})[e.budget_duration]);let a=await (0,b.Nc)(i,e);c&&c(a),F.ZP.success("Key updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update key"),console.error("Error updating key:",e)}},Z=async()=>{try{if(!i)return;await (0,b.I1)(i,r.token),F.ZP.success("Key deleted successfully"),h&&h(),a()}catch(e){console.error("Error deleting the key:",e),F.ZP.error("Failed to delete key")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:a,className:"mb-4",children:"Back to Keys"}),(0,m.jsx)(O.Z,{children:r.key_alias||"API Key"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:r.token})]}),o&&eZ.LQ.includes(o)&&(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{icon:eV.Z,variant:"secondary",onClick:()=>v(!0),className:"flex items-center",children:"Regenerate Key"}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>f(!0),className:"flex items-center",children:"Delete Key"})]})]}),(0,m.jsx)(eH,{selectedToken:r,visible:_,onClose:()=>v(!1),accessToken:i}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:Z,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>f(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number(r.spend).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",null!==r.max_budget?"$".concat(r.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Key Settings"}),!x&&o&&eZ.LQ.includes(o)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>p(!0),children:"Edit Settings"})]}),x?(0,m.jsx)(eB,{keyData:r,onCancel:()=>p(!1),onSubmit:y,teams:d,accessToken:i,userID:n,userRole:o}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.token})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Key Alias"}),(0,m.jsx)(P.Z,{children:r.key_alias||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Secret Key"}),(0,m.jsx)(P.Z,{className:"font-mono",children:r.key_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)(P.Z,{children:r.team_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),(0,m.jsx)(P.Z,{children:r.organization_id||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:new Date(r.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Expires"}),(0,m.jsx)(P.Z,{children:r.expires?new Date(r.expires).toLocaleString():"Never"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Spend"}),(0,m.jsxs)(P.Z,{children:["$",Number(r.spend).toFixed(4)," USD"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsx)(P.Z,{children:null!==r.max_budget?"$".concat(r.max_budget," USD"):"Unlimited"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:r.models&&r.models.length>0?r.models.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"No models specified"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)(P.Z,{children:["TPM: ",null!==r.tpm_limit?r.tpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",null!==r.rpm_limit?r.rpm_limit:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",null!==r.max_parallel_requests?r.max_parallel_requests:"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model TPM Limits: ",(null===(s=r.metadata)||void 0===s?void 0:s.model_tpm_limit)?JSON.stringify(r.metadata.model_tpm_limit):"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["Model RPM Limits: ",(null===(l=r.metadata)||void 0===l?void 0:l.model_rpm_limit)?JSON.stringify(r.metadata.model_rpm_limit):"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(r.metadata,null,2)})]})]})]})})]})]})]})}var eG=l(2356),eW=e=>{let{options:s,onApplyFilters:l,onResetFilters:t,initialValues:a={},buttonLabel:r="Filters"}=e,[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(a),[c,h]=(0,u.useState)({}),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)({}),f=(0,u.useCallback)(eb()(async(e,s)=>{if(s.isSearchable&&s.searchFn){p(e=>({...e,[s.name]:!0}));try{let l=await s.searchFn(e);h(e=>({...e,[s.name]:l}))}catch(e){console.error("Error searching:",e),h(e=>({...e,[s.name]:[]}))}finally{p(e=>({...e,[s.name]:!1}))}}},300),[]),_=(e,s)=>{let t={...o,[e]:s};d(t),l(t)};return(0,m.jsxs)("div",{className:"w-full",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-6",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eG.Z,{className:"h-4 w-4"}),onClick:()=>n(!i),className:"flex items-center gap-2",children:r}),(0,m.jsx)(U.ZP,{onClick:()=>{let e={};s.forEach(s=>{e[s.name]=""}),d(e),t()},children:"Reset Filters"})]}),i&&(0,m.jsx)("div",{className:"grid grid-cols-3 gap-x-6 gap-y-4 mb-6",children:["Team ID","Status","Organization ID","Key Alias","User ID","Key Hash"].map(e=>{let l=s.find(s=>s.label===e||s.name===e);return l?(0,m.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,m.jsx)("label",{className:"text-sm text-gray-600",children:l.label||l.name}),l.isSearchable?(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),onSearch:e=>{j(s=>({...s,[l.name]:e})),l.searchFn&&f(e,l)},filterOption:!1,loading:x[l.name],options:c[l.name]||[],allowClear:!0}):l.options?(0,m.jsx)(D.default,{className:"w-full",placeholder:"Select ".concat(l.label||l.name,"..."),value:o[l.name]||void 0,onChange:e=>_(l.name,e),allowClear:!0,children:l.options.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))}):(0,m.jsx)(z.default,{className:"w-full",placeholder:"Enter ".concat(l.label||l.name,"..."),value:o[l.name]||"",onChange:e=>_(l.name,e.target.value),allowClear:!0})]},l.name):null})})]})},eY=l(16593);let e$=async e=>{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.OD)(e,null,"",null,null,null,l,100),r=a.keys.map(e=>e.key_alias).filter(Boolean);s=[...s,...r],l{if(!e)return[];try{let l=[],t=1,a=!0;for(;a;){let r=await (0,b.It)(e,s||null,null);l=[...l,...r],t{if(!e)return[];try{let s=[],l=1,t=!0;for(;t;){let a=await (0,b.r6)(e);s=[...s,...a],l{let[e,s]=(0,u.useState)("http://localhost:4000");return(0,u.useEffect)(()=>{{let{protocol:e,host:l}=window.location;s("".concat(e,"//").concat(l))}},[]),e};function e1(e,s){let l=structuredClone(e);for(let[e,t]of Object.entries(s))e in l&&(l[e]=t);return l}var e2=l(71594),e4=l(24525),e5=l(21626),e3=l(97214),e6=l(28241),e8=l(58834),e7=l(69552),e9=l(71876),se=l(44633),ss=l(86462),sl=l(49084);function st(e){let{keys:s,setKeys:l,isLoading:t=!1,pagination:a,onPageChange:r,pageSize:i=50,teams:n,selectedTeam:o,setSelectedTeam:d,selectedKeyAlias:c,setSelectedKeyAlias:h,accessToken:x,userID:p,userRole:g,organizations:j,setCurrentOrg:f,refresh:_,onSortChange:v,currentSort:y}=e,[Z,N]=(0,u.useState)(null),[w,k]=(0,u.useState)([]),[S,I]=u.useState(()=>y?[{id:y.sortBy,desc:"desc"===y.sortOrder}]:[{id:"created_at",desc:!0}]),{filters:T,filteredKeys:A,allKeyAliases:E,allTeams:P,allOrganizations:O,handleFilterChange:L,handleFilterReset:D}=function(e){let{keys:s,teams:l,organizations:t,accessToken:a}=e,r={"Team ID":"","Organization ID":"","Key Alias":"","User ID":"","Sort By":"created_at","Sort Order":"desc"},[i,n]=(0,u.useState)(r),[o,d]=(0,u.useState)(l||[]),[c,m]=(0,u.useState)(t||[]),[h,x]=(0,u.useState)(s),p=(0,u.useRef)(0),g=(0,u.useCallback)(eb()(async e=>{if(!a)return;let s=Date.now();p.current=s;try{let l=await (0,b.OD)(a,e["Organization ID"]||null,e["Team ID"]||null,e["Key Alias"]||null,e["User ID"]||null,e["Key Hash"]||null,1,25,e["Sort By"]||null,e["Sort Order"]||null);s===p.current&&l&&(x(l.keys),console.log("called from debouncedSearch filters:",JSON.stringify(e)),console.log("called from debouncedSearch data:",JSON.stringify(l)))}catch(e){console.error("Error searching users:",e)}},300),[a]);(0,u.useEffect)(()=>{if(!s){x([]);return}let e=[...s];i["Team ID"]&&(e=e.filter(e=>e.team_id===i["Team ID"])),i["Organization ID"]&&(e=e.filter(e=>e.organization_id===i["Organization ID"])),x(e)},[s,i]),(0,u.useEffect)(()=>{let e=async()=>{let e=await eX(a);e.length>0&&d(e);let s=await eQ(a);s.length>0&&m(s)};a&&e()},[a]);let j=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!a)throw Error("Access token required");return await e$(a)},enabled:!!a}).data||[];return(0,u.useEffect)(()=>{l&&l.length>0&&d(e=>e.length{t&&t.length>0&&m(e=>e.length{n({"Team ID":e["Team ID"]||"","Organization ID":e["Organization ID"]||"","Key Alias":e["Key Alias"]||"","User ID":e["User ID"]||"","Sort By":e["Sort By"]||"created_at","Sort Order":e["Sort Order"]||"desc"}),g({...i,...e})},handleFilterReset:()=>{n(r),g(r)}}}({keys:s,teams:n,organizations:j,accessToken:x});(0,u.useEffect)(()=>{if(x){let e=s.map(e=>e.user_id).filter(e=>null!==e);(async()=>{k((await (0,b.Of)(x,e,1,100)).users)})()}},[x,s]),(0,u.useEffect)(()=>{if(_){let e=()=>{_()};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e)}}},[_]);let M=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return s.getCanExpand()?(0,m.jsx)("button",{onClick:s.getToggleExpandedHandler(),style:{cursor:"pointer"},children:s.getIsExpanded()?"▼":"▶"}):null}},{id:"token",accessorKey:"token",header:"Key ID",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>N(e.getValue()),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{id:"key_alias",accessorKey:"key_alias",header:"Key Alias",cell:e=>{let s=e.getValue();return(0,m.jsx)(Y.Z,{title:s,children:s?s.length>20?"".concat(s.slice(0,20),"..."):s:"-"})}},{id:"key_name",accessorKey:"key_name",header:"Secret Key",cell:e=>(0,m.jsx)("span",{className:"font-mono text-xs",children:e.getValue()})},{id:"team_alias",accessorKey:"team_id",header:"Team Alias",cell:e=>{let{row:s,getValue:l}=e,t=l(),a=null==n?void 0:n.find(e=>e.team_id===t);return(null==a?void 0:a.team_alias)||"Unknown"}},{id:"team_id",accessorKey:"team_id",header:"Team ID",cell:e=>(0,m.jsx)(Y.Z,{title:e.getValue(),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})},{id:"organization_id",accessorKey:"organization_id",header:"Organization ID",cell:e=>e.getValue()?e.renderValue():"-"},{id:"user_email",accessorKey:"user_id",header:"User Email",cell:e=>{let s=e.getValue(),l=w.find(e=>e.user_id===s);return(null==l?void 0:l.user_email)?l.user_email:"-"}},{id:"user_id",accessorKey:"user_id",header:"User ID",cell:e=>{let s=e.getValue();return s?(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsxs)("span",{children:[s.slice(0,7),"..."]})}):"-"}},{id:"created_at",accessorKey:"created_at",header:"Created At",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"-"}},{id:"created_by",accessorKey:"created_by",header:"Created By",cell:e=>e.getValue()||"Unknown"},{id:"expires",accessorKey:"expires",header:"Expires",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleDateString():"Never"}},{id:"spend",accessorKey:"spend",header:"Spend (USD)",cell:e=>Number(e.getValue()).toFixed(4)},{id:"max_budget",accessorKey:"max_budget",header:"Budget (USD)",cell:e=>null!==e.getValue()&&void 0!==e.getValue()?e.getValue():"Unlimited"},{id:"budget_reset_at",accessorKey:"budget_reset_at",header:"Budget Reset",cell:e=>{let s=e.getValue();return s?new Date(s).toLocaleString():"Never"}},{id:"models",accessorKey:"models",header:"Models",cell:e=>{let s=e.getValue();return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:s&&s.length>0?s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):"-"})}},{id:"rate_limits",header:"Rate Limits",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:["TPM: ",null!==l.tpm_limit?l.tpm_limit:"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",null!==l.rpm_limit?l.rpm_limit:"Unlimited"]})]})}}];console.log("keys: ".concat(JSON.stringify(s)));let F=(0,e2.b7)({data:A,columns:M.filter(e=>"expander"!==e.id),state:{sorting:S},onSortingChange:e=>{let s="function"==typeof e?e(S):e;if(console.log("newSorting: ".concat(JSON.stringify(s))),I(s),s&&s.length>0){let e=s[0],l=e.id,t=e.desc?"desc":"asc";console.log("sortBy: ".concat(l,", sortOrder: ").concat(t)),L({...T,"Sort By":l,"Sort Order":t}),null==v||v(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,manualSorting:!1});return u.useEffect(()=>{y&&I([{id:y.sortBy,desc:"desc"===y.sortOrder}])},[y]),(0,m.jsx)("div",{className:"w-full h-full overflow-hidden",children:Z?(0,m.jsx)(eJ,{keyId:Z,onClose:()=>N(null),keyData:A.find(e=>e.token===Z),onKeyDataUpdate:e=>{l(s=>s.map(s=>s.token===e.token?e1(s,e):s))},onDelete:()=>{l(e=>e.filter(e=>e.token!==Z))},accessToken:x,userID:p,userRole:g,teams:P}):(0,m.jsxs)("div",{className:"border-b py-4 flex-1 overflow-hidden",children:[(0,m.jsx)("div",{className:"w-full mb-6",children:(0,m.jsx)(eW,{options:[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>P&&0!==P.length?P.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Organization ID",label:"Organization ID",isSearchable:!0,searchFn:async e=>O&&0!==O.length?O.filter(s=>{var l,t;return null!==(t=null===(l=s.organization_id)||void 0===l?void 0:l.toLowerCase().includes(e.toLowerCase()))&&void 0!==t&&t}).filter(e=>null!==e.organization_id&&void 0!==e.organization_id).map(e=>({label:"".concat(e.organization_id||"Unknown"," (").concat(e.organization_id,")"),value:e.organization_id})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>E.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e}))},{name:"User ID",label:"User ID",isSearchable:!1},{name:"Key Hash",label:"Key Hash",isSearchable:!1}],onApplyFilters:L,initialValues:T,onResetFilters:D})}),(0,m.jsxs)("div",{className:"flex items-center justify-between w-full mb-4",children:[(0,m.jsxs)("span",{className:"inline-flex text-sm text-gray-700",children:["Showing ",t?"...":"".concat((a.currentPage-1)*i+1," - ").concat(Math.min(a.currentPage*i,a.totalCount))," of ",t?"...":a.totalCount," results"]}),(0,m.jsxs)("div",{className:"inline-flex items-center gap-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",t?"...":a.currentPage," of ",t?"...":a.totalPages]}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage-1),disabled:t||1===a.currentPage,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>r(a.currentPage+1),disabled:t||a.currentPage===a.totalPages,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]}),(0,m.jsx)("div",{className:"h-[75vh] overflow-auto",children:(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:F.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading keys..."})})})}):A.length>0?F.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:M.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No keys found"})})})})})]})})})})]})})}console.log=function(){};var sa=e=>{let{userID:s,userRole:l,accessToken:t,selectedTeam:a,setSelectedTeam:r,data:i,setData:n,teams:o,premiumUser:d,currentOrg:c,organizations:h,setCurrentOrg:x,selectedKeyAlias:p,setSelectedKeyAlias:g,createClicked:j}=e,[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(null),[w,T]=(0,u.useState)(null),[A,E]=(0,u.useState)(null),[D,q]=(0,u.useState)((null==a?void 0:a.team_id)||"");(0,u.useEffect)(()=>{q((null==a?void 0:a.team_id)||"")},[a]);let{keys:U,isLoading:z,error:V,pagination:K,refresh:H,setKeys:J}=eP({selectedTeam:a,currentOrg:c,selectedKeyAlias:p,accessToken:t,createClicked:j}),[W,Y]=(0,u.useState)(!1),[$,X]=(0,u.useState)(!1),[Q,ee]=(0,u.useState)(null),[es,el]=(0,u.useState)([]),et=new Set,[ea,er]=(0,u.useState)(!1),[ei,en]=(0,u.useState)(!1),[eo,ed]=(0,u.useState)(null),[ec,em]=(0,u.useState)(null),[eu]=M.Z.useForm(),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)(et),[ej,ef]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",Q),(null==ec?void 0:ec.duration)?ex((e=>{if(!e)return null;try{let s;let l=new Date;if(e.endsWith("s"))s=(0,eE.Z)(l,{seconds:parseInt(e)});else if(e.endsWith("h"))s=(0,eE.Z)(l,{hours:parseInt(e)});else if(e.endsWith("d"))s=(0,eE.Z)(l,{days:parseInt(e)});else throw Error("Invalid duration format");return s.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(ec.duration)):ex(null),console.log("calculateNewExpiryTime:",eh)},[Q,null==ec?void 0:ec.duration]),(0,u.useEffect)(()=>{(async()=>{try{if(null===s||null===l||null===t)return;let e=await B(s,l,t);e&&el(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,s,l]),(0,u.useEffect)(()=>{if(o){let e=new Set;o.forEach((s,l)=>{let t=s.team_id;e.add(t)}),eg(e)}},[o]);let e_=async()=>{if(null!=Z&&null!=i){try{await (0,b.I1)(t,Z);let e=i.filter(e=>e.token!==Z);n(e)}catch(e){console.error("Error deleting the key:",e)}y(!1),N(null)}},ev=(e,s)=>{em(l=>({...l,[e]:s}))},ey=async()=>{if(!d){F.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=Q)try{let e=await eu.validateFields(),s=await (0,b.s0)(t,Q.token,e);if(ed(s.key),i){let l=i.map(l=>l.token===(null==Q?void 0:Q.token)?{...l,key_name:s.key_name,...e}:l);n(l)}en(!1),eu.resetFields(),F.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),F.ZP.error("Failed to regenerate API Key")}};return(0,m.jsxs)("div",{children:[(0,m.jsx)(st,{keys:U,setKeys:J,isLoading:z,pagination:K,onPageChange:e=>{H({page:e})},pageSize:100,teams:o,selectedTeam:a,setSelectedTeam:r,accessToken:t,userID:s,userRole:l,organizations:h,setCurrentOrg:x,refresh:H,selectedKeyAlias:p,setSelectedKeyAlias:g}),v&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{y(!1),N(null)},children:"Cancel"})]})]})]})}),(0,m.jsx)(R.Z,{title:"Regenerate API Key",visible:ei,onCancel:()=>{en(!1),eu.resetFields()},footer:[(0,m.jsx)(C.Z,{onClick:()=>{en(!1),eu.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,m.jsx)(C.Z,{onClick:ey,disabled:!d,children:d?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:d?(0,m.jsxs)(M.Z,{form:eu,layout:"vertical",onValuesChange:(e,s)=>{"duration"in e&&ev("duration",e.duration)},children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,m.jsx)(G.Z,{style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==Q?void 0:Q.expires)!=null?new Date(Q.expires).toLocaleString():"Never"]}),eh&&(0,m.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",eh]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),eo&&(0,m.jsx)(R.Z,{visible:!!eo,onCancel:()=>ed(null),footer:[(0,m.jsx)(C.Z,{onClick:()=>ed(null),children:"Close"},"close")],children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full",children:[(0,m.jsx)(O.Z,{children:"Regenerated Key"}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,m.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(P.Z,{className:"mt-3",children:"Key Alias:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==Q?void 0:Q.key_alias)||"No alias set"})}),(0,m.jsx)(P.Z,{className:"mt-3",children:"New API Key:"}),(0,m.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,m.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:eo})}),(0,m.jsx)(L.CopyToClipboard,{text:eo,onCopy:()=>F.ZP.success("API Key copied to clipboard"),children:(0,m.jsx)(C.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})},sr=l(12011);console.log=function(){},console.log("isLocal:",!1);var si=e=>{let{userID:s,userRole:l,teams:t,keys:a,setUserRole:r,userEmail:i,setUserEmail:n,setTeams:o,setKeys:d,premiumUser:c,organizations:p,addKey:g,createClicked:j}=e,[f,_]=(0,u.useState)(null),[v,Z]=(0,u.useState)(null),N=(0,h.useSearchParams)(),C=function(e){console.log("COOKIES",document.cookie);let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token"),I=N.get("invitation_id"),[T,A]=(0,u.useState)(null),[E,P]=(0,u.useState)(null),[O,L]=(0,u.useState)([]),[D,M]=(0,u.useState)(null),[F,R]=(0,u.useState)(null),[q,U]=(0,u.useState)(null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,u.useEffect)(()=>{if(C){let e=(0,x.o)(C);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),A(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";case"internal_user":return"Internal User";case"internal_user_viewer":return"Internal Viewer";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),r(s)}else console.log("User role not defined");e.user_email?n(e.user_email):console.log("User Email is not set ".concat(e))}}if(s&&T&&l&&!a&&!f){let e=sessionStorage.getItem("userModels"+s);e?L(JSON.parse(e)):(console.log("currentOrg: ".concat(JSON.stringify(v))),(async()=>{try{let e=await (0,b.g)(T);M(e);let t=await (0,b.Br)(T,s,l,!1,null,null);_(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(f))),(null==t?void 0:t.teams[0].keys)?d(t.keys.concat(t.teams.filter(e=>"Admin"===l||e.user_id===s).flatMap(e=>e.keys))):d(t.keys),sessionStorage.setItem("userData"+s,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+s,JSON.stringify(t.user_info));let a=(await (0,b.So)(T,s,l)).data.map(e=>e.id);console.log("available_model_names:",a),L(a),console.log("userModels:",O),sessionStorage.setItem("userModels"+s,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e),e.message.includes("Invalid proxy server token passed")&&z()}})(),w(T,s,l,v,o))}},[s,C,T,a,l]),(0,u.useEffect)(()=>{T&&(async()=>{try{let e=await (0,b.e2)(T,[T]);console.log("keyInfo: ",e)}catch(e){e.message.includes("Invalid proxy server token passed")&&z()}})()},[T]),(0,u.useEffect)(()=>{console.log("currentOrg: ".concat(JSON.stringify(v),", accessToken: ").concat(T,", userID: ").concat(s,", userRole: ").concat(l)),T&&(console.log("fetching teams"),w(T,s,l,v,o))},[v]),(0,u.useEffect)(()=>{if(null!==a&&null!=F&&null!==F.team_id){let e=0;for(let s of(console.log("keys: ".concat(JSON.stringify(a))),a))F.hasOwnProperty("team_id")&&null!==s.team_id&&s.team_id===F.team_id&&(e+=s.spend);console.log("sum: ".concat(e)),P(e)}else if(null!==a){let e=0;for(let s of a)e+=s.spend;P(e)}},[F]),null!=I)return(0,m.jsx)(sr.default,{});function z(){(0,y.b)();let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==C)return console.log("All cookies before redirect:",document.cookie),z(),null;try{let e=(0,x.o)(C);console.log("Decoded token:",e);let s=e.exp,l=Math.floor(Date.now()/1e3);if(s&&l>=s){console.log("Token expired, redirecting to login"),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL for expired token:",e),window.location.href=e,null}}catch(s){console.error("Error decoding token:",s),(0,y.b)();let e="/sso/key/generate";return console.log("Full URL after token decode error:",e),window.location.href=e,null}if(null==T)return null;if(null==s)return(0,m.jsx)("h1",{children:"User ID is not set"});if(null==l&&r("App Owner"),l&&"Admin Viewer"==l){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",F),console.log("All cookies after redirect:",document.cookie),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(k.Z,{numColSpan:1,className:"flex flex-col gap-2",children:[(0,m.jsx)(eA,{userID:s,team:F,teams:t,userRole:l,accessToken:T,data:a,addKey:g},F?F.team_id:null),(0,m.jsx)(sa,{userID:s,userRole:l,accessToken:T,selectedTeam:F||null,setSelectedTeam:R,selectedKeyAlias:q,setSelectedKeyAlias:U,data:a,setData:d,premiumUser:c,teams:t,currentOrg:v,setCurrentOrg:Z,organizations:p,createClicked:j})]})})})},sn=l(97765);(t=n||(n={})).OpenAI="OpenAI",t.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.OpenAI_Text="OpenAI Text Completion",t.OpenAI_Text_Compatible="OpenAI-Compatible Text Completion Models (Together AI, etc.)",t.Azure="Azure",t.Azure_AI_Studio="Azure AI Foundry (Studio)",t.Anthropic="Anthropic",t.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)",t.Google_AI_Studio="Google AI Studio",t.Bedrock="Amazon Bedrock",t.Groq="Groq",t.MistralAI="Mistral AI",t.Deepseek="Deepseek",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI",t.AssemblyAI="AssemblyAI",t.Cerebras="Cerebras",t.Sambanova="Sambanova",t.Perplexity="Perplexity",t.TogetherAI="TogetherAI",t.Openrouter="Openrouter",t.FireworksAI="Fireworks AI",t.Triton="Triton";let so={OpenAI:"openai",OpenAI_Text:"text-completion-openai",Azure:"azure",Azure_AI_Studio:"azure_ai",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",Groq:"groq",MistralAI:"mistral",Cohere:"cohere_chat",OpenAI_Compatible:"openai",OpenAI_Text_Compatible:"text-completion-openai",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama",AssemblyAI:"assemblyai",Cerebras:"cerebras",Sambanova:"sambanova",Perplexity:"perplexity",TogetherAI:"together_ai",Openrouter:"openrouter",FireworksAI:"fireworks_ai",Triton:"triton"},sd="/ui/assets/logos/",sc={Anthropic:"".concat(sd,"anthropic.svg"),AssemblyAI:"".concat(sd,"assemblyai_small.png"),Azure:"".concat(sd,"microsoft_azure.svg"),"Azure AI Foundry (Studio)":"".concat(sd,"microsoft_azure.svg"),"Amazon Bedrock":"".concat(sd,"bedrock.svg"),Cerebras:"".concat(sd,"cerebras.svg"),Cohere:"".concat(sd,"cohere.svg"),Databricks:"".concat(sd,"databricks.svg"),Deepseek:"".concat(sd,"deepseek.svg"),"Fireworks AI":"".concat(sd,"fireworks.svg"),Groq:"".concat(sd,"groq.svg"),"Google AI Studio":"".concat(sd,"google.svg"),"Mistral AI":"".concat(sd,"mistral.svg"),Ollama:"".concat(sd,"ollama.svg"),OpenAI:"".concat(sd,"openai_small.svg"),"OpenAI Text Completion":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Text Completion Models (Together AI, etc.)":"".concat(sd,"openai_small.svg"),"OpenAI-Compatible Endpoints (Together AI, etc.)":"".concat(sd,"openai_small.svg"),Openrouter:"".concat(sd,"openrouter.svg"),Perplexity:"".concat(sd,"perplexity-ai.svg"),Sambanova:"".concat(sd,"sambanova.svg"),TogetherAI:"".concat(sd,"togetherai.svg"),"Vertex AI (Anthropic, Gemini, etc.)":"".concat(sd,"google.svg"),xAI:"".concat(sd,"xai.svg"),Triton:"".concat(sd,"nvidia_triton.png")},sm=e=>{if(!e)return{logo:"",displayName:"-"};if("gemini"===e.toLowerCase()){let e="Google AI Studio";return{logo:sc[e],displayName:e}}let s=Object.keys(so).find(s=>so[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=n[s];return{logo:sc[l],displayName:l}},su=e=>"Vertex AI (Anthropic, Gemini, etc.)"===e?"gemini-pro":"Anthropic"==e||"Amazon Bedrock"==e?"claude-3-opus":"Google AI Studio"==e?"gemini-pro":"Azure AI Foundry (Studio)"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",sh=(e,s)=>{console.log("Provider key: ".concat(e));let l=so[e];console.log("Provider mapped to: ".concat(l));let t=[];return e&&"object"==typeof s&&(Object.entries(s).forEach(e=>{let[s,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===l||a.litellm_provider.includes(l))&&t.push(s)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(s).forEach(e=>{let[s,l]=e;null!==l&&"object"==typeof l&&"litellm_provider"in l&&"cohere"===l.litellm_provider&&t.push(s)}))),t},sx=async(e,s,l)=>{try{console.log("handling submit for formValues:",e);let s=e.model_mappings||[];if("model_mappings"in e&&delete e.model_mappings,e.model&&e.model.includes("all-wildcard")){let l=so[e.custom_llm_provider]+"/*";e.model_name=l,s.push({public_name:l,litellm_model:l}),e.model=l}let l=[];for(let t of s){let s={},a={},r=t.public_name;for(let[l,r]of(s.model=t.litellm_model,e.input_cost_per_token&&(e.input_cost_per_token=Number(e.input_cost_per_token)/1e6),e.output_cost_per_token&&(e.output_cost_per_token=Number(e.output_cost_per_token)/1e6),s.model=t.litellm_model,console.log("formValues add deployment:",e),Object.entries(e)))if(""!==r&&"custom_pricing"!==l&&"pricing_model"!==l&&"cache_control"!==l){if("model_name"==l)s.model=r;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",r);let e=so[r];s.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=r;else if("team_id"===l)a.team_id=r;else if("mode"==l)console.log("placing mode in modelInfo"),a.mode=r,delete s.mode;else if("custom_model_name"===l)s.model=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else if("model_info_params"==l){console.log("model_info_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw F.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[s,l]of Object.entries(e))a[s]=l}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){r&&(s[l]=Number(r));continue}else s[l]=r}l.push({litellmParamsObj:s,modelInfoObj:a,modelName:r})}return l}catch(e){F.ZP.error("Failed to create model: "+e,10)}},sp=async(e,s,l,t)=>{try{let a=await sx(e,s,l);if(!a||0===a.length)return;for(let e of a){let{litellmParamsObj:l,modelInfoObj:t,modelName:a}=e,r={model_name:a,litellm_params:l,model_info:t},i=await (0,b.kK)(s,r);console.log("response for model create call: ".concat(i.data))}t&&t(),l.resetFields()}catch(e){F.ZP.error("Failed to add model: "+e,10)}};var sg=l(53410),sj=l(47451),sf=l(69410);let{Link:s_}=et.default,sv={[n.OpenAI]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.OpenAI_Text]:[{key:"api_base",label:"API Base",type:"select",options:["https://api.openai.com/v1","https://eu.api.openai.com"],defaultValue:"https://api.openai.com/v1"},{key:"organization",label:"OpenAI Organization ID",placeholder:"[OPTIONAL] my-unique-org"},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.Vertex_AI]:[{key:"vertex_project",label:"Vertex Project",placeholder:"adroit-cadet-1234..",required:!0},{key:"vertex_location",label:"Vertex Location",placeholder:"us-east-1",required:!0},{key:"vertex_credentials",label:"Vertex Credentials",required:!0,type:"upload"}],[n.AssemblyAI]:[{key:"api_base",label:"API Base",type:"select",required:!0,options:["https://api.assemblyai.com","https://api.eu.assemblyai.com"]},{key:"api_key",label:"AssemblyAI API Key",type:"password",required:!0}],[n.Azure]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_version",label:"API Version",placeholder:"2023-07-01-preview",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here"},{key:"base_model",label:"Base Model",placeholder:"azure/gpt-3.5-turbo"},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[n.Azure_AI_Studio]:[{key:"api_base",label:"API Base",placeholder:"https://.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",tooltip:"Enter your full Target URI from Azure Foundry here. Example: https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",required:!0},{key:"api_key",label:"Azure API Key",type:"password",required:!0}],[n.OpenAI_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.OpenAI_Text_Compatible]:[{key:"api_base",label:"API Base",placeholder:"https://...",required:!0},{key:"api_key",label:"OpenAI API Key",type:"password",required:!0}],[n.Bedrock]:[{key:"aws_access_key_id",label:"AWS Access Key ID",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_secret_access_key",label:"AWS Secret Access Key",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."},{key:"aws_region_name",label:"AWS Region Name",placeholder:"us-east-1",required:!0,tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`)."}],[n.Ollama]:[{key:"api_base",label:"API Base",placeholder:"http://localhost:11434",defaultValue:"http://localhost:11434",required:!1,tooltip:"The base URL for your Ollama server. Defaults to http://localhost:11434 if not specified."}],[n.Anthropic]:[{key:"api_key",label:"API Key",placeholder:"sk-",type:"password",required:!0}],[n.Google_AI_Studio]:[{key:"api_key",label:"API Key",placeholder:"aig-",type:"password",required:!0}],[n.Groq]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.MistralAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Deepseek]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Cohere]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Databricks]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.xAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Cerebras]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Sambanova]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Perplexity]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.TogetherAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Openrouter]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.FireworksAI]:[{key:"api_key",label:"API Key",type:"password",required:!0}],[n.Triton]:[{key:"api_key",label:"API Key",type:"password",required:!1},{key:"api_base",label:"API Base",placeholder:"http://localhost:8000/generate",required:!1}]};var sy=e=>{let{selectedProvider:s,uploadProps:l}=e,t=n[s],a=M.Z.useFormInstance(),r=u.useMemo(()=>sv[t]||[],[t]),i={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Setting field value from JSON, length: ".concat(s.length)),a.setFieldsValue({vertex_credentials:s}),console.log("Form values after setting:",a.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered in ProviderSpecificFields"),console.log("Current form values:",a.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList)}};return(0,m.jsx)(m.Fragment,{children:r.map(e=>{var s;return(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:e.label,name:e.key,rules:e.required?[{required:!0,message:"Required"}]:void 0,tooltip:e.tooltip,className:"vertex_credentials"===e.key?"mb-0":void 0,children:"select"===e.type?(0,m.jsx)(D.default,{placeholder:e.placeholder,defaultValue:e.defaultValue,children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"upload"===e.type?(0,m.jsx)(er.Z,{...i,onChange:s=>{(null==l?void 0:l.onChange)&&l.onChange(s),setTimeout(()=>{let s=a.getFieldValue(e.key);console.log("".concat(e.key," value after upload:"),JSON.stringify(s))},500)},children:(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(eu.Z,{}),children:"Click to Upload"})}):(0,m.jsx)(I.Z,{placeholder:e.placeholder,type:"password"===e.type?"password":"text"})}),"vertex_credentials"===e.key&&(0,m.jsx)(sj.Z,{children:(0,m.jsx)(sf.Z,{children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Give a gcp service account(.json file)"})})}),"base_model"===e.key&&(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,m.jsx)(s_,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]},e.key)})})};let{Title:sb,Link:sZ}=et.default;var sN=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,onUpdateCredential:a,uploadProps:r,addOrEdit:i,existingCredential:o}=e,[d]=M.Z.useForm(),[c,h]=(0,u.useState)(n.OpenAI),[x,p]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{o&&(d.setFieldsValue({credential_name:o.credential_name,custom_llm_provider:o.credential_info.custom_llm_provider,api_base:o.credential_values.api_base,api_version:o.credential_values.api_version,base_model:o.credential_values.base_model,api_key:o.credential_values.api_key}),h(o.credential_info.custom_llm_provider))},[o]),(0,m.jsx)(R.Z,{title:"add"===i?"Add New Credential":"Edit Credential",visible:s,onCancel:()=>{l(),d.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:d,onFinish:e=>{"add"===i?t(e):a(e),d.resetFields()},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==o?void 0:o.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials",disabled:null!=o&&!!o.credential_name})}),(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"Helper to auto-populate provider specific fields",children:(0,m.jsx)(D.default,{onChange:e=>{h(e),d.setFieldValue("custom_llm_provider",e)},children:Object.entries(n).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(sy,{selectedProvider:c,uploadProps:r}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sZ,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),d.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"add"===i?"Add Credential":"Update Credential"})]})]})]})})},sw=e=>{let{accessToken:s,uploadProps:l,credentialList:t,fetchCredentials:a}=e,[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(null),[h]=M.Z.useForm(),x=["credential_name","custom_llm_provider"],p=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.eZ)(s,e.credential_name,t),F.ZP.success("Credential updated successfully"),o(!1),a(s)},g=async e=>{if(!s)return;let l=Object.entries(e).filter(e=>{let[s]=e;return!x.includes(s)}).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:t}},{}),t={credential_name:e.credential_name,credential_values:l,credential_info:{custom_llm_provider:e.custom_llm_provider}};await (0,b.oC)(s,t),F.ZP.success("Credential added successfully"),i(!1),a(s)};(0,u.useEffect)(()=>{s&&a(s)},[s]);let j=e=>{let s={openai:"blue",azure:"indigo",anthropic:"purple",default:"gray"},l=s[e.toLowerCase()]||s.default;return(0,m.jsx)(eL.Z,{color:l,size:"xs",children:e})},f=async e=>{s&&(await (0,b.gX)(s,e),F.ZP.success("Credential deleted successfully"),a(s))};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)(P.Z,{children:["Configured credentials for different AI providers. Add and manage your API credentials."," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/credentials",target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700 underline",children:"Docs"})]})}),(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Credential Name"}),(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Description"})]})}),(0,m.jsx)(e3.Z,{children:t&&0!==t.length?t.map((e,s)=>{var l,t;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.credential_name}),(0,m.jsx)(e6.Z,{children:j((null===(l=e.credential_info)||void 0===l?void 0:l.custom_llm_provider)||"-")}),(0,m.jsx)(e6.Z,{children:(null===(t=e.credential_info)||void 0===t?void 0:t.description)||"-"}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{icon:sg.Z,variant:"light",size:"sm",onClick:()=>{c(e),o(!0)}}),(0,m.jsx)(C.Z,{icon:eK.Z,variant:"light",size:"sm",onClick:()=>f(e.credential_name)})]})]},s)}):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:4,className:"text-center py-4 text-gray-500",children:"No credentials configured"})})})]})}),(0,m.jsx)(C.Z,{onClick:()=>i(!0),className:"mt-4",children:"Add Credential"}),r&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:r,onCancel:()=>i(!1),uploadProps:l,addOrEdit:"add",onUpdateCredential:p,existingCredential:null}),n&&(0,m.jsx)(sN,{onAddCredential:g,isVisible:n,existingCredential:d,onUpdateCredential:p,uploadProps:l,onCancel:()=>o(!1),addOrEdit:"edit"})]})};let sk=e=>{var s;return(null==e?void 0:null===(s=e.model_info)||void 0===s?void 0:s.team_public_model_name)?e.model_info.team_public_model_name:(null==e?void 0:e.model_name)||"-"};var sS=l(53003),sC=l(47323),sI=l(75105),sT=l(40278),sA=l(14301),sE=l(59664),sP=e=>{let{modelMetrics:s,modelMetricsCategories:l,customTooltip:t,premiumUser:a}=e;return(0,m.jsx)(sE.Z,{title:"Time to First token (s)",className:"h-72",data:s,index:"date",showLegend:!1,categories:l,colors:["indigo","rose"],connectNulls:!0,customTooltip:t})},sO=e=>{let{teamData:s,canEditTeam:l,handleMemberDelete:t,setSelectedEditMember:a,setIsEditMemberModalVisible:r,setIsAddMemberModalVisible:i}=e;return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"User Email"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:s.team_info.members_with_roles.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_email})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.role})}),(0,m.jsx)(e6.Z,{children:l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{a(e),r(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(e)})]})})]},s))})]})}),(0,m.jsx)(C.Z,{onClick:()=>i(!0),children:"Add Member"})]})},sL=l(61994),sD=l(85180),sM=l(89245),sF=l(78355);let sR={"/key/generate":"Member can generate a virtual key for this team","/key/update":"Member can update a virtual key belonging to this team","/key/delete":"Member can delete a virtual key belonging to this team","/key/info":"Member can get info about a virtual key belonging to this team","/key/regenerate":"Member can regenerate a virtual key belonging to this team","/key/{key_id}/regenerate":"Member can regenerate a virtual key belonging to this team","/key/list":"Member can list virtual keys belonging to this team","/key/block":"Member can block a virtual key belonging to this team","/key/unblock":"Member can unblock a virtual key belonging to this team"},sq=e=>e.includes("/info")||e.includes("/list")?"GET":"POST",sU=e=>{let s=sq(e),l=sR[e];if(!l){for(let[s,t]of Object.entries(sR))if(e.includes(s)){l=t;break}}return l||(l="Access ".concat(e)),{method:s,endpoint:e,description:l,route:e}};var sz=e=>{let{teamId:s,accessToken:l,canEditTeam:t}=e,[a,r]=(0,u.useState)([]),[i,n]=(0,u.useState)([]),[o,d]=(0,u.useState)(!0),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),g=async()=>{try{if(d(!0),!l)return;let e=await (0,b.aC)(l,s),t=e.all_available_permissions||[];r(t);let a=e.team_member_permissions||[];n(a),p(!1)}catch(e){F.ZP.error("Failed to load permissions"),console.error("Error fetching permissions:",e)}finally{d(!1)}};(0,u.useEffect)(()=>{g()},[s,l]);let j=(e,s)=>{n(s?[...i,e]:i.filter(s=>s!==e)),p(!0)},f=async()=>{try{if(!l)return;h(!0),await (0,b.TF)(l,s,i),F.ZP.success("Permissions updated successfully"),p(!1)}catch(e){F.ZP.error("Failed to update permissions"),console.error("Error updating permissions:",e)}finally{h(!1)}};if(o)return(0,m.jsx)("div",{className:"p-6 text-center",children:"Loading permissions..."});let _=a.length>0;return(0,m.jsxs)(eD.Z,{className:"bg-white shadow-md rounded-md p-6",children:[(0,m.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center border-b pb-4 mb-6",children:[(0,m.jsx)(O.Z,{className:"mb-2 sm:mb-0",children:"Member Permissions"}),t&&x&&(0,m.jsxs)("div",{className:"flex gap-3",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(sM.Z,{}),onClick:()=>{g()},children:"Reset"}),(0,m.jsxs)(C.Z,{onClick:f,loading:c,className:"flex items-center gap-2",children:[(0,m.jsx)(sF.Z,{})," Save Changes"]})]})]}),(0,m.jsx)(P.Z,{className:"mb-6 text-gray-600",children:"Control what team members can do when they are not team admins."}),_?(0,m.jsxs)(e5.Z,{className:"mt-4",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Method"}),(0,m.jsx)(e7.Z,{children:"Endpoint"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Access"})]})}),(0,m.jsx)(e3.Z,{children:a.map(e=>{let s=sU(e);return(0,m.jsxs)(e9.Z,{className:"hover:bg-gray-50 transition-colors",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"px-2 py-1 rounded text-xs font-medium ".concat("GET"===s.method?"bg-blue-100 text-blue-800":"bg-green-100 text-green-800"),children:s.method})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("span",{className:"font-mono text-sm text-gray-800",children:s.endpoint})}),(0,m.jsx)(e6.Z,{className:"text-gray-700",children:s.description}),(0,m.jsx)(e6.Z,{className:"text-right",children:(0,m.jsx)(sL.Z,{checked:i.includes(e),onChange:s=>j(e,s.target.checked),disabled:!t})})]},e)})})]}):(0,m.jsx)("div",{className:"py-12",children:(0,m.jsx)(sD.Z,{description:"No permissions available"})})]})},sV=e=>{var s,l,t;let{visible:a,onCancel:r,onSubmit:i,initialData:n,mode:o,config:d}=e,[c]=M.Z.useForm();console.log("Initial Data:",n),(0,u.useEffect)(()=>{if(a){if("edit"===o&&n)c.setFieldsValue({...n,role:n.role||d.defaultRole});else{var e;c.resetFields(),c.setFieldsValue({role:d.defaultRole||(null===(e=d.roleOptions[0])||void 0===e?void 0:e.value)})}}},[a,n,o,c,d.defaultRole,d.roleOptions]);let h=async e=>{try{let s=Object.entries(e).reduce((e,s)=>{let[l,t]=s;return{...e,[l]:"string"==typeof t?t.trim():t}},{});i(s),c.resetFields(),F.ZP.success("Successfully ".concat("add"===o?"added":"updated"," member"))}catch(e){F.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}},x=e=>{switch(e.type){case"input":return(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",onChange:e=>{e.target.value=e.target.value.trim()}});case"select":var s;return(0,m.jsx)(D.default,{children:null===(s=e.options)||void 0===s?void 0:s.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))});default:return null}};return(0,m.jsx)(R.Z,{title:d.title||("add"===o?"Add Member":"Edit Member"),open:a,width:800,footer:null,onCancel:r,children:(0,m.jsxs)(M.Z,{form:c,onFinish:h,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[d.showEmail&&(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user@example.com",onChange:e=>{e.target.value=e.target.value.trim()}})}),d.showEmail&&d.showUserId&&(0,m.jsx)("div",{className:"text-center mb-4",children:(0,m.jsx)(P.Z,{children:"OR"})}),d.showUserId&&(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(z.default,{className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"Role"}),"edit"===o&&n&&(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["(Current: ",(l=n.role,(null===(t=d.roleOptions.find(e=>e.value===l))||void 0===t?void 0:t.label)||l),")"]})]}),name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,m.jsx)(D.default,{children:"edit"===o&&n?[...d.roleOptions.filter(e=>e.value===n.role),...d.roleOptions.filter(e=>e.value!==n.role)].map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value)):d.roleOptions.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:e.label},e.value))})}),null===(s=d.additionalFields)||void 0===s?void 0:s.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,className:"mb-4",rules:e.rules,children:x(e)},e.name)),(0,m.jsxs)("div",{className:"text-right mt-6",children:[(0,m.jsx)(U.ZP,{onClick:r,className:"mr-2",children:"Cancel"}),(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"add"===o?"Add Member":"Save Changes"})]})]})})},sK=e=>{let{isVisible:s,onCancel:l,onSubmit:t,accessToken:a,title:r="Add Team Member",roles:i=[{label:"admin",value:"admin",description:"Admin role. Can create team keys, add members, and manage settings."},{label:"user",value:"user",description:"User role. Can view team info, but not manage it."}],defaultRole:n="user"}=e,[o]=M.Z.useForm(),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p,g]=(0,u.useState)("user_email"),j=async(e,s)=>{if(!e){c([]);return}x(!0);try{let l=new URLSearchParams;if(l.append(s,e),null==a)return;let t=(await (0,b.u5)(a,l)).map(e=>({label:"user_email"===s?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===s?e.user_email:e.user_id,user:e}));c(t)}catch(e){console.error("Error fetching users:",e)}finally{x(!1)}},f=(0,u.useCallback)(eb()((e,s)=>j(e,s),300),[]),_=(e,s)=>{g(s),f(e,s)},v=(e,s)=>{let l=s.user;o.setFieldsValue({user_email:l.user_email,user_id:l.user_id,role:o.getFieldValue("role")})};return(0,m.jsx)(R.Z,{title:r,open:s,onCancel:()=>{o.resetFields(),c([]),l()},footer:null,width:800,children:(0,m.jsxs)(M.Z,{form:o,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:n},children:[(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>_(e,"user_email"),onSelect:(e,s)=>v(e,s),options:"user_email"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,m.jsx)(D.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>_(e,"user_id"),onSelect:(e,s)=>v(e,s),options:"user_id"===p?d:[],loading:h,allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:n,children:i.map(e=>(0,m.jsx)(D.default.Option,{value:e.value,children:(0,m.jsxs)(Y.Z,{title:e.description,children:[(0,m.jsx)("span",{className:"font-medium",children:e.label}),(0,m.jsxs)("span",{className:"ml-2 text-gray-500 text-sm",children:["- ",e.description]})]})},e.value))})}),(0,m.jsx)("div",{className:"text-right mt-4",children:(0,m.jsx)(U.ZP,{type:"default",htmlType:"submit",children:"Add Member"})})]})})},sB=e=>{var s;let{teamId:l,onClose:t,accessToken:a,is_team_admin:r,is_proxy_admin:i,userModels:n,editTeam:o}=e,[d,c]=(0,u.useState)(null),[h,x]=(0,u.useState)(!0),[p,g]=(0,u.useState)(!1),[j]=M.Z.useForm(),[f,_]=(0,u.useState)(!1),[v,y]=(0,u.useState)(null),[Z,N]=(0,u.useState)(!1);console.log("userModels in team info",n);let w=r||i,k=async()=>{try{if(x(!0),!a)return;let e=await (0,b.Xm)(a,l);c(e)}catch(e){F.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{x(!1)}};(0,u.useEffect)(()=>{k()},[l,a]);let I=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.cu)(a,l,s),F.ZP.success("Team member added successfully"),g(!1),j.resetFields(),k()}catch(e){F.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},T=async e=>{try{if(null==a)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.sN)(a,l,s),F.ZP.success("Team member updated successfully"),_(!1),k()}catch(e){F.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}},A=async e=>{try{if(null==a)return;await (0,b.Lp)(a,l,e),F.ZP.success("Team member removed successfully"),k()}catch(e){F.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},E=async e=>{try{if(!a)return;let s={};try{s=e.metadata?JSON.parse(e.metadata):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}let t={team_id:l,team_alias:e.team_alias,models:e.models,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration,metadata:{...s,guardrails:e.guardrails||[]},organization_id:e.organization_id};await (0,b.Gh)(a,t),F.ZP.success("Team settings updated successfully"),N(!1),k()}catch(e){console.error("Error updating team:",e)}};if(h)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==d?void 0:d.team_info))return(0,m.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:L}=d;return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:t,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:L.team_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:L.team_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:o?3:0,children:[(0,m.jsx)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),...w?[(0,m.jsx)(eM.Z,{children:"Members"},"members"),(0,m.jsx)(eM.Z,{children:"Member Permissions"},"member-permissions"),(0,m.jsx)(eM.Z,{children:"Settings"},"settings")]:[]]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",L.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===L.max_budget?"Unlimited":"$".concat(L.max_budget)]}),L.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",L.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",L.rpm_limit||"Unlimited"]}),L.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",L.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sO,{teamData:d,canEditTeam:w,handleMemberDelete:A,setSelectedEditMember:y,setIsEditMemberModalVisible:_,setIsAddMemberModalVisible:g})}),w&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sz,{teamId:l,accessToken:a,canEditTeam:w})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Team Settings"}),w&&!Z&&(0,m.jsx)(C.Z,{onClick:()=>N(!0),children:"Edit Settings"})]}),Z?(0,m.jsxs)(M.Z,{form:j,onFinish:E,initialValues:{...L,team_alias:L.team_alias,models:L.models,tpm_limit:L.tpm_limit,rpm_limit:L.rpm_limit,max_budget:L.max_budget,budget_duration:L.budget_duration,guardrails:(null===(s=L.metadata)||void 0===s?void 0:s.guardrails)||[],metadata:L.metadata?JSON.stringify(L.metadata,null,2):"",organization_id:L.organization_id},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),n.map((e,s)=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},s))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",placeholder:"Select or enter guardrails"})}),(0,m.jsx)(M.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,m.jsx)(z.default,{type:""})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:10})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>N(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team Name"}),(0,m.jsx)("div",{children:L.team_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"font-mono",children:L.team_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(L.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:L.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",L.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",L.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==L.max_budget?"$".concat(L.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",L.budget_duration||"Never"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{children:L.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Status"}),(0,m.jsx)(eL.Z,{color:L.blocked?"red":"green",children:L.blocked?"Blocked":"Active"})]})]})]})})]})]}),(0,m.jsx)(sV,{visible:f,onCancel:()=>_(!1),onSubmit:T,initialData:v,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Admin",value:"admin"},{label:"User",value:"user"}]}}),(0,m.jsx)(sK,{isVisible:p,onCancel:()=>g(!1),onSubmit:I,accessToken:a})]})},sH=l(45589);let{Title:sJ,Link:sG}=et.default;var sW=e=>{let{isVisible:s,onCancel:l,onAddCredential:t,existingCredential:a,setIsCredentialModalOpen:r}=e,[i]=M.Z.useForm();return console.log("existingCredential in add credentials tab: ".concat(JSON.stringify(a))),(0,m.jsx)(R.Z,{title:"Reuse Credentials",visible:s,onCancel:()=>{l(),i.resetFields()},footer:null,width:600,children:(0,m.jsxs)(M.Z,{form:i,onFinish:e=>{t(e),i.resetFields(),r(!1)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Credential Name:",name:"credential_name",rules:[{required:!0,message:"Credential name is required"}],initialValue:null==a?void 0:a.credential_name,children:(0,m.jsx)(I.Z,{placeholder:"Enter a friendly name for these credentials"})}),Object.entries((null==a?void 0:a.credential_values)||{}).map(e=>{let[s,l]=e;return(0,m.jsx)(M.Z.Item,{label:s,name:s,initialValue:l,children:(0,m.jsx)(I.Z,{placeholder:"Enter ".concat(s),disabled:!0})},s)}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(sG,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:()=>{l(),i.resetFields()},style:{marginRight:10},children:"Cancel"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Reuse Credentials"})]})]})]})})},sY=l(63709),s$=l(45246),sX=l(96473);let{Text:sQ}=et.default;var s0=e=>{let{form:s,showCacheControl:l,onCacheControlChange:t}=e,a=e=>{let l=s.getFieldValue("litellm_extra_params");try{let t=l?JSON.parse(l):{};e.length>0?t.cache_control_injection_points=e:delete t.cache_control_injection_points,Object.keys(t).length>0?s.setFieldValue("litellm_extra_params",JSON.stringify(t,null,2)):s.setFieldValue("litellm_extra_params","")}catch(e){console.error("Error updating cache control points:",e)}};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Cache Control Injection Points",name:"cache_control",valuePropName:"checked",className:"mb-4",tooltip:"Tell litellm where to inject cache control checkpoints. You can specify either by role (to apply to all messages of that role) or by specific message index.",children:(0,m.jsx)(sY.Z,{onChange:t,className:"bg-gray-600"})}),l&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(sQ,{className:"text-sm text-gray-500 block mb-4",children:"Providers like Anthropic, Bedrock API require users to specify where to inject cache control checkpoints, litellm can automatically add them for you as a cost saving feature."}),(0,m.jsx)(M.Z.List,{name:"cache_control_injection_points",initialValue:[{location:"message"}],children:(e,l)=>{let{add:t,remove:r}=l;return(0,m.jsxs)(m.Fragment,{children:[e.map((l,t)=>(0,m.jsxs)("div",{className:"flex items-center mb-4 gap-4",children:[(0,m.jsx)(M.Z.Item,{...l,label:"Type",name:[l.name,"location"],initialValue:"message",className:"mb-0",style:{width:"180px"},children:(0,m.jsx)(D.default,{disabled:!0,options:[{value:"message",label:"Message"}]})}),(0,m.jsx)(M.Z.Item,{...l,label:"Role",name:[l.name,"role"],className:"mb-0",style:{width:"180px"},tooltip:"LiteLLM will mark all messages of this role as cacheable",children:(0,m.jsx)(D.default,{placeholder:"Select a role",allowClear:!0,options:[{value:"user",label:"User"},{value:"system",label:"System"},{value:"assistant",label:"Assistant"}],onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),(0,m.jsx)(M.Z.Item,{...l,label:"Index",name:[l.name,"index"],className:"mb-0",style:{width:"180px"},tooltip:"(Optional) If set litellm will mark the message at this index as cacheable",children:(0,m.jsx)(K,{type:"number",placeholder:"Optional",step:1,min:0,onChange:()=>{a(s.getFieldValue("cache_control_points"))}})}),e.length>1&&(0,m.jsx)(s$.Z,{className:"text-red-500 cursor-pointer text-lg ml-12",onClick:()=>{r(l.name),setTimeout(()=>{a(s.getFieldValue("cache_control_points"))},0)}})]},l.key)),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full border border-dashed border-gray-300 py-2 px-4 text-gray-600 hover:text-blue-600 hover:border-blue-300 transition-all rounded",onClick:()=>t(),children:[(0,m.jsx)(sX.Z,{className:"mr-2"}),"Add Injection Point"]})})]})}})]})]})};function s1(e){var s,l,t,a,r,i,n,o,d,c,h,x,p,g,j,f,_,v,y,Z,N;let{modelId:w,onClose:k,modelData:T,accessToken:A,userID:E,userRole:L,editModel:D,setEditModalVisible:q,setSelectedModel:z,onModelUpdate:V}=e,[B]=M.Z.useForm(),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)(!1),[X,Q]=(0,u.useState)(!1),[ee,es]=(0,u.useState)(!1),[el,et]=(0,u.useState)(!1),[ea,er]=(0,u.useState)(null),[ei,en]=(0,u.useState)(!1),eo="Admin"===L||T.model_info.created_by===E,ed=(null===(s=T.litellm_params)||void 0===s?void 0:s.litellm_credential_name)!=null&&(null===(l=T.litellm_params)||void 0===l?void 0:l.litellm_credential_name)!=void 0;console.log("usingExistingCredential, ",ed),console.log("modelData.litellm_params.litellm_credential_name, ",T.litellm_params.litellm_credential_name),(0,u.useEffect)(()=>{let e=async()=>{var e;if(!A)return;let s=await (0,b.ix)(A,w);console.log("modelInfoResponse, ",s);let l=s.data[0];J(l),(null==l?void 0:null===(e=l.litellm_params)||void 0===e?void 0:e.cache_control_injection_points)&&en(!0)};(async()=>{if(console.log("accessToken, ",A),!A||ed)return;let e=await (0,b.Qg)(A,null,w);console.log("existingCredentialResponse, ",e),er({credential_name:e.credential_name,credential_values:e.credential_values,credential_info:e.credential_info})})(),e()},[A,w]);let ec=async e=>{var s;if(console.log("values, ",e),!A)return;let l={credential_name:e.credential_name,model_id:w,credential_info:{custom_llm_provider:null===(s=H.litellm_params)||void 0===s?void 0:s.custom_llm_provider}};F.ZP.info("Storing credential.."),console.log("credentialResponse, ",await (0,b.oC)(A,l)),F.ZP.success("Credential stored successfully")},em=async e=>{try{var s;if(!A)return;es(!0),console.log("values.model_name, ",e.model_name);let l={...H.litellm_params,model:e.litellm_model_name,api_base:e.api_base,custom_llm_provider:e.custom_llm_provider,organization:e.organization,tpm:e.tpm,rpm:e.rpm,max_retries:e.max_retries,timeout:e.timeout,stream_timeout:e.stream_timeout,input_cost_per_token:e.input_cost/1e6,output_cost_per_token:e.output_cost/1e6};e.cache_control&&(null===(s=e.cache_control_injection_points)||void 0===s?void 0:s.length)>0?l.cache_control_injection_points=e.cache_control_injection_points:delete l.cache_control_injection_points;let t={model_name:e.model_name,litellm_params:l,model_info:{id:w}};await (0,b.$D)(A,t,w);let a={...H,model_name:e.model_name,litellm_model_name:e.litellm_model_name,litellm_params:l};J(a),V&&V(a),F.ZP.success("Model settings updated successfully"),Q(!1),et(!1)}catch(e){console.error("Error updating model:",e),F.ZP.error("Failed to update model settings")}finally{es(!1)}};if(!T)return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsx)(P.Z,{children:"Model not found"})]});let eu=async()=>{try{if(!A)return;await (0,b.Og)(A,w),F.ZP.success("Model deleted successfully"),V&&V({deleted:!0,model_info:{id:w}}),k()}catch(e){console.error("Error deleting the model:",e),F.ZP.error("Failed to delete model")}};return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{icon:(0,m.jsx)(ez.Z,{}),onClick:k,className:"mb-4",children:"Back to Models"}),(0,m.jsxs)(O.Z,{children:["Public Model Name: ",sk(T)]}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:T.model_info.id})]}),(0,m.jsxs)("div",{className:"flex gap-2",children:["Admin"===L&&(0,m.jsx)(C.Z,{icon:sH.Z,variant:"secondary",onClick:()=>$(!0),className:"flex items-center",children:"Re-use Credentials"}),eo&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>W(!0),className:"flex items-center",children:"Delete Model"})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-6",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Raw JSON"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6 mb-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[T.provider&&(0,m.jsx)("img",{src:sm(T.provider).logo,alt:"".concat(T.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,l=s.parentElement;if(l){var t;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(t=T.provider)||void 0===t?void 0:t.charAt(0))||"-",l.replaceChild(e,s)}}}),(0,m.jsx)(O.Z,{children:T.provider||"Not Set"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"LiteLLM Model"}),(0,m.jsx)("pre",{children:(0,m.jsx)(O.Z,{children:T.litellm_model_name||"Not Set"})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Pricing"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Input: $",T.input_cost,"/1M tokens"]}),(0,m.jsxs)(P.Z,{children:["Output: $",T.output_cost,"/1M tokens"]})]})]})]}),(0,m.jsxs)("div",{className:"mb-6 text-sm text-gray-500 flex items-center gap-x-6",children:[(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Created At ",T.model_info.created_at?new Date(T.model_info.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"Not Set"]}),(0,m.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),"Created By ",T.model_info.created_by||"Not Set"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Model Settings"}),eo&&!el&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>et(!0),className:"flex items-center",children:"Edit Model"})]}),H?(0,m.jsx)(M.Z,{form:B,onFinish:em,initialValues:{model_name:H.model_name,litellm_model_name:H.litellm_model_name,api_base:H.litellm_params.api_base,custom_llm_provider:H.litellm_params.custom_llm_provider,organization:H.litellm_params.organization,tpm:H.litellm_params.tpm,rpm:H.litellm_params.rpm,max_retries:H.litellm_params.max_retries,timeout:H.litellm_params.timeout,stream_timeout:H.litellm_params.stream_timeout,input_cost:H.litellm_params.input_cost_per_token?1e6*H.litellm_params.input_cost_per_token:(null===(t=H.model_info)||void 0===t?void 0:t.input_cost_per_token)*1e6||null,output_cost:(null===(a=H.litellm_params)||void 0===a?void 0:a.output_cost_per_token)?1e6*H.litellm_params.output_cost_per_token:(null===(r=H.model_info)||void 0===r?void 0:r.output_cost_per_token)*1e6||null,cache_control:null!==(i=H.litellm_params)&&void 0!==i&&!!i.cache_control_injection_points,cache_control_injection_points:(null===(n=H.litellm_params)||void 0===n?void 0:n.cache_control_injection_points)||[]},layout:"vertical",onValuesChange:()=>Q(!0),children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"LiteLLM Model Name"}),el?(0,m.jsx)(M.Z.Item,{name:"litellm_model_name",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter LiteLLM model name"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:H.litellm_model_name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Input Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"input_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter input cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(o=H.litellm_params)||void 0===o?void 0:o.input_cost_per_token)?((null===(d=H.litellm_params)||void 0===d?void 0:d.input_cost_per_token)*1e6).toFixed(4):(null==H?void 0:null===(c=H.model_info)||void 0===c?void 0:c.input_cost_per_token)?(1e6*H.model_info.input_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Output Cost (per 1M tokens)"}),el?(0,m.jsx)(M.Z.Item,{name:"output_cost",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter output cost"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null==H?void 0:null===(h=H.litellm_params)||void 0===h?void 0:h.output_cost_per_token)?(1e6*H.litellm_params.output_cost_per_token).toFixed(4):(null==H?void 0:null===(x=H.model_info)||void 0===x?void 0:x.output_cost_per_token)?(1e6*H.model_info.output_cost_per_token).toFixed(4):null})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Base"}),el?(0,m.jsx)(M.Z.Item,{name:"api_base",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter API base"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(p=H.litellm_params)||void 0===p?void 0:p.api_base)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Custom LLM Provider"}),el?(0,m.jsx)(M.Z.Item,{name:"custom_llm_provider",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom LLM provider"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(g=H.litellm_params)||void 0===g?void 0:g.custom_llm_provider)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization"}),el?(0,m.jsx)(M.Z.Item,{name:"organization",className:"mb-0",children:(0,m.jsx)(I.Z,{placeholder:"Enter organization"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(j=H.litellm_params)||void 0===j?void 0:j.organization)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"TPM (Tokens per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"tpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter TPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(f=H.litellm_params)||void 0===f?void 0:f.tpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"RPM (Requests per Minute)"}),el?(0,m.jsx)(M.Z.Item,{name:"rpm",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter RPM"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(_=H.litellm_params)||void 0===_?void 0:_.rpm)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Max Retries"}),el?(0,m.jsx)(M.Z.Item,{name:"max_retries",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter max retries"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(v=H.litellm_params)||void 0===v?void 0:v.max_retries)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(y=H.litellm_params)||void 0===y?void 0:y.timeout)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Stream Timeout (seconds)"}),el?(0,m.jsx)(M.Z.Item,{name:"stream_timeout",className:"mb-0",children:(0,m.jsx)(K,{placeholder:"Enter stream timeout"})}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(Z=H.litellm_params)||void 0===Z?void 0:Z.stream_timeout)||"Not Set"})]}),el?(0,m.jsx)(s0,{form:B,showCacheControl:ei,onCacheControlChange:e=>en(e)}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Cache Control"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:(null===(N=H.litellm_params)||void 0===N?void 0:N.cache_control_injection_points)?(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{children:"Enabled"}),(0,m.jsx)("div",{className:"mt-2",children:H.litellm_params.cache_control_injection_points.map((e,s)=>(0,m.jsxs)("div",{className:"text-sm text-gray-600 mb-1",children:["Location: ",e.location,",",e.role&&(0,m.jsxs)("span",{children:[" Role: ",e.role]}),void 0!==e.index&&(0,m.jsxs)("span",{children:[" Index: ",e.index]})]},s))})]}):"Disabled"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Team ID"}),(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:T.model_info.team_id||"Not Set"})]})]}),el&&(0,m.jsxs)("div",{className:"mt-6 flex justify-end gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{B.resetFields(),Q(!1),et(!1)},children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",onClick:()=>B.submit(),loading:ee,children:"Save Changes"})]})]})}):(0,m.jsx)(P.Z,{children:"Loading..."})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsx)("pre",{className:"bg-gray-100 p-4 rounded text-xs overflow-auto",children:JSON.stringify(T,null,2)})})})]})]}),G&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Model"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this model?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(U.ZP,{onClick:eu,className:"ml-2",danger:!0,children:"Delete"}),(0,m.jsx)(U.ZP,{onClick:()=>W(!1),children:"Cancel"})]})]})]})}),Y&&!ed?(0,m.jsx)(sW,{isVisible:Y,onCancel:()=>$(!1),onAddCredential:ec,existingCredential:ea,setIsCredentialModalOpen:$}):(0,m.jsx)(R.Z,{open:Y,onCancel:()=>$(!1),title:"Using Existing Credential",children:(0,m.jsx)(P.Z,{children:T.litellm_params.litellm_credential_name})})]})}var s2=l(67960),s4=e=>{let{selectedProvider:s,providerModels:l,getPlaceholder:t}=e,a=M.Z.useFormInstance(),r=e=>{let s=e.target.value,l=(a.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:s,litellm_model:s}:e);a.setFieldsValue({model_mappings:l})};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(M.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,m.jsx)(M.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:s===n.Azure||s===n.OpenAI_Compatible||s===n.Ollama?(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(I.Z,{placeholder:t(s)})}):l.length>0?(0,m.jsx)(D.default,{mode:"multiple",allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{let s=Array.isArray(e)?e:[e];if(s.includes("all-wildcard"))a.setFieldsValue({model_name:void 0,model_mappings:[]});else if(JSON.stringify(a.getFieldValue("model"))!==JSON.stringify(s)){let e=s.map(e=>({public_name:e,litellm_model:e}));a.setFieldsValue({model:s,model_mappings:e})}},optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"Custom Model Name (Enter below)",value:"custom"},{label:"All ".concat(s," Models (Wildcard)"),value:"all-wildcard"},...l.map(e=>({label:e,value:e}))],style:{width:"100%"}}):(0,m.jsx)(I.Z,{placeholder:t(s)})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.model!==s.model,children:e=>{let{getFieldValue:s}=e,l=s("model")||[];return(Array.isArray(l)?l:[l]).includes("custom")&&(0,m.jsx)(M.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,m.jsx)(I.Z,{placeholder:"Enter custom model name",onChange:r})})}})]}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsx)(P.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},s5=()=>{let e=M.Z.useFormInstance(),[s,l]=(0,u.useState)(0),t=M.Z.useWatch("model",e)||[],a=Array.isArray(t)?t:[t],r=M.Z.useWatch("custom_model_name",e),i=!a.includes("all-wildcard");if((0,u.useEffect)(()=>{if(r&&a.includes("custom")){let s=(e.getFieldValue("model_mappings")||[]).map(e=>"custom"===e.public_name||"custom"===e.litellm_model?{public_name:r,litellm_model:r}:e);e.setFieldValue("model_mappings",s),l(e=>e+1)}},[r,a,e]),(0,u.useEffect)(()=>{if(a.length>0&&!a.includes("all-wildcard")){let s=e.getFieldValue("model_mappings")||[];if(s.length!==a.length||!a.every(e=>s.some(s=>s.public_name===e||"custom"===e&&s.public_name===r))){let s=a.map(e=>"custom"===e&&r?{public_name:r,litellm_model:r}:{public_name:e,litellm_model:e});e.setFieldValue("model_mappings",s),l(e=>e+1)}}},[a,r,e]),!i)return null;let n=[{title:"Public Name",dataIndex:"public_name",key:"public_name",render:(s,l,t)=>(0,m.jsx)(I.Z,{value:s,onChange:s=>{let l=[...e.getFieldValue("model_mappings")];l[t].public_name=s.target.value,e.setFieldValue("model_mappings",l)}})},{title:"LiteLLM Model",dataIndex:"litellm_model",key:"litellm_model"}];return(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(M.Z.Item,{label:"Model Mappings",name:"model_mappings",tooltip:"Map public model names to LiteLLM model names for load balancing",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!0,children:(0,m.jsx)(ei.Z,{dataSource:e.getFieldValue("model_mappings"),columns:n,pagination:!1,size:"small"},s)})})},s3=l(90464);let{Link:s6}=et.default;var s8=e=>{let{showAdvancedSettings:s,setShowAdvancedSettings:l,teams:t}=e,[a]=M.Z.useForm(),[r,i]=u.useState(!1),[n,o]=u.useState("per_token"),[d,c]=u.useState(!1),h=(e,s)=>s&&(isNaN(Number(s))||0>Number(s))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),x=(e,s)=>{if(!s)return Promise.resolve();try{return JSON.parse(s),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(T.Z,{className:"mt-2 mb-4",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Advanced Settings"})}),(0,m.jsx)(A.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,m.jsx)(M.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,m.jsx)(sY.Z,{onChange:e=>{i(e),e||a.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),r&&(0,m.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,m.jsx)(M.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,m.jsx)(D.default,{defaultValue:"per_token",onChange:e=>o(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===n?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}):(0,m.jsx)(M.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:h}],className:"mb-4",children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)(M.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,m.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,m.jsx)(sY.Z,{onChange:e=>{let s=a.getFieldValue("litellm_extra_params");try{let l=s?JSON.parse(s):{};e?l.use_in_pass_through=!0:delete l.use_in_pass_through,Object.keys(l).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(l,null,2)):a.setFieldValue("litellm_extra_params","")}catch(s){e?a.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):a.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,m.jsx)(s0,{form:a,showCacheControl:d,onCacheControlChange:e=>{if(c(e),!e){let e=a.getFieldValue("litellm_extra_params");try{let s=e?JSON.parse(e):{};delete s.cache_control_injection_points,Object.keys(s).length>0?a.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):a.setFieldValue("litellm_extra_params","")}catch(e){a.setFieldValue("litellm_extra_params","")}}}}),(0,m.jsx)(M.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-4 mt-4",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,m.jsxs)(sj.Z,{className:"mb-4",children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,m.jsx)(s6,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,m.jsx)(M.Z.Item,{label:"Model Info",name:"model_info_params",tooltip:"Optional model info params. Returned when calling `/model/info` endpoint.",className:"mb-0",rules:[{validator:x}],children:(0,m.jsx)(s3.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},s7=l(29),s9=l.n(s7),le=l(23496),ls=l(23639);let{Text:ll}=et.default;var lt=e=>{let{formValues:s,accessToken:l,testMode:t,modelName:a="this model",onClose:r,onTestComplete:i}=e,[n,o]=u.useState(null),[d,c]=u.useState(null),[h,x]=u.useState(null),[p,g]=u.useState(!0),[j,f]=u.useState(!1),[_,v]=u.useState(!1),y=async()=>{g(!0),v(!1),o(null),c(null),x(null),f(!1),await new Promise(e=>setTimeout(e,100));try{console.log("Testing connection with form values:",s);let a=await sx(s,l,null);if(!a){console.log("No result from prepareModelAddRequest"),o("Failed to prepare model data. Please check your form inputs."),f(!1),g(!1);return}console.log("Result from prepareModelAddRequest:",a);let{litellmParamsObj:r,modelInfoObj:i,modelName:n}=a[0],d=await (0,b.Hx)(l,r,null==i?void 0:i.mode);if("success"===d.status)F.ZP.success("Connection test successful!"),o(null),f(!0);else{var e,t;let s=(null===(e=d.result)||void 0===e?void 0:e.error)||d.message||"Unknown error";o(s),c(r),x(null===(t=d.result)||void 0===t?void 0:t.raw_request_typed_dict),f(!1)}}catch(e){console.error("Test connection error:",e),o(e instanceof Error?e.message:String(e)),f(!1)}finally{g(!1),i&&i()}};u.useEffect(()=>{let e=setTimeout(()=>{y()},200);return()=>clearTimeout(e)},[]);let Z=e=>e?e.split("stack trace:")[0].trim().replace(/^litellm\.(.*?)Error: /,""):"Unknown error",N="string"==typeof n?Z(n):(null==n?void 0:n.message)?Z(n.message):"Unknown error",w=h?((e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")})(h.raw_request_api_base,h.raw_request_body,h.raw_request_headers||{}):"";return(0,m.jsxs)("div",{style:{padding:"24px",borderRadius:"8px",backgroundColor:"#fff"},children:[p?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},className:"jsx-776cdcbc0448e4ea",children:[(0,m.jsx)("div",{style:{marginBottom:"16px"},className:"jsx-776cdcbc0448e4ea loading-spinner",children:(0,m.jsx)("div",{style:{border:"3px solid #f3f3f3",borderTop:"3px solid #1890ff",borderRadius:"50%",width:"30px",height:"30px",animation:"spin 1s linear infinite",margin:"0 auto"},className:"jsx-776cdcbc0448e4ea"})}),(0,m.jsxs)(ll,{style:{fontSize:"16px"},children:["Testing connection to ",a,"..."]}),(0,m.jsx)(s9(),{id:"776cdcbc0448e4ea",children:"@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0deg);transform:rotate(0deg)}100%{-moz-transform:rotate(360deg);transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-o-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);-moz-transform:rotate(0deg);-o-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);-moz-transform:rotate(360deg);-o-transform:rotate(360deg);transform:rotate(360deg)}}"})]}):j?(0,m.jsxs)("div",{style:{textAlign:"center",padding:"32px 20px"},children:[(0,m.jsx)("div",{style:{color:"#52c41a",fontSize:"32px",marginBottom:"16px"},children:(0,m.jsx)("svg",{viewBox:"64 64 896 896",focusable:"false","data-icon":"check-circle",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",children:(0,m.jsx)("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 01-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"})})}),(0,m.jsxs)(ll,{type:"success",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," successful!"]})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",marginBottom:"20px"},children:[(0,m.jsx)(em.Z,{style:{color:"#ff4d4f",fontSize:"24px",marginRight:"12px"}}),(0,m.jsxs)(ll,{type:"danger",style:{fontSize:"18px",fontWeight:500},children:["Connection to ",a," failed"]})]}),(0,m.jsxs)("div",{style:{backgroundColor:"#fff2f0",border:"1px solid #ffccc7",borderRadius:"8px",padding:"16px",marginBottom:"20px",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px"},children:"Error: "}),(0,m.jsx)(ll,{type:"danger",style:{fontSize:"14px",lineHeight:"1.5"},children:N}),n&&(0,m.jsx)("div",{style:{marginTop:"12px"},children:(0,m.jsx)(U.ZP,{type:"link",onClick:()=>v(!_),style:{paddingLeft:0,height:"auto"},children:_?"Hide Details":"Show Details"})})]}),_&&(0,m.jsxs)("div",{style:{marginBottom:"20px"},children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"Troubleshooting Details"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"200px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:"string"==typeof n?n:JSON.stringify(n,null,2)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(ll,{strong:!0,style:{display:"block",marginBottom:"8px",fontSize:"15px"},children:"API Request"}),(0,m.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",fontSize:"13px",maxHeight:"250px",overflow:"auto",border:"1px solid #e8e8e8",lineHeight:"1.5"},children:w||"No request data available"}),(0,m.jsx)(U.ZP,{style:{marginTop:"8px"},icon:(0,m.jsx)(ls.Z,{}),onClick:()=>{navigator.clipboard.writeText(w||""),F.ZP.success("Copied to clipboard")},children:"Copy to Clipboard"})]})]})}),(0,m.jsx)(le.Z,{style:{margin:"24px 0 16px"}}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:(0,m.jsx)(U.ZP,{type:"link",href:"https://docs.litellm.ai/docs/providers",target:"_blank",icon:(0,m.jsx)(W.Z,{}),children:"View Documentation"})})]})};let la=[{value:"chat",label:"Chat - /chat/completions"},{value:"completion",label:"Completion - /completions"},{value:"embedding",label:"Embedding - /embeddings"},{value:"audio_speech",label:"Audio Speech - /audio/speech"},{value:"audio_transcription",label:"Audio Transcription - /audio/transcriptions"},{value:"image_generation",label:"Image Generation - /images/generations"},{value:"rerank",label:"Rerank - /rerank"},{value:"realtime",label:"Realtime - /realtime"}],{Title:lr,Link:li}=et.default;var ln=e=>{let{form:s,handleOk:l,selectedProvider:t,setSelectedProvider:a,providerModels:r,setProviderModelsFn:i,getPlaceholder:o,uploadProps:d,showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x,credentials:p,accessToken:g,userRole:j}=e,[f,_]=(0,u.useState)("chat"),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(""),k=async()=>{Z(!0),w("test-".concat(Date.now())),y(!0)},S=eZ.ZL.includes(j);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lr,{level:2,children:"Add new model"}),(0,m.jsx)(s2.Z,{children:(0,m.jsx)(M.Z,{form:s,onFinish:l,labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,m.jsx)(D.default,{showSearch:!0,value:t,onChange:e=>{a(e),i(e),s.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(n).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(s4,{selectedProvider:t,providerModels:r,getPlaceholder:o}),(0,m.jsx)(s5,{}),(0,m.jsx)(M.Z.Item,{label:"Mode",name:"mode",className:"mb-1",children:(0,m.jsx)(D.default,{style:{width:"100%"},value:f,onChange:e=>_(e),options:la})}),(0,m.jsxs)(sj.Z,{children:[(0,m.jsx)(sf.Z,{span:10}),(0,m.jsx)(sf.Z,{span:10,children:(0,m.jsxs)(P.Z,{className:"mb-5 mt-1",children:[(0,m.jsx)("strong",{children:"Optional"})," - LiteLLM endpoint to use when health checking this model ",(0,m.jsx)(li,{href:"https://docs.litellm.ai/docs/proxy/health#health",target:"_blank",children:"Learn more"})]})})]}),(0,m.jsx)("div",{className:"mb-4",children:(0,m.jsx)(et.default.Text,{className:"text-sm text-gray-500 mb-2",children:"Either select existing credentials OR enter new provider credentials below"})}),(0,m.jsx)(M.Z.Item,{label:"Existing Credentials",name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...p.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"OR"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.litellm_credential_name!==s.litellm_credential_name||e.provider!==s.provider,children:e=>{let{getFieldValue:s}=e,l=s("litellm_credential_name");return(console.log("\uD83D\uDD11 Credential Name Changed:",l),l)?(0,m.jsx)("div",{className:"text-gray-500 text-sm text-center",children:"Using existing credentials - no additional provider fields needed"}):(0,m.jsx)(sy,{selectedProvider:t,uploadProps:d})}}),(0,m.jsxs)("div",{className:"flex items-center my-4",children:[(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"}),(0,m.jsx)("span",{className:"px-4 text-gray-500 text-sm",children:"Team Settings"}),(0,m.jsx)("div",{className:"flex-grow border-t border-gray-200"})]}),(0,m.jsx)(M.Z.Item,{label:"Team",name:"team_id",className:"mb-4",tooltip:"Only keys for this team, will be able to call this model.",rules:[{required:!S,message:"Please select a team."}],children:(0,m.jsx)(es,{teams:x})}),(0,m.jsx)(s8,{showAdvancedSettings:c,setShowAdvancedSettings:h,teams:x}),(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(Y.Z,{title:"Get help on our github",children:(0,m.jsx)(et.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,m.jsxs)("div",{className:"space-x-2",children:[(0,m.jsx)(U.ZP,{onClick:k,loading:b,children:"Test Connect"}),(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Model"})]})]})]})})}),(0,m.jsx)(R.Z,{title:"Connection Test Results",open:v,onCancel:()=>{y(!1),Z(!1)},footer:[(0,m.jsx)(U.ZP,{onClick:()=>{y(!1),Z(!1)},children:"Close"},"close")],width:700,children:v&&(0,m.jsx)(lt,{formValues:s.getFieldsValue(),accessToken:g,testMode:f,modelName:s.getFieldValue("model_name")||s.getFieldValue("model"),onClose:()=>{y(!1),Z(!1)},onTestComplete:()=>Z(!1)},N)})]})};function lo(e){let{data:s=[],columns:l,isLoading:t=!1,table:a}=e,[r,i]=u.useState([{id:"model_info.created_at",desc:!0}]),[n]=u.useState("onChange"),[o,d]=u.useState({}),[c,h]=u.useState({}),x=(0,e2.b7)({data:s,columns:l,state:{sorting:r,columnSizing:o,columnVisibility:c},columnResizeMode:n,onSortingChange:i,onColumnSizingChange:d,onColumnVisibilityChange:h,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0,enableColumnResizing:!0,defaultColumn:{minSize:40,maxSize:500}});return u.useEffect(()=>{a&&(a.current=x)},[x,a]),(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsx)("div",{className:"relative min-w-full",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1 w-full",children:[(0,m.jsx)(e8.Z,{children:x.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsxs)(e7.Z,{className:"py-1 h-8 relative ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.id?120:e.getSize(),position:"actions"===e.id?"sticky":"relative",right:"actions"===e.id?0:"auto"},onClick:e.column.getToggleSortingHandler(),children:[(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]}),e.column.getCanResize()&&(0,m.jsx)("div",{onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler(),className:"absolute right-0 top-0 h-full w-2 cursor-col-resize select-none touch-none ".concat(e.column.getIsResizing()?"bg-blue-500":"hover:bg-blue-200")})]},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading models..."})})})}):x.getRowModel().rows.length>0?x.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)] z-20 w-[120px] ml-8":""),style:{width:"actions"===e.column.id?120:e.column.getSize(),position:"actions"===e.column.id?"sticky":"relative",right:"actions"===e.column.id?0:"auto"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No models found"})})})})})]})})})})}let ld=(e,s,l,t,a,r,i,n,o)=>[{header:"Model ID",accessorKey:"model_info.id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.model_info.id,children:(0,m.jsx)("div",{className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left w-full truncate whitespace-nowrap cursor-pointer max-w-[15ch]",onClick:()=>t(l.model_info.id),children:l.model_info.id})})}},{header:"Public Model Name",accessorKey:"model_name",cell:e=>{let{row:s}=e,l=r(s.original)||"-";return(0,m.jsx)(Y.Z,{title:l,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l})})}},{header:"Provider",accessorKey:"provider",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l.provider&&(0,m.jsx)("img",{src:sm(l.provider).logo,alt:"".concat(l.provider," logo"),className:"w-4 h-4",onError:e=>{let s=e.target,t=s.parentElement;if(t){var a;let e=document.createElement("div");e.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=(null===(a=l.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(e,s)}}}),(0,m.jsx)("p",{className:"text-xs",children:l.provider||"-"})]})}},{header:"LiteLLM Model Name",accessorKey:"litellm_model_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.litellm_model_name,children:(0,m.jsx)("div",{className:"text-xs truncate whitespace-nowrap",children:l.litellm_model_name||"-"})})}},{header:"Created At",accessorKey:"model_info.created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_at?new Date(l.model_info.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"model_info.updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.updated_at?new Date(l.model_info.updated_at).toLocaleDateString():"-"})}},{header:"Created By",accessorKey:"model_info.created_by",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.model_info.created_by||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Input Cost"})}),accessorKey:"input_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.input_cost||"-"})}},{header:()=>(0,m.jsx)(Y.Z,{title:"Cost per 1M tokens",children:(0,m.jsx)("span",{children:"Output Cost"})}),accessorKey:"output_cost",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("pre",{className:"text-xs",children:l.output_cost||"-"})}},{header:"Team ID",accessorKey:"model_info.team_id",cell:e=>{let{row:s}=e,l=s.original;return l.model_info.team_id?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.model_info.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>a(l.model_info.team_id),children:[l.model_info.team_id.slice(0,7),"..."]})})}):"-"}},{header:"Credentials",accessorKey:"litellm_credential_name",cell:e=>{let{row:s}=e,l=s.original;return l.litellm_params&&l.litellm_params.litellm_credential_name?(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsxs)(Y.Z,{title:l.litellm_params.litellm_credential_name,children:[l.litellm_params.litellm_credential_name.slice(0,7),"..."]})}):(0,m.jsx)("span",{className:"text-gray-400",children:"-"})}},{header:"Status",accessorKey:"model_info.db_model",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"\n inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium\n ".concat(l.model_info.db_model?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-600","\n "),children:l.model_info.db_model?"DB Model":"Config Model"})}},{id:"actions",header:"",cell:l=>{var a;let{row:r}=l,i=r.original,n="Admin"===e||(null===(a=i.model_info)||void 0===a?void 0:a.created_by)===s;return(0,m.jsxs)("div",{className:"flex items-center justify-end gap-2 pr-4",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{n&&(t(i.model_info.id),o(!0))},className:n?"cursor-pointer":"opacity-50 cursor-not-allowed"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{n&&(t(i.model_info.id),o(!1))},className:n?"cursor-pointer":"opacity-50 cursor-not-allowed"})]})}}],{Title:lc,Link:lm}=et.default,lu={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var lh=e=>{let{accessToken:s,token:l,userRole:t,userID:a,modelData:r={data:[]},keys:i,setModelData:o,premiumUser:d,teams:c}=e,[h,x]=(0,u.useState)([]),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)([]);Object.values(n).filter(e=>isNaN(Number(e)));let[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(n.OpenAI),[I,T]=(0,u.useState)(""),[A,E]=(0,u.useState)(!1),[L,D]=(0,u.useState)(null),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)([]),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)([]),[J,W]=(0,u.useState)([]),[Y,$]=(0,u.useState)([]),[X,Q]=(0,u.useState)([]),[ee,es]=(0,u.useState)([]),[ea,er]=(0,u.useState)([]),[ei,en]=(0,u.useState)([]),[eo,ed]=(0,u.useState)([]),[ec,em]=(0,u.useState)([]),[eu,eh]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[ex,ep]=(0,u.useState)(null),[eg,ej]=(0,u.useState)(0),[ef,e_]=(0,u.useState)({}),[ev,ey]=(0,u.useState)([]),[eb,eN]=(0,u.useState)(!1),[ew,ek]=(0,u.useState)(null),[eS,eC]=(0,u.useState)(null),[eI,eT]=(0,u.useState)([]),[eA,eE]=(0,u.useState)([]),[eP,eL]=(0,u.useState)(!1),[ez,eK]=(0,u.useState)(null),[eB,eH]=(0,u.useState)(!1),[eJ,eW]=(0,u.useState)(null),[eY,e$]=(0,u.useState)(null),[eX,eQ]=(0,u.useState)(null),[e0,e1]=(0,u.useState)(!1),[e2,e4]=(0,u.useState)(!1),se=(0,u.useRef)(null),ss=(0,u.useRef)(null),sl=async(e,l,r)=>{if(console.log("Updating model metrics for group:",e),!s||!a||!t||!l||!r)return;console.log("inside updateModelMetrics - startTime:",l,"endTime:",r),K(e);let i=null==ew?void 0:ew.token;void 0===i&&(i=null);let n=eS;void 0===n&&(n=null),l.setHours(0),l.setMinutes(0),l.setSeconds(0),r.setHours(23),r.setMinutes(59),r.setSeconds(59);try{let o=await (0,b.o6)(s,a,t,e,l.toISOString(),r.toISOString(),i,n);console.log("Model metrics response:",o),W(o.data),$(o.all_api_bases);let d=await (0,b.Rg)(s,e,l.toISOString(),r.toISOString());Q(d.data),es(d.all_api_bases);let c=await (0,b.N8)(s,a,t,e,l.toISOString(),r.toISOString(),i,n);console.log("Model exceptions response:",c),er(c.data),en(c.exception_types);let m=await (0,b.fP)(s,a,t,e,l.toISOString(),r.toISOString(),i,n);if(console.log("slowResponses:",m),em(m),e){let t=await (0,b.n$)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);e_(t);let a=await (0,b.v9)(s,null==l?void 0:l.toISOString().split("T")[0],null==r?void 0:r.toISOString().split("T")[0],e);ey(a)}}catch(e){console.error("Failed to fetch model metrics",e)}},st=async e=>{try{let s=await (0,b.N3)(e);console.log("credentials: ".concat(JSON.stringify(s))),eE(s.credentials)}catch(e){console.error("Error fetching credentials:",e)}};(0,u.useEffect)(()=>{sl(V,eu.from,eu.to)},[ew,eS,eY]),(0,u.useEffect)(()=>{let e=e=>{se.current&&!se.current.contains(e.target)&&e4(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let sa={name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let s=new FileReader;s.onload=e=>{if(e.target){let s=e.target.result;console.log("Resetting vertex_credentials to JSON; jsonStr: ".concat(s)),p.setFieldsValue({vertex_credentials:s}),console.log("Form values right after setting:",p.getFieldsValue())}},s.readAsText(e)}return!1},onChange(e){console.log("Upload onChange triggered with values:",e),console.log("Current form values:",p.getFieldsValue()),"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?F.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&F.ZP.error("".concat(e.file.name," file upload failed."))}},sr=()=>{_(new Date().toLocaleString())},si=async()=>{if(!s){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",ex);try{await (0,b.K_)(s,{router_settings:{model_group_retry_policy:ex}}),F.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),F.ZP.error("Failed to save retry settings")}};if((0,u.useEffect)(()=>{if(!s||!l||!t||!a)return;let e=async()=>{try{var e,l,r,i,n,d,c,m,u,h,x,p;let g=await (0,b.AZ)(s,a,t);console.log("Model data response:",g.data),o(g);let j=await (0,b.hy)(s);j&&N(j);let f=new Set;for(let e=0;e0&&(v=_[_.length-1],console.log("_initial_model_group:",v)),console.log("selectedModelGroup:",V);let y=await (0,b.o6)(s,a,t,v,null===(e=eu.from)||void 0===e?void 0:e.toISOString(),null===(l=eu.to)||void 0===l?void 0:l.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model metrics response:",y),W(y.data),$(y.all_api_bases);let Z=await (0,b.Rg)(s,v,null===(r=eu.from)||void 0===r?void 0:r.toISOString(),null===(i=eu.to)||void 0===i?void 0:i.toISOString());Q(Z.data),es(Z.all_api_bases);let w=await (0,b.N8)(s,a,t,v,null===(n=eu.from)||void 0===n?void 0:n.toISOString(),null===(d=eu.to)||void 0===d?void 0:d.toISOString(),null==ew?void 0:ew.token,eS);console.log("Model exceptions response:",w),er(w.data),en(w.exception_types);let k=await (0,b.fP)(s,a,t,v,null===(c=eu.from)||void 0===c?void 0:c.toISOString(),null===(m=eu.to)||void 0===m?void 0:m.toISOString(),null==ew?void 0:ew.token,eS),S=await (0,b.n$)(s,null===(u=eu.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=eu.to)||void 0===h?void 0:h.toISOString().split("T")[0],v);e_(S);let C=await (0,b.v9)(s,null===(x=eu.from)||void 0===x?void 0:x.toISOString().split("T")[0],null===(p=eu.to)||void 0===p?void 0:p.toISOString().split("T")[0],v);ey(C),console.log("dailyExceptions:",S),console.log("dailyExceptionsPerDeplyment:",C),console.log("slowResponses:",k),em(k);let I=await (0,b.j2)(s);eT(null==I?void 0:I.end_users);let T=(await (0,b.BL)(s,a,t)).router_settings;console.log("routerSettingsInfo:",T);let A=T.model_group_retry_policy,E=T.num_retries;console.log("model_group_retry_policy:",A),console.log("default_retries:",E),ep(A),ej(E)}catch(e){console.error("There was an error fetching the model data",e)}};s&&l&&t&&a&&e();let r=async()=>{let e=await (0,b.qm)(s);console.log("received model cost map data: ".concat(Object.keys(e))),j(e)};null==g&&r(),sr()},[s,l,t,a,g,f,eY]),!r||!s||!l||!t||!a)return(0,m.jsx)("div",{children:"Loading..."});let sd=[],sc=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(g)),null!=g&&"object"==typeof g&&e in g)?g[e].litellm_provider:"openai";if(l){let e=l.split("/"),s=e[0];(i=t)||(i=1===e.length?u(l):s)}else i="-";a&&(n=null==a?void 0:a.input_cost_per_token,o=null==a?void 0:a.output_cost_per_token,d=null==a?void 0:a.max_tokens,c=null==a?void 0:a.max_input_tokens),(null==s?void 0:s.litellm_params)&&(m=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[s]=e;return"model"!==s&&"api_base"!==s}))),r.data[e].provider=i,r.data[e].input_cost=n,r.data[e].output_cost=o,r.data[e].litellm_model_name=l,sc.push(i),r.data[e].input_cost&&(r.data[e].input_cost=(1e6*Number(r.data[e].input_cost)).toFixed(2)),r.data[e].output_cost&&(r.data[e].output_cost=(1e6*Number(r.data[e].output_cost)).toFixed(2)),r.data[e].max_tokens=d,r.data[e].max_input_tokens=c,r.data[e].api_base=null==s?void 0:null===(sg=s.litellm_params)||void 0===sg?void 0:sg.api_base,r.data[e].cleanedLitellmParams=m,sd.push(s.model_name),console.log(r.data[e])}if(t&&"Admin Viewer"==t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to view all models"})]})}let sj=async()=>{try{F.ZP.info("Running health check..."),T("");let e=await (0,b.EY)(s);T(e)}catch(e){console.error("Error running health check:",e),T("Error running health check")}},s_=(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mb-1",children:"Select API Key Name"}),d?(0,m.jsxs)("div",{children:[(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{ek(null)},children:"All Keys"},"all-keys"),null==i?void 0:i.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{ek(e)},children:e.key_alias},s):null)]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Customer Name"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-customers",children:[(0,m.jsx)(el.Z,{value:"all-customers",onClick:()=>{eC(null)},children:"All Customers"},"all-customers"),null==eI?void 0:eI.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>{eC(e)},children:e},s))]}),(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-1",children:"Select Team"}),(0,m.jsxs)(eO.Z,{className:"w-64 relative z-50",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]}),sv=e=>{var s,l;let{payload:t,active:a}=e;if(!a||!t)return null;let r=null===(l=t[0])||void 0===l?void 0:null===(s=l.payload)||void 0===s?void 0:s.date,i=t.sort((e,s)=>s.value-e.value);if(i.length>5){let e=i.length-5;(i=i.slice(0,5)).push({dataKey:"".concat(e," other deployments"),value:t.slice(5).reduce((e,s)=>e+s.value,0),color:"gray"})}return(0,m.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[r&&(0,m.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",r]}),i.map((e,s)=>{let l=parseFloat(e.value.toFixed(5)),t=0===l&&e.value>0?"<0.00001":l.toFixed(5);return(0,m.jsxs)("div",{className:"flex justify-between",children:[(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,m.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,m.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:t})]},s)})]})};console.log("selectedProvider: ".concat(w)),console.log("providerModels.length: ".concat(v.length));let sy=Object.keys(n).find(e=>n[e]===w);return(sy&&Z&&Z.find(e=>e.name===so[sy]),eJ)?(0,m.jsx)("div",{className:"w-full h-full",children:(0,m.jsx)(sB,{teamId:eJ,onClose:()=>eW(null),accessToken:s,is_team_admin:"Admin"===t,is_proxy_admin:"Proxy Admin"===t,userModels:sd,editTeam:!1,onUpdate:sr})}):(0,m.jsx)("div",{style:{width:"100%",height:"100%"},children:ez?(0,m.jsx)(s1,{modelId:ez,editModel:!0,onClose:()=>{eK(null),eH(!1)},modelData:r.data.find(e=>e.model_info.id===ez),accessToken:s,userID:a,userRole:t,setEditModalVisible:E,setSelectedModel:D,onModelUpdate:e=>{o({...r,data:r.data.map(s=>s.model_info.id===e.model_info.id?e:s)}),sr()}}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[eZ.ZL.includes(t)?(0,m.jsx)(eM.Z,{children:"All Models"}):(0,m.jsx)(eM.Z,{children:"Your Models"}),(0,m.jsx)(eM.Z,{children:"Add Model"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"LLM Credentials"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"/health Models"})}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Analytics"}),eZ.ZL.includes(t)&&(0,m.jsx)(eM.Z,{children:"Model Retry Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:sr})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(S.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(O.Z,{children:"Model Management"}),eZ.ZL.includes(t)?(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add and manage models for the proxy"}):(0,m.jsx)(P.Z,{className:"text-tremor-content",children:"Add models for teams you are an admin for."})]})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)("div",{className:"flex items-center justify-between",children:(0,m.jsxs)("div",{className:"flex items-center gap-3",children:[(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:null!=V?V:"all",onValueChange:e=>K("all"===e?"all":e),value:null!=V?V:"all",children:[(0,m.jsx)(el.Z,{value:"all",children:"All Models"}),R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,children:e},s))]})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)(P.Z,{children:"Filter by Team:"}),(0,m.jsxs)(eO.Z,{className:"w-64",defaultValue:"all",value:null!=eX?eX:"all",onValueChange:e=>eQ("all"===e?null:e),children:[(0,m.jsx)(el.Z,{value:"all",children:"All Teams"}),null==c?void 0:c.filter(e=>e.team_id).map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias?"".concat(e.team_alias," (").concat(e.team_id.slice(0,8),"...)"):"Team ".concat(e.team_id.slice(0,8),"...")},e.team_id))]})]})]})}),(0,m.jsx)("div",{className:"flex justify-between items-center",children:(0,m.jsxs)(P.Z,{className:"text-sm text-gray-700",children:["Showing ",r&&r.data.length>0?r.data.length:0," results"]})})]})}),(0,m.jsx)(lo,{columns:ld(t,a,d,eK,eW,sk,e=>{D(e),E(!0)},sr,eH),data:r.data.filter(e=>("all"===V||e.model_name===V||!V)&&("all"===eX||e.model_info.team_id===eX||!eX)),isLoading:!1,table:ss})]})]})})}),(0,m.jsx)(eq.Z,{className:"h-full",children:(0,m.jsx)(ln,{form:p,handleOk:()=>{p.validateFields().then(e=>{sp(e,s,p,sr)}).catch(e=>{console.error("Validation failed:",e)})},selectedProvider:w,setSelectedProvider:k,providerModels:v,setProviderModelsFn:e=>{let s=sh(e,g);y(s),console.log("providerModels: ".concat(s))},getPlaceholder:su,uploadProps:sa,showAdvancedSettings:eP,setShowAdvancedSettings:eL,teams:c,credentials:eA,accessToken:s,userRole:t})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sw,{accessToken:s,uploadProps:sa,credentialList:eA,fetchCredentials:st})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,m.jsx)(C.Z,{onClick:sj,children:"Run `/health`"}),I&&(0,m.jsx)("pre",{children:JSON.stringify(I,null,2)})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:eu,className:"mr-2",onValueChange:e=>{eh(e),sl(V,e.from,e.to)}})]}),(0,m.jsxs)(sf.Z,{className:"ml-2",children:[(0,m.jsx)(P.Z,{children:"Select Model Group"}),(0,m.jsx)(eO.Z,{defaultValue:V||R[0],value:V||R[0],children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>sl(e,eu.from,eu.to),children:e},s))})]}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(sA.Z,{trigger:"click",content:s_,overlayStyle:{width:"20vw"},children:(0,m.jsx)(C.Z,{icon:eG.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>eN(!0)})})})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Avg. Latency per Token"}),(0,m.jsx)(eM.Z,{value:"2",children:"Time to first token"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,m.jsx)(P.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),J&&Y&&(0,m.jsx)(sI.Z,{title:"Model Latency",className:"h-72",data:J,showLegend:!1,index:"date",categories:Y,connectNulls:!0,customTooltip:sv})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(sP,{modelMetrics:X,modelMetricsCategories:ee,customTooltip:sv,premiumUser:d})})]})]})})}),(0,m.jsx)(sf.Z,{children:(0,m.jsx)(eD.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Deployment"}),(0,m.jsx)(e7.Z,{children:"Success Responses"}),(0,m.jsxs)(e7.Z,{children:["Slow Responses ",(0,m.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,m.jsx)(e3.Z,{children:ec.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.api_base}),(0,m.jsx)(e6.Z,{children:e.total_count}),(0,m.jsx)(e6.Z,{children:e.slow_count})]},s))})]})})})]}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Exceptions for ",V]}),(0,m.jsx)(sT.Z,{className:"h-60",data:ea,index:"model",categories:ei,stack:!0,yAxisWidth:30})]})}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["All Up Rate Limit Errors (429) for ",V]}),(0,m.jsxs)(S.Z,{numItems:1,children:[(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",ef.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:ef.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,m.jsx)(sf.Z,{})]})]}),d?(0,m.jsx)(m.Fragment,{children:ev.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},s))}):(0,m.jsx)(m.Fragment,{children:ev&&ev.length>0&&ev.slice(0,1).map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,m.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,m.jsx)(C.Z,{variant:"primary",className:"mb-2",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.api_base}),(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(sf.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},s))})]})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(P.Z,{children:"Filter by Public Model Name"}),(0,m.jsx)(eO.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:V||R[0],value:V||R[0],onValueChange:e=>K(e),children:R.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>K(e),children:e},s))})]}),(0,m.jsxs)(O.Z,{children:["Retry Policy for ",V]}),(0,m.jsx)(P.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),lu&&(0,m.jsx)("table",{children:(0,m.jsx)("tbody",{children:Object.entries(lu).map((e,s)=>{var l;let[t,a]=e,r=null==ex?void 0:null===(l=ex[V])||void 0===l?void 0:l[a];return null==r&&(r=eg),(0,m.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,m.jsx)("td",{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)("td",{children:(0,m.jsx)(G.Z,{className:"ml-5",value:r,min:0,step:1,onChange:e=>{ep(s=>{var l;let t=null!==(l=null==s?void 0:s[V])&&void 0!==l?l:{};return{...null!=s?s:{},[V]:{...t,[a]:e}}})}})})]},s)})})}),(0,m.jsx)(C.Z,{className:"mt-6 mr-8",onClick:si,children:"Save"})]})]})]})})},lx=e=>{let{visible:s,possibleUIRoles:l,onCancel:t,user:a,onSubmit:r}=e,[i,n]=(0,u.useState)(a),[o]=M.Z.useForm();(0,u.useEffect)(()=>{o.resetFields()},[a]);let d=async()=>{o.resetFields(),t()},c=async e=>{r(e),o.resetFields(),t()};return a?(0,m.jsx)(R.Z,{visible:s,onCancel:d,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,m.jsx)(M.Z,{form:o,onFinish:c,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"User Role",name:"user_role",children:(0,m.jsx)(D.default,{children:l&&Object.entries(l).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:"Spend (USD)",name:"spend",tooltip:"(float) - Spend of all LLM calls completed by this user",help:"Across all keys (including keys with team_id).",children:(0,m.jsx)(G.Z,{min:0,step:.01})}),(0,m.jsx)(M.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Maximum budget of this user.",children:(0,m.jsx)(K,{min:0,step:.01})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})}):null},lp=l(15731);let lg=(e,s,l)=>[{header:"User ID",accessorKey:"user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)(Y.Z,{title:s.original.user_id,children:(0,m.jsx)("span",{className:"text-xs",children:s.original.user_id?"".concat(s.original.user_id.slice(0,7),"..."):"-"})})}},{header:"User Email",accessorKey:"user_email",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.user_email||"-"})}},{header:"Global Proxy Role",accessorKey:"user_role",cell:s=>{var l;let{row:t}=s;return(0,m.jsx)("span",{className:"text-xs",children:(null==e?void 0:null===(l=e[t.original.user_role])||void 0===l?void 0:l.ui_label)||"-"})}},{header:"User Spend ($ USD)",accessorKey:"spend",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.spend?s.original.spend.toFixed(2):"-"})}},{header:"User Max Budget ($ USD)",accessorKey:"max_budget",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.max_budget?s.original.max_budget:"Unlimited"})}},{header:()=>(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("span",{children:"SSO ID"}),(0,m.jsx)(Y.Z,{title:"SSO ID is the ID of the user in the SSO provider. If the user is not using SSO, this will be null.",children:(0,m.jsx)(lp.Z,{className:"w-4 h-4"})})]}),accessorKey:"sso_user_id",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:null!==s.original.sso_user_id?s.original.sso_user_id:"-"})}},{header:"API Keys",accessorKey:"key_count",cell:e=>{let{row:s}=e;return(0,m.jsx)(S.Z,{numItems:2,children:s.original.key_count>0?(0,m.jsxs)(eL.Z,{size:"xs",color:"indigo",children:[s.original.key_count," Keys"]}):(0,m.jsx)(eL.Z,{size:"xs",color:"gray",children:"No Keys"})})}},{header:"Created At",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.created_at?new Date(s.original.created_at).toLocaleDateString():"-"})}},{header:"Updated At",accessorKey:"updated_at",sortingFn:"datetime",cell:e=>{let{row:s}=e;return(0,m.jsx)("span",{className:"text-xs",children:s.original.updated_at?new Date(s.original.updated_at).toLocaleDateString():"-"})}},{id:"actions",header:"",cell:e=>{let{row:t}=e;return(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>s(t.original)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.original.user_id)})]})}}];var lj=l(16853);function lf(e){let{userData:s,onCancel:l,onSubmit:t,teams:a,accessToken:r,userID:i,userRole:n,userModels:o,possibleUIRoles:d}=e,[c]=M.Z.useForm();return u.useEffect(()=>{var e,l,t,a,r;c.setFieldsValue({user_id:s.user_id,user_email:null===(e=s.user_info)||void 0===e?void 0:e.user_email,user_role:null===(l=s.user_info)||void 0===l?void 0:l.user_role,models:(null===(t=s.user_info)||void 0===t?void 0:t.models)||[],max_budget:null===(a=s.user_info)||void 0===a?void 0:a.max_budget,metadata:(null===(r=s.user_info)||void 0===r?void 0:r.metadata)?JSON.stringify(s.user_info.metadata,null,2):void 0})},[s,c]),(0,m.jsxs)(M.Z,{form:c,onFinish:e=>{if(e.metadata&&"string"==typeof e.metadata)try{e.metadata=JSON.parse(e.metadata)}catch(e){console.error("Error parsing metadata JSON:",e);return}t(e)},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"User ID",name:"user_id",children:(0,m.jsx)(I.Z,{disabled:!0})}),(0,m.jsx)(M.Z.Item,{label:"Email",name:"user_email",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Global Proxy Role"," ",(0,m.jsx)(Y.Z,{title:"This is the role that the user will globally on the proxy. This role is independent of any team/org specific roles.",children:(0,m.jsx)(W.Z,{})})]}),name:"user_role",children:(0,m.jsx)(D.default,{children:d&&Object.entries(d).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(el.Z,{value:s,title:l,children:(0,m.jsxs)("div",{className:"flex",children:[l," ",(0,m.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},s)})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Personal Models"," ",(0,m.jsx)(Y.Z,{title:"Select which models this user can access outside of team-scope. Choose 'All Proxy Models' to grant access to all models available on the proxy.",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},disabled:!eZ.ZL.includes(n||""),children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(lj.Z,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:l,children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}function l_(e){var s,l,t,a,r,i,n,o,d,c,h,x,p,g,j,f,_,v,y,Z,N,w,k,I,T,A,E;let{userId:L,onClose:D,accessToken:M,userRole:R,onDelete:q,possibleUIRoles:U}=e,[z,V]=(0,u.useState)(null),[K,B]=(0,u.useState)(!1),[H,J]=(0,u.useState)(!0),[G,W]=(0,u.useState)(!1),[Y,$]=(0,u.useState)([]);u.useEffect(()=>{console.log("userId: ".concat(L,", userRole: ").concat(R,", accessToken: ").concat(M)),(async()=>{try{if(!M)return;let e=await (0,b.Br)(M,L,R||"",!1,null,null,!0);V(e);let s=(await (0,b.So)(M,L,R||"")).data.map(e=>e.id);$(s)}catch(e){console.error("Error fetching user data:",e),F.ZP.error("Failed to fetch user data")}finally{J(!1)}})()},[M,L,R]);let X=async()=>{try{if(!M)return;await (0,b.Eb)(M,[L]),F.ZP.success("User deleted successfully"),q&&q(),D()}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}},Q=async e=>{try{if(!M||!z)return;await (0,b.pf)(M,e,null),V({...z,user_info:{...z.user_info,user_email:e.user_email,models:e.models,max_budget:e.max_budget,metadata:e.metadata}}),F.ZP.success("User updated successfully"),W(!1)}catch(e){console.error("Error updating user:",e),F.ZP.error("Failed to update user")}};return H?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"Loading user data..."})]}):z?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(O.Z,{children:(null===(s=z.user_info)||void 0===s?void 0:s.user_email)||"User"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:z.user_id})]}),R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{icon:eK.Z,variant:"secondary",onClick:()=>B(!0),className:"flex items-center",children:"Delete User"})]}),K&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:X,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>B(!1),children:"Cancel"})]})]})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Details"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Spend"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",Number((null===(l=z.user_info)||void 0===l?void 0:l.spend)||0).toFixed(4)]}),(0,m.jsxs)(P.Z,{children:["of ",(null===(t=z.user_info)||void 0===t?void 0:t.max_budget)!==null?"$".concat(z.user_info.max_budget):"Unlimited"]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(a=z.teams)||void 0===a?void 0:a.length)||0," teams"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"API Keys"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(P.Z,{children:[(null===(r=z.keys)||void 0===r?void 0:r.length)||0," keys"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Personal Models"}),(0,m.jsx)("div",{className:"mt-2",children:(null===(n=z.user_info)||void 0===n?void 0:null===(i=n.models)||void 0===i?void 0:i.length)&&(null===(d=z.user_info)||void 0===d?void 0:null===(o=d.models)||void 0===o?void 0:o.length)>0?null===(h=z.user_info)||void 0===h?void 0:null===(c=h.models)||void 0===c?void 0:c.map((e,s)=>(0,m.jsx)(P.Z,{children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"User Settings"}),!G&&R&&eZ.LQ.includes(R)&&(0,m.jsx)(C.Z,{variant:"light",onClick:()=>W(!0),children:"Edit Settings"})]}),G&&z?(0,m.jsx)(lf,{userData:z,onCancel:()=>W(!1),onSubmit:Q,teams:z.teams,accessToken:M,userID:L,userRole:R,userModels:Y,possibleUIRoles:U}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"User ID"}),(0,m.jsx)(P.Z,{className:"font-mono",children:z.user_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Email"}),(0,m.jsx)(P.Z,{children:(null===(x=z.user_info)||void 0===x?void 0:x.user_email)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Role"}),(0,m.jsx)(P.Z,{children:(null===(p=z.user_info)||void 0===p?void 0:p.user_role)||"Not Set"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:(null===(g=z.user_info)||void 0===g?void 0:g.created_at)?new Date(z.user_info.created_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:(null===(j=z.user_info)||void 0===j?void 0:j.updated_at)?new Date(z.user_info.updated_at).toLocaleString():"Unknown"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Teams"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(f=z.teams)||void 0===f?void 0:f.length)&&(null===(_=z.teams)||void 0===_?void 0:_.length)>0?null===(v=z.teams)||void 0===v?void 0:v.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e.team_alias||e.team_id},s)):(0,m.jsx)(P.Z,{children:"No teams"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(Z=z.user_info)||void 0===Z?void 0:null===(y=Z.models)||void 0===y?void 0:y.length)&&(null===(w=z.user_info)||void 0===w?void 0:null===(N=w.models)||void 0===N?void 0:N.length)>0?null===(I=z.user_info)||void 0===I?void 0:null===(k=I.models)||void 0===k?void 0:k.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:e},s)):(0,m.jsx)(P.Z,{children:"All proxy models"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"API Keys"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:(null===(T=z.keys)||void 0===T?void 0:T.length)&&(null===(A=z.keys)||void 0===A?void 0:A.length)>0?z.keys.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-green-100 rounded text-xs",children:e.key_alias||e.token},s)):(0,m.jsx)(P.Z,{children:"No API keys"})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Metadata"}),(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify((null===(E=z.user_info)||void 0===E?void 0:E.metadata)||{},null,2)})]})]})]})})]})]})]}):(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)(C.Z,{icon:ez.Z,variant:"light",onClick:D,className:"mb-4",children:"Back to Users"}),(0,m.jsx)(P.Z,{children:"User not found"})]})}function lv(e){let{data:s=[],columns:l,isLoading:t=!1,onSortChange:a,currentSort:r,accessToken:i,userRole:n,possibleUIRoles:o}=e,[d,c]=u.useState([{id:(null==r?void 0:r.sortBy)||"created_at",desc:(null==r?void 0:r.sortOrder)==="desc"}]),[h,x]=u.useState(null),p=(0,e2.b7)({data:s,columns:l,state:{sorting:d},onSortingChange:e=>{if(c(e),e.length>0){let s=e[0],l=s.id,t=s.desc?"desc":"asc";null==a||a(l,t)}},getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0}),g=e=>{x(e)};return(u.useEffect(()=>{r&&c([{id:r.sortBy,desc:"desc"===r.sortOrder}])},[r]),h)?(0,m.jsx)(l_,{userId:h,onClose:()=>{x(null)},accessToken:i,userRole:n,possibleUIRoles:o}):(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:p.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:t?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"\uD83D\uDE85 Loading users..."})})})}):s.length>0?p.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:()=>{"user_id"===e.column.id&&g(e.getValue())},style:{cursor:"user_id"===e.column.id?"pointer":"default",color:"user_id"===e.column.id?"#3b82f6":"inherit"},children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No users found"})})})})})]})})})}var ly=l(67982),lb=l(87908),lZ=e=>{var s;let{accessToken:l,possibleUIRoles:t,userID:a,userRole:r}=e,[i,n]=(0,u.useState)(!0),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)({}),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)([]),{Paragraph:v}=et.default,{Option:y}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){n(!1);return}try{let e=await (0,b.NL)(l);if(d(e),p(e.values||{}),l)try{let e=await (0,b.So)(l,a,r);if(e&&e.data){let s=e.data.map(e=>e.id);_(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching SSO settings:",e),F.ZP.error("Failed to fetch SSO settings")}finally{n(!1)}})()},[l]);let Z=async()=>{if(l){j(!0);try{let e=await (0,b.nd)(l,x);d({...o,values:e.settings}),h(!1)}catch(e){console.error("Error updating SSO settings:",e),F.ZP.error("Failed to update settings")}finally{j(!1)}}},N=(e,s)=>{p(l=>({...l,[e]:s}))},w=(e,s,l)=>{var a;let r=s.type;return"user_role"===e&&t?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:Object.entries(t).filter(e=>{let[s]=e;return s.includes("internal_user")}).map(e=>{let[s,{ui_label:l,description:t}]=e;return(0,m.jsx)(y,{value:s,children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{children:l}),(0,m.jsx)("span",{className:"ml-2 text-xs text-gray-500",children:t})]})},s)})}):"budget_duration"===e?(0,m.jsx)(ek,{value:x[e]||null,onChange:s=>N(e,s),className:"mt-2"}):"boolean"===r?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!x[e],onChange:s=>N(e,s)})}):"array"===r&&(null===(a=s.items)||void 0===a?void 0:a.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:x[e]||[],onChange:s=>N(e,s),className:"mt-2",children:f.map(e=>(0,m.jsx)(y,{value:e,children:H(e)},e))}):"string"===r&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:x[e]||"",onChange:s=>N(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(y,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==x[e]?String(x[e]):"",onChange:s=>N(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},k=(e,s)=>{if(null==s)return(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"});if("user_role"===e&&t&&t[s]){let{ui_label:e,description:l}=t[s];return(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-medium",children:e}),l&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:l})]})}return"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)})};return i?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):o?(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex justify-end items-center mb-4",children:!i&&o&&(c?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{h(!1),p(o.values||{})},disabled:g,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:Z,loading:g,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>h(!0),children:"Edit Settings"}))}),(null==o?void 0:null===(s=o.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(v,{className:"mb-4",children:o.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=o;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(v,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),c?(0,m.jsx)("div",{className:"mt-2",children:w(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:k(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No settings available or you do not have permission to view them."})})},lN=l(19616);console.log=function(){};let lw={email:"",user_id:"",user_role:"",sso_user_id:"",team:"",model:"",min_spend:null,max_spend:null,sort_by:"created_at",sort_order:"desc"};var lk=e=>{var s;let{accessToken:l,token:t,userRole:a,userID:r,teams:i}=e,n=(0,g.NL)(),[o,d]=(0,u.useState)(1),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)("users"),[N,w]=(0,u.useState)(lw),[k,S,I]=(0,lN.G)(N,{wait:300}),[T,A]=(0,u.useState)(!1);(0,u.useEffect)(()=>()=>{I.cancel()},[I]);let E=e=>{w(s=>{let l={...s,...e};return S(l),l})},P=async()=>{if(_&&l)try{await (0,b.Eb)(l,[_]),n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let s=e.users.filter(e=>e.user_id!==_);return{...e,users:s}}),F.ZP.success("User deleted successfully")}catch(e){console.error("Error deleting user:",e),F.ZP.error("Failed to delete user")}f(!1),v(null)},O=async()=>{p(null),h(!1)},L=async e=>{if(console.log("inside handleEditSubmit:",e),l&&t&&a&&r){try{let s=await (0,b.pf)(l,e,null);n.setQueriesData({queryKey:["userList"]},e=>{if(void 0===e)return e;let l=e.users.map(e=>e.user_id===s.data.user_id?e1(e,s.data):e);return{...e,users:l}}),F.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}p(null),h(!1)}},D=async e=>{d(e)},M=(0,eY.a)({queryKey:["userList",{debouncedFilter:k,currentPage:o}],queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.Of)(l,k.user_id?[k.user_id]:null,o,25,k.email||null,k.user_role||null,k.team||null,k.sso_user_id||null,k.sort_by,k.sort_order)},enabled:!!(l&&t&&a&&r),placeholderData:e=>e}),R=M.data,q=(0,eY.a)({queryKey:["userRoles"],initialData:()=>({}),queryFn:async()=>{if(!l)throw Error("Access token required");return await (0,b.lg)(l)},enabled:!!(l&&t&&a&&r)}).data;if(M.isLoading||!l||!t||!a||!r)return(0,m.jsx)("div",{children:"Loading..."});let U=lg(q,e=>{p(e),h(!0)},e=>{v(e),f(!0)});return(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"Users"}),(0,m.jsx)("div",{className:"flex space-x-3",children:(0,m.jsx)(ev,{userID:r,accessToken:l,teams:i,possibleUIRoles:q})})]}),(0,m.jsxs)(eF.Z,{defaultIndex:0,onIndexChange:e=>Z(0===e?"users":"settings"),children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Users"}),(0,m.jsx)(eM.Z,{children:"Default User Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by email...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.email,onChange:e=>E({email:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(T?"bg-gray-100":""),onClick:()=>A(!T),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(N.user_id||N.user_role||N.team)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{E(lw)},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),T&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Filter by User ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.user_id,onChange:e=>E({user_id:e.target.value})}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.user_role,onValueChange:e=>E({user_role:e}),placeholder:"Select Role",children:Object.entries(q).map(e=>{let[s,l]=e;return(0,m.jsx)(el.Z,{value:s,children:l.ui_label},s)})})}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:N.team,onValueChange:e=>E({team:e}),placeholder:"Select Team",children:null==i?void 0:i.map(e=>(0,m.jsx)(el.Z,{value:e.team_id,children:e.team_alias||e.team_id},e.team_id))})}),(0,m.jsx)("div",{className:"relative w-64",children:(0,m.jsx)("input",{type:"text",placeholder:"Filter by SSO ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:N.sso_user_id,onChange:e=>E({sso_user_id:e.target.value})})})]}),(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",R&&R.users&&R.users.length>0?(R.page-1)*R.page_size+1:0," ","-"," ",R&&R.users?Math.min(R.page*R.page_size,R.total):0," ","of ",R?R.total:0," results"]}),(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>D(o-1),disabled:1===o,className:"px-3 py-1 text-sm border rounded-md ".concat(1===o?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Previous"}),(0,m.jsx)("button",{onClick:()=>D(o+1),disabled:!R||o>=R.total_pages,className:"px-3 py-1 text-sm border rounded-md ".concat(!R||o>=R.total_pages?"bg-gray-100 text-gray-400 cursor-not-allowed":"hover:bg-gray-50"),children:"Next"})]})]})]})}),(0,m.jsx)(lv,{data:(null===(s=M.data)||void 0===s?void 0:s.users)||[],columns:U,isLoading:M.isLoading,accessToken:l,userRole:a,onSortChange:(e,s)=>{E({sort_by:e,sort_order:s})},currentSort:{sortBy:N.sort_by,sortOrder:N.sort_order},possibleUIRoles:q})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lZ,{accessToken:l,possibleUIRoles:q,userID:r,userRole:a})})]})]}),(0,m.jsx)(lx,{visible:c,possibleUIRoles:q,onCancel:O,user:x,onSubmit:L}),j&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,m.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",_]})]})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:P,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})})]})},lS=e=>{var s;let{accessToken:l,userID:t,userRole:a}=e,[r,i]=(0,u.useState)(!0),[n,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)({}),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)([]),{Paragraph:_}=et.default,{Option:v}=D.default;(0,u.useEffect)(()=>{(async()=>{if(!l){i(!1);return}try{let e=await (0,b.EB)(l);if(o(e),x(e.values||{}),l)try{let e=await (0,b.So)(l,t,a);if(e&&e.data){let s=e.data.map(e=>e.id);f(s)}}catch(e){console.error("Error fetching available models:",e)}}catch(e){console.error("Error fetching team SSO settings:",e),F.ZP.error("Failed to fetch team settings")}finally{i(!1)}})()},[l]);let y=async()=>{if(l){g(!0);try{let e=await (0,b.r1)(l,h);o({...n,values:e.settings}),c(!1),F.ZP.success("Default team settings updated successfully")}catch(e){console.error("Error updating team settings:",e),F.ZP.error("Failed to update team settings")}finally{g(!1)}}},Z=(e,s)=>{x(l=>({...l,[e]:s}))},N=(e,s,l)=>{var t;let a=s.type;return"budget_duration"===e?(0,m.jsx)(ek,{value:h[e]||null,onChange:s=>Z(e,s),className:"mt-2"}):"boolean"===a?(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)(sY.Z,{checked:!!h[e],onChange:s=>Z(e,s)})}):"array"===a&&(null===(t=s.items)||void 0===t?void 0:t.enum)?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:s.items.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):"models"===e?(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},value:h[e]||[],onChange:s=>Z(e,s),className:"mt-2",children:j.map(e=>(0,m.jsx)(v,{value:e,children:H(e)},e))}):"string"===a&&s.enum?(0,m.jsx)(D.default,{style:{width:"100%"},value:h[e]||"",onChange:s=>Z(e,s),className:"mt-2",children:s.enum.map(e=>(0,m.jsx)(v,{value:e,children:e},e))}):(0,m.jsx)(I.Z,{value:void 0!==h[e]?String(h[e]):"",onChange:s=>Z(e,s.target.value),placeholder:s.description||"",className:"mt-2"})},w=(e,s)=>null==s?(0,m.jsx)("span",{className:"text-gray-400",children:"Not set"}):"budget_duration"===e?(0,m.jsx)("span",{children:ew(s)}):"boolean"==typeof s?(0,m.jsx)("span",{children:s?"Enabled":"Disabled"}):"models"===e&&Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:H(e)},s))}):"object"==typeof s?Array.isArray(s)?0===s.length?(0,m.jsx)("span",{className:"text-gray-400",children:"None"}):(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:s.map((e,s)=>(0,m.jsx)("span",{className:"px-2 py-1 bg-blue-100 rounded text-xs",children:"object"==typeof e?JSON.stringify(e):String(e)},s))}):(0,m.jsx)("pre",{className:"bg-gray-100 p-2 rounded text-xs overflow-auto mt-1",children:JSON.stringify(s,null,2)}):(0,m.jsx)("span",{children:String(s)});return r?(0,m.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,m.jsx)(lb.Z,{size:"large"})}):n?(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{className:"text-xl",children:"Default Team Settings"}),!r&&n&&(d?(0,m.jsxs)("div",{className:"flex gap-2",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{c(!1),x(n.values||{})},disabled:p,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:y,loading:p,children:"Save Changes"})]}):(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Settings"}))]}),(0,m.jsx)(P.Z,{children:"These settings will be applied by default when creating new teams."}),(null==n?void 0:null===(s=n.schema)||void 0===s?void 0:s.description)&&(0,m.jsx)(_,{className:"mb-4 mt-2",children:n.schema.description}),(0,m.jsx)(ly.Z,{}),(0,m.jsx)("div",{className:"mt-4 space-y-4",children:(()=>{let{values:e,schema:s}=n;return s&&s.properties?Object.entries(s.properties).map(s=>{let[l,t]=s,a=e[l],r=l.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,m.jsxs)("div",{className:"mb-6 pb-6 border-b border-gray-200 last:border-0",children:[(0,m.jsx)(P.Z,{className:"font-medium text-lg",children:r}),(0,m.jsx)(_,{className:"text-sm text-gray-500 mt-1",children:t.description||"No description available"}),d?(0,m.jsx)("div",{className:"mt-2",children:N(l,t,a)}):(0,m.jsx)("div",{className:"mt-1 p-2 bg-gray-50 rounded",children:w(l,a)})]},l)}):(0,m.jsx)(P.Z,{children:"No schema information available"})})()})]}):(0,m.jsx)(eD.Z,{children:(0,m.jsx)(P.Z,{children:"No team settings available or you do not have permission to view them."})})},lC=e=>{let{accessToken:s,userID:l}=e,[t,a]=(0,u.useState)([]);(0,u.useEffect)(()=>{(async()=>{if(s&&l)try{let e=await (0,b.a6)(s);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[s,l]);let r=async e=>{if(s&&l)try{await (0,b.cu)(s,e,{user_id:l,role:"user"}),F.ZP.success("Successfully joined team"),a(s=>s.filter(s=>s.team_id!==e))}catch(e){console.error("Error joining team:",e),F.ZP.error("Failed to join team")}};return(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Description"}),(0,m.jsx)(e7.Z,{children:"Members"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsxs)(e3.Z,{children:[t.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.team_alias})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.description||"No description available"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[e.members_with_roles.length," members"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,s)=>(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},s)):(0,m.jsx)(eL.Z,{size:"xs",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})})})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{size:"xs",variant:"secondary",onClick:()=>r(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:5,className:"text-center",children:(0,m.jsx)(P.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};let lI=(e,s)=>{let l=[];return e&&e.models.length>0?(console.log("organization.models: ".concat(e.models)),l=e.models):l=s,J(l,s)};var lT=e=>{let{teams:s,searchParams:l,accessToken:t,setTeams:a,userID:r,userRole:i,organizations:n}=e,[o,d]=(0,u.useState)(""),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"});(0,u.useEffect)(()=>{console.log("inside useeffect - ".concat(o)),t&&w(t,r,i,c,a),ew()},[o]);let[v]=M.Z.useForm(),[y]=M.Z.useForm(),{Title:Z,Paragraph:N}=et.default,[O,L]=(0,u.useState)(""),[q,V]=(0,u.useState)(!1),[J,G]=(0,u.useState)(null),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(!1),[es,ea]=(0,u.useState)(!1),[er,ei]=(0,u.useState)(!1),[en,eo]=(0,u.useState)(!1),[ed,ec]=(0,u.useState)([]),[em,eu]=(0,u.useState)(!1),[eh,ex]=(0,u.useState)(null),[ep,eg]=(0,u.useState)([]),[ej,ef]=(0,u.useState)({}),[e_,ev]=(0,u.useState)([]);(0,u.useEffect)(()=>{console.log("currentOrgForCreateTeam: ".concat(x));let e=lI(x,ed);console.log("models: ".concat(e)),eg(e),v.setFieldValue("models",[])},[x,ed]),(0,u.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,b.t3)(t)).guardrails.map(e=>e.guardrail_name);ev(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let ey=async e=>{ex(e),eu(!0)},eb=async()=>{if(null!=eh&&null!=s&&null!=t){try{await (0,b.rs)(t,eh),w(t,r,i,c,a)}catch(e){console.error("Error deleting the team:",e)}eu(!1),ex(null)}};(0,u.useEffect)(()=>{(async()=>{try{if(null===r||null===i||null===t)return;let e=await B(r,i,t);e&&ec(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,r,i,s]);let eN=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var l;let r=null==e?void 0:e.team_alias,i=null!==(l=null==s?void 0:s.map(e=>e.team_alias))&&void 0!==l?l:[],n=(null==e?void 0:e.organization_id)||(null==c?void 0:c.organization_id);if(""===n||"string"!=typeof n?e.organization_id=null:e.organization_id=n.trim(),i.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));F.ZP.info("Creating Team");let o=await (0,b.hT)(t,e);null!==s?a([...s,o]):a([o]),console.log("response for team create call: ".concat(o)),F.ZP.success("Team created"),v.resetFields(),ea(!1)}}catch(e){console.error("Error creating the team:",e),F.ZP.error("Error creating the team: "+e,20)}},ew=()=>{d(new Date().toLocaleString())},ek=(e,s)=>{let l={...f,[e]:s};_(l),t&&(0,b.JO)(t,l.organization_id||null,null,l.team_id||null,l.team_alias||null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})};return(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:$?(0,m.jsx)(sB,{teamId:$,onUpdate:e=>{a(s=>null==s?s:s.map(s=>e.team_id===s.team_id?e1(s,e):s))},onClose:()=>{X(null),ee(!1)},accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let s=0;se.team_id===$)),is_proxy_admin:"Admin"==i,userModels:ed,editTeam:Q}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Your Teams"}),(0,m.jsx)(eM.Z,{children:"Available Teams"}),(0,eZ.tY)(i||"")&&(0,m.jsx)(eM.Z,{children:"Default Team Settings"})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[o&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",o]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:ew})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(P.Z,{children:["Click on “Team ID” to view team details ",(0,m.jsx)("b",{children:"and"})," manage team members."]}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"w-full mx-auto flex-auto overflow-hidden overflow-y-auto max-h-[50vh]",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Team Name...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_alias,onChange:e=>ek("team_alias",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2 ".concat(g?"bg-gray-100":""),onClick:()=>j(!g),children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"})}),"Filters",(f.team_id||f.team_alias||f.organization_id)&&(0,m.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500"})]}),(0,m.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>{_({team_id:"",team_alias:"",organization_id:"",sort_by:"created_at",sort_order:"desc"}),t&&(0,b.JO)(t,null,r||null,null,null).then(e=>{e&&e.teams&&a(e.teams)}).catch(e=>{console.error("Error fetching teams:",e)})},children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Reset Filters"]})]}),g&&(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mt-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Enter Team ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:f.team_id,onChange:e=>ek("team_id",e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]}),(0,m.jsx)("div",{className:"w-64",children:(0,m.jsx)(eO.Z,{value:f.organization_id||"",onValueChange:e=>ek("organization_id",e),placeholder:"Select Organization",children:null==n?void 0:n.map(e=>(0,m.jsx)(el.Z,{value:e.organization_id||"",children:e.organization_alias||e.organization_id},e.organization_id))})})]})]})}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Team Name"}),(0,m.jsx)(e7.Z,{children:"Team ID"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"Organization"}),(0,m.jsx)(e7.Z,{children:"Info"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.filter(e=>!c||e.organization_id===c.organization_id).sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.team_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{X(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,m.jsx)(e6.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!==e.max_budget&&void 0!==e.max_budget?e.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:(0,m.jsx)(P.Z,{children:"All Proxy Models"})},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(P.Z,{children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)})},s))}):null}),(0,m.jsx)(e6.Z,{children:e.organization_id}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].keys&&ej[e.team_id].keys.length," ","Keys"]}),(0,m.jsxs)(P.Z,{children:[ej&&e.team_id&&ej[e.team_id]&&ej[e.team_id].members_with_roles&&ej[e.team_id].members_with_roles.length," ","Members"]})]}),(0,m.jsx)(e6.Z,{children:"Admin"==i?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{X(e.team_id),ee(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>ey(e.team_id),icon:eK.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),em&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:eb,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{eu(!1),ex(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==i||"Org Admin"==i?(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>ea(!0),children:"+ Create New Team"}),(0,m.jsx)(R.Z,{title:"Create Team",visible:es,width:800,footer:null,onOk:()=>{ea(!1),v.resetFields()},onCancel:()=>{ea(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:eN,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Organization"," ",(0,m.jsx)(Y.Z,{title:(0,m.jsxs)("span",{children:["Organizations can have multiple teams. Learn more about"," ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/user_management_heirarchy",target:"_blank",rel:"noopener noreferrer",style:{color:"#1890ff",textDecoration:"underline"},onClick:e=>e.stopPropagation(),children:"user management hierarchy"})]}),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"organization_id",initialValue:c?c.organization_id:null,className:"mt-8",children:(0,m.jsx)(D.default,{showSearch:!0,allowClear:!0,placeholder:"Search or select an Organization",onChange:e=>{v.setFieldValue("organization_id",e),p((null==n?void 0:n.find(s=>s.organization_id===e))||null)},filterOption:(e,s)=>{var l;return!!s&&((null===(l=s.children)||void 0===l?void 0:l.toString())||"").toLowerCase().includes(e.toLowerCase())},optionFilterProp:"children",children:null==n?void 0:n.map(e=>(0,m.jsxs)(D.default.Option,{value:e.organization_id,children:[(0,m.jsx)("span",{className:"font-medium",children:e.organization_alias})," ",(0,m.jsxs)("span",{className:"text-gray-500",children:["(",e.organization_id,")"]})]},e.organization_id))})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Models"," ",(0,m.jsx)(Y.Z,{title:"These are the models that your selected team has access to",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ep.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Additional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Team ID",name:"team_id",help:"ID of the team you want to create. If not provided, it will be generated automatically.",children:(0,m.jsx)(I.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",help:"Additional team metadata. Enter metadata as JSON object.",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Guardrails"," ",(0,m.jsx)(Y.Z,{title:"Setup your first guardrail",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,m.jsx)(D.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:e_.map(e=>({value:e,label:e}))})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lC,{accessToken:t,userID:r})}),(0,eZ.tY)(i||"")&&(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lS,{accessToken:t,userID:r||"",userRole:i||""})})]})]})})},lA=e=>{var s,l;let{organizationId:t,onClose:a,accessToken:r,is_org_admin:i,is_proxy_admin:n,userModels:o,editOrg:d}=e,[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(!0),[g]=M.Z.useForm(),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(!1),[y,Z]=(0,u.useState)(!1),[N,w]=(0,u.useState)(null),k=i||n,T=async()=>{try{if(p(!0),!r)return;let e=await (0,b.t$)(r,t);h(e)}catch(e){F.ZP.error("Failed to load organization information"),console.error("Error fetching organization info:",e)}finally{p(!1)}};(0,u.useEffect)(()=>{T()},[t,r]);let A=async e=>{try{if(null==r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.vh)(r,t,s),F.ZP.success("Organization member added successfully"),v(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to add organization member"),console.error("Error adding organization member:",e)}},E=async e=>{try{if(!r)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,b.LY)(r,t,s),F.ZP.success("Organization member updated successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to update organization member"),console.error("Error updating organization member:",e)}},L=async e=>{try{if(!r)return;await (0,b.Sb)(r,t,e.user_id),F.ZP.success("Organization member deleted successfully"),Z(!1),g.resetFields(),T()}catch(e){F.ZP.error("Failed to delete organization member"),console.error("Error deleting organization member:",e)}},R=async e=>{try{if(!r)return;let s={organization_id:t,organization_alias:e.organization_alias,models:e.models,litellm_budget_table:{tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,max_budget:e.max_budget,budget_duration:e.budget_duration},metadata:e.metadata?JSON.parse(e.metadata):null};await (0,b.VA)(r,s),F.ZP.success("Organization settings updated successfully"),f(!1),T()}catch(e){F.ZP.error("Failed to update organization settings"),console.error("Error updating organization:",e)}};return x?(0,m.jsx)("div",{className:"p-4",children:"Loading..."}):c?(0,m.jsxs)("div",{className:"w-full h-screen p-4 bg-white",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:a,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:c.organization_alias}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:c.organization_id})]})}),(0,m.jsxs)(eF.Z,{defaultIndex:d?2:0,children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"}),(0,m.jsx)(eM.Z,{children:"Members"}),(0,m.jsx)(eM.Z,{children:"Settings"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Organization Details"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["Created: ",new Date(c.created_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Updated: ",new Date(c.updated_at).toLocaleDateString()]}),(0,m.jsxs)(P.Z,{children:["Created By: ",c.created_by]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Budget Status"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(O.Z,{children:["$",c.spend.toFixed(6)]}),(0,m.jsxs)(P.Z,{children:["of ",null===c.litellm_budget_table.max_budget?"Unlimited":"$".concat(c.litellm_budget_table.max_budget)]}),c.litellm_budget_table.budget_duration&&(0,m.jsxs)(P.Z,{className:"text-gray-500",children:["Reset: ",c.litellm_budget_table.budget_duration]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Rate Limits"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsxs)(P.Z,{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)(P.Z,{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]}),c.litellm_budget_table.max_parallel_requests&&(0,m.jsxs)(P.Z,{children:["Max Parallel Requests: ",c.litellm_budget_table.max_parallel_requests]})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Models"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Teams"}),(0,m.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:null===(s=c.teams)||void 0===s?void 0:s.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e.team_id},s))})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[75vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"User ID"}),(0,m.jsx)(e7.Z,{children:"Role"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Created At"}),(0,m.jsx)(e7.Z,{})]})}),(0,m.jsx)(e3.Z,{children:null===(l=c.members)||void 0===l?void 0:l.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_id})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{className:"font-mono",children:e.user_role})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["$",e.spend.toFixed(6)]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:new Date(e.created_at).toLocaleString()})}),(0,m.jsx)(e6.Z,{children:k&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{w({role:e.user_role,user_email:e.user_email,user_id:e.user_id}),Z(!0)}}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>{L(e)}})]})})]},s))})]})}),k&&(0,m.jsx)(C.Z,{onClick:()=>{v(!0)},children:"Add Member"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Organization Settings"}),k&&!j&&(0,m.jsx)(C.Z,{onClick:()=>f(!0),children:"Edit Settings"})]}),j?(0,m.jsxs)(M.Z,{form:g,onFinish:R,initialValues:{organization_alias:c.organization_alias,models:c.models,tpm_limit:c.litellm_budget_table.tpm_limit,rpm_limit:c.litellm_budget_table.rpm_limit,max_budget:c.litellm_budget_table.max_budget,budget_duration:c.litellm_budget_table.budget_duration,metadata:c.metadata?JSON.stringify(c.metadata,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),o.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,style:{width:"100%"}})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>f(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization Name"}),(0,m.jsx)("div",{children:c.organization_alias})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Organization ID"}),(0,m.jsx)("div",{className:"font-mono",children:c.organization_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:new Date(c.created_at).toLocaleString()})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Models"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-1",children:c.models.map((e,s)=>(0,m.jsx)(eL.Z,{color:"red",children:e},s))})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Rate Limits"}),(0,m.jsxs)("div",{children:["TPM: ",c.litellm_budget_table.tpm_limit||"Unlimited"]}),(0,m.jsxs)("div",{children:["RPM: ",c.litellm_budget_table.rpm_limit||"Unlimited"]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Budget"}),(0,m.jsxs)("div",{children:["Max: ",null!==c.litellm_budget_table.max_budget?"$".concat(c.litellm_budget_table.max_budget):"No Limit"]}),(0,m.jsxs)("div",{children:["Reset: ",c.litellm_budget_table.budget_duration||"Never"]})]})]})]})})]})]}),(0,m.jsx)(sK,{isVisible:_,onCancel:()=>v(!1),onSubmit:A,accessToken:r,title:"Add Organization Member",roles:[{label:"org_admin",value:"org_admin",description:"Can add and remove members, and change their roles."},{label:"internal_user",value:"internal_user",description:"Can view/create keys for themselves within organization."},{label:"internal_user_viewer",value:"internal_user_viewer",description:"Can only view their keys within organization."}],defaultRole:"internal_user"}),(0,m.jsx)(sV,{visible:y,onCancel:()=>Z(!1),onSubmit:E,initialData:N,mode:"edit",config:{title:"Edit Member",showEmail:!0,showUserId:!0,roleOptions:[{label:"Org Admin",value:"org_admin"},{label:"Internal User",value:"internal_user"},{label:"Internal User Viewer",value:"internal_user_viewer"}]}})]}):(0,m.jsx)("div",{className:"p-4",children:"Organization not found"})};let lE=async(e,s)=>{s(await (0,b.r6)(e))};var lP=e=>{let{organizations:s,userRole:l,userModels:t,accessToken:a,lastRefreshed:r,handleRefreshClick:i,currentOrg:n,guardrailsList:o=[],setOrganizations:d,premiumUser:c}=e,[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),[j,f]=(0,u.useState)(!1),[_,v]=(0,u.useState)(null),[y,Z]=(0,u.useState)(!1),[N]=M.Z.useForm();(0,u.useEffect)(()=>{0===s.length&&a&&lE(a,d)},[s,a]);let w=e=>{e&&(v(e),f(!0))},T=async()=>{if(_&&a)try{await (0,b.cq)(a,_),F.ZP.success("Organization deleted successfully"),f(!1),v(null),lE(a,d)}catch(e){console.error("Error deleting organization:",e)}},A=async e=>{try{if(!a)return;console.log("values in organizations new create call: ".concat(JSON.stringify(e))),await (0,b.H1)(a,e),Z(!1),N.resetFields(),lE(a,d)}catch(e){console.error("Error creating organization:",e)}};return c?h?(0,m.jsx)(lA,{organizationId:h,onClose:()=>{x(null),g(!1)},accessToken:a,is_org_admin:!0,is_proxy_admin:"Admin"===l,userModels:t,editOrg:p}):(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsx)("div",{className:"flex",children:(0,m.jsx)(eM.Z,{children:"Your Organizations"})}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[r&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",r]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:i})]})]}),(0,m.jsx)(eU.Z,{children:(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(P.Z,{children:"Click on “Organization ID” to view organization details."}),(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(eD.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Organization ID"}),(0,m.jsx)(e7.Z,{children:"Organization Name"}),(0,m.jsx)(e7.Z,{children:"Created"}),(0,m.jsx)(e7.Z,{children:"Spend (USD)"}),(0,m.jsx)(e7.Z,{children:"Budget (USD)"}),(0,m.jsx)(e7.Z,{children:"Models"}),(0,m.jsx)(e7.Z,{children:"TPM / RPM Limits"}),(0,m.jsx)(e7.Z,{children:"Info"}),(0,m.jsx)(e7.Z,{children:"Actions"})]})}),(0,m.jsx)(e3.Z,{children:s&&s.length>0?s.sort((e,s)=>new Date(s.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>{var s,t,a,r,i,n,o,d,c;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.organization_id,children:(0,m.jsxs)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>x(e.organization_id),children:[null===(s=e.organization_id)||void 0===s?void 0:s.slice(0,7),"..."]})})})}),(0,m.jsx)(e6.Z,{children:e.organization_alias}),(0,m.jsx)(e6.Z,{children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,m.jsx)(e6.Z,{children:e.spend}),(0,m.jsx)(e6.Z,{children:(null===(t=e.litellm_budget_table)||void 0===t?void 0:t.max_budget)!==null&&(null===(a=e.litellm_budget_table)||void 0===a?void 0:a.max_budget)!==void 0?null===(r=e.litellm_budget_table)||void 0===r?void 0:r.max_budget:"No limit"}),(0,m.jsx)(e6.Z,{children:Array.isArray(e.models)&&(0,m.jsx)("div",{className:"flex flex-col",children:0===e.models.length?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"}):e.models.map((e,s)=>"all-proxy-models"===e?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Proxy Models"},s):(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:e.length>30?"".concat(H(e).slice(0,30),"..."):H(e)},s))})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:["TPM: ",(null===(i=e.litellm_budget_table)||void 0===i?void 0:i.tpm_limit)?null===(n=e.litellm_budget_table)||void 0===n?void 0:n.tpm_limit:"Unlimited",(0,m.jsx)("br",{}),"RPM: ",(null===(o=e.litellm_budget_table)||void 0===o?void 0:o.rpm_limit)?null===(d=e.litellm_budget_table)||void 0===d?void 0:d.rpm_limit:"Unlimited"]})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(P.Z,{children:[(null===(c=e.members)||void 0===c?void 0:c.length)||0," Members"]})}),(0,m.jsx)(e6.Z,{children:"Admin"===l&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{x(e.organization_id),g(!0)}}),(0,m.jsx)(sC.Z,{onClick:()=>w(e.organization_id),icon:eK.Z,size:"sm"})]})})]},e.organization_id)}):null})]})})}),("Admin"===l||"Org Admin"===l)&&(0,m.jsxs)(k.Z,{numColSpan:1,children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>Z(!0),children:"+ Create New Organization"}),(0,m.jsx)(R.Z,{title:"Create Organization",visible:y,width:800,footer:null,onCancel:()=>{Z(!1),N.resetFields()},children:(0,m.jsxs)(M.Z,{form:N,onFinish:A,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Organization Name",name:"organization_alias",rules:[{required:!0,message:"Please input an organization name"}],children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Models",name:"models",children:(0,m.jsxs)(D.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,m.jsx)(D.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),t&&t.length>0&&t.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))]})}),(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(K,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})}),(0,m.jsx)(M.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,m.jsx)(K,{step:1,width:400})}),(0,m.jsx)(M.Z.Item,{label:"Metadata",name:"metadata",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Organization"})})]})})]})]})]})}),j?(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Organization"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this organization?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:T,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{f(!1),v(null)},children:"Cancel"})]})]})]})}):(0,m.jsx)(m.Fragment,{})]}):(0,m.jsx)("div",{children:(0,m.jsxs)(P.Z,{children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,m.jsx)("a",{href:"https://litellm.ai/pricing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})},lO=l(94789);let lL={google:"https://artificialanalysis.ai/img/logos/google_small.svg",microsoft:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",okta:"https://www.okta.com/sites/default/files/Okta_Logo_BrightBlue_Medium.png",generic:""},lD={google:{envVarMap:{google_client_id:"GOOGLE_CLIENT_ID",google_client_secret:"GOOGLE_CLIENT_SECRET"},fields:[{label:"GOOGLE CLIENT ID",name:"google_client_id"},{label:"GOOGLE CLIENT SECRET",name:"google_client_secret"}]},microsoft:{envVarMap:{microsoft_client_id:"MICROSOFT_CLIENT_ID",microsoft_client_secret:"MICROSOFT_CLIENT_SECRET",microsoft_tenant:"MICROSOFT_TENANT"},fields:[{label:"MICROSOFT CLIENT ID",name:"microsoft_client_id"},{label:"MICROSOFT CLIENT SECRET",name:"microsoft_client_secret"},{label:"MICROSOFT TENANT",name:"microsoft_tenant"}]},okta:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint",placeholder:"https://your-okta-domain/authorize"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint",placeholder:"https://your-okta-domain/token"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint",placeholder:"https://your-okta-domain/userinfo"}]},generic:{envVarMap:{generic_client_id:"GENERIC_CLIENT_ID",generic_client_secret:"GENERIC_CLIENT_SECRET",generic_authorization_endpoint:"GENERIC_AUTHORIZATION_ENDPOINT",generic_token_endpoint:"GENERIC_TOKEN_ENDPOINT",generic_userinfo_endpoint:"GENERIC_USERINFO_ENDPOINT"},fields:[{label:"GENERIC CLIENT ID",name:"generic_client_id"},{label:"GENERIC CLIENT SECRET",name:"generic_client_secret"},{label:"AUTHORIZATION ENDPOINT",name:"generic_authorization_endpoint"},{label:"TOKEN ENDPOINT",name:"generic_token_endpoint"},{label:"USERINFO ENDPOINT",name:"generic_userinfo_endpoint"}]}};var lM=e=>{let{isAddSSOModalVisible:s,isInstructionsModalVisible:l,handleAddSSOOk:t,handleAddSSOCancel:a,handleShowInstructions:r,handleInstructionsOk:i,handleInstructionsCancel:n,form:o}=e,d=e=>{let s=lD[e];return s?s.fields.map(e=>(0,m.jsx)(M.Z.Item,{label:e.label,name:e.name,rules:[{required:!0,message:"Please enter the ".concat(e.label.toLowerCase())}],children:e.name.includes("client")?(0,m.jsx)(z.default.Password,{}):(0,m.jsx)(I.Z,{placeholder:e.placeholder})},e.name)):null};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(R.Z,{title:"Add SSO",visible:s,width:800,footer:null,onOk:t,onCancel:a,children:(0,m.jsxs)(M.Z,{form:o,onFinish:r,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"SSO Provider",name:"sso_provider",rules:[{required:!0,message:"Please select an SSO provider"}],children:(0,m.jsx)(D.default,{children:Object.entries(lL).map(e=>{let[s,l]=e;return(0,m.jsx)(D.default.Option,{value:s,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center",padding:"4px 0"},children:[l&&(0,m.jsx)("img",{src:l,alt:s,style:{height:24,width:24,marginRight:12,objectFit:"contain"}}),(0,m.jsxs)("span",{children:[s.charAt(0).toUpperCase()+s.slice(1)," SSO"]})]})},s)})})}),(0,m.jsx)(M.Z.Item,{noStyle:!0,shouldUpdate:(e,s)=>e.sso_provider!==s.sso_provider,children:e=>{let{getFieldValue:s}=e,l=s("sso_provider");return l?d(l):null}}),(0,m.jsx)(M.Z.Item,{label:"Proxy Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,m.jsx)(I.Z,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,m.jsxs)(R.Z,{title:"SSO Setup Instructions",visible:l,width:800,footer:null,onOk:i,onCancel:n,children:[(0,m.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,m.jsx)(P.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{onClick:i,children:"Done"})})]})]})},lF=l(62272),lR=l(92403),lq=l(29271),lU=l(34419);let lz=e=>{if(!e)return"An unknown error occurred";if("string"==typeof e)return e;if(e.message)try{let s=JSON.parse(e.message);if(s.error&&s.error.message)return s.error.message;return"string"==typeof s?s:JSON.stringify(s,null,2)}catch(s){return e.message}if(e.response&&e.response.data){if("string"==typeof e.response.data)return e.response.data;if(e.response.data.message)return e.response.data.message;if(e.response.data.error)return"string"==typeof e.response.data.error?e.response.data.error:e.response.data.error.message||JSON.stringify(e.response.data.error)}return String(e)};var lV=e=>{let{accessToken:s,userID:l,proxySettings:t}=e,[a]=M.Z.useForm(),[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(null),[d,c]=(0,u.useState)("");(0,u.useEffect)(()=>{let e="";c(t&&t.PROXY_BASE_URL&&void 0!==t.PROXY_BASE_URL?t.PROXY_BASE_URL:window.location.origin)},[t]);let h="".concat(d,"/scim/v2"),x=async e=>{if(!s||!l){F.ZP.error("You need to be logged in to create a SCIM token");return}try{i(!0);let t={key_alias:e.key_alias||"SCIM Access Token",team_id:null,models:[],allowed_routes:["/scim/*"]},a=await (0,b.wX)(s,l,t);o(a),F.ZP.success("SCIM token created successfully")}catch(e){console.error("Error creating SCIM token:",e),F.ZP.error("Failed to create SCIM token: "+lz(e))}finally{i(!1)}};return(0,m.jsx)(S.Z,{numItems:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("div",{className:"flex items-center mb-4",children:(0,m.jsx)(O.Z,{children:"SCIM Configuration"})}),(0,m.jsx)(P.Z,{className:"text-gray-600",children:"System for Cross-domain Identity Management (SCIM) allows you to automatically provision and manage users and groups in LiteLLM."}),(0,m.jsx)(ly.Z,{}),(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"1"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lF.Z,{className:"h-5 w-5 mr-2"}),"SCIM Tenant URL"]})]}),(0,m.jsx)(P.Z,{className:"text-gray-600 mb-3",children:"Use this URL in your identity provider SCIM integration settings."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:h,disabled:!0,className:"flex-grow"}),(0,m.jsx)(L.CopyToClipboard,{text:h,onCopy:()=>F.ZP.success("URL copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"ml-2 flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-blue-100 text-blue-700 mr-2",children:"2"}),(0,m.jsxs)(O.Z,{className:"text-lg flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-5 w-5 mr-2"}),"Authentication Token"]})]}),(0,m.jsx)(lO.Z,{title:"Using SCIM",color:"blue",className:"mb-4",children:"You need a SCIM token to authenticate with the SCIM API. Create one below and use it in your SCIM provider configuration."}),n?(0,m.jsxs)(eD.Z,{className:"border border-yellow-300 bg-yellow-50",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 text-yellow-800",children:[(0,m.jsx)(lq.Z,{className:"h-5 w-5 mr-2"}),(0,m.jsx)(O.Z,{className:"text-lg text-yellow-800",children:"Your SCIM Token"})]}),(0,m.jsx)(P.Z,{className:"text-yellow-800 mb-4 font-medium",children:"Make sure to copy this token now. You will not be able to see it again."}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(I.Z,{value:n.token,className:"flex-grow mr-2 bg-white",type:"password",disabled:!0}),(0,m.jsx)(L.CopyToClipboard,{text:n.token,onCopy:()=>F.ZP.success("Token copied to clipboard"),children:(0,m.jsxs)(C.Z,{variant:"primary",className:"flex items-center",children:[(0,m.jsx)(ls.Z,{className:"h-4 w-4 mr-1"}),"Copy"]})})]}),(0,m.jsxs)(C.Z,{className:"mt-4 flex items-center",variant:"secondary",onClick:()=>o(null),children:[(0,m.jsx)(lU.Z,{className:"h-4 w-4 mr-1"}),"Create Another Token"]})]}):(0,m.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,m.jsxs)(M.Z,{form:a,onFinish:x,layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{name:"key_alias",label:"Token Name",rules:[{required:!0,message:"Please enter a name for your token"}],children:(0,m.jsx)(I.Z,{placeholder:"SCIM Access Token"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsxs)(C.Z,{variant:"primary",type:"submit",loading:r,className:"flex items-center",children:[(0,m.jsx)(lR.Z,{className:"h-4 w-4 mr-1"}),"Create SCIM Token"]})})]})})]})]})]})})},lK=e=>{let{searchParams:s,accessToken:l,userID:t,showSSOBanner:a,premiumUser:r,proxySettings:i}=e,[n]=M.Z.useForm(),[o]=M.Z.useForm(),{Title:d,Paragraph:c}=et.default,[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(!1),[Z,N]=(0,u.useState)(!1),[w,k]=(0,u.useState)(!1),[S,I]=(0,u.useState)(!1),[T,A]=(0,u.useState)(!1),[E,P]=(0,u.useState)(!1),[O,L]=(0,u.useState)(!1),[D,q]=(0,u.useState)(!1),[V,K]=(0,u.useState)(!1),[B,H]=(0,u.useState)([]),[J,G]=(0,u.useState)(null);(0,h.useRouter)();let[W,Y]=(0,u.useState)(null);console.log=function(){};let $=e0(),X="All IP Addresses Allowed",Q=$;Q+="/fallback/login";let ee=async()=>{try{if(!0!==r){F.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(l){let e=await (0,b.PT)(l);H(e&&e.length>0?e:[X])}else H([X])}catch(e){console.error("Error fetching allowed IPs:",e),F.ZP.error("Failed to fetch allowed IPs ".concat(e)),H([X])}finally{!0===r&&L(!0)}},es=async e=>{try{if(l){await (0,b.eH)(l,e.ip);let s=await (0,b.PT)(l);H(s),F.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),F.ZP.error("Failed to add IP address ".concat(e))}finally{q(!1)}},el=async e=>{G(e),K(!0)},ea=async()=>{if(J&&l)try{await (0,b.$I)(l,J);let e=await (0,b.PT)(l);H(e.length>0?e:[X]),F.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),F.ZP.error("Failed to delete IP address ".concat(e))}finally{K(!1),G(null)}};(0,u.useEffect)(()=>{(async()=>{if(null!=l){let e=[],s=await (0,b.Xd)(l,"proxy_admin_viewer");console.log("proxy admin viewer response: ",s);let t=s.users;console.log("proxy viewers response: ".concat(t)),t.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,b.Xd)(l,"proxy_admin")).users;a.forEach(s=>{e.push({user_role:s.user_role,user_id:s.user_id,user_email:s.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),j(e),Y(await (0,b.lg)(l))}})()},[l]);let er=async e=>{try{if(null!=l&&null!=g){var s;F.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,b.pf)(l,e,"proxy_admin"),a=(null===(s=t.data)||void 0===s?void 0:s.user_id)||t.user_id;(0,b.XO)(l,a).then(e=>{_(e),y(!0)}),console.log("response for team create call: ".concat(t));let r=g.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(a)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),g.push(t),j(g)),n.resetFields(),k(!1)}}catch(e){console.error("Error creating the key:",e)}},ei=async e=>{if(null==l)return;let s=lD[e.sso_provider],t={PROXY_BASE_URL:e.proxy_base_url};s&&Object.entries(s.envVarMap).forEach(s=>{let[l,a]=s;e[l]&&(t[a]=e[l])}),(0,b.K_)(l,{environment_variables:t})};return console.log("admins: ".concat(null==g?void 0:g.length)),(0,m.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,m.jsx)(d,{level:4,children:"Admin Access "}),(0,m.jsx)(c,{children:"Go to 'Internal Users' page to add other admins."}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Security Settings"}),(0,m.jsx)(eM.Z,{children:"SCIM"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(d,{level:4,children:" ✨ Security Settings"}),(0,m.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:()=>!0===r?A(!0):F.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,m.jsx)("div",{children:(0,m.jsx)(C.Z,{onClick:ee,children:"Allowed IPs"})})]})]}),(0,m.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,m.jsx)(lM,{isAddSSOModalVisible:T,isInstructionsModalVisible:E,handleAddSSOOk:()=>{A(!1),n.resetFields()},handleAddSSOCancel:()=>{A(!1),n.resetFields()},handleShowInstructions:e=>{er(e),ei(e),A(!1),P(!0)},handleInstructionsOk:()=>{P(!1)},handleInstructionsCancel:()=>{P(!1)},form:n}),(0,m.jsx)(R.Z,{title:"Manage Allowed IP Addresses",width:800,visible:O,onCancel:()=>L(!1),footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,m.jsx)(C.Z,{onClick:()=>L(!1),children:"Close"},"close")],children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"IP Address"}),(0,m.jsx)(e7.Z,{className:"text-right",children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:B.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e}),(0,m.jsx)(e6.Z,{className:"text-right",children:e!==X&&(0,m.jsx)(C.Z,{onClick:()=>el(e),color:"red",size:"xs",children:"Delete"})})]},s))})]})}),(0,m.jsx)(R.Z,{title:"Add Allowed IP Address",visible:D,onCancel:()=>q(!1),footer:null,children:(0,m.jsxs)(M.Z,{onFinish:es,children:[(0,m.jsx)(M.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,m.jsx)(z.default,{placeholder:"Enter IP address"})}),(0,m.jsx)(M.Z.Item,{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,m.jsx)(R.Z,{title:"Confirm Delete",visible:V,onCancel:()=>K(!1),onOk:ea,footer:[(0,m.jsx)(C.Z,{className:"mx-1",onClick:()=>ea(),children:"Yes"},"delete"),(0,m.jsx)(C.Z,{onClick:()=>K(!1),children:"Close"},"close")],children:(0,m.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",J,"?"]})})]}),(0,m.jsxs)(lO.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,m.jsxs)("a",{href:Q,target:"_blank",children:[(0,m.jsx)("b",{children:Q})," "]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lV,{accessToken:l,userID:t,proxySettings:i})})]})]})]})},lB=l(92858);let{Title:lH}=et.default;var lJ=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)([]);(0,u.useEffect)(()=>{i()},[s]);let i=async()=>{if(s){t(!0);try{let e=await (0,b.pu)(s);r(e.settings)}catch(e){console.error("Failed to fetch email event settings:",e),F.ZP.error("Failed to fetch email event settings")}finally{t(!1)}}},n=(e,s)=>{r(a.map(l=>l.event===e?{...l,enabled:s}:l))},o=async()=>{if(s)try{await (0,b.qW)(s,{settings:a}),F.ZP.success("Email event settings updated successfully")}catch(e){console.error("Failed to update email event settings:",e),F.ZP.error("Failed to update email event settings")}},d=async()=>{if(s)try{await (0,b.jr)(s),F.ZP.success("Email event settings reset to defaults"),i()}catch(e){console.error("Failed to reset email event settings:",e),F.ZP.error("Failed to reset email event settings")}},c=e=>{if(e.includes("Virtual Key Created"))return"An email will be sent to the user when a new virtual key is created with their user ID";if(e.includes("New User Invitation"))return"An email will be sent to the email address of the user when a new user is created";{let s=e.split(/(?=[A-Z])/).join(" ").toLowerCase();return"Receive an email notification when ".concat(s)}};return(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lH,{level:4,children:"Email Notifications"}),(0,m.jsx)(P.Z,{children:"Select which events should trigger email notifications."}),(0,m.jsx)(le.Z,{}),l?(0,m.jsx)("div",{style:{textAlign:"center",padding:"20px"},children:(0,m.jsx)(lb.Z,{size:"large"})}):(0,m.jsx)("div",{className:"space-y-4",children:a.map(e=>(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(sL.Z,{checked:e.enabled,onChange:s=>n(e.event,s.target.checked)}),(0,m.jsxs)("div",{className:"ml-3",children:[(0,m.jsx)(P.Z,{children:e.event}),(0,m.jsx)("div",{className:"text-sm text-gray-500 block",children:c(e.event)})]})]},e.event))}),(0,m.jsxs)("div",{className:"mt-6 flex space-x-4",children:[(0,m.jsx)(C.Z,{onClick:o,disabled:l,children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:d,variant:"secondary",disabled:l,children:"Reset to Defaults"})]})]})};let{Title:lG}=et.default;var lW=e=>{let{accessToken:s,premiumUser:l,alerts:t}=e,a=()=>{if(!s)return;let e={};t.filter(e=>"email"===e.name).forEach(s=>{var l;Object.entries(null!==(l=s.variables)&&void 0!==l?l:{}).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));a&&a.value&&(e[l]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,b.K_)(s,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Email settings updated successfully")};return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mt-6 mb-6",children:(0,m.jsx)(lJ,{accessToken:s})}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(lG,{level:4,children:"Email Server Settings"}),(0,m.jsxs)(P.Z,{children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,m.jsx)("br",{})]}),(0,m.jsx)("div",{className:"flex w-full",children:t.filter(e=>"email"===e.name).map((e,s)=>{var t;return(0,m.jsx)(e6.Z,{children:(0,m.jsx)("ul",{children:(0,m.jsx)(S.Z,{numItems:2,children:Object.entries(null!==(t=e.variables)&&void 0!==t?t:{}).map(e=>{let[s,t]=e;return(0,m.jsxs)("li",{className:"mx-2 my-2",children:[!0!=l&&("EMAIL_LOGO_URL"===s||"EMAIL_SUPPORT_CONTACT"===s)?(0,m.jsxs)("div",{children:[(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,m.jsxs)(P.Z,{className:"mt-2",children:[" ","✨ ",s]})}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"mt-2",children:s}),(0,m.jsx)(I.Z,{name:s,defaultValue:t,type:"password",style:{width:"400px"}})]}),(0,m.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===s&&(0,m.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `sender@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===s&&(0,m.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `info@berri.ai`",(0,m.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===s&&(0,m.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is support@berri.ai"})]})]},s)})})})},s)})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>a(),children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>s&&(0,b.jE)(s,"email"),className:"mx-2",children:"Test Email Alerts"})]})]})},lY=e=>{let{alertingSettings:s,handleInputChange:l,handleResetField:t,handleSubmit:a,premiumUser:r}=e,[i]=M.Z.useForm();return(0,m.jsxs)(M.Z,{form:i,onFinish:()=>{console.log("INSIDE ONFINISH");let e=i.getFieldsValue(),s=Object.entries(e).every(e=>{let[s,l]=e;return"boolean"!=typeof l&&(""===l||null==l)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(s)),s?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[s.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{align:"center",children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?r?(0,m.jsx)(M.Z.Item,{name:e.field_name,children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s)}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>l(e.field_name,s)}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}):(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,m.jsx)(M.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,m.jsx)(e6.Z,{children:"Integer"===e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>l(e.field_name,s),className:"p-0"}):"Boolean"===e.field_type?(0,m.jsx)(lB.Z,{checked:e.field_value,onChange:s=>{l(e.field_name,s),i.setFieldsValue({[e.field_name]:s})}}):(0,m.jsx)(z.default,{value:e.field_value,onChange:s=>l(e.field_name,s)})})}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>t(e.field_name,s),children:"Reset"})})]},s)),(0,m.jsx)("div",{children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Update Settings"})})]})},l$=e=>{let{accessToken:s,premiumUser:l}=e,[t,a]=(0,u.useState)([]);return(0,u.useEffect)(()=>{s&&(0,b.RQ)(s).then(e=>{a(e)})},[s]),(0,m.jsx)(lY,{alertingSettings:t,handleInputChange:(e,s)=>{let l=t.map(l=>l.field_name===e?{...l,field_value:s}:l);console.log("updatedSettings: ".concat(JSON.stringify(l))),a(l)},handleResetField:(e,l)=>{if(s)try{let s=t.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:s.field_default_value}:s);a(s)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!s||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let l={};t.forEach(e=>{l[e.field_name]=e.field_value});let a={...e,...l};console.log("mergedFormValues: ".concat(JSON.stringify(a)));let{slack_alerting:r,...i}=a;console.log("slack_alerting: ".concat(r,", alertingArgs: ").concat(JSON.stringify(i)));try{(0,b.jA)(s,"alerting_args",i),"boolean"==typeof r&&(!0==r?(0,b.jA)(s,"alerting",["slack"]):(0,b.jA)(s,"alerting",[])),F.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:l})},lX=l(86582);let{Title:lQ,Paragraph:l0}=et.default;console.log=function(){};var l1=e=>{let{accessToken:s,userRole:l,userID:t,premiumUser:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)([]),[d,c]=(0,u.useState)(!1),[h]=M.Z.useForm(),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)(""),[v,y]=(0,u.useState)({}),[Z,N]=(0,u.useState)([]),[w,k]=(0,u.useState)(!1),[T,A]=(0,u.useState)([]),[E,O]=(0,u.useState)(null),[L,q]=(0,u.useState)([]),[z,V]=(0,u.useState)(!1),[K,B]=(0,u.useState)(null),H=e=>{Z.includes(e)?N(Z.filter(s=>s!==e)):N([...Z,e])},J={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)",db_exceptions:"Database Exceptions (Read/Write)",daily_reports:"Weekly/Monthly Spend Reports",outage_alerts:"Outage Alerts",region_outage_alerts:"Region Outage Alerts"};(0,u.useEffect)(()=>{s&&l&&t&&(0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e),i(e.callbacks),A(e.available_callbacks);let s=e.alerts;if(console.log("alerts_data",s),s&&s.length>0){let e=s[0];console.log("_alert_info",e);let l=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",l),N(e.active_alerts),_(l),y(e.alerts_to_webhook)}o(s)})},[s,l,t]);let G=e=>Z&&Z.includes(e),W=async e=>{if(!s)return;let l={};Object.entries(e).forEach(e=>{let[s,t]=e;"callback"!==s&&(l[s]=t)});try{await (0,b.K_)(s,{environment_variables:l}),F.ZP.success("Callback added successfully"),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},Y=async e=>{if(!s)return;let l=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[s,l]=e;"callback"!==s&&(t[s]=l)});try{await (0,b.K_)(s,{environment_variables:t,litellm_settings:{success_callback:[l]}}),F.ZP.success("Callback ".concat(l," added successfully")),c(!1),h.resetFields(),p(null)}catch(e){F.ZP.error("Failed to add callback: "+e,20)}},$=e=>{console.log("inside handleSelectedCallbackChange",e),p(e.litellm_callback_name),console.log("all callbacks",T),e&&e.litellm_callback_params?(q(e.litellm_callback_params),console.log("selectedCallbackParams",L)):q([])};return s?(console.log("callbacks: ".concat(r)),(0,m.jsxs)("div",{className:"w-full mx-4",children:[(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Logging Callbacks"}),(0,m.jsx)(eM.Z,{value:"2",children:"Alerting Types"}),(0,m.jsx)(eM.Z,{value:"3",children:"Alerting Settings"}),(0,m.jsx)(eM.Z,{value:"4",children:"Email Alerts"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(lQ,{level:4,children:"Active Logging Callbacks"}),(0,m.jsx)(S.Z,{numItems:2,children:(0,m.jsx)(eD.Z,{className:"max-h-[50vh]",children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e7.Z,{children:"Callback Name"})})}),(0,m.jsx)(e3.Z,{children:r.map((e,l)=>(0,m.jsxs)(e9.Z,{className:"flex justify-between",children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.name})}),(0,m.jsx)(e6.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"flex justify-between",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>{B(e),V(!0)}}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},l))})]})})}),(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>k(!0),children:"Add Callback"})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(P.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,m.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{}),(0,m.jsx)(e7.Z,{children:"Slack Webhook URL"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(J).map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:"region_outage_alerts"==l?a?(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)}):(0,m.jsx)(C.Z,{className:"flex items-center justify-center",children:(0,m.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,m.jsx)(lB.Z,{id:"switch",name:"switch",checked:G(l),onChange:()=>H(l)})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:t})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:l,type:"password",defaultValue:v&&v[l]?v[l]:f})})]},s)})})]}),(0,m.jsx)(C.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!s)return;let e={};Object.entries(J).forEach(s=>{let[l,t]=s,a=document.querySelector('input[name="'.concat(l,'"]'));console.log("key",l),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[l]=r}),console.log("updatedAlertToWebhooks",e);let l={general_settings:{alert_to_webhook_url:e,alert_types:Z}};console.log("payload",l);try{(0,b.K_)(s,l)}catch(e){F.ZP.error("Failed to update alerts: "+e,20)}F.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,m.jsx)(C.Z,{onClick:()=>(0,b.jE)(s,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(l$,{accessToken:s,premiumUser:a})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(lW,{accessToken:s,premiumUser:a,alerts:n})})]})]})}),(0,m.jsxs)(R.Z,{title:"Add Logging Callback",visible:w,width:800,onCancel:()=>k(!1),footer:null,children:[(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/logging",className:"mb-8 mt-4",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: Logging"}),(0,m.jsx)(M.Z,{form:h,onFinish:Y,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(lX.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,m.jsx)(D.default,{onChange:e=>{let s=T[e];s&&(console.log(s.ui_callback_name),$(s))},children:T&&Object.values(T).map(e=>(0,m.jsx)(el.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),L&&L.map(e=>(0,m.jsx)(lX.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,m.jsx)(I.Z,{type:"password"})},e)),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,m.jsx)(R.Z,{visible:z,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>V(!1),footer:null,children:(0,m.jsxs)(M.Z,{form:h,onFinish:W,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(m.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[s,l]=e;return(0,m.jsx)(lX.Z,{label:s,name:s,children:(0,m.jsx)(I.Z,{type:"password",defaultValue:l})},s)})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},l2=l(92414),l4=l(46030);let{Option:l5}=D.default;var l3=e=>{let{models:s,accessToken:l,routerSettings:t,setRouterSettings:a}=e,[r]=M.Z.useForm(),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>n(!0),children:"+ Add Fallbacks"}),(0,m.jsx)(R.Z,{title:"Add Fallbacks",visible:i,width:800,footer:null,onOk:()=>{n(!1),r.resetFields()},onCancel:()=>{n(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:e=>{console.log(e);let{model_name:s,models:i}=e,o=[...t.fallbacks||[],{[s]:i}],d={...t,fallbacks:o};console.log(d);try{(0,b.K_)(l,{router_settings:d}),a(d)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully"),n(!1),r.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,m.jsx)(eO.Z,{defaultValue:o,children:s&&s.map((e,s)=>(0,m.jsx)(el.Z,{value:e,onClick:()=>d(e),children:e},s))})}),(0,m.jsx)(M.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,m.jsx)(l2.Z,{value:s,children:s&&s.filter(e=>e!=o).map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},l6=l(26433);async function l8(e,s){console.log=function(){},console.log("isLocal:",!1);let l=window.location.origin,t=new l6.ZP.OpenAI({apiKey:s,baseURL:l,dangerouslyAllowBrowser:!0});try{let s=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});F.ZP.success((0,m.jsxs)("span",{children:["Test model=",(0,m.jsx)("strong",{children:e}),", received model=",(0,m.jsx)("strong",{children:s.model}),". See"," ",(0,m.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let l7={ttl:3600,lowest_latency_buffer:0},l9=e=>{let{selectedStrategy:s,strategyArgs:l,paramExplanation:t}=e;return(0,m.jsxs)(T.Z,{children:[(0,m.jsx)(E.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,m.jsx)(A.Z,{children:"latency-based-routing"==s?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(l).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[s]})]}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]})}):(0,m.jsx)(P.Z,{children:"No specific settings"})})]})};var te=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,i]=(0,u.useState)({}),[n,o]=(0,u.useState)({}),[d,c]=(0,u.useState)([]),[h,x]=(0,u.useState)(!1),[p]=M.Z.useForm(),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(null),[v,y]=(0,u.useState)(null),Z={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request",ttl:"(int) Sliding window to look back over when calculating the average latency of a deployment. Default - 1 hour (in seconds).",lowest_latency_buffer:"(float) Shuffle between deployments within this % of the lowest latency. Default - 0 (i.e. always pick lowest latency)."};(0,u.useEffect)(()=>{s&&l&&t&&((0,b.BL)(s,t,l).then(e=>{console.log("callbacks",e);let s=e.router_settings;"model_group_retry_policy"in s&&delete s.model_group_retry_policy,i(s)}),(0,b.YU)(s).then(e=>{c(e)}))},[s,l,t]);let N=async e=>{if(!s)return;console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(r.fallbacks));let l=r.fallbacks.map(s=>(e in s&&delete s[e],s)).filter(e=>Object.keys(e).length>0),t={...r,fallbacks:l};try{await (0,b.K_)(s,{router_settings:t}),i(t),F.ZP.success("Router settings updated successfully")}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}},w=(e,s)=>{c(d.map(l=>l.field_name===e?{...l,field_value:s}:l))},T=(e,l)=>{if(!s)return;let t=d[l].field_value;if(null!=t&&void 0!=t)try{(0,b.jA)(s,e,t);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:!0}:s);c(l)}catch(e){}},A=(e,l)=>{if(s)try{(0,b.ao)(s,e);let l=d.map(s=>s.field_name===e?{...s,stored_in_db:null,field_value:null}:s);c(l)}catch(e){}},E=e=>{if(!s)return;console.log("router_settings",e);let l=Object.fromEntries(Object.entries(e).map(e=>{let[s,l]=e;if("routing_strategy_args"!==s&&"routing_strategy"!==s){var t;return[s,(null===(t=document.querySelector('input[name="'.concat(s,'"]')))||void 0===t?void 0:t.value)||l]}if("routing_strategy"==s)return[s,f];if("routing_strategy_args"==s&&"latency-based-routing"==f){let e={},s=document.querySelector('input[name="lowest_latency_buffer"]'),l=document.querySelector('input[name="ttl"]');return(null==s?void 0:s.value)&&(e.lowest_latency_buffer=Number(s.value)),(null==l?void 0:l.value)&&(e.ttl=Number(l.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",l);try{(0,b.K_)(s,{router_settings:l})}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("router settings updated successfully")};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)(eR.Z,{variant:"line",defaultValue:"1",children:[(0,m.jsx)(eM.Z,{value:"1",children:"Loadbalancing"}),(0,m.jsx)(eM.Z,{value:"2",children:"Fallbacks"}),(0,m.jsx)(eM.Z,{value:"3",children:"General"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,m.jsx)(O.Z,{children:"Router Settings"}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"})]})}),(0,m.jsx)(e3.Z,{children:Object.entries(r).filter(e=>{let[s,l]=e;return"fallbacks"!=s&&"context_window_fallbacks"!=s&&"routing_strategy_args"!=s}).map(e=>{let[s,l]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:s}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:Z[s]})]}),(0,m.jsx)(e6.Z,{children:"routing_strategy"==s?(0,m.jsxs)(eO.Z,{defaultValue:l,className:"w-full max-w-md",onValueChange:_,children:[(0,m.jsx)(el.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,m.jsx)(el.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,m.jsx)(el.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,m.jsx)(I.Z,{name:s,defaultValue:"object"==typeof l?JSON.stringify(l,null,2):l.toString()})})]},s)})})]}),(0,m.jsx)(l9,{selectedStrategy:f,strategyArgs:r&&r.routing_strategy_args&&Object.keys(r.routing_strategy_args).length>0?r.routing_strategy_args:l7,paramExplanation:Z})]}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(C.Z,{className:"mt-2",onClick:()=>E(r),children:"Save Changes"})})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Model Name"}),(0,m.jsx)(e7.Z,{children:"Fallbacks"})]})}),(0,m.jsx)(e3.Z,{children:r.fallbacks&&r.fallbacks.map((e,l)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:t}),(0,m.jsx)(e6.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(C.Z,{onClick:()=>l8(t,s),children:"Test Fallback"})}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>N(t)})})]},l.toString()+t)}))})]}),(0,m.jsx)(l3,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:s,routerSettings:r,setRouterSettings:i})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Setting"}),(0,m.jsx)(e7.Z,{children:"Value"}),(0,m.jsx)(e7.Z,{children:"Status"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:d.filter(e=>"TypedDictionary"!==e.field_type).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(P.Z,{children:e.field_name}),(0,m.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,m.jsx)(e6.Z,{children:"Integer"==e.field_type?(0,m.jsx)(G.Z,{step:1,value:e.field_value,onChange:s=>w(e.field_name,s)}):null}),(0,m.jsx)(e6.Z,{children:!0==e.stored_in_db?(0,m.jsx)(eL.Z,{icon:eg.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,m.jsx)(eL.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,m.jsxs)(e6.Z,{children:[(0,m.jsx)(C.Z,{onClick:()=>T(e.field_name,s),children:"Update"}),(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>A(e.field_name,s),children:"Reset"})]})]},s))})]})})})]})]})}):null},ts=l(93142),tl=e=>{let{value:s={},onChange:l}=e,[t,a]=(0,u.useState)(Object.entries(s)),r=e=>{let s=t.filter((s,l)=>l!==e);a(s),null==l||l(Object.fromEntries(s))},i=(e,s,r)=>{let i=[...t];i[e]=[s,r],a(i),null==l||l(Object.fromEntries(i))};return(0,m.jsxs)("div",{children:[t.map((e,s)=>{let[l,t]=e;return(0,m.jsxs)(ts.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,m.jsx)(I.Z,{placeholder:"Header Name",value:l,onChange:e=>i(s,e.target.value,t)}),(0,m.jsx)(I.Z,{placeholder:"Header Value",value:t,onChange:e=>i(s,l,e.target.value)}),(0,m.jsx)(s$.Z,{onClick:()=>r(s)})]},s)}),(0,m.jsx)(U.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,m.jsx)(sX.Z,{}),children:"Add Header"})]})};let{Option:tt}=D.default;var ta=e=>{let{accessToken:s,setPassThroughItems:l,passThroughItems:t}=e,[a]=M.Z.useForm(),[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)("");return(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Add Pass-Through Endpoint"}),(0,m.jsx)(R.Z,{title:"Add Pass-Through Endpoint",visible:r,width:800,footer:null,onOk:()=>{i(!1),a.resetFields()},onCancel:()=>{i(!1),a.resetFields()},children:(0,m.jsxs)(M.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,b.Vt)(s,e),l(r)}catch(e){F.ZP.error("Failed to update router settings: "+e,20)}F.ZP.success("Pass through endpoint successfully added"),i(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Target",name:"target",rules:[{required:!0,message:"The URL to which requests for this path should be forwarded."}],help:"required",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Headers",name:"headers",rules:[{required:!0,message:"Key-value pairs of headers to be forwarded with the request. You can set any key value pair here and it will be forwarded to your target endpoint"}],help:"required",children:(0,m.jsx)(tl,{})})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},tr=e=>{let{accessToken:s,userRole:l,userID:t,modelData:a}=e,[r,i]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&l&&t&&(0,b.mp)(s).then(e=>{i(e.endpoints)})},[s,l,t]);let n=(e,l)=>{if(s)try{(0,b.EG)(s,e);let l=r.filter(s=>s.path!==e);i(l),F.ZP.success("Endpoint deleted successfully.")}catch(e){}};return s?(0,m.jsx)("div",{className:"w-full mx-4",children:(0,m.jsx)(eF.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Path"}),(0,m.jsx)(e7.Z,{children:"Target"}),(0,m.jsx)(e7.Z,{children:"Headers"}),(0,m.jsx)(e7.Z,{children:"Action"})]})}),(0,m.jsx)(e3.Z,{children:r.map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:(0,m.jsx)(P.Z,{children:e.path})}),(0,m.jsx)(e6.Z,{children:e.target}),(0,m.jsx)(e6.Z,{children:JSON.stringify(e.headers)}),(0,m.jsx)(e6.Z,{children:(0,m.jsx)(sC.Z,{icon:eK.Z,color:"red",onClick:()=>n(e.path,s),children:"Reset"})})]},s))})]}),(0,m.jsx)(ta,{accessToken:s,setPassThroughItems:i,passThroughItems:r})]})})}):null},ti=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a}=e,[r]=M.Z.useForm(),i=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call");let s=await (0,b.Zr)(l,e);console.log("key create Response:",s),a(e=>e?[...e,s]:[s]),F.ZP.success("API Key Created"),r.resetFields()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Create Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),r.resetFields()},onCancel:()=>{t(!1),r.resetFields()},children:(0,m.jsxs)(M.Z,{form:r,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},tn=e=>{let{isModalVisible:s,accessToken:l,setIsModalVisible:t,setBudgetList:a,existingBudget:r,handleUpdateCall:i}=e;console.log("existingBudget",r);let[n]=M.Z.useForm();(0,u.useEffect)(()=>{n.setFieldsValue(r)},[r,n]);let o=async e=>{if(null!=l&&void 0!=l)try{F.ZP.info("Making API Call"),t(!0);let s=await (0,b.qI)(l,e);a(e=>e?[...e,s]:[s]),F.ZP.success("Budget Updated"),n.resetFields(),i()}catch(e){console.error("Error creating the key:",e),F.ZP.error("Error creating the key: ".concat(e),20)}};return(0,m.jsx)(R.Z,{title:"Edit Budget",visible:s,width:800,footer:null,onOk:()=>{t(!1),n.resetFields()},onCancel:()=>{t(!1),n.resetFields()},children:(0,m.jsxs)(M.Z,{form:n,onFinish:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:r,children:[(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{label:"Budget ID",name:"budget_id",rules:[{required:!0,message:"Please input a human-friendly name for the budget"}],help:"A human-friendly name for the budget",children:(0,m.jsx)(I.Z,{placeholder:""})}),(0,m.jsx)(M.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,m.jsx)(G.Z,{step:1,precision:2,width:200})}),(0,m.jsxs)(T.Z,{className:"mt-20 mb-8",children:[(0,m.jsx)(E.Z,{children:(0,m.jsx)("b",{children:"Optional Settings"})}),(0,m.jsxs)(A.Z,{children:[(0,m.jsx)(M.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,m.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,m.jsx)(M.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,m.jsxs)(D.default,{defaultValue:null,placeholder:"n/a",children:[(0,m.jsx)(D.default.Option,{value:"24h",children:"daily"}),(0,m.jsx)(D.default.Option,{value:"7d",children:"weekly"}),(0,m.jsx)(D.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(U.ZP,{htmlType:"submit",children:"Save"})})]})})},to=l(17906),td=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)([]);(0,u.useEffect)(()=>{s&&(0,b.O3)(s).then(e=>{d(e)})},[s]);let c=async(e,l)=>{console.log("budget_id",e),null!=s&&(n(o.find(s=>s.budget_id===e)||null),r(!0))},h=async(e,l)=>{if(null==s)return;F.ZP.info("Request made"),await (0,b.NV)(s,e);let t=[...o];t.splice(l,1),d(t),F.ZP.success("Budget Deleted.")},x=async()=>{null!=s&&(0,b.O3)(s).then(e=>{d(e)})};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,m.jsx)(C.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,m.jsx)(ti,{accessToken:s,isModalVisible:l,setIsModalVisible:t,setBudgetList:d}),i&&(0,m.jsx)(tn,{accessToken:s,isModalVisible:a,setIsModalVisible:r,setBudgetList:d,existingBudget:i,handleUpdateCall:x}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Create a budget to assign to customers."}),(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Budget ID"}),(0,m.jsx)(e7.Z,{children:"Max Budget"}),(0,m.jsx)(e7.Z,{children:"TPM"}),(0,m.jsx)(e7.Z,{children:"RPM"})]})}),(0,m.jsx)(e3.Z,{children:o.slice().sort((e,s)=>new Date(s.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,s)=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.budget_id}),(0,m.jsx)(e6.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,m.jsx)(e6.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,m.jsx)(e6.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>c(e.budget_id,s)}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>h(e.budget_id,s)})]},s))})]})]}),(0,m.jsxs)("div",{className:"mt-5",children:[(0,m.jsx)(P.Z,{className:"text-base",children:"How to use budget id"}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"Assign Budget to Customer"}),(0,m.jsx)(eM.Z,{children:"Test it (Curl)"}),(0,m.jsx)(eM.Z,{children:"Test it (OpenAI SDK)"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:"\ncurl -X POST --location '/end_user/new' \n-H 'Authorization: Bearer ' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"bash",children:'\ncurl -X POST --location \'/chat/completions\' \n-H \'Authorization: Bearer \' \n-H \'Content-Type: application/json\' \n-d \'{\n "model": "gpt-3.5-turbo\', \n "messages":[{"role": "user", "content": "Hey, how\'s it going?"}],\n "user": "my-customer-id"\n}\' # \uD83D\uDC48 KEY CHANGE\n\n '})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="",\n api_key=""\n)\n\ncompletion = client.chat.completions.create(\n model="gpt-3.5-turbo",\n messages=[\n {"role": "system", "content": "You are a helpful assistant."},\n {"role": "user", "content": "Hello!"}\n ],\n user="my-customer-id"\n)\n\nprint(completion.choices[0].message)'})})]})]})]})]})},tc=l(77398),tm=l.n(tc);function tu(e){let{data:s=[],columns:l,getRowCanExpand:t,renderSubComponent:a,isLoading:r=!1,loadingMessage:i="\uD83D\uDE85 Loading logs...",noDataMessage:n="No logs found"}=e,o=(0,e2.b7)({data:s,columns:l,getRowCanExpand:t,getRowId:(e,s)=>{var l;return null!==(l=null==e?void 0:e.request_id)&&void 0!==l?l:String(s)},getCoreRowModel:(0,e4.sC)(),getExpandedRowModel:(0,e4.rV)()});return(0,m.jsx)("div",{className:"rounded-lg custom-border",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:r?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:i})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsxs)(u.Fragment,{children:[(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap",children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:l.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:n})})})})})]})})}let th=e=>{try{return new Date(e).toLocaleString("en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0}).replace(",","")}catch(e){return"Error converting time"}},tx=e=>{let{utcTime:s}=e;return(0,m.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:th(s)})},tp=(e,s)=>{var l,t;return(null===(t=e.metadata)||void 0===t?void 0:null===(l=t.mcp_tool_call_metadata)||void 0===l?void 0:l.mcp_server_logo_url)?e.metadata.mcp_tool_call_metadata.mcp_server_logo_url:s?sm(s).logo:""},tg=[{id:"expander",header:()=>null,cell:e=>{let{row:s}=e;return(0,m.jsx)(()=>{let[e,l]=u.useState(s.getIsExpanded()),t=u.useCallback(()=>{l(e=>!e),s.getToggleExpandedHandler()()},[s]);return s.getCanExpand()?(0,m.jsx)("button",{onClick:t,style:{cursor:"pointer"},"aria-label":e?"Collapse row":"Expand row",className:"w-6 h-6 flex items-center justify-center focus:outline-none",children:(0,m.jsx)("svg",{className:"w-4 h-4 transform transition-transform duration-75 ".concat(e?"rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}):(0,m.jsx)("span",{className:"w-6 h-6 flex items-center justify-center",children:"●"})},{})}},{header:"Time",accessorKey:"startTime",cell:e=>(0,m.jsx)(tx,{utcTime:e.getValue()})},{header:"Status",accessorKey:"metadata.status",cell:e=>{let s="failure"!==(e.getValue()||"Success").toLowerCase();return(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat(s?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s?"Success":"Failure"})}},{header:"Session ID",accessorKey:"session_id",cell:e=>{let s=String(e.getValue()||""),l=e.row.original.onSessionClick;return(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal text-xs max-w-[15ch] truncate block",onClick:()=>null==l?void 0:l(s),children:String(e.getValue()||"")})})}},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)("span",{className:"font-mono text-xs max-w-[15ch] truncate block",children:String(e.getValue()||"")})})},{header:"Cost",accessorKey:"spend",cell:e=>(0,m.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Team Name",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Key Hash",accessorKey:"metadata.user_api_key",cell:e=>{let s=String(e.getValue()||"-"),l=e.row.original.onKeyHashClick;return(0,m.jsx)(Y.Z,{title:s,children:(0,m.jsx)("span",{className:"font-mono max-w-[15ch] truncate block cursor-pointer hover:text-blue-600",onClick:()=>null==l?void 0:l(s),children:s})})}},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Model",accessorKey:"model",cell:e=>{let s=e.row.original,l=s.custom_llm_provider,t=String(e.getValue()||"");return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:tp(s,l),alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(Y.Z,{title:t,children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:t})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let s=e.row.original;return(0,m.jsxs)("span",{className:"text-sm",children:[String(s.total_tokens||"0"),(0,m.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(s.prompt_tokens||"0"),"+",String(s.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"End User",accessorKey:"end_user",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||"-"),children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:String(e.getValue()||"-")})})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let s=e.getValue();if(!s||0===Object.keys(s).length)return"-";let l=Object.entries(s),t=l[0],a=l.slice(1);return(0,m.jsx)("div",{className:"flex flex-wrap gap-1",children:(0,m.jsx)(Y.Z,{title:(0,m.jsx)("div",{className:"flex flex-col gap-1",children:l.map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{children:[s,": ",String(l)]},s)})}),children:(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[t[0],": ",String(t[1]),a.length>0&&" +".concat(a.length)]})})})}}],tj=async(e,s,l,t)=>{console.log("prefetchLogDetails called with",e.length,"logs");let a=e.map(e=>{if(e.request_id)return console.log("Prefetching details for request_id:",e.request_id),t.prefetchQuery({queryKey:["logDetails",e.request_id,s],queryFn:async()=>{console.log("Fetching details for",e.request_id);let t=await (0,b.qk)(l,e.request_id,s);return console.log("Received details for",e.request_id,":",t?"success":"failed"),t},staleTime:6e5,gcTime:6e5})});try{let e=await Promise.all(a);return console.log("All prefetch promises completed:",e.length),e}catch(e){throw console.error("Error in prefetchLogDetails:",e),e}};function tf(e){let{row:s,hasMessages:l,hasResponse:t,hasError:a,errorInfo:r,getRawRequest:i,formattedResponse:n}=e;return(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request"}),(0,m.jsx)("button",{onClick:()=>{try{navigator.clipboard.writeText(JSON.stringify(i(),null,2)),F.ZP.success("Request copied to clipboard")}catch(e){F.ZP.error("Failed to copy request")}},className:"p-1 hover:bg-gray-200 rounded",title:"Copy request",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(i(),null,2)})})]}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsxs)("h3",{className:"text-lg font-medium",children:["Response",a&&(0,m.jsxs)("span",{className:"ml-2 text-sm text-red-600",children:["• HTTP code ",(null==r?void 0:r.error_code)||400]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(n(),null,2)),F.ZP.success("Response copied to clipboard")},className:"p-1 hover:bg-gray-200 rounded",title:"Copy response",disabled:!t,children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-96 bg-gray-50",children:t?(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(n(),null,2)}):(0,m.jsx)("div",{className:"text-gray-500 text-sm italic text-center py-4",children:"Response data not available"})})]})]})}let t_=e=>{var s;let{errorInfo:l}=e,[t,a]=u.useState({}),[r,i]=u.useState(!1),n=e=>{a(s=>({...s,[e]:!s[e]}))},o=l.traceback&&(s=l.traceback)?Array.from(s.matchAll(/File "([^"]+)", line (\d+)/g)).map(e=>{let l=e[1],t=e[2],a=l.split("/").pop()||l,r=e.index||0,i=s.indexOf('File "',r+1),n=i>-1?s.substring(r,i).trim():s.substring(r).trim(),o=n.split("\n"),d="";return o.length>1&&(d=o[o.length-1].trim()),{filePath:l,fileName:a,lineNumber:t,code:d,inFunction:n.includes(" in ")?n.split(" in ")[1].split("\n")[0]:""}}):[];return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsxs)("h3",{className:"text-lg font-medium flex items-center text-red-600",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Error Details"]})}),(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-red-50 rounded-md p-4 mb-4",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20",children:"Type:"}),(0,m.jsx)("span",{className:"text-red-700",children:l.error_class||"Unknown Error"})]}),(0,m.jsxs)("div",{className:"flex mt-2",children:[(0,m.jsx)("span",{className:"text-red-800 font-medium w-20 flex-shrink-0",children:"Message:"}),(0,m.jsx)("span",{className:"text-red-700 break-words whitespace-pre-wrap",children:l.error_message||"Unknown error occurred"})]})]}),l.traceback&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,m.jsx)("h4",{className:"font-medium",children:"Traceback"}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsx)("button",{onClick:()=>{let e=!r;if(i(e),o.length>0){let s={};o.forEach((l,t)=>{s[t]=e}),a(s)}},className:"text-gray-500 hover:text-gray-700 flex items-center text-sm",children:r?"Collapse All":"Expand All"}),(0,m.jsxs)("button",{onClick:()=>navigator.clipboard.writeText(l.traceback||""),className:"text-gray-500 hover:text-gray-700 flex items-center",title:"Copy traceback",children:[(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),(0,m.jsx)("span",{className:"ml-1",children:"Copy"})]})]})]}),(0,m.jsx)("div",{className:"bg-white rounded-md border border-gray-200 overflow-hidden shadow-sm",children:o.map((e,s)=>(0,m.jsxs)("div",{className:"border-b border-gray-200 last:border-b-0",children:[(0,m.jsxs)("div",{className:"px-4 py-2 flex items-center justify-between cursor-pointer hover:bg-gray-50",onClick:()=>n(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("span",{className:"text-gray-400 mr-2 w-12 text-right",children:e.lineNumber}),(0,m.jsx)("span",{className:"text-gray-600 font-medium",children:e.fileName}),(0,m.jsx)("span",{className:"text-gray-500 mx-1",children:"in"}),(0,m.jsx)("span",{className:"text-indigo-600 font-medium",children:e.inFunction||e.fileName})]}),(0,m.jsx)("svg",{className:"w-5 h-5 text-gray-500 transition-transform ".concat(t[s]?"transform rotate-180":""),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),(t[s]||!1)&&e.code&&(0,m.jsx)("div",{className:"px-12 py-2 font-mono text-sm text-gray-800 bg-gray-50 overflow-x-auto border-t border-gray-100",children:e.code})]},s))})]})]})]})},tv=e=>{let{show:s}=e;return s?(0,m.jsxs)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-start",children:[(0,m.jsx)("div",{className:"text-blue-500 mr-3 flex-shrink-0 mt-0.5",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,m.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,m.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}),(0,m.jsxs)("div",{children:[(0,m.jsx)("h4",{className:"text-sm font-medium text-blue-800",children:"Request/Response Data Not Available"}),(0,m.jsxs)("p",{className:"text-sm text-blue-700 mt-1",children:["To view request and response details, enable prompt storage in your LiteLLM configuration by adding the following to your ",(0,m.jsx)("code",{className:"bg-blue-100 px-1 py-0.5 rounded",children:"proxy_config.yaml"})," file:"]}),(0,m.jsx)("pre",{className:"mt-2 bg-white p-3 rounded border border-blue-200 text-xs font-mono overflow-auto",children:"general_settings:\n store_model_in_db: true\n store_prompts_in_spend_logs: true"}),(0,m.jsx)("p",{className:"text-xs text-blue-700 mt-2",children:"Note: This will only affect new requests after the configuration change."})]})]}):null};var ty=l(35829);let tb=e=>{let{sessionId:s,logs:l,onBack:t}=e,[a,r]=(0,u.useState)(null),i=l.reduce((e,s)=>e+(s.spend||0),0),n=l.reduce((e,s)=>e+(s.total_tokens||0),0),o=l.length>0?new Date(l[0].startTime):new Date;return(((l.length>0?new Date(l[l.length-1].endTime):new Date).getTime()-o.getTime())/1e3).toFixed(2),l.map(e=>({time:new Date(e.startTime).toISOString(),tokens:e.total_tokens||0,cost:e.spend||0})),(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{className:"mb-8",children:[(0,m.jsx)("div",{className:"flex items-center space-x-4",children:(0,m.jsxs)("button",{onClick:t,className:"flex items-center text-gray-600 hover:text-gray-900 transition-colors",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),"Back to All Logs"]})}),(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsx)("h1",{className:"text-2xl font-semibold text-gray-900",children:"Session Details"}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsx)("p",{className:"text-sm text-gray-500 font-mono",children:s}),(0,m.jsxs)("a",{href:"https://docs.litellm.ai/docs/proxy/ui_logs_sessions",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Get started with session management here",(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(ty.Z,{children:l.length})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Cost"}),(0,m.jsxs)(ty.Z,{children:["$",i.toFixed(4)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(ty.Z,{children:n})]})]}),(0,m.jsx)(O.Z,{children:"Session Logs"}),(0,m.jsx)("div",{className:"mt-4",children:(0,m.jsx)(tu,{columns:tg,data:l,renderSubComponent:tS,getRowCanExpand:()=>!0,loadingMessage:"Loading logs...",noDataMessage:"No logs found"})})]})};function tZ(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)({});if(!s||0===s.length)return null;let i=e=>new Date(1e3*e).toLocaleString(),n=(e,s)=>"".concat(((s-e)*1e3).toFixed(2),"ms"),o=(e,s)=>{let l="".concat(e,"-").concat(s);r(e=>({...e,[l]:!e[l]}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Vector Store Requests"})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsx)("div",{className:"p-4",children:s.map((e,s)=>(0,m.jsxs)("div",{className:"mb-6 last:mb-0",children:[(0,m.jsx)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Query:"}),(0,m.jsx)("span",{className:"font-mono",children:e.query})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Vector Store ID:"}),(0,m.jsx)("span",{className:"font-mono",children:e.vector_store_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{className:"flex items-center",children:(()=>{let{logo:s,displayName:l}=sm(e.custom_llm_provider);return(0,m.jsxs)(m.Fragment,{children:[s&&(0,m.jsx)("img",{src:s,alt:"".concat(l," logo"),className:"h-5 w-5 mr-2"}),l]})})()})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:i(e.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:i(e.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsx)("span",{children:n(e.start_time,e.end_time)})]})]})]})}),(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Search Results"}),(0,m.jsx)("div",{className:"space-y-2",children:e.vector_store_search_response.data.map((e,l)=>{let t=a["".concat(s,"-").concat(l)]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center p-3 bg-gray-50 cursor-pointer",onClick:()=>o(s,l),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(t?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsxs)("span",{className:"font-medium mr-2",children:["Result ",l+1]}),(0,m.jsxs)("span",{className:"text-gray-500 text-sm",children:["Score: ",(0,m.jsx)("span",{className:"font-mono",children:e.score.toFixed(4)})]})]})]}),t&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:e.content.map((e,s)=>(0,m.jsxs)("div",{className:"mb-2 last:mb-0",children:[(0,m.jsx)("div",{className:"text-xs text-gray-500 mb-1",children:e.type}),(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all bg-gray-50 p-2 rounded",children:e.text})]},s))})]},l)})})]},s))})]})}function tN(e){let{data:s}=e,[l,t]=(0,u.useState)(!0),[a,r]=(0,u.useState)(!0),[i,n]=(0,u.useState)({});if(!s)return null;let o=s.masked_entity_count?Object.values(s.masked_entity_count).reduce((e,s)=>e+s,0):0,d=e=>new Date(1e3*e).toLocaleString(),c=e=>{n(s=>({...s,[e]:!s[e]}))},h=e=>e>=.8?"text-green-600":"text-yellow-600";return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow mb-6",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b cursor-pointer hover:bg-gray-50",onClick:()=>t(!l),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 text-gray-600 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Guardrail Information"}),(0,m.jsx)("span",{className:"ml-3 px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status}),o>0&&(0,m.jsxs)("span",{className:"ml-3 px-2 py-1 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[o," masked ",1===o?"entity":"entities"]})]}),(0,m.jsx)("span",{className:"text-sm text-gray-500",children:l?"Click to collapse":"Click to expand"})]}),l&&(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg border p-4 mb-4",children:[(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail Name:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_name})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Mode:"}),(0,m.jsx)("span",{className:"font-mono",children:s.guardrail_mode})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block ".concat("success"===s.guardrail_status?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:s.guardrail_status})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:d(s.start_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:d(s.end_time)})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Duration:"}),(0,m.jsxs)("span",{children:[s.duration.toFixed(4),"s"]})]})]})]}),s.masked_entity_count&&Object.keys(s.masked_entity_count).length>0&&(0,m.jsxs)("div",{className:"mt-4 pt-4 border-t",children:[(0,m.jsx)("h4",{className:"font-medium mb-2",children:"Masked Entity Summary"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(s.masked_entity_count).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-3 py-1.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[s,": ",l]},s)})})]})]}),s.guardrail_response&&s.guardrail_response.length>0&&(0,m.jsxs)("div",{className:"mt-4",children:[(0,m.jsxs)("div",{className:"flex items-center mb-2 cursor-pointer",onClick:()=>r(!a),children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(a?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsxs)("h4",{className:"font-medium",children:["Detected Entities (",s.guardrail_response.length,")"]})]}),a&&(0,m.jsx)("div",{className:"space-y-2",children:s.guardrail_response.map((e,s)=>{let l=i[s]||!1;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 cursor-pointer hover:bg-gray-100",onClick:()=>c(s),children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("svg",{className:"w-5 h-5 mr-2 transition-transform ".concat(l?"transform rotate-90":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,m.jsx)("span",{className:"font-medium mr-2",children:e.entity_type}),(0,m.jsxs)("span",{className:"font-mono ".concat(h(e.score)),children:["Score: ",e.score.toFixed(2)]})]}),(0,m.jsxs)("span",{className:"text-xs text-gray-500",children:["Position: ",e.start,"-",e.end]})]}),l&&(0,m.jsx)("div",{className:"p-3 border-t bg-white",children:(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 mb-2",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Entity Type:"}),(0,m.jsx)("span",{children:e.entity_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Position:"}),(0,m.jsxs)("span",{children:["Characters ",e.start,"-",e.end]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Confidence:"}),(0,m.jsx)("span",{className:h(e.score),children:e.score.toFixed(2)})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[e.recognition_metadata&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Recognizer:"}),(0,m.jsx)("span",{children:e.recognition_metadata.recognizer_name})]}),(0,m.jsxs)("div",{className:"flex overflow-hidden",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Identifier:"}),(0,m.jsx)("span",{className:"truncate text-xs font-mono",children:e.recognition_metadata.recognizer_identifier})]})]}),e.analysis_explanation&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Explanation:"}),(0,m.jsx)("span",{children:e.analysis_explanation})]})]})]})})]},s)})})]})]})]})}let tw={TEAM_ID:"Team ID",KEY_HASH:"Key Hash",REQUEST_ID:"Request ID",MODEL:"Model",USER_ID:"User ID",STATUS:"Status",KEY_ALIAS:"Key Alias"};function tk(e){var s,l,t;let{accessToken:a,token:r,userRole:i,userID:n,allTeams:o}=e,[d,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(!1),[p,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(1),[v]=(0,u.useState)(50),y=(0,u.useRef)(null),Z=(0,u.useRef)(null),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(tm()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,C]=(0,u.useState)(tm()().format("YYYY-MM-DDTHH:mm")),[I,T]=(0,u.useState)(!1),[A,E]=(0,u.useState)(!1),[P,O]=(0,u.useState)(""),[L,D]=(0,u.useState)(""),[M,F]=(0,u.useState)(""),[R,q]=(0,u.useState)(""),[U,z]=(0,u.useState)(""),[V,K]=(0,u.useState)(null),[B,H]=(0,u.useState)(null),[J,G]=(0,u.useState)(""),[W,Y]=(0,u.useState)(i&&eZ.lo.includes(i)),[$,X]=(0,u.useState)(null),[Q,ee]=(0,u.useState)(null),es=(0,g.NL)();(0,u.useEffect)(()=>{(async()=>{B&&a&&K({...(await (0,b.t0)(a,B)).info,token:B,api_key:B})})()},[B,a]),(0,u.useEffect)(()=>{function e(e){y.current&&!y.current.contains(e.target)&&j(!1),Z.current&&!Z.current.contains(e.target)&&x(!1),N.current&&!N.current.contains(e.target)&&E(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,u.useEffect)(()=>{i&&eZ.lo.includes(i)&&Y(!0)},[i]);let el=(0,eY.a)({queryKey:["logs","table",f,v,w,S,M,R,W?n:null,J,U],queryFn:async()=>{if(!a||!r||!i||!n)return{data:[],total:0,page:1,page_size:v,total_pages:0};let e=tm()(w).utc().format("YYYY-MM-DD HH:mm:ss"),s=I?tm()(S).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss"),l=await (0,b.h3)(a,R||void 0,M||void 0,void 0,e,s,f,v,W?n:void 0,J,U);return await tj(l.data,e,a,es),l.data=l.data.map(s=>{let l=es.getQueryData(["logDetails",s.request_id,e]);return(null==l?void 0:l.messages)&&(null==l?void 0:l.response)&&(s.messages=l.messages,s.response=l.response),s}),l},enabled:!!a&&!!r&&!!i&&!!n,refetchInterval:5e3,refetchIntervalInBackground:!0}),{filters:et,filteredLogs:ea,allTeams:er,allKeyAliases:ei,allModels:en,handleFilterChange:eo,handleFilterReset:ed}=function(e){let{logs:s,accessToken:l,startTime:t,endTime:a,pageSize:r=25,isCustomDate:i,setCurrentPage:n,userID:o,userRole:d}=e,c=(0,u.useMemo)(()=>({[tw.TEAM_ID]:"",[tw.KEY_HASH]:"",[tw.REQUEST_ID]:"",[tw.MODEL]:"",[tw.USER_ID]:"",[tw.STATUS]:"",[tw.KEY_ALIAS]:""}),[]),[m,h]=(0,u.useState)(c),[x,p]=(0,u.useState)(s),g=(0,u.useRef)(0),j=(0,u.useCallback)(async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(!l)return;let n=Date.now();g.current=n;let o=tm()(t).utc().format("YYYY-MM-DD HH:mm:ss"),d=i?tm()(a).utc().format("YYYY-MM-DD HH:mm:ss"):tm()().utc().format("YYYY-MM-DD HH:mm:ss");try{let t=await (0,b.h3)(l,e[tw.KEY_HASH]||void 0,e[tw.TEAM_ID]||void 0,e[tw.REQUEST_ID]||void 0,o,d,s,r,e[tw.USER_ID]||void 0,e[tw.STATUS]||void 0,e[tw.MODEL]||void 0);n===g.current&&t.data&&p(t)}catch(e){console.error("Error searching users:",e)}},[l,t,a,i,r]),f=(0,u.useMemo)(()=>eb()((e,s)=>j(e,s),300),[j]);(0,u.useEffect)(()=>()=>f.cancel(),[f]);let _=(0,eY.a)({queryKey:["allKeys"],queryFn:async()=>{if(!l)throw Error("Access token required");return await e$(l)},enabled:!!l}).data||[];(0,u.useEffect)(()=>{if(!s||!s.data){p({data:[],total:0,page:1,page_size:50,total_pages:0});return}let e=[...s.data];if(m[tw.TEAM_ID]&&(e=e.filter(e=>e.team_id===m[tw.TEAM_ID])),m[tw.STATUS]&&(e=e.filter(e=>"success"===m[tw.STATUS]?!e.status||"success"===e.status:e.status===m[tw.STATUS])),m[tw.MODEL]&&(e=e.filter(e=>e.model===m[tw.MODEL])),m[tw.KEY_HASH]&&(e=e.filter(e=>e.api_key===m[tw.KEY_HASH])),m[tw.KEY_ALIAS])try{let s=m[tw.KEY_ALIAS];s&&(e=e.filter(e=>{var l;return(null===(l=e.metadata)||void 0===l?void 0:l.user_api_key_alias)===s}))}catch(e){console.error("Error fetching key info for alias:",e)}let l={data:e,total:s.total,page:s.page,page_size:s.page_size,total_pages:s.total_pages};JSON.stringify(l)!==JSON.stringify(x)&&p(l)},[s,m,x,l]);let{data:v}=(0,eY.a)({queryKey:["allTeamsForLogFilters",l],queryFn:async()=>l&&await eX(l)||[],enabled:!!l}),{data:y=[]}=(0,eY.a)({queryKey:["allModels",l,o,d],queryFn:async()=>l&&o&&d?(await (0,b.So)(l,o,d,!1,null)).data.map(e=>e.id):[],enabled:!!l&&!!o&&!!d});return{filters:m,filteredLogs:x,allKeyAliases:_,allTeams:v,allModels:y,handleFilterChange:e=>{h(s=>{let l={...s,...e};for(let e of Object.keys(c))e in l||(l[e]=c[e]);return JSON.stringify(l)!==JSON.stringify(s)&&(n(1),f(l,1)),l})},handleFilterReset:()=>{h(c),f(c,1)}}}({logs:el.data||{data:[],total:0,page:1,page_size:v||10,total_pages:1},accessToken:a,startTime:w,endTime:S,pageSize:v,isCustomDate:I,setCurrentPage:_,userID:n,userRole:i}),ec=(0,u.useCallback)(async e=>{if(a)try{let s=(await (0,b.OD)(a,null,null,e,null,null,f,v)).keys.find(s=>s.key_alias===e);s&&q(s.token)}catch(e){console.error("Error fetching key hash for alias:",e)}},[a,f,v]);(0,u.useEffect)(()=>{a&&(et["Team ID"]?F(et["Team ID"]):F(""),G(et.Status||""),z(et.Model||""),et["Key Hash"]?q(et["Key Hash"]):et["Key Alias"]?ec(et["Key Alias"]):q(""))},[et,a,ec]);let em=(0,eY.a)({queryKey:["sessionLogs",Q],queryFn:async()=>{if(!a||!Q)return{data:[],total:0,page:1,page_size:50,total_pages:1};let e=await (0,b.XB)(a,Q);return{data:e.data||e||[],total:(e.data||e||[]).length,page:1,page_size:1e3,total_pages:1}},enabled:!!a&&!!Q});if((0,u.useEffect)(()=>{var e;(null===(e=el.data)||void 0===e?void 0:e.data)&&$&&!el.data.data.some(e=>e.request_id===$)&&X(null)},[null===(s=el.data)||void 0===s?void 0:s.data,$]),!a||!r||!i||!n)return null;let eu=ea.data.filter(e=>!d||e.request_id.includes(d)||e.model.includes(d)||e.user&&e.user.includes(d)).map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{e&&ee(e)}}))||[],eh=(null===(t=em.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.map(e=>({...e,onKeyHashClick:e=>H(e),onSessionClick:e=>{}})))||[],ex=()=>{if(I)return"".concat(tm()(w).format("MMM D, h:mm A")," - ").concat(tm()(S).format("MMM D, h:mm A"));let e=tm()(),s=tm()(w),l=e.diff(s,"minutes");if(l<=15)return"Last 15 Minutes";if(l<=60)return"Last Hour";let t=e.diff(s,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(s.format("MMM D")," - ").concat(e.format("MMM D"))},ep=[{name:"Team ID",label:"Team ID",isSearchable:!0,searchFn:async e=>o&&0!==o.length?o.filter(s=>s.team_id.toLowerCase().includes(e.toLowerCase())||s.team_alias&&s.team_alias.toLowerCase().includes(e.toLowerCase())).map(e=>({label:"".concat(e.team_alias||e.team_id," (").concat(e.team_id,")"),value:e.team_id})):[]},{name:"Status",label:"Status",isSearchable:!1,options:[{label:"Success",value:"success"},{label:"Failure",value:"failure"}]},{name:"Model",label:"Model",isSearchable:!0,searchFn:async e=>en&&0!==en.length?en.filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Alias",label:"Key Alias",isSearchable:!0,searchFn:async e=>a?(await e$(a)).filter(s=>s.toLowerCase().includes(e.toLowerCase())).map(e=>({label:e,value:e})):[]},{name:"Key Hash",label:"Key Hash",isSearchable:!1}];return Q&&em.data?(0,m.jsx)("div",{className:"w-full p-6",children:(0,m.jsx)(tb,{sessionId:Q,logs:em.data.data,onBack:()=>ee(null)})}):(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:Q?(0,m.jsxs)(m.Fragment,{children:["Session: ",(0,m.jsx)("span",{className:"font-mono",children:Q}),(0,m.jsx)("button",{className:"ml-4 px-3 py-1 text-sm border rounded hover:bg-gray-50",onClick:()=>ee(null),children:"← Back to All Logs"})]}):"Request Logs"})}),V&&B&&V.api_key===B?(0,m.jsx)(eJ,{keyId:B,keyData:V,accessToken:a,userID:n,userRole:i,teams:o,onClose:()=>H(null)}):Q?(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsx)(tu,{columns:tg,data:eh,renderSubComponent:tS,getRowCanExpand:()=>!0})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eW,{options:ep,onApplyFilters:eo,onResetFilters:ed}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between space-y-4 md:space-y-0",children:[(0,m.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search by Request ID",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:d,onChange:e=>c(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsxs)("div",{className:"relative",ref:N,children:[(0,m.jsxs)("button",{onClick:()=>E(!A),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,m.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})}),ex()]}),A&&(0,m.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,m.jsxs)("div",{className:"space-y-1",children:[[{label:"Last 15 Minutes",value:15,unit:"minutes"},{label:"Last Hour",value:1,unit:"hours"},{label:"Last 4 Hours",value:4,unit:"hours"},{label:"Last 24 Hours",value:24,unit:"hours"},{label:"Last 7 Days",value:7,unit:"days"}].map(e=>(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(ex()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{C(tm()().format("YYYY-MM-DDTHH:mm")),k(tm()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),E(!1),T(!1)},children:e.label},e.label)),(0,m.jsx)("div",{className:"border-t my-2"}),(0,m.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(I?"bg-blue-50 text-blue-600":""),onClick:()=>T(!I),children:"Custom Range"})]})})]}),(0,m.jsxs)("button",{onClick:()=>{el.refetch()},className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",title:"Refresh data",children:[(0,m.jsx)("svg",{className:"w-4 h-4 ".concat(el.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,m.jsx)("span",{children:"Refresh"})]})]}),I&&(0,m.jsxs)("div",{className:"flex items-center gap-2",children:[(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:w,onChange:e=>{k(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})}),(0,m.jsx)("span",{className:"text-gray-500",children:"to"}),(0,m.jsx)("div",{children:(0,m.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{C(e.target.value),_(1)},className:"px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})})]})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",el.isLoading?"...":ea?(f-1)*v+1:0," ","-"," ",el.isLoading?"...":ea?Math.min(f*v,ea.total):0," ","of"," ",el.isLoading?"...":ea?ea.total:0," ","results"]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",el.isLoading?"...":f," of"," ",el.isLoading?"...":ea?ea.total_pages:1]}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.max(1,e-1)),disabled:el.isLoading||1===f,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,m.jsx)("button",{onClick:()=>_(e=>Math.min(ea.total_pages||1,e+1)),disabled:el.isLoading||f===(ea.total_pages||1),className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Next"})]})]})]})}),(0,m.jsx)(tu,{columns:tg,data:eu,renderSubComponent:tS,getRowCanExpand:()=>!0})]})]})]})}function tS(e){var s,l,t,a,r;let{row:i}=e,n=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e},o=i.original.metadata||{},d="failure"===o.status,c=d?o.error_information:null,u=i.original.messages&&(Array.isArray(i.original.messages)?i.original.messages.length>0:Object.keys(i.original.messages).length>0),h=i.original.response&&Object.keys(n(i.original.response)).length>0,x=o.vector_store_request_metadata&&Array.isArray(o.vector_store_request_metadata)&&o.vector_store_request_metadata.length>0,p=i.original.metadata&&i.original.metadata.guardrail_information,g=p&&(null===(r=i.original.metadata)||void 0===r?void 0:r.guardrail_information.masked_entity_count)?Object.values(i.original.metadata.guardrail_information.masked_entity_count).reduce((e,s)=>e+("number"==typeof s?s:0),0):0;return(0,m.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Details"})}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4 p-4",children:[(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,m.jsx)("span",{className:"font-mono text-sm",children:i.original.request_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,m.jsx)("span",{children:i.original.model})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Model ID:"}),(0,m.jsx)("span",{children:i.original.model_id})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,m.jsx)("span",{children:i.original.call_type})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Provider:"}),(0,m.jsx)("span",{children:i.original.custom_llm_provider||"-"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"API Base:"}),(0,m.jsx)(Y.Z,{title:i.original.api_base||"-",children:(0,m.jsx)("span",{className:"max-w-[15ch] truncate block",children:i.original.api_base||"-"})})]}),(null==i?void 0:null===(s=i.original)||void 0===s?void 0:s.requester_ip_address)&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"IP Address:"}),(0,m.jsx)("span",{children:null==i?void 0:null===(l=i.original)||void 0===l?void 0:l.requester_ip_address})]}),p&&(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Guardrail:"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{className:"font-mono",children:i.original.metadata.guardrail_information.guardrail_name}),g>0&&(0,m.jsxs)("span",{className:"ml-2 px-2 py-0.5 bg-blue-50 text-blue-700 rounded-md text-xs font-medium",children:[g," masked"]})]})]})]}),(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Tokens:"}),(0,m.jsxs)("span",{children:[i.original.total_tokens," (",i.original.prompt_tokens,"+",i.original.completion_tokens,")"]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cost:"}),(0,m.jsxs)("span",{children:["$",Number(i.original.spend||0).toFixed(6)]})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,m.jsx)("span",{children:i.original.cache_hit})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Status:"}),(0,m.jsx)("span",{className:"px-2 py-1 rounded-md text-xs font-medium inline-block text-center w-16 ".concat("failure"!==((null===(t=i.original.metadata)||void 0===t?void 0:t.status)||"Success").toLowerCase()?"bg-green-100 text-green-800":"bg-red-100 text-red-800"),children:"failure"!==((null===(a=i.original.metadata)||void 0===a?void 0:a.status)||"Success").toLowerCase()?"Success":"Failure"})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,m.jsx)("span",{children:i.original.startTime})]}),(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,m.jsx)("span",{children:i.original.endTime})]})]})]})]}),(0,m.jsx)(tv,{show:!u&&!h}),(0,m.jsx)(tf,{row:i,hasMessages:u,hasResponse:h,hasError:d,errorInfo:c,getRawRequest:()=>{var e;return(null===(e=i.original)||void 0===e?void 0:e.proxy_server_request)?n(i.original.proxy_server_request):n(i.original.messages)},formattedResponse:()=>d&&c?{error:{message:c.error_message||"An error occurred",type:c.error_class||"error",code:c.error_code||"unknown",param:null}}:n(i.original.response)}),p&&(0,m.jsx)(tN,{data:i.original.metadata.guardrail_information}),x&&(0,m.jsx)(tZ,{data:o.vector_store_request_metadata}),d&&c&&(0,m.jsx)(t_,{errorInfo:c}),i.original.request_tags&&Object.keys(i.original.request_tags).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,m.jsx)("div",{className:"p-4",children:(0,m.jsx)("div",{className:"flex flex-wrap gap-2",children:Object.entries(i.original.request_tags).map(e=>{let[s,l]=e;return(0,m.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[s,": ",String(l)]},s)})})})]}),i.original.metadata&&Object.keys(i.original.metadata).length>0&&(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,m.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(JSON.stringify(i.original.metadata,null,2))},className:"p-1 hover:bg-gray-200 rounded",title:"Copy metadata",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,m.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]}),(0,m.jsx)("div",{className:"p-4 overflow-auto max-h-64",children:(0,m.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:JSON.stringify(i.original.metadata,null,2)})})]})]})}var tC=l(92699),tI=l(14042);console.log=function(){};var tT=e=>{let{userID:s,userRole:l,accessToken:t,userSpend:a,userMaxBudget:r,selectedTeam:i}=e;console.log("userSpend: ".concat(a));let[n,o]=(0,u.useState)(null!==a?a:0),[d,c]=(0,u.useState)(i?i.max_budget:null);(0,u.useEffect)(()=>{if(i){if("Default Team"===i.team_alias)c(r);else{let e=!1;if(i.team_memberships)for(let l of i.team_memberships)l.user_id===s&&"max_budget"in l.litellm_budget_table&&null!==l.litellm_budget_table.max_budget&&(c(l.litellm_budget_table.max_budget),e=!0);e||c(i.max_budget)}}},[i,r]);let[h,x]=(0,u.useState)([]);(0,u.useEffect)(()=>{let e=async()=>{if(!t||!s||!l)return};(async()=>{try{if(null===s||null===l)return;if(null!==t){let e=(await (0,b.So)(t,s,l)).data.map(e=>e.id);console.log("available_model_names:",e),x(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[l,t,s]),(0,u.useEffect)(()=>{null!==a&&o(a)},[a]);let p=[];i&&i.models&&(p=i.models),p&&p.includes("all-proxy-models")?(console.log("user models:",h),p=h):p&&p.includes("all-team-models")?p=i.models:p&&0===p.length&&(p=h);let g=void 0!==n?n.toFixed(4):null;return console.log("spend in view user spend: ".concat(n)),(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,m.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==d?"$".concat(d," limit"):"No limit"})]})]})})};let tA=e=>{let{key:s,info:l}=e;return{token:s,...l}};var tE=e=>{let{topKeys:s,accessToken:l,userID:t,userRole:a,teams:r}=e,[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(void 0),[x,p]=(0,u.useState)("table"),g=async e=>{if(l)try{let s=await (0,b.t0)(l,e.api_key),t=tA(s);h(t),d(e.api_key),n(!0)}catch(e){console.error("Error fetching key info:",e)}},j=()=>{n(!1),d(null),h(void 0)};return u.useEffect(()=>{let e=e=>{"Escape"===e.key&&i&&j()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[i]),(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("div",{className:"mb-4 flex justify-end items-center",children:(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)("button",{onClick:()=>p("table"),className:"px-3 py-1 text-sm rounded-md ".concat("table"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Table View"}),(0,m.jsx)("button",{onClick:()=>p("chart"),className:"px-3 py-1 text-sm rounded-md ".concat("chart"===x?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"),children:"Chart View"})]})}),"chart"===x?(0,m.jsx)("div",{className:"relative",children:(0,m.jsx)(sT.Z,{className:"mt-4 h-40 cursor-pointer hover:opacity-90",data:s,index:"key_alias",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>e?"$".concat(e.toFixed(2)):"No Key Alias",onValueChange:e=>g(e),showTooltip:!0,customTooltip:e=>{var s,l,t;let a=null===(l=e.payload)||void 0===l?void 0:null===(s=l[0])||void 0===s?void 0:s.payload;return(0,m.jsx)("div",{className:"p-3 bg-black/90 shadow-lg rounded-lg text-white",children:(0,m.jsxs)("div",{className:"space-y-1.5",children:[(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Key: "}),(0,m.jsxs)("span",{className:"font-mono text-gray-100",children:[null==a?void 0:null===(t=a.api_key)||void 0===t?void 0:t.slice(0,10),"..."]})]}),(0,m.jsxs)("div",{className:"text-sm",children:[(0,m.jsx)("span",{className:"text-gray-300",children:"Spend: "}),(0,m.jsxs)("span",{className:"text-white font-medium",children:["$",null==a?void 0:a.spend.toFixed(2)]})]})]})})}})}):(0,m.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,m.jsx)(tu,{columns:[{header:"Key ID",accessorKey:"api_key",cell:e=>(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:e.getValue(),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>g(e.row.original),children:e.getValue()?"".concat(e.getValue().slice(0,7),"..."):"-"})})})},{header:"Key Alias",accessorKey:"key_alias",cell:e=>e.getValue()||"-"},{header:"Spend (USD)",accessorKey:"spend",cell:e=>"$".concat(Number(e.getValue()).toFixed(2))}],data:s,renderSubComponent:()=>(0,m.jsx)(m.Fragment,{}),getRowCanExpand:()=>!1,isLoading:!1})}),i&&o&&c&&(console.log("Rendering modal with:",{isModalOpen:i,selectedKey:o,keyData:c}),(0,m.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",onClick:e=>{e.target===e.currentTarget&&j()},children:(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-xl relative w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto min-h-[750px]",children:[(0,m.jsx)("button",{onClick:j,className:"absolute top-4 right-4 text-gray-500 hover:text-gray-700 focus:outline-none","aria-label":"Close",children:(0,m.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),(0,m.jsx)("div",{className:"p-6 h-full",children:(0,m.jsx)(eJ,{keyId:o,onClose:j,keyData:c,accessToken:l,userID:t,userRole:a,teams:r})})]})}))]})},tP=l(44851);let tO=e=>{var s,l;let{modelName:t,metrics:a}=e;return(0,m.jsxs)("div",{className:"space-y-2",children:[(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:a.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:a.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:a.total_tokens.toLocaleString()}),(0,m.jsxs)(P.Z,{children:[Math.round(a.total_tokens/a.total_successful_requests)," avg per successful request"]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",a.total_spend.toFixed(2)]}),(0,m.jsxs)(P.Z,{children:["$",(a.total_spend/a.total_successful_requests).toFixed(3)," per successful request"]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Requests per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.api_requests"],colors:["blue"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend per day"}),(0,m.jsx)(sT.Z,{data:a.daily_data,index:"date",categories:["metrics.spend"],colors:["green"],valueFormatter:e=>"$".concat(e.toFixed(2))})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Success vs Failed Requests"}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Prompt Caching Metrics"}),(0,m.jsxs)("div",{className:"mb-2",children:[(0,m.jsxs)(P.Z,{children:["Cache Read: ",(null===(s=a.total_cache_read_input_tokens)||void 0===s?void 0:s.toLocaleString())||0," tokens"]}),(0,m.jsxs)(P.Z,{children:["Cache Creation: ",(null===(l=a.total_cache_creation_input_tokens)||void 0===l?void 0:l.toLocaleString())||0," tokens"]})]}),(0,m.jsx)(sI.Z,{data:a.daily_data,index:"date",categories:["metrics.cache_read_input_tokens","metrics.cache_creation_input_tokens"],colors:["cyan","purple"],valueFormatter:e=>e.toLocaleString()})]})]})]})},tL=e=>{let{modelMetrics:s}=e,l=Object.keys(s).sort((e,l)=>""===e?1:""===l?-1:s[l].total_spend-s[e].total_spend),t={total_requests:0,total_successful_requests:0,total_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:{}};Object.values(s).forEach(e=>{t.total_requests+=e.total_requests,t.total_successful_requests+=e.total_successful_requests,t.total_tokens+=e.total_tokens,t.total_spend+=e.total_spend,t.total_cache_read_input_tokens+=e.total_cache_read_input_tokens||0,t.total_cache_creation_input_tokens+=e.total_cache_creation_input_tokens||0,e.daily_data.forEach(e=>{t.daily_data[e.date]||(t.daily_data[e.date]={prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,spend:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0}),t.daily_data[e.date].prompt_tokens+=e.metrics.prompt_tokens,t.daily_data[e.date].completion_tokens+=e.metrics.completion_tokens,t.daily_data[e.date].total_tokens+=e.metrics.total_tokens,t.daily_data[e.date].api_requests+=e.metrics.api_requests,t.daily_data[e.date].spend+=e.metrics.spend,t.daily_data[e.date].successful_requests+=e.metrics.successful_requests,t.daily_data[e.date].failed_requests+=e.metrics.failed_requests,t.daily_data[e.date].cache_read_input_tokens+=e.metrics.cache_read_input_tokens||0,t.daily_data[e.date].cache_creation_input_tokens+=e.metrics.cache_creation_input_tokens||0})});let a=Object.entries(t.daily_data).map(e=>{let[s,l]=e;return{date:s,metrics:l}}).sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime());return(0,m.jsxs)("div",{className:"space-y-8",children:[(0,m.jsxs)("div",{className:"border rounded-lg p-4",children:[(0,m.jsx)(O.Z,{children:"Overall Usage"}),(0,m.jsxs)(S.Z,{numItems:4,className:"gap-4 mb-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Requests"}),(0,m.jsx)(O.Z,{children:t.total_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Successful Requests"}),(0,m.jsx)(O.Z,{children:t.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Tokens"}),(0,m.jsx)(O.Z,{children:t.total_tokens.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Total Spend"}),(0,m.jsxs)(O.Z,{children:["$",t.total_spend.toFixed(2)]})]})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.prompt_tokens","metrics.completion_tokens","metrics.total_tokens"],colors:["blue","cyan","indigo"],valueFormatter:e=>e.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests Over Time"}),(0,m.jsx)(sI.Z,{data:a,index:"date",categories:["metrics.successful_requests","metrics.failed_requests"],colors:["emerald","red"],valueFormatter:e=>e.toLocaleString(),stack:!0})]})]})]}),(0,m.jsx)(tP.Z,{defaultActiveKey:l[0],children:l.map(e=>(0,m.jsx)(tP.Z.Panel,{header:(0,m.jsxs)("div",{className:"flex justify-between items-center w-full",children:[(0,m.jsx)(O.Z,{children:s[e].label||"Unknown Item"}),(0,m.jsxs)("div",{className:"flex space-x-4 text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["$",s[e].total_spend.toFixed(2)]}),(0,m.jsxs)("span",{children:[s[e].total_requests.toLocaleString()," requests"]})]})]}),children:(0,m.jsx)(tO,{modelName:e||"Unknown Model",metrics:s[e]})},e))})]})},tD=(e,s)=>{let l=e.metadata.key_alias||"key-hash-".concat(s),t=e.metadata.team_id;return t?"".concat(l," (team_id: ").concat(t,")"):l},tM=(e,s)=>{let l={};return e.results.forEach(e=>{Object.entries(e.breakdown[s]||{}).forEach(t=>{let[a,r]=t;l[a]||(l[a]={label:"api_keys"===s?tD(r,a):a,total_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0,prompt_tokens:0,completion_tokens:0,total_spend:0,total_cache_read_input_tokens:0,total_cache_creation_input_tokens:0,daily_data:[]}),l[a].total_requests+=r.metrics.api_requests,l[a].prompt_tokens+=r.metrics.prompt_tokens,l[a].completion_tokens+=r.metrics.completion_tokens,l[a].total_tokens+=r.metrics.total_tokens,l[a].total_spend+=r.metrics.spend,l[a].total_successful_requests+=r.metrics.successful_requests,l[a].total_failed_requests+=r.metrics.failed_requests,l[a].total_cache_read_input_tokens+=r.metrics.cache_read_input_tokens||0,l[a].total_cache_creation_input_tokens+=r.metrics.cache_creation_input_tokens||0,l[a].daily_data.push({date:e.date,metrics:{prompt_tokens:r.metrics.prompt_tokens,completion_tokens:r.metrics.completion_tokens,total_tokens:r.metrics.total_tokens,api_requests:r.metrics.api_requests,spend:r.metrics.spend,successful_requests:r.metrics.successful_requests,failed_requests:r.metrics.failed_requests,cache_read_input_tokens:r.metrics.cache_read_input_tokens||0,cache_creation_input_tokens:r.metrics.cache_creation_input_tokens||0}})})}),Object.values(l).forEach(e=>{e.daily_data.sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime())}),l};var tF=e=>{let{accessToken:s,entityType:l,entityId:t,userID:a,userRole:r,entityList:i}=e,[n,o]=(0,u.useState)({results:[],metadata:{total_spend:0,total_api_requests:0,total_successful_requests:0,total_failed_requests:0,total_tokens:0}}),d=tM(n,"models"),c=tM(n,"api_keys"),[h,x]=(0,u.useState)([]),[p,g]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),j=async()=>{if(!s||!p.from||!p.to)return;let e=p.from,t=p.to;if("tag"===l)o(await (0,b.Z9)(s,e,t,1,h.length>0?h:null));else if("team"===l)o(await (0,b.ol)(s,e,t,1,h.length>0?h:null));else throw Error("Invalid entity type")};(0,u.useEffect)(()=>{j()},[s,p,t,h]);let f=()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={provider:l,spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend,e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens}catch(e){console.log("Error processing provider ".concat(l,": ").concat(e))}})}),Object.values(e).filter(e=>e.spend>0).sort((e,s)=>s.spend-e.spend)},_=e=>0===h.length?e:e.filter(e=>h.includes(e.metadata.id)),v=()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.entities||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{alias:t.metadata.team_alias||l,id:l}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.total_tokens+=t.metrics.total_tokens})}),_(Object.values(e).sort((e,s)=>s.metrics.spend-e.metrics.spend))};return(0,m.jsxs)("div",{style:{width:"100%"},children:[(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:p,onValueChange:g})]}),i&&i.length>0&&(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(P.Z,{children:["Filter by ","tag"===l?"Tags":"Teams"]}),(0,m.jsx)(D.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select ".concat("tag"===l?"tags":"teams"," to filter..."),value:h,onChange:x,options:(()=>{if(i)return i})(),className:"mt-2",allowClear:!0})]})]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(O.Z,{children:["tag"===l?"Tag":"Team"," Spend Overview"]}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Spend"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",n.metadata.total_spend.toFixed(2)]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:n.metadata.total_api_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:n.metadata.total_successful_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:n.metadata.total_failed_requests.toLocaleString()})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:n.metadata.total_tokens.toLocaleString()})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...n.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:t}=e;if(!t||!(null==s?void 0:s[0]))return null;let a=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:a.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Total Spend: $",a.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",a.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",a.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",a.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Tokens: ",a.metrics.total_tokens]}),(0,m.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,m.jsxs)("p",{className:"font-semibold",children:["Spend by ","tag"===l?"Tag":"Team",":"]}),Object.entries(a.breakdown.entities||{}).map(e=>{let[s,l]=e;return(0,m.jsxs)("p",{className:"text-sm text-gray-600",children:[l.metadata.team_alias||s,": $",l.metrics.spend.toFixed(2)]},s)})]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,m.jsxs)(O.Z,{children:["Spend Per ","tag"===l?"Tag":"Team"]}),(0,m.jsxs)("div",{className:"flex items-center text-sm text-gray-500",children:[(0,m.jsxs)("span",{children:["Get Started Tracking cost per ",l," "]}),(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tags",className:"text-blue-500 hover:text-blue-700 ml-1",children:"here"})]})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sT.Z,{className:"mt-4 h-52",data:v(),index:"metadata.alias",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(4)),layout:"vertical",showLegend:!1,yAxisWidth:100})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"tag"===l?"Tag":"Team"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:v().filter(e=>e.metrics.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.metadata.alias}),(0,m.jsxs)(e6.Z,{children:["$",e.metrics.spend.toFixed(4)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.metrics.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.metrics.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.metrics.total_tokens.toLocaleString()})]},e.metadata.id))})]})})]})]})})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:s,userID:a,userRole:r,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return n.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={spend:0,requests:0,successful_requests:0,failed_requests:0,tokens:0});try{e[l].spend+=t.metrics.spend}catch(e){console.log("Error adding spend for ".concat(l,": ").concat(e,", got metrics: ").concat(JSON.stringify(t)))}e[l].requests+=t.metrics.api_requests,e[l].successful_requests+=t.metrics.successful_requests,e[l].failed_requests+=t.metrics.failed_requests,e[l].tokens+=t.metrics.total_tokens})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,...l}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsx)(eD.Z,{children:(0,m.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,m.jsx)(O.Z,{children:"Provider Usage"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:f(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan","blue","indigo","violet","purple"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:f().map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:d})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:c})})]})]})]})},tR=e=>{var s,l,t,a,r,i,n,o,d,c;let{accessToken:h,userRole:x,userID:p,teams:g}=e,[j,f]=(0,u.useState)({results:[],metadata:{}}),[_,v]=(0,u.useState)({from:new Date(Date.now()-24192e5),to:new Date}),[y,Z]=(0,u.useState)([]),N=async()=>{h&&Z(Object.values(await (0,b.UM)(h)).map(e=>({label:e.name,value:e.name})))};(0,u.useEffect)(()=>{N()},[h]);let w=(null===(s=j.metadata)||void 0===s?void 0:s.total_spend)||0,C=()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.providers||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{provider:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}})},I=async()=>{if(!h||!_.from||!_.to)return;let e=_.from,s=_.to;try{let l=await (0,b.xX)(h,e,s);if(l.metadata.total_pages>10)throw Error("Too many pages of data (>10). Please select a smaller date range.");if(1===l.metadata.total_pages){f(l);return}let t=[...l.results];for(let a=2;a<=l.metadata.total_pages;a++){let l=await (0,b.xX)(h,e,s,a);t.push(...l.results)}f({results:t,metadata:l.metadata})}catch(e){throw console.error("Error fetching user spend data:",e),e}};(0,u.useEffect)(()=>{I()},[h,_]);let T=tM(j,"models"),A=tM(j,"api_keys");return(0,m.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,m.jsxs)(P.Z,{className:"text-sm text-gray-500 mb-4",children:["This is the new usage dashboard. ",(0,m.jsx)("br",{})," You may see empty data, as these use ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/blob/6de348125208dd4be81ff0e5813753df2fbe9735/schema.prisma#L320",className:"text-blue-500 hover:text-blue-700 ml-1",children:"new aggregate tables"})," to allow UI to work at 1M+ spend logs. To access the old dashboard, go to Experimental ",">"," Old Usage."]}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Global Usage"}):(0,m.jsx)(eM.Z,{children:"Your Usage"}),(0,m.jsx)(eM.Z,{children:"Team Usage"}),eZ.ZL.includes(x||"")?(0,m.jsx)(eM.Z,{children:"Tag Usage"}):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsx)(S.Z,{numItems:2,className:"gap-2 w-full mb-4",children:(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:_,onValueChange:e=>{v(e)}})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Model Activity"}),(0,m.jsx)(eM.Z,{children:"Key Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:p,userRole:x,accessToken:h,userSpend:w,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Usage Metrics"}),(0,m.jsxs)(S.Z,{numItems:5,className:"gap-4 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(t=j.metadata)||void 0===t?void 0:null===(l=t.total_api_requests)||void 0===l?void 0:l.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Successful Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-green-600",children:(null===(r=j.metadata)||void 0===r?void 0:null===(a=r.total_successful_requests)||void 0===a?void 0:a.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Failed Requests"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2 text-red-600",children:(null===(n=j.metadata)||void 0===n?void 0:null===(i=n.total_failed_requests)||void 0===i?void 0:i.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Total Tokens"}),(0,m.jsx)(P.Z,{className:"text-2xl font-bold mt-2",children:(null===(d=j.metadata)||void 0===d?void 0:null===(o=d.total_tokens)||void 0===o?void 0:o.toLocaleString())||0})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Average Cost per Request"}),(0,m.jsxs)(P.Z,{className:"text-2xl font-bold mt-2",children:["$",((w||0)/((null===(c=j.metadata)||void 0===c?void 0:c.total_api_requests)||1)).toFixed(4)]})]})]})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend"}),(0,m.jsx)(sT.Z,{data:[...j.results].sort((e,s)=>new Date(e.date).getTime()-new Date(s.date).getTime()),index:"date",categories:["metrics.spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),yAxisWidth:100,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.date}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.metrics.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Requests: ",t.metrics.api_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Successful: ",t.metrics.successful_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Failed: ",t.metrics.failed_requests]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.metrics.total_tokens]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.api_keys||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{key_alias:t.metadata.key_alias}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests,e[l].metrics.failed_requests+=t.metrics.failed_requests,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{api_key:s,key_alias:l.metadata.key_alias||"-",spend:l.metrics.spend}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),accessToken:h,userID:p,userRole:x,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Top Models"})}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:(()=>{let e={};return j.results.forEach(s=>{Object.entries(s.breakdown.models||{}).forEach(s=>{let[l,t]=s;e[l]||(e[l]={metrics:{spend:0,prompt_tokens:0,completion_tokens:0,total_tokens:0,api_requests:0,successful_requests:0,failed_requests:0,cache_read_input_tokens:0,cache_creation_input_tokens:0},metadata:{}}),e[l].metrics.spend+=t.metrics.spend,e[l].metrics.prompt_tokens+=t.metrics.prompt_tokens,e[l].metrics.completion_tokens+=t.metrics.completion_tokens,e[l].metrics.total_tokens+=t.metrics.total_tokens,e[l].metrics.api_requests+=t.metrics.api_requests,e[l].metrics.successful_requests+=t.metrics.successful_requests||0,e[l].metrics.failed_requests+=t.metrics.failed_requests||0,e[l].metrics.cache_read_input_tokens+=t.metrics.cache_read_input_tokens||0,e[l].metrics.cache_creation_input_tokens+=t.metrics.cache_creation_input_tokens||0})}),Object.entries(e).map(e=>{let[s,l]=e;return{key:s,spend:l.metrics.spend,requests:l.metrics.api_requests,successful_requests:l.metrics.successful_requests,failed_requests:l.metrics.failed_requests,tokens:l.metrics.total_tokens}}).sort((e,s)=>s.spend-e.spend).slice(0,5)})(),index:"key",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2)),layout:"vertical",yAxisWidth:200,showLegend:!1,customTooltip:e=>{let{payload:s,active:l}=e;if(!l||!(null==s?void 0:s[0]))return null;let t=s[0].payload;return(0,m.jsxs)("div",{className:"bg-white p-4 shadow-lg rounded-lg border",children:[(0,m.jsx)("p",{className:"font-bold",children:t.key}),(0,m.jsxs)("p",{className:"text-cyan-500",children:["Spend: $",t.spend.toFixed(2)]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Total Requests: ",t.requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-green-600",children:["Successful: ",t.successful_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-red-600",children:["Failed: ",t.failed_requests.toLocaleString()]}),(0,m.jsxs)("p",{className:"text-gray-600",children:["Tokens: ",t.tokens.toLocaleString()]})]})}})]})}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(O.Z,{children:"Spend by Provider"})}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",data:C(),index:"provider",category:"spend",valueFormatter:e=>"$".concat(e.toFixed(2)),colors:["cyan"]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{className:"text-green-600",children:"Successful"}),(0,m.jsx)(e7.Z,{className:"text-red-600",children:"Failed"}),(0,m.jsx)(e7.Z,{children:"Tokens"})]})}),(0,m.jsx)(e3.Z,{children:C().filter(e=>e.spend>0).map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsxs)(e6.Z,{children:["$",e.spend<1e-5?"less than 0.00001":e.spend.toFixed(2)]}),(0,m.jsx)(e6.Z,{className:"text-green-600",children:e.successful_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{className:"text-red-600",children:e.failed_requests.toLocaleString()}),(0,m.jsx)(e6.Z,{children:e.tokens.toLocaleString()})]},e.provider))})]})})]})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:T})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tL,{modelMetrics:A})})]})]})]}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"team",userID:p,userRole:x,entityList:(null==g?void 0:g.map(e=>({label:e.team_alias,value:e.team_id})))||null})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(tF,{accessToken:h,entityType:"tag",userID:p,userRole:x,entityList:y})})]})]})]})},tq=e=>{let{proxySettings:s}=e,l="";return s&&s.PROXY_BASE_URL&&void 0!==s.PROXY_BASE_URL&&(l=s.PROXY_BASE_URL),(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(S.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,m.jsxs)("div",{className:"mb-5",children:[(0,m.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,m.jsx)(P.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{children:[(0,m.jsx)(eM.Z,{children:"OpenAI Python SDK"}),(0,m.jsx)(eM.Z,{children:"LlamaIndex"}),(0,m.jsx)(eM.Z,{children:"Langchain Py"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(l,'" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nimport os, dotenv\n\nfrom llama_index.llms import AzureOpenAI\nfrom llama_index.embeddings import AzureOpenAIEmbedding\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext\n\nllm = AzureOpenAI(\n engine="azure-gpt-3.5", # model_name on litellm proxy\n temperature=0.0,\n azure_endpoint="'.concat(l,'", # litellm proxy endpoint\n api_key="sk-1234", # litellm proxy API Key\n api_version="2023-07-01-preview",\n)\n\nembed_model = AzureOpenAIEmbedding(\n deployment_name="azure-embedding-model",\n azure_endpoint="').concat(l,'",\n api_key="sk-1234",\n api_version="2023-07-01-preview",\n)\n\n\ndocuments = SimpleDirectoryReader("llama_index_data").load_data()\nservice_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)\nindex = VectorStoreIndex.from_documents(documents, service_context=service_context)\n\nquery_engine = index.as_query_engine()\nresponse = query_engine.query("What did the author do growing up?")\nprint(response)\n\n ')})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(to.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="'.concat(l,'",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n ')})})]})]})]})})})},tU=l(243),tz=l(93837);async function tV(e,s,l,t,a,r,i,n,o,d,c,m){console.log=function(){},console.log("isLocal:",!1);let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t;let a=Date.now(),u=!1;for await(let h of(await x.chat.completions.create({model:l,stream:!0,stream_options:{include_usage:!0},litellm_trace_id:d,messages:e,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r}))){var p,g,j,f,_,v,y,b;console.log("Stream chunk:",h);let e=null===(p=h.choices[0])||void 0===p?void 0:p.delta;if(console.log("Delta content:",null===(j=h.choices[0])||void 0===j?void 0:null===(g=j.delta)||void 0===g?void 0:g.content),console.log("Delta reasoning content:",null==e?void 0:e.reasoning_content),!u&&((null===(_=h.choices[0])||void 0===_?void 0:null===(f=_.delta)||void 0===f?void 0:f.content)||e&&e.reasoning_content)&&(u=!0,t=Date.now()-a,console.log("First token received! Time:",t,"ms"),n?(console.log("Calling onTimingData with:",t),n(t)):console.log("onTimingData callback is not defined!")),null===(y=h.choices[0])||void 0===y?void 0:null===(v=y.delta)||void 0===v?void 0:v.content){let e=h.choices[0].delta.content;s(e,h.model)}if(e&&e.reasoning_content){let s=e.reasoning_content;i&&i(s)}if(h.usage&&o){console.log("Usage data found:",h.usage);let e={completionTokens:h.usage.completion_tokens,promptTokens:h.usage.prompt_tokens,totalTokens:h.usage.total_tokens};(null===(b=h.usage.completion_tokens_details)||void 0===b?void 0:b.reasoning_tokens)&&(e.reasoningTokens=h.usage.completion_tokens_details.reasoning_tokens),o(e)}}}catch(e){throw(null==r?void 0:r.aborted)&&console.log("Chat completion request was cancelled"),e}}async function tK(e,s,l,t,a,r){console.log=function(){},console.log("isLocal:",!1);let i=window.location.origin,n=new l6.ZP.OpenAI({apiKey:t,baseURL:i,dangerouslyAllowBrowser:!0,defaultHeaders:a&&a.length>0?{"x-litellm-tags":a.join(",")}:void 0});try{let t=await n.images.generate({model:l,prompt:e},{signal:r});if(console.log(t.data),t.data&&t.data[0]){if(t.data[0].url)s(t.data[0].url,l);else if(t.data[0].b64_json){let e=t.data[0].b64_json;s("data:image/png;base64,".concat(e),l)}else throw Error("No image data found in response")}else throw Error("Invalid response format")}catch(e){throw(null==r?void 0:r.aborted)?console.log("Image generation request was cancelled"):F.ZP.error("Error occurred while generating image. Please try again. Error: ".concat(e),20),e}}async function tB(e,s,l,t){let a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],r=arguments.length>5?arguments[5]:void 0,i=arguments.length>6?arguments[6]:void 0,n=arguments.length>7?arguments[7]:void 0,o=arguments.length>8?arguments[8]:void 0,d=arguments.length>9?arguments[9]:void 0,c=arguments.length>10?arguments[10]:void 0,m=arguments.length>11?arguments[11]:void 0;if(!t)throw Error("API key is required");console.log=function(){};let u=window.location.origin,h={};a&&a.length>0&&(h["x-litellm-tags"]=a.join(","));let x=new l6.ZP.OpenAI({apiKey:t,baseURL:u,dangerouslyAllowBrowser:!0,defaultHeaders:h});try{let t=Date.now(),a=!1,u=e.map(e=>({role:e.role,content:e.content,type:"message"}));for await(let e of(await x.responses.create({model:l,input:u,stream:!0,litellm_trace_id:d,...c?{vector_store_ids:c}:{},...m?{guardrails:m}:{}},{signal:r})))if(console.log("Response event:",e),"object"==typeof e&&null!==e){if("response.role.delta"===e.type)continue;if("response.output_text.delta"===e.type&&"string"==typeof e.delta){let r=e.delta;if(console.log("Text delta",r),r.trim().length>0&&(s("assistant",r,l),!a)){a=!0;let e=Date.now()-t;console.log("First token received! Time:",e,"ms"),n&&n(e)}}if("response.reasoning.delta"===e.type&&"delta"in e){let s=e.delta;"string"==typeof s&&i&&i(s)}if("response.completed"===e.type&&"response"in e){let s=e.response.usage;if(console.log("Usage data:",s),s&&o){var p;console.log("Usage data:",s);let e={completionTokens:s.output_tokens,promptTokens:s.input_tokens,totalTokens:s.total_tokens};(null===(p=s.completion_tokens_details)||void 0===p?void 0:p.reasoning_tokens)&&(e.reasoningTokens=s.completion_tokens_details.reasoning_tokens),o(e)}}}}catch(e){throw(null==r?void 0:r.aborted)?console.log("Responses API request was cancelled"):F.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20),e}}let tH=async e=>{try{let s=await (0,b.kn)(e);if(console.log("model_info:",s),(null==s?void 0:s.data.length)>0){let e=s.data.map(e=>({model_group:e.model_group,mode:null==e?void 0:e.mode}));return e.sort((e,s)=>e.model_group.localeCompare(s.model_group)),e}return[]}catch(e){throw console.error("Error fetching model info:",e),e}};(a=o||(o={})).IMAGE_GENERATION="image_generation",a.CHAT="chat",a.RESPONSES="responses",(r=d||(d={})).IMAGE="image",r.CHAT="chat",r.RESPONSES="responses";let tJ={image_generation:"image",chat:"chat",responses:"responses"},tG=e=>{if(console.log("getEndpointType:",e),Object.values(o).includes(e)){let s=tJ[e];return console.log("endpointType:",s),s}return"chat"};var tW=l(94263),tY=e=>{let{endpointType:s,onEndpointChange:l,className:t}=e,a=[{value:d.CHAT,label:"/v1/chat/completions"},{value:d.RESPONSES,label:"/v1/responses"},{value:d.IMAGE,label:"/v1/images/generations"}];return(0,m.jsxs)("div",{className:t,children:[(0,m.jsx)(P.Z,{children:"Endpoint Type:"}),(0,m.jsx)(D.default,{value:s,style:{width:"100%"},onChange:l,options:a,className:"rounded-md"})]})},t$=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a)try{let e=await (0,b.UM)(a);console.log("List tags response:",e),i(Object.values(e))}catch(e){console.error("Error fetching tags:",e)}})()},[]),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select tags",onChange:s,value:l,loading:n,className:t,options:r.map(e=>({label:e.name,value:e.name,title:e.description||e.name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})},tX=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.Ou)(a);e.data&&i(e.data)}catch(e){console.error("Error fetching vector stores:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select vector stores",onChange:s,value:l,loading:n,className:t,options:r.map(e=>({label:"".concat(e.vector_store_name||e.vector_store_id," (").concat(e.vector_store_id,")"),value:e.vector_store_id,title:e.vector_store_description||e.vector_store_id})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})},tQ=e=>{let{onChange:s,value:l,className:t,accessToken:a}=e,[r,i]=(0,u.useState)([]),[n,o]=(0,u.useState)(!1);return(0,u.useEffect)(()=>{(async()=>{if(a){o(!0);try{let e=await (0,b.t3)(a);console.log("Guardrails response:",e),e.guardrails&&(console.log("Guardrails data:",e.guardrails),i(e.guardrails))}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}})()},[a]),(0,m.jsx)("div",{children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select guardrails",onChange:e=>{console.log("Selected guardrails:",e),s(e)},value:l,loading:n,className:t,options:r.map(e=>(console.log("Mapping guardrail:",e),{label:"".concat(e.guardrail_name),value:e.guardrail_name})),optionFilterProp:"label",showSearch:!0,style:{width:"100%"}})})};let t0=(e,s)=>{let l=s.find(s=>s.model_group===e);return(null==l?void 0:l.mode)?tG(l.mode):d.CHAT};var t1=l(83322),t2=l(70464),t4=l(77565),t5=e=>{let{reasoningContent:s}=e,[l,t]=(0,u.useState)(!0);return s?(0,m.jsxs)("div",{className:"reasoning-content mt-1 mb-2",children:[(0,m.jsxs)(U.ZP,{type:"text",className:"flex items-center text-xs text-gray-500 hover:text-gray-700",onClick:()=>t(!l),icon:(0,m.jsx)(t1.Z,{}),children:[l?"Hide reasoning":"Show reasoning",l?(0,m.jsx)(t2.Z,{className:"ml-1"}):(0,m.jsx)(t4.Z,{className:"ml-1"})]}),l&&(0,m.jsx)("div",{className:"mt-2 p-3 bg-gray-50 border border-gray-200 rounded-md text-sm text-gray-700",children:(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,i=/language-(\w+)/.exec(t||"");return!l&&i?(0,m.jsx)(to.Z,{style:tW.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),...r,children:a})}},children:s})})]}):null},t3=l(5540),t6=l(71282),t8=l(11741),t7=l(16601),t9=e=>{let{timeToFirstToken:s,usage:l}=e;return s||l?(0,m.jsxs)("div",{className:"response-metrics mt-2 pt-2 border-t border-gray-100 text-xs text-gray-500 flex flex-wrap gap-3",children:[void 0!==s&&(0,m.jsx)(Y.Z,{title:"Time to first token",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t3.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:[(s/1e3).toFixed(2),"s"]})]})}),(null==l?void 0:l.promptTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Prompt tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t6.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["In: ",l.promptTokens]})]})}),(null==l?void 0:l.completionTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Completion tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t8.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Out: ",l.completionTokens]})]})}),(null==l?void 0:l.reasoningTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Reasoning tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t1.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Reasoning: ",l.reasoningTokens]})]})}),(null==l?void 0:l.totalTokens)!==void 0&&(0,m.jsx)(Y.Z,{title:"Total tokens",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(t7.Z,{className:"mr-1"}),(0,m.jsxs)("span",{children:["Total: ",l.totalTokens]})]})})]}):null},ae=l(61935),as=l(69993),al=l(12660),at=l(71891),aa=l(44625),ar=l(57400),ai=l(26430),an=l(23907);let{TextArea:ao}=z.default;var ad=e=>{let{accessToken:s,token:l,userRole:t,userID:a,disabledPersonalKeyCreation:r}=e,[i,n]=(0,u.useState)(r?"custom":"session"),[o,c]=(0,u.useState)(""),[h,x]=(0,u.useState)(""),[p,g]=(0,u.useState)([]),[j,f]=(0,u.useState)(void 0),[v,y]=(0,u.useState)(!1),[b,Z]=(0,u.useState)([]),N=(0,u.useRef)(null),[w,k]=(0,u.useState)(d.CHAT),[S,T]=(0,u.useState)(!1),A=(0,u.useRef)(null),[E,O]=(0,u.useState)([]),[L,M]=(0,u.useState)([]),[R,q]=(0,u.useState)([]),[U,z]=(0,u.useState)(null),V=(0,u.useRef)(null);(0,u.useEffect)(()=>{let e="session"===i?s:o;if(!e||!l||!t||!a){console.log("userApiKey or token or userRole or userID is missing = ",e,l,t,a);return}(async()=>{try{if(!e){console.log("userApiKey is missing");return}let s=await tH(e);if(console.log("Fetched models:",s),s.length>0&&(Z(s),f(s[0].model_group),s[0].mode)){let e=t0(s[0].model_group,s);k(e)}}catch(e){console.error("Error fetching model info:",e)}})()},[s,a,t,i,o]),(0,u.useEffect)(()=>{V.current&&setTimeout(()=>{var e;null===(e=V.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[p]);let K=(e,s,l)=>{console.log("updateTextUI called with:",e,s,l),g(t=>{let a=t[t.length-1];if(!a||a.role!==e||a.isImage)return[...t,{role:e,content:s,model:l}];{var r;let e={...a,content:a.content+s,model:null!==(r=a.model)&&void 0!==r?r:l};return[...t.slice(0,-1),e]}})},B=e=>{g(s=>{let l=s[s.length-1];return l&&"assistant"===l.role&&!l.isImage?[...s.slice(0,s.length-1),{...l,reasoningContent:(l.reasoningContent||"")+e}]:s.length>0&&"user"===s[s.length-1].role?[...s,{role:"assistant",content:"",reasoningContent:e}]:s})},H=e=>{console.log("updateTimingData called with:",e),g(s=>{let l=s[s.length-1];if(console.log("Current last message:",l),l&&"assistant"===l.role){console.log("Updating assistant message with timeToFirstToken:",e);let t=[...s.slice(0,s.length-1),{...l,timeToFirstToken:e}];return console.log("Updated chat history:",t),t}return l&&"user"===l.role?(console.log("Creating new assistant message with timeToFirstToken:",e),[...s,{role:"assistant",content:"",timeToFirstToken:e}]):(console.log("No appropriate message found to update timing"),s)})},J=e=>{console.log("Received usage data:",e),g(s=>{let l=s[s.length-1];if(l&&"assistant"===l.role){console.log("Updating message with usage data:",e);let t={...l,usage:e};return console.log("Updated message:",t),[...s.slice(0,s.length-1),t]}return s})},G=(e,s)=>{g(l=>[...l,{role:"assistant",content:e,model:s,isImage:!0}])},$=async()=>{if(""===h.trim()||!l||!t||!a)return;let e="session"===i?s:o;if(!e){F.ZP.error("Please provide an API key or select Current UI Session");return}A.current=new AbortController;let r=A.current.signal,n={role:"user",content:h},c=U||(0,tz.Z)();U||z(c),g([...p,n]),T(!0);try{if(j){if(w===d.CHAT){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),n];await tV(s,(e,s)=>K("assistant",e,s),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}else if(w===d.IMAGE)await tK(h,(e,s)=>G(e,s),j,e,E,r);else if(w===d.RESPONSES){let s=[...p.filter(e=>!e.isImage).map(e=>{let{role:s,content:l}=e;return{role:s,content:l}}),n];await tB(s,(e,s,l)=>K(e,s,l),j,e,E,r,B,H,J,c,L.length>0?L:void 0,R.length>0?R:void 0)}}}catch(e){r.aborted?console.log("Request was cancelled"):(console.error("Error fetching response",e),K("assistant","Error fetching response:"+e))}finally{T(!1),A.current=null}x("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:s}=et.default;return(0,m.jsxs)("div",{children:[(0,m.jsx)(e,{level:1,children:"Access Denied"}),(0,m.jsx)(s,{children:"Ask your proxy admin for access to test models"})]})}let X=(0,m.jsx)(ae.Z,{style:{fontSize:24},spin:!0});return(0,m.jsx)("div",{className:"w-full h-screen p-4 bg-white",children:(0,m.jsx)(eD.Z,{className:"w-full rounded-xl shadow-md overflow-hidden",children:(0,m.jsxs)("div",{className:"flex h-[80vh] w-full",children:[(0,m.jsx)("div",{className:"w-1/4 p-4 border-r border-gray-200 bg-gray-50",children:(0,m.jsx)("div",{className:"mb-6",children:(0,m.jsxs)("div",{className:"space-y-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(lR.Z,{className:"mr-2"})," API Key Source"]}),(0,m.jsx)(D.default,{disabled:r,defaultValue:"session",style:{width:"100%"},onChange:e=>n(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}],className:"rounded-md"}),"custom"===i&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:c,value:o,icon:lR.Z})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(as.Z,{className:"mr-2"})," Select Model"]}),(0,m.jsx)(D.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),f(e),"custom"!==e&&k(t0(e,b)),y("custom"===e)},options:[...Array.from(new Set(b.map(e=>e.model_group))).map((e,s)=>({value:e,label:e,key:s})),{value:"custom",label:"Enter custom model",key:"custom"}],style:{width:"100%"},showSearch:!0,className:"rounded-md"}),v&&(0,m.jsx)(I.Z,{className:"mt-2",placeholder:"Enter custom model name",onValueChange:e=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{f(e)},500)}})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(al.Z,{className:"mr-2"})," Endpoint Type"]}),(0,m.jsx)(tY,{endpointType:w,onEndpointChange:e=>{k(e)},className:"mb-4"})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(at.Z,{className:"mr-2"})," Tags"]}),(0,m.jsx)(t$,{value:E,onChange:O,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(aa.Z,{className:"mr-2"})," Vector Store",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select vector store(s) to use for this LLM API call. You can set up your vector store ",(0,m.jsx)("a",{href:"?page=vector-stores",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tX,{value:L,onChange:M,className:"mb-4",accessToken:s||""})]}),(0,m.jsxs)("div",{children:[(0,m.jsxs)(P.Z,{className:"font-medium block mb-2 text-gray-700 flex items-center",children:[(0,m.jsx)(ar.Z,{className:"mr-2"})," Guardrails",(0,m.jsx)(Y.Z,{className:"ml-1",title:(0,m.jsxs)("span",{children:["Select guardrail(s) to use for this LLM API call. You can set up your guardrails ",(0,m.jsx)("a",{href:"?page=guardrails",style:{color:"#1890ff"},children:"here"}),"."]}),children:(0,m.jsx)(W.Z,{})})]}),(0,m.jsx)(tQ,{value:R,onChange:q,className:"mb-4",accessToken:s||""})]}),(0,m.jsx)(C.Z,{onClick:()=>{g([]),z(null),F.ZP.success("Chat history cleared.")},className:"w-full bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300 mt-4",icon:ai.Z,children:"Clear Chat"})]})})}),(0,m.jsxs)("div",{className:"w-3/4 flex flex-col bg-white",children:[(0,m.jsxs)("div",{className:"flex-1 overflow-auto p-4 pb-0",children:[0===p.length&&(0,m.jsxs)("div",{className:"h-full flex flex-col items-center justify-center text-gray-400",children:[(0,m.jsx)(as.Z,{style:{fontSize:"48px",marginBottom:"16px"}}),(0,m.jsx)(P.Z,{children:"Start a conversation or generate an image"})]}),p.map((e,s)=>(0,m.jsx)("div",{className:"mb-4 ".concat("user"===e.role?"text-right":"text-left"),children:(0,m.jsxs)("div",{className:"inline-block max-w-[80%] rounded-lg shadow-sm p-3.5 px-4",style:{backgroundColor:"user"===e.role?"#f0f8ff":"#ffffff",border:"user"===e.role?"1px solid #e6f0fa":"1px solid #f0f0f0",textAlign:"left"},children:[(0,m.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,m.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full mr-1",style:{backgroundColor:"user"===e.role?"#e6f0fa":"#f5f5f5"},children:"user"===e.role?(0,m.jsx)(_.Z,{style:{fontSize:"12px",color:"#2563eb"}}):(0,m.jsx)(as.Z,{style:{fontSize:"12px",color:"#4b5563"}})}),(0,m.jsx)("strong",{className:"text-sm capitalize",children:e.role}),"assistant"===e.role&&e.model&&(0,m.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-600 font-normal",children:e.model})]}),e.reasoningContent&&(0,m.jsx)(t5,{reasoningContent:e.reasoningContent}),(0,m.jsxs)("div",{className:"whitespace-pre-wrap break-words max-w-full message-content",style:{wordWrap:"break-word",overflowWrap:"break-word",wordBreak:"break-word",hyphens:"auto"},children:[e.isImage?(0,m.jsx)("img",{src:e.content,alt:"Generated image",className:"max-w-full rounded-md border border-gray-200 shadow-sm",style:{maxHeight:"500px"}}):(0,m.jsx)(tU.U,{components:{code(e){let{node:s,inline:l,className:t,children:a,...r}=e,i=/language-(\w+)/.exec(t||"");return!l&&i?(0,m.jsx)(to.Z,{style:tW.Z,language:i[1],PreTag:"div",className:"rounded-md my-2",wrapLines:!0,wrapLongLines:!0,...r,children:String(a).replace(/\n$/,"")}):(0,m.jsx)("code",{className:"".concat(t," px-1.5 py-0.5 rounded bg-gray-100 text-sm font-mono"),style:{wordBreak:"break-word"},...r,children:a})},pre:e=>{let{node:s,...l}=e;return(0,m.jsx)("pre",{style:{overflowX:"auto",maxWidth:"100%"},...l})}},children:e.content}),"assistant"===e.role&&(e.timeToFirstToken||e.usage)&&(0,m.jsx)(t9,{timeToFirstToken:e.timeToFirstToken,usage:e.usage})]})]})},s)),S&&(0,m.jsx)("div",{className:"flex justify-center items-center my-4",children:(0,m.jsx)(lb.Z,{indicator:X})}),(0,m.jsx)("div",{ref:V,style:{height:"1px"}})]}),(0,m.jsx)("div",{className:"p-4 border-t border-gray-200 bg-white",children:(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(ao,{value:h,onChange:e=>x(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),$())},placeholder:w===d.CHAT||w===d.RESPONSES?"Type your message... (Shift+Enter for new line)":"Describe the image you want to generate...",disabled:S,className:"flex-1",autoSize:{minRows:1,maxRows:6},style:{resize:"none",paddingRight:"10px",paddingLeft:"10px"}}),S?(0,m.jsx)(C.Z,{onClick:()=>{A.current&&(A.current.abort(),A.current=null,T(!1),F.ZP.info("Request cancelled"))},className:"ml-2 bg-red-50 hover:bg-red-100 text-red-600 border-red-200",icon:ec.Z,children:"Cancel"}):(0,m.jsx)(C.Z,{onClick:$,className:"ml-2 text-white",icon:w===d.CHAT?an.Z:as.Z,children:w===d.CHAT?"Send":"Generate"})]})})]})]})})})},ac=l(19226),am=l(45937),au=l(28595),ah=l(68208),ax=l(9775),ap=l(41361),ag=l(37527),aj=l(88009),af=l(48231),a_=l(41169),av=l(58630),ay=l(55322);let{Sider:ab}=ac.default;var aZ=e=>{let{setPage:s,userRole:l,defaultSelectedKey:t}=e,a=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,m.jsx)(lR.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,m.jsx)(au.Z,{}),roles:eZ.LQ},{key:"2",page:"models",label:"Models",icon:(0,m.jsx)(ah.Z,{}),roles:eZ.LQ},{key:"12",page:"new_usage",label:"Usage",icon:(0,m.jsx)(ax.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"6",page:"teams",label:"Teams",icon:(0,m.jsx)(ap.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"5",page:"users",label:"Internal Users",icon:(0,m.jsx)(_.Z,{}),roles:eZ.ZL},{key:"14",page:"api_ref",label:"API Reference",icon:(0,m.jsx)(al.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,m.jsx)(aj.Z,{})},{key:"15",page:"logs",label:"Logs",icon:(0,m.jsx)(af.Z,{})},{key:"11",page:"guardrails",label:"Guardrails",icon:(0,m.jsx)(ar.Z,{}),roles:eZ.ZL},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,m.jsx)(a_.Z,{}),children:[{key:"9",page:"caching",label:"Caching",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"10",page:"budgets",label:"Budgets",icon:(0,m.jsx)(ag.Z,{}),roles:eZ.ZL},{key:"20",page:"transform-request",label:"API Playground",icon:(0,m.jsx)(al.Z,{}),roles:[...eZ.ZL,...eZ.lo]},{key:"18",page:"mcp-tools",label:"MCP Tools",icon:(0,m.jsx)(av.Z,{}),roles:eZ.ZL},{key:"19",page:"tag-management",label:"Tag Management",icon:(0,m.jsx)(at.Z,{}),roles:eZ.ZL},{key:"21",page:"vector-stores",label:"Vector Stores",icon:(0,m.jsx)(aa.Z,{}),roles:eZ.ZL},{key:"4",page:"usage",label:"Old Usage",icon:(0,m.jsx)(ax.Z,{})}]},{key:"settings",page:"settings",label:"Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,m.jsx)(al.Z,{}),roles:eZ.ZL},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,m.jsx)(ay.Z,{}),roles:eZ.ZL}]}],r=(e=>{let s=a.find(s=>s.page===e);if(s)return s.key;for(let s of a)if(s.children){let l=s.children.find(s=>s.page===e);if(l)return l.key}return"1"})(t),i=a.filter(e=>!!(!e.roles||e.roles.includes(l))&&(e.children&&(e.children=e.children.filter(e=>!e.roles||e.roles.includes(l))),!0));return(0,m.jsx)(ac.default,{style:{minHeight:"100vh"},children:(0,m.jsx)(ab,{theme:"light",width:220,children:(0,m.jsx)(am.Z,{mode:"inline",selectedKeys:[r],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:i.map(e=>{var l;return{key:e.key,icon:e.icon,label:e.label,children:null===(l=e.children)||void 0===l?void 0:l.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}})),onClick:e.children?void 0:()=>{let l=new URLSearchParams(window.location.search);l.set("page",e.page),window.history.pushState(null,"","?".concat(l.toString())),s(e.page)}}})})})})},aN=l(96889);console.log("process.env.NODE_ENV","production"),console.log=function(){};let aw=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var ak=e=>{let{accessToken:s,token:l,userRole:t,userID:a,keys:r,premiumUser:i}=e,n=new Date,[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)([]),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)([]),[Z,N]=(0,u.useState)([]),[w,I]=(0,u.useState)([]),[T,A]=(0,u.useState)([]),[E,L]=(0,u.useState)([]),[D,M]=(0,u.useState)({}),[F,R]=(0,u.useState)([]),[q,U]=(0,u.useState)(""),[z,V]=(0,u.useState)(["all-tags"]),[K,B]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[H,J]=(0,u.useState)(null),[G,W]=(0,u.useState)(0),Y=new Date(n.getFullYear(),n.getMonth(),1),$=new Date(n.getFullYear(),n.getMonth()+1,0),X=er(Y),Q=er($);function ee(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",r),console.log("premium user in usage",i);let es=async()=>{if(s)try{let e=await (0,b.g)(s);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,u.useEffect)(()=>{ea(K.from,K.to)},[K,z]);let et=async(e,l,t)=>{if(!e||!l||!s)return;l.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,b.b1)(s,t,e.toISOString(),l.toISOString());console.log("End user data updated successfully",a),j(a)},ea=async(e,l)=>{if(!e||!l||!s)return;let t=await es();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(l.setHours(23,59,59,999),e.setHours(0,0,0,0),y((await (0,b.J$)(s,e.toISOString(),l.toISOString(),0===z.length?void 0:z)).spend_per_tag),console.log("Tag spend data updated successfully"))};function er(e){let s=e.getFullYear(),l=e.getMonth()+1,t=e.getDate();return"".concat(s,"-").concat(l<10?"0"+l:l,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(X)),console.log("End date is ".concat(Q));let ei=async(e,s,l)=>{try{let l=await e();s(l)}catch(e){console.error(l,e)}},en=(e,s,l,t)=>{let a=[],r=new Date(s),i=e=>{if(e.includes("-"))return e;{let[s,l]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(s," 01 2024")).getMonth(),parseInt(l)).toISOString().split("T")[0]}},n=new Map(e.map(e=>{let s=i(e.date);return[s,{...e,date:s}]}));for(;r<=l;){let e=r.toISOString().split("T")[0];if(n.has(e))a.push(n.get(e));else{let s={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{s[e]||(s[e]=0)}),a.push(s)}r.setDate(r.getDate()+1)}return a},eo=async()=>{if(s)try{let e=await (0,b.FC)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=en(e,t,a,[]),i=Number(r.reduce((e,s)=>e+(s.spend||0),0).toFixed(2));W(i),d(r)}catch(e){console.error("Error fetching overall spend:",e)}},ed=()=>ei(()=>s&&l?(0,b.OU)(s,l,X,Q):Promise.reject("No access token or token"),L,"Error fetching provider spend"),ec=async()=>{s&&await ei(async()=>(await (0,b.tN)(s)).map(e=>({key:e.api_key.substring(0,10),api_key:e.api_key,key_alias:e.key_alias,spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},em=async()=>{s&&await ei(async()=>(await (0,b.Au)(s)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),p,"Error fetching top models")},eu=async()=>{s&&await ei(async()=>{let e=await (0,b.mR)(s),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0);return _(en(e.daily_spend,t,a,e.teams)),I(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},A,"Error fetching team spend")},eh=()=>{s&&ei(async()=>(await (0,b.X)(s)).tag_names,N,"Error fetching tag names")},ex=()=>{s&&ei(()=>{var e,l;return(0,b.J$)(s,null===(e=K.from)||void 0===e?void 0:e.toISOString(),null===(l=K.to)||void 0===l?void 0:l.toISOString(),void 0)},e=>y(e.spend_per_tag),"Error fetching top tags")},ep=()=>{s&&ei(()=>(0,b.b1)(s,null,void 0,void 0),j,"Error fetching top end users")},eg=async()=>{if(s)try{let e=await (0,b.wd)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=en(e.daily_data||[],t,a,["api_requests","total_tokens"]);M({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},ej=async()=>{if(s)try{let e=await (0,b.xA)(s,X,Q),l=new Date,t=new Date(l.getFullYear(),l.getMonth(),1),a=new Date(l.getFullYear(),l.getMonth()+1,0),r=e.map(e=>({...e,daily_data:en(e.daily_data||[],t,a,["api_requests","total_tokens"])}));R(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,u.useEffect)(()=>{(async()=>{if(s&&l&&t&&a){let e=await es();e&&(J(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",H),eo(),ed(),ec(),em(),eg(),ej(),aw(t)&&(eu(),eh(),ex(),ep()))}})()},[s,l,t,a,X,Q]),null==H?void 0:H.DISABLE_EXPENSIVE_DB_QUERIES)?(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Database Query Limit Reached"}),(0,m.jsxs)(P.Z,{className:"mt-4",children:["SpendLogs in DB has ",H.NUM_SPEND_LOGS_ROWS," rows.",(0,m.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,m.jsx)(C.Z,{className:"mt-4",children:(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,m.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mt-2",children:[(0,m.jsx)(eM.Z,{children:"All Up"}),aw(t)?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(eM.Z,{children:"Team Based Usage"}),(0,m.jsx)(eM.Z,{children:"Customer Usage"}),(0,m.jsx)(eM.Z,{children:"Tag Based Usage"})]}):(0,m.jsx)(m.Fragment,{children:(0,m.jsx)("div",{})})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{variant:"solid",className:"mt-1",children:[(0,m.jsx)(eM.Z,{children:"Cost"}),(0,m.jsx)(eM.Z,{children:"Activity"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(P.Z,{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content mb-2 mt-2 text-lg",children:["Project Spend ",new Date().toLocaleString("default",{month:"long"})," 1 - ",new Date(new Date().getFullYear(),new Date().getMonth()+1,0).getDate()]}),(0,m.jsx)(tT,{userID:a,userRole:t,accessToken:s,userSpend:G,selectedTeam:null,userMaxBudget:null})]}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Monthly Spend"}),(0,m.jsx)(sT.Z,{data:o,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top API Keys"}),(0,m.jsx)(tE,{topKeys:c,accessToken:s,userID:a,userRole:t,teams:null})]})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(eD.Z,{className:"h-full",children:[(0,m.jsx)(O.Z,{children:"Top Models"}),(0,m.jsx)(sT.Z,{className:"mt-4 h-40",data:x,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,m.jsx)(k.Z,{numColSpan:1}),(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Spend by Provider"}),(0,m.jsx)(m.Fragment,{children:(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(tI.Z,{className:"mt-4 h-40",variant:"pie",data:E,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsxs)(e5.Z,{children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Provider"}),(0,m.jsx)(e7.Z,{children:"Spend"})]})}),(0,m.jsx)(e3.Z,{children:E.map(e=>(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.provider}),(0,m.jsx)(e6.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"All Up"}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(D.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(D.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:D.daily_data,valueFormatter:ee,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,m.jsx)(m.Fragment,{children:F.map((e,s)=>(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:e.model}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ee(e.sum_api_requests)]}),(0,m.jsx)(sI.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:ee,onValueChange:e=>console.log(e)})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsxs)(sn.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ee(e.sum_total_tokens)]}),(0,m.jsx)(sT.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:ee,onValueChange:e=>console.log(e)})]})]})]},s))})]})})]})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,m.jsxs)(k.Z,{numColSpan:2,children:[(0,m.jsxs)(eD.Z,{className:"mb-2",children:[(0,m.jsx)(O.Z,{children:"Total Spend Per Team"}),(0,m.jsx)(aN.Z,{data:T})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Daily Spend Per Team"}),(0,m.jsx)(sT.Z,{className:"h-72",data:f,showLegend:!0,index:"date",categories:w,yAxisWidth:80,stack:!0})]})]}),(0,m.jsx)(k.Z,{numColSpan:2})]})}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:["Customers of your LLM API calls. Tracked when a `user` param is passed in your LLM calls ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Time Range"}),(0,m.jsx)(sS.Z,{enableSelect:!0,value:K,onValueChange:e=>{B(e),et(e.from,e.to,null)}})]}),(0,m.jsxs)(k.Z,{children:[(0,m.jsx)(P.Z,{children:"Select Key"}),(0,m.jsxs)(eO.Z,{defaultValue:"all-keys",children:[(0,m.jsx)(el.Z,{value:"all-keys",onClick:()=>{et(K.from,K.to,null)},children:"All Keys"},"all-keys"),null==r?void 0:r.map((e,s)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,m.jsx)(el.Z,{value:String(s),onClick:()=>{et(K.from,K.to,e.token)},children:e.key_alias},s):null)]})]})]}),(0,m.jsx)(eD.Z,{className:"mt-4",children:(0,m.jsxs)(e5.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,m.jsx)(e8.Z,{children:(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e7.Z,{children:"Customer"}),(0,m.jsx)(e7.Z,{children:"Spend"}),(0,m.jsx)(e7.Z,{children:"Total Events"})]})}),(0,m.jsx)(e3.Z,{children:null==g?void 0:g.map((e,s)=>{var l;return(0,m.jsxs)(e9.Z,{children:[(0,m.jsx)(e6.Z,{children:e.end_user}),(0,m.jsx)(e6.Z,{children:null===(l=e.total_spend)||void 0===l?void 0:l.toFixed(4)}),(0,m.jsx)(e6.Z,{children:e.total_count})]},s)})})]})})]}),(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:2,children:[(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(sS.Z,{className:"mb-4",enableSelect:!0,value:K,onValueChange:e=>{B(e),ea(e.from,e.to)}})}),(0,m.jsx)(k.Z,{children:i?(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsx)(l4.Z,{value:String(e),children:e},e))]})}):(0,m.jsx)("div",{children:(0,m.jsxs)(l2.Z,{value:z,onValueChange:e=>V(e),children:[(0,m.jsx)(l4.Z,{value:"all-tags",onClick:()=>V(["all-tags"]),children:"All Tags"},"all-tags"),Z&&Z.filter(e=>"all-tags"!==e).map((e,s)=>(0,m.jsxs)(el.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,m.jsxs)(S.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,m.jsx)(k.Z,{numColSpan:2,children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Spend Per Tag"}),(0,m.jsxs)(P.Z,{children:["Get Started Tracking cost per tag ",(0,m.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,m.jsx)(sT.Z,{className:"h-72",data:v,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,m.jsx)(k.Z,{numColSpan:2})]})]})]})]})})},aS=l(51853);let aC=e=>{let{responseTimeMs:s}=e;return null==s?null:(0,m.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-gray-500 font-mono",children:[(0,m.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,m.jsx)("path",{d:"M12 6V12L16 14M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,m.jsxs)("span",{children:[s.toFixed(0),"ms"]})]})},aI=e=>{let s=e;if("string"==typeof s)try{s=JSON.parse(s)}catch(e){}return s},aT=e=>{let{label:s,value:l}=e,[t,a]=u.useState(!1),[r,i]=u.useState(!1),n=(null==l?void 0:l.toString())||"N/A",o=n.length>50?n.substring(0,50)+"...":n;return(0,m.jsx)("tr",{className:"hover:bg-gray-50",children:(0,m.jsx)("td",{className:"px-4 py-2 align-top",colSpan:2,children:(0,m.jsxs)("div",{className:"flex items-center justify-between group",children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)("button",{onClick:()=>a(!t),className:"text-gray-400 hover:text-gray-600 mr-2",children:t?"▼":"▶"}),(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{className:"text-sm text-gray-600",children:s}),(0,m.jsx)("pre",{className:"mt-1 text-sm font-mono text-gray-800 whitespace-pre-wrap",children:t?n:o})]})]}),(0,m.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),2e3)},className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-gray-600",children:(0,m.jsx)(aS.Z,{className:"h-4 w-4"})})]})})})},aA=e=>{var s,l,t,a,r,i,n,o,d,c,u,h,x,p;let{response:g}=e,j=null,f={},_={};try{if(null==g?void 0:g.error)try{let e="string"==typeof g.error.message?JSON.parse(g.error.message):g.error.message;j={message:(null==e?void 0:e.message)||"Unknown error",traceback:(null==e?void 0:e.traceback)||"No traceback available",litellm_params:(null==e?void 0:e.litellm_cache_params)||{},health_check_cache_params:(null==e?void 0:e.health_check_cache_params)||{}},f=aI(j.litellm_params)||{},_=aI(j.health_check_cache_params)||{}}catch(e){console.warn("Error parsing error details:",e),j={message:String(g.error.message||"Unknown error"),traceback:"Error parsing details",litellm_params:{},health_check_cache_params:{}}}else f=aI(null==g?void 0:g.litellm_cache_params)||{},_=aI(null==g?void 0:g.health_check_cache_params)||{}}catch(e){console.warn("Error in response parsing:",e),f={},_={}}let v={redis_host:(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host)||(null==_?void 0:null===(n=_.connection_kwargs)||void 0===n?void 0:n.host)||(null==_?void 0:_.host)||"N/A",redis_port:(null==_?void 0:null===(c=_.redis_client)||void 0===c?void 0:null===(d=c.connection_pool)||void 0===d?void 0:null===(o=d.connection_kwargs)||void 0===o?void 0:o.port)||(null==_?void 0:null===(x=_.redis_async_client)||void 0===x?void 0:null===(h=x.connection_pool)||void 0===h?void 0:null===(u=h.connection_kwargs)||void 0===u?void 0:u.port)||(null==_?void 0:null===(p=_.connection_kwargs)||void 0===p?void 0:p.port)||(null==_?void 0:_.port)||"N/A",redis_version:(null==_?void 0:_.redis_version)||"N/A",startup_nodes:(()=>{try{var e,s,l,t,a,r,i,n,o,d,c,m,u;if(null==_?void 0:null===(e=_.redis_kwargs)||void 0===e?void 0:e.startup_nodes)return JSON.stringify(_.redis_kwargs.startup_nodes);let h=(null==_?void 0:null===(t=_.redis_client)||void 0===t?void 0:null===(l=t.connection_pool)||void 0===l?void 0:null===(s=l.connection_kwargs)||void 0===s?void 0:s.host)||(null==_?void 0:null===(i=_.redis_async_client)||void 0===i?void 0:null===(r=i.connection_pool)||void 0===r?void 0:null===(a=r.connection_kwargs)||void 0===a?void 0:a.host),x=(null==_?void 0:null===(d=_.redis_client)||void 0===d?void 0:null===(o=d.connection_pool)||void 0===o?void 0:null===(n=o.connection_kwargs)||void 0===n?void 0:n.port)||(null==_?void 0:null===(u=_.redis_async_client)||void 0===u?void 0:null===(m=u.connection_pool)||void 0===m?void 0:null===(c=m.connection_kwargs)||void 0===c?void 0:c.port);return h&&x?JSON.stringify([{host:h,port:x}]):"N/A"}catch(e){return"N/A"}})(),namespace:(null==_?void 0:_.namespace)||"N/A"};return(0,m.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"border-b border-gray-200 px-4",children:[(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Summary"}),(0,m.jsx)(eM.Z,{className:"px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-800",children:"Raw Response"})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-6",children:[(null==g?void 0:g.status)==="healthy"?(0,m.jsx)(eg.Z,{className:"h-5 w-5 text-green-500 mr-2"}):(0,m.jsx)(ep.Z,{className:"h-5 w-5 text-red-500 mr-2"}),(0,m.jsxs)(P.Z,{className:"text-sm font-medium ".concat((null==g?void 0:g.status)==="healthy"?"text-green-500":"text-red-500"),children:["Cache Status: ",(null==g?void 0:g.status)||"unhealthy"]})]}),(0,m.jsx)("table",{className:"w-full border-collapse",children:(0,m.jsxs)("tbody",{children:[j&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold text-red-600",children:"Error Details"})}),(0,m.jsx)(aT,{label:"Error Message",value:j.message}),(0,m.jsx)(aT,{label:"Traceback",value:j.traceback})]}),(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Cache Details"})}),(0,m.jsx)(aT,{label:"Cache Configuration",value:String(null==f?void 0:f.type)}),(0,m.jsx)(aT,{label:"Ping Response",value:String(g.ping_response)}),(0,m.jsx)(aT,{label:"Set Cache Response",value:g.set_cache_response||"N/A"}),(0,m.jsx)(aT,{label:"litellm_settings.cache_params",value:JSON.stringify(f,null,2)}),(null==f?void 0:f.type)==="redis"&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)("tr",{children:(0,m.jsx)("td",{colSpan:2,className:"pt-4 pb-2 font-semibold",children:"Redis Details"})}),(0,m.jsx)(aT,{label:"Redis Host",value:v.redis_host||"N/A"}),(0,m.jsx)(aT,{label:"Redis Port",value:v.redis_port||"N/A"}),(0,m.jsx)(aT,{label:"Redis Version",value:v.redis_version||"N/A"}),(0,m.jsx)(aT,{label:"Startup Nodes",value:v.startup_nodes||"N/A"}),(0,m.jsx)(aT,{label:"Namespace",value:v.namespace||"N/A"})]})]})})]})}),(0,m.jsx)(eq.Z,{className:"p-4",children:(0,m.jsx)("div",{className:"bg-gray-50 rounded-md p-4 font-mono text-sm",children:(0,m.jsx)("pre",{className:"whitespace-pre-wrap break-words overflow-auto max-h-[500px]",children:(()=>{try{let e={...g,litellm_cache_params:f,health_check_cache_params:_},s=JSON.parse(JSON.stringify(e,(e,s)=>{if("string"==typeof s)try{return JSON.parse(s)}catch(e){}return s}));return JSON.stringify(s,null,2)}catch(e){return"Error formatting JSON: "+e.message}})()})})})]})]})})},aE=e=>{let{accessToken:s,healthCheckResponse:l,runCachingHealthCheck:t,responseTimeMs:a}=e,[r,i]=u.useState(null),[n,o]=u.useState(!1),d=async()=>{o(!0);let e=performance.now();await t(),i(performance.now()-e),o(!1)};return(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsx)(C.Z,{onClick:d,disabled:n,className:"bg-indigo-600 hover:bg-indigo-700 disabled:bg-indigo-400 text-white text-sm px-4 py-2 rounded-md",children:n?"Running Health Check...":"Run Health Check"}),(0,m.jsx)(aC,{responseTimeMs:r})]}),l&&(0,m.jsx)(aA,{response:l})]})},aP=e=>{if(e)return e.toISOString().split("T")[0]};function aO(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var aL=e=>{let{accessToken:s,token:l,userRole:t,userID:a,premiumUser:r}=e,[i,n]=(0,u.useState)([]),[o,d]=(0,u.useState)([]),[c,h]=(0,u.useState)([]),[x,p]=(0,u.useState)([]),[g,j]=(0,u.useState)("0"),[f,_]=(0,u.useState)("0"),[v,y]=(0,u.useState)("0"),[Z,N]=(0,u.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[w,C]=(0,u.useState)(""),[I,T]=(0,u.useState)("");(0,u.useEffect)(()=>{s&&Z&&((async()=>{p(await (0,b.zg)(s,aP(Z.from),aP(Z.to)))})(),C(new Date().toLocaleString()))},[s]);let A=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.api_key)&&void 0!==s?s:""}))),E=Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.model)&&void 0!==s?s:""})));Array.from(new Set(x.map(e=>{var s;return null!==(s=null==e?void 0:e.call_type)&&void 0!==s?s:""})));let O=async(e,l)=>{e&&l&&s&&(l.setHours(23,59,59,999),e.setHours(0,0,0,0),p(await (0,b.zg)(s,aP(e),aP(l))))};(0,u.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",x);let e=x;o.length>0&&(e=e.filter(e=>o.includes(e.api_key))),c.length>0&&(e=e.filter(e=>c.includes(e.model))),console.log("before processed data in cache dashboard",e);let s=0,l=0,t=0,a=e.reduce((e,a)=>{console.log("Processing item:",a),a.call_type||(console.log("Item has no call_type:",a),a.call_type="Unknown"),s+=(a.total_rows||0)-(a.cache_hit_true_rows||0),l+=a.cache_hit_true_rows||0,t+=a.cached_completion_tokens||0;let r=e.find(e=>e.name===a.call_type);return r?(r["LLM API requests"]+=(a.total_rows||0)-(a.cache_hit_true_rows||0),r["Cache hit"]+=a.cache_hit_true_rows||0,r["Cached Completion Tokens"]+=a.cached_completion_tokens||0,r["Generated Completion Tokens"]+=a.generated_completion_tokens||0):e.push({name:a.call_type,"LLM API requests":(a.total_rows||0)-(a.cache_hit_true_rows||0),"Cache hit":a.cache_hit_true_rows||0,"Cached Completion Tokens":a.cached_completion_tokens||0,"Generated Completion Tokens":a.generated_completion_tokens||0}),e},[]);j(aO(l)),_(aO(t));let r=l+s;r>0?y((l/r*100).toFixed(2)):y("0"),n(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[o,c,Z,x]);let L=async()=>{try{F.ZP.info("Running cache health check..."),T("");let e=await (0,b.Tj)(null!==s?s:"");console.log("CACHING HEALTH CHECK RESPONSE",e),T(e)}catch(s){let e;if(console.error("Error running health check:",s),s&&s.message)try{let l=JSON.parse(s.message);l.error&&(l=l.error),e=l}catch(l){e={message:s.message}}else e={message:"Unknown error occurred"};T({error:e})}};return(0,m.jsxs)(eF.Z,{className:"gap-2 p-8 h-full w-full mt-2 mb-8",children:[(0,m.jsxs)(eR.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(eM.Z,{children:"Cache Analytics"}),(0,m.jsx)(eM.Z,{children:(0,m.jsx)("pre",{children:"Cache Health"})})]}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[w&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",w]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center",onClick:()=>{C(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)(S.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select API Keys",value:o,onValueChange:d,children:A.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(l2.Z,{placeholder:"Select Models",value:c,onValueChange:h,children:E.map(e=>(0,m.jsx)(l4.Z,{value:e,children:e},e))})}),(0,m.jsx)(k.Z,{children:(0,m.jsx)(sS.Z,{enableSelect:!0,value:Z,onValueChange:e=>{N(e),O(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[v,"%"]})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:g})})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,m.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,m.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:f})})]})]}),(0,m.jsx)(sn.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,m.jsx)(sT.Z,{title:"Cache Hits vs API Requests",data:i,stack:!0,index:"name",valueFormatter:aO,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,m.jsx)(sn.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,m.jsx)(sT.Z,{className:"mt-6",data:i,stack:!0,index:"name",valueFormatter:aO,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})}),(0,m.jsx)(eq.Z,{children:(0,m.jsx)(aE,{accessToken:s,healthCheckResponse:I,runCachingHealthCheck:L})})]})]})},aD=l(22452),aM=l(91810),aF=l(3810);(i=c||(c={})).PresidioPII="Presidio PII",i.Bedrock="Bedrock Guardrail",i.Lakera="Lakera";let aR={PresidioPII:"presidio",Bedrock:"bedrock",Lakera:"lakera_v2"},aq=e=>!!e&&"Presidio PII"===c[e],aU="../ui/assets/logos/",az={"Presidio PII":"".concat(aU,"presidio.png"),"Bedrock Guardrail":"".concat(aU,"bedrock.svg"),Lakera:"".concat(aU,"lakeraai.jpeg")},aV=e=>{if(!e)return{logo:"",displayName:"-"};let s=Object.keys(aR).find(s=>aR[s].toLowerCase()===e.toLowerCase());if(!s)return{logo:"",displayName:e};let l=c[s];return{logo:az[l],displayName:l}};var aK=l(33866),aB=l(97416),aH=l(8881),aJ=l(10798),aG=l(49638);let{Text:aW}=et.default,{Option:aY}=D.default,a$=e=>e.replace(/_/g," "),aX=e=>{switch(e){case"MASK":return(0,m.jsx)(aB.Z,{style:{marginRight:4}});case"BLOCK":return(0,m.jsx)(aH.Z,{style:{marginRight:4}});default:return null}},aQ=e=>{let{categories:s,selectedCategories:l,onChange:t}=e;return(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{className:"flex items-center mb-2",children:[(0,m.jsx)(aJ.Z,{className:"text-gray-500 mr-1"}),(0,m.jsx)(aW,{className:"text-gray-500 font-medium",children:"Filter by category"})]}),(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select categories to filter by",style:{width:"100%"},onChange:t,value:l,allowClear:!0,showSearch:!0,optionFilterProp:"children",className:"mb-4",tagRender:e=>(0,m.jsx)(aF.Z,{color:"blue",closable:e.closable,onClose:e.onClose,className:"mr-2 mb-2",children:e.label}),children:s.map(e=>(0,m.jsx)(aY,{value:e.category,children:e.category},e.category))})]})},a0=e=>{let{onSelectAll:s,onUnselectAll:l,hasSelectedEntities:t}=e;return(0,m.jsxs)("div",{className:"bg-gray-50 p-5 rounded-lg mb-6 border border-gray-200 shadow-sm",children:[(0,m.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)(aW,{strong:!0,className:"text-gray-700 text-base",children:"Quick Actions"}),(0,m.jsx)(Y.Z,{title:"Apply action to all PII types at once",children:(0,m.jsx)("div",{className:"ml-2 text-gray-400 cursor-help text-xs",children:"ⓘ"})})]}),(0,m.jsx)(U.ZP,{type:"default",onClick:l,disabled:!t,icon:(0,m.jsx)(aG.Z,{}),className:"border-gray-300 hover:text-red-600 hover:border-red-300",children:"Unselect All"})]}),(0,m.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("MASK"),className:"flex items-center justify-center h-10 border-blue-200 hover:border-blue-300 hover:text-blue-700 bg-blue-50 hover:bg-blue-100 text-blue-600",block:!0,icon:(0,m.jsx)(aB.Z,{}),children:"Select All & Mask"}),(0,m.jsx)(U.ZP,{type:"default",onClick:()=>s("BLOCK"),className:"flex items-center justify-center h-10 border-red-200 hover:border-red-300 hover:text-red-700 bg-red-50 hover:bg-red-100 text-red-600",block:!0,icon:(0,m.jsx)(aH.Z,{}),children:"Select All & Block"})]})]})},a1=e=>{let{entities:s,selectedEntities:l,selectedActions:t,actions:a,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:n}=e;return(0,m.jsxs)("div",{className:"border rounded-lg overflow-hidden shadow-sm",children:[(0,m.jsxs)("div",{className:"bg-gray-50 px-5 py-3 border-b flex",children:[(0,m.jsx)(aW,{strong:!0,className:"flex-1 text-gray-700",children:"PII Type"}),(0,m.jsx)(aW,{strong:!0,className:"w-32 text-right text-gray-700",children:"Action"})]}),(0,m.jsx)("div",{className:"max-h-[400px] overflow-y-auto",children:0===s.length?(0,m.jsx)("div",{className:"py-10 text-center text-gray-500",children:"No PII types match your filter criteria"}):s.map(e=>(0,m.jsxs)("div",{className:"px-5 py-3 flex items-center justify-between hover:bg-gray-50 border-b ".concat(l.includes(e)?"bg-blue-50":""),children:[(0,m.jsxs)("div",{className:"flex items-center flex-1",children:[(0,m.jsx)(sL.Z,{checked:l.includes(e),onChange:()=>r(e),className:"mr-3"}),(0,m.jsx)(aW,{className:l.includes(e)?"font-medium text-gray-900":"text-gray-700",children:a$(e)}),n.get(e)&&(0,m.jsx)(aF.Z,{className:"ml-2 text-xs",color:"blue",children:n.get(e)})]}),(0,m.jsx)("div",{className:"w-32",children:(0,m.jsx)(D.default,{value:l.includes(e)&&t[e]||"MASK",onChange:s=>i(e,s),style:{width:120},disabled:!l.includes(e),className:"".concat(l.includes(e)?"":"opacity-50"),dropdownMatchSelectWidth:!1,children:a.map(e=>(0,m.jsx)(aY,{value:e,children:(0,m.jsxs)("div",{className:"flex items-center",children:[aX(e),e]})},e))})})]},e))})]})},{Title:a2,Text:a4}=et.default;var a5=e=>{let{entities:s,actions:l,selectedEntities:t,selectedActions:a,onEntitySelect:r,onActionSelect:i,entityCategories:n=[]}=e,[o,d]=(0,u.useState)([]),c=new Map;n.forEach(e=>{e.entities.forEach(s=>{c.set(s,e.category)})});let h=s.filter(e=>0===o.length||o.includes(c.get(e)||""));return(0,m.jsxs)("div",{className:"pii-configuration",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-5",children:[(0,m.jsx)("div",{className:"flex items-center",children:(0,m.jsx)(a2,{level:4,className:"mb-0 font-semibold text-gray-800",children:"Configure PII Protection"})}),(0,m.jsx)(aK.Z,{count:t.length,showZero:!0,style:{backgroundColor:t.length>0?"#4f46e5":"#d9d9d9"},overflowCount:999,children:(0,m.jsxs)(a4,{className:"text-gray-500",children:[t.length," items selected"]})})]}),(0,m.jsxs)("div",{className:"mb-6",children:[(0,m.jsx)(aQ,{categories:n,selectedCategories:o,onChange:d}),(0,m.jsx)(a0,{onSelectAll:e=>{s.forEach(s=>{t.includes(s)||r(s),i(s,e)})},onUnselectAll:()=>{t.forEach(e=>{r(e)})},hasSelectedEntities:t.length>0})]}),(0,m.jsx)(a1,{entities:h,selectedEntities:t,selectedActions:a,actions:l,onEntitySelect:r,onActionSelect:i,entityToCategoryMap:c})]})},a3=e=>{var s;let{selectedProvider:l,accessToken:t,providerParams:a=null}=e,[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(a),[d,c]=(0,u.useState)(null);if((0,u.useEffect)(()=>{if(a){o(a);return}let e=async()=>{if(t){i(!0),c(null);try{let e=await (0,b.eW)(t);console.log("Provider params API response:",e),o(e)}catch(e){console.error("Error fetching provider params:",e),c("Failed to load provider parameters")}finally{i(!1)}}};a||e()},[t,a]),!l)return null;if(r)return(0,m.jsx)(lb.Z,{tip:"Loading provider parameters..."});if(d)return(0,m.jsx)("div",{className:"text-red-500",children:d});let h=null===(s=aR[l])||void 0===s?void 0:s.toLowerCase(),x=n&&n[h];return(console.log("Provider key:",h),console.log("Provider fields:",x),x&&0!==x.length)?(0,m.jsx)(m.Fragment,{children:x.map(e=>(0,m.jsx)(M.Z.Item,{name:e.param,label:e.param,tooltip:e.description,rules:e.required?[{required:!0,message:"".concat(e.param," is required")}]:void 0,children:"select"===e.type&&e.options?(0,m.jsx)(D.default,{placeholder:e.description,defaultValue:e.default_value,children:e.options.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:e},e))}):"bool"===e.type?(0,m.jsxs)(D.default,{placeholder:e.description,defaultValue:e.default_value,children:[(0,m.jsx)(D.default.Option,{value:"True",children:"True"}),(0,m.jsx)(D.default.Option,{value:"False",children:"False"})]}):e.param.includes("password")||e.param.includes("secret")?(0,m.jsx)(I.Z,{placeholder:e.description,type:"password"}):(0,m.jsx)(I.Z,{placeholder:e.description,type:"text"})},e.param))}):(0,m.jsx)("div",{children:"No configuration fields available for this provider."})};let{Title:a6,Text:a8,Link:a7}=et.default,{Option:a9}=D.default,{Step:re}=aM.default,rs={pre_call:"Before LLM Call - Runs before the LLM call and checks the input (Recommended)",during_call:"During LLM Call - Runs in parallel with the LLM call, with response held until check completes",post_call:"After LLM Call - Runs after the LLM call and checks only the output",logging_only:"Logging Only - Only runs on logging callbacks without affecting the LLM call"};var rl=e=>{let{visible:s,onClose:l,accessToken:t,onSuccess:a}=e,[r]=M.Z.useForm(),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)([]),[j,f]=(0,u.useState)({}),[_,v]=(0,u.useState)(0),[y,Z]=(0,u.useState)(null);(0,u.useEffect)(()=>{t&&(async()=>{try{let[e,s]=await Promise.all([(0,b.qd)(t),(0,b.eW)(t)]);x(e),Z(s)}catch(e){console.error("Error fetching guardrail data:",e),F.ZP.error("Failed to load guardrail configuration")}})()},[t]);let N=e=>{d(e),r.setFieldsValue({config:void 0,presidio_analyzer_api_base:void 0,presidio_anonymizer_api_base:void 0}),g([]),f({})},w=e=>{g(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},k=(e,s)=>{f(l=>({...l,[e]:s}))},S=async()=>{try{if(0===_&&(await r.validateFields(["guardrail_name","provider","mode","default_on"]),o)){let e=["guardrail_name","provider","mode","default_on"];"PresidioPII"===o&&e.push("presidio_analyzer_api_base","presidio_anonymizer_api_base"),await r.validateFields(e)}v(_+1)}catch(e){console.error("Form validation failed:",e)}},T=()=>{r.resetFields(),d(null),g([]),f({}),v(0)},A=()=>{T(),l()},E=async()=>{try{n(!0),await r.validateFields();let s=r.getFieldsValue(!0),i=aR[s.provider],d={guardrail_name:s.guardrail_name,litellm_params:{guardrail:i,mode:s.mode,default_on:s.default_on},guardrail_info:{}};if("PresidioPII"===s.provider&&p.length>0){let e={};p.forEach(s=>{e[s]=j[s]||"MASK"}),d.litellm_params.pii_entities_config=e,s.presidio_analyzer_api_base&&(d.litellm_params.presidio_analyzer_api_base=s.presidio_analyzer_api_base),s.presidio_anonymizer_api_base&&(d.litellm_params.presidio_anonymizer_api_base=s.presidio_anonymizer_api_base)}else if(s.config)try{let e=JSON.parse(s.config);d.guardrail_info=e}catch(e){F.ZP.error("Invalid JSON in configuration"),n(!1);return}if(y&&o){var e;let l=y[null===(e=aR[o])||void 0===e?void 0:e.toLowerCase()]||[];new Set(l.map(e=>e.param)).forEach(e=>{let l=s[e];null!=l&&""!==l&&(d.litellm_params[e]=l)})}if(!t)throw Error("No access token available");console.log("Sending guardrail data:",JSON.stringify(d)),await (0,b.PC)(t,d),F.ZP.success("Guardrail created successfully"),T(),a(),l()}catch(e){console.error("Failed to create guardrail:",e),F.ZP.error("Failed to create guardrail: "+(e instanceof Error?e.message:String(e)))}finally{n(!1)}},P=()=>{var e;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:N,labelInValue:!1,optionLabelProp:"label",dropdownRender:e=>e,showSearch:!0,children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(a9,{value:s,label:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[az[l]&&(0,m.jsx)("img",{src:az[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]}),children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[az[l]&&(0,m.jsx)("img",{src:az[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{optionLabelProp:"label",mode:"multiple",children:(null==h?void 0:null===(e=h.supported_modes)||void 0===e?void 0:e.map(e=>(0,m.jsx)(a9,{value:e,label:e,children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("strong",{children:e}),"pre_call"===e&&(0,m.jsx)(aF.Z,{color:"green",style:{marginLeft:"8px"},children:"Recommended"})]}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs[e]})]})},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(a9,{value:"pre_call",label:"pre_call",children:(0,m.jsxs)("div",{children:[(0,m.jsxs)("div",{children:[(0,m.jsx)("strong",{children:"pre_call"})," ",(0,m.jsx)(aF.Z,{color:"green",children:"Recommended"})]}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.pre_call})]})}),(0,m.jsx)(a9,{value:"during_call",label:"during_call",children:(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{children:(0,m.jsx)("strong",{children:"during_call"})}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.during_call})]})}),(0,m.jsx)(a9,{value:"post_call",label:"post_call",children:(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{children:(0,m.jsx)("strong",{children:"post_call"})}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.post_call})]})}),(0,m.jsx)(a9,{value:"logging_only",label:"logging_only",children:(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{children:(0,m.jsx)("strong",{children:"logging_only"})}),(0,m.jsx)("div",{style:{fontSize:"12px",color:"#888"},children:rs.logging_only})]})})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default.",children:(0,m.jsxs)(D.default,{children:[(0,m.jsx)(D.default.Option,{value:!0,children:"Yes"}),(0,m.jsx)(D.default.Option,{value:!1,children:"No"})]})}),(0,m.jsx)(a3,{selectedProvider:o,accessToken:t,providerParams:y})]})},O=()=>h&&"PresidioPII"===o?(0,m.jsx)(a5,{entities:h.supported_entities,actions:h.supported_actions,selectedEntities:p,selectedActions:j,onEntitySelect:w,onActionSelect:k,entityCategories:h.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Add Guardrail",open:s,onCancel:A,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:r,layout:"vertical",initialValues:{mode:"pre_call",default_on:!1},children:[(0,m.jsxs)(aM.default,{current:_,className:"mb-6",children:[(0,m.jsx)(re,{title:"Basic Info"}),(0,m.jsx)(re,{title:"PresidioPII"===o?"PII Configuration":"Provider Configuration"})]}),(()=>{switch(_){case 0:return P();case 1:if(aq(o))return O();default:return null}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[_>0&&(0,m.jsx)(C.Z,{variant:"secondary",onClick:()=>{v(_-1)},children:"Previous"}),_<1&&(0,m.jsx)(C.Z,{onClick:S,children:"Next"}),1===_&&(0,m.jsx)(C.Z,{onClick:E,loading:i,children:"Create Guardrail"}),(0,m.jsx)(C.Z,{variant:"secondary",onClick:A,children:"Cancel"})]})]})})};let{Title:rt,Text:ra}=et.default,{Option:rr}=D.default;var ri=e=>{var s;let{visible:l,onClose:t,accessToken:a,onSuccess:r,guardrailId:i,initialValues:n}=e,[o]=M.Z.useForm(),[d,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)((null==n?void 0:n.provider)||null),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)([]),[v,y]=(0,u.useState)({});(0,u.useEffect)(()=>{(async()=>{try{if(!a)return;let e=await (0,b.qd)(a);j(e)}catch(e){console.error("Error fetching guardrail settings:",e),F.ZP.error("Failed to load guardrail settings")}})()},[a]),(0,u.useEffect)(()=>{(null==n?void 0:n.pii_entities_config)&&Object.keys(n.pii_entities_config).length>0&&(_(Object.keys(n.pii_entities_config)),y(n.pii_entities_config))},[n]);let Z=e=>{_(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},N=(e,s)=>{y(l=>({...l,[e]:s}))},w=async()=>{try{h(!0);let e=await o.validateFields(),s=aR[e.provider],l={guardrail_id:i,guardrail:{guardrail_name:e.guardrail_name,litellm_params:{guardrail:s,mode:e.mode,default_on:e.default_on},guardrail_info:{}}};if("PresidioPII"===e.provider&&f.length>0){let e={};f.forEach(s=>{e[s]=v[s]||"MASK"}),l.guardrail.litellm_params.pii_entities_config=e}else if(e.config)try{let s=JSON.parse(e.config);"Bedrock"===e.provider&&s?(s.guardrail_id&&(l.guardrail.litellm_params.guardrailIdentifier=s.guardrail_id),s.guardrail_version&&(l.guardrail.litellm_params.guardrailVersion=s.guardrail_version)):l.guardrail.guardrail_info=s}catch(e){F.ZP.error("Invalid JSON in configuration"),h(!1);return}if(!a)throw Error("No access token available");console.log("Sending guardrail update data:",JSON.stringify(l));let n=await fetch("/guardrails/".concat(i),{method:"PUT",headers:{Authorization:"Bearer ".concat(a),"Content-Type":"application/json"},body:JSON.stringify(l)});if(!n.ok){let e=await n.text();throw Error(e||"Failed to update guardrail")}F.ZP.success("Guardrail updated successfully"),r(),t()}catch(e){console.error("Failed to update guardrail:",e),F.ZP.error("Failed to update guardrail: "+(e instanceof Error?e.message:String(e)))}finally{h(!1)}},k=()=>g&&x&&"PresidioPII"===x?(0,m.jsx)(a5,{entities:g.supported_entities,actions:g.supported_actions,selectedEntities:f,selectedActions:v,onEntitySelect:Z,onActionSelect:N,entityCategories:g.pii_entity_categories}):null;return(0,m.jsx)(R.Z,{title:"Edit Guardrail",open:l,onCancel:t,footer:null,width:700,children:(0,m.jsxs)(M.Z,{form:o,layout:"vertical",initialValues:n,children:[(0,m.jsx)(M.Z.Item,{name:"guardrail_name",label:"Guardrail Name",rules:[{required:!0,message:"Please enter a guardrail name"}],children:(0,m.jsx)(I.Z,{placeholder:"Enter a name for this guardrail"})}),(0,m.jsx)(M.Z.Item,{name:"provider",label:"Guardrail Provider",rules:[{required:!0,message:"Please select a provider"}],children:(0,m.jsx)(D.default,{placeholder:"Select a guardrail provider",onChange:e=>{p(e),o.setFieldsValue({config:void 0}),_([]),y({})},disabled:!0,optionLabelProp:"label",children:Object.entries(c).map(e=>{let[s,l]=e;return(0,m.jsx)(rr,{value:s,label:l,children:(0,m.jsxs)("div",{style:{display:"flex",alignItems:"center"},children:[az[l]&&(0,m.jsx)("img",{src:az[l],alt:"",style:{height:"20px",width:"20px",marginRight:"8px",objectFit:"contain"},onError:e=>{e.currentTarget.style.display="none"}}),(0,m.jsx)("span",{children:l})]})},s)})})}),(0,m.jsx)(M.Z.Item,{name:"mode",label:"Mode",tooltip:"How the guardrail should be applied",rules:[{required:!0,message:"Please select a mode"}],children:(0,m.jsx)(D.default,{children:(null==g?void 0:null===(s=g.supported_modes)||void 0===s?void 0:s.map(e=>(0,m.jsx)(rr,{value:e,children:e},e)))||(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(rr,{value:"pre_call",children:"pre_call"}),(0,m.jsx)(rr,{value:"post_call",children:"post_call"})]})})}),(0,m.jsx)(M.Z.Item,{name:"default_on",label:"Always On",tooltip:"If enabled, this guardrail will be applied to all requests by default",valuePropName:"checked",children:(0,m.jsx)(sY.Z,{})}),(()=>{if(!x)return null;if("PresidioPII"===x)return k();switch(x){case"Aporia":return(0,m.jsx)(M.Z.Item,{label:"Aporia Configuration",name:"config",tooltip:"JSON configuration for Aporia",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aporia_api_key",\n "project_name": "your_project_name"\n}'})});case"AimSecurity":return(0,m.jsx)(M.Z.Item,{label:"Aim Security Configuration",name:"config",tooltip:"JSON configuration for Aim Security",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_aim_api_key"\n}'})});case"Bedrock":return(0,m.jsx)(M.Z.Item,{label:"Amazon Bedrock Configuration",name:"config",tooltip:"JSON configuration for Amazon Bedrock guardrails",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "guardrail_id": "your_guardrail_id",\n "guardrail_version": "your_guardrail_version"\n}'})});case"GuardrailsAI":return(0,m.jsx)(M.Z.Item,{label:"Guardrails.ai Configuration",name:"config",tooltip:"JSON configuration for Guardrails.ai",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_guardrails_api_key",\n "guardrail_id": "your_guardrail_id"\n}'})});case"LakeraAI":return(0,m.jsx)(M.Z.Item,{label:"Lakera AI Configuration",name:"config",tooltip:"JSON configuration for Lakera AI",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "api_key": "your_lakera_api_key"\n}'})});case"PromptInjection":return(0,m.jsx)(M.Z.Item,{label:"Prompt Injection Configuration",name:"config",tooltip:"JSON configuration for prompt injection detection",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "threshold": 0.8\n}'})});default:return(0,m.jsx)(M.Z.Item,{label:"Custom Configuration",name:"config",tooltip:"JSON configuration for your custom guardrail",children:(0,m.jsx)(z.default.TextArea,{rows:4,placeholder:'{\n "key1": "value1",\n "key2": "value2"\n}'})})}})(),(0,m.jsxs)("div",{className:"flex justify-end space-x-2 mt-4",children:[(0,m.jsx)(C.Z,{variant:"secondary",onClick:t,children:"Cancel"}),(0,m.jsx)(C.Z,{onClick:w,loading:d,children:"Update Guardrail"})]})]})})},rn=e=>{var s,l,t,a,r,i,n,o,d;let{guardrailId:c,onClose:h,accessToken:x,isAdmin:p}=e,[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(!0),[v,y]=(0,u.useState)(!1),[Z]=M.Z.useForm(),[N,w]=(0,u.useState)([]),[k,T]=(0,u.useState)({}),[A,E]=(0,u.useState)(null),L=async()=>{try{var e;if(_(!0),!x)return;let s=await (0,b.fk)(x,c);if(j(s),null===(e=s.litellm_params)||void 0===e?void 0:e.pii_entities_config){let e=s.litellm_params.pii_entities_config;if(w([]),T({}),Object.keys(e).length>0){let s=[],l={};Object.entries(e).forEach(e=>{let[t,a]=e;s.push(t),l[t]="string"==typeof a?a:"MASK"}),w(s),T(l)}}else w([]),T({})}catch(e){F.ZP.error("Failed to load guardrail information"),console.error("Error fetching guardrail info:",e)}finally{_(!1)}},R=async()=>{try{if(!x)return;let e=await (0,b.qd)(x);E(e)}catch(e){console.error("Error fetching guardrail UI settings:",e)}};(0,u.useEffect)(()=>{L(),R()},[c,x]);let q=async e=>{try{if(!x)return;let s={guardrail_name:e.guardrail_name,litellm_params:{default_on:e.default_on},guardrail_info:e.guardrail_info?JSON.parse(e.guardrail_info):void 0};if(N.length>0){let e={};N.forEach(s=>{e[s]=k[s]||"MASK"}),s.litellm_params.pii_entities_config=e}else s.litellm_params.pii_entities_config={};await (0,b.Ko)(x,c,s),F.ZP.success("Guardrail updated successfully"),L(),y(!1)}catch(e){console.error("Error updating guardrail:",e),F.ZP.error("Failed to update guardrail")}};if(f)return(0,m.jsx)("div",{className:"p-4",children:"Loading..."});if(!g)return(0,m.jsx)("div",{className:"p-4",children:"Guardrail not found"});let V=e=>e?new Date(e).toLocaleString():"-",{logo:K,displayName:B}=aV((null===(s=g.litellm_params)||void 0===s?void 0:s.guardrail)||"");return(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,m.jsxs)("div",{children:[(0,m.jsx)(U.ZP,{onClick:h,className:"mb-4",children:"← Back"}),(0,m.jsx)(O.Z,{children:g.guardrail_name||"Unnamed Guardrail"}),(0,m.jsx)(P.Z,{className:"text-gray-500 font-mono",children:g.guardrail_id})]})}),(0,m.jsxs)(eF.Z,{children:[(0,m.jsxs)(eR.Z,{className:"mb-4",children:[(0,m.jsx)(eM.Z,{children:"Overview"},"overview"),p?(0,m.jsx)(eM.Z,{children:"Settings"},"settings"):(0,m.jsx)(m.Fragment,{})]}),(0,m.jsxs)(eU.Z,{children:[(0,m.jsxs)(eq.Z,{children:[(0,m.jsxs)(S.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Provider"}),(0,m.jsxs)("div",{className:"mt-2 flex items-center space-x-2",children:[K&&(0,m.jsx)("img",{src:K,alt:"".concat(B," logo"),className:"w-6 h-6",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)(O.Z,{children:B})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Mode"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:(null===(l=g.litellm_params)||void 0===l?void 0:l.mode)||"-"}),(0,m.jsx)(eL.Z,{color:(null===(t=g.litellm_params)||void 0===t?void 0:t.default_on)?"green":"gray",children:(null===(a=g.litellm_params)||void 0===a?void 0:a.default_on)?"Default On":"Default Off"})]})]}),(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(P.Z,{children:"Created At"}),(0,m.jsxs)("div",{className:"mt-2",children:[(0,m.jsx)(O.Z,{children:V(g.created_at)}),(0,m.jsxs)(P.Z,{children:["Last Updated: ",V(g.updated_at)]})]})]})]}),(null===(r=g.litellm_params)||void 0===r?void 0:r.pii_entities_config)&&Object.keys(g.litellm_params.pii_entities_config).length>0&&(0,m.jsx)(eD.Z,{className:"mt-6",children:(0,m.jsxs)("div",{className:"flex justify-between items-center",children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"PII Protection"}),(0,m.jsxs)(eL.Z,{color:"blue",children:[Object.keys(g.litellm_params.pii_entities_config).length," PII entities configured"]})]})}),g.guardrail_info&&Object.keys(g.guardrail_info).length>0&&(0,m.jsxs)(eD.Z,{className:"mt-6",children:[(0,m.jsx)(P.Z,{children:"Guardrail Info"}),(0,m.jsx)("div",{className:"mt-2 space-y-2",children:Object.entries(g.guardrail_info).map(e=>{let[s,l]=e;return(0,m.jsxs)("div",{className:"flex",children:[(0,m.jsx)(P.Z,{className:"font-medium w-1/3",children:s}),(0,m.jsx)(P.Z,{className:"w-2/3",children:"object"==typeof l?JSON.stringify(l,null,2):String(l)})]},s)})})]})]}),p&&(0,m.jsx)(eq.Z,{children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,m.jsx)(O.Z,{children:"Guardrail Settings"}),!v&&(0,m.jsx)(C.Z,{onClick:()=>y(!0),children:"Edit Settings"})]}),v?(0,m.jsxs)(M.Z,{form:Z,onFinish:q,initialValues:{guardrail_name:g.guardrail_name,...g.litellm_params,guardrail_info:g.guardrail_info?JSON.stringify(g.guardrail_info,null,2):""},layout:"vertical",children:[(0,m.jsx)(M.Z.Item,{label:"Guardrail Name",name:"guardrail_name",rules:[{required:!0,message:"Please input a guardrail name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Default On",name:"default_on",children:(0,m.jsxs)(D.default,{children:[(0,m.jsx)(D.default.Option,{value:!0,children:"Yes"}),(0,m.jsx)(D.default.Option,{value:!1,children:"No"})]})}),(0,m.jsx)(le.Z,{orientation:"left",children:"PII Protection"}),(0,m.jsx)("div",{className:"mb-6",children:A&&(0,m.jsx)(a5,{entities:A.supported_entities,actions:A.supported_actions,selectedEntities:N,selectedActions:k,onEntitySelect:e=>{w(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])},onActionSelect:(e,s)=>{T(l=>({...l,[e]:s}))},entityCategories:A.pii_entity_categories})}),(0,m.jsx)(le.Z,{orientation:"left",children:"Advanced Settings"}),(0,m.jsx)(M.Z.Item,{label:"Guardrail Information",name:"guardrail_info",children:(0,m.jsx)(z.default.TextArea,{rows:5})}),(0,m.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,m.jsx)(U.ZP,{onClick:()=>y(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{children:"Save Changes"})]})]}):(0,m.jsxs)("div",{className:"space-y-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail ID"}),(0,m.jsx)("div",{className:"font-mono",children:g.guardrail_id})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Guardrail Name"}),(0,m.jsx)("div",{children:g.guardrail_name||"Unnamed Guardrail"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Provider"}),(0,m.jsx)("div",{children:B})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Mode"}),(0,m.jsx)("div",{children:(null===(i=g.litellm_params)||void 0===i?void 0:i.mode)||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Default On"}),(0,m.jsx)(eL.Z,{color:(null===(n=g.litellm_params)||void 0===n?void 0:n.default_on)?"green":"gray",children:(null===(o=g.litellm_params)||void 0===o?void 0:o.default_on)?"Yes":"No"})]}),(null===(d=g.litellm_params)||void 0===d?void 0:d.pii_entities_config)&&Object.keys(g.litellm_params.pii_entities_config).length>0&&(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"PII Protection"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)(eL.Z,{color:"blue",children:[Object.keys(g.litellm_params.pii_entities_config).length," PII entities configured"]})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created At"}),(0,m.jsx)("div",{children:V(g.created_at)})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)("div",{children:V(g.updated_at)})]})]})]})})]})]})]})},ro=e=>{let{guardrailsList:s,isLoading:l,onDeleteClick:t,accessToken:a,onGuardrailUpdated:r,isAdmin:i=!1,onShowGuardrailInfo:n}=e,[o,d]=(0,u.useState)([{id:"created_at",desc:!0}]),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(null),[g,j]=(0,u.useState)(!1),[f,_]=(0,u.useState)(null),v=e=>e?new Date(e).toLocaleString():"-",y=e=>{_(e),j(!0),null==n||n(!0)},b=[{header:"Guardrail ID",accessorKey:"guardrail_id",cell:e=>(0,m.jsx)(Y.Z,{title:String(e.getValue()||""),children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>e.getValue()&&y(e.getValue()),children:e.getValue()?"".concat(String(e.getValue()).slice(0,7),"..."):""})})},{header:"Name",accessorKey:"guardrail_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.guardrail_name,children:(0,m.jsx)("span",{className:"text-xs font-medium",children:l.guardrail_name||"-"})})}},{header:"Provider",accessorKey:"litellm_params.guardrail",cell:e=>{let{row:s}=e,{logo:l,displayName:t}=aV(s.original.litellm_params.guardrail);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,m.jsx)("img",{src:l,alt:"".concat(t," logo"),className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,m.jsx)("span",{className:"text-xs",children:t})]})}},{header:"Mode",accessorKey:"litellm_params.mode",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:l.litellm_params.mode})}},{header:"Created At",accessorKey:"created_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.created_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.created_at)})})}},{header:"Updated At",accessorKey:"updated_at",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.updated_at,children:(0,m.jsx)("span",{className:"text-xs",children:v(l.updated_at)})})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l.guardrail_id&&t(l.guardrail_id,l.guardrail_name||"Unnamed Guardrail"),className:"cursor-pointer hover:text-red-500",tooltip:"Delete guardrail"})})}}],Z=(0,e2.b7)({data:s,columns:b,state:{sorting:o},onSortingChange:d,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return g&&f?(0,m.jsx)(rn,{guardrailId:f,onClose:()=>{j(!1),_(null),null==n||n(!1)},accessToken:a,isAdmin:i}):(0,m.jsxs)("div",{className:"rounded-lg custom-border relative",children:[(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:Z.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:l?(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"Loading..."})})})}):s.length>0?Z.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:b.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No guardrails found"})})})})})]})}),x&&(0,m.jsx)(ri,{visible:c,onClose:()=>h(!1),accessToken:a,onSuccess:()=>{h(!1),p(null),r()},guardrailId:x.guardrail_id||"",initialValues:{guardrail_name:x.guardrail_name||"",provider:Object.keys(aR).find(e=>aR[e]===(null==x?void 0:x.litellm_params.guardrail))||"",mode:x.litellm_params.mode,default_on:x.litellm_params.default_on,pii_entities_config:x.litellm_params.pii_entities_config,...x.guardrail_info}})]})},rd=e=>{let{accessToken:s,userRole:l}=e,[t,a]=(0,u.useState)([]),[r,i]=(0,u.useState)(!1),[n,o]=(0,u.useState)(!1),[d,c]=(0,u.useState)(!1),[h,x]=(0,u.useState)(null),[p,g]=(0,u.useState)(!1),j=!!l&&(0,eZ.tY)(l),f=async()=>{if(s){o(!0);try{let e=await (0,b.t3)(s);console.log("guardrails: ".concat(JSON.stringify(e))),a(e.guardrails)}catch(e){console.error("Error fetching guardrails:",e)}finally{o(!1)}}};(0,u.useEffect)(()=>{f()},[s]);let _=async()=>{if(h&&s){c(!0);try{await (0,b.Yi)(s,h.id),F.ZP.success('Guardrail "'.concat(h.name,'" deleted successfully')),f()}catch(e){console.error("Error deleting guardrail:",e),F.ZP.error("Failed to delete guardrail")}finally{c(!1),x(null)}}};return(0,m.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[!p&&(0,m.jsx)("div",{className:"flex justify-between items-center mb-4",children:(0,m.jsx)(C.Z,{icon:aD.Z,onClick:()=>{i(!0)},disabled:!s,children:"Add Guardrail"})}),(0,m.jsx)(ro,{guardrailsList:t,isLoading:n,onDeleteClick:(e,s)=>{x({id:e,name:s})},accessToken:s,onGuardrailUpdated:f,isAdmin:j,onShowGuardrailInfo:g}),(0,m.jsx)(rl,{visible:r,onClose:()=>{i(!1)},accessToken:s,onSuccess:()=>{f()}}),h&&(0,m.jsxs)(R.Z,{title:"Delete Guardrail",open:null!==h,onOk:_,onCancel:()=>{x(null)},confirmLoading:d,okText:"Delete",okButtonProps:{danger:!0},children:[(0,m.jsxs)("p",{children:["Are you sure you want to delete guardrail: ",h.name," ?"]}),(0,m.jsx)("p",{children:"This action cannot be undone."})]})]})},rc=e=>{let{accessToken:s}=e,[l,t]=(0,u.useState)('{\n "model": "openai/gpt-4o",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n },\n {\n "role": "user",\n "content": "Explain quantum computing in simple terms"\n }\n ],\n "temperature": 0.7,\n "max_tokens": 500,\n "stream": true\n}'),[a,r]=(0,u.useState)(""),[i,n]=(0,u.useState)(!1),o=(e,s,l)=>{let t=JSON.stringify(s,null,2).split("\n").map(e=>" ".concat(e)).join("\n"),a=Object.entries(l).map(e=>{let[s,l]=e;return"-H '".concat(s,": ").concat(l,"'")}).join(" \\\n ");return"curl -X POST \\\n ".concat(e," \\\n ").concat(a?"".concat(a," \\\n "):"","-H 'Content-Type: application/json' \\\n -d '{\n").concat(t,"\n }'")},d=async()=>{n(!0);try{let e;try{e=JSON.parse(l)}catch(e){F.ZP.error("Invalid JSON in request body"),n(!1);return}let t={call_type:"completion",request_body:e};if(!s){F.ZP.error("No access token found"),n(!1);return}let a=await (0,b.Yo)(s,t);if(a.raw_request_api_base&&a.raw_request_body){let e=o(a.raw_request_api_base,a.raw_request_body,a.raw_request_headers||{});r(e),F.ZP.success("Request transformed successfully")}else{let e="string"==typeof a?a:JSON.stringify(a);r(e),F.ZP.info("Transformed request received in unexpected format")}}catch(e){console.error("Error transforming request:",e),F.ZP.error("Failed to transform request")}finally{n(!1)}};return(0,m.jsxs)("div",{className:"w-full m-2",style:{overflow:"hidden"},children:[(0,m.jsx)(O.Z,{children:"Playground"}),(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"See how LiteLLM transforms your request for the specified provider."}),(0,m.jsxs)("div",{style:{display:"flex",gap:"16px",width:"100%",minWidth:0,overflow:"hidden"},className:"mt-4",children:[(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"600px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Original Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"The request you would send to LiteLLM /chat/completions endpoint."})]}),(0,m.jsx)("textarea",{style:{flex:"1 1 auto",width:"100%",minHeight:"240px",padding:"16px",border:"1px solid #e8e8e8",borderRadius:"6px",fontFamily:"monospace",fontSize:"14px",resize:"none",marginBottom:"24px",overflow:"auto"},value:l,onChange:e=>t(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),d())},placeholder:"Press Cmd/Ctrl + Enter to transform"}),(0,m.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"auto"},children:(0,m.jsxs)(U.ZP,{type:"primary",style:{backgroundColor:"#000",display:"flex",alignItems:"center",gap:"8px"},onClick:d,loading:i,children:[(0,m.jsx)("span",{children:"Transform"}),(0,m.jsx)("span",{children:"→"})]})})]}),(0,m.jsxs)("div",{style:{flex:"1 1 50%",display:"flex",flexDirection:"column",border:"1px solid #e8e8e8",borderRadius:"8px",padding:"24px",overflow:"hidden",maxHeight:"800px",minWidth:0},children:[(0,m.jsxs)("div",{style:{marginBottom:"24px"},children:[(0,m.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",margin:"0 0 4px 0"},children:"Transformed Request"}),(0,m.jsx)("p",{style:{color:"#666",margin:0},children:"How LiteLLM transforms your request for the specified provider."}),(0,m.jsx)("br",{}),(0,m.jsx)("p",{style:{color:"#666",margin:0},className:"text-xs",children:"Note: Sensitive headers are not shown."})]}),(0,m.jsxs)("div",{style:{position:"relative",backgroundColor:"#f5f5f5",borderRadius:"6px",flex:"1 1 auto",display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,m.jsx)("pre",{style:{padding:"16px",fontFamily:"monospace",fontSize:"14px",margin:0,overflow:"auto",flex:"1 1 auto"},children:a||'curl -X POST \\\n https://api.openai.com/v1/chat/completions \\\n -H \'Authorization: Bearer sk-xxx\' \\\n -H \'Content-Type: application/json\' \\\n -d \'{\n "model": "gpt-4",\n "messages": [\n {\n "role": "system",\n "content": "You are a helpful assistant."\n }\n ],\n "temperature": 0.7\n }\''}),(0,m.jsx)(U.ZP,{type:"text",icon:(0,m.jsx)(ls.Z,{}),style:{position:"absolute",right:"8px",top:"8px"},size:"small",onClick:()=>{navigator.clipboard.writeText(a||""),F.ZP.success("Copied to clipboard")}})]})]})]}),(0,m.jsx)("div",{className:"mt-4 text-right w-full",children:(0,m.jsxs)("p",{className:"text-sm text-gray-500",children:["Found an error? File an issue ",(0,m.jsx)("a",{href:"https://github.com/BerriAI/litellm/issues",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})})]})},rm=l(21770);let ru=[{accessorKey:"mcp_info.server_name",header:"Provider",cell:e=>{let{row:s}=e,l=s.original.mcp_info.server_name,t=s.original.mcp_info.logo_url;return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:"".concat(l," logo"),className:"h-5 w-5 object-contain"}),(0,m.jsx)("span",{className:"font-medium",children:l})]})}},{accessorKey:"name",header:"Tool Name",cell:e=>{let{row:s}=e,l=s.getValue("name");return(0,m.jsx)("div",{children:(0,m.jsx)("span",{className:"font-mono text-sm",children:l})})}},{accessorKey:"description",header:"Description",cell:e=>{let{row:s}=e,l=s.getValue("description");return(0,m.jsx)("div",{className:"max-w-md",children:(0,m.jsx)("span",{className:"text-sm text-gray-700",children:l})})}},{id:"actions",header:"Actions",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"flex items-center space-x-2",children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]",onClick:()=>{"function"==typeof s.original.onToolSelect&&s.original.onToolSelect(l)},children:"Test Tool"})})}}];function rh(e){let{tool:s,onSubmit:l,isLoading:t,result:a,error:r,onClose:i}=e,[n,o]=u.useState({}),d=u.useMemo(()=>"string"==typeof s.inputSchema?{type:"object",properties:{input:{type:"string",description:"Input for this tool"}},required:["input"]}:s.inputSchema,[s.inputSchema]),c=(e,s)=>{o(l=>({...l,[e]:s}))};return(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow-lg border p-6 max-w-4xl w-full",children:[(0,m.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsxs)("h2",{className:"text-xl font-bold",children:["Test Tool: ",(0,m.jsx)("span",{className:"font-mono",children:s.name})]}),(0,m.jsx)("p",{className:"text-gray-600",children:s.description}),(0,m.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:["Provider: ",s.mcp_info.server_name]})]}),(0,m.jsx)("button",{onClick:i,className:"p-1 rounded-full hover:bg-gray-200",children:(0,m.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,m.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,m.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,m.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Input Parameters"}),(0,m.jsxs)("form",{onSubmit:e=>{e.preventDefault(),l(n)},children:["string"==typeof s.inputSchema?(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:"This tool uses a dynamic input schema."}),(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Input ",(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,m.jsx)("input",{type:"text",value:n.input||"",onChange:e=>c("input",e.target.value),required:!0,className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"})]})]}):Object.entries(d.properties).map(e=>{var s,l,t;let[a,r]=e;return(0,m.jsxs)("div",{className:"mb-4",children:[(0,m.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[a," ",(null===(s=d.required)||void 0===s?void 0:s.includes(a))&&(0,m.jsx)("span",{className:"text-red-500",children:"*"})]}),r.description&&(0,m.jsx)("p",{className:"text-xs text-gray-500 mb-1",children:r.description}),"string"===r.type&&(0,m.jsx)("input",{type:"text",value:n[a]||"",onChange:e=>c(a,e.target.value),required:null===(l=d.required)||void 0===l?void 0:l.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"number"===r.type&&(0,m.jsx)("input",{type:"number",value:n[a]||"",onChange:e=>c(a,parseFloat(e.target.value)),required:null===(t=d.required)||void 0===t?void 0:t.includes(a),className:"w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"}),"boolean"===r.type&&(0,m.jsxs)("div",{className:"flex items-center",children:[(0,m.jsx)("input",{type:"checkbox",checked:n[a]||!1,onChange:e=>c(a,e.target.checked),className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),(0,m.jsx)("span",{className:"ml-2 text-sm text-gray-600",children:"Enable"})]})]},a)}),(0,m.jsx)("div",{className:"mt-6",children:(0,m.jsx)(C.Z,{type:"submit",disabled:t,className:"w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white",children:t?"Calling...":"Call Tool"})})]})]}),(0,m.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg overflow-auto max-h-[500px]",children:[(0,m.jsx)("h3",{className:"font-medium mb-4",children:"Result"}),t&&(0,m.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,m.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-700"})}),r&&(0,m.jsxs)("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-md",children:[(0,m.jsx)("p",{className:"font-medium",children:"Error"}),(0,m.jsx)("pre",{className:"mt-2 text-xs overflow-auto whitespace-pre-wrap",children:r.message})]}),a&&!t&&!r&&(0,m.jsxs)("div",{children:[a.map((e,s)=>(0,m.jsxs)("div",{className:"mb-4",children:["text"===e.type&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("p",{className:"whitespace-pre-wrap text-sm",children:e.text})}),"image"===e.type&&e.url&&(0,m.jsx)("div",{className:"bg-white border p-3 rounded-md",children:(0,m.jsx)("img",{src:e.url,alt:"Tool result",className:"max-w-full h-auto rounded"})}),"embedded_resource"===e.type&&(0,m.jsxs)("div",{className:"bg-white border p-3 rounded-md",children:[(0,m.jsx)("p",{className:"text-sm font-medium",children:"Embedded Resource"}),(0,m.jsxs)("p",{className:"text-xs text-gray-500",children:["Type: ",e.resource_type]}),e.url&&(0,m.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-600 hover:underline",children:"View Resource"})]})]},s)),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsxs)("details",{className:"text-xs",children:[(0,m.jsx)("summary",{className:"cursor-pointer text-gray-500 hover:text-gray-700",children:"Raw JSON Response"}),(0,m.jsx)("pre",{className:"mt-2 bg-gray-100 p-2 rounded-md overflow-auto max-h-[300px]",children:JSON.stringify(a,null,2)})]})})]}),!a&&!t&&!r&&(0,m.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,m.jsx)("p",{children:"The result will appear here after you call the tool."})})]})]})]})}function rx(e){let{columns:s,data:l,isLoading:t}=e;return(0,m.jsx)(tu,{columns:s,data:l,isLoading:t,renderSubComponent:()=>(0,m.jsx)("div",{}),getRowCanExpand:()=>!1,loadingMessage:"\uD83D\uDE85 Loading tools...",noDataMessage:"No tools found"})}function rp(e){let{accessToken:s,userRole:l,userID:t}=e,[a,r]=(0,u.useState)(""),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(null),{data:x,isLoading:p}=(0,eY.a)({queryKey:["mcpTools"],queryFn:()=>{if(!s)throw Error("Access Token required");return(0,b.lU)(s)},enabled:!!s}),{mutate:g,isPending:j}=(0,rm.D)({mutationFn:e=>{if(!s)throw Error("Access Token required");return(0,b.tB)(s,e.tool.name,e.arguments)},onSuccess:e=>{d(e),h(null)},onError:e=>{h(e),d(null)}}),f=u.useMemo(()=>x?x.map(e=>({...e,onToolSelect:e=>{n(e),d(null),h(null)}})):[],[x]),_=u.useMemo(()=>f.filter(e=>{let s=a.toLowerCase();return e.name.toLowerCase().includes(s)||e.description.toLowerCase().includes(s)||e.mcp_info.server_name.toLowerCase().includes(s)}),[f,a]);return s&&l&&t?(0,m.jsxs)("div",{className:"w-full p-6",children:[(0,m.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,m.jsx)("h1",{className:"text-xl font-semibold",children:"MCP Tools"})}),(0,m.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,m.jsx)("div",{className:"border-b px-6 py-4",children:(0,m.jsxs)("div",{className:"flex items-center justify-between",children:[(0,m.jsxs)("div",{className:"relative w-64",children:[(0,m.jsx)("input",{type:"text",placeholder:"Search tools...",className:"w-full px-3 py-2 pl-8 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:a,onChange:e=>r(e.target.value)}),(0,m.jsx)("svg",{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),(0,m.jsxs)("div",{className:"text-sm text-gray-500",children:[_.length," tool",1!==_.length?"s":""," available"]})]})}),(0,m.jsx)(rx,{columns:ru,data:_,isLoading:p})]}),i&&(0,m.jsx)("div",{className:"fixed inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center z-50 p-4",children:(0,m.jsx)(rh,{tool:i,onSubmit:e=>{i&&g({tool:i,arguments:e})},isLoading:j,result:o,error:c,onClose:()=>n(null)})})]}):(0,m.jsx)("div",{className:"p-6 text-center text-gray-500",children:"Missing required authentication parameters."})}var rg=e=>{let{tagId:s,onClose:l,accessToken:t,is_admin:a,editTag:r}=e,[i]=M.Z.useForm(),[n,o]=(0,u.useState)(null),[d,c]=(0,u.useState)(r),[h,x]=(0,u.useState)([]),p=async()=>{if(t)try{let e=(await (0,b.mC)(t,[s]))[s];e&&(o(e),r&&i.setFieldsValue({name:e.name,description:e.description,models:e.models}))}catch(e){console.error("Error fetching tag details:",e),F.ZP.error("Error fetching tag details: "+e)}};(0,u.useEffect)(()=>{p()},[s,t]),(0,u.useEffect)(()=>{t&&eT("dummy-user","Admin",t,x)},[t]);let g=async e=>{if(t)try{await (0,b.n9)(t,{name:e.name,description:e.description,models:e.models}),F.ZP.success("Tag updated successfully"),c(!1),p()}catch(e){console.error("Error updating tag:",e),F.ZP.error("Error updating tag: "+e)}};return n?(0,m.jsxs)("div",{className:"p-4",children:[(0,m.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(C.Z,{onClick:l,className:"mb-4",children:"← Back to Tags"}),(0,m.jsxs)(O.Z,{children:["Tag Name: ",n.name]}),(0,m.jsx)(P.Z,{className:"text-gray-500",children:n.description||"No description"})]}),a&&!d&&(0,m.jsx)(C.Z,{onClick:()=>c(!0),children:"Edit Tag"})]}),d?(0,m.jsx)(eD.Z,{children:(0,m.jsxs)(M.Z,{form:i,onFinish:g,layout:"vertical",initialValues:n,children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(z.default,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed LLMs"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process this type of data",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"models",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:h.map(e=>(0,m.jsx)(D.default.Option,{value:e,children:H(e)},e))})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-2",children:[(0,m.jsx)(C.Z,{onClick:()=>c(!1),children:"Cancel"}),(0,m.jsx)(C.Z,{type:"submit",children:"Save Changes"})]})]})}):(0,m.jsx)("div",{className:"space-y-6",children:(0,m.jsxs)(eD.Z,{children:[(0,m.jsx)(O.Z,{children:"Tag Details"}),(0,m.jsxs)("div",{className:"space-y-4 mt-4",children:[(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Name"}),(0,m.jsx)(P.Z,{children:n.name})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Description"}),(0,m.jsx)(P.Z,{children:n.description||"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Allowed LLMs"}),(0,m.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:0===n.models.length?(0,m.jsx)(eL.Z,{color:"red",children:"All Models"}):n.models.map(e=>{var s;return(0,m.jsx)(eL.Z,{color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(null===(s=n.model_info)||void 0===s?void 0:s[e])||e})},e)})})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Created"}),(0,m.jsx)(P.Z,{children:n.created_at?new Date(n.created_at).toLocaleString():"-"})]}),(0,m.jsxs)("div",{children:[(0,m.jsx)(P.Z,{className:"font-medium",children:"Last Updated"}),(0,m.jsx)(P.Z,{children:n.updated_at?new Date(n.updated_at).toLocaleString():"-"})]})]})]})})]}):(0,m.jsx)("div",{children:"Loading..."})},rj=e=>{let{data:s,onEdit:l,onDelete:t,onSelectTag:a}=e,[r,i]=u.useState([{id:"created_at",desc:!0}]),n=[{header:"Tag Name",accessorKey:"name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.name,children:(0,m.jsx)(C.Z,{size:"xs",variant:"light",className:"font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5",onClick:()=>a(l.name),children:l.name})})})}},{header:"Description",accessorKey:"description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.description,children:(0,m.jsx)("span",{className:"text-xs",children:l.description||"-"})})}},{header:"Allowed LLMs",accessorKey:"models",cell:e=>{var s,l;let{row:t}=e,a=t.original;return(0,m.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:(null==a?void 0:null===(s=a.models)||void 0===s?void 0:s.length)===0?(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"red",children:"All Models"}):null==a?void 0:null===(l=a.models)||void 0===l?void 0:l.map(e=>{var s;return(0,m.jsx)(eL.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,m.jsx)(Y.Z,{title:"ID: ".concat(e),children:(0,m.jsx)(P.Z,{children:(null===(s=a.model_info)||void 0===s?void 0:s[e])||e})})},e)})})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,a=s.original;return(0,m.jsxs)("div",{className:"flex space-x-2",children:[(0,m.jsx)(sC.Z,{icon:sg.Z,size:"sm",onClick:()=>l(a),className:"cursor-pointer"}),(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>t(a.name),className:"cursor-pointer"})]})}}],o=(0,e2.b7)({data:s,columns:n,state:{sorting:r},onSortingChange:i,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:o.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:n.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No tags found"})})})})})]})})})},rf=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(null),[c,h]=(0,u.useState)(!1),[x,p]=(0,u.useState)(!1),[g,j]=(0,u.useState)(null),[f,_]=(0,u.useState)(""),[v]=M.Z.useForm(),[y,Z]=(0,u.useState)([]),N=async()=>{if(s)try{let e=await (0,b.UM)(s);console.log("List tags response:",e),r(Object.values(e))}catch(e){console.error("Error fetching tags:",e),F.ZP.error("Error fetching tags: "+e)}},w=async e=>{if(s)try{await (0,b.mY)(s,{name:e.tag_name,description:e.description,models:e.allowed_llms}),F.ZP.success("Tag created successfully"),n(!1),v.resetFields(),N()}catch(e){console.error("Error creating tag:",e),F.ZP.error("Error creating tag: "+e)}},T=async e=>{j(e),p(!0)},A=async()=>{if(s&&g){try{await (0,b.fE)(s,g),F.ZP.success("Tag deleted successfully"),N()}catch(e){console.error("Error deleting tag:",e),F.ZP.error("Error deleting tag: "+e)}p(!1),j(null)}};return(0,u.useEffect)(()=>{l&&t&&s&&(async()=>{try{let e=await (0,b.AZ)(s,l,t);e&&e.data&&Z(e.data)}catch(e){console.error("Error fetching models:",e),F.ZP.error("Error fetching models: "+e)}})()},[s,l,t]),(0,u.useEffect)(()=>{N()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:o?(0,m.jsx)(rg,{tagId:o,onClose:()=>{d(null),h(!1)},accessToken:s,is_admin:"Admin"===t,editTag:c}):(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Tag Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[f&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",f]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{N(),_(new Date().toLocaleString())}})]})]}),(0,m.jsxs)(P.Z,{className:"mb-4",children:["Click on a tag name to view and edit its details.",(0,m.jsxs)("p",{children:["You can use tags to restrict the usage of certain LLMs based on tags passed in the request. Read more about tag routing ",(0,m.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/tag_routing",target:"_blank",rel:"noopener noreferrer",children:"here"}),"."]})]}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Create New Tag"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(rj,{data:a,onEdit:e=>{d(e.name),h(!0)},onDelete:T,onSelectTag:d})})}),(0,m.jsx)(R.Z,{title:"Create New Tag",visible:i,width:800,footer:null,onCancel:()=>{n(!1),v.resetFields()},children:(0,m.jsxs)(M.Z,{form:v,onFinish:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:"Tag Name",name:"tag_name",rules:[{required:!0,message:"Please input a tag name"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Allowed Models"," ",(0,m.jsx)(Y.Z,{title:"Select which LLMs are allowed to process requests from this tag",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"allowed_llms",children:(0,m.jsx)(D.default,{mode:"multiple",placeholder:"Select LLMs",children:y.map(e=>(0,m.jsx)(D.default.Option,{value:e.model_info.id,children:(0,m.jsxs)("div",{children:[(0,m.jsx)("span",{children:e.model_name}),(0,m.jsxs)("span",{className:"text-gray-400 ml-2",children:["(",e.model_info.id,")"]})]})},e.model_info.id))})}),(0,m.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,m.jsx)(C.Z,{type:"submit",children:"Create Tag"})})]})}),x&&(0,m.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,m.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,m.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,m.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,m.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,m.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,m.jsx)("div",{className:"sm:flex sm:items-start",children:(0,m.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,m.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Tag"}),(0,m.jsx)("div",{className:"mt-2",children:(0,m.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this tag?"})})]})})}),(0,m.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:A,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:()=>{p(!1),j(null)},children:"Cancel"})]})]})]})})]})})},r_=e=>{let{data:s,onDelete:l}=e,[t,a]=u.useState([{id:"created_at",desc:!0}]),r=[{header:"Vector Store ID",accessorKey:"vector_store_id",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("div",{className:"overflow-hidden",children:(0,m.jsx)(Y.Z,{title:l.vector_store_id,children:(0,m.jsx)("span",{className:"font-mono text-blue-500 text-xs font-normal",children:l.vector_store_id})})})}},{header:"Name",accessorKey:"vector_store_name",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_name,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_name||"-"})})}},{header:"Description",accessorKey:"vector_store_description",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)(Y.Z,{title:l.vector_store_description,children:(0,m.jsx)("span",{className:"text-xs",children:l.vector_store_description||"-"})})}},{header:"Provider",accessorKey:"custom_llm_provider",cell:e=>{let{row:s}=e,{displayName:l,logo:t}=sm(s.original.custom_llm_provider);return(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[t&&(0,m.jsx)("img",{src:t,alt:l,className:"h-4 w-4"}),(0,m.jsx)("span",{className:"text-xs",children:l})]})}},{header:"Created",accessorKey:"created_at",sortingFn:"datetime",cell:e=>{let{row:s}=e,l=s.original;return(0,m.jsx)("span",{className:"text-xs",children:new Date(l.created_at).toLocaleDateString()})}},{id:"actions",header:"",cell:e=>{let{row:s}=e,t=s.original;return(0,m.jsx)("div",{className:"flex space-x-2",children:(0,m.jsx)(sC.Z,{icon:eK.Z,size:"sm",onClick:()=>l(t.vector_store_id),className:"cursor-pointer"})})}}],i=(0,e2.b7)({data:s,columns:r,state:{sorting:t},onSortingChange:a,getCoreRowModel:(0,e4.sC)(),getSortedRowModel:(0,e4.tj)(),enableSorting:!0});return(0,m.jsx)("div",{className:"rounded-lg custom-border relative",children:(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsxs)(e5.Z,{className:"[&_td]:py-0.5 [&_th]:py-1",children:[(0,m.jsx)(e8.Z,{children:i.getHeaderGroups().map(e=>(0,m.jsx)(e9.Z,{children:e.headers.map(e=>(0,m.jsx)(e7.Z,{className:"py-1 h-8 ".concat("actions"===e.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),onClick:e.column.getToggleSortingHandler(),children:(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,m.jsx)("div",{className:"flex items-center",children:e.isPlaceholder?null:(0,e2.ie)(e.column.columnDef.header,e.getContext())}),"actions"!==e.id&&(0,m.jsx)("div",{className:"w-4",children:e.column.getIsSorted()?({asc:(0,m.jsx)(se.Z,{className:"h-4 w-4 text-blue-500"}),desc:(0,m.jsx)(ss.Z,{className:"h-4 w-4 text-blue-500"})})[e.column.getIsSorted()]:(0,m.jsx)(sl.Z,{className:"h-4 w-4 text-gray-400"})})]})},e.id))},e.id))}),(0,m.jsx)(e3.Z,{children:i.getRowModel().rows.length>0?i.getRowModel().rows.map(e=>(0,m.jsx)(e9.Z,{className:"h-8",children:e.getVisibleCells().map(e=>(0,m.jsx)(e6.Z,{className:"py-0.5 max-h-8 overflow-hidden text-ellipsis whitespace-nowrap ".concat("actions"===e.column.id?"sticky right-0 bg-white shadow-[-4px_0_8px_-6px_rgba(0,0,0,0.1)]":""),children:(0,e2.ie)(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,m.jsx)(e9.Z,{children:(0,m.jsx)(e6.Z,{colSpan:r.length,className:"h-8 text-center",children:(0,m.jsx)("div",{className:"text-center text-gray-500",children:(0,m.jsx)("p",{children:"No vector stores found"})})})})})]})})})},rv=e=>{let{isVisible:s,onCancel:l,onSuccess:t,accessToken:a,credentials:r}=e,[i]=M.Z.useForm(),[o,d]=(0,u.useState)("{}"),c=async e=>{if(a)try{let s={};try{s=o.trim()?JSON.parse(o):{}}catch(e){F.ZP.error("Invalid JSON in metadata field");return}await (0,b.Mx)(a,{vector_store_id:e.vector_store_id,custom_llm_provider:e.custom_llm_provider,vector_store_name:e.vector_store_name,vector_store_description:e.vector_store_description,vector_store_metadata:s,litellm_credential_name:e.litellm_credential_name}),F.ZP.success("Vector store created successfully"),i.resetFields(),d("{}"),t()}catch(e){console.error("Error creating vector store:",e),F.ZP.error("Error creating vector store: "+e)}},h=()=>{i.resetFields(),d("{}"),l()};return(0,m.jsx)(R.Z,{title:"Create New Vector Store",visible:s,width:800,footer:null,onCancel:h,children:(0,m.jsxs)(M.Z,{form:i,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Provider"," ",(0,m.jsx)(Y.Z,{title:"Select the provider for this vector store",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"custom_llm_provider",rules:[{required:!0,message:"Please select a provider"}],initialValue:"bedrock",children:(0,m.jsx)(D.default,{children:Object.entries(n).map(e=>{let[s,l]=e;return"Bedrock"===s?(0,m.jsx)(D.default.Option,{value:so[s],children:(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,m.jsx)("img",{src:sc[l],alt:"".concat(s," logo"),className:"w-5 h-5",onError:e=>{let s=e.target,t=s.parentElement;if(t){let e=document.createElement("div");e.className="w-5 h-5 rounded-full bg-gray-200 flex items-center justify-center text-xs",e.textContent=l.charAt(0),t.replaceChild(e,s)}}}),(0,m.jsx)("span",{children:l})]})},s):null})})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store ID"," ",(0,m.jsx)(Y.Z,{title:"Enter the vector store ID from your api provider",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_id",rules:[{required:!0,message:"Please input the vector store ID from your api provider"}],children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Vector Store Name"," ",(0,m.jsx)(Y.Z,{title:"Custom name you want to give to the vector store, this name will be rendered on the LiteLLM UI",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"vector_store_name",children:(0,m.jsx)(I.Z,{})}),(0,m.jsx)(M.Z.Item,{label:"Description",name:"vector_store_description",children:(0,m.jsx)(z.default.TextArea,{rows:4})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Existing Credentials"," ",(0,m.jsx)(Y.Z,{title:"Optionally select API provider credentials for this vector store eg. Bedrock API KEY",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),name:"litellm_credential_name",children:(0,m.jsx)(D.default,{showSearch:!0,placeholder:"Select or search for existing credentials",optionFilterProp:"children",filterOption:(e,s)=>{var l;return(null!==(l=null==s?void 0:s.label)&&void 0!==l?l:"").toLowerCase().includes(e.toLowerCase())},options:[{value:null,label:"None"},...r.map(e=>({value:e.credential_name,label:e.credential_name}))],allowClear:!0})}),(0,m.jsx)(M.Z.Item,{label:(0,m.jsxs)("span",{children:["Metadata"," ",(0,m.jsx)(Y.Z,{title:"JSON metadata for the vector store (optional)",children:(0,m.jsx)(W.Z,{style:{marginLeft:"4px"}})})]}),children:(0,m.jsx)(z.default.TextArea,{rows:4,value:o,onChange:e=>d(e.target.value),placeholder:'{"key": "value"}'})}),(0,m.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,m.jsx)(C.Z,{onClick:h,variant:"secondary",children:"Cancel"}),(0,m.jsx)(C.Z,{variant:"primary",type:"submit",children:"Create"})]})]})})},ry=e=>{let{isVisible:s,onCancel:l,onConfirm:t}=e;return(0,m.jsxs)(R.Z,{title:"Delete Vector Store",visible:s,footer:null,onCancel:l,children:[(0,m.jsx)("p",{children:"Are you sure you want to delete this vector store? This action cannot be undone."}),(0,m.jsxs)("div",{className:"px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,m.jsx)(C.Z,{onClick:t,color:"red",className:"ml-2",children:"Delete"}),(0,m.jsx)(C.Z,{onClick:l,variant:"primary",children:"Cancel"})]})]})},rb=e=>{let{accessToken:s,userID:l,userRole:t}=e,[a,r]=(0,u.useState)([]),[i,n]=(0,u.useState)(!1),[o,d]=(0,u.useState)(!1),[c,h]=(0,u.useState)(null),[x,p]=(0,u.useState)(""),[g,j]=(0,u.useState)([]),f=async()=>{if(s)try{let e=await (0,b.Ou)(s);console.log("List vector stores response:",e),r(e.data||[])}catch(e){console.error("Error fetching vector stores:",e),F.ZP.error("Error fetching vector stores: "+e)}},_=async()=>{if(s)try{let e=await (0,b.N3)(s);console.log("List credentials response:",e),j(e.credentials||[])}catch(e){console.error("Error fetching credentials:",e),F.ZP.error("Error fetching credentials: "+e)}},v=async e=>{h(e),d(!0)},y=async()=>{if(s&&c){try{await (0,b.Pv)(s,c),F.ZP.success("Vector store deleted successfully"),f()}catch(e){console.error("Error deleting vector store:",e),F.ZP.error("Error deleting vector store: "+e)}d(!1),h(null)}};return(0,u.useEffect)(()=>{f(),_()},[s]),(0,m.jsx)("div",{className:"w-full mx-4 h-[75vh]",children:(0,m.jsxs)("div",{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,m.jsxs)("div",{className:"flex justify-between mt-2 w-full items-center mb-4",children:[(0,m.jsx)("h1",{children:"Vector Store Management"}),(0,m.jsxs)("div",{className:"flex items-center space-x-2",children:[x&&(0,m.jsxs)(P.Z,{children:["Last Refreshed: ",x]}),(0,m.jsx)(sC.Z,{icon:eV.Z,variant:"shadow",size:"xs",className:"self-center cursor-pointer",onClick:()=>{f(),_(),p(new Date().toLocaleString())}})]})]}),(0,m.jsx)(P.Z,{className:"mb-4",children:(0,m.jsx)("p",{children:"You can use vector stores to store and retrieve LLM embeddings. Currently, we support Amazon Bedrock vector stores."})}),(0,m.jsx)(C.Z,{className:"mb-4",onClick:()=>n(!0),children:"+ Create Vector Store"}),(0,m.jsx)(S.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:(0,m.jsx)(k.Z,{numColSpan:1,children:(0,m.jsx)(r_,{data:a,onDelete:v})})}),(0,m.jsx)(rv,{isVisible:i,onCancel:()=>n(!1),onSuccess:()=>{n(!1),f()},accessToken:s,credentials:g}),(0,m.jsx)(ry,{isVisible:o,onCancel:()=>d(!1),onConfirm:y})]})})},rZ=l(49096),rN=l(53335);let{cva:rw,cx:rk,compose:rS}=(0,rZ.ZD)({hooks:{onComplete:e=>(0,rN.m6)(e)}});function rC(e){var s,l;let{className:t="",...a}=e,r=(0,u.useId)();return s=()=>{let e=document.getAnimations().filter(e=>e instanceof CSSAnimation&&"spin"===e.animationName),s=e.find(e=>{var s;return(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))===r}),l=e.find(e=>{var s;return e.effect instanceof KeyframeEffect&&(null===(s=e.effect.target)||void 0===s?void 0:s.getAttribute("data-spinner-id"))!==r});s&&l&&(s.currentTime=l.currentTime)},l=[r],(0,u.useLayoutEffect)(s,l),(0,m.jsxs)("svg",{"data-spinner-id":r,className:rk("pointer-events-none size-12 animate-spin text-current",t),fill:"none",viewBox:"0 0 24 24",...a,children:[(0,m.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,m.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}let rI=new p.S;function rT(){return(0,m.jsxs)("div",{className:rk("h-screen","flex items-center justify-center gap-4"),children:[(0,m.jsx)("div",{className:"text-lg font-medium py-2 pr-4 border-r border-r-gray-200",children:"\uD83D\uDE85 LiteLLM"}),(0,m.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,m.jsx)(rC,{className:"size-4"}),(0,m.jsx)("span",{className:"text-gray-600 text-sm",children:"Loading..."})]})]})}function rA(){let[e,s]=(0,u.useState)(""),[l,t]=(0,u.useState)(!1),[a,r]=(0,u.useState)(!1),[i,n]=(0,u.useState)(null),[o,d]=(0,u.useState)(null),[c,p]=(0,u.useState)([]),[j,f]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,Z]=(0,u.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[k,S]=(0,u.useState)(!0),C=(0,h.useSearchParams)(),[I,T]=(0,u.useState)({data:[]}),[A,E]=(0,u.useState)(null),[P,O]=(0,u.useState)(!1),[L,D]=(0,u.useState)(!0),[M,F]=(0,u.useState)(null),R=C.get("invitation_id"),[q,U]=(0,u.useState)(()=>C.get("page")||"api-keys"),[z,V]=(0,u.useState)(null),K=e=>{p(s=>s?[...s,e]:[e]),O(()=>!P)},B=!1===L&&null===A&&null===R;return((0,u.useEffect)(()=>{E(function(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}("token")),D(!1)},[]),(0,u.useEffect)(()=>{B&&(window.location.href=(b.H2||"")+"/sso/key/generate")},[B]),(0,u.useEffect)(()=>{if(!A)return;let e=(0,x.o)(A);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),V(e.key),r(e.disabled_non_admin_personal_key_creation),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"org_admin":return"Org Admin";case"internal_user":return"Internal User";case"internal_viewer":return"Internal Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&U("usage")}else console.log("User role not defined");e.user_email?n(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?S("username_password"==e.login_method):console.log("User Email is not set ".concat(e)),e.premium_user&&t(e.premium_user),e.auth_header_name&&(0,b.K8)(e.auth_header_name),e.user_id&&F(e.user_id)}},[A]),(0,u.useEffect)(()=>{z&&M&&e&&eT(M,e,z,v),z&&M&&e&&w(z,M,e,null,d),z&&lE(z,f)},[z,M,e]),L||B)?(0,m.jsx)(rT,{}):(0,m.jsx)(u.Suspense,{fallback:(0,m.jsx)(rT,{}),children:(0,m.jsx)(g.aH,{client:rI,children:R?(0,m.jsx)(si,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):(0,m.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,m.jsx)(N,{userID:M,userRole:e,premiumUser:l,userEmail:i,setProxySettings:Z,proxySettings:y,accessToken:z}),(0,m.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,m.jsx)("div",{className:"mt-8",children:(0,m.jsx)(aZ,{setPage:e=>{let s=new URLSearchParams(C);s.set("page",e),window.history.pushState(null,"","?".concat(s.toString())),U(e)},userRole:e,defaultSelectedKey:q})}),"api-keys"==q?(0,m.jsx)(si,{userID:M,userRole:e,premiumUser:l,teams:o,keys:c,setUserRole:s,userEmail:i,setUserEmail:n,setTeams:d,setKeys:p,organizations:j,addKey:K,createClicked:P}):"models"==q?(0,m.jsx)(lh,{userID:M,userRole:e,token:A,keys:c,accessToken:z,modelData:I,setModelData:T,premiumUser:l,teams:o}):"llm-playground"==q?(0,m.jsx)(ad,{userID:M,userRole:e,token:A,accessToken:z,disabledPersonalKeyCreation:a}):"users"==q?(0,m.jsx)(lk,{userID:M,userRole:e,token:A,keys:c,teams:o,accessToken:z,setKeys:p}):"teams"==q?(0,m.jsx)(lT,{teams:o,setTeams:d,searchParams:C,accessToken:z,userID:M,userRole:e,organizations:j}):"organizations"==q?(0,m.jsx)(lP,{organizations:j,setOrganizations:f,userModels:_,accessToken:z,userRole:e,premiumUser:l}):"admin-panel"==q?(0,m.jsx)(lK,{setTeams:d,searchParams:C,accessToken:z,userID:M,showSSOBanner:k,premiumUser:l,proxySettings:y}):"api_ref"==q?(0,m.jsx)(tq,{proxySettings:y}):"settings"==q?(0,m.jsx)(l1,{userID:M,userRole:e,accessToken:z,premiumUser:l}):"budgets"==q?(0,m.jsx)(td,{accessToken:z}):"guardrails"==q?(0,m.jsx)(rd,{accessToken:z,userRole:e}):"transform-request"==q?(0,m.jsx)(rc,{accessToken:z}):"general-settings"==q?(0,m.jsx)(te,{userID:M,userRole:e,accessToken:z,modelData:I}):"model-hub"==q?(0,m.jsx)(tC.Z,{accessToken:z,publicPage:!1,premiumUser:l}):"caching"==q?(0,m.jsx)(aL,{userID:M,userRole:e,token:A,accessToken:z,premiumUser:l}):"pass-through-settings"==q?(0,m.jsx)(tr,{userID:M,userRole:e,accessToken:z,modelData:I}):"logs"==q?(0,m.jsx)(tk,{userID:M,userRole:e,token:A,accessToken:z,allTeams:null!=o?o:[]}):"mcp-tools"==q?(0,m.jsx)(rp,{accessToken:z,userRole:e,userID:M}):"tag-management"==q?(0,m.jsx)(rf,{accessToken:z,userRole:e,userID:M}):"vector-stores"==q?(0,m.jsx)(rb,{accessToken:z,userRole:e,userID:M}):"new_usage"==q?(0,m.jsx)(tR,{userID:M,userRole:e,accessToken:z,teams:null!=o?o:[]}):(0,m.jsx)(ak,{userID:M,userRole:e,token:A,accessToken:z,keys:c,premiumUser:l})]})]})})})}},3914:function(e,s,l){"use strict";function t(){let e=window.location.hostname,s=["Lax","Strict","None"];["/","/ui"].forEach(l=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,";"),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,";"),s.forEach(s=>{let t="None"===s?" Secure;":"";document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; SameSite=").concat(s,";").concat(t),document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=".concat(l,"; domain=").concat(e,"; SameSite=").concat(s,";").concat(t)})}),console.log("After clearing cookies:",document.cookie)}function a(e){let s=document.cookie.split("; ").find(s=>s.startsWith(e+"="));return s?s.split("=")[1]:null}l.d(s,{b:function(){return t},e:function(){return a}})}},function(e){e.O(0,[665,990,402,313,899,460,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_buildManifest.js b/ui/litellm-dashboard/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_buildManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_buildManifest.js rename to ui/litellm-dashboard/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_buildManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_ssgManifest.js b/ui/litellm-dashboard/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_ssgManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/qsCBX7lGZ8wS9ItsE0Soj/_ssgManifest.js rename to ui/litellm-dashboard/out/_next/static/zGtpf6gsLk3yIgGiM71ql/_ssgManifest.js diff --git a/ui/litellm-dashboard/out/index.html b/ui/litellm-dashboard/out/index.html index cf96cffc00f..fb47f3c8ce8 100644 --- a/ui/litellm-dashboard/out/index.html +++ b/ui/litellm-dashboard/out/index.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/ui/litellm-dashboard/out/index.txt b/ui/litellm-dashboard/out/index.txt index 38ed1ea2619..a5430891ee4 100644 --- a/ui/litellm-dashboard/out/index.txt +++ b/ui/litellm-dashboard/out/index.txt @@ -1,7 +1,7 @@ 2:I[19107,[],"ClientPageRoot"] -3:I[96564,["665","static/chunks/3014691f-b7b79b78e27792f3.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","402","static/chunks/402-ba983153c902cb17.js","313","static/chunks/313-9496b55e0596d651.js","899","static/chunks/899-ebef5c8ffc176e86.js","460","static/chunks/460-f6ee8934fa9fc1ae.js","250","static/chunks/250-45f35de8b3449336.js","699","static/chunks/699-6fbb6ca66d95cf3c.js","931","static/chunks/app/page-a61458b2080ad3dd.js"],"default",1] +3:I[96564,["665","static/chunks/3014691f-b7b79b78e27792f3.js","990","static/chunks/13b76428-ebdf3012af0e4489.js","402","static/chunks/402-ba983153c902cb17.js","313","static/chunks/313-9496b55e0596d651.js","899","static/chunks/899-ebef5c8ffc176e86.js","460","static/chunks/460-f6ee8934fa9fc1ae.js","250","static/chunks/250-45f35de8b3449336.js","699","static/chunks/699-6fbb6ca66d95cf3c.js","931","static/chunks/app/page-b69fceb3ef4b38ca.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["qsCBX7lGZ8wS9ItsE0Soj",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] +0:["zGtpf6gsLk3yIgGiM71ql",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"LiteLLM Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/ui/litellm-dashboard/out/model_hub.html b/ui/litellm-dashboard/out/model_hub.html index 65cca569eb2..31a7e095a40 100644 --- a/ui/litellm-dashboard/out/model_hub.html +++ b/ui/litellm-dashboard/out/model_hub.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/ui/litellm-dashboard/out/model_hub.txt b/ui/litellm-dashboard/out/model_hub.txt index f98c604ffa8..059237305e8 100644 --- a/ui/litellm-dashboard/out/model_hub.txt +++ b/ui/litellm-dashboard/out/model_hub.txt @@ -2,6 +2,6 @@ 3:I[52829,["402","static/chunks/402-ba983153c902cb17.js","313","static/chunks/313-9496b55e0596d651.js","250","static/chunks/250-45f35de8b3449336.js","699","static/chunks/699-6fbb6ca66d95cf3c.js","418","static/chunks/app/model_hub/page-ce40c5a05f3174ca.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["qsCBX7lGZ8wS9ItsE0Soj",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] +0:["zGtpf6gsLk3yIgGiM71ql",[[["",{"children":["model_hub",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["model_hub",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","model_hub","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"LiteLLM Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/ui/litellm-dashboard/out/onboarding.html b/ui/litellm-dashboard/out/onboarding.html index 31dfc72286e..51a7ab12d8d 100644 --- a/ui/litellm-dashboard/out/onboarding.html +++ b/ui/litellm-dashboard/out/onboarding.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/ui/litellm-dashboard/out/onboarding.txt b/ui/litellm-dashboard/out/onboarding.txt index bcc9d435057..2bde17545e2 100644 --- a/ui/litellm-dashboard/out/onboarding.txt +++ b/ui/litellm-dashboard/out/onboarding.txt @@ -2,6 +2,6 @@ 3:I[12011,["665","static/chunks/3014691f-b7b79b78e27792f3.js","402","static/chunks/402-ba983153c902cb17.js","899","static/chunks/899-ebef5c8ffc176e86.js","250","static/chunks/250-45f35de8b3449336.js","461","static/chunks/app/onboarding/page-8c2f1d7b29a0b5ff.js"],"default",1] 4:I[4707,[],""] 5:I[36423,[],""] -0:["qsCBX7lGZ8wS9ItsE0Soj",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] +0:["zGtpf6gsLk3yIgGiM71ql",[[["",{"children":["onboarding",{"children":["__PAGE__",{}]}]},"$undefined","$undefined",true],["",{"children":["onboarding",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],null],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","onboarding","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/86f6cc749f6b8493.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/ui/_next/static/css/56219c479b47698a.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_cf7686","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]}]],null],null],["$L6",null]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"LiteLLM Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null