litellm/ui/litellm-dashboard/out/_next/static/chunks/app/page-514ba06ce2e4268a.js
2024-04-03 19:42:26 -07:00

1 line
No EOL
69 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{20661:function(e,t,l){Promise.resolve().then(l.bind(l,93838))},93838:function(e,t,l){"use strict";l.r(t),l.d(t,{default:function(){return eq}});var s=l(3827),a=l(64090),r=l(47907),n=l(8792),o=l(40491),i=l(65270),c=e=>{let{userID:t,userRole:l,userEmail:a,showSSOBanner:r}=e;console.log("User ID:",t),console.log("userEmail:",a);let c=[{key:"1",label:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{children:["Role: ",l]}),(0,s.jsxs)("p",{children:["ID: ",t]})]})}];return(0,s.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,s.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,s.jsx)("div",{className:"flex flex-col items-center",children:(0,s.jsx)(n.default,{href:"/",children:(0,s.jsx)("button",{className:"text-gray-800 text-2xl py-1 rounded text-center",children:(0,s.jsx)("img",{src:"/get_image",width:200,height:200,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,s.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,s.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#setup-ssoauth-for-ui",target:"_blank",className:"mr-2"}):null,(0,s.jsx)("div",{style:{border:"1px solid #391085",padding:"6px",borderRadius:"8px"},children:(0,s.jsx)(o.Z,{menu:{items:c},children:(0,s.jsx)(i.Z,{children:a})})})]})]})},d=l(80588);let m=async(e,t,l)=>{try{if(console.log("Form Values in keyCreateCall:",l),l.description&&(l.metadata||(l.metadata={}),l.metadata.description=l.description,delete l.description,l.metadata=JSON.stringify(l.metadata)),l.metadata){console.log("formValues.metadata:",l.metadata);try{l.metadata=JSON.parse(l.metadata)}catch(e){throw d.ZP.error("Failed to parse metadata: "+e),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",l);let s=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...l})});if(!s.ok){let e=await s.text();throw d.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let a=await s.json();return console.log("API Response:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},h=async(e,t,l)=>{try{if(console.log("Form Values in keyCreateCall:",l),l.description&&(l.metadata||(l.metadata={}),l.metadata.description=l.description,delete l.description,l.metadata=JSON.stringify(l.metadata)),l.metadata){console.log("formValues.metadata:",l.metadata);try{l.metadata=JSON.parse(l.metadata)}catch(e){throw d.ZP.error("Failed to parse metadata: "+e),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",l);let s=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:t,...l})});if(!s.ok){let e=await s.text();throw d.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let a=await s.json();return console.log("API Response:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},u=async(e,t)=>{try{console.log("in keyDeleteCall:",t);let l=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[t]})});if(!l.ok){let e=await l.text();throw d.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let s=await l.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},x=async(e,t)=>{try{console.log("in teamDeleteCall:",t);let l=await fetch("/team/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[t]})});if(!l.ok){let e=await l.text();throw d.ZP.error("Failed to delete team: "+e),Error("Network response was not ok")}let s=await l.json();return console.log(s),s}catch(e){throw console.error("Failed to delete key:",e),e}},p=async function(e,t,l){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];try{let a="/user/info";"App Owner"==l&&t&&(a="".concat(a,"?user_id=").concat(t)),console.log("in userInfoCall viewAll=",s),s&&(a="".concat(a,"?view_all=true"));let r=await fetch(a,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!r.ok){let e=await r.text();throw d.ZP.error(e),Error("Network response was not ok")}let n=await r.json();return console.log("API Response:",n),n}catch(e){throw console.error("Failed to create key:",e),e}},j=async e=>{try{let t=await fetch("/global/spend",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw d.ZP.error(e),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},g=async(e,t,l)=>{try{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 d.ZP.error(e),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},y=async(e,t,l)=>{try{let t=await fetch("/model/metrics",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw d.ZP.error(e),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},f=async(e,t,l)=>{try{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 d.ZP.error(e),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,t)=>{try{let l="/global/spend/logs";console.log("in keySpendLogsCall:",l);let s=await fetch("".concat(l,"?api_key=").concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw d.ZP.error(e),Error("Network response was not ok")}let a=await s.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},Z=async e=>{try{let t="/global/spend/teams";console.log("in teamSpendLogsCall:",t);let l=await fetch("".concat(t),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw d.ZP.error(e),Error("Network response was not ok")}let s=await l.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},k=async(e,t,l,s,a,r)=>{try{console.log("user role in spend logs call: ".concat(l));let t="/spend/logs";t="App Owner"==l?"".concat(t,"?user_id=").concat(s,"&start_date=").concat(a,"&end_date=").concat(r):"".concat(t,"?start_date=").concat(a,"&end_date=").concat(r);let n=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.text();throw d.ZP.error(e),Error("Network response was not ok")}let o=await n.json();return console.log(o),o}catch(e){throw console.error("Failed to create key:",e),e}},b=async e=>{try{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 d.ZP.error(e),Error("Network response was not ok")}let l=await t.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},_=async e=>{try{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 d.ZP.error(e),Error("Network response was not ok")}let l=await t.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},v=async(e,t)=>{try{t&&JSON.stringify({api_key:t});let l={method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}};t&&(l.body=JSON.stringify({api_key:t}));let s=await fetch("/global/spend/end_users",l);if(!s.ok){let e=await s.text();throw d.ZP.error(e),Error("Network response was not ok")}let a=await s.json();return console.log(a),a}catch(e){throw console.error("Failed to create key:",e),e}},N=async e=>{try{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 d.ZP.error(e),Error("Network response was not ok")}let l=await t.json();return console.log(l),l}catch(e){throw console.error("Failed to create key:",e),e}},S=async(e,t)=>{try{let l=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:t})});if(!l.ok){let e=await l.text();throw d.ZP.error(e),Error("Network response was not ok")}let s=await l.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},A=async(e,t,l,s)=>{try{let a=await fetch("/user/request_model",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({models:[t],user_id:l,justification:s})});if(!a.ok){let e=await a.text();throw d.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let r=await a.json();return console.log(r),r}catch(e){throw console.error("Failed to create key:",e),e}},C=async e=>{try{let t="/user/get_requests";console.log("in userGetRequesedtModelsCall:",t);let l=await fetch(t,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw d.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let s=await l.json();return console.log(s),s}catch(e){throw console.error("Failed to get requested models:",e),e}},T=async(e,t)=>{try{let l="/user/get_users?role=".concat(t);console.log("in userGetAllUsersCall:",l);let s=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw d.ZP.error("Failed to delete key: "+e),Error("Network response was not ok")}let a=await s.json();return console.log(a),a}catch(e){throw console.error("Failed to get requested models:",e),e}},P=async(e,t)=>{try{console.log("Form Values in teamCreateCall:",t);let l=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!l.ok){let e=await l.text();throw d.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await l.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},I=async(e,t)=>{try{console.log("Form Values in keyUpdateCall:",t);let l=await fetch("/key/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!l.ok){let e=await l.text();throw d.ZP.error("Failed to update key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await l.json();return console.log("Update key Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},E=async(e,t)=>{try{console.log("Form Values in teamUpateCall:",t);let l=await fetch("/team/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...t})});if(!l.ok){let e=await l.text();throw d.ZP.error("Failed to update team: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await l.json();return console.log("Update Team Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},F=async(e,t,l)=>{try{console.log("Form Values in teamMemberAddCall:",l);let s=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:t,member:l})});if(!s.ok){let e=await s.text();throw d.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let a=await s.json();return console.log("API Response:",a),a}catch(e){throw console.error("Failed to create key:",e),e}},M=async(e,t)=>{try{console.log("Form Values in userUpdateUserCall:",t);let l=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(!l.ok){let e=await l.text();throw d.ZP.error("Failed to create key: "+e),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await l.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},O=async(e,t)=>{try{let l=await fetch("/global/predict/spend/logs",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:t})});if(!l.ok){let e=await l.text();throw d.ZP.error(e),Error("Network response was not ok")}let s=await l.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}};var R=l(10384),D=l(46453),U=l(2179),z=l(71801),B=l(42440),L=l(42308),K=l(50670),V=l(12143),q=l(77171),J=l(42539),G=l(88707),W=l(1861);let{Option:$}=K.default;var Y=e=>{let{userID:t,team:l,userRole:r,accessToken:n,data:o,setData:i}=e,[c]=V.Z.useForm(),[h,u]=(0,a.useState)(!1),[x,p]=(0,a.useState)(null),[j,g]=(0,a.useState)(null),[y,w]=(0,a.useState)([]),Z=()=>{u(!1),c.resetFields()},k=()=>{u(!1),p(null),c.resetFields()};(0,a.useEffect)(()=>{(async()=>{try{if(null===t||null===r)return;if(null!==n){let e=(await f(n,t,r)).data.map(e=>e.id);console.log("available_model_names:",e),w(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[n,t,r]);let b=async e=>{try{d.ZP.info("Making API Call"),u(!0);let l=await m(n,t,e);console.log("key create Response:",l),i(e=>e?[...e,l]:[l]),p(l.key),g(l.soft_budget),d.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+t)}catch(e){console.error("Error creating the key:",e)}};return(0,s.jsxs)("div",{children:[(0,s.jsx)(U.Z,{className:"mx-auto",onClick:()=>u(!0),children:"+ Create New Key"}),(0,s.jsx)(q.Z,{title:"Create Key",visible:h,width:800,footer:null,onOk:Z,onCancel:k,children:(0,s.jsxs)(V.Z,{form:c,onFinish:b,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===r||"Admin"===r?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Team ID",name:"team_id",hidden:!0,initialValue:l?l.team_id:null,valuePropName:"team_id",className:"mt-8",children:(0,s.jsx)(J.Z,{value:l?l.team_alias:"",disabled:!0})}),(0,s.jsx)(V.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,s.jsxs)(K.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,s.jsx)($,{value:"all-team-models",children:"All Team Models"},"all-team-models"),l&&l.models?l.models.includes("all-proxy-models")?y.map(e=>(0,s.jsx)($,{value:e,children:e},e)):l.models.map(e=>(0,s.jsx)($,{value:e,children:e},e)):y.map(e=>(0,s.jsx)($,{value:e,children:e},e))]})}),(0,s.jsx)(V.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==l?void 0:l.max_budget)!==null&&(null==l?void 0:l.max_budget)!==void 0?null==l?void 0:l.max_budget:"unlimited"),rules:[{validator:async(e,t)=>{if(t&&l&&null!==l.max_budget&&t>l.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(l.max_budget))}}],children:(0,s.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,s.jsx)(V.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Team Reset Budget: ".concat((null==l?void 0:l.budget_duration)!==null&&(null==l?void 0:l.budget_duration)!==void 0?null==l?void 0:l.budget_duration:"None"),children:(0,s.jsxs)(K.default,{defaultValue:null,placeholder:"n/a",children:[(0,s.jsx)(K.default.Option,{value:"24h",children:"daily"}),(0,s.jsx)(K.default.Option,{value:"30d",children:"monthly"})]})}),(0,s.jsx)(V.Z.Item,{className:"mt-8",label:"Tokens per minute Limit (TPM)",name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==l?void 0:l.tpm_limit)!==null&&(null==l?void 0:l.tpm_limit)!==void 0?null==l?void 0:l.tpm_limit:"unlimited"),rules:[{validator:async(e,t)=>{if(t&&l&&null!==l.tpm_limit&&t>l.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(l.tpm_limit))}}],children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{className:"mt-8",label:"Requests per minute Limit (RPM)",name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==l?void 0:l.rpm_limit)!==null&&(null==l?void 0:l.rpm_limit)!==void 0?null==l?void 0:l.rpm_limit:"unlimited"),rules:[{validator:async(e,t)=>{if(t&&l&&null!==l.rpm_limit&&t>l.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(l.rpm_limit))}}],children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Metadata",name:"metadata",children:(0,s.jsx)(J.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Key Name",name:"key_alias",children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Team ID (Contact Group)",name:"team_id",children:(0,s.jsx)(J.Z,{placeholder:"default team (create a new team)"})}),(0,s.jsx)(V.Z.Item,{label:"Description",name:"description",children:(0,s.jsx)(J.Z.TextArea,{placeholder:"Enter description",rows:4})})]}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Create Key"})})]})}),x&&(0,s.jsx)(q.Z,{visible:h,onOk:Z,onCancel:k,footer:null,children:(0,s.jsxs)(D.Z,{numItems:1,className:"gap-2 w-full",children:[(0,s.jsx)(B.Z,{children:"Save your Key"}),(0,s.jsx)(R.Z,{numColSpan:1,children:(0,s.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,s.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,s.jsx)(R.Z,{numColSpan:1,children:null!=x?(0,s.jsxs)("div",{children:[(0,s.jsx)(z.Z,{className:"mt-3",children:"API Key:"}),(0,s.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,s.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:x})}),(0,s.jsx)(L.CopyToClipboard,{text:x,onCopy:()=>{d.ZP.success("API Key copied to clipboard")},children:(0,s.jsx)(U.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,s.jsx)(z.Z,{children:"Key being created, this might take 30s"})})]})})]})},H=l(9454),X=l(98941),Q=l(33393),ee=l(5),et=l(9853),el=l(13810),es=l(39290),ea=l(66952),er=l(61244),en=l(10827),eo=l(3851),ei=l(2044),ec=l(64167),ed=l(74480),em=l(7178);let{Option:eh}=K.default;var eu=e=>{let{userID:t,accessToken:l,selectedTeam:r,userModels:n,data:o,setData:i}=e,[c,m]=(0,a.useState)(!1),[h,x]=(0,a.useState)(!1),[p,j]=(0,a.useState)(null),[g,y]=a.useState(null),[f,Z]=(0,a.useState)(null),[k,b]=(0,a.useState)(null),[_,v]=(0,a.useState)(""),[N,S]=(0,a.useState)(!1),[A,C]=(0,a.useState)(null),T=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),C(e),S(!0)},P=async e=>{if(null==l)return;let t=e.token;e.key=t,console.log("handleEditSubmit:",e);let s=await I(l,e);console.log("handleEditSubmit: newKeyValues",s),o&&i(o.map(e=>e.token===t?s:e)),d.ZP.success("Key updated successfully"),S(!1),C(null)},E=async e=>{try{if(null==l||null==e)return;console.log("accessToken: ".concat(l,"; token: ").concat(e.token));let t=await w(l,e.token);console.log("Response:",t),b(t);try{let e=await O(l,t);console.log("Response2:",e);let s=[...t,...e.response];b(s),v(e.predicted_spend),console.log("Combined Data:",s)}catch(e){console.error("There was an error fetching the predicted data",e)}}catch(e){console.error("There was an error fetching the data",e)}};(0,a.useEffect)(()=>{E(f)},[f]);let F=async e=>{console.log("handleDelete:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),null!=o&&(j(e.token),localStorage.removeItem("userData"+t),x(!0))},M=async()=>{if(null!=p&&null!=o){try{await u(l,p);let e=o.filter(e=>e.token!==p);i(e)}catch(e){console.error("Error deleting the key:",e)}x(!1),j(null)}};if(null!=o)return console.log("RERENDER TRIGGERED"),(0,s.jsxs)("div",{children:[(0,s.jsxs)(el.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,s.jsxs)(en.Z,{className:"mt-5",children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"Key Alias"}),(0,s.jsx)(ed.Z,{children:"Secret Key"}),(0,s.jsx)(ed.Z,{children:"Spend (USD)"}),(0,s.jsx)(ed.Z,{children:"Budget (USD)"}),(0,s.jsx)(ed.Z,{children:"Models"}),(0,s.jsx)(ed.Z,{children:"TPM / RPM Limits"})]})}),(0,s.jsx)(eo.Z,{children:o.map(e=>(console.log(e),"litellm-dashboard"===e.team_id||r&&e.team_id!=r.team_id)?null:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,s.jsx)(z.Z,{children:e.key_alias}):(0,s.jsx)(z.Z,{children:"Not Set"})}),(0,s.jsx)(ei.Z,{children:(0,s.jsx)(z.Z,{children:e.key_name})}),(0,s.jsx)(ei.Z,{children:(0,s.jsx)(z.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(t){return e.spend}})()})}),(0,s.jsx)(ei.Z,{children:null!=e.max_budget?(0,s.jsx)(z.Z,{children:e.max_budget}):(0,s.jsx)(z.Z,{children:"Unlimited"})}),(0,s.jsx)(ei.Z,{children:Array.isArray(e.models)?(0,s.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,s.jsx)(s.Fragment,{children:r&&r.models&&r.models.length>0?r.models.map((e,t)=>"all-proxy-models"===e?(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"red",children:(0,s.jsx)(z.Z,{children:"All Proxy Models"})},t):"all-team-models"===e?(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"red",children:(0,s.jsx)(z.Z,{children:"All Team Models"})},t):(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,s.jsx)(z.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},t)):(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,s.jsx)(z.Z,{children:"all-proxy-models"})})}):e.models.map((e,t)=>"all-proxy-models"===e?(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"red",children:(0,s.jsx)(z.Z,{children:"All Proxy Models"})},t):"all-team-models"===e?(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"red",children:(0,s.jsx)(z.Z,{children:"All Team Models"})},t):(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,s.jsx)(z.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},t))}):null}),(0,s.jsx)(ei.Z,{children:(0,s.jsxs)(z.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,s.jsx)("br",{})," RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,s.jsxs)(ei.Z,{children:[(0,s.jsx)(er.Z,{onClick:()=>{Z(e),y(e.id)},icon:H.Z,size:"sm"}),(0,s.jsx)(es.Z,{open:null!==g,onClose:()=>{y(null),Z(null)},children:(0,s.jsx)(ea.Z,{children:f&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:[(0,s.jsxs)(el.Z,{children:[(0,s.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Spend"}),(0,s.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,s.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:(()=>{try{return parseFloat(f.spend).toFixed(4)}catch(e){return f.spend}})()})})]}),(0,s.jsxs)(el.Z,{children:[(0,s.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Budget"}),(0,s.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,s.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=f.max_budget?(0,s.jsx)(s.Fragment,{children:f.max_budget}):(0,s.jsx)(s.Fragment,{children:"Unlimited"})})})]},e.name),(0,s.jsxs)(el.Z,{children:[(0,s.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Expires"}),(0,s.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,s.jsx)("p",{className:"text-tremor-default font-small text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=f.expires?(0,s.jsx)(s.Fragment,{children:new Date(f.expires).toLocaleString(void 0,{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}):(0,s.jsx)(s.Fragment,{children:"Never"})})})]},e.name)]}),(0,s.jsx)(el.Z,{className:"mt-6 mb-6",children:k&&(0,s.jsx)(et.Z,{className:"mt-6",data:k,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,s.jsx)(B.Z,{children:"Metadata"}),(0,s.jsx)(z.Z,{children:JSON.stringify(f.metadata)}),(0,s.jsx)(U.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{y(null),Z(null)},children:"Close"})]})})}),(0,s.jsx)(er.Z,{icon:X.Z,size:"sm",onClick:()=>T(e)}),(0,s.jsx)(er.Z,{onClick:()=>F(e),icon:Q.Z,size:"sm"})]})]},e.token))})]}),h&&(0,s.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,s.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,s.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,s.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,s.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:""}),(0,s.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,s.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,s.jsx)("div",{className:"sm:flex sm:items-start",children:(0,s.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,s.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,s.jsx)("div",{className:"mt-2",children:(0,s.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,s.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,s.jsx)(U.Z,{onClick:M,color:"red",className:"ml-2",children:"Delete"}),(0,s.jsx)(U.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),A&&(0,s.jsx)(e=>{let{visible:t,onCancel:l,token:a,onSubmit:o}=e,[i]=V.Z.useForm();return 0==a.models.length&&r&&(a.models=r.models),(0,s.jsx)(q.Z,{title:"Edit Key",visible:t,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:l,children:(0,s.jsxs)(V.Z,{form:i,onFinish:P,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Models",name:"models",children:(0,s.jsxs)(K.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,s.jsx)(eh,{value:"all-team-models",children:"All Team Models"},"all-team-models"),r&&r.models?r.models.includes("all-proxy-models")?n.filter(e=>"all-proxy-models"!==e).map(e=>(0,s.jsx)(eh,{value:e,children:e},e)):r.models.map(e=>(0,s.jsx)(eh,{value:e,children:e},e)):n.map(e=>(0,s.jsx)(eh,{value:e,children:e},e))]})}),(0,s.jsx)(V.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==r?void 0:r.max_budget)!==null&&(null==r?void 0:r.max_budget)!==void 0?null==r?void 0:r.max_budget:"unlimited"),rules:[{validator:async(e,t)=>{if(t&&r&&null!==r.max_budget&&t>r.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(r.max_budget))}}],children:(0,s.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,s.jsx)(V.Z.Item,{label:"token",name:"token",hidden:!0})]}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{S(!1),C(null)},token:A,onSubmit:P})]})},ex=e=>{let{userID:t,userRole:l,accessToken:r}=e,[n,o]=(0,a.useState)(0),[i,c]=(0,a.useState)(0);(0,a.useEffect)(()=>{(async()=>{if(r&&t&&l&&"Admin"===l)try{let e=await j(r);e&&(e.spend?o(e.spend):o(0),e.max_budget?c(e.max_budget):c(0))}catch(e){console.error("Error fetching global spend data:",e)}})()},[l,r]);let d=void 0!==n?n.toFixed(5):null;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend"}),(0,s.jsxs)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",d]})]})},ep=l(55901),ej=l(27166),eg=e=>{let{teams:t,setSelectedTeam:l}=e,[r,n]=(0,a.useState)("");return(0,s.jsxs)("div",{className:"mt-5 mb-5",children:[(0,s.jsx)(B.Z,{children:"Select Team"}),(0,s.jsx)(z.Z,{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,s.jsx)(ep.Z,{defaultValue:"0",children:t.map((e,t)=>(0,s.jsx)(ej.Z,{value:String(t),onClick:()=>l(e),children:e.team_alias},t))}):(0,s.jsxs)(z.Z,{children:["No team created. ",(0,s.jsx)("b",{children:"Defaulting to personal account."})]})]})},ey=l(37963),ef=l(36083);console.log("isLocal:",!1);var ew=e=>{let{userID:t,userRole:l,teams:n,keys:o,setUserRole:i,userEmail:c,setUserEmail:d,setTeams:m,setKeys:h}=e,[u,x]=(0,a.useState)(null),g=(0,r.useSearchParams)();g.get("viewSpend"),(0,r.useRouter)();let y=g.get("token"),[w,Z]=(0,a.useState)(null),[k,b]=(0,a.useState)([]),[_,v]=(0,a.useState)(n?n[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,a.useEffect)(()=>{if(y){let e=(0,ey.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),Z(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),i(t)}else console.log("User role not defined");e.user_email?d(e.user_email):console.log("User Email is not set ".concat(e))}}if(t&&w&&l&&!o&&!u){let e=sessionStorage.getItem("userModels"+t);e?b(JSON.parse(e)):(async()=>{try{let e=await p(w,t,l);if(console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),"Admin"==l){let e=await j(w);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams),v(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+t,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+t,JSON.stringify(e.user_info));let s=(await f(w,t,l)).data.map(e=>e.id);console.log("available_model_names:",s),b(s),console.log("userModels:",k),sessionStorage.setItem("userModels"+t,JSON.stringify(s))}catch(e){console.error("There was an error fetching the data",e)}})()}},[t,y,w,o,l]),null==t||null==y){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==w)return null;if(null==l&&i("App Owner"),l&&"Admin Viewer"==l){let{Title:e,Paragraph:t}=ef.default;return(0,s.jsxs)("div",{children:[(0,s.jsx)(e,{level:1,children:"Access Denied"}),(0,s.jsx)(t,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",_),(0,s.jsx)("div",{className:"w-full mx-4",children:(0,s.jsx)(D.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(ex,{userID:t,userRole:l,accessToken:w}),(0,s.jsx)(eu,{userID:t,accessToken:w,selectedTeam:_||null,data:o,userModels:k,setData:h}),(0,s.jsx)(Y,{userID:t,team:_||null,userRole:l,accessToken:w,data:o,setData:h},_?_.team_id:null),(0,s.jsx)(eg,{teams:n,setSelectedTeam:v})]})})})};let{Option:eZ}=K.default;var ek=e=>{let{userModels:t,accessToken:l,userID:r}=e,[n]=V.Z.useForm(),[o,i]=(0,a.useState)(!1),c=async e=>{try{d.ZP.info("Requesting access");let{selectedModel:t,accessReason:s}=e;await A(l,t,r,s),i(!0)}catch(e){console.error("Error requesting access:",e)}};return(0,s.jsxs)("div",{children:[(0,s.jsx)(U.Z,{size:"xs",onClick:()=>i(!0),children:"Request Access"}),(0,s.jsx)(q.Z,{title:"Request Access",visible:o,width:800,footer:null,onOk:()=>{i(!1),n.resetFields()},onCancel:()=>{i(!1),n.resetFields()},children:(0,s.jsxs)(V.Z,{form:n,onFinish:c,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsx)(V.Z.Item,{label:"Select Model",name:"selectedModel",children:(0,s.jsx)(K.default,{placeholder:"Select model",style:{width:"100%"},children:t.map(e=>(0,s.jsx)(eZ,{value:e,children:e},e))})}),(0,s.jsx)(V.Z.Item,{label:"Reason for Access",name:"accessReason",children:(0,s.jsx)(J.Z.TextArea,{rows:4,placeholder:"Enter reason for access"})}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(U.Z,{children:"Request Access"})})]})})]})},eb=e=>{let{accessToken:t,token:l,userRole:r,userID:n}=e,[o,i]=(0,a.useState)({data:[]}),[c,d]=(0,a.useState)([]),[m,h]=(0,a.useState)([]);if((0,a.useEffect)(()=>{if(!t||!l||!r||!n)return;let e=async()=>{try{let e=await g(t,n,r);console.log("Model data response:",e.data),i(e);let l=await y(t,n,r);if(console.log("Model metrics response:",l),d(l),"Admin"===r&&t){let e=await C(t);console.log("Pending Requests:",m),h(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};t&&l&&r&&n&&e()},[t,l,r,n]),!o||!t||!l||!r||!n)return(0,s.jsx)("div",{children:"Loading..."});let u=[];for(let e=0;e<o.data.length;e++){var x,p;let t=o.data[e],l=null==t?void 0:null===(x=t.litellm_params)||void 0===x?void 0:x.mode,s=null==t?void 0:t.model_info,a="openai",r="",n="Undefined",i="Undefined",c="Undefined";if(l){let e=l.split("/"),t=e[0];r=1===e.length?a:t}else r=a;s&&(n=null==s?void 0:s.input_cost_per_token,i=null==s?void 0:s.output_cost_per_token,c=null==s?void 0:s.max_tokens),o.data[e].provider=r,o.data[e].input_cost=n,o.data[e].output_cost=i,o.data[e].max_tokens=c,o.data[e].api_base=null==t?void 0:null===(p=t.litellm_params)||void 0===p?void 0:p.api_base,u.push(t.model_name),console.log(o.data[e])}if(r&&"Admin Viewer"==r){let{Title:e,Paragraph:t}=ef.default;return(0,s.jsxs)("div",{children:[(0,s.jsx)(e,{level:1,children:"Access Denied"}),(0,s.jsx)(t,{children:"Ask your proxy admin for access to view all models"})]})}return(0,s.jsx)("div",{style:{width:"100%"},children:(0,s.jsxs)(D.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,s.jsx)(el.Z,{children:(0,s.jsxs)(en.Z,{className:"mt-5",children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"Model Name "}),(0,s.jsx)(ed.Z,{children:"Provider"}),"Admin"===r&&(0,s.jsx)(ed.Z,{children:"API Base"}),(0,s.jsx)(ed.Z,{children:"Access"}),(0,s.jsx)(ed.Z,{children:"Input Price per token ($)"}),(0,s.jsx)(ed.Z,{children:"Output Price per token ($)"}),(0,s.jsx)(ed.Z,{children:"Max Tokens"})]})}),(0,s.jsx)(eo.Z,{children:o.data.map(e=>(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{children:(0,s.jsx)(z.Z,{children:e.model_name})}),(0,s.jsx)(ei.Z,{children:e.provider}),"Admin"===r&&(0,s.jsx)(ei.Z,{children:e.api_base}),(0,s.jsx)(ei.Z,{children:e.user_access?(0,s.jsx)(ee.Z,{color:"green",children:"Yes"}):(0,s.jsx)(ek,{userModels:u,accessToken:t,userID:n})}),(0,s.jsx)(ei.Z,{children:e.input_cost}),(0,s.jsx)(ei.Z,{children:e.output_cost}),(0,s.jsx)(ei.Z,{children:e.max_tokens})]},e.model_name))})]})}),(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Model Statistics (Number Requests)"}),(0,s.jsx)(et.Z,{data:c,index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Model Statistics (Latency)"}),(0,s.jsx)(et.Z,{data:c,index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})})},e_=l(92836),ev=l(26734),eN=l(41608),eS=l(32126),eA=l(23682);let{Option:eC}=K.default;var eT=e=>{let{userID:t,accessToken:l}=e,[r]=V.Z.useForm(),[n,o]=(0,a.useState)(!1),[i,c]=(0,a.useState)(null),[m,u]=(0,a.useState)([]);(0,a.useEffect)(()=>{(async()=>{try{let e=await f(l,t,"any"),s=[];for(let t=0;t<e.data.length;t++){let l=e.data[t];s.push(l.id)}console.log("Model data response:",e.data),console.log("Available models:",s),u(s)}catch(e){console.error("Error fetching model data:",e)}})()},[]);let x=()=>{o(!1),r.resetFields()},p=()=>{o(!1),c(null),r.resetFields()},j=async e=>{try{d.ZP.info("Making API Call"),o(!0),console.log("formValues in create user:",e);let s=await h(l,t,e);console.log("user create Response:",s),c(s.key),d.ZP.success("API user Created"),r.resetFields(),localStorage.removeItem("userData"+t)}catch(e){console.error("Error creating the user:",e)}};return(0,s.jsxs)("div",{children:[(0,s.jsx)(U.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Create New User"}),(0,s.jsx)(q.Z,{title:"Create User",visible:n,width:800,footer:null,onOk:x,onCancel:p,children:(0,s.jsxs)(V.Z,{form:r,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsx)(V.Z.Item,{label:"User ID",name:"user_id",children:(0,s.jsx)(J.Z,{placeholder:"Enter User ID"})}),(0,s.jsx)(V.Z.Item,{label:"Team ID",name:"team_id",children:(0,s.jsx)(J.Z,{placeholder:"ai_team"})}),(0,s.jsx)(V.Z.Item,{label:"Models",name:"models",children:(0,s.jsx)(K.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:m.map(e=>(0,s.jsx)(eC,{value:e,children:e},e))})}),(0,s.jsx)(V.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,s.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,s.jsx)(V.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{label:"Duration (eg: 30s, 30h, 30d)",name:"duration",children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Metadata",name:"metadata",children:(0,s.jsx)(J.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Create User"})})]})}),i&&(0,s.jsxs)(q.Z,{title:"Save Your User",visible:n,onOk:x,onCancel:p,footer:null,children:[(0,s.jsxs)("p",{children:["Please save this secret user somewhere safe and accessible. For security reasons, ",(0,s.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,s.jsx)("p",{children:null!=i?"API user: ".concat(i):"User being created, this might take 30s"})]})]})},eP=e=>{let{accessToken:t,token:l,keys:r,userRole:n,userID:o,setKeys:i}=e,[c,d]=(0,a.useState)(null),[m,h]=(0,a.useState)(null),[u,x]=(0,a.useState)(1);if((0,a.useEffect)(()=>{if(!t||!l||!n||!o)return;let e=async()=>{try{let e=await p(t,null,n,!0);console.log("user data response:",e),d(e)}catch(e){console.error("There was an error fetching the model data",e)}};t&&l&&n&&o&&!c&&e();let s=async()=>{try{let e=await v(t,null);console.log("user data response:",e),h(e)}catch(e){console.error("There was an error fetching the model data",e)}};n&&("Admin"==n||"Admin Viewer"==n)&&!m&&s()},[t,l,n,o]),!c||!t||!l||!n||!o)return(0,s.jsx)("div",{children:"Loading..."});let j=async e=>{try{let l=await v(t,e);console.log("user data response:",l),h(l)}catch(e){console.error("There was an error fetching the model data",e)}};return(0,s.jsx)("div",{style:{width:"100%"},children:(0,s.jsxs)(D.Z,{className:"gap-2 p-2 h-[75vh] w-full mt-8",children:[(0,s.jsx)(eT,{userID:o,accessToken:t}),(0,s.jsx)(el.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:(0,s.jsxs)(ev.Z,{children:[(0,s.jsxs)(eN.Z,{variant:"line",defaultValue:"1",children:[(0,s.jsx)(e_.Z,{value:"1",children:"Key Owners"}),(0,s.jsx)(e_.Z,{value:"2",children:"End-Users"})]}),(0,s.jsxs)(eA.Z,{children:[(0,s.jsx)(eS.Z,{children:(0,s.jsxs)(en.Z,{className:"mt-5",children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"User ID"}),(0,s.jsx)(ed.Z,{children:"User Role"}),(0,s.jsx)(ed.Z,{children:"User Models"}),(0,s.jsx)(ed.Z,{children:"User Spend ($ USD)"}),(0,s.jsx)(ed.Z,{children:"User Max Budget ($ USD)"})]})}),(0,s.jsx)(eo.Z,{children:c.map(e=>(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{children:e.user_id}),(0,s.jsx)(ei.Z,{children:e.user_role?e.user_role:"app_owner"}),(0,s.jsx)(ei.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,s.jsx)(ei.Z,{children:e.spend?e.spend:0}),(0,s.jsx)(ei.Z,{children:e.max_budget?e.max_budget:"Unlimited"})]},e.user_id))})]})}),(0,s.jsxs)(eS.Z,{children:[(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsxs)("div",{className:"flex-1 flex justify-between items-center",children:[(0,s.jsx)(z.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,s.jsx)(ep.Z,{defaultValue:"1",className:"w-3/4",children:null==r?void 0:r.map((e,t)=>{if(e&&null!==e.key_name&&e.key_name.length>0)return(0,s.jsx)(ej.Z,{value:String(t),onClick:()=>j(e.token),children:e.key_name},t)})})]})]}),(0,s.jsxs)(en.Z,{children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"End User"}),(0,s.jsx)(ed.Z,{children:"Spend"}),(0,s.jsx)(ed.Z,{children:"Total Events"})]})}),(0,s.jsx)(eo.Z,{children:null==m?void 0:m.map((e,t)=>(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{children:e.end_user}),(0,s.jsx)(ei.Z,{children:e.total_spend}),(0,s.jsx)(ei.Z,{children:e.total_events})]},t))})]})]})]})]})}),function(){if(!c)return null;let e=Math.ceil(c.length/25),t=Math.min(25*u,c.length);return(0,s.jsxs)("div",{className:"flex justify-between items-center",children:[(0,s.jsxs)("div",{children:["Showing ",(u-1)*25+1," ",t," of ",c.length]}),(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l focus:outline-none",disabled:1===u,onClick:()=>x(u-1),children:"← Prev"}),(0,s.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r focus:outline-none",disabled:u===e,onClick:()=>x(u+1),children:"Next →"})]})]})}()]})})},eI=e=>{let{teams:t,searchParams:l,accessToken:r,setTeams:n,userID:o,userRole:i}=e,[c]=V.Z.useForm(),[m]=V.Z.useForm(),{Title:h,Paragraph:u}=ef.default,[p,j]=(0,a.useState)(""),[g,y]=(0,a.useState)(!1),[w,Z]=(0,a.useState)(t?t[0]:null),[k,b]=(0,a.useState)(!1),[_,v]=(0,a.useState)(!1),[N,S]=(0,a.useState)([]),[A,C]=(0,a.useState)(!1),[T,I]=(0,a.useState)(null),M=e=>{Z(e),y(!0)},O=async e=>{let l=e.team_id;if(console.log("handleEditSubmit:",e),null==r)return;let s=await E(r,e);t&&n(t.map(e=>e.team_id===l?s.data:e)),d.ZP.success("Team updated successfully"),y(!1),Z(null)},B=async e=>{I(e),C(!0)},L=async()=>{if(null!=T&&null!=t&&null!=r){try{await x(r,T);let e=t.filter(e=>e.team_id!==T);n(e)}catch(e){console.error("Error deleting the team:",e)}C(!1),I(null)}};(0,a.useEffect)(()=>{(async()=>{try{if(null===o||null===i)return;if(null!==r){let e=(await f(r,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),S(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[r,o,i]);let $=async e=>{try{if(null!=r){d.ZP.info("Creating Team");let l=await P(r,e);null!==t?n([...t,l]):n([l]),console.log("response for team create call: ".concat(l)),d.ZP.success("Team created"),b(!1)}}catch(e){console.error("Error creating the team:",e),d.ZP.error("Error creating the team: "+e)}},Y=async e=>{try{if(null!=r&&null!=t){d.ZP.info("Adding Member");let l={role:"user",user_email:e.user_email,user_id:e.user_id},s=await F(r,w.team_id,l);console.log("response for team create call: ".concat(s.data));let a=t.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(s.data.team_id)),e.team_id===s.data.team_id));if(console.log("foundIndex: ".concat(a)),-1!==a){let e=[...t];e[a]=s.data,n(e),Z(s.data)}v(!1)}}catch(e){console.error("Error creating the team:",e)}};return console.log("received teams ".concat(t)),(0,s.jsx)("div",{className:"w-full mx-4",children:(0,s.jsxs)(D.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(h,{level:4,children:"All Teams"}),(0,s.jsxs)(el.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,s.jsxs)(en.Z,{children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"Team Name"}),(0,s.jsx)(ed.Z,{children:"Spend (USD)"}),(0,s.jsx)(ed.Z,{children:"Budget (USD)"}),(0,s.jsx)(ed.Z,{children:"Models"}),(0,s.jsx)(ed.Z,{children:"TPM / RPM Limits"})]})}),(0,s.jsx)(eo.Z,{children:t&&t.length>0?t.map(e=>(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,s.jsx)(ei.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,s.jsx)(ei.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,s.jsx)(ei.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,s.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"red",children:(0,s.jsx)(z.Z,{children:"All Proxy Models"})}):e.models.map((e,t)=>"all-proxy-models"===e?(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"red",children:(0,s.jsx)(z.Z,{children:"All Proxy Models"})},t):(0,s.jsx)(ee.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,s.jsx)(z.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},t))}):null}),(0,s.jsx)(ei.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,s.jsxs)(z.Z,{children:["TPM:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,s.jsx)("br",{}),"RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,s.jsxs)(ei.Z,{children:[(0,s.jsx)(er.Z,{icon:X.Z,size:"sm",onClick:()=>M(e)}),(0,s.jsx)(er.Z,{onClick:()=>B(e.team_id),icon:Q.Z,size:"sm"})]})]},e.team_id)):null})]}),A&&(0,s.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,s.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,s.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,s.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,s.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:""}),(0,s.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,s.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,s.jsx)("div",{className:"sm:flex sm:items-start",children:(0,s.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,s.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,s.jsx)("div",{className:"mt-2",children:(0,s.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,s.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,s.jsx)(U.Z,{onClick:L,color:"red",className:"ml-2",children:"Delete"}),(0,s.jsx)(U.Z,{onClick:()=>{C(!1),I(null)},children:"Cancel"})]})]})]})})]})]}),(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(U.Z,{className:"mx-auto",onClick:()=>b(!0),children:"+ Create New Team"}),(0,s.jsx)(q.Z,{title:"Create Team",visible:k,width:800,footer:null,onOk:()=>{b(!1),c.resetFields()},onCancel:()=>{b(!1),c.resetFields()},children:(0,s.jsxs)(V.Z,{form:c,onFinish:$,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Models",name:"models",children:(0,s.jsxs)(K.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,s.jsx)(K.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),N.map(e=>(0,s.jsx)(K.default.Option,{value:e,children:e},e))]})}),(0,s.jsx)(V.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,s.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,s.jsx)(V.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,s.jsx)(G.Z,{step:1,width:400})})]}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(h,{level:4,children:"Team Members"}),(0,s.jsx)(u,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),t&&t.length>0?(0,s.jsx)(ep.Z,{defaultValue:"0",children:t.map((e,t)=>(0,s.jsx)(ej.Z,{value:String(t),onClick:()=>{Z(e)},children:e.team_alias},t))}):(0,s.jsxs)(u,{children:["No team created. ",(0,s.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(el.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,s.jsxs)(en.Z,{children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"Member Name"}),(0,s.jsx)(ed.Z,{children:"Role"})]})}),(0,s.jsx)(eo.Z,{children:w?w.members_with_roles.map((e,t)=>(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,s.jsx)(ei.Z,{children:e.role})]},t)):null})]})}),w&&(0,s.jsx)(e=>{let{visible:t,onCancel:l,team:a,onSubmit:r}=e,[n]=V.Z.useForm();return(0,s.jsx)(q.Z,{title:"Edit Team",visible:t,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{r({...e,team_id:a.team_id}),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:l,children:(0,s.jsxs)(V.Z,{form:n,onFinish:O,initialValues:a,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,s.jsx)(J.Z,{})}),(0,s.jsx)(V.Z.Item,{label:"Models",name:"models",children:(0,s.jsxs)(K.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,s.jsx)(K.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),N&&N.map(e=>(0,s.jsx)(K.default.Option,{value:e,children:e},e))]})}),(0,s.jsx)(V.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,s.jsx)(G.Z,{step:.01,precision:2,width:200})}),(0,s.jsx)(V.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,s.jsx)(G.Z,{step:1,width:400})}),(0,s.jsx)(V.Z.Item,{label:"Requests per minute Limit (RPM)",name:"team_id",hidden:!0})]}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:g,onCancel:()=>{y(!1),Z(null)},team:w,onSubmit:O})]}),(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(U.Z,{className:"mx-auto mb-5",onClick:()=>v(!0),children:"+ Add member"}),(0,s.jsx)(q.Z,{title:"Add member",visible:_,width:800,footer:null,onOk:()=>{v(!1),m.resetFields()},onCancel:()=>{v(!1),m.resetFields()},children:(0,s.jsxs)(V.Z,{form:c,onFinish:Y,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,s.jsx)(J.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,s.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,s.jsx)(V.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,s.jsx)(J.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},eE=e=>{let{searchParams:t,accessToken:l}=e,[r]=V.Z.useForm(),[n]=V.Z.useForm(),{Title:o,Paragraph:i}=ef.default,[c,m]=(0,a.useState)(""),[h,u]=(0,a.useState)(null),[x,p]=(0,a.useState)(!1);(0,a.useEffect)(()=>{(async()=>{if(null!=l){let e=[],t=await T(l,"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 s=await T(l,"proxy_admin");s.forEach(t=>{e.push({user_role:t.user_role,user_id:t.user_id,user_email:t.user_email})}),console.log("proxy admins: ".concat(s)),console.log("combinedList: ".concat(e)),u(e)}})()},[l]);let j=async e=>{try{if(null!=l&&null!=h){d.ZP.info("Making API Call"),e.user_email,e.user_id;let t=await M(l,e);console.log("response for team create call: ".concat(t));let s=h.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(s)),-1==s&&(console.log("updates admin with new user"),h.push(t),u(h)),p(!1)}}catch(e){console.error("Error creating the key:",e)}};return console.log("admins: ".concat(null==h?void 0:h.length)),(0,s.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,s.jsx)(o,{level:4,children:"Restricted Access"}),(0,s.jsxs)(i,{children:["Add other people to just view spend. They cannot create keys, teams or grant users access to new models."," ",(0,s.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access",children:"Requires SSO Setup"})]}),(0,s.jsxs)(D.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,s.jsx)(R.Z,{numColSpan:1,children:(0,s.jsx)(el.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,s.jsxs)(en.Z,{children:[(0,s.jsx)(ec.Z,{children:(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ed.Z,{children:"Member Name"}),(0,s.jsx)(ed.Z,{children:"Role"})]})}),(0,s.jsx)(eo.Z,{children:h?h.map((e,t)=>(0,s.jsxs)(em.Z,{children:[(0,s.jsx)(ei.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,s.jsx)(ei.Z,{children:e.user_role})]},t)):null})]})})}),(0,s.jsxs)(R.Z,{numColSpan:1,children:[(0,s.jsx)(U.Z,{className:"mx-auto mb-5",onClick:()=>p(!0),children:"+ Add viewer"}),(0,s.jsx)(q.Z,{title:"Add viewer",visible:x,width:800,footer:null,onOk:()=>{p(!1),n.resetFields()},onCancel:()=>{p(!1),n.resetFields()},children:(0,s.jsxs)(V.Z,{form:r,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(V.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,s.jsx)(J.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,s.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,s.jsx)(V.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,s.jsx)(J.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,s.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,s.jsx)(W.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})]})},eF=l(52273),eM=l(12968),eO=l(67951);async function eR(e,t,l,s){console.log("isLocal:",!1);let a=window.location.origin,r=new eM.ZP.OpenAI({apiKey:s,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let s of(await r.chat.completions.create({model:l,stream:!0,messages:[{role:"user",content:e}]})))console.log(s),s.choices[0].delta.content&&t(s.choices[0].delta.content)}catch(e){d.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e))}}var eD=e=>{let{accessToken:t,token:l,userRole:r,userID:n}=e,[o,i]=(0,a.useState)(""),[c,d]=(0,a.useState)(""),[m,h]=(0,a.useState)([]),[u,x]=(0,a.useState)(void 0),[p,j]=(0,a.useState)([]);(0,a.useEffect)(()=>{t&&l&&r&&n&&(async()=>{try{let e=await f(t,n,r);if(console.log("model_info:",e),(null==e?void 0:e.data.length)>0){let t=e.data.map(e=>({value:e.id,label:e.id}));console.log(t),j(t),x(e.data[0].id)}}catch(e){console.error("Error fetching model info:",e)}})()},[t,n,r]);let g=(e,t)=>{h(l=>{let s=l[l.length-1];return s&&s.role===e?[...l.slice(0,l.length-1),{role:e,content:s.content+t}]:[...l,{role:e,content:t}]})},y=async()=>{if(""!==c.trim()&&o&&l&&r&&n){h(e=>[...e,{role:"user",content:c}]);try{u&&await eR(c,e=>g("assistant",e),u,o)}catch(e){console.error("Error fetching model response",e),g("assistant","Error fetching model response")}d("")}};if(r&&"Admin Viewer"==r){let{Title:e,Paragraph:t}=ef.default;return(0,s.jsxs)("div",{children:[(0,s.jsx)(e,{level:1,children:"Access Denied"}),(0,s.jsx)(t,{children:"Ask your proxy admin for access to test models"})]})}return(0,s.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,s.jsx)(D.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,s.jsx)(el.Z,{children:(0,s.jsxs)(ev.Z,{children:[(0,s.jsxs)(eN.Z,{children:[(0,s.jsx)(e_.Z,{children:"Chat"}),(0,s.jsx)(e_.Z,{children:"API Reference"})]}),(0,s.jsxs)(eA.Z,{children:[(0,s.jsxs)(eS.Z,{children:[(0,s.jsx)("div",{className:"sm:max-w-2xl",children:(0,s.jsxs)(D.Z,{numItems:2,children:[(0,s.jsxs)(R.Z,{children:[(0,s.jsx)(z.Z,{children:"API Key"}),(0,s.jsx)(eF.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,s.jsxs)(R.Z,{className:"mx-2",children:[(0,s.jsx)(z.Z,{children:"Select Model:"}),(0,s.jsx)(K.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,s.jsxs)(en.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,s.jsx)(ec.Z,{children:(0,s.jsx)(em.Z,{children:(0,s.jsx)(ei.Z,{})})}),(0,s.jsx)(eo.Z,{children:m.map((e,t)=>(0,s.jsx)(em.Z,{children:(0,s.jsx)(ei.Z,{children:"".concat(e.role,": ").concat(e.content)})},t))})]}),(0,s.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)(eF.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,s.jsx)(U.Z,{onClick:y,className:"ml-2",children:"Send"})]})})]}),(0,s.jsx)(eS.Z,{children:(0,s.jsxs)(ev.Z,{children:[(0,s.jsxs)(eN.Z,{children:[(0,s.jsx)(e_.Z,{children:"OpenAI Python SDK"}),(0,s.jsx)(e_.Z,{children:"LlamaIndex"}),(0,s.jsx)(e_.Z,{children:"Langchain Py"})]}),(0,s.jsxs)(eA.Z,{children:[(0,s.jsx)(eS.Z,{children:(0,s.jsx)(eO.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,s.jsx)(eS.Z,{children:(0,s.jsx)(eO.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,s.jsx)(eS.Z,{children:(0,s.jsx)(eO.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 '})})]})]})})]})]})})})})},eU=l(33509),ez=l(95781);let{Sider:eB}=eU.default;var eL=e=>{let{setPage:t,userRole:l,defaultSelectedKey:a}=e;return"Admin Viewer"==l?(0,s.jsx)(eU.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,s.jsx)(eB,{width:120,children:(0,s.jsxs)(ez.Z,{mode:"inline",defaultSelectedKeys:a||["4"],style:{height:"100%",borderRight:0},children:[(0,s.jsx)(ez.Z.Item,{onClick:()=>t("api-keys"),children:"API Keys"},"4"),(0,s.jsx)(ez.Z.Item,{onClick:()=>t("models"),children:"Models"},"2"),(0,s.jsx)(ez.Z.Item,{onClick:()=>t("llm-playground"),children:"Chat UI"},"3"),(0,s.jsx)(ez.Z.Item,{onClick:()=>t("usage"),children:"Usage"},"1")]})})}):(0,s.jsx)(eU.default,{style:{minHeight:"100vh",maxWidth:"100px"},children:(0,s.jsx)(eB,{width:100,children:(0,s.jsxs)(ez.Z,{mode:"inline",defaultSelectedKeys:a||["1"],style:{height:"100%",borderRight:0},children:[(0,s.jsx)(ez.Z.Item,{onClick:()=>t("api-keys"),children:(0,s.jsx)(z.Z,{children:"API Keys"})},"1"),(0,s.jsx)(ez.Z.Item,{onClick:()=>t("llm-playground"),children:(0,s.jsx)(z.Z,{children:"Test Key"})},"3"),"Admin"==l?(0,s.jsx)(ez.Z.Item,{onClick:()=>t("teams"),children:(0,s.jsx)(z.Z,{children:"Teams"})},"6"):null,(0,s.jsx)(ez.Z.Item,{onClick:()=>t("usage"),children:(0,s.jsx)(z.Z,{children:"Usage"})},"4"),"Admin"==l?(0,s.jsx)(ez.Z.Item,{onClick:()=>t("users"),children:(0,s.jsx)(z.Z,{children:"Users"})},"5"):null,(0,s.jsx)(ez.Z.Item,{onClick:()=>t("models"),children:(0,s.jsx)(z.Z,{children:"Models"})},"2"),"Admin"==l?(0,s.jsx)(ez.Z.Item,{onClick:()=>t("admin-panel"),children:(0,s.jsx)(z.Z,{children:"Admin"})},"7"):null]})})})},eK=l(67989),eV=e=>{let{accessToken:t,token:l,userRole:r,userID:n}=e,o=new Date,[i,c]=(0,a.useState)([]),[d,m]=(0,a.useState)([]),[h,u]=(0,a.useState)([]),[x,p]=(0,a.useState)([]),[j,g]=(0,a.useState)([]),[y,f]=(0,a.useState)([]),[w,v]=(0,a.useState)([]),A=new Date(o.getFullYear(),o.getMonth(),1),C=new Date(o.getFullYear(),o.getMonth()+1,0),T=I(A),P=I(C);function I(e){let t=e.getFullYear(),l=e.getMonth()+1,s=e.getDate();return"".concat(t,"-").concat(l<10?"0"+l:l,"-").concat(s<10?"0"+s:s)}return console.log("Start date is ".concat(T)),console.log("End date is ".concat(P)),(0,a.useEffect)(()=>{t&&l&&r&&n&&(async()=>{try{if(console.log("user role: ".concat(r)),"Admin"==r||"Admin Viewer"==r){let e=await b(t);c(e);let l=(await _(t)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(l);let s=(await N(t)).map(e=>({key:e.model,spend:e.total_spend}));u(s);let a=await Z(t);console.log("teamSpend",a),g(a.daily_spend),f(a.teams);let r=a.total_spend_per_team;r=r.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),v(r)}else"App Owner"==r&&await k(t,l,r,n,T,P).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 l=e.top_api_keys;m(l)}else{let l=(await S(t,function(e){let t=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[l,s]=e;"spend"!==l&&"startTime"!==l&&"models"!==l&&"users"!==l&&t.push({key:l,spend:s})})}),t.sort((e,t)=>Number(t.spend)-Number(e.spend));let l=t.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(l[0]))),l}(e))).info.map(e=>({key:(e.key_name||e.key_alias).substring(0,10),spend:e.spend}));m(l),p(function(e){let t={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[l,s]=e;""!==l&&null!=l&&"None"!=l&&(t[l]||(t[l]=0),t[l]+=s)})});let l=Object.entries(t).map(e=>{let[t,l]=e;return{user_id:t,spend:l}});l.sort((e,t)=>t.spend-e.spend);let s=l.slice(0,5);return console.log("topKeys: ".concat(Object.values(s[0]))),s}(e)),c(e)}})}catch(e){console.error("There was an error fetching the data",e)}})()},[t,l,r,n,T,P]),(0,s.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,s.jsx)(ex,{userID:n,userRole:r,accessToken:t}),(0,s.jsxs)(ev.Z,{children:[(0,s.jsxs)(eN.Z,{className:"mt-2",children:[(0,s.jsx)(e_.Z,{children:"All Up"}),(0,s.jsx)(e_.Z,{children:"Team Based Usage"})]}),(0,s.jsxs)(eA.Z,{children:[(0,s.jsx)(eS.Z,{children:(0,s.jsxs)(D.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,s.jsx)(R.Z,{numColSpan:2,children:(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Monthly Spend"}),(0,s.jsx)(et.Z,{data:i,index:"date",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,s.jsx)(R.Z,{numColSpan:1,children:(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Top API Keys"}),(0,s.jsx)(et.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,s.jsx)(R.Z,{numColSpan:1,children:(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Top Users"}),(0,s.jsx)(et.Z,{className:"mt-4 h-40",data:x,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,s.jsx)(R.Z,{numColSpan:1,children:(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Top Models"}),(0,s.jsx)(et.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})}),(0,s.jsx)(eS.Z,{children:(0,s.jsxs)(D.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,s.jsxs)(R.Z,{numColSpan:2,children:[(0,s.jsxs)(el.Z,{className:"mb-2",children:[(0,s.jsx)(B.Z,{children:"Total Spend Per Team"}),(0,s.jsx)(eK.Z,{data:w})]}),(0,s.jsxs)(el.Z,{children:[(0,s.jsx)(B.Z,{children:"Daily Spend Per Team"}),(0,s.jsx)(et.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:y,yAxisWidth:80,stack:!0})]})]}),(0,s.jsx)(R.Z,{numColSpan:2})]})})]})]})]})},eq=()=>{let{Title:e,Paragraph:t}=ef.default,[l,n]=(0,a.useState)(""),[o,i]=(0,a.useState)(null),[d,m]=(0,a.useState)(null),[h,u]=(0,a.useState)(null),[x,p]=(0,a.useState)(!0),j=(0,r.useSearchParams)(),g=j.get("userID"),y=j.get("token"),[f,w]=(0,a.useState)("api-keys"),[Z,k]=(0,a.useState)(null);return(0,a.useEffect)(()=>{if(y){let e=(0,ey.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),k(e.key),e.user_role){let t=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:",t),n(t),"Admin Viewer"==t&&w("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?p("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[y]),(0,s.jsx)(a.Suspense,{fallback:(0,s.jsx)("div",{children:"Loading..."}),children:(0,s.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,s.jsx)(c,{userID:g,userRole:l,userEmail:o,showSSOBanner:x}),(0,s.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,s.jsx)("div",{className:"mt-8",children:(0,s.jsx)(eL,{setPage:w,userRole:l,defaultSelectedKey:null})}),"api-keys"==f?(0,s.jsx)(ew,{userID:g,userRole:l,teams:d,keys:h,setUserRole:n,userEmail:o,setUserEmail:i,setTeams:m,setKeys:u}):"models"==f?(0,s.jsx)(eb,{userID:g,userRole:l,token:y,accessToken:Z}):"llm-playground"==f?(0,s.jsx)(eD,{userID:g,userRole:l,token:y,accessToken:Z}):"users"==f?(0,s.jsx)(eP,{userID:g,userRole:l,token:y,keys:h,accessToken:Z,setKeys:u}):"teams"==f?(0,s.jsx)(eI,{teams:d,setTeams:m,searchParams:j,accessToken:Z,userID:g,userRole:l}):"admin-panel"==f?(0,s.jsx)(eE,{setTeams:m,searchParams:j,accessToken:Z}):(0,s.jsx)(eV,{userID:g,userRole:l,token:y,accessToken:Z})]})]})})}}},function(e){e.O(0,[886,971,69,744],function(){return e(e.s=20661)}),_N_E=e.O()}]);