diff --git a/docs/my-website/docs/proxy/alerting.md b/docs/my-website/docs/proxy/alerting.md index feb54babd..4275e0bf0 100644 --- a/docs/my-website/docs/proxy/alerting.md +++ b/docs/my-website/docs/proxy/alerting.md @@ -1,13 +1,13 @@ -# Slack Alerting +# 🚨 Alerting Get alerts for: -- hanging LLM api calls -- failed LLM api calls -- slow LLM api calls -- budget Tracking per key/user: +- Hanging LLM api calls +- Failed LLM api calls +- Slow LLM api calls +- Budget Tracking per key/user: - When a User/Key crosses their Budget - When a User/Key is 15% away from crossing their Budget -- failed db read/writes +- Failed db read/writes ## Quick Start diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index a5d1f30ae..e4f4e806e 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -43,6 +43,12 @@ const sidebars = { "proxy/user_keys", "proxy/enterprise", "proxy/virtual_keys", + "proxy/alerting", + { + type: "category", + label: "Logging", + items: ["proxy/logging", "proxy/streaming_logging"], + }, "proxy/team_based_routing", "proxy/ui", "proxy/cost_tracking", @@ -58,11 +64,6 @@ const sidebars = { "proxy/pii_masking", "proxy/prompt_injection", "proxy/caching", - { - type: "category", - label: "Logging, Alerting", - items: ["proxy/logging", "proxy/alerting", "proxy/streaming_logging"], - }, "proxy/prometheus", "proxy/call_hooks", "proxy/rules", diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 51ad4d19a..c2612feb8 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -12,7 +12,9 @@ import litellm class LangFuseLogger: # Class variables or attributes - def __init__(self, langfuse_public_key=None, langfuse_secret=None): + def __init__( + self, langfuse_public_key=None, langfuse_secret=None, flush_interval=1 + ): try: from langfuse import Langfuse except Exception as e: @@ -31,7 +33,7 @@ class LangFuseLogger: host=self.langfuse_host, release=self.langfuse_release, debug=self.langfuse_debug, - flush_interval=1, # flush interval in seconds + flush_interval=flush_interval, # flush interval in seconds ) # set the current langfuse project id in the environ diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index adc56698c..8f8ce712e 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -12,6 +12,7 @@ from litellm.caching import DualCache import asyncio import aiohttp from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +import datetime class SlackAlerting: @@ -47,6 +48,18 @@ class SlackAlerting: self.internal_usage_cache = DualCache() self.async_http_handler = AsyncHTTPHandler() self.alert_to_webhook_url = alert_to_webhook_url + self.langfuse_logger = None + + try: + from litellm.integrations.langfuse import LangFuseLogger + + self.langfuse_logger = LangFuseLogger( + os.getenv("LANGFUSE_PUBLIC_KEY"), + os.getenv("LANGFUSE_SECRET_KEY"), + flush_interval=1, + ) + except: + pass pass @@ -93,39 +106,68 @@ class SlackAlerting: request_info: str, request_data: Optional[dict] = None, kwargs: Optional[dict] = None, + type: Literal["hanging_request", "slow_response"] = "hanging_request", + start_time: Optional[datetime.datetime] = None, + end_time: Optional[datetime.datetime] = None, ): import uuid # For now: do nothing as we're debugging why this is not working as expected + if request_data is not None: + trace_id = request_data.get("metadata", {}).get( + "trace_id", None + ) # get langfuse trace id + if trace_id is None: + trace_id = "litellm-alert-trace-" + str(uuid.uuid4()) + request_data["metadata"]["trace_id"] = trace_id + elif kwargs is not None: + _litellm_params = kwargs.get("litellm_params", {}) + trace_id = _litellm_params.get("metadata", {}).get( + "trace_id", None + ) # get langfuse trace id + if trace_id is None: + trace_id = "litellm-alert-trace-" + str(uuid.uuid4()) + _litellm_params["metadata"]["trace_id"] = trace_id + + # Log hanging request as an error on langfuse + if type == "hanging_request": + if self.langfuse_logger is not None: + _logging_kwargs = copy.deepcopy(request_data) + if _logging_kwargs is None: + _logging_kwargs = {} + _logging_kwargs["litellm_params"] = {} + request_data = request_data or {} + _logging_kwargs["litellm_params"]["metadata"] = request_data.get( + "metadata", {} + ) + # log to langfuse in a separate thread + import threading + + threading.Thread( + target=self.langfuse_logger.log_event, + args=( + _logging_kwargs, + None, + start_time, + end_time, + None, + print, + "ERROR", + "Requests is hanging", + ), + ).start() + + _langfuse_host = os.environ.get("LANGFUSE_HOST", "https://cloud.langfuse.com") + _langfuse_project_id = os.environ.get("LANGFUSE_PROJECT_ID") + + # langfuse urls look like: https://us.cloud.langfuse.com/project/************/traces/litellm-alert-trace-ididi9dk-09292-************ + + _langfuse_url = ( + f"{_langfuse_host}/project/{_langfuse_project_id}/traces/{trace_id}" + ) + request_info += f"\n🪢 Langfuse Trace: {_langfuse_url}" return request_info - # if request_data is not None: - # trace_id = request_data.get("metadata", {}).get( - # "trace_id", None - # ) # get langfuse trace id - # if trace_id is None: - # trace_id = "litellm-alert-trace-" + str(uuid.uuid4()) - # request_data["metadata"]["trace_id"] = trace_id - # elif kwargs is not None: - # _litellm_params = kwargs.get("litellm_params", {}) - # trace_id = _litellm_params.get("metadata", {}).get( - # "trace_id", None - # ) # get langfuse trace id - # if trace_id is None: - # trace_id = "litellm-alert-trace-" + str(uuid.uuid4()) - # _litellm_params["metadata"]["trace_id"] = trace_id - - # _langfuse_host = os.environ.get("LANGFUSE_HOST", "https://cloud.langfuse.com") - # _langfuse_project_id = os.environ.get("LANGFUSE_PROJECT_ID") - - # # langfuse urls look like: https://us.cloud.langfuse.com/project/************/traces/litellm-alert-trace-ididi9dk-09292-************ - - # _langfuse_url = ( - # f"{_langfuse_host}/project/{_langfuse_project_id}/traces/{trace_id}" - # ) - # request_info += f"\n🪢 Langfuse Trace: {_langfuse_url}" - # return request_info - def _response_taking_too_long_callback( self, kwargs, # kwargs to completion @@ -167,6 +209,14 @@ class SlackAlerting: _deployment_latencies = metadata["_latency_per_deployment"] if len(_deployment_latencies) == 0: return None + try: + # try sorting deployments by latency + _deployment_latencies = sorted( + _deployment_latencies.items(), key=lambda x: x[1] + ) + _deployment_latencies = dict(_deployment_latencies) + except: + pass for api_base, latency in _deployment_latencies.items(): _message_to_send += f"\n{api_base}: {round(latency,2)}s" _message_to_send = "```" + _message_to_send + "```" @@ -194,7 +244,7 @@ class SlackAlerting: if time_difference_float > self.alerting_threshold: if "langfuse" in litellm.success_callback: request_info = self._add_langfuse_trace_id_to_alert( - request_info=request_info, kwargs=kwargs + request_info=request_info, kwargs=kwargs, type="slow_response" ) # add deployment latencies to alert if ( @@ -222,8 +272,8 @@ class SlackAlerting: async def response_taking_too_long( self, - start_time: Optional[float] = None, - end_time: Optional[float] = None, + start_time: Optional[datetime.datetime] = None, + end_time: Optional[datetime.datetime] = None, type: Literal["hanging_request", "slow_response"] = "hanging_request", request_data: Optional[dict] = None, ): @@ -243,10 +293,6 @@ class SlackAlerting: except: messages = "" request_info = f"\nRequest Model: `{model}`\nMessages: `{messages}`" - if "langfuse" in litellm.success_callback: - request_info = self._add_langfuse_trace_id_to_alert( - request_info=request_info, request_data=request_data - ) else: request_info = "" @@ -288,6 +334,15 @@ class SlackAlerting: f"`Requests are hanging - {self.alerting_threshold}s+ request time`" ) + if "langfuse" in litellm.success_callback: + request_info = self._add_langfuse_trace_id_to_alert( + request_info=request_info, + request_data=request_data, + type="hanging_request", + start_time=start_time, + end_time=end_time, + ) + # add deployment latencies to alert _deployment_latency_map = self._get_deployment_latencies_to_alert( metadata=request_data.get("metadata", {}) diff --git a/litellm/proxy/_experimental/out/404.html b/litellm/proxy/_experimental/out/404.html index 310a90e22..6d3d33c80 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 Dashboard

404

This page could not be found.

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

404

This page could not be found.

\ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-508c39694bd40fe9.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-508c39694bd40fe9.js new file mode 100644 index 000000000..290d55662 --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-508c39694bd40fe9.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{20661:function(e,l,t){Promise.resolve().then(t.bind(t,27125))},27125:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return lf}});var s,a,r=t(3827),n=t(64090),o=t(47907),i=t(8792),c=t(40491),d=t(65270),m=e=>{let{userID:l,userRole:t,userEmail:s,showSSOBanner:a}=e;console.log("User ID:",l),console.log("userEmail:",s),console.log("showSSOBanner:",a);let n=[{key:"1",label:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("p",{children:["Role: ",t]}),(0,r.jsxs)("p",{children:["ID: ",l]})]})}];return(0,r.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,r.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,r.jsx)("div",{className:"flex flex-col items-center",children:(0,r.jsx)(i.default,{href:"/",children:(0,r.jsx)("button",{className:"text-gray-800 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:160,height:160,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,r.jsxs)("div",{className:"text-right mx-4 my-2 absolute top-0 right-0 flex items-center justify-end space-x-2",children:[a?(0,r.jsx)("div",{style:{padding:"6px",borderRadius:"8px"},children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",style:{fontSize:"14px",textDecoration:"underline"},children:"Request hosted proxy"})}):null,(0,r.jsx)("div",{style:{border:"1px solid #391085",padding:"6px",borderRadius:"8px"},children:(0,r.jsx)(c.Z,{menu:{items:n},children:(0,r.jsx)(d.Z,{children:s})})})]})]})},h=t(80588);let u=async()=>{try{let e=await fetch("https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"),l=await e.json();return console.log("received data: ".concat(l)),l}catch(e){throw console.error("Failed to get model cost map:",e),e}},x=async(e,l)=>{try{let t=await fetch("/model/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model created successfully. Wait 60s and refresh on 'All Models' page"),s}catch(e){throw console.error("Failed to create key:",e),e}},p=async(e,l)=>{console.log("model_id in model delete call: ".concat(l));try{let t=await fetch("/model/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model deleted successfully. Restart server to see this."),s}catch(e){throw console.error("Failed to create key:",e),e}},j=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},g=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},f=async(e,l)=>{try{console.log("in keyDeleteCall:",l);let t=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},y=async(e,l)=>{try{console.log("in teamDeleteCall:",l);let t=await fetch("/team/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete team: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to delete key:",e),e}},Z=async function(e,l,t){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0;try{let n="/user/info";"App Owner"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),"App User"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),console.log("in userInfoCall viewAll=",s),s&&r&&null!=a&&void 0!=a&&(n="".concat(n,"?view_all=true&page=").concat(a,"&page_size=").concat(r));let o=await fetch(n,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let i=await o.json();return console.log("API Response:",i),i}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,l)=>{try{let t="/team/info";l&&(t="".concat(t,"?team_id=").concat(l)),console.log("in teamInfoCall");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 h.ZP.error(e,20),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}},b=async e=>{try{let l=await fetch("/global/spend",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},_=async(e,l,t)=>{try{let l=await fetch("/v2/model/info",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log("modelInfoCall:",t),t}catch(e){throw console.error("Failed to create key:",e),e}},k=async(e,l,t,s)=>{try{let l="/model/metrics";s&&(l="".concat(l,"?_selected_model_group=").concat(s));let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},v=async(e,l,t)=>{try{let l=await fetch("/models",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},S=async(e,l)=>{try{let t="/global/spend/logs";console.log("in keySpendLogsCall:",t);let s=await fetch("".concat(t,"?api_key=").concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},A=async e=>{try{let l="/global/spend/teams";console.log("in teamSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},N=async e=>{try{let l="/global/spend/tags";console.log("in tagsSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},C=async(e,l,t,s,a,r)=>{try{console.log("user role in spend logs call: ".concat(t));let l="/spend/logs";l="App Owner"==t?"".concat(l,"?user_id=").concat(s,"&start_date=").concat(a,"&end_date=").concat(r):"".concat(l,"?start_date=").concat(a,"&end_date=").concat(r);let n=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.text();throw h.ZP.error(e,20),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}},I=async e=>{try{let l=await fetch("/global/spend/logs",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},P=async e=>{try{let l=await fetch("/global/spend/keys?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},T=async(e,l)=>{try{l&&JSON.stringify({api_key:l});let t={method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}};l&&(t.body=JSON.stringify({api_key:l}));let s=await fetch("/global/spend/end_users",t);if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},E=async e=>{try{let l=await fetch("/global/spend/models?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},F=async(e,l)=>{try{let t=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},O=async e=>{try{let l="/user/get_requests";console.log("in userGetRequesedtModelsCall:",l);let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to get requested models:",e),e}},M=async(e,l)=>{try{let t="/user/get_users?role=".concat(l);console.log("in userGetAllUsersCall:",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 h.ZP.error("Failed to delete key: "+e,20),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}},R=async(e,l)=>{try{console.log("Form Values in teamCreateCall:",l);let t=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},L=async(e,l)=>{try{console.log("Form Values in keyUpdateCall:",l);let t=await fetch("/key/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update key Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},U=async(e,l)=>{try{console.log("Form Values in teamUpateCall:",l);let t=await fetch("/team/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update team: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update Team Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},D=async(e,l)=>{try{console.log("Form Values in modelUpateCall:",l);let t=await fetch("/model/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update model: "+e,20),console.error("Error update from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update model Response:",s),s}catch(e){throw console.error("Failed to update model:",e),e}},z=async(e,l,t)=>{try{console.log("Form Values in teamMemberAddCall:",t);let s=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:l,member:t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},B=async(e,l,t)=>{try{console.log("Form Values in userUpdateUserCall:",l);let s={...l};null!==t&&(s.user_role=t),s=JSON.stringify(s);let a=await fetch("/user/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:s});if(!a.ok){let e=await a.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},q=async(e,l)=>{try{let t=await fetch("/global/predict/spend/logs",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},K=async(e,l)=>{try{let t="/health/services?service=".concat(l);console.log("Checking Slack Budget Alerts service health");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 h.ZP.error("Failed ".concat(l," service health check ")+e),Error(e)}let a=await s.json();return h.ZP.success("Test request to ".concat(l," made - check logs/alerts on ").concat(l," to verify")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},V=async(e,l,t)=>{try{let l=await fetch("/get/config/callbacks",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},G=async(e,l)=>{try{let t=await fetch("/config/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},W=async e=>{try{let l=await fetch("/health",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to call /health:",e),e}};var J=t(10384),Y=t(46453),H=t(2179),$=t(52273),X=t(26780),Q=t(15595),ee=t(6698),el=t(71801),et=t(42440),es=t(42308),ea=t(50670),er=t(81583),en=t(99129),eo=t(44839),ei=t(88707),ec=t(1861);let{Option:ed}=ea.default;var em=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=er.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[f,y]=(0,n.useState)([]),[Z,w]=(0,n.useState)([]),b=()=>{m(!1),c.resetFields()},_=()=>{m(!1),x(null),c.resetFields()};(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===s)return;if(null!==a){let e=(await v(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),y(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let k=async e=>{try{h.ZP.info("Making API Call"),m(!0);let t=await j(a,l,e);console.log("key create Response:",t),i(e=>e?[...e,t]:[t]),x(t.key),g(t.soft_budget),h.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the key:",e)}};return(0,n.useEffect)(()=>{w(t&&t.models.length>0?t.models.includes("all-proxy-models")?f:t.models:f)},[t,f]),(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(en.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:b,onCancel:_,children:(0,r.jsxs)(er.Z,{form:c,onFinish:k,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",hidden:!0,initialValue:t?t.team_id:null,valuePropName:"team_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),Z.map(e=>(0,r.jsx)(ed,{value:e,children:e},e))]})}),(0,r.jsxs)(X.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Q.Z,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==t?void 0:t.max_budget)!==null&&(null==t?void 0:t.max_budget)!==void 0?null==t?void 0:t.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.max_budget&&l>t.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(t.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Team Reset Budget: ".concat((null==t?void 0:t.budget_duration)!==null&&(null==t?void 0:t.budget_duration)!==void 0?null==t?void 0:t.budget_duration:"None"),children:(0,r.jsxs)(ea.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(ea.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(ea.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Tokens per minute Limit (TPM)",name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==t?void 0:t.tpm_limit)!==null&&(null==t?void 0:t.tpm_limit)!==void 0?null==t?void 0:t.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.tpm_limit&&l>t.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(t.tpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Requests per minute Limit (RPM)",name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==t?void 0:t.rpm_limit)!==null&&(null==t?void 0:t.rpm_limit)!==void 0?null==t?void 0:t.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.rpm_limit&&l>t.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(t.rpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(en.Z,{visible:d,onOk:b,onCancel:_,footer:null,children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Save your Key"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(el.Z,{className:"mt-3",children:"API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:u})}),(0,r.jsx)(es.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(H.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(el.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=t(9454),eu=t(98941),ex=t(33393),ep=t(5),ej=t(9853),eg=t(13810),ef=t(39290),ey=t(66952),eZ=t(61244),ew=t(10827),eb=t(3851),e_=t(2044),ek=t(64167),ev=t(74480),eS=t(7178),eA=t(95093),eN=t(27166);let{Option:eC}=ea.default;var eI=e=>{let{userID:l,userRole:t,accessToken:s,selectedTeam:a,data:o,setData:i,teams:c}=e,[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(!1),[p,j]=(0,n.useState)(null),[g,y]=n.useState(null),[Z,w]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),[k,A]=(0,n.useState)(""),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),F=new Set,[O,M]=(0,n.useState)(F);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),E(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,l,t]),(0,n.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,t)=>{let s=l.team_id;e.add(s)}),M(e)}},[c]);let R=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),C(!0)},U=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await L(s,e);console.log("handleEditSubmit: newKeyValues",t),o&&i(o.map(e=>e.token===l?t:e)),h.ZP.success("Key updated successfully"),C(!1),P(null)},D=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await S(s,e.token);console.log("Response:",l),_(l);try{let e=await q(s,l);console.log("Response2:",e);let t=[...l,...e.response];_(t),A(e.predicted_spend),console.log("Combined Data:",t)}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,n.useEffect)(()=>{D(Z)},[Z]);let z=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"+l),x(!0))},B=async()=>{if(null!=p&&null!=o){try{await f(s,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,r.jsxs)("div",{children:[(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ew.Z,{className:"mt-5 max-h-[300px] min-h-[300px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Key Alias"}),(0,r.jsx)(ev.Z,{children:"Secret Key"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eb.Z,{children:o.map(e=>{if(console.log(e),"litellm-dashboard"===e.team_id)return null;if(a){if(console.log("item team id: ".concat(e.team_id,", knownTeamIDs.has(item.team_id): ").concat(O.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||O.has(e.team_id))&&e.team_id!=a.team_id)return null;console.log("item team id: ".concat(e.team_id,", is returned"))}return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(el.Z,{children:e.key_alias}):(0,r.jsx)(el.Z,{children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.key_name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(e_.Z,{children:null!=e.max_budget?(0,r.jsx)(el.Z,{children:e.max_budget}):(0,r.jsx)(el.Z,{children:"Unlimited"})}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(r.Fragment,{children:a&&a.models&&a.models.length>0?a.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(el.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{})," RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{onClick:()=>{w(e),y(e.id)},icon:eh.Z,size:"sm"}),(0,r.jsx)(ef.Z,{open:null!==g,onClose:()=>{y(null),w(null)},children:(0,r.jsx)(ey.Z,{children:Z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:[(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Spend"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:(()=>{try{return parseFloat(Z.spend).toFixed(4)}catch(e){return Z.spend}})()})})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Budget"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.max_budget?(0,r.jsx)(r.Fragment,{children:Z.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Expires"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-default font-small text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.expires?(0,r.jsx)(r.Fragment,{children:new Date(Z.expires).toLocaleString(void 0,{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}):(0,r.jsx)(r.Fragment,{children:"Never"})})})]},e.name)]}),(0,r.jsx)(eg.Z,{className:"mt-6 mb-6",children:b&&(0,r.jsx)(ej.Z,{className:"mt-6",data:b,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(et.Z,{children:"Metadata"}),(0,r.jsx)(el.Z,{children:JSON.stringify(Z.metadata)}),(0,r.jsx)(H.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{y(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>R(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>z(e),icon:ex.Z,size:"sm"})]})]},e.token)})})]}),u&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:B,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),I&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=er.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(en.Z,{title:"Edit Key",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:i,onFinish:U,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{validator:(e,l)=>{let t=l.filter(e=>!d.models.includes(e)&&"all-team-models"!==e&&"all-proxy-models"!==e&&!d.models.includes("all-proxy-models"));return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t,"Team models: ").concat(d.models)):Promise.resolve()}}],children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eC,{value:"all-team-models",children:"All Team Models"},"all-team-models"),d&&d.models?d.models.includes("all-proxy-models")?T.filter(e=>"all-proxy-models"!==e).map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(eC,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: ".concat((null==d?void 0:d.max_budget)!==null&&(null==d?void 0:d.max_budget)!==void 0?null==d?void 0:d.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&d&&null!==d.max_budget&&l>d.max_budget)throw console.log("keyTeam.max_budget: ".concat(d.max_budget)),Error("Budget cannot exceed team max budget: $".concat(d.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(er.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(eA.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(eN.Z,{value:e.team_id,onClick:()=>m(e),children:e.team_alias},l))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{C(!1),P(null)},token:I,onSubmit:U})]})},eP=t(76032),eT=t(35152),eE=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[i,c]=(0,n.useState)(null!==a?a:0),[d,m]=(0,n.useState)(0),[h,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{let e=async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await b(s);e&&(e.spend?c(e.spend):c(0),e.max_budget?m(e.max_budget):m(0))}catch(e){console.error("Error fetching global spend data:",e)}};(async()=>{try{if(null===l||null===t)return;if(null!==s){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),u(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,s,l]),(0,n.useEffect)(()=>{null!==a&&c(a)},[a]);let x=[];o&&o.models&&(x=o.models),x&&x.includes("all-proxy-models")?(console.log("user models:",h),x=h):x&&x.includes("all-team-models")?x=o.models:x&&0===x.length&&(x=h);let p=void 0!==i?i.toFixed(4):null;return console.log("spend in view user spend: ".concat(i)),(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:["Total Spend"," "]}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",p]})]}),(0,r.jsx)("div",{className:"ml-auto",children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Team Models"})}),(0,r.jsx)(Q.Z,{className:"absolute right-0 z-10 bg-white p-2 shadow-lg max-w-xs",children:(0,r.jsx)(eP.Z,{children:x.map(e=>(0,r.jsx)(eT.Z,{children:(0,r.jsx)(el.Z,{children:e})},e))})})]})})]})},eF=e=>{let{userID:l,userRole:t,selectedTeam:s,accessToken:a}=e,[o,i]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===t)return;if(null!==a){let e=(await v(a,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),i(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,t]);let c=[];return s&&s.models&&(c=s.models),c&&c.includes("all-proxy-models")&&(console.log("user models:",o),c=o),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"mb-5",children:(0,r.jsx)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null==s?void 0:s.team_alias})})})},eO=e=>{let l,{teams:t,setSelectedTeam:s,userRole:a}=e,o={models:[],team_id:null,team_alias:"Default Team"},[i,c]=(0,n.useState)(o);return(l="App User"===a?t:t?[...t,o]:[o],"App User"===a)?null:(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(et.Z,{children:"Select Team"}),(0,r.jsx)(el.Z,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),(0,r.jsxs)(el.Z,{className:"mt-3 mb-3",children:[(0,r.jsx)("b",{children:"Default Team:"})," If no team_id is set for a key, it will be grouped under here."]}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>s(e),children:e.team_alias},l))}):(0,r.jsxs)(el.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eM=t(37963),eR=t(36083);console.log("isLocal:",!1);var eL=e=>{let{userID:l,userRole:t,teams:s,keys:a,setUserRole:i,userEmail:c,setUserEmail:d,setTeams:m,setKeys:h}=e,[u,x]=(0,n.useState)(null),p=(0,o.useSearchParams)();p.get("viewSpend"),(0,o.useRouter)();let j=p.get("token"),[g,f]=(0,n.useState)(null),[y,w]=(0,n.useState)(null),[_,k]=(0,n.useState)([]),S={models:[],team_alias:"Default Team",team_id:null},[A,N]=(0,n.useState)(s?s[0]:S);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eM.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),f(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),i(l)}else console.log("User role not defined");e.user_email?d(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&g&&t&&!a&&!u){let e=sessionStorage.getItem("userModels"+l);e?k(JSON.parse(e)):(async()=>{try{let e=await Z(g,l,t,!1,null,null);if(console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),"Admin"==t){let e=await b(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams);let s=[...e.teams];s.length>0?(console.log("response['teams']: ".concat(s)),N(s[0])):N(S),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let a=(await v(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",a),k(a),console.log("userModels:",_),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=A){let e=0;for(let l of a)A.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===A.team_id&&(e+=l.spend);w(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;w(e)}},[A]),null==l||null==j){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==g)return null;if(null==t&&i("App Owner"),t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",A),console.log("teamSpend: ".concat(y)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eF,{userID:l,userRole:t,selectedTeam:A||null,accessToken:g}),(0,r.jsx)(eE,{userID:l,userRole:t,accessToken:g,userSpend:y,selectedTeam:A||null}),(0,r.jsx)(eI,{userID:l,userRole:t,accessToken:g,selectedTeam:A||null,data:a,setData:h,teams:s}),(0,r.jsx)(em,{userID:l,team:A||null,userRole:t,accessToken:g,data:a,setData:h},A?A.team_id:null),(0,r.jsx)(eO,{teams:s,setSelectedTeam:N,userRole:t})]})})})},eU=t(92836),eD=t(26734),ez=t(41608),eB=t(32126),eq=t(23682),eK=t(47047),eV=t(76628),eG=t(38302),eW=t(28683),eJ=t(1460),eY=t(78578),eH=t(63954),e$=e=>{let{modelID:l,accessToken:t}=e,[s,a]=(0,n.useState)(!1),o=async()=>{try{h.ZP.info("Making API Call"),a(!0);let e=await p(t,l);console.log("model delete Response:",e),h.ZP.success("Model ".concat(l," deleted successfully")),a(!1)}catch(e){console.error("Error deleting the model:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eZ.Z,{onClick:()=>a(!0),icon:ex.Z,size:"sm"}),(0,r.jsx)(en.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Delete Model"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)("p",{children:"Are you sure you want to delete this model? This action is irreversible."})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eX=t(97766),eQ=t(46495);let{Title:e0,Link:e1}=eR.default;(s=a||(a={})).OpenAI="OpenAI",s.Azure="Azure",s.Anthropic="Anthropic",s.Google_AI_Studio="Gemini (Google AI Studio)",s.Bedrock="Amazon Bedrock",s.OpenAI_Compatible="OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)",s.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)";let e2={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"},e4=async(e,l,t)=>{try{let s=Array.isArray(e.model)?e.model:[e.model];console.log("received deployments: ".concat(s)),console.log("received type of deployments: ".concat(typeof s)),s.forEach(async t=>{console.log("litellm_model: ".concat(t));let s={},a={};s.model=t;let r="";for(let[l,t]of Object.entries(e))if(""!==t){if("model_name"==l)r+=t;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)a[l]=t;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",t);let e={};if(t&&void 0!=t){try{e=JSON.parse(t)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else s[l]=t}let n={model_name:r,litellm_params:s,model_info:a},o=await x(l,n);console.log("response for model create call: ".concat(o.data))}),t.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};var e8=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d,modelData:m={data:[]},setModelData:x}=e,[p,j]=(0,n.useState)([]),[g]=er.Z.useForm(),[f,y]=(0,n.useState)(null),[Z,w]=(0,n.useState)(""),[b,k]=(0,n.useState)([]),v=Object.values(a).filter(e=>isNaN(Number(e))),[S,A]=(0,n.useState)("OpenAI"),[N,C]=(0,n.useState)(""),[I,P]=(0,n.useState)(!1),[T,E]=(0,n.useState)(null),[F,M]=(0,n.useState)([]),[R,L]=(0,n.useState)(null),U=e=>{E(e),P(!0)},z=async e=>{if(console.log("handleEditSubmit:",e),null==o)return;let l={},t=null;for(let[s,a]of Object.entries(e))"model_id"!==s?l[s]=a:t=a;let s={litellm_params:l,model_info:{id:t}};console.log("handleEditSubmit payload:",s),await D(o,s),h.ZP.success("Model updated successfully, restart server to see updates"),P(!1),E(null)},B=()=>{w(new Date().toLocaleString())};if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await _(o,d,c);console.log("Model data response:",e.data),x(e);let l=new Set;for(let t=0;t{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),y(e)};null==f&&l(),B()},[o,i,c,d,f,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let q=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(f)),null!=f&&"object"==typeof f&&e in f)?f[e].litellm_provider:"openai";if(a){let e=a.split("/"),l=e[0];n=1===e.length?h(a):l}else n="openai";r&&(o=null==r?void 0:r.input_cost_per_token,i=null==r?void 0:r.output_cost_per_token,c=null==r?void 0:r.max_tokens),(null==s?void 0:s.litellm_params)&&(d=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),m.data[e].provider=n,m.data[e].input_cost=o,m.data[e].output_cost=i,m.data[e].max_tokens=c,m.data[e].api_base=null==s?void 0:null===(t=s.litellm_params)||void 0===t?void 0:t.api_base,m.data[e].cleanedLitellmParams=d,q.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to view all models"})]})}let K=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=e2[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof f&&Object.entries(f).forEach(l=>{let[s,a]=l;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===e||a.litellm_provider.includes(e))&&t.push(s)}),k(t),console.log("providerModels: ".concat(b))}},V=async()=>{try{h.ZP.info("Running health check..."),C("");let e=await W(o);C(e)}catch(e){console.error("Error running health check:",e),C("Error running health check")}};return console.log("selectedProvider: ".concat(S)),console.log("providerModels.length: ".concat(b.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eU.Z,{children:"All Models"}),(0,r.jsx)(eU.Z,{children:"Add Model"}),(0,r.jsx)(eU.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[Z&&(0,r.jsxs)(el.Z,{children:["Last Refreshed: ",Z]}),(0,r.jsx)(eZ.Z,{icon:eH.Z,variant:"shadow",size:"xs",className:"self-center",onClick:B})]})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(Y.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:"all",onValueChange:e=>L("all"===e?"all":e),children:[(0,r.jsx)(eN.Z,{value:"all",children:"All Models"}),F.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>L(e),children:e},l))]})]}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Public Model Name "}),(0,r.jsx)(ev.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(ev.Z,{children:"API Base"}),(0,r.jsx)(ev.Z,{children:"Extra litellm Params"}),(0,r.jsx)(ev.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(eb.Z,{children:m.data.filter(e=>"all"===R||e.model_name===R||null==R||""===R).map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.model_name})}),(0,r.jsx)(e_.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(e_.Z,{children:e.api_base}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Litellm params"})}),(0,r.jsx)(Q.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(e_.Z,{children:e.input_cost}),(0,r.jsx)(e_.Z,{children:e.output_cost}),(0,r.jsx)(e_.Z,{children:e.max_tokens}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>U(e)}),(0,r.jsx)(e$,{modelID:e.model_info.id,accessToken:o})]})]},l))})]})})]}),(0,r.jsx)(e=>{let{visible:l,onCancel:t,model:s,onSubmit:a}=e,[n]=er.Z.useForm(),o={},i="",c="";if(s){o=s.litellm_params,i=s.model_name;let e=s.model_info;e&&(c=e.id,console.log("model_id: ".concat(c)),o.model_id=c)}return(0,r.jsx)(en.Z,{title:"Edit Model "+i,visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a(e),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:z,initialValues:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)($.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})},{visible:I,onCancel:()=>{P(!1),E(null)},model:T,onSubmit:z})]}),(0,r.jsxs)(eB.Z,{className:"h-full",children:[(0,r.jsx)(e0,{level:2,children:"Add new model"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(er.Z,{form:g,onFinish:()=>{g.validateFields().then(e=>{e4(e,o,g)}).catch(e=>{console.error("Validation failed:",e)})},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:S.toString(),children:v.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>{K(e),A(e)},children:e},l))})}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Public Model Name",name:"model_name",tooltip:"Model name your users will pass in. Also used for load-balancing, LiteLLM will load balance between all models with this public name.",className:"mb-0",children:(0,r.jsx)($.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=S.toString())?"gemini-pro":"Anthropic"==s?"claude-3-opus":"Amazon Bedrock"==s?"claude-3-opus":"Gemini (Google AI Studio)"==s?"gemini-pro":"gpt-3.5-turbo"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"LiteLLM Model Name(s)",name:"model",tooltip:"Actual model name used for making litellm.completion() call.",className:"mb-0",children:"Azure"===S?(0,r.jsx)($.Z,{placeholder:"Enter model name"}):b.length>0?(0,r.jsx)(eK.Z,{value:b,children:b.map((e,l)=>(0,r.jsx)(eV.Z,{value:e,children:e},l))}):(0,r.jsx)($.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/proxy/reliability#step-1---set-deployments-on-config",target:"_blank",children:"loadbalance"})," models with the same 'public name'"]})})]}),"Amazon Bedrock"!=S&&"Vertex AI (Anthropic, Gemini, etc.)"!=S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)($.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==S&&(0,r.jsx)(er.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)($.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)($.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eQ.Z,{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;g.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?h.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&h.ZP.error("".concat(e.file.name," file upload failed."))},children:(0,r.jsx)(ec.ZP,{icon:(0,r.jsx)(eX.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==S||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==S)&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)($.Z,{placeholder:"https://..."})}),"Azure"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)($.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==S&&(0,r.jsxs)(er.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)($.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(el.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(e1,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Access Key ID",name:"aws_access_key_id",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Secret Access Key",name:"aws_secret_access_key",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Region Name",name:"aws_region_name",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(er.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-0",children:(0,r.jsx)(eY.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]})]}),(0,r.jsx)("div",{style:{textAlign:"center",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eJ.Z,{title:"Get help on our github",children:(0,r.jsx)(eR.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(el.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(H.Z,{onClick:V,children:"Run `/health`"}),N&&(0,r.jsx)("pre",{children:JSON.stringify(N,null,2)})]})})]})]})})};let{Option:e5}=ea.default;var e3=e=>{let{userID:l,accessToken:t,teams:s}=e,[a]=er.Z.useForm(),[o,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),[m,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await v(t,l,"any"),s=[];for(let l=0;l{i(!1),a.resetFields()},p=()=>{i(!1),d(null),a.resetFields()},j=async e=>{try{h.ZP.info("Making API Call"),i(!0),console.log("formValues in create user:",e);let s=await g(t,null,e);console.log("user create Response:",s),d(s.key),h.ZP.success("API user Created"),a.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Invite User"}),(0,r.jsxs)(en.Z,{title:"Invite User",visible:o,width:800,footer:null,onOk:x,onCancel:p,children:[(0,r.jsx)(el.Z,{className:"mb-1",children:"Invite a user to login to the Admin UI and create Keys"}),(0,r.jsx)(el.Z,{className:"mb-6",children:(0,r.jsx)("b",{children:"Note: SSO Setup Required for this"})}),(0,r.jsxs)(er.Z,{form:a,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(er.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(ea.default,{placeholder:"Select Team ID",style:{width:"100%"},children:s?s.map(e=>(0,r.jsx)(e5,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(e5,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create User"})})]})]}),c&&(0,r.jsxs)(en.Z,{title:"User Created Successfully",visible:o,onOk:x,onCancel:p,footer:null,children:[(0,r.jsx)("p",{children:"User has been created to access your proxy. Please Ask them to Log In."}),(0,r.jsx)("br",{}),(0,r.jsx)("p",{children:(0,r.jsx)("b",{children:"Note: This Feature is only supported through SSO on the Admin UI"})})]})]})},e6=e=>{let{accessToken:l,token:t,keys:s,userRole:a,userID:o,teams:i,setKeys:c}=e,[d,m]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(0),[j,g]=n.useState(null),[f,y]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await Z(l,null,a,!0,x,25);console.log("user data response:",e),m(e)}catch(e){console.error("There was an error fetching the model data",e)}};l&&t&&a&&o&&e();let s=async()=>{try{let e=await T(l,null);console.log("user data response:",e),u(e)}catch(e){console.error("There was an error fetching the model data",e)}};a&&("Admin"==a||"Admin Viewer"==a)&&!h&&s()},[l,t,a,o,x]),!d||!l||!t||!a||!o)return(0,r.jsx)("div",{children:"Loading..."});let w=async e=>{try{let t=await T(l,e);console.log("user data response:",t),u(t)}catch(e){console.error("There was an error fetching the model data",e)}};return(0,r.jsx)("div",{style:{width:"100%"},children:(0,r.jsxs)(Y.Z,{className:"gap-2 p-2 h-[80vh] w-full mt-8",children:[(0,r.jsx)(e3,{userID:o,accessToken:l,teams:i}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[80vh] mb-4",children:[(0,r.jsxs)("div",{className:"mb-4 mt-1",children:[(0,r.jsxs)(el.Z,{children:[(0,r.jsx)("b",{children:"Key Owners: "})," Users on LiteLLM that created API Keys. Automatically tracked by LiteLLM"]}),(0,r.jsxs)(el.Z,{className:"mt-1",children:[(0,r.jsx)("b",{children:"End Users: "}),"End Users of your LLM API calls. Tracked When a `user` param is passed in your LLM calls"]})]}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eU.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"User ID"}),(0,r.jsx)(ev.Z,{children:"User Email"}),(0,r.jsx)(ev.Z,{children:"User Models"}),(0,r.jsx)(ev.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(eb.Z,{children:d.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_id}),(0,r.jsx)(e_.Z,{children:e.user_email}),(0,r.jsx)(e_.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(e_.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(Y.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(ep.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(ep.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsxs)("div",{className:"flex-1 flex justify-between items-center",children:[(0,r.jsx)(el.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(eA.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_alias&&e.key_alias.length>0)return(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>w(e.token),children:e.key_alias},l)})})]})]}),(0,r.jsxs)(ew.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"End User"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Total Events"})]})}),(0,r.jsx)(eb.Z,{children:null==h?void 0:h.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:e.total_spend}),(0,r.jsx)(e_.Z,{children:e.total_events})]},l))})]})]})]})]})]}),function(){if(!d)return null;let e=Math.ceil(d.length/25);return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",x+1," of ",e]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l focus:outline-none",disabled:0===x,onClick:()=>p(x-1),children:"← Prev"}),(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r focus:outline-none",onClick:()=>{p(x+1)},children:"Next →"})]})]})}()]})})},e7=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=er.Z.useForm(),[d]=er.Z.useForm(),{Title:m,Paragraph:u}=eR.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[f,Z]=(0,n.useState)(l?l[0]:null),[b,_]=(0,n.useState)(!1),[k,S]=(0,n.useState)(!1),[A,N]=(0,n.useState)([]),[C,I]=(0,n.useState)(!1),[P,T]=(0,n.useState)(null),[E,F]=(0,n.useState)({}),O=e=>{Z(e),g(!0)},M=async e=>{let t=e.team_id;if(console.log("handleEditSubmit:",e),null==s)return;let r=await U(s,e);l&&a(l.map(e=>e.team_id===t?r.data:e)),h.ZP.success("Team updated successfully"),g(!1),Z(null)},L=async e=>{T(e),I(!0)},D=async()=>{if(null!=P&&null!=l&&null!=s){try{await y(s,P);let e=l.filter(e=>e.team_id!==P);a(e)}catch(e){console.error("Error deleting the team:",e)}I(!1),T(null)}};(0,n.useEffect)(()=>{let e=async()=>{try{if(null===o||null===i||null===s||null===l)return;console.log("fetching team info:");let e={};for(let t=0;t<(null==l?void 0:l.length);t++){let a=l[t].team_id,r=await w(s,a);console.log("teamInfo response:",r),null!==r&&(e={...e,[a]:r})}F(e)}catch(e){console.error("Error fetching team info:",e)}};(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await v(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),N(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,o,i,l]);let B=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await R(s,e);null!==l?a([...l,t]):a([t]),console.log("response for team create call: ".concat(t)),h.ZP.success("Team created"),_(!1)}}catch(e){console.error("Error creating the team:",e),h.ZP.error("Error creating the team: "+e,20)}},q=async e=>{try{if(null!=s&&null!=l){h.ZP.info("Adding Member");let t={role:"user",user_email:e.user_email,user_id:e.user_id},r=await z(s,f.team_id,t);console.log("response for team create call: ".concat(r.data));let n=l.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(r.data.team_id)),e.team_id===r.data.team_id));if(console.log("foundIndex: ".concat(n)),-1!==n){let e=[...l];e[n]=r.data,a(e),Z(r.data)}S(!1)}}catch(e){console.error("Error creating the team:",e)}};return console.log("received teams ".concat(l)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Team Name"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ev.Z,{children:"Info"})]})}),(0,r.jsx)(eb.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(el.Z,{children:["TPM:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{}),"RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].keys&&E[e.team_id].keys.length," Keys"]}),(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].team_info&&E[e.team_id].team_info.members_with_roles&&E[e.team_id].team_info.members_with_roles.length," Members"]})]}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>O(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>L(e.team_id),icon:ex.Z,size:"sm"})]})]},e.team_id)):null})]}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{I(!1),T(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>_(!0),children:"+ Create New Team"}),(0,r.jsx)(en.Z,{title:"Create Team",visible:b,width:800,footer:null,onOk:()=>{_(!1),c.resetFields()},onCancel:()=>{_(!1),c.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:B,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"Team Members"}),(0,r.jsx)(u,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>{Z(e)},children:e.team_alias},l))}):(0,r.jsxs)(u,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:f?f.members_with_roles.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.role})]},l)):null})]})}),f&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=er.Z.useForm();return(0,r.jsx)(en.Z,{title:"Edit Team",visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a({...e,team_id:s.team_id}),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:M,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A&&A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"team_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),Z(null)},team:f,onSubmit:M})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto mb-5",onClick:()=>S(!0),children:"+ Add member"}),(0,r.jsx)(en.Z,{title:"Add member",visible:k,width:800,footer:null,onOk:()=>{S(!1),d.resetFields()},onCancel:()=>{S(!1),d.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e9=t(18190),le=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=er.Z.useForm(),[i]=er.Z.useForm(),{Title:c,Paragraph:d}=eR.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[f,y]=(0,n.useState)(!1),[Z,w]=(0,n.useState)(!1),[b,_]=(0,n.useState)(!1),[k,v]=(0,n.useState)(!1);try{l=window.location.origin}catch(e){l=""}l+="/fallback/login";let S=()=>{v(!1)},A=["proxy_admin","proxy_admin_viewer"];(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await M(s,"proxy_admin_viewer");l.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(l));let t=await M(s,"proxy_admin");t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(t)),console.log("combinedList: ".concat(e)),p(e)}})()},[s]);let N=()=>{w(!1),i.resetFields()},C=()=>{w(!1),i.resetFields()},I=e=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,null);console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),h.ZP.success("Refresh tab to see updated user role"),w(!1)}}catch(e){console.error("Error creating the key:",e)}},E=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,"proxy_admin_viewer");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),g(!1)}}catch(e){console.error("Error creating the key:",e)}},F=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await B(s,e,"proxy_admin");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),y(!1)}}catch(e){console.error("Error creating the key:",e)}},O=async e=>{null!=s&&G(s,{environment_variables:{PROXY_BASE_URL:e.proxy_base_url,GOOGLE_CLIENT_ID:e.google_client_id,GOOGLE_CLIENT_SECRET:e.google_client_secret}})};return console.log("admins: ".concat(null==x?void 0:x.length)),(0,r.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,r.jsx)(c,{level:4,children:"Admin Access "}),(0,r.jsxs)(d,{children:[a&&(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access",children:"Requires SSO Setup"}),(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin: "})," Can create keys, teams, users, add models, etc. ",(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin Viewer: "}),"Can just view spend. They cannot create keys, teams or grant users access to new models."," "]}),(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.user_role}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(en.Z,{title:"Update role",visible:Z,width:800,footer:null,onOk:N,onCancel:C,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(H.Z,{className:"mr-4 mb-5",onClick:()=>y(!0),children:"+ Add admin"}),(0,r.jsx)(en.Z,{title:"Add admin",visible:f,width:800,footer:null,onOk:()=>{y(!1),i.resetFields()},onCancel:()=>{y(!1),i.resetFields()},children:I(F)}),(0,r.jsx)(H.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(en.Z,{title:"Add viewer",visible:j,width:800,footer:null,onOk:()=>{g(!1),i.resetFields()},onCancel:()=>{g(!1),i.resetFields()},children:I(E)})]})})]}),(0,r.jsxs)(Y.Z,{children:[(0,r.jsx)(c,{level:4,children:"Add SSO"}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(H.Z,{onClick:()=>_(!0),children:"Add SSO"}),(0,r.jsx)(en.Z,{title:"Add SSO",visible:b,width:800,footer:null,onOk:()=>{_(!1),o.resetFields()},onCancel:()=>{_(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{F(e),O(e),_(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(eo.Z.Password,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(eo.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(en.Z,{title:"SSO Setup Instructions",visible:k,width:800,footer:null,onOk:S,onCancel:()=>{v(!1)},children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e9.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access ",(0,r.jsxs)("a",{href:l,target:"_blank",children:[(0,r.jsx)("b",{children:l})," "]})]})]})]})},ll=t(12224),lt=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)(!1),[u]=er.Z.useForm(),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)(""),[Z,w]=(0,n.useState)({}),[b,_]=(0,n.useState)([]),k=e=>{b.includes(e)?_(b.filter(l=>l!==e)):_([...b,e])},v={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),o(e.callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let t=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",t),_(e.active_alerts),y(t),w(e.alerts_to_webhook)}c(l)})},[l,t,s]);let S=e=>b&&b.includes(e),A=e=>{if(!l)return;let t=Object.fromEntries(Object.entries(e.variables).map(e=>{var l;let[t,s]=e;return[t,(null===(l=document.querySelector('input[name="'.concat(t,'"]')))||void 0===l?void 0:l.value)||s]}));console.log("updatedVariables",t),console.log("updateAlertTypes",j);try{G(l,{environment_variables:t})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},N=()=>{l&&u.validateFields().then(e=>{if(console.log("Form values:",e),"langfuse"===e.callback){G(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}});let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:null,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey}};o(a?[...a,t]:[t])}else if("slack"===e.callback){console.log("values.slackWebhookUrl: ".concat(e.slackWebhookUrl)),G(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),console.log("values.callback: ".concat(e.callback));let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:null,LANGFUSE_SECRET_KEY:null}};o(a?[...a,t]:[t])}m(!1),u.resetFields(),p(null)})};return l?(console.log("callbacks: ".concat(a)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eU.Z,{value:"2",children:"Alerting"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Callback"}),(0,r.jsx)(ev.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(eb.Z,{children:a.map((e,t)=>{var s;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ep.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).filter(e=>{let[l,t]=e;return null!==t}).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(el.Z,{className:"mt-2",children:l}),"LANGFUSE_HOST"===l?(0,r.jsx)("p",{children:"default value=https://cloud.langfuse.com"}):(0,r.jsx)("div",{}),(0,r.jsx)($.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>A(e),children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),m(!0)},children:"Add Callback"})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(el.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(v).map((e,l)=>{let[t,s]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ll.Z,{id:"switch",name:"switch",checked:S(t),onChange:()=>k(t)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:s})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:t,type:"password",defaultValue:Z&&Z[t]?Z[t]:f})})]},l)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(v).forEach(l=>{let[t,s]=l,a=document.querySelector('input[name="'.concat(t,'"]'));console.log("key",t),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[t]=r}),console.log("updatedAlertToWebhooks",e);let t={general_settings:{alert_to_webhook_url:e,alert_types:b}};console.log("payload",t);try{G(l,t)}catch(e){h.ZP.error("Failed to update alerts: "+e,20)}h.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,"slack"),className:"mx-2",children:"Test Alerts"})]})})]})]})}),(0,r.jsx)(en.Z,{title:"Add Callback",visible:d,onOk:N,width:800,onCancel:()=>{m(!1),u.resetFields(),p(null)},footer:null,children:(0,r.jsxs)(er.Z,{form:u,layout:"vertical",onFinish:N,children:[(0,r.jsx)(er.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(ea.default,{onChange:e=>{p(e)},children:(0,r.jsx)(ea.default.Option,{value:"langfuse",children:"langfuse"})})}),"langfuse"===x&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)($.Z,{type:"password"})}),(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)($.Z,{type:"password"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null};let{Option:ls}=ea.default;var la=e=>{let{models:l,accessToken:t,routerSettings:s,setRouterSettings:a}=e,[o]=er.Z.useForm(),[i,c]=(0,n.useState)(!1),[d,m]=(0,n.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(en.Z,{title:"Add Fallbacks",visible:i,width:800,footer:null,onOk:()=>{c(!1),o.resetFields()},onCancel:()=>{c(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,n=[...s.fallbacks||[],{[l]:r}],i={...s,fallbacks:n};console.log(i);try{G(t,{router_settings:i}),a(i)}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully"),c(!1),o.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eA.Z,{defaultValue:d,children:l&&l.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(eK.Z,{value:l,children:l&&l.filter(e=>e!=d).map(e=>(0,r.jsx)(eV.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lr=t(12968);async function ln(e,l){console.log("isLocal:",!1);let t=window.location.origin,s=new lr.ZP.OpenAI({apiKey:l,baseURL:t,dangerouslyAllowBrowser:!0});try{let l=await s.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});h.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lo=e=>{let{accessToken:l,userRole:t,userID:s,modelData:a}=e,[o,i]=(0,n.useState)({}),[c,d]=(0,n.useState)(!1),[m]=er.Z.useForm(),[u,x]=(0,n.useState)(null),p={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),i(e.router_settings)})},[l,t,s]);let j=async e=>{if(l){console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(o.fallbacks)),o.fallbacks.map(l=>(e in l&&delete l[e],l));try{await G(l,{router_settings:o}),i({...o}),h.ZP.success("Router settings updated successfully")}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}}},g=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).map(e=>{let[l,t]=e;if("routing_strategy_args"!==l){var s;return[l,(null===(s=document.querySelector('input[name="'.concat(l,'"]')))||void 0===s?void 0:s.value)||t]}return null}).filter(e=>null!==e));console.log("updatedVariables",t);try{G(l,{router_settings:t})}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"General Settings"}),(0,r.jsx)(eU.Z,{value:"2",children:"Fallbacks"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(et.Z,{children:"Router Settings"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Setting"}),(0,r.jsx)(ev.Z,{children:"Value"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(o).filter(e=>{let[l,t]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l}).map(e=>{let[l,t]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(el.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:p[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(J.Z,{children:(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>g(o),children:"Save Changes"})})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Model Name"}),(0,r.jsx)(ev.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(eb.Z,{children:o.fallbacks&&o.fallbacks.map((e,t)=>Object.entries(e).map(e=>{let[s,a]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:s}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(H.Z,{onClick:()=>ln(s,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(eZ.Z,{icon:ex.Z,size:"sm",onClick:()=>j(s)})})]},t.toString()+s)}))})]}),(0,r.jsx)(la,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:o,setRouterSettings:i})]})]})]})}):null},li=t(67951),lc=e=>{let{}=e;return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(el.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eU.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eU.Z,{children:"LlamaIndex"}),(0,r.jsx)(eU.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n '})}),(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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:4000",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})]})})})};async function ld(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new lr.ZP.OpenAI({apiKey:s,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let s of(await r.chat.completions.create({model:t,stream:!0,messages:[{role:"user",content:e}]})))console.log(s),s.choices[0].delta.content&&l(s.choices[0].delta.content)}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lm=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,[o,i]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[m,h]=(0,n.useState)([]),[u,x]=(0,n.useState)(void 0),[p,j]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{let e=await v(l,a,s);if(console.log("model_info:",e),(null==e?void 0:e.data.length)>0){let l=e.data.map(e=>({value:e.id,label:e.id}));console.log(l),j(l),x(e.data[0].id)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,s]);let g=(e,l)=>{h(t=>{let s=t[t.length-1];return s&&s.role===e?[...t.slice(0,t.length-1),{role:e,content:s.content+l}]:[...t,{role:e,content:l}]})},f=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await ld(c,e=>g("assistant",e),u,o)}catch(e){console.error("Error fetching model response",e),g("assistant","Error fetching model response")}d("")}};if(s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsx)(ez.Z,{children:(0,r.jsx)(eU.Z,{children:"Chat"})}),(0,r.jsx)(eq.Z,{children:(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(Y.Z,{numItems:2,children:[(0,r.jsxs)(J.Z,{children:[(0,r.jsx)(el.Z,{children:"API Key"}),(0,r.jsx)($.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(J.Z,{className:"mx-2",children:[(0,r.jsx)(el.Z,{children:"Select Model:"}),(0,r.jsx)(ea.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ew.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ek.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsx)(eb.Z,{children:m.map((e,l)=>(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{children:"".concat(e.role,": ").concat(e.content)})},l))})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)($.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(H.Z,{onClick:f,className:"ml-2",children:"Send"})]})})]})})]})})})})},lh=t(33509),lu=t(95781);let{Sider:lx}=lh.default;var lp=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lx,{width:120,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"145px"},children:(0,r.jsx)(lx,{width:145,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(el.Z,{children:"API Keys"})},"1"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(el.Z,{children:"Test Key"})},"3"),"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(el.Z,{children:"Models"})},"2"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(el.Z,{children:"Usage"})},"4"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(el.Z,{children:"Teams"})},"6"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(el.Z,{children:"Users"})},"5"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(el.Z,{children:"Logging & Alerts"})},"8"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(el.Z,{children:"Router Settings"})},"9"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(el.Z,{children:"Admin"})},"7"):null,(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api_ref"),children:(0,r.jsx)(el.Z,{children:"API Reference"})},"11")]})})})},lj=t(67989),lg=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,o=new Date,[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)([]),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)([]),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)([]),[Z,w]=(0,n.useState)([]),[b,v]=(0,n.useState)([]),[S,T]=(0,n.useState)([]),[O,M]=(0,n.useState)([]),[R,L]=(0,n.useState)([]),[U,D]=(0,n.useState)(null),z=new Date(o.getFullYear(),o.getMonth(),1),B=new Date(o.getFullYear(),o.getMonth()+1,0),q=V(z),K=V(B);function V(e){let l=e.getFullYear(),t=e.getMonth()+1,s=e.getDate();return"".concat(l,"-").concat(t<10?"0"+t:t,"-").concat(s<10?"0"+s:s)}console.log("Start date is ".concat(q)),console.log("End date is ".concat(K)),(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{if(console.log("user role: ".concat(s)),"Admin"==s||"Admin Viewer"==s){let e=await I(l);c(e);let t=(await P(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let r=(await E(l)).map(e=>({key:e.model,spend:e.total_spend}));u(r);let n=await A(l);console.log("teamSpend",n),g(n.daily_spend),w(n.teams);let o=n.total_spend_per_team;o=o.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),v(o);let i=await N(l);y(i.top_10_tags);let d=(await _(l,a,s)).data;console.log("model groups in model dashboard",d);let h=[];for(let e=0;e{if(console.log("result from spend logs call",e),"daily_spend"in e){let l=e.daily_spend;console.log("daily spend",l),c(l);let t=e.top_api_keys;m(t)}else{let t=(await F(l,function(e){let l=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[t,s]=e;"spend"!==t&&"startTime"!==t&&"models"!==t&&"users"!==t&&l.push({key:t,spend:s})})}),l.sort((e,l)=>Number(l.spend)-Number(e.spend));let t=l.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(t[0]))),t}(e))).info.map(e=>({key:(e.key_name||e.key_alias).substring(0,10),spend:e.spend}));m(t),p(function(e){let l={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[t,s]=e;""!==t&&null!=t&&"None"!=t&&(l[t]||(l[t]=0),l[t]+=s)})});let t=Object.entries(l).map(e=>{let[l,t]=e;return{user_id:l,spend:t}});t.sort((e,l)=>l.spend-e.spend);let s=t.slice(0,5);return console.log("topKeys: ".concat(Object.values(s[0]))),s}(e)),c(e)}});let e=await k(l,a,s,null);console.log("Model metrics response:",e);let r=[...e].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(e),M(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,q,K]);let G=async e=>{if(console.log("Updating model metrics for group:",e),l&&a&&s){D(e);try{let t=await k(l,a,s,e);console.log("Model metrics response:",t);let r=[...t].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(t),M(r)}catch(e){console.error("Failed to fetch model metrics",e)}}};return(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(eE,{userID:a,userRole:s,accessToken:l,userSpend:null,selectedTeam:null}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{className:"mt-2",children:[(0,r.jsx)(eU.Z,{children:"All Up"}),(0,r.jsx)(eU.Z,{children:"Team Based Usage"}),(0,r.jsx)(eU.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eU.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Monthly Spend"}),(0,r.jsx)(ej.Z,{data:i,index:"date",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top API Keys"}),(0,r.jsx)(ej.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,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Users"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:x,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Models"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(J.Z,{numColSpan:2,children:[(0,r.jsxs)(eg.Z,{className:"mb-2",children:[(0,r.jsx)(et.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(lj.Z,{data:b})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(ej.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:Z,yAxisWidth:80,colors:["blue","green","yellow","red","purple"],stack:!0})]})]}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(el.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/enterprise#tracking-spend-for-custom-tags",target:"_blank",children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Tag"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Requests"})]})}),(0,r.jsx)(eb.Z,{children:f.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.name}),(0,r.jsx)(e_.Z,{children:e.value}),(0,r.jsx)(e_.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)(et.Z,{children:"Filter By Model Group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080"},children:"View how requests were load balanced within a model group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080",fontStyle:"italic"},children:"(Beta feature) only supported for Azure Model Groups"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2",defaultValue:"all",children:[(0,r.jsx)(eN.Z,{value:"all",onClick:()=>G(null),children:"All Model Groups"}),R.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>G(e),children:e},l))]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Number Requests per Model"}),(0,r.jsx)(ej.Z,{data:S,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(eg.Z,{className:"mt-4",children:[(0,r.jsx)(et.Z,{children:"Latency Per Model"}),(0,r.jsx)(ej.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},lf=()=>{let{Title:e,Paragraph:l}=eR.default,[t,s]=(0,n.useState)(""),[a,i]=(0,n.useState)(null),[c,d]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(!0),j=(0,o.useSearchParams)(),[g,f]=(0,n.useState)({data:[]}),y=j.get("userID"),Z=j.get("token"),[w,b]=(0,n.useState)("api-keys"),[_,k]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(Z){let e=(0,eM.o)(Z);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),k(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&b("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))}}},[Z]),(0,r.jsx)(n.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(m,{userID:y,userRole:t,userEmail:a,showSSOBanner:x}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(lp,{setPage:b,userRole:t,defaultSelectedKey:null})}),"api-keys"==w?(0,r.jsx)(eL,{userID:y,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==w?(0,r.jsx)(e8,{userID:y,userRole:t,token:Z,accessToken:_,modelData:g,setModelData:f}):"llm-playground"==w?(0,r.jsx)(lm,{userID:y,userRole:t,token:Z,accessToken:_}):"users"==w?(0,r.jsx)(e6,{userID:y,userRole:t,token:Z,keys:h,teams:c,accessToken:_,setKeys:u}):"teams"==w?(0,r.jsx)(e7,{teams:c,setTeams:d,searchParams:j,accessToken:_,userID:y,userRole:t}):"admin-panel"==w?(0,r.jsx)(le,{setTeams:d,searchParams:j,accessToken:_,showSSOBanner:x}):"api_ref"==w?(0,r.jsx)(lc,{}):"settings"==w?(0,r.jsx)(lt,{userID:y,userRole:t,accessToken:_}):"general-settings"==w?(0,r.jsx)(lo,{userID:y,userRole:t,accessToken:_,modelData:g}):(0,r.jsx)(lg,{userID:y,userRole:t,token:Z,accessToken:_})]})]})})}}},function(e){e.O(0,[447,971,69,744],function(){return e(e.s=20661)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-781ca5f151d78d1d.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-781ca5f151d78d1d.js deleted file mode 100644 index 40715cd06..000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-781ca5f151d78d1d.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{20661:function(e,l,t){Promise.resolve().then(t.bind(t,27125))},27125:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return lf}});var s,a,r=t(3827),n=t(64090),o=t(47907),i=t(8792),c=t(40491),d=t(65270),m=e=>{let{userID:l,userRole:t,userEmail:s,showSSOBanner:a}=e;console.log("User ID:",l),console.log("userEmail:",s),console.log("showSSOBanner:",a);let n=[{key:"1",label:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("p",{children:["Role: ",t]}),(0,r.jsxs)("p",{children:["ID: ",l]})]})}];return(0,r.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,r.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,r.jsx)("div",{className:"flex flex-col items-center",children:(0,r.jsx)(i.default,{href:"/",children:(0,r.jsx)("button",{className:"text-gray-800 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:160,height:160,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,r.jsxs)("div",{className:"text-right mx-4 my-2 absolute top-0 right-0 flex items-center justify-end space-x-2",children:[a?(0,r.jsx)("div",{style:{padding:"6px",borderRadius:"8px"},children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",style:{fontSize:"14px",textDecoration:"underline"},children:"Request hosted proxy"})}):null,(0,r.jsx)("div",{style:{border:"1px solid #391085",padding:"6px",borderRadius:"8px"},children:(0,r.jsx)(c.Z,{menu:{items:n},children:(0,r.jsx)(d.Z,{children:s})})})]})]})},h=t(80588);let u=async()=>{try{let e=await fetch("https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"),l=await e.json();return console.log("received data: ".concat(l)),l}catch(e){throw console.error("Failed to get model cost map:",e),e}},x=async(e,l)=>{try{let t=await fetch("/model/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model created successfully. Wait 60s and refresh on 'All Models' page"),s}catch(e){throw console.error("Failed to create key:",e),e}},p=async(e,l)=>{console.log("model_id in model delete call: ".concat(l));try{let t=await fetch("/model/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model deleted successfully. Restart server to see this."),s}catch(e){throw console.error("Failed to create key:",e),e}},j=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},g=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},f=async(e,l)=>{try{console.log("in keyDeleteCall:",l);let t=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},y=async(e,l)=>{try{console.log("in teamDeleteCall:",l);let t=await fetch("/team/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete team: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to delete key:",e),e}},Z=async function(e,l,t){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0;try{let n="/user/info";"App Owner"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),"App User"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),console.log("in userInfoCall viewAll=",s),s&&r&&null!=a&&void 0!=a&&(n="".concat(n,"?view_all=true&page=").concat(a,"&page_size=").concat(r));let o=await fetch(n,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let i=await o.json();return console.log("API Response:",i),i}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,l)=>{try{let t="/team/info";l&&(t="".concat(t,"?team_id=").concat(l)),console.log("in teamInfoCall");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 h.ZP.error(e,20),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}},b=async e=>{try{let l=await fetch("/global/spend",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},_=async(e,l,t)=>{try{let l=await fetch("/v2/model/info",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log("modelInfoCall:",t),t}catch(e){throw console.error("Failed to create key:",e),e}},k=async(e,l,t,s)=>{try{let l="/model/metrics";s&&(l="".concat(l,"?_selected_model_group=").concat(s));let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},v=async(e,l,t)=>{try{let l=await fetch("/models",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},S=async(e,l)=>{try{let t="/global/spend/logs";console.log("in keySpendLogsCall:",t);let s=await fetch("".concat(t,"?api_key=").concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},A=async e=>{try{let l="/global/spend/teams";console.log("in teamSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},N=async e=>{try{let l="/global/spend/tags";console.log("in tagsSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},C=async(e,l,t,s,a,r)=>{try{console.log("user role in spend logs call: ".concat(t));let l="/spend/logs";l="App Owner"==t?"".concat(l,"?user_id=").concat(s,"&start_date=").concat(a,"&end_date=").concat(r):"".concat(l,"?start_date=").concat(a,"&end_date=").concat(r);let n=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.text();throw h.ZP.error(e,20),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}},I=async e=>{try{let l=await fetch("/global/spend/logs",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},P=async e=>{try{let l=await fetch("/global/spend/keys?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},T=async(e,l)=>{try{l&&JSON.stringify({api_key:l});let t={method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}};l&&(t.body=JSON.stringify({api_key:l}));let s=await fetch("/global/spend/end_users",t);if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},E=async e=>{try{let l=await fetch("/global/spend/models?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},F=async(e,l)=>{try{let t=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},O=async e=>{try{let l="/user/get_requests";console.log("in userGetRequesedtModelsCall:",l);let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to get requested models:",e),e}},M=async(e,l)=>{try{let t="/user/get_users?role=".concat(l);console.log("in userGetAllUsersCall:",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 h.ZP.error("Failed to delete key: "+e,20),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}},R=async(e,l)=>{try{console.log("Form Values in teamCreateCall:",l);let t=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},L=async(e,l)=>{try{console.log("Form Values in keyUpdateCall:",l);let t=await fetch("/key/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update key Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},U=async(e,l)=>{try{console.log("Form Values in teamUpateCall:",l);let t=await fetch("/team/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update team: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update Team Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},D=async(e,l)=>{try{console.log("Form Values in modelUpateCall:",l);let t=await fetch("/model/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update model: "+e,20),console.error("Error update from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update model Response:",s),s}catch(e){throw console.error("Failed to update model:",e),e}},z=async(e,l,t)=>{try{console.log("Form Values in teamMemberAddCall:",t);let s=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:l,member:t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},B=async(e,l,t)=>{try{console.log("Form Values in userUpdateUserCall:",l);let s={...l};null!==t&&(s.user_role=t),s=JSON.stringify(s);let a=await fetch("/user/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:s});if(!a.ok){let e=await a.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},q=async(e,l)=>{try{let t=await fetch("/global/predict/spend/logs",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},K=async(e,l)=>{try{let t="/health/services?service=".concat(l);console.log("Checking Slack Budget Alerts service health");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 h.ZP.error("Failed ".concat(l," service health check ")+e),Error(e)}let a=await s.json();return h.ZP.success("Test request to ".concat(l," made - check logs/alerts on ").concat(l," to verify")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},V=async(e,l,t)=>{try{let l=await fetch("/get/config/callbacks",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},G=async(e,l)=>{try{let t=await fetch("/config/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},W=async e=>{try{let l=await fetch("/health",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to call /health:",e),e}};var J=t(10384),Y=t(46453),H=t(2179),$=t(52273),X=t(26780),Q=t(15595),ee=t(6698),el=t(71801),et=t(42440),es=t(42308),ea=t(50670),er=t(81583),en=t(99129),eo=t(44839),ei=t(88707),ec=t(1861);let{Option:ed}=ea.default;var em=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=er.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[f,y]=(0,n.useState)([]),Z=()=>{m(!1),c.resetFields()},w=()=>{m(!1),x(null),c.resetFields()};(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===s)return;if(null!==a){let e=(await v(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),y(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let b=async e=>{try{h.ZP.info("Making API Call"),m(!0);let t=await j(a,l,e);console.log("key create Response:",t),i(e=>e?[...e,t]:[t]),x(t.key),g(t.soft_budget),h.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the key:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(en.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:Z,onCancel:w,children:(0,r.jsxs)(er.Z,{form:c,onFinish:b,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",hidden:!0,initialValue:t?t.team_id:null,valuePropName:"team_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?f.map(e=>(0,r.jsx)(ed,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(ed,{value:e,children:e},e)):f.map(e=>(0,r.jsx)(ed,{value:e,children:e},e))]})}),(0,r.jsxs)(X.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Q.Z,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==t?void 0:t.max_budget)!==null&&(null==t?void 0:t.max_budget)!==void 0?null==t?void 0:t.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.max_budget&&l>t.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(t.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Team Reset Budget: ".concat((null==t?void 0:t.budget_duration)!==null&&(null==t?void 0:t.budget_duration)!==void 0?null==t?void 0:t.budget_duration:"None"),children:(0,r.jsxs)(ea.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(ea.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(ea.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Tokens per minute Limit (TPM)",name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==t?void 0:t.tpm_limit)!==null&&(null==t?void 0:t.tpm_limit)!==void 0?null==t?void 0:t.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.tpm_limit&&l>t.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(t.tpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Requests per minute Limit (RPM)",name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==t?void 0:t.rpm_limit)!==null&&(null==t?void 0:t.rpm_limit)!==void 0?null==t?void 0:t.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.rpm_limit&&l>t.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(t.rpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(en.Z,{visible:d,onOk:Z,onCancel:w,footer:null,children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Save your Key"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(el.Z,{className:"mt-3",children:"API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:u})}),(0,r.jsx)(es.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(H.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(el.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=t(9454),eu=t(98941),ex=t(33393),ep=t(5),ej=t(9853),eg=t(13810),ef=t(39290),ey=t(66952),eZ=t(61244),ew=t(10827),eb=t(3851),e_=t(2044),ek=t(64167),ev=t(74480),eS=t(7178),eA=t(95093),eN=t(27166);let{Option:eC}=ea.default;var eI=e=>{let{userID:l,userRole:t,accessToken:s,selectedTeam:a,data:o,setData:i,teams:c}=e,[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(!1),[p,j]=(0,n.useState)(null),[g,y]=n.useState(null),[Z,w]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),[k,A]=(0,n.useState)(""),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),F=new Set,[O,M]=(0,n.useState)(F);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),E(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,l,t]),(0,n.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,t)=>{let s=l.team_id;e.add(s)}),M(e)}},[c]);let R=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),C(!0)},U=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await L(s,e);console.log("handleEditSubmit: newKeyValues",t),o&&i(o.map(e=>e.token===l?t:e)),h.ZP.success("Key updated successfully"),C(!1),P(null)},D=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await S(s,e.token);console.log("Response:",l),_(l);try{let e=await q(s,l);console.log("Response2:",e);let t=[...l,...e.response];_(t),A(e.predicted_spend),console.log("Combined Data:",t)}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,n.useEffect)(()=>{D(Z)},[Z]);let z=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"+l),x(!0))},B=async()=>{if(null!=p&&null!=o){try{await f(s,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,r.jsxs)("div",{children:[(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ew.Z,{className:"mt-5 max-h-[300px] min-h-[300px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Key Alias"}),(0,r.jsx)(ev.Z,{children:"Secret Key"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eb.Z,{children:o.map(e=>{if(console.log(e),"litellm-dashboard"===e.team_id)return null;if(a){if(console.log("item team id: ".concat(e.team_id,", knownTeamIDs.has(item.team_id): ").concat(O.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||O.has(e.team_id))&&e.team_id!=a.team_id)return null;console.log("item team id: ".concat(e.team_id,", is returned"))}return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(el.Z,{children:e.key_alias}):(0,r.jsx)(el.Z,{children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.key_name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(e_.Z,{children:null!=e.max_budget?(0,r.jsx)(el.Z,{children:e.max_budget}):(0,r.jsx)(el.Z,{children:"Unlimited"})}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(r.Fragment,{children:a&&a.models&&a.models.length>0?a.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(el.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{})," RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{onClick:()=>{w(e),y(e.id)},icon:eh.Z,size:"sm"}),(0,r.jsx)(ef.Z,{open:null!==g,onClose:()=>{y(null),w(null)},children:(0,r.jsx)(ey.Z,{children:Z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:[(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Spend"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:(()=>{try{return parseFloat(Z.spend).toFixed(4)}catch(e){return Z.spend}})()})})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Budget"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.max_budget?(0,r.jsx)(r.Fragment,{children:Z.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Expires"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-default font-small text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.expires?(0,r.jsx)(r.Fragment,{children:new Date(Z.expires).toLocaleString(void 0,{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}):(0,r.jsx)(r.Fragment,{children:"Never"})})})]},e.name)]}),(0,r.jsx)(eg.Z,{className:"mt-6 mb-6",children:b&&(0,r.jsx)(ej.Z,{className:"mt-6",data:b,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(et.Z,{children:"Metadata"}),(0,r.jsx)(el.Z,{children:JSON.stringify(Z.metadata)}),(0,r.jsx)(H.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{y(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>R(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>z(e),icon:ex.Z,size:"sm"})]})]},e.token)})})]}),u&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:B,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),I&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=er.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(en.Z,{title:"Edit Key",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:i,onFinish:U,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{validator:(e,l)=>{let t=l.filter(e=>!d.models.includes(e)&&"all-team-models"!==e&&"all-proxy-models"!==e&&!d.models.includes("all-proxy-models"));return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t,"Team models: ").concat(d.models)):Promise.resolve()}}],children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eC,{value:"all-team-models",children:"All Team Models"},"all-team-models"),d&&d.models?d.models.includes("all-proxy-models")?T.filter(e=>"all-proxy-models"!==e).map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(eC,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: ".concat((null==d?void 0:d.max_budget)!==null&&(null==d?void 0:d.max_budget)!==void 0?null==d?void 0:d.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&d&&null!==d.max_budget&&l>d.max_budget)throw console.log("keyTeam.max_budget: ".concat(d.max_budget)),Error("Budget cannot exceed team max budget: $".concat(d.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(er.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(eA.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(eN.Z,{value:e.team_id,onClick:()=>m(e),children:e.team_alias},l))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{C(!1),P(null)},token:I,onSubmit:U})]})},eP=t(76032),eT=t(35152),eE=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[i,c]=(0,n.useState)(null!==a?a:0),[d,m]=(0,n.useState)(0),[h,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{let e=async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await b(s);e&&(e.spend?c(e.spend):c(0),e.max_budget?m(e.max_budget):m(0))}catch(e){console.error("Error fetching global spend data:",e)}};(async()=>{try{if(null===l||null===t)return;if(null!==s){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),u(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,s,l]),(0,n.useEffect)(()=>{null!==a&&c(a)},[a]);let x=[];o&&o.models&&(x=o.models),x&&x.includes("all-proxy-models")?(console.log("user models:",h),x=h):x&&x.includes("all-team-models")?x=o.models:x&&0===x.length&&(x=h);let p=void 0!==i?i.toFixed(4):null;return console.log("spend in view user spend: ".concat(i)),(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:["Total Spend"," "]}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",p]})]}),(0,r.jsx)("div",{className:"ml-auto",children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Team Models"})}),(0,r.jsx)(Q.Z,{className:"absolute right-0 z-10 bg-white p-2 shadow-lg max-w-xs",children:(0,r.jsx)(eP.Z,{children:x.map(e=>(0,r.jsx)(eT.Z,{children:(0,r.jsx)(el.Z,{children:e})},e))})})]})})]})},eF=e=>{let{userID:l,userRole:t,selectedTeam:s,accessToken:a}=e,[o,i]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===t)return;if(null!==a){let e=(await v(a,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),i(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,t]);let c=[];return s&&s.models&&(c=s.models),c&&c.includes("all-proxy-models")&&(console.log("user models:",o),c=o),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"mb-5",children:(0,r.jsx)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null==s?void 0:s.team_alias})})})},eO=e=>{let l,{teams:t,setSelectedTeam:s,userRole:a}=e,o={models:[],team_id:null,team_alias:"Default Team"},[i,c]=(0,n.useState)(o);return(l="App User"===a?t:t?[...t,o]:[o],"App User"===a)?null:(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(et.Z,{children:"Select Team"}),(0,r.jsx)(el.Z,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),(0,r.jsxs)(el.Z,{className:"mt-3 mb-3",children:[(0,r.jsx)("b",{children:"Default Team:"})," If no team_id is set for a key, it will be grouped under here."]}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>s(e),children:e.team_alias},l))}):(0,r.jsxs)(el.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eM=t(37963),eR=t(36083);console.log("isLocal:",!1);var eL=e=>{let{userID:l,userRole:t,teams:s,keys:a,setUserRole:i,userEmail:c,setUserEmail:d,setTeams:m,setKeys:h}=e,[u,x]=(0,n.useState)(null),p=(0,o.useSearchParams)();p.get("viewSpend"),(0,o.useRouter)();let j=p.get("token"),[g,f]=(0,n.useState)(null),[y,w]=(0,n.useState)(null),[_,k]=(0,n.useState)([]),S={models:[],team_alias:"Default Team",team_id:null},[A,N]=(0,n.useState)(s?s[0]:S);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eM.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),f(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),i(l)}else console.log("User role not defined");e.user_email?d(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&g&&t&&!a&&!u){let e=sessionStorage.getItem("userModels"+l);e?k(JSON.parse(e)):(async()=>{try{let e=await Z(g,l,t,!1,null,null);if(console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),"Admin"==t){let e=await b(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams);let s=[...e.teams];s.length>0?(console.log("response['teams']: ".concat(s)),N(s[0])):N(S),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let a=(await v(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",a),k(a),console.log("userModels:",_),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=A){let e=0;for(let l of a)A.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===A.team_id&&(e+=l.spend);w(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;w(e)}},[A]),null==l||null==j){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==g)return null;if(null==t&&i("App Owner"),t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",A),console.log("teamSpend: ".concat(y)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eF,{userID:l,userRole:t,selectedTeam:A||null,accessToken:g}),(0,r.jsx)(eE,{userID:l,userRole:t,accessToken:g,userSpend:y,selectedTeam:A||null}),(0,r.jsx)(eI,{userID:l,userRole:t,accessToken:g,selectedTeam:A||null,data:a,setData:h,teams:s}),(0,r.jsx)(em,{userID:l,team:A||null,userRole:t,accessToken:g,data:a,setData:h},A?A.team_id:null),(0,r.jsx)(eO,{teams:s,setSelectedTeam:N,userRole:t})]})})})},eU=t(92836),eD=t(26734),ez=t(41608),eB=t(32126),eq=t(23682),eK=t(47047),eV=t(76628),eG=t(38302),eW=t(28683),eJ=t(1460),eY=t(78578),eH=t(63954),e$=e=>{let{modelID:l,accessToken:t}=e,[s,a]=(0,n.useState)(!1),o=async()=>{try{h.ZP.info("Making API Call"),a(!0);let e=await p(t,l);console.log("model delete Response:",e),h.ZP.success("Model ".concat(l," deleted successfully")),a(!1)}catch(e){console.error("Error deleting the model:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eZ.Z,{onClick:()=>a(!0),icon:ex.Z,size:"sm"}),(0,r.jsx)(en.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Delete Model"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)("p",{children:"Are you sure you want to delete this model? This action is irreversible."})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eX=t(97766),eQ=t(46495);let{Title:e0,Link:e1}=eR.default;(s=a||(a={})).OpenAI="OpenAI",s.Azure="Azure",s.Anthropic="Anthropic",s.Google_AI_Studio="Gemini (Google AI Studio)",s.Bedrock="Amazon Bedrock",s.OpenAI_Compatible="OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)",s.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)";let e2={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"},e4=async(e,l,t)=>{try{let s=Array.isArray(e.model)?e.model:[e.model];console.log("received deployments: ".concat(s)),console.log("received type of deployments: ".concat(typeof s)),s.forEach(async t=>{console.log("litellm_model: ".concat(t));let s={},a={};s.model=t;let r="";for(let[l,t]of Object.entries(e))if(""!==t){if("model_name"==l)r+=t;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)a[l]=t;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",t);let e={};if(t&&void 0!=t){try{e=JSON.parse(t)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else s[l]=t}let n={model_name:r,litellm_params:s,model_info:a},o=await x(l,n);console.log("response for model create call: ".concat(o.data))}),t.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};var e8=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d,modelData:m={data:[]},setModelData:x}=e,[p,j]=(0,n.useState)([]),[g]=er.Z.useForm(),[f,y]=(0,n.useState)(null),[Z,w]=(0,n.useState)(""),[b,k]=(0,n.useState)([]),v=Object.values(a).filter(e=>isNaN(Number(e))),[S,A]=(0,n.useState)("OpenAI"),[N,C]=(0,n.useState)(""),[I,P]=(0,n.useState)(!1),[T,E]=(0,n.useState)(null),[F,M]=(0,n.useState)([]),[R,L]=(0,n.useState)(null),U=e=>{E(e),P(!0)},z=async e=>{if(console.log("handleEditSubmit:",e),null==o)return;let l={},t=null;for(let[s,a]of Object.entries(e))"model_id"!==s?l[s]=a:t=a;let s={litellm_params:l,model_info:{id:t}};console.log("handleEditSubmit payload:",s),await D(o,s),h.ZP.success("Model updated successfully, restart server to see updates"),P(!1),E(null)},B=()=>{w(new Date().toLocaleString())};if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await _(o,d,c);console.log("Model data response:",e.data),x(e);let l=new Set;for(let t=0;t{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),y(e)};null==f&&l(),B()},[o,i,c,d,f,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let q=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(f)),null!=f&&"object"==typeof f&&e in f)?f[e].litellm_provider:"openai";if(a){let e=a.split("/"),l=e[0];n=1===e.length?h(a):l}else n="openai";r&&(o=null==r?void 0:r.input_cost_per_token,i=null==r?void 0:r.output_cost_per_token,c=null==r?void 0:r.max_tokens),(null==s?void 0:s.litellm_params)&&(d=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),m.data[e].provider=n,m.data[e].input_cost=o,m.data[e].output_cost=i,m.data[e].max_tokens=c,m.data[e].api_base=null==s?void 0:null===(t=s.litellm_params)||void 0===t?void 0:t.api_base,m.data[e].cleanedLitellmParams=d,q.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to view all models"})]})}let K=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=e2[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof f&&Object.entries(f).forEach(l=>{let[s,a]=l;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===e||a.litellm_provider.includes(e))&&t.push(s)}),k(t),console.log("providerModels: ".concat(b))}},V=async()=>{try{h.ZP.info("Running health check..."),C("");let e=await W(o);C(e)}catch(e){console.error("Error running health check:",e),C("Error running health check")}};return console.log("selectedProvider: ".concat(S)),console.log("providerModels.length: ".concat(b.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eU.Z,{children:"All Models"}),(0,r.jsx)(eU.Z,{children:"Add Model"}),(0,r.jsx)(eU.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[Z&&(0,r.jsxs)(el.Z,{children:["Last Refreshed: ",Z]}),(0,r.jsx)(eZ.Z,{icon:eH.Z,variant:"shadow",size:"xs",className:"self-center",onClick:B})]})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(Y.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:"all",onValueChange:e=>L("all"===e?"all":e),children:[(0,r.jsx)(eN.Z,{value:"all",children:"All Models"}),F.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>L(e),children:e},l))]})]}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Public Model Name "}),(0,r.jsx)(ev.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(ev.Z,{children:"API Base"}),(0,r.jsx)(ev.Z,{children:"Extra litellm Params"}),(0,r.jsx)(ev.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(eb.Z,{children:m.data.filter(e=>"all"===R||e.model_name===R||null==R||""===R).map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.model_name})}),(0,r.jsx)(e_.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(e_.Z,{children:e.api_base}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Litellm params"})}),(0,r.jsx)(Q.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(e_.Z,{children:e.input_cost}),(0,r.jsx)(e_.Z,{children:e.output_cost}),(0,r.jsx)(e_.Z,{children:e.max_tokens}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>U(e)}),(0,r.jsx)(e$,{modelID:e.model_info.id,accessToken:o})]})]},l))})]})})]}),(0,r.jsx)(e=>{let{visible:l,onCancel:t,model:s,onSubmit:a}=e,[n]=er.Z.useForm(),o={},i="",c="";if(s){o=s.litellm_params,i=s.model_name;let e=s.model_info;e&&(c=e.id,console.log("model_id: ".concat(c)),o.model_id=c)}return(0,r.jsx)(en.Z,{title:"Edit Model "+i,visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a(e),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:z,initialValues:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)($.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})},{visible:I,onCancel:()=>{P(!1),E(null)},model:T,onSubmit:z})]}),(0,r.jsxs)(eB.Z,{className:"h-full",children:[(0,r.jsx)(e0,{level:2,children:"Add new model"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(er.Z,{form:g,onFinish:()=>{g.validateFields().then(e=>{e4(e,o,g)}).catch(e=>{console.error("Validation failed:",e)})},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:S.toString(),children:v.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>{K(e),A(e)},children:e},l))})}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Public Model Name",name:"model_name",tooltip:"Model name your users will pass in. Also used for load-balancing, LiteLLM will load balance between all models with this public name.",className:"mb-0",children:(0,r.jsx)($.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=S.toString())?"gemini-pro":"Anthropic"==s?"claude-3-opus":"Amazon Bedrock"==s?"claude-3-opus":"Gemini (Google AI Studio)"==s?"gemini-pro":"gpt-3.5-turbo"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"LiteLLM Model Name(s)",name:"model",tooltip:"Actual model name used for making litellm.completion() call.",className:"mb-0",children:"Azure"===S?(0,r.jsx)($.Z,{placeholder:"Enter model name"}):b.length>0?(0,r.jsx)(eK.Z,{value:b,children:b.map((e,l)=>(0,r.jsx)(eV.Z,{value:e,children:e},l))}):(0,r.jsx)($.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/proxy/reliability#step-1---set-deployments-on-config",target:"_blank",children:"loadbalance"})," models with the same 'public name'"]})})]}),"Amazon Bedrock"!=S&&"Vertex AI (Anthropic, Gemini, etc.)"!=S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)($.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==S&&(0,r.jsx)(er.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)($.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)($.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eQ.Z,{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;g.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?h.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&h.ZP.error("".concat(e.file.name," file upload failed."))},children:(0,r.jsx)(ec.ZP,{icon:(0,r.jsx)(eX.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==S||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==S)&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)($.Z,{placeholder:"https://..."})}),"Azure"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)($.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==S&&(0,r.jsxs)(er.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)($.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(el.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(e1,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Access Key ID",name:"aws_access_key_id",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Secret Access Key",name:"aws_secret_access_key",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Region Name",name:"aws_region_name",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(er.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-0",children:(0,r.jsx)(eY.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]})]}),(0,r.jsx)("div",{style:{textAlign:"center",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eJ.Z,{title:"Get help on our github",children:(0,r.jsx)(eR.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(el.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(H.Z,{onClick:V,children:"Run `/health`"}),N&&(0,r.jsx)("pre",{children:JSON.stringify(N,null,2)})]})})]})]})})};let{Option:e5}=ea.default;var e3=e=>{let{userID:l,accessToken:t,teams:s}=e,[a]=er.Z.useForm(),[o,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),[m,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await v(t,l,"any"),s=[];for(let l=0;l{i(!1),a.resetFields()},p=()=>{i(!1),d(null),a.resetFields()},j=async e=>{try{h.ZP.info("Making API Call"),i(!0),console.log("formValues in create user:",e);let s=await g(t,null,e);console.log("user create Response:",s),d(s.key),h.ZP.success("API user Created"),a.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Invite User"}),(0,r.jsxs)(en.Z,{title:"Invite User",visible:o,width:800,footer:null,onOk:x,onCancel:p,children:[(0,r.jsx)(el.Z,{className:"mb-1",children:"Invite a user to login to the Admin UI and create Keys"}),(0,r.jsx)(el.Z,{className:"mb-6",children:(0,r.jsx)("b",{children:"Note: SSO Setup Required for this"})}),(0,r.jsxs)(er.Z,{form:a,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(er.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(ea.default,{placeholder:"Select Team ID",style:{width:"100%"},children:s?s.map(e=>(0,r.jsx)(e5,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(e5,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create User"})})]})]}),c&&(0,r.jsxs)(en.Z,{title:"User Created Successfully",visible:o,onOk:x,onCancel:p,footer:null,children:[(0,r.jsx)("p",{children:"User has been created to access your proxy. Please Ask them to Log In."}),(0,r.jsx)("br",{}),(0,r.jsx)("p",{children:(0,r.jsx)("b",{children:"Note: This Feature is only supported through SSO on the Admin UI"})})]})]})},e6=e=>{let{accessToken:l,token:t,keys:s,userRole:a,userID:o,teams:i,setKeys:c}=e,[d,m]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(0),[j,g]=n.useState(null),[f,y]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await Z(l,null,a,!0,x,25);console.log("user data response:",e),m(e)}catch(e){console.error("There was an error fetching the model data",e)}};l&&t&&a&&o&&e();let s=async()=>{try{let e=await T(l,null);console.log("user data response:",e),u(e)}catch(e){console.error("There was an error fetching the model data",e)}};a&&("Admin"==a||"Admin Viewer"==a)&&!h&&s()},[l,t,a,o,x]),!d||!l||!t||!a||!o)return(0,r.jsx)("div",{children:"Loading..."});let w=async e=>{try{let t=await T(l,e);console.log("user data response:",t),u(t)}catch(e){console.error("There was an error fetching the model data",e)}};return(0,r.jsx)("div",{style:{width:"100%"},children:(0,r.jsxs)(Y.Z,{className:"gap-2 p-2 h-[80vh] w-full mt-8",children:[(0,r.jsx)(e3,{userID:o,accessToken:l,teams:i}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[80vh] mb-4",children:[(0,r.jsxs)("div",{className:"mb-4 mt-1",children:[(0,r.jsxs)(el.Z,{children:[(0,r.jsx)("b",{children:"Key Owners: "})," Users on LiteLLM that created API Keys. Automatically tracked by LiteLLM"]}),(0,r.jsxs)(el.Z,{className:"mt-1",children:[(0,r.jsx)("b",{children:"End Users: "}),"End Users of your LLM API calls. Tracked When a `user` param is passed in your LLM calls"]})]}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eU.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"User ID"}),(0,r.jsx)(ev.Z,{children:"User Email"}),(0,r.jsx)(ev.Z,{children:"User Models"}),(0,r.jsx)(ev.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(eb.Z,{children:d.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_id}),(0,r.jsx)(e_.Z,{children:e.user_email}),(0,r.jsx)(e_.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(e_.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(Y.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(ep.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(ep.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsxs)("div",{className:"flex-1 flex justify-between items-center",children:[(0,r.jsx)(el.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(eA.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_alias&&e.key_alias.length>0)return(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>w(e.token),children:e.key_alias},l)})})]})]}),(0,r.jsxs)(ew.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"End User"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Total Events"})]})}),(0,r.jsx)(eb.Z,{children:null==h?void 0:h.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:e.total_spend}),(0,r.jsx)(e_.Z,{children:e.total_events})]},l))})]})]})]})]})]}),function(){if(!d)return null;let e=Math.ceil(d.length/25);return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",x+1," of ",e]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l focus:outline-none",disabled:0===x,onClick:()=>p(x-1),children:"← Prev"}),(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r focus:outline-none",onClick:()=>{p(x+1)},children:"Next →"})]})]})}()]})})},e7=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=er.Z.useForm(),[d]=er.Z.useForm(),{Title:m,Paragraph:u}=eR.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[f,Z]=(0,n.useState)(l?l[0]:null),[b,_]=(0,n.useState)(!1),[k,S]=(0,n.useState)(!1),[A,N]=(0,n.useState)([]),[C,I]=(0,n.useState)(!1),[P,T]=(0,n.useState)(null),[E,F]=(0,n.useState)({}),O=e=>{Z(e),g(!0)},M=async e=>{let t=e.team_id;if(console.log("handleEditSubmit:",e),null==s)return;let r=await U(s,e);l&&a(l.map(e=>e.team_id===t?r.data:e)),h.ZP.success("Team updated successfully"),g(!1),Z(null)},L=async e=>{T(e),I(!0)},D=async()=>{if(null!=P&&null!=l&&null!=s){try{await y(s,P);let e=l.filter(e=>e.team_id!==P);a(e)}catch(e){console.error("Error deleting the team:",e)}I(!1),T(null)}};(0,n.useEffect)(()=>{let e=async()=>{try{if(null===o||null===i||null===s||null===l)return;console.log("fetching team info:");let e={};for(let t=0;t<(null==l?void 0:l.length);t++){let a=l[t].team_id,r=await w(s,a);console.log("teamInfo response:",r),null!==r&&(e={...e,[a]:r})}F(e)}catch(e){console.error("Error fetching team info:",e)}};(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await v(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),N(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,o,i,l]);let B=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await R(s,e);null!==l?a([...l,t]):a([t]),console.log("response for team create call: ".concat(t)),h.ZP.success("Team created"),_(!1)}}catch(e){console.error("Error creating the team:",e),h.ZP.error("Error creating the team: "+e,20)}},q=async e=>{try{if(null!=s&&null!=l){h.ZP.info("Adding Member");let t={role:"user",user_email:e.user_email,user_id:e.user_id},r=await z(s,f.team_id,t);console.log("response for team create call: ".concat(r.data));let n=l.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(r.data.team_id)),e.team_id===r.data.team_id));if(console.log("foundIndex: ".concat(n)),-1!==n){let e=[...l];e[n]=r.data,a(e),Z(r.data)}S(!1)}}catch(e){console.error("Error creating the team:",e)}};return console.log("received teams ".concat(l)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Team Name"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ev.Z,{children:"Info"})]})}),(0,r.jsx)(eb.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(el.Z,{children:["TPM:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{}),"RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].keys&&E[e.team_id].keys.length," Keys"]}),(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].team_info&&E[e.team_id].team_info.members_with_roles&&E[e.team_id].team_info.members_with_roles.length," Members"]})]}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>O(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>L(e.team_id),icon:ex.Z,size:"sm"})]})]},e.team_id)):null})]}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{I(!1),T(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>_(!0),children:"+ Create New Team"}),(0,r.jsx)(en.Z,{title:"Create Team",visible:b,width:800,footer:null,onOk:()=>{_(!1),c.resetFields()},onCancel:()=>{_(!1),c.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:B,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"Team Members"}),(0,r.jsx)(u,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>{Z(e)},children:e.team_alias},l))}):(0,r.jsxs)(u,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:f?f.members_with_roles.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.role})]},l)):null})]})}),f&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=er.Z.useForm();return(0,r.jsx)(en.Z,{title:"Edit Team",visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a({...e,team_id:s.team_id}),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:M,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A&&A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"team_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),Z(null)},team:f,onSubmit:M})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto mb-5",onClick:()=>S(!0),children:"+ Add member"}),(0,r.jsx)(en.Z,{title:"Add member",visible:k,width:800,footer:null,onOk:()=>{S(!1),d.resetFields()},onCancel:()=>{S(!1),d.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e9=t(18190),le=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=er.Z.useForm(),[i]=er.Z.useForm(),{Title:c,Paragraph:d}=eR.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[f,y]=(0,n.useState)(!1),[Z,w]=(0,n.useState)(!1),[b,_]=(0,n.useState)(!1),[k,v]=(0,n.useState)(!1);try{l=window.location.origin}catch(e){l=""}l+="/fallback/login";let S=()=>{v(!1)},A=["proxy_admin","proxy_admin_viewer"];(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await M(s,"proxy_admin_viewer");l.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(l));let t=await M(s,"proxy_admin");t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(t)),console.log("combinedList: ".concat(e)),p(e)}})()},[s]);let N=()=>{w(!1),i.resetFields()},C=()=>{w(!1),i.resetFields()},I=e=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,null);console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),h.ZP.success("Refresh tab to see updated user role"),w(!1)}}catch(e){console.error("Error creating the key:",e)}},E=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,"proxy_admin_viewer");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),g(!1)}}catch(e){console.error("Error creating the key:",e)}},F=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await B(s,e,"proxy_admin");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),y(!1)}}catch(e){console.error("Error creating the key:",e)}},O=async e=>{null!=s&&G(s,{environment_variables:{PROXY_BASE_URL:e.proxy_base_url,GOOGLE_CLIENT_ID:e.google_client_id,GOOGLE_CLIENT_SECRET:e.google_client_secret}})};return console.log("admins: ".concat(null==x?void 0:x.length)),(0,r.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,r.jsx)(c,{level:4,children:"Admin Access "}),(0,r.jsxs)(d,{children:[a&&(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access",children:"Requires SSO Setup"}),(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin: "})," Can create keys, teams, users, add models, etc. ",(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin Viewer: "}),"Can just view spend. They cannot create keys, teams or grant users access to new models."," "]}),(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.user_role}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(en.Z,{title:"Update role",visible:Z,width:800,footer:null,onOk:N,onCancel:C,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(H.Z,{className:"mr-4 mb-5",onClick:()=>y(!0),children:"+ Add admin"}),(0,r.jsx)(en.Z,{title:"Add admin",visible:f,width:800,footer:null,onOk:()=>{y(!1),i.resetFields()},onCancel:()=>{y(!1),i.resetFields()},children:I(F)}),(0,r.jsx)(H.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(en.Z,{title:"Add viewer",visible:j,width:800,footer:null,onOk:()=>{g(!1),i.resetFields()},onCancel:()=>{g(!1),i.resetFields()},children:I(E)})]})})]}),(0,r.jsxs)(Y.Z,{children:[(0,r.jsx)(c,{level:4,children:"Add SSO"}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(H.Z,{onClick:()=>_(!0),children:"Add SSO"}),(0,r.jsx)(en.Z,{title:"Add SSO",visible:b,width:800,footer:null,onOk:()=>{_(!1),o.resetFields()},onCancel:()=>{_(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{F(e),O(e),_(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(eo.Z.Password,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(eo.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(en.Z,{title:"SSO Setup Instructions",visible:k,width:800,footer:null,onOk:S,onCancel:()=>{v(!1)},children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e9.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access ",(0,r.jsxs)("a",{href:l,target:"_blank",children:[(0,r.jsx)("b",{children:l})," "]})]})]})]})},ll=t(12224),lt=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)(!1),[u]=er.Z.useForm(),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)(""),[Z,w]=(0,n.useState)({}),[b,_]=(0,n.useState)([]),k=e=>{b.includes(e)?_(b.filter(l=>l!==e)):_([...b,e])},v={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),o(e.callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let t=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",t),_(e.active_alerts),y(t),w(e.alerts_to_webhook)}c(l)})},[l,t,s]);let S=e=>b&&b.includes(e),A=e=>{if(!l)return;let t=Object.fromEntries(Object.entries(e.variables).map(e=>{var l;let[t,s]=e;return[t,(null===(l=document.querySelector('input[name="'.concat(t,'"]')))||void 0===l?void 0:l.value)||s]}));console.log("updatedVariables",t),console.log("updateAlertTypes",j);try{G(l,{environment_variables:t})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},N=()=>{l&&u.validateFields().then(e=>{if(console.log("Form values:",e),"langfuse"===e.callback){G(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}});let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:null,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey}};o(a?[...a,t]:[t])}else if("slack"===e.callback){console.log("values.slackWebhookUrl: ".concat(e.slackWebhookUrl)),G(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),console.log("values.callback: ".concat(e.callback));let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:null,LANGFUSE_SECRET_KEY:null}};o(a?[...a,t]:[t])}m(!1),u.resetFields(),p(null)})};return l?(console.log("callbacks: ".concat(a)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eU.Z,{value:"2",children:"Alerting"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Callback"}),(0,r.jsx)(ev.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(eb.Z,{children:a.map((e,t)=>{var s;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ep.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).filter(e=>{let[l,t]=e;return null!==t}).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(el.Z,{className:"mt-2",children:l}),"LANGFUSE_HOST"===l?(0,r.jsx)("p",{children:"default value=https://cloud.langfuse.com"}):(0,r.jsx)("div",{}),(0,r.jsx)($.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>A(e),children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),m(!0)},children:"Add Callback"})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(el.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(v).map((e,l)=>{let[t,s]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ll.Z,{id:"switch",name:"switch",checked:S(t),onChange:()=>k(t)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:s})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:t,type:"password",defaultValue:Z&&Z[t]?Z[t]:f})})]},l)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(v).forEach(l=>{let[t,s]=l,a=document.querySelector('input[name="'.concat(t,'"]'));console.log("key",t),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[t]=r}),console.log("updatedAlertToWebhooks",e);let t={general_settings:{alert_to_webhook_url:e,alert_types:b}};console.log("payload",t);try{G(l,t)}catch(e){h.ZP.error("Failed to update alerts: "+e,20)}h.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,"slack"),className:"mx-2",children:"Test Alerts"})]})})]})]})}),(0,r.jsx)(en.Z,{title:"Add Callback",visible:d,onOk:N,width:800,onCancel:()=>{m(!1),u.resetFields(),p(null)},footer:null,children:(0,r.jsxs)(er.Z,{form:u,layout:"vertical",onFinish:N,children:[(0,r.jsx)(er.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(ea.default,{onChange:e=>{p(e)},children:(0,r.jsx)(ea.default.Option,{value:"langfuse",children:"langfuse"})})}),"langfuse"===x&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)($.Z,{type:"password"})}),(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)($.Z,{type:"password"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null};let{Option:ls}=ea.default;var la=e=>{let{models:l,accessToken:t,routerSettings:s,setRouterSettings:a}=e,[o]=er.Z.useForm(),[i,c]=(0,n.useState)(!1),[d,m]=(0,n.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(en.Z,{title:"Add Fallbacks",visible:i,width:800,footer:null,onOk:()=>{c(!1),o.resetFields()},onCancel:()=>{c(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,n=[...s.fallbacks||[],{[l]:r}],i={...s,fallbacks:n};console.log(i);try{G(t,{router_settings:i}),a(i)}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully"),c(!1),o.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eA.Z,{defaultValue:d,children:l&&l.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(eK.Z,{value:l,children:l&&l.filter(e=>e!=d).map(e=>(0,r.jsx)(eV.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lr=t(12968);async function ln(e,l){console.log("isLocal:",!1);let t=window.location.origin,s=new lr.ZP.OpenAI({apiKey:l,baseURL:t,dangerouslyAllowBrowser:!0});try{let l=await s.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});h.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lo=e=>{let{accessToken:l,userRole:t,userID:s,modelData:a}=e,[o,i]=(0,n.useState)({}),[c,d]=(0,n.useState)(!1),[m]=er.Z.useForm(),[u,x]=(0,n.useState)(null),p={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),i(e.router_settings)})},[l,t,s]);let j=async e=>{if(l){console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(o.fallbacks)),o.fallbacks.map(l=>(e in l&&delete l[e],l));try{await G(l,{router_settings:o}),i({...o}),h.ZP.success("Router settings updated successfully")}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}}},g=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).map(e=>{let[l,t]=e;if("routing_strategy_args"!==l){var s;return[l,(null===(s=document.querySelector('input[name="'.concat(l,'"]')))||void 0===s?void 0:s.value)||t]}return null}).filter(e=>null!==e));console.log("updatedVariables",t);try{G(l,{router_settings:t})}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"General Settings"}),(0,r.jsx)(eU.Z,{value:"2",children:"Fallbacks"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(et.Z,{children:"Router Settings"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Setting"}),(0,r.jsx)(ev.Z,{children:"Value"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(o).filter(e=>{let[l,t]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l}).map(e=>{let[l,t]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(el.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:p[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(J.Z,{children:(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>g(o),children:"Save Changes"})})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Model Name"}),(0,r.jsx)(ev.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(eb.Z,{children:o.fallbacks&&o.fallbacks.map((e,t)=>Object.entries(e).map(e=>{let[s,a]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:s}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(H.Z,{onClick:()=>ln(s,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(eZ.Z,{icon:ex.Z,size:"sm",onClick:()=>j(s)})})]},t.toString()+s)}))})]}),(0,r.jsx)(la,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:o,setRouterSettings:i})]})]})]})}):null},li=t(67951),lc=e=>{let{}=e;return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(el.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eU.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eU.Z,{children:"LlamaIndex"}),(0,r.jsx)(eU.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n '})}),(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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:4000",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})]})})})};async function ld(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new lr.ZP.OpenAI({apiKey:s,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let s of(await r.chat.completions.create({model:t,stream:!0,messages:[{role:"user",content:e}]})))console.log(s),s.choices[0].delta.content&&l(s.choices[0].delta.content)}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lm=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,[o,i]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[m,h]=(0,n.useState)([]),[u,x]=(0,n.useState)(void 0),[p,j]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{let e=await v(l,a,s);if(console.log("model_info:",e),(null==e?void 0:e.data.length)>0){let l=e.data.map(e=>({value:e.id,label:e.id}));console.log(l),j(l),x(e.data[0].id)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,s]);let g=(e,l)=>{h(t=>{let s=t[t.length-1];return s&&s.role===e?[...t.slice(0,t.length-1),{role:e,content:s.content+l}]:[...t,{role:e,content:l}]})},f=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await ld(c,e=>g("assistant",e),u,o)}catch(e){console.error("Error fetching model response",e),g("assistant","Error fetching model response")}d("")}};if(s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsx)(ez.Z,{children:(0,r.jsx)(eU.Z,{children:"Chat"})}),(0,r.jsx)(eq.Z,{children:(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(Y.Z,{numItems:2,children:[(0,r.jsxs)(J.Z,{children:[(0,r.jsx)(el.Z,{children:"API Key"}),(0,r.jsx)($.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(J.Z,{className:"mx-2",children:[(0,r.jsx)(el.Z,{children:"Select Model:"}),(0,r.jsx)(ea.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ew.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ek.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsx)(eb.Z,{children:m.map((e,l)=>(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{children:"".concat(e.role,": ").concat(e.content)})},l))})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)($.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(H.Z,{onClick:f,className:"ml-2",children:"Send"})]})})]})})]})})})})},lh=t(33509),lu=t(95781);let{Sider:lx}=lh.default;var lp=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lx,{width:120,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"145px"},children:(0,r.jsx)(lx,{width:145,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(el.Z,{children:"API Keys"})},"1"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(el.Z,{children:"Test Key"})},"3"),"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(el.Z,{children:"Models"})},"2"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(el.Z,{children:"Usage"})},"4"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(el.Z,{children:"Teams"})},"6"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(el.Z,{children:"Users"})},"5"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(el.Z,{children:"Logging & Alerts"})},"8"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(el.Z,{children:"Router Settings"})},"9"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(el.Z,{children:"Admin"})},"7"):null,(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api_ref"),children:(0,r.jsx)(el.Z,{children:"API Reference"})},"11")]})})})},lj=t(67989),lg=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,o=new Date,[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)([]),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)([]),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)([]),[Z,w]=(0,n.useState)([]),[b,v]=(0,n.useState)([]),[S,T]=(0,n.useState)([]),[O,M]=(0,n.useState)([]),[R,L]=(0,n.useState)([]),[U,D]=(0,n.useState)(null),z=new Date(o.getFullYear(),o.getMonth(),1),B=new Date(o.getFullYear(),o.getMonth()+1,0),q=V(z),K=V(B);function V(e){let l=e.getFullYear(),t=e.getMonth()+1,s=e.getDate();return"".concat(l,"-").concat(t<10?"0"+t:t,"-").concat(s<10?"0"+s:s)}console.log("Start date is ".concat(q)),console.log("End date is ".concat(K)),(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{if(console.log("user role: ".concat(s)),"Admin"==s||"Admin Viewer"==s){let e=await I(l);c(e);let t=(await P(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let r=(await E(l)).map(e=>({key:e.model,spend:e.total_spend}));u(r);let n=await A(l);console.log("teamSpend",n),g(n.daily_spend),w(n.teams);let o=n.total_spend_per_team;o=o.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),v(o);let i=await N(l);y(i.top_10_tags);let d=(await _(l,a,s)).data;console.log("model groups in model dashboard",d);let h=[];for(let e=0;e{if(console.log("result from spend logs call",e),"daily_spend"in e){let l=e.daily_spend;console.log("daily spend",l),c(l);let t=e.top_api_keys;m(t)}else{let t=(await F(l,function(e){let l=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[t,s]=e;"spend"!==t&&"startTime"!==t&&"models"!==t&&"users"!==t&&l.push({key:t,spend:s})})}),l.sort((e,l)=>Number(l.spend)-Number(e.spend));let t=l.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(t[0]))),t}(e))).info.map(e=>({key:(e.key_name||e.key_alias).substring(0,10),spend:e.spend}));m(t),p(function(e){let l={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[t,s]=e;""!==t&&null!=t&&"None"!=t&&(l[t]||(l[t]=0),l[t]+=s)})});let t=Object.entries(l).map(e=>{let[l,t]=e;return{user_id:l,spend:t}});t.sort((e,l)=>l.spend-e.spend);let s=t.slice(0,5);return console.log("topKeys: ".concat(Object.values(s[0]))),s}(e)),c(e)}});let e=await k(l,a,s,null);console.log("Model metrics response:",e);let r=[...e].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(e),M(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,q,K]);let G=async e=>{if(console.log("Updating model metrics for group:",e),l&&a&&s){D(e);try{let t=await k(l,a,s,e);console.log("Model metrics response:",t);let r=[...t].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(t),M(r)}catch(e){console.error("Failed to fetch model metrics",e)}}};return(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(eE,{userID:a,userRole:s,accessToken:l,userSpend:null,selectedTeam:null}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{className:"mt-2",children:[(0,r.jsx)(eU.Z,{children:"All Up"}),(0,r.jsx)(eU.Z,{children:"Team Based Usage"}),(0,r.jsx)(eU.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eU.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Monthly Spend"}),(0,r.jsx)(ej.Z,{data:i,index:"date",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top API Keys"}),(0,r.jsx)(ej.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,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Users"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:x,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Models"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(J.Z,{numColSpan:2,children:[(0,r.jsxs)(eg.Z,{className:"mb-2",children:[(0,r.jsx)(et.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(lj.Z,{data:b})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(ej.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:Z,yAxisWidth:80,colors:["blue","green","yellow","red","purple"],stack:!0})]})]}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(el.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/enterprise#tracking-spend-for-custom-tags",target:"_blank",children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Tag"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Requests"})]})}),(0,r.jsx)(eb.Z,{children:f.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.name}),(0,r.jsx)(e_.Z,{children:e.value}),(0,r.jsx)(e_.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)(et.Z,{children:"Filter By Model Group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080"},children:"View how requests were load balanced within a model group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080",fontStyle:"italic"},children:"(Beta feature) only supported for Azure Model Groups"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2",defaultValue:"all",children:[(0,r.jsx)(eN.Z,{value:"all",onClick:()=>G(null),children:"All Model Groups"}),R.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>G(e),children:e},l))]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Number Requests per Model"}),(0,r.jsx)(ej.Z,{data:S,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(eg.Z,{className:"mt-4",children:[(0,r.jsx)(et.Z,{children:"Latency Per Model"}),(0,r.jsx)(ej.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},lf=()=>{let{Title:e,Paragraph:l}=eR.default,[t,s]=(0,n.useState)(""),[a,i]=(0,n.useState)(null),[c,d]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(!0),j=(0,o.useSearchParams)(),[g,f]=(0,n.useState)({data:[]}),y=j.get("userID"),Z=j.get("token"),[w,b]=(0,n.useState)("api-keys"),[_,k]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(Z){let e=(0,eM.o)(Z);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),k(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&b("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))}}},[Z]),(0,r.jsx)(n.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(m,{userID:y,userRole:t,userEmail:a,showSSOBanner:x}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(lp,{setPage:b,userRole:t,defaultSelectedKey:null})}),"api-keys"==w?(0,r.jsx)(eL,{userID:y,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==w?(0,r.jsx)(e8,{userID:y,userRole:t,token:Z,accessToken:_,modelData:g,setModelData:f}):"llm-playground"==w?(0,r.jsx)(lm,{userID:y,userRole:t,token:Z,accessToken:_}):"users"==w?(0,r.jsx)(e6,{userID:y,userRole:t,token:Z,keys:h,teams:c,accessToken:_,setKeys:u}):"teams"==w?(0,r.jsx)(e7,{teams:c,setTeams:d,searchParams:j,accessToken:_,userID:y,userRole:t}):"admin-panel"==w?(0,r.jsx)(le,{setTeams:d,searchParams:j,accessToken:_,showSSOBanner:x}):"api_ref"==w?(0,r.jsx)(lc,{}):"settings"==w?(0,r.jsx)(lt,{userID:y,userRole:t,accessToken:_}):"general-settings"==w?(0,r.jsx)(lo,{userID:y,userRole:t,accessToken:_,modelData:g}):(0,r.jsx)(lg,{userID:y,userRole:t,token:Z,accessToken:_})]})]})})}}},function(e){e.O(0,[447,971,69,744],function(){return e(e.s=20661)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/index.html b/litellm/proxy/_experimental/out/index.html index cb197f11e..0dbd09152 100644 --- a/litellm/proxy/_experimental/out/index.html +++ b/litellm/proxy/_experimental/out/index.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/litellm/proxy/_experimental/out/index.txt b/litellm/proxy/_experimental/out/index.txt index 267d8e5ba..70ccce541 100644 --- a/litellm/proxy/_experimental/out/index.txt +++ b/litellm/proxy/_experimental/out/index.txt @@ -1,7 +1,7 @@ 2:I[77831,[],""] -3:I[27125,["447","static/chunks/447-9f8d32190ff7d16d.js","931","static/chunks/app/page-781ca5f151d78d1d.js"],""] +3:I[27125,["447","static/chunks/447-9f8d32190ff7d16d.js","931","static/chunks/app/page-508c39694bd40fe9.js"],""] 4:I[5613,[],""] 5:I[31778,[],""] -0:["PtTtxXIYvdjQsvRgdITlk",[[["",{"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/5e699db73bf6f8c2.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] +0:["kbGdRQFfI6W3bEwfzmJDI",[[["",{"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/5e699db73bf6f8c2.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 Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/litellm/proxy/_super_secret_config.yaml b/litellm/proxy/_super_secret_config.yaml index 2e8183cb2..0e1b4b2e1 100644 --- a/litellm/proxy/_super_secret_config.yaml +++ b/litellm/proxy/_super_secret_config.yaml @@ -4,5 +4,20 @@ model_list: api_key: my-fake-key model: openai/my-fake-model model_name: fake-openai-endpoint +- litellm_params: + api_base: http://0.0.0.0:8080 + api_key: my-fake-key + model: openai/my-fake-model-2 + model_name: fake-openai-endpoint +- litellm_params: + api_base: http://0.0.0.0:8080 + api_key: my-fake-key + model: openai/my-fake-model-3 + model_name: fake-openai-endpoint +- litellm_params: + api_base: http://0.0.0.0:8080 + api_key: my-fake-key + model: openai/my-fake-model-4 + model_name: fake-openai-endpoint router_settings: num_retries: 0 \ No newline at end of file diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index c037190d3..a393ec90a 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -95,7 +95,15 @@ def common_checks( f"'user' param not passed in. 'enforce_user_param'={general_settings['enforce_user_param']}" ) # 7. [OPTIONAL] If 'litellm.max_budget' is set (>0), is proxy under budget - if litellm.max_budget > 0 and global_proxy_spend is not None: + if ( + litellm.max_budget > 0 + and global_proxy_spend is not None + # only run global budget checks for OpenAI routes + # Reason - the Admin UI should continue working if the proxy crosses it's global budget + and route in LiteLLMRoutes.openai_routes.value + and route != "/v1/models" + and route != "/models" + ): if global_proxy_spend > litellm.max_budget: raise Exception( f"ExceededBudget: LiteLLM Proxy has exceeded its budget. Current spend: {global_proxy_spend}; Max Budget: {litellm.max_budget}" diff --git a/litellm/router.py b/litellm/router.py index be20f5d2b..23618123f 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -72,7 +72,9 @@ class Router: ## RELIABILITY ## num_retries: Optional[int] = None, timeout: Optional[float] = None, - default_litellm_params={}, # default params for Router.chat.completion.create + default_litellm_params: Optional[ + dict + ] = None, # default params for Router.chat.completion.create default_max_parallel_requests: Optional[int] = None, set_verbose: bool = False, debug_level: Literal["DEBUG", "INFO"] = "INFO", @@ -158,6 +160,7 @@ class Router: router = Router(model_list=model_list, fallbacks=[{"azure-gpt-3.5-turbo": "openai-gpt-3.5-turbo"}]) ``` """ + if semaphore: self.semaphore = semaphore self.set_verbose = set_verbose @@ -260,6 +263,7 @@ class Router: ) # dict to store aliases for router, ex. {"gpt-4": "gpt-3.5-turbo"}, all requests with gpt-4 -> get routed to gpt-3.5-turbo group # make Router.chat.completions.create compatible for openai.chat.completions.create + default_litellm_params = default_litellm_params or {} self.chat = litellm.Chat(params=default_litellm_params, router_obj=self) # default litellm args @@ -475,6 +479,7 @@ class Router: ) kwargs["model_info"] = deployment.get("model_info", {}) data = deployment["litellm_params"].copy() + model_name = data["model"] for k, v in self.default_litellm_params.items(): if ( @@ -1453,6 +1458,7 @@ class Router: await asyncio.sleep(timeout) elif RouterErrors.user_defined_ratelimit_error.value in str(e): raise e # don't wait to retry if deployment hits user-defined rate-limit + elif hasattr(original_exception, "status_code") and litellm._should_retry( status_code=original_exception.status_code ): @@ -1614,6 +1620,28 @@ class Router: raise e raise original_exception + def _router_should_retry( + self, e: Exception, remaining_retries: int, num_retries: int + ): + """ + Calculate back-off, then retry + """ + if hasattr(e, "response") and hasattr(e.response, "headers"): + timeout = litellm._calculate_retry_after( + remaining_retries=remaining_retries, + max_retries=num_retries, + response_headers=e.response.headers, + min_timeout=self.retry_after, + ) + time.sleep(timeout) + else: + timeout = litellm._calculate_retry_after( + remaining_retries=remaining_retries, + max_retries=num_retries, + min_timeout=self.retry_after, + ) + time.sleep(timeout) + def function_with_retries(self, *args, **kwargs): """ Try calling the model 3 times. Shuffle between available deployments. @@ -1633,9 +1661,6 @@ class Router: return response except Exception as e: original_exception = e - verbose_router_logger.debug( - f"num retries in function with retries: {num_retries}" - ) ### CHECK IF RATE LIMIT / CONTEXT WINDOW ERROR if ( isinstance(original_exception, litellm.ContextWindowExceededError) @@ -1649,6 +1674,11 @@ class Router: if num_retries > 0: kwargs = self.log_retry(kwargs=kwargs, e=original_exception) ### RETRY + self._router_should_retry( + e=original_exception, + remaining_retries=num_retries, + num_retries=num_retries, + ) for current_attempt in range(num_retries): verbose_router_logger.debug( f"retrying request. Current attempt - {current_attempt}; retries left: {num_retries}" @@ -1662,34 +1692,11 @@ class Router: ## LOGGING kwargs = self.log_retry(kwargs=kwargs, e=e) remaining_retries = num_retries - current_attempt - if "No models available" in str(e): - timeout = litellm._calculate_retry_after( - remaining_retries=remaining_retries, - max_retries=num_retries, - min_timeout=self.retry_after, - ) - time.sleep(timeout) - elif ( - hasattr(e, "status_code") - and hasattr(e, "response") - and litellm._should_retry(status_code=e.status_code) - ): - if hasattr(e.response, "headers"): - timeout = litellm._calculate_retry_after( - remaining_retries=remaining_retries, - max_retries=num_retries, - response_headers=e.response.headers, - min_timeout=self.retry_after, - ) - else: - timeout = litellm._calculate_retry_after( - remaining_retries=remaining_retries, - max_retries=num_retries, - min_timeout=self.retry_after, - ) - time.sleep(timeout) - else: - raise e + self._router_should_retry( + e=e, + remaining_retries=remaining_retries, + num_retries=num_retries, + ) raise original_exception ### HELPER FUNCTIONS @@ -1987,6 +1994,8 @@ class Router: # check if it ends with a trailing slash if api_base.endswith("/"): api_base += "v1/" + elif api_base.endswith("/v1"): + api_base += "/" else: api_base += "/v1/" diff --git a/litellm/tests/test_acooldowns_router.py b/litellm/tests/test_acooldowns_router.py index 28573d5be..7dced31a8 100644 --- a/litellm/tests/test_acooldowns_router.py +++ b/litellm/tests/test_acooldowns_router.py @@ -119,7 +119,9 @@ def test_multiple_deployments_parallel(): # test_multiple_deployments_parallel() -def test_cooldown_same_model_name(): +@pytest.mark.parametrize("sync_mode", [True, False]) +@pytest.mark.asyncio +async def test_cooldown_same_model_name(sync_mode): # users could have the same model with different api_base # example # azure/chatgpt, api_base: 1234 @@ -161,22 +163,40 @@ def test_cooldown_same_model_name(): num_retries=3, ) # type: ignore - response = router.completion( - model="gpt-3.5-turbo", - messages=[{"role": "user", "content": "hello this request will pass"}], - ) - print(router.model_list) - model_ids = [] - for model in router.model_list: - model_ids.append(model["model_info"]["id"]) - print("\n litellm model ids ", model_ids) + if sync_mode: + response = router.completion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "hello this request will pass"}], + ) + print(router.model_list) + model_ids = [] + for model in router.model_list: + model_ids.append(model["model_info"]["id"]) + print("\n litellm model ids ", model_ids) - # example litellm_model_names ['azure/chatgpt-v-2-ModelID-64321', 'azure/chatgpt-v-2-ModelID-63960'] - assert ( - model_ids[0] != model_ids[1] - ) # ensure both models have a uuid added, and they have different names + # example litellm_model_names ['azure/chatgpt-v-2-ModelID-64321', 'azure/chatgpt-v-2-ModelID-63960'] + assert ( + model_ids[0] != model_ids[1] + ) # ensure both models have a uuid added, and they have different names - print("\ngot response\n", response) + print("\ngot response\n", response) + else: + response = await router.acompletion( + model="gpt-3.5-turbo", + messages=[{"role": "user", "content": "hello this request will pass"}], + ) + print(router.model_list) + model_ids = [] + for model in router.model_list: + model_ids.append(model["model_info"]["id"]) + print("\n litellm model ids ", model_ids) + + # example litellm_model_names ['azure/chatgpt-v-2-ModelID-64321', 'azure/chatgpt-v-2-ModelID-63960'] + assert ( + model_ids[0] != model_ids[1] + ) # ensure both models have a uuid added, and they have different names + + print("\ngot response\n", response) except Exception as e: pytest.fail(f"Got unexpected exception on router! - {e}") diff --git a/litellm/tests/test_embedding.py b/litellm/tests/test_embedding.py index e9a86997b..69ddb39ff 100644 --- a/litellm/tests/test_embedding.py +++ b/litellm/tests/test_embedding.py @@ -483,6 +483,8 @@ def test_mistral_embeddings(): except Exception as e: pytest.fail(f"Error occurred: {e}") + +@pytest.mark.skip(reason="local test") def test_watsonx_embeddings(): try: litellm.set_verbose = True diff --git a/litellm/tests/test_least_busy_routing.py b/litellm/tests/test_least_busy_routing.py index 782d5b343..cb9d59e75 100644 --- a/litellm/tests/test_least_busy_routing.py +++ b/litellm/tests/test_least_busy_routing.py @@ -201,6 +201,7 @@ async def test_router_atext_completion_streaming(): @pytest.mark.asyncio async def test_router_completion_streaming(): + litellm.set_verbose = True messages = [ {"role": "user", "content": "Hello, can you generate a 500 words poem?"} ] @@ -219,9 +220,9 @@ async def test_router_completion_streaming(): { "model_name": "azure-model", "litellm_params": { - "model": "azure/gpt-35-turbo", - "api_key": "os.environ/AZURE_EUROPE_API_KEY", - "api_base": "https://my-endpoint-europe-berri-992.openai.azure.com", + "model": "azure/gpt-turbo", + "api_key": "os.environ/AZURE_FRANCE_API_KEY", + "api_base": "https://openai-france-1234.openai.azure.com", "rpm": 6, }, "model_info": {"id": 2}, @@ -229,9 +230,9 @@ async def test_router_completion_streaming(): { "model_name": "azure-model", "litellm_params": { - "model": "azure/gpt-35-turbo", - "api_key": "os.environ/AZURE_CANADA_API_KEY", - "api_base": "https://my-endpoint-canada-berri992.openai.azure.com", + "model": "azure/gpt-turbo", + "api_key": "os.environ/AZURE_FRANCE_API_KEY", + "api_base": "https://openai-france-1234.openai.azure.com", "rpm": 6, }, "model_info": {"id": 3}, @@ -262,4 +263,4 @@ async def test_router_completion_streaming(): ## check if calls equally distributed cache_dict = router.cache.get_cache(key=cache_key) for k, v in cache_dict.items(): - assert v == 1 + assert v == 1, f"Failed. K={k} called v={v} times, cache_dict={cache_dict}" diff --git a/litellm/tests/test_router.py b/litellm/tests/test_router.py index 8659b5d66..7520ac75f 100644 --- a/litellm/tests/test_router.py +++ b/litellm/tests/test_router.py @@ -57,6 +57,7 @@ def test_router_num_retries_init(num_retries, max_retries): else: assert getattr(model_client, "max_retries") == 0 + @pytest.mark.parametrize( "timeout", [10, 1.0, httpx.Timeout(timeout=300.0, connect=20.0)] ) @@ -137,6 +138,7 @@ def test_router_azure_ai_studio_init(mistral_api_base): print(f"uri_reference: {uri_reference}") assert "/v1/" in uri_reference + assert uri_reference.count("v1") == 1 def test_exception_raising(): diff --git a/litellm/tests/test_router_init.py b/litellm/tests/test_router_init.py index 862d7e965..f0f0cc541 100644 --- a/litellm/tests/test_router_init.py +++ b/litellm/tests/test_router_init.py @@ -203,7 +203,7 @@ def test_timeouts_router(): }, }, ] - router = Router(model_list=model_list) + router = Router(model_list=model_list, num_retries=0) print("PASSED !") @@ -396,7 +396,9 @@ def test_router_init_gpt_4_vision_enhancements(): pytest.fail(f"Error occurred: {e}") -def test_openai_with_organization(): +@pytest.mark.parametrize("sync_mode", [True, False]) +@pytest.mark.asyncio +async def test_openai_with_organization(sync_mode): try: print("Testing OpenAI with organization") model_list = [ @@ -418,32 +420,65 @@ def test_openai_with_organization(): print(router.model_list) print(router.model_list[0]) - openai_client = router._get_client( - deployment=router.model_list[0], - kwargs={"input": ["hello"], "model": "openai-bad-org"}, - ) - print(vars(openai_client)) - - assert openai_client.organization == "org-ikDc4ex8NB" - - # bad org raises error - - try: - response = router.completion( - model="openai-bad-org", - messages=[{"role": "user", "content": "this is a test"}], + if sync_mode: + openai_client = router._get_client( + deployment=router.model_list[0], + kwargs={"input": ["hello"], "model": "openai-bad-org"}, ) - pytest.fail("Request should have failed - This organization does not exist") - except Exception as e: - print("Got exception: " + str(e)) - assert "No such organization: org-ikDc4ex8NB" in str(e) + print(vars(openai_client)) - # good org works - response = router.completion( - model="openai-good-org", - messages=[{"role": "user", "content": "this is a test"}], - max_tokens=5, - ) + assert openai_client.organization == "org-ikDc4ex8NB" + + # bad org raises error + + try: + response = router.completion( + model="openai-bad-org", + messages=[{"role": "user", "content": "this is a test"}], + ) + pytest.fail( + "Request should have failed - This organization does not exist" + ) + except Exception as e: + print("Got exception: " + str(e)) + assert "No such organization: org-ikDc4ex8NB" in str(e) + + # good org works + response = router.completion( + model="openai-good-org", + messages=[{"role": "user", "content": "this is a test"}], + max_tokens=5, + ) + else: + openai_client = router._get_client( + deployment=router.model_list[0], + kwargs={"input": ["hello"], "model": "openai-bad-org"}, + client_type="async", + ) + print(vars(openai_client)) + + assert openai_client.organization == "org-ikDc4ex8NB" + + # bad org raises error + + try: + response = await router.acompletion( + model="openai-bad-org", + messages=[{"role": "user", "content": "this is a test"}], + ) + pytest.fail( + "Request should have failed - This organization does not exist" + ) + except Exception as e: + print("Got exception: " + str(e)) + assert "No such organization: org-ikDc4ex8NB" in str(e) + + # good org works + response = await router.acompletion( + model="openai-good-org", + messages=[{"role": "user", "content": "this is a test"}], + max_tokens=5, + ) except Exception as e: pytest.fail(f"Error occurred: {e}") diff --git a/litellm/tests/test_router_timeout.py b/litellm/tests/test_router_timeout.py index dff30113b..1126f6fb8 100644 --- a/litellm/tests/test_router_timeout.py +++ b/litellm/tests/test_router_timeout.py @@ -57,6 +57,7 @@ def test_router_timeouts(): redis_password=os.getenv("REDIS_PASSWORD"), redis_port=int(os.getenv("REDIS_PORT")), timeout=10, + num_retries=0, ) print("***** TPM SETTINGS *****") @@ -89,15 +90,15 @@ def test_router_timeouts(): @pytest.mark.asyncio async def test_router_timeouts_bedrock(): - import openai + import openai, uuid # Model list for OpenAI and Anthropic models - model_list = [ + _model_list = [ { "model_name": "bedrock", "litellm_params": { "model": "bedrock/anthropic.claude-instant-v1", - "timeout": 0.001, + "timeout": 0.00001, }, "tpm": 80000, }, @@ -105,17 +106,18 @@ async def test_router_timeouts_bedrock(): # Configure router router = Router( - model_list=model_list, + model_list=_model_list, routing_strategy="usage-based-routing", debug_level="DEBUG", set_verbose=True, + num_retries=0, ) litellm.set_verbose = True try: response = await router.acompletion( model="bedrock", - messages=[{"role": "user", "content": "hello, who are u"}], + messages=[{"role": "user", "content": f"hello, who are u {uuid.uuid4()}"}], ) print(response) pytest.fail("Did not raise error `openai.APITimeoutError`") diff --git a/litellm/utils.py b/litellm/utils.py index 0cf4f9f16..045506b22 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -5482,17 +5482,21 @@ def get_optional_params( optional_params["random_seed"] = seed if stop is not None: optional_params["stop_sequences"] = stop - + # WatsonX-only parameters extra_body = {} if "decoding_method" in passed_params: extra_body["decoding_method"] = passed_params.pop("decoding_method") - if "min_tokens" in passed_params or "min_new_tokens" in passed_params: - extra_body["min_new_tokens"] = passed_params.pop("min_tokens", passed_params.pop("min_new_tokens")) + if "min_tokens" in passed_params or "min_new_tokens" in passed_params: + extra_body["min_new_tokens"] = passed_params.pop( + "min_tokens", passed_params.pop("min_new_tokens") + ) if "top_k" in passed_params: extra_body["top_k"] = passed_params.pop("top_k") if "truncate_input_tokens" in passed_params: - extra_body["truncate_input_tokens"] = passed_params.pop("truncate_input_tokens") + extra_body["truncate_input_tokens"] = passed_params.pop( + "truncate_input_tokens" + ) if "length_penalty" in passed_params: extra_body["length_penalty"] = passed_params.pop("length_penalty") if "time_limit" in passed_params: @@ -5500,7 +5504,7 @@ def get_optional_params( if "return_options" in passed_params: extra_body["return_options"] = passed_params.pop("return_options") optional_params["extra_body"] = ( - extra_body # openai client supports `extra_body` param + extra_body # openai client supports `extra_body` param ) else: # assume passing in params for openai/azure openai print_verbose( @@ -9829,7 +9833,7 @@ class CustomStreamWrapper: "is_finished": chunk["is_finished"], "finish_reason": finish_reason, } - + def handle_watsonx_stream(self, chunk): try: if isinstance(chunk, dict): @@ -9837,19 +9841,21 @@ class CustomStreamWrapper: elif isinstance(chunk, (str, bytes)): if isinstance(chunk, bytes): chunk = chunk.decode("utf-8") - if 'generated_text' in chunk: - response = chunk.replace('data: ', '').strip() + if "generated_text" in chunk: + response = chunk.replace("data: ", "").strip() parsed_response = json.loads(response) else: return {"text": "", "is_finished": False} else: print_verbose(f"chunk: {chunk} (Type: {type(chunk)})") - raise ValueError(f"Unable to parse response. Original response: {chunk}") + raise ValueError( + f"Unable to parse response. Original response: {chunk}" + ) results = parsed_response.get("results", []) if len(results) > 0: text = results[0].get("generated_text", "") finish_reason = results[0].get("stop_reason") - is_finished = finish_reason != 'not_finished' + is_finished = finish_reason != "not_finished" return { "text": text, "is_finished": is_finished, @@ -10119,16 +10125,6 @@ class CustomStreamWrapper: elif self.custom_llm_provider == "watsonx": response_obj = self.handle_watsonx_stream(chunk) completion_obj["content"] = response_obj["text"] - print_verbose(f"completion obj content: {completion_obj['content']}") - if response_obj.get("prompt_tokens") is not None: - prompt_token_count = getattr(model_response.usage, "prompt_tokens", 0) - model_response.usage.prompt_tokens = (prompt_token_count+response_obj["prompt_tokens"]) - if response_obj.get("completion_tokens") is not None: - model_response.usage.completion_tokens = response_obj["completion_tokens"] - model_response.usage.total_tokens = ( - getattr(model_response.usage, "prompt_tokens", 0) - + getattr(model_response.usage, "completion_tokens", 0) - ) if response_obj["is_finished"]: self.received_finish_reason = response_obj["finish_reason"] elif self.custom_llm_provider == "text-completion-openai": diff --git a/pyproject.toml b/pyproject.toml index 2bd77b6c9..ae09ad3cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "1.35.30" +version = "1.35.31" description = "Library to easily interface with LLM API providers" authors = ["BerriAI"] license = "MIT" @@ -80,7 +80,7 @@ requires = ["poetry-core", "wheel"] build-backend = "poetry.core.masonry.api" [tool.commitizen] -version = "1.35.30" +version = "1.35.31" version_files = [ "pyproject.toml:^version" ] diff --git a/ui/litellm-dashboard/out/404.html b/ui/litellm-dashboard/out/404.html index 310a90e22..6d3d33c80 100644 --- a/ui/litellm-dashboard/out/404.html +++ b/ui/litellm-dashboard/out/404.html @@ -1 +1 @@ -404: This page could not be found.LiteLLM Dashboard

404

This page could not be found.

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

404

This page could not be found.

\ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-508c39694bd40fe9.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-508c39694bd40fe9.js new file mode 100644 index 000000000..290d55662 --- /dev/null +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/page-508c39694bd40fe9.js @@ -0,0 +1 @@ +(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{20661:function(e,l,t){Promise.resolve().then(t.bind(t,27125))},27125:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return lf}});var s,a,r=t(3827),n=t(64090),o=t(47907),i=t(8792),c=t(40491),d=t(65270),m=e=>{let{userID:l,userRole:t,userEmail:s,showSSOBanner:a}=e;console.log("User ID:",l),console.log("userEmail:",s),console.log("showSSOBanner:",a);let n=[{key:"1",label:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("p",{children:["Role: ",t]}),(0,r.jsxs)("p",{children:["ID: ",l]})]})}];return(0,r.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,r.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,r.jsx)("div",{className:"flex flex-col items-center",children:(0,r.jsx)(i.default,{href:"/",children:(0,r.jsx)("button",{className:"text-gray-800 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:160,height:160,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,r.jsxs)("div",{className:"text-right mx-4 my-2 absolute top-0 right-0 flex items-center justify-end space-x-2",children:[a?(0,r.jsx)("div",{style:{padding:"6px",borderRadius:"8px"},children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",style:{fontSize:"14px",textDecoration:"underline"},children:"Request hosted proxy"})}):null,(0,r.jsx)("div",{style:{border:"1px solid #391085",padding:"6px",borderRadius:"8px"},children:(0,r.jsx)(c.Z,{menu:{items:n},children:(0,r.jsx)(d.Z,{children:s})})})]})]})},h=t(80588);let u=async()=>{try{let e=await fetch("https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"),l=await e.json();return console.log("received data: ".concat(l)),l}catch(e){throw console.error("Failed to get model cost map:",e),e}},x=async(e,l)=>{try{let t=await fetch("/model/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model created successfully. Wait 60s and refresh on 'All Models' page"),s}catch(e){throw console.error("Failed to create key:",e),e}},p=async(e,l)=>{console.log("model_id in model delete call: ".concat(l));try{let t=await fetch("/model/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model deleted successfully. Restart server to see this."),s}catch(e){throw console.error("Failed to create key:",e),e}},j=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},g=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},f=async(e,l)=>{try{console.log("in keyDeleteCall:",l);let t=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},y=async(e,l)=>{try{console.log("in teamDeleteCall:",l);let t=await fetch("/team/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete team: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to delete key:",e),e}},Z=async function(e,l,t){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0;try{let n="/user/info";"App Owner"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),"App User"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),console.log("in userInfoCall viewAll=",s),s&&r&&null!=a&&void 0!=a&&(n="".concat(n,"?view_all=true&page=").concat(a,"&page_size=").concat(r));let o=await fetch(n,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let i=await o.json();return console.log("API Response:",i),i}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,l)=>{try{let t="/team/info";l&&(t="".concat(t,"?team_id=").concat(l)),console.log("in teamInfoCall");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 h.ZP.error(e,20),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}},b=async e=>{try{let l=await fetch("/global/spend",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},_=async(e,l,t)=>{try{let l=await fetch("/v2/model/info",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log("modelInfoCall:",t),t}catch(e){throw console.error("Failed to create key:",e),e}},k=async(e,l,t,s)=>{try{let l="/model/metrics";s&&(l="".concat(l,"?_selected_model_group=").concat(s));let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},v=async(e,l,t)=>{try{let l=await fetch("/models",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},S=async(e,l)=>{try{let t="/global/spend/logs";console.log("in keySpendLogsCall:",t);let s=await fetch("".concat(t,"?api_key=").concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},A=async e=>{try{let l="/global/spend/teams";console.log("in teamSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},N=async e=>{try{let l="/global/spend/tags";console.log("in tagsSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},C=async(e,l,t,s,a,r)=>{try{console.log("user role in spend logs call: ".concat(t));let l="/spend/logs";l="App Owner"==t?"".concat(l,"?user_id=").concat(s,"&start_date=").concat(a,"&end_date=").concat(r):"".concat(l,"?start_date=").concat(a,"&end_date=").concat(r);let n=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.text();throw h.ZP.error(e,20),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}},I=async e=>{try{let l=await fetch("/global/spend/logs",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},P=async e=>{try{let l=await fetch("/global/spend/keys?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},T=async(e,l)=>{try{l&&JSON.stringify({api_key:l});let t={method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}};l&&(t.body=JSON.stringify({api_key:l}));let s=await fetch("/global/spend/end_users",t);if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},E=async e=>{try{let l=await fetch("/global/spend/models?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},F=async(e,l)=>{try{let t=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},O=async e=>{try{let l="/user/get_requests";console.log("in userGetRequesedtModelsCall:",l);let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to get requested models:",e),e}},M=async(e,l)=>{try{let t="/user/get_users?role=".concat(l);console.log("in userGetAllUsersCall:",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 h.ZP.error("Failed to delete key: "+e,20),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}},R=async(e,l)=>{try{console.log("Form Values in teamCreateCall:",l);let t=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},L=async(e,l)=>{try{console.log("Form Values in keyUpdateCall:",l);let t=await fetch("/key/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update key Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},U=async(e,l)=>{try{console.log("Form Values in teamUpateCall:",l);let t=await fetch("/team/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update team: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update Team Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},D=async(e,l)=>{try{console.log("Form Values in modelUpateCall:",l);let t=await fetch("/model/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update model: "+e,20),console.error("Error update from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update model Response:",s),s}catch(e){throw console.error("Failed to update model:",e),e}},z=async(e,l,t)=>{try{console.log("Form Values in teamMemberAddCall:",t);let s=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:l,member:t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},B=async(e,l,t)=>{try{console.log("Form Values in userUpdateUserCall:",l);let s={...l};null!==t&&(s.user_role=t),s=JSON.stringify(s);let a=await fetch("/user/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:s});if(!a.ok){let e=await a.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},q=async(e,l)=>{try{let t=await fetch("/global/predict/spend/logs",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},K=async(e,l)=>{try{let t="/health/services?service=".concat(l);console.log("Checking Slack Budget Alerts service health");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 h.ZP.error("Failed ".concat(l," service health check ")+e),Error(e)}let a=await s.json();return h.ZP.success("Test request to ".concat(l," made - check logs/alerts on ").concat(l," to verify")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},V=async(e,l,t)=>{try{let l=await fetch("/get/config/callbacks",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},G=async(e,l)=>{try{let t=await fetch("/config/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},W=async e=>{try{let l=await fetch("/health",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to call /health:",e),e}};var J=t(10384),Y=t(46453),H=t(2179),$=t(52273),X=t(26780),Q=t(15595),ee=t(6698),el=t(71801),et=t(42440),es=t(42308),ea=t(50670),er=t(81583),en=t(99129),eo=t(44839),ei=t(88707),ec=t(1861);let{Option:ed}=ea.default;var em=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=er.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[f,y]=(0,n.useState)([]),[Z,w]=(0,n.useState)([]),b=()=>{m(!1),c.resetFields()},_=()=>{m(!1),x(null),c.resetFields()};(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===s)return;if(null!==a){let e=(await v(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),y(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let k=async e=>{try{h.ZP.info("Making API Call"),m(!0);let t=await j(a,l,e);console.log("key create Response:",t),i(e=>e?[...e,t]:[t]),x(t.key),g(t.soft_budget),h.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the key:",e)}};return(0,n.useEffect)(()=>{w(t&&t.models.length>0?t.models.includes("all-proxy-models")?f:t.models:f)},[t,f]),(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(en.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:b,onCancel:_,children:(0,r.jsxs)(er.Z,{form:c,onFinish:k,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",hidden:!0,initialValue:t?t.team_id:null,valuePropName:"team_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),Z.map(e=>(0,r.jsx)(ed,{value:e,children:e},e))]})}),(0,r.jsxs)(X.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Q.Z,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==t?void 0:t.max_budget)!==null&&(null==t?void 0:t.max_budget)!==void 0?null==t?void 0:t.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.max_budget&&l>t.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(t.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Team Reset Budget: ".concat((null==t?void 0:t.budget_duration)!==null&&(null==t?void 0:t.budget_duration)!==void 0?null==t?void 0:t.budget_duration:"None"),children:(0,r.jsxs)(ea.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(ea.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(ea.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Tokens per minute Limit (TPM)",name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==t?void 0:t.tpm_limit)!==null&&(null==t?void 0:t.tpm_limit)!==void 0?null==t?void 0:t.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.tpm_limit&&l>t.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(t.tpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Requests per minute Limit (RPM)",name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==t?void 0:t.rpm_limit)!==null&&(null==t?void 0:t.rpm_limit)!==void 0?null==t?void 0:t.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.rpm_limit&&l>t.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(t.rpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(en.Z,{visible:d,onOk:b,onCancel:_,footer:null,children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Save your Key"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(el.Z,{className:"mt-3",children:"API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:u})}),(0,r.jsx)(es.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(H.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(el.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=t(9454),eu=t(98941),ex=t(33393),ep=t(5),ej=t(9853),eg=t(13810),ef=t(39290),ey=t(66952),eZ=t(61244),ew=t(10827),eb=t(3851),e_=t(2044),ek=t(64167),ev=t(74480),eS=t(7178),eA=t(95093),eN=t(27166);let{Option:eC}=ea.default;var eI=e=>{let{userID:l,userRole:t,accessToken:s,selectedTeam:a,data:o,setData:i,teams:c}=e,[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(!1),[p,j]=(0,n.useState)(null),[g,y]=n.useState(null),[Z,w]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),[k,A]=(0,n.useState)(""),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),F=new Set,[O,M]=(0,n.useState)(F);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),E(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,l,t]),(0,n.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,t)=>{let s=l.team_id;e.add(s)}),M(e)}},[c]);let R=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),C(!0)},U=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await L(s,e);console.log("handleEditSubmit: newKeyValues",t),o&&i(o.map(e=>e.token===l?t:e)),h.ZP.success("Key updated successfully"),C(!1),P(null)},D=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await S(s,e.token);console.log("Response:",l),_(l);try{let e=await q(s,l);console.log("Response2:",e);let t=[...l,...e.response];_(t),A(e.predicted_spend),console.log("Combined Data:",t)}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,n.useEffect)(()=>{D(Z)},[Z]);let z=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"+l),x(!0))},B=async()=>{if(null!=p&&null!=o){try{await f(s,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,r.jsxs)("div",{children:[(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ew.Z,{className:"mt-5 max-h-[300px] min-h-[300px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Key Alias"}),(0,r.jsx)(ev.Z,{children:"Secret Key"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eb.Z,{children:o.map(e=>{if(console.log(e),"litellm-dashboard"===e.team_id)return null;if(a){if(console.log("item team id: ".concat(e.team_id,", knownTeamIDs.has(item.team_id): ").concat(O.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||O.has(e.team_id))&&e.team_id!=a.team_id)return null;console.log("item team id: ".concat(e.team_id,", is returned"))}return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(el.Z,{children:e.key_alias}):(0,r.jsx)(el.Z,{children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.key_name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(e_.Z,{children:null!=e.max_budget?(0,r.jsx)(el.Z,{children:e.max_budget}):(0,r.jsx)(el.Z,{children:"Unlimited"})}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(r.Fragment,{children:a&&a.models&&a.models.length>0?a.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(el.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{})," RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{onClick:()=>{w(e),y(e.id)},icon:eh.Z,size:"sm"}),(0,r.jsx)(ef.Z,{open:null!==g,onClose:()=>{y(null),w(null)},children:(0,r.jsx)(ey.Z,{children:Z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:[(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Spend"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:(()=>{try{return parseFloat(Z.spend).toFixed(4)}catch(e){return Z.spend}})()})})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Budget"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.max_budget?(0,r.jsx)(r.Fragment,{children:Z.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Expires"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-default font-small text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.expires?(0,r.jsx)(r.Fragment,{children:new Date(Z.expires).toLocaleString(void 0,{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}):(0,r.jsx)(r.Fragment,{children:"Never"})})})]},e.name)]}),(0,r.jsx)(eg.Z,{className:"mt-6 mb-6",children:b&&(0,r.jsx)(ej.Z,{className:"mt-6",data:b,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(et.Z,{children:"Metadata"}),(0,r.jsx)(el.Z,{children:JSON.stringify(Z.metadata)}),(0,r.jsx)(H.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{y(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>R(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>z(e),icon:ex.Z,size:"sm"})]})]},e.token)})})]}),u&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:B,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),I&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=er.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(en.Z,{title:"Edit Key",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:i,onFinish:U,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{validator:(e,l)=>{let t=l.filter(e=>!d.models.includes(e)&&"all-team-models"!==e&&"all-proxy-models"!==e&&!d.models.includes("all-proxy-models"));return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t,"Team models: ").concat(d.models)):Promise.resolve()}}],children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eC,{value:"all-team-models",children:"All Team Models"},"all-team-models"),d&&d.models?d.models.includes("all-proxy-models")?T.filter(e=>"all-proxy-models"!==e).map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(eC,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: ".concat((null==d?void 0:d.max_budget)!==null&&(null==d?void 0:d.max_budget)!==void 0?null==d?void 0:d.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&d&&null!==d.max_budget&&l>d.max_budget)throw console.log("keyTeam.max_budget: ".concat(d.max_budget)),Error("Budget cannot exceed team max budget: $".concat(d.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(er.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(eA.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(eN.Z,{value:e.team_id,onClick:()=>m(e),children:e.team_alias},l))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{C(!1),P(null)},token:I,onSubmit:U})]})},eP=t(76032),eT=t(35152),eE=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[i,c]=(0,n.useState)(null!==a?a:0),[d,m]=(0,n.useState)(0),[h,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{let e=async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await b(s);e&&(e.spend?c(e.spend):c(0),e.max_budget?m(e.max_budget):m(0))}catch(e){console.error("Error fetching global spend data:",e)}};(async()=>{try{if(null===l||null===t)return;if(null!==s){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),u(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,s,l]),(0,n.useEffect)(()=>{null!==a&&c(a)},[a]);let x=[];o&&o.models&&(x=o.models),x&&x.includes("all-proxy-models")?(console.log("user models:",h),x=h):x&&x.includes("all-team-models")?x=o.models:x&&0===x.length&&(x=h);let p=void 0!==i?i.toFixed(4):null;return console.log("spend in view user spend: ".concat(i)),(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:["Total Spend"," "]}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",p]})]}),(0,r.jsx)("div",{className:"ml-auto",children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Team Models"})}),(0,r.jsx)(Q.Z,{className:"absolute right-0 z-10 bg-white p-2 shadow-lg max-w-xs",children:(0,r.jsx)(eP.Z,{children:x.map(e=>(0,r.jsx)(eT.Z,{children:(0,r.jsx)(el.Z,{children:e})},e))})})]})})]})},eF=e=>{let{userID:l,userRole:t,selectedTeam:s,accessToken:a}=e,[o,i]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===t)return;if(null!==a){let e=(await v(a,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),i(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,t]);let c=[];return s&&s.models&&(c=s.models),c&&c.includes("all-proxy-models")&&(console.log("user models:",o),c=o),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"mb-5",children:(0,r.jsx)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null==s?void 0:s.team_alias})})})},eO=e=>{let l,{teams:t,setSelectedTeam:s,userRole:a}=e,o={models:[],team_id:null,team_alias:"Default Team"},[i,c]=(0,n.useState)(o);return(l="App User"===a?t:t?[...t,o]:[o],"App User"===a)?null:(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(et.Z,{children:"Select Team"}),(0,r.jsx)(el.Z,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),(0,r.jsxs)(el.Z,{className:"mt-3 mb-3",children:[(0,r.jsx)("b",{children:"Default Team:"})," If no team_id is set for a key, it will be grouped under here."]}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>s(e),children:e.team_alias},l))}):(0,r.jsxs)(el.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eM=t(37963),eR=t(36083);console.log("isLocal:",!1);var eL=e=>{let{userID:l,userRole:t,teams:s,keys:a,setUserRole:i,userEmail:c,setUserEmail:d,setTeams:m,setKeys:h}=e,[u,x]=(0,n.useState)(null),p=(0,o.useSearchParams)();p.get("viewSpend"),(0,o.useRouter)();let j=p.get("token"),[g,f]=(0,n.useState)(null),[y,w]=(0,n.useState)(null),[_,k]=(0,n.useState)([]),S={models:[],team_alias:"Default Team",team_id:null},[A,N]=(0,n.useState)(s?s[0]:S);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eM.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),f(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),i(l)}else console.log("User role not defined");e.user_email?d(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&g&&t&&!a&&!u){let e=sessionStorage.getItem("userModels"+l);e?k(JSON.parse(e)):(async()=>{try{let e=await Z(g,l,t,!1,null,null);if(console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),"Admin"==t){let e=await b(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams);let s=[...e.teams];s.length>0?(console.log("response['teams']: ".concat(s)),N(s[0])):N(S),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let a=(await v(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",a),k(a),console.log("userModels:",_),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=A){let e=0;for(let l of a)A.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===A.team_id&&(e+=l.spend);w(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;w(e)}},[A]),null==l||null==j){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==g)return null;if(null==t&&i("App Owner"),t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",A),console.log("teamSpend: ".concat(y)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eF,{userID:l,userRole:t,selectedTeam:A||null,accessToken:g}),(0,r.jsx)(eE,{userID:l,userRole:t,accessToken:g,userSpend:y,selectedTeam:A||null}),(0,r.jsx)(eI,{userID:l,userRole:t,accessToken:g,selectedTeam:A||null,data:a,setData:h,teams:s}),(0,r.jsx)(em,{userID:l,team:A||null,userRole:t,accessToken:g,data:a,setData:h},A?A.team_id:null),(0,r.jsx)(eO,{teams:s,setSelectedTeam:N,userRole:t})]})})})},eU=t(92836),eD=t(26734),ez=t(41608),eB=t(32126),eq=t(23682),eK=t(47047),eV=t(76628),eG=t(38302),eW=t(28683),eJ=t(1460),eY=t(78578),eH=t(63954),e$=e=>{let{modelID:l,accessToken:t}=e,[s,a]=(0,n.useState)(!1),o=async()=>{try{h.ZP.info("Making API Call"),a(!0);let e=await p(t,l);console.log("model delete Response:",e),h.ZP.success("Model ".concat(l," deleted successfully")),a(!1)}catch(e){console.error("Error deleting the model:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eZ.Z,{onClick:()=>a(!0),icon:ex.Z,size:"sm"}),(0,r.jsx)(en.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Delete Model"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)("p",{children:"Are you sure you want to delete this model? This action is irreversible."})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eX=t(97766),eQ=t(46495);let{Title:e0,Link:e1}=eR.default;(s=a||(a={})).OpenAI="OpenAI",s.Azure="Azure",s.Anthropic="Anthropic",s.Google_AI_Studio="Gemini (Google AI Studio)",s.Bedrock="Amazon Bedrock",s.OpenAI_Compatible="OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)",s.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)";let e2={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"},e4=async(e,l,t)=>{try{let s=Array.isArray(e.model)?e.model:[e.model];console.log("received deployments: ".concat(s)),console.log("received type of deployments: ".concat(typeof s)),s.forEach(async t=>{console.log("litellm_model: ".concat(t));let s={},a={};s.model=t;let r="";for(let[l,t]of Object.entries(e))if(""!==t){if("model_name"==l)r+=t;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)a[l]=t;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",t);let e={};if(t&&void 0!=t){try{e=JSON.parse(t)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else s[l]=t}let n={model_name:r,litellm_params:s,model_info:a},o=await x(l,n);console.log("response for model create call: ".concat(o.data))}),t.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};var e8=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d,modelData:m={data:[]},setModelData:x}=e,[p,j]=(0,n.useState)([]),[g]=er.Z.useForm(),[f,y]=(0,n.useState)(null),[Z,w]=(0,n.useState)(""),[b,k]=(0,n.useState)([]),v=Object.values(a).filter(e=>isNaN(Number(e))),[S,A]=(0,n.useState)("OpenAI"),[N,C]=(0,n.useState)(""),[I,P]=(0,n.useState)(!1),[T,E]=(0,n.useState)(null),[F,M]=(0,n.useState)([]),[R,L]=(0,n.useState)(null),U=e=>{E(e),P(!0)},z=async e=>{if(console.log("handleEditSubmit:",e),null==o)return;let l={},t=null;for(let[s,a]of Object.entries(e))"model_id"!==s?l[s]=a:t=a;let s={litellm_params:l,model_info:{id:t}};console.log("handleEditSubmit payload:",s),await D(o,s),h.ZP.success("Model updated successfully, restart server to see updates"),P(!1),E(null)},B=()=>{w(new Date().toLocaleString())};if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await _(o,d,c);console.log("Model data response:",e.data),x(e);let l=new Set;for(let t=0;t{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),y(e)};null==f&&l(),B()},[o,i,c,d,f,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let q=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(f)),null!=f&&"object"==typeof f&&e in f)?f[e].litellm_provider:"openai";if(a){let e=a.split("/"),l=e[0];n=1===e.length?h(a):l}else n="openai";r&&(o=null==r?void 0:r.input_cost_per_token,i=null==r?void 0:r.output_cost_per_token,c=null==r?void 0:r.max_tokens),(null==s?void 0:s.litellm_params)&&(d=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),m.data[e].provider=n,m.data[e].input_cost=o,m.data[e].output_cost=i,m.data[e].max_tokens=c,m.data[e].api_base=null==s?void 0:null===(t=s.litellm_params)||void 0===t?void 0:t.api_base,m.data[e].cleanedLitellmParams=d,q.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to view all models"})]})}let K=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=e2[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof f&&Object.entries(f).forEach(l=>{let[s,a]=l;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===e||a.litellm_provider.includes(e))&&t.push(s)}),k(t),console.log("providerModels: ".concat(b))}},V=async()=>{try{h.ZP.info("Running health check..."),C("");let e=await W(o);C(e)}catch(e){console.error("Error running health check:",e),C("Error running health check")}};return console.log("selectedProvider: ".concat(S)),console.log("providerModels.length: ".concat(b.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eU.Z,{children:"All Models"}),(0,r.jsx)(eU.Z,{children:"Add Model"}),(0,r.jsx)(eU.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[Z&&(0,r.jsxs)(el.Z,{children:["Last Refreshed: ",Z]}),(0,r.jsx)(eZ.Z,{icon:eH.Z,variant:"shadow",size:"xs",className:"self-center",onClick:B})]})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(Y.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:"all",onValueChange:e=>L("all"===e?"all":e),children:[(0,r.jsx)(eN.Z,{value:"all",children:"All Models"}),F.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>L(e),children:e},l))]})]}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Public Model Name "}),(0,r.jsx)(ev.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(ev.Z,{children:"API Base"}),(0,r.jsx)(ev.Z,{children:"Extra litellm Params"}),(0,r.jsx)(ev.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(eb.Z,{children:m.data.filter(e=>"all"===R||e.model_name===R||null==R||""===R).map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.model_name})}),(0,r.jsx)(e_.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(e_.Z,{children:e.api_base}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Litellm params"})}),(0,r.jsx)(Q.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(e_.Z,{children:e.input_cost}),(0,r.jsx)(e_.Z,{children:e.output_cost}),(0,r.jsx)(e_.Z,{children:e.max_tokens}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>U(e)}),(0,r.jsx)(e$,{modelID:e.model_info.id,accessToken:o})]})]},l))})]})})]}),(0,r.jsx)(e=>{let{visible:l,onCancel:t,model:s,onSubmit:a}=e,[n]=er.Z.useForm(),o={},i="",c="";if(s){o=s.litellm_params,i=s.model_name;let e=s.model_info;e&&(c=e.id,console.log("model_id: ".concat(c)),o.model_id=c)}return(0,r.jsx)(en.Z,{title:"Edit Model "+i,visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a(e),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:z,initialValues:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)($.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})},{visible:I,onCancel:()=>{P(!1),E(null)},model:T,onSubmit:z})]}),(0,r.jsxs)(eB.Z,{className:"h-full",children:[(0,r.jsx)(e0,{level:2,children:"Add new model"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(er.Z,{form:g,onFinish:()=>{g.validateFields().then(e=>{e4(e,o,g)}).catch(e=>{console.error("Validation failed:",e)})},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:S.toString(),children:v.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>{K(e),A(e)},children:e},l))})}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Public Model Name",name:"model_name",tooltip:"Model name your users will pass in. Also used for load-balancing, LiteLLM will load balance between all models with this public name.",className:"mb-0",children:(0,r.jsx)($.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=S.toString())?"gemini-pro":"Anthropic"==s?"claude-3-opus":"Amazon Bedrock"==s?"claude-3-opus":"Gemini (Google AI Studio)"==s?"gemini-pro":"gpt-3.5-turbo"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"LiteLLM Model Name(s)",name:"model",tooltip:"Actual model name used for making litellm.completion() call.",className:"mb-0",children:"Azure"===S?(0,r.jsx)($.Z,{placeholder:"Enter model name"}):b.length>0?(0,r.jsx)(eK.Z,{value:b,children:b.map((e,l)=>(0,r.jsx)(eV.Z,{value:e,children:e},l))}):(0,r.jsx)($.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/proxy/reliability#step-1---set-deployments-on-config",target:"_blank",children:"loadbalance"})," models with the same 'public name'"]})})]}),"Amazon Bedrock"!=S&&"Vertex AI (Anthropic, Gemini, etc.)"!=S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)($.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==S&&(0,r.jsx)(er.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)($.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)($.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eQ.Z,{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;g.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?h.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&h.ZP.error("".concat(e.file.name," file upload failed."))},children:(0,r.jsx)(ec.ZP,{icon:(0,r.jsx)(eX.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==S||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==S)&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)($.Z,{placeholder:"https://..."})}),"Azure"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)($.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==S&&(0,r.jsxs)(er.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)($.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(el.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(e1,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Access Key ID",name:"aws_access_key_id",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Secret Access Key",name:"aws_secret_access_key",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Region Name",name:"aws_region_name",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(er.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-0",children:(0,r.jsx)(eY.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]})]}),(0,r.jsx)("div",{style:{textAlign:"center",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eJ.Z,{title:"Get help on our github",children:(0,r.jsx)(eR.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(el.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(H.Z,{onClick:V,children:"Run `/health`"}),N&&(0,r.jsx)("pre",{children:JSON.stringify(N,null,2)})]})})]})]})})};let{Option:e5}=ea.default;var e3=e=>{let{userID:l,accessToken:t,teams:s}=e,[a]=er.Z.useForm(),[o,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),[m,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await v(t,l,"any"),s=[];for(let l=0;l{i(!1),a.resetFields()},p=()=>{i(!1),d(null),a.resetFields()},j=async e=>{try{h.ZP.info("Making API Call"),i(!0),console.log("formValues in create user:",e);let s=await g(t,null,e);console.log("user create Response:",s),d(s.key),h.ZP.success("API user Created"),a.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Invite User"}),(0,r.jsxs)(en.Z,{title:"Invite User",visible:o,width:800,footer:null,onOk:x,onCancel:p,children:[(0,r.jsx)(el.Z,{className:"mb-1",children:"Invite a user to login to the Admin UI and create Keys"}),(0,r.jsx)(el.Z,{className:"mb-6",children:(0,r.jsx)("b",{children:"Note: SSO Setup Required for this"})}),(0,r.jsxs)(er.Z,{form:a,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(er.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(ea.default,{placeholder:"Select Team ID",style:{width:"100%"},children:s?s.map(e=>(0,r.jsx)(e5,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(e5,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create User"})})]})]}),c&&(0,r.jsxs)(en.Z,{title:"User Created Successfully",visible:o,onOk:x,onCancel:p,footer:null,children:[(0,r.jsx)("p",{children:"User has been created to access your proxy. Please Ask them to Log In."}),(0,r.jsx)("br",{}),(0,r.jsx)("p",{children:(0,r.jsx)("b",{children:"Note: This Feature is only supported through SSO on the Admin UI"})})]})]})},e6=e=>{let{accessToken:l,token:t,keys:s,userRole:a,userID:o,teams:i,setKeys:c}=e,[d,m]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(0),[j,g]=n.useState(null),[f,y]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await Z(l,null,a,!0,x,25);console.log("user data response:",e),m(e)}catch(e){console.error("There was an error fetching the model data",e)}};l&&t&&a&&o&&e();let s=async()=>{try{let e=await T(l,null);console.log("user data response:",e),u(e)}catch(e){console.error("There was an error fetching the model data",e)}};a&&("Admin"==a||"Admin Viewer"==a)&&!h&&s()},[l,t,a,o,x]),!d||!l||!t||!a||!o)return(0,r.jsx)("div",{children:"Loading..."});let w=async e=>{try{let t=await T(l,e);console.log("user data response:",t),u(t)}catch(e){console.error("There was an error fetching the model data",e)}};return(0,r.jsx)("div",{style:{width:"100%"},children:(0,r.jsxs)(Y.Z,{className:"gap-2 p-2 h-[80vh] w-full mt-8",children:[(0,r.jsx)(e3,{userID:o,accessToken:l,teams:i}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[80vh] mb-4",children:[(0,r.jsxs)("div",{className:"mb-4 mt-1",children:[(0,r.jsxs)(el.Z,{children:[(0,r.jsx)("b",{children:"Key Owners: "})," Users on LiteLLM that created API Keys. Automatically tracked by LiteLLM"]}),(0,r.jsxs)(el.Z,{className:"mt-1",children:[(0,r.jsx)("b",{children:"End Users: "}),"End Users of your LLM API calls. Tracked When a `user` param is passed in your LLM calls"]})]}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eU.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"User ID"}),(0,r.jsx)(ev.Z,{children:"User Email"}),(0,r.jsx)(ev.Z,{children:"User Models"}),(0,r.jsx)(ev.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(eb.Z,{children:d.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_id}),(0,r.jsx)(e_.Z,{children:e.user_email}),(0,r.jsx)(e_.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(e_.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(Y.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(ep.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(ep.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsxs)("div",{className:"flex-1 flex justify-between items-center",children:[(0,r.jsx)(el.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(eA.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_alias&&e.key_alias.length>0)return(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>w(e.token),children:e.key_alias},l)})})]})]}),(0,r.jsxs)(ew.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"End User"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Total Events"})]})}),(0,r.jsx)(eb.Z,{children:null==h?void 0:h.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:e.total_spend}),(0,r.jsx)(e_.Z,{children:e.total_events})]},l))})]})]})]})]})]}),function(){if(!d)return null;let e=Math.ceil(d.length/25);return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",x+1," of ",e]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l focus:outline-none",disabled:0===x,onClick:()=>p(x-1),children:"← Prev"}),(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r focus:outline-none",onClick:()=>{p(x+1)},children:"Next →"})]})]})}()]})})},e7=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=er.Z.useForm(),[d]=er.Z.useForm(),{Title:m,Paragraph:u}=eR.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[f,Z]=(0,n.useState)(l?l[0]:null),[b,_]=(0,n.useState)(!1),[k,S]=(0,n.useState)(!1),[A,N]=(0,n.useState)([]),[C,I]=(0,n.useState)(!1),[P,T]=(0,n.useState)(null),[E,F]=(0,n.useState)({}),O=e=>{Z(e),g(!0)},M=async e=>{let t=e.team_id;if(console.log("handleEditSubmit:",e),null==s)return;let r=await U(s,e);l&&a(l.map(e=>e.team_id===t?r.data:e)),h.ZP.success("Team updated successfully"),g(!1),Z(null)},L=async e=>{T(e),I(!0)},D=async()=>{if(null!=P&&null!=l&&null!=s){try{await y(s,P);let e=l.filter(e=>e.team_id!==P);a(e)}catch(e){console.error("Error deleting the team:",e)}I(!1),T(null)}};(0,n.useEffect)(()=>{let e=async()=>{try{if(null===o||null===i||null===s||null===l)return;console.log("fetching team info:");let e={};for(let t=0;t<(null==l?void 0:l.length);t++){let a=l[t].team_id,r=await w(s,a);console.log("teamInfo response:",r),null!==r&&(e={...e,[a]:r})}F(e)}catch(e){console.error("Error fetching team info:",e)}};(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await v(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),N(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,o,i,l]);let B=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await R(s,e);null!==l?a([...l,t]):a([t]),console.log("response for team create call: ".concat(t)),h.ZP.success("Team created"),_(!1)}}catch(e){console.error("Error creating the team:",e),h.ZP.error("Error creating the team: "+e,20)}},q=async e=>{try{if(null!=s&&null!=l){h.ZP.info("Adding Member");let t={role:"user",user_email:e.user_email,user_id:e.user_id},r=await z(s,f.team_id,t);console.log("response for team create call: ".concat(r.data));let n=l.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(r.data.team_id)),e.team_id===r.data.team_id));if(console.log("foundIndex: ".concat(n)),-1!==n){let e=[...l];e[n]=r.data,a(e),Z(r.data)}S(!1)}}catch(e){console.error("Error creating the team:",e)}};return console.log("received teams ".concat(l)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Team Name"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ev.Z,{children:"Info"})]})}),(0,r.jsx)(eb.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(el.Z,{children:["TPM:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{}),"RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].keys&&E[e.team_id].keys.length," Keys"]}),(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].team_info&&E[e.team_id].team_info.members_with_roles&&E[e.team_id].team_info.members_with_roles.length," Members"]})]}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>O(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>L(e.team_id),icon:ex.Z,size:"sm"})]})]},e.team_id)):null})]}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{I(!1),T(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>_(!0),children:"+ Create New Team"}),(0,r.jsx)(en.Z,{title:"Create Team",visible:b,width:800,footer:null,onOk:()=>{_(!1),c.resetFields()},onCancel:()=>{_(!1),c.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:B,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"Team Members"}),(0,r.jsx)(u,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>{Z(e)},children:e.team_alias},l))}):(0,r.jsxs)(u,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:f?f.members_with_roles.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.role})]},l)):null})]})}),f&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=er.Z.useForm();return(0,r.jsx)(en.Z,{title:"Edit Team",visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a({...e,team_id:s.team_id}),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:M,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A&&A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"team_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),Z(null)},team:f,onSubmit:M})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto mb-5",onClick:()=>S(!0),children:"+ Add member"}),(0,r.jsx)(en.Z,{title:"Add member",visible:k,width:800,footer:null,onOk:()=>{S(!1),d.resetFields()},onCancel:()=>{S(!1),d.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e9=t(18190),le=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=er.Z.useForm(),[i]=er.Z.useForm(),{Title:c,Paragraph:d}=eR.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[f,y]=(0,n.useState)(!1),[Z,w]=(0,n.useState)(!1),[b,_]=(0,n.useState)(!1),[k,v]=(0,n.useState)(!1);try{l=window.location.origin}catch(e){l=""}l+="/fallback/login";let S=()=>{v(!1)},A=["proxy_admin","proxy_admin_viewer"];(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await M(s,"proxy_admin_viewer");l.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(l));let t=await M(s,"proxy_admin");t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(t)),console.log("combinedList: ".concat(e)),p(e)}})()},[s]);let N=()=>{w(!1),i.resetFields()},C=()=>{w(!1),i.resetFields()},I=e=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,null);console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),h.ZP.success("Refresh tab to see updated user role"),w(!1)}}catch(e){console.error("Error creating the key:",e)}},E=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,"proxy_admin_viewer");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),g(!1)}}catch(e){console.error("Error creating the key:",e)}},F=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await B(s,e,"proxy_admin");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),y(!1)}}catch(e){console.error("Error creating the key:",e)}},O=async e=>{null!=s&&G(s,{environment_variables:{PROXY_BASE_URL:e.proxy_base_url,GOOGLE_CLIENT_ID:e.google_client_id,GOOGLE_CLIENT_SECRET:e.google_client_secret}})};return console.log("admins: ".concat(null==x?void 0:x.length)),(0,r.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,r.jsx)(c,{level:4,children:"Admin Access "}),(0,r.jsxs)(d,{children:[a&&(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access",children:"Requires SSO Setup"}),(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin: "})," Can create keys, teams, users, add models, etc. ",(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin Viewer: "}),"Can just view spend. They cannot create keys, teams or grant users access to new models."," "]}),(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.user_role}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(en.Z,{title:"Update role",visible:Z,width:800,footer:null,onOk:N,onCancel:C,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(H.Z,{className:"mr-4 mb-5",onClick:()=>y(!0),children:"+ Add admin"}),(0,r.jsx)(en.Z,{title:"Add admin",visible:f,width:800,footer:null,onOk:()=>{y(!1),i.resetFields()},onCancel:()=>{y(!1),i.resetFields()},children:I(F)}),(0,r.jsx)(H.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(en.Z,{title:"Add viewer",visible:j,width:800,footer:null,onOk:()=>{g(!1),i.resetFields()},onCancel:()=>{g(!1),i.resetFields()},children:I(E)})]})})]}),(0,r.jsxs)(Y.Z,{children:[(0,r.jsx)(c,{level:4,children:"Add SSO"}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(H.Z,{onClick:()=>_(!0),children:"Add SSO"}),(0,r.jsx)(en.Z,{title:"Add SSO",visible:b,width:800,footer:null,onOk:()=>{_(!1),o.resetFields()},onCancel:()=>{_(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{F(e),O(e),_(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(eo.Z.Password,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(eo.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(en.Z,{title:"SSO Setup Instructions",visible:k,width:800,footer:null,onOk:S,onCancel:()=>{v(!1)},children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e9.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access ",(0,r.jsxs)("a",{href:l,target:"_blank",children:[(0,r.jsx)("b",{children:l})," "]})]})]})]})},ll=t(12224),lt=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)(!1),[u]=er.Z.useForm(),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)(""),[Z,w]=(0,n.useState)({}),[b,_]=(0,n.useState)([]),k=e=>{b.includes(e)?_(b.filter(l=>l!==e)):_([...b,e])},v={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),o(e.callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let t=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",t),_(e.active_alerts),y(t),w(e.alerts_to_webhook)}c(l)})},[l,t,s]);let S=e=>b&&b.includes(e),A=e=>{if(!l)return;let t=Object.fromEntries(Object.entries(e.variables).map(e=>{var l;let[t,s]=e;return[t,(null===(l=document.querySelector('input[name="'.concat(t,'"]')))||void 0===l?void 0:l.value)||s]}));console.log("updatedVariables",t),console.log("updateAlertTypes",j);try{G(l,{environment_variables:t})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},N=()=>{l&&u.validateFields().then(e=>{if(console.log("Form values:",e),"langfuse"===e.callback){G(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}});let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:null,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey}};o(a?[...a,t]:[t])}else if("slack"===e.callback){console.log("values.slackWebhookUrl: ".concat(e.slackWebhookUrl)),G(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),console.log("values.callback: ".concat(e.callback));let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:null,LANGFUSE_SECRET_KEY:null}};o(a?[...a,t]:[t])}m(!1),u.resetFields(),p(null)})};return l?(console.log("callbacks: ".concat(a)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eU.Z,{value:"2",children:"Alerting"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Callback"}),(0,r.jsx)(ev.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(eb.Z,{children:a.map((e,t)=>{var s;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ep.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).filter(e=>{let[l,t]=e;return null!==t}).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(el.Z,{className:"mt-2",children:l}),"LANGFUSE_HOST"===l?(0,r.jsx)("p",{children:"default value=https://cloud.langfuse.com"}):(0,r.jsx)("div",{}),(0,r.jsx)($.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>A(e),children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),m(!0)},children:"Add Callback"})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(el.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(v).map((e,l)=>{let[t,s]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ll.Z,{id:"switch",name:"switch",checked:S(t),onChange:()=>k(t)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:s})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:t,type:"password",defaultValue:Z&&Z[t]?Z[t]:f})})]},l)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(v).forEach(l=>{let[t,s]=l,a=document.querySelector('input[name="'.concat(t,'"]'));console.log("key",t),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[t]=r}),console.log("updatedAlertToWebhooks",e);let t={general_settings:{alert_to_webhook_url:e,alert_types:b}};console.log("payload",t);try{G(l,t)}catch(e){h.ZP.error("Failed to update alerts: "+e,20)}h.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,"slack"),className:"mx-2",children:"Test Alerts"})]})})]})]})}),(0,r.jsx)(en.Z,{title:"Add Callback",visible:d,onOk:N,width:800,onCancel:()=>{m(!1),u.resetFields(),p(null)},footer:null,children:(0,r.jsxs)(er.Z,{form:u,layout:"vertical",onFinish:N,children:[(0,r.jsx)(er.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(ea.default,{onChange:e=>{p(e)},children:(0,r.jsx)(ea.default.Option,{value:"langfuse",children:"langfuse"})})}),"langfuse"===x&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)($.Z,{type:"password"})}),(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)($.Z,{type:"password"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null};let{Option:ls}=ea.default;var la=e=>{let{models:l,accessToken:t,routerSettings:s,setRouterSettings:a}=e,[o]=er.Z.useForm(),[i,c]=(0,n.useState)(!1),[d,m]=(0,n.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(en.Z,{title:"Add Fallbacks",visible:i,width:800,footer:null,onOk:()=>{c(!1),o.resetFields()},onCancel:()=>{c(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,n=[...s.fallbacks||[],{[l]:r}],i={...s,fallbacks:n};console.log(i);try{G(t,{router_settings:i}),a(i)}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully"),c(!1),o.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eA.Z,{defaultValue:d,children:l&&l.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(eK.Z,{value:l,children:l&&l.filter(e=>e!=d).map(e=>(0,r.jsx)(eV.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lr=t(12968);async function ln(e,l){console.log("isLocal:",!1);let t=window.location.origin,s=new lr.ZP.OpenAI({apiKey:l,baseURL:t,dangerouslyAllowBrowser:!0});try{let l=await s.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});h.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lo=e=>{let{accessToken:l,userRole:t,userID:s,modelData:a}=e,[o,i]=(0,n.useState)({}),[c,d]=(0,n.useState)(!1),[m]=er.Z.useForm(),[u,x]=(0,n.useState)(null),p={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),i(e.router_settings)})},[l,t,s]);let j=async e=>{if(l){console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(o.fallbacks)),o.fallbacks.map(l=>(e in l&&delete l[e],l));try{await G(l,{router_settings:o}),i({...o}),h.ZP.success("Router settings updated successfully")}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}}},g=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).map(e=>{let[l,t]=e;if("routing_strategy_args"!==l){var s;return[l,(null===(s=document.querySelector('input[name="'.concat(l,'"]')))||void 0===s?void 0:s.value)||t]}return null}).filter(e=>null!==e));console.log("updatedVariables",t);try{G(l,{router_settings:t})}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"General Settings"}),(0,r.jsx)(eU.Z,{value:"2",children:"Fallbacks"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(et.Z,{children:"Router Settings"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Setting"}),(0,r.jsx)(ev.Z,{children:"Value"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(o).filter(e=>{let[l,t]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l}).map(e=>{let[l,t]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(el.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:p[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(J.Z,{children:(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>g(o),children:"Save Changes"})})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Model Name"}),(0,r.jsx)(ev.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(eb.Z,{children:o.fallbacks&&o.fallbacks.map((e,t)=>Object.entries(e).map(e=>{let[s,a]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:s}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(H.Z,{onClick:()=>ln(s,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(eZ.Z,{icon:ex.Z,size:"sm",onClick:()=>j(s)})})]},t.toString()+s)}))})]}),(0,r.jsx)(la,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:o,setRouterSettings:i})]})]})]})}):null},li=t(67951),lc=e=>{let{}=e;return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(el.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eU.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eU.Z,{children:"LlamaIndex"}),(0,r.jsx)(eU.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n '})}),(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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:4000",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})]})})})};async function ld(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new lr.ZP.OpenAI({apiKey:s,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let s of(await r.chat.completions.create({model:t,stream:!0,messages:[{role:"user",content:e}]})))console.log(s),s.choices[0].delta.content&&l(s.choices[0].delta.content)}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lm=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,[o,i]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[m,h]=(0,n.useState)([]),[u,x]=(0,n.useState)(void 0),[p,j]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{let e=await v(l,a,s);if(console.log("model_info:",e),(null==e?void 0:e.data.length)>0){let l=e.data.map(e=>({value:e.id,label:e.id}));console.log(l),j(l),x(e.data[0].id)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,s]);let g=(e,l)=>{h(t=>{let s=t[t.length-1];return s&&s.role===e?[...t.slice(0,t.length-1),{role:e,content:s.content+l}]:[...t,{role:e,content:l}]})},f=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await ld(c,e=>g("assistant",e),u,o)}catch(e){console.error("Error fetching model response",e),g("assistant","Error fetching model response")}d("")}};if(s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsx)(ez.Z,{children:(0,r.jsx)(eU.Z,{children:"Chat"})}),(0,r.jsx)(eq.Z,{children:(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(Y.Z,{numItems:2,children:[(0,r.jsxs)(J.Z,{children:[(0,r.jsx)(el.Z,{children:"API Key"}),(0,r.jsx)($.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(J.Z,{className:"mx-2",children:[(0,r.jsx)(el.Z,{children:"Select Model:"}),(0,r.jsx)(ea.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ew.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ek.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsx)(eb.Z,{children:m.map((e,l)=>(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{children:"".concat(e.role,": ").concat(e.content)})},l))})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)($.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(H.Z,{onClick:f,className:"ml-2",children:"Send"})]})})]})})]})})})})},lh=t(33509),lu=t(95781);let{Sider:lx}=lh.default;var lp=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lx,{width:120,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"145px"},children:(0,r.jsx)(lx,{width:145,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(el.Z,{children:"API Keys"})},"1"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(el.Z,{children:"Test Key"})},"3"),"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(el.Z,{children:"Models"})},"2"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(el.Z,{children:"Usage"})},"4"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(el.Z,{children:"Teams"})},"6"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(el.Z,{children:"Users"})},"5"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(el.Z,{children:"Logging & Alerts"})},"8"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(el.Z,{children:"Router Settings"})},"9"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(el.Z,{children:"Admin"})},"7"):null,(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api_ref"),children:(0,r.jsx)(el.Z,{children:"API Reference"})},"11")]})})})},lj=t(67989),lg=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,o=new Date,[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)([]),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)([]),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)([]),[Z,w]=(0,n.useState)([]),[b,v]=(0,n.useState)([]),[S,T]=(0,n.useState)([]),[O,M]=(0,n.useState)([]),[R,L]=(0,n.useState)([]),[U,D]=(0,n.useState)(null),z=new Date(o.getFullYear(),o.getMonth(),1),B=new Date(o.getFullYear(),o.getMonth()+1,0),q=V(z),K=V(B);function V(e){let l=e.getFullYear(),t=e.getMonth()+1,s=e.getDate();return"".concat(l,"-").concat(t<10?"0"+t:t,"-").concat(s<10?"0"+s:s)}console.log("Start date is ".concat(q)),console.log("End date is ".concat(K)),(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{if(console.log("user role: ".concat(s)),"Admin"==s||"Admin Viewer"==s){let e=await I(l);c(e);let t=(await P(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let r=(await E(l)).map(e=>({key:e.model,spend:e.total_spend}));u(r);let n=await A(l);console.log("teamSpend",n),g(n.daily_spend),w(n.teams);let o=n.total_spend_per_team;o=o.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),v(o);let i=await N(l);y(i.top_10_tags);let d=(await _(l,a,s)).data;console.log("model groups in model dashboard",d);let h=[];for(let e=0;e{if(console.log("result from spend logs call",e),"daily_spend"in e){let l=e.daily_spend;console.log("daily spend",l),c(l);let t=e.top_api_keys;m(t)}else{let t=(await F(l,function(e){let l=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[t,s]=e;"spend"!==t&&"startTime"!==t&&"models"!==t&&"users"!==t&&l.push({key:t,spend:s})})}),l.sort((e,l)=>Number(l.spend)-Number(e.spend));let t=l.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(t[0]))),t}(e))).info.map(e=>({key:(e.key_name||e.key_alias).substring(0,10),spend:e.spend}));m(t),p(function(e){let l={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[t,s]=e;""!==t&&null!=t&&"None"!=t&&(l[t]||(l[t]=0),l[t]+=s)})});let t=Object.entries(l).map(e=>{let[l,t]=e;return{user_id:l,spend:t}});t.sort((e,l)=>l.spend-e.spend);let s=t.slice(0,5);return console.log("topKeys: ".concat(Object.values(s[0]))),s}(e)),c(e)}});let e=await k(l,a,s,null);console.log("Model metrics response:",e);let r=[...e].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(e),M(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,q,K]);let G=async e=>{if(console.log("Updating model metrics for group:",e),l&&a&&s){D(e);try{let t=await k(l,a,s,e);console.log("Model metrics response:",t);let r=[...t].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(t),M(r)}catch(e){console.error("Failed to fetch model metrics",e)}}};return(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(eE,{userID:a,userRole:s,accessToken:l,userSpend:null,selectedTeam:null}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{className:"mt-2",children:[(0,r.jsx)(eU.Z,{children:"All Up"}),(0,r.jsx)(eU.Z,{children:"Team Based Usage"}),(0,r.jsx)(eU.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eU.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Monthly Spend"}),(0,r.jsx)(ej.Z,{data:i,index:"date",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top API Keys"}),(0,r.jsx)(ej.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,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Users"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:x,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Models"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(J.Z,{numColSpan:2,children:[(0,r.jsxs)(eg.Z,{className:"mb-2",children:[(0,r.jsx)(et.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(lj.Z,{data:b})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(ej.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:Z,yAxisWidth:80,colors:["blue","green","yellow","red","purple"],stack:!0})]})]}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(el.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/enterprise#tracking-spend-for-custom-tags",target:"_blank",children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Tag"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Requests"})]})}),(0,r.jsx)(eb.Z,{children:f.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.name}),(0,r.jsx)(e_.Z,{children:e.value}),(0,r.jsx)(e_.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)(et.Z,{children:"Filter By Model Group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080"},children:"View how requests were load balanced within a model group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080",fontStyle:"italic"},children:"(Beta feature) only supported for Azure Model Groups"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2",defaultValue:"all",children:[(0,r.jsx)(eN.Z,{value:"all",onClick:()=>G(null),children:"All Model Groups"}),R.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>G(e),children:e},l))]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Number Requests per Model"}),(0,r.jsx)(ej.Z,{data:S,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(eg.Z,{className:"mt-4",children:[(0,r.jsx)(et.Z,{children:"Latency Per Model"}),(0,r.jsx)(ej.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},lf=()=>{let{Title:e,Paragraph:l}=eR.default,[t,s]=(0,n.useState)(""),[a,i]=(0,n.useState)(null),[c,d]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(!0),j=(0,o.useSearchParams)(),[g,f]=(0,n.useState)({data:[]}),y=j.get("userID"),Z=j.get("token"),[w,b]=(0,n.useState)("api-keys"),[_,k]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(Z){let e=(0,eM.o)(Z);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),k(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&b("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))}}},[Z]),(0,r.jsx)(n.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(m,{userID:y,userRole:t,userEmail:a,showSSOBanner:x}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(lp,{setPage:b,userRole:t,defaultSelectedKey:null})}),"api-keys"==w?(0,r.jsx)(eL,{userID:y,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==w?(0,r.jsx)(e8,{userID:y,userRole:t,token:Z,accessToken:_,modelData:g,setModelData:f}):"llm-playground"==w?(0,r.jsx)(lm,{userID:y,userRole:t,token:Z,accessToken:_}):"users"==w?(0,r.jsx)(e6,{userID:y,userRole:t,token:Z,keys:h,teams:c,accessToken:_,setKeys:u}):"teams"==w?(0,r.jsx)(e7,{teams:c,setTeams:d,searchParams:j,accessToken:_,userID:y,userRole:t}):"admin-panel"==w?(0,r.jsx)(le,{setTeams:d,searchParams:j,accessToken:_,showSSOBanner:x}):"api_ref"==w?(0,r.jsx)(lc,{}):"settings"==w?(0,r.jsx)(lt,{userID:y,userRole:t,accessToken:_}):"general-settings"==w?(0,r.jsx)(lo,{userID:y,userRole:t,accessToken:_,modelData:g}):(0,r.jsx)(lg,{userID:y,userRole:t,token:Z,accessToken:_})]})]})})}}},function(e){e.O(0,[447,971,69,744],function(){return e(e.s=20661)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-781ca5f151d78d1d.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-781ca5f151d78d1d.js deleted file mode 100644 index 40715cd06..000000000 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/page-781ca5f151d78d1d.js +++ /dev/null @@ -1 +0,0 @@ -(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{20661:function(e,l,t){Promise.resolve().then(t.bind(t,27125))},27125:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return lf}});var s,a,r=t(3827),n=t(64090),o=t(47907),i=t(8792),c=t(40491),d=t(65270),m=e=>{let{userID:l,userRole:t,userEmail:s,showSSOBanner:a}=e;console.log("User ID:",l),console.log("userEmail:",s),console.log("showSSOBanner:",a);let n=[{key:"1",label:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("p",{children:["Role: ",t]}),(0,r.jsxs)("p",{children:["ID: ",l]})]})}];return(0,r.jsxs)("nav",{className:"left-0 right-0 top-0 flex justify-between items-center h-12 mb-4",children:[(0,r.jsx)("div",{className:"text-left my-2 absolute top-0 left-0",children:(0,r.jsx)("div",{className:"flex flex-col items-center",children:(0,r.jsx)(i.default,{href:"/",children:(0,r.jsx)("button",{className:"text-gray-800 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:160,height:160,alt:"LiteLLM Brand",className:"mr-2"})})})})}),(0,r.jsxs)("div",{className:"text-right mx-4 my-2 absolute top-0 right-0 flex items-center justify-end space-x-2",children:[a?(0,r.jsx)("div",{style:{padding:"6px",borderRadius:"8px"},children:(0,r.jsx)("a",{href:"https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat",target:"_blank",style:{fontSize:"14px",textDecoration:"underline"},children:"Request hosted proxy"})}):null,(0,r.jsx)("div",{style:{border:"1px solid #391085",padding:"6px",borderRadius:"8px"},children:(0,r.jsx)(c.Z,{menu:{items:n},children:(0,r.jsx)(d.Z,{children:s})})})]})]})},h=t(80588);let u=async()=>{try{let e=await fetch("https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"),l=await e.json();return console.log("received data: ".concat(l)),l}catch(e){throw console.error("Failed to get model cost map:",e),e}},x=async(e,l)=>{try{let t=await fetch("/model/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model created successfully. Wait 60s and refresh on 'All Models' page"),s}catch(e){throw console.error("Failed to create key:",e),e}},p=async(e,l)=>{console.log("model_id in model delete call: ".concat(l));try{let t=await fetch("/model/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({id:l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),h.ZP.success("Model deleted successfully. Restart server to see this."),s}catch(e){throw console.error("Failed to create key:",e),e}},j=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/key/generate",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},g=async(e,l,t)=>{try{if(console.log("Form Values in keyCreateCall:",t),t.description&&(t.metadata||(t.metadata={}),t.metadata.description=t.description,delete t.description,t.metadata=JSON.stringify(t.metadata)),t.metadata){console.log("formValues.metadata:",t.metadata);try{t.metadata=JSON.parse(t.metadata)}catch(e){throw h.ZP.error("Failed to parse metadata: "+e,20),Error("Failed to parse metadata: "+e)}}console.log("Form Values after check:",t);let s=await fetch("/user/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({user_id:l,...t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},f=async(e,l)=>{try{console.log("in keyDeleteCall:",l);let t=await fetch("/key/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},y=async(e,l)=>{try{console.log("in teamDeleteCall:",l);let t=await fetch("/team/delete",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_ids:[l]})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete team: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to delete key:",e),e}},Z=async function(e,l,t){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0;try{let n="/user/info";"App Owner"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),"App User"==t&&l&&(n="".concat(n,"?user_id=").concat(l)),console.log("in userInfoCall viewAll=",s),s&&r&&null!=a&&void 0!=a&&(n="".concat(n,"?view_all=true&page=").concat(a,"&page_size=").concat(r));let o=await fetch(n,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!o.ok){let e=await o.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let i=await o.json();return console.log("API Response:",i),i}catch(e){throw console.error("Failed to create key:",e),e}},w=async(e,l)=>{try{let t="/team/info";l&&(t="".concat(t,"?team_id=").concat(l)),console.log("in teamInfoCall");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 h.ZP.error(e,20),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}},b=async e=>{try{let l=await fetch("/global/spend",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},_=async(e,l,t)=>{try{let l=await fetch("/v2/model/info",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log("modelInfoCall:",t),t}catch(e){throw console.error("Failed to create key:",e),e}},k=async(e,l,t,s)=>{try{let l="/model/metrics";s&&(l="".concat(l,"?_selected_model_group=").concat(s));let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to create key:",e),e}},v=async(e,l,t)=>{try{let l=await fetch("/models",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to create key:",e),e}},S=async(e,l)=>{try{let t="/global/spend/logs";console.log("in keySpendLogsCall:",t);let s=await fetch("".concat(t,"?api_key=").concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},A=async e=>{try{let l="/global/spend/teams";console.log("in teamSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},N=async e=>{try{let l="/global/spend/tags";console.log("in tagsSpendLogsCall:",l);let t=await fetch("".concat(l),{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},C=async(e,l,t,s,a,r)=>{try{console.log("user role in spend logs call: ".concat(t));let l="/spend/logs";l="App Owner"==t?"".concat(l,"?user_id=").concat(s,"&start_date=").concat(a,"&end_date=").concat(r):"".concat(l,"?start_date=").concat(a,"&end_date=").concat(r);let n=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!n.ok){let e=await n.text();throw h.ZP.error(e,20),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}},I=async e=>{try{let l=await fetch("/global/spend/logs",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},P=async e=>{try{let l=await fetch("/global/spend/keys?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},T=async(e,l)=>{try{l&&JSON.stringify({api_key:l});let t={method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}};l&&(t.body=JSON.stringify({api_key:l}));let s=await fetch("/global/spend/end_users",t);if(!s.ok){let e=await s.text();throw h.ZP.error(e,20),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}},E=async e=>{try{let l=await fetch("/global/spend/models?limit=5",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let t=await l.json();return console.log(t),t}catch(e){throw console.error("Failed to create key:",e),e}},F=async(e,l)=>{try{let t=await fetch("/v2/key/info",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({keys:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},O=async e=>{try{let l="/user/get_requests";console.log("in userGetRequesedtModelsCall:",l);let t=await fetch(l,{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to delete key: "+e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to get requested models:",e),e}},M=async(e,l)=>{try{let t="/user/get_users?role=".concat(l);console.log("in userGetAllUsersCall:",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 h.ZP.error("Failed to delete key: "+e,20),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}},R=async(e,l)=>{try{console.log("Form Values in teamCreateCall:",l);let t=await fetch("/team/new",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("API Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},L=async(e,l)=>{try{console.log("Form Values in keyUpdateCall:",l);let t=await fetch("/key/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update key Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},U=async(e,l)=>{try{console.log("Form Values in teamUpateCall:",l);let t=await fetch("/team/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update team: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update Team Response:",s),s}catch(e){throw console.error("Failed to create key:",e),e}},D=async(e,l)=>{try{console.log("Form Values in modelUpateCall:",l);let t=await fetch("/model/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error("Failed to update model: "+e,20),console.error("Error update from the server:",e),Error("Network response was not ok")}let s=await t.json();return console.log("Update model Response:",s),s}catch(e){throw console.error("Failed to update model:",e),e}},z=async(e,l,t)=>{try{console.log("Form Values in teamMemberAddCall:",t);let s=await fetch("/team/member_add",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({team_id:l,member:t})});if(!s.ok){let e=await s.text();throw h.ZP.error("Failed to create key: "+e,20),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}},B=async(e,l,t)=>{try{console.log("Form Values in userUpdateUserCall:",l);let s={...l};null!==t&&(s.user_role=t),s=JSON.stringify(s);let a=await fetch("/user/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:s});if(!a.ok){let e=await a.text();throw h.ZP.error("Failed to create key: "+e,20),console.error("Error response from the server:",e),Error("Network response was not ok")}let r=await a.json();return console.log("API Response:",r),r}catch(e){throw console.error("Failed to create key:",e),e}},q=async(e,l)=>{try{let t=await fetch("/global/predict/spend/logs",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({data:l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}let s=await t.json();return console.log(s),s}catch(e){throw console.error("Failed to create key:",e),e}},K=async(e,l)=>{try{let t="/health/services?service=".concat(l);console.log("Checking Slack Budget Alerts service health");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 h.ZP.error("Failed ".concat(l," service health check ")+e),Error(e)}let a=await s.json();return h.ZP.success("Test request to ".concat(l," made - check logs/alerts on ").concat(l," to verify")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},V=async(e,l,t)=>{try{let l=await fetch("/get/config/callbacks",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to get callbacks:",e),e}},G=async(e,l)=>{try{let t=await fetch("/config/update",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify({...l})});if(!t.ok){let e=await t.text();throw h.ZP.error(e,20),Error("Network response was not ok")}return await t.json()}catch(e){throw console.error("Failed to set callbacks:",e),e}},W=async e=>{try{let l=await fetch("/health",{method:"GET",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!l.ok){let e=await l.text();throw h.ZP.error(e),Error("Network response was not ok")}return await l.json()}catch(e){throw console.error("Failed to call /health:",e),e}};var J=t(10384),Y=t(46453),H=t(2179),$=t(52273),X=t(26780),Q=t(15595),ee=t(6698),el=t(71801),et=t(42440),es=t(42308),ea=t(50670),er=t(81583),en=t(99129),eo=t(44839),ei=t(88707),ec=t(1861);let{Option:ed}=ea.default;var em=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=er.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[f,y]=(0,n.useState)([]),Z=()=>{m(!1),c.resetFields()},w=()=>{m(!1),x(null),c.resetFields()};(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===s)return;if(null!==a){let e=(await v(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),y(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let b=async e=>{try{h.ZP.info("Making API Call"),m(!0);let t=await j(a,l,e);console.log("key create Response:",t),i(e=>e?[...e,t]:[t]),x(t.key),g(t.soft_budget),h.ZP.success("API Key Created"),c.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the key:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(en.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:Z,onCancel:w,children:(0,r.jsxs)(er.Z,{form:c,onFinish:b,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",hidden:!0,initialValue:t?t.team_id:null,valuePropName:"team_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},onChange:e=>{e.includes("all-team-models")&&c.setFieldsValue({models:["all-team-models"]})},children:[(0,r.jsx)(ed,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?f.map(e=>(0,r.jsx)(ed,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(ed,{value:e,children:e},e)):f.map(e=>(0,r.jsx)(ed,{value:e,children:e},e))]})}),(0,r.jsxs)(X.Z,{className:"mt-20 mb-8",children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)(Q.Z,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: $".concat((null==t?void 0:t.max_budget)!==null&&(null==t?void 0:t.max_budget)!==void 0?null==t?void 0:t.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.max_budget&&l>t.max_budget)throw Error("Budget cannot exceed team max budget: $".concat(t.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Reset Budget",name:"budget_duration",help:"Team Reset Budget: ".concat((null==t?void 0:t.budget_duration)!==null&&(null==t?void 0:t.budget_duration)!==void 0?null==t?void 0:t.budget_duration:"None"),children:(0,r.jsxs)(ea.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(ea.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(ea.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Tokens per minute Limit (TPM)",name:"tpm_limit",help:"TPM cannot exceed team TPM limit: ".concat((null==t?void 0:t.tpm_limit)!==null&&(null==t?void 0:t.tpm_limit)!==void 0?null==t?void 0:t.tpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.tpm_limit&&l>t.tpm_limit)throw Error("TPM limit cannot exceed team TPM limit: ".concat(t.tpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Requests per minute Limit (RPM)",name:"rpm_limit",help:"RPM cannot exceed team RPM limit: ".concat((null==t?void 0:t.rpm_limit)!==null&&(null==t?void 0:t.rpm_limit)!==void 0?null==t?void 0:t.rpm_limit:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&t&&null!==t.rpm_limit&&l>t.rpm_limit)throw Error("RPM limit cannot exceed team RPM limit: ".concat(t.rpm_limit))}}],children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(en.Z,{visible:d,onOk:Z,onCancel:w,footer:null,children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Save your Key"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Please save this secret key somewhere safe and accessible. For security reasons, ",(0,r.jsx)("b",{children:"you will not be able to view it again"})," ","through your LiteLLM account. If you lose this secret key, you will need to generate a new one."]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(el.Z,{className:"mt-3",children:"API Key:"}),(0,r.jsx)("div",{style:{background:"#f8f8f8",padding:"10px",borderRadius:"5px",marginBottom:"10px"},children:(0,r.jsx)("pre",{style:{wordWrap:"break-word",whiteSpace:"normal"},children:u})}),(0,r.jsx)(es.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(H.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(el.Z,{children:"Key being created, this might take 30s"})})]})})]})},eh=t(9454),eu=t(98941),ex=t(33393),ep=t(5),ej=t(9853),eg=t(13810),ef=t(39290),ey=t(66952),eZ=t(61244),ew=t(10827),eb=t(3851),e_=t(2044),ek=t(64167),ev=t(74480),eS=t(7178),eA=t(95093),eN=t(27166);let{Option:eC}=ea.default;var eI=e=>{let{userID:l,userRole:t,accessToken:s,selectedTeam:a,data:o,setData:i,teams:c}=e,[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(!1),[p,j]=(0,n.useState)(null),[g,y]=n.useState(null),[Z,w]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),[k,A]=(0,n.useState)(""),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),F=new Set,[O,M]=(0,n.useState)(F);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),E(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,l,t]),(0,n.useEffect)(()=>{if(c){let e=new Set;c.forEach((l,t)=>{let s=l.team_id;e.add(s)}),M(e)}},[c]);let R=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),C(!0)},U=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await L(s,e);console.log("handleEditSubmit: newKeyValues",t),o&&i(o.map(e=>e.token===l?t:e)),h.ZP.success("Key updated successfully"),C(!1),P(null)},D=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await S(s,e.token);console.log("Response:",l),_(l);try{let e=await q(s,l);console.log("Response2:",e);let t=[...l,...e.response];_(t),A(e.predicted_spend),console.log("Combined Data:",t)}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,n.useEffect)(()=>{D(Z)},[Z]);let z=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"+l),x(!0))},B=async()=>{if(null!=p&&null!=o){try{await f(s,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,r.jsxs)("div",{children:[(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ew.Z,{className:"mt-5 max-h-[300px] min-h-[300px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Key Alias"}),(0,r.jsx)(ev.Z,{children:"Secret Key"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eb.Z,{children:o.map(e=>{if(console.log(e),"litellm-dashboard"===e.team_id)return null;if(a){if(console.log("item team id: ".concat(e.team_id,", knownTeamIDs.has(item.team_id): ").concat(O.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||O.has(e.team_id))&&e.team_id!=a.team_id)return null;console.log("item team id: ".concat(e.team_id,", is returned"))}return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(el.Z,{children:e.key_alias}):(0,r.jsx)(el.Z,{children:"Not Set"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.key_name})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(e_.Z,{children:null!=e.max_budget?(0,r.jsx)(el.Z,{children:e.max_budget}):(0,r.jsx)(el.Z,{children:"Unlimited"})}),(0,r.jsx)(e_.Z,{children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(r.Fragment,{children:a&&a.models&&a.models.length>0?a.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Team Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(el.Z,{children:["TPM: ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{})," RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{onClick:()=>{w(e),y(e.id)},icon:eh.Z,size:"sm"}),(0,r.jsx)(ef.Z,{open:null!==g,onClose:()=>{y(null),w(null)},children:(0,r.jsx)(ey.Z,{children:Z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:[(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Spend"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:(()=>{try{return parseFloat(Z.spend).toFixed(4)}catch(e){return Z.spend}})()})})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Budget"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor font-semibold text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.max_budget?(0,r.jsx)(r.Fragment,{children:Z.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("p",{className:"text-tremor-default font-medium text-tremor-content dark:text-dark-tremor-content",children:"Expires"}),(0,r.jsx)("div",{className:"mt-2 flex items-baseline space-x-2.5",children:(0,r.jsx)("p",{className:"text-tremor-default font-small text-tremor-content-strong dark:text-dark-tremor-content-strong",children:null!=Z.expires?(0,r.jsx)(r.Fragment,{children:new Date(Z.expires).toLocaleString(void 0,{day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}):(0,r.jsx)(r.Fragment,{children:"Never"})})})]},e.name)]}),(0,r.jsx)(eg.Z,{className:"mt-6 mb-6",children:b&&(0,r.jsx)(ej.Z,{className:"mt-6",data:b,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(et.Z,{children:"Metadata"}),(0,r.jsx)(el.Z,{children:JSON.stringify(Z.metadata)}),(0,r.jsx)(H.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{y(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>R(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>z(e),icon:ex.Z,size:"sm"})]})]},e.token)})})]}),u&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Key"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this key ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:B,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),I&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=er.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(en.Z,{title:"Edit Key",visible:l,width:800,footer:null,onOk:()=>{i.validateFields().then(e=>{i.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:i,onFinish:U,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",rules:[{validator:(e,l)=>{let t=l.filter(e=>!d.models.includes(e)&&"all-team-models"!==e&&"all-proxy-models"!==e&&!d.models.includes("all-proxy-models"));return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t,"Team models: ").concat(d.models)):Promise.resolve()}}],children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eC,{value:"all-team-models",children:"All Team Models"},"all-team-models"),d&&d.models?d.models.includes("all-proxy-models")?T.filter(e=>"all-proxy-models"!==e).map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(eC,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(eC,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"Max Budget (USD)",name:"max_budget",help:"Budget cannot exceed team max budget: ".concat((null==d?void 0:d.max_budget)!==null&&(null==d?void 0:d.max_budget)!==void 0?null==d?void 0:d.max_budget:"unlimited"),rules:[{validator:async(e,l)=>{if(l&&d&&null!==d.max_budget&&l>d.max_budget)throw console.log("keyTeam.max_budget: ".concat(d.max_budget)),Error("Budget cannot exceed team max budget: $".concat(d.max_budget))}}],children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(er.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(eA.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(eN.Z,{value:e.team_id,onClick:()=>m(e),children:e.team_alias},l))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{C(!1),P(null)},token:I,onSubmit:U})]})},eP=t(76032),eT=t(35152),eE=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a,selectedTeam:o}=e;console.log("userSpend: ".concat(a));let[i,c]=(0,n.useState)(null!==a?a:0),[d,m]=(0,n.useState)(0),[h,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{let e=async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await b(s);e&&(e.spend?c(e.spend):c(0),e.max_budget?m(e.max_budget):m(0))}catch(e){console.error("Error fetching global spend data:",e)}};(async()=>{try{if(null===l||null===t)return;if(null!==s){let e=(await v(s,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),u(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[t,s,l]),(0,n.useEffect)(()=>{null!==a&&c(a)},[a]);let x=[];o&&o.models&&(x=o.models),x&&x.includes("all-proxy-models")?(console.log("user models:",h),x=h):x&&x.includes("all-team-models")?x=o.models:x&&0===x.length&&(x=h);let p=void 0!==i?i.toFixed(4):null;return console.log("spend in view user spend: ".concat(i)),(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("div",{children:[(0,r.jsxs)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:["Total Spend"," "]}),(0,r.jsxs)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",p]})]}),(0,r.jsx)("div",{className:"ml-auto",children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Team Models"})}),(0,r.jsx)(Q.Z,{className:"absolute right-0 z-10 bg-white p-2 shadow-lg max-w-xs",children:(0,r.jsx)(eP.Z,{children:x.map(e=>(0,r.jsx)(eT.Z,{children:(0,r.jsx)(el.Z,{children:e})},e))})})]})})]})},eF=e=>{let{userID:l,userRole:t,selectedTeam:s,accessToken:a}=e,[o,i]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{if(null===l||null===t)return;if(null!==a){let e=(await v(a,l,t)).data.map(e=>e.id);console.log("available_model_names:",e),i(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,t]);let c=[];return s&&s.models&&(c=s.models),c&&c.includes("all-proxy-models")&&(console.log("user models:",o),c=o),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)("div",{className:"mb-5",children:(0,r.jsx)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:null==s?void 0:s.team_alias})})})},eO=e=>{let l,{teams:t,setSelectedTeam:s,userRole:a}=e,o={models:[],team_id:null,team_alias:"Default Team"},[i,c]=(0,n.useState)(o);return(l="App User"===a?t:t?[...t,o]:[o],"App User"===a)?null:(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(et.Z,{children:"Select Team"}),(0,r.jsx)(el.Z,{children:"If you belong to multiple teams, this setting controls which team is used by default when creating new API Keys."}),(0,r.jsxs)(el.Z,{className:"mt-3 mb-3",children:[(0,r.jsx)("b",{children:"Default Team:"})," If no team_id is set for a key, it will be grouped under here."]}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>s(e),children:e.team_alias},l))}):(0,r.jsxs)(el.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eM=t(37963),eR=t(36083);console.log("isLocal:",!1);var eL=e=>{let{userID:l,userRole:t,teams:s,keys:a,setUserRole:i,userEmail:c,setUserEmail:d,setTeams:m,setKeys:h}=e,[u,x]=(0,n.useState)(null),p=(0,o.useSearchParams)();p.get("viewSpend"),(0,o.useRouter)();let j=p.get("token"),[g,f]=(0,n.useState)(null),[y,w]=(0,n.useState)(null),[_,k]=(0,n.useState)([]),S={models:[],team_alias:"Default Team",team_id:null},[A,N]=(0,n.useState)(s?s[0]:S);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eM.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),f(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),i(l)}else console.log("User role not defined");e.user_email?d(e.user_email):console.log("User Email is not set ".concat(e))}}if(l&&g&&t&&!a&&!u){let e=sessionStorage.getItem("userModels"+l);e?k(JSON.parse(e)):(async()=>{try{let e=await Z(g,l,t,!1,null,null);if(console.log("received teams in user dashboard: ".concat(Object.keys(e),"; team values: ").concat(Object.entries(e.teams))),"Admin"==t){let e=await b(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams);let s=[...e.teams];s.length>0?(console.log("response['teams']: ".concat(s)),N(s[0])):N(S),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let a=(await v(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",a),k(a),console.log("userModels:",_),sessionStorage.setItem("userModels"+l,JSON.stringify(a))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=A){let e=0;for(let l of a)A.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===A.team_id&&(e+=l.spend);w(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;w(e)}},[A]),null==l||null==j){let e="/sso/key/generate";return console.log("Full URL:",e),window.location.href=e,null}if(null==g)return null;if(null==t&&i("App Owner"),t&&"Admin Viewer"==t){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to create keys"})]})}return console.log("inside user dashboard, selected team",A),console.log("teamSpend: ".concat(y)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eF,{userID:l,userRole:t,selectedTeam:A||null,accessToken:g}),(0,r.jsx)(eE,{userID:l,userRole:t,accessToken:g,userSpend:y,selectedTeam:A||null}),(0,r.jsx)(eI,{userID:l,userRole:t,accessToken:g,selectedTeam:A||null,data:a,setData:h,teams:s}),(0,r.jsx)(em,{userID:l,team:A||null,userRole:t,accessToken:g,data:a,setData:h},A?A.team_id:null),(0,r.jsx)(eO,{teams:s,setSelectedTeam:N,userRole:t})]})})})},eU=t(92836),eD=t(26734),ez=t(41608),eB=t(32126),eq=t(23682),eK=t(47047),eV=t(76628),eG=t(38302),eW=t(28683),eJ=t(1460),eY=t(78578),eH=t(63954),e$=e=>{let{modelID:l,accessToken:t}=e,[s,a]=(0,n.useState)(!1),o=async()=>{try{h.ZP.info("Making API Call"),a(!0);let e=await p(t,l);console.log("model delete Response:",e),h.ZP.success("Model ".concat(l," deleted successfully")),a(!1)}catch(e){console.error("Error deleting the model:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(eZ.Z,{onClick:()=>a(!0),icon:ex.Z,size:"sm"}),(0,r.jsx)(en.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(et.Z,{children:"Delete Model"}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)("p",{children:"Are you sure you want to delete this model? This action is irreversible."})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eX=t(97766),eQ=t(46495);let{Title:e0,Link:e1}=eR.default;(s=a||(a={})).OpenAI="OpenAI",s.Azure="Azure",s.Anthropic="Anthropic",s.Google_AI_Studio="Gemini (Google AI Studio)",s.Bedrock="Amazon Bedrock",s.OpenAI_Compatible="OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)",s.Vertex_AI="Vertex AI (Anthropic, Gemini, etc.)";let e2={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"},e4=async(e,l,t)=>{try{let s=Array.isArray(e.model)?e.model:[e.model];console.log("received deployments: ".concat(s)),console.log("received type of deployments: ".concat(typeof s)),s.forEach(async t=>{console.log("litellm_model: ".concat(t));let s={},a={};s.model=t;let r="";for(let[l,t]of Object.entries(e))if(""!==t){if("model_name"==l)r+=t;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)a[l]=t;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",t);let e={};if(t&&void 0!=t){try{e=JSON.parse(t)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,t]of Object.entries(e))s[l]=t}}else s[l]=t}let n={model_name:r,litellm_params:s,model_info:a},o=await x(l,n);console.log("response for model create call: ".concat(o.data))}),t.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};var e8=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d,modelData:m={data:[]},setModelData:x}=e,[p,j]=(0,n.useState)([]),[g]=er.Z.useForm(),[f,y]=(0,n.useState)(null),[Z,w]=(0,n.useState)(""),[b,k]=(0,n.useState)([]),v=Object.values(a).filter(e=>isNaN(Number(e))),[S,A]=(0,n.useState)("OpenAI"),[N,C]=(0,n.useState)(""),[I,P]=(0,n.useState)(!1),[T,E]=(0,n.useState)(null),[F,M]=(0,n.useState)([]),[R,L]=(0,n.useState)(null),U=e=>{E(e),P(!0)},z=async e=>{if(console.log("handleEditSubmit:",e),null==o)return;let l={},t=null;for(let[s,a]of Object.entries(e))"model_id"!==s?l[s]=a:t=a;let s={litellm_params:l,model_info:{id:t}};console.log("handleEditSubmit payload:",s),await D(o,s),h.ZP.success("Model updated successfully, restart server to see updates"),P(!1),E(null)},B=()=>{w(new Date().toLocaleString())};if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await _(o,d,c);console.log("Model data response:",e.data),x(e);let l=new Set;for(let t=0;t{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),y(e)};null==f&&l(),B()},[o,i,c,d,f,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let q=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(f)),null!=f&&"object"==typeof f&&e in f)?f[e].litellm_provider:"openai";if(a){let e=a.split("/"),l=e[0];n=1===e.length?h(a):l}else n="openai";r&&(o=null==r?void 0:r.input_cost_per_token,i=null==r?void 0:r.output_cost_per_token,c=null==r?void 0:r.max_tokens),(null==s?void 0:s.litellm_params)&&(d=Object.fromEntries(Object.entries(null==s?void 0:s.litellm_params).filter(e=>{let[l]=e;return"model"!==l&&"api_base"!==l}))),m.data[e].provider=n,m.data[e].input_cost=o,m.data[e].output_cost=i,m.data[e].max_tokens=c,m.data[e].api_base=null==s?void 0:null===(t=s.litellm_params)||void 0===t?void 0:t.api_base,m.data[e].cleanedLitellmParams=d,q.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to view all models"})]})}let K=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=e2[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof f&&Object.entries(f).forEach(l=>{let[s,a]=l;null!==a&&"object"==typeof a&&"litellm_provider"in a&&(a.litellm_provider===e||a.litellm_provider.includes(e))&&t.push(s)}),k(t),console.log("providerModels: ".concat(b))}},V=async()=>{try{h.ZP.info("Running health check..."),C("");let e=await W(o);C(e)}catch(e){console.error("Error running health check:",e),C("Error running health check")}};return console.log("selectedProvider: ".concat(S)),console.log("providerModels.length: ".concat(b.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{className:"flex justify-between mt-2 w-full items-center",children:[(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)(eU.Z,{children:"All Models"}),(0,r.jsx)(eU.Z,{children:"Add Model"}),(0,r.jsx)(eU.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[Z&&(0,r.jsxs)(el.Z,{children:["Last Refreshed: ",Z]}),(0,r.jsx)(eZ.Z,{icon:eH.Z,variant:"shadow",size:"xs",className:"self-center",onClick:B})]})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(Y.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)(el.Z,{children:"Filter by Public Model Name"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2 ml-2 w-50",defaultValue:"all",onValueChange:e=>L("all"===e?"all":e),children:[(0,r.jsx)(eN.Z,{value:"all",children:"All Models"}),F.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>L(e),children:e},l))]})]}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Public Model Name "}),(0,r.jsx)(ev.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(ev.Z,{children:"API Base"}),(0,r.jsx)(ev.Z,{children:"Extra litellm Params"}),(0,r.jsx)(ev.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(ev.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(eb.Z,{children:m.data.filter(e=>"all"===R||e.model_name===R||null==R||""===R).map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:e.model_name})}),(0,r.jsx)(e_.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(e_.Z,{children:e.api_base}),(0,r.jsx)(e_.Z,{children:(0,r.jsxs)(X.Z,{children:[(0,r.jsx)(ee.Z,{children:(0,r.jsx)(el.Z,{children:"Litellm params"})}),(0,r.jsx)(Q.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(e_.Z,{children:e.input_cost}),(0,r.jsx)(e_.Z,{children:e.output_cost}),(0,r.jsx)(e_.Z,{children:e.max_tokens}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>U(e)}),(0,r.jsx)(e$,{modelID:e.model_info.id,accessToken:o})]})]},l))})]})})]}),(0,r.jsx)(e=>{let{visible:l,onCancel:t,model:s,onSubmit:a}=e,[n]=er.Z.useForm(),o={},i="",c="";if(s){o=s.litellm_params,i=s.model_name;let e=s.model_info;e&&(c=e.id,console.log("model_id: ".concat(c)),o.model_id=c)}return(0,r.jsx)(en.Z,{title:"Edit Model "+i,visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a(e),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:z,initialValues:o,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{className:"mt-8",label:"api_base",name:"api_base",children:(0,r.jsx)($.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"tpm",name:"tpm",tooltip:"int (optional) - Tokens limit for this deployment: in tokens per minute (tpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"rpm",name:"rpm",tooltip:"int (optional) - Rate limit for this deployment: in requests per minute (rpm). Find this information on your model/providers website",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"max_retries",name:"max_retries",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"timeout",name:"timeout",tooltip:"int (optional) - Timeout in seconds for LLM requests (Defaults to 600 seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"stream_timeout",name:"stream_timeout",tooltip:"int (optional) - Timeout for stream requests (seconds)",children:(0,r.jsx)(ei.Z,{min:0,step:1})}),(0,r.jsx)(er.Z.Item,{label:"model_id",name:"model_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})},{visible:I,onCancel:()=>{P(!1),E(null)},model:T,onSubmit:z})]}),(0,r.jsxs)(eB.Z,{className:"h-full",children:[(0,r.jsx)(e0,{level:2,children:"Add new model"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(er.Z,{form:g,onFinish:()=>{g.validateFields().then(e=>{e4(e,o,g)}).catch(e=>{console.error("Validation failed:",e)})},labelCol:{span:10},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Provider:",name:"custom_llm_provider",tooltip:"E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:S.toString(),children:v.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>{K(e),A(e)},children:e},l))})}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Public Model Name",name:"model_name",tooltip:"Model name your users will pass in. Also used for load-balancing, LiteLLM will load balance between all models with this public name.",className:"mb-0",children:(0,r.jsx)($.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=S.toString())?"gemini-pro":"Anthropic"==s?"claude-3-opus":"Amazon Bedrock"==s?"claude-3-opus":"Gemini (Google AI Studio)"==s?"gemini-pro":"gpt-3.5-turbo"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"LiteLLM Model Name(s)",name:"model",tooltip:"Actual model name used for making litellm.completion() call.",className:"mb-0",children:"Azure"===S?(0,r.jsx)($.Z,{placeholder:"Enter model name"}):b.length>0?(0,r.jsx)(eK.Z,{value:b,children:b.map((e,l)=>(0,r.jsx)(eV.Z,{value:e,children:e},l))}):(0,r.jsx)($.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/proxy/reliability#step-1---set-deployments-on-config",target:"_blank",children:"loadbalance"})," models with the same 'public name'"]})})]}),"Amazon Bedrock"!=S&&"Vertex AI (Anthropic, Gemini, etc.)"!=S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)($.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==S&&(0,r.jsx)(er.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)($.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)($.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eQ.Z,{name:"file",accept:".json",beforeUpload:e=>{if("application/json"===e.type){let l=new FileReader;l.onload=e=>{if(e.target){let l=e.target.result;g.setFieldsValue({vertex_credentials:l})}},l.readAsText(e)}return!1},onChange(e){"uploading"!==e.file.status&&console.log(e.file,e.fileList),"done"===e.file.status?h.ZP.success("".concat(e.file.name," file uploaded successfully")):"error"===e.file.status&&h.ZP.error("".concat(e.file.name," file upload failed."))},children:(0,r.jsx)(ec.ZP,{icon:(0,r.jsx)(eX.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==S&&(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsx)(el.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==S||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==S)&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)($.Z,{placeholder:"https://..."})}),"Azure"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)($.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==S&&(0,r.jsxs)(er.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)($.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(el.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(e1,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Access Key ID",name:"aws_access_key_id",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Secret Access Key",name:"aws_secret_access_key",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:""})}),"Amazon Bedrock"==S&&(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"AWS Region Name",name:"aws_region_name",tooltip:"You can provide the raw key or the environment variable (e.g. `os.environ/MY_SECRET_KEY`).",children:(0,r.jsx)($.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(er.Z.Item,{label:"LiteLLM Params",name:"litellm_extra_params",tooltip:"Optional litellm params used for making a litellm.completion() call.",className:"mb-0",children:(0,r.jsx)(eY.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(eG.Z,{children:[(0,r.jsx)(eW.Z,{span:10}),(0,r.jsx)(eW.Z,{span:10,children:(0,r.jsxs)(el.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(e1,{href:"https://docs.litellm.ai/docs/completion/input",target:"_blank",children:"litellm.completion() call"})]})})]})]}),(0,r.jsx)("div",{style:{textAlign:"center",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eJ.Z,{title:"Get help on our github",children:(0,r.jsx)(eR.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(el.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(H.Z,{onClick:V,children:"Run `/health`"}),N&&(0,r.jsx)("pre",{children:JSON.stringify(N,null,2)})]})})]})]})})};let{Option:e5}=ea.default;var e3=e=>{let{userID:l,accessToken:t,teams:s}=e,[a]=er.Z.useForm(),[o,i]=(0,n.useState)(!1),[c,d]=(0,n.useState)(null),[m,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await v(t,l,"any"),s=[];for(let l=0;l{i(!1),a.resetFields()},p=()=>{i(!1),d(null),a.resetFields()},j=async e=>{try{h.ZP.info("Making API Call"),i(!0),console.log("formValues in create user:",e);let s=await g(t,null,e);console.log("user create Response:",s),d(s.key),h.ZP.success("API user Created"),a.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Invite User"}),(0,r.jsxs)(en.Z,{title:"Invite User",visible:o,width:800,footer:null,onOk:x,onCancel:p,children:[(0,r.jsx)(el.Z,{className:"mb-1",children:"Invite a user to login to the Admin UI and create Keys"}),(0,r.jsx)(el.Z,{className:"mb-6",children:(0,r.jsx)("b",{children:"Note: SSO Setup Required for this"})}),(0,r.jsxs)(er.Z,{form:a,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(er.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(ea.default,{placeholder:"Select Team ID",style:{width:"100%"},children:s?s.map(e=>(0,r.jsx)(e5,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(e5,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(er.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(eo.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create User"})})]})]}),c&&(0,r.jsxs)(en.Z,{title:"User Created Successfully",visible:o,onOk:x,onCancel:p,footer:null,children:[(0,r.jsx)("p",{children:"User has been created to access your proxy. Please Ask them to Log In."}),(0,r.jsx)("br",{}),(0,r.jsx)("p",{children:(0,r.jsx)("b",{children:"Note: This Feature is only supported through SSO on the Admin UI"})})]})]})},e6=e=>{let{accessToken:l,token:t,keys:s,userRole:a,userID:o,teams:i,setKeys:c}=e,[d,m]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(0),[j,g]=n.useState(null),[f,y]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await Z(l,null,a,!0,x,25);console.log("user data response:",e),m(e)}catch(e){console.error("There was an error fetching the model data",e)}};l&&t&&a&&o&&e();let s=async()=>{try{let e=await T(l,null);console.log("user data response:",e),u(e)}catch(e){console.error("There was an error fetching the model data",e)}};a&&("Admin"==a||"Admin Viewer"==a)&&!h&&s()},[l,t,a,o,x]),!d||!l||!t||!a||!o)return(0,r.jsx)("div",{children:"Loading..."});let w=async e=>{try{let t=await T(l,e);console.log("user data response:",t),u(t)}catch(e){console.error("There was an error fetching the model data",e)}};return(0,r.jsx)("div",{style:{width:"100%"},children:(0,r.jsxs)(Y.Z,{className:"gap-2 p-2 h-[80vh] w-full mt-8",children:[(0,r.jsx)(e3,{userID:o,accessToken:l,teams:i}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[80vh] mb-4",children:[(0,r.jsxs)("div",{className:"mb-4 mt-1",children:[(0,r.jsxs)(el.Z,{children:[(0,r.jsx)("b",{children:"Key Owners: "})," Users on LiteLLM that created API Keys. Automatically tracked by LiteLLM"]}),(0,r.jsxs)(el.Z,{className:"mt-1",children:[(0,r.jsx)("b",{children:"End Users: "}),"End Users of your LLM API calls. Tracked When a `user` param is passed in your LLM calls"]})]}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eU.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(ew.Z,{className:"mt-5",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"User ID"}),(0,r.jsx)(ev.Z,{children:"User Email"}),(0,r.jsx)(ev.Z,{children:"User Models"}),(0,r.jsx)(ev.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(ev.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(eb.Z,{children:d.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_id}),(0,r.jsx)(e_.Z,{children:e.user_email}),(0,r.jsx)(e_.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(e_.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(e_.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(Y.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(ep.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(ep.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsxs)("div",{className:"flex-1 flex justify-between items-center",children:[(0,r.jsx)(el.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(eA.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_alias&&e.key_alias.length>0)return(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>w(e.token),children:e.key_alias},l)})})]})]}),(0,r.jsxs)(ew.Z,{className:"max-h-[70vh] min-h-[500px]",children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"End User"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Total Events"})]})}),(0,r.jsx)(eb.Z,{children:null==h?void 0:h.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.end_user}),(0,r.jsx)(e_.Z,{children:e.total_spend}),(0,r.jsx)(e_.Z,{children:e.total_events})]},l))})]})]})]})]})]}),function(){if(!d)return null;let e=Math.ceil(d.length/25);return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",x+1," of ",e]}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l focus:outline-none",disabled:0===x,onClick:()=>p(x-1),children:"← Prev"}),(0,r.jsx)("button",{className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r focus:outline-none",onClick:()=>{p(x+1)},children:"Next →"})]})]})}()]})})},e7=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=er.Z.useForm(),[d]=er.Z.useForm(),{Title:m,Paragraph:u}=eR.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[f,Z]=(0,n.useState)(l?l[0]:null),[b,_]=(0,n.useState)(!1),[k,S]=(0,n.useState)(!1),[A,N]=(0,n.useState)([]),[C,I]=(0,n.useState)(!1),[P,T]=(0,n.useState)(null),[E,F]=(0,n.useState)({}),O=e=>{Z(e),g(!0)},M=async e=>{let t=e.team_id;if(console.log("handleEditSubmit:",e),null==s)return;let r=await U(s,e);l&&a(l.map(e=>e.team_id===t?r.data:e)),h.ZP.success("Team updated successfully"),g(!1),Z(null)},L=async e=>{T(e),I(!0)},D=async()=>{if(null!=P&&null!=l&&null!=s){try{await y(s,P);let e=l.filter(e=>e.team_id!==P);a(e)}catch(e){console.error("Error deleting the team:",e)}I(!1),T(null)}};(0,n.useEffect)(()=>{let e=async()=>{try{if(null===o||null===i||null===s||null===l)return;console.log("fetching team info:");let e={};for(let t=0;t<(null==l?void 0:l.length);t++){let a=l[t].team_id,r=await w(s,a);console.log("teamInfo response:",r),null!==r&&(e={...e,[a]:r})}F(e)}catch(e){console.error("Error fetching team info:",e)}};(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await v(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),N(e)}}catch(e){console.error("Error fetching user models:",e)}})(),e()},[s,o,i,l]);let B=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await R(s,e);null!==l?a([...l,t]):a([t]),console.log("response for team create call: ".concat(t)),h.ZP.success("Team created"),_(!1)}}catch(e){console.error("Error creating the team:",e),h.ZP.error("Error creating the team: "+e,20)}},q=async e=>{try{if(null!=s&&null!=l){h.ZP.info("Adding Member");let t={role:"user",user_email:e.user_email,user_id:e.user_id},r=await z(s,f.team_id,t);console.log("response for team create call: ".concat(r.data));let n=l.findIndex(e=>(console.log("team.team_id=".concat(e.team_id,"; response.data.team_id=").concat(r.data.team_id)),e.team_id===r.data.team_id));if(console.log("foundIndex: ".concat(n)),-1!==n){let e=[...l];e[n]=r.data,a(e),Z(r.data)}S(!1)}}catch(e){console.error("Error creating the team:",e)}};return console.log("received teams ".concat(l)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Team Name"}),(0,r.jsx)(ev.Z,{children:"Spend (USD)"}),(0,r.jsx)(ev.Z,{children:"Budget (USD)"}),(0,r.jsx)(ev.Z,{children:"Models"}),(0,r.jsx)(ev.Z,{children:"TPM / RPM Limits"}),(0,r.jsx)(ev.Z,{children:"Info"})]})}),(0,r.jsx)(eb.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(e_.Z,{style:{maxWidth:"8-x",whiteSpace:"pre-wrap",overflow:"hidden"},children:Array.isArray(e.models)?(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:0===e.models.length?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(el.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ep.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(el.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(e_.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(el.Z,{children:["TPM:"," ",e.tpm_limit?e.tpm_limit:"Unlimited"," ",(0,r.jsx)("br",{}),"RPM:"," ",e.rpm_limit?e.rpm_limit:"Unlimited"]})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].keys&&E[e.team_id].keys.length," Keys"]}),(0,r.jsxs)(el.Z,{children:[E&&e.team_id&&E[e.team_id]&&E[e.team_id].team_info&&E[e.team_id].team_info.members_with_roles&&E[e.team_id].team_info.members_with_roles.length," Members"]})]}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>O(e)}),(0,r.jsx)(eZ.Z,{onClick:()=>L(e.team_id),icon:ex.Z,size:"sm"})]})]},e.team_id)):null})]}),C&&(0,r.jsx)("div",{className:"fixed z-10 inset-0 overflow-y-auto",children:(0,r.jsxs)("div",{className:"flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,r.jsx)("div",{className:"fixed inset-0 transition-opacity","aria-hidden":"true",children:(0,r.jsx)("div",{className:"absolute inset-0 bg-gray-500 opacity-75"})}),(0,r.jsx)("span",{className:"hidden sm:inline-block sm:align-middle sm:h-screen","aria-hidden":"true",children:"​"}),(0,r.jsxs)("div",{className:"inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full",children:[(0,r.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:(0,r.jsx)("div",{className:"sm:flex sm:items-start",children:(0,r.jsxs)("div",{className:"mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left",children:[(0,r.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",children:"Delete Team"}),(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)("p",{className:"text-sm text-gray-500",children:"Are you sure you want to delete this team ?"})})]})})}),(0,r.jsxs)("div",{className:"bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse",children:[(0,r.jsx)(H.Z,{onClick:D,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(H.Z,{onClick:()=>{I(!1),T(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>_(!0),children:"+ Create New Team"}),(0,r.jsx)(en.Z,{title:"Create Team",visible:b,width:800,footer:null,onOk:()=>{_(!1),c.resetFields()},onCancel:()=>{_(!1),c.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:B,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)($.Z,{placeholder:""})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"Team Members"}),(0,r.jsx)(u,{children:"If you belong to multiple teams, this setting controls which teams members you see."}),l&&l.length>0?(0,r.jsx)(eA.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eN.Z,{value:String(l),onClick:()=>{Z(e)},children:e.team_alias},l))}):(0,r.jsxs)(u,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:f?f.members_with_roles.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.role})]},l)):null})]})}),f&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=er.Z.useForm();return(0,r.jsx)(en.Z,{title:"Edit Team",visible:l,width:800,footer:null,onOk:()=>{n.validateFields().then(e=>{a({...e,team_id:s.team_id}),n.resetFields()}).catch(e=>{console.error("Validation failed:",e)})},onCancel:t,children:(0,r.jsxs)(er.Z,{form:n,onFinish:M,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(ea.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),A&&A.map(e=>(0,r.jsx)(ea.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(er.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(ei.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(er.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(ei.Z,{step:1,width:400})}),(0,r.jsx)(er.Z.Item,{label:"Requests per minute Limit (RPM)",name:"team_id",hidden:!0})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),Z(null)},team:f,onSubmit:M})]}),(0,r.jsxs)(J.Z,{numColSpan:1,children:[(0,r.jsx)(H.Z,{className:"mx-auto mb-5",onClick:()=>S(!0),children:"+ Add member"}),(0,r.jsx)(en.Z,{title:"Add member",visible:k,width:800,footer:null,onOk:()=>{S(!1),d.resetFields()},onCancel:()=>{S(!1),d.resetFields()},children:(0,r.jsxs)(er.Z,{form:c,onFinish:q,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e9=t(18190),le=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=er.Z.useForm(),[i]=er.Z.useForm(),{Title:c,Paragraph:d}=eR.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[f,y]=(0,n.useState)(!1),[Z,w]=(0,n.useState)(!1),[b,_]=(0,n.useState)(!1),[k,v]=(0,n.useState)(!1);try{l=window.location.origin}catch(e){l=""}l+="/fallback/login";let S=()=>{v(!1)},A=["proxy_admin","proxy_admin_viewer"];(0,n.useEffect)(()=>{(async()=>{if(null!=s){let e=[],l=await M(s,"proxy_admin_viewer");l.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy viewers: ".concat(l));let t=await M(s,"proxy_admin");t.forEach(l=>{e.push({user_role:l.user_role,user_id:l.user_id,user_email:l.user_email})}),console.log("proxy admins: ".concat(t)),console.log("combinedList: ".concat(e)),p(e)}})()},[s]);let N=()=>{w(!1),i.resetFields()},C=()=>{w(!1),i.resetFields()},I=e=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_email",className:"px-3 py-2 border rounded-md w-full"})}),(0,r.jsx)("div",{className:"text-center mb-4",children:"OR"}),(0,r.jsx)(er.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(eo.Z,{name:"user_id",className:"px-3 py-2 border rounded-md w-full"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(er.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(eA.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(eo.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,null);console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),h.ZP.success("Refresh tab to see updated user role"),w(!1)}}catch(e){console.error("Error creating the key:",e)}},E=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await B(s,e,"proxy_admin_viewer");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),g(!1)}}catch(e){console.error("Error creating the key:",e)}},F=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await B(s,e,"proxy_admin");console.log("response for team create call: ".concat(l));let t=x.findIndex(e=>(console.log("user.user_id=".concat(e.user_id,"; response.user_id=").concat(l.user_id)),e.user_id===l.user_id));console.log("foundIndex: ".concat(t)),-1==t&&(console.log("updates admin with new user"),x.push(l),p(x)),y(!1)}}catch(e){console.error("Error creating the key:",e)}},O=async e=>{null!=s&&G(s,{environment_variables:{PROXY_BASE_URL:e.proxy_base_url,GOOGLE_CLIENT_ID:e.google_client_id,GOOGLE_CLIENT_SECRET:e.google_client_secret}})};return console.log("admins: ".concat(null==x?void 0:x.length)),(0,r.jsxs)("div",{className:"w-full m-2 mt-2 p-8",children:[(0,r.jsx)(c,{level:4,children:"Admin Access "}),(0,r.jsxs)(d,{children:[a&&(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/ui#restrict-ui-access",children:"Requires SSO Setup"}),(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin: "})," Can create keys, teams, users, add models, etc. ",(0,r.jsx)("br",{}),(0,r.jsx)("b",{children:"Proxy Admin Viewer: "}),"Can just view spend. They cannot create keys, teams or grant users access to new models."," "]}),(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsx)(eg.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Member Name"}),(0,r.jsx)(ev.Z,{children:"Role"})]})}),(0,r.jsx)(eb.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(e_.Z,{children:e.user_role}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(eZ.Z,{icon:eu.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(en.Z,{title:"Update role",visible:Z,width:800,footer:null,onOk:N,onCancel:C,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(H.Z,{className:"mr-4 mb-5",onClick:()=>y(!0),children:"+ Add admin"}),(0,r.jsx)(en.Z,{title:"Add admin",visible:f,width:800,footer:null,onOk:()=>{y(!1),i.resetFields()},onCancel:()=>{y(!1),i.resetFields()},children:I(F)}),(0,r.jsx)(H.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(en.Z,{title:"Add viewer",visible:j,width:800,footer:null,onOk:()=>{g(!1),i.resetFields()},onCancel:()=>{g(!1),i.resetFields()},children:I(E)})]})})]}),(0,r.jsxs)(Y.Z,{children:[(0,r.jsx)(c,{level:4,children:"Add SSO"}),(0,r.jsxs)("div",{className:"flex justify-start mb-4",children:[(0,r.jsx)(H.Z,{onClick:()=>_(!0),children:"Add SSO"}),(0,r.jsx)(en.Z,{title:"Add SSO",visible:b,width:800,footer:null,onOk:()=>{_(!1),o.resetFields()},onCancel:()=>{_(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{F(e),O(e),_(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(eo.Z,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(eo.Z.Password,{})}),(0,r.jsx)(er.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(eo.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(en.Z,{title:"SSO Setup Instructions",visible:k,width:800,footer:null,onOk:S,onCancel:()=>{v(!1)},children:[(0,r.jsx)("p",{children:"Follow these steps to complete the SSO setup:"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(el.Z,{className:"mt-2",children:"4. If Step 3 is successful, you can close this tab"}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e9.Z,{title:"Login without SSO",color:"teal",children:["If you need to login without sso, you can access ",(0,r.jsxs)("a",{href:l,target:"_blank",children:[(0,r.jsx)("b",{children:l})," "]})]})]})]})},ll=t(12224),lt=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)(!1),[u]=er.Z.useForm(),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)(""),[Z,w]=(0,n.useState)({}),[b,_]=(0,n.useState)([]),k=e=>{b.includes(e)?_(b.filter(l=>l!==e)):_([...b,e])},v={llm_exceptions:"LLM Exceptions",llm_too_slow:"LLM Responses Too Slow",llm_requests_hanging:"LLM Requests Hanging",budget_alerts:"Budget Alerts (API Keys, Users)"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),o(e.callbacks);let l=e.alerts;if(console.log("alerts_data",l),l&&l.length>0){let e=l[0];console.log("_alert_info",e);let t=e.variables.SLACK_WEBHOOK_URL;console.log("catch_all_webhook",t),_(e.active_alerts),y(t),w(e.alerts_to_webhook)}c(l)})},[l,t,s]);let S=e=>b&&b.includes(e),A=e=>{if(!l)return;let t=Object.fromEntries(Object.entries(e.variables).map(e=>{var l;let[t,s]=e;return[t,(null===(l=document.querySelector('input[name="'.concat(t,'"]')))||void 0===l?void 0:l.value)||s]}));console.log("updatedVariables",t),console.log("updateAlertTypes",j);try{G(l,{environment_variables:t})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},N=()=>{l&&u.validateFields().then(e=>{if(console.log("Form values:",e),"langfuse"===e.callback){G(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}});let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:null,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey}};o(a?[...a,t]:[t])}else if("slack"===e.callback){console.log("values.slackWebhookUrl: ".concat(e.slackWebhookUrl)),G(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),console.log("values.callback: ".concat(e.callback));let t={name:e.callback,variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl,LANGFUSE_HOST:null,LANGFUSE_PUBLIC_KEY:null,LANGFUSE_SECRET_KEY:null}};o(a?[...a,t]:[t])}m(!1),u.resetFields(),p(null)})};return l?(console.log("callbacks: ".concat(a)),(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsx)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"Logging Callbacks"}),(0,r.jsx)(eU.Z,{value:"2",children:"Alerting"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Callback"}),(0,r.jsx)(ev.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(eb.Z,{children:a.map((e,t)=>{var s;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ep.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(null!==(s=e.variables)&&void 0!==s?s:{}).filter(e=>{let[l,t]=e;return null!==t}).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(el.Z,{className:"mt-2",children:l}),"LANGFUSE_HOST"===l?(0,r.jsx)("p",{children:"default value=https://cloud.langfuse.com"}):(0,r.jsx)("div",{}),(0,r.jsx)($.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>A(e),children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),m(!0)},children:"Add Callback"})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsxs)(el.Z,{className:"my-2",children:["Alerts are only supported for Slack Webhook URLs. Get your webhook urls from ",(0,r.jsx)("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",style:{color:"blue"},children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{}),(0,r.jsx)(ev.Z,{children:"Slack Webhook URL"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(v).map((e,l)=>{let[t,s]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:(0,r.jsx)(ll.Z,{id:"switch",name:"switch",checked:S(t),onChange:()=>k(t)})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(el.Z,{children:s})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:t,type:"password",defaultValue:Z&&Z[t]?Z[t]:f})})]},l)})})]}),(0,r.jsx)(H.Z,{size:"xs",className:"mt-2",onClick:()=>{if(!l)return;let e={};Object.entries(v).forEach(l=>{let[t,s]=l,a=document.querySelector('input[name="'.concat(t,'"]'));console.log("key",t),console.log("webhookInput",a);let r=(null==a?void 0:a.value)||"";console.log("newWebhookValue",r),e[t]=r}),console.log("updatedAlertToWebhooks",e);let t={general_settings:{alert_to_webhook_url:e,alert_types:b}};console.log("payload",t);try{G(l,t)}catch(e){h.ZP.error("Failed to update alerts: "+e,20)}h.ZP.success("Alerts updated successfully")},children:"Save Changes"}),(0,r.jsx)(H.Z,{onClick:()=>K(l,"slack"),className:"mx-2",children:"Test Alerts"})]})})]})]})}),(0,r.jsx)(en.Z,{title:"Add Callback",visible:d,onOk:N,width:800,onCancel:()=>{m(!1),u.resetFields(),p(null)},footer:null,children:(0,r.jsxs)(er.Z,{form:u,layout:"vertical",onFinish:N,children:[(0,r.jsx)(er.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsx)(ea.default,{onChange:e=>{p(e)},children:(0,r.jsx)(ea.default.Option,{value:"langfuse",children:"langfuse"})})}),"langfuse"===x&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)($.Z,{type:"password"})}),(0,r.jsx)(er.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)($.Z,{type:"password"})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Save"})})]})})]})):null};let{Option:ls}=ea.default;var la=e=>{let{models:l,accessToken:t,routerSettings:s,setRouterSettings:a}=e,[o]=er.Z.useForm(),[i,c]=(0,n.useState)(!1),[d,m]=(0,n.useState)("");return(0,r.jsxs)("div",{children:[(0,r.jsx)(H.Z,{className:"mx-auto",onClick:()=>c(!0),children:"+ Add Fallbacks"}),(0,r.jsx)(en.Z,{title:"Add Fallbacks",visible:i,width:800,footer:null,onOk:()=>{c(!1),o.resetFields()},onCancel:()=>{c(!1),o.resetFields()},children:(0,r.jsxs)(er.Z,{form:o,onFinish:e=>{console.log(e);let{model_name:l,models:r}=e,n=[...s.fallbacks||[],{[l]:r}],i={...s,fallbacks:n};console.log(i);try{G(t,{router_settings:i}),a(i)}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully"),c(!1),o.resetFields()},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(er.Z.Item,{label:"Public Model Name",name:"model_name",rules:[{required:!0,message:"Set the model to fallback for"}],help:"required",children:(0,r.jsx)(eA.Z,{defaultValue:d,children:l&&l.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>m(e),children:e},l))})}),(0,r.jsx)(er.Z.Item,{label:"Fallback Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsx)(eK.Z,{value:l,children:l&&l.filter(e=>e!=d).map(e=>(0,r.jsx)(eV.Z,{value:e,children:e},e))})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(ec.ZP,{htmlType:"submit",children:"Add Fallbacks"})})]})})]})},lr=t(12968);async function ln(e,l){console.log("isLocal:",!1);let t=window.location.origin,s=new lr.ZP.OpenAI({apiKey:l,baseURL:t,dangerouslyAllowBrowser:!0});try{let l=await s.chat.completions.create({model:e,messages:[{role:"user",content:"Hi, this is a test message"}],mock_testing_fallbacks:!0});h.ZP.success((0,r.jsxs)("span",{children:["Test model=",(0,r.jsx)("strong",{children:e}),", received model=",(0,r.jsx)("strong",{children:l.model}),". See ",(0,r.jsx)("a",{href:"#",onClick:()=>window.open("https://docs.litellm.ai/docs/proxy/reliability","_blank"),style:{textDecoration:"underline",color:"blue"},children:"curl"})]}))}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lo=e=>{let{accessToken:l,userRole:t,userID:s,modelData:a}=e,[o,i]=(0,n.useState)({}),[c,d]=(0,n.useState)(!1),[m]=er.Z.useForm(),[u,x]=(0,n.useState)(null),p={routing_strategy_args:"(dict) Arguments to pass to the routing strategy",routing_strategy:"(string) Routing strategy to use",allowed_fails:"(int) Number of times a deployment can fail before being added to cooldown",cooldown_time:"(int) time in seconds to cooldown a deployment after failure",num_retries:"(int) Number of retries for failed requests. Defaults to 0.",timeout:"(float) Timeout for requests. Defaults to None.",retry_after:"(int) Minimum time to wait before retrying a failed request"};(0,n.useEffect)(()=>{l&&t&&s&&V(l,s,t).then(e=>{console.log("callbacks",e),i(e.router_settings)})},[l,t,s]);let j=async e=>{if(l){console.log("received key: ".concat(e)),console.log("routerSettings['fallbacks']: ".concat(o.fallbacks)),o.fallbacks.map(l=>(e in l&&delete l[e],l));try{await G(l,{router_settings:o}),i({...o}),h.ZP.success("Router settings updated successfully")}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}}},g=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).map(e=>{let[l,t]=e;if("routing_strategy_args"!==l){var s;return[l,(null===(s=document.querySelector('input[name="'.concat(l,'"]')))||void 0===s?void 0:s.value)||t]}return null}).filter(e=>null!==e));console.log("updatedVariables",t);try{G(l,{router_settings:t})}catch(e){h.ZP.error("Failed to update router settings: "+e,20)}h.ZP.success("router settings updated successfully")};return l?(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsxs)(eD.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(ez.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eU.Z,{value:"1",children:"General Settings"}),(0,r.jsx)(eU.Z,{value:"2",children:"Fallbacks"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(et.Z,{children:"Router Settings"}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Setting"}),(0,r.jsx)(ev.Z,{children:"Value"})]})}),(0,r.jsx)(eb.Z,{children:Object.entries(o).filter(e=>{let[l,t]=e;return"fallbacks"!=l&&"context_window_fallbacks"!=l}).map(e=>{let[l,t]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsxs)(e_.Z,{children:[(0,r.jsx)(el.Z,{children:l}),(0,r.jsx)("p",{style:{fontSize:"0.65rem",color:"#808080",fontStyle:"italic"},className:"mt-1",children:p[l]})]}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)($.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(J.Z,{children:(0,r.jsx)(H.Z,{className:"mt-2",onClick:()=>g(o),children:"Save Changes"})})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Model Name"}),(0,r.jsx)(ev.Z,{children:"Fallbacks"})]})}),(0,r.jsx)(eb.Z,{children:o.fallbacks&&o.fallbacks.map((e,t)=>Object.entries(e).map(e=>{let[s,a]=e;return(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:s}),(0,r.jsx)(e_.Z,{children:Array.isArray(a)?a.join(", "):a}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(H.Z,{onClick:()=>ln(s,l),children:"Test Fallback"})}),(0,r.jsx)(e_.Z,{children:(0,r.jsx)(eZ.Z,{icon:ex.Z,size:"sm",onClick:()=>j(s)})})]},t.toString()+s)}))})]}),(0,r.jsx)(la,{models:(null==a?void 0:a.data)?a.data.map(e=>e.model_name):[],accessToken:l,routerSettings:o,setRouterSettings:i})]})]})]})}):null},li=t(67951),lc=e=>{let{}=e;return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsxs)("div",{className:"mb-5",children:[(0,r.jsx)("p",{className:"text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:"OpenAI Compatible Proxy: API Reference"}),(0,r.jsx)(el.Z,{className:"mt-2 mb-2",children:"LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to point to your litellm proxy. Example Below "}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eU.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eU.Z,{children:"LlamaIndex"}),(0,r.jsx)(eU.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to send to the proxy\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ]\n)\n\nprint(response)\n '})}),(0,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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,r.jsx)(eB.Z,{children:(0,r.jsx)(li.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:4000",\n model = "gpt-3.5-turbo",\n temperature=0.1\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})]})})})};async function ld(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new lr.ZP.OpenAI({apiKey:s,baseURL:a,dangerouslyAllowBrowser:!0});try{for await(let s of(await r.chat.completions.create({model:t,stream:!0,messages:[{role:"user",content:e}]})))console.log(s),s.choices[0].delta.content&&l(s.choices[0].delta.content)}catch(e){h.ZP.error("Error occurred while generating model response. Please try again. Error: ".concat(e),20)}}var lm=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,[o,i]=(0,n.useState)(""),[c,d]=(0,n.useState)(""),[m,h]=(0,n.useState)([]),[u,x]=(0,n.useState)(void 0),[p,j]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{let e=await v(l,a,s);if(console.log("model_info:",e),(null==e?void 0:e.data.length)>0){let l=e.data.map(e=>({value:e.id,label:e.id}));console.log(l),j(l),x(e.data[0].id)}}catch(e){console.error("Error fetching model info:",e)}})()},[l,a,s]);let g=(e,l)=>{h(t=>{let s=t[t.length-1];return s&&s.role===e?[...t.slice(0,t.length-1),{role:e,content:s.content+l}]:[...t,{role:e,content:l}]})},f=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await ld(c,e=>g("assistant",e),u,o)}catch(e){console.error("Error fetching model response",e),g("assistant","Error fetching model response")}d("")}};if(s&&"Admin Viewer"==s){let{Title:e,Paragraph:l}=eR.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(Y.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(eD.Z,{children:[(0,r.jsx)(ez.Z,{children:(0,r.jsx)(eU.Z,{children:"Chat"})}),(0,r.jsx)(eq.Z,{children:(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(Y.Z,{numItems:2,children:[(0,r.jsxs)(J.Z,{children:[(0,r.jsx)(el.Z,{children:"API Key"}),(0,r.jsx)($.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(J.Z,{className:"mx-2",children:[(0,r.jsx)(el.Z,{children:"Select Model:"}),(0,r.jsx)(ea.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ew.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ek.Z,{children:(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{})})}),(0,r.jsx)(eb.Z,{children:m.map((e,l)=>(0,r.jsx)(eS.Z,{children:(0,r.jsx)(e_.Z,{children:"".concat(e.role,": ").concat(e.content)})},l))})]}),(0,r.jsx)("div",{className:"mt-3",style:{position:"absolute",bottom:5,width:"95%"},children:(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)($.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(H.Z,{onClick:f,className:"ml-2",children:"Send"})]})})]})})]})})})})},lh=t(33509),lu=t(95781);let{Sider:lx}=lh.default;var lp=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lx,{width:120,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(lh.default,{style:{minHeight:"100vh",maxWidth:"145px"},children:(0,r.jsx)(lx,{width:145,children:(0,r.jsxs)(lu.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(el.Z,{children:"API Keys"})},"1"),(0,r.jsx)(lu.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(el.Z,{children:"Test Key"})},"3"),"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(el.Z,{children:"Models"})},"2"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(el.Z,{children:"Usage"})},"4"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(el.Z,{children:"Teams"})},"6"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(el.Z,{children:"Users"})},"5"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(el.Z,{children:"Logging & Alerts"})},"8"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(el.Z,{children:"Router Settings"})},"9"):null,"Admin"==t?(0,r.jsx)(lu.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(el.Z,{children:"Admin"})},"7"):null,(0,r.jsx)(lu.Z.Item,{onClick:()=>l("api_ref"),children:(0,r.jsx)(el.Z,{children:"API Reference"})},"11")]})})})},lj=t(67989),lg=e=>{let{accessToken:l,token:t,userRole:s,userID:a}=e,o=new Date,[i,c]=(0,n.useState)([]),[d,m]=(0,n.useState)([]),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)([]),[j,g]=(0,n.useState)([]),[f,y]=(0,n.useState)([]),[Z,w]=(0,n.useState)([]),[b,v]=(0,n.useState)([]),[S,T]=(0,n.useState)([]),[O,M]=(0,n.useState)([]),[R,L]=(0,n.useState)([]),[U,D]=(0,n.useState)(null),z=new Date(o.getFullYear(),o.getMonth(),1),B=new Date(o.getFullYear(),o.getMonth()+1,0),q=V(z),K=V(B);function V(e){let l=e.getFullYear(),t=e.getMonth()+1,s=e.getDate();return"".concat(l,"-").concat(t<10?"0"+t:t,"-").concat(s<10?"0"+s:s)}console.log("Start date is ".concat(q)),console.log("End date is ".concat(K)),(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{if(console.log("user role: ".concat(s)),"Admin"==s||"Admin Viewer"==s){let e=await I(l);c(e);let t=(await P(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let r=(await E(l)).map(e=>({key:e.model,spend:e.total_spend}));u(r);let n=await A(l);console.log("teamSpend",n),g(n.daily_spend),w(n.teams);let o=n.total_spend_per_team;o=o.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),v(o);let i=await N(l);y(i.top_10_tags);let d=(await _(l,a,s)).data;console.log("model groups in model dashboard",d);let h=[];for(let e=0;e{if(console.log("result from spend logs call",e),"daily_spend"in e){let l=e.daily_spend;console.log("daily spend",l),c(l);let t=e.top_api_keys;m(t)}else{let t=(await F(l,function(e){let l=[];e.forEach(e=>{Object.entries(e).forEach(e=>{let[t,s]=e;"spend"!==t&&"startTime"!==t&&"models"!==t&&"users"!==t&&l.push({key:t,spend:s})})}),l.sort((e,l)=>Number(l.spend)-Number(e.spend));let t=l.slice(0,5).map(e=>e.key);return console.log("topKeys: ".concat(Object.keys(t[0]))),t}(e))).info.map(e=>({key:(e.key_name||e.key_alias).substring(0,10),spend:e.spend}));m(t),p(function(e){let l={};e.forEach(e=>{Object.entries(e.users).forEach(e=>{let[t,s]=e;""!==t&&null!=t&&"None"!=t&&(l[t]||(l[t]=0),l[t]+=s)})});let t=Object.entries(l).map(e=>{let[l,t]=e;return{user_id:l,spend:t}});t.sort((e,l)=>l.spend-e.spend);let s=t.slice(0,5);return console.log("topKeys: ".concat(Object.values(s[0]))),s}(e)),c(e)}});let e=await k(l,a,s,null);console.log("Model metrics response:",e);let r=[...e].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(e),M(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,q,K]);let G=async e=>{if(console.log("Updating model metrics for group:",e),l&&a&&s){D(e);try{let t=await k(l,a,s,e);console.log("Model metrics response:",t);let r=[...t].sort((e,l)=>l.avg_latency_seconds-e.avg_latency_seconds);console.log("Sorted by latency:",r),T(t),M(r)}catch(e){console.error("Failed to fetch model metrics",e)}}};return(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(eE,{userID:a,userRole:s,accessToken:l,userSpend:null,selectedTeam:null}),(0,r.jsxs)(eD.Z,{children:[(0,r.jsxs)(ez.Z,{className:"mt-2",children:[(0,r.jsx)(eU.Z,{children:"All Up"}),(0,r.jsx)(eU.Z,{children:"Team Based Usage"}),(0,r.jsx)(eU.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eU.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eq.Z,{children:[(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Monthly Spend"}),(0,r.jsx)(ej.Z,{data:i,index:"date",categories:["spend"],colors:["blue"],valueFormatter:e=>"$ ".concat(new Intl.NumberFormat("us").format(e).toString()),yAxisWidth:100,tickGap:5})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top API Keys"}),(0,r.jsx)(ej.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,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Users"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:x,index:"user_id",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})}),(0,r.jsx)(J.Z,{numColSpan:1,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Top Models"}),(0,r.jsx)(ej.Z,{className:"mt-4 h-40",data:h,index:"key",categories:["spend"],colors:["blue"],yAxisWidth:200,layout:"vertical",showXAxis:!1,showLegend:!1})]})})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(J.Z,{numColSpan:2,children:[(0,r.jsxs)(eg.Z,{className:"mb-2",children:[(0,r.jsx)(et.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(lj.Z,{data:b})]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(ej.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:Z,yAxisWidth:80,colors:["blue","green","yellow","red","purple"],stack:!0})]})]}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsx)(eB.Z,{children:(0,r.jsxs)(Y.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(J.Z,{numColSpan:2,children:(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(el.Z,{children:["Get Started Tracking cost per tag ",(0,r.jsx)("a",{href:"https://docs.litellm.ai/docs/proxy/enterprise#tracking-spend-for-custom-tags",target:"_blank",children:"here"})]}),(0,r.jsxs)(ew.Z,{children:[(0,r.jsx)(ek.Z,{children:(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(ev.Z,{children:"Tag"}),(0,r.jsx)(ev.Z,{children:"Spend"}),(0,r.jsx)(ev.Z,{children:"Requests"})]})}),(0,r.jsx)(eb.Z,{children:f.map(e=>(0,r.jsxs)(eS.Z,{children:[(0,r.jsx)(e_.Z,{children:e.name}),(0,r.jsx)(e_.Z,{children:e.value}),(0,r.jsx)(e_.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(J.Z,{numColSpan:2})]})}),(0,r.jsxs)(eB.Z,{children:[(0,r.jsx)(et.Z,{children:"Filter By Model Group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080"},children:"View how requests were load balanced within a model group"}),(0,r.jsx)("p",{style:{fontSize:"0.85rem",color:"#808080",fontStyle:"italic"},children:"(Beta feature) only supported for Azure Model Groups"}),(0,r.jsxs)(eA.Z,{className:"mb-4 mt-2",defaultValue:"all",children:[(0,r.jsx)(eN.Z,{value:"all",onClick:()=>G(null),children:"All Model Groups"}),R.map((e,l)=>(0,r.jsx)(eN.Z,{value:e,onClick:()=>G(e),children:e},l))]}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(et.Z,{children:"Number Requests per Model"}),(0,r.jsx)(ej.Z,{data:S,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(eg.Z,{className:"mt-4",children:[(0,r.jsx)(et.Z,{children:"Latency Per Model"}),(0,r.jsx)(ej.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},lf=()=>{let{Title:e,Paragraph:l}=eR.default,[t,s]=(0,n.useState)(""),[a,i]=(0,n.useState)(null),[c,d]=(0,n.useState)(null),[h,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(!0),j=(0,o.useSearchParams)(),[g,f]=(0,n.useState)({data:[]}),y=j.get("userID"),Z=j.get("token"),[w,b]=(0,n.useState)("api-keys"),[_,k]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(Z){let e=(0,eM.o)(Z);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),k(e.key),e.user_role){let l=function(e){if(!e)return"Undefined Role";switch(console.log("Received user role: ".concat(e.toLowerCase())),console.log("Received user role length: ".concat(e.toLowerCase().length)),e.toLowerCase()){case"app_owner":case"demo_app_owner":return"App Owner";case"app_admin":case"proxy_admin":return"Admin";case"proxy_admin_viewer":return"Admin Viewer";case"app_user":return"App User";default:return"Unknown Role"}}(e.user_role);console.log("Decoded user_role:",l),s(l),"Admin Viewer"==l&&b("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))}}},[Z]),(0,r.jsx)(n.Suspense,{fallback:(0,r.jsx)("div",{children:"Loading..."}),children:(0,r.jsxs)("div",{className:"flex flex-col min-h-screen",children:[(0,r.jsx)(m,{userID:y,userRole:t,userEmail:a,showSSOBanner:x}),(0,r.jsxs)("div",{className:"flex flex-1 overflow-auto",children:[(0,r.jsx)("div",{className:"mt-8",children:(0,r.jsx)(lp,{setPage:b,userRole:t,defaultSelectedKey:null})}),"api-keys"==w?(0,r.jsx)(eL,{userID:y,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==w?(0,r.jsx)(e8,{userID:y,userRole:t,token:Z,accessToken:_,modelData:g,setModelData:f}):"llm-playground"==w?(0,r.jsx)(lm,{userID:y,userRole:t,token:Z,accessToken:_}):"users"==w?(0,r.jsx)(e6,{userID:y,userRole:t,token:Z,keys:h,teams:c,accessToken:_,setKeys:u}):"teams"==w?(0,r.jsx)(e7,{teams:c,setTeams:d,searchParams:j,accessToken:_,userID:y,userRole:t}):"admin-panel"==w?(0,r.jsx)(le,{setTeams:d,searchParams:j,accessToken:_,showSSOBanner:x}):"api_ref"==w?(0,r.jsx)(lc,{}):"settings"==w?(0,r.jsx)(lt,{userID:y,userRole:t,accessToken:_}):"general-settings"==w?(0,r.jsx)(lo,{userID:y,userRole:t,accessToken:_,modelData:g}):(0,r.jsx)(lg,{userID:y,userRole:t,token:Z,accessToken:_})]})]})})}}},function(e){e.O(0,[447,971,69,744],function(){return e(e.s=20661)}),_N_E=e.O()}]); \ No newline at end of file diff --git a/ui/litellm-dashboard/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_buildManifest.js b/ui/litellm-dashboard/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_buildManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_buildManifest.js rename to ui/litellm-dashboard/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_buildManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_ssgManifest.js b/ui/litellm-dashboard/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_ssgManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/PtTtxXIYvdjQsvRgdITlk/_ssgManifest.js rename to ui/litellm-dashboard/out/_next/static/kbGdRQFfI6W3bEwfzmJDI/_ssgManifest.js diff --git a/ui/litellm-dashboard/out/index.html b/ui/litellm-dashboard/out/index.html index cb197f11e..0dbd09152 100644 --- a/ui/litellm-dashboard/out/index.html +++ b/ui/litellm-dashboard/out/index.html @@ -1 +1 @@ -LiteLLM Dashboard \ No newline at end of file +LiteLLM Dashboard \ No newline at end of file diff --git a/ui/litellm-dashboard/out/index.txt b/ui/litellm-dashboard/out/index.txt index 267d8e5ba..70ccce541 100644 --- a/ui/litellm-dashboard/out/index.txt +++ b/ui/litellm-dashboard/out/index.txt @@ -1,7 +1,7 @@ 2:I[77831,[],""] -3:I[27125,["447","static/chunks/447-9f8d32190ff7d16d.js","931","static/chunks/app/page-781ca5f151d78d1d.js"],""] +3:I[27125,["447","static/chunks/447-9f8d32190ff7d16d.js","931","static/chunks/app/page-508c39694bd40fe9.js"],""] 4:I[5613,[],""] 5:I[31778,[],""] -0:["PtTtxXIYvdjQsvRgdITlk",[[["",{"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/5e699db73bf6f8c2.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] +0:["kbGdRQFfI6W3bEwfzmJDI",[[["",{"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/5e699db73bf6f8c2.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 Dashboard"}],["$","meta","3",{"name":"description","content":"LiteLLM Proxy Admin UI"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]] 1:null diff --git a/ui/litellm-dashboard/src/components/create_key_button.tsx b/ui/litellm-dashboard/src/components/create_key_button.tsx index 976ac2ccf..648eee9ca 100644 --- a/ui/litellm-dashboard/src/components/create_key_button.tsx +++ b/ui/litellm-dashboard/src/components/create_key_button.tsx @@ -39,6 +39,7 @@ const CreateKey: React.FC = ({ const [apiKey, setApiKey] = useState(null); const [softBudget, setSoftBudget] = useState(null); const [userModels, setUserModels] = useState([]); + const [modelsToPick, setModelsToPick] = useState([]); const handleOk = () => { setIsModalVisible(false); form.resetFields(); @@ -94,6 +95,30 @@ const CreateKey: React.FC = ({ const handleCopy = () => { message.success('API Key copied to clipboard'); }; + + useEffect(() => { + let tempModelsToPick = []; + + if (team) { + if (team.models.length > 0) { + if (team.models.includes("all-proxy-models")) { + // if the team has all-proxy-models show all available models + tempModelsToPick = userModels; + } else { + // show team models + tempModelsToPick = team.models; + } + } else { + // show all available models if the team has no models set + tempModelsToPick = userModels; + } + } else { + // no team set, show all available models + tempModelsToPick = userModels; + } + + setModelsToPick(tempModelsToPick); + }, [team, userModels]); return ( @@ -161,30 +186,15 @@ const CreateKey: React.FC = ({ - {team && team.models ? ( - team.models.includes("all-proxy-models") ? ( - userModels.map((model: string) => ( + { + modelsToPick.map((model: string) => ( ( ) )) - ) : ( - team.models.map((model: string) => ( - - )) - ) - ) : ( - userModels.map((model: string) => ( - - )) - )} - + }