(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{1900:function(e,l,s){Promise.resolve().then(s.bind(s,82080))},12011:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return Z}});var t=s(57437),a=s(2265),r=s(99376),n=s(20831),i=s(94789),o=s(12514),d=s(49804),c=s(67101),m=s(84264),u=s(26637),h=s(96761),x=s(84566),p=s(19250),j=s(14474),g=s(13634),f=s(73002);function Z(){let[e]=g.Z.useForm(),l=(0,r.useSearchParams)();!function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));l&&l.split("=")[1]}("token");let s=l.get("invitation_id"),[Z,_]=(0,a.useState)(null),[y,b]=(0,a.useState)(""),[v,w]=(0,a.useState)(""),[S,k]=(0,a.useState)(null),[N,C]=(0,a.useState)(""),[I,A]=(0,a.useState)("");return(0,a.useEffect)(()=>{s&&(0,p.W_)(s).then(e=>{let l=e.login_url;console.log("login_url:",l),C(l);let s=e.token,t=(0,j.o)(s);A(s),console.log("decoded:",t),_(t.key),console.log("decoded user email:",t.user_email),w(t.user_email),k(t.user_id)})},[s]),(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 Tirer."}),(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)(g.Z,{className:"mt-10 mb-5 mx-auto",layout:"vertical",onFinish:e=>{console.log("in handle submit. accessToken:",Z,"token:",I,"formValues:",e),Z&&I&&(e.user_email=v,S&&s&&(0,p.m_)(Z,s,S,e.password).then(e=>{var l;let s="/ui/";s+="?userID="+((null===(l=e.data)||void 0===l?void 0:l.user_id)||e.user_id),document.cookie="token="+I,console.log("redirecting to:",s),window.location.href=s}))},children:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(g.Z.Item,{label:"Email Address",name:"user_email",children:(0,t.jsx)(u.Z,{type:"email",disabled:!0,value:v,defaultValue:v,className:"max-w-md"})}),(0,t.jsx)(g.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"})})]})]})})}},82080:function(e,l,s){"use strict";s.r(l),s.d(l,{default:function(){return sZ}});var t,a,r=s(57437),n=s(2265),i=s(99376),o=s(14474),d=s(90946),c=s(29827),m=s(27648),u=s(92643),h=e=>{let{userID:l,userRole:s,userEmail:t,premiumUser:a,setProxySettings:n,proxySettings:i}=e;console.log("User ID:",l),console.log("userEmail:",t),console.log("premiumUser:",a),console.log=function(){};let o="";console.log("PROXY_settings=",i),i&&i.PROXY_LOGOUT_URL&&void 0!==i.PROXY_LOGOUT_URL&&(o=i.PROXY_LOGOUT_URL),console.log("logoutUrl=",o);let d=[{key:"1",label:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("p",{children:["Role: ",s]}),(0,r.jsxs)("p",{children:["ID: ",l]}),(0,r.jsxs)("p",{children:["Premium User: ",String(a)]})]})},{key:"2",label:(0,r.jsx)("p",{onClick:()=>{document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",window.location.href=o},children:"Logout"})}];return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("nav",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:(0,r.jsx)("div",{className:"w-full px-4",children:(0,r.jsxs)("div",{className:"flex justify-between items-center h-14",children:[(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsx)(m.default,{href:"/",className:"flex items-center",children:(0,r.jsx)("button",{className:"text-gray-800 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",alt:"LiteLLM Brand",className:"h-10 w-40 object-contain"})})})}),(0,r.jsxs)("div",{className:"flex items-center space-x-6",children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-gray-600 hover:text-gray-800",children:"Docs"}),(0,r.jsx)(u.Z,{menu:{items:d},children:(0,r.jsxs)("button",{className:"flex items-center text-sm text-gray-600 hover:text-gray-800",children:["User",(0,r.jsx)("svg",{className:"ml-1 w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M19 9l-7 7-7-7"})})]})})]})]})})})})},x=s(19250),p=s(49804),j=s(67101),g=s(20831),f=s(26637),Z=s(87452),_=s(88829),y=s(72208),b=s(84264),v=s(96761),w=s(29233),S=s(41326),k=s(13634),N=s(41021),C=s(51369),I=s(8104),A=s(20577),P=s(56632),E=s(73002);let T=async(e,l,s)=>{try{if(null===e||null===l)return;if(null!==s){let t=(await (0,x.So)(s,e,l,!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)}},O=e=>{if(console.log("getModelDisplayName",e),e.endsWith("/*")){let l=e.replace("/*","");return"All ".concat(l," models")}return e},D=(e,l)=>{let s=[],t=[];return console.log("teamModels",e),console.log("allModels",l),e.forEach(e=>{if(e.endsWith("/*")){let a=e.replace("/*",""),r=l.filter(e=>e.startsWith(a+"/"));t.push(...r),s.push(e)}else t.push(e)}),[...s,...t].filter((e,l,s)=>s.indexOf(e)===l)};var M=s(15424),F=s(75957);let{Option:R}=S.default,L=e=>{let l=[];if(console.log("data:",JSON.stringify(e)),e)for(let s of e)s.metadata&&s.metadata.tags&&l.push(...s.metadata.tags);let s=Array.from(new Set(l)).map(e=>({value:e,label:e}));return console.log("uniqueTags:",s),s};var U=e=>{let{userID:l,team:s,userRole:t,accessToken:a,data:i,setData:o}=e,[d]=k.Z.useForm(),[c,m]=(0,n.useState)(!1),[u,h]=(0,n.useState)(null),[T,U]=(0,n.useState)(null),[z,V]=(0,n.useState)([]),[B,q]=(0,n.useState)([]),[K,W]=(0,n.useState)("you"),[H,Y]=(0,n.useState)(L(i)),[G,J]=(0,n.useState)([]),X=()=>{m(!1),d.resetFields()},$=()=>{m(!1),h(null),d.resetFields()};(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===t)return;if(null!==a){let e=(await (0,x.So)(a,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),V(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,t]),(0,n.useEffect)(()=>{(async()=>{try{let e=(await (0,x.t3)(a)).guardrails.map(e=>e.guardrail_name);J(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[a]);let Q=async e=>{try{var s,t,r;let n=null!==(s=null==e?void 0:e.key_alias)&&void 0!==s?s:"",c=null!==(t=null==e?void 0:e.team_id)&&void 0!==t?t:null;if((null!==(r=null==i?void 0:i.filter(e=>e.team_id===c).map(e=>e.key_alias))&&void 0!==r?r:[]).includes(n))throw Error("Key alias ".concat(n," already exists for team with ID ").concat(c,", please provide another key alias"));if(N.ZP.info("Making API Call"),m(!0),"service_account"===K){let l={};try{l=JSON.parse(e.metadata||"{}")}catch(e){console.error("Error parsing metadata:",e)}l.service_account_id=e.key_alias,e.metadata=JSON.stringify(l)}let u=await (0,x.wX)(a,l,e);console.log("key create Response:",u),o(e=>e?[...e,u]:[u]),h(u.key),U(u.soft_budget),N.ZP.success("API Key Created"),d.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.log("error in create key:",e),N.ZP.error("Error creating the key: ".concat(e))}};return(0,n.useEffect)(()=>{q(D(s&&s.models.length>0?s.models.includes("all-proxy-models")?z:s.models:z,z))},[s,z]),(0,r.jsxs)("div",{children:[(0,r.jsx)(g.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(C.Z,{title:"Create Key",visible:c,width:800,footer:null,onOk:X,onCancel:$,children:(0,r.jsxs)(k.Z,{form:d,onFinish:Q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Owned By",className:"mb-4",children:(0,r.jsxs)(I.ZP.Group,{onChange:e=>W(e.target.value),value:K,children:[(0,r.jsx)(I.ZP,{value:"you",children:"You"}),(0,r.jsx)(I.ZP,{value:"service_account",children:"Service Account"}),"Admin"===t&&(0,r.jsx)(I.ZP,{value:"another_user",children:"Another User"})]})}),(0,r.jsx)(k.Z.Item,{label:"User ID",name:"user_id",hidden:"another_user"!==K,valuePropName:"user_id",className:"mt-8",rules:[{required:"another_user"===K,message:"Please input the user ID of the user you are assigning the key to"}],help:"Get User ID - Click on the 'Users' tab in the sidebar.",children:(0,r.jsx)(f.Z,{placeholder:"User ID",onChange:e=>d.setFieldValue("user_id",e.target.value)})}),(0,r.jsx)(k.Z.Item,{label:"you"===K||"another_user"===K?"Key Name":"Service Account ID",name:"key_alias",rules:[{required:!0,message:"Please input a ".concat("you"===K?"key name":"service account ID")}],help:"you"===K?"required":"IDs can include letters, numbers, and hyphens",children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:"Team ID",name:"team_id",hidden:"another_user"!==K,initialValue:s?s.team_id:null,valuePropName:"team_id",className:"mt-8",children:(0,r.jsx)(f.Z,{defaultValue:s?s.team_id:null,onChange:e=>d.setFieldValue("team_id",e.target.value)})}),(0,r.jsx)(k.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(S.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&d.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(R,{value:"all-team-models",children:"All Team Models"},"all-team-models"),B.map(e=>(0,r.jsx)(R,{value:e,children:O(e)},e))]})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(y.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==s?void 0:s.max_budget)!==null&&(null==s?void 0:s.max_budget)!==void 0?null==s?void 0:s.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.max_budget&&l>s.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(s.max_budget))}}],children:(0,r.jsx)(A.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Team Reset Budget: ".concat((null==s?void 0:s.budget_duration)!==null&&(null==s?void 0:s.budget_duration)!==void 0?null==s?void 0:s.budget_duration:"None"),children:(0,r.jsxs)(S.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(S.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(S.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(S.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Tokens per minute Limit (TPM)",name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==s?void 0:s.tpm_limit)!==null&&(null==s?void 0:s.tpm_limit)!==void 0?null==s?void 0:s.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.tpm_limit&&l>s.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(s.tpm_limit))}}],children:(0,r.jsx)(A.Z,{step:1,width:400})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Requests per minute Limit (RPM)",name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==s?void 0:s.rpm_limit)!==null&&(null==s?void 0:s.rpm_limit)!==void 0?null==s?void 0:s.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&s&&null!==s.rpm_limit&&l>s.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(s.rpm_limit))}}],children:(0,r.jsx)(A.Z,{step:1,width:400})}),(0,r.jsx)(k.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(F.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(M.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(S.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:G.map(e=>({value:e,label:e}))})}),(0,r.jsx)(k.Z.Item,{label:"Metadata",name:"metadata",className:"mt-8",children:(0,r.jsx)(P.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)(k.Z.Item,{label:"Tags",name:"tags",className:"mt-8",help:"Tags for tracking spend and/or doing tag-based routing.",children:(0,r.jsx)(S.default,{mode:"tags",style:{width:"100%"},placeholder:"Enter tags",tokenSeparators:[","],options:H})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(C.Z,{visible:c,onOk:X,onCancel:$,footer:null,children:(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(v.Z,{children:"Save your Key"}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,r.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,r.jsx)(p.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(b.Z,{className:"mt-3",children:"API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:u})}),(0,r.jsx)(w.CopyToClipboard,{text:u,onCopy:()=>{N.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(g.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(b.Z,{children:"Key being created, this might take 30s"})})]})})]})},z=s(7366),V=s(15731),B=s(53410),q=s(23628),K=s(74998),W=s(41649),H=s(12514),Y=s(47323),G=s(21626),J=s(97214),X=s(28241),$=s(58834),Q=s(69552),ee=s(71876),el=s(27281),es=s(57365),et=s(90464);let{Option:ea}=S.default;console.log=function(){};var er=e=>{let{userID:l,userRole:s,accessToken:t,selectedTeam:a,data:i,setData:o,teams:d,premiumUser:c}=e,[m,u]=(0,n.useState)(!1),[h,Z]=(0,n.useState)(!1),[_,y]=(0,n.useState)(null),[I,P]=(0,n.useState)(null),[D,R]=(0,n.useState)(null),[L,U]=(0,n.useState)(""),[er,en]=(0,n.useState)(!1),[ei,eo]=(0,n.useState)(!1),[ed,ec]=(0,n.useState)(null),[em,eu]=(0,n.useState)([]),eh=new Set,[ex,ep]=(0,n.useState)(!1),[ej,eg]=(0,n.useState)(!1),[ef,eZ]=(0,n.useState)(null),[e_,ey]=(0,n.useState)(null),[eb]=k.Z.useForm(),[ev,ew]=(0,n.useState)(null),[eS,ek]=(0,n.useState)(eh),[eN,eC]=(0,n.useState)([]),eI=e=>!!e.members_with_roles&&e.members_with_roles.some(e=>"admin"===e.role&&e.user_id===l),eA=n.useMemo(()=>{let e=[];return d&&0!==d.length?(d.forEach(l=>{"default-team"!==l.team_id&&eI(l)?eI(l)&&a&&a.team_id===l.team_id&&(e=[...e,...(null==i?void 0:i.filter(e=>(null==e?void 0:e.team_id)===(null==l?void 0:l.team_id)))||[]]):a&&a.team_id===l.team_id&&i&&(e=[...e,...i.filter(e=>e.team_id===l.team_id)])}),(!a||"Default Team"===a.team_alias)&&i&&(e=[...i.filter(e=>!e.team_id||"default-team"===e.team_id),...d.filter(e=>eI(e)).flatMap(e=>e.keys||[])]),Array.from(new Map((e=e.filter(e=>"litellm-dashboard"!==e.team_id)).map(e=>[e.token,e])).values())):i},[i,d,a,l]);(0,n.useEffect)(()=>{console.log("in calculateNewExpiryTime for selectedToken",ed),(null==e_?void 0:e_.duration)?ew((e=>{if(!e)return null;try{let l;let s=new Date;if(e.endsWith("s"))l=(0,z.Z)(s,{seconds:parseInt(e)});else if(e.endsWith("h"))l=(0,z.Z)(s,{hours:parseInt(e)});else if(e.endsWith("d"))l=(0,z.Z)(s,{days:parseInt(e)});else throw Error("Invalid duration format");return l.toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0})}catch(e){return null}})(e_.duration)):ew(null),console.log("calculateNewExpiryTime:",ev)},[ed,null==e_?void 0:e_.duration]),(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===s||null===t)return;let e=await T(l,s,t);e&&eu(e)}catch(e){console.error("Error fetching user models:",e)}})()},[t,l,s]);let eP=e=>{ec(e),ep(!0)},eE=async e=>{if(null==t||null==ed)return;let l={...ed,metadata:e,key:ed.token};try{let e=await (0,x.Nc)(t,l);if(console.log("Model limits updated:",e),i){let l=i.map(l=>l.token===ed.token?e:l);o(l)}N.ZP.success("Model-specific limits updated successfully")}catch(e){console.error("Error updating model-specific limits:",e),N.ZP.error("Failed to update model-specific limits")}ep(!1),ec(null)};(0,n.useEffect)(()=>{if(d){let e=new Set;d.forEach((l,s)=>{let t=l.team_id;e.add(t)}),ek(e)}},[d]);let eT=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id);let l=null;if(e.budget_duration)switch(e.budget_duration){case"24h":l="daily";break;case"7d":l="weekly";break;case"30d":l="monthly";break;default:l="None"}ec({...e,budget_duration:l}),en(!0)},eO=async e=>{var l,s;if(null==t)return;let a=e.token;if(e.key=a,e.metadata&&"string"==typeof e.metadata)try{let s=JSON.parse(e.metadata);e.metadata={...s,...(null===(l=e.guardrails)||void 0===l?void 0:l.length)>0?{guardrails:e.guardrails}:{}}}catch(l){console.error("Error parsing metadata JSON:",l),N.ZP.error("Invalid metadata JSON for formValue "+e.metadata);return}else e.metadata={...e.metadata||{},...(null===(s=e.guardrails)||void 0===s?void 0:s.length)>0?{guardrails:e.guardrails}:{}};if(e.budget_duration)switch(e.budget_duration){case"daily":e.budget_duration="24h";break;case"weekly":e.budget_duration="7d";break;case"monthly":e.budget_duration="30d"}console.log("handleEditSubmit:",e);try{let l=await (0,x.Nc)(t,e);if(console.log("handleEditSubmit: newKeyValues",l),i){let e=i.map(e=>e.token===a?l:e);o(e)}N.ZP.success("Key updated successfully"),en(!1),ec(null)}catch(e){console.error("Error updating key:",e),N.ZP.error("Failed to update key")}},eD=async e=>{console.log("handleDelete:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),null!=i&&(y(e.token),localStorage.removeItem("userData"+l),Z(!0))},eM=async()=>{if(null!=_&&null!=i){try{await (0,x.I1)(t,_);let e=i.filter(e=>e.token!==_);o(e)}catch(e){console.error("Error deleting the key:",e)}Z(!1),y(null)}},eF=e=>{ec(e),ew(null),eb.setFieldsValue({key_alias:e.key_alias,max_budget:e.max_budget,tpm_limit:e.tpm_limit,rpm_limit:e.rpm_limit,duration:e.duration||""}),eg(!0)},eR=(e,l)=>{ey(s=>({...s,[e]:l}))},eL=async()=>{if(!c){N.ZP.error("Regenerate API Key is an Enterprise feature. Please upgrade to use this feature.");return}if(null!=ed)try{let e=await eb.validateFields(),l=await (0,x.s0)(t,ed.token,e);if(eZ(l.key),i){let s=i.map(s=>s.token===(null==ed?void 0:ed.token)?{...s,key_name:l.key_name,...e}:s);o(s)}eg(!1),eb.resetFields(),N.ZP.success("API Key regenerated successfully")}catch(e){console.error("Error regenerating key:",e),N.ZP.error("Failed to regenerate API Key")}};if(null!=i)return console.log("RERENDER TRIGGERED"),(0,r.jsxs)("div",{children:[(0,r.jsxs)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(G.Z,{className:"mt-5 max-h-[300px] min-h-[300px]",children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Key Alias"}),(0,r.jsx)(Q.Z,{children:"Secret Key"}),(0,r.jsx)(Q.Z,{children:"Created"}),(0,r.jsx)(Q.Z,{children:"Expires"}),(0,r.jsx)(Q.Z,{children:"Spend (USD)"}),(0,r.jsx)(Q.Z,{children:"Budget (USD)"}),(0,r.jsx)(Q.Z,{children:"Budget Reset"}),(0,r.jsx)(Q.Z,{children:"Models"}),(0,r.jsx)(Q.Z,{children:"Rate Limits"}),(0,r.jsx)(Q.Z,{children:"Rate Limits per model"})]})}),(0,r.jsx)(J.Z,{children:eA&&eA.map(e=>{if(console.log(e),"litellm-dashboard"===e.team_id)return null;if(a){if(console.log("item team id: ".concat(e.team_id,", knownTeamIDs.has(item.team_id): ").concat(eS.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||eS.has(e.team_id))&&e.team_id!=a.team_id)return null;console.log("item team id: ".concat(e.team_id,", is returned"))}return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(b.Z,{children:e.key_alias}):(0,r.jsx)(b.Z,{children:"Not Set"})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:e.key_name})}),(0,r.jsx)(X.Z,{children:null!=e.created_at?(0,r.jsx)("div",{children:(0,r.jsx)("p",{style:{fontSize:"0.70rem"},children:new Date(e.created_at).toLocaleDateString()})}):(0,r.jsx)("p",{style:{fontSize:"0.70rem"},children:"Not available"})}),(0,r.jsx)(X.Z,{children:null!=e.expires?(0,r.jsx)("div",{children:(0,r.jsx)("p",{style:{fontSize:"0.70rem"},children:new Date(e.expires).toLocaleDateString()})}):(0,r.jsx)("p",{style:{fontSize:"0.70rem"},children:"Never"})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(X.Z,{children:null!=e.max_budget?(0,r.jsx)(b.Z,{children:e.max_budget}):(0,r.jsx)(b.Z,{children:"Unlimited"})}),(0,r.jsx)(X.Z,{children:null!=e.budget_reset_at?(0,r.jsx)("div",{children:(0,r.jsx)("p",{style:{fontSize:"0.70rem"},children:new Date(e.budget_reset_at).toLocaleString()})}):(0,r.jsx)("p",{style:{fontSize:"0.70rem"},children:"Never"})}),(0,r.jsx)(X.Z,{children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(r.Fragment,{children:a&&a.models&&a.models.length>0?a.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"All Team Models"})},l):(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(b.Z,{children:e.length>30?"".concat(O(e).slice(0,30),"..."):O(e)})},l)):(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(b.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"All Team Models"})},l):(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(b.Z,{children:e.length>30?"".concat(O(e).slice(0,30),"..."):O(e)})},l))}):null}),(0,r.jsx)(X.Z,{children:(0,r.jsxs)(b.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{})," RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(g.Z,{size:"xs",onClick:()=>eP(e),children:"Edit Limits"})}),(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(Y.Z,{onClick:()=>{ec(e),eo(!0)},icon:V.Z,size:"sm"}),(0,r.jsx)(C.Z,{open:ei,onCancel:()=>{eo(!1),ec(null)},footer:null,width:800,children:ed&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-8",children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Spend"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:(()=>{try{return parseFloat(ed.spend).toFixed(4)}catch(e){return ed.spend}})()})})]}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Budget"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=ed.max_budget?(0,r.jsxs)(r.Fragment,{children:[ed.max_budget,ed.budget_duration&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("br",{}),"Budget will be reset at"," ",ed.budget_reset_at?new Date(ed.budget_reset_at).toLocaleString():"Never"]})]}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Expires"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-default font-small text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=ed.expires?(0,r.jsx)(r.Fragment,{children:new Date(ed.expires).toLocaleString(void 0,{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}):(0,r.jsx)(r.Fragment,{children:"Never"})})})]},e.name)]}),(0,r.jsxs)(H.Z,{className:"my-4",children:[(0,r.jsx)(v.Z,{children:"Token Name"}),(0,r.jsx)(b.Z,{className:"my-1",children:ed.key_alias?ed.key_alias:ed.key_name}),(0,r.jsx)(v.Z,{children:"Token ID"}),(0,r.jsx)(b.Z,{className:"my-1 text-[12px]",children:ed.token}),(0,r.jsx)(v.Z,{children:"User ID"}),(0,r.jsx)(b.Z,{className:"my-1 text-[12px]",children:ed.user_id}),(0,r.jsx)(v.Z,{children:"Metadata"}),(0,r.jsx)(b.Z,{className:"my-1",children:(0,r.jsxs)("pre",{children:[JSON.stringify(ed.metadata)," "]})})]}),(0,r.jsx)(g.Z,{className:"mx-auto flex items-center",onClick:()=>{eo(!1),ec(null)},children:"Close"})]})}),(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>eT(e)}),(0,r.jsx)(Y.Z,{onClick:()=>eF(e),icon:q.Z,size:"sm"}),(0,r.jsx)(Y.Z,{onClick:()=>eD(e),icon:K.Z,size:"sm"})]})]},e.token)})})]}),h&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.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,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:""}),(0,r.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,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(g.Z,{onClick:eM,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(g.Z,{onClick:()=>{Z(!1),y(null)},children:"Cancel"})]})]})]})})]}),ed&&(0,r.jsx)(e=>{let{visible:l,onCancel:s,token:i,onSubmit:o}=e,[c]=k.Z.useForm(),[m,u]=(0,n.useState)(a),[h,p]=(0,n.useState)([]),[j,g]=(0,n.useState)(!1),[Z,_]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=(await (0,x.t3)(t)).guardrails.map(e=>e.guardrail_name);_(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let y="";try{let e={...i.metadata};delete e.guardrails,y=JSON.stringify(e,null,2)}catch(e){console.error("Error stringifying metadata:",e),y=""}let b=[];try{var v;b=(null===(v=i.metadata)||void 0===v?void 0:v.guardrails)||[]}catch(e){console.error("Error extracting guardrails:",e)}let w=i?{...i,budget_duration:i.budget_duration,metadata:y,guardrails:b}:{metadata:y,guardrails:[]};return(0,r.jsx)(C.Z,{title:"Edit Key",visible:l,width:800,footer:null,onOk:()=>{c.validateFields().then(e=>{c.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(k.Z,{form:c,onFinish:eO,initialValues:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"Models",name:"models",rules:[{validator:(e,l)=>{if("Default Team"===m.team_alias)return Promise.resolve();let s=l.filter(e=>!m.models.includes(e)&&"all-team-models"!==e&&"all-proxy-models"!==e&&!m.models.includes("all-proxy-models"));return(console.log("errorModels: ".concat(s)),s.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(s," Team models: ").concat(m.models)):Promise.resolve()}}],children:(0,r.jsxs)(S.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea,{value:"all-team-models",children:"All Team Models"},"all-team-models"),"Default Team"===m.team_alias?em.filter(e=>"all-proxy-models"!==e).map(e=>(0,r.jsx)(ea,{value:e,children:O(e)},e)):m.models.map(e=>(0,r.jsx)(ea,{value:e,children:O(e)},e))]})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: ".concat((null==m?void 0:m.max_budget)!==null&&(null==m?void 0:m.max_budget)!==void 0?null==m?void 0:m.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&m&&null!==m.max_budget&&l>m.max_budget)throw console.log("keyTeam.max_budget: ".concat(m.max_budget)),Error("Budget cannot exceed team max budget: $".concat(m.max_budget))}}],children:(0,r.jsx)(A.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Current Reset Budget: ".concat(i.budget_duration,", budget will be reset: ").concat(i.budget_reset_at?new Date(i.budget_reset_at).toLocaleString():"Never"),children:(0,r.jsxs)(S.default,{placeholder:"n/a",children:[(0,r.jsx)(S.default.Option,{value:"daily",children:"daily"}),(0,r.jsx)(S.default.Option,{value:"weekly",children:"weekly"}),(0,r.jsx)(S.default.Option,{value:"monthly",children:"monthly"})]})}),(0,r.jsx)(k.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(k.Z.Item,{label:"Team",name:"team_id",className:"mt-8",help:"the team this key belongs to",children:(0,r.jsx)(el.Z,{value:i.team_alias,children:null==d?void 0:d.map((e,l)=>(0,r.jsx)(es.Z,{value:e.team_id,onClick:()=>u(e),children:e.team_alias},l))})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"TPM Limit (tokens per minute)",name:"tpm_limit",help:"tpm_limit cannot exceed team tpm_limit ".concat((null==m?void 0:m.tpm_limit)!==null&&(null==m?void 0:m.tpm_limit)!==void 0?null==m?void 0:m.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&m&&null!==m.tpm_limit&&l>m.tpm_limit)throw console.log("keyTeam.tpm_limit: ".concat(m.tpm_limit)),Error("tpm_limit cannot exceed team max tpm_limit: $".concat(m.tpm_limit))}}],children:(0,r.jsx)(A.Z,{step:1,precision:1,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"RPM Limit (requests per minute)",name:"rpm_limit",help:"rpm_limit cannot exceed team max rpm_limit: ".concat((null==m?void 0:m.rpm_limit)!==null&&(null==m?void 0:m.rpm_limit)!==void 0?null==m?void 0:m.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&m&&null!==m.rpm_limit&&l>m.rpm_limit)throw console.log("keyTeam.rpm_limit: ".concat(m.rpm_limit)),Error("rpm_limit cannot exceed team max rpm_limit: $".concat(m.rpm_limit))}}],children:(0,r.jsx)(A.Z,{step:1,precision:1,width:200})}),(0,r.jsx)(k.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(F.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(M.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(S.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:Z.map(e=>({value:e,label:e}))})}),(0,r.jsx)(k.Z.Item,{label:"Metadata (ensure this is valid JSON)",name:"metadata",children:(0,r.jsx)(et.Z,{rows:10,onChange:e=>{c.setFieldsValue({metadata:e.target.value})}})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:er,onCancel:()=>{en(!1),ec(null)},token:ed,onSubmit:eO}),ed&&(0,r.jsx)(e=>{let{visible:l,onCancel:s,token:t,onSubmit:a,accessToken:i}=e,[o,d]=(0,n.useState)({}),[c,m]=(0,n.useState)([]),[u,h]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(t.metadata){let e=t.metadata.model_tpm_limit||{},l=t.metadata.model_rpm_limit||{},s={};Object.keys({...e,...l}).forEach(t=>{s[t]={tpm:e[t]||0,rpm:l[t]||0}}),d(s)}(async()=>{try{let e=await (0,x.AZ)(i,"",""),l=Array.from(new Set(e.data.map(e=>e.model_name)));m(l)}catch(e){console.error("Error fetching model data:",e),N.ZP.error("Failed to fetch available models")}})()},[t,i]);let p=(e,l,s)=>{d(t=>({...t,[e]:{...t[e],[l]:s||0}}))},j=e=>{d(l=>{let{[e]:s,...t}=l;return t})};return(0,r.jsxs)(C.Z,{title:"Edit Model-Specific Limits",visible:l,onCancel:s,footer:null,width:800,children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Model"}),(0,r.jsx)(Q.Z,{children:"TPM Limit"}),(0,r.jsx)(Q.Z,{children:"RPM Limit"}),(0,r.jsx)(Q.Z,{children:"Actions"})]})}),(0,r.jsxs)(J.Z,{children:[Object.entries(o).map(e=>{let[l,s]=e;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:l}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(A.Z,{value:s.tpm,onChange:e=>p(l,"tpm",e)})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(A.Z,{value:s.rpm,onChange:e=>p(l,"rpm",e)})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(g.Z,{onClick:()=>j(l),children:"Remove"})})]},l)}),null!==u&&(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:(0,r.jsx)(S.default,{style:{width:200},placeholder:"Select a model",onChange:e=>{o[e]||d(l=>({...l,[e]:{tpm:0,rpm:0}})),h(null)},value:u||void 0,children:c.filter(e=>!o.hasOwnProperty(e)).map(e=>(0,r.jsx)(ea,{value:e,children:e},e))})}),(0,r.jsx)(X.Z,{children:"-"}),(0,r.jsx)(X.Z,{children:"-"}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(g.Z,{onClick:()=>h(null),children:"Cancel"})})]})]})]}),(0,r.jsx)(g.Z,{onClick:()=>{h("")},disabled:null!==u,children:"Add Limit"})]}),(0,r.jsxs)("div",{className:"flex justify-end space-x-4 mt-6",children:[(0,r.jsx)(g.Z,{onClick:s,children:"Cancel"}),(0,r.jsx)(g.Z,{onClick:()=>{a({...t.metadata,model_tpm_limit:Object.fromEntries(Object.entries(o).map(e=>{let[l,s]=e;return[l,s.tpm]})),model_rpm_limit:Object.fromEntries(Object.entries(o).map(e=>{let[l,s]=e;return[l,s.rpm]}))})},children:"Save"})]})]})},{visible:ex,onCancel:()=>ep(!1),token:ed,onSubmit:eE,accessToken:t}),(0,r.jsx)(C.Z,{title:"Regenerate API Key",visible:ej,onCancel:()=>{eg(!1),eb.resetFields()},footer:[(0,r.jsx)(g.Z,{onClick:()=>{eg(!1),eb.resetFields()},className:"mr-2",children:"Cancel"},"cancel"),(0,r.jsx)(g.Z,{onClick:eL,disabled:!c,children:c?"Regenerate":"Upgrade to Regenerate"},"regenerate")],children:c?(0,r.jsxs)(k.Z,{form:eb,layout:"vertical",onValuesChange:(e,l)=>{"duration"in e&&eR("duration",e.duration)},children:[(0,r.jsx)(k.Z.Item,{name:"key_alias",label:"Key Alias",children:(0,r.jsx)(f.Z,{disabled:!0})}),(0,r.jsx)(k.Z.Item,{name:"max_budget",label:"Max Budget (USD)",children:(0,r.jsx)(A.Z,{step:.01,precision:2,style:{width:"100%"}})}),(0,r.jsx)(k.Z.Item,{name:"tpm_limit",label:"TPM Limit",children:(0,r.jsx)(A.Z,{style:{width:"100%"}})}),(0,r.jsx)(k.Z.Item,{name:"rpm_limit",label:"RPM Limit",children:(0,r.jsx)(A.Z,{style:{width:"100%"}})}),(0,r.jsx)(k.Z.Item,{name:"duration",label:"Expire Key (eg: 30s, 30h, 30d)",className:"mt-8",children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsxs)("div",{className:"mt-2 text-sm text-gray-500",children:["Current expiry:"," ",(null==ed?void 0:ed.expires)!=null?new Date(ed.expires).toLocaleString():"Never"]}),ev&&(0,r.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["New expiry: ",ev]})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to use this feature"}),(0,r.jsx)(g.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",children:"Get Free Trial"})})]})}),ef&&(0,r.jsx)(C.Z,{visible:!!ef,onCancel:()=>eZ(null),footer:[(0,r.jsx)(g.Z,{onClick:()=>eZ(null),children:"Close"},"close")],children:(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(v.Z,{children:"Regenerated Key"}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please replace your old key with the new key generated. For security reasons, ",(0,r.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,r.jsxs)(p.Z,{numColSpan:1,children:[(0,r.jsx)(b.Z,{className:"mt-3",children:"Key Alias:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:(null==ed?void 0:ed.key_alias)||"No alias set"})}),(0,r.jsx)(b.Z,{className:"mt-3",children:"New API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:ef})}),(0,r.jsx)(w.CopyToClipboard,{text:ef,onCopy:()=>N.ZP.success("API Key copied to clipboard"),children:(0,r.jsx)(g.Z,{className:"mt-3",children:"Copy API Key"})})]})]})})]})};console.log=function(){};var en=e=>{let{userID:l,userRole:s,accessToken:t,userSpend:a,userMaxBudget:i,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[d,c]=(0,n.useState)(null!==a?a:0),[m,u]=(0,n.useState)(o?o.max_budget:null);(0,n.useEffect)(()=>{if(o){if("Default Team"===o.team_alias)u(i);else{let e=!1;if(o.team_memberships)for(let s of o.team_memberships)s.user_id===l&&"max_budget"in s.litellm_budget_table&&null!==s.litellm_budget_table.max_budget&&(u(s.litellm_budget_table.max_budget),e=!0);e||u(o.max_budget)}}},[o,i]);let[h,p]=(0,n.useState)([]);(0,n.useEffect)(()=>{let e=async()=>{if(!t||!l||!s)return};(async()=>{try{if(null===l||null===s)return;if(null!==t){let e=(await (0,x.So)(t,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),p(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,t,l]),(0,n.useEffect)(()=>{null!==a&&c(a)},[a]);let j=[];o&&o.models&&(j=o.models),j&&j.includes("all-proxy-models")?(console.log("user models:",h),j=h):j&&j.includes("all-team-models")?j=o.models:j&&0===j.length&&(j=h);let g=void 0!==d?d.toFixed(4):null;return console.log("spend in view user spend: ".concat(d)),(0,r.jsx)("div",{className:"flex items-center",children:(0,r.jsxs)("div",{className:"flex justify-between gap-x-6",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",g]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Max Budget"}),(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null!==m?"$".concat(m," limit"):"No limit"})]})]})})};console.log=function(){};var ei=e=>{let{userID:l,userRole:s,selectedTeam:t,accessToken:a}=e,[i,o]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===s)return;if(null!==a){let e=(await (0,x.So)(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),o(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let d=[];return t&&t.models&&(d=t.models),d&&d.includes("all-proxy-models")&&(console.log("user models:",i),d=i),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null==t?void 0:t.team_alias}),(null==t?void 0:t.team_id)&&(0,r.jsxs)("p",{className:"text-xs text-gray-400 dark:text-gray-400 font-semibold",children:["Team ID: ",null==t?void 0:t.team_id]})]})})},eo=e=>{let l,{teams:s,setSelectedTeam:t,userRole:a,proxySettings:i,setProxySettings:o,userInfo:d,accessToken:c,setKeys:m}=e;console.log("userInfo: ".concat(JSON.stringify(d)));let u={models:(null==d?void 0:d.models)||[],team_id:null,team_alias:"Default Team",max_budget:(null==d?void 0:d.max_budget)||null},h=async()=>{null===i&&c&&o(await (0,x.g)(c))};(0,n.useEffect)(()=>{h()},[i]);let[p,j]=(0,n.useState)(u);return console.log("userRole: ".concat(a)),console.log("proxySettings: ".concat(JSON.stringify(i))),l="App User"===a?s:i&&!0===i.DEFAULT_TEAM_DISABLED?s?[...s]:[u]:s?[...s,u]:[u],(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(v.Z,{children:"Select Team"}),(0,r.jsx)(b.Z,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),(0,r.jsxs)(b.Z,{className:"mt-3 mb-3",children:[(0,r.jsx)("b",{children:"Default Team:"})," If no team_id is set for a key, it will be grouped under here."]}),l&&l.length>0?(0,r.jsx)(el.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(es.Z,{value:String(l),onClick:()=>{t(e)},children:e.team_alias},l))}):(0,r.jsxs)(b.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},ed=s(12011),ec=s(68060);console.log=function(){},console.log("isLocal:",!1);var em=e=>{let{userID:l,userRole:s,teams:t,keys:a,setUserRole:d,userEmail:c,setUserEmail:m,setTeams:u,setKeys:h,premiumUser:g}=e,[f,Z]=(0,n.useState)(null),_=(0,i.useSearchParams)();_.get("viewSpend"),(0,i.useRouter)();let y=function(e){console.log("COOKIES",document.cookie);let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"),b=_.get("invitation_id"),[v,w]=(0,n.useState)(null),[S,k]=(0,n.useState)(null),[N,C]=(0,n.useState)([]),[I,A]=(0,n.useState)(null),P={models:[],team_alias:"Default Team",team_id:null},[E,T]=(0,n.useState)(t?t[0]:P);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(y){let e=(0,o.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),w(e.key),e.user_role){let l=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:",l),d(l)}else console.log("User role not defined");e.user_email?m(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&v&&s&&!a&&!f){let e=sessionStorage.getItem("userModels"+l);if(e)C(JSON.parse(e));else{let e=async()=>{let e;e="Admin"!=s&&"Admin Viewer"!=s?await (0,x.It)(v,l):await (0,x.It)(v),console.log("givenTeams: ".concat(e)),u(e)};(async()=>{try{let e=await (0,x.g)(v);A(e);let t=await (0,x.Br)(v,l,s,!1,null,null);console.log("received teams in user dashboard: ".concat(Object.keys(t),"; team values: ").concat(Object.entries(t.teams))),Z(t.user_info),console.log("userSpendData: ".concat(JSON.stringify(f))),h(t.keys);let a=[...t.teams];a.length>0?(console.log("response['teams']: ".concat(JSON.stringify(a))),T(a[0])):T(P),sessionStorage.setItem("userData"+l,JSON.stringify(t.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(t.user_info));let r=(await (0,x.So)(v,l,s)).data.map(e=>e.id);console.log("available_model_names:",r),C(r),console.log("userModels:",N),sessionStorage.setItem("userModels"+l,JSON.stringify(r))}catch(e){console.error("There was an error fetching the data",e)}})(),e()}}},[l,y,v,a,s]),(0,n.useEffect)(()=>{if(null!==a&&null!=E&&null!==E.team_id){let e=0;for(let l of(console.log("keys: ".concat(JSON.stringify(a))),a))E.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===E.team_id&&(e+=l.spend);console.log("sum: ".concat(e)),k(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;k(e)}},[E]),null!=b)return(0,r.jsx)(ed.default,{});if(null==l||null==y){let e="/sso/key/generate";return document.cookie="token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",console.log("Full URL:",e),window.location.href=e,null}if(null==v)return null;if(null==s&&d("App Owner"),s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=ec.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",E),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(j.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(p.Z,{numColSpan:1,children:[(0,r.jsx)(ei,{userID:l,userRole:s,selectedTeam:E||null,accessToken:v}),(0,r.jsx)(en,{userID:l,userRole:s,userMaxBudget:(null==f?void 0:f.max_budget)||null,accessToken:v,userSpend:S,selectedTeam:E||null}),(0,r.jsx)(er,{userID:l,userRole:s,accessToken:v,selectedTeam:E||null,data:a,setData:h,premiumUser:g,teams:t}),(0,r.jsx)(U,{userID:l,team:E||null,userRole:s,accessToken:v,data:a,setData:h},E?E.team_id:null),(0,r.jsx)(eo,{teams:t,setSelectedTeam:T,userRole:s,proxySettings:I,setProxySettings:A,userInfo:f,accessToken:v,setKeys:h})]})})})},eu=s(97765),eh=s(47451),ex=s(69410),ep=()=>{let e=k.Z.useFormInstance();return(k.Z.useWatch("model",e)||[]).includes("all-wildcard")?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Public Model Name",name:"model_name",tooltip:"Model name your users will pass in. Also used for load-balancing, LiteLLM will load balance between all models with this public name.",labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",required:!1,className:"mb-0",rules:[e=>{let{getFieldValue:l}=e;return{validator:(e,s)=>!(l("model")||[]).includes("all-wildcard")||s?Promise.resolve():Promise.reject(Error('Public Model Name is required unless "All Models" is selected.'))}}],children:(0,r.jsx)(f.Z,{placeholder:"my-gpt-4"})}),(0,r.jsxs)(eh.Z,{children:[(0,r.jsx)(ex.Z,{span:10}),(0,r.jsx)(ex.Z,{span:10,children:(0,r.jsx)(b.Z,{className:"mb-2",children:"Model name your users will pass in."})})]})]})};(t=a||(a={})).OpenAI="OpenAI",t.Azure="Azure",t.Azure_AI_Studio="Azure AI 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.OpenAI_Compatible="OpenAI-Compatible Endpoints (Together AI, etc.)",t.Cohere="Cohere",t.Databricks="Databricks",t.Ollama="Ollama",t.xAI="xAI";let ej={OpenAI:"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",Vertex_AI:"vertex_ai",Databricks:"databricks",xAI:"xai",Deepseek:"deepseek",Ollama:"ollama"},eg={OpenAI:"https://artificialanalysis.ai/img/logos/openai_small.svg",Azure:"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg","Azure AI Studio":"https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",Anthropic:"https://artificialanalysis.ai/img/logos/anthropic_small.svg","Google AI Studio":"https://artificialanalysis.ai/img/logos/google_small.svg","Amazon Bedrock":"https://artificialanalysis.ai/img/logos/aws_small.png",Groq:"https://artificialanalysis.ai/img/logos/groq_small.png","Mistral AI":"https://artificialanalysis.ai/img/logos/mistral_small.png",Cohere:"https://artificialanalysis.ai/img/logos/cohere_small.png","OpenAI-Compatible Endpoints (Together AI, etc.)":"https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg","Vertex AI (Anthropic, Gemini, etc.)":"https://artificialanalysis.ai/img/logos/google_small.svg",Databricks:"https://artificialanalysis.ai/img/logos/databricks_small.png",Ollama:"https://artificialanalysis.ai/img/logos/ollama_small.svg",xAI:"https://artificialanalysis.ai/img/logos/xai_small.svg",Deepseek:"https://artificialanalysis.ai/img/logos/deepseek_small.jpg"},ef=e=>{if(!e)return{logo:"",displayName:"-"};let l=Object.keys(ej).find(l=>ej[l].toLowerCase()===e.toLowerCase());if(!l)return{logo:"",displayName:e};let s=a[l];return{logo:eg[s],displayName:s}},eZ=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 Studio"==e?"azure_ai/command-r-plus":"Azure"==e?"azure/my-deployment":"gpt-3.5-turbo",e_=(e,l)=>{console.log("Provider key: ".concat(e));let s=ej[e];console.log("Provider mapped to: ".concat(s));let t=[];return e&&"object"==typeof l&&(Object.entries(l).forEach(e=>{let[l,a]=e;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===s||a.litellm_provider.includes(s))&&t.push(l)}),"Cohere"==e&&(console.log("Adding cohere chat models"),Object.entries(l).forEach(e=>{let[l,s]=e;null!==s&&"object"==typeof s&&"litellm_provider"in s&&"cohere"===s.litellm_provider&&t.push(l)}))),t};var ey=e=>{let{selectedProvider:l,providerModels:s,getPlaceholder:t}=e,n=k.Z.useFormInstance();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(k.Z.Item,{label:"LiteLLM Model Name(s)",tooltip:"Actual model name used for making litellm.completion() / litellm.embedding() call.",className:"mb-0",children:[(0,r.jsx)(k.Z.Item,{name:"model",rules:[{required:!0,message:"Please select at least one model."}],noStyle:!0,children:l===a.Azure||l===a.OpenAI_Compatible||l===a.Ollama?(0,r.jsx)(f.Z,{placeholder:t(l.toString())}):s.length>0?(0,r.jsx)(S.default,{allowClear:!0,showSearch:!0,placeholder:"Select models",onChange:e=>{e.includes("all-wildcard")&&n.setFieldsValue({model_name:void 0})},optionFilterProp:"children",filterOption:(e,l)=>{var s;return(null!==(s=null==l?void 0:l.label)&&void 0!==s?s:"").toLowerCase().includes(e.toLowerCase())},options:[{label:"All ".concat(l," Models (Wildcard)"),value:"all-wildcard"},...s.map(e=>({label:e,value:e})),{label:"Custom Model Name (Enter below)",value:"custom"}],style:{width:"100%"}}):(0,r.jsx)(f.Z,{placeholder:t(l.toString())})}),(0,r.jsx)(k.Z.Item,{noStyle:!0,shouldUpdate:(e,l)=>e.model!==l.model,children:e=>{let{getFieldValue:l}=e;return(l("model")||[]).includes("custom")&&(0,r.jsx)(k.Z.Item,{name:"custom_model_name",rules:[{required:!0,message:"Please enter a custom model name."}],className:"mt-2",children:(0,r.jsx)(f.Z,{placeholder:"Enter custom model name"})})}})]}),(0,r.jsxs)(eh.Z,{children:[(0,r.jsx)(ex.Z,{span:10}),(0,r.jsx)(ex.Z,{span:10,children:(0,r.jsx)(b.Z,{className:"mb-3 mt-1",children:"Actual model name used for making litellm.completion() call. We loadbalance models with the same public name"})})]})]})},eb=s(63709);let{Link:ev}=ec.default;var ew=e=>{let{showAdvancedSettings:l,setShowAdvancedSettings:s}=e,[t]=k.Z.useForm(),[a,i]=n.useState(!1),[o,d]=n.useState("per_token"),c=(e,l)=>l&&(isNaN(Number(l))||0>Number(l))?Promise.reject("Please enter a valid positive number"):Promise.resolve(),m=(e,l)=>{if(!l)return Promise.resolve();try{return JSON.parse(l),Promise.resolve()}catch(e){return Promise.reject("Please enter valid JSON")}};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(Z.Z,{className:"mt-2 mb-4",children:[(0,r.jsx)(y.Z,{children:(0,r.jsx)("b",{children:"Advanced Settings"})}),(0,r.jsx)(_.Z,{children:(0,r.jsxs)("div",{className:"bg-white rounded-lg",children:[(0,r.jsx)(k.Z.Item,{label:"Custom Pricing",name:"custom_pricing",valuePropName:"checked",className:"mb-4",children:(0,r.jsx)(eb.Z,{onChange:e=>{i(e),e||t.setFieldsValue({input_cost_per_token:void 0,output_cost_per_token:void 0,input_cost_per_second:void 0})},className:"bg-gray-600"})}),a&&(0,r.jsxs)("div",{className:"ml-6 pl-4 border-l-2 border-gray-200",children:[(0,r.jsx)(k.Z.Item,{label:"Pricing Model",name:"pricing_model",className:"mb-4",children:(0,r.jsx)(S.default,{defaultValue:"per_token",onChange:e=>d(e),options:[{value:"per_token",label:"Per Million Tokens"},{value:"per_second",label:"Per Second"}]})}),"per_token"===o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",rules:[{validator:c}],className:"mb-4",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",rules:[{validator:c}],className:"mb-4",children:(0,r.jsx)(f.Z,{})})]}):(0,r.jsx)(k.Z.Item,{label:"Cost Per Second",name:"input_cost_per_second",rules:[{validator:c}],className:"mb-4",children:(0,r.jsx)(f.Z,{})})]}),(0,r.jsx)(k.Z.Item,{label:"Use in pass through routes",name:"use_in_pass_through",valuePropName:"checked",className:"mb-4 mt-4",tooltip:(0,r.jsxs)("span",{children:["Allow using these credentials in pass through routes."," ",(0,r.jsx)(ev,{href:"https://docs.litellm.ai/docs/pass_through/vertex_ai",target:"_blank",children:"Learn more"})]}),children:(0,r.jsx)(eb.Z,{onChange:e=>{let l=t.getFieldValue("litellm_extra_params");try{let s=l?JSON.parse(l):{};e?s.use_in_pass_through=!0:delete s.use_in_pass_through,Object.keys(s).length>0?t.setFieldValue("litellm_extra_params",JSON.stringify(s,null,2)):t.setFieldValue("litellm_extra_params","")}catch(l){e?t.setFieldValue("litellm_extra_params",JSON.stringify({use_in_pass_through:!0},null,2)):t.setFieldValue("litellm_extra_params","")}},className:"bg-gray-600"})}),(0,r.jsx)(k.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:m}],children:(0,r.jsx)(et.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(eh.Z,{className:"mb-4",children:[(0,r.jsx)(ex.Z,{span:10}),(0,r.jsx)(ex.Z,{span:10,children:(0,r.jsxs)(b.Z,{className:"text-gray-600 text-sm",children:["Pass JSON of litellm supported params"," ",(0,r.jsx)(ev,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]}),(0,r.jsx)(k.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:m}],children:(0,r.jsx)(et.Z,{rows:4,placeholder:'{ "mode": "chat" }'})})]})})]})})},eS=s(18502),ek=s(3632);let{Link:eN}=ec.default;var eC=e=>{let{selectedProvider:l,uploadProps:s}=e;console.log("Selected provider: ".concat(l)),console.log("type of selectedProvider: ".concat(typeof l));let t=a[l];return console.log("selectedProviderEnum: ".concat(t)),console.log("type of selectedProviderEnum: ".concat(typeof t)),(0,r.jsxs)(r.Fragment,{children:[t===a.OpenAI&&(0,r.jsx)(k.Z.Item,{label:"Organization ID",name:"organization",children:(0,r.jsx)(f.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),t===a.Vertex_AI&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(f.Z,{placeholder:"adroit-cadet-1234.."})}),(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(f.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eS.Z,{...s,children:(0,r.jsx)(E.ZP,{icon:(0,r.jsx)(ek.Z,{}),children:"Click to Upload"})})}),(0,r.jsxs)(eh.Z,{children:[(0,r.jsx)(ex.Z,{span:10}),(0,r.jsx)(ex.Z,{span:10,children:(0,r.jsx)(b.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]})]}),(t===a.Azure||t===a.OpenAI_Compatible)&&(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(f.Z,{placeholder:"https://..."})}),t===a.Azure&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"API Version",name:"api_version",tooltip:"By default litellm will use the latest version. If you want to use a different version, you can specify it here",children:(0,r.jsx)(f.Z,{placeholder:"2023-07-01-preview"})}),(0,r.jsxs)("div",{children:[(0,r.jsx)(k.Z.Item,{label:"Base Model",name:"base_model",className:"mb-0",children:(0,r.jsx)(f.Z,{placeholder:"azure/gpt-3.5-turbo"})}),(0,r.jsxs)(eh.Z,{children:[(0,r.jsx)(ex.Z,{span:10}),(0,r.jsx)(ex.Z,{span:10,children:(0,r.jsxs)(b.Z,{className:"mb-2",children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from"," ",(0,r.jsx)(eN,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})})]})]})]}),t===a.Bedrock&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Access Key ID",name:"aws_access_key_id",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Secret Access Key",name:"aws_secret_access_key",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Region Name",name:"aws_region_name",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)(f.Z,{placeholder:"us-east-1"})})]}),t!=a.Bedrock&&t!=a.Vertex_AI&&t!=a.Ollama&&(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",tooltip:"LLM API Credentials",children:(0,r.jsx)(f.Z,{placeholder:"sk-",type:"password"})})]})};let eI=async(e,l,s)=>{try{if(console.log("handling submit for formValues:",e),e.model&&e.model.includes("all-wildcard")){let l=ej[e.custom_llm_provider]+"/*";e.model_name=l,e.model=l}let t=Array.isArray(e.model)?e.model:[e.model];console.log("received deployments: ".concat(t)),console.log("received type of deployments: ".concat(typeof t)),t.forEach(async s=>{console.log("litellm_model: ".concat(s));let t={},a={};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),t.model=s;let r="";for(let[l,s]of(console.log("formValues add deployment:",e),Object.entries(e)))if(""!==s&&"custom_pricing"!==l&&"pricing_model"!==l){if("model_name"==l)r+=s;else if("custom_llm_provider"==l){console.log("custom_llm_provider:",s);let e=ej[s];t.custom_llm_provider=e,console.log("custom_llm_provider mappingResult:",e)}else if("model"==l)continue;else if("base_model"===l)a[l]=s;else if("custom_model_name"===l)t.model=s;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",s);let e={};if(s&&void 0!=s){try{e=JSON.parse(s)}catch(e){throw N.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else if("model_info_params"==l){console.log("model_info_params:",s);let e={};if(s&&void 0!=s){try{e=JSON.parse(s)}catch(e){throw N.ZP.error("Failed to parse LiteLLM Extra Params: "+e,10),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))a[l]=s}}else if("input_cost_per_token"===l||"output_cost_per_token"===l||"input_cost_per_second"===l){s&&(t[l]=Number(s));continue}else t[l]=s}let n={model_name:r,litellm_params:t,model_info:a},i=await (0,x.kK)(l,n);console.log("response for model create call: ".concat(i.data))}),s.resetFields()}catch(e){N.ZP.error("Failed to create model: "+e,10)}};var eA=e=>{let{visible:l,onCancel:s,model:t,onSubmit:a}=e,[n]=k.Z.useForm(),i={},o="",d="";if(t){var c,m;i={...t.litellm_params,input_cost_per_token:(null===(c=t.litellm_params)||void 0===c?void 0:c.input_cost_per_token)?1e6*t.litellm_params.input_cost_per_token:void 0,output_cost_per_token:(null===(m=t.litellm_params)||void 0===m?void 0:m.output_cost_per_token)?1e6*t.litellm_params.output_cost_per_token:void 0},o=t.model_name;let e=t.model_info;e&&(d=e.id,console.log("model_id: ".concat(d)),i.model_id=d)}return(0,r.jsx)(C.Z,{title:"Edit Model "+o,visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a({...e,input_cost_per_token:e.input_cost_per_token?Number(e.input_cost_per_token)/1e6:void 0,output_cost_per_token:e.output_cost_per_token?Number(e.output_cost_per_token)/1e6:void 0}),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:s,children:(0,r.jsxs)(k.Z,{form:n,onFinish:a,initialValues:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Input Cost (per 1M tokens)",name:"input_cost_per_token",tooltip:"float (optional) - Input cost per 1 million tokens",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"Output Cost (per 1M tokens)",name:"output_cost_per_token",tooltip:"float (optional) - Output cost per 1 million tokens",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"organization",name:"organization",tooltip:"OpenAI Organization ID",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)(k.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)(k.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)(k.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)(k.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)(k.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Save"})})]})})},eP=s(53003),eE=s(12485),eT=s(18135),eO=s(35242),eD=s(29706),eM=s(77991),eF=s(75105),eR=s(40278),eL=s(14301),eU=s(2356),ez=e=>{let{modelID:l,accessToken:s}=e,[t,a]=(0,n.useState)(!1),i=async()=>{try{N.ZP.info("Making API Call"),a(!0);let e=await (0,x.Og)(s,l);console.log("model delete Response:",e),N.ZP.success("Model ".concat(l," deleted successfully")),a(!1)}catch(e){console.error("Error deleting the model:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.Z,{onClick:()=>a(!0),icon:K.Z,size:"sm"}),(0,r.jsx)(C.Z,{open:t,onOk:i,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(v.Z,{children:"Delete Model"}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsx)("p",{children:"Are you sure you want to delete this model? This action is irreversible."})}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eV=s(94789),eB=s(59664),eq=e=>{let{modelMetrics:l,modelMetricsCategories:s,customTooltip:t,premiumUser:a}=e;return a?(0,r.jsx)(eB.Z,{title:"Time to First token (s)",className:"h-72",data:l,index:"date",showLegend:!1,categories:s,colors:["indigo","rose"],connectNulls:!0,customTooltip:t}):(0,r.jsxs)("div",{children:[(0,r.jsx)(eV.Z,{title:"✨ Enterprise Feature",color:"teal",className:"mt-2 mb-4",children:"Enterprise features are available for users with a specific license, please contact LiteLLM to unlock this limitation."}),(0,r.jsx)(g.Z,{variant:"primary",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get in touch"})})]})},eK=s(17906);let{Title:eW,Link:eH}=ec.default,eY={"BadRequestError (400)":"BadRequestErrorRetries","AuthenticationError (401)":"AuthenticationErrorRetries","TimeoutError (408)":"TimeoutErrorRetries","RateLimitError (429)":"RateLimitErrorRetries","ContentPolicyViolationError (400)":"ContentPolicyViolationErrorRetries","InternalServerError (500)":"InternalServerErrorRetries"};var eG=e=>{let{accessToken:l,token:s,userRole:t,userID:i,modelData:o={data:[]},keys:d,setModelData:c,premiumUser:m}=e,[u,h]=(0,n.useState)([]),[p]=k.Z.useForm(),[f,Z]=(0,n.useState)(null),[_,y]=(0,n.useState)(""),[w,I]=(0,n.useState)([]);Object.values(a).filter(e=>isNaN(Number(e)));let[P,T]=(0,n.useState)([]),[O,D]=(0,n.useState)(a.OpenAI),[M,R]=(0,n.useState)(""),[L,U]=(0,n.useState)(!1),[z,K]=(0,n.useState)(!1),[et,ea]=(0,n.useState)(null),[er,en]=(0,n.useState)([]),[ei,eo]=(0,n.useState)([]),[ed,em]=(0,n.useState)(null),[eh,eb]=(0,n.useState)([]),[ev,eS]=(0,n.useState)([]),[ek,eN]=(0,n.useState)([]),[eV,eB]=(0,n.useState)([]),[eH,eG]=(0,n.useState)([]),[eJ,eX]=(0,n.useState)([]),[e$,eQ]=(0,n.useState)([]),[e0,e1]=(0,n.useState)([]),[e2,e4]=(0,n.useState)([]),[e5,e8]=(0,n.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[e3,e6]=(0,n.useState)(null),[e7,e9]=(0,n.useState)(0),[le,ll]=(0,n.useState)({}),[ls,lt]=(0,n.useState)([]),[la,lr]=(0,n.useState)(!1),[ln,li]=(0,n.useState)(null),[lo,ld]=(0,n.useState)(null),[lc,lm]=(0,n.useState)([]),[lu,lh]=(0,n.useState)(!1),lx=e=>{let l=e_(e,f);I(l),console.log("providerModels: ".concat(l))},lp=async(e,s,a)=>{if(console.log("Updating model metrics for group:",e),!l||!i||!t||!s||!a)return;console.log("inside updateModelMetrics - startTime:",s,"endTime:",a),em(e);let r=null==ln?void 0:ln.token;void 0===r&&(r=null);let n=lo;void 0===n&&(n=null),s.setHours(0),s.setMinutes(0),s.setSeconds(0),a.setHours(23),a.setMinutes(59),a.setSeconds(59);try{let o=await (0,x.o6)(l,i,t,e,s.toISOString(),a.toISOString(),r,n);console.log("Model metrics response:",o),eS(o.data),eN(o.all_api_bases);let d=await (0,x.Rg)(l,e,s.toISOString(),a.toISOString());eB(d.data),eG(d.all_api_bases);let c=await (0,x.N8)(l,i,t,e,s.toISOString(),a.toISOString(),r,n);console.log("Model exceptions response:",c),eX(c.data),eQ(c.exception_types);let m=await (0,x.fP)(l,i,t,e,s.toISOString(),a.toISOString(),r,n);if(console.log("slowResponses:",m),e4(m),e){let t=await (0,x.n$)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);ll(t);let r=await (0,x.v9)(l,null==s?void 0:s.toISOString().split("T")[0],null==a?void 0:a.toISOString().split("T")[0],e);lt(r)}}catch(e){console.error("Failed to fetch model metrics",e)}};(0,n.useEffect)(()=>{lp(ed,e5.from,e5.to)},[ln,lo]);let lj=e=>{ea(e),U(!0)},lg=e=>{ea(e),K(!0)},lf=async e=>{if(console.log("handleEditSubmit:",e),null==l)return;let s={},t=null;for(let[l,a]of(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),Object.entries(e)))"model_id"!==l?s[l]=a:t=a;let a={litellm_params:s,model_info:{id:t}};console.log("handleEditSubmit payload:",a);try{await (0,x.um)(l,a),N.ZP.success("Model updated successfully, restart server to see updates"),U(!1),ea(null)}catch(e){console.log("Error occurred")}},lZ=()=>{y(new Date().toLocaleString())},l_=async()=>{if(!l){console.error("Access token is missing");return}console.log("new modelGroupRetryPolicy:",e3);try{await (0,x.K_)(l,{router_settings:{model_group_retry_policy:e3}}),N.ZP.success("Retry settings saved successfully")}catch(e){console.error("Failed to save retry settings:",e),N.ZP.error("Failed to save retry settings")}};if((0,n.useEffect)(()=>{if(!l||!s||!t||!i)return;let e=async()=>{try{var e,s,a,r,n,o,d,m,u,h,p,j;let g=await (0,x.hy)(l);T(g);let f=await (0,x.AZ)(l,i,t);console.log("Model data response:",f.data),c(f);let Z=new Set;for(let e=0;e<f.data.length;e++){let l=f.data[e];Z.add(l.model_name)}console.log("all_model_groups:",Z);let _=Array.from(Z);_=_.sort(),en(_),console.log("array_model_groups:",_);let y="all";_.length>0&&(y=_[_.length-1],console.log("_initial_model_group:",y)),console.log("selectedModelGroup:",ed);let b=await (0,x.o6)(l,i,t,y,null===(e=e5.from)||void 0===e?void 0:e.toISOString(),null===(s=e5.to)||void 0===s?void 0:s.toISOString(),null==ln?void 0:ln.token,lo);console.log("Model metrics response:",b),eS(b.data),eN(b.all_api_bases);let v=await (0,x.Rg)(l,y,null===(a=e5.from)||void 0===a?void 0:a.toISOString(),null===(r=e5.to)||void 0===r?void 0:r.toISOString());eB(v.data),eG(v.all_api_bases);let w=await (0,x.N8)(l,i,t,y,null===(n=e5.from)||void 0===n?void 0:n.toISOString(),null===(o=e5.to)||void 0===o?void 0:o.toISOString(),null==ln?void 0:ln.token,lo);console.log("Model exceptions response:",w),eX(w.data),eQ(w.exception_types);let S=await (0,x.fP)(l,i,t,y,null===(d=e5.from)||void 0===d?void 0:d.toISOString(),null===(m=e5.to)||void 0===m?void 0:m.toISOString(),null==ln?void 0:ln.token,lo),k=await (0,x.n$)(l,null===(u=e5.from)||void 0===u?void 0:u.toISOString().split("T")[0],null===(h=e5.to)||void 0===h?void 0:h.toISOString().split("T")[0],y);ll(k);let N=await (0,x.v9)(l,null===(p=e5.from)||void 0===p?void 0:p.toISOString().split("T")[0],null===(j=e5.to)||void 0===j?void 0:j.toISOString().split("T")[0],y);lt(N),console.log("dailyExceptions:",k),console.log("dailyExceptionsPerDeplyment:",N),console.log("slowResponses:",S),e4(S);let C=await (0,x.j2)(l);lm(null==C?void 0:C.end_users);let I=(await (0,x.BL)(l,i,t)).router_settings;console.log("routerSettingsInfo:",I);let A=I.model_group_retry_policy,P=I.num_retries;console.log("model_group_retry_policy:",A),console.log("default_retries:",P),e6(A),e9(P)}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&t&&i&&e();let a=async()=>{let e=await (0,x.qm)(l);console.log("received model cost map data: ".concat(Object.keys(e))),Z(e)};null==f&&a(),lZ()},[l,s,t,i,f,_]),!o||!l||!s||!t||!i)return(0,r.jsx)("div",{children:"Loading..."});let ly=[],lb=[];for(let e=0;e<o.data.length;e++){var lv,lw,lS;let l=o.data[e],s=null==l?void 0:null===(lv=l.litellm_params)||void 0===lv?void 0:lv.model,t=null==l?void 0:null===(lw=l.litellm_params)||void 0===lw?void 0:lw.custom_llm_provider,a=null==l?void 0:l.model_info,r="",n="Undefined",i="Undefined",d="Undefined",c="Undefined",m={},u=e=>(console.log("GET PROVIDER CALLED! - ".concat(f)),null!=f&&"object"==typeof f&&e in f)?f[e].litellm_provider:"openai";if(s){let e=s.split("/"),l=e[0];(r=t)||(r=1===e.length?u(s):l)}else r="-";a&&(n=null==a?void 0:a.input_cost_per_token,i=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==l?void 0:l.litellm_params)&&(m=Object.fromEntries(Object.entries(null==l?void 0:l.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),o.data[e].provider=r,o.data[e].input_cost=n,o.data[e].output_cost=i,o.data[e].litellm_model_name=s,lb.push(r),o.data[e].input_cost&&(o.data[e].input_cost=(1e6*Number(o.data[e].input_cost)).toFixed(2)),o.data[e].output_cost&&(o.data[e].output_cost=(1e6*Number(o.data[e].output_cost)).toFixed(2)),o.data[e].max_tokens=d,o.data[e].max_input_tokens=c,o.data[e].api_base=null==l?void 0:null===(lS=l.litellm_params)||void 0===lS?void 0:lS.api_base,o.data[e].cleanedLitellmParams=m,ly.push(l.model_name),console.log(o.data[e])}if(o.data&&o.data.length>0&&o.data.sort((e,l)=>e.provider&&l.provider?e.provider.localeCompare(l.provider):e.provider&&!l.provider?-1:!e.provider&&l.provider?1:0),t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=ec.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to view all models"})]})}let lk=async()=>{try{N.ZP.info("Running health check..."),R("");let e=await (0,x.EY)(l);R(e)}catch(e){console.error("Error running health check:",e),R("Error running health check")}},lN=(0,r.jsxs)("div",{children:[(0,r.jsx)(b.Z,{className:"mb-1",children:"Select API Key Name"}),m?(0,r.jsxs)("div",{children:[(0,r.jsxs)(el.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(es.Z,{value:"all-keys",onClick:()=>{li(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(es.Z,{value:String(l),onClick:()=>{li(e)},children:e.key_alias},l):null)]}),(0,r.jsx)(b.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(el.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(es.Z,{value:"all-customers",onClick:()=>{ld(null)},children:"All Customers"},"all-customers"),null==lc?void 0:lc.map((e,l)=>(0,r.jsx)(es.Z,{value:e,onClick:()=>{ld(e)},children:e},l))]})]}):(0,r.jsxs)("div",{children:[(0,r.jsxs)(el.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(es.Z,{value:"all-keys",onClick:()=>{li(null)},children:"All Keys"},"all-keys"),null==d?void 0:d.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsxs)(es.Z,{value:String(l),disabled:!0,onClick:()=>{li(e)},children:["✨ ",e.key_alias," (Enterprise only Feature)"]},l):null)]}),(0,r.jsx)(b.Z,{className:"mt-1",children:"Select Customer Name"}),(0,r.jsxs)(el.Z,{defaultValue:"all-customers",children:[(0,r.jsx)(es.Z,{value:"all-customers",onClick:()=>{ld(null)},children:"All Customers"},"all-customers"),null==lc?void 0:lc.map((e,l)=>(0,r.jsxs)(es.Z,{value:e,disabled:!0,onClick:()=>{ld(e)},children:["✨ ",e," (Enterprise only Feature)"]},l))]})]})]}),lC=e=>{var l,s;let{payload:t,active:a}=e;if(!a||!t)return null;let n=null===(s=t[0])||void 0===s?void 0:null===(l=s.payload)||void 0===l?void 0:l.date,i=t.sort((e,l)=>l.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,l)=>e+l.value,0),color:"gray"})}return(0,r.jsxs)("div",{className:"w-150 rounded-tremor-default border border-tremor-border bg-tremor-background p-2 text-tremor-default shadow-tremor-dropdown",children:[n&&(0,r.jsxs)("p",{className:"text-tremor-content-emphasis mb-2",children:["Date: ",n]}),i.map((e,l)=>{let s=parseFloat(e.value.toFixed(5)),t=0===s&&e.value>0?"<0.00001":s.toFixed(5);return(0,r.jsxs)("div",{className:"flex justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("div",{className:"w-2 h-2 mt-1 rounded-full bg-".concat(e.color,"-500")}),(0,r.jsx)("p",{className:"text-tremor-content",children:e.dataKey})]}),(0,r.jsx)("p",{className:"font-medium text-tremor-content-emphasis text-righ ml-2",children:t})]},l)})]})};console.log("selectedProvider: ".concat(O)),console.log("providerModels.length: ".concat(w.length));let lI=Object.keys(a).find(e=>a[e]===O);return lI&&P.find(e=>e.name===ej[lI]),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eT.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eO.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eE.Z,{children:"All Models"}),(0,r.jsx)(eE.Z,{children:"Add Model"}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})}),(0,r.jsx)(eE.Z,{children:"Model Analytics"}),(0,r.jsx)(eE.Z,{children:"Model Retry Settings"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[_&&(0,r.jsxs)(b.Z,{children:["Last Refreshed: ",_]}),(0,r.jsx)(Y.Z,{icon:q.Z,variant:"shadow",size:"xs",className:"self-center",onClick:lZ})]})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(j.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(b.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(el.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:ed||void 0,onValueChange:e=>em("all"===e?"all":e),value:ed||void 0,children:[(0,r.jsx)(es.Z,{value:"all",children:"All Models"}),er.map((e,l)=>(0,r.jsx)(es.Z,{value:e,onClick:()=>em(e),children:e},l))]})]}),(0,r.jsx)(H.Z,{children:(0,r.jsxs)(G.Z,{style:{maxWidth:"1500px",width:"100%"},children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:"Public Model Name"}),(0,r.jsx)(Q.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:"Provider"}),(0,r.jsx)(Q.Z,{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:"LiteLLM Model"}),"Admin"===t&&(0,r.jsx)(Q.Z,{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:"API Base"}),(0,r.jsxs)(Q.Z,{style:{maxWidth:"85px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:["Input Price"," ",(0,r.jsx)("p",{style:{fontSize:"10px",color:"gray"},children:"/1M Tokens ($)"})]}),(0,r.jsxs)(Q.Z,{style:{maxWidth:"85px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:["Output Price"," ",(0,r.jsx)("p",{style:{fontSize:"10px",color:"gray"},children:"/1M Tokens ($)"})]}),(0,r.jsx)(Q.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:m?"Created At":(0,r.jsxs)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",style:{color:"#72bcd4"},children:[" ","✨ Created At"]})}),(0,r.jsx)(Q.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:m?"Created By":(0,r.jsxs)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",style:{color:"#72bcd4"},children:[" ","✨ Created By"]})}),(0,r.jsx)(Q.Z,{style:{maxWidth:"50px",whiteSpace:"normal",wordBreak:"break-word",fontSize:"11px"},children:"Status"}),(0,r.jsx)(Q.Z,{})]})}),(0,r.jsx)(J.Z,{children:o.data.filter(e=>"all"===ed||e.model_name===ed||null==ed||""===ed).map((e,s)=>{var a;return(0,r.jsxs)(ee.Z,{style:{maxHeight:"1px",minHeight:"1px"},children:[(0,r.jsx)(X.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsx)("p",{className:"text-xs",children:e.model_name||"-"})}),(0,r.jsx)(X.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[e.provider&&(0,r.jsx)("img",{src:ef(e.provider).logo,alt:"".concat(e.provider," logo"),className:"w-4 h-4",onError:l=>{let s=l.target,t=s.parentElement;if(t){var a;let l=document.createElement("div");l.className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs",l.textContent=(null===(a=e.provider)||void 0===a?void 0:a.charAt(0))||"-",t.replaceChild(l,s)}}}),(0,r.jsx)("p",{className:"text-xs",children:e.provider||"-"})]})}),(0,r.jsx)(X.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsx)(F.Z,{title:e&&e.litellm_model_name,children:(0,r.jsx)("pre",{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word"},className:"text-xs",title:e&&e.litellm_model_name?e.litellm_model_name:"",children:e&&e.litellm_model_name?e.litellm_model_name.slice(0,20)+(e.litellm_model_name.length>20?"...":""):"-"})})}),"Admin"===t&&(0,r.jsx)(X.Z,{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsx)(F.Z,{title:e&&e.api_base,children:(0,r.jsx)("pre",{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word"},className:"text-xs",title:e&&e.api_base?e.api_base:"",children:e&&e.api_base?e.api_base.slice(0,20):"-"})})}),(0,r.jsx)(X.Z,{style:{maxWidth:"80px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsx)("pre",{className:"text-xs",children:e.input_cost?e.input_cost:null!=e.litellm_params.input_cost_per_token&&void 0!=e.litellm_params.input_cost_per_token?(1e6*Number(e.litellm_params.input_cost_per_token)).toFixed(2):null})}),(0,r.jsx)(X.Z,{style:{maxWidth:"80px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsx)("pre",{className:"text-xs",children:e.output_cost?e.output_cost:e.litellm_params.output_cost_per_token?(1e6*Number(e.litellm_params.output_cost_per_token)).toFixed(2):null})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)("p",{className:"text-xs",children:m&&((a=e.model_info.created_at)?new Date(a).toLocaleDateString("en-US"):null)||"-"})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)("p",{className:"text-xs",children:m&&e.model_info.created_by||"-"})}),(0,r.jsx)(X.Z,{style:{maxWidth:"100px",whiteSpace:"normal",wordBreak:"break-word"},children:e.model_info.db_model?(0,r.jsx)(W.Z,{size:"xs",className:"text-white",children:(0,r.jsx)("p",{className:"text-xs",children:"DB Model"})}):(0,r.jsx)(W.Z,{size:"xs",className:"text-black",children:(0,r.jsx)("p",{className:"text-xs",children:"Config Model"})})}),(0,r.jsx)(X.Z,{style:{maxWidth:"150px",whiteSpace:"normal",wordBreak:"break-word"},children:(0,r.jsxs)(j.Z,{numItems:3,children:[(0,r.jsx)(ex.Z,{children:(0,r.jsx)(Y.Z,{icon:V.Z,size:"sm",onClick:()=>lg(e)})}),(0,r.jsx)(ex.Z,{children:(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>lj(e)})}),(0,r.jsx)(ex.Z,{children:(0,r.jsx)(ez,{modelID:e.model_info.id,accessToken:l})})]})})]},s)})})]})})]}),(0,r.jsx)(eA,{visible:L,onCancel:()=>{U(!1),ea(null)},model:et,onSubmit:lf}),(0,r.jsxs)(C.Z,{title:et&&et.model_name,visible:z,width:800,footer:null,onCancel:()=>{K(!1),ea(null)},children:[(0,r.jsx)(v.Z,{children:"Model Info"}),(0,r.jsx)(eK.Z,{language:"json",children:et&&JSON.stringify(et,null,2)})]})]}),(0,r.jsxs)(eD.Z,{className:"h-full",children:[(0,r.jsx)(eW,{level:2,children:"Add new model"}),(0,r.jsx)(H.Z,{children:(0,r.jsx)(k.Z,{form:p,onFinish:()=>{p.validateFields().then(e=>{eI(e,l,p)}).catch(e=>{console.error("Validation failed:",e)})},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.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,r.jsx)(S.default,{showSearch:!0,value:O,onChange:e=>{D(e),lx(e),p.setFieldsValue({model:[],model_name:void 0})},children:Object.entries(a).map(e=>{let[l,s]=e;return(0,r.jsx)(S.default.Option,{value:l,children:(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)("img",{src:eg[s],alt:"".concat(l," logo"),className:"w-5 h-5",onError:e=>{let l=e.target,t=l.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=s.charAt(0),t.replaceChild(e,l)}}}),(0,r.jsx)("span",{children:s})]})},l)})})}),(0,r.jsx)(ey,{selectedProvider:O,providerModels:w,getPlaceholder:eZ}),(0,r.jsx)(ep,{}),(0,r.jsx)(eC,{selectedProvider:O,uploadProps:{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;p.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?N.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&N.ZP.error("".concat(e.file.name," file upload failed."))}}}),(0,r.jsx)(ew,{showAdvancedSettings:lu,setShowAdvancedSettings:lh}),(0,r.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,r.jsx)(F.Z,{title:"Get help on our github",children:(0,r.jsx)(ec.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})}),(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Add Model"})]})]})})})]}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(b.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(g.Z,{onClick:lk,children:"Run `/health`"}),M&&(0,r.jsx)("pre",{children:JSON.stringify(M,null,2)})]})}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(j.Z,{numItems:4,className:"mt-2 mb-2",children:[(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(b.Z,{children:"Select Time Range"}),(0,r.jsx)(eP.Z,{enableSelect:!0,value:e5,className:"mr-2",onValueChange:e=>{e8(e),lp(ed,e.from,e.to)}})]}),(0,r.jsxs)(ex.Z,{className:"ml-2",children:[(0,r.jsx)(b.Z,{children:"Select Model Group"}),(0,r.jsx)(el.Z,{defaultValue:ed||er[0],value:ed||er[0],children:er.map((e,l)=>(0,r.jsx)(es.Z,{value:e,onClick:()=>lp(e,e5.from,e5.to),children:e},l))})]}),(0,r.jsx)(ex.Z,{children:(0,r.jsx)(eL.Z,{trigger:"click",content:lN,overlayStyle:{width:"20vw"},children:(0,r.jsx)(g.Z,{icon:eU.Z,size:"md",variant:"secondary",className:"mt-4 ml-2",style:{border:"none"},onClick:()=>lr(!0)})})})]}),(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsx)(ex.Z,{children:(0,r.jsx)(H.Z,{className:"mr-2 max-h-[400px] min-h-[400px]",children:(0,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Avg. Latency per Token"}),(0,r.jsx)(eE.Z,{value:"2",children:"✨ Time to first token"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(eD.Z,{children:[(0,r.jsx)("p",{className:"text-gray-500 italic",children:" (seconds/token)"}),(0,r.jsx)(b.Z,{className:"text-gray-500 italic mt-1 mb-1",children:"average Latency for successfull requests divided by the total tokens"}),ev&&ek&&(0,r.jsx)(eF.Z,{title:"Model Latency",className:"h-72",data:ev,showLegend:!1,index:"date",categories:ek,connectNulls:!0,customTooltip:lC})]}),(0,r.jsx)(eD.Z,{children:(0,r.jsx)(eq,{modelMetrics:eV,modelMetricsCategories:eH,customTooltip:lC,premiumUser:m})})]})]})})}),(0,r.jsx)(ex.Z,{children:(0,r.jsx)(H.Z,{className:"ml-2 max-h-[400px] min-h-[400px] overflow-y-auto",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Deployment"}),(0,r.jsx)(Q.Z,{children:"Success Responses"}),(0,r.jsxs)(Q.Z,{children:["Slow Responses ",(0,r.jsx)("p",{children:"Success Responses taking 600+s"})]})]})}),(0,r.jsx)(J.Z,{children:e2.map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.api_base}),(0,r.jsx)(X.Z,{children:e.total_count}),(0,r.jsx)(X.Z,{children:e.slow_count})]},l))})]})})})]}),(0,r.jsx)(j.Z,{numItems:1,className:"gap-2 w-full mt-2",children:(0,r.jsxs)(H.Z,{children:[(0,r.jsxs)(v.Z,{children:["All Exceptions for ",ed]}),(0,r.jsx)(eR.Z,{className:"h-60",data:eJ,index:"model",categories:e$,stack:!0,yAxisWidth:30})]})}),(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 w-full mt-2",children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsxs)(v.Z,{children:["All Up Rate Limit Errors (429) for ",ed]}),(0,r.jsxs)(j.Z,{numItems:1,children:[(0,r.jsxs)(ex.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",le.sum_num_rate_limit_exceptions]}),(0,r.jsx)(eR.Z,{className:"h-40",data:le.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]}),(0,r.jsx)(ex.Z,{})]})]}),m?(0,r.jsx)(r.Fragment,{children:ls.map((e,l)=>(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:e.api_base?e.api_base:"Unknown API Base"}),(0,r.jsx)(j.Z,{numItems:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors (429) ",e.sum_num_rate_limit_exceptions]}),(0,r.jsx)(eR.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]},l))}):(0,r.jsx)(r.Fragment,{children:ls&&ls.length>0&&ls.slice(0,1).map((e,l)=>(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"✨ Rate Limit Errors by Deployment"}),(0,r.jsx)("p",{className:"mb-2 text-gray-500 italic text-[12px]",children:"Upgrade to see exceptions for all deployments"}),(0,r.jsx)(g.Z,{variant:"primary",className:"mb-2",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"Get Free Trial"})}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:e.api_base}),(0,r.jsx)(j.Z,{numItems:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Num Rate Limit Errors ",e.sum_num_rate_limit_exceptions]}),(0,r.jsx)(eR.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["rose"],categories:["num_rate_limit_exceptions"],onValueChange:e=>console.log(e)})]})})]})]},l))})]})]}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(b.Z,{children:"Filter by Public Model Name"}),(0,r.jsx)(el.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:ed||er[0],value:ed||er[0],onValueChange:e=>em(e),children:er.map((e,l)=>(0,r.jsx)(es.Z,{value:e,onClick:()=>em(e),children:e},l))})]}),(0,r.jsxs)(v.Z,{children:["Retry Policy for ",ed]}),(0,r.jsx)(b.Z,{className:"mb-6",children:"How many retries should be attempted based on the Exception"}),eY&&(0,r.jsx)("table",{children:(0,r.jsx)("tbody",{children:Object.entries(eY).map((e,l)=>{var s;let[t,a]=e,n=null==e3?void 0:null===(s=e3[ed])||void 0===s?void 0:s[a];return null==n&&(n=e7),(0,r.jsxs)("tr",{className:"flex justify-between items-center mt-2",children:[(0,r.jsx)("td",{children:(0,r.jsx)(b.Z,{children:t})}),(0,r.jsx)("td",{children:(0,r.jsx)(A.Z,{className:"ml-5",value:n,min:0,step:1,onChange:e=>{e6(l=>{var s;let t=null!==(s=null==l?void 0:l[ed])&&void 0!==s?s:{};return{...null!=l?l:{},[ed]:{...t,[a]:e}}})}})})]},l)})})}),(0,r.jsx)(g.Z,{className:"mt-6 mr-8",onClick:l_,children:"Save"})]})]})]})})};function eJ(e){let{isInvitationLinkModalVisible:l,setIsInvitationLinkModalVisible:s,baseUrl:t,invitationLinkData:a}=e,{Title:n,Paragraph:i}=ec.default,o=()=>(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,r.jsxs)(C.Z,{title:"Invitation Link",visible:l,width:800,footer:null,onOk:()=>{s(!1)},onCancel:()=>{s(!1)},children:[(0,r.jsx)(i,{children:"Copy and send the generated link to onboard this user to the proxy."}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(b.Z,{className:"text-base",children:"User ID"}),(0,r.jsx)(b.Z,{children:null==a?void 0:a.user_id})]}),(0,r.jsxs)("div",{className:"flex justify-between pt-5 pb-2",children:[(0,r.jsx)(b.Z,{children:"Invitation Link"}),(0,r.jsx)(b.Z,{children:(0,r.jsx)(b.Z,{children:o()})})]}),(0,r.jsx)("div",{className:"flex justify-end mt-5",children:(0,r.jsx)(w.CopyToClipboard,{text:o(),onCopy:()=>N.ZP.success("Copied!"),children:(0,r.jsx)(g.Z,{variant:"primary",children:"Copy invitation link"})})})]})}let{Option:eX}=S.default;var e$=e=>{let{userID:l,accessToken:s,teams:t,possibleUIRoles:a}=e,[o,d]=(0,n.useState)(null),[c]=k.Z.useForm(),[m,u]=(0,n.useState)(!1),[h,p]=(0,n.useState)(null),[j,Z]=(0,n.useState)([]),[_,y]=(0,n.useState)(!1),[v,w]=(0,n.useState)(null),I=(0,i.useRouter)(),[A,T]=(0,n.useState)("http://localhost:4000");(0,n.useEffect)(()=>{(async()=>{try{let e=await (0,x.So)(s,l,"any"),t=[];for(let l=0;l<e.data.length;l++){let s=e.data[l];t.push(s.id)}console.log("Model data response:",e.data),console.log("Available models:",t),Z(t);let a=await (0,x.g)(s);console.log("uiSettingsResponse:",a),d(a)}catch(e){console.error("Error fetching model data:",e)}})()},[]),(0,n.useEffect)(()=>{I&&T(new URL("/",window.location.href).toString())},[I]);let O=async e=>{try{var t;N.ZP.info("Making API Call"),u(!0),console.log("formValues in create user:",e);let a=await (0,x.Ov)(s,null,e);console.log("user create Response:",a),p(a.key);let r=(null===(t=a.data)||void 0===t?void 0:t.user_id)||a.user_id;if(null==o?void 0:o.SSO_ENABLED){let e={id:crypto.randomUUID(),user_id:r,is_accepted:!1,accepted_at:null,expires_at:new Date(Date.now()+6048e5),created_at:new Date,created_by:l,updated_at:new Date,updated_by:l,has_user_setup_sso:!0};w(e),y(!0)}else(0,x.XO)(s,r).then(e=>{e.has_user_setup_sso=!1,w(e),y(!0)});N.ZP.success("API user Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(g.Z,{className:"mx-auto mb-0",onClick:()=>u(!0),children:"+ Invite User"}),(0,r.jsxs)(C.Z,{title:"Invite User",visible:m,width:800,footer:null,onOk:()=>{u(!1),c.resetFields()},onCancel:()=>{u(!1),p(null),c.resetFields()},children:[(0,r.jsx)(b.Z,{className:"mb-1",children:"Create a User who can own keys"}),(0,r.jsxs)(k.Z,{form:c,onFinish:O,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(k.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(S.default,{children:a&&Object.entries(a).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(es.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(k.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(S.default,{placeholder:"Select Team ID",style:{width:"100%"},children:t?t.map(e=>(0,r.jsx)(eX,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(eX,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(k.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(P.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Create User"})})]})]}),h&&(0,r.jsx)(eJ,{isInvitationLinkModalVisible:_,setIsInvitationLinkModalVisible:y,baseUrl:A,invitationLinkData:v})]})},eQ=e=>{let{visible:l,possibleUIRoles:s,onCancel:t,user:a,onSubmit:i}=e,[o,d]=(0,n.useState)(a),[c]=k.Z.useForm();(0,n.useEffect)(()=>{c.resetFields()},[a]);let m=async()=>{c.resetFields(),t()},u=async e=>{i(e),c.resetFields(),t()};return a?(0,r.jsx)(C.Z,{visible:l,onCancel:m,footer:null,title:"Edit User "+a.user_id,width:1e3,children:(0,r.jsx)(k.Z,{form:c,onFinish:u,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"User Email",tooltip:"Email of the User",name:"user_email",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"user_id",name:"user_id",hidden:!0,children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"User Role",name:"user_role",children:(0,r.jsx)(S.default,{children:s&&Object.entries(s).map(e=>{let[l,{ui_label:s,description:t}]=e;return(0,r.jsx)(es.Z,{value:l,title:s,children:(0,r.jsxs)("div",{className:"flex",children:[s," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:t})]})},l)})})}),(0,r.jsx)(k.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,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)(k.Z.Item,{label:"User Budget (USD)",name:"max_budget",tooltip:"(float) - Maximum budget of this user",help:"Ignored if the key has a team_id; team budget applies there.",children:(0,r.jsx)(A.Z,{min:0,step:1})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Save"})})]})})}):null};console.log=function(){};var e0=e=>{let{accessToken:l,token:s,keys:t,userRole:a,userID:i,teams:o,setKeys:d}=e,[c,m]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),[p,f]=(0,n.useState)(null),[Z,_]=(0,n.useState)(1),[y,b]=n.useState(null),[v,w]=(0,n.useState)(null),[S,k]=(0,n.useState)(!1),[C,I]=(0,n.useState)(null),[A,P]=(0,n.useState)(!1),[E,T]=(0,n.useState)(null),[O,D]=(0,n.useState)({});window.addEventListener("beforeunload",function(){sessionStorage.clear()});let M=e=>{T(e),P(!0)},F=async()=>{if(E&&l)try{if(await (0,x.Eb)(l,[E]),N.ZP.success("User deleted successfully"),u){let e=u.filter(e=>e.user_id!==E);h(e)}}catch(e){console.error("Error deleting user:",e),N.ZP.error("Failed to delete user")}P(!1),T(null)},R=async()=>{I(null),k(!1)},L=async e=>{if(console.log("inside handleEditSubmit:",e),l&&s&&a&&i){try{await (0,x.pf)(l,e,null),N.ZP.success("User ".concat(e.user_id," updated successfully"))}catch(e){console.error("There was an error updating the user",e)}u&&h(u.map(l=>l.user_id===e.user_id?e:l)),I(null),k(!1)}};return((0,n.useEffect)(()=>{if(!l||!s||!a||!i)return;let e=async()=>{try{let e=sessionStorage.getItem("userList_".concat(Z));if(e){let l=JSON.parse(e);m(l),h(l.users||[])}else{let e=await (0,x.Br)(l,null,a,!0,Z,25);sessionStorage.setItem("userList_".concat(Z),JSON.stringify(e)),m(e),h(e.users||[])}let s=sessionStorage.getItem("possibleUserRoles");if(s)D(JSON.parse(s));else{let e=await (0,x.lg)(l);sessionStorage.setItem("possibleUserRoles",JSON.stringify(e)),D(e)}}catch(e){console.error("There was an error fetching the model data",e)}};l&&s&&a&&i&&e()},[l,s,a,i,Z]),u&&l&&s&&a&&i)?(0,r.jsx)("div",{style:{width:"100%"},children:(0,r.jsxs)(j.Z,{className:"gap-2 p-2 h-[90vh] w-full mt-8",children:[(0,r.jsx)(e$,{userID:i,accessToken:l,teams:o,possibleUIRoles:O}),(0,r.jsxs)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[90vh] mb-4",children:[(0,r.jsx)("div",{className:"mb-4 mt-1"}),(0,r.jsx)(eT.Z,{children:(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(G.Z,{className:"mt-5",children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"User ID"}),(0,r.jsx)(Q.Z,{children:"User Email"}),(0,r.jsx)(Q.Z,{children:"Role"}),(0,r.jsx)(Q.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(Q.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(Q.Z,{children:"API Keys"}),(0,r.jsx)(Q.Z,{})]})}),(0,r.jsx)(J.Z,{children:u.map(e=>{var l,s;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.user_id||"-"}),(0,r.jsx)(X.Z,{children:e.user_email||"-"}),(0,r.jsx)(X.Z,{children:(null==O?void 0:null===(l=O[null==e?void 0:e.user_role])||void 0===l?void 0:l.ui_label)||"-"}),(0,r.jsx)(X.Z,{children:e.spend?null===(s=e.spend)||void 0===s?void 0:s.toFixed(2):"-"}),(0,r.jsx)(X.Z,{children:null!==e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(j.Z,{numItems:2,children:e.key_count>0?(0,r.jsxs)(W.Z,{size:"xs",color:"indigo",children:[e.key_count," Keys"]}):(0,r.jsx)(W.Z,{size:"xs",color:"gray",children:"No Keys"})})}),(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(Y.Z,{icon:B.Z,onClick:()=>{I(e),k(!0)},children:"View Keys"}),(0,r.jsx)(Y.Z,{icon:K.Z,onClick:()=>M(e.user_id),children:"Delete"})]})]},e.user_id)})})]})}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsx)("div",{className:"flex-1 flex justify-between items-center"})]})})]})}),(0,r.jsx)(eQ,{visible:S,possibleUIRoles:O,onCancel:R,user:C,onSubmit:L}),A&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.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,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:""}),(0,r.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,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete User"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this user?"}),(0,r.jsxs)("p",{className:"text-sm font-medium text-gray-900 mt-2",children:["User ID: ",E]})]})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(g.Z,{onClick:F,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(g.Z,{onClick:()=>{P(!1),T(null)},children:"Cancel"})]})]})]})})]}),function(){if(!u)return null;let e=(null==c?void 0:c.total_pages)||0,l=e=>{h([]),_(e)};return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",Z," of ",e]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l focus:outline-none",disabled:1===Z,onClick:()=>l(Z-1),children:"← Prev"}),(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r focus:outline-none",disabled:Z===e,onClick:()=>l(Z+1),children:"Next →"})]})]})}()]})}):(0,r.jsx)("div",{children:"Loading..."})},e1=e=>{var l,s;let{visible:t,onCancel:a,onSubmit:i,initialData:o,mode:d}=e,[c]=k.Z.useForm();(0,n.useEffect)(()=>{o&&c.setFieldsValue({user_email:o.user_email,user_id:o.user_id,role:o.role})},[o,c]);let m=async e=>{try{let l={user_email:e.user_email,user_id:e.user_id,role:e.role};i(l),c.resetFields(),N.ZP.success("Successfully ".concat("add"===d?"added":"updated"," team member"))}catch(e){N.ZP.error("Failed to submit form"),console.error("Form submission error:",e)}};return(0,r.jsx)(C.Z,{title:"add"===d?"Add Team Member":"Edit Team Member",visible:t,width:800,footer:null,onCancel:a,children:(0,r.jsxs)(k.Z,{form:c,onFinish:m,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{user_email:(null==o?void 0:null===(l=o.user_email)||void 0===l?void 0:l.trim())||"",user_id:(null==o?void 0:null===(s=o.user_id)||void 0===s?void 0:s.trim())||"",role:(null==o?void 0:o.role)||"user"},children:[(0,r.jsx)(k.Z.Item,{label:"Email",name:"user_email",className:"mb-4",rules:[{type:"email",message:"Please enter a valid email!"}],children:(0,r.jsx)(P.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full",placeholder:"[email protected]",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)("div",{className:"text-center mb-4",children:(0,r.jsx)(b.Z,{children:"OR"})}),(0,r.jsx)(k.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(P.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full",placeholder:"user_123",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(k.Z.Item,{label:"Member Role",name:"role",className:"mb-4",rules:[{required:!0,message:"Please select a role!"}],children:(0,r.jsxs)(S.default,{defaultValue:"user",children:[(0,r.jsx)(S.default.Option,{value:"admin",children:"admin"}),(0,r.jsx)(S.default.Option,{value:"user",children:"user"})]})}),(0,r.jsxs)("div",{style:{textAlign:"right",marginTop:"20px"},children:[(0,r.jsx)(E.ZP,{onClick:a,style:{marginRight:8},children:"Cancel"}),(0,r.jsx)(E.ZP,{type:"primary",htmlType:"submit",children:"add"===d?"Add Member":"Save Changes"})]})]})})},e2=s(7310),e4=s.n(e2),e5=e=>{let{isVisible:l,onCancel:s,onSubmit:t,accessToken:a}=e,[i]=k.Z.useForm(),[o,d]=(0,n.useState)([]),[c,m]=(0,n.useState)(!1),[u,h]=(0,n.useState)("user_email"),p=async(e,l)=>{if(!e){d([]);return}m(!0);try{let s=new URLSearchParams;if(s.append(l,e),null==a)return;let t=(await (0,x.u5)(a,s)).map(e=>({label:"user_email"===l?"".concat(e.user_email):"".concat(e.user_id),value:"user_email"===l?e.user_email:e.user_id,user:e}));d(t)}catch(e){console.error("Error fetching users:",e)}finally{m(!1)}},j=(0,n.useCallback)(e4()((e,l)=>p(e,l),300),[]),g=(e,l)=>{h(l),j(e,l)},f=(e,l)=>{let s=l.user;i.setFieldsValue({user_email:s.user_email,user_id:s.user_id,role:i.getFieldValue("role")})};return(0,r.jsx)(C.Z,{title:"Add Team Member",open:l,onCancel:()=>{i.resetFields(),d([]),s()},footer:null,width:800,children:(0,r.jsxs)(k.Z,{form:i,onFinish:t,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:"user"},children:[(0,r.jsx)(k.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(S.default,{showSearch:!0,className:"w-full",placeholder:"Search by email",filterOption:!1,onSearch:e=>g(e,"user_email"),onSelect:(e,l)=>f(e,l),options:"user_email"===u?o:[],loading:c,allowClear:!0})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(k.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(S.default,{showSearch:!0,className:"w-full",placeholder:"Search by user ID",filterOption:!1,onSearch:e=>g(e,"user_id"),onSelect:(e,l)=>f(e,l),options:"user_id"===u?o:[],loading:c,allowClear:!0})}),(0,r.jsx)(k.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsxs)(S.default,{defaultValue:"user",children:[(0,r.jsx)(S.default.Option,{value:"admin",children:"admin"}),(0,r.jsx)(S.default.Option,{value:"user",children:"user"})]})}),(0,r.jsx)("div",{className:"text-right mt-4",children:(0,r.jsx)(E.ZP,{type:"primary",htmlType:"submit",children:"Add Member"})})]})})},e8=e=>{let{teamId:l,onClose:s,accessToken:t,is_team_admin:a,is_proxy_admin:i}=e,[o,d]=(0,n.useState)(null),[c,m]=(0,n.useState)(!0),[u,h]=(0,n.useState)(!1),[p]=k.Z.useForm(),[f,Z]=(0,n.useState)(!1),[_,y]=(0,n.useState)(null),w=async()=>{try{if(m(!0),!t)return;let e=await (0,x.Xm)(t,l);d(e)}catch(e){N.ZP.error("Failed to load team information"),console.error("Error fetching team info:",e)}finally{m(!1)}};(0,n.useEffect)(()=>{w()},[l,t]);let S=async e=>{try{if(null==t)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,x.cu)(t,l,s),N.ZP.success("Team member added successfully"),h(!1),p.resetFields(),w()}catch(e){N.ZP.error("Failed to add team member"),console.error("Error adding team member:",e)}},C=async e=>{try{if(null==t)return;await (0,x.Lp)(t,l,e),N.ZP.success("Team member removed successfully"),w()}catch(e){N.ZP.error("Failed to remove team member"),console.error("Error removing team member:",e)}},I=async e=>{try{if(null==t)return;let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,x.sN)(t,l,s),N.ZP.success("Team member updated successfully"),Z(!1),w()}catch(e){N.ZP.error("Failed to update team member"),console.error("Error updating team member:",e)}};if(c)return(0,r.jsx)("div",{className:"p-4",children:"Loading..."});if(!(null==o?void 0:o.team_info))return(0,r.jsx)("div",{className:"p-4",children:"Team not found"});let{team_info:A}=o;return(0,r.jsxs)("div",{className:"p-4",children:[(0,r.jsx)("div",{className:"flex justify-between items-center mb-6",children:(0,r.jsxs)("div",{children:[(0,r.jsx)(E.ZP,{onClick:s,className:"mb-4",children:"← Back"}),(0,r.jsx)(v.Z,{children:A.team_alias}),(0,r.jsx)(b.Z,{className:"text-gray-500 font-mono",children:A.team_id})]})}),(0,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{className:"mb-4",children:[(0,r.jsx)(eE.Z,{children:"Overview"}),(0,r.jsx)(eE.Z,{children:"Members"}),(0,r.jsx)(eE.Z,{children:"Settings"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(j.Z,{numItems:1,numItemsSm:2,numItemsLg:3,className:"gap-6",children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(b.Z,{children:"Budget Status"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(v.Z,{children:["$",A.spend.toFixed(6)]}),(0,r.jsxs)(b.Z,{children:["of ",null===A.max_budget?"Unlimited":"$".concat(A.max_budget)]}),A.budget_duration&&(0,r.jsxs)(b.Z,{className:"text-gray-500",children:["Reset: ",A.budget_duration]})]})]}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(b.Z,{children:"Rate Limits"}),(0,r.jsxs)("div",{className:"mt-2",children:[(0,r.jsxs)(b.Z,{children:["TPM: ",A.tpm_limit||"Unlimited"]}),(0,r.jsxs)(b.Z,{children:["RPM: ",A.rpm_limit||"Unlimited"]}),A.max_parallel_requests&&(0,r.jsxs)(b.Z,{children:["Max Parallel Requests: ",A.max_parallel_requests]})]})]}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(b.Z,{children:"Models"}),(0,r.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:A.models.map((e,l)=>(0,r.jsx)(W.Z,{color:"red",children:e},l))})]})]})}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"User ID"}),(0,r.jsx)(Q.Z,{children:"User Email"}),(0,r.jsx)(Q.Z,{children:"Role"})]})}),(0,r.jsx)(J.Z,{children:o?o.team_info.members_with_roles.map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{className:"font-mono",children:e.user_id})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{className:"font-mono",children:e.user_email})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{className:"font-mono",children:e.role})}),(0,r.jsx)(X.Z,{children:a?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>{y(e),Z(!0)}}),(0,r.jsx)(Y.Z,{onClick:()=>{C(e)},icon:K.Z,size:"sm"})]}):null})]},l)):null})]})}),(0,r.jsx)(g.Z,{onClick:()=>h(!0),children:"Add Member"})]})}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Team Settings"}),(0,r.jsxs)("div",{className:"mt-4 space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(b.Z,{className:"font-medium",children:"Team ID"}),(0,r.jsx)(b.Z,{className:"font-mono",children:A.team_id})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.Z,{className:"font-medium",children:"Created At"}),(0,r.jsx)(b.Z,{children:new Date(A.created_at).toLocaleString()})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.Z,{className:"font-medium",children:"Status"}),(0,r.jsx)(W.Z,{color:A.blocked?"red":"green",children:A.blocked?"Blocked":"Active"})]})]})]}),(0,r.jsx)(e1,{visible:f,onCancel:()=>Z(!1),onSubmit:I,initialData:_,mode:"edit"})]})]})]}),(0,r.jsx)(e5,{isVisible:u,onCancel:()=>h(!1),onSubmit:S,accessToken:t})]})},e3=e=>{let{accessToken:l,userID:s}=e,[t,a]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{if(l&&s)try{let e=await (0,x.a6)(l);a(e)}catch(e){console.error("Error fetching available teams:",e)}})()},[l,s]);let i=async e=>{if(l&&s)try{await (0,x.cu)(l,e,{user_id:s,role:"user"}),N.ZP.success("Successfully joined team"),a(l=>l.filter(l=>l.team_id!==e))}catch(e){console.error("Error joining team:",e),N.ZP.error("Failed to join team")}};return(0,r.jsx)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Team Name"}),(0,r.jsx)(Q.Z,{children:"Description"}),(0,r.jsx)(Q.Z,{children:"Members"}),(0,r.jsx)(Q.Z,{children:"Models"}),(0,r.jsx)(Q.Z,{children:"Actions"})]})}),(0,r.jsxs)(J.Z,{children:[t.map(e=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:e.team_alias})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:e.description||"No description available"})}),(0,r.jsx)(X.Z,{children:(0,r.jsxs)(b.Z,{children:[e.members_with_roles.length," members"]})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)("div",{className:"flex flex-col",children:e.models&&0!==e.models.length?e.models.map((e,l)=>(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(b.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(W.Z,{size:"xs",color:"red",children:(0,r.jsx)(b.Z,{children:"All Proxy Models"})})})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(g.Z,{size:"xs",variant:"secondary",onClick:()=>i(e.team_id),children:"Join Team"})})]},e.team_id)),0===t.length&&(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{colSpan:5,className:"text-center",children:(0,r.jsx)(b.Z,{children:"No available teams to join"})})})]})]})})};console.log=function(){};var e6=e=>{let{teams:l,searchParams:s,accessToken:t,setTeams:a,userID:i,userRole:o}=e,[d,c]=(0,n.useState)(""),m=async(e,l,s)=>{let t;t="Admin"!=s&&"Admin Viewer"!=s?await (0,x.It)(e,l):await (0,x.It)(e),console.log("givenTeams: ".concat(t)),a(t)};(0,n.useEffect)(()=>{console.log("inside useeffect - ".concat(l)),null===l&&t&&m(t,i,o)},[l]),(0,n.useEffect)(()=>{console.log("inside useeffect - ".concat(d)),t&&m(t,i,o),eb()},[d]);let[u]=k.Z.useForm(),[h]=k.Z.useForm(),{Title:v,Paragraph:w}=ec.default,[I,P]=(0,n.useState)(""),[D,R]=(0,n.useState)(!1),[L,U]=(0,n.useState)(null),[z,V]=(0,n.useState)(null),[el,es]=(0,n.useState)(!1),[et,ea]=(0,n.useState)(!1),[er,en]=(0,n.useState)(!1),[ei,eo]=(0,n.useState)([]),[ed,em]=(0,n.useState)(!1),[eu,eh]=(0,n.useState)(null),[ex,ep]=(0,n.useState)({}),[ej,eg]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{if(null==t)return;let e=(await (0,x.t3)(t)).guardrails.map(e=>e.guardrail_name);eg(e)}catch(e){console.error("Failed to fetch guardrails:",e)}})()},[t]);let ef=e=>{U(e),R(!0)},eZ=async e=>{eh(e),em(!0)},e_=async()=>{if(null!=eu&&null!=l&&null!=t){try{await (0,x.rs)(t,eu);let e=l.filter(e=>e.team_id!==eu);a(e)}catch(e){console.error("Error deleting the team:",e)}em(!1),eh(null)}};(0,n.useEffect)(()=>{let e=async()=>{try{let e;if(null===i||null===o||null===t||null===l)return;let s={};e="Admin"!=o&&"Admin Viewer"!=o?await (0,x.It)(t,i):await (0,x.It)(t);for(let l=0;l<e.length;l++){let t=e[l],a=t.team_id;null!==t&&(s={...s,[a]:t})}ep(s)}catch(e){console.error("Error fetching team info:",e)}};(async()=>{try{if(null===i||null===o||null===t)return;let e=await T(i,o,t);e&&eo(e)}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,i,o,l]);let ey=async e=>{try{if(console.log("formValues: ".concat(JSON.stringify(e))),null!=t){var s;let r=null==e?void 0:e.team_alias,n=null!==(s=null==l?void 0:l.map(e=>e.team_alias))&&void 0!==s?s:[],i=null==e?void 0:e.organization_id;if(""===i||"string"!=typeof i?e.organization_id=null:e.organization_id=i.trim(),e.metadata={...e.guardrails?{guardrails:e.guardrails}:{}},delete e.guardrails,n.includes(r))throw Error("Team alias ".concat(r," already exists, please pick another alias"));N.ZP.info("Creating Team");let o=await (0,x.hT)(t,e);null!==l?a([...l,o]):a([o]),console.log("response for team create call: ".concat(o)),N.ZP.success("Team created"),es(!1)}}catch(e){console.error("Error creating the team:",e),N.ZP.error("Error creating the team: "+e,20)}},eb=()=>{c(new Date().toLocaleString())};return(0,r.jsx)("div",{className:"w-full mx-4",children:z?(0,r.jsx)(e8,{teamId:z,onClose:()=>V(null),accessToken:t,is_team_admin:(e=>{if(null==e||null==e.members_with_roles)return!1;for(let l=0;l<e.members_with_roles.length;l++){let s=e.members_with_roles[l];if(s.user_id==i&&"admin"==s.role)return!0}return!1})(null==l?void 0:l.find(e=>e.team_id===z)),is_proxy_admin:"Admin"==o}):(0,r.jsxs)(eT.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eO.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eE.Z,{children:"Your Teams"}),(0,r.jsx)(eE.Z,{children:"Available Teams"})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[d&&(0,r.jsxs)(b.Z,{children:["Last Refreshed: ",d]}),(0,r.jsx)(Y.Z,{icon:q.Z,variant:"shadow",size:"xs",className:"self-center",onClick:eb})]})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(b.Z,{children:["Click on “Team ID” to view team details ",(0,r.jsx)("b",{children:"and"})," manage team members."]}),(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 pt-2 pb-2 h-[75vh] w-full mt-2",children:[(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Team Name"}),(0,r.jsx)(Q.Z,{children:"Team ID"}),(0,r.jsx)(Q.Z,{children:"Created"}),(0,r.jsx)(Q.Z,{children:"Spend (USD)"}),(0,r.jsx)(Q.Z,{children:"Budget (USD)"}),(0,r.jsx)(Q.Z,{children:"Models"}),(0,r.jsx)(Q.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(Q.Z,{children:"Info"})]})}),(0,r.jsx)(J.Z,{children:l&&l.length>0?l.sort((e,l)=>new Date(l.created_at).getTime()-new Date(e.created_at).getTime()).map(e=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{children:(0,r.jsx)("div",{className:"overflow-hidden",children:(0,r.jsx)(F.Z,{title:e.team_id,children:(0,r.jsxs)(g.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:()=>{V(e.team_id)},children:[e.team_id.slice(0,7),"..."]})})})})}),(0,r.jsx)(X.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.created_at?new Date(e.created_at).toLocaleDateString():"N/A"}),(0,r.jsx)(X.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(X.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,r.jsx)(X.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(b.Z,{children:e.length>30?"".concat(O(e).slice(0,30),"..."):O(e)})},l))}):null}),(0,r.jsx)(X.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(b.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{}),"RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(X.Z,{children:[(0,r.jsxs)(b.Z,{children:[ex&&e.team_id&&ex[e.team_id]&&ex[e.team_id].keys&&ex[e.team_id].keys.length," ","Keys"]}),(0,r.jsxs)(b.Z,{children:[ex&&e.team_id&&ex[e.team_id]&&ex[e.team_id].members_with_roles&&ex[e.team_id].members_with_roles.length," ","Members"]})]}),(0,r.jsx)(X.Z,{children:"Admin"==o?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>ef(e)}),(0,r.jsx)(Y.Z,{onClick:()=>eZ(e.team_id),icon:K.Z,size:"sm"})]}):null})]},e.team_id)):null})]}),ed&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.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,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:""}),(0,r.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,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(g.Z,{onClick:e_,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(g.Z,{onClick:()=>{em(!1),eh(null)},children:"Cancel"})]})]})]})})]})}),"Admin"==o?(0,r.jsxs)(p.Z,{numColSpan:1,children:[(0,r.jsx)(g.Z,{className:"mx-auto",onClick:()=>es(!0),children:"+ Create New Team"}),(0,r.jsx)(C.Z,{title:"Create Team",visible:el,width:800,footer:null,onOk:()=>{es(!1),u.resetFields()},onCancel:()=>{es(!1),u.resetFields()},children:(0,r.jsxs)(k.Z,{form:u,onFinish:ey,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(S.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(S.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),ei.map(e=>(0,r.jsx)(S.default.Option,{value:e,children:O(e)},e))]})}),(0,r.jsx)(k.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(A.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(S.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(S.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(S.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(S.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(k.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(A.Z,{step:1,width:400})}),(0,r.jsx)(k.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(A.Z,{step:1,width:400})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(y.Z,{children:(0,r.jsx)("b",{children:"Additional Settings"})}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(k.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,r.jsx)(f.Z,{onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(k.Z.Item,{label:"Organization ID",name:"organization_id",help:"Assign team to an organization. Found in the 'Organization' tab.",children:(0,r.jsx)(f.Z,{placeholder:"",onChange:e=>{e.target.value=e.target.value.trim()}})}),(0,r.jsx)(k.Z.Item,{label:(0,r.jsxs)("span",{children:["Guardrails"," ",(0,r.jsx)(F.Z,{title:"Setup your first guardrail",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/guardrails/quick_start",target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(M.Z,{style:{marginLeft:"4px"}})})})]}),name:"guardrails",className:"mt-8",help:"Select existing guardrails or enter new ones",children:(0,r.jsx)(S.default,{mode:"tags",style:{width:"100%"},placeholder:"Select or enter guardrails",options:ej.map(e=>({value:e,label:e}))})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}):null]})]}),(0,r.jsx)(eD.Z,{children:(0,r.jsx)(e3,{accessToken:t,userID:i})})]})]})})};let e7=async(e,l,s)=>{if(null!=l)try{N.ZP.info("Creating Organization"),console.log("formValues: "+JSON.stringify(e));let t=await (0,x.H1)(l,e);console.log("response for organization create call: ".concat(t)),N.ZP.success("Organization created"),sessionStorage.removeItem("organizations"),s(!1)}catch(e){console.error("Error creating the organization:",e),N.ZP.error("Error creating the organization: "+e,20)}};var e9=e=>{let{title:l="Create Organization",onCancel:s,accessToken:t,availableModels:a=[],initialValues:i={},submitButtonText:o="Create",modelSelectionType:d="multiple"}=e,[c]=k.Z.useForm(),[m,u]=(0,n.useState)(!1),[h,x]=(0,n.useState)({name:i.name||"",models:i.models||[],maxBudget:i.maxBudget||null,budgetDuration:i.budgetDuration||null,tpmLimit:i.tpmLimit||null,rpmLimit:i.rpmLimit||null});console.log("availableModels: ".concat(a));let p=async e=>{null!=t&&(await e7(e,t,u),u(!1))};return(0,r.jsxs)("div",{className:"w-full",children:[(0,r.jsxs)(g.Z,{onClick:()=>u(!0),className:"mx-auto",type:"button",children:["+ Create New ",l]}),(0,r.jsx)(C.Z,{title:"Create ".concat(l),visible:m,width:800,footer:null,onCancel:()=>{u(!1),s&&s()},children:(0,r.jsxs)(k.Z,{form:c,onFinish:p,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"".concat(l," Name"),name:"organization_alias",rules:[{required:!0,message:"Please input a ".concat(l," name")}],children:(0,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(S.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(S.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),a.map(e=>(0,r.jsx)(S.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(k.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(A.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(S.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(S.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(S.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(S.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(k.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(A.Z,{step:1,width:400})}),(0,r.jsx)(k.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(A.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:o})})]})})]})};let le=(e,l)=>{for(let s=0;s<e.members_with_roles.length;s++){let t=e.members_with_roles[s];if(t.user_id==l&&"admin"==t.role)return!0}return!1};var ll=e=>{let{userRole:l,userID:s,selectedOrganization:t,onMemberAdd:a}=e,[i,o]=n.useState(!1),[d]=k.Z.useForm();return(0,r.jsxs)(p.Z,{numColSpan:1,children:["Admin"===l||t&&le(t,s)?(0,r.jsx)(g.Z,{className:"mx-auto mb-5",onClick:()=>o(!0),children:"+ Add member"}):null,(0,r.jsxs)(C.Z,{title:"Add member",visible:i,width:800,footer:null,onOk:()=>{d.submit()},onCancel:()=>{d.resetFields(),o(!1)},children:[(0,r.jsx)(b.Z,{className:"mb-2",children:"User must exist in proxy. Get User ID from 'Users' tab."}),(0,r.jsxs)(k.Z,{form:d,onFinish:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:{role:"internal_user"},children:[(0,r.jsx)(k.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(P.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(k.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(P.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)(k.Z.Item,{label:"Member Role",name:"role",className:"mb-4",children:(0,r.jsxs)(S.default,{defaultValue:"user",children:[(0,r.jsx)(S.default.Option,{value:"org_admin",children:(0,r.jsxs)("div",{className:"flex",children:["Org Admin"," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:"Can add and remove members, and change their roles."})]})}),(0,r.jsx)(S.default.Option,{value:"internal_user",children:(0,r.jsxs)("div",{className:"flex",children:["Internal User"," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:"Can view/create keys for themselves within organization."})]})}),(0,r.jsx)(S.default.Option,{value:"internal_user_viewer",children:(0,r.jsxs)("div",{className:"flex",children:["Internal User Viewer"," ",(0,r.jsx)("p",{className:"ml-2",style:{color:"gray",fontSize:"12px"},children:"Can only view their keys within organization."})]})})]})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Add member"})})]})]})]})},ls=e=>{var l;let{selectedEntity:s,onEditSubmit:t,editModalComponent:a,entityType:i}=e,[o,d]=n.useState(!1);return(0,r.jsxs)(p.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"team"===i?"Team Member":"Organization Member"}),(0,r.jsx)(Q.Z,{children:"Role"})]})}),(0,r.jsx)(J.Z,{children:(null!==(l=null==s?void 0:s.members)&&void 0!==l?l:[]).map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.user_id}),(0,r.jsx)(X.Z,{children:e.user_role})]},"".concat(e.user_id,"-").concat(l)))})]})}),s&&(0,r.jsx)(a,{visible:o,onCancel:()=>{d(!1)},entity:s,onSubmit:e=>{t(e),d(!1)}})]})},lt=e=>{let{data:l,columns:s,actions:t,emptyMessage:a="No data available",deleteModal:n}=e,i=(e,l)=>{let s=l[e.accessor];return e.cellRenderer?e.cellRenderer(s,l):Array.isArray(s)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===s.length?(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(b.Z,{children:"None"})}):s.map((e,l)=>(0,r.jsx)(W.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(b.Z,{children:String(e).length>30?"".concat(String(e).slice(0,30),"..."):e})},l))}):(null==s?void 0:s.toString())||""};return(0,r.jsx)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[40vh]",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[s.map((e,l)=>(0,r.jsx)(Q.Z,{children:e.header},l)),t&&t.length>0&&(0,r.jsx)(Q.Z,{children:"Actions"})]})}),(0,r.jsx)(J.Z,{children:l&&l.length>0?l.map((e,l)=>(0,r.jsxs)(ee.Z,{children:[s.map((l,s)=>(0,r.jsx)(X.Z,{style:{maxWidth:l.width||"4px",whiteSpace:"pre-wrap",overflow:"hidden",...l.style},children:"id"===l.accessor?(0,r.jsx)(F.Z,{title:e[l.accessor],children:i(l,e)}):i(l,e)},s)),t&&t.length>0&&(0,r.jsx)(X.Z,{children:t.map((l,s)=>{var t;return(null===(t=l.condition)||void 0===t?void 0:t.call(l,e))!==!1&&(0,r.jsx)(F.Z,{title:l.tooltip,children:(0,r.jsx)(Y.Z,{icon:l.icon,size:"sm",onClick:()=>l.onClick(e),className:"cursor-pointer mx-1"})},s)})})]},l)):(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{colSpan:s.length+(t?1:0),children:(0,r.jsx)(b.Z,{className:"text-center",children:a})})})})]})})};console.log=function(){};let la=e=>{let{visible:l,onCancel:s,entity:t,onSubmit:a}=e;return(0,r.jsx)("div",{})},lr=e=>{let{organizations:l,userRole:s,onEdit:t,onDelete:a,isDeleteModalOpen:n,setIsDeleteModalOpen:i,selectedOrganization:o,setSelectedOrganization:d}=e,c=[...t&&"Admin"===s?[{icon:void 0,onClick:e=>t(e),condition:()=>"Admin"===s,tooltip:"Edit organization"}]:[],...a&&"Admin"===s?[{icon:void 0,onClick:e=>a(e),condition:()=>"Admin"===s,tooltip:"Delete organization"}]:[]];return(0,r.jsx)(lt,{data:l,columns:[{header:"Organization Name",accessor:"organization_alias",width:"4px",style:{whiteSpace:"pre-wrap",overflow:"hidden"}},{header:"Organization ID",accessor:"organization_id",width:"4px",style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.75em"}},{header:"Spend (USD)",accessor:"spend"},{header:"Budget (USD)",accessor:"max_budget",cellRenderer:e=>null!=e?e:"No limit"},{header:"Models",accessor:"models"},{header:"TPM / RPM Limits",accessor:"limits",cellRenderer:(e,l)=>(0,r.jsxs)("div",{className:"text-sm",children:[(0,r.jsxs)("span",{children:["TPM: ",l.tpm_limit?l.tpm_limit:"Unlimited"]}),(0,r.jsx)("br",{}),(0,r.jsxs)("span",{children:["RPM: ",l.rpm_limit?l.rpm_limit:"Unlimited"]})]})},{header:"Info",accessor:"info",cellRenderer:(e,l)=>{var s;return(0,r.jsx)("div",{className:"space-y-1",children:(0,r.jsxs)("div",{className:"text-sm",children:[(null===(s=l.members)||void 0===s?void 0:s.length)||0," Members"]})})}}],actions:c,emptyMessage:"No organizations available",deleteModal:{isOpen:n,onConfirm:()=>{o&&a&&a(o),i(!1),d(null)},onCancel:()=>{i(!1),d(null)},title:"Delete Organization",message:"Are you sure you want to delete this organization?"}})};var ln=e=>{let{accessToken:l,userID:s,userRole:t,premiumUser:a}=e,[i,o]=(0,n.useState)([]),{Title:d,Paragraph:c}=ec.default,[m,u]=(0,n.useState)(!1),[h,g]=(0,n.useState)(null),[f,Z]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(!l||!s||!t)return;let e=async()=>{try{let e=(await (0,x.So)(l,s,t)).data.map(e=>e.id);console.log("available_model_names:",e),Z(e)}catch(e){console.error("Error fetching user models:",e)}},r=async()=>{let e;e=await (0,x.r6)(l),console.log("givenOrganizations: ".concat(e)),o(e),sessionStorage.setItem("organizations",JSON.stringify(e))};a&&(e(),r())},[l]);let _=async e=>{if(h&&l)try{let s={user_email:e.user_email,user_id:e.user_id,role:e.role};await (0,x.vh)(l,h.organization_id,s),N.ZP.success("Member added")}catch(e){console.error("Error creating the team:",e),N.ZP.error("Error creating the organization: "+e)}};return(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(p.Z,{numColSpan:1,children:[(0,r.jsx)(d,{level:4,children:"✨ All Organizations"}),(0,r.jsxs)(b.Z,{className:"mb-2",children:["This is a LiteLLM Enterprise feature, and requires a valid key to use. Get a trial key ",(0,r.jsx)("a",{href:"https://www.litellm.ai/#trial",className:"text-blue-600 hover:text-blue-800 underline",target:"_blank",rel:"noopener noreferrer",children:"here"})]}),t?lr({organizations:i,userRole:t,isDeleteModalOpen:m,setIsDeleteModalOpen:u,selectedOrganization:h,setSelectedOrganization:g}):null]}),"Admin"==t&&l&&a?(0,r.jsx)(e9,{title:"Organization",accessToken:l,availableModels:f,submitButtonText:"Create Organization"}):null,a?(0,r.jsxs)(p.Z,{numColSpan:1,children:[(0,r.jsx)(d,{level:4,children:"Organization Members"}),(0,r.jsx)(c,{children:"If you belong to multiple organizations, this setting controls which organizations' members you see."}),i&&i.length>0?(0,r.jsx)(el.Z,{children:i.map((e,l)=>(0,r.jsx)(es.Z,{value:String(l),onClick:()=>{g(e)},children:e.organization_alias},l))}):(0,r.jsxs)(c,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]}):null,"Admin"==t&&s&&h&&a?(0,r.jsx)(ll,{userRole:t,userID:s,selectedOrganization:h,onMemberAdd:_}):null,"Admin"==t&&s&&h&&a?(0,r.jsx)(ls,{selectedEntity:h,onEditSubmit:()=>{},editModalComponent:la,entityType:"organization"}):null]})})};let li=()=>{let[e,l]=(0,n.useState)("http://localhost:4000");return(0,n.useEffect)(()=>{{let{protocol:e,host:s}=window.location;l("".concat(e,"//").concat(s))}},[]),e};var lo=e=>{let{searchParams:l,accessToken:s,showSSOBanner:t,premiumUser:a}=e,[o]=k.Z.useForm(),[d]=k.Z.useForm(),{Title:c,Paragraph:m}=ec.default,[u,h]=(0,n.useState)(""),[f,Z]=(0,n.useState)(null),[_,y]=(0,n.useState)(null),[v,w]=(0,n.useState)(!1),[S,I]=(0,n.useState)(!1),[A,T]=(0,n.useState)(!1),[O,D]=(0,n.useState)(!1),[M,F]=(0,n.useState)(!1),[R,L]=(0,n.useState)(!1),[U,z]=(0,n.useState)(!1),[V,q]=(0,n.useState)(!1),[K,W]=(0,n.useState)(!1),[et,ea]=(0,n.useState)([]),[er,en]=(0,n.useState)(null);(0,i.useRouter)();let[ei,eo]=(0,n.useState)(null);console.log=function(){};let ed=li(),em="All IP Addresses Allowed",eu=ed;eu+="/fallback/login";let eh=async()=>{try{if(!0!==a){N.ZP.error("This feature is only available for premium users. Please upgrade your account.");return}if(s){let e=await (0,x.PT)(s);ea(e&&e.length>0?e:[em])}else ea([em])}catch(e){console.error("Error fetching allowed IPs:",e),N.ZP.error("Failed to fetch allowed IPs ".concat(e)),ea([em])}finally{!0===a&&z(!0)}},ex=async e=>{try{if(s){await (0,x.eH)(s,e.ip);let l=await (0,x.PT)(s);ea(l),N.ZP.success("IP address added successfully")}}catch(e){console.error("Error adding IP:",e),N.ZP.error("Failed to add IP address ".concat(e))}finally{q(!1)}},ep=async e=>{en(e),W(!0)},ej=async()=>{if(er&&s)try{await (0,x.$I)(s,er);let e=await (0,x.PT)(s);ea(e.length>0?e:[em]),N.ZP.success("IP address deleted successfully")}catch(e){console.error("Error deleting IP:",e),N.ZP.error("Failed to delete IP address ".concat(e))}finally{W(!1),en(null)}},eg=()=>{L(!1)},ef=["proxy_admin","proxy_admin_viewer"];(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await (0,x.Xd)(s,"proxy_admin_viewer");console.log("proxy admin viewer response: ",l);let t=l.users;console.log("proxy viewers response: ".concat(t)),t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(t));let a=(await (0,x.Xd)(s,"proxy_admin")).users;a.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(a)),console.log("combinedList: ".concat(e)),Z(e),eo(await (0,x.lg)(s))}})()},[s]);let eZ=()=>{D(!1),d.resetFields(),o.resetFields()},e_=()=>{D(!1),d.resetFields(),o.resetFields()},ey=e=>(0,r.jsxs)(k.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(k.Z.Item,{label:"Email",name:"user_email",className:"mb-8 mt-4",children:(0,r.jsx)(P.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},className:"mt-4",children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Add member"})})]}),eb=(e,l,s)=>(0,r.jsxs)(k.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(el.Z,{value:l,children:ef.map((e,l)=>(0,r.jsx)(es.Z,{value:e,children:e},l))})}),(0,r.jsx)(k.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:s,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(P.Z,{value:s,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Update role"})})]}),ev=async e=>{try{if(null!=s&&null!=f){N.ZP.info("Making API Call");let l=await (0,x.pf)(s,e,null);console.log("response for team create call: ".concat(l));let t=f.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),f.push(l),Z(f)),N.ZP.success("Refresh tab to see updated user role"),D(!1)}}catch(e){console.error("Error creating the key:",e)}},ew=async e=>{try{if(null!=s&&null!=f){var l;N.ZP.info("Making API Call");let t=await (0,x.pf)(s,e,"proxy_admin_viewer");console.log("response for team create call: ".concat(t));let a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,x.XO)(s,a).then(e=>{y(e),w(!0)});let r=f.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(t.user_id)),e.user_id===t.user_id));console.log("foundIndex: ".concat(r)),-1==r&&(console.log("updates admin with new user"),f.push(t),Z(f)),o.resetFields(),I(!1)}}catch(e){console.error("Error creating the key:",e)}},eS=async e=>{try{if(null!=s&&null!=f){var l;N.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await (0,x.pf)(s,e,"proxy_admin"),a=(null===(l=t.data)||void 0===l?void 0:l.user_id)||t.user_id;(0,x.XO)(s,a).then(e=>{y(e),w(!0)}),console.log("response for team create call: ".concat(t));let r=f.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"),f.push(t),Z(f)),o.resetFields(),T(!1)}}catch(e){console.error("Error creating the key:",e)}},ek=async e=>{if(null==s)return;let l={environment_variables:{PROXY_BASE_URL:e.proxy_base_url,GOOGLE_CLIENT_ID:e.google_client_id,GOOGLE_CLIENT_SECRET:e.google_client_secret}};(0,x.K_)(s,l)};return console.log("admins: ".concat(null==f?void 0:f.length)),(0,r.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,r.jsx)(c,{level:4,children:"Admin Access "}),(0,r.jsxs)(m,{children:[t&&(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access",children:"Requires SSO Setup"}),(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin: "})," Can create keys, teams, users, add models, etc."," ",(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin Viewer: "}),"Can just view spend. They cannot create keys, teams or grant users access to new models."," "]}),(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsx)(H.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Member Name"}),(0,r.jsx)(Q.Z,{children:"Role"})]})}),(0,r.jsx)(J.Z,{children:f?f.map((e,l)=>{var s;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsxs)(X.Z,{children:[" ",(null==ei?void 0:null===(s=ei[null==e?void 0:e.user_role])||void 0===s?void 0:s.ui_label)||"-"]}),(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>D(!0)}),(0,r.jsx)(C.Z,{title:"Update role",visible:O,width:800,footer:null,onOk:eZ,onCancel:e_,children:eb(ev,e.user_role,e.user_id)})]})]},l)}):null})]})})}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(g.Z,{className:"mr-4 mb-5",onClick:()=>T(!0),children:"+ Add admin"}),(0,r.jsx)(C.Z,{title:"Add admin",visible:A,width:800,footer:null,onOk:()=>{T(!1),d.resetFields(),o.resetFields()},onCancel:()=>{T(!1),w(!1),d.resetFields(),o.resetFields()},children:ey(eS)}),(0,r.jsx)(eJ,{isInvitationLinkModalVisible:v,setIsInvitationLinkModalVisible:w,baseUrl:ed,invitationLinkData:_}),(0,r.jsx)(g.Z,{className:"mb-5",onClick:()=>I(!0),children:"+ Add viewer"}),(0,r.jsx)(C.Z,{title:"Add viewer",visible:S,width:800,footer:null,onOk:()=>{I(!1),d.resetFields(),o.resetFields()},onCancel:()=>{I(!1),d.resetFields(),o.resetFields()},children:ey(ew)})]})})]}),(0,r.jsxs)(j.Z,{children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(c,{level:4,children:" ✨ Security Settings"}),(0,r.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",marginTop:"1rem"},children:[(0,r.jsx)("div",{children:(0,r.jsx)(g.Z,{onClick:()=>!0===a?F(!0):N.ZP.error("Only premium users can add SSO"),children:"Add SSO"})}),(0,r.jsx)("div",{children:(0,r.jsx)(g.Z,{onClick:eh,children:"Allowed IPs"})})]})]}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(C.Z,{title:"Add SSO",visible:M,width:800,footer:null,onOk:()=>{F(!1),o.resetFields()},onCancel:()=>{F(!1),o.resetFields()},children:(0,r.jsxs)(k.Z,{form:o,onFinish:e=>{eS(e),ek(e),F(!1),L(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(P.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(P.Z,{})}),(0,r.jsx)(k.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(P.Z.Password,{})}),(0,r.jsx)(k.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(P.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(C.Z,{title:"SSO Setup Instructions",visible:R,width:800,footer:null,onOk:eg,onCancel:()=>{L(!1)},children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(b.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(b.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(b.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(b.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{onClick:eg,children:"Done"})})]}),(0,r.jsx)(C.Z,{title:"Manage Allowed IP Addresses",width:800,visible:U,onCancel:()=>z(!1),footer:[(0,r.jsx)(g.Z,{className:"mx-1",onClick:()=>q(!0),children:"Add IP Address"},"add"),(0,r.jsx)(g.Z,{onClick:()=>z(!1),children:"Close"},"close")],children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"IP Address"}),(0,r.jsx)(Q.Z,{className:"text-right",children:"Action"})]})}),(0,r.jsx)(J.Z,{children:et.map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e}),(0,r.jsx)(X.Z,{className:"text-right",children:e!==em&&(0,r.jsx)(g.Z,{onClick:()=>ep(e),color:"red",size:"xs",children:"Delete"})})]},l))})]})}),(0,r.jsx)(C.Z,{title:"Add Allowed IP Address",visible:V,onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(k.Z,{onFinish:ex,children:[(0,r.jsx)(k.Z.Item,{name:"ip",rules:[{required:!0,message:"Please enter an IP address"}],children:(0,r.jsx)(P.Z,{placeholder:"Enter IP address"})}),(0,r.jsx)(k.Z.Item,{children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Add IP Address"})})]})}),(0,r.jsx)(C.Z,{title:"Confirm Delete",visible:K,onCancel:()=>W(!1),onOk:ej,footer:[(0,r.jsx)(g.Z,{className:"mx-1",onClick:()=>ej(),children:"Yes"},"delete"),(0,r.jsx)(g.Z,{onClick:()=>W(!1),children:"Close"},"close")],children:(0,r.jsxs)("p",{children:["Are you sure you want to delete the IP address: ",er,"?"]})})]}),(0,r.jsxs)(eV.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access"," ",(0,r.jsxs)("a",{href:eu,target:"_blank",children:[(0,r.jsx)("b",{children:eu})," "]})]})]})]})},ld=s(92858),lc=s(44643),lm=e=>{let{alertingSettings:l,handleInputChange:s,handleResetField:t,handleSubmit:a,premiumUser:n}=e,[i]=k.Z.useForm();return(0,r.jsxs)(k.Z,{form:i,onFinish:()=>{console.log("INSIDE ONFINISH");let e=i.getFieldsValue(),l=Object.entries(e).every(e=>{let[l,s]=e;return"boolean"!=typeof s&&(""===s||null==s)});console.log("formData: ".concat(JSON.stringify(e),", isEmpty: ").concat(l)),l?console.log("Some form fields are empty."):a(e)},labelAlign:"left",children:[l.map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsxs)(X.Z,{align:"center",children:[(0,r.jsx)(b.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),e.premium_field?n?(0,r.jsx)(k.Z.Item,{name:e.field_name,children:(0,r.jsx)(X.Z,{children:"Integer"===e.field_type?(0,r.jsx)(A.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l)}):"Boolean"===e.field_type?(0,r.jsx)(ld.Z,{checked:e.field_value,onChange:l=>s(e.field_name,l)}):(0,r.jsx)(P.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}):(0,r.jsx)(X.Z,{children:(0,r.jsx)(g.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})})}):(0,r.jsx)(k.Z.Item,{name:e.field_name,className:"mb-0",valuePropName:"Boolean"===e.field_type?"checked":"value",children:(0,r.jsx)(X.Z,{children:"Integer"===e.field_type?(0,r.jsx)(A.Z,{step:1,value:e.field_value,onChange:l=>s(e.field_name,l),className:"p-0"}):"Boolean"===e.field_type?(0,r.jsx)(ld.Z,{checked:e.field_value,onChange:l=>{s(e.field_name,l),i.setFieldsValue({[e.field_name]:l})}}):(0,r.jsx)(P.Z,{value:e.field_value,onChange:l=>s(e.field_name,l)})})}),(0,r.jsx)(X.Z,{children:!0==e.stored_in_db?(0,r.jsx)(W.Z,{icon:lc.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(W.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(W.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(Y.Z,{icon:K.Z,color:"red",onClick:()=>t(e.field_name,l),children:"Reset"})})]},l)),(0,r.jsx)("div",{children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Update Settings"})})]})},lu=e=>{let{accessToken:l,premiumUser:s}=e,[t,a]=(0,n.useState)([]);return(0,n.useEffect)(()=>{l&&(0,x.RQ)(l).then(e=>{a(e)})},[l]),(0,r.jsx)(lm,{alertingSettings:t,handleInputChange:(e,l)=>{let s=t.map(s=>s.field_name===e?{...s,field_value:l}:s);console.log("updatedSettings: ".concat(JSON.stringify(s))),a(s)},handleResetField:(e,s)=>{if(l)try{let l=t.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:l.field_default_value}:l);a(l)}catch(e){console.log("ERROR OCCURRED!")}},handleSubmit:e=>{if(!l||(console.log("formValues: ".concat(e)),null==e||void 0==e))return;let s={};t.forEach(e=>{s[e.field_name]=e.field_value});let a={...e,...s};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,x.jA)(l,"alerting_args",n),"boolean"==typeof r&&(!0==r?(0,x.jA)(l,"alerting",["slack"]):(0,x.jA)(l,"alerting",[])),N.ZP.success("Wait 10s for proxy to update.")}catch(e){}},premiumUser:s})},lh=s(86582);let{Title:lx,Paragraph:lp}=ec.default;console.log=function(){};var lj=e=>{let{accessToken:l,userRole:s,userID:t,premiumUser:a}=e,[i,o]=(0,n.useState)([]),[d,c]=(0,n.useState)([]),[m,u]=(0,n.useState)(!1),[h]=k.Z.useForm(),[p,Z]=(0,n.useState)(null),[_,y]=(0,n.useState)([]),[v,w]=(0,n.useState)(""),[I,A]=(0,n.useState)({}),[P,T]=(0,n.useState)([]),[O,D]=(0,n.useState)(!1),[M,F]=(0,n.useState)([]),[R,L]=(0,n.useState)(null),[U,z]=(0,n.useState)([]),[V,q]=(0,n.useState)(!1),[K,W]=(0,n.useState)(null),el=e=>{P.includes(e)?T(P.filter(l=>l!==e)):T([...P,e])},et={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,n.useEffect)(()=>{l&&s&&t&&(0,x.BL)(l,t,s).then(e=>{console.log("callbacks",e),o(e.callbacks),F(e.available_callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let s=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",s),T(e.active_alerts),w(s),A(e.alerts_to_webhook)}c(l)})},[l,s,t]);let ea=e=>P&&P.includes(e),er=()=>{if(!l)return;let e={};d.filter(e=>"email"===e.name).forEach(l=>{var s;Object.entries(null!==(s=l.variables)&&void 0!==s?s:{}).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));a&&a.value&&(e[s]=null==a?void 0:a.value)})}),console.log("updatedVariables",e);try{(0,x.K_)(l,{general_settings:{alerting:["email"]},environment_variables:e})}catch(e){N.ZP.error("Failed to update alerts: "+e,20)}N.ZP.success("Email settings updated successfully")},en=async e=>{if(!l)return;let s={};Object.entries(e).forEach(e=>{let[l,t]=e;"callback"!==l&&(s[l]=t)});try{await (0,x.K_)(l,{environment_variables:s}),N.ZP.success("Callback added successfully"),u(!1),h.resetFields(),Z(null)}catch(e){N.ZP.error("Failed to add callback: "+e,20)}},ei=async e=>{if(!l)return;let s=null==e?void 0:e.callback,t={};Object.entries(e).forEach(e=>{let[l,s]=e;"callback"!==l&&(t[l]=s)});try{await (0,x.K_)(l,{environment_variables:t,litellm_settings:{success_callback:[s]}}),N.ZP.success("Callback ".concat(s," added successfully")),u(!1),h.resetFields(),Z(null)}catch(e){N.ZP.error("Failed to add callback: "+e,20)}},eo=e=>{console.log("inside handleSelectedCallbackChange",e),Z(e.litellm_callback_name),console.log("all callbacks",M),e&&e.litellm_callback_params?(z(e.litellm_callback_params),console.log("selectedCallbackParams",U)):z([])};return l?(console.log("callbacks: ".concat(i)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(j.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eE.Z,{value:"2",children:"Alerting Types"}),(0,r.jsx)(eE.Z,{value:"3",children:"Alerting Settings"}),(0,r.jsx)(eE.Z,{value:"4",children:"Email Alerts"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(eD.Z,{children:[(0,r.jsx)(lx,{level:4,children:"Active Logging Callbacks"}),(0,r.jsx)(j.Z,{numItems:2,children:(0,r.jsx)(H.Z,{className:"max-h-[50vh]",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsx)(ee.Z,{children:(0,r.jsx)(Q.Z,{children:"Callback Name"})})}),(0,r.jsx)(J.Z,{children:i.map((e,s)=>(0,r.jsxs)(ee.Z,{className:"flex justify-between",children:[(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:e.name})}),(0,r.jsx)(X.Z,{children:(0,r.jsxs)(j.Z,{numItems:2,className:"flex justify-between",children:[(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>{W(e),q(!0)}}),(0,r.jsx)(g.Z,{onClick:()=>(0,x.jE)(l,e.name),className:"ml-2",variant:"secondary",children:"Test Callback"})]})})]},s))})]})})}),(0,r.jsx)(g.Z,{className:"mt-2",onClick:()=>D(!0),children:"Add Callback"})]}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(H.Z,{children:[(0,r.jsxs)(b.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from"," ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{}),(0,r.jsx)(Q.Z,{}),(0,r.jsx)(Q.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(J.Z,{children:Object.entries(et).map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:"region_outage_alerts"==s?a?(0,r.jsx)(ld.Z,{id:"switch",name:"switch",checked:ea(s),onChange:()=>el(s)}):(0,r.jsx)(g.Z,{className:"flex items-center justify-center",children:(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:"✨ Enterprise Feature"})}):(0,r.jsx)(ld.Z,{id:"switch",name:"switch",checked:ea(s),onChange:()=>el(s)})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:t})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(f.Z,{name:s,type:"password",defaultValue:I&&I[s]?I[s]:v})})]},l)})})]}),(0,r.jsx)(g.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(et).forEach(l=>{let[s,t]=l,a=document.querySelector('input[name="'.concat(s,'"]'));console.log("key",s),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[s]=r}),console.log("updatedAlertToWebhooks",e);let s={general_settings:{alert_to_webhook_url:e,alert_types:P}};console.log("payload",s);try{(0,x.K_)(l,s)}catch(e){N.ZP.error("Failed to update alerts: "+e,20)}N.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(g.Z,{onClick:()=>(0,x.jE)(l,"slack"),className:"mx-2",children:"Test Alerts"})]})}),(0,r.jsx)(eD.Z,{children:(0,r.jsx)(lu,{accessToken:l,premiumUser:a})}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(lx,{level:4,children:"Email Settings"}),(0,r.jsxs)(b.Z,{children:[(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/email",target:"_blank",style:{color:"blue"},children:" LiteLLM Docs: email alerts"})," ",(0,r.jsx)("br",{})]}),(0,r.jsx)("div",{className:"flex w-full",children:d.filter(e=>"email"===e.name).map((e,l)=>{var s;return(0,r.jsx)(X.Z,{children:(0,r.jsx)("ul",{children:(0,r.jsx)(j.Z,{numItems:2,children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).map(e=>{let[l,s]=e;return(0,r.jsxs)("li",{className:"mx-2 my-2",children:[!0!=a&&("EMAIL_LOGO_URL"===l||"EMAIL_SUPPORT_CONTACT"===l)?(0,r.jsxs)("div",{children:[(0,r.jsx)("a",{href:"https://forms.gle/W3U4PZpJGFHWtHyA9",target:"_blank",children:(0,r.jsxs)(b.Z,{className:"mt-2",children:[" ","✨ ",l]})}),(0,r.jsx)(f.Z,{name:l,defaultValue:s,type:"password",disabled:!0,style:{width:"400px"}})]}):(0,r.jsxs)("div",{children:[(0,r.jsx)(b.Z,{className:"mt-2",children:l}),(0,r.jsx)(f.Z,{name:l,defaultValue:s,type:"password",style:{width:"400px"}})]}),(0,r.jsxs)("p",{style:{fontSize:"small",fontStyle:"italic"},children:["SMTP_HOST"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP host address, e.g. `smtp.resend.com`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PORT"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP port number, e.g. `587`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_USERNAME"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the SMTP username, e.g. `username`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"SMTP_PASSWORD"===l&&(0,r.jsx)("span",{style:{color:"red"},children:" Required * "}),"SMTP_SENDER_EMAIL"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Enter the sender email address, e.g. `[email protected]`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"TEST_EMAIL_ADDRESS"===l&&(0,r.jsxs)("div",{style:{color:"gray"},children:["Email Address to send `Test Email Alert` to. example: `[email protected]`",(0,r.jsx)("span",{style:{color:"red"},children:" Required * "})]}),"EMAIL_LOGO_URL"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the Logo that appears in the email, pass a url to your logo"}),"EMAIL_SUPPORT_CONTACT"===l&&(0,r.jsx)("div",{style:{color:"gray"},children:"(Optional) Customize the support email address that appears in the email. Default is [email protected]"})]})]},l)})})})},l)})}),(0,r.jsx)(g.Z,{className:"mt-2",onClick:()=>er(),children:"Save Changes"}),(0,r.jsx)(g.Z,{onClick:()=>(0,x.jE)(l,"email"),className:"mx-2",children:"Test Email Alerts"})]})})]})]})}),(0,r.jsxs)(C.Z,{title:"Add Logging Callback",visible:O,width:800,onCancel:()=>D(!1),footer:null,children:[(0,r.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,r.jsx)(k.Z,{form:h,onFinish:ei,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(lh.Z,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(S.default,{onChange:e=>{let l=M[e];l&&(console.log(l.ui_callback_name),eo(l))},children:M&&Object.values(M).map(e=>(0,r.jsx)(es.Z,{value:e.litellm_callback_name,children:e.ui_callback_name},e.litellm_callback_name))})}),U&&U.map(e=>(0,r.jsx)(lh.Z,{label:e,name:e,rules:[{required:!0,message:"Please enter the value for "+e}],children:(0,r.jsx)(f.Z,{type:"password"})},e)),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Save"})})]})})]}),(0,r.jsx)(C.Z,{visible:V,width:800,title:"Edit ".concat(null==K?void 0:K.name," Settings"),onCancel:()=>q(!1),footer:null,children:(0,r.jsxs)(k.Z,{form:h,onFinish:en,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(r.Fragment,{children:K&&K.variables&&Object.entries(K.variables).map(e=>{let[l,s]=e;return(0,r.jsx)(lh.Z,{label:l,name:l,children:(0,r.jsx)(f.Z,{type:"password",defaultValue:s})},l)})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null},lg=s(92414),lf=s(46030);let{Option:lZ}=S.default;var l_=e=>{let{models:l,accessToken:s,routerSettings:t,setRouterSettings:a}=e,[i]=k.Z.useForm(),[o,d]=(0,n.useState)(!1),[c,m]=(0,n.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(g.Z,{className:"mx-auto",onClick:()=>d(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(C.Z,{title:"Add Fallbacks",visible:o,width:800,footer:null,onOk:()=>{d(!1),i.resetFields()},onCancel:()=>{d(!1),i.resetFields()},children:(0,r.jsxs)(k.Z,{form:i,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,n=[...t.fallbacks||[],{[l]:r}],o={...t,fallbacks:n};console.log(o);try{(0,x.K_)(s,{router_settings:o}),a(o)}catch(e){N.ZP.error("Failed to update router settings: "+e,20)}N.ZP.success("router settings updated successfully"),d(!1),i.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(el.Z,{defaultValue:c,children:l&&l.map((e,l)=>(0,r.jsx)(es.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(k.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(lg.Z,{value:l,children:l&&l.filter(e=>e!=c).map(e=>(0,r.jsx)(lf.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},ly=s(33619);async function lb(e,l){console.log=function(){},console.log("isLocal:",!1);let s=window.location.origin,t=new ly.ZP.OpenAI({apiKey:l,baseURL:s,dangerouslyAllowBrowser:!0});try{let l=await t.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});N.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See"," ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){N.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}let lv={ttl:3600,lowest_latency_buffer:0},lw=e=>{let{selectedStrategy:l,strategyArgs:s,paramExplanation:t}=e;return(0,r.jsxs)(Z.Z,{children:[(0,r.jsx)(y.Z,{className:"text-sm font-medium text-tremor-content-strong dark:text-dark-tremor-content-strong",children:"Routing Strategy Specific Args"}),(0,r.jsx)(_.Z,{children:"latency-based-routing"==l?(0,r.jsx)(H.Z,{children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Setting"}),(0,r.jsx)(Q.Z,{children:"Value"})]})}),(0,r.jsx)(J.Z,{children:Object.entries(s).map(e=>{let[l,s]=e;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(b.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:t[l]})]}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(f.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]})}):(0,r.jsx)(b.Z,{children:"No specific settings"})})]})};var lS=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[i,o]=(0,n.useState)({}),[d,c]=(0,n.useState)({}),[m,u]=(0,n.useState)([]),[h,Z]=(0,n.useState)(!1),[_]=k.Z.useForm(),[y,w]=(0,n.useState)(null),[S,C]=(0,n.useState)(null),[I,P]=(0,n.useState)(null),E={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,n.useEffect)(()=>{l&&s&&t&&((0,x.BL)(l,t,s).then(e=>{console.log("callbacks",e);let l=e.router_settings;"model_group_retry_policy"in l&&delete l.model_group_retry_policy,o(l)}),(0,x.YU)(l).then(e=>{u(e)}))},[l,s,t]);let T=async e=>{if(l){console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(i.fallbacks)),i.fallbacks.map(l=>(e in l&&delete l[e],l));try{await (0,x.K_)(l,{router_settings:i}),o({...i}),C(i.routing_strategy),N.ZP.success("Router settings updated successfully")}catch(e){N.ZP.error("Failed to update router settings: "+e,20)}}},O=(e,l)=>{u(m.map(s=>s.field_name===e?{...s,field_value:l}:s))},D=(e,s)=>{if(!l)return;let t=m[s].field_value;if(null!=t&&void 0!=t)try{(0,x.jA)(l,e,t);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:!0}:l);u(s)}catch(e){}},M=(e,s)=>{if(l)try{(0,x.ao)(l,e);let s=m.map(l=>l.field_name===e?{...l,stored_in_db:null,field_value:null}:l);u(s)}catch(e){}},F=e=>{if(!l)return;console.log("router_settings",e);let s=Object.fromEntries(Object.entries(e).map(e=>{let[l,s]=e;if("routing_strategy_args"!==l&&"routing_strategy"!==l){var t;return[l,(null===(t=document.querySelector('input[name="'.concat(l,'"]')))||void 0===t?void 0:t.value)||s]}if("routing_strategy"==l)return[l,S];if("routing_strategy_args"==l&&"latency-based-routing"==S){let e={},l=document.querySelector('input[name="lowest_latency_buffer"]'),s=document.querySelector('input[name="ttl"]');return(null==l?void 0:l.value)&&(e.lowest_latency_buffer=Number(l.value)),(null==s?void 0:s.value)&&(e.ttl=Number(s.value)),console.log("setRoutingStrategyArgs: ".concat(e)),["routing_strategy_args",e]}return null}).filter(e=>null!=e));console.log("updatedVariables",s);try{(0,x.K_)(l,{router_settings:s})}catch(e){N.ZP.error("Failed to update router settings: "+e,20)}N.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eT.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eO.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Loadbalancing"}),(0,r.jsx)(eE.Z,{value:"2",children:"Fallbacks"}),(0,r.jsx)(eE.Z,{value:"3",children:"General"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(v.Z,{children:"Router Settings"}),(0,r.jsxs)(H.Z,{children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Setting"}),(0,r.jsx)(Q.Z,{children:"Value"})]})}),(0,r.jsx)(J.Z,{children:Object.entries(i).filter(e=>{let[l,s]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l&&"routing_strategy_args"!=l}).map(e=>{let[l,s]=e;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(b.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:E[l]})]}),(0,r.jsx)(X.Z,{children:"routing_strategy"==l?(0,r.jsxs)(el.Z,{defaultValue:s,className:"w-full max-w-md",onValueChange:C,children:[(0,r.jsx)(es.Z,{value:"usage-based-routing",children:"usage-based-routing"}),(0,r.jsx)(es.Z,{value:"latency-based-routing",children:"latency-based-routing"}),(0,r.jsx)(es.Z,{value:"simple-shuffle",children:"simple-shuffle"})]}):(0,r.jsx)(f.Z,{name:l,defaultValue:"object"==typeof s?JSON.stringify(s,null,2):s.toString()})})]},l)})})]}),(0,r.jsx)(lw,{selectedStrategy:S,strategyArgs:i&&i.routing_strategy_args&&Object.keys(i.routing_strategy_args).length>0?i.routing_strategy_args:lv,paramExplanation:E})]}),(0,r.jsx)(p.Z,{children:(0,r.jsx)(g.Z,{className:"mt-2",onClick:()=>F(i),children:"Save Changes"})})]})}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Model Name"}),(0,r.jsx)(Q.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(J.Z,{children:i.fallbacks&&i.fallbacks.map((e,s)=>Object.entries(e).map(e=>{let[t,a]=e;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:t}),(0,r.jsx)(X.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(g.Z,{onClick:()=>lb(t,l),children:"Test Fallback"})}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(Y.Z,{icon:K.Z,size:"sm",onClick:()=>T(t)})})]},s.toString()+t)}))})]}),(0,r.jsx)(l_,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:i,setRouterSettings:o})]}),(0,r.jsx)(eD.Z,{children:(0,r.jsx)(H.Z,{children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Setting"}),(0,r.jsx)(Q.Z,{children:"Value"}),(0,r.jsx)(Q.Z,{children:"Status"}),(0,r.jsx)(Q.Z,{children:"Action"})]})}),(0,r.jsx)(J.Z,{children:m.filter(e=>"TypedDictionary"!==e.field_type).map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(b.Z,{children:e.field_name}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:e.field_description})]}),(0,r.jsx)(X.Z,{children:"Integer"==e.field_type?(0,r.jsx)(A.Z,{step:1,value:e.field_value,onChange:l=>O(e.field_name,l)}):null}),(0,r.jsx)(X.Z,{children:!0==e.stored_in_db?(0,r.jsx)(W.Z,{icon:lc.Z,className:"text-white",children:"In DB"}):!1==e.stored_in_db?(0,r.jsx)(W.Z,{className:"text-gray bg-white outline",children:"In Config"}):(0,r.jsx)(W.Z,{className:"text-gray bg-white outline",children:"Not Set"})}),(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(g.Z,{onClick:()=>D(e.field_name,l),children:"Update"}),(0,r.jsx)(Y.Z,{icon:K.Z,color:"red",onClick:()=>M(e.field_name,l),children:"Reset"})]})]},l))})]})})})]})]})}):null},lk=s(93142),lN=s(45246),lC=s(96473),lI=e=>{let{value:l={},onChange:s}=e,[t,a]=(0,n.useState)(Object.entries(l)),i=e=>{let l=t.filter((l,s)=>s!==e);a(l),null==s||s(Object.fromEntries(l))},o=(e,l,r)=>{let n=[...t];n[e]=[l,r],a(n),null==s||s(Object.fromEntries(n))};return(0,r.jsxs)("div",{children:[t.map((e,l)=>{let[s,t]=e;return(0,r.jsxs)(lk.Z,{style:{display:"flex",marginBottom:8},align:"start",children:[(0,r.jsx)(f.Z,{placeholder:"Header Name",value:s,onChange:e=>o(l,e.target.value,t)}),(0,r.jsx)(f.Z,{placeholder:"Header Value",value:t,onChange:e=>o(l,s,e.target.value)}),(0,r.jsx)(lN.Z,{onClick:()=>i(l)})]},l)}),(0,r.jsx)(E.ZP,{type:"dashed",onClick:()=>{a([...t,["",""]])},icon:(0,r.jsx)(lC.Z,{}),children:"Add Header"})]})};let{Option:lA}=S.default;var lP=e=>{let{accessToken:l,setPassThroughItems:s,passThroughItems:t}=e,[a]=k.Z.useForm(),[i,o]=(0,n.useState)(!1),[d,c]=(0,n.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(g.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Add Pass-Through Endpoint"}),(0,r.jsx)(C.Z,{title:"Add Pass-Through Endpoint",visible:i,width:800,footer:null,onOk:()=>{o(!1),a.resetFields()},onCancel:()=>{o(!1),a.resetFields()},children:(0,r.jsxs)(k.Z,{form:a,onFinish:e=>{console.log(e);let r=[...t,{headers:e.headers,path:e.path,target:e.target}];try{(0,x.Vt)(l,e),s(r)}catch(e){N.ZP.error("Failed to update router settings: "+e,20)}N.ZP.success("Pass through endpoint successfully added"),o(!1),a.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.Z.Item,{label:"Path",name:"path",rules:[{required:!0,message:"The route to be added to the LiteLLM Proxy Server."}],help:"required",children:(0,r.jsx)(f.Z,{})}),(0,r.jsx)(k.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,r.jsx)(f.Z,{})}),(0,r.jsx)(k.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,r.jsx)(lI,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Add Pass-Through Endpoint"})})]})})]})},lE=e=>{let{accessToken:l,userRole:s,userID:t,modelData:a}=e,[i,o]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&s&&t&&(0,x.mp)(l).then(e=>{o(e.endpoints)})},[l,s,t]);let d=(e,s)=>{if(l)try{(0,x.EG)(l,e);let s=i.filter(l=>l.path!==e);o(s),N.ZP.success("Endpoint deleted successfully.")}catch(e){}};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(eT.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(H.Z,{children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Path"}),(0,r.jsx)(Q.Z,{children:"Target"}),(0,r.jsx)(Q.Z,{children:"Headers"}),(0,r.jsx)(Q.Z,{children:"Action"})]})}),(0,r.jsx)(J.Z,{children:i.map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:(0,r.jsx)(b.Z,{children:e.path})}),(0,r.jsx)(X.Z,{children:e.target}),(0,r.jsx)(X.Z,{children:JSON.stringify(e.headers)}),(0,r.jsx)(X.Z,{children:(0,r.jsx)(Y.Z,{icon:K.Z,color:"red",onClick:()=>d(e.path,l),children:"Reset"})})]},l))})]}),(0,r.jsx)(lP,{accessToken:l,setPassThroughItems:o,passThroughItems:i})]})})}):null},lT=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a}=e,[n]=k.Z.useForm(),i=async e=>{if(null!=s&&void 0!=s)try{N.ZP.info("Making API Call");let l=await (0,x.Zr)(s,e);console.log("key create Response:",l),a(e=>e?[...e,l]:[l]),N.ZP.success("API Key Created"),n.resetFields()}catch(e){console.error("Error creating the key:",e),N.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(C.Z,{title:"Create Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),n.resetFields()},onCancel:()=>{t(!1),n.resetFields()},children:(0,r.jsxs)(k.Z,{form:n,onFinish:i,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.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,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(A.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(A.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(y.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(k.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(A.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(S.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(S.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(S.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(S.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Create Budget"})})]})})},lO=e=>{let{isModalVisible:l,accessToken:s,setIsModalVisible:t,setBudgetList:a,existingBudget:i,handleUpdateCall:o}=e;console.log("existingBudget",i);let[d]=k.Z.useForm();(0,n.useEffect)(()=>{d.setFieldsValue(i)},[i,d]);let c=async e=>{if(null!=s&&void 0!=s)try{N.ZP.info("Making API Call"),t(!0);let l=await (0,x.qI)(s,e);a(e=>e?[...e,l]:[l]),N.ZP.success("Budget Updated"),d.resetFields(),o()}catch(e){console.error("Error creating the key:",e),N.ZP.error("Error creating the key: ".concat(e),20)}};return(0,r.jsx)(C.Z,{title:"Edit Budget",visible:l,width:800,footer:null,onOk:()=>{t(!1),d.resetFields()},onCancel:()=>{t(!1),d.resetFields()},children:(0,r.jsxs)(k.Z,{form:d,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",initialValues:i,children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(k.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,r.jsx)(f.Z,{placeholder:""})}),(0,r.jsx)(k.Z.Item,{label:"Max Tokens per minute",name:"tpm_limit",help:"Default is model limit.",children:(0,r.jsx)(A.Z,{step:1,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{label:"Max Requests per minute",name:"rpm_limit",help:"Default is model limit.",children:(0,r.jsx)(A.Z,{step:1,precision:2,width:200})}),(0,r.jsxs)(Z.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(y.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(_.Z,{children:[(0,r.jsx)(k.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(A.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(k.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",children:(0,r.jsxs)(S.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(S.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(S.default.Option,{value:"7d",children:"weekly"}),(0,r.jsx)(S.default.Option,{value:"30d",children:"monthly"})]})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(E.ZP,{htmlType:"submit",children:"Save"})})]})})},lD=e=>{let{accessToken:l}=e,[s,t]=(0,n.useState)(!1),[a,i]=(0,n.useState)(!1),[o,d]=(0,n.useState)(null),[c,m]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&(0,x.O3)(l).then(e=>{m(e)})},[l]);let u=async(e,s)=>{console.log("budget_id",e),null!=l&&(d(c.find(l=>l.budget_id===e)||null),i(!0))},h=async(e,s)=>{if(null==l)return;N.ZP.info("Request made"),await (0,x.NV)(l,e);let t=[...c];t.splice(s,1),m(t),N.ZP.success("Budget Deleted.")},p=async()=>{null!=l&&(0,x.O3)(l).then(e=>{m(e)})};return(0,r.jsxs)("div",{className:"w-full mx-auto flex-auto overflow-y-auto m-8 p-2",children:[(0,r.jsx)(g.Z,{size:"sm",variant:"primary",className:"mb-2",onClick:()=>t(!0),children:"+ Create Budget"}),(0,r.jsx)(lT,{accessToken:l,isModalVisible:s,setIsModalVisible:t,setBudgetList:m}),o&&(0,r.jsx)(lO,{accessToken:l,isModalVisible:a,setIsModalVisible:i,setBudgetList:m,existingBudget:o,handleUpdateCall:p}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(b.Z,{children:"Create a budget to assign to customers."}),(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Budget ID"}),(0,r.jsx)(Q.Z,{children:"Max Budget"}),(0,r.jsx)(Q.Z,{children:"TPM"}),(0,r.jsx)(Q.Z,{children:"RPM"})]})}),(0,r.jsx)(J.Z,{children:c.slice().sort((e,l)=>new Date(l.updated_at).getTime()-new Date(e.updated_at).getTime()).map((e,l)=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.budget_id}),(0,r.jsx)(X.Z,{children:e.max_budget?e.max_budget:"n/a"}),(0,r.jsx)(X.Z,{children:e.tpm_limit?e.tpm_limit:"n/a"}),(0,r.jsx)(X.Z,{children:e.rpm_limit?e.rpm_limit:"n/a"}),(0,r.jsx)(Y.Z,{icon:B.Z,size:"sm",onClick:()=>u(e.budget_id,l)}),(0,r.jsx)(Y.Z,{icon:K.Z,size:"sm",onClick:()=>h(e.budget_id,l)})]},l))})]})]}),(0,r.jsxs)("div",{className:"mt-5",children:[(0,r.jsx)(b.Z,{className:"text-base",children:"How to use budget id"}),(0,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{children:[(0,r.jsx)(eE.Z,{children:"Assign Budget to Customer"}),(0,r.jsx)(eE.Z,{children:"Test it (Curl)"}),(0,r.jsx)(eE.Z,{children:"Test it (OpenAI SDK)"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsx)(eK.Z,{language:"bash",children:"\ncurl -X POST --location '<your_proxy_base_url>/end_user/new' \n-H 'Authorization: Bearer <your-master-key>' \n-H 'Content-Type: application/json' \n-d '{\"user_id\": \"my-customer-id', \"budget_id\": \"<BUDGET_ID>\"}' # \uD83D\uDC48 KEY CHANGE\n\n "})}),(0,r.jsx)(eD.Z,{children:(0,r.jsx)(eK.Z,{language:"bash",children:'\ncurl -X POST --location \'<your_proxy_base_url>/chat/completions\' \n-H \'Authorization: Bearer <your-master-key>\' \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,r.jsx)(eD.Z,{children:(0,r.jsx)(eK.Z,{language:"python",children:'from openai import OpenAI\nclient = OpenAI(\n base_url="<your_proxy_base_url>",\n api_key="<your_proxy_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)'})})]})]})]})]})},lM=s(77398),lF=s.n(lM),lR=s(20016),lL=s(71594),lU=s(24525);function lz(e){let{data:l=[],columns:s,getRowCanExpand:t,renderSubComponent:a,isLoading:i=!1}=e,o=(0,lL.b7)({data:l,columns:s,getRowCanExpand:t,getCoreRowModel:(0,lU.sC)(),getExpandedRowModel:(0,lU.rV)()});return(0,r.jsx)("div",{className:"rounded-lg custom-border table-wrapper",children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:o.getHeaderGroups().map(e=>(0,r.jsx)(ee.Z,{children:e.headers.map(e=>(0,r.jsx)(Q.Z,{children:e.isPlaceholder?null:(0,lL.ie)(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,r.jsx)(J.Z,{children:i?(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{colSpan:s.length,className:"h-24 text-center",children:(0,r.jsx)("div",{className:"p-8 text-center text-gray-500",children:(0,r.jsx)("p",{children:"\uD83D\uDE85 Loading logs..."})})})}):o.getRowModel().rows.length>0?o.getRowModel().rows.map(e=>(0,r.jsxs)(n.Fragment,{children:[(0,r.jsx)(ee.Z,{children:e.getVisibleCells().map(e=>(0,r.jsx)(X.Z,{children:(0,lL.ie)(e.column.columnDef.cell,e.getContext())},e.id))}),e.getIsExpanded()&&(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{colSpan:e.getVisibleCells().length,children:a({row:e})})})]},e.id)):(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{colSpan:s.length,className:"h-24 text-center",children:(0,r.jsx)("div",{className:"p-8 text-center text-gray-500",children:(0,r.jsx)("p",{children:"No logs found"})})})})})]})})}async function lV(e){try{let l=await fetch("http://ip-api.com/json/".concat(e)),s=await l.json();console.log("ip lookup data",s);let t=s.countryCode?s.countryCode.toUpperCase().split("").map(e=>String.fromCodePoint(e.charCodeAt(0)+127397)).join(""):"";return s.country?"".concat(t," ").concat(s.country):"Unknown"}catch(e){return console.error("Error looking up IP:",e),"Unknown"}}let lB=e=>{let{ipAddress:l}=e,[s,t]=n.useState("-");return n.useEffect(()=>{if(!l)return;let e=!0;return lV(l).then(l=>{e&&t(l)}).catch(()=>{e&&t("-")}),()=>{e=!1}},[l]),(0,r.jsx)("span",{children:s})},lq=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"}},lK=e=>{let{utcTime:l}=e;return(0,r.jsx)("span",{style:{fontFamily:"monospace",width:"180px",display:"inline-block"},children:lq(l)})},lW=[{id:"expander",header:()=>null,cell:e=>{let{row:l}=e;return l.getCanExpand()?(0,r.jsx)("button",{onClick:l.getToggleExpandedHandler(),style:{cursor:"pointer"},children:l.getIsExpanded()?"▼":"▶"}):"●"}},{header:"Time",accessorKey:"startTime",cell:e=>(0,r.jsx)(lK,{utcTime:e.getValue()})},{header:"Request ID",accessorKey:"request_id",cell:e=>(0,r.jsx)(F.Z,{title:String(e.getValue()||""),children:(0,r.jsx)("span",{className:"font-mono text-xs max-w-[100px] truncate block",children:String(e.getValue()||"")})})},{header:"Country",accessorKey:"requester_ip_address",cell:e=>(0,r.jsx)(lB,{ipAddress:e.getValue()})},{header:"Team",accessorKey:"metadata.user_api_key_team_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Key Name",accessorKey:"metadata.user_api_key_alias",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Request",accessorKey:"messages",cell:e=>{let l=e.getValue();try{let e="string"==typeof l?JSON.parse(l):l,t="";if(Array.isArray(e)){var s;t=lH(null===(s=e[0])||void 0===s?void 0:s.content)}else t=lH(e);return(0,r.jsx)("span",{className:"truncate max-w-md text-sm",children:t})}catch(e){return(0,r.jsx)("span",{className:"truncate max-w-md text-sm",children:lH(l)})}}},{header:"Model",accessorKey:"model",cell:e=>{let l=e.row.original.custom_llm_provider,s=String(e.getValue()||"");return(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,r.jsx)("img",{src:ef(l).logo,alt:"",className:"w-4 h-4",onError:e=>{e.target.style.display="none"}}),(0,r.jsx)(F.Z,{title:s,children:(0,r.jsx)("span",{className:"max-w-[100px] truncate",children:s})})]})}},{header:"Tokens",accessorKey:"total_tokens",cell:e=>{let l=e.row.original;return(0,r.jsxs)("span",{className:"text-sm",children:[String(l.total_tokens||"0"),(0,r.jsxs)("span",{className:"text-gray-400 text-xs ml-1",children:["(",String(l.prompt_tokens||"0"),"+",String(l.completion_tokens||"0"),")"]})]})}},{header:"Internal User",accessorKey:"user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"End User",accessorKey:"end_user",cell:e=>(0,r.jsx)("span",{children:String(e.getValue()||"-")})},{header:"Cost",accessorKey:"spend",cell:e=>(0,r.jsxs)("span",{children:["$",Number(e.getValue()||0).toFixed(6)]})},{header:"Tags",accessorKey:"request_tags",cell:e=>{let l=e.getValue();return l&&0!==Object.keys(l).length?(0,r.jsx)("div",{className:"flex flex-wrap gap-1",children:Object.entries(l).map(e=>{let[l,s]=e;return(0,r.jsxs)("span",{className:"px-2 py-1 bg-gray-100 rounded-full text-xs",children:[l,": ",String(s)]},l)})}):"-"}}],lH=e=>e?"string"==typeof e?e:"object"==typeof e?e.text?e.text:e.content?e.content:JSON.stringify(e):String(e):"N/A";function lY(e){var l,s,t;let{accessToken:a,token:i,userRole:o,userID:d}=e,[c,m]=(0,n.useState)(""),[u,h]=(0,n.useState)(!1),[p,j]=(0,n.useState)(!1),[g,f]=(0,n.useState)(1),[Z]=(0,n.useState)(50),_=(0,n.useRef)(null),y=(0,n.useRef)(null),b=(0,n.useRef)(null),[v,w]=(0,n.useState)(lF()().subtract(24,"hours").format("YYYY-MM-DDTHH:mm")),[S,k]=(0,n.useState)(lF()().format("YYYY-MM-DDTHH:mm")),[N,C]=(0,n.useState)(!1),[I,A]=(0,n.useState)(!1),[P,E]=(0,n.useState)(""),[T,O]=(0,n.useState)(""),[D,M]=(0,n.useState)(""),[F,R]=(0,n.useState)(""),[L,U]=(0,n.useState)("Team ID");(0,n.useEffect)(()=>{function e(e){_.current&&!_.current.contains(e.target)&&j(!1),y.current&&!y.current.contains(e.target)&&h(!1),b.current&&!b.current.contains(e.target)&&A(!1)}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let z=(0,lR.a)({queryKey:["logs","table",g,Z,v,S,D,F],queryFn:async()=>{if(!a||!i||!o||!d)return console.log("Missing required auth parameters"),{data:[],total:0,page:1,page_size:Z,total_pages:0};let e=lF()(v).utc().format("YYYY-MM-DD HH:mm:ss"),l=N?lF()(S).utc().format("YYYY-MM-DD HH:mm:ss"):lF()().utc().format("YYYY-MM-DD HH:mm:ss");return await (0,x.h3)(a,F||void 0,D||void 0,void 0,e,l,g,Z)},enabled:!!a&&!!i&&!!o&&!!d,refetchInterval:5e3,refetchIntervalInBackground:!0});if(!a||!i||!o||!d)return console.log("got None values for one of accessToken, token, userRole, userID"),null;let V=(null===(s=z.data)||void 0===s?void 0:null===(l=s.data)||void 0===l?void 0:l.filter(e=>!c||e.request_id.includes(c)||e.model.includes(c)||e.user&&e.user.includes(c)))||[],B=()=>{if(N)return"".concat(lF()(v).format("MMM D, h:mm A")," - ").concat(lF()(S).format("MMM D, h:mm A"));let e=lF()(),l=lF()(v),s=e.diff(l,"minutes");if(s<=15)return"Last 15 Minutes";if(s<=60)return"Last Hour";let t=e.diff(l,"hours");return t<=4?"Last 4 Hours":t<=24?"Last 24 Hours":t<=168?"Last 7 Days":"".concat(l.format("MMM D")," - ").concat(e.format("MMM D"))};return(0,r.jsxs)("div",{className:"w-full p-6",children:[(0,r.jsx)("div",{className:"flex items-center justify-between mb-4",children:(0,r.jsx)("h1",{className:"text-xl font-semibold",children:"Request Logs"})}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"border-b px-6 py-4",children:(0,r.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,r.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,r.jsxs)("div",{className:"relative w-64",children:[(0,r.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:c,onChange:e=>m(e.target.value)}),(0,r.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,r.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,r.jsxs)("div",{className:"relative",ref:y,children:[(0,r.jsxs)("button",{className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",onClick:()=>h(!u),children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})}),"Filter"]}),u&&(0,r.jsx)("div",{className:"absolute left-0 mt-2 w-[500px] bg-white rounded-lg shadow-lg border p-4 z-50",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Where"}),(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsxs)("button",{onClick:()=>j(!p),className:"px-3 py-1.5 border rounded-md bg-white text-sm min-w-[160px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-left flex justify-between items-center",children:[L,(0,r.jsx)("svg",{className:"h-4 w-4 text-gray-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),p&&(0,r.jsx)("div",{className:"absolute left-0 mt-1 w-[160px] bg-white border rounded-md shadow-lg z-50",children:["Team ID","Key Hash"].map(e=>(0,r.jsxs)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 flex items-center gap-2 ".concat(L===e?"bg-blue-50 text-blue-600":""),onClick:()=>{U(e),j(!1),"Team ID"===e?O(""):E("")},children:[L===e&&(0,r.jsx)("svg",{className:"h-4 w-4 text-blue-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e]},e))})]}),(0,r.jsx)("input",{type:"text",placeholder:"Enter value...",className:"px-3 py-1.5 border rounded-md text-sm flex-1 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:"Team ID"===L?P:T,onChange:e=>{"Team ID"===L?E(e.target.value):O(e.target.value)}}),(0,r.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded-md",onClick:()=>{E(""),O("")},children:(0,r.jsx)("span",{className:"text-gray-500",children:"\xd7"})})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm border rounded-md hover:bg-gray-50",onClick:()=>{E(""),O(""),h(!1)},children:"Cancel"}),(0,r.jsx)("button",{className:"px-3 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700",onClick:()=>{M(P),R(T),f(1),h(!1)},children:"Apply Filters"})]})]})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"relative",ref:b,children:[(0,r.jsxs)("button",{onClick:()=>A(!I),className:"px-3 py-2 text-sm border rounded-md hover:bg-gray-50 flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})}),B()]}),I&&(0,r.jsx)("div",{className:"absolute right-0 mt-2 w-64 bg-white rounded-lg shadow-lg border p-2 z-50",children:(0,r.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,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(B()===e.label?"bg-blue-50 text-blue-600":""),onClick:()=>{k(lF()().format("YYYY-MM-DDTHH:mm")),w(lF()().subtract(e.value,e.unit).format("YYYY-MM-DDTHH:mm")),A(!1),C(!1)},children:e.label},e.label)),(0,r.jsx)("div",{className:"border-t my-2"}),(0,r.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm hover:bg-gray-50 rounded-md ".concat(N?"bg-blue-50 text-blue-600":""),onClick:()=>C(!N),children:"Custom Range"})]})})]}),(0,r.jsxs)("button",{onClick:()=>{z.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,r.jsx)("svg",{className:"w-4 h-4 ".concat(z.isFetching?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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,r.jsx)("span",{children:"Refresh"})]})]}),N&&(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:v,onChange:e=>{w(e.target.value),f(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,r.jsx)("span",{className:"text-gray-500",children:"to"}),(0,r.jsx)("div",{children:(0,r.jsx)("input",{type:"datetime-local",value:S,onChange:e=>{k(e.target.value),f(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,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Showing"," ",z.isLoading?"...":z.data?(g-1)*Z+1:0," ","-"," ",z.isLoading?"...":z.data?Math.min(g*Z,z.data.total):0," ","of"," ",z.isLoading?"...":z.data?z.data.total:0," ","results"]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsxs)("span",{className:"text-sm text-gray-700",children:["Page ",z.isLoading?"...":g," of"," ",z.isLoading?"...":z.data?z.data.total_pages:1]}),(0,r.jsx)("button",{onClick:()=>f(e=>Math.max(1,e-1)),disabled:z.isLoading||1===g,className:"px-3 py-1 text-sm border rounded-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed",children:"Previous"}),(0,r.jsx)("button",{onClick:()=>f(e=>{var l;return Math.min((null===(l=z.data)||void 0===l?void 0:l.total_pages)||1,e+1)}),disabled:z.isLoading||g===((null===(t=z.data)||void 0===t?void 0:t.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,r.jsx)(lz,{columns:lW,data:V,renderSubComponent:lG,getRowCanExpand:()=>!0})]})]})}function lG(e){var l,s;let{row:t}=e,a=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){}return e};return(0,r.jsxs)("div",{className:"p-6 bg-gray-50 space-y-6",children:[(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium ",children:"Request Details"})}),(0,r.jsxs)("div",{className:"space-y-2 p-4 ",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request ID:"}),(0,r.jsx)("span",{children:t.original.request_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Api Key:"}),(0,r.jsx)("span",{children:t.original.api_key})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Team ID:"}),(0,r.jsx)("span",{children:t.original.team_id})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Model:"}),(0,r.jsx)("span",{children:t.original.model})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Api Base:"}),(0,r.jsx)("span",{children:t.original.api_base})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Call Type:"}),(0,r.jsx)("span",{children:t.original.call_type})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Spend:"}),(0,r.jsx)("span",{children:t.original.spend})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Total Tokens:"}),(0,r.jsx)("span",{children:t.original.total_tokens})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Prompt Tokens:"}),(0,r.jsx)("span",{children:t.original.prompt_tokens})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Completion Tokens:"}),(0,r.jsx)("span",{children:t.original.completion_tokens})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Start Time:"}),(0,r.jsx)("span",{children:t.original.startTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"End Time:"}),(0,r.jsx)("span",{children:t.original.endTime})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Hit:"}),(0,r.jsx)("span",{children:t.original.cache_hit})]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Cache Key:"}),(0,r.jsx)("span",{children:t.original.cache_key})]}),(null==t?void 0:null===(l=t.original)||void 0===l?void 0:l.requester_ip_address)&&(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"font-medium w-1/3",children:"Request IP Address:"}),(0,r.jsx)("span",{children:null==t?void 0:null===(s=t.original)||void 0===s?void 0:s.requester_ip_address})]})]})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request Tags"})}),(0,r.jsx)("pre",{className:"p-4 text-wrap overflow-auto text-sm",children:JSON.stringify(a(t.original.request_tags),null,2)})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Request"})}),(0,r.jsx)("pre",{className:"p-4 text-wrap overflow-auto text-sm",children:JSON.stringify(a(t.original.messages),null,2)})]}),(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center p-4 border-b",children:[(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Response"}),(0,r.jsx)("div",{})]}),(0,r.jsx)("pre",{className:"p-4 text-wrap overflow-auto text-sm",children:JSON.stringify(a(t.original.response),null,2)})]}),t.original.metadata&&Object.keys(t.original.metadata).length>0&&(0,r.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,r.jsx)("div",{className:"flex justify-between items-center p-4 border-b",children:(0,r.jsx)("h3",{className:"text-lg font-medium",children:"Metadata"})}),(0,r.jsx)("pre",{className:"p-4 text-wrap overflow-auto text-sm ",children:JSON.stringify(t.original.metadata,null,2)})]})]})}var lJ=s(92699),lX=e=>{let{proxySettings:l}=e,s="<your_proxy_base_url>";return l&&l.PROXY_BASE_URL&&void 0!==l.PROXY_BASE_URL&&(s=l.PROXY_BASE_URL),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(j.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(b.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,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{children:[(0,r.jsx)(eE.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eE.Z,{children:"LlamaIndex"}),(0,r.jsx)(eE.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsx)(eK.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="'.concat(s,'" # 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,r.jsx)(eD.Z,{children:(0,r.jsx)(eK.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(s,'", # 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(s,'",\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,r.jsx)(eD.Z,{children:(0,r.jsx)(eK.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(s,'",\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 ')})})]})]})]})})})},l$=s(243),lQ=s(94263);async function l0(e,l,s,t){console.log=function(){},console.log("isLocal:",!1);let a=window.location.origin,r=new ly.ZP.OpenAI({apiKey:t,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let t of(await r.chat.completions.create({model:s,stream:!0,messages:e})))console.log(t),t.choices[0].delta.content&&l(t.choices[0].delta.content,t.model)}catch(e){N.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var l1=e=>{let{accessToken:l,token:s,userRole:t,userID:a,disabledPersonalKeyCreation:i}=e,[o,d]=(0,n.useState)(i?"custom":"session"),[c,m]=(0,n.useState)(""),[u,h]=(0,n.useState)(""),[Z,_]=(0,n.useState)([]),[y,v]=(0,n.useState)(void 0),[w,k]=(0,n.useState)([]),C=(0,n.useRef)(null);(0,n.useEffect)(()=>{l&&s&&t&&a&&(async()=>{try{let e=await (0,x.So)(l,a,t);if(console.log("model_info:",e),(null==e?void 0:e.data.length)>0){let l=new Map;e.data.forEach(e=>{l.set(e.id,{value:e.id,label:e.id})});let s=Array.from(l.values());s.sort((e,l)=>e.label.localeCompare(l.label)),k(s),v(s[0].value)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,t]),(0,n.useEffect)(()=>{C.current&&setTimeout(()=>{var e;null===(e=C.current)||void 0===e||e.scrollIntoView({behavior:"smooth",block:"end"})},100)},[Z]);let I=(e,l,s)=>{_(t=>{let a=t[t.length-1];return a&&a.role===e?[...t.slice(0,t.length-1),{role:e,content:a.content+l,model:s}]:[...t,{role:e,content:l,model:s}]})},A=async()=>{if(""===u.trim()||!s||!t||!a)return;let e="session"===o?l:c;if(!e){N.ZP.error("Please provide an API key or select Current UI Session");return}let r={role:"user",content:u},n=[...Z.map(e=>{let{role:l,content:s}=e;return{role:l,content:s}}),r];_([...Z,r]);try{y&&await l0(n,(e,l)=>I("assistant",e,l),y,e)}catch(e){console.error("Error fetching model response",e),I("assistant","Error fetching model response")}h("")};if(t&&"Admin Viewer"===t){let{Title:e,Paragraph:l}=ec.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(j.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(H.Z,{children:(0,r.jsxs)(eT.Z,{children:[(0,r.jsx)(eO.Z,{children:(0,r.jsx)(eE.Z,{children:"Chat"})}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)("div",{className:"sm:max-w-2xl",children:[(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsxs)(p.Z,{children:[(0,r.jsx)(b.Z,{children:"API Key Source"}),(0,r.jsx)(S.default,{disabled:i,defaultValue:"session",style:{width:"100%"},onChange:e=>d(e),options:[{value:"session",label:"Current UI Session"},{value:"custom",label:"Virtual Key"}]}),"custom"===o&&(0,r.jsx)(f.Z,{className:"mt-2",placeholder:"Enter custom API key",type:"password",onValueChange:m,value:c})]}),(0,r.jsxs)(p.Z,{className:"mx-2",children:[(0,r.jsx)(b.Z,{children:"Select Model:"}),(0,r.jsx)(S.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),v(e)},options:w,style:{width:"350px"},showSearch:!0})]})]}),(0,r.jsx)(g.Z,{onClick:()=>{_([]),N.ZP.success("Chat history cleared.")},className:"mt-4",children:"Clear Chat"})]}),(0,r.jsxs)(G.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)($.Z,{children:(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{})})}),(0,r.jsxs)(J.Z,{children:[Z.map((e,l)=>(0,r.jsx)(ee.Z,{children:(0,r.jsxs)(X.Z,{children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},children:[(0,r.jsx)("strong",{children:e.role}),"assistant"===e.role&&e.model&&(0,r.jsx)("span",{style:{fontSize:"12px",color:"#666",backgroundColor:"#f5f5f5",padding:"2px 6px",borderRadius:"4px",fontWeight:"normal"},children:e.model})]}),(0,r.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",maxWidth:"100%"},children:(0,r.jsx)(l$.U,{components:{code(e){let{node:l,inline:s,className:t,children:a,...n}=e,i=/language-(\w+)/.exec(t||"");return!s&&i?(0,r.jsx)(eK.Z,{style:lQ.Z,language:i[1],PreTag:"div",...n,children:String(a).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...n,children:a})}},children:e.content})})]})},l)),(0,r.jsx)(ee.Z,{children:(0,r.jsx)(X.Z,{children:(0,r.jsx)("div",{ref:C,style:{height:"1px"}})})})]})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",style:{marginTop:"16px"},children:[(0,r.jsx)(f.Z,{type:"text",value:u,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"===e.key&&A()},placeholder:"Type your message..."}),(0,r.jsx)(g.Z,{onClick:A,className:"ml-2",children:"Send"})]})})]})})]})})})})},l2=s(19226),l4=s(61787),l5=s(92403),l8=s(28595),l3=s(68208),l6=s(9775),l7=s(41361),l9=s(37527),se=s(15883),sl=s(12660),ss=s(88009),st=s(41169),sa=s(48231),sr=s(44625),sn=s(55322);let{Sider:si}=l2.default,so=["Admin","Admin Viewer","proxy_admin","proxy_admin_viewer","org_admin"],sd=[{key:"1",page:"api-keys",label:"Virtual Keys",icon:(0,r.jsx)(l5.Z,{})},{key:"3",page:"llm-playground",label:"Test Key",icon:(0,r.jsx)(l8.Z,{})},{key:"2",page:"models",label:"Models",icon:(0,r.jsx)(l3.Z,{}),roles:so},{key:"4",page:"usage",label:"Usage",icon:(0,r.jsx)(l6.Z,{})},{key:"6",page:"teams",label:"Teams",icon:(0,r.jsx)(l7.Z,{})},{key:"17",page:"organizations",label:"Organizations",icon:(0,r.jsx)(l9.Z,{}),roles:so},{key:"5",page:"users",label:"Internal Users",icon:(0,r.jsx)(se.Z,{}),roles:so},{key:"14",page:"api_ref",label:"API Reference",icon:(0,r.jsx)(sl.Z,{})},{key:"16",page:"model-hub",label:"Model Hub",icon:(0,r.jsx)(ss.Z,{})},{key:"experimental",page:"experimental",label:"Experimental",icon:(0,r.jsx)(st.Z,{}),roles:so,children:[{key:"15",page:"logs",label:"Logs",icon:(0,r.jsx)(sa.Z,{}),roles:so},{key:"9",page:"caching",label:"Caching",icon:(0,r.jsx)(sr.Z,{}),roles:so},{key:"10",page:"budgets",label:"Budgets",icon:(0,r.jsx)(l9.Z,{}),roles:so}]},{key:"settings",page:"settings",label:"Settings",icon:(0,r.jsx)(sn.Z,{}),roles:so,children:[{key:"11",page:"general-settings",label:"Router Settings",icon:(0,r.jsx)(sn.Z,{}),roles:so},{key:"12",page:"pass-through-settings",label:"Pass-Through",icon:(0,r.jsx)(sl.Z,{}),roles:so},{key:"8",page:"settings",label:"Logging & Alerts",icon:(0,r.jsx)(sn.Z,{}),roles:so},{key:"13",page:"admin-panel",label:"Admin Settings",icon:(0,r.jsx)(sn.Z,{}),roles:so}]}];var sc=e=>{let{setPage:l,userRole:s,defaultSelectedKey:t}=e,a=(e=>{let l=sd.find(l=>l.page===e);if(l)return l.key;for(let l of sd)if(l.children){let s=l.children.find(l=>l.page===e);if(s)return s.key}return"1"})(t),n=sd.filter(e=>!e.roles||e.roles.includes(s));return(0,r.jsx)(l2.default,{style:{minHeight:"100vh"},children:(0,r.jsx)(si,{theme:"light",width:220,children:(0,r.jsx)(l4.Z,{mode:"inline",selectedKeys:[a],style:{borderRight:0,backgroundColor:"transparent",fontSize:"14px"},items:n.map(e=>{var s;return{key:e.key,icon:e.icon,label:e.label,children:null===(s=e.children)||void 0===s?void 0:s.map(e=>({key:e.key,icon:e.icon,label:e.label,onClick:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}})),onClick:e.children?void 0:()=>{let s=new URLSearchParams(window.location.search);s.set("page",e.page),window.history.pushState(null,"","?".concat(s.toString())),l(e.page)}}})})})})},sm=s(96889),su=s(14042);console.log("process.env.NODE_ENV","production"),console.log=function(){};let sh=e=>null!==e&&("Admin"===e||"Admin Viewer"===e);var sx=e=>{let{accessToken:l,token:s,userRole:t,userID:a,keys:i,premiumUser:o}=e,d=new Date,[c,m]=(0,n.useState)([]),[u,h]=(0,n.useState)([]),[f,Z]=(0,n.useState)([]),[_,y]=(0,n.useState)([]),[w,S]=(0,n.useState)([]),[k,N]=(0,n.useState)([]),[C,I]=(0,n.useState)([]),[A,P]=(0,n.useState)([]),[E,T]=(0,n.useState)([]),[O,D]=(0,n.useState)([]),[M,F]=(0,n.useState)({}),[R,L]=(0,n.useState)([]),[U,z]=(0,n.useState)(""),[V,B]=(0,n.useState)(["all-tags"]),[q,K]=(0,n.useState)({from:new Date(Date.now()-6048e5),to:new Date}),[W,Y]=(0,n.useState)(null),[et,ea]=(0,n.useState)(0),er=new Date(d.getFullYear(),d.getMonth(),1),ei=new Date(d.getFullYear(),d.getMonth()+1,0),eo=ep(er),ed=ep(ei);function ec(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}console.log("keys in usage",i),console.log("premium user in usage",o);let em=async()=>{if(l)try{let e=await (0,x.g)(l);return console.log("usage tab: proxy_settings",e),e}catch(e){console.error("Error fetching proxy settings:",e)}};(0,n.useEffect)(()=>{ex(q.from,q.to)},[q,V]);let eh=async(e,s,t)=>{if(!e||!s||!l)return;s.setHours(23,59,59,999),e.setHours(0,0,0,0),console.log("uiSelectedKey",t);let a=await (0,x.b1)(l,t,e.toISOString(),s.toISOString());console.log("End user data updated successfully",a),y(a)},ex=async(e,s)=>{if(!e||!s||!l)return;let t=await em();null!=t&&t.DISABLE_EXPENSIVE_DB_QUERIES||(s.setHours(23,59,59,999),e.setHours(0,0,0,0),N((await (0,x.J$)(l,e.toISOString(),s.toISOString(),0===V.length?void 0:V)).spend_per_tag),console.log("Tag spend data updated successfully"))};function ep(e){let l=e.getFullYear(),s=e.getMonth()+1,t=e.getDate();return"".concat(l,"-").concat(s<10?"0"+s:s,"-").concat(t<10?"0"+t:t)}console.log("Start date is ".concat(eo)),console.log("End date is ".concat(ed));let ej=async(e,l,s)=>{try{let s=await e();l(s)}catch(e){console.error(s,e)}},eg=(e,l,s,t)=>{let a=[],r=new Date(l),n=e=>{if(e.includes("-"))return e;{let[l,s]=e.split(" ");return new Date(new Date().getFullYear(),new Date("".concat(l," 01 2024")).getMonth(),parseInt(s)).toISOString().split("T")[0]}},i=new Map(e.map(e=>{let l=n(e.date);return[l,{...e,date:l}]}));for(;r<=s;){let e=r.toISOString().split("T")[0];if(i.has(e))a.push(i.get(e));else{let l={date:e,api_requests:0,total_tokens:0};t.forEach(e=>{l[e]||(l[e]=0)}),a.push(l)}r.setDate(r.getDate()+1)}return a},ef=async()=>{if(l)try{let e=await (0,x.FC)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=eg(e,t,a,[]),n=Number(r.reduce((e,l)=>e+(l.spend||0),0).toFixed(2));ea(n),m(r)}catch(e){console.error("Error fetching overall spend:",e)}},eZ=()=>ej(()=>l&&s?(0,x.OU)(l,s,eo,ed):Promise.reject("No access token or token"),D,"Error fetching provider spend"),e_=async()=>{l&&await ej(async()=>(await (0,x.tN)(l)).map(e=>({key:(e.key_alias||e.key_name||e.api_key).substring(0,10),spend:Number(e.total_spend.toFixed(2))})),h,"Error fetching top keys")},ey=async()=>{l&&await ej(async()=>(await (0,x.Au)(l)).map(e=>({key:e.model,spend:Number(e.total_spend.toFixed(2))})),Z,"Error fetching top models")},eb=async()=>{l&&await ej(async()=>{let e=await (0,x.mR)(l),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0);return S(eg(e.daily_spend,t,a,e.teams)),P(e.teams),e.total_spend_per_team.map(e=>({name:e.team_id||"",value:Number(e.total_spend||0).toFixed(2)}))},T,"Error fetching team spend")},ev=()=>{l&&ej(async()=>(await (0,x.X)(l)).tag_names,I,"Error fetching tag names")},ew=()=>{l&&ej(()=>{var e,s;return(0,x.J$)(l,null===(e=q.from)||void 0===e?void 0:e.toISOString(),null===(s=q.to)||void 0===s?void 0:s.toISOString(),void 0)},e=>N(e.spend_per_tag),"Error fetching top tags")},eS=()=>{l&&ej(()=>(0,x.b1)(l,null,void 0,void 0),y,"Error fetching top end users")},ek=async()=>{if(l)try{let e=await (0,x.wd)(l,eo,ed),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=eg(e.daily_data||[],t,a,["api_requests","total_tokens"]);F({...e,daily_data:r})}catch(e){console.error("Error fetching global activity:",e)}},eN=async()=>{if(l)try{let e=await (0,x.xA)(l,eo,ed),s=new Date,t=new Date(s.getFullYear(),s.getMonth(),1),a=new Date(s.getFullYear(),s.getMonth()+1,0),r=e.map(e=>({...e,daily_data:eg(e.daily_data||[],t,a,["api_requests","total_tokens"])}));L(r)}catch(e){console.error("Error fetching global activity per model:",e)}};return((0,n.useEffect)(()=>{(async()=>{if(l&&s&&t&&a){let e=await em();e&&(Y(e),null!=e&&e.DISABLE_EXPENSIVE_DB_QUERIES)||(console.log("fetching data - valiue of proxySettings",W),ef(),eZ(),e_(),ey(),ek(),eN(),sh(t)&&(eb(),ev(),ew(),eS()))}})()},[l,s,t,a,eo,ed]),null==W?void 0:W.DISABLE_EXPENSIVE_DB_QUERIES)?(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Database Query Limit Reached"}),(0,r.jsxs)(b.Z,{className:"mt-4",children:["SpendLogs in DB has ",W.NUM_SPEND_LOGS_ROWS," rows.",(0,r.jsx)("br",{}),"Please follow our guide to view usage when SpendLogs has more than 1M rows."]}),(0,r.jsx)(g.Z,{className:"mt-4",children:(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/spending_monitoring",target:"_blank",children:"View Usage Guide"})})]})}):(0,r.jsx)("div",{style:{width:"100%"},className:"p-8",children:(0,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Up"}),sh(t)?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(eE.Z,{children:"Team Based Usage"}),(0,r.jsx)(eE.Z,{children:"Customer Usage"}),(0,r.jsx)(eE.Z,{children:"Tag Based Usage"})]}):(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{})})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(eT.Z,{children:[(0,r.jsxs)(eO.Z,{variant:"solid",className:"mt-1",children:[(0,r.jsx)(eE.Z,{children:"Cost"}),(0,r.jsx)(eE.Z,{children:"Activity"})]}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(j.Z,{numItems:2,className:"gap-2 h-[100vh] w-full",children:[(0,r.jsxs)(p.Z,{numColSpan:2,children:[(0,r.jsxs)(b.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,r.jsx)(en,{userID:a,userRole:t,accessToken:l,userSpend:et,selectedTeam:null,userMaxBudget:null})]}),(0,r.jsx)(p.Z,{numColSpan:2,children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Monthly Spend"}),(0,r.jsx)(eR.Z,{data:c,index:"date",categories:["spend"],colors:["cyan"],valueFormatter:e=>"$ ".concat(e.toFixed(2)),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Top API Keys"}),(0,r.jsx)(eR.Z,{className:"mt-4 h-40",data:u,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Top Models"}),(0,r.jsx)(eR.Z,{className:"mt-4 h-40",data:f,index:"key",categories:["spend"],colors:["cyan"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1,valueFormatter:e=>"$".concat(e.toFixed(2))})]})}),(0,r.jsx)(p.Z,{numColSpan:1}),(0,r.jsx)(p.Z,{numColSpan:2,children:(0,r.jsxs)(H.Z,{className:"mb-2",children:[(0,r.jsx)(v.Z,{children:"Spend by Provider"}),(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsx)(su.Z,{className:"mt-4 h-40",variant:"pie",data:O,index:"provider",category:"spend",colors:["cyan"],valueFormatter:e=>"$".concat(e.toFixed(2))})}),(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsxs)(G.Z,{children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Provider"}),(0,r.jsx)(Q.Z,{children:"Spend"})]})}),(0,r.jsx)(J.Z,{children:O.map(e=>(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.provider}),(0,r.jsx)(X.Z,{children:1e-5>parseFloat(e.spend.toFixed(2))?"less than 0.00":e.spend.toFixed(2)})]},e.provider))})]})})]})})]})})]})}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(j.Z,{numItems:1,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"All Up"}),(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsxs)(p.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ec(M.sum_api_requests)]}),(0,r.jsx)(eF.Z,{className:"h-40",data:M.daily_data,valueFormatter:ec,index:"date",colors:["cyan"],categories:["api_requests"],onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(p.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ec(M.sum_total_tokens)]}),(0,r.jsx)(eR.Z,{className:"h-40",data:M.daily_data,valueFormatter:ec,index:"date",colors:["cyan"],categories:["total_tokens"],onValueChange:e=>console.log(e)})]})]})]}),(0,r.jsx)(r.Fragment,{children:R.map((e,l)=>(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:e.model}),(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsxs)(p.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["API Requests ",ec(e.sum_api_requests)]}),(0,r.jsx)(eF.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["api_requests"],valueFormatter:ec,onValueChange:e=>console.log(e)})]}),(0,r.jsxs)(p.Z,{children:[(0,r.jsxs)(eu.Z,{style:{fontSize:"15px",fontWeight:"normal",color:"#535452"},children:["Tokens ",ec(e.sum_total_tokens)]}),(0,r.jsx)(eR.Z,{className:"h-40",data:e.daily_data,index:"date",colors:["cyan"],categories:["total_tokens"],valueFormatter:ec,onValueChange:e=>console.log(e)})]})]})]},l))})]})})]})]})}),(0,r.jsx)(eD.Z,{children:(0,r.jsxs)(j.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(p.Z,{numColSpan:2,children:[(0,r.jsxs)(H.Z,{className:"mb-2",children:[(0,r.jsx)(v.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(sm.Z,{data:E})]}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(eR.Z,{className:"h-72",data:w,showLegend:!0,index:"date",categories:A,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(p.Z,{numColSpan:2})]})}),(0,r.jsxs)(eD.Z,{children:[(0,r.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,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/users",target:"_blank",children:"docs here"})]}),(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsxs)(p.Z,{children:[(0,r.jsx)(b.Z,{children:"Select Time Range"}),(0,r.jsx)(eP.Z,{enableSelect:!0,value:q,onValueChange:e=>{K(e),eh(e.from,e.to,null)}})]}),(0,r.jsxs)(p.Z,{children:[(0,r.jsx)(b.Z,{children:"Select Key"}),(0,r.jsxs)(el.Z,{defaultValue:"all-keys",children:[(0,r.jsx)(es.Z,{value:"all-keys",onClick:()=>{eh(q.from,q.to,null)},children:"All Keys"},"all-keys"),null==i?void 0:i.map((e,l)=>e&&null!==e.key_alias&&e.key_alias.length>0?(0,r.jsx)(es.Z,{value:String(l),onClick:()=>{eh(q.from,q.to,e.token)},children:e.key_alias},l):null)]})]})]}),(0,r.jsx)(H.Z,{className:"mt-4",children:(0,r.jsxs)(G.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)($.Z,{children:(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(Q.Z,{children:"Customer"}),(0,r.jsx)(Q.Z,{children:"Spend"}),(0,r.jsx)(Q.Z,{children:"Total Events"})]})}),(0,r.jsx)(J.Z,{children:null==_?void 0:_.map((e,l)=>{var s;return(0,r.jsxs)(ee.Z,{children:[(0,r.jsx)(X.Z,{children:e.end_user}),(0,r.jsx)(X.Z,{children:null===(s=e.total_spend)||void 0===s?void 0:s.toFixed(4)}),(0,r.jsx)(X.Z,{children:e.total_count})]},l)})})]})})]}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(j.Z,{numItems:2,children:[(0,r.jsx)(p.Z,{numColSpan:1,children:(0,r.jsx)(eP.Z,{className:"mb-4",enableSelect:!0,value:q,onValueChange:e=>{K(e),ex(e.from,e.to)}})}),(0,r.jsx)(p.Z,{children:o?(0,r.jsx)("div",{children:(0,r.jsxs)(lg.Z,{value:V,onValueChange:e=>B(e),children:[(0,r.jsx)(lf.Z,{value:"all-tags",onClick:()=>B(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsx)(lf.Z,{value:String(e),children:e},e))]})}):(0,r.jsx)("div",{children:(0,r.jsxs)(lg.Z,{value:V,onValueChange:e=>B(e),children:[(0,r.jsx)(lf.Z,{value:"all-tags",onClick:()=>B(["all-tags"]),children:"All Tags"},"all-tags"),C&&C.filter(e=>"all-tags"!==e).map((e,l)=>(0,r.jsxs)(es.Z,{value:String(e),disabled:!0,children:["✨ ",e," (Enterprise only Feature)"]},e))]})})})]}),(0,r.jsxs)(j.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(p.Z,{numColSpan:2,children:(0,r.jsxs)(H.Z,{children:[(0,r.jsx)(v.Z,{children:"Spend Per Tag"}),(0,r.jsxs)(b.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{className:"text-blue-500",href:"https://docs.litellm.ai/docs/proxy/cost_tracking",target:"_blank",children:"here"})]}),(0,r.jsx)(eR.Z,{className:"h-72",data:k,index:"name",categories:["spend"],colors:["cyan"]})]})}),(0,r.jsx)(p.Z,{numColSpan:2})]})]})]})]})})};let sp=e=>{if(e)return e.toISOString().split("T")[0]};function sj(e){return new Intl.NumberFormat("en-US",{maximumFractionDigits:0,notation:"compact",compactDisplay:"short"}).format(e)}var sg=e=>{let{accessToken:l,token:s,userRole:t,userID:a,premiumUser:i}=e,[o,d]=(0,n.useState)([]),[c,m]=(0,n.useState)([]),[u,h]=(0,n.useState)([]),[g,f]=(0,n.useState)([]),[Z,_]=(0,n.useState)("0"),[y,b]=(0,n.useState)("0"),[v,w]=(0,n.useState)("0"),[S,k]=(0,n.useState)({from:new Date(Date.now()-6048e5),to:new Date});(0,n.useEffect)(()=>{l&&S&&(async()=>{f(await (0,x.zg)(l,sp(S.from),sp(S.to)))})()},[l]);let N=Array.from(new Set(g.map(e=>{var l;return null!==(l=null==e?void 0:e.api_key)&&void 0!==l?l:""}))),C=Array.from(new Set(g.map(e=>{var l;return null!==(l=null==e?void 0:e.model)&&void 0!==l?l:""})));Array.from(new Set(g.map(e=>{var l;return null!==(l=null==e?void 0:e.call_type)&&void 0!==l?l:""})));let I=async(e,s)=>{e&&s&&l&&(s.setHours(23,59,59,999),e.setHours(0,0,0,0),f(await (0,x.zg)(l,sp(e),sp(s))))};return(0,n.useEffect)(()=>{console.log("DATA IN CACHE DASHBOARD",g);let e=g;c.length>0&&(e=e.filter(e=>c.includes(e.api_key))),u.length>0&&(e=e.filter(e=>u.includes(e.model))),console.log("before processed data in cache dashboard",e);let l=0,s=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"),l+=(a.total_rows||0)-(a.cache_hit_true_rows||0),s+=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},[]);_(sj(s)),b(sj(t));let r=s+l;r>0?w((s/r*100).toFixed(2)):w("0"),d(a),console.log("PROCESSED DATA IN CACHE DASHBOARD",a)},[c,u,S,g]),(0,r.jsxs)(H.Z,{children:[(0,r.jsxs)(j.Z,{numItems:3,className:"gap-4 mt-4",children:[(0,r.jsx)(p.Z,{children:(0,r.jsx)(lg.Z,{placeholder:"Select API Keys",value:c,onValueChange:m,children:N.map(e=>(0,r.jsx)(lf.Z,{value:e,children:e},e))})}),(0,r.jsx)(p.Z,{children:(0,r.jsx)(lg.Z,{placeholder:"Select Models",value:u,onValueChange:h,children:C.map(e=>(0,r.jsx)(lf.Z,{value:e,children:e},e))})}),(0,r.jsx)(p.Z,{children:(0,r.jsx)(eP.Z,{enableSelect:!0,value:S,onValueChange:e=>{k(e),I(e.from,e.to)},selectPlaceholder:"Select date range"})})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 mt-4",children:[(0,r.jsxs)(H.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hit Ratio"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsxs)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:[v,"%"]})})]}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cache Hits"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:Z})})]}),(0,r.jsxs)(H.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Cached Tokens"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-metric font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:y})})]})]}),(0,r.jsx)(eu.Z,{className:"mt-4",children:"Cache Hits vs API Requests"}),(0,r.jsx)(eR.Z,{title:"Cache Hits vs API Requests",data:o,stack:!0,index:"name",valueFormatter:sj,categories:["LLM API requests","Cache hit"],colors:["sky","teal"],yAxisWidth:48}),(0,r.jsx)(eu.Z,{className:"mt-4",children:"Cached Completion Tokens vs Generated Completion Tokens"}),(0,r.jsx)(eR.Z,{className:"mt-6",data:o,stack:!0,index:"name",valueFormatter:sj,categories:["Generated Completion Tokens","Cached Completion Tokens"],colors:["sky","teal"],yAxisWidth:48})]})};let sf=new d.S;function sZ(){let[e,l]=(0,n.useState)(""),[s,t]=(0,n.useState)(!1),[a,d]=(0,n.useState)(!1),[m,u]=(0,n.useState)(null),[p,j]=(0,n.useState)(null),[g,f]=(0,n.useState)(null),[Z,_]=(0,n.useState)({PROXY_BASE_URL:"",PROXY_LOGOUT_URL:""}),[y,b]=(0,n.useState)(!0),v=(0,i.useSearchParams)(),[w,S]=(0,n.useState)({data:[]}),[k,N]=(0,n.useState)(null),C=v.get("userID"),I=v.get("invitation_id"),[A,P]=(0,n.useState)(()=>v.get("page")||"api-keys"),[E,T]=(0,n.useState)(null);return(0,n.useEffect)(()=>{N(function(e){let l=document.cookie.split("; ").find(l=>l.startsWith(e+"="));return l?l.split("=")[1]:null}("token"))},[]),(0,n.useEffect)(()=>{if(!k)return;let e=(0,o.o)(k);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),T(e.key),d(e.disabled_non_admin_personal_key_creation),e.user_role){let s=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"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:",s),l(s),"Admin Viewer"==s&&P("usage")}else console.log("User role not defined");e.user_email?u(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?b("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,x.K8)(e.auth_header_name)}},[k]),(0,r.jsx)(n.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsx)(c.aH,{client:sf,children:I?(0,r.jsx)(em,{userID:C,userRole:e,premiumUser:s,teams:p,keys:g,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:j,setKeys:f}):(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(h,{userID:C,userRole:e,userEmail:m,premiumUser:s,setProxySettings:_,proxySettings:Z}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(sc,{setPage:e=>{let l=new URLSearchParams(v);l.set("page",e),window.history.pushState(null,"","?".concat(l.toString())),P(e)},userRole:e,defaultSelectedKey:A})}),"api-keys"==A?(0,r.jsx)(em,{userID:C,userRole:e,premiumUser:s,teams:p,keys:g,setUserRole:l,userEmail:m,setUserEmail:u,setTeams:j,setKeys:f}):"models"==A?(0,r.jsx)(eG,{userID:C,userRole:e,token:k,keys:g,accessToken:E,modelData:w,setModelData:S,premiumUser:s}):"llm-playground"==A?(0,r.jsx)(l1,{userID:C,userRole:e,token:k,accessToken:E,disabledPersonalKeyCreation:a}):"users"==A?(0,r.jsx)(e0,{userID:C,userRole:e,token:k,keys:g,teams:p,accessToken:E,setKeys:f}):"teams"==A?(0,r.jsx)(e6,{teams:p,setTeams:j,searchParams:v,accessToken:E,userID:C,userRole:e}):"organizations"==A?(0,r.jsx)(ln,{teams:p,setTeams:j,searchParams:v,accessToken:E,userID:C,userRole:e,premiumUser:s}):"admin-panel"==A?(0,r.jsx)(lo,{setTeams:j,searchParams:v,accessToken:E,showSSOBanner:y,premiumUser:s}):"api_ref"==A?(0,r.jsx)(lX,{proxySettings:Z}):"settings"==A?(0,r.jsx)(lj,{userID:C,userRole:e,accessToken:E,premiumUser:s}):"budgets"==A?(0,r.jsx)(lD,{accessToken:E}):"general-settings"==A?(0,r.jsx)(lS,{userID:C,userRole:e,accessToken:E,modelData:w}):"model-hub"==A?(0,r.jsx)(lJ.Z,{accessToken:E,publicPage:!1,premiumUser:s}):"caching"==A?(0,r.jsx)(sg,{userID:C,userRole:e,token:k,accessToken:E,premiumUser:s}):"pass-through-settings"==A?(0,r.jsx)(lE,{userID:C,userRole:e,accessToken:E,modelData:w}):"logs"==A?(0,r.jsx)(lY,{userID:C,userRole:e,token:k,accessToken:E}):(0,r.jsx)(sx,{userID:C,userRole:e,token:k,accessToken:E,keys:g,premiumUser:s})]})]})})})}}},function(e){e.O(0,[665,990,42,261,755,309,250,699,971,117,744],function(){return e(e.s=1900)}),_N_E=e.O()}]); |