diff --git a/docs/my-website/docs/routing.md b/docs/my-website/docs/routing.md index c10d804990..5d9b38cc1f 100644 --- a/docs/my-website/docs/routing.md +++ b/docs/my-website/docs/routing.md @@ -279,7 +279,7 @@ router_settings: ``` - + **Default** Picks a deployment based on the provided **Requests per minute (rpm) or Tokens per minute (tpm)** diff --git a/litellm/integrations/prometheus.py b/litellm/integrations/prometheus.py index 74632d49a0..30a1188fe9 100644 --- a/litellm/integrations/prometheus.py +++ b/litellm/integrations/prometheus.py @@ -19,7 +19,7 @@ class PrometheusLogger: **kwargs, ): try: - verbose_logger.debug(f"in init prometheus metrics") + print(f"in init prometheus metrics") from prometheus_client import Counter self.litellm_llm_api_failed_requests_metric = Counter( diff --git a/litellm/integrations/prometheus_services.py b/litellm/integrations/prometheus_services.py index 548d0a2a3a..45f70a8c1a 100644 --- a/litellm/integrations/prometheus_services.py +++ b/litellm/integrations/prometheus_services.py @@ -44,9 +44,18 @@ class PrometheusServicesLogger: ) # store the prometheus histogram/counter we need to call for each field in payload for service in self.services: - histogram = self.create_histogram(service) - counter = self.create_counter(service) - self.payload_to_prometheus_map[service] = [histogram, counter] + histogram = self.create_histogram(service, type_of_request="latency") + counter_failed_request = self.create_counter( + service, type_of_request="failed_requests" + ) + counter_total_requests = self.create_counter( + service, type_of_request="total_requests" + ) + self.payload_to_prometheus_map[service] = [ + histogram, + counter_failed_request, + counter_total_requests, + ] self.prometheus_to_amount_map: dict = ( {} @@ -74,26 +83,26 @@ class PrometheusServicesLogger: return metric return None - def create_histogram(self, label: str): - metric_name = "litellm_{}_latency".format(label) + def create_histogram(self, service: str, type_of_request: str): + metric_name = "litellm_{}_{}".format(service, type_of_request) is_registered = self.is_metric_registered(metric_name) if is_registered: return self.get_metric(metric_name) return self.Histogram( metric_name, - "Latency for {} service".format(label), - labelnames=[label], + "Latency for {} service".format(service), + labelnames=[service], ) - def create_counter(self, label: str): - metric_name = "litellm_{}_failed_requests".format(label) + def create_counter(self, service: str, type_of_request: str): + metric_name = "litellm_{}_{}".format(service, type_of_request) is_registered = self.is_metric_registered(metric_name) if is_registered: return self.get_metric(metric_name) return self.Counter( metric_name, - "Total failed requests for {} service".format(label), - labelnames=[label], + "Total {} for {} service".format(type_of_request, service), + labelnames=[service], ) def observe_histogram( @@ -120,6 +129,8 @@ class PrometheusServicesLogger: if self.mock_testing: self.mock_testing_success_calls += 1 + print(f"payload call type: {payload.call_type}") + if payload.service.value in self.payload_to_prometheus_map: prom_objects = self.payload_to_prometheus_map[payload.service.value] for obj in prom_objects: @@ -129,11 +140,19 @@ class PrometheusServicesLogger: labels=payload.service.value, amount=payload.duration, ) + elif isinstance(obj, self.Counter) and "total_requests" in obj._name: + self.increment_counter( + counter=obj, + labels=payload.service.value, + amount=1, # LOG TOTAL REQUESTS TO PROMETHEUS + ) def service_failure_hook(self, payload: ServiceLoggerPayload): if self.mock_testing: self.mock_testing_failure_calls += 1 + print(f"payload call type: {payload.call_type}") + if payload.service.value in self.payload_to_prometheus_map: prom_objects = self.payload_to_prometheus_map[payload.service.value] for obj in prom_objects: @@ -141,7 +160,7 @@ class PrometheusServicesLogger: self.increment_counter( counter=obj, labels=payload.service.value, - amount=1, # LOG ERROR COUNT TO PROMETHEUS + amount=1, # LOG ERROR COUNT / TOTAL REQUESTS TO PROMETHEUS ) async def async_service_success_hook(self, payload: ServiceLoggerPayload): @@ -151,6 +170,8 @@ class PrometheusServicesLogger: if self.mock_testing: self.mock_testing_success_calls += 1 + print(f"payload call type: {payload.call_type}") + if payload.service.value in self.payload_to_prometheus_map: prom_objects = self.payload_to_prometheus_map[payload.service.value] for obj in prom_objects: @@ -160,12 +181,20 @@ class PrometheusServicesLogger: labels=payload.service.value, amount=payload.duration, ) + elif isinstance(obj, self.Counter) and "total_requests" in obj._name: + self.increment_counter( + counter=obj, + labels=payload.service.value, + amount=1, # LOG TOTAL REQUESTS TO PROMETHEUS + ) async def async_service_failure_hook(self, payload: ServiceLoggerPayload): print(f"received error payload: {payload.error}") if self.mock_testing: self.mock_testing_failure_calls += 1 + print(f"payload call type: {payload.call_type}") + if payload.service.value in self.payload_to_prometheus_map: prom_objects = self.payload_to_prometheus_map[payload.service.value] for obj in prom_objects: diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index 8ebd2a38f4..405ff9d4b4 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -507,10 +507,11 @@ def construct_tool_use_system_prompt( ): # from https://github.com/anthropics/anthropic-cookbook/blob/main/function_calling/function_calling.ipynb tool_str_list = [] for tool in tools: + tool_function = get_attribute_or_key(tool, "function") tool_str = construct_format_tool_for_claude_prompt( - tool["function"]["name"], - tool["function"].get("description", ""), - tool["function"].get("parameters", {}), + get_attribute_or_key(tool_function, "name"), + get_attribute_or_key(tool_function, "description", ""), + get_attribute_or_key(tool_function, "parameters", {}), ) tool_str_list.append(tool_str) tool_use_system_prompt = ( @@ -634,7 +635,8 @@ def convert_to_anthropic_tool_result_xml(message: dict) -> str: """ name = message.get("name") - content = message.get("content") + content = message.get("content", "") + content = content.replace("<", "<").replace(">", ">").replace("&", "&") # We can't determine from openai message format whether it's a successful or # error call result so default to the successful result template @@ -655,13 +657,15 @@ def convert_to_anthropic_tool_result_xml(message: dict) -> str: def convert_to_anthropic_tool_invoke_xml(tool_calls: list) -> str: invokes = "" for tool in tool_calls: - if tool["type"] != "function": + if get_attribute_or_key(tool, "type") != "function": continue - tool_name = tool["function"]["name"] + tool_function = get_attribute_or_key(tool,"function") + tool_name = get_attribute_or_key(tool_function, "name") + tool_arguments = get_attribute_or_key(tool_function, "arguments") parameters = "".join( f"<{param}>{val}\n" - for param, val in json.loads(tool["function"]["arguments"]).items() + for param, val in json.loads(tool_arguments).items() ) invokes += ( "\n" @@ -715,7 +719,7 @@ def anthropic_messages_pt_xml(messages: list): { "type": "text", "text": ( - convert_to_anthropic_tool_result(messages[msg_i]) + convert_to_anthropic_tool_result_xml(messages[msg_i]) if messages[msg_i]["role"] == "tool" else messages[msg_i]["content"] ), @@ -736,7 +740,7 @@ def anthropic_messages_pt_xml(messages: list): if messages[msg_i].get( "tool_calls", [] ): # support assistant tool invoke convertion - assistant_text += convert_to_anthropic_tool_invoke( # type: ignore + assistant_text += convert_to_anthropic_tool_invoke_xml( # type: ignore messages[msg_i]["tool_calls"] ) @@ -848,12 +852,12 @@ def convert_to_anthropic_tool_invoke(tool_calls: list) -> list: anthropic_tool_invoke = [ { "type": "tool_use", - "id": tool["id"], - "name": tool["function"]["name"], - "input": json.loads(tool["function"]["arguments"]), + "id": get_attribute_or_key(tool, "id"), + "name": get_attribute_or_key(get_attribute_or_key(tool, "function"), "name"), + "input": json.loads(get_attribute_or_key(get_attribute_or_key(tool, "function"), "arguments")), } for tool in tool_calls - if tool["type"] == "function" + if get_attribute_or_key(tool, "type") == "function" ] return anthropic_tool_invoke @@ -1074,7 +1078,8 @@ def cohere_message_pt(messages: list): tool_result = convert_openai_message_to_cohere_tool_result(message) tool_results.append(tool_result) else: - prompt += message["content"] + prompt += message["content"] + "\n\n" + prompt = prompt.rstrip() return prompt, tool_results @@ -1414,3 +1419,8 @@ def prompt_factory( return default_pt( messages=messages ) # default that covers Bloom, T-5, any non-chat tuned model (e.g. base Llama2) + +def get_attribute_or_key(tool_or_function, attribute, default=None): + if hasattr(tool_or_function, attribute): + return getattr(tool_or_function, attribute) + return tool_or_function.get(attribute, default) diff --git a/litellm/llms/vertex_ai_anthropic.py b/litellm/llms/vertex_ai_anthropic.py index 9bce746dd6..34709e0c56 100644 --- a/litellm/llms/vertex_ai_anthropic.py +++ b/litellm/llms/vertex_ai_anthropic.py @@ -123,7 +123,7 @@ class VertexAIAnthropicConfig: """ -- Run client init +- Run client init - Support async completion, streaming """ @@ -236,17 +236,19 @@ def completion( if client is None: if vertex_credentials is not None and isinstance(vertex_credentials, str): import google.oauth2.service_account - - json_obj = json.loads(vertex_credentials) - creds = ( google.oauth2.service_account.Credentials.from_service_account_info( - json_obj, + json.loads(vertex_credentials), scopes=["https://www.googleapis.com/auth/cloud-platform"], ) ) ### CHECK IF ACCESS access_token = refresh_auth(credentials=creds) + else: + import google.auth + creds, _ = google.auth.default() + ### CHECK IF ACCESS + access_token = refresh_auth(credentials=creds) vertex_ai_client = AnthropicVertex( project_id=vertex_project, diff --git a/litellm/main.py b/litellm/main.py index 753193f965..b61df8c12e 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -610,6 +610,7 @@ def completion( "client", "rpm", "tpm", + "max_parallel_requests", "input_cost_per_token", "output_cost_per_token", "input_cost_per_second", @@ -2598,6 +2599,7 @@ def embedding( client = kwargs.pop("client", None) rpm = kwargs.pop("rpm", None) tpm = kwargs.pop("tpm", None) + max_parallel_requests = kwargs.pop("max_parallel_requests", None) model_info = kwargs.get("model_info", None) metadata = kwargs.get("metadata", None) encoding_format = kwargs.get("encoding_format", None) @@ -2655,6 +2657,7 @@ def embedding( "client", "rpm", "tpm", + "max_parallel_requests", "input_cost_per_token", "output_cost_per_token", "input_cost_per_second", @@ -3514,6 +3517,7 @@ def image_generation( "client", "rpm", "tpm", + "max_parallel_requests", "input_cost_per_token", "output_cost_per_token", "hf_model_name", diff --git a/litellm/proxy/_experimental/out/404.html b/litellm/proxy/_experimental/out/404.html index 3ace44f682..bb4c1890da 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/Oe7aA-U7OV9Y13gspREJQ/_buildManifest.js b/litellm/proxy/_experimental/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_buildManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/Oe7aA-U7OV9Y13gspREJQ/_buildManifest.js rename to litellm/proxy/_experimental/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_buildManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/Oe7aA-U7OV9Y13gspREJQ/_ssgManifest.js b/litellm/proxy/_experimental/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_ssgManifest.js similarity index 100% rename from litellm/proxy/_experimental/out/_next/static/Oe7aA-U7OV9Y13gspREJQ/_ssgManifest.js rename to litellm/proxy/_experimental/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_ssgManifest.js diff --git a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-6ba29bc4256320f4.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-6ba29bc4256320f4.js new file mode 100644 index 0000000000..e765986ea2 --- /dev/null +++ b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-6ba29bc4256320f4.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,65249))},65249:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return ln}});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 text-2xl py-1 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:200,height:200,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}},y=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}},Z=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}},f=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=>{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}},b=async(e,l,t)=>{try{let l=await fetch("/model/metrics",{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}},k=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}},v=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}},S=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}},A=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}},N=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}},C=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}},P=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}},T=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}},E=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}},F=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}},M=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}},R=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,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}},L=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}},z=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}},B=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 on ").concat(l," dashboard!")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},q=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}},V=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}},K=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 G=t(10384),J=t(46453),W=t(2179),Y=t(26780),$=t(15595),H=t(6698),X=t(71801),Q=t(42440),ee=t(42308),el=t(50670),et=t(81583),es=t(99129),ea=t(44839),er=t(88707),en=t(1861);let{Option:eo}=el.default;var ei=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=et.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[y,Z]=(0,n.useState)([]),f=()=>{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 k(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),Z(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let _=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)(W.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(es.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:f,onCancel:w,children:(0,r.jsxs)(et.Z,{form:c,onFinish:_,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===s||"Admin"===s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.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)(ea.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e))]})}),(0,r.jsx)(et.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)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.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)(el.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(el.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(el.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(ea.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.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)(ea.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e))]})}),(0,r.jsxs)(Y.Z,{className:"mt-8",children:[(0,r.jsx)(H.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)($.Z,{children:[(0,r.jsx)(et.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)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.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)(el.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(el.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(el.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(ea.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(es.Z,{visible:d,onOk:f,onCancel:w,footer:null,children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(Q.Z,{children:"Save your Key"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(X.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)(ee.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(W.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(X.Z,{children:"Key being created, this might take 30s"})})]})})]})},ec=t(9454),ed=t(98941),em=t(33393),eh=t(5),eu=t(9853),ex=t(13810),ep=t(39290),ej=t(66952),eg=t(61244),ey=t(10827),eZ=t(3851),ef=t(2044),ew=t(64167),e_=t(74480),eb=t(7178),ek=t(95093),ev=t(27166);let{Option:eS}=el.default;var eA=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,Z]=n.useState(null),[f,w]=(0,n.useState)(null),[_,b]=(0,n.useState)(null),[S,A]=(0,n.useState)(""),[N,I]=(0,n.useState)(!1),[C,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),O=new Set,[F,M]=(0,n.useState)(O);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await k(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 U=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),I(!0)},D=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await R(s,e);console.log("handleEditSubmit: newKeyValues",t),o&&i(o.map(e=>e.token===l?t:e)),h.ZP.success("Key updated successfully"),I(!1),P(null)},L=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await v(s,e.token);console.log("Response:",l),b(l);try{let e=await z(s,l);console.log("Response2:",e);let t=[...l,...e.response];b(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)(()=>{L(f)},[f]);let B=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))},q=async()=>{if(null!=p&&null!=o){try{await y(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)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ey.Z,{className:"mt-5",children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Key Alias"}),(0,r.jsx)(e_.Z,{children:"Secret Key"}),(0,r.jsx)(e_.Z,{children:"Spend (USD)"}),(0,r.jsx)(e_.Z,{children:"Budget (USD)"}),(0,r.jsx)(e_.Z,{children:"Models"}),(0,r.jsx)(e_.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eZ.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(F.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||F.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)(eb.Z,{children:[(0,r.jsx)(ef.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(X.Z,{children:e.key_alias}):(0,r.jsx)(X.Z,{children:"Not Set"})}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:e.key_name})}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(ef.Z,{children:null!=e.max_budget?(0,r.jsx)(X.Z,{children:e.max_budget}):(0,r.jsx)(X.Z,{children:"Unlimited"})}),(0,r.jsx)(ef.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)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Team Models"})},l):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Team Models"})},l):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(ef.Z,{children:(0,r.jsxs)(X.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)(ef.Z,{children:[(0,r.jsx)(eg.Z,{onClick:()=>{w(e),Z(e.id)},icon:ec.Z,size:"sm"}),(0,r.jsx)(ep.Z,{open:null!==g,onClose:()=>{Z(null),w(null)},children:(0,r.jsx)(ej.Z,{children:f&&(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)(ex.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(f.spend).toFixed(4)}catch(e){return f.spend}})()})})]}),(0,r.jsxs)(ex.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!=f.max_budget?(0,r.jsx)(r.Fragment,{children:f.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(ex.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!=f.expires?(0,r.jsx)(r.Fragment,{children:new Date(f.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)(ex.Z,{className:"mt-6 mb-6",children:_&&(0,r.jsx)(eu.Z,{className:"mt-6",data:_,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(Q.Z,{children:"Metadata"}),(0,r.jsx)(X.Z,{children:JSON.stringify(f.metadata)}),(0,r.jsx)(W.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{Z(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(eg.Z,{icon:ed.Z,size:"sm",onClick:()=>U(e)}),(0,r.jsx)(eg.Z,{onClick:()=>B(e),icon:em.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)(W.Z,{onClick:q,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),C&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=et.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(es.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)(et.Z,{form:i,onFinish:D,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.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);return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t)):Promise.resolve()}}],children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eS,{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)(eS,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(eS,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(eS,{value:e,children:e},e))]})}),(0,r.jsx)(et.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)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(et.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(ek.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(ev.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)(en.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{I(!1),P(null)},token:C,onSubmit:D})]})},eN=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a}=e;console.log("userSpend: ".concat(a));let[o,i]=(0,n.useState)(null!==a?a:0),[c,d]=(0,n.useState)(0);(0,n.useEffect)(()=>{(async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await w(s);e&&(e.spend?i(e.spend):i(0),e.max_budget?d(e.max_budget):d(0))}catch(e){console.error("Error fetching global spend data:",e)}})()},[t,s]),(0,n.useEffect)(()=>{null!==a&&i(a)},[a]);let m=void 0!==o?o.toFixed(4):null;return console.log("spend in view user spend: ".concat(o)),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend "}),(0,r.jsxs)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",m]})]})},eI=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],(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(Q.Z,{children:"Select Team"}),"App User"!==a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(X.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)(X.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)(ek.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(ev.Z,{value:String(l),onClick:()=>s(e),children:e.team_alias},l))}):(0,r.jsxs)(X.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eC=t(37963),eP=t(36083);console.log("isLocal:",!1);var eT=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,y]=(0,n.useState)(null),[Z,_]=(0,n.useState)(null),[b,v]=(0,n.useState)([]),[S,A]=(0,n.useState)(s?s[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eC.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),y(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?v(JSON.parse(e)):(async()=>{try{let e=await f(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 w(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams),A(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let s=(await k(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",s),v(s),console.log("userModels:",b),sessionStorage.setItem("userModels"+l,JSON.stringify(s))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=S){let e=0;for(let l of a)S.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===S.team_id&&(e+=l.spend);_(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;_(e)}},[S]),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}=eP.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",S),console.log("teamSpend: ".concat(Z)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(eN,{userID:l,userRole:t,accessToken:g,userSpend:Z}),(0,r.jsx)(eA,{userID:l,userRole:t,accessToken:g,selectedTeam:S||null,data:a,setData:h,teams:s}),(0,r.jsx)(ei,{userID:l,team:S||null,userRole:t,accessToken:g,data:a,setData:h},S?S.team_id:null),(0,r.jsx)(eI,{teams:s,setSelectedTeam:A,userRole:t})]})})})},eE=t(92836),eO=t(26734),eF=t(41608),eM=t(32126),eR=t(23682),eU=t(52273),eD=t(47047),eL=t(76628),ez=t(38302),eB=t(28683),eq=t(1460),eV=t(78578),eK=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)(eg.Z,{onClick:()=>a(!0),icon:em.Z,size:"sm"}),(0,r.jsx)(es.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(Q.Z,{children:"Delete Model"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eG=t(97766),eJ=t(46495);let{Title:eW,Link:eY}=eP.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 e$={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"};var eH=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d}=e,[m,p]=(0,n.useState)({data:[]}),[j,g]=(0,n.useState)([]),[y]=et.Z.useForm(),[Z,f]=(0,n.useState)(null),[w,b]=(0,n.useState)([]),k=Object.values(a).filter(e=>isNaN(Number(e))),[v,S]=(0,n.useState)("OpenAI"),[A,N]=(0,n.useState)("");if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await _(o,d,c);if(console.log("Model data response:",e.data),p(e),"Admin"===c&&o){let e=await O(o);console.log("Pending Requests:",j),g(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};o&&i&&c&&d&&e();let l=async()=>{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==Z&&l()},[o,i,c,d,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let I=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(Z)),null!=Z&&"object"==typeof Z&&e in Z)?Z[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,I.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eP.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 C=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=e$[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof Z&&Object.entries(Z).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)}),b(t),console.log("providerModels: ".concat(w))}},P=async()=>{try{h.ZP.info("Running health check..."),N("");let e=await K(o);N(e)}catch(e){console.error("Error running health check:",e),N("Error running health check")}},T=async e=>{try{let l=Object.values(e.model);console.log("received deployments: ".concat(l)),console.log("received type of deployments: ".concat(typeof l)),l.forEach(async l=>{console.log("litellm_model: ".concat(l));let t={},s={};t.model=l;let a="";for(let[l,r]of Object.entries(e))if("model_name"==l)a+=r;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)s[l]=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else t[l]=r;let r={model_name:a,litellm_params:t,model_info:s},n=await x(o,r);console.log("response for model create call: ".concat(n.data))}),y.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};return console.log("selectedProvider: ".concat(v)),console.log("providerModels.length: ".concat(w.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eO.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Models"}),(0,r.jsx)(eE.Z,{children:"Add Model"}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(J.Z,{children:(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(ey.Z,{className:"mt-5",children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Model Name "}),(0,r.jsx)(e_.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(e_.Z,{children:"API Base"}),(0,r.jsx)(e_.Z,{children:"Extra litellm Params"}),(0,r.jsx)(e_.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(e_.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(e_.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(eZ.Z,{children:m.data.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:e.model_name})}),(0,r.jsx)(ef.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(ef.Z,{children:e.api_base}),(0,r.jsx)(ef.Z,{children:(0,r.jsxs)(Y.Z,{children:[(0,r.jsx)(H.Z,{children:(0,r.jsx)(X.Z,{children:"Litellm params"})}),(0,r.jsx)($.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(ef.Z,{children:e.input_cost}),(0,r.jsx)(ef.Z,{children:e.output_cost}),(0,r.jsx)(ef.Z,{children:e.max_tokens}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eK,{modelID:e.model_info.id,accessToken:o})})]},l))})]})})})}),(0,r.jsxs)(eM.Z,{className:"h-full",children:[(0,r.jsx)(eW,{level:2,children:"Add new model"}),(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(et.Z,{form:y,onFinish:()=>{y.validateFields().then(e=>{T(e)}).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)(et.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)(ek.Z,{value:v.toString(),children:k.map((e,l)=>(0,r.jsx)(ev.Z,{value:e,onClick:()=>{C(e),S(e)},children:e},l))})}),(0,r.jsx)(et.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)(eU.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=v.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)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(X.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(et.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"===v?(0,r.jsx)(eU.Z,{placeholder:"Enter model name"}):w.length>0?(0,r.jsx)(eD.Z,{value:w,children:w.map((e,l)=>(0,r.jsx)(eL.Z,{value:e,children:e},l))}):(0,r.jsx)(eU.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(X.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(eY,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(eY,{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"!=v&&"Vertex AI (Anthropic, Gemini, etc.)"!=v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)(eU.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==v&&(0,r.jsx)(et.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)(eU.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(eU.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(eU.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eJ.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;y.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)(en.ZP,{icon:(0,r.jsx)(eG.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(X.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==v||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==v)&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(eU.Z,{placeholder:"https://..."})}),"Azure"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)(eU.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==v&&(0,r.jsxs)(et.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)(eU.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(X.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(eY,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==v&&(0,r.jsx)(et.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)(eU.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(et.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)(eU.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(et.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)(eU.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(et.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)(eV.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(X.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(eY,{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)(en.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eq.Z,{title:"Get help on our github",children:(0,r.jsx)(eP.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(X.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(W.Z,{onClick:P,children:"Run `/health`"}),A&&(0,r.jsx)("pre",{children:JSON.stringify(A,null,2)})]})})]})]})})};let{Option:eX}=el.default;var eQ=e=>{let{userID:l,accessToken:t,teams:s}=e,[a]=et.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 k(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)(W.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Invite User"}),(0,r.jsxs)(es.Z,{title:"Invite User",visible:o,width:800,footer:null,onOk:x,onCancel:p,children:[(0,r.jsx)(X.Z,{className:"mb-1",children:"Invite a user to login to the Admin UI and create Keys"}),(0,r.jsx)(X.Z,{className:"mb-6",children:(0,r.jsx)("b",{children:"Note: SSO Setup Required for this"})}),(0,r.jsxs)(et.Z,{form:a,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(et.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(ea.Z,{placeholder:"Enter User Email"})}),(0,r.jsx)(et.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(el.default,{placeholder:"Select Team ID",style:{width:"100%"},children:s?s.map(e=>(0,r.jsx)(eX,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(eX,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(et.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(ea.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Create User"})})]})]}),c&&(0,r.jsxs)(es.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"})})]})]})},e0=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),[y,Z]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await f(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 P(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 P(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)(J.Z,{className:"gap-2 p-2 h-[75vh] w-full mt-8",children:[(0,r.jsx)(eQ,{userID:o,accessToken:l,teams:i}),(0,r.jsx)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eE.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(ey.Z,{className:"mt-5",children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"User ID"}),(0,r.jsx)(e_.Z,{children:"User Email"}),(0,r.jsx)(e_.Z,{children:"User Models"}),(0,r.jsx)(e_.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(e_.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(e_.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(eZ.Z,{children:d.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.user_id}),(0,r.jsx)(ef.Z,{children:e.user_email}),(0,r.jsx)(ef.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(ef.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(ef.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(J.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(eh.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(eh.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eM.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)(X.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(ek.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_name&&e.key_name.length>0)return(0,r.jsx)(ev.Z,{value:String(l),onClick:()=>w(e.token),children:e.key_name},l)})})]})]}),(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"End User"}),(0,r.jsx)(e_.Z,{children:"Spend"}),(0,r.jsx)(e_.Z,{children:"Total Events"})]})}),(0,r.jsx)(eZ.Z,{children:null==h?void 0:h.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.end_user}),(0,r.jsx)(ef.Z,{children:e.total_spend}),(0,r.jsx)(ef.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 →"})]})]})}()]})})},e1=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=et.Z.useForm(),[d]=et.Z.useForm(),{Title:m,Paragraph:u}=eP.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[y,f]=(0,n.useState)(l?l[0]:null),[w,_]=(0,n.useState)(!1),[b,v]=(0,n.useState)(!1),[S,A]=(0,n.useState)([]),[N,I]=(0,n.useState)(!1),[C,P]=(0,n.useState)(null),T=e=>{f(e),g(!0)},E=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),f(null)},O=async e=>{P(e),I(!0)},F=async()=>{if(null!=C&&null!=l&&null!=s){try{await Z(s,C);let e=l.filter(e=>e.team_id!==C);a(e)}catch(e){console.error("Error deleting the team:",e)}I(!1),P(null)}};(0,n.useEffect)(()=>{(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await k(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),A(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,o,i]);let R=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await M(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)}},L=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 D(s,y.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),f(r.data)}v(!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)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Team Name"}),(0,r.jsx)(e_.Z,{children:"Spend (USD)"}),(0,r.jsx)(e_.Z,{children:"Budget (USD)"}),(0,r.jsx)(e_.Z,{children:"Models"}),(0,r.jsx)(e_.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eZ.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(ef.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)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(X.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)(ef.Z,{children:[(0,r.jsx)(eg.Z,{icon:ed.Z,size:"sm",onClick:()=>T(e)}),(0,r.jsx)(eg.Z,{onClick:()=>O(e.team_id),icon:em.Z,size:"sm"})]})]},e.team_id)):null})]}),N&&(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)(W.Z,{onClick:F,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto",onClick:()=>_(!0),children:"+ Create New Team"}),(0,r.jsx)(es.Z,{title:"Create Team",visible:w,width:800,footer:null,onOk:()=>{_(!1),c.resetFields()},onCancel:()=>{_(!1),c.resetFields()},children:(0,r.jsxs)(et.Z,{form:c,onFinish:R,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(el.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S.map(e=>(0,r.jsx)(el.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(et.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(G.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)(ek.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(ev.Z,{value:String(l),onClick:()=>{f(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)(G.Z,{numColSpan:1,children:[(0,r.jsx)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Member Name"}),(0,r.jsx)(e_.Z,{children:"Role"})]})}),(0,r.jsx)(eZ.Z,{children:y?y.members_with_roles.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(ef.Z,{children:e.role})]},l)):null})]})}),y&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=et.Z.useForm();return(0,r.jsx)(es.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)(et.Z,{form:n,onFinish:E,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(el.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S&&S.map(e=>(0,r.jsx)(el.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(et.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.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)(en.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),f(null)},team:y,onSubmit:E})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto mb-5",onClick:()=>v(!0),children:"+ Add member"}),(0,r.jsx)(es.Z,{title:"Add member",visible:b,width:800,footer:null,onOk:()=>{v(!1),d.resetFields()},onCancel:()=>{v(!1),d.resetFields()},children:(0,r.jsxs)(et.Z,{form:c,onFinish:L,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(ea.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)(et.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(ea.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)(en.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e2=t(18190),e4=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=et.Z.useForm(),[i]=et.Z.useForm(),{Title:c,Paragraph:d}=eP.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[y,Z]=(0,n.useState)(!1),[f,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 F(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 F(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()},I=()=>{w(!1),i.resetFields()},C=e=>(0,r.jsxs)(et.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(ea.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)(et.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(ea.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)(en.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(et.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(ek.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(ev.Z,{value:e,children:e},l))})}),(0,r.jsx)(et.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(ea.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await L(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 L(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)}},O=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await L(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)),Z(!1)}}catch(e){console.error("Error creating the key:",e)}},M=async e=>{null!=s&&V(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)(J.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsx)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Member Name"}),(0,r.jsx)(e_.Z,{children:"Role"})]})}),(0,r.jsx)(eZ.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(ef.Z,{children:e.user_role}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{icon:ed.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(es.Z,{title:"Update role",visible:f,width:800,footer:null,onOk:N,onCancel:I,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(W.Z,{className:"mr-4 mb-5",onClick:()=>Z(!0),children:"+ Add admin"}),(0,r.jsx)(es.Z,{title:"Add admin",visible:y,width:800,footer:null,onOk:()=>{Z(!1),i.resetFields()},onCancel:()=>{Z(!1),i.resetFields()},children:C(O)}),(0,r.jsx)(W.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(es.Z,{title:"Add viewer",visible:j,width:800,footer:null,onOk:()=>{g(!1),i.resetFields()},onCancel:()=>{g(!1),i.resetFields()},children:C(E)})]})})]}),(0,r.jsxs)(J.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)(W.Z,{onClick:()=>b(!0),children:"Add SSO"}),(0,r.jsx)(es.Z,{title:"Add SSO",visible:_,width:800,footer:null,onOk:()=>{b(!1),o.resetFields()},onCancel:()=>{b(!1),o.resetFields()},children:(0,r.jsxs)(et.Z,{form:o,onFinish:e=>{O(e),M(e),b(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(ea.Z.Password,{})}),(0,r.jsx)(et.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(ea.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(es.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)(X.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(X.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(X.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(X.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)(en.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e2.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})," "]})]})]})]})},e8=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)(!1),[d]=et.Z.useForm(),[m,u]=(0,n.useState)(null),[x,p]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.data)})},[l,t,s]);let j=e=>{p(e),console.log("Selected values:",e)},g=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",x);try{V(l,{environment_variables:t,general_settings:{alert_types:x}})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},y=()=>{l&&d.validateFields().then(e=>{console.log("Form values:",e),"langfuse"===e.callback?(V(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}}),o(a?[...a,e.callback]:[e.callback])):"slack"===e.callback&&(V(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),o(a?[...a,e.callback]:[e.callback])),c(!1),d.resetFields(),u(null)})};return l?(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(Q.Z,{children:"Logging Callbacks"}),(0,r.jsxs)(ex.Z,{children:[(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Callback"}),(0,r.jsx)(e_.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(eZ.Z,{children:a.map((e,t)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eh.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(e.variables).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(X.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)(eU.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),e.all_alert_types&&(0,r.jsxs)("div",{children:[(0,r.jsx)(X.Z,{className:"mt-2",children:"Alerting Types"}),(0,r.jsx)(el.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select Alerting Types",optionLabelProp:"label",onChange:j,defaultValue:e.alerting_types,children:e.all_alert_types.map(e=>(0,r.jsx)(el.default.Option,{value:e,label:e,children:e},e))})]}),(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>g(e),children:"Save Changes"}),(0,r.jsx)(W.Z,{onClick:()=>B(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t))})]}),(0,r.jsx)(W.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),c(!0)},children:"Add Callback"})]})]}),(0,r.jsx)(es.Z,{title:"Add Callback",visible:i,onOk:y,width:800,onCancel:()=>{c(!1),d.resetFields(),u(null)},footer:null,children:(0,r.jsxs)(et.Z,{form:d,layout:"vertical",onFinish:y,children:[(0,r.jsx)(et.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsxs)(el.default,{onChange:e=>{u(e)},children:[(0,r.jsx)(el.default.Option,{value:"langfuse",children:"langfuse"}),(0,r.jsx)(el.default.Option,{value:"slack",children:"slack alerting"})]})}),"langfuse"===m&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)(ea.Z.Password,{})}),(0,r.jsx)(et.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)(ea.Z.Password,{})})]}),"slack"===m&&(0,r.jsx)(et.Z.Item,{label:"SLACK_WEBHOOK_URL",name:"slackWebhookUrl",rules:[{required:!0,message:"Please enter the Slack webhook URL"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Save"})})]})})]}):null},e3=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)({}),[i,c]=(0,n.useState)(!1),[d]=et.Z.useForm(),[m,u]=(0,n.useState)(null);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.router_settings)})},[l,t,s]);let x=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).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);try{V(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)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(Q.Z,{children:"Router Settings"}),(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Setting"}),(0,r.jsx)(e_.Z,{children:"Value"})]})}),(0,r.jsx)(eZ.Z,{children:Object.entries(a).map(e=>{let[l,t]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:l})}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eU.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(G.Z,{children:(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>x(a),children:"Save Changes"})})]})}):null},e5=t(12968),e6=t(67951);async function e7(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new e5.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 e9=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 k(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}]})},y=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await e7(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}=eP.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(J.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"Chat"}),(0,r.jsx)(eE.Z,{children:"API Reference"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(J.Z,{numItems:2,children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)(X.Z,{children:"API Key"}),(0,r.jsx)(eU.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(G.Z,{className:"mx-2",children:[(0,r.jsx)(X.Z,{children:"Select Model:"}),(0,r.jsx)(el.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ey.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ew.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ef.Z,{})})}),(0,r.jsx)(eZ.Z,{children:m.map((e,l)=>(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ef.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)(eU.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(W.Z,{onClick:y,className:"ml-2",children:"Send"})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eE.Z,{children:"LlamaIndex"}),(0,r.jsx)(eE.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # proxy base url\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to use from Models Tab\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ],\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-openai-client",\n "generation_id": "openai-client-gen-id22",\n "trace_id": "openai-client-trace-id22",\n "trace_user_id": "openai-client-user-id2"\n }\n }\n)\n\nprint(response)\n '})}),(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.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)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="http://0.0.0.0:8000",\n model = "gpt-3.5-turbo",\n temperature=0.1,\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-langchain-client",\n "generation_id": "langchain-client-gen-id22",\n "trace_id": "langchain-client-trace-id22",\n "trace_user_id": "langchain-client-user-id2"\n }\n }\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})})]})]})})})})},le=t(33509),ll=t(95781);let{Sider:lt}=le.default;var ls=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(X.Z,{children:"API Keys"})},"1"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(X.Z,{children:"Test Key"})},"3"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(X.Z,{children:"Models"})},"2"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(X.Z,{children:"Teams"})},"6"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(X.Z,{children:"Usage"})},"4"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(X.Z,{children:"Users"})},"5"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(X.Z,{children:"Integrations"})},"8"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(X.Z,{children:"Settings"})},"9"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(X.Z,{children:"Admin"})},"7"):null]})})})},la=t(67989),lr=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)([]),[y,Z]=(0,n.useState)([]),[f,w]=(0,n.useState)([]),[_,k]=(0,n.useState)([]),[v,P]=(0,n.useState)([]),[O,F]=(0,n.useState)([]),M=new Date(o.getFullYear(),o.getMonth(),1),R=new Date(o.getFullYear(),o.getMonth()+1,0),U=L(M),D=L(R);function L(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)}return console.log("Start date is ".concat(U)),console.log("End date is ".concat(D)),(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 C(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let s=(await T(l)).map(e=>({key:e.model,spend:e.total_spend}));u(s);let a=await S(l);console.log("teamSpend",a),g(a.daily_spend),w(a.teams);let r=a.total_spend_per_team;r=r.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),k(r);let n=await A(l);Z(n.top_10_tags)}else"App Owner"==s&&await N(l,t,s,a,U,D).then(async 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 E(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 b(l,a,s);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),P(e),F(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,U,D]),(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(eN,{userID:a,userRole:s,accessToken:l,userSpend:null}),(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Up"}),(0,r.jsx)(eE.Z,{children:"Team Based Usage"}),(0,r.jsx)(eE.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eE.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Monthly Spend"}),(0,r.jsx)(eu.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Top API Keys"}),(0,r.jsx)(eu.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Top Users"}),(0,r.jsx)(eu.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Top Models"}),(0,r.jsx)(eu.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)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(G.Z,{numColSpan:2,children:[(0,r.jsxs)(ex.Z,{className:"mb-2",children:[(0,r.jsx)(Q.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(la.Z,{data:_})]}),(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(eu.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:f,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(X.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)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Tag"}),(0,r.jsx)(e_.Z,{children:"Spend"}),(0,r.jsx)(e_.Z,{children:"Requests"})]})}),(0,r.jsx)(eZ.Z,{children:y.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.name}),(0,r.jsx)(ef.Z,{children:e.value}),(0,r.jsx)(ef.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Number Requests per Model"}),(0,r.jsx)(eu.Z,{data:v,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(ex.Z,{className:"mt-4",children:[(0,r.jsx)(Q.Z,{children:"Latency Per Model"}),(0,r.jsx)(eu.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},ln=()=>{let{Title:e,Paragraph:l}=eP.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=j.get("userID"),y=j.get("token"),[Z,f]=(0,n.useState)("api-keys"),[w,_]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(y){let e=(0,eC.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),_(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&&f("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?p("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[y]),(0,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:g,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)(ls,{setPage:f,userRole:t,defaultSelectedKey:null})}),"api-keys"==Z?(0,r.jsx)(eT,{userID:g,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==Z?(0,r.jsx)(eH,{userID:g,userRole:t,token:y,accessToken:w}):"llm-playground"==Z?(0,r.jsx)(e9,{userID:g,userRole:t,token:y,accessToken:w}):"users"==Z?(0,r.jsx)(e0,{userID:g,userRole:t,token:y,keys:h,teams:c,accessToken:w,setKeys:u}):"teams"==Z?(0,r.jsx)(e1,{teams:c,setTeams:d,searchParams:j,accessToken:w,userID:g,userRole:t}):"admin-panel"==Z?(0,r.jsx)(e4,{setTeams:d,searchParams:j,accessToken:w,showSSOBanner:x}):"settings"==Z?(0,r.jsx)(e8,{userID:g,userRole:t,accessToken:w}):"general-settings"==Z?(0,r.jsx)(e3,{userID:g,userRole:t,accessToken:w}):(0,r.jsx)(lr,{userID:g,userRole:t,token:y,accessToken:w})]})]})})}}},function(e){e.O(0,[968,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-93ac11fb17dce9d6.js b/litellm/proxy/_experimental/out/_next/static/chunks/app/page-93ac11fb17dce9d6.js deleted file mode 100644 index 696bbfce8d..0000000000 --- a/litellm/proxy/_experimental/out/_next/static/chunks/app/page-93ac11fb17dce9d6.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,16586))},16586:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return ln}});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 text-2xl py-1 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:200,height:200,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}},y=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}},Z=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}},f=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)),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=>{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}},b=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}},_=async(e,l,t)=>{try{let l=await fetch("/model/metrics",{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}},k=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}},v=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}},S=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}},A=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}},N=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}},C=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}},I=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}},P=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}},T=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}},E=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}},F=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}},M=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}},R=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}},D=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}},L=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}},U=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}},z=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}},B=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 on ").concat(l," dashboard!")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},q=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}},V=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}},K=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 G=t(10384),J=t(46453),W=t(2179),Y=t(71801),H=t(42440),$=t(42308),X=t(50670),Q=t(81583),ee=t(99129),el=t(44839),et=t(88707),es=t(1861);let{Option:ea}=X.default;var er=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=Q.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[y,Z]=(0,n.useState)([]),f=()=>{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 k(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),Z(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)(W.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(ee.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:f,onCancel:w,children:(0,r.jsxs)(Q.Z,{form:c,onFinish:b,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===s||"Admin"===s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.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)(el.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?y.map(e=>(0,r.jsx)(ea,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(ea,{value:e,children:e},e)):y.map(e=>(0,r.jsx)(ea,{value:e,children:e},e))]})}),(0,r.jsx)(Q.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)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.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)(X.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(X.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(X.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(Q.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)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.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)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(el.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Key Name",name:"key_alias",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Team ID (Contact Group)",name:"team_id",children:(0,r.jsx)(el.Z,{placeholder:"default team (create a new team)"})}),(0,r.jsx)(Q.Z.Item,{label:"Description",name:"description",children:(0,r.jsx)(el.Z.TextArea,{placeholder:"Enter description",rows:4})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(ee.Z,{visible:d,onOk:f,onCancel:w,footer:null,children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(H.Z,{children:"Save your Key"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.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)($.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(W.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(Y.Z,{children:"Key being created, this might take 30s"})})]})})]})},en=t(9454),eo=t(98941),ei=t(33393),ec=t(5),ed=t(9853),em=t(13810),eh=t(39290),eu=t(66952),ex=t(61244),ep=t(10827),ej=t(3851),eg=t(2044),ey=t(64167),eZ=t(74480),ef=t(7178),ew=t(95093),eb=t(27166);let{Option:e_}=X.default;var ek=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,Z]=n.useState(null),[f,w]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),[S,A]=(0,n.useState)(""),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),O=new Set,[F,M]=(0,n.useState)(O);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await k(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 D=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),C(!0)},L=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await R(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)},U=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await v(s,e.token);console.log("Response:",l),_(l);try{let e=await z(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)(()=>{U(f)},[f]);let B=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))},q=async()=>{if(null!=p&&null!=o){try{await y(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)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ep.Z,{className:"mt-5",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Key Alias"}),(0,r.jsx)(eZ.Z,{children:"Secret Key"}),(0,r.jsx)(eZ.Z,{children:"Spend (USD)"}),(0,r.jsx)(eZ.Z,{children:"Budget (USD)"}),(0,r.jsx)(eZ.Z,{children:"Models"}),(0,r.jsx)(eZ.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(ej.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(F.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||F.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)(ef.Z,{children:[(0,r.jsx)(eg.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(Y.Z,{children:e.key_alias}):(0,r.jsx)(Y.Z,{children:"Not Set"})}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:e.key_name})}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(eg.Z,{children:null!=e.max_budget?(0,r.jsx)(Y.Z,{children:e.max_budget}):(0,r.jsx)(Y.Z,{children:"Unlimited"})}),(0,r.jsx)(eg.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)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Team Models"})},l):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Team Models"})},l):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(Y.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)(eg.Z,{children:[(0,r.jsx)(ex.Z,{onClick:()=>{w(e),Z(e.id)},icon:en.Z,size:"sm"}),(0,r.jsx)(eh.Z,{open:null!==g,onClose:()=>{Z(null),w(null)},children:(0,r.jsx)(eu.Z,{children:f&&(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)(em.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(f.spend).toFixed(4)}catch(e){return f.spend}})()})})]}),(0,r.jsxs)(em.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!=f.max_budget?(0,r.jsx)(r.Fragment,{children:f.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(em.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!=f.expires?(0,r.jsx)(r.Fragment,{children:new Date(f.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)(em.Z,{className:"mt-6 mb-6",children:b&&(0,r.jsx)(ed.Z,{className:"mt-6",data:b,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(H.Z,{children:"Metadata"}),(0,r.jsx)(Y.Z,{children:JSON.stringify(f.metadata)}),(0,r.jsx)(W.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{Z(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(ex.Z,{icon:eo.Z,size:"sm",onClick:()=>D(e)}),(0,r.jsx)(ex.Z,{onClick:()=>B(e),icon:ei.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)(W.Z,{onClick:q,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),I&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=Q.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(ee.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)(Q.Z,{form:i,onFinish:L,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.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);return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t)):Promise.resolve()}}],children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(e_,{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)(e_,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(e_,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(e_,{value:e,children:e},e))]})}),(0,r.jsx)(Q.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)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(Q.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(ew.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(eb.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)(es.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{C(!1),P(null)},token:I,onSubmit:L})]})},ev=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a}=e;console.log("userSpend: ".concat(a));let[o,i]=(0,n.useState)(null!==a?a:0),[c,d]=(0,n.useState)(0);(0,n.useEffect)(()=>{(async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await w(s);e&&(e.spend?i(e.spend):i(0),e.max_budget?d(e.max_budget):d(0))}catch(e){console.error("Error fetching global spend data:",e)}})()},[t,s]),(0,n.useEffect)(()=>{null!==a&&i(a)},[a]);let m=void 0!==o?o.toFixed(4):null;return console.log("spend in view user spend: ".concat(o)),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend "}),(0,r.jsxs)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",m]})]})},eS=e=>{let{teams:l,setSelectedTeam:t}=e,s={models:[],team_id:null,team_alias:"Default Team"},[a,o]=(0,n.useState)(s),i=l?[...l,s]:[s];return(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(H.Z,{children:"Select Team"}),(0,r.jsx)(Y.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)(Y.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."]}),i&&i.length>0?(0,r.jsx)(ew.Z,{defaultValue:"0",children:i.map((e,l)=>(0,r.jsx)(eb.Z,{value:String(l),onClick:()=>t(e),children:e.team_alias},l))}):(0,r.jsxs)(Y.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eA=t(37963),eN=t(36083);console.log("isLocal:",!1);var eC=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,y]=(0,n.useState)(null),[Z,b]=(0,n.useState)(null),[_,v]=(0,n.useState)([]),[S,A]=(0,n.useState)(s?s[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eA.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),y(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?v(JSON.parse(e)):(async()=>{try{let e=await f(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 w(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams),A(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let s=(await k(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",s),v(s),console.log("userModels:",_),sessionStorage.setItem("userModels"+l,JSON.stringify(s))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=S){let e=0;for(let l of a)S.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===S.team_id&&(e+=l.spend);b(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;b(e)}},[S]),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}=eN.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",S),console.log("teamSpend: ".concat(Z)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(ev,{userID:l,userRole:t,accessToken:g,userSpend:Z}),(0,r.jsx)(ek,{userID:l,userRole:t,accessToken:g,selectedTeam:S||null,data:a,setData:h,teams:s}),(0,r.jsx)(er,{userID:l,team:S||null,userRole:t,accessToken:g,data:a,setData:h},S?S.team_id:null),(0,r.jsx)(eS,{teams:s,setSelectedTeam:A})]})})})},eI=t(26780),eP=t(15595),eT=t(6698),eE=t(92836),eO=t(26734),eF=t(41608),eM=t(32126),eR=t(23682),eD=t(52273),eL=t(47047),eU=t(76628),ez=t(38302),eB=t(28683),eq=t(1460),eV=t(78578),eK=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)(ex.Z,{onClick:()=>a(!0),icon:ei.Z,size:"sm"}),(0,r.jsx)(ee.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(H.Z,{children:"Delete Model"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eG=t(97766),eJ=t(46495);let{Title:eW,Link:eY}=eN.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 eH={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"};var e$=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d}=e,[m,p]=(0,n.useState)({data:[]}),[j,g]=(0,n.useState)([]),[y]=Q.Z.useForm(),[Z,f]=(0,n.useState)(null),[w,_]=(0,n.useState)([]),k=Object.values(a).filter(e=>isNaN(Number(e))),[v,S]=(0,n.useState)("OpenAI"),[A,N]=(0,n.useState)("");if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await b(o,d,c);if(console.log("Model data response:",e.data),p(e),"Admin"===c&&o){let e=await O(o);console.log("Pending Requests:",j),g(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};o&&i&&c&&d&&e();let l=async()=>{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==Z&&l()},[o,i,c,d,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let C=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(Z)),null!=Z&&"object"==typeof Z&&e in Z)?Z[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,C.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eN.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 I=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=eH[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof Z&&Object.entries(Z).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)}),_(t),console.log("providerModels: ".concat(w))}},P=async()=>{try{h.ZP.info("Running health check..."),N("");let e=await K(o);N(e)}catch(e){console.error("Error running health check:",e),N("Error running health check")}},T=async e=>{try{let l=Object.values(e.model);console.log("received deployments: ".concat(l)),console.log("received type of deployments: ".concat(typeof l)),l.forEach(async l=>{console.log("litellm_model: ".concat(l));let t={},s={};t.model=l;let a="";for(let[l,r]of Object.entries(e))if("model_name"==l)a+=r;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)s[l]=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else t[l]=r;let r={model_name:a,litellm_params:t,model_info:s},n=await x(o,r);console.log("response for model create call: ".concat(n.data))}),y.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};return console.log("selectedProvider: ".concat(v)),console.log("providerModels.length: ".concat(w.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eO.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Models"}),(0,r.jsx)(eE.Z,{children:"Add Model"}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(J.Z,{children:(0,r.jsx)(em.Z,{children:(0,r.jsxs)(ep.Z,{className:"mt-5",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Model Name "}),(0,r.jsx)(eZ.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(eZ.Z,{children:"API Base"}),(0,r.jsx)(eZ.Z,{children:"Extra litellm Params"}),(0,r.jsx)(eZ.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(eZ.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(eZ.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(ej.Z,{children:m.data.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:e.model_name})}),(0,r.jsx)(eg.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(eg.Z,{children:e.api_base}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(eT.Z,{children:(0,r.jsx)(Y.Z,{children:"Litellm params"})}),(0,r.jsx)(eP.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(eg.Z,{children:e.input_cost}),(0,r.jsx)(eg.Z,{children:e.output_cost}),(0,r.jsx)(eg.Z,{children:e.max_tokens}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(eK,{modelID:e.model_info.id,accessToken:o})})]},l))})]})})})}),(0,r.jsxs)(eM.Z,{className:"h-full",children:[(0,r.jsx)(eW,{level:2,children:"Add new model"}),(0,r.jsx)(em.Z,{children:(0,r.jsxs)(Q.Z,{form:y,onFinish:()=>{y.validateFields().then(e=>{T(e)}).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)(Q.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)(ew.Z,{value:v.toString(),children:k.map((e,l)=>(0,r.jsx)(eb.Z,{value:e,onClick:()=>{I(e),S(e)},children:e},l))})}),(0,r.jsx)(Q.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)(eD.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=v.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)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(Y.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(Q.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"===v?(0,r.jsx)(eD.Z,{placeholder:"Enter model name"}):w.length>0?(0,r.jsx)(eL.Z,{value:w,children:w.map((e,l)=>(0,r.jsx)(eU.Z,{value:e,children:e},l))}):(0,r.jsx)(eD.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(Y.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(eY,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(eY,{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"!=v&&"Vertex AI (Anthropic, Gemini, etc.)"!=v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)(eD.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==v&&(0,r.jsx)(Q.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)(eD.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(eD.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(eD.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eJ.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;y.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)(es.ZP,{icon:(0,r.jsx)(eG.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(Y.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==v||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==v)&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(eD.Z,{placeholder:"https://..."})}),"Azure"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)(eD.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==v&&(0,r.jsxs)(Q.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)(eD.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(Y.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(eY,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==v&&(0,r.jsx)(Q.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)(eD.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(Q.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)(eD.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(Q.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)(eD.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(Q.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)(eV.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(Y.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(eY,{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)(es.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eq.Z,{title:"Get help on our github",children:(0,r.jsx)(eN.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(Y.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(W.Z,{onClick:P,children:"Run `/health`"}),A&&(0,r.jsx)("pre",{children:JSON.stringify(A,null,2)})]})})]})]})})};let{Option:eX}=X.default;var eQ=e=>{let{userID:l,accessToken:t}=e,[s]=Q.Z.useForm(),[a,o]=(0,n.useState)(!1),[i,c]=(0,n.useState)(null),[d,m]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await k(t,l,"any"),s=[];for(let l=0;l{o(!1),s.resetFields()},x=()=>{o(!1),c(null),s.resetFields()},p=async e=>{try{h.ZP.info("Making API Call"),o(!0),console.log("formValues in create user:",e);let a=await g(t,l,e);console.log("user create Response:",a),c(a.key),h.ZP.success("API user Created"),s.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(W.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Create New User"}),(0,r.jsx)(ee.Z,{title:"Create User",visible:a,width:800,footer:null,onOk:u,onCancel:x,children:(0,r.jsxs)(Q.Z,{form:s,onFinish:p,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(Q.Z.Item,{label:"User ID",name:"user_id",children:(0,r.jsx)(el.Z,{placeholder:"Enter User ID"})}),(0,r.jsx)(Q.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(el.Z,{placeholder:"ai_team"})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",children:(0,r.jsx)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:d.map(e=>(0,r.jsx)(eX,{value:e,children:e},e))})}),(0,r.jsx)(Q.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Duration (eg: 30s, 30h, 30d)",name:"duration",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(el.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Create User"})})]})}),i&&(0,r.jsxs)(ee.Z,{title:"Save Your User",visible:a,onOk:u,onCancel:x,footer:null,children:[(0,r.jsxs)("p",{children:["Please save this secret user 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 user, you will need to generate a new one."]}),(0,r.jsx)("p",{children:null!=i?"API user: ".concat(i):"User being created, this might take 30s"})]})]})},e0=e=>{let{accessToken:l,token:t,keys:s,userRole:a,userID:o,setKeys:i}=e,[c,d]=(0,n.useState)(null),[m,h]=(0,n.useState)(null),[u,x]=(0,n.useState)(0),[p,j]=n.useState(null),[g,y]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await f(l,null,a,!0,u,25);console.log("user data response:",e),d(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 P(l,null);console.log("user data response:",e),h(e)}catch(e){console.error("There was an error fetching the model data",e)}};a&&("Admin"==a||"Admin Viewer"==a)&&!m&&s()},[l,t,a,o,u]),!c||!l||!t||!a||!o)return(0,r.jsx)("div",{children:"Loading..."});let Z=async e=>{try{let t=await P(l,e);console.log("user data response:",t),h(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)(J.Z,{className:"gap-2 p-2 h-[75vh] w-full mt-8",children:[(0,r.jsx)(eQ,{userID:o,accessToken:l}),(0,r.jsx)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eE.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(ep.Z,{className:"mt-5",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"User ID"}),(0,r.jsx)(eZ.Z,{children:"User Email"}),(0,r.jsx)(eZ.Z,{children:"User Models"}),(0,r.jsx)(eZ.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(eZ.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(eZ.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(ej.Z,{children:c.map(e=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.user_id}),(0,r.jsx)(eg.Z,{children:e.user_email}),(0,r.jsx)(eg.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(eg.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(eg.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(J.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(ec.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(ec.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eM.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)(Y.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(ew.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_name&&e.key_name.length>0)return(0,r.jsx)(eb.Z,{value:String(l),onClick:()=>Z(e.token),children:e.key_name},l)})})]})]}),(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"End User"}),(0,r.jsx)(eZ.Z,{children:"Spend"}),(0,r.jsx)(eZ.Z,{children:"Total Events"})]})}),(0,r.jsx)(ej.Z,{children:null==m?void 0:m.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.end_user}),(0,r.jsx)(eg.Z,{children:e.total_spend}),(0,r.jsx)(eg.Z,{children:e.total_events})]},l))})]})]})]})]})}),function(){if(!c)return null;let e=Math.ceil(c.length/25);return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",u+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===u,onClick:()=>x(u-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:()=>{x(u+1)},children:"Next →"})]})]})}()]})})},e1=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=Q.Z.useForm(),[d]=Q.Z.useForm(),{Title:m,Paragraph:u}=eN.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[y,f]=(0,n.useState)(l?l[0]:null),[w,b]=(0,n.useState)(!1),[_,v]=(0,n.useState)(!1),[S,A]=(0,n.useState)([]),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),T=e=>{f(e),g(!0)},E=async e=>{let t=e.team_id;if(console.log("handleEditSubmit:",e),null==s)return;let r=await D(s,e);l&&a(l.map(e=>e.team_id===t?r.data:e)),h.ZP.success("Team updated successfully"),g(!1),f(null)},O=async e=>{P(e),C(!0)},F=async()=>{if(null!=I&&null!=l&&null!=s){try{await Z(s,I);let e=l.filter(e=>e.team_id!==I);a(e)}catch(e){console.error("Error deleting the team:",e)}C(!1),P(null)}};(0,n.useEffect)(()=>{(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await k(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),A(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,o,i]);let R=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await M(s,e);null!==l?a([...l,t]):a([t]),console.log("response for team create call: ".concat(t)),h.ZP.success("Team created"),b(!1)}}catch(e){console.error("Error creating the team:",e),h.ZP.error("Error creating the team: "+e,20)}},U=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 L(s,y.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),f(r.data)}v(!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)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Team Name"}),(0,r.jsx)(eZ.Z,{children:"Spend (USD)"}),(0,r.jsx)(eZ.Z,{children:"Budget (USD)"}),(0,r.jsx)(eZ.Z,{children:"Models"}),(0,r.jsx)(eZ.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(ej.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(eg.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)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(Y.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)(eg.Z,{children:[(0,r.jsx)(ex.Z,{icon:eo.Z,size:"sm",onClick:()=>T(e)}),(0,r.jsx)(ex.Z,{onClick:()=>O(e.team_id),icon:ei.Z,size:"sm"})]})]},e.team_id)):null})]}),N&&(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)(W.Z,{onClick:F,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{C(!1),P(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto",onClick:()=>b(!0),children:"+ Create New Team"}),(0,r.jsx)(ee.Z,{title:"Create Team",visible:w,width:800,footer:null,onOk:()=>{b(!1),c.resetFields()},onCancel:()=>{b(!1),c.resetFields()},children:(0,r.jsxs)(Q.Z,{form:c,onFinish:R,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(X.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S.map(e=>(0,r.jsx)(X.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(Q.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(G.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)(ew.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eb.Z,{value:String(l),onClick:()=>{f(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)(G.Z,{numColSpan:1,children:[(0,r.jsx)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Member Name"}),(0,r.jsx)(eZ.Z,{children:"Role"})]})}),(0,r.jsx)(ej.Z,{children:y?y.members_with_roles.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(eg.Z,{children:e.role})]},l)):null})]})}),y&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=Q.Z.useForm();return(0,r.jsx)(ee.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)(Q.Z,{form:n,onFinish:E,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(X.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S&&S.map(e=>(0,r.jsx)(X.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(Q.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.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)(es.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),f(null)},team:y,onSubmit:E})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto mb-5",onClick:()=>v(!0),children:"+ Add member"}),(0,r.jsx)(ee.Z,{title:"Add member",visible:_,width:800,footer:null,onOk:()=>{v(!1),d.resetFields()},onCancel:()=>{v(!1),d.resetFields()},children:(0,r.jsxs)(Q.Z,{form:c,onFinish:U,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(el.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)(Q.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(el.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)(es.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e2=t(18190),e4=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=Q.Z.useForm(),[i]=Q.Z.useForm(),{Title:c,Paragraph:d}=eN.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[y,Z]=(0,n.useState)(!1),[f,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 F(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 F(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)(Q.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(el.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)(Q.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(el.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)(es.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(Q.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(ew.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(eb.Z,{value:e,children:e},l))})}),(0,r.jsx)(Q.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(el.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await U(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 U(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)}},O=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await U(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)),Z(!1)}}catch(e){console.error("Error creating the key:",e)}},M=async e=>{null!=s&&V(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)(J.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsx)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Member Name"}),(0,r.jsx)(eZ.Z,{children:"Role"})]})}),(0,r.jsx)(ej.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(eg.Z,{children:e.user_role}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(ex.Z,{icon:eo.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(ee.Z,{title:"Update role",visible:f,width:800,footer:null,onOk:N,onCancel:C,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(W.Z,{className:"mr-4 mb-5",onClick:()=>Z(!0),children:"+ Add admin"}),(0,r.jsx)(ee.Z,{title:"Add admin",visible:y,width:800,footer:null,onOk:()=>{Z(!1),i.resetFields()},onCancel:()=>{Z(!1),i.resetFields()},children:I(O)}),(0,r.jsx)(W.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(ee.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)(J.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)(W.Z,{onClick:()=>_(!0),children:"Add SSO"}),(0,r.jsx)(ee.Z,{title:"Add SSO",visible:b,width:800,footer:null,onOk:()=>{_(!1),o.resetFields()},onCancel:()=>{_(!1),o.resetFields()},children:(0,r.jsxs)(Q.Z,{form:o,onFinish:e=>{O(e),M(e),_(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(el.Z.Password,{})}),(0,r.jsx)(Q.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(el.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(ee.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)(Y.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(Y.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(Y.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(Y.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)(es.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e2.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})," "]})]})]})]})},e8=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)(!1),[d]=Q.Z.useForm(),[m,u]=(0,n.useState)(null),[x,p]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.data)})},[l,t,s]);let j=e=>{p(e),console.log("Selected values:",e)},g=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",x);try{V(l,{environment_variables:t,general_settings:{alert_types:x}})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},y=()=>{l&&d.validateFields().then(e=>{console.log("Form values:",e),"langfuse"===e.callback?(V(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}}),o(a?[...a,e.callback]:[e.callback])):"slack"===e.callback&&(V(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),o(a?[...a,e.callback]:[e.callback])),c(!1),d.resetFields(),u(null)})};return l?(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(H.Z,{children:"Logging Callbacks"}),(0,r.jsxs)(em.Z,{children:[(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Callback"}),(0,r.jsx)(eZ.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(ej.Z,{children:a.map((e,t)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:(0,r.jsx)(ec.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(e.variables).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(Y.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)(eD.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),e.all_alert_types&&(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.Z,{className:"mt-2",children:"Alerting Types"}),(0,r.jsx)(X.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select Alerting Types",optionLabelProp:"label",onChange:j,defaultValue:e.alerting_types,children:e.all_alert_types.map(e=>(0,r.jsx)(X.default.Option,{value:e,label:e,children:e},e))})]}),(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>g(e),children:"Save Changes"}),(0,r.jsx)(W.Z,{onClick:()=>B(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t))})]}),(0,r.jsx)(W.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),c(!0)},children:"Add Callback"})]})]}),(0,r.jsx)(ee.Z,{title:"Add Callback",visible:i,onOk:y,width:800,onCancel:()=>{c(!1),d.resetFields(),u(null)},footer:null,children:(0,r.jsxs)(Q.Z,{form:d,layout:"vertical",onFinish:y,children:[(0,r.jsx)(Q.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsxs)(X.default,{onChange:e=>{u(e)},children:[(0,r.jsx)(X.default.Option,{value:"langfuse",children:"langfuse"}),(0,r.jsx)(X.default.Option,{value:"slack",children:"slack alerting"})]})}),"langfuse"===m&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)(el.Z.Password,{})}),(0,r.jsx)(Q.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)(el.Z.Password,{})})]}),"slack"===m&&(0,r.jsx)(Q.Z.Item,{label:"SLACK_WEBHOOK_URL",name:"slackWebhookUrl",rules:[{required:!0,message:"Please enter the Slack webhook URL"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Save"})})]})})]}):null},e3=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)({}),[i,c]=(0,n.useState)(!1),[d]=Q.Z.useForm(),[m,u]=(0,n.useState)(null);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.router_settings)})},[l,t,s]);let x=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).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);try{V(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)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(H.Z,{children:"Router Settings"}),(0,r.jsx)(em.Z,{children:(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Setting"}),(0,r.jsx)(eZ.Z,{children:"Value"})]})}),(0,r.jsx)(ej.Z,{children:Object.entries(a).map(e=>{let[l,t]=e;return(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:l})}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(eD.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(G.Z,{children:(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>x(a),children:"Save Changes"})})]})}):null},e5=t(12968),e6=t(67951);async function e7(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new e5.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 e9=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 k(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}]})},y=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await e7(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}=eN.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(J.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(em.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"Chat"}),(0,r.jsx)(eE.Z,{children:"API Reference"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(J.Z,{numItems:2,children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)(Y.Z,{children:"API Key"}),(0,r.jsx)(eD.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(G.Z,{className:"mx-2",children:[(0,r.jsx)(Y.Z,{children:"Select Model:"}),(0,r.jsx)(X.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ep.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eg.Z,{})})}),(0,r.jsx)(ej.Z,{children:m.map((e,l)=>(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eg.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)(eD.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(W.Z,{onClick:y,className:"ml-2",children:"Send"})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eE.Z,{children:"LlamaIndex"}),(0,r.jsx)(eE.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # proxy base url\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to use from Models Tab\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ],\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-openai-client",\n "generation_id": "openai-client-gen-id22",\n "trace_id": "openai-client-trace-id22",\n "trace_user_id": "openai-client-user-id2"\n }\n }\n)\n\nprint(response)\n '})}),(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.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)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="http://0.0.0.0:8000",\n model = "gpt-3.5-turbo",\n temperature=0.1,\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-langchain-client",\n "generation_id": "langchain-client-gen-id22",\n "trace_id": "langchain-client-trace-id22",\n "trace_user_id": "langchain-client-user-id2"\n }\n }\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})})]})]})})})})},le=t(33509),ll=t(95781);let{Sider:lt}=le.default;var ls=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(Y.Z,{children:"API Keys"})},"1"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(Y.Z,{children:"Test Key"})},"3"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(Y.Z,{children:"Models"})},"2"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(Y.Z,{children:"Teams"})},"6"):null,(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(Y.Z,{children:"Usage"})},"4"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(Y.Z,{children:"Users"})},"5"):null,(0,r.jsx)(ll.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(Y.Z,{children:"Integrations"})},"8"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(Y.Z,{children:"Settings"})},"9"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(Y.Z,{children:"Admin"})},"7"):null]})})})},la=t(67989),lr=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)([]),[y,Z]=(0,n.useState)([]),[f,w]=(0,n.useState)([]),[b,k]=(0,n.useState)([]),[v,P]=(0,n.useState)([]),[O,F]=(0,n.useState)([]),M=new Date(o.getFullYear(),o.getMonth(),1),R=new Date(o.getFullYear(),o.getMonth()+1,0),D=U(M),L=U(R);function U(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)}return console.log("Start date is ".concat(D)),console.log("End date is ".concat(L)),(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{if(console.log("user role: ".concat(s)),"Admin"==s||"Admin Viewer"==s){let e=await C(l);c(e);let t=(await I(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let s=(await T(l)).map(e=>({key:e.model,spend:e.total_spend}));u(s);let a=await S(l);console.log("teamSpend",a),g(a.daily_spend),w(a.teams);let r=a.total_spend_per_team;r=r.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),k(r);let n=await A(l);Z(n.top_10_tags)}else"App Owner"==s&&await N(l,t,s,a,D,L).then(async 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 E(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 _(l,a,s);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),P(e),F(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,D,L]),(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(ev,{userID:a,userRole:s,accessToken:l,userSpend:null}),(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Up"}),(0,r.jsx)(eE.Z,{children:"Team Based Usage"}),(0,r.jsx)(eE.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eE.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Monthly Spend"}),(0,r.jsx)(ed.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Top API Keys"}),(0,r.jsx)(ed.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Top Users"}),(0,r.jsx)(ed.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Top Models"}),(0,r.jsx)(ed.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)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(G.Z,{numColSpan:2,children:[(0,r.jsxs)(em.Z,{className:"mb-2",children:[(0,r.jsx)(H.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(la.Z,{data:b})]}),(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(ed.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:f,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(Y.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)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Tag"}),(0,r.jsx)(eZ.Z,{children:"Spend"}),(0,r.jsx)(eZ.Z,{children:"Requests"})]})}),(0,r.jsx)(ej.Z,{children:y.map(e=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.name}),(0,r.jsx)(eg.Z,{children:e.value}),(0,r.jsx)(eg.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Number Requests per Model"}),(0,r.jsx)(ed.Z,{data:v,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(em.Z,{className:"mt-4",children:[(0,r.jsx)(H.Z,{children:"Latency Per Model"}),(0,r.jsx)(ed.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},ln=()=>{let{Title:e,Paragraph:l}=eN.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=j.get("userID"),y=j.get("token"),[Z,f]=(0,n.useState)("api-keys"),[w,b]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(y){let e=(0,eA.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),b(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&&f("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?p("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[y]),(0,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:g,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)(ls,{setPage:f,userRole:t,defaultSelectedKey:null})}),"api-keys"==Z?(0,r.jsx)(eC,{userID:g,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==Z?(0,r.jsx)(e$,{userID:g,userRole:t,token:y,accessToken:w}):"llm-playground"==Z?(0,r.jsx)(e9,{userID:g,userRole:t,token:y,accessToken:w}):"users"==Z?(0,r.jsx)(e0,{userID:g,userRole:t,token:y,keys:h,accessToken:w,setKeys:u}):"teams"==Z?(0,r.jsx)(e1,{teams:c,setTeams:d,searchParams:j,accessToken:w,userID:g,userRole:t}):"admin-panel"==Z?(0,r.jsx)(e4,{setTeams:d,searchParams:j,accessToken:w,showSSOBanner:x}):"settings"==Z?(0,r.jsx)(e8,{userID:g,userRole:t,accessToken:w}):"general-settings"==Z?(0,r.jsx)(e3,{userID:g,userRole:t,accessToken:w}):(0,r.jsx)(lr,{userID:g,userRole:t,token:y,accessToken:w})]})]})})}}},function(e){e.O(0,[968,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/index.html b/litellm/proxy/_experimental/out/index.html index 93b1ab8ebf..acb0606eed 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 8a4a6fb5b5..c49dab960c 100644 --- a/litellm/proxy/_experimental/out/index.txt +++ b/litellm/proxy/_experimental/out/index.txt @@ -1,7 +1,7 @@ 2:I[77831,[],""] -3:I[16586,["968","static/chunks/968-0cc23fee51b47e4e.js","931","static/chunks/app/page-93ac11fb17dce9d6.js"],""] +3:I[65249,["968","static/chunks/968-0cc23fee51b47e4e.js","931","static/chunks/app/page-6ba29bc4256320f4.js"],""] 4:I[5613,[],""] 5:I[31778,[],""] -0:["Oe7aA-U7OV9Y13gspREJQ",[[["",{"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/dc347b0d22ffde5d.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] +0:["Vjlnu8AomhCFg4fkGtcUs",[[["",{"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/dc347b0d22ffde5d.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/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index a8101181cc..d717dc1595 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -4,14 +4,12 @@ model_list: model: openai/my-fake-model api_key: my-fake-key api_base: https://openai-function-calling-workers.tasslexyz.workers.dev/ - # api_base: http://0.0.0.0:8080 stream_timeout: 0.001 - model_name: fake-openai-endpoint litellm_params: model: openai/my-fake-model-2 api_key: my-fake-key api_base: https://openai-function-calling-workers.tasslexyz.workers.dev/ - # api_base: http://0.0.0.0:8080 stream_timeout: 0.001 - litellm_params: model: azure/chatgpt-v-2 @@ -30,13 +28,6 @@ model_list: # api_key: my-fake-key # api_base: https://exampleopenaiendpoint-production.up.railway.app/ -# litellm_settings: -# success_callback: ["prometheus"] -# failure_callback: ["prometheus"] -# service_callback: ["prometheus_system"] -# upperbound_key_generate_params: -# max_budget: os.environ/LITELLM_UPPERBOUND_KEYS_MAX_BUDGET - router_settings: routing_strategy: usage-based-routing-v2 # redis_url: "os.environ/REDIS_URL" @@ -48,6 +39,10 @@ router_settings: litellm_settings: num_retries: 3 # retry call 3 times on each model_name allowed_fails: 3 # cooldown model if it fails > 1 call in a minute. + success_callback: ["prometheus"] + failure_callback: ["prometheus"] + service_callback: ["prometheus_system"] + general_settings: alerting: ["slack"] diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index b697b6e976..ca9926cef0 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -87,6 +87,14 @@ class LiteLLMRoutes(enum.Enum): "/v2/key/info", ] + sso_only_routes: List = [ + "/key/generate", + "/key/update", + "/key/delete", + "/global/spend/logs", + "/global/predict/spend/logs", + ] + management_routes: List = [ # key "/key/generate", "/key/update", diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 1aab7bac28..7f8d7d4a36 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1053,6 +1053,11 @@ async def user_api_key_auth( status_code=status.HTTP_403_FORBIDDEN, detail="key not allowed to access this team's info", ) + elif ( + _has_user_setup_sso() + and route in LiteLLMRoutes.sso_only_routes.value + ): + pass else: raise Exception( f"Only master key can be used to generate, delete, update info for new keys/users/teams. Route={route}" @@ -1102,6 +1107,13 @@ async def user_api_key_auth( return UserAPIKeyAuth( api_key=api_key, user_role="proxy_admin", **valid_token_dict ) + elif ( + _has_user_setup_sso() + and route in LiteLLMRoutes.sso_only_routes.value + ): + return UserAPIKeyAuth( + api_key=api_key, user_role="app_owner", **valid_token_dict + ) else: raise Exception( f"This key is made for LiteLLM UI, Tried to access route: {route}. Not allowed" @@ -5721,6 +5733,20 @@ async def new_user(data: NewUserRequest): "user" # only create a user, don't create key if 'auto_create_key' set to False ) response = await generate_key_helper_fn(**data_json) + + # Admin UI Logic + # if team_id passed add this user to the team + if data_json.get("team_id", None) is not None: + await team_member_add( + data=TeamMemberAddRequest( + team_id=data_json.get("team_id", None), + member=Member( + user_id=data_json.get("user_id", None), + role="user", + user_email=data_json.get("user_email", None), + ), + ) + ) return NewUserResponse( key=response.get("token", ""), expires=response.get("expires", None), @@ -6526,13 +6552,20 @@ async def team_member_add( existing_team_row = await prisma_client.get_data( # type: ignore team_id=data.team_id, table_name="team", query_type="find_unique" ) + if existing_team_row is None: + raise HTTPException( + status_code=404, + detail={ + "error": f"Team not found for team_id={getattr(data, 'team_id', None)}" + }, + ) new_member = data.member existing_team_row.members_with_roles.append(new_member) complete_team_data = LiteLLM_TeamTable( - **existing_team_row.model_dump(), + **_get_pydantic_json_dict(existing_team_row), ) team_row = await prisma_client.update_data( @@ -8120,36 +8153,33 @@ async def auth_callback(request: Request): } user_role = getattr(user_info, "user_role", None) - else: - ## check if user-email in db ## - user_info = await prisma_client.db.litellm_usertable.find_first( - where={"user_email": user_email} - ) - if user_info is not None: - user_defined_values = { - "models": getattr(user_info, "models", user_id_models), - "user_id": getattr(user_info, "user_id", user_id), - "user_email": getattr(user_info, "user_id", user_email), - "user_role": getattr(user_info, "user_role", None), - } - user_role = getattr(user_info, "user_role", None) + ## check if user-email in db ## + user_info = await prisma_client.db.litellm_usertable.find_first( + where={"user_email": user_email} + ) + if user_info is not None: + user_defined_values = { + "models": getattr(user_info, "models", user_id_models), + "user_id": getattr(user_info, "user_id", user_id), + "user_email": getattr(user_info, "user_id", user_email), + "user_role": getattr(user_info, "user_role", None), + } + user_role = getattr(user_info, "user_role", None) - # update id - await prisma_client.db.litellm_usertable.update_many( - where={"user_email": user_email}, data={"user_id": user_id} # type: ignore - ) - elif litellm.default_user_params is not None and isinstance( - litellm.default_user_params, dict - ): - user_defined_values = { - "models": litellm.default_user_params.get( - "models", user_id_models - ), - "user_id": litellm.default_user_params.get("user_id", user_id), - "user_email": litellm.default_user_params.get( - "user_email", user_email - ), - } + # update id + await prisma_client.db.litellm_usertable.update_many( + where={"user_email": user_email}, data={"user_id": user_id} # type: ignore + ) + elif litellm.default_user_params is not None and isinstance( + litellm.default_user_params, dict + ): + user_defined_values = { + "models": litellm.default_user_params.get("models", user_id_models), + "user_id": litellm.default_user_params.get("user_id", user_id), + "user_email": litellm.default_user_params.get( + "user_email", user_email + ), + } except Exception as e: pass diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 02e8a41668..18f1b837f4 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -238,7 +238,10 @@ class ProxyLogging: litellm_params = kwargs.get("litellm_params", {}) model = kwargs.get("model", "") api_base = litellm.get_api_base(model=model, optional_params=litellm_params) - messages = kwargs.get("messages", "") + messages = kwargs.get("messages", None) + # if messages does not exist fallback to "input" + if messages is None: + messages = kwargs.get("input", None) # only use first 100 chars for alerting _messages = str(messages)[:100] @@ -282,7 +285,10 @@ class ProxyLogging: ): if request_data is not None: model = request_data.get("model", "") - messages = request_data.get("messages", "") + messages = request_data.get("messages", None) + if messages is None: + # if messages does not exist fallback to "input" + messages = request_data.get("input", None) trace_id = request_data.get("metadata", {}).get( "trace_id", None ) # get langfuse trace id diff --git a/litellm/router.py b/litellm/router.py index 8145ef619e..fda53eb4fa 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -26,7 +26,12 @@ from litellm.llms.custom_httpx.azure_dall_e_2 import ( CustomHTTPTransport, AsyncCustomHTTPTransport, ) -from litellm.utils import ModelResponse, CustomStreamWrapper, get_utc_datetime +from litellm.utils import ( + ModelResponse, + CustomStreamWrapper, + get_utc_datetime, + calculate_max_parallel_requests, +) import copy from litellm._logging import verbose_router_logger import logging @@ -61,6 +66,7 @@ class Router: num_retries: int = 0, timeout: Optional[float] = None, default_litellm_params={}, # default params for Router.chat.completion.create + default_max_parallel_requests: Optional[int] = None, set_verbose: bool = False, debug_level: Literal["DEBUG", "INFO"] = "INFO", fallbacks: List = [], @@ -198,6 +204,7 @@ class Router: ) # use a dual cache (Redis+In-Memory) for tracking cooldowns, usage, etc. self.default_deployment = None # use this to track the users default deployment, when they want to use model = * + self.default_max_parallel_requests = default_max_parallel_requests if model_list: model_list = copy.deepcopy(model_list) @@ -213,6 +220,7 @@ class Router: ) # cache to track failed call per deployment, if num failed calls within 1 minute > allowed fails, then add it to cooldown self.num_retries = num_retries or litellm.num_retries or 0 self.timeout = timeout or litellm.request_timeout + self.retry_after = retry_after self.routing_strategy = routing_strategy self.fallbacks = fallbacks or litellm.fallbacks @@ -298,7 +306,7 @@ class Router: else: litellm.failure_callback = [self.deployment_callback_on_failure] verbose_router_logger.info( - f"Intialized router with Routing strategy: {self.routing_strategy}\n\nRouting fallbacks: {self.fallbacks}\n\nRouting context window fallbacks: {self.context_window_fallbacks}" + f"Intialized router with Routing strategy: {self.routing_strategy}\n\nRouting fallbacks: {self.fallbacks}\n\nRouting context window fallbacks: {self.context_window_fallbacks}\n\nRouter Redis Caching={self.cache.redis_cache}" ) self.routing_strategy_args = routing_strategy_args @@ -496,7 +504,9 @@ class Router: ) rpm_semaphore = self._get_client( - deployment=deployment, kwargs=kwargs, client_type="rpm_client" + deployment=deployment, + kwargs=kwargs, + client_type="max_parallel_requests", ) if rpm_semaphore is not None and isinstance( @@ -681,7 +691,9 @@ class Router: ### CONCURRENCY-SAFE RPM CHECKS ### rpm_semaphore = self._get_client( - deployment=deployment, kwargs=kwargs, client_type="rpm_client" + deployment=deployment, + kwargs=kwargs, + client_type="max_parallel_requests", ) if rpm_semaphore is not None and isinstance( @@ -803,7 +815,9 @@ class Router: ### CONCURRENCY-SAFE RPM CHECKS ### rpm_semaphore = self._get_client( - deployment=deployment, kwargs=kwargs, client_type="rpm_client" + deployment=deployment, + kwargs=kwargs, + client_type="max_parallel_requests", ) if rpm_semaphore is not None and isinstance( @@ -1049,7 +1063,9 @@ class Router: ) rpm_semaphore = self._get_client( - deployment=deployment, kwargs=kwargs, client_type="rpm_client" + deployment=deployment, + kwargs=kwargs, + client_type="max_parallel_requests", ) if rpm_semaphore is not None and isinstance( @@ -1243,7 +1259,9 @@ class Router: ### CONCURRENCY-SAFE RPM CHECKS ### rpm_semaphore = self._get_client( - deployment=deployment, kwargs=kwargs, client_type="rpm_client" + deployment=deployment, + kwargs=kwargs, + client_type="max_parallel_requests", ) if rpm_semaphore is not None and isinstance( @@ -1862,17 +1880,23 @@ class Router: model_id = model["model_info"]["id"] # ### IF RPM SET - initialize a semaphore ### rpm = litellm_params.get("rpm", None) - if rpm: - semaphore = asyncio.Semaphore(rpm) - cache_key = f"{model_id}_rpm_client" + tpm = litellm_params.get("tpm", None) + max_parallel_requests = litellm_params.get("max_parallel_requests", None) + calculated_max_parallel_requests = calculate_max_parallel_requests( + rpm=rpm, + max_parallel_requests=max_parallel_requests, + tpm=tpm, + default_max_parallel_requests=self.default_max_parallel_requests, + ) + if calculated_max_parallel_requests: + semaphore = asyncio.Semaphore(calculated_max_parallel_requests) + cache_key = f"{model_id}_max_parallel_requests_client" self.cache.set_cache( key=cache_key, value=semaphore, local_only=True, ) - # print("STORES SEMAPHORE IN CACHE") - #### for OpenAI / Azure we need to initalize the Client for High Traffic ######## custom_llm_provider = litellm_params.get("custom_llm_provider") custom_llm_provider = custom_llm_provider or model_name.split("/", 1)[0] or "" @@ -2537,8 +2561,8 @@ class Router: The appropriate client based on the given client_type and kwargs. """ model_id = deployment["model_info"]["id"] - if client_type == "rpm_client": - cache_key = "{}_rpm_client".format(model_id) + if client_type == "max_parallel_requests": + cache_key = "{}_max_parallel_requests_client".format(model_id) client = self.cache.get_cache(key=cache_key, local_only=True) return client elif client_type == "async": @@ -2778,6 +2802,7 @@ class Router: """ if ( self.routing_strategy != "usage-based-routing-v2" + and self.routing_strategy != "simple-shuffle" ): # prevent regressions for other routing strategies, that don't have async get available deployments implemented. return self.get_available_deployment( model=model, @@ -2828,6 +2853,25 @@ class Router: messages=messages, input=input, ) + elif self.routing_strategy == "simple-shuffle": + # if users pass rpm or tpm, we do a random weighted pick - based on rpm/tpm + ############## Check if we can do a RPM/TPM based weighted pick ################# + rpm = healthy_deployments[0].get("litellm_params").get("rpm", None) + if rpm is not None: + # use weight-random pick if rpms provided + rpms = [m["litellm_params"].get("rpm", 0) for m in healthy_deployments] + verbose_router_logger.debug(f"\nrpms {rpms}") + total_rpm = sum(rpms) + weights = [rpm / total_rpm for rpm in rpms] + verbose_router_logger.debug(f"\n weights {weights}") + # Perform weighted random pick + selected_index = random.choices(range(len(rpms)), weights=weights)[0] + verbose_router_logger.debug(f"\n selected index, {selected_index}") + deployment = healthy_deployments[selected_index] + verbose_router_logger.info( + f"get_available_deployment for model: {model}, Selected deployment: {self.print_deployment(deployment) or deployment[0]} for model: {model}" + ) + return deployment or deployment[0] if deployment is None: verbose_router_logger.info( diff --git a/litellm/router_strategy/lowest_tpm_rpm_v2.py b/litellm/router_strategy/lowest_tpm_rpm_v2.py index b2b6df42bf..39dbcd9d05 100644 --- a/litellm/router_strategy/lowest_tpm_rpm_v2.py +++ b/litellm/router_strategy/lowest_tpm_rpm_v2.py @@ -407,13 +407,15 @@ class LowestTPMLoggingHandler_v2(CustomLogger): tpm_keys.append(tpm_key) rpm_keys.append(rpm_key) - tpm_values = await self.router_cache.async_batch_get_cache( - keys=tpm_keys - ) # [1, 2, None, ..] - rpm_values = await self.router_cache.async_batch_get_cache( - keys=rpm_keys + combined_tpm_rpm_keys = tpm_keys + rpm_keys + + combined_tpm_rpm_values = await self.router_cache.async_batch_get_cache( + keys=combined_tpm_rpm_keys ) # [1, 2, None, ..] + tpm_values = combined_tpm_rpm_values[: len(tpm_keys)] + rpm_values = combined_tpm_rpm_values[len(tpm_keys) :] + return self._common_checks_available_deployment( model_group=model_group, healthy_deployments=healthy_deployments, diff --git a/litellm/tests/test_bedrock_completion.py b/litellm/tests/test_bedrock_completion.py index 4b1781cd93..ca2ffea5f5 100644 --- a/litellm/tests/test_bedrock_completion.py +++ b/litellm/tests/test_bedrock_completion.py @@ -269,6 +269,30 @@ def test_bedrock_claude_3_tool_calling(): assert isinstance( response.choices[0].message.tool_calls[0].function.arguments, str ) + messages.append( + response.choices[0].message.model_dump() + ) # Add assistant tool invokes + tool_result = ( + '{"location": "Boston", "temperature": "72", "unit": "fahrenheit"}' + ) + # Add user submitted tool results in the OpenAI format + messages.append( + { + "tool_call_id": response.choices[0].message.tool_calls[0].id, + "role": "tool", + "name": response.choices[0].message.tool_calls[0].function.name, + "content": tool_result, + } + ) + # In the second response, Claude should deduce answer from tool results + second_response = completion( + model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0", + messages=messages, + tools=tools, + tool_choice="auto", + ) + print(f"second response: {second_response}") + assert isinstance(second_response.choices[0].message.content, str) except RateLimitError: pass except Exception as e: diff --git a/litellm/tests/test_key_generate_prisma.py b/litellm/tests/test_key_generate_prisma.py index fdb7649d52..08618c9889 100644 --- a/litellm/tests/test_key_generate_prisma.py +++ b/litellm/tests/test_key_generate_prisma.py @@ -120,6 +120,15 @@ async def test_new_user_response(prisma_client): await litellm.proxy.proxy_server.prisma_client.connect() from litellm.proxy.proxy_server import user_api_key_cache + await new_team( + NewTeamRequest( + team_id="ishaan-special-team", + ), + user_api_key_dict=UserAPIKeyAuth( + user_role="proxy_admin", api_key="sk-1234", user_id="1234" + ), + ) + _response = await new_user( data=NewUserRequest( models=["azure-gpt-3.5"], @@ -999,10 +1008,32 @@ def test_generate_and_update_key(prisma_client): async def test(): await litellm.proxy.proxy_server.prisma_client.connect() + + # create team "litellm-core-infra@gmail.com"" + print("creating team litellm-core-infra@gmail.com") + await new_team( + NewTeamRequest( + team_id="litellm-core-infra@gmail.com", + ), + user_api_key_dict=UserAPIKeyAuth( + user_role="proxy_admin", api_key="sk-1234", user_id="1234" + ), + ) + + await new_team( + NewTeamRequest( + team_id="ishaan-special-team", + ), + user_api_key_dict=UserAPIKeyAuth( + user_role="proxy_admin", api_key="sk-1234", user_id="1234" + ), + ) + request = NewUserRequest( - metadata={"team": "litellm-team3", "project": "litellm-project3"}, + metadata={"project": "litellm-project3"}, team_id="litellm-core-infra@gmail.com", ) + key = await new_user(request) print(key) @@ -1015,7 +1046,6 @@ def test_generate_and_update_key(prisma_client): print("\n info for key=", result["info"]) assert result["info"]["max_parallel_requests"] == None assert result["info"]["metadata"] == { - "team": "litellm-team3", "project": "litellm-project3", } assert result["info"]["team_id"] == "litellm-core-infra@gmail.com" @@ -1037,7 +1067,7 @@ def test_generate_and_update_key(prisma_client): # update the team id response2 = await update_key_fn( request=Request, - data=UpdateKeyRequest(key=generated_key, team_id="ishaan"), + data=UpdateKeyRequest(key=generated_key, team_id="ishaan-special-team"), ) print("response2=", response2) @@ -1048,11 +1078,10 @@ def test_generate_and_update_key(prisma_client): print("\n info for key=", result["info"]) assert result["info"]["max_parallel_requests"] == None assert result["info"]["metadata"] == { - "team": "litellm-team3", "project": "litellm-project3", } assert result["info"]["models"] == ["ada", "babbage", "curie", "davinci"] - assert result["info"]["team_id"] == "ishaan" + assert result["info"]["team_id"] == "ishaan-special-team" # cleanup - delete key delete_key_request = KeyRequest(keys=[generated_key]) @@ -1941,6 +1970,15 @@ async def test_master_key_hashing(prisma_client): await litellm.proxy.proxy_server.prisma_client.connect() from litellm.proxy.proxy_server import user_api_key_cache + await new_team( + NewTeamRequest( + team_id="ishaans-special-team", + ), + user_api_key_dict=UserAPIKeyAuth( + user_role="proxy_admin", api_key="sk-1234", user_id="1234" + ), + ) + _response = await new_user( data=NewUserRequest( models=["azure-gpt-3.5"], diff --git a/litellm/tests/test_router_debug_logs.py b/litellm/tests/test_router_debug_logs.py index a768864aeb..0bc711b157 100644 --- a/litellm/tests/test_router_debug_logs.py +++ b/litellm/tests/test_router_debug_logs.py @@ -81,7 +81,7 @@ def test_async_fallbacks(caplog): # Define the expected log messages # - error request, falling back notice, success notice expected_logs = [ - "Intialized router with Routing strategy: simple-shuffle\n\nRouting fallbacks: [{'gpt-3.5-turbo': ['azure/gpt-3.5-turbo']}]\n\nRouting context window fallbacks: None", + "Intialized router with Routing strategy: simple-shuffle\n\nRouting fallbacks: [{'gpt-3.5-turbo': ['azure/gpt-3.5-turbo']}]\n\nRouting context window fallbacks: None\n\nRouter Redis Caching=None", "litellm.acompletion(model=gpt-3.5-turbo)\x1b[31m Exception OpenAIException - Error code: 401 - {'error': {'message': 'Incorrect API key provided: bad-key. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}\x1b[0m", "Falling back to model_group = azure/gpt-3.5-turbo", "litellm.acompletion(model=azure/chatgpt-v-2)\x1b[32m 200 OK\x1b[0m", diff --git a/litellm/tests/test_router_max_parallel_requests.py b/litellm/tests/test_router_max_parallel_requests.py new file mode 100644 index 0000000000..f9cac6aafb --- /dev/null +++ b/litellm/tests/test_router_max_parallel_requests.py @@ -0,0 +1,115 @@ +# What is this? +## Unit tests for the max_parallel_requests feature on Router +import sys, os, time, inspect, asyncio, traceback +from datetime import datetime +import pytest + +sys.path.insert(0, os.path.abspath("../..")) +import litellm +from litellm.utils import calculate_max_parallel_requests +from typing import Optional + +""" +- only rpm +- only tpm +- only max_parallel_requests +- max_parallel_requests + rpm +- max_parallel_requests + tpm +- max_parallel_requests + tpm + rpm +""" + + +max_parallel_requests_values = [None, 10] +tpm_values = [None, 20, 300000] +rpm_values = [None, 30] +default_max_parallel_requests = [None, 40] + + +@pytest.mark.parametrize( + "max_parallel_requests, tpm, rpm, default_max_parallel_requests", + [ + (mp, tp, rp, dmp) + for mp in max_parallel_requests_values + for tp in tpm_values + for rp in rpm_values + for dmp in default_max_parallel_requests + ], +) +def test_scenario(max_parallel_requests, tpm, rpm, default_max_parallel_requests): + calculated_max_parallel_requests = calculate_max_parallel_requests( + max_parallel_requests=max_parallel_requests, + rpm=rpm, + tpm=tpm, + default_max_parallel_requests=default_max_parallel_requests, + ) + if max_parallel_requests is not None: + assert max_parallel_requests == calculated_max_parallel_requests + elif rpm is not None: + assert rpm == calculated_max_parallel_requests + elif tpm is not None: + calculated_rpm = int(tpm / 1000 / 6) + if calculated_rpm == 0: + calculated_rpm = 1 + print( + f"test calculated_rpm: {calculated_rpm}, calculated_max_parallel_requests={calculated_max_parallel_requests}" + ) + assert calculated_rpm == calculated_max_parallel_requests + elif default_max_parallel_requests is not None: + assert calculated_max_parallel_requests == default_max_parallel_requests + else: + assert calculated_max_parallel_requests is None + + +@pytest.mark.parametrize( + "max_parallel_requests, tpm, rpm, default_max_parallel_requests", + [ + (mp, tp, rp, dmp) + for mp in max_parallel_requests_values + for tp in tpm_values + for rp in rpm_values + for dmp in default_max_parallel_requests + ], +) +def test_setting_mpr_limits_per_model( + max_parallel_requests, tpm, rpm, default_max_parallel_requests +): + deployment = { + "model_name": "gpt-3.5-turbo", + "litellm_params": { + "model": "gpt-3.5-turbo", + "max_parallel_requests": max_parallel_requests, + "tpm": tpm, + "rpm": rpm, + }, + "model_info": {"id": "my-unique-id"}, + } + + router = litellm.Router( + model_list=[deployment], + default_max_parallel_requests=default_max_parallel_requests, + ) + + mpr_client: Optional[asyncio.Semaphore] = router._get_client( + deployment=deployment, + kwargs={}, + client_type="max_parallel_requests", + ) + + if max_parallel_requests is not None: + assert max_parallel_requests == mpr_client._value + elif rpm is not None: + assert rpm == mpr_client._value + elif tpm is not None: + calculated_rpm = int(tpm / 1000 / 6) + if calculated_rpm == 0: + calculated_rpm = 1 + print( + f"test calculated_rpm: {calculated_rpm}, calculated_max_parallel_requests={mpr_client._value}" + ) + assert calculated_rpm == mpr_client._value + elif default_max_parallel_requests is not None: + assert mpr_client._value == default_max_parallel_requests + else: + assert mpr_client is None + + # raise Exception("it worked!") diff --git a/litellm/utils.py b/litellm/utils.py index 824957d3ea..836587fb1d 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -5434,6 +5434,49 @@ def get_optional_params( return optional_params +def calculate_max_parallel_requests( + max_parallel_requests: Optional[int], + rpm: Optional[int], + tpm: Optional[int], + default_max_parallel_requests: Optional[int], +) -> Optional[int]: + """ + Returns the max parallel requests to send to a deployment. + + Used in semaphore for async requests on router. + + Parameters: + - max_parallel_requests - Optional[int] - max_parallel_requests allowed for that deployment + - rpm - Optional[int] - requests per minute allowed for that deployment + - tpm - Optional[int] - tokens per minute allowed for that deployment + - default_max_parallel_requests - Optional[int] - default_max_parallel_requests allowed for any deployment + + Returns: + - int or None (if all params are None) + + Order: + max_parallel_requests > rpm > tpm / 6 (azure formula) > default max_parallel_requests + + Azure RPM formula: + 6 rpm per 1000 TPM + https://learn.microsoft.com/en-us/azure/ai-services/openai/quotas-limits + + + """ + if max_parallel_requests is not None: + return max_parallel_requests + elif rpm is not None: + return rpm + elif tpm is not None: + calculated_rpm = int(tpm / 1000 / 6) + if calculated_rpm == 0: + calculated_rpm = 1 + return calculated_rpm + elif default_max_parallel_requests is not None: + return default_max_parallel_requests + return None + + def get_api_base(model: str, optional_params: dict) -> Optional[str]: """ Returns the api base used for calling the model. diff --git a/proxy_server_config.yaml b/proxy_server_config.yaml index dcd5c68557..7c2d742672 100644 --- a/proxy_server_config.yaml +++ b/proxy_server_config.yaml @@ -96,9 +96,9 @@ litellm_settings: router_settings: routing_strategy: usage-based-routing-v2 - redis_host: os.environ/REDIS_HOST - redis_password: os.environ/REDIS_PASSWORD - redis_port: os.environ/REDIS_PORT + # redis_host: os.environ/REDIS_HOST + # redis_password: os.environ/REDIS_PASSWORD + # redis_port: os.environ/REDIS_PORT enable_pre_call_checks: true general_settings: diff --git a/pyproject.toml b/pyproject.toml index a5de973741..44b4f4808a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "1.35.17" +version = "1.35.18" 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.17" +version = "1.35.18" version_files = [ "pyproject.toml:^version" ] diff --git a/tests/test_keys.py b/tests/test_keys.py index 39787eb97f..f21c50c0dd 100644 --- a/tests/test_keys.py +++ b/tests/test_keys.py @@ -14,6 +14,24 @@ sys.path.insert( import litellm +async def generate_team(session): + url = "http://0.0.0.0:4000/team/new" + headers = {"Authorization": "Bearer sk-1234", "Content-Type": "application/json"} + data = { + "team_id": "litellm-dashboard", + } + + async with session.post(url, headers=headers, json=data) as response: + status = response.status + response_text = await response.text() + + print(f"Response (Status code: {status}):") + print(response_text) + print() + _json_response = await response.json() + return _json_response + + async def generate_user( session, user_role="app_owner", @@ -668,7 +686,7 @@ async def test_key_rate_limit(): @pytest.mark.asyncio -async def test_key_delete(): +async def test_key_delete_ui(): """ Admin UI flow - DO NOT DELETE -> Create a key with user_id = "ishaan" @@ -680,6 +698,8 @@ async def test_key_delete(): key = key_gen["key"] # generate a admin UI key + team = await generate_team(session=session) + print("generated team: ", team) admin_ui_key = await generate_user(session=session, user_role="proxy_admin") print( "trying to delete key=", diff --git a/tests/test_openai_endpoints.py b/tests/test_openai_endpoints.py index 465817d832..c77eeba5b0 100644 --- a/tests/test_openai_endpoints.py +++ b/tests/test_openai_endpoints.py @@ -260,7 +260,10 @@ async def test_chat_completion_ratelimit(): await asyncio.gather(*tasks) pytest.fail("Expected at least 1 call to fail") except Exception as e: - pass + if "Request did not return a 200 status code: 429" in str(e): + pass + else: + pytest.fail(f"Wrong error received - {str(e)}") @pytest.mark.asyncio diff --git a/ui/litellm-dashboard/out/404.html b/ui/litellm-dashboard/out/404.html index 3ace44f682..bb4c1890da 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/Oe7aA-U7OV9Y13gspREJQ/_buildManifest.js b/ui/litellm-dashboard/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_buildManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/Oe7aA-U7OV9Y13gspREJQ/_buildManifest.js rename to ui/litellm-dashboard/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_buildManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/Oe7aA-U7OV9Y13gspREJQ/_ssgManifest.js b/ui/litellm-dashboard/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_ssgManifest.js similarity index 100% rename from ui/litellm-dashboard/out/_next/static/Oe7aA-U7OV9Y13gspREJQ/_ssgManifest.js rename to ui/litellm-dashboard/out/_next/static/Vjlnu8AomhCFg4fkGtcUs/_ssgManifest.js diff --git a/ui/litellm-dashboard/out/_next/static/chunks/app/page-6ba29bc4256320f4.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-6ba29bc4256320f4.js new file mode 100644 index 0000000000..e765986ea2 --- /dev/null +++ b/ui/litellm-dashboard/out/_next/static/chunks/app/page-6ba29bc4256320f4.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,65249))},65249:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return ln}});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 text-2xl py-1 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:200,height:200,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}},y=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}},Z=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}},f=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=>{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}},b=async(e,l,t)=>{try{let l=await fetch("/model/metrics",{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}},k=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}},v=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}},S=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}},A=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}},N=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}},C=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}},P=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}},T=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}},E=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}},F=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}},M=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}},R=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,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}},L=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}},z=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}},B=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 on ").concat(l," dashboard!")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},q=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}},V=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}},K=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 G=t(10384),J=t(46453),W=t(2179),Y=t(26780),$=t(15595),H=t(6698),X=t(71801),Q=t(42440),ee=t(42308),el=t(50670),et=t(81583),es=t(99129),ea=t(44839),er=t(88707),en=t(1861);let{Option:eo}=el.default;var ei=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=et.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[y,Z]=(0,n.useState)([]),f=()=>{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 k(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),Z(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[a,l,s]);let _=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)(W.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(es.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:f,onCancel:w,children:(0,r.jsxs)(et.Z,{form:c,onFinish:_,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===s||"Admin"===s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.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)(ea.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e))]})}),(0,r.jsx)(et.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)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.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)(el.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(el.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(el.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(ea.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.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)(ea.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eo,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(eo,{value:e,children:e},e)):y.map(e=>(0,r.jsx)(eo,{value:e,children:e},e))]})}),(0,r.jsxs)(Y.Z,{className:"mt-8",children:[(0,r.jsx)(H.Z,{children:(0,r.jsx)("b",{children:"Optional Settings"})}),(0,r.jsxs)($.Z,{children:[(0,r.jsx)(et.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)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.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)(el.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(el.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(el.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.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)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(ea.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]})]})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(es.Z,{visible:d,onOk:f,onCancel:w,footer:null,children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(Q.Z,{children:"Save your Key"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(X.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)(ee.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(W.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(X.Z,{children:"Key being created, this might take 30s"})})]})})]})},ec=t(9454),ed=t(98941),em=t(33393),eh=t(5),eu=t(9853),ex=t(13810),ep=t(39290),ej=t(66952),eg=t(61244),ey=t(10827),eZ=t(3851),ef=t(2044),ew=t(64167),e_=t(74480),eb=t(7178),ek=t(95093),ev=t(27166);let{Option:eS}=el.default;var eA=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,Z]=n.useState(null),[f,w]=(0,n.useState)(null),[_,b]=(0,n.useState)(null),[S,A]=(0,n.useState)(""),[N,I]=(0,n.useState)(!1),[C,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),O=new Set,[F,M]=(0,n.useState)(O);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await k(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 U=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),I(!0)},D=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await R(s,e);console.log("handleEditSubmit: newKeyValues",t),o&&i(o.map(e=>e.token===l?t:e)),h.ZP.success("Key updated successfully"),I(!1),P(null)},L=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await v(s,e.token);console.log("Response:",l),b(l);try{let e=await z(s,l);console.log("Response2:",e);let t=[...l,...e.response];b(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)(()=>{L(f)},[f]);let B=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))},q=async()=>{if(null!=p&&null!=o){try{await y(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)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ey.Z,{className:"mt-5",children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Key Alias"}),(0,r.jsx)(e_.Z,{children:"Secret Key"}),(0,r.jsx)(e_.Z,{children:"Spend (USD)"}),(0,r.jsx)(e_.Z,{children:"Budget (USD)"}),(0,r.jsx)(e_.Z,{children:"Models"}),(0,r.jsx)(e_.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eZ.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(F.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||F.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)(eb.Z,{children:[(0,r.jsx)(ef.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(X.Z,{children:e.key_alias}):(0,r.jsx)(X.Z,{children:"Not Set"})}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:e.key_name})}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(ef.Z,{children:null!=e.max_budget?(0,r.jsx)(X.Z,{children:e.max_budget}):(0,r.jsx)(X.Z,{children:"Unlimited"})}),(0,r.jsx)(ef.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)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Team Models"})},l):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Team Models"})},l):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(ef.Z,{children:(0,r.jsxs)(X.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)(ef.Z,{children:[(0,r.jsx)(eg.Z,{onClick:()=>{w(e),Z(e.id)},icon:ec.Z,size:"sm"}),(0,r.jsx)(ep.Z,{open:null!==g,onClose:()=>{Z(null),w(null)},children:(0,r.jsx)(ej.Z,{children:f&&(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)(ex.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(f.spend).toFixed(4)}catch(e){return f.spend}})()})})]}),(0,r.jsxs)(ex.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!=f.max_budget?(0,r.jsx)(r.Fragment,{children:f.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(ex.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!=f.expires?(0,r.jsx)(r.Fragment,{children:new Date(f.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)(ex.Z,{className:"mt-6 mb-6",children:_&&(0,r.jsx)(eu.Z,{className:"mt-6",data:_,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(Q.Z,{children:"Metadata"}),(0,r.jsx)(X.Z,{children:JSON.stringify(f.metadata)}),(0,r.jsx)(W.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{Z(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(eg.Z,{icon:ed.Z,size:"sm",onClick:()=>U(e)}),(0,r.jsx)(eg.Z,{onClick:()=>B(e),icon:em.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)(W.Z,{onClick:q,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),C&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=et.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(es.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)(et.Z,{form:i,onFinish:D,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.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);return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t)):Promise.resolve()}}],children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(eS,{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)(eS,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(eS,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(eS,{value:e,children:e},e))]})}),(0,r.jsx)(et.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)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(et.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(ek.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(ev.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)(en.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{I(!1),P(null)},token:C,onSubmit:D})]})},eN=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a}=e;console.log("userSpend: ".concat(a));let[o,i]=(0,n.useState)(null!==a?a:0),[c,d]=(0,n.useState)(0);(0,n.useEffect)(()=>{(async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await w(s);e&&(e.spend?i(e.spend):i(0),e.max_budget?d(e.max_budget):d(0))}catch(e){console.error("Error fetching global spend data:",e)}})()},[t,s]),(0,n.useEffect)(()=>{null!==a&&i(a)},[a]);let m=void 0!==o?o.toFixed(4):null;return console.log("spend in view user spend: ".concat(o)),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend "}),(0,r.jsxs)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",m]})]})},eI=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],(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(Q.Z,{children:"Select Team"}),"App User"!==a&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(X.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)(X.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)(ek.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(ev.Z,{value:String(l),onClick:()=>s(e),children:e.team_alias},l))}):(0,r.jsxs)(X.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eC=t(37963),eP=t(36083);console.log("isLocal:",!1);var eT=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,y]=(0,n.useState)(null),[Z,_]=(0,n.useState)(null),[b,v]=(0,n.useState)([]),[S,A]=(0,n.useState)(s?s[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eC.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),y(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?v(JSON.parse(e)):(async()=>{try{let e=await f(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 w(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams),A(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let s=(await k(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",s),v(s),console.log("userModels:",b),sessionStorage.setItem("userModels"+l,JSON.stringify(s))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=S){let e=0;for(let l of a)S.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===S.team_id&&(e+=l.spend);_(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;_(e)}},[S]),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}=eP.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",S),console.log("teamSpend: ".concat(Z)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(eN,{userID:l,userRole:t,accessToken:g,userSpend:Z}),(0,r.jsx)(eA,{userID:l,userRole:t,accessToken:g,selectedTeam:S||null,data:a,setData:h,teams:s}),(0,r.jsx)(ei,{userID:l,team:S||null,userRole:t,accessToken:g,data:a,setData:h},S?S.team_id:null),(0,r.jsx)(eI,{teams:s,setSelectedTeam:A,userRole:t})]})})})},eE=t(92836),eO=t(26734),eF=t(41608),eM=t(32126),eR=t(23682),eU=t(52273),eD=t(47047),eL=t(76628),ez=t(38302),eB=t(28683),eq=t(1460),eV=t(78578),eK=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)(eg.Z,{onClick:()=>a(!0),icon:em.Z,size:"sm"}),(0,r.jsx)(es.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(Q.Z,{children:"Delete Model"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eG=t(97766),eJ=t(46495);let{Title:eW,Link:eY}=eP.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 e$={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"};var eH=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d}=e,[m,p]=(0,n.useState)({data:[]}),[j,g]=(0,n.useState)([]),[y]=et.Z.useForm(),[Z,f]=(0,n.useState)(null),[w,b]=(0,n.useState)([]),k=Object.values(a).filter(e=>isNaN(Number(e))),[v,S]=(0,n.useState)("OpenAI"),[A,N]=(0,n.useState)("");if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await _(o,d,c);if(console.log("Model data response:",e.data),p(e),"Admin"===c&&o){let e=await O(o);console.log("Pending Requests:",j),g(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};o&&i&&c&&d&&e();let l=async()=>{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==Z&&l()},[o,i,c,d,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let I=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(Z)),null!=Z&&"object"==typeof Z&&e in Z)?Z[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,I.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eP.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 C=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=e$[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof Z&&Object.entries(Z).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)}),b(t),console.log("providerModels: ".concat(w))}},P=async()=>{try{h.ZP.info("Running health check..."),N("");let e=await K(o);N(e)}catch(e){console.error("Error running health check:",e),N("Error running health check")}},T=async e=>{try{let l=Object.values(e.model);console.log("received deployments: ".concat(l)),console.log("received type of deployments: ".concat(typeof l)),l.forEach(async l=>{console.log("litellm_model: ".concat(l));let t={},s={};t.model=l;let a="";for(let[l,r]of Object.entries(e))if("model_name"==l)a+=r;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)s[l]=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else t[l]=r;let r={model_name:a,litellm_params:t,model_info:s},n=await x(o,r);console.log("response for model create call: ".concat(n.data))}),y.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};return console.log("selectedProvider: ".concat(v)),console.log("providerModels.length: ".concat(w.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eO.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Models"}),(0,r.jsx)(eE.Z,{children:"Add Model"}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(J.Z,{children:(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(ey.Z,{className:"mt-5",children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Model Name "}),(0,r.jsx)(e_.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(e_.Z,{children:"API Base"}),(0,r.jsx)(e_.Z,{children:"Extra litellm Params"}),(0,r.jsx)(e_.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(e_.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(e_.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(eZ.Z,{children:m.data.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:e.model_name})}),(0,r.jsx)(ef.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(ef.Z,{children:e.api_base}),(0,r.jsx)(ef.Z,{children:(0,r.jsxs)(Y.Z,{children:[(0,r.jsx)(H.Z,{children:(0,r.jsx)(X.Z,{children:"Litellm params"})}),(0,r.jsx)($.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(ef.Z,{children:e.input_cost}),(0,r.jsx)(ef.Z,{children:e.output_cost}),(0,r.jsx)(ef.Z,{children:e.max_tokens}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eK,{modelID:e.model_info.id,accessToken:o})})]},l))})]})})})}),(0,r.jsxs)(eM.Z,{className:"h-full",children:[(0,r.jsx)(eW,{level:2,children:"Add new model"}),(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(et.Z,{form:y,onFinish:()=>{y.validateFields().then(e=>{T(e)}).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)(et.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)(ek.Z,{value:v.toString(),children:k.map((e,l)=>(0,r.jsx)(ev.Z,{value:e,onClick:()=>{C(e),S(e)},children:e},l))})}),(0,r.jsx)(et.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)(eU.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=v.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)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(X.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(et.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"===v?(0,r.jsx)(eU.Z,{placeholder:"Enter model name"}):w.length>0?(0,r.jsx)(eD.Z,{value:w,children:w.map((e,l)=>(0,r.jsx)(eL.Z,{value:e,children:e},l))}):(0,r.jsx)(eU.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(X.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(eY,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(eY,{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"!=v&&"Vertex AI (Anthropic, Gemini, etc.)"!=v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)(eU.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==v&&(0,r.jsx)(et.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)(eU.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(eU.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(eU.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eJ.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;y.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)(en.ZP,{icon:(0,r.jsx)(eG.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(X.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==v||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==v)&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(eU.Z,{placeholder:"https://..."})}),"Azure"==v&&(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)(eU.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==v&&(0,r.jsxs)(et.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)(eU.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(X.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(eY,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==v&&(0,r.jsx)(et.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)(eU.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(et.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)(eU.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(et.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)(eU.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(et.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)(eV.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(X.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(eY,{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)(en.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eq.Z,{title:"Get help on our github",children:(0,r.jsx)(eP.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(X.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(W.Z,{onClick:P,children:"Run `/health`"}),A&&(0,r.jsx)("pre",{children:JSON.stringify(A,null,2)})]})})]})]})})};let{Option:eX}=el.default;var eQ=e=>{let{userID:l,accessToken:t,teams:s}=e,[a]=et.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 k(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)(W.Z,{className:"mx-auto",onClick:()=>i(!0),children:"+ Invite User"}),(0,r.jsxs)(es.Z,{title:"Invite User",visible:o,width:800,footer:null,onOk:x,onCancel:p,children:[(0,r.jsx)(X.Z,{className:"mb-1",children:"Invite a user to login to the Admin UI and create Keys"}),(0,r.jsx)(X.Z,{className:"mb-6",children:(0,r.jsx)("b",{children:"Note: SSO Setup Required for this"})}),(0,r.jsxs)(et.Z,{form:a,onFinish:j,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(et.Z.Item,{label:"User Email",name:"user_email",children:(0,r.jsx)(ea.Z,{placeholder:"Enter User Email"})}),(0,r.jsx)(et.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(el.default,{placeholder:"Select Team ID",style:{width:"100%"},children:s?s.map(e=>(0,r.jsx)(eX,{value:e.team_id,children:e.team_alias},e.team_id)):(0,r.jsx)(eX,{value:null,children:"Default Team"},"default")})}),(0,r.jsx)(et.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(ea.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Create User"})})]})]}),c&&(0,r.jsxs)(es.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"})})]})]})},e0=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),[y,Z]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await f(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 P(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 P(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)(J.Z,{className:"gap-2 p-2 h-[75vh] w-full mt-8",children:[(0,r.jsx)(eQ,{userID:o,accessToken:l,teams:i}),(0,r.jsx)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eE.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(ey.Z,{className:"mt-5",children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"User ID"}),(0,r.jsx)(e_.Z,{children:"User Email"}),(0,r.jsx)(e_.Z,{children:"User Models"}),(0,r.jsx)(e_.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(e_.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(e_.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(eZ.Z,{children:d.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.user_id}),(0,r.jsx)(ef.Z,{children:e.user_email}),(0,r.jsx)(ef.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(ef.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(ef.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(J.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(eh.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(eh.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eM.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)(X.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(ek.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_name&&e.key_name.length>0)return(0,r.jsx)(ev.Z,{value:String(l),onClick:()=>w(e.token),children:e.key_name},l)})})]})]}),(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"End User"}),(0,r.jsx)(e_.Z,{children:"Spend"}),(0,r.jsx)(e_.Z,{children:"Total Events"})]})}),(0,r.jsx)(eZ.Z,{children:null==h?void 0:h.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.end_user}),(0,r.jsx)(ef.Z,{children:e.total_spend}),(0,r.jsx)(ef.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 →"})]})]})}()]})})},e1=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=et.Z.useForm(),[d]=et.Z.useForm(),{Title:m,Paragraph:u}=eP.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[y,f]=(0,n.useState)(l?l[0]:null),[w,_]=(0,n.useState)(!1),[b,v]=(0,n.useState)(!1),[S,A]=(0,n.useState)([]),[N,I]=(0,n.useState)(!1),[C,P]=(0,n.useState)(null),T=e=>{f(e),g(!0)},E=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),f(null)},O=async e=>{P(e),I(!0)},F=async()=>{if(null!=C&&null!=l&&null!=s){try{await Z(s,C);let e=l.filter(e=>e.team_id!==C);a(e)}catch(e){console.error("Error deleting the team:",e)}I(!1),P(null)}};(0,n.useEffect)(()=>{(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await k(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),A(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,o,i]);let R=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await M(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)}},L=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 D(s,y.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),f(r.data)}v(!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)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Team Name"}),(0,r.jsx)(e_.Z,{children:"Spend (USD)"}),(0,r.jsx)(e_.Z,{children:"Budget (USD)"}),(0,r.jsx)(e_.Z,{children:"Models"}),(0,r.jsx)(e_.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(eZ.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(ef.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)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(X.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(eh.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(X.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(ef.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(X.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)(ef.Z,{children:[(0,r.jsx)(eg.Z,{icon:ed.Z,size:"sm",onClick:()=>T(e)}),(0,r.jsx)(eg.Z,{onClick:()=>O(e.team_id),icon:em.Z,size:"sm"})]})]},e.team_id)):null})]}),N&&(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)(W.Z,{onClick:F,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{I(!1),P(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto",onClick:()=>_(!0),children:"+ Create New Team"}),(0,r.jsx)(es.Z,{title:"Create Team",visible:w,width:800,footer:null,onOk:()=>{_(!1),c.resetFields()},onCancel:()=>{_(!1),c.resetFields()},children:(0,r.jsxs)(et.Z,{form:c,onFinish:R,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(el.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S.map(e=>(0,r.jsx)(el.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(et.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(G.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)(ek.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(ev.Z,{value:String(l),onClick:()=>{f(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)(G.Z,{numColSpan:1,children:[(0,r.jsx)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Member Name"}),(0,r.jsx)(e_.Z,{children:"Role"})]})}),(0,r.jsx)(eZ.Z,{children:y?y.members_with_roles.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(ef.Z,{children:e.role})]},l)):null})]})}),y&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=et.Z.useForm();return(0,r.jsx)(es.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)(et.Z,{form:n,onFinish:E,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(el.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(el.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S&&S.map(e=>(0,r.jsx)(el.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(et.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(er.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(et.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(er.Z,{step:1,width:400})}),(0,r.jsx)(et.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)(en.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),f(null)},team:y,onSubmit:E})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto mb-5",onClick:()=>v(!0),children:"+ Add member"}),(0,r.jsx)(es.Z,{title:"Add member",visible:b,width:800,footer:null,onOk:()=>{v(!1),d.resetFields()},onCancel:()=>{v(!1),d.resetFields()},children:(0,r.jsxs)(et.Z,{form:c,onFinish:L,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(ea.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)(et.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(ea.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)(en.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e2=t(18190),e4=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=et.Z.useForm(),[i]=et.Z.useForm(),{Title:c,Paragraph:d}=eP.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[y,Z]=(0,n.useState)(!1),[f,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 F(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 F(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()},I=()=>{w(!1),i.resetFields()},C=e=>(0,r.jsxs)(et.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(ea.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)(et.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(ea.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)(en.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(et.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(ek.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(ev.Z,{value:e,children:e},l))})}),(0,r.jsx)(et.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(ea.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await L(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 L(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)}},O=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await L(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)),Z(!1)}}catch(e){console.error("Error creating the key:",e)}},M=async e=>{null!=s&&V(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)(J.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsx)(ex.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Member Name"}),(0,r.jsx)(e_.Z,{children:"Role"})]})}),(0,r.jsx)(eZ.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(ef.Z,{children:e.user_role}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{icon:ed.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(es.Z,{title:"Update role",visible:f,width:800,footer:null,onOk:N,onCancel:I,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(W.Z,{className:"mr-4 mb-5",onClick:()=>Z(!0),children:"+ Add admin"}),(0,r.jsx)(es.Z,{title:"Add admin",visible:y,width:800,footer:null,onOk:()=>{Z(!1),i.resetFields()},onCancel:()=>{Z(!1),i.resetFields()},children:C(O)}),(0,r.jsx)(W.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(es.Z,{title:"Add viewer",visible:j,width:800,footer:null,onOk:()=>{g(!1),i.resetFields()},onCancel:()=>{g(!1),i.resetFields()},children:C(E)})]})})]}),(0,r.jsxs)(J.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)(W.Z,{onClick:()=>b(!0),children:"Add SSO"}),(0,r.jsx)(es.Z,{title:"Add SSO",visible:_,width:800,footer:null,onOk:()=>{b(!1),o.resetFields()},onCancel:()=>{b(!1),o.resetFields()},children:(0,r.jsxs)(et.Z,{form:o,onFinish:e=>{O(e),M(e),b(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)(et.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(ea.Z.Password,{})}),(0,r.jsx)(et.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(ea.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(es.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)(X.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(X.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(X.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(X.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)(en.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e2.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})," "]})]})]})]})},e8=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)(!1),[d]=et.Z.useForm(),[m,u]=(0,n.useState)(null),[x,p]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.data)})},[l,t,s]);let j=e=>{p(e),console.log("Selected values:",e)},g=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",x);try{V(l,{environment_variables:t,general_settings:{alert_types:x}})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},y=()=>{l&&d.validateFields().then(e=>{console.log("Form values:",e),"langfuse"===e.callback?(V(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}}),o(a?[...a,e.callback]:[e.callback])):"slack"===e.callback&&(V(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),o(a?[...a,e.callback]:[e.callback])),c(!1),d.resetFields(),u(null)})};return l?(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(Q.Z,{children:"Logging Callbacks"}),(0,r.jsxs)(ex.Z,{children:[(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Callback"}),(0,r.jsx)(e_.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(eZ.Z,{children:a.map((e,t)=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eh.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(e.variables).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(X.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)(eU.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),e.all_alert_types&&(0,r.jsxs)("div",{children:[(0,r.jsx)(X.Z,{className:"mt-2",children:"Alerting Types"}),(0,r.jsx)(el.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select Alerting Types",optionLabelProp:"label",onChange:j,defaultValue:e.alerting_types,children:e.all_alert_types.map(e=>(0,r.jsx)(el.default.Option,{value:e,label:e,children:e},e))})]}),(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>g(e),children:"Save Changes"}),(0,r.jsx)(W.Z,{onClick:()=>B(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t))})]}),(0,r.jsx)(W.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),c(!0)},children:"Add Callback"})]})]}),(0,r.jsx)(es.Z,{title:"Add Callback",visible:i,onOk:y,width:800,onCancel:()=>{c(!1),d.resetFields(),u(null)},footer:null,children:(0,r.jsxs)(et.Z,{form:d,layout:"vertical",onFinish:y,children:[(0,r.jsx)(et.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsxs)(el.default,{onChange:e=>{u(e)},children:[(0,r.jsx)(el.default.Option,{value:"langfuse",children:"langfuse"}),(0,r.jsx)(el.default.Option,{value:"slack",children:"slack alerting"})]})}),"langfuse"===m&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(et.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)(ea.Z.Password,{})}),(0,r.jsx)(et.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)(ea.Z.Password,{})})]}),"slack"===m&&(0,r.jsx)(et.Z.Item,{label:"SLACK_WEBHOOK_URL",name:"slackWebhookUrl",rules:[{required:!0,message:"Please enter the Slack webhook URL"}],children:(0,r.jsx)(ea.Z,{})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(en.ZP,{htmlType:"submit",children:"Save"})})]})})]}):null},e3=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)({}),[i,c]=(0,n.useState)(!1),[d]=et.Z.useForm(),[m,u]=(0,n.useState)(null);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.router_settings)})},[l,t,s]);let x=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).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);try{V(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)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(Q.Z,{children:"Router Settings"}),(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Setting"}),(0,r.jsx)(e_.Z,{children:"Value"})]})}),(0,r.jsx)(eZ.Z,{children:Object.entries(a).map(e=>{let[l,t]=e;return(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:(0,r.jsx)(X.Z,{children:l})}),(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eU.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(G.Z,{children:(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>x(a),children:"Save Changes"})})]})}):null},e5=t(12968),e6=t(67951);async function e7(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new e5.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 e9=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 k(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}]})},y=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await e7(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}=eP.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(J.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(ex.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"Chat"}),(0,r.jsx)(eE.Z,{children:"API Reference"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(J.Z,{numItems:2,children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)(X.Z,{children:"API Key"}),(0,r.jsx)(eU.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(G.Z,{className:"mx-2",children:[(0,r.jsx)(X.Z,{children:"Select Model:"}),(0,r.jsx)(el.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ey.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ew.Z,{children:(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ef.Z,{})})}),(0,r.jsx)(eZ.Z,{children:m.map((e,l)=>(0,r.jsx)(eb.Z,{children:(0,r.jsx)(ef.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)(eU.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(W.Z,{onClick:y,className:"ml-2",children:"Send"})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eE.Z,{children:"LlamaIndex"}),(0,r.jsx)(eE.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # proxy base url\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to use from Models Tab\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ],\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-openai-client",\n "generation_id": "openai-client-gen-id22",\n "trace_id": "openai-client-trace-id22",\n "trace_user_id": "openai-client-user-id2"\n }\n }\n)\n\nprint(response)\n '})}),(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.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)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="http://0.0.0.0:8000",\n model = "gpt-3.5-turbo",\n temperature=0.1,\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-langchain-client",\n "generation_id": "langchain-client-gen-id22",\n "trace_id": "langchain-client-trace-id22",\n "trace_user_id": "langchain-client-user-id2"\n }\n }\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})})]})]})})})})},le=t(33509),ll=t(95781);let{Sider:lt}=le.default;var ls=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(X.Z,{children:"API Keys"})},"1"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(X.Z,{children:"Test Key"})},"3"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(X.Z,{children:"Models"})},"2"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(X.Z,{children:"Teams"})},"6"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(X.Z,{children:"Usage"})},"4"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(X.Z,{children:"Users"})},"5"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(X.Z,{children:"Integrations"})},"8"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(X.Z,{children:"Settings"})},"9"):null,"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(X.Z,{children:"Admin"})},"7"):null]})})})},la=t(67989),lr=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)([]),[y,Z]=(0,n.useState)([]),[f,w]=(0,n.useState)([]),[_,k]=(0,n.useState)([]),[v,P]=(0,n.useState)([]),[O,F]=(0,n.useState)([]),M=new Date(o.getFullYear(),o.getMonth(),1),R=new Date(o.getFullYear(),o.getMonth()+1,0),U=L(M),D=L(R);function L(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)}return console.log("Start date is ".concat(U)),console.log("End date is ".concat(D)),(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 C(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let s=(await T(l)).map(e=>({key:e.model,spend:e.total_spend}));u(s);let a=await S(l);console.log("teamSpend",a),g(a.daily_spend),w(a.teams);let r=a.total_spend_per_team;r=r.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),k(r);let n=await A(l);Z(n.top_10_tags)}else"App Owner"==s&&await N(l,t,s,a,U,D).then(async 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 E(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 b(l,a,s);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),P(e),F(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,U,D]),(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(eN,{userID:a,userRole:s,accessToken:l,userSpend:null}),(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Up"}),(0,r.jsx)(eE.Z,{children:"Team Based Usage"}),(0,r.jsx)(eE.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eE.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Monthly Spend"}),(0,r.jsx)(eu.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Top API Keys"}),(0,r.jsx)(eu.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Top Users"}),(0,r.jsx)(eu.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Top Models"}),(0,r.jsx)(eu.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)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(G.Z,{numColSpan:2,children:[(0,r.jsxs)(ex.Z,{className:"mb-2",children:[(0,r.jsx)(Q.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(la.Z,{data:_})]}),(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(eu.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:f,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(X.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)(ey.Z,{children:[(0,r.jsx)(ew.Z,{children:(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(e_.Z,{children:"Tag"}),(0,r.jsx)(e_.Z,{children:"Spend"}),(0,r.jsx)(e_.Z,{children:"Requests"})]})}),(0,r.jsx)(eZ.Z,{children:y.map(e=>(0,r.jsxs)(eb.Z,{children:[(0,r.jsx)(ef.Z,{children:e.name}),(0,r.jsx)(ef.Z,{children:e.value}),(0,r.jsx)(ef.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(ex.Z,{children:[(0,r.jsx)(Q.Z,{children:"Number Requests per Model"}),(0,r.jsx)(eu.Z,{data:v,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(ex.Z,{className:"mt-4",children:[(0,r.jsx)(Q.Z,{children:"Latency Per Model"}),(0,r.jsx)(eu.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},ln=()=>{let{Title:e,Paragraph:l}=eP.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=j.get("userID"),y=j.get("token"),[Z,f]=(0,n.useState)("api-keys"),[w,_]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(y){let e=(0,eC.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),_(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&&f("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?p("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[y]),(0,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:g,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)(ls,{setPage:f,userRole:t,defaultSelectedKey:null})}),"api-keys"==Z?(0,r.jsx)(eT,{userID:g,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==Z?(0,r.jsx)(eH,{userID:g,userRole:t,token:y,accessToken:w}):"llm-playground"==Z?(0,r.jsx)(e9,{userID:g,userRole:t,token:y,accessToken:w}):"users"==Z?(0,r.jsx)(e0,{userID:g,userRole:t,token:y,keys:h,teams:c,accessToken:w,setKeys:u}):"teams"==Z?(0,r.jsx)(e1,{teams:c,setTeams:d,searchParams:j,accessToken:w,userID:g,userRole:t}):"admin-panel"==Z?(0,r.jsx)(e4,{setTeams:d,searchParams:j,accessToken:w,showSSOBanner:x}):"settings"==Z?(0,r.jsx)(e8,{userID:g,userRole:t,accessToken:w}):"general-settings"==Z?(0,r.jsx)(e3,{userID:g,userRole:t,accessToken:w}):(0,r.jsx)(lr,{userID:g,userRole:t,token:y,accessToken:w})]})]})})}}},function(e){e.O(0,[968,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-93ac11fb17dce9d6.js b/ui/litellm-dashboard/out/_next/static/chunks/app/page-93ac11fb17dce9d6.js deleted file mode 100644 index 696bbfce8d..0000000000 --- a/ui/litellm-dashboard/out/_next/static/chunks/app/page-93ac11fb17dce9d6.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,16586))},16586:function(e,l,t){"use strict";t.r(l),t.d(l,{default:function(){return ln}});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 text-2xl py-1 rounded text-center",children:(0,r.jsx)("img",{src:"/get_image",width:200,height:200,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}},y=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}},Z=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}},f=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)),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=>{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}},b=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}},_=async(e,l,t)=>{try{let l=await fetch("/model/metrics",{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}},k=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}},v=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}},S=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}},A=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}},N=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}},C=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}},I=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}},P=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}},T=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}},E=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}},F=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}},M=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}},R=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}},D=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}},L=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}},U=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}},z=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}},B=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 on ").concat(l," dashboard!")),a}catch(e){throw console.error("Failed to perform health check:",e),e}},q=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}},V=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}},K=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 G=t(10384),J=t(46453),W=t(2179),Y=t(71801),H=t(42440),$=t(42308),X=t(50670),Q=t(81583),ee=t(99129),el=t(44839),et=t(88707),es=t(1861);let{Option:ea}=X.default;var er=e=>{let{userID:l,team:t,userRole:s,accessToken:a,data:o,setData:i}=e,[c]=Q.Z.useForm(),[d,m]=(0,n.useState)(!1),[u,x]=(0,n.useState)(null),[p,g]=(0,n.useState)(null),[y,Z]=(0,n.useState)([]),f=()=>{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 k(a,l,s)).data.map(e=>e.id);console.log("available_model_names:",e),Z(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)(W.Z,{className:"mx-auto",onClick:()=>m(!0),children:"+ Create New Key"}),(0,r.jsx)(ee.Z,{title:"Create Key",visible:d,width:800,footer:null,onOk:f,onCancel:w,children:(0,r.jsxs)(Q.Z,{form:c,onFinish:b,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:["App Owner"===s||"Admin"===s?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.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)(el.Z,{value:t?t.team_alias:"",disabled:!0})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",rules:[{required:!0,message:"Please select a model"}],help:"required",children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(ea,{value:"all-team-models",children:"All Team Models"},"all-team-models"),t&&t.models?t.models.includes("all-proxy-models")?y.map(e=>(0,r.jsx)(ea,{value:e,children:e},e)):t.models.map(e=>(0,r.jsx)(ea,{value:e,children:e},e)):y.map(e=>(0,r.jsx)(ea,{value:e,children:e},e))]})}),(0,r.jsx)(Q.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)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.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)(X.default,{defaultValue:null,placeholder:"n/a",children:[(0,r.jsx)(X.default.Option,{value:"24h",children:"daily"}),(0,r.jsx)(X.default.Option,{value:"30d",children:"monthly"})]})}),(0,r.jsx)(Q.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)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.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)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Expire Key (eg: 30s, 30h, 30d)",name:"duration",className:"mt-8",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(el.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Key Name",name:"key_alias",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Team ID (Contact Group)",name:"team_id",children:(0,r.jsx)(el.Z,{placeholder:"default team (create a new team)"})}),(0,r.jsx)(Q.Z.Item,{label:"Description",name:"description",children:(0,r.jsx)(el.Z.TextArea,{placeholder:"Enter description",rows:4})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Create Key"})})]})}),u&&(0,r.jsx)(ee.Z,{visible:d,onOk:f,onCancel:w,footer:null,children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(H.Z,{children:"Save your Key"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:null!=u?(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.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)($.CopyToClipboard,{text:u,onCopy:()=>{h.ZP.success("API Key copied to clipboard")},children:(0,r.jsx)(W.Z,{className:"mt-3",children:"Copy API Key"})})]}):(0,r.jsx)(Y.Z,{children:"Key being created, this might take 30s"})})]})})]})},en=t(9454),eo=t(98941),ei=t(33393),ec=t(5),ed=t(9853),em=t(13810),eh=t(39290),eu=t(66952),ex=t(61244),ep=t(10827),ej=t(3851),eg=t(2044),ey=t(64167),eZ=t(74480),ef=t(7178),ew=t(95093),eb=t(27166);let{Option:e_}=X.default;var ek=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,Z]=n.useState(null),[f,w]=(0,n.useState)(null),[b,_]=(0,n.useState)(null),[S,A]=(0,n.useState)(""),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),[T,E]=(0,n.useState)([]),O=new Set,[F,M]=(0,n.useState)(O);(0,n.useEffect)(()=>{(async()=>{try{if(null===l)return;if(null!==s&&null!==t){let e=(await k(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 D=e=>{console.log("handleEditClick:",e),null==e.token&&null!==e.token_id&&(e.token=e.token_id),P(e),C(!0)},L=async e=>{if(null==s)return;let l=e.token;e.key=l,console.log("handleEditSubmit:",e);let t=await R(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)},U=async e=>{try{if(null==s||null==e)return;console.log("accessToken: ".concat(s,"; token: ").concat(e.token));let l=await v(s,e.token);console.log("Response:",l),_(l);try{let e=await z(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)(()=>{U(f)},[f]);let B=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))},q=async()=>{if(null!=p&&null!=o){try{await y(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)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4 mt-2",children:[(0,r.jsxs)(ep.Z,{className:"mt-5",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Key Alias"}),(0,r.jsx)(eZ.Z,{children:"Secret Key"}),(0,r.jsx)(eZ.Z,{children:"Spend (USD)"}),(0,r.jsx)(eZ.Z,{children:"Budget (USD)"}),(0,r.jsx)(eZ.Z,{children:"Models"}),(0,r.jsx)(eZ.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(ej.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(F.has(e.team_id),", selectedTeam id: ").concat(a.team_id)),(null!=a.team_id||null===e.team_id||F.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)(ef.Z,{children:[(0,r.jsx)(eg.Z,{style:{maxWidth:"2px",whiteSpace:"pre-wrap",overflow:"hidden"},children:null!=e.key_alias?(0,r.jsx)(Y.Z,{children:e.key_alias}):(0,r.jsx)(Y.Z,{children:"Not Set"})}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:e.key_name})}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:(()=>{try{return parseFloat(e.spend).toFixed(4)}catch(l){return e.spend}})()})}),(0,r.jsx)(eg.Z,{children:null!=e.max_budget?(0,r.jsx)(Y.Z,{children:e.max_budget}):(0,r.jsx)(Y.Z,{children:"Unlimited"})}),(0,r.jsx)(eg.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)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Team Models"})},l):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l)):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:"all-proxy-models"})})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})},l):"all-team-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Team Models"})},l):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(Y.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)(eg.Z,{children:[(0,r.jsx)(ex.Z,{onClick:()=>{w(e),Z(e.id)},icon:en.Z,size:"sm"}),(0,r.jsx)(eh.Z,{open:null!==g,onClose:()=>{Z(null),w(null)},children:(0,r.jsx)(eu.Z,{children:f&&(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)(em.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(f.spend).toFixed(4)}catch(e){return f.spend}})()})})]}),(0,r.jsxs)(em.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!=f.max_budget?(0,r.jsx)(r.Fragment,{children:f.max_budget}):(0,r.jsx)(r.Fragment,{children:"Unlimited"})})})]},e.name),(0,r.jsxs)(em.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!=f.expires?(0,r.jsx)(r.Fragment,{children:new Date(f.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)(em.Z,{className:"mt-6 mb-6",children:b&&(0,r.jsx)(ed.Z,{className:"mt-6",data:b,colors:["blue","amber"],index:"date",categories:["spend","predicted_spend"],yAxisWidth:80})}),(0,r.jsx)(H.Z,{children:"Metadata"}),(0,r.jsx)(Y.Z,{children:JSON.stringify(f.metadata)}),(0,r.jsx)(W.Z,{variant:"light",className:"mx-auto flex items-center",onClick:()=>{Z(null),w(null)},children:"Close"})]})})}),(0,r.jsx)(ex.Z,{icon:eo.Z,size:"sm",onClick:()=>D(e)}),(0,r.jsx)(ex.Z,{onClick:()=>B(e),icon:ei.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)(W.Z,{onClick:q,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{x(!1),j(null)},children:"Cancel"})]})]})]})})]}),I&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,token:s,onSubmit:o}=e,[i]=Q.Z.useForm(),[d,m]=(0,n.useState)(a),[h,u]=(0,n.useState)([]),[x,p]=(0,n.useState)(!1);return(0,r.jsx)(ee.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)(Q.Z,{form:i,onFinish:L,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Key Name",name:"key_alias",rules:[{required:!0,message:"Please input a key name"}],help:"required",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.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);return(console.log("errorModels: ".concat(t)),t.length>0)?Promise.reject("Some models are not part of the new team's models - ".concat(t)):Promise.resolve()}}],children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(e_,{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)(e_,{value:e,children:e},e)):d.models.map(e=>(0,r.jsx)(e_,{value:e,children:e},e)):T.map(e=>(0,r.jsx)(e_,{value:e,children:e},e))]})}),(0,r.jsx)(Q.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)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"token",name:"token",hidden:!0}),(0,r.jsx)(Q.Z.Item,{label:"Team",name:"team_id",help:"the team this key belongs to",children:(0,r.jsx)(ew.Z,{value:s.team_alias,children:null==c?void 0:c.map((e,l)=>(0,r.jsx)(eb.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)(es.ZP,{htmlType:"submit",children:"Edit Key"})})]})})},{visible:N,onCancel:()=>{C(!1),P(null)},token:I,onSubmit:L})]})},ev=e=>{let{userID:l,userRole:t,accessToken:s,userSpend:a}=e;console.log("userSpend: ".concat(a));let[o,i]=(0,n.useState)(null!==a?a:0),[c,d]=(0,n.useState)(0);(0,n.useEffect)(()=>{(async()=>{if(s&&l&&t&&"Admin"===t&&null==a)try{let e=await w(s);e&&(e.spend?i(e.spend):i(0),e.max_budget?d(e.max_budget):d(0))}catch(e){console.error("Error fetching global spend data:",e)}})()},[t,s]),(0,n.useEffect)(()=>{null!==a&&i(a)},[a]);let m=void 0!==o?o.toFixed(4):null;return console.log("spend in view user spend: ".concat(o)),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-tremor-default text-tremor-content dark:text-dark-tremor-content",children:"Total Spend "}),(0,r.jsxs)("p",{className:"text-3xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold",children:["$",m]})]})},eS=e=>{let{teams:l,setSelectedTeam:t}=e,s={models:[],team_id:null,team_alias:"Default Team"},[a,o]=(0,n.useState)(s),i=l?[...l,s]:[s];return(0,r.jsxs)("div",{className:"mt-5 mb-5",children:[(0,r.jsx)(H.Z,{children:"Select Team"}),(0,r.jsx)(Y.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)(Y.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."]}),i&&i.length>0?(0,r.jsx)(ew.Z,{defaultValue:"0",children:i.map((e,l)=>(0,r.jsx)(eb.Z,{value:String(l),onClick:()=>t(e),children:e.team_alias},l))}):(0,r.jsxs)(Y.Z,{children:["No team created. ",(0,r.jsx)("b",{children:"Defaulting to personal account."})]})]})},eA=t(37963),eN=t(36083);console.log("isLocal:",!1);var eC=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,y]=(0,n.useState)(null),[Z,b]=(0,n.useState)(null),[_,v]=(0,n.useState)([]),[S,A]=(0,n.useState)(s?s[0]:null);if(window.addEventListener("beforeunload",function(){sessionStorage.clear()}),(0,n.useEffect)(()=>{if(j){let e=(0,eA.o)(j);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),y(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?v(JSON.parse(e)):(async()=>{try{let e=await f(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 w(g);x(e),console.log("globalSpend:",e)}else x(e.user_info);h(e.keys),m(e.teams),A(e.teams?e.teams[0]:null),sessionStorage.setItem("userData"+l,JSON.stringify(e.keys)),sessionStorage.setItem("userSpendData"+l,JSON.stringify(e.user_info));let s=(await k(g,l,t)).data.map(e=>e.id);console.log("available_model_names:",s),v(s),console.log("userModels:",_),sessionStorage.setItem("userModels"+l,JSON.stringify(s))}catch(e){console.error("There was an error fetching the data",e)}})()}},[l,j,g,a,t]),(0,n.useEffect)(()=>{if(null!==a&&null!=S){let e=0;for(let l of a)S.hasOwnProperty("team_id")&&null!==l.team_id&&l.team_id===S.team_id&&(e+=l.spend);b(e)}else if(null!==a){let e=0;for(let l of a)e+=l.spend;b(e)}},[S]),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}=eN.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",S),console.log("teamSpend: ".concat(Z)),(0,r.jsx)("div",{className:"w-full mx-4",children:(0,r.jsx)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(ev,{userID:l,userRole:t,accessToken:g,userSpend:Z}),(0,r.jsx)(ek,{userID:l,userRole:t,accessToken:g,selectedTeam:S||null,data:a,setData:h,teams:s}),(0,r.jsx)(er,{userID:l,team:S||null,userRole:t,accessToken:g,data:a,setData:h},S?S.team_id:null),(0,r.jsx)(eS,{teams:s,setSelectedTeam:A})]})})})},eI=t(26780),eP=t(15595),eT=t(6698),eE=t(92836),eO=t(26734),eF=t(41608),eM=t(32126),eR=t(23682),eD=t(52273),eL=t(47047),eU=t(76628),ez=t(38302),eB=t(28683),eq=t(1460),eV=t(78578),eK=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)(ex.Z,{onClick:()=>a(!0),icon:ei.Z,size:"sm"}),(0,r.jsx)(ee.Z,{open:s,onOk:o,okType:"danger",onCancel:()=>a(!1),children:(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 w-full",children:[(0,r.jsx)(H.Z,{children:"Delete Model"}),(0,r.jsx)(G.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)("p",{children:["Model ID: ",(0,r.jsx)("b",{children:l})]})})]})})]})},eG=t(97766),eJ=t(46495);let{Title:eW,Link:eY}=eN.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 eH={OpenAI:"openai",Azure:"azure",Anthropic:"anthropic",Google_AI_Studio:"gemini",Bedrock:"bedrock",OpenAI_Compatible:"openai",Vertex_AI:"vertex_ai"};var e$=e=>{var l,t,s;let{accessToken:o,token:i,userRole:c,userID:d}=e,[m,p]=(0,n.useState)({data:[]}),[j,g]=(0,n.useState)([]),[y]=Q.Z.useForm(),[Z,f]=(0,n.useState)(null),[w,_]=(0,n.useState)([]),k=Object.values(a).filter(e=>isNaN(Number(e))),[v,S]=(0,n.useState)("OpenAI"),[A,N]=(0,n.useState)("");if((0,n.useEffect)(()=>{if(!o||!i||!c||!d)return;let e=async()=>{try{let e=await b(o,d,c);if(console.log("Model data response:",e.data),p(e),"Admin"===c&&o){let e=await O(o);console.log("Pending Requests:",j),g(e.requests||[])}}catch(e){console.error("There was an error fetching the model data",e)}};o&&i&&c&&d&&e();let l=async()=>{let e=await u();console.log("received model cost map data: ".concat(Object.keys(e))),f(e)};null==Z&&l()},[o,i,c,d,Z]),!m||!o||!i||!c||!d)return(0,r.jsx)("div",{children:"Loading..."});let C=[];for(let e=0;e(console.log("GET PROVIDER CALLED! - ".concat(Z)),null!=Z&&"object"==typeof Z&&e in Z)?Z[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,C.push(s.model_name),console.log(m.data[e])}if(c&&"Admin Viewer"==c){let{Title:e,Paragraph:l}=eN.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 I=e=>{console.log("received provider string: ".concat(e));let l=Object.keys(a).find(l=>a[l]===e);if(l){let e=eH[l];console.log("mappingResult: ".concat(e));let t=[];"object"==typeof Z&&Object.entries(Z).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)}),_(t),console.log("providerModels: ".concat(w))}},P=async()=>{try{h.ZP.info("Running health check..."),N("");let e=await K(o);N(e)}catch(e){console.error("Error running health check:",e),N("Error running health check")}},T=async e=>{try{let l=Object.values(e.model);console.log("received deployments: ".concat(l)),console.log("received type of deployments: ".concat(typeof l)),l.forEach(async l=>{console.log("litellm_model: ".concat(l));let t={},s={};t.model=l;let a="";for(let[l,r]of Object.entries(e))if("model_name"==l)a+=r;else if("custom_llm_provider"==l)continue;else if("model"==l)continue;else if("base_model"===l)s[l]=r;else if("litellm_extra_params"==l){console.log("litellm_extra_params:",r);let e={};if(r&&void 0!=r){try{e=JSON.parse(r)}catch(e){throw h.ZP.error("Failed to parse LiteLLM Extra Params: "+e,20),Error("Failed to parse litellm_extra_params: "+e)}for(let[l,s]of Object.entries(e))t[l]=s}}else t[l]=r;let r={model_name:a,litellm_params:t,model_info:s},n=await x(o,r);console.log("response for model create call: ".concat(n.data))}),y.resetFields()}catch(e){h.ZP.error("Failed to create model: "+e,20)}};return console.log("selectedProvider: ".concat(v)),console.log("providerModels.length: ".concat(w.length)),(0,r.jsx)("div",{style:{width:"100%",height:"100%"},children:(0,r.jsxs)(eO.Z,{className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Models"}),(0,r.jsx)(eE.Z,{children:"Add Model"}),(0,r.jsx)(eE.Z,{children:(0,r.jsx)("pre",{children:"/health Models"})})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(J.Z,{children:(0,r.jsx)(em.Z,{children:(0,r.jsxs)(ep.Z,{className:"mt-5",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Model Name "}),(0,r.jsx)(eZ.Z,{children:"Provider"}),"Admin"===c&&(0,r.jsx)(eZ.Z,{children:"API Base"}),(0,r.jsx)(eZ.Z,{children:"Extra litellm Params"}),(0,r.jsx)(eZ.Z,{children:"Input Price per token ($)"}),(0,r.jsx)(eZ.Z,{children:"Output Price per token ($)"}),(0,r.jsx)(eZ.Z,{children:"Max Tokens"})]})}),(0,r.jsx)(ej.Z,{children:m.data.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:e.model_name})}),(0,r.jsx)(eg.Z,{children:e.provider}),"Admin"===c&&(0,r.jsx)(eg.Z,{children:e.api_base}),(0,r.jsx)(eg.Z,{children:(0,r.jsxs)(eI.Z,{children:[(0,r.jsx)(eT.Z,{children:(0,r.jsx)(Y.Z,{children:"Litellm params"})}),(0,r.jsx)(eP.Z,{children:(0,r.jsx)("pre",{children:JSON.stringify(e.cleanedLitellmParams,null,2)})})]})}),(0,r.jsx)(eg.Z,{children:e.input_cost}),(0,r.jsx)(eg.Z,{children:e.output_cost}),(0,r.jsx)(eg.Z,{children:e.max_tokens}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(eK,{modelID:e.model_info.id,accessToken:o})})]},l))})]})})})}),(0,r.jsxs)(eM.Z,{className:"h-full",children:[(0,r.jsx)(eW,{level:2,children:"Add new model"}),(0,r.jsx)(em.Z,{children:(0,r.jsxs)(Q.Z,{form:y,onFinish:()=>{y.validateFields().then(e=>{T(e)}).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)(Q.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)(ew.Z,{value:v.toString(),children:k.map((e,l)=>(0,r.jsx)(eb.Z,{value:e,onClick:()=>{I(e),S(e)},children:e},l))})}),(0,r.jsx)(Q.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)(eD.Z,{placeholder:"Vertex AI (Anthropic, Gemini, etc.)"===(s=v.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)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(Y.Z,{className:"mb-3 mt-1",children:"Model name your users will pass in."})})]}),(0,r.jsx)(Q.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"===v?(0,r.jsx)(eD.Z,{placeholder:"Enter model name"}):w.length>0?(0,r.jsx)(eL.Z,{value:w,children:w.map((e,l)=>(0,r.jsx)(eU.Z,{value:e,children:e},l))}):(0,r.jsx)(eD.Z,{placeholder:"gpt-3.5-turbo-0125"})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(Y.Z,{className:"mb-3 mt-1",children:["Actual model name used for making ",(0,r.jsx)(eY,{href:"https://docs.litellm.ai/docs/providers",target:"_blank",children:"litellm.completion() call"}),". We'll ",(0,r.jsx)(eY,{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"!=v&&"Vertex AI (Anthropic, Gemini, etc.)"!=v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Key",name:"api_key",children:(0,r.jsx)(eD.Z,{placeholder:"sk-",type:"password"})}),"OpenAI"==v&&(0,r.jsx)(Q.Z.Item,{label:"Organization ID",name:"organization_id",children:(0,r.jsx)(eD.Z,{placeholder:"[OPTIONAL] my-unique-org"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Project",name:"vertex_project",children:(0,r.jsx)(eD.Z,{placeholder:"adroit-cadet-1234.."})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Location",name:"vertex_location",children:(0,r.jsx)(eD.Z,{placeholder:"us-east-1"})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"Vertex Credentials",name:"vertex_credentials",className:"mb-0",children:(0,r.jsx)(eJ.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;y.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)(es.ZP,{icon:(0,r.jsx)(eG.Z,{}),children:"Click to Upload"})})}),"Vertex AI (Anthropic, Gemini, etc.)"==v&&(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsx)(Y.Z,{className:"mb-3 mt-1",children:"Give litellm a gcp service account(.json file), so it can make the relevant calls"})})]}),("Azure"==v||"OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"==v)&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Base",name:"api_base",children:(0,r.jsx)(eD.Z,{placeholder:"https://..."})}),"Azure"==v&&(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"API Version",name:"api_version",children:(0,r.jsx)(eD.Z,{placeholder:"2023-07-01-preview"})}),"Azure"==v&&(0,r.jsxs)(Q.Z.Item,{label:"Base Model",name:"base_model",children:[(0,r.jsx)(eD.Z,{placeholder:"azure/gpt-3.5-turbo"}),(0,r.jsxs)(Y.Z,{children:["The actual model your azure deployment uses. Used for accurate cost tracking. Select name from ",(0,r.jsx)(eY,{href:"https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json",target:"_blank",children:"here"})]})]}),"Amazon Bedrock"==v&&(0,r.jsx)(Q.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)(eD.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(Q.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)(eD.Z,{placeholder:""})}),"Amazon Bedrock"==v&&(0,r.jsx)(Q.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)(eD.Z,{placeholder:"us-east-1"})}),(0,r.jsx)(Q.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)(eV.Z,{rows:4,placeholder:'{ "rpm": 100, "timeout": 0, "stream_timeout": 0 }'})}),(0,r.jsxs)(ez.Z,{children:[(0,r.jsx)(eB.Z,{span:10}),(0,r.jsx)(eB.Z,{span:10,children:(0,r.jsxs)(Y.Z,{className:"mb-3 mt-1",children:["Pass JSON of litellm supported params ",(0,r.jsx)(eY,{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)(es.ZP,{htmlType:"submit",children:"Add Model"})}),(0,r.jsx)(eq.Z,{title:"Get help on our github",children:(0,r.jsx)(eN.default.Link,{href:"https://github.com/BerriAI/litellm/issues",children:"Need Help?"})})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(Y.Z,{children:"`/health` will run a very small request through your models configured on litellm"}),(0,r.jsx)(W.Z,{onClick:P,children:"Run `/health`"}),A&&(0,r.jsx)("pre",{children:JSON.stringify(A,null,2)})]})})]})]})})};let{Option:eX}=X.default;var eQ=e=>{let{userID:l,accessToken:t}=e,[s]=Q.Z.useForm(),[a,o]=(0,n.useState)(!1),[i,c]=(0,n.useState)(null),[d,m]=(0,n.useState)([]);(0,n.useEffect)(()=>{(async()=>{try{let e=await k(t,l,"any"),s=[];for(let l=0;l{o(!1),s.resetFields()},x=()=>{o(!1),c(null),s.resetFields()},p=async e=>{try{h.ZP.info("Making API Call"),o(!0),console.log("formValues in create user:",e);let a=await g(t,l,e);console.log("user create Response:",a),c(a.key),h.ZP.success("API user Created"),s.resetFields(),localStorage.removeItem("userData"+l)}catch(e){console.error("Error creating the user:",e)}};return(0,r.jsxs)("div",{children:[(0,r.jsx)(W.Z,{className:"mx-auto",onClick:()=>o(!0),children:"+ Create New User"}),(0,r.jsx)(ee.Z,{title:"Create User",visible:a,width:800,footer:null,onOk:u,onCancel:x,children:(0,r.jsxs)(Q.Z,{form:s,onFinish:p,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsx)(Q.Z.Item,{label:"User ID",name:"user_id",children:(0,r.jsx)(el.Z,{placeholder:"Enter User ID"})}),(0,r.jsx)(Q.Z.Item,{label:"Team ID",name:"team_id",children:(0,r.jsx)(el.Z,{placeholder:"ai_team"})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",children:(0,r.jsx)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:d.map(e=>(0,r.jsx)(eX,{value:e,children:e},e))})}),(0,r.jsx)(Q.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Duration (eg: 30s, 30h, 30d)",name:"duration",children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Metadata",name:"metadata",children:(0,r.jsx)(el.Z.TextArea,{rows:4,placeholder:"Enter metadata as JSON"})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Create User"})})]})}),i&&(0,r.jsxs)(ee.Z,{title:"Save Your User",visible:a,onOk:u,onCancel:x,footer:null,children:[(0,r.jsxs)("p",{children:["Please save this secret user 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 user, you will need to generate a new one."]}),(0,r.jsx)("p",{children:null!=i?"API user: ".concat(i):"User being created, this might take 30s"})]})]})},e0=e=>{let{accessToken:l,token:t,keys:s,userRole:a,userID:o,setKeys:i}=e,[c,d]=(0,n.useState)(null),[m,h]=(0,n.useState)(null),[u,x]=(0,n.useState)(0),[p,j]=n.useState(null),[g,y]=(0,n.useState)(null);if((0,n.useEffect)(()=>{if(!l||!t||!a||!o)return;let e=async()=>{try{let e=await f(l,null,a,!0,u,25);console.log("user data response:",e),d(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 P(l,null);console.log("user data response:",e),h(e)}catch(e){console.error("There was an error fetching the model data",e)}};a&&("Admin"==a||"Admin Viewer"==a)&&!m&&s()},[l,t,a,o,u]),!c||!l||!t||!a||!o)return(0,r.jsx)("div",{children:"Loading..."});let Z=async e=>{try{let t=await P(l,e);console.log("user data response:",t),h(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)(J.Z,{className:"gap-2 p-2 h-[75vh] w-full mt-8",children:[(0,r.jsx)(eQ,{userID:o,accessToken:l}),(0,r.jsx)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh] mb-4",children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{variant:"line",defaultValue:"1",children:[(0,r.jsx)(eE.Z,{value:"1",children:"Key Owners"}),(0,r.jsx)(eE.Z,{value:"2",children:"End-Users"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(ep.Z,{className:"mt-5",children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"User ID"}),(0,r.jsx)(eZ.Z,{children:"User Email"}),(0,r.jsx)(eZ.Z,{children:"User Models"}),(0,r.jsx)(eZ.Z,{children:"User Spend ($ USD)"}),(0,r.jsx)(eZ.Z,{children:"User Max Budget ($ USD)"}),(0,r.jsx)(eZ.Z,{children:"User API Key Aliases"})]})}),(0,r.jsx)(ej.Z,{children:c.map(e=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.user_id}),(0,r.jsx)(eg.Z,{children:e.user_email}),(0,r.jsx)(eg.Z,{children:e.models&&e.models.length>0?e.models:"All Models"}),(0,r.jsx)(eg.Z,{children:e.spend?e.spend:0}),(0,r.jsx)(eg.Z,{children:e.max_budget?e.max_budget:"Unlimited"}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(J.Z,{numItems:2,children:e&&e.key_aliases&&e.key_aliases.filter(e=>null!==e).length>0?(0,r.jsx)(ec.Z,{size:"xs",color:"indigo",children:e.key_aliases.filter(e=>null!==e).join(", ")}):(0,r.jsx)(ec.Z,{size:"xs",color:"gray",children:"No Keys"})})})]},e.user_id))})]})}),(0,r.jsxs)(eM.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)(Y.Z,{className:"w-1/4 mr-2 text-right",children:"Key"}),(0,r.jsx)(ew.Z,{defaultValue:"1",className:"w-3/4",children:null==s?void 0:s.map((e,l)=>{if(e&&null!==e.key_name&&e.key_name.length>0)return(0,r.jsx)(eb.Z,{value:String(l),onClick:()=>Z(e.token),children:e.key_name},l)})})]})]}),(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"End User"}),(0,r.jsx)(eZ.Z,{children:"Spend"}),(0,r.jsx)(eZ.Z,{children:"Total Events"})]})}),(0,r.jsx)(ej.Z,{children:null==m?void 0:m.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.end_user}),(0,r.jsx)(eg.Z,{children:e.total_spend}),(0,r.jsx)(eg.Z,{children:e.total_events})]},l))})]})]})]})]})}),function(){if(!c)return null;let e=Math.ceil(c.length/25);return(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("div",{children:["Showing Page ",u+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===u,onClick:()=>x(u-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:()=>{x(u+1)},children:"Next →"})]})]})}()]})})},e1=e=>{let{teams:l,searchParams:t,accessToken:s,setTeams:a,userID:o,userRole:i}=e,[c]=Q.Z.useForm(),[d]=Q.Z.useForm(),{Title:m,Paragraph:u}=eN.default,[x,p]=(0,n.useState)(""),[j,g]=(0,n.useState)(!1),[y,f]=(0,n.useState)(l?l[0]:null),[w,b]=(0,n.useState)(!1),[_,v]=(0,n.useState)(!1),[S,A]=(0,n.useState)([]),[N,C]=(0,n.useState)(!1),[I,P]=(0,n.useState)(null),T=e=>{f(e),g(!0)},E=async e=>{let t=e.team_id;if(console.log("handleEditSubmit:",e),null==s)return;let r=await D(s,e);l&&a(l.map(e=>e.team_id===t?r.data:e)),h.ZP.success("Team updated successfully"),g(!1),f(null)},O=async e=>{P(e),C(!0)},F=async()=>{if(null!=I&&null!=l&&null!=s){try{await Z(s,I);let e=l.filter(e=>e.team_id!==I);a(e)}catch(e){console.error("Error deleting the team:",e)}C(!1),P(null)}};(0,n.useEffect)(()=>{(async()=>{try{if(null===o||null===i)return;if(null!==s){let e=(await k(s,o,i)).data.map(e=>e.id);console.log("available_model_names:",e),A(e)}}catch(e){console.error("Error fetching user models:",e)}})()},[s,o,i]);let R=async e=>{try{if(null!=s){h.ZP.info("Creating Team");let t=await M(s,e);null!==l?a([...l,t]):a([t]),console.log("response for team create call: ".concat(t)),h.ZP.success("Team created"),b(!1)}}catch(e){console.error("Error creating the team:",e),h.ZP.error("Error creating the team: "+e,20)}},U=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 L(s,y.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),f(r.data)}v(!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)(J.Z,{numItems:1,className:"gap-2 p-8 h-[75vh] w-full mt-2",children:[(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(m,{level:4,children:"All Teams"}),(0,r.jsxs)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:[(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Team Name"}),(0,r.jsx)(eZ.Z,{children:"Spend (USD)"}),(0,r.jsx)(eZ.Z,{children:"Budget (USD)"}),(0,r.jsx)(eZ.Z,{children:"Models"}),(0,r.jsx)(eZ.Z,{children:"TPM / RPM Limits"})]})}),(0,r.jsx)(ej.Z,{children:l&&l.length>0?l.map(e=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.team_alias}),(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.spend}),(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:e.max_budget?e.max_budget:"No limit"}),(0,r.jsx)(eg.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)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})}):e.models.map((e,l)=>"all-proxy-models"===e?(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"red",children:(0,r.jsx)(Y.Z,{children:"All Proxy Models"})},l):(0,r.jsx)(ec.Z,{size:"xs",className:"mb-1",color:"blue",children:(0,r.jsx)(Y.Z,{children:e.length>30?"".concat(e.slice(0,30),"..."):e})},l))}):null}),(0,r.jsx)(eg.Z,{style:{maxWidth:"4px",whiteSpace:"pre-wrap",overflow:"hidden"},children:(0,r.jsxs)(Y.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)(eg.Z,{children:[(0,r.jsx)(ex.Z,{icon:eo.Z,size:"sm",onClick:()=>T(e)}),(0,r.jsx)(ex.Z,{onClick:()=>O(e.team_id),icon:ei.Z,size:"sm"})]})]},e.team_id)):null})]}),N&&(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)(W.Z,{onClick:F,color:"red",className:"ml-2",children:"Delete"}),(0,r.jsx)(W.Z,{onClick:()=>{C(!1),P(null)},children:"Cancel"})]})]})]})})]})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto",onClick:()=>b(!0),children:"+ Create New Team"}),(0,r.jsx)(ee.Z,{title:"Create Team",visible:w,width:800,footer:null,onOk:()=>{b(!1),c.resetFields()},onCancel:()=>{b(!1),c.resetFields()},children:(0,r.jsxs)(Q.Z,{form:c,onFinish:R,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(X.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S.map(e=>(0,r.jsx)(X.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(Q.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Create Team"})})]})})]}),(0,r.jsxs)(G.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)(ew.Z,{defaultValue:"0",children:l.map((e,l)=>(0,r.jsx)(eb.Z,{value:String(l),onClick:()=>{f(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)(G.Z,{numColSpan:1,children:[(0,r.jsx)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Member Name"}),(0,r.jsx)(eZ.Z,{children:"Role"})]})}),(0,r.jsx)(ej.Z,{children:y?y.members_with_roles.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(eg.Z,{children:e.role})]},l)):null})]})}),y&&(0,r.jsx)(e=>{let{visible:l,onCancel:t,team:s,onSubmit:a}=e,[n]=Q.Z.useForm();return(0,r.jsx)(ee.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)(Q.Z,{form:n,onFinish:E,initialValues:s,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Team Name",name:"team_alias",rules:[{required:!0,message:"Please input a team name"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"Models",name:"models",children:(0,r.jsxs)(X.default,{mode:"multiple",placeholder:"Select models",style:{width:"100%"},children:[(0,r.jsx)(X.default.Option,{value:"all-proxy-models",children:"All Proxy Models"},"all-proxy-models"),S&&S.map(e=>(0,r.jsx)(X.default.Option,{value:e,children:e},e))]})}),(0,r.jsx)(Q.Z.Item,{label:"Max Budget (USD)",name:"max_budget",children:(0,r.jsx)(et.Z,{step:.01,precision:2,width:200})}),(0,r.jsx)(Q.Z.Item,{label:"Tokens per minute Limit (TPM)",name:"tpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.Z.Item,{label:"Requests per minute Limit (RPM)",name:"rpm_limit",children:(0,r.jsx)(et.Z,{step:1,width:400})}),(0,r.jsx)(Q.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)(es.ZP,{htmlType:"submit",children:"Edit Team"})})]})})},{visible:j,onCancel:()=>{g(!1),f(null)},team:y,onSubmit:E})]}),(0,r.jsxs)(G.Z,{numColSpan:1,children:[(0,r.jsx)(W.Z,{className:"mx-auto mb-5",onClick:()=>v(!0),children:"+ Add member"}),(0,r.jsx)(ee.Z,{title:"Add member",visible:_,width:800,footer:null,onOk:()=>{v(!1),d.resetFields()},onCancel:()=>{v(!1),d.resetFields()},children:(0,r.jsxs)(Q.Z,{form:c,onFinish:U,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(el.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)(Q.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(el.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)(es.ZP,{htmlType:"submit",children:"Add member"})})]})})]})]})})},e2=t(18190),e4=e=>{let l,{searchParams:t,accessToken:s,showSSOBanner:a}=e,[o]=Q.Z.useForm(),[i]=Q.Z.useForm(),{Title:c,Paragraph:d}=eN.default,[m,u]=(0,n.useState)(""),[x,p]=(0,n.useState)(null),[j,g]=(0,n.useState)(!1),[y,Z]=(0,n.useState)(!1),[f,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 F(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 F(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)(Q.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Email",name:"user_email",className:"mb-4",children:(0,r.jsx)(el.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)(Q.Z.Item,{label:"User ID",name:"user_id",className:"mb-4",children:(0,r.jsx)(el.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)(es.ZP,{htmlType:"submit",children:"Add member"})})]}),P=(e,l,t)=>(0,r.jsxs)(Q.Z,{form:o,onFinish:e,labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{rules:[{required:!0,message:"Required"}],label:"User Role",name:"user_role",labelCol:{span:10},labelAlign:"left",children:(0,r.jsx)(ew.Z,{value:l,children:A.map((e,l)=>(0,r.jsx)(eb.Z,{value:e,children:e},l))})}),(0,r.jsx)(Q.Z.Item,{label:"Team ID",name:"user_id",hidden:!0,initialValue:t,valuePropName:"user_id",className:"mt-8",children:(0,r.jsx)(el.Z,{value:t,disabled:!0})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Update role"})})]}),T=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call");let l=await U(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 U(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)}},O=async e=>{try{if(null!=s&&null!=x){h.ZP.info("Making API Call"),e.user_email,e.user_id;let l=await U(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)),Z(!1)}}catch(e){console.error("Error creating the key:",e)}},M=async e=>{null!=s&&V(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)(J.Z,{numItems:1,className:"gap-2 p-2 w-full",children:[(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsx)(em.Z,{className:"w-full mx-auto flex-auto overflow-y-auto max-h-[50vh]",children:(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Member Name"}),(0,r.jsx)(eZ.Z,{children:"Role"})]})}),(0,r.jsx)(ej.Z,{children:x?x.map((e,l)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.user_email?e.user_email:e.user_id?e.user_id:null}),(0,r.jsx)(eg.Z,{children:e.user_role}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)(ex.Z,{icon:eo.Z,size:"sm",onClick:()=>w(!0)}),(0,r.jsx)(ee.Z,{title:"Update role",visible:f,width:800,footer:null,onOk:N,onCancel:C,children:P(T,e.user_role,e.user_id)})]})]},l)):null})]})})}),(0,r.jsx)(G.Z,{numColSpan:1,children:(0,r.jsxs)("div",{className:"flex justify-start",children:[(0,r.jsx)(W.Z,{className:"mr-4 mb-5",onClick:()=>Z(!0),children:"+ Add admin"}),(0,r.jsx)(ee.Z,{title:"Add admin",visible:y,width:800,footer:null,onOk:()=>{Z(!1),i.resetFields()},onCancel:()=>{Z(!1),i.resetFields()},children:I(O)}),(0,r.jsx)(W.Z,{className:"mb-5",onClick:()=>g(!0),children:"+ Add viewer"}),(0,r.jsx)(ee.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)(J.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)(W.Z,{onClick:()=>_(!0),children:"Add SSO"}),(0,r.jsx)(ee.Z,{title:"Add SSO",visible:b,width:800,footer:null,onOk:()=>{_(!1),o.resetFields()},onCancel:()=>{_(!1),o.resetFields()},children:(0,r.jsxs)(Q.Z,{form:o,onFinish:e=>{O(e),M(e),_(!1),v(!0)},labelCol:{span:8},wrapperCol:{span:16},labelAlign:"left",children:[(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"Admin Email",name:"user_email",rules:[{required:!0,message:"Please enter the email of the proxy admin"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"PROXY BASE URL",name:"proxy_base_url",rules:[{required:!0,message:"Please enter the proxy base url"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)(Q.Z.Item,{label:"GOOGLE CLIENT ID",name:"google_client_id",rules:[{required:!0,message:"Please enter the google client id"}],children:(0,r.jsx)(el.Z.Password,{})}),(0,r.jsx)(Q.Z.Item,{label:"GOOGLE CLIENT SECRET",name:"google_client_secret",rules:[{required:!0,message:"Please enter the google client secret"}],children:(0,r.jsx)(el.Z.Password,{})})]}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Save"})})]})}),(0,r.jsxs)(ee.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)(Y.Z,{className:"mt-2",children:"1. DO NOT Exit this TAB"}),(0,r.jsx)(Y.Z,{className:"mt-2",children:"2. Open a new tab, visit your proxy base url"}),(0,r.jsx)(Y.Z,{className:"mt-2",children:"3. Confirm your SSO is configured correctly and you can login on the new Tab"}),(0,r.jsx)(Y.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)(es.ZP,{onClick:S,children:"Done"})})]})]}),(0,r.jsxs)(e2.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})," "]})]})]})]})},e8=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)([]),[i,c]=(0,n.useState)(!1),[d]=Q.Z.useForm(),[m,u]=(0,n.useState)(null),[x,p]=(0,n.useState)([]);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.data)})},[l,t,s]);let j=e=>{p(e),console.log("Selected values:",e)},g=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",x);try{V(l,{environment_variables:t,general_settings:{alert_types:x}})}catch(e){h.ZP.error("Failed to update callback: "+e,20)}h.ZP.success("Callback updated successfully")},y=()=>{l&&d.validateFields().then(e=>{console.log("Form values:",e),"langfuse"===e.callback?(V(l,{environment_variables:{LANGFUSE_PUBLIC_KEY:e.langfusePublicKey,LANGFUSE_SECRET_KEY:e.langfusePrivateKey},litellm_settings:{success_callback:[e.callback]}}),o(a?[...a,e.callback]:[e.callback])):"slack"===e.callback&&(V(l,{general_settings:{alerting:["slack"],alerting_threshold:300},environment_variables:{SLACK_WEBHOOK_URL:e.slackWebhookUrl}}),o(a?[...a,e.callback]:[e.callback])),c(!1),d.resetFields(),u(null)})};return l?(0,r.jsxs)("div",{className:"w-full mx-4",children:[(0,r.jsxs)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(H.Z,{children:"Logging Callbacks"}),(0,r.jsxs)(em.Z,{children:[(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Callback"}),(0,r.jsx)(eZ.Z,{children:"Callback Env Vars"})]})}),(0,r.jsx)(ej.Z,{children:a.map((e,t)=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:(0,r.jsx)(ec.Z,{color:"emerald",children:e.name})}),(0,r.jsxs)(eg.Z,{children:[(0,r.jsx)("ul",{children:Object.entries(e.variables).map(e=>{let[l,t]=e;return(0,r.jsxs)("li",{children:[(0,r.jsx)(Y.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)(eD.Z,{name:l,defaultValue:t,type:"password"})]},l)})}),e.all_alert_types&&(0,r.jsxs)("div",{children:[(0,r.jsx)(Y.Z,{className:"mt-2",children:"Alerting Types"}),(0,r.jsx)(X.default,{mode:"multiple",style:{width:"100%"},placeholder:"Select Alerting Types",optionLabelProp:"label",onChange:j,defaultValue:e.alerting_types,children:e.all_alert_types.map(e=>(0,r.jsx)(X.default.Option,{value:e,label:e,children:e},e))})]}),(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>g(e),children:"Save Changes"}),(0,r.jsx)(W.Z,{onClick:()=>B(l,e.name),className:"mx-2",children:"Test Callback"})]})]},t))})]}),(0,r.jsx)(W.Z,{size:"xs",className:"mt-2",onClick:()=>{console.log("Add callback clicked"),c(!0)},children:"Add Callback"})]})]}),(0,r.jsx)(ee.Z,{title:"Add Callback",visible:i,onOk:y,width:800,onCancel:()=>{c(!1),d.resetFields(),u(null)},footer:null,children:(0,r.jsxs)(Q.Z,{form:d,layout:"vertical",onFinish:y,children:[(0,r.jsx)(Q.Z.Item,{label:"Callback",name:"callback",rules:[{required:!0,message:"Please select a callback"}],children:(0,r.jsxs)(X.default,{onChange:e=>{u(e)},children:[(0,r.jsx)(X.default.Option,{value:"langfuse",children:"langfuse"}),(0,r.jsx)(X.default.Option,{value:"slack",children:"slack alerting"})]})}),"langfuse"===m&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q.Z.Item,{label:"LANGFUSE_PUBLIC_KEY",name:"langfusePublicKey",rules:[{required:!0,message:"Please enter the public key"}],children:(0,r.jsx)(el.Z.Password,{})}),(0,r.jsx)(Q.Z.Item,{label:"LANGFUSE_PRIVATE_KEY",name:"langfusePrivateKey",rules:[{required:!0,message:"Please enter the private key"}],children:(0,r.jsx)(el.Z.Password,{})})]}),"slack"===m&&(0,r.jsx)(Q.Z.Item,{label:"SLACK_WEBHOOK_URL",name:"slackWebhookUrl",rules:[{required:!0,message:"Please enter the Slack webhook URL"}],children:(0,r.jsx)(el.Z,{})}),(0,r.jsx)("div",{style:{textAlign:"right",marginTop:"10px"},children:(0,r.jsx)(es.ZP,{htmlType:"submit",children:"Save"})})]})})]}):null},e3=e=>{let{accessToken:l,userRole:t,userID:s}=e,[a,o]=(0,n.useState)({}),[i,c]=(0,n.useState)(!1),[d]=Q.Z.useForm(),[m,u]=(0,n.useState)(null);(0,n.useEffect)(()=>{l&&t&&s&&q(l,s,t).then(e=>{console.log("callbacks",e),o(e.router_settings)})},[l,t,s]);let x=e=>{if(!l)return;console.log("router_settings",e);let t=Object.fromEntries(Object.entries(e).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);try{V(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)(J.Z,{numItems:1,className:"gap-2 p-8 w-full mt-2",children:[(0,r.jsx)(H.Z,{children:"Router Settings"}),(0,r.jsx)(em.Z,{children:(0,r.jsxs)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Setting"}),(0,r.jsx)(eZ.Z,{children:"Value"})]})}),(0,r.jsx)(ej.Z,{children:Object.entries(a).map(e=>{let[l,t]=e;return(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:(0,r.jsx)(Y.Z,{children:l})}),(0,r.jsx)(eg.Z,{children:(0,r.jsx)(eD.Z,{name:l,defaultValue:"object"==typeof t?JSON.stringify(t,null,2):t.toString()})})]},l)})})]})}),(0,r.jsx)(G.Z,{children:(0,r.jsx)(W.Z,{className:"mt-2",onClick:()=>x(a),children:"Save Changes"})})]})}):null},e5=t(12968),e6=t(67951);async function e7(e,l,t,s){console.log("isLocal:",!1);let a=window.location.origin,r=new e5.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 e9=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 k(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}]})},y=async()=>{if(""!==c.trim()&&o&&t&&s&&a){h(e=>[...e,{role:"user",content:c}]);try{u&&await e7(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}=eN.default;return(0,r.jsxs)("div",{children:[(0,r.jsx)(e,{level:1,children:"Access Denied"}),(0,r.jsx)(l,{children:"Ask your proxy admin for access to test models"})]})}return(0,r.jsx)("div",{style:{width:"100%",position:"relative"},children:(0,r.jsx)(J.Z,{className:"gap-2 p-8 h-[80vh] w-full mt-2",children:(0,r.jsx)(em.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"Chat"}),(0,r.jsx)(eE.Z,{children:"API Reference"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsxs)(eM.Z,{children:[(0,r.jsx)("div",{className:"sm:max-w-2xl",children:(0,r.jsxs)(J.Z,{numItems:2,children:[(0,r.jsxs)(G.Z,{children:[(0,r.jsx)(Y.Z,{children:"API Key"}),(0,r.jsx)(eD.Z,{placeholder:"Type API Key here",type:"password",onValueChange:i,value:o})]}),(0,r.jsxs)(G.Z,{className:"mx-2",children:[(0,r.jsx)(Y.Z,{children:"Select Model:"}),(0,r.jsx)(X.default,{placeholder:"Select a Model",onChange:e=>{console.log("selected ".concat(e)),x(e)},options:p,style:{width:"200px"}})]})]})}),(0,r.jsxs)(ep.Z,{className:"mt-5",style:{display:"block",maxHeight:"60vh",overflowY:"auto"},children:[(0,r.jsx)(ey.Z,{children:(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eg.Z,{})})}),(0,r.jsx)(ej.Z,{children:m.map((e,l)=>(0,r.jsx)(ef.Z,{children:(0,r.jsx)(eg.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)(eD.Z,{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"Type your message..."}),(0,r.jsx)(W.Z,{onClick:y,className:"ml-2",children:"Send"})]})})]}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{children:[(0,r.jsx)(eE.Z,{children:"OpenAI Python SDK"}),(0,r.jsx)(eE.Z,{children:"LlamaIndex"}),(0,r.jsx)(eE.Z,{children:"Langchain Py"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nimport openai\nclient = openai.OpenAI(\n api_key="your_api_key",\n base_url="http://0.0.0.0:4000" # proxy base url\n)\n\nresponse = client.chat.completions.create(\n model="gpt-3.5-turbo", # model to use from Models Tab\n messages = [\n {\n "role": "user",\n "content": "this is a test request, write a short poem"\n }\n ],\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-openai-client",\n "generation_id": "openai-client-gen-id22",\n "trace_id": "openai-client-trace-id22",\n "trace_user_id": "openai-client-user-id2"\n }\n }\n)\n\nprint(response)\n '})}),(0,r.jsx)(eM.Z,{children:(0,r.jsx)(e6.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)(eM.Z,{children:(0,r.jsx)(e6.Z,{language:"python",children:'\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.prompts.chat import (\n ChatPromptTemplate,\n HumanMessagePromptTemplate,\n SystemMessagePromptTemplate,\n)\nfrom langchain.schema import HumanMessage, SystemMessage\n\nchat = ChatOpenAI(\n openai_api_base="http://0.0.0.0:8000",\n model = "gpt-3.5-turbo",\n temperature=0.1,\n extra_body={\n "metadata": {\n "generation_name": "ishaan-generation-langchain-client",\n "generation_id": "langchain-client-gen-id22",\n "trace_id": "langchain-client-trace-id22",\n "trace_user_id": "langchain-client-user-id2"\n }\n }\n)\n\nmessages = [\n SystemMessage(\n content="You are a helpful assistant that im using to make a test request to."\n ),\n HumanMessage(\n content="test from litellm. tell me why it\'s amazing in 1 sentence"\n ),\n]\nresponse = chat(messages)\n\nprint(response)\n\n '})})]})]})})]})]})})})})},le=t(33509),ll=t(95781);let{Sider:lt}=le.default;var ls=e=>{let{setPage:l,userRole:t,defaultSelectedKey:s}=e;return"Admin Viewer"==t?(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["4"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:"API Keys"},"4"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:"Models"},"2"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:"Chat UI"},"3"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:"Usage"},"1")]})})}):(0,r.jsx)(le.default,{style:{minHeight:"100vh",maxWidth:"120px"},children:(0,r.jsx)(lt,{width:120,children:(0,r.jsxs)(ll.Z,{mode:"inline",defaultSelectedKeys:s||["1"],style:{height:"100%",borderRight:0},children:[(0,r.jsx)(ll.Z.Item,{onClick:()=>l("api-keys"),children:(0,r.jsx)(Y.Z,{children:"API Keys"})},"1"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("llm-playground"),children:(0,r.jsx)(Y.Z,{children:"Test Key"})},"3"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("models"),children:(0,r.jsx)(Y.Z,{children:"Models"})},"2"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("teams"),children:(0,r.jsx)(Y.Z,{children:"Teams"})},"6"):null,(0,r.jsx)(ll.Z.Item,{onClick:()=>l("usage"),children:(0,r.jsx)(Y.Z,{children:"Usage"})},"4"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("users"),children:(0,r.jsx)(Y.Z,{children:"Users"})},"5"):null,(0,r.jsx)(ll.Z.Item,{onClick:()=>l("settings"),children:(0,r.jsx)(Y.Z,{children:"Integrations"})},"8"),(0,r.jsx)(ll.Z.Item,{onClick:()=>l("general-settings"),children:(0,r.jsx)(Y.Z,{children:"Settings"})},"9"),"Admin"==t?(0,r.jsx)(ll.Z.Item,{onClick:()=>l("admin-panel"),children:(0,r.jsx)(Y.Z,{children:"Admin"})},"7"):null]})})})},la=t(67989),lr=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)([]),[y,Z]=(0,n.useState)([]),[f,w]=(0,n.useState)([]),[b,k]=(0,n.useState)([]),[v,P]=(0,n.useState)([]),[O,F]=(0,n.useState)([]),M=new Date(o.getFullYear(),o.getMonth(),1),R=new Date(o.getFullYear(),o.getMonth()+1,0),D=U(M),L=U(R);function U(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)}return console.log("Start date is ".concat(D)),console.log("End date is ".concat(L)),(0,n.useEffect)(()=>{l&&t&&s&&a&&(async()=>{try{if(console.log("user role: ".concat(s)),"Admin"==s||"Admin Viewer"==s){let e=await C(l);c(e);let t=(await I(l)).map(e=>({key:(e.key_name||e.key_alias||e.api_key).substring(0,10),spend:e.total_spend}));m(t);let s=(await T(l)).map(e=>({key:e.model,spend:e.total_spend}));u(s);let a=await S(l);console.log("teamSpend",a),g(a.daily_spend),w(a.teams);let r=a.total_spend_per_team;r=r.map(e=>(e.name=e.team_id||"",e.value=e.total_spend||0,e)),k(r);let n=await A(l);Z(n.top_10_tags)}else"App Owner"==s&&await N(l,t,s,a,D,L).then(async 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 E(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 _(l,a,s);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),P(e),F(r)}catch(e){console.error("There was an error fetching the data",e)}})()},[l,t,s,a,D,L]),(0,r.jsxs)("div",{style:{width:"100%"},className:"p-8",children:[(0,r.jsx)(ev,{userID:a,userRole:s,accessToken:l,userSpend:null}),(0,r.jsxs)(eO.Z,{children:[(0,r.jsxs)(eF.Z,{className:"mt-2",children:[(0,r.jsx)(eE.Z,{children:"All Up"}),(0,r.jsx)(eE.Z,{children:"Team Based Usage"}),(0,r.jsx)(eE.Z,{children:"Tag Based Usage"}),(0,r.jsx)(eE.Z,{children:"Model Based Usage"})]}),(0,r.jsxs)(eR.Z,{children:[(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Monthly Spend"}),(0,r.jsx)(ed.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Top API Keys"}),(0,r.jsx)(ed.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Top Users"}),(0,r.jsx)(ed.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)(G.Z,{numColSpan:1,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Top Models"}),(0,r.jsx)(ed.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)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full",children:[(0,r.jsxs)(G.Z,{numColSpan:2,children:[(0,r.jsxs)(em.Z,{className:"mb-2",children:[(0,r.jsx)(H.Z,{children:"Total Spend Per Team"}),(0,r.jsx)(la.Z,{data:b})]}),(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Daily Spend Per Team"}),(0,r.jsx)(ed.Z,{className:"h-72",data:j,showLegend:!0,index:"date",categories:f,yAxisWidth:80,stack:!0})]})]}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsx)(eM.Z,{children:(0,r.jsxs)(J.Z,{numItems:2,className:"gap-2 h-[75vh] w-full mb-4",children:[(0,r.jsx)(G.Z,{numColSpan:2,children:(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Spend Per Tag - Last 30 Days"}),(0,r.jsxs)(Y.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)(ep.Z,{children:[(0,r.jsx)(ey.Z,{children:(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eZ.Z,{children:"Tag"}),(0,r.jsx)(eZ.Z,{children:"Spend"}),(0,r.jsx)(eZ.Z,{children:"Requests"})]})}),(0,r.jsx)(ej.Z,{children:y.map(e=>(0,r.jsxs)(ef.Z,{children:[(0,r.jsx)(eg.Z,{children:e.name}),(0,r.jsx)(eg.Z,{children:e.value}),(0,r.jsx)(eg.Z,{children:e.log_count})]},e.name))})]})]})}),(0,r.jsx)(G.Z,{numColSpan:2})]})}),(0,r.jsxs)(eM.Z,{children:[(0,r.jsxs)(em.Z,{children:[(0,r.jsx)(H.Z,{children:"Number Requests per Model"}),(0,r.jsx)(ed.Z,{data:v,className:"h-[50vh]",index:"model",categories:["num_requests"],colors:["blue"],yAxisWidth:400,layout:"vertical",tickGap:5})]}),(0,r.jsxs)(em.Z,{className:"mt-4",children:[(0,r.jsx)(H.Z,{children:"Latency Per Model"}),(0,r.jsx)(ed.Z,{data:O,className:"h-[50vh]",index:"model",categories:["avg_latency_seconds"],colors:["red"],yAxisWidth:400,layout:"vertical",tickGap:5})]})]})]})]})]})},ln=()=>{let{Title:e,Paragraph:l}=eN.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=j.get("userID"),y=j.get("token"),[Z,f]=(0,n.useState)("api-keys"),[w,b]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(y){let e=(0,eA.o)(y);if(e){if(console.log("Decoded token:",e),console.log("Decoded key:",e.key),b(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&&f("usage")}else console.log("User role not defined");e.user_email?i(e.user_email):console.log("User Email is not set ".concat(e)),e.login_method?p("username_password"==e.login_method):console.log("User Email is not set ".concat(e))}}},[y]),(0,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:g,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)(ls,{setPage:f,userRole:t,defaultSelectedKey:null})}),"api-keys"==Z?(0,r.jsx)(eC,{userID:g,userRole:t,teams:c,keys:h,setUserRole:s,userEmail:a,setUserEmail:i,setTeams:d,setKeys:u}):"models"==Z?(0,r.jsx)(e$,{userID:g,userRole:t,token:y,accessToken:w}):"llm-playground"==Z?(0,r.jsx)(e9,{userID:g,userRole:t,token:y,accessToken:w}):"users"==Z?(0,r.jsx)(e0,{userID:g,userRole:t,token:y,keys:h,accessToken:w,setKeys:u}):"teams"==Z?(0,r.jsx)(e1,{teams:c,setTeams:d,searchParams:j,accessToken:w,userID:g,userRole:t}):"admin-panel"==Z?(0,r.jsx)(e4,{setTeams:d,searchParams:j,accessToken:w,showSSOBanner:x}):"settings"==Z?(0,r.jsx)(e8,{userID:g,userRole:t,accessToken:w}):"general-settings"==Z?(0,r.jsx)(e3,{userID:g,userRole:t,accessToken:w}):(0,r.jsx)(lr,{userID:g,userRole:t,token:y,accessToken:w})]})]})})}}},function(e){e.O(0,[968,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/index.html b/ui/litellm-dashboard/out/index.html index 93b1ab8ebf..acb0606eed 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 8a4a6fb5b5..c49dab960c 100644 --- a/ui/litellm-dashboard/out/index.txt +++ b/ui/litellm-dashboard/out/index.txt @@ -1,7 +1,7 @@ 2:I[77831,[],""] -3:I[16586,["968","static/chunks/968-0cc23fee51b47e4e.js","931","static/chunks/app/page-93ac11fb17dce9d6.js"],""] +3:I[65249,["968","static/chunks/968-0cc23fee51b47e4e.js","931","static/chunks/app/page-6ba29bc4256320f4.js"],""] 4:I[5613,[],""] 5:I[31778,[],""] -0:["Oe7aA-U7OV9Y13gspREJQ",[[["",{"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/dc347b0d22ffde5d.css","precedence":"next","crossOrigin":""}]],"$L6"]]]] +0:["Vjlnu8AomhCFg4fkGtcUs",[[["",{"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/dc347b0d22ffde5d.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/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx index 0a7cc6403f..f20f0aee7c 100644 --- a/ui/litellm-dashboard/src/app/page.tsx +++ b/ui/litellm-dashboard/src/app/page.tsx @@ -9,6 +9,7 @@ import Teams from "@/components/teams"; import AdminPanel from "@/components/admins"; import Settings from "@/components/settings"; import GeneralSettings from "@/components/general_settings"; +import APIRef from "@/components/api_ref"; import ChatUI from "@/components/chat_ui"; import Sidebar from "../components/leftnav"; import Usage from "../components/usage"; @@ -165,6 +166,8 @@ const CreateKeyPage = () => { accessToken={accessToken} showSSOBanner={showSSOBanner} /> + ) : page == "api_ref" ? ( + ) : page == "settings" ? ( { + return ( + <> + +
+

OpenAI Compatible Proxy: API Reference

+ 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 + + + + OpenAI Python SDK + LlamaIndex + Langchain Py + + + + + {` +import openai +client = openai.OpenAI( + api_key="your_api_key", + base_url="http://0.0.0.0:4000" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys +) + +response = client.chat.completions.create( + model="gpt-3.5-turbo", # model to send to the proxy + messages = [ + { + "role": "user", + "content": "this is a test request, write a short poem" + } + ] +) + +print(response) + `} + + + + + {` +import os, dotenv + +from llama_index.llms import AzureOpenAI +from llama_index.embeddings import AzureOpenAIEmbedding +from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext + +llm = AzureOpenAI( + engine="azure-gpt-3.5", # model_name on litellm proxy + temperature=0.0, + azure_endpoint="http://0.0.0.0:4000", # litellm proxy endpoint + api_key="sk-1234", # litellm proxy API Key + api_version="2023-07-01-preview", +) + +embed_model = AzureOpenAIEmbedding( + deployment_name="azure-embedding-model", + azure_endpoint="http://0.0.0.0:4000", + api_key="sk-1234", + api_version="2023-07-01-preview", +) + + +documents = SimpleDirectoryReader("llama_index_data").load_data() +service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model) +index = VectorStoreIndex.from_documents(documents, service_context=service_context) + +query_engine = index.as_query_engine() +response = query_engine.query("What did the author do growing up?") +print(response) + + `} + + + + + {` +from langchain.chat_models import ChatOpenAI +from langchain.prompts.chat import ( + ChatPromptTemplate, + HumanMessagePromptTemplate, + SystemMessagePromptTemplate, +) +from langchain.schema import HumanMessage, SystemMessage + +chat = ChatOpenAI( + openai_api_base="http://0.0.0.0:4000", + model = "gpt-3.5-turbo", + temperature=0.1 +) + +messages = [ + SystemMessage( + content="You are a helpful assistant that im using to make a test request to." + ), + HumanMessage( + content="test from litellm. tell me why it's amazing in 1 sentence" + ), +] +response = chat(messages) + +print(response) + + `} + + + + + + +
+
+ + + + ) +} + +export default APIRef; + diff --git a/ui/litellm-dashboard/src/components/chat_ui.tsx b/ui/litellm-dashboard/src/components/chat_ui.tsx index 774a68af64..5bc9abde69 100644 --- a/ui/litellm-dashboard/src/components/chat_ui.tsx +++ b/ui/litellm-dashboard/src/components/chat_ui.tsx @@ -13,12 +13,12 @@ import { TabGroup, TabList, TabPanel, + TabPanels, Metric, Col, Text, SelectItem, TextInput, - TabPanels, Button, } from "@tremor/react"; @@ -201,7 +201,6 @@ const ChatUI: React.FC = ({ Chat - API Reference @@ -272,124 +271,7 @@ const ChatUI: React.FC = ({ - - - - OpenAI Python SDK - LlamaIndex - Langchain Py - - - - - {` -import openai -client = openai.OpenAI( - api_key="your_api_key", - base_url="http://0.0.0.0:4000" # proxy base url -) - -response = client.chat.completions.create( - model="gpt-3.5-turbo", # model to use from Models Tab - messages = [ - { - "role": "user", - "content": "this is a test request, write a short poem" - } - ], - extra_body={ - "metadata": { - "generation_name": "ishaan-generation-openai-client", - "generation_id": "openai-client-gen-id22", - "trace_id": "openai-client-trace-id22", - "trace_user_id": "openai-client-user-id2" - } - } -) - -print(response) - `} - - - - - {` -import os, dotenv - -from llama_index.llms import AzureOpenAI -from llama_index.embeddings import AzureOpenAIEmbedding -from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext - -llm = AzureOpenAI( - engine="azure-gpt-3.5", # model_name on litellm proxy - temperature=0.0, - azure_endpoint="http://0.0.0.0:4000", # litellm proxy endpoint - api_key="sk-1234", # litellm proxy API Key - api_version="2023-07-01-preview", -) - -embed_model = AzureOpenAIEmbedding( - deployment_name="azure-embedding-model", - azure_endpoint="http://0.0.0.0:4000", - api_key="sk-1234", - api_version="2023-07-01-preview", -) - - -documents = SimpleDirectoryReader("llama_index_data").load_data() -service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model) -index = VectorStoreIndex.from_documents(documents, service_context=service_context) - -query_engine = index.as_query_engine() -response = query_engine.query("What did the author do growing up?") -print(response) - - `} - - - - - {` -from langchain.chat_models import ChatOpenAI -from langchain.prompts.chat import ( - ChatPromptTemplate, - HumanMessagePromptTemplate, - SystemMessagePromptTemplate, -) -from langchain.schema import HumanMessage, SystemMessage - -chat = ChatOpenAI( - openai_api_base="http://0.0.0.0:8000", - model = "gpt-3.5-turbo", - temperature=0.1, - extra_body={ - "metadata": { - "generation_name": "ishaan-generation-langchain-client", - "generation_id": "langchain-client-gen-id22", - "trace_id": "langchain-client-trace-id22", - "trace_user_id": "langchain-client-user-id2" - } - } -) - -messages = [ - SystemMessage( - content="You are a helpful assistant that im using to make a test request to." - ), - HumanMessage( - content="test from litellm. tell me why it's amazing in 1 sentence" - ), -] -response = chat(messages) - -print(response) - - `} - - - - - + diff --git a/ui/litellm-dashboard/src/components/create_key_button.tsx b/ui/litellm-dashboard/src/components/create_key_button.tsx index 8dde3fb001..d950c3be5c 100644 --- a/ui/litellm-dashboard/src/components/create_key_button.tsx +++ b/ui/litellm-dashboard/src/components/create_key_button.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from "react"; import { Button, TextInput, Grid, Col } from "@tremor/react"; -import { Card, Metric, Text, Title, Subtitle } from "@tremor/react"; +import { Card, Metric, Text, Title, Subtitle, Accordion, AccordionHeader, AccordionBody, } from "@tremor/react"; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { Button as Button2, @@ -147,6 +147,17 @@ const CreateKey: React.FC = ({ mode="multiple" placeholder="Select models" style={{ width: "100%" }} + onChange={(values) => { + // Check if "All Team Models" is selected + const isAllTeamModelsSelected = values.includes("all-team-models"); + + // If "All Team Models" is selected, deselect all other models + if (isAllTeamModelsSelected) { + const newValues = ["all-team-models"]; + // You can call the form's setFieldsValue method to update the value + form.setFieldsValue({ models: newValues }); + } + }} >