From 034ca95a94f424b76d4e2bdead94999455369a2c Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 29 Feb 2024 09:56:26 -0800 Subject: [PATCH] build(ui): fix admin viewer issue --- litellm/proxy/_experimental/out/404.html | 2 +- .../_buildManifest.js | 0 .../_ssgManifest.js | 0 ...157f538dff.js => page-f5480eede36fdcd5.js} | 2 +- litellm/proxy/_experimental/out/index.html | 2 +- litellm/proxy/_experimental/out/index.txt | 4 +-- litellm/proxy/proxy_server.py | 29 +++++++++++++----- litellm/proxy/utils.py | 30 ++++++++++++++++++- ui/litellm-dashboard/out/404.html | 2 +- ui/litellm-dashboard/out/index.html | 2 +- ui/litellm-dashboard/out/index.txt | 4 +-- ui/litellm-dashboard/src/app/page.tsx | 6 +++- .../src/components/leftnav.tsx | 19 ++++++++++++ ui/litellm-dashboard/src/components/usage.tsx | 2 +- .../src/components/user_dashboard.tsx | 4 +++ 15 files changed, 88 insertions(+), 20 deletions(-) rename litellm/proxy/_experimental/out/_next/static/{kyOCJPBB9pyUfbMKCAXr- => HOfpn9FdKIMCOfG_am2z2}/_buildManifest.js (100%) rename litellm/proxy/_experimental/out/_next/static/{kyOCJPBB9pyUfbMKCAXr- => HOfpn9FdKIMCOfG_am2z2}/_ssgManifest.js (100%) rename litellm/proxy/_experimental/out/_next/static/chunks/app/{page-8f65fc157f538dff.js => page-f5480eede36fdcd5.js} (82%) diff --git a/litellm/proxy/_experimental/out/404.html b/litellm/proxy/_experimental/out/404.html index c6632b021..b86464e15 100644 --- a/litellm/proxy/_experimental/out/404.html +++ b/litellm/proxy/_experimental/out/404.html @@ -1 +1 @@ -404: This page could not be found.🚅 LiteLLM

404

This page could not be found.

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

404

This page could not be found.

\ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/kyOCJPBB9pyUfbMKCAXr-/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/HOfpn9FdKIMCOfG_am2z2/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/kyOCJPBB9pyUfbMKCAXr-/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/HOfpn9FdKIMCOfG_am2z2/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/kyOCJPBB9pyUfbMKCAXr-/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/HOfpn9FdKIMCOfG_am2z2/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/kyOCJPBB9pyUfbMKCAXr-/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/HOfpn9FdKIMCOfG_am2z2/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-8f65fc157f538dff.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-f5480eede36fdcd5.js similarity index 82% rename from litellm/proxy/_experimental/out/_next/static/chunks/app/page-8f65fc157f538dff.js rename to litellm/proxy/_experimental/out/_next/static/chunks/app/page-f5480eede36fdcd5.js index 9c44391b0..088b88219 100644 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-8f65fc157f538dff.js +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-f5480eede36fdcd5.js @@ -1 +1 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{79615:function(e,t,s){Promise.resolve().then(s.bind(s,30280))},30280:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return eT}});var l=s(3827),n=s(64090),r=s(47907),a=s(8792),o=s(2179),i=e=>{let{userID:t,userRole:s,userEmail:n,showSSOBanner:r}=e;return console.log("User ID:",t),console.log("userEmail:",n),(0,l.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,l.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,l.jsx)("div",{className:"flex flex-col items-center",children:(0,l.jsx)(a.default,{href:"/",children:(0,l.jsx)("button",{className:"text-gray-800 text-2xl py-1 rounded text-center",children:(0,l.jsx)("img",{src:"/get_image",width:200,height:200,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,l.jsxs)("div",{className:"text-right mx-4 my-2 absolute top-0 right-0 flex items-center justify-end space-x-2",children:[r?(0,l.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#setup-ssoauth-for-ui",target:"_blank",className:"mr-2",children:(0,l.jsx)(o.Z,{variant:"primary",size:"lg",children:"Enable SSO"})}):null,(0,l.jsxs)(o.Z,{variant:"secondary",size:"lg",children:[n,(0,l.jsxs)("p",{children:["Role: ",s]}),(0,l.jsxs)("p",{children:["ID: ",t]})]})]})]})},c=s(80588);let d=async(e,t,s)=>{try{if(console.log("Form Values in keyCreateCall:",s),s.description&&(s.metadata||(s.metadata={}),s.metadata.description=s.description,delete s.description,s.metadata=JSON.stringify(s.metadata)),s.metadata){console.log("formValues.metadata:",s.metadata);try{s.metadata=JSON.parse(s.metadata)}catch(e){throw c.ZP.error("Failed to parse metadata: "+e),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",s);let l=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...s})});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let n=await l.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},m=async(e,t,s)=>{try{if(console.log("Form Values in keyCreateCall:",s),s.description&&(s.metadata||(s.metadata={}),s.metadata.description=s.description,delete s.description,s.metadata=JSON.stringify(s.metadata)),s.metadata){console.log("formValues.metadata:",s.metadata);try{s.metadata=JSON.parse(s.metadata)}catch(e){throw c.ZP.error("Failed to parse metadata: "+e),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",s);let l=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...s})});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let n=await l.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},h=async(e,t)=>{try{console.log("in keyDeleteCall:",t),c.ZP.info("Making key delete request");let s=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[t]})});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let l=await s.json();return console.log(l),c.ZP.success("API Key Deleted"),l}catch(e){throw console.error("Failed to create key:",e),e}},u=async function(e,t,s){let l=arguments.length>3&&void 0!==arguments[3]&&arguments[3];try{let n="/user/info";"App Owner"==s&&t&&(n="".concat(n,"/?user_id=").concat(t)),console.log("in userInfoCall viewAll=",l),l&&(n="".concat(n,"/?view_all=true")),c.ZP.info("Requesting user data");let r=await fetch(n,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.text();throw c.ZP.error(e),Error("Network response was not ok")}let a=await r.json();return console.log("API Response:",a),c.ZP.info("Received user data"),a}catch(e){throw console.error("Failed to create key:",e),e}},x=async(e,t,s)=>{try{c.ZP.info("Requesting model data");let t=await fetch("/v2/model/info",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return c.ZP.info("Received model data"),s}catch(e){throw console.error("Failed to create key:",e),e}},p=async(e,t,s)=>{try{c.ZP.info("Requesting model data");let t=await fetch("/models",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return c.ZP.info("Received model data"),s}catch(e){throw console.error("Failed to create key:",e),e}},j=async(e,t)=>{try{let s="/spend/logs";console.log("in keySpendLogsCall:",s);let l=await fetch("".concat(s,"/?api_key=").concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw c.ZP.error(e),Error("Network response was not ok")}let n=await l.json();return console.log(n),n}catch(e){throw console.error("Failed to create key:",e),e}},g=async(e,t,s,l,n,r)=>{try{console.log("user role in spend logs call: ".concat(s));let t="/spend/logs";t="App Owner"==s?"".concat(t,"/?user_id=").concat(l,"&start_date=").concat(n,"&end_date=").concat(r):"".concat(t,"/?start_date=").concat(n,"&end_date=").concat(r),c.ZP.info("Making spend logs request");let a=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw c.ZP.error(e),Error("Network response was not ok")}let o=await a.json();return console.log(o),c.ZP.success("Spend Logs received"),o}catch(e){throw console.error("Failed to create key:",e),e}},Z=async e=>{try{c.ZP.info("Making spend logs request");let t=await fetch("/global/spend/logs",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return console.log(s),c.ZP.success("Spend Logs received"),s}catch(e){throw console.error("Failed to create key:",e),e}},y=async e=>{try{c.ZP.info("Making spend keys request");let t=await fetch("/global/spend/keys?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return console.log(s),c.ZP.success("Spend Logs received"),s}catch(e){throw console.error("Failed to create key:",e),e}},f=async e=>{try{c.ZP.info("Making spend models request");let t=await fetch("/global/spend/models?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return console.log(s),c.ZP.success("Spend Logs received"),s}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,t)=>{try{let s=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:t})});if(!s.ok){let e=await s.text();throw c.ZP.error(e),Error("Network response was not ok")}let l=await s.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},_=async(e,t)=>{try{let s="/spend/users";console.log("in spendUsersCall:",s);let l=await fetch("".concat(s,"/?user_id=").concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw c.ZP.error(e),Error("Network response was not ok")}let n=await l.json();return console.log(n),n}catch(e){throw console.error("Failed to get spend for user",e),e}},k=async(e,t,s,l)=>{try{let n=await fetch("/user/request_model",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({models:[t],user_id:s,justification:l})});if(!n.ok){let e=await n.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let r=await n.json();return console.log(r),c.ZP.success(""),r}catch(e){throw console.error("Failed to create key:",e),e}},b=async e=>{try{let t="/user/get_requests";console.log("in userGetRequesedtModelsCall:",t);let s=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let l=await s.json();return console.log(l),c.ZP.success(""),l}catch(e){throw console.error("Failed to get requested models:",e),e}},v=async(e,t)=>{try{let s="/user/get_users?role=".concat(t);console.log("in userGetAllUsersCall:",s);let l=await fetch(s,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let n=await l.json();return console.log(n),c.ZP.success("Got all users"),n}catch(e){throw console.error("Failed to get requested models:",e),e}},S=async(e,t)=>{try{console.log("Form Values in teamCreateCall:",t);let s=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let l=await s.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},N=async(e,t,s)=>{try{console.log("Form Values in teamMemberAddCall:",s);let l=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,member:s})});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let n=await l.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},A=async(e,t)=>{try{console.log("Form Values in userUpdateUserCall:",t);let s=await fetch("/user/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_role:"proxy_admin_viewer",...t})});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let l=await s.json();return console.log("API Response:",l),c.ZP.success("User role updated"),l}catch(e){throw console.error("Failed to create key:",e),e}};var I=s(10384),C=s(46453),P=s(71801),T=s(17189),E=s(12143),F=s(77171),O=s(42539),D=s(88707),M=s(1861);let{Option:R}=T.default;var U=e=>{let{userID:t,teamID:s,userRole:r,accessToken:a,data:i,userModels:m,setData:h}=e,[u]=E.Z.useForm(),[x,p]=(0,n.useState)(!1),[j,g]=(0,n.useState)(null),Z=()=>{p(!1),u.resetFields()},y=()=>{p(!1),g(null),u.resetFields()},f=async e=>{try{c.ZP.info("Making API Call"),p(!0);let s=await d(a,t,e);h(e=>e?[...e,s]:[s]),g(s.key),c.ZP.success("API Key Created"),u.resetFields(),localStorage.removeItem("userData"+t)}catch(e){console.error("Error creating the key:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>p(!0),children:"+ Create New Key"}),(0,l.jsx)(F.Z,{title:"Create Key",visible:x,width:800,footer:null,onOk:Z,onCancel:y,children:(0,l.jsxs)(E.Z,{form:u,onFinish:f,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===r||"Admin"===r?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Key Name",name:"key_alias",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Team ID",name:"team_id",children:(0,l.jsx)(O.Z,{placeholder:"ai_team",defaultValue:s||""})}),(0,l.jsx)(E.Z.Item,{label:"Models",name:"models",children:(0,l.jsx)(T.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:m.map(e=>(0,l.jsx)(R,{value:e,children:e},e))})}),(0,l.jsx)(E.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(D.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(E.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,l.jsxs)(T.default,{defaultValue:null,placeholder:"n/a",children:[(0,l.jsx)(T.default.Option,{value:"24h",children:"daily"}),(0,l.jsx)(T.default.Option,{value:"30d",children:"monthly"})]})}),(0,l.jsx)(E.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Metadata",name:"metadata",children:(0,l.jsx)(O.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Key Name",name:"key_alias",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Team ID (Contact Group)",name:"team_id",children:(0,l.jsx)(O.Z,{placeholder:"ai_team"})}),(0,l.jsx)(E.Z.Item,{label:"Description",name:"description",children:(0,l.jsx)(O.Z.TextArea,{placeholder:"Enter description",rows:4})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(M.ZP,{htmlType:"submit",children:"Create Key"})})]})}),j&&(0,l.jsx)(F.Z,{title:"Save your key",visible:x,onOk:Z,onCancel:y,footer:null,children:(0,l.jsxs)(C.Z,{numItems:1,className:"gap-2 w-full",children:[(0,l.jsx)(I.Z,{numColSpan:1,children:(0,l.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,l.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,l.jsx)(I.Z,{numColSpan:1,children:null!=j?(0,l.jsxs)(P.Z,{children:["API Key: ",j]}):(0,l.jsx)(P.Z,{children:"Key being created, this might take 30s"})})]})})]})},L=s(33393),z=s(13810),q=s(61244),B=s(10827),K=s(3851),J=s(2044),G=s(64167),V=s(74480),$=s(7178),Y=s(9853),W=s(67989),H=s(56863),X=s(42440),Q=e=>{let{token:t,accessToken:s,keySpend:r,keyBudget:a,keyName:i}=e,[c,d]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),[u,x]=(0,n.useState)(null),p=async()=>{try{if(null==s||null==t)return;console.log("accessToken: ".concat(s,"; token: ").concat(t));let e=await j(s,t);console.log("Response:",e);let l=Object.values(e).reduce((e,t)=>{let s=new Date(t.startTime),l=new Intl.DateTimeFormat("en-US",{day:"2-digit",month:"short"}).format(s);return e[l]=(e[l]||0)+t.spend,e},{}),n=Object.entries(l);n.sort((e,t)=>{let[s]=e,[l]=t,n=new Date(s),r=new Date(l);return n.getTime()-r.getTime()});let r=Object.fromEntries(n);console.log(r);let a=Object.values(e).reduce((e,t)=>{let s=t.user;return e[s]=(e[s]||0)+t.spend,e},{});console.log(l),console.log(a);let o=[];for(let[e,t]of Object.entries(r))o.push({day:e,spend:t});let i=Object.entries(a).sort((e,t)=>t[1]-e[1]).slice(0,5).map(e=>{let[t,s]=e;return{name:t,value:s}});h(o),x(i),console.log("arrayBarChart:",o)}catch(e){console.error("There was an error fetching the data",e)}};return t?(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>{console.log("Show Modal triggered"),d(!0),p()},children:"View Spend Report"}),(0,l.jsxs)(F.Z,{visible:c,width:1e3,onOk:()=>{d(!1)},onCancel:()=>{d(!1)},footer:null,children:[(0,l.jsxs)(X.Z,{style:{textAlign:"left"},children:["Key Name: ",i]}),(0,l.jsxs)(H.Z,{children:["Monthly Spend $",r]}),(0,l.jsx)(z.Z,{className:"mt-6 mb-6",children:m&&(0,l.jsx)(Y.Z,{className:"mt-6",data:m,colors:["green"],index:"day",categories:["spend"],yAxisWidth:48})}),(0,l.jsx)(X.Z,{className:"mt-6",children:"Top 5 Users Spend (USD)"}),(0,l.jsx)(z.Z,{className:"mb-6",children:u&&(0,l.jsx)(W.Z,{className:"mt-6",data:u,color:"teal"})})]})]}):null},ee=e=>{let{userID:t,accessToken:s,data:r,setData:a}=e,[i,c]=(0,n.useState)(!1),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),p=async e=>{null!=r&&(x(e),localStorage.removeItem("userData"+t),m(!0))},j=async()=>{if(null!=u&&null!=r){try{await h(s,u);let e=r.filter(e=>e.token!==u);a(e)}catch(e){console.error("Error deleting the key:",e)}m(!1),x(null)}};if(null!=r)return console.log("RERENDER TRIGGERED"),(0,l.jsxs)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:[(0,l.jsxs)(B.Z,{className:"mt-5",children:[(0,l.jsx)(G.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(V.Z,{children:"Key Alias"}),(0,l.jsx)(V.Z,{children:"Secret Key"}),(0,l.jsx)(V.Z,{children:"Spend (USD)"}),(0,l.jsx)(V.Z,{children:"Key Budget (USD)"}),(0,l.jsx)(V.Z,{children:"Team ID"}),(0,l.jsx)(V.Z,{children:"Metadata"}),(0,l.jsx)(V.Z,{children:"Models"}),(0,l.jsx)(V.Z,{children:"TPM / RPM Limits"}),(0,l.jsx)(V.Z,{children:"Expires"})]})}),(0,l.jsx)(K.Z,{children:r.map(e=>(console.log(e),"litellm-dashboard"===e.team_id)?null:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:null!=e.key_alias?(0,l.jsx)(P.Z,{children:e.key_alias}):(0,l.jsx)(P.Z,{children:"Not Set"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:e.key_name})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:e.spend})}),(0,l.jsx)(J.Z,{children:null!=e.max_budget?(0,l.jsx)(P.Z,{children:e.max_budget}):(0,l.jsx)(P.Z,{children:"Unlimited Budget"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:e.team_id})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:JSON.stringify(e.metadata)})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:JSON.stringify(e.models)})}),(0,l.jsx)(J.Z,{children:(0,l.jsxs)(P.Z,{children:["TPM Limit: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,l.jsx)("br",{})," RPM Limit:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,l.jsx)(J.Z,{children:null!=e.expires?(0,l.jsx)(P.Z,{children:e.expires}):(0,l.jsx)(P.Z,{children:"Never expires"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{onClick:()=>p(e.token),icon:L.Z,size:"sm"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(Q,{token:e.token,accessToken:s,keySpend:e.spend,keyBudget:e.max_budget,keyName:e.key_name})})]},e.token))})]}),d&&(0,l.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,l.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,l.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,l.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,l.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,l.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,l.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,l.jsx)("div",{className:"sm:flex sm:items-start",children:(0,l.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,l.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,l.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,l.jsx)(o.Z,{onClick:j,color:"red",className:"ml-2",children:"Delete"}),(0,l.jsx)(o.Z,{onClick:()=>{m(!1),x(null)},children:"Cancel"})]})]})]})})]})},et=e=>{let{userID:t,userSpendData:s,userRole:r,accessToken:a}=e;console.log("User SpendData:",s);let[o,i]=(0,n.useState)(null==s?void 0:s.spend),[c,d]=(0,n.useState)((null==s?void 0:s.max_budget)||null);return(0,n.useEffect)(()=>{(async()=>{if("Admin"===r)try{let e=await _(a,"litellm-proxy-budget");console.log("Result from callSpendUsers:",e);let t=e[0];i(null==t?void 0:t.spend),d((null==t?void 0:t.max_budget)||null)}catch(e){console.error("Failed to get spend for user",e)}})()},[r,a,t]),(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)(z.Z,{className:"mx-auto mb-4",children:[(0,l.jsxs)(H.Z,{children:["$",o]}),(0,l.jsxs)(X.Z,{children:["/ ",null!==c?"$".concat(c," limit"):"No limit"]})]})})},es=s(36083),el=s(68967),en=s(27166),er=e=>{let{teams:t,setSelectedTeam:s}=e,{Title:r,Paragraph:a}=es.default,[o,i]=(0,n.useState)("");return(0,l.jsxs)("div",{className:"mt-10",children:[(0,l.jsx)(r,{level:4,children:"Default Team"}),(0,l.jsx)(a,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),t&&t.length>0?(0,l.jsx)(el.Z,{defaultValue:"0",children:t.map((e,t)=>(0,l.jsx)(en.Z,{value:String(t),onClick:()=>s(e),children:e.team_alias},t))}):(0,l.jsxs)(a,{children:["No team created. ",(0,l.jsx)("b",{children:"Defaulting to personal account."})]})]})},ea=s(37963);console.log("isLocal:",!1);var eo=e=>{let{userID:t,userRole:s,teams:a,setUserRole:o,userEmail:i,setUserEmail:c,setTeams:d}=e,[m,h]=(0,n.useState)(null),[x,j]=(0,n.useState)(null),g=(0,r.useSearchParams)();g.get("viewSpend"),(0,r.useRouter)();let Z=g.get("token"),[y,f]=(0,n.useState)(null),[w,_]=(0,n.useState)([]),[k,b]=(0,n.useState)(a?a[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(Z){let e=(0,ea.o)(Z);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),f(e.key),e.user_role){let t=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":return"Admin";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",t),o(t)}else console.log("User role not defined");e.user_email?c(e.user_email):console.log("User Email is not set ".concat(e))}}if(t&&y&&s&&!m){let e=sessionStorage.getItem("userModels"+t);e?_(JSON.parse(e)):(async()=>{try{let e=await u(y,t,s);console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),j(e.user_info),h(e.keys),d(e.teams),b(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+t,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+t,JSON.stringify(e.user_info));let l=(await p(y,t,s)).data.map(e=>e.id);console.log("available_model_names:",l),_(l),console.log("userModels:",w),sessionStorage.setItem("userModels"+t,JSON.stringify(l))}catch(e){console.error("There was an error fetching the data",e)}})()}},[t,Z,y,m,s]),null==t||null==Z){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}return null==y?null:(null==s&&o("App Owner"),(0,l.jsx)("div",{children:(0,l.jsx)(C.Z,{numItems:1,className:"gap-0 p-10 h-[75vh] w-full",children:(0,l.jsxs)(I.Z,{numColSpan:1,children:[(0,l.jsx)(et,{userID:t,userSpendData:x,userRole:s,accessToken:y}),(0,l.jsx)(ee,{userID:t,accessToken:y,data:m,setData:h}),(0,l.jsx)(U,{userID:t,teamID:k?k.team_id:null,userRole:s,userModels:w,accessToken:y,data:m,setData:h}),(0,l.jsx)(er,{teams:a,setSelectedTeam:b})]})})}))},ei=s(5);let{Option:ec}=T.default;var ed=e=>{let{userModels:t,accessToken:s,userID:r}=e,[a]=E.Z.useForm(),[i,d]=(0,n.useState)(!1),m=async e=>{try{c.ZP.info("Requesting access");let{selectedModel:t,accessReason:l}=e;await k(s,t,r,l),d(!0)}catch(e){console.error("Error requesting access:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{size:"xs",onClick:()=>d(!0),children:"Request Access"}),(0,l.jsx)(F.Z,{title:"Request Access",visible:i,width:800,footer:null,onOk:()=>{d(!1),a.resetFields()},onCancel:()=>{d(!1),a.resetFields()},children:(0,l.jsxs)(E.Z,{form:a,onFinish:m,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsx)(E.Z.Item,{label:"Select Model",name:"selectedModel",children:(0,l.jsx)(T.default,{placeholder:"Select model",style:{width:"100%"},children:t.map(e=>(0,l.jsx)(ec,{value:e,children:e},e))})}),(0,l.jsx)(E.Z.Item,{label:"Reason for Access",name:"accessReason",children:(0,l.jsx)(O.Z.TextArea,{rows:4,placeholder:"Enter reason for access"})}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(o.Z,{children:"Request Access"})})]})})]})},em=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,[i,c]=(0,n.useState)({data:[]}),[d,m]=(0,n.useState)([]);if((0,n.useEffect)(()=>{if(!t||!s||!r||!a)return;let e=async()=>{try{let e=await x(t,a,r);if(console.log("Model data response:",e.data),c(e),"Admin"===r&&t){let e=await b(t);console.log("Pending Requests:",d),m(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};t&&s&&r&&a&&e()},[t,s,r,a]),!i||!t||!s||!r||!a)return(0,l.jsx)("div",{children:"Loading..."});let h=[];for(let e=0;e(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.model_name})}),(0,l.jsx)(J.Z,{children:e.provider}),(0,l.jsx)(J.Z,{children:e.user_access?(0,l.jsx)(ei.Z,{color:"green",children:"Yes"}):(0,l.jsx)(ed,{userModels:h,accessToken:t,userID:a})}),(0,l.jsx)(J.Z,{children:e.input_cost}),(0,l.jsx)(J.Z,{children:e.output_cost}),(0,l.jsx)(J.Z,{children:e.max_tokens})]},e.model_name))})]})}),"Admin"===r&&d&&d.length>0?(0,l.jsx)(z.Z,{children:(0,l.jsxs)(B.Z,{children:[(0,l.jsxs)(G.Z,{children:[(0,l.jsx)(X.Z,{children:"Pending Requests"}),(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User ID"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Requested Models"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Justification"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Justification"})})]})]}),(0,l.jsx)(K.Z,{children:d.map(e=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.user_id})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.models[0]})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.justification})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.user_id})}),(0,l.jsx)(o.Z,{children:"Approve"}),(0,l.jsx)(o.Z,{variant:"secondary",className:"ml-2",children:"Deny"})]},e.request_id))})]})}):null]})})};let{Option:eh}=T.default;var eu=e=>{let{userID:t,accessToken:s}=e,[r]=E.Z.useForm(),[a,i]=(0,n.useState)(!1),[d,h]=(0,n.useState)(null),[u,x]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await p(s,t,"any"),l=[];for(let t=0;t{i(!1),r.resetFields()},g=()=>{i(!1),h(null),r.resetFields()},Z=async e=>{try{c.ZP.info("Making API Call"),i(!0),console.log("formValues in create user:",e);let l=await m(s,t,e);console.log("user create Response:",l),h(l.key),c.ZP.success("API user Created"),r.resetFields(),localStorage.removeItem("userData"+t)}catch(e){console.error("Error creating the user:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Create New User"}),(0,l.jsx)(F.Z,{title:"Create User",visible:a,width:800,footer:null,onOk:j,onCancel:g,children:(0,l.jsxs)(E.Z,{form:r,onFinish:Z,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsx)(E.Z.Item,{label:"User ID",name:"user_id",children:(0,l.jsx)(O.Z,{placeholder:"Enter User ID"})}),(0,l.jsx)(E.Z.Item,{label:"Team ID",name:"team_id",children:(0,l.jsx)(O.Z,{placeholder:"ai_team"})}),(0,l.jsx)(E.Z.Item,{label:"Models",name:"models",children:(0,l.jsx)(T.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:u.map(e=>(0,l.jsx)(eh,{value:e,children:e},e))})}),(0,l.jsx)(E.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(D.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(E.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Duration (eg: 30s, 30h, 30d)",name:"duration",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Metadata",name:"metadata",children:(0,l.jsx)(O.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(M.ZP,{htmlType:"submit",children:"Create User"})})]})}),d&&(0,l.jsxs)(F.Z,{title:"Save Your User",visible:a,onOk:j,onCancel:g,footer:null,children:[(0,l.jsxs)("p",{children:["Please save this secret user somewhere safe and accessible. For security reasons, ",(0,l.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret user, you will need to generate a new one."]}),(0,l.jsx)("p",{children:null!=d?"API user: ".concat(d):"User being created, this might take 30s"})]})]})},ex=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,[o,i]=(0,n.useState)(null),[c,d]=(0,n.useState)([]);return((0,n.useEffect)(()=>{if(!t||!s||!r||!a)return;let e=async()=>{try{let e=await u(t,null,r,!0);console.log("user data response:",e),i(e)}catch(e){console.error("There was an error fetching the model data",e)}};t&&s&&r&&a&&e()},[t,s,r,a]),o&&t&&s&&r&&a)?(0,l.jsx)("div",{style:{width:"100%"},children:(0,l.jsxs)(C.Z,{className:"gap-2 p-10 h-[75vh] w-full",children:[(0,l.jsx)(eu,{userID:a,accessToken:t}),(0,l.jsx)(z.Z,{children:(0,l.jsxs)(B.Z,{className:"mt-5",children:[(0,l.jsx)(G.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User ID "})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Role"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Models"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Spend ($ USD)"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Max Budget ($ USD)"})})]})}),(0,l.jsx)(K.Z,{children:o.map(e=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.user_id})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.user_role?e.user_role:"app_user"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.models&&e.models.length>0?e.models:"All Models"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.spend?e.spend:0})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.max_budget?e.max_budget:"Unlimited"})})]},e.user_id))})]})})]})}):(0,l.jsx)("div",{children:"Loading..."})},ep=s(8510),ej=e=>{let{teams:t,searchParams:s,accessToken:r,setTeams:a}=e,[i]=E.Z.useForm(),[d]=E.Z.useForm(),{Title:m,Paragraph:h}=es.default,[u,x]=(0,n.useState)(""),[p,j]=(0,n.useState)(t?t[0]:null),[g,Z]=(0,n.useState)(!1),[y,f]=(0,n.useState)(!1),w=async e=>{try{if(null!=r){c.ZP.info("Making API Call");let s=await S(r,e);null!==t?a([...t,s]):a([s]),console.log("response for team create call: ".concat(s)),Z(!1)}}catch(e){console.error("Error creating the key:",e)}},_=async e=>{try{if(null!=r&&null!=t){c.ZP.info("Making API Call");let s={role:"user",user_email:e.user_email,user_id:e.user_id},l=await N(r,p.team_id,s);console.log("response for team create call: ".concat(l.data));let n=t.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(l.data.team_id)),e.team_id===l.data.team_id));if(console.log("foundIndex: ".concat(n)),-1!==n){let e=[...t];e[n]=l.data,a(e),j(l.data)}f(!1)}}catch(e){console.error("Error creating the key:",e)}};return console.log("received teams ".concat(t)),(0,l.jsx)("div",{className:"w-full",children:(0,l.jsxs)(C.Z,{numItems:1,className:"gap-2 p-2 h-[75vh] w-full",children:[(0,l.jsxs)(I.Z,{numColSpan:1,children:[(0,l.jsx)(m,{level:4,children:"All Teams"}),(0,l.jsx)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,l.jsxs)(B.Z,{children:[(0,l.jsx)(G.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(V.Z,{children:"Team Name"}),(0,l.jsx)(V.Z,{children:"Spend (USD)"}),(0,l.jsx)(V.Z,{children:"Budget (USD)"}),(0,l.jsx)(V.Z,{children:"TPM / RPM Limits"})]})}),(0,l.jsx)(K.Z,{children:t&&t.length>0?t.map(e=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:e.team_alias}),(0,l.jsx)(J.Z,{children:e.spend}),(0,l.jsx)(J.Z,{children:e.max_budget?e.max_budget:"No limit"}),(0,l.jsx)(J.Z,{children:(0,l.jsxs)(P.Z,{children:["TPM Limit:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,l.jsx)("br",{})," RPM Limit:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{icon:ep.Z,size:"sm"})})]},e.team_id)):null})]})})]}),(0,l.jsxs)(I.Z,{numColSpan:1,children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>Z(!0),children:"+ Create New Team"}),(0,l.jsx)(F.Z,{title:"Create Team",visible:g,width:800,footer:null,onOk:()=>{Z(!1),i.resetFields()},onCancel:()=>{Z(!1),i.resetFields()},children:(0,l.jsxs)(E.Z,{form:i,onFinish:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Team Name",name:"team_alias",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Models",name:"models",children:(0,l.jsx)(T.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"}})}),(0,l.jsx)(E.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(D.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(E.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(M.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,l.jsxs)(I.Z,{numColSpan:1,children:[(0,l.jsx)(m,{level:4,children:"Team Members"}),(0,l.jsx)(h,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),t&&t.length>0?(0,l.jsx)(el.Z,{defaultValue:"0",children:t.map((e,t)=>(0,l.jsx)(en.Z,{value:String(t),onClick:()=>{j(e)},children:e.team_alias},t))}):(0,l.jsxs)(h,{children:["No team created. ",(0,l.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,l.jsx)(I.Z,{numColSpan:1,children:(0,l.jsx)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,l.jsxs)(B.Z,{children:[(0,l.jsx)(G.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(V.Z,{children:"Member Name"}),(0,l.jsx)(V.Z,{children:"Role"}),(0,l.jsx)(V.Z,{children:"Action"})]})}),(0,l.jsx)(K.Z,{children:p?p.members_with_roles.map((e,t)=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,l.jsx)(J.Z,{children:e.role}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{icon:ep.Z,size:"sm"})})]},t)):null})]})})}),(0,l.jsxs)(I.Z,{numColSpan:1,children:[(0,l.jsx)(o.Z,{className:"mx-auto mb-5",onClick:()=>f(!0),children:"+ Add member"}),(0,l.jsx)(F.Z,{title:"Add member",visible:y,width:800,footer:null,onOk:()=>{f(!1),d.resetFields()},onCancel:()=>{f(!1),d.resetFields()},children:(0,l.jsxs)(E.Z,{form:i,onFinish:_,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,l.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,l.jsx)(E.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(M.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},eg=e=>{let{searchParams:t,accessToken:s}=e,[r]=E.Z.useForm(),[a]=E.Z.useForm(),{Title:i,Paragraph:d}=es.default,[m,h]=(0,n.useState)(""),[u,x]=(0,n.useState)(null),[p,j]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],t=await v(s,"proxy_admin_viewer");t.forEach(t=>{e.push({user_role:t.user_role,user_id:t.user_id,user_email:t.user_email})}),console.log("proxy viewers: ".concat(t));let l=await v(s,"proxy_admin");l.forEach(t=>{e.push({user_role:t.user_role,user_id:t.user_id,user_email:t.user_email})}),console.log("proxy admins: ".concat(l)),console.log("combinedList: ".concat(e)),x(e)}})()},[s]);let g=async e=>{try{if(null!=s&&null!=u){c.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await A(s,e);console.log("response for team create call: ".concat(t));let l=u.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(l)),-1==l&&(console.log("updates admin with new user"),u.push(t),x(u)),j(!1)}}catch(e){console.error("Error creating the key:",e)}};return console.log("admins: ".concat(null==u?void 0:u.length)),(0,l.jsxs)("div",{className:"w-full m-2",children:[(0,l.jsx)(i,{level:4,children:"Proxy Admins"}),(0,l.jsx)(d,{children:"Add other people to just view global spend. They cannot create teams or grant users access to new models."}),(0,l.jsxs)(C.Z,{numItems:1,className:"gap-2 p-0 w-full",children:[(0,l.jsx)(I.Z,{numColSpan:1,children:(0,l.jsx)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,l.jsxs)(B.Z,{children:[(0,l.jsx)(G.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(V.Z,{children:"Member Name"}),(0,l.jsx)(V.Z,{children:"Role"}),(0,l.jsx)(V.Z,{children:"Action"})]})}),(0,l.jsx)(K.Z,{children:u?u.map((e,t)=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,l.jsx)(J.Z,{children:e.user_role}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{icon:ep.Z,size:"sm"})})]},t)):null})]})})}),(0,l.jsxs)(I.Z,{numColSpan:1,children:[(0,l.jsx)(o.Z,{className:"mx-auto mb-5",onClick:()=>j(!0),children:"+ Add viewer"}),(0,l.jsx)(F.Z,{title:"Add viewer",visible:p,width:800,footer:null,onOk:()=>{j(!1),a.resetFields()},onCancel:()=>{j(!1),a.resetFields()},children:(0,l.jsxs)(E.Z,{form:r,onFinish:g,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,l.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,l.jsx)(E.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(M.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})]})},eZ=s(92836),ey=s(26734),ef=s(41608),ew=s(32126),e_=s(23682),ek=s(12968),eb=s(67951);async function ev(e,t,s,l){console.log("isLocal:",!1);let n=window.location.origin,r=new ek.ZP.OpenAI({apiKey:l,baseURL:n,dangerouslyAllowBrowser:!0});for await(let l of(await r.chat.completions.create({model:s,stream:!0,messages:[{role:"user",content:e}]})))console.log(l),l.choices[0].delta.content&&t(l.choices[0].delta.content)}var eS=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,[o,i]=(0,n.useState)(""),[c,d]=(0,n.useState)([]),[m,h]=(0,n.useState)(void 0),[u,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&s&&r&&a&&(async()=>{let e=await p(t,a,r);console.log("model_info:",e),(null==e?void 0:e.data.length)>0&&(x(e.data),h(e.data[0].id))})()},[t,a,r]);let j=(e,t)=>{d(s=>{let l=s[s.length-1];return l&&l.role===e?[...s.slice(0,s.length-1),{role:e,content:l.content+t}]:[...s,{role:e,content:t}]})},g=async()=>{if(""!==o.trim()&&t&&s&&r&&a){d(e=>[...e,{role:"user",content:o}]);try{m&&await ev(o,e=>j("assistant",e),m,t)}catch(e){console.error("Error fetching model response",e),j("assistant","Error fetching model response")}i("")}};return(0,l.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,l.jsx)(C.Z,{className:"gap-2 p-10 h-[75vh] w-full",children:(0,l.jsx)(z.Z,{children:(0,l.jsxs)(ey.Z,{children:[(0,l.jsxs)(ef.Z,{className:"mt-4",children:[(0,l.jsx)(eZ.Z,{children:"Chat"}),(0,l.jsx)(eZ.Z,{children:"API Reference"})]}),(0,l.jsxs)(e_.Z,{children:[(0,l.jsxs)(ew.Z,{children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{children:"Select Model:"}),(0,l.jsx)("select",{value:m||"",onChange:e=>h(e.target.value),children:null==u?void 0:u.map(e=>(0,l.jsx)("option",{value:e.id,children:e.id},e.id))})]}),(0,l.jsxs)(B.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,l.jsx)(G.Z,{children:(0,l.jsx)($.Z,{children:(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Chat"})})})}),(0,l.jsx)(K.Z,{children:c.map((e,t)=>(0,l.jsx)($.Z,{children:(0,l.jsx)(J.Z,{children:"".concat(e.role,": ").concat(e.content)})},t))})]}),(0,l.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,l.jsxs)("div",{className:"flex",children:[(0,l.jsx)("input",{type:"text",value:o,onChange:e=>i(e.target.value),className:"flex-1 p-2 border rounded-md mr-2",placeholder:"Type your message..."}),(0,l.jsx)("button",{onClick:g,className:"p-2 bg-blue-500 text-white rounded-md",children:"Send"})]})})]}),(0,l.jsx)(ew.Z,{children:(0,l.jsxs)(ey.Z,{children:[(0,l.jsxs)(ef.Z,{children:[(0,l.jsx)(eZ.Z,{children:"OpenAI Python SDK"}),(0,l.jsx)(eZ.Z,{children:"LlamaIndex"}),(0,l.jsx)(eZ.Z,{children:"Langchain Py"})]}),(0,l.jsxs)(e_.Z,{children:[(0,l.jsx)(ew.Z,{children:(0,l.jsx)(eb.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # proxy base url\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to use from Models Tab\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ],\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-openai-client",\n "generation_id": "openai-client-gen-id22",\n "trace_id": "openai-client-trace-id22",\n "trace_user_id": "openai-client-user-id2"\n }\n }\n)\n\nprint(response)\n '})}),(0,l.jsx)(ew.Z,{children:(0,l.jsx)(eb.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="http://0.0.0.0:4000", # 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="http://0.0.0.0:4000",\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,l.jsx)(ew.Z,{children:(0,l.jsx)(eb.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="http://0.0.0.0:8000",\n model = "gpt-3.5-turbo",\n temperature=0.1,\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-langchain-client",\n "generation_id": "langchain-client-gen-id22",\n "trace_id": "langchain-client-trace-id22",\n "trace_user_id": "langchain-client-user-id2"\n }\n }\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 '})})]})]})})]})]})})})})},eN=s(33509),eA=s(30569);let{Sider:eI}=eN.default;var eC=e=>{let{setPage:t,userRole:s,defaultSelectedKey:n}=e;return(0,l.jsx)(eN.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,l.jsx)(eI,{width:120,children:(0,l.jsxs)(eA.Z,{mode:"inline",defaultSelectedKeys:n||["1"],style:{height:"100%",borderRight:0},children:[(0,l.jsx)(eA.Z.Item,{onClick:()=>t("api-keys"),children:"API Keys"},"1"),(0,l.jsx)(eA.Z.Item,{onClick:()=>t("models"),children:"Models"},"2"),(0,l.jsx)(eA.Z.Item,{onClick:()=>t("llm-playground"),children:"Chat UI"},"3"),(0,l.jsx)(eA.Z.Item,{onClick:()=>t("usage"),children:"Usage"},"4"),"Admin"==s?(0,l.jsx)(eA.Z.Item,{onClick:()=>t("users"),children:"Users"},"5"):null,"Admin"==s?(0,l.jsx)(eA.Z.Item,{onClick:()=>t("teams"),children:"Teams"},"6"):null,"Admin"==s?(0,l.jsx)(eA.Z.Item,{onClick:()=>t("admin-panel"),children:"Admin"},"7"):null]})})})},eP=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,o=new Date,[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)([]),[h,u]=(0,n.useState)([]),x=new Date(o.getFullYear(),o.getMonth(),1),p=new Date(o.getFullYear(),o.getMonth()+1,0),j=k(x),_=k(p);function k(e){let t=e.getFullYear(),s=e.getMonth()+1,l=e.getDate();return"".concat(t,"-").concat(s<10?"0"+s:s,"-").concat(l<10?"0"+l:l)}return console.log("Start date is ".concat(j)),console.log("End date is ".concat(_)),(0,n.useEffect)(()=>{t&&s&&r&&a&&(async()=>{try{if(console.log("user role: ".concat(r)),"Admin"==r){let e=await Z(t);c(e);let s=(await y(t)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,7),spend:e.total_spend}));m(s),await f(t)}else"App Owner"==r&&await g(t,s,r,a,j,_).then(async e=>{if(console.log("result from spend logs call",e),"daily_spend"in e){let t=e.daily_spend;console.log("daily spend",t),c(t);let s=e.top_api_keys;m(s)}else{let s=(await w(t,function(e){let t=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[s,l]=e;"spend"!==s&&"startTime"!==s&&"models"!==s&&"users"!==s&&t.push({key:s,spend:l})})}),t.sort((e,t)=>Number(t.spend)-Number(e.spend));let s=t.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(s[0]))),s}(e))).info.map(e=>({key:(e.key_name||e.key_alias||e.token).substring(0,7),spend:e.spend}));m(s),u(function(e){let t={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[s,l]=e;""!==s&&null!=s&&"None"!=s&&(t[s]||(t[s]=0),t[s]+=l)})});let s=Object.entries(t).map(e=>{let[t,s]=e;return{user_id:t,spend:s}});s.sort((e,t)=>t.spend-e.spend);let l=s.slice(0,5);return console.log("topKeys: ".concat(Object.values(l[0]))),l}(e)),c(e)}})}catch(e){console.error("There was an error fetching the data",e)}})()},[t,s,r,a,j,_]),(0,l.jsx)("div",{style:{width:"100%"},children:(0,l.jsxs)(C.Z,{numItems:2,className:"gap-2 p-10 h-[75vh] w-full",children:[(0,l.jsx)(I.Z,{numColSpan:2,children:(0,l.jsxs)(z.Z,{children:[(0,l.jsx)(X.Z,{children:"Monthly Spend"}),(0,l.jsx)(Y.Z,{data:i,index:"startTime",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,l.jsx)(I.Z,{numColSpan:1,children:(0,l.jsxs)(z.Z,{children:[(0,l.jsx)(X.Z,{children:"Top API Keys"}),(0,l.jsx)(Y.Z,{className:"mt-4 h-40",data:d,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,l.jsx)(I.Z,{numColSpan:1,children:(0,l.jsxs)(z.Z,{children:[(0,l.jsx)(X.Z,{children:"Top Users"}),(0,l.jsx)(Y.Z,{className:"mt-4 h-40",data:h,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})})},eT=()=>{let[e,t]=(0,n.useState)(""),[s,a]=(0,n.useState)(null),[o,c]=(0,n.useState)(null),[d,m]=(0,n.useState)(!0),h=(0,r.useSearchParams)(),u=h.get("userID"),x=h.get("token"),[p,j]=(0,n.useState)("api-keys"),[g,Z]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(x){let e=(0,ea.o)(x);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),Z(e.key),e.user_role){let s=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),t(s)}else console.log("User role not defined");e.user_email?a(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?m("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[x]),(0,l.jsx)(n.Suspense,{fallback:(0,l.jsx)("div",{children:"Loading..."}),children:(0,l.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,l.jsx)(i,{userID:u,userRole:e,userEmail:s,showSSOBanner:d}),(0,l.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,l.jsx)(eC,{setPage:j,userRole:e,defaultSelectedKey:null}),"api-keys"==p?(0,l.jsx)(eo,{userID:u,userRole:e,teams:o,setUserRole:t,userEmail:s,setUserEmail:a,setTeams:c}):"models"==p?(0,l.jsx)(em,{userID:u,userRole:e,token:x,accessToken:g}):"llm-playground"==p?(0,l.jsx)(eS,{userID:u,userRole:e,token:x,accessToken:g}):"users"==p?(0,l.jsx)(ex,{userID:u,userRole:e,token:x,accessToken:g}):"teams"==p?(0,l.jsx)(ej,{teams:o,setTeams:c,searchParams:h,accessToken:g}):"admin-panel"==p?(0,l.jsx)(eg,{setTeams:c,searchParams:h,accessToken:g}):(0,l.jsx)(eP,{userID:u,userRole:e,token:x,accessToken:g})]})]})})}}},function(e){e.O(0,[303,971,69,744],function(){return e(e.s=79615)}),_N_E=e.O()}]); \ No newline at end of file +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{79615:function(e,t,s){Promise.resolve().then(s.bind(s,30280))},30280:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return eT}});var l=s(3827),n=s(64090),r=s(47907),a=s(8792),o=s(2179),i=e=>{let{userID:t,userRole:s,userEmail:n,showSSOBanner:r}=e;return console.log("User ID:",t),console.log("userEmail:",n),(0,l.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,l.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,l.jsx)("div",{className:"flex flex-col items-center",children:(0,l.jsx)(a.default,{href:"/",children:(0,l.jsx)("button",{className:"text-gray-800 text-2xl py-1 rounded text-center",children:(0,l.jsx)("img",{src:"/get_image",width:200,height:200,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,l.jsxs)("div",{className:"text-right mx-4 my-2 absolute top-0 right-0 flex items-center justify-end space-x-2",children:[r?(0,l.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#setup-ssoauth-for-ui",target:"_blank",className:"mr-2",children:(0,l.jsx)(o.Z,{variant:"primary",size:"lg",children:"Enable SSO"})}):null,(0,l.jsxs)(o.Z,{variant:"secondary",size:"lg",children:[n,(0,l.jsxs)("p",{children:["Role: ",s]}),(0,l.jsxs)("p",{children:["ID: ",t]})]})]})]})},c=s(80588);let d=async(e,t,s)=>{try{if(console.log("Form Values in keyCreateCall:",s),s.description&&(s.metadata||(s.metadata={}),s.metadata.description=s.description,delete s.description,s.metadata=JSON.stringify(s.metadata)),s.metadata){console.log("formValues.metadata:",s.metadata);try{s.metadata=JSON.parse(s.metadata)}catch(e){throw c.ZP.error("Failed to parse metadata: "+e),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",s);let l=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...s})});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let n=await l.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},m=async(e,t,s)=>{try{if(console.log("Form Values in keyCreateCall:",s),s.description&&(s.metadata||(s.metadata={}),s.metadata.description=s.description,delete s.description,s.metadata=JSON.stringify(s.metadata)),s.metadata){console.log("formValues.metadata:",s.metadata);try{s.metadata=JSON.parse(s.metadata)}catch(e){throw c.ZP.error("Failed to parse metadata: "+e),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",s);let l=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...s})});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let n=await l.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},h=async(e,t)=>{try{console.log("in keyDeleteCall:",t),c.ZP.info("Making key delete request");let s=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[t]})});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let l=await s.json();return console.log(l),c.ZP.success("API Key Deleted"),l}catch(e){throw console.error("Failed to create key:",e),e}},u=async function(e,t,s){let l=arguments.length>3&&void 0!==arguments[3]&&arguments[3];try{let n="/user/info";"App Owner"==s&&t&&(n="".concat(n,"/?user_id=").concat(t)),console.log("in userInfoCall viewAll=",l),l&&(n="".concat(n,"/?view_all=true")),c.ZP.info("Requesting user data");let r=await fetch(n,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.text();throw c.ZP.error(e),Error("Network response was not ok")}let a=await r.json();return console.log("API Response:",a),c.ZP.info("Received user data"),a}catch(e){throw console.error("Failed to create key:",e),e}},x=async(e,t,s)=>{try{c.ZP.info("Requesting model data");let t=await fetch("/v2/model/info",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return c.ZP.info("Received model data"),s}catch(e){throw console.error("Failed to create key:",e),e}},p=async(e,t,s)=>{try{c.ZP.info("Requesting model data");let t=await fetch("/models",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return c.ZP.info("Received model data"),s}catch(e){throw console.error("Failed to create key:",e),e}},j=async(e,t)=>{try{let s="/spend/logs";console.log("in keySpendLogsCall:",s);let l=await fetch("".concat(s,"/?api_key=").concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw c.ZP.error(e),Error("Network response was not ok")}let n=await l.json();return console.log(n),n}catch(e){throw console.error("Failed to create key:",e),e}},g=async(e,t,s,l,n,r)=>{try{console.log("user role in spend logs call: ".concat(s));let t="/spend/logs";t="App Owner"==s?"".concat(t,"/?user_id=").concat(l,"&start_date=").concat(n,"&end_date=").concat(r):"".concat(t,"/?start_date=").concat(n,"&end_date=").concat(r),c.ZP.info("Making spend logs request");let a=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!a.ok){let e=await a.text();throw c.ZP.error(e),Error("Network response was not ok")}let o=await a.json();return console.log(o),c.ZP.success("Spend Logs received"),o}catch(e){throw console.error("Failed to create key:",e),e}},Z=async e=>{try{c.ZP.info("Making spend logs request");let t=await fetch("/global/spend/logs",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return console.log(s),c.ZP.success("Spend Logs received"),s}catch(e){throw console.error("Failed to create key:",e),e}},y=async e=>{try{c.ZP.info("Making spend keys request");let t=await fetch("/global/spend/keys?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return console.log(s),c.ZP.success("Spend Logs received"),s}catch(e){throw console.error("Failed to create key:",e),e}},f=async e=>{try{c.ZP.info("Making spend models request");let t=await fetch("/global/spend/models?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw c.ZP.error(e),Error("Network response was not ok")}let s=await t.json();return console.log(s),c.ZP.success("Spend Logs received"),s}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,t)=>{try{let s=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:t})});if(!s.ok){let e=await s.text();throw c.ZP.error(e),Error("Network response was not ok")}let l=await s.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},_=async(e,t)=>{try{let s="/spend/users";console.log("in spendUsersCall:",s);let l=await fetch("".concat(s,"/?user_id=").concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw c.ZP.error(e),Error("Network response was not ok")}let n=await l.json();return console.log(n),n}catch(e){throw console.error("Failed to get spend for user",e),e}},k=async(e,t,s,l)=>{try{let n=await fetch("/user/request_model",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({models:[t],user_id:s,justification:l})});if(!n.ok){let e=await n.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let r=await n.json();return console.log(r),c.ZP.success(""),r}catch(e){throw console.error("Failed to create key:",e),e}},b=async e=>{try{let t="/user/get_requests";console.log("in userGetRequesedtModelsCall:",t);let s=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let l=await s.json();return console.log(l),c.ZP.success(""),l}catch(e){throw console.error("Failed to get requested models:",e),e}},v=async(e,t)=>{try{let s="/user/get_users?role=".concat(t);console.log("in userGetAllUsersCall:",s);let l=await fetch(s,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let n=await l.json();return console.log(n),c.ZP.success("Got all users"),n}catch(e){throw console.error("Failed to get requested models:",e),e}},S=async(e,t)=>{try{console.log("Form Values in teamCreateCall:",t);let s=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let l=await s.json();return console.log("API Response:",l),l}catch(e){throw console.error("Failed to create key:",e),e}},N=async(e,t,s)=>{try{console.log("Form Values in teamMemberAddCall:",s);let l=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,member:s})});if(!l.ok){let e=await l.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let n=await l.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},A=async(e,t)=>{try{console.log("Form Values in userUpdateUserCall:",t);let s=await fetch("/user/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_role:"proxy_admin_viewer",...t})});if(!s.ok){let e=await s.text();throw c.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let l=await s.json();return console.log("API Response:",l),c.ZP.success("User role updated"),l}catch(e){throw console.error("Failed to create key:",e),e}};var C=s(10384),I=s(46453),P=s(71801),T=s(17189),E=s(12143),F=s(77171),O=s(42539),D=s(88707),R=s(1861);let{Option:M}=T.default;var U=e=>{let{userID:t,teamID:s,userRole:r,accessToken:a,data:i,userModels:m,setData:h}=e,[u]=E.Z.useForm(),[x,p]=(0,n.useState)(!1),[j,g]=(0,n.useState)(null),Z=()=>{p(!1),u.resetFields()},y=()=>{p(!1),g(null),u.resetFields()},f=async e=>{try{c.ZP.info("Making API Call"),p(!0);let s=await d(a,t,e);h(e=>e?[...e,s]:[s]),g(s.key),c.ZP.success("API Key Created"),u.resetFields(),localStorage.removeItem("userData"+t)}catch(e){console.error("Error creating the key:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>p(!0),children:"+ Create New Key"}),(0,l.jsx)(F.Z,{title:"Create Key",visible:x,width:800,footer:null,onOk:Z,onCancel:y,children:(0,l.jsxs)(E.Z,{form:u,onFinish:f,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===r||"Admin"===r?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Key Name",name:"key_alias",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Team ID",name:"team_id",children:(0,l.jsx)(O.Z,{placeholder:"ai_team",defaultValue:s||""})}),(0,l.jsx)(E.Z.Item,{label:"Models",name:"models",children:(0,l.jsx)(T.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:m.map(e=>(0,l.jsx)(M,{value:e,children:e},e))})}),(0,l.jsx)(E.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(D.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(E.Z.Item,{label:"Reset Budget",name:"budget_duration",children:(0,l.jsxs)(T.default,{defaultValue:null,placeholder:"n/a",children:[(0,l.jsx)(T.default.Option,{value:"24h",children:"daily"}),(0,l.jsx)(T.default.Option,{value:"30d",children:"monthly"})]})}),(0,l.jsx)(E.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Metadata",name:"metadata",children:(0,l.jsx)(O.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Key Name",name:"key_alias",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Team ID (Contact Group)",name:"team_id",children:(0,l.jsx)(O.Z,{placeholder:"ai_team"})}),(0,l.jsx)(E.Z.Item,{label:"Description",name:"description",children:(0,l.jsx)(O.Z.TextArea,{placeholder:"Enter description",rows:4})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(R.ZP,{htmlType:"submit",children:"Create Key"})})]})}),j&&(0,l.jsx)(F.Z,{title:"Save your key",visible:x,onOk:Z,onCancel:y,footer:null,children:(0,l.jsxs)(I.Z,{numItems:1,className:"gap-2 w-full",children:[(0,l.jsx)(C.Z,{numColSpan:1,children:(0,l.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,l.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,l.jsx)(C.Z,{numColSpan:1,children:null!=j?(0,l.jsxs)(P.Z,{children:["API Key: ",j]}):(0,l.jsx)(P.Z,{children:"Key being created, this might take 30s"})})]})})]})},L=s(33393),z=s(13810),q=s(61244),B=s(10827),K=s(3851),J=s(2044),V=s(64167),G=s(74480),$=s(7178),W=s(9853),Y=s(67989),H=s(56863),X=s(42440),Q=e=>{let{token:t,accessToken:s,keySpend:r,keyBudget:a,keyName:i}=e,[c,d]=(0,n.useState)(!1),[m,h]=(0,n.useState)(null),[u,x]=(0,n.useState)(null),p=async()=>{try{if(null==s||null==t)return;console.log("accessToken: ".concat(s,"; token: ").concat(t));let e=await j(s,t);console.log("Response:",e);let l=Object.values(e).reduce((e,t)=>{let s=new Date(t.startTime),l=new Intl.DateTimeFormat("en-US",{day:"2-digit",month:"short"}).format(s);return e[l]=(e[l]||0)+t.spend,e},{}),n=Object.entries(l);n.sort((e,t)=>{let[s]=e,[l]=t,n=new Date(s),r=new Date(l);return n.getTime()-r.getTime()});let r=Object.fromEntries(n);console.log(r);let a=Object.values(e).reduce((e,t)=>{let s=t.user;return e[s]=(e[s]||0)+t.spend,e},{});console.log(l),console.log(a);let o=[];for(let[e,t]of Object.entries(r))o.push({day:e,spend:t});let i=Object.entries(a).sort((e,t)=>t[1]-e[1]).slice(0,5).map(e=>{let[t,s]=e;return{name:t,value:s}});h(o),x(i),console.log("arrayBarChart:",o)}catch(e){console.error("There was an error fetching the data",e)}};return t?(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>{console.log("Show Modal triggered"),d(!0),p()},children:"View Spend Report"}),(0,l.jsxs)(F.Z,{visible:c,width:1e3,onOk:()=>{d(!1)},onCancel:()=>{d(!1)},footer:null,children:[(0,l.jsxs)(X.Z,{style:{textAlign:"left"},children:["Key Name: ",i]}),(0,l.jsxs)(H.Z,{children:["Monthly Spend $",r]}),(0,l.jsx)(z.Z,{className:"mt-6 mb-6",children:m&&(0,l.jsx)(W.Z,{className:"mt-6",data:m,colors:["green"],index:"day",categories:["spend"],yAxisWidth:48})}),(0,l.jsx)(X.Z,{className:"mt-6",children:"Top 5 Users Spend (USD)"}),(0,l.jsx)(z.Z,{className:"mb-6",children:u&&(0,l.jsx)(Y.Z,{className:"mt-6",data:u,color:"teal"})})]})]}):null},ee=e=>{let{userID:t,accessToken:s,data:r,setData:a}=e,[i,c]=(0,n.useState)(!1),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),p=async e=>{null!=r&&(x(e),localStorage.removeItem("userData"+t),m(!0))},j=async()=>{if(null!=u&&null!=r){try{await h(s,u);let e=r.filter(e=>e.token!==u);a(e)}catch(e){console.error("Error deleting the key:",e)}m(!1),x(null)}};if(null!=r)return console.log("RERENDER TRIGGERED"),(0,l.jsxs)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:[(0,l.jsxs)(B.Z,{className:"mt-5",children:[(0,l.jsx)(V.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(G.Z,{children:"Key Alias"}),(0,l.jsx)(G.Z,{children:"Secret Key"}),(0,l.jsx)(G.Z,{children:"Spend (USD)"}),(0,l.jsx)(G.Z,{children:"Key Budget (USD)"}),(0,l.jsx)(G.Z,{children:"Team ID"}),(0,l.jsx)(G.Z,{children:"Metadata"}),(0,l.jsx)(G.Z,{children:"Models"}),(0,l.jsx)(G.Z,{children:"TPM / RPM Limits"}),(0,l.jsx)(G.Z,{children:"Expires"})]})}),(0,l.jsx)(K.Z,{children:r.map(e=>(console.log(e),"litellm-dashboard"===e.team_id)?null:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:null!=e.key_alias?(0,l.jsx)(P.Z,{children:e.key_alias}):(0,l.jsx)(P.Z,{children:"Not Set"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:e.key_name})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:e.spend})}),(0,l.jsx)(J.Z,{children:null!=e.max_budget?(0,l.jsx)(P.Z,{children:e.max_budget}):(0,l.jsx)(P.Z,{children:"Unlimited Budget"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:e.team_id})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:JSON.stringify(e.metadata)})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(P.Z,{children:JSON.stringify(e.models)})}),(0,l.jsx)(J.Z,{children:(0,l.jsxs)(P.Z,{children:["TPM Limit: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,l.jsx)("br",{})," RPM Limit:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,l.jsx)(J.Z,{children:null!=e.expires?(0,l.jsx)(P.Z,{children:e.expires}):(0,l.jsx)(P.Z,{children:"Never expires"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{onClick:()=>p(e.token),icon:L.Z,size:"sm"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(Q,{token:e.token,accessToken:s,keySpend:e.spend,keyBudget:e.max_budget,keyName:e.key_name})})]},e.token))})]}),d&&(0,l.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,l.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,l.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,l.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,l.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,l.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,l.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,l.jsx)("div",{className:"sm:flex sm:items-start",children:(0,l.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,l.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,l.jsx)("div",{className:"mt-2",children:(0,l.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,l.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,l.jsx)(o.Z,{onClick:j,color:"red",className:"ml-2",children:"Delete"}),(0,l.jsx)(o.Z,{onClick:()=>{m(!1),x(null)},children:"Cancel"})]})]})]})})]})},et=e=>{let{userID:t,userSpendData:s,userRole:r,accessToken:a}=e;console.log("User SpendData:",s);let[o,i]=(0,n.useState)(null==s?void 0:s.spend),[c,d]=(0,n.useState)((null==s?void 0:s.max_budget)||null);return(0,n.useEffect)(()=>{(async()=>{if("Admin"===r)try{let e=await _(a,"litellm-proxy-budget");console.log("Result from callSpendUsers:",e);let t=e[0];i(null==t?void 0:t.spend),d((null==t?void 0:t.max_budget)||null)}catch(e){console.error("Failed to get spend for user",e)}})()},[r,a,t]),(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)(z.Z,{className:"mx-auto mb-4",children:[(0,l.jsxs)(H.Z,{children:["$",o]}),(0,l.jsxs)(X.Z,{children:["/ ",null!==c?"$".concat(c," limit"):"No limit"]})]})})},es=s(36083),el=s(68967),en=s(27166),er=e=>{let{teams:t,setSelectedTeam:s}=e,{Title:r,Paragraph:a}=es.default,[o,i]=(0,n.useState)("");return(0,l.jsxs)("div",{className:"mt-10",children:[(0,l.jsx)(r,{level:4,children:"Default Team"}),(0,l.jsx)(a,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),t&&t.length>0?(0,l.jsx)(el.Z,{defaultValue:"0",children:t.map((e,t)=>(0,l.jsx)(en.Z,{value:String(t),onClick:()=>s(e),children:e.team_alias},t))}):(0,l.jsxs)(a,{children:["No team created. ",(0,l.jsx)("b",{children:"Defaulting to personal account."})]})]})},ea=s(37963);console.log("isLocal:",!1);var eo=e=>{let{userID:t,userRole:s,teams:a,setUserRole:o,userEmail:i,setUserEmail:c,setTeams:d}=e,[m,h]=(0,n.useState)(null),[x,j]=(0,n.useState)(null),g=(0,r.useSearchParams)();g.get("viewSpend"),(0,r.useRouter)();let Z=g.get("token"),[y,f]=(0,n.useState)(null),[w,_]=(0,n.useState)([]),[k,b]=(0,n.useState)(a?a[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(Z){let e=(0,ea.o)(Z);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),f(e.key),e.user_role){let t=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";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",t),o(t)}else console.log("User role not defined");e.user_email?c(e.user_email):console.log("User Email is not set ".concat(e))}}if(t&&y&&s&&!m){let e=sessionStorage.getItem("userModels"+t);e?_(JSON.parse(e)):(async()=>{try{let e=await u(y,t,s);console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),j(e.user_info),h(e.keys),d(e.teams),b(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+t,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+t,JSON.stringify(e.user_info));let l=(await p(y,t,s)).data.map(e=>e.id);console.log("available_model_names:",l),_(l),console.log("userModels:",w),sessionStorage.setItem("userModels"+t,JSON.stringify(l))}catch(e){console.error("There was an error fetching the data",e)}})()}},[t,Z,y,m,s]),null==t||null==Z){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}return null==y?null:(null==s&&o("App Owner"),(0,l.jsx)("div",{children:(0,l.jsx)(I.Z,{numItems:1,className:"gap-0 p-10 h-[75vh] w-full",children:(0,l.jsxs)(C.Z,{numColSpan:1,children:[(0,l.jsx)(et,{userID:t,userSpendData:x,userRole:s,accessToken:y}),(0,l.jsx)(ee,{userID:t,accessToken:y,data:m,setData:h}),(0,l.jsx)(U,{userID:t,teamID:k?k.team_id:null,userRole:s,userModels:w,accessToken:y,data:m,setData:h}),(0,l.jsx)(er,{teams:a,setSelectedTeam:b})]})})}))},ei=s(5);let{Option:ec}=T.default;var ed=e=>{let{userModels:t,accessToken:s,userID:r}=e,[a]=E.Z.useForm(),[i,d]=(0,n.useState)(!1),m=async e=>{try{c.ZP.info("Requesting access");let{selectedModel:t,accessReason:l}=e;await k(s,t,r,l),d(!0)}catch(e){console.error("Error requesting access:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{size:"xs",onClick:()=>d(!0),children:"Request Access"}),(0,l.jsx)(F.Z,{title:"Request Access",visible:i,width:800,footer:null,onOk:()=>{d(!1),a.resetFields()},onCancel:()=>{d(!1),a.resetFields()},children:(0,l.jsxs)(E.Z,{form:a,onFinish:m,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsx)(E.Z.Item,{label:"Select Model",name:"selectedModel",children:(0,l.jsx)(T.default,{placeholder:"Select model",style:{width:"100%"},children:t.map(e=>(0,l.jsx)(ec,{value:e,children:e},e))})}),(0,l.jsx)(E.Z.Item,{label:"Reason for Access",name:"accessReason",children:(0,l.jsx)(O.Z.TextArea,{rows:4,placeholder:"Enter reason for access"})}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(o.Z,{children:"Request Access"})})]})})]})},em=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,[i,c]=(0,n.useState)({data:[]}),[d,m]=(0,n.useState)([]);if((0,n.useEffect)(()=>{if(!t||!s||!r||!a)return;let e=async()=>{try{let e=await x(t,a,r);if(console.log("Model data response:",e.data),c(e),"Admin"===r&&t){let e=await b(t);console.log("Pending Requests:",d),m(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};t&&s&&r&&a&&e()},[t,s,r,a]),!i||!t||!s||!r||!a)return(0,l.jsx)("div",{children:"Loading..."});let h=[];for(let e=0;e(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.model_name})}),(0,l.jsx)(J.Z,{children:e.provider}),(0,l.jsx)(J.Z,{children:e.user_access?(0,l.jsx)(ei.Z,{color:"green",children:"Yes"}):(0,l.jsx)(ed,{userModels:h,accessToken:t,userID:a})}),(0,l.jsx)(J.Z,{children:e.input_cost}),(0,l.jsx)(J.Z,{children:e.output_cost}),(0,l.jsx)(J.Z,{children:e.max_tokens})]},e.model_name))})]})}),"Admin"===r&&d&&d.length>0?(0,l.jsx)(z.Z,{children:(0,l.jsxs)(B.Z,{children:[(0,l.jsxs)(V.Z,{children:[(0,l.jsx)(X.Z,{children:"Pending Requests"}),(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User ID"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Requested Models"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Justification"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Justification"})})]})]}),(0,l.jsx)(K.Z,{children:d.map(e=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.user_id})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.models[0]})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.justification})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)("p",{children:e.user_id})}),(0,l.jsx)(o.Z,{children:"Approve"}),(0,l.jsx)(o.Z,{variant:"secondary",className:"ml-2",children:"Deny"})]},e.request_id))})]})}):null]})})};let{Option:eh}=T.default;var eu=e=>{let{userID:t,accessToken:s}=e,[r]=E.Z.useForm(),[a,i]=(0,n.useState)(!1),[d,h]=(0,n.useState)(null),[u,x]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await p(s,t,"any"),l=[];for(let t=0;t{i(!1),r.resetFields()},g=()=>{i(!1),h(null),r.resetFields()},Z=async e=>{try{c.ZP.info("Making API Call"),i(!0),console.log("formValues in create user:",e);let l=await m(s,t,e);console.log("user create Response:",l),h(l.key),c.ZP.success("API user Created"),r.resetFields(),localStorage.removeItem("userData"+t)}catch(e){console.error("Error creating the user:",e)}};return(0,l.jsxs)("div",{children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Create New User"}),(0,l.jsx)(F.Z,{title:"Create User",visible:a,width:800,footer:null,onOk:j,onCancel:g,children:(0,l.jsxs)(E.Z,{form:r,onFinish:Z,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsx)(E.Z.Item,{label:"User ID",name:"user_id",children:(0,l.jsx)(O.Z,{placeholder:"Enter User ID"})}),(0,l.jsx)(E.Z.Item,{label:"Team ID",name:"team_id",children:(0,l.jsx)(O.Z,{placeholder:"ai_team"})}),(0,l.jsx)(E.Z.Item,{label:"Models",name:"models",children:(0,l.jsx)(T.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:u.map(e=>(0,l.jsx)(eh,{value:e,children:e},e))})}),(0,l.jsx)(E.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(D.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(E.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Duration (eg: 30s, 30h, 30d)",name:"duration",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Metadata",name:"metadata",children:(0,l.jsx)(O.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(R.ZP,{htmlType:"submit",children:"Create User"})})]})}),d&&(0,l.jsxs)(F.Z,{title:"Save Your User",visible:a,onOk:j,onCancel:g,footer:null,children:[(0,l.jsxs)("p",{children:["Please save this secret user somewhere safe and accessible. For security reasons, ",(0,l.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret user, you will need to generate a new one."]}),(0,l.jsx)("p",{children:null!=d?"API user: ".concat(d):"User being created, this might take 30s"})]})]})},ex=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,[o,i]=(0,n.useState)(null),[c,d]=(0,n.useState)([]);return((0,n.useEffect)(()=>{if(!t||!s||!r||!a)return;let e=async()=>{try{let e=await u(t,null,r,!0);console.log("user data response:",e),i(e)}catch(e){console.error("There was an error fetching the model data",e)}};t&&s&&r&&a&&e()},[t,s,r,a]),o&&t&&s&&r&&a)?(0,l.jsx)("div",{style:{width:"100%"},children:(0,l.jsxs)(I.Z,{className:"gap-2 p-10 h-[75vh] w-full",children:[(0,l.jsx)(eu,{userID:a,accessToken:t}),(0,l.jsx)(z.Z,{children:(0,l.jsxs)(B.Z,{className:"mt-5",children:[(0,l.jsx)(V.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User ID "})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Role"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Models"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Spend ($ USD)"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"User Max Budget ($ USD)"})})]})}),(0,l.jsx)(K.Z,{children:o.map(e=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.user_id})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.user_role?e.user_role:"app_user"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.models&&e.models.length>0?e.models:"All Models"})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.spend?e.spend:0})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:e.max_budget?e.max_budget:"Unlimited"})})]},e.user_id))})]})})]})}):(0,l.jsx)("div",{children:"Loading..."})},ep=s(8510),ej=e=>{let{teams:t,searchParams:s,accessToken:r,setTeams:a}=e,[i]=E.Z.useForm(),[d]=E.Z.useForm(),{Title:m,Paragraph:h}=es.default,[u,x]=(0,n.useState)(""),[p,j]=(0,n.useState)(t?t[0]:null),[g,Z]=(0,n.useState)(!1),[y,f]=(0,n.useState)(!1),w=async e=>{try{if(null!=r){c.ZP.info("Making API Call");let s=await S(r,e);null!==t?a([...t,s]):a([s]),console.log("response for team create call: ".concat(s)),Z(!1)}}catch(e){console.error("Error creating the key:",e)}},_=async e=>{try{if(null!=r&&null!=t){c.ZP.info("Making API Call");let s={role:"user",user_email:e.user_email,user_id:e.user_id},l=await N(r,p.team_id,s);console.log("response for team create call: ".concat(l.data));let n=t.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(l.data.team_id)),e.team_id===l.data.team_id));if(console.log("foundIndex: ".concat(n)),-1!==n){let e=[...t];e[n]=l.data,a(e),j(l.data)}f(!1)}}catch(e){console.error("Error creating the key:",e)}};return console.log("received teams ".concat(t)),(0,l.jsx)("div",{className:"w-full",children:(0,l.jsxs)(I.Z,{numItems:1,className:"gap-2 p-2 h-[75vh] w-full",children:[(0,l.jsxs)(C.Z,{numColSpan:1,children:[(0,l.jsx)(m,{level:4,children:"All Teams"}),(0,l.jsx)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,l.jsxs)(B.Z,{children:[(0,l.jsx)(V.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(G.Z,{children:"Team Name"}),(0,l.jsx)(G.Z,{children:"Spend (USD)"}),(0,l.jsx)(G.Z,{children:"Budget (USD)"}),(0,l.jsx)(G.Z,{children:"TPM / RPM Limits"})]})}),(0,l.jsx)(K.Z,{children:t&&t.length>0?t.map(e=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:e.team_alias}),(0,l.jsx)(J.Z,{children:e.spend}),(0,l.jsx)(J.Z,{children:e.max_budget?e.max_budget:"No limit"}),(0,l.jsx)(J.Z,{children:(0,l.jsxs)(P.Z,{children:["TPM Limit:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,l.jsx)("br",{})," RPM Limit:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{icon:ep.Z,size:"sm"})})]},e.team_id)):null})]})})]}),(0,l.jsxs)(C.Z,{numColSpan:1,children:[(0,l.jsx)(o.Z,{className:"mx-auto",onClick:()=>Z(!0),children:"+ Create New Team"}),(0,l.jsx)(F.Z,{title:"Create Team",visible:g,width:800,footer:null,onOk:()=>{Z(!1),i.resetFields()},onCancel:()=>{Z(!1),i.resetFields()},children:(0,l.jsxs)(E.Z,{form:i,onFinish:w,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Team Name",name:"team_alias",children:(0,l.jsx)(O.Z,{})}),(0,l.jsx)(E.Z.Item,{label:"Models",name:"models",children:(0,l.jsx)(T.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"}})}),(0,l.jsx)(E.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,l.jsx)(D.Z,{step:.01,precision:2,width:200})}),(0,l.jsx)(E.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})}),(0,l.jsx)(E.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,l.jsx)(D.Z,{step:1,width:400})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(R.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,l.jsxs)(C.Z,{numColSpan:1,children:[(0,l.jsx)(m,{level:4,children:"Team Members"}),(0,l.jsx)(h,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),t&&t.length>0?(0,l.jsx)(el.Z,{defaultValue:"0",children:t.map((e,t)=>(0,l.jsx)(en.Z,{value:String(t),onClick:()=>{j(e)},children:e.team_alias},t))}):(0,l.jsxs)(h,{children:["No team created. ",(0,l.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,l.jsx)(C.Z,{numColSpan:1,children:(0,l.jsx)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,l.jsxs)(B.Z,{children:[(0,l.jsx)(V.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(G.Z,{children:"Member Name"}),(0,l.jsx)(G.Z,{children:"Role"}),(0,l.jsx)(G.Z,{children:"Action"})]})}),(0,l.jsx)(K.Z,{children:p?p.members_with_roles.map((e,t)=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,l.jsx)(J.Z,{children:e.role}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{icon:ep.Z,size:"sm"})})]},t)):null})]})})}),(0,l.jsxs)(C.Z,{numColSpan:1,children:[(0,l.jsx)(o.Z,{className:"mx-auto mb-5",onClick:()=>f(!0),children:"+ Add member"}),(0,l.jsx)(F.Z,{title:"Add member",visible:y,width:800,footer:null,onOk:()=>{f(!1),d.resetFields()},onCancel:()=>{f(!1),d.resetFields()},children:(0,l.jsxs)(E.Z,{form:i,onFinish:_,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,l.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,l.jsx)(E.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(R.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},eg=e=>{let{searchParams:t,accessToken:s}=e,[r]=E.Z.useForm(),[a]=E.Z.useForm(),{Title:i,Paragraph:d}=es.default,[m,h]=(0,n.useState)(""),[u,x]=(0,n.useState)(null),[p,j]=(0,n.useState)(!1);(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],t=await v(s,"proxy_admin_viewer");t.forEach(t=>{e.push({user_role:t.user_role,user_id:t.user_id,user_email:t.user_email})}),console.log("proxy viewers: ".concat(t));let l=await v(s,"proxy_admin");l.forEach(t=>{e.push({user_role:t.user_role,user_id:t.user_id,user_email:t.user_email})}),console.log("proxy admins: ".concat(l)),console.log("combinedList: ".concat(e)),x(e)}})()},[s]);let g=async e=>{try{if(null!=s&&null!=u){c.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await A(s,e);console.log("response for team create call: ".concat(t));let l=u.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(l)),-1==l&&(console.log("updates admin with new user"),u.push(t),x(u)),j(!1)}}catch(e){console.error("Error creating the key:",e)}};return console.log("admins: ".concat(null==u?void 0:u.length)),(0,l.jsxs)("div",{className:"w-full m-2",children:[(0,l.jsx)(i,{level:4,children:"Proxy Admins"}),(0,l.jsx)(d,{children:"Add other people to just view global spend. They cannot create teams or grant users access to new models."}),(0,l.jsxs)(I.Z,{numItems:1,className:"gap-2 p-0 w-full",children:[(0,l.jsx)(C.Z,{numColSpan:1,children:(0,l.jsx)(z.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,l.jsxs)(B.Z,{children:[(0,l.jsx)(V.Z,{children:(0,l.jsxs)($.Z,{children:[(0,l.jsx)(G.Z,{children:"Member Name"}),(0,l.jsx)(G.Z,{children:"Role"}),(0,l.jsx)(G.Z,{children:"Action"})]})}),(0,l.jsx)(K.Z,{children:u?u.map((e,t)=>(0,l.jsxs)($.Z,{children:[(0,l.jsx)(J.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,l.jsx)(J.Z,{children:e.user_role}),(0,l.jsx)(J.Z,{children:(0,l.jsx)(q.Z,{icon:ep.Z,size:"sm"})})]},t)):null})]})})}),(0,l.jsxs)(C.Z,{numColSpan:1,children:[(0,l.jsx)(o.Z,{className:"mx-auto mb-5",onClick:()=>j(!0),children:"+ Add viewer"}),(0,l.jsx)(F.Z,{title:"Add viewer",visible:p,width:800,footer:null,onOk:()=>{j(!1),a.resetFields()},onCancel:()=>{j(!1),a.resetFields()},children:(0,l.jsxs)(E.Z,{form:r,onFinish:g,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(E.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,l.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,l.jsx)(E.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,l.jsx)(O.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,l.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,l.jsx)(R.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})]})},eZ=s(92836),ey=s(26734),ef=s(41608),ew=s(32126),e_=s(23682),ek=s(12968),eb=s(67951);async function ev(e,t,s,l){console.log("isLocal:",!1);let n=window.location.origin,r=new ek.ZP.OpenAI({apiKey:l,baseURL:n,dangerouslyAllowBrowser:!0});for await(let l of(await r.chat.completions.create({model:s,stream:!0,messages:[{role:"user",content:e}]})))console.log(l),l.choices[0].delta.content&&t(l.choices[0].delta.content)}var eS=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,[o,i]=(0,n.useState)(""),[c,d]=(0,n.useState)([]),[m,h]=(0,n.useState)(void 0),[u,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&s&&r&&a&&(async()=>{let e=await p(t,a,r);console.log("model_info:",e),(null==e?void 0:e.data.length)>0&&(x(e.data),h(e.data[0].id))})()},[t,a,r]);let j=(e,t)=>{d(s=>{let l=s[s.length-1];return l&&l.role===e?[...s.slice(0,s.length-1),{role:e,content:l.content+t}]:[...s,{role:e,content:t}]})},g=async()=>{if(""!==o.trim()&&t&&s&&r&&a){d(e=>[...e,{role:"user",content:o}]);try{m&&await ev(o,e=>j("assistant",e),m,t)}catch(e){console.error("Error fetching model response",e),j("assistant","Error fetching model response")}i("")}};return(0,l.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,l.jsx)(I.Z,{className:"gap-2 p-10 h-[75vh] w-full",children:(0,l.jsx)(z.Z,{children:(0,l.jsxs)(ey.Z,{children:[(0,l.jsxs)(ef.Z,{className:"mt-4",children:[(0,l.jsx)(eZ.Z,{children:"Chat"}),(0,l.jsx)(eZ.Z,{children:"API Reference"})]}),(0,l.jsxs)(e_.Z,{children:[(0,l.jsxs)(ew.Z,{children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{children:"Select Model:"}),(0,l.jsx)("select",{value:m||"",onChange:e=>h(e.target.value),children:null==u?void 0:u.map(e=>(0,l.jsx)("option",{value:e.id,children:e.id},e.id))})]}),(0,l.jsxs)(B.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,l.jsx)(V.Z,{children:(0,l.jsx)($.Z,{children:(0,l.jsx)(J.Z,{children:(0,l.jsx)(X.Z,{children:"Chat"})})})}),(0,l.jsx)(K.Z,{children:c.map((e,t)=>(0,l.jsx)($.Z,{children:(0,l.jsx)(J.Z,{children:"".concat(e.role,": ").concat(e.content)})},t))})]}),(0,l.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,l.jsxs)("div",{className:"flex",children:[(0,l.jsx)("input",{type:"text",value:o,onChange:e=>i(e.target.value),className:"flex-1 p-2 border rounded-md mr-2",placeholder:"Type your message..."}),(0,l.jsx)("button",{onClick:g,className:"p-2 bg-blue-500 text-white rounded-md",children:"Send"})]})})]}),(0,l.jsx)(ew.Z,{children:(0,l.jsxs)(ey.Z,{children:[(0,l.jsxs)(ef.Z,{children:[(0,l.jsx)(eZ.Z,{children:"OpenAI Python SDK"}),(0,l.jsx)(eZ.Z,{children:"LlamaIndex"}),(0,l.jsx)(eZ.Z,{children:"Langchain Py"})]}),(0,l.jsxs)(e_.Z,{children:[(0,l.jsx)(ew.Z,{children:(0,l.jsx)(eb.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # proxy base url\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to use from Models Tab\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ],\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-openai-client",\n "generation_id": "openai-client-gen-id22",\n "trace_id": "openai-client-trace-id22",\n "trace_user_id": "openai-client-user-id2"\n }\n }\n)\n\nprint(response)\n '})}),(0,l.jsx)(ew.Z,{children:(0,l.jsx)(eb.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="http://0.0.0.0:4000", # 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="http://0.0.0.0:4000",\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,l.jsx)(ew.Z,{children:(0,l.jsx)(eb.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="http://0.0.0.0:8000",\n model = "gpt-3.5-turbo",\n temperature=0.1,\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-langchain-client",\n "generation_id": "langchain-client-gen-id22",\n "trace_id": "langchain-client-trace-id22",\n "trace_user_id": "langchain-client-user-id2"\n }\n }\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 '})})]})]})})]})]})})})})},eN=s(33509),eA=s(30569);let{Sider:eC}=eN.default;var eI=e=>{let{setPage:t,userRole:s,defaultSelectedKey:n}=e;return"Admin Viewer"==s?(0,l.jsx)(eN.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,l.jsx)(eC,{width:120,children:(0,l.jsx)(eA.Z,{mode:"inline",defaultSelectedKeys:n||["1"],style:{height:"100%",borderRight:0},children:(0,l.jsx)(eA.Z.Item,{onClick:()=>t("usage"),children:"Usage"},"1")})})}):(0,l.jsx)(eN.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,l.jsx)(eC,{width:120,children:(0,l.jsxs)(eA.Z,{mode:"inline",defaultSelectedKeys:n||["1"],style:{height:"100%",borderRight:0},children:[(0,l.jsx)(eA.Z.Item,{onClick:()=>t("api-keys"),children:"API Keys"},"1"),(0,l.jsx)(eA.Z.Item,{onClick:()=>t("models"),children:"Models"},"2"),(0,l.jsx)(eA.Z.Item,{onClick:()=>t("llm-playground"),children:"Chat UI"},"3"),(0,l.jsx)(eA.Z.Item,{onClick:()=>t("usage"),children:"Usage"},"4"),"Admin"==s?(0,l.jsx)(eA.Z.Item,{onClick:()=>t("users"),children:"Users"},"5"):null,"Admin"==s?(0,l.jsx)(eA.Z.Item,{onClick:()=>t("teams"),children:"Teams"},"6"):null,"Admin"==s?(0,l.jsx)(eA.Z.Item,{onClick:()=>t("admin-panel"),children:"Admin"},"7"):null]})})})},eP=e=>{let{accessToken:t,token:s,userRole:r,userID:a}=e,o=new Date,[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)([]),[h,u]=(0,n.useState)([]),x=new Date(o.getFullYear(),o.getMonth(),1),p=new Date(o.getFullYear(),o.getMonth()+1,0),j=k(x),_=k(p);function k(e){let t=e.getFullYear(),s=e.getMonth()+1,l=e.getDate();return"".concat(t,"-").concat(s<10?"0"+s:s,"-").concat(l<10?"0"+l:l)}return console.log("Start date is ".concat(j)),console.log("End date is ".concat(_)),(0,n.useEffect)(()=>{t&&s&&r&&a&&(async()=>{try{if(console.log("user role: ".concat(r)),"Admin"==r||"Admin Viewer"==r){let e=await Z(t);c(e);let s=(await y(t)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,7),spend:e.total_spend}));m(s),await f(t)}else"App Owner"==r&&await g(t,s,r,a,j,_).then(async e=>{if(console.log("result from spend logs call",e),"daily_spend"in e){let t=e.daily_spend;console.log("daily spend",t),c(t);let s=e.top_api_keys;m(s)}else{let s=(await w(t,function(e){let t=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[s,l]=e;"spend"!==s&&"startTime"!==s&&"models"!==s&&"users"!==s&&t.push({key:s,spend:l})})}),t.sort((e,t)=>Number(t.spend)-Number(e.spend));let s=t.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(s[0]))),s}(e))).info.map(e=>({key:(e.key_name||e.key_alias||e.token).substring(0,7),spend:e.spend}));m(s),u(function(e){let t={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[s,l]=e;""!==s&&null!=s&&"None"!=s&&(t[s]||(t[s]=0),t[s]+=l)})});let s=Object.entries(t).map(e=>{let[t,s]=e;return{user_id:t,spend:s}});s.sort((e,t)=>t.spend-e.spend);let l=s.slice(0,5);return console.log("topKeys: ".concat(Object.values(l[0]))),l}(e)),c(e)}})}catch(e){console.error("There was an error fetching the data",e)}})()},[t,s,r,a,j,_]),(0,l.jsx)("div",{style:{width:"100%"},children:(0,l.jsxs)(I.Z,{numItems:2,className:"gap-2 p-10 h-[75vh] w-full",children:[(0,l.jsx)(C.Z,{numColSpan:2,children:(0,l.jsxs)(z.Z,{children:[(0,l.jsx)(X.Z,{children:"Monthly Spend"}),(0,l.jsx)(W.Z,{data:i,index:"startTime",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,l.jsx)(C.Z,{numColSpan:1,children:(0,l.jsxs)(z.Z,{children:[(0,l.jsx)(X.Z,{children:"Top API Keys"}),(0,l.jsx)(W.Z,{className:"mt-4 h-40",data:d,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:80,tickGap:5,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,l.jsx)(C.Z,{numColSpan:1,children:(0,l.jsxs)(z.Z,{children:[(0,l.jsx)(X.Z,{children:"Top Users"}),(0,l.jsx)(W.Z,{className:"mt-4 h-40",data:h,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})})},eT=()=>{let[e,t]=(0,n.useState)(""),[s,a]=(0,n.useState)(null),[o,c]=(0,n.useState)(null),[d,m]=(0,n.useState)(!0),h=(0,r.useSearchParams)(),u=h.get("userID"),x=h.get("token"),[p,j]=(0,n.useState)("api-keys"),[g,Z]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(x){let e=(0,ea.o)(x);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),Z(e.key),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"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",s),t(s),"Admin Viewer"==s&&j("usage")}else console.log("User role not defined");e.user_email?a(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?m("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[x]),(0,l.jsx)(n.Suspense,{fallback:(0,l.jsx)("div",{children:"Loading..."}),children:(0,l.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,l.jsx)(i,{userID:u,userRole:e,userEmail:s,showSSOBanner:d}),(0,l.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,l.jsx)(eI,{setPage:j,userRole:e,defaultSelectedKey:null}),"api-keys"==p?(0,l.jsx)(eo,{userID:u,userRole:e,teams:o,setUserRole:t,userEmail:s,setUserEmail:a,setTeams:c}):"models"==p?(0,l.jsx)(em,{userID:u,userRole:e,token:x,accessToken:g}):"llm-playground"==p?(0,l.jsx)(eS,{userID:u,userRole:e,token:x,accessToken:g}):"users"==p?(0,l.jsx)(ex,{userID:u,userRole:e,token:x,accessToken:g}):"teams"==p?(0,l.jsx)(ej,{teams:o,setTeams:c,searchParams:h,accessToken:g}):"admin-panel"==p?(0,l.jsx)(eg,{setTeams:c,searchParams:h,accessToken:g}):(0,l.jsx)(eP,{userID:u,userRole:e,token:x,accessToken:g})]})]})})}}},function(e){e.O(0,[303,971,69,744],function(){return e(e.s=79615)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/index.html b/litellm/proxy/_experimental/out/index.html index 0cd8f91ff..60430c217 100644 --- a/litellm/proxy/_experimental/out/index.html +++ b/litellm/proxy/_experimental/out/index.html @@ -1 +1 @@ -🚅 LiteLLM \ No newline at end of file +🚅 LiteLLM \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/index.txt b/litellm/proxy/_experimental/out/index.txt index 2a66e727b..85cdda85d 100644 --- a/litellm/proxy/_experimental/out/index.txt +++ b/litellm/proxy/_experimental/out/index.txt @@ -1,7 +1,7 @@ 2:I[77831,[],""] -3:I[30280,["303","static/chunks/303-d80f23087a9e6aec.js","931","static/chunks/app/page-8f65fc157f538dff.js"],""] +3:I[30280,["303","static/chunks/303-d80f23087a9e6aec.js","931","static/chunks/app/page-f5480eede36fdcd5.js"],""] 4:I[5613,[],""] 5:I[31778,[],""] -0:["kyOCJPBB9pyUfbMKCAXr-",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$L2",null,{"propsForComponent":{"params":{}},"Component":"$3","isStaticGeneration":true}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/a40ad0909dd7838e.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] +0:["HOfpn9FdKIMCOfG_am2z2",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$L2",null,{"propsForComponent":{"params":{}},"Component":"$3","isStaticGeneration":true}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/a40ad0909dd7838e.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"🚅 LiteLLM"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 7578f3809..b8aec2e82 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -783,6 +783,8 @@ async def user_api_key_auth( "/v2/key/info", "/models", "/v1/models", + "/global/spend/logs", + "/global/spend/keys", ] # check if the current route startswith any of the allowed routes if ( @@ -4455,31 +4457,42 @@ async def user_update(data: UpdateUserRequest): non_default_values[k] = v ## ADD USER, IF NEW ## - if data.user_id is not None and len(data.user_id) == 0: + verbose_proxy_logger.debug(f"/user/update: Received data = {data}") + if data.user_id is not None and len(data.user_id) > 0: non_default_values["user_id"] = data.user_id # type: ignore - await prisma_client.update_data( + verbose_proxy_logger.debug(f"In update user, user_id condition block.") + response = await prisma_client.update_data( user_id=data.user_id, data=non_default_values, table_name="user", ) + verbose_proxy_logger.debug( + f"received response from updating prisma client. response={response}" + ) elif data.user_email is not None: non_default_values["user_id"] = str(uuid.uuid4()) non_default_values["user_email"] = data.user_email ## user email is not unique acc. to prisma schema -> future improvement ### for now: check if it exists in db, if not - insert it - existing_user_row = await prisma_client.get_data( + existing_user_rows = await prisma_client.get_data( key_val={"user_email": data.user_email}, table_name="user", query_type="find_all", ) - if existing_user_row is None or ( - isinstance(existing_user_row, list) and len(existing_user_row) == 0 + if existing_user_rows is None or ( + isinstance(existing_user_rows, list) and len(existing_user_rows) == 0 ): - await prisma_client.insert_data( + response = await prisma_client.insert_data( data=non_default_values, table_name="user" ) - - return non_default_values + elif isinstance(existing_user_rows, list) and len(existing_user_rows) > 0: + for existing_user in existing_user_rows: + response = await prisma_client.update_data( + user_id=existing_user.user_id, + data=non_default_values, + table_name="user", + ) + return response # update based on remaining passed in values except Exception as e: traceback.print_exc() diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index ec563bbf3..03d69e285 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -542,6 +542,34 @@ class PrismaClient: print("MonthlyGlobalSpend Created!") # noqa + try: + await self.db.query_raw("""SELECT 1 FROM "Last30dKeysBySpend" LIMIT 1""") + print("Last30dKeysBySpend Exists!") # noqa + except Exception as e: + sql_query = """ + CREATE OR REPLACE VIEW "Last30dKeysBySpend" AS + SELECT + L."api_key", + V."key_alias", + V."key_name", + SUM(L."spend") AS total_spend + FROM + "LiteLLM_SpendLogs" L + LEFT JOIN + "LiteLLM_VerificationToken" V + ON + L."api_key" = V."token" + WHERE + L."startTime" >= (CURRENT_DATE - INTERVAL '30 days') + GROUP BY + L."api_key", V."key_alias", V."key_name" + ORDER BY + total_spend DESC; + """ + await self.db.execute_raw(query=sql_query) + + print("Last30dKeysBySpend Created!") # noqa + return @backoff.on_exception( @@ -1034,7 +1062,7 @@ class PrismaClient: + f"DB User Table - update succeeded {update_user_row}" + "\033[0m" ) - return {"user_id": user_id, "data": db_data} + return {"user_id": user_id, "data": update_user_row} elif ( team_id is not None or (table_name is not None and table_name == "team") diff --git a/ui/litellm-dashboard/out/404.html b/ui/litellm-dashboard/out/404.html index c6632b021..b86464e15 100644 --- a/ui/litellm-dashboard/out/404.html +++ b/ui/litellm-dashboard/out/404.html @@ -1 +1 @@ -404: This page could not be found.🚅 LiteLLM

404

This page could not be found.

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

404

This page could not be found.

\ No newline at end of file diff --git a/ui/litellm-dashboard/out/index.html b/ui/litellm-dashboard/out/index.html index 0cd8f91ff..60430c217 100644 --- a/ui/litellm-dashboard/out/index.html +++ b/ui/litellm-dashboard/out/index.html @@ -1 +1 @@ -🚅 LiteLLM \ No newline at end of file +🚅 LiteLLM \ No newline at end of file diff --git a/ui/litellm-dashboard/out/index.txt b/ui/litellm-dashboard/out/index.txt index 2a66e727b..85cdda85d 100644 --- a/ui/litellm-dashboard/out/index.txt +++ b/ui/litellm-dashboard/out/index.txt @@ -1,7 +1,7 @@ 2:I[77831,[],""] -3:I[30280,["303","static/chunks/303-d80f23087a9e6aec.js","931","static/chunks/app/page-8f65fc157f538dff.js"],""] +3:I[30280,["303","static/chunks/303-d80f23087a9e6aec.js","931","static/chunks/app/page-f5480eede36fdcd5.js"],""] 4:I[5613,[],""] 5:I[31778,[],""] -0:["kyOCJPBB9pyUfbMKCAXr-",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$L2",null,{"propsForComponent":{"params":{}},"Component":"$3","isStaticGeneration":true}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/a40ad0909dd7838e.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] +0:["HOfpn9FdKIMCOfG_am2z2",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$L2",null,{"propsForComponent":{"params":{}},"Component":"$3","isStaticGeneration":true}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/a40ad0909dd7838e.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] 6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"🚅 LiteLLM"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx index 50b50af4b..815da264e 100644 --- a/ui/litellm-dashboard/src/app/page.tsx +++ b/ui/litellm-dashboard/src/app/page.tsx @@ -41,6 +41,9 @@ const CreateKeyPage = () => { const formattedUserRole = formatUserRole(decoded.user_role); console.log("Decoded user_role:", formattedUserRole); setUserRole(formattedUserRole); + if (formattedUserRole == "Admin Viewer") { + setPage("usage"); + } } else { console.log("User role not defined"); } @@ -66,7 +69,8 @@ const CreateKeyPage = () => { if (!userRole) { return "Undefined Role"; } - console.log(`Received user role: ${userRole}`); + console.log(`Received user role: ${userRole.toLowerCase()}`); + console.log(`Received user role length: ${userRole.toLowerCase().length}`); switch (userRole.toLowerCase()) { case "app_owner": return "App Owner"; diff --git a/ui/litellm-dashboard/src/components/leftnav.tsx b/ui/litellm-dashboard/src/components/leftnav.tsx index de273490d..077b1a9e2 100644 --- a/ui/litellm-dashboard/src/components/leftnav.tsx +++ b/ui/litellm-dashboard/src/components/leftnav.tsx @@ -16,6 +16,25 @@ const Sidebar: React.FC = ({ userRole, defaultSelectedKey, }) => { + if (userRole == "Admin Viewer") { + return ( + + + + setPage("usage")}> + Usage + + + + + ); + } return ( diff --git a/ui/litellm-dashboard/src/components/usage.tsx b/ui/litellm-dashboard/src/components/usage.tsx index afc002fd5..fd26fa2d7 100644 --- a/ui/litellm-dashboard/src/components/usage.tsx +++ b/ui/litellm-dashboard/src/components/usage.tsx @@ -175,7 +175,7 @@ const UsagePage: React.FC = ({ * If user is App Owner - use the normal spend logs call */ console.log(`user role: ${userRole}`); - if (userRole == "Admin") { + if (userRole == "Admin" || userRole == "Admin Viewer") { const overall_spend = await adminSpendLogsCall(accessToken); setKeySpendData(overall_spend); const top_keys = await adminTopKeysCall(accessToken); diff --git a/ui/litellm-dashboard/src/components/user_dashboard.tsx b/ui/litellm-dashboard/src/components/user_dashboard.tsx index 3e1c9c4d4..d4969751c 100644 --- a/ui/litellm-dashboard/src/components/user_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/user_dashboard.tsx @@ -73,6 +73,10 @@ const UserDashboard: React.FC = ({ return "App Owner"; case "app_admin": return "Admin"; + case "proxy_admin": + return "Admin"; + case "proxy_admin_viewer": + return "Admin Viewer"; case "app_user": return "App User"; default: